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

Commit cdd5718e authored by Mady Mellor's avatar Mady Mellor
Browse files

Fix the gear so that it is always centered based on the min noti height

This alters how the gear is positioned so that it is centered based
on what the minimum height of the notification or the height of a
collapsed group.

Bug: 27316874
Change-Id: I726f51ab8b18b485d1b2ea22ca7bb4dd71ee3d85
parent 65136ac6
Loading
Loading
Loading
Loading
+3 −6
Original line number Diff line number Diff line
@@ -24,12 +24,9 @@

    <com.android.systemui.statusbar.AlphaOptimizedImageView
        android:id="@+id/gear_icon"
        android:layout_width="@dimen/notification_gear_width"
        android:layout_height="@dimen/notification_gear_height"
        android:paddingTop="@dimen/notification_gear_top_padding"
        android:paddingStart="@dimen/notification_gear_padding"
        android:paddingEnd="@dimen/notification_gear_padding"
        android:paddingBottom="@dimen/notification_gear_padding"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="@dimen/notification_gear_padding"
        android:src="@drawable/ic_settings"
        android:tint="@color/notification_gear_color"
        android:alpha="0"
+1 −7
Original line number Diff line number Diff line
@@ -81,13 +81,7 @@
    <!-- Width of the space containing the gear icon behind a notification -->
    <dimen name="notification_gear_width">64dp</dimen>

    <!-- Height of the space containing the gear icon behind a notification -->
    <dimen name="notification_gear_height">74dp</dimen>

    <!-- The space above the gear icon displayed behind a notification -->
    <dimen name="notification_gear_top_padding">30dp</dimen>

    <!-- The space on either side and below the gear icon displayed behind a notification  -->
    <!-- The space around the gear icon displayed behind a notification  -->
    <dimen name="notification_gear_padding">20dp</dimen>

    <!-- size at which Notification icons will be drawn in the status bar -->
+3 −0
Original line number Diff line number Diff line
@@ -260,6 +260,9 @@ public class ExpandableNotificationRow extends ActivatableNotificationView {
        int headsUpheight = headsUpCustom && beforeN ? mMaxHeadsUpHeightLegacy
                : mMaxHeadsUpHeight;
        layout.setHeights(minHeight, headsUpheight, mNotificationMaxHeight);
        if (mSettingsIconRow != null) {
            mSettingsIconRow.updateVerticalLocation();
        }
    }

    public StatusBarNotification getStatusBarNotification() {
+31 −10
Original line number Diff line number Diff line
@@ -55,8 +55,11 @@ public class NotificationSettingsIconRow extends FrameLayout implements View.OnC
    private boolean mOnLeft = true;
    private boolean mDismissing = false;
    private boolean mSnapping = false;
    private boolean mIconPlaced = false;

    private int[] mGearLocation = new int[2];
    private int[] mParentLocation = new int[2];
    private int mVertSpaceForGear;

    public NotificationSettingsIconRow(Context context) {
        this(context, null);
@@ -83,16 +86,18 @@ public class NotificationSettingsIconRow extends FrameLayout implements View.OnC
        setOnClickListener(this);
        mHorizSpaceForGear =
                getResources().getDimensionPixelOffset(R.dimen.notification_gear_width);
        mVertSpaceForGear = getResources().getDimensionPixelOffset(R.dimen.notification_min_height);
        resetState();
    }

    public void resetState() {
        setGearAlpha(0f);
        mIconPlaced = false;
        mSettingsFadedIn = false;
        mAnimating = false;
        mSnapping = false;
        mDismissing = false;
        setIconLocation(true /* on left */, true /* force */);
        setIconLocation(true /* on left */);
        if (mListener != null) {
            mListener.onSettingsIconRowReset(mParent);
        }
@@ -104,7 +109,7 @@ public class NotificationSettingsIconRow extends FrameLayout implements View.OnC

    public void setNotificationRowParent(ExpandableNotificationRow parent) {
        mParent = parent;
        setIconLocation(mOnLeft, true /* force */);
        setIconLocation(mOnLeft);
    }

    public void setAppName(String appName) {
@@ -184,7 +189,7 @@ public class NotificationSettingsIconRow extends FrameLayout implements View.OnC
        if (isIconLocationChange(transX)) {
            setGearAlpha(0f);
        }
        setIconLocation(transX > 0 /* fromLeft */, false /* force */);
        setIconLocation(transX > 0 /* fromLeft */);
        mFadeAnimator = ValueAnimator.ofFloat(mGearIcon.getAlpha(), 1);
        mFadeAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
@@ -221,22 +226,39 @@ public class NotificationSettingsIconRow extends FrameLayout implements View.OnC
        mFadeAnimator.start();
    }

    public void updateVerticalLocation() {
        if (mParent == null) {
            return;
        }
        int parentHeight = mParent.getCollapsedHeight();
        if (parentHeight < mVertSpaceForGear) {
            mGearIcon.setTranslationY((parentHeight / 2) - (mGearIcon.getHeight() / 2));
        } else {
            mGearIcon.setTranslationY((mVertSpaceForGear - mGearIcon.getHeight()) / 2);
        }
    }

    @Override
    public void onRtlPropertiesChanged(int layoutDirection) {
        setIconLocation(mOnLeft, true /* force */);
        setIconLocation(mOnLeft);
    }

    public void setIconLocation(boolean onLeft, boolean force) {
        if ((!force && onLeft == mOnLeft) || mSnapping || mParent == null) {
    public void setIconLocation(boolean onLeft) {
        updateVerticalLocation();
        if ((mIconPlaced && onLeft == mOnLeft) || mSnapping || mParent == null
                || mGearIcon.getWidth() == 0) {
            // Do nothing
            return;
        }
        final boolean isRtl = mParent.isLayoutRtl();

        // TODO No need to cast to float here once b/28050538 is fixed.
        final float left = (float) (isRtl ? -(mParent.getWidth() - mHorizSpaceForGear) : 0);
        final float right = (float) (isRtl ? 0 : (mParent.getWidth() - mHorizSpaceForGear));
        setTranslationX(onLeft ? left : right);
        final float centerX = ((mHorizSpaceForGear - mGearIcon.getWidth()) / 2);
        setTranslationX(onLeft ? left + centerX : right + centerX);
        mOnLeft = onLeft;
        mIconPlaced = true;
    }

    public boolean isIconLocationChange(float translation) {
@@ -264,9 +286,8 @@ public class NotificationSettingsIconRow extends FrameLayout implements View.OnC
                mParent.getLocationOnScreen(mParentLocation);

                final int centerX = (int) (mHorizSpaceForGear / 2);
                // Top / bottom padding are not equal, need to subtract them to get center of gear.
                final int centerY = (int) (mGearIcon.getHeight() - mGearIcon.getPaddingTop()
                        - mGearIcon.getPaddingBottom()) / 2 + mGearIcon.getPaddingTop();
                final int centerY =
                        (int) (mGearIcon.getTranslationY() * 2 + mGearIcon.getHeight())/ 2;
                final int x = mGearLocation[0] - mParentLocation[0] + centerX;
                final int y = mGearLocation[1] - mParentLocation[1] + centerY;
                mListener.onGearTouched(mParent, x, y);
+1 −2
Original line number Diff line number Diff line
@@ -3519,8 +3519,7 @@ public class NotificationStackScrollLayout extends ViewGroup
                    } else {
                        // Check scheduled, reset alpha and update location; check will fade it in
                        mCurrIconRow.setGearAlpha(0f);
                        mCurrIconRow.setIconLocation(translation > 0 /* onLeft */,
                                false /* force */);
                        mCurrIconRow.setIconLocation(translation > 0 /* onLeft */);
                    }
                }
            }