Skip to content

Commit

Permalink
SystemUI: clear all icon customization code improvements [1/2]
Browse files Browse the repository at this point in the history
SDB:
   1. fixed the bloody annoying log of "requestlayout()" spam
   2. fixed the colors not taking affect without systemui restart
   3. some code clean-ups as required

Signed-off-by: SuperDroidBond <superdroidbond@yahoo.com>
  • Loading branch information
SuperDroidBond committed Oct 13, 2021
1 parent cbb2ec6 commit 7c2986e
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 85 deletions.
Expand Up @@ -185,17 +185,7 @@
*/
public class NotificationStackScrollLayout extends ViewGroup implements ScrollAdapter,
NotificationListContainer, ConfigurationListener, Dumpable,
DynamicPrivacyController.Listener,TunerService.Tunable {

private static final String NOTIF_DISMISALL_COLOR_MODE =
"system:" + Settings.System.NOTIF_DISMISALL_COLOR_MODE;
private static final String NOTIF_DISMISALL_ICON_COLOR_MODE =
"system:" + Settings.System.NOTIF_DISMISALL_ICON_COLOR_MODE;
private static final String NOTIF_CLEAR_ALL_ICON_COLOR =
"system:" + Settings.System.NOTIF_CLEAR_ALL_ICON_COLOR;
private static final String NOTIF_CLEAR_ALL_BG_COLOR =
"system:" + Settings.System.NOTIF_CLEAR_ALL_BG_COLOR;
private int mMode, mNotifIconColor, mNotifBgColor, mIconMode;
DynamicPrivacyController.Listener {

public static final float BACKGROUND_ALPHA_DIMMED = 0.7f;
private static final String TAG = "StackScroller";
Expand Down Expand Up @@ -694,11 +684,6 @@ public NotificationStackScrollLayout(
}, HIGH_PRIORITY, Settings.Secure.NOTIFICATION_DISMISS_RTL,
Settings.Secure.NOTIFICATION_HISTORY_ENABLED);

tunerService.addTunable(this, NOTIF_DISMISALL_COLOR_MODE);
tunerService.addTunable(this, NOTIF_DISMISALL_ICON_COLOR_MODE);
tunerService.addTunable(this, NOTIF_CLEAR_ALL_BG_COLOR);
tunerService.addTunable(this, NOTIF_CLEAR_ALL_ICON_COLOR);

mFeatureFlags = featureFlags;
mNotifPipeline = notifPipeline;
mEntryManager = entryManager;
Expand Down Expand Up @@ -795,10 +780,11 @@ private void reinflateViews() {
inflateFooterView();
inflateEmptyShadeView();
updateFooter();
mIconColor = mContext.getColor(R.color.dismiss_all_icon_color);
mSectionsManager.reinflateViews(LayoutInflater.from(mContext));
checkColor();
mBgColor = mContext.getColor(R.color.dismiss_all_background_color);
mIconColor = mContext.getColor(R.color.dismiss_all_icon_color);
mStatusBar.updateDismissAllButton(mIconColor, mBgColor);
mStatusBar.updateDismissAllButton();
}

@Override
Expand Down Expand Up @@ -836,44 +822,6 @@ public void updateFooter() {
updateFooterView(showFooterView, showDismissView, showHistory);
}

public void checkColor() {
if (mMode == 0) {
mBgColor = mContext.getColor(R.color.dismiss_all_background_color);
} else if (mMode == 1) {
mBgColor = mContext.getColor(R.color.accent_device_default_light);
} else if (mMode == 2) {
mBgColor = mNotifBgColor;
}

if (mIconMode == 0) {
mIconColor = mContext.getColor(R.color.dismiss_all_icon_color);
} else if (mIconMode == 1) {
mIconColor = mContext.getColor(R.color.accent_device_default_light);
} else if (mIconMode == 2) {
mIconColor = mNotifIconColor;
}
}

@Override
public void onTuningChanged(String key, String newValue) {
if (NOTIF_DISMISALL_COLOR_MODE.equals(key)) {
mMode =
TunerService.parseInteger(newValue, 0);
} else if (NOTIF_DISMISALL_ICON_COLOR_MODE.equals(key)) {
mIconMode =
TunerService.parseInteger(newValue, 0);
} else if (NOTIF_CLEAR_ALL_ICON_COLOR.equals(key)) {
int color = mContext.getColor(R.color.dismiss_all_icon_color);
mNotifIconColor =
TunerService.parseInteger(newValue, color);
} else if (NOTIF_CLEAR_ALL_BG_COLOR.equals(key)) {
int color = mContext.getColor(R.color.dismiss_all_background_color);
mNotifBgColor =
TunerService.parseInteger(newValue, color);
}
checkColor();
}

/**
* Return whether there are any clearable notifications
*/
Expand Down Expand Up @@ -964,11 +912,10 @@ public NotificationSwipeActionHelper getSwipeActionHelper() {
@Override
@ShadeViewRefactor(RefactorComponent.SHADE_VIEW)
public void onUiModeChanged() {
mBgColor = mContext.getColor(R.color.notification_shade_background_color);
mBgColor = mContext.getColor(R.color.dismiss_all_background_color);
mIconColor = mContext.getColor(R.color.dismiss_all_icon_color);
updateBackgroundDimming();
mShelf.onUiModeChanged();
checkColor();
mStatusBar.updateDismissAllButton(mIconColor, mBgColor);
}

Expand Down
Expand Up @@ -2307,8 +2307,7 @@ public void updateNotificationTranslucency() {
}
mNotificationStackScroller.setAlpha(alpha);
mStatusBar.updateDismissAllVisibility(true);
mStatusBar.dismissAllButtonStyle();
mStatusBar.updateDismissAllButtonColors();
mStatusBar.updateDismissAllButton();
mStatusBar.getPulseController().setQSShowing(mBarState != StatusBarState.KEYGUARD && !isFullyCollapsed());
}

Expand Down
Expand Up @@ -455,7 +455,6 @@ public class StatusBar extends SystemUI implements DemoMode,
private final UserInfoControllerImpl mUserInfoControllerImpl;
private final DismissCallbackRegistry mDismissCallbackRegistry;
private NotificationsController mNotificationsController;
private NotificationStackScrollLayout mNotificationStackScrollLayout;

// viewgroup containing the normal contents of the statusbar
LinearLayout mStatusBarContent;
Expand Down Expand Up @@ -553,6 +552,7 @@ public class StatusBar extends SystemUI implements DemoMode,
public boolean mClearableNotifications = true;
public float mQsExpansionFraction = 0f;
private int mDismissAllStyle;
private int mBgColor, mIconColor, mMode, mNotifIconColor, mNotifBgColor, mIconMode;

Runnable mLongPressBrightnessChange = new Runnable() {
@Override
Expand Down Expand Up @@ -1618,36 +1618,23 @@ public void updateDismissAllVisibility(boolean visible) {
mDismissAllButton.getBackground().setAlpha(0);
mDismissAllButton.setVisibility(View.INVISIBLE);
}
}

FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mDismissAllButton.getLayoutParams();
switch (getDismissAllButtonGravity()) {
case 0:
lp.gravity = Gravity.LEFT|Gravity.BOTTOM;
break;
case 1:
lp.gravity = Gravity.CENTER_HORIZONTAL|Gravity.BOTTOM;
break;
case 2:
lp.gravity = Gravity.RIGHT|Gravity.BOTTOM;
break;
}
mDismissAllButton.setLayoutParams(lp);
updateDismissAllButtonColors();
public void updateDismissAllButton() {
dismissAllButtonStyle();
dismissAllButtonGravity();
updateDismissAllButtonColors();
updateDismissAllButton(mIconColor, mBgColor);
}

public void updateDismissAllButton(int iconcolor, int bgcolor) {
iconcolor = mIconColor;
bgcolor = mBgColor;
if (mDismissAllButton != null) {
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) mDismissAllButton.getLayoutParams();
layoutParams.width = mContext.getResources().getDimensionPixelSize(R.dimen.dismiss_all_button_width);
layoutParams.height = mContext.getResources().getDimensionPixelSize(R.dimen.dismiss_all_button_height);
layoutParams.bottomMargin = mContext.getResources().getDimensionPixelSize(R.dimen.dismiss_all_button_margin_bottom);
mDismissAllButton.setElevation(mContext.getResources().getDimension(R.dimen.dismiss_all_button_elevation));
Drawable d = mContext.getResources().getDrawable(R.drawable.dismiss_all_background);
updateDismissAllButtonColors();
d.setTint(bgcolor);
mDismissAllButton.setBackground(d);
mDismissAllButton.setColorFilter(iconcolor);
d.setTint(mBgColor);
mDismissAllButton.setColorFilter(mIconColor);
}
}

Expand Down Expand Up @@ -2787,6 +2774,8 @@ public void dismissAllButtonStyle() {

mDismissAllStyle = Settings.System.getIntForUser(mContext.getContentResolver(),
Settings.System.NOTIF_DISMISSALL_STYLE, 0, UserHandle.USER_CURRENT);

if (mDismissAllButton != null) {
switch(mDismissAllStyle) {
case 1:
d = mContext.getDrawable(R.drawable.ic_dismiss_all);
Expand Down Expand Up @@ -2870,14 +2859,75 @@ public void dismissAllButtonStyle() {
default: // Default
d = mContext.getDrawable(R.drawable.dismiss_all_icon);
break;
}
}
mDismissAllButton.setImageDrawable(null);
mDismissAllButton.setImageDrawable(d);
}

public void updateDismissAllButtonColors() {
if (mNotificationStackScrollLayout != null) {
mNotificationStackScrollLayout.checkColor();
if (mContext == null) {
return;
}

int bgColor = mContext.getColor(R.color.dismiss_all_background_color);
int iconColor = mContext.getColor(R.color.dismiss_all_icon_color);

mMode = Settings.System.getIntForUser(mContext.getContentResolver(),
Settings.System.NOTIF_DISMISALL_COLOR_MODE, 0, UserHandle.USER_CURRENT);

mIconMode = Settings.System.getIntForUser(mContext.getContentResolver(),
Settings.System.NOTIF_DISMISALL_ICON_COLOR_MODE, 0, UserHandle.USER_CURRENT);

mNotifIconColor = Settings.System.getIntForUser(mContext.getContentResolver(),
Settings.System.NOTIF_CLEAR_ALL_ICON_COLOR, iconColor, UserHandle.USER_CURRENT);

mNotifBgColor = Settings.System.getIntForUser(mContext.getContentResolver(),
Settings.System.NOTIF_CLEAR_ALL_BG_COLOR, bgColor, UserHandle.USER_CURRENT);

if (mDismissAllButton != null) {
switch (mMode) {
default:
case 0:
mBgColor = mContext.getColor(R.color.dismiss_all_background_color);
break;
case 1:
mBgColor = mContext.getColor(R.color.accent_device_default_light);
break;
case 2:
mBgColor = mNotifBgColor;
break;
}
switch (mIconMode) {
default:
case 0:
mIconColor = mContext.getColor(R.color.dismiss_all_icon_color);
break;
case 1:
mIconColor = mContext.getColor(R.color.accent_device_default_light);
break;
case 2:
mIconColor = mNotifIconColor;
break;
}
}
}

public void dismissAllButtonGravity() {
if (mDismissAllButton != null) {
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) mDismissAllButton.getLayoutParams();
switch (getDismissAllButtonGravity()) {
case 0:
layoutParams.gravity = Gravity.LEFT|Gravity.BOTTOM;
break;
case 1:
layoutParams.gravity = Gravity.CENTER_HORIZONTAL|Gravity.BOTTOM;
break;
case 2:
layoutParams.gravity = Gravity.RIGHT|Gravity.BOTTOM;
break;
}
mDismissAllButton.setLayoutParams(layoutParams);
}
}

Expand Down

0 comments on commit 7c2986e

Please sign in to comment.