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

Commit 02cca81c authored by Lyn Han's avatar Lyn Han
Browse files

Update color for permission, settings, pointer

Fix bug where we created inset drawable from adaptive icon
drawable, instead of the original settings drawable.

And refactors.

Test: manual
Bug: 123829494
Bug: 123663905
Change-Id: I9342213365cf3679facd22da8592325777d3d17f
parent 2b67a2b3
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -28,7 +28,7 @@
    />
    />


    <FrameLayout
    <FrameLayout
        android:id="@+id/header_permission_wrapper"
        android:id="@+id/permission_or_settings"
        android:layout_width="match_parent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_height="wrap_content"
        android:animateLayoutChanges="true">
        android:animateLayoutChanges="true">
+2 −2
Original line number Original line Diff line number Diff line
@@ -222,14 +222,14 @@ public class BubbleController implements BubbleExpandedView.OnBubbleBlockedListe
    @Override
    @Override
    public void onUiModeChanged() {
    public void onUiModeChanged() {
        if (mStackView != null) {
        if (mStackView != null) {
            mStackView.onConfigChanged();
            mStackView.onThemeChanged();
        }
        }
    }
    }


    @Override
    @Override
    public void onOverlayChanged() {
    public void onOverlayChanged() {
        if (mStackView != null) {
        if (mStackView != null) {
            mStackView.onConfigChanged();
            mStackView.onThemeChanged();
        }
        }
    }
    }


+61 −44
Original line number Original line Diff line number Diff line
@@ -69,7 +69,7 @@ import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow
import com.android.systemui.statusbar.notification.stack.ExpandableViewState;
import com.android.systemui.statusbar.notification.stack.ExpandableViewState;


/**
/**
 * Container for the expanded bubble view, handles rendering the caret and header of the view.
 * Container for the expanded bubble view, handles rendering the caret and settings icon.
 */
 */
public class BubbleExpandedView extends LinearLayout implements View.OnClickListener {
public class BubbleExpandedView extends LinearLayout implements View.OnClickListener {
    private static final String TAG = "BubbleExpandedView";
    private static final String TAG = "BubbleExpandedView";
@@ -82,6 +82,7 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList


    // Permission view
    // Permission view
    private View mPermissionView;
    private View mPermissionView;
    private TextView mPermissionPrompt;


    // Views for expanded state
    // Views for expanded state
    private ExpandableNotificationRow mNotifRow;
    private ExpandableNotificationRow mNotifRow;
@@ -94,9 +95,13 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
    private boolean mNeedsNewHeight;
    private boolean mNeedsNewHeight;


    private int mMinHeight;
    private int mMinHeight;
    private int mHeaderHeight;
    private int mSettingsIconHeight;
    private int mBubbleHeight;
    private int mBubbleHeight;
    private int mPermissionHeight;
    private int mPermissionHeight;
    private int mIconInset;
    private Drawable mSettingsIconDrawable;
    private int mPointerWidth;
    private int mPointerHeight;


    private NotificationEntry mEntry;
    private NotificationEntry mEntry;
    private PackageManager mPm;
    private PackageManager mPm;
@@ -173,20 +178,21 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList


        Resources res = getResources();
        Resources res = getResources();
        mPointerView = findViewById(R.id.pointer_view);
        mPointerView = findViewById(R.id.pointer_view);
        int width = res.getDimensionPixelSize(R.dimen.bubble_pointer_width);
        mPointerWidth = res.getDimensionPixelSize(R.dimen.bubble_pointer_width);
        int height = res.getDimensionPixelSize(R.dimen.bubble_pointer_height);
        mPointerHeight = res.getDimensionPixelSize(R.dimen.bubble_pointer_height);


        TypedArray ta = getContext().obtainStyledAttributes(
        TypedArray ta = getContext().obtainStyledAttributes(
                new int[] {android.R.attr.colorBackgroundFloating});
                new int[] {android.R.attr.colorBackgroundFloating});
        int bgColor = ta.getColor(0, Color.WHITE);
        int bgColor = ta.getColor(0, Color.WHITE);
        ta.recycle();
        ta.recycle();


        ShapeDrawable triangleDrawable = new ShapeDrawable(
        ShapeDrawable triangleDrawable = new ShapeDrawable(TriangleShape.create(
                TriangleShape.create(width, height, false /* pointUp */));
                mPointerWidth, mPointerHeight, false /* pointUp */));

        triangleDrawable.setTint(bgColor);
        triangleDrawable.setTint(bgColor);
        mPointerView.setBackground(triangleDrawable);
        mPointerView.setBackground(triangleDrawable);


        FrameLayout viewWrapper = findViewById(R.id.header_permission_wrapper);
        FrameLayout permissionOrSettings = findViewById(R.id.permission_or_settings);


        LayoutTransition transition = new LayoutTransition();
        LayoutTransition transition = new LayoutTransition();
        transition.setDuration(200);
        transition.setDuration(200);
@@ -200,18 +206,21 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
        transition.setInterpolator(LayoutTransition.DISAPPEARING, Interpolators.ALPHA_OUT);
        transition.setInterpolator(LayoutTransition.DISAPPEARING, Interpolators.ALPHA_OUT);


        transition.setAnimateParentHierarchy(false);
        transition.setAnimateParentHierarchy(false);
        viewWrapper.setLayoutTransition(transition);
        permissionOrSettings.setLayoutTransition(transition);
        viewWrapper.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
        permissionOrSettings.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);


        mHeaderHeight = getContext().getResources().getDimensionPixelSize(
        mSettingsIconHeight = getContext().getResources().getDimensionPixelSize(
                R.dimen.bubble_expanded_header_height);
                R.dimen.bubble_expanded_header_height);
        mSettingsIcon = findViewById(R.id.settings_button);
        mIconInset = getResources().getDimensionPixelSize(R.dimen.bubble_icon_inset);
        mSettingsIcon.setOnClickListener(this);
        // Save initial drawable to create adaptive icons that will take its place.
        mSettingsIconDrawable = mSettingsIcon.getDrawable();

        mPermissionHeight = getContext().getResources().getDimensionPixelSize(
        mPermissionHeight = getContext().getResources().getDimensionPixelSize(
                R.dimen.bubble_permission_height);
                R.dimen.bubble_permission_height);

        mPermissionView = findViewById(R.id.permission_layout);
        mPermissionView = findViewById(R.id.permission_layout);
        mSettingsIcon = findViewById(R.id.settings_button);
        mPermissionPrompt = mPermissionView.findViewById(R.id.prompt);
        mSettingsIcon.setOnClickListener(this);
        updateHeaderColor();


        findViewById(R.id.no_bubbles_button).setOnClickListener(this);
        findViewById(R.id.no_bubbles_button).setOnClickListener(this);
        findViewById(R.id.yes_bubbles_button).setOnClickListener(this);
        findViewById(R.id.yes_bubbles_button).setOnClickListener(this);
@@ -264,7 +273,7 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
    /**
    /**
     * Creates a background with corners rounded based on how the view is configured to display
     * Creates a background with corners rounded based on how the view is configured to display
     */
     */
    private Drawable createHeaderPermissionBackground(int bgColor) {
    private Drawable createPermissionBackground(int bgColor) {
        TypedArray ta2 = getContext().obtainStyledAttributes(
        TypedArray ta2 = getContext().obtainStyledAttributes(
                new int[] {android.R.attr.dialogCornerRadius});
                new int[] {android.R.attr.dialogCornerRadius});
        final float cr = ta2.getDimension(0, 0f);
        final float cr = ta2.getDimension(0, 0f);
@@ -311,8 +320,8 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
        if (mAppIcon == null) {
        if (mAppIcon == null) {
            mAppIcon = mPm.getDefaultActivityIcon();
            mAppIcon = mPm.getDefaultActivityIcon();
        }
        }
        updateHeaderView();
        updateTheme();
        updatePermissionView();
        togglePermissionOrSettings();
        updateExpandedView();
        updateExpandedView();
    }
    }


@@ -338,12 +347,12 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList


    /**
    /**
     * Updates the entry backing this view. This will not re-populate ActivityView, it will
     * Updates the entry backing this view. This will not re-populate ActivityView, it will
     * only update the deep-links in the header, the title, and the height of the view.
     * only update the deep-links in the title, and the height of the view.
     */
     */
    public void update(NotificationEntry entry) {
    public void update(NotificationEntry entry) {
        if (entry.key.equals(mEntry.key)) {
        if (entry.key.equals(mEntry.key)) {
            mEntry = entry;
            mEntry = entry;
            updateHeaderView();
            updateSettingsContentDescription();
            updateHeight();
            updateHeight();
        } else {
        } else {
            Log.w(TAG, "Trying to update entry with different key, new entry: "
            Log.w(TAG, "Trying to update entry with different key, new entry: "
@@ -351,35 +360,36 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
        }
        }
    }
    }


    /**
    void updateTheme() {
     * Update header color and icon shape when theme changes.
        // Get new colors.
     */
    void updateHeaderColor() {
        TypedArray ta = mContext.obtainStyledAttributes(
        TypedArray ta = mContext.obtainStyledAttributes(
                new int[]{android.R.attr.colorBackgroundFloating, android.R.attr.colorForeground});
                new int[]{android.R.attr.colorBackgroundFloating, android.R.attr.colorForeground});
        int backgroundColor = ta.getColor(0, Color.WHITE /* default */);
        int backgroundColor = ta.getColor(0, Color.WHITE /* default */);
        int foregroundColor = ta.getColor(1, Color.BLACK /* default */);
        int foregroundColor = ta.getColor(1, Color.BLACK /* default */);
        ta.recycle();
        ta.recycle();


        mPermissionView.setBackground(createHeaderPermissionBackground(backgroundColor));
        // Must clear tint first - otherwise tint updates inconsistently.

        mSettingsIconDrawable.setTintList(null);
        Drawable settingsIcon =  mSettingsIcon.getDrawable();
        mSettingsIconDrawable.setTint(foregroundColor);
        settingsIcon.setTint(foregroundColor);


        int mIconInset = getResources().getDimensionPixelSize(R.dimen.bubble_icon_inset);
        InsetDrawable foreground = new InsetDrawable(mSettingsIconDrawable, mIconInset);
        InsetDrawable foreground = new InsetDrawable(settingsIcon, mIconInset);
        ColorDrawable background = new ColorDrawable(backgroundColor);
        ColorDrawable background = new ColorDrawable(backgroundColor);
        AdaptiveIconDrawable adaptiveIcon = new AdaptiveIconDrawable(background,
        AdaptiveIconDrawable adaptiveIcon = new AdaptiveIconDrawable(background,
                foreground);
                foreground);
        mSettingsIcon.setImageDrawable(adaptiveIcon);
        mSettingsIcon.setImageDrawable(adaptiveIcon);
    }


    private void updateHeaderView() {
        // Update permission prompt color.
        mSettingsIcon.setContentDescription(getResources().getString(
        mPermissionView.setBackground(createPermissionBackground(backgroundColor));
                R.string.bubbles_settings_button_description, mAppName));
        mPermissionPrompt.setTextColor(foregroundColor);

        // Update triangle color.
        ShapeDrawable triangleDrawable = new ShapeDrawable(
                TriangleShape.create(mPointerWidth, mPointerHeight, false /* pointUp */));
        triangleDrawable.setTint(backgroundColor);
        mPointerView.setBackground(triangleDrawable);
    }
    }


    private void updatePermissionView() {
    void togglePermissionOrSettings() {
        boolean hasUserApprovedBubblesForPackage = false;
        boolean hasUserApprovedBubblesForPackage = false;
        try {
        try {
            hasUserApprovedBubblesForPackage =
            hasUserApprovedBubblesForPackage =
@@ -392,12 +402,6 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
            showSettingsIcon();
            showSettingsIcon();
        } else {
        } else {
            showPermissionView();
            showPermissionView();
            ((ImageView) mPermissionView.findViewById(R.id.pkgicon)).setImageDrawable(mAppIcon);
            ((TextView) mPermissionView.findViewById(R.id.pkgname)).setText(mAppName);
            ((TextView) mPermissionView.findViewById(R.id.prompt)).setText(
                    getResources().getString(R.string.bubbles_prompt, mAppName));
            logBubbleClickEvent(mEntry,
                    StatsLog.BUBBLE_UICHANGED__ACTION__PERMISSION_DIALOG_SHOWN);
        }
        }
    }
    }


@@ -432,7 +436,7 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
     */
     */
    int getExpandedSize() {
    int getExpandedSize() {
        int chromeHeight = mPermissionView.getVisibility() != View.VISIBLE
        int chromeHeight = mPermissionView.getVisibility() != View.VISIBLE
                ? mHeaderHeight
                ? mSettingsIconHeight
                : mPermissionHeight;
                : mPermissionHeight;
        return mBubbleHeight + mPointerView.getHeight() + mPointerMargin
        return mBubbleHeight + mPointerView.getHeight() + mPointerMargin
                + chromeHeight;
                + chromeHeight;
@@ -460,7 +464,7 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
                desiredHeight = desiredPx > 0 ? desiredPx : mMinHeight;
                desiredHeight = desiredPx > 0 ? desiredPx : mMinHeight;
            }
            }
            int chromeHeight = mPermissionView.getVisibility() != View.VISIBLE
            int chromeHeight = mPermissionView.getVisibility() != View.VISIBLE
                    ? mHeaderHeight
                    ? mSettingsIconHeight
                    : mPermissionHeight;
                    : mPermissionHeight;
            int max = mStackView.getMaxExpandedHeight() - chromeHeight - mPointerView.getHeight()
            int max = mStackView.getMaxExpandedHeight() - chromeHeight - mPointerView.getHeight()
                    - mPointerMargin;
                    - mPointerMargin;
@@ -523,15 +527,28 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
        }
        }
    }
    }


    private void updateSettingsContentDescription() {
        mSettingsIcon.setContentDescription(getResources().getString(
                R.string.bubbles_settings_button_description, mAppName));
    }

    void showSettingsIcon() {
    void showSettingsIcon() {
        updateSettingsContentDescription();

        mPermissionView.setVisibility(GONE);
        mPermissionView.setVisibility(GONE);
        mSettingsIcon.setVisibility(VISIBLE);
        mSettingsIcon.setVisibility(VISIBLE);
    }
    }


    void showPermissionView() {
    void showPermissionView() {
        ((ImageView) mPermissionView.findViewById(R.id.pkgicon)).setImageDrawable(mAppIcon);
        ((TextView) mPermissionView.findViewById(R.id.pkgname)).setText(mAppName);
        mPermissionPrompt.setText(
                getResources().getString(R.string.bubbles_prompt, mAppName));
        logBubbleClickEvent(mEntry,
                StatsLog.BUBBLE_UICHANGED__ACTION__PERMISSION_DIALOG_SHOWN);

        mSettingsIcon.setVisibility(GONE);
        mSettingsIcon.setVisibility(GONE);
        mPermissionView.setVisibility(VISIBLE);
        mPermissionView.setVisibility(VISIBLE);

    }
    }


    /**
    /**
+3 −3
Original line number Original line Diff line number Diff line
@@ -309,12 +309,12 @@ public class BubbleStackView extends FrameLayout {
    }
    }


    /**
    /**
     * Handle config changes.
     * Handle theme changes.
     */
     */
    public void onConfigChanged() {
    public void onThemeChanged() {
        for (Bubble b: mBubbleData.getBubbles()) {
        for (Bubble b: mBubbleData.getBubbles()) {
            b.iconView.updateViews();
            b.iconView.updateViews();
            b.expandedView.updateHeaderColor();
            b.expandedView.updateTheme();
        }
        }
    }
    }