mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-09 19:38:34 +00:00
Fix reactions scrubber positioning on vertically split multiscreen.
This commit is contained in:
parent
5782c8a58b
commit
4453d1752f
@ -6,21 +6,21 @@ import android.graphics.Canvas;
|
|||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
import android.graphics.PorterDuffXfermode;
|
import android.graphics.PorterDuffXfermode;
|
||||||
|
import android.graphics.Rect;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.view.ViewTreeObserver;
|
import android.view.ViewTreeObserver;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
|
||||||
|
|
||||||
public class MaskView extends View {
|
public class MaskView extends View {
|
||||||
|
|
||||||
private View target;
|
private View target;
|
||||||
private int[] targetLocation = new int[2];
|
private ViewGroup activityContentView;
|
||||||
private int statusBarHeight;
|
private Paint maskPaint;
|
||||||
private Paint maskPaint;
|
private Rect drawingRect = new Rect();
|
||||||
|
|
||||||
private final ViewTreeObserver.OnDrawListener onDrawListener = this::invalidate;
|
private final ViewTreeObserver.OnDrawListener onDrawListener = this::invalidate;
|
||||||
|
|
||||||
@ -41,8 +41,12 @@ public class MaskView extends View {
|
|||||||
setLayerType(LAYER_TYPE_HARDWARE, maskPaint);
|
setLayerType(LAYER_TYPE_HARDWARE, maskPaint);
|
||||||
|
|
||||||
maskPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
|
maskPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
|
||||||
|
}
|
||||||
|
|
||||||
statusBarHeight = ViewUtil.getStatusBarHeight(this);
|
@Override
|
||||||
|
protected void onAttachedToWindow() {
|
||||||
|
super.onAttachedToWindow();
|
||||||
|
activityContentView = getRootView().findViewById(android.R.id.content);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTarget(@Nullable View target) {
|
public void setTarget(@Nullable View target) {
|
||||||
@ -67,14 +71,15 @@ public class MaskView extends View {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
target.getLocationInWindow(targetLocation);
|
target.getDrawingRect(drawingRect);
|
||||||
|
activityContentView.offsetDescendantRectToMyCoords(target, drawingRect);
|
||||||
|
|
||||||
Bitmap mask = Bitmap.createBitmap(target.getWidth(), target.getHeight(), Bitmap.Config.ARGB_8888);
|
Bitmap mask = Bitmap.createBitmap(target.getWidth(), target.getHeight(), Bitmap.Config.ARGB_8888);
|
||||||
Canvas maskCanvas = new Canvas(mask);
|
Canvas maskCanvas = new Canvas(mask);
|
||||||
|
|
||||||
target.draw(maskCanvas);
|
target.draw(maskCanvas);
|
||||||
|
|
||||||
canvas.drawBitmap(mask, 0, targetLocation[1] - statusBarHeight, maskPaint);
|
canvas.drawBitmap(mask, 0, drawingRect.top, maskPaint);
|
||||||
|
|
||||||
mask.recycle();
|
mask.recycle();
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,6 @@ public final class ConversationReactionOverlay extends RelativeLayout {
|
|||||||
private MaskView maskView;
|
private MaskView maskView;
|
||||||
private Toolbar toolbar;
|
private Toolbar toolbar;
|
||||||
|
|
||||||
private int statusBarHeight;
|
|
||||||
private float touchDownDeadZoneSize;
|
private float touchDownDeadZoneSize;
|
||||||
private float distanceFromTouchDownPointToTopOfScrubberDeadZone;
|
private float distanceFromTouchDownPointToTopOfScrubberDeadZone;
|
||||||
private float distanceFromTouchDownPointToBottomOfScrubberDeadZone;
|
private float distanceFromTouchDownPointToBottomOfScrubberDeadZone;
|
||||||
@ -87,6 +86,7 @@ public final class ConversationReactionOverlay extends RelativeLayout {
|
|||||||
private int selectedVerticalTranslation;
|
private int selectedVerticalTranslation;
|
||||||
private int scrubberHorizontalMargin;
|
private int scrubberHorizontalMargin;
|
||||||
private int animationEmojiStartDelayFactor;
|
private int animationEmojiStartDelayFactor;
|
||||||
|
private int statusBarHeight;
|
||||||
|
|
||||||
private OnReactionSelectedListener onReactionSelectedListener;
|
private OnReactionSelectedListener onReactionSelectedListener;
|
||||||
private Toolbar.OnMenuItemClickListener onToolbarItemClickedListener;
|
private Toolbar.OnMenuItemClickListener onToolbarItemClickedListener;
|
||||||
@ -124,7 +124,6 @@ public final class ConversationReactionOverlay extends RelativeLayout {
|
|||||||
distanceFromTouchDownPointToBottomOfScrubberDeadZone = getResources().getDimensionPixelSize(R.dimen.conversation_reaction_scrub_deadzone_distance_from_touch_bottom);
|
distanceFromTouchDownPointToBottomOfScrubberDeadZone = getResources().getDimensionPixelSize(R.dimen.conversation_reaction_scrub_deadzone_distance_from_touch_bottom);
|
||||||
|
|
||||||
touchDownDeadZoneSize = getResources().getDimensionPixelSize(R.dimen.conversation_reaction_touch_deadzone_size);
|
touchDownDeadZoneSize = getResources().getDimensionPixelSize(R.dimen.conversation_reaction_touch_deadzone_size);
|
||||||
statusBarHeight = ViewUtil.getStatusBarHeight(this);
|
|
||||||
scrubberDistanceFromTouchDown = getResources().getDimensionPixelOffset(R.dimen.conversation_reaction_scrubber_distance);
|
scrubberDistanceFromTouchDown = getResources().getDimensionPixelOffset(R.dimen.conversation_reaction_scrubber_distance);
|
||||||
scrubberHeight = getResources().getDimensionPixelOffset(R.dimen.conversation_reaction_scrubber_height);
|
scrubberHeight = getResources().getDimensionPixelOffset(R.dimen.conversation_reaction_scrubber_height);
|
||||||
scrubberWidth = getResources().getDimensionPixelOffset(R.dimen.reaction_scrubber_width);
|
scrubberWidth = getResources().getDimensionPixelOffset(R.dimen.reaction_scrubber_width);
|
||||||
@ -150,8 +149,15 @@ public final class ConversationReactionOverlay extends RelativeLayout {
|
|||||||
setupToolbarMenuItems();
|
setupToolbarMenuItems();
|
||||||
setupSelectedEmojiBackground();
|
setupSelectedEmojiBackground();
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= 21) {
|
||||||
|
View statusBarBackground = activity.findViewById(android.R.id.statusBarBackground);
|
||||||
|
statusBarHeight = statusBarBackground == null ? 0 : statusBarBackground.getHeight();
|
||||||
|
} else {
|
||||||
|
statusBarHeight = ViewUtil.getStatusBarHeight(this);
|
||||||
|
}
|
||||||
|
|
||||||
final float scrubberTranslationY = Math.max(-scrubberDistanceFromTouchDown + halfActionBarHeight,
|
final float scrubberTranslationY = Math.max(-scrubberDistanceFromTouchDown + halfActionBarHeight,
|
||||||
lastSeenDownPoint.y - scrubberHeight - scrubberDistanceFromTouchDown);
|
lastSeenDownPoint.y - scrubberHeight - scrubberDistanceFromTouchDown - statusBarHeight);
|
||||||
|
|
||||||
final float halfWidth = scrubberWidth / 2f + scrubberHorizontalMargin;
|
final float halfWidth = scrubberWidth / 2f + scrubberHorizontalMargin;
|
||||||
final float screenWidth = getResources().getDisplayMetrics().widthPixels;
|
final float screenWidth = getResources().getDisplayMetrics().widthPixels;
|
||||||
@ -222,7 +228,7 @@ public final class ConversationReactionOverlay extends RelativeLayout {
|
|||||||
public boolean applyTouchEvent(@NonNull MotionEvent motionEvent) {
|
public boolean applyTouchEvent(@NonNull MotionEvent motionEvent) {
|
||||||
if (!isShowing()) {
|
if (!isShowing()) {
|
||||||
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
|
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
|
||||||
lastSeenDownPoint.set(motionEvent.getRawX(), motionEvent.getRawY());
|
lastSeenDownPoint.set(motionEvent.getX(), motionEvent.getY());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -234,14 +240,14 @@ public final class ConversationReactionOverlay extends RelativeLayout {
|
|||||||
if (overlayState == OverlayState.UNINITAILIZED) {
|
if (overlayState == OverlayState.UNINITAILIZED) {
|
||||||
downIsOurs = false;
|
downIsOurs = false;
|
||||||
|
|
||||||
deadzoneTouchPoint.set(motionEvent.getRawX(), motionEvent.getRawY());
|
deadzoneTouchPoint.set(motionEvent.getX(), motionEvent.getY());
|
||||||
|
|
||||||
overlayState = OverlayState.DEADZONE;
|
overlayState = OverlayState.DEADZONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (overlayState == OverlayState.DEADZONE) {
|
if (overlayState == OverlayState.DEADZONE) {
|
||||||
float deltaX = Math.abs(deadzoneTouchPoint.x - motionEvent.getRawX());
|
float deltaX = Math.abs(deadzoneTouchPoint.x - motionEvent.getX());
|
||||||
float deltaY = Math.abs(deadzoneTouchPoint.y - motionEvent.getRawY());
|
float deltaY = Math.abs(deadzoneTouchPoint.y - motionEvent.getY());
|
||||||
|
|
||||||
if (deltaX > touchDownDeadZoneSize || deltaY > touchDownDeadZoneSize) {
|
if (deltaX > touchDownDeadZoneSize || deltaY > touchDownDeadZoneSize) {
|
||||||
overlayState = OverlayState.SCRUB;
|
overlayState = OverlayState.SCRUB;
|
||||||
@ -277,7 +283,7 @@ public final class ConversationReactionOverlay extends RelativeLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
deadzoneTouchPoint.set(motionEvent.getRawX(), motionEvent.getRawY());
|
deadzoneTouchPoint.set(motionEvent.getX(), motionEvent.getY());
|
||||||
overlayState = OverlayState.DEADZONE;
|
overlayState = OverlayState.DEADZONE;
|
||||||
downIsOurs = true;
|
downIsOurs = true;
|
||||||
return true;
|
return true;
|
||||||
@ -337,7 +343,7 @@ public final class ConversationReactionOverlay extends RelativeLayout {
|
|||||||
final float emojiLeft = (segmentSize * i) + emojiStripViewBounds.left;
|
final float emojiLeft = (segmentSize * i) + emojiStripViewBounds.left;
|
||||||
horizontalEmojiBoundary.update(emojiLeft, emojiLeft + segmentSize);
|
horizontalEmojiBoundary.update(emojiLeft, emojiLeft + segmentSize);
|
||||||
|
|
||||||
if (horizontalEmojiBoundary.contains(motionEvent.getRawX()) && boundary.contains(motionEvent.getRawY())) {
|
if (horizontalEmojiBoundary.contains(motionEvent.getX()) && boundary.contains(motionEvent.getY())) {
|
||||||
selected = i;
|
selected = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user