Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d0208e16 authored by Jeff DeCew's avatar Jeff DeCew Committed by Automerger Merge Worker
Browse files

Merge "Fix Notification view transformations in RTL" into sc-dev am:...

Merge "Fix Notification view transformations in RTL" into sc-dev am: 37781305 am: 14d71626 am: 71cea0f9

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14722830

Change-Id: Iddc57c50750def155aaf13fbc1a148ef4f67526c
parents b5bbf7d4 71cea0f9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -100,6 +100,7 @@
    <!-- For notification icons for which targetSdk < L, this caches whether the icon is grayscale -->
    <item type="id" name="icon_is_grayscale" />
    <item type="id" name="image_icon_tag" />
    <item type="id" name="align_transform_end_tag" />
    <item type="id" name="contains_transformed_view" />
    <item type="id" name="is_clicked_heads_up_tag" />

+4 −4
Original line number Diff line number Diff line
@@ -98,20 +98,20 @@ public class TextViewTransformState extends TransformState {
        int lineCount = mText.getLineCount();
        return lineCount == 1 && lineCount == otherTvs.mText.getLineCount()
                && getEllipsisCount() == otherTvs.getEllipsisCount()
                && getViewHeight() != otherTvs.getViewHeight();
                && getContentHeight() != otherTvs.getContentHeight();
    }

    @Override
    protected int getViewWidth() {
    protected int getContentWidth() {
        Layout l = mText.getLayout();
        if (l != null) {
            return (int) l.getLineWidth(0);
        }
        return super.getViewWidth();
        return super.getContentWidth();
    }

    @Override
    protected int getViewHeight() {
    protected int getContentHeight() {
        return mText.getLineHeight();
    }

+56 −23
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ public class TransformState {
    public static final int TRANSFORM_X = 0x1;
    public static final int TRANSFORM_Y = 0x10;
    public static final int TRANSFORM_ALL = TRANSFORM_X | TRANSFORM_Y;
    public static final int ALIGN_END_TAG = R.id.align_transform_end_tag;

    private static final float UNDEFINED = -1f;
    private static final int TRANSFORMATION_START_X = R.id.transformation_start_x_tag;
@@ -78,11 +79,13 @@ public class TransformState {
    private boolean mSameAsAny;
    private float mTransformationEndY = UNDEFINED;
    private float mTransformationEndX = UNDEFINED;
    private boolean mAlignEnd;
    protected Interpolator mDefaultInterpolator = Interpolators.FAST_OUT_SLOW_IN;

    public void initFrom(View view, TransformInfo transformInfo) {
        mTransformedView = view;
        mTransformInfo = transformInfo;
        mAlignEnd = Boolean.TRUE.equals(view.getTag(ALIGN_END_TAG));
    }

    /**
@@ -135,13 +138,16 @@ public class TransformState {
        final View transformedView = mTransformedView;
        boolean transformX = (transformationFlags & TRANSFORM_X) != 0;
        boolean transformY = (transformationFlags & TRANSFORM_Y) != 0;
        int viewHeight = getViewHeight();
        int otherHeight = otherState.getViewHeight();
        boolean differentHeight = otherHeight != viewHeight && otherHeight != 0 && viewHeight != 0;
        int viewWidth = getViewWidth();
        int otherWidth = otherState.getViewWidth();
        boolean differentWidth = otherWidth != viewWidth && otherWidth != 0 && viewWidth != 0;
        boolean transformScale = transformScale(otherState) && (differentHeight || differentWidth);
        int ownContentHeight = getContentHeight();
        int otherContentHeight = otherState.getContentHeight();
        boolean differentHeight = otherContentHeight != ownContentHeight
                && otherContentHeight != 0 && ownContentHeight != 0;
        int ownContentWidth = getContentWidth();
        int otherContentWidth = otherState.getContentWidth();
        boolean differentWidth = otherContentWidth != ownContentWidth
                && otherContentWidth != 0 && ownContentWidth != 0;
        boolean transformScale = (differentHeight || differentWidth) && transformScale(otherState);
        boolean transformRightEdge = transformRightEdge(otherState);
        // lets animate the positions correctly
        if (transformationAmount == 0.0f
                || transformX && getTransformationStartX() == UNDEFINED
@@ -159,23 +165,30 @@ public class TransformState {
            if (customTransformation == null
                    || !customTransformation.initTransformation(this, otherState)) {
                if (transformX) {
                    if (transformRightEdge) {
                        int otherViewWidth = otherState.getTransformedView().getWidth();
                        int ownViewWidth = transformedView.getWidth();
                        setTransformationStartX((otherPosition[0] + otherViewWidth)
                                - (ownStablePosition[0] + ownViewWidth));
                    } else {
                        setTransformationStartX(otherPosition[0] - ownStablePosition[0]);
                    }
                }
                if (transformY) {
                    setTransformationStartY(otherPosition[1] - ownStablePosition[1]);
                }
                // we also want to animate the scale if we're the same
                View otherView = otherState.getTransformedView();
                if (transformScale && differentWidth) {
                    setTransformationStartScaleX(otherWidth * otherView.getScaleX()
                            / (float) viewWidth);
                    transformedView.setPivotX(0);
                    setTransformationStartScaleX(otherContentWidth * otherView.getScaleX()
                            / (float) ownContentWidth);
                    transformedView.setPivotX(transformRightEdge ? transformedView.getWidth() : 0);
                } else {
                    setTransformationStartScaleX(UNDEFINED);
                }
                if (transformScale && differentHeight) {
                    setTransformationStartScaleY(otherHeight * otherView.getScaleY()
                            / (float) viewHeight);
                    setTransformationStartScaleY(otherContentHeight * otherView.getScaleY()
                            / (float) ownContentHeight);
                    transformedView.setPivotY(0);
                } else {
                    setTransformationStartScaleY(UNDEFINED);
@@ -239,11 +252,19 @@ public class TransformState {
        }
    }

    protected int getViewWidth() {
    /**
     * The width of the content of this view.  For some views, like TextViews, this will be the
     * width of content inside the view which is transforming, rather than the view's full width.
     */
    protected int getContentWidth() {
        return mTransformedView.getWidth();
    }

    protected int getViewHeight() {
    /**
     * The height of the content of this view.  For some views, like TextViews, this will be the
     * height of content inside the view which is transforming, rather than the view's full height.
     */
    protected int getContentHeight() {
        return mTransformedView.getHeight();
    }

@@ -251,6 +272,12 @@ public class TransformState {
        return sameAs(otherState);
    }

    protected boolean transformRightEdge(TransformState otherState) {
        boolean alignEnd = mAlignEnd && otherState.mAlignEnd;
        boolean isRtl = mTransformedView.isLayoutRtl() && otherState.mTransformedView.isLayoutRtl();
        return alignEnd ^ isRtl;
    }

    /**
     * Transforms the {@link #mTransformedView} to the given transformviewstate
     * @param otherState the state to transform from
@@ -302,6 +329,9 @@ public class TransformState {
        boolean transformX = (transformationFlags & TRANSFORM_X) != 0;
        boolean transformY = (transformationFlags & TRANSFORM_Y) != 0;
        boolean transformScale = transformScale(otherState);
        boolean transformRightEdge = transformRightEdge(otherState);
        int ownContentWidth = getContentWidth();
        int otherContentWidth = otherState.getContentWidth();
        // lets animate the positions correctly
        if (transformationAmount == 0.0f) {
            if (transformX) {
@@ -316,14 +346,13 @@ public class TransformState {
                        : transformedView.getTranslationY();
                setTransformationStartY(start);
            }
            View otherView = otherState.getTransformedView();
            if (transformScale && otherState.getViewWidth() != getViewWidth()) {
            if (transformScale && otherContentWidth != ownContentWidth) {
                setTransformationStartScaleX(transformedView.getScaleX());
                transformedView.setPivotX(0);
                transformedView.setPivotX(transformRightEdge ? transformedView.getWidth() : 0);
            } else {
                setTransformationStartScaleX(UNDEFINED);
            }
            if (transformScale && otherState.getViewHeight() != getViewHeight()) {
            if (transformScale && otherState.getContentHeight() != getContentHeight()) {
                setTransformationStartScaleY(transformedView.getScaleY());
                transformedView.setPivotY(0);
            } else {
@@ -336,7 +365,11 @@ public class TransformState {
        int[] otherStablePosition = otherState.getLaidOutLocationOnScreen();
        int[] ownPosition = getLaidOutLocationOnScreen();
        if (transformX) {
            float endX = otherStablePosition[0] - ownPosition[0];
            int ownViewWidth = transformedView.getWidth();
            int otherViewWidth = otherState.getTransformedView().getWidth();
            float endX = transformRightEdge
                    ? (otherStablePosition[0] + otherViewWidth) - (ownPosition[0] + ownViewWidth)
                    : otherStablePosition[0] - ownPosition[0];
            float interpolation = interpolatedValue;
            if (customTransformation != null) {
                if (customTransformation.customTransformTarget(this, otherState)) {
@@ -370,19 +403,18 @@ public class TransformState {
                    interpolation));
        }
        if (transformScale) {
            View otherView = otherState.getTransformedView();
            float transformationStartScaleX = getTransformationStartScaleX();
            if (transformationStartScaleX != UNDEFINED) {
                transformedView.setScaleX(
                        NotificationUtils.interpolate(transformationStartScaleX,
                                (otherState.getViewWidth() / (float) getViewWidth()),
                                (otherContentWidth / (float) ownContentWidth),
                                interpolatedValue));
            }
            float transformationStartScaleY = getTransformationStartScaleY();
            if (transformationStartScaleY != UNDEFINED) {
                transformedView.setScaleY(
                        NotificationUtils.interpolate(transformationStartScaleY,
                                (otherState.getViewHeight() / (float) getViewHeight()),
                                (otherState.getContentHeight() / (float) getContentHeight()),
                                interpolatedValue));
            }
        }
@@ -529,6 +561,7 @@ public class TransformState {
        mSameAsAny = false;
        mTransformationEndX = UNDEFINED;
        mTransformationEndY = UNDEFINED;
        mAlignEnd = false;
        mDefaultInterpolator = Interpolators.FAST_OUT_SLOW_IN;
    }

+1 −0
Original line number Diff line number Diff line
@@ -151,6 +151,7 @@ public class NotificationTemplateViewWrapper extends NotificationHeaderViewWrapp
        mRightIcon = mView.findViewById(com.android.internal.R.id.right_icon);
        if (mRightIcon != null) {
            mRightIcon.setTag(ImageTransformState.ICON_TAG, getRightIcon(sbn.getNotification()));
            mRightIcon.setTag(TransformState.ALIGN_END_TAG, true);
        }
        mLeftIcon = mView.findViewById(com.android.internal.R.id.left_icon);
        if (mLeftIcon != null) {