Fix color offset on devices with notches.

fork-5.53.8
Alex Hart 2021-10-01 16:09:54 -03:00 zatwierdzone przez Cody Henthorne
rodzic a385cb0b68
commit 52cfb57d36
9 zmienionych plików z 18 dodań i 29 usunięć

Wyświetl plik

@ -10,6 +10,7 @@ import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect; 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.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
@ -207,9 +208,9 @@ public class ConversationItemFooter extends ConstraintLayout {
setBackground(null); setBackground(null);
} }
public @Nullable Projection getProjection() { public @Nullable Projection getProjection(@NonNull ViewGroup coordinateRoot) {
if (getVisibility() == VISIBLE) { if (getVisibility() == VISIBLE) {
return Projection.relativeToViewRoot(this, new Projection.Corners(ViewUtil.dpToPx(11))); return Projection.relativeToParent(coordinateRoot, this, new Projection.Corners(ViewUtil.dpToPx(11)));
} else { } else {
return null; return null;
} }

Wyświetl plik

@ -691,8 +691,8 @@ public class ConversationAdapter
} }
@Override @Override
public @NonNull List<Projection> getColorizerProjections() { public @NonNull List<Projection> getColorizerProjections(@NonNull ViewGroup coordinateRoot) {
return getBindable().getColorizerProjections(); return getBindable().getColorizerProjections(coordinateRoot);
} }
} }

Wyświetl plik

@ -1715,7 +1715,7 @@ public final class ConversationItem extends RelativeLayout implements BindableCo
} }
@Override @Override
public @NonNull List<Projection> getColorizerProjections() { public @NonNull List<Projection> getColorizerProjections(@NonNull ViewGroup coordinateRoot) {
List<Projection> projections = new LinkedList<>(); List<Projection> projections = new LinkedList<>();
if (messageRecord.isOutgoing() && if (messageRecord.isOutgoing() &&
@ -1723,10 +1723,10 @@ public final class ConversationItem extends RelativeLayout implements BindableCo
!messageRecord.isRemoteDelete() && !messageRecord.isRemoteDelete() &&
bodyBubbleCorners != null) bodyBubbleCorners != null)
{ {
Projection bodyBubbleToRoot = Projection.relativeToViewRoot(bodyBubble, bodyBubbleCorners).translateX(bodyBubble.getTranslationX()); Projection bodyBubbleToRoot = Projection.relativeToParent(coordinateRoot, bodyBubble, bodyBubbleCorners).translateX(bodyBubble.getTranslationX());
Projection videoToBubble = bodyBubble.getVideoPlayerProjection(); Projection videoToBubble = bodyBubble.getVideoPlayerProjection();
if (videoToBubble != null) { if (videoToBubble != null) {
Projection videoToRoot = Projection.translateFromDescendantToParentCoords(videoToBubble, bodyBubble, (ViewGroup) getRootView()); Projection videoToRoot = Projection.translateFromDescendantToParentCoords(videoToBubble, bodyBubble, coordinateRoot);
projections.addAll(Projection.getCapAndTail(bodyBubbleToRoot, videoToRoot)); projections.addAll(Projection.getCapAndTail(bodyBubbleToRoot, videoToRoot));
} else { } else {
projections.add(bodyBubbleToRoot); projections.add(bodyBubbleToRoot);
@ -1737,7 +1737,7 @@ public final class ConversationItem extends RelativeLayout implements BindableCo
hasNoBubble(messageRecord) && hasNoBubble(messageRecord) &&
hasWallpaper) hasWallpaper)
{ {
Projection footerProjection = getActiveFooter(messageRecord).getProjection(); Projection footerProjection = getActiveFooter(messageRecord).getProjection(coordinateRoot);
if (footerProjection != null) { if (footerProjection != null) {
projections.add(footerProjection.translateX(bodyBubble.getTranslationX())); projections.add(footerProjection.translateX(bodyBubble.getTranslationX()));
} }
@ -1748,7 +1748,7 @@ public final class ConversationItem extends RelativeLayout implements BindableCo
quoteView != null) quoteView != null)
{ {
bodyBubble.setQuoteViewProjection(quoteView.getProjection(bodyBubble)); bodyBubble.setQuoteViewProjection(quoteView.getProjection(bodyBubble));
projections.add(quoteView.getProjection((ViewGroup) getRootView()).translateX(bodyBubble.getTranslationX() + this.getTranslationX())); projections.add(quoteView.getProjection(coordinateRoot).translateX(bodyBubble.getTranslationX() + this.getTranslationX()));
} }
return projections; return projections;

Wyświetl plik

@ -221,7 +221,7 @@ public final class ConversationUpdateItem extends FrameLayout
} }
@Override @Override
public @NonNull List<Projection> getColorizerProjections() { public @NonNull List<Projection> getColorizerProjections(@NonNull ViewGroup coordinateRoot) {
return Collections.emptyList(); return Collections.emptyList();
} }

Wyświetl plik

@ -1,5 +1,6 @@
package org.thoughtcrime.securesms.conversation.colors package org.thoughtcrime.securesms.conversation.colors
import android.view.ViewGroup
import org.thoughtcrime.securesms.util.Projection import org.thoughtcrime.securesms.util.Projection
/** /**
@ -7,5 +8,5 @@ import org.thoughtcrime.securesms.util.Projection
* generating its own projection. * generating its own projection.
*/ */
interface Colorizable { interface Colorizable {
val colorizerProjections: List<Projection> fun getColorizerProjections(coordinateRoot: ViewGroup): List<Projection>
} }

Wyświetl plik

@ -98,7 +98,7 @@ class RecyclerViewColorizer(private val recyclerView: RecyclerView) {
if (child != null) { if (child != null) {
val holder = parent.getChildViewHolder(child) val holder = parent.getChildViewHolder(child)
if (holder is Colorizable) { if (holder is Colorizable) {
holder.colorizerProjections.forEach { holder.getColorizerProjections(parent).forEach {
c.drawPath(it.path, holePunchPaint) c.drawPath(it.path, holePunchPaint)
} }
} }

Wyświetl plik

@ -127,7 +127,7 @@ class MultiselectItemDecoration(
val parts: MultiselectCollection = child.conversationMessage.multiselectCollection val parts: MultiselectCollection = child.conversationMessage.multiselectCollection
val projections: List<Projection> = child.colorizerProjections + if (child.canPlayContent()) listOf(child.getGiphyMp4PlayableProjection(child.rootView as ViewGroup)) else emptyList() val projections: List<Projection> = child.getColorizerProjections(parent) + if (child.canPlayContent()) listOf(child.getGiphyMp4PlayableProjection(parent)) else emptyList()
path.reset() path.reset()
projections.forEach { it.applyToPath(path) } projections.forEach { it.applyToPath(path) }
@ -307,7 +307,7 @@ class MultiselectItemDecoration(
parent.forEach { child -> parent.forEach { child ->
if (child is Multiselectable && child.conversationMessage == inFocus.conversationMessage) { if (child is Multiselectable && child.conversationMessage == inFocus.conversationMessage) {
path.addRect(child.left.toFloat(), child.top.toFloat(), child.right.toFloat(), child.bottom.toFloat(), Path.Direction.CW) path.addRect(child.left.toFloat(), child.top.toFloat(), child.right.toFloat(), child.bottom.toFloat(), Path.Direction.CW)
child.colorizerProjections.forEach { child.getColorizerProjections(parent).forEach {
path.op(it.path, Path.Op.DIFFERENCE) path.op(it.path, Path.Op.DIFFERENCE)
} }

Wyświetl plik

@ -250,11 +250,8 @@ final class MessageHeaderViewHolder extends RecyclerView.ViewHolder implements G
} }
@Override @Override
public @NonNull List<Projection> getColorizerProjections() { public @NonNull List<Projection> getColorizerProjections(@NonNull ViewGroup coordinateRoot) {
return conversationItem.getColorizerProjections() return conversationItem.getColorizerProjections(coordinateRoot);
.stream()
.map(p -> Projection.translateFromRootToDescendantCoords(p, (ViewGroup) itemView.getParent()))
.collect(Collectors.toList());
} }
private class ExpiresUpdater implements Runnable { private class ExpiresUpdater implements Runnable {

Wyświetl plik

@ -142,16 +142,6 @@ public final class Projection {
return new Projection(viewBounds.left, viewBounds.top, toProject.getWidth(), toProject.getHeight(), corners); return new Projection(viewBounds.left, viewBounds.top, toProject.getWidth(), toProject.getHeight(), corners);
} }
public static @NonNull Projection translateFromRootToDescendantCoords(@NonNull Projection rootProjection, @NonNull View descendant) {
Rect viewBounds = new Rect();
viewBounds.set((int) rootProjection.x, (int) rootProjection.y, (int) rootProjection.x + rootProjection.width, (int) rootProjection.y + rootProjection.height);
((ViewGroup) descendant.getRootView()).offsetRectIntoDescendantCoords(descendant, viewBounds);
return new Projection(viewBounds.left, viewBounds.top, rootProjection.width, rootProjection.height, rootProjection.corners);
}
public static @NonNull Projection translateFromDescendantToParentCoords(@NonNull Projection descendantProjection, @NonNull View descendant, @NonNull ViewGroup parent) { public static @NonNull Projection translateFromDescendantToParentCoords(@NonNull Projection descendantProjection, @NonNull View descendant, @NonNull ViewGroup parent) {
Rect viewBounds = new Rect(); Rect viewBounds = new Rect();