Skip to content

Commit

Permalink
Update color for permission, settings, pointer
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Lyn Han committed Apr 6, 2019
1 parent 2b67a2b commit 02cca81
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 50 deletions.
2 changes: 1 addition & 1 deletion packages/SystemUI/res/layout/bubble_expanded_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
/>

<FrameLayout
android:id="@+id/header_permission_wrapper"
android:id="@+id/permission_or_settings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,14 @@ public BubbleController(Context context, StatusBarWindowController statusBarWind
@Override
public void onUiModeChanged() {
if (mStackView != null) {
mStackView.onConfigChanged();
mStackView.onThemeChanged();
}
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
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 {
private static final String TAG = "BubbleExpandedView";
Expand All @@ -82,6 +82,7 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList

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

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

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

private NotificationEntry mEntry;
private PackageManager mPm;
Expand Down Expand Up @@ -173,20 +178,21 @@ protected void onFinishInflate() {

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

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

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

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

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

LayoutTransition transition = new LayoutTransition();
transition.setDuration(200);
Expand All @@ -200,18 +206,21 @@ protected void onFinishInflate() {
transition.setInterpolator(LayoutTransition.DISAPPEARING, Interpolators.ALPHA_OUT);

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

mHeaderHeight = getContext().getResources().getDimensionPixelSize(
mSettingsIconHeight = getContext().getResources().getDimensionPixelSize(
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(
R.dimen.bubble_permission_height);

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

findViewById(R.id.no_bubbles_button).setOnClickListener(this);
findViewById(R.id.yes_bubbles_button).setOnClickListener(this);
Expand Down Expand Up @@ -264,7 +273,7 @@ void updateInsets(WindowInsets insets) {
/**
* 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(
new int[] {android.R.attr.dialogCornerRadius});
final float cr = ta2.getDimension(0, 0f);
Expand Down Expand Up @@ -311,8 +320,8 @@ public void setEntry(NotificationEntry entry, BubbleStackView stackView) {
if (mAppIcon == null) {
mAppIcon = mPm.getDefaultActivityIcon();
}
updateHeaderView();
updatePermissionView();
updateTheme();
togglePermissionOrSettings();
updateExpandedView();
}

Expand All @@ -338,48 +347,49 @@ public void populateExpandedView() {

/**
* 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) {
if (entry.key.equals(mEntry.key)) {
mEntry = entry;
updateHeaderView();
updateSettingsContentDescription();
updateHeight();
} else {
Log.w(TAG, "Trying to update entry with different key, new entry: "
+ entry.key + " old entry: " + mEntry.key);
}
}

/**
* Update header color and icon shape when theme changes.
*/
void updateHeaderColor() {
void updateTheme() {
// Get new colors.
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 foregroundColor = ta.getColor(1, Color.BLACK /* default */);
ta.recycle();

mPermissionView.setBackground(createHeaderPermissionBackground(backgroundColor));
// Must clear tint first - otherwise tint updates inconsistently.
mSettingsIconDrawable.setTintList(null);
mSettingsIconDrawable.setTint(foregroundColor);

Drawable settingsIcon = mSettingsIcon.getDrawable();
settingsIcon.setTint(foregroundColor);

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

private void updateHeaderView() {
mSettingsIcon.setContentDescription(getResources().getString(
R.string.bubbles_settings_button_description, mAppName));
// Update permission prompt color.
mPermissionView.setBackground(createPermissionBackground(backgroundColor));
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;
try {
hasUserApprovedBubblesForPackage =
Expand All @@ -392,12 +402,6 @@ private void updatePermissionView() {
showSettingsIcon();
} else {
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);
}
}

Expand Down Expand Up @@ -432,7 +436,7 @@ boolean performBackPressIfNeeded() {
*/
int getExpandedSize() {
int chromeHeight = mPermissionView.getVisibility() != View.VISIBLE
? mHeaderHeight
? mSettingsIconHeight
: mPermissionHeight;
return mBubbleHeight + mPointerView.getHeight() + mPointerMargin
+ chromeHeight;
Expand Down Expand Up @@ -460,7 +464,7 @@ void updateHeight() {
desiredHeight = desiredPx > 0 ? desiredPx : mMinHeight;
}
int chromeHeight = mPermissionView.getVisibility() != View.VISIBLE
? mHeaderHeight
? mSettingsIconHeight
: mPermissionHeight;
int max = mStackView.getMaxExpandedHeight() - chromeHeight - mPointerView.getHeight()
- mPointerMargin;
Expand Down Expand Up @@ -523,15 +527,28 @@ private void setBubblesAllowed(boolean allowed) {
}
}

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

void showSettingsIcon() {
updateSettingsContentDescription();

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

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);
mPermissionView.setVisibility(VISIBLE);

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,12 @@ public BubbleStackView(Context context, BubbleData data,
}

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

Expand Down

0 comments on commit 02cca81

Please sign in to comment.