Skip to content

Commit

Permalink
StatusBarIconView: use app icons instead of provided notif one
Browse files Browse the repository at this point in the history
Change-Id: I931f60e0e6941c1d5786b54534f8f0469e4c0cc8
  • Loading branch information
Dil3mm4 authored and Undying-yueyue committed Feb 27, 2022
1 parent 164ef2b commit 718c21b
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.provider.Settings;
import android.app.Notification;
import android.content.Context;
import android.content.pm.ApplicationInfo;
Expand Down Expand Up @@ -123,6 +124,7 @@ public Float get(StatusBarIconView object) {
};

private boolean mAlwaysScaleIcon;
private static boolean mIsSystemUI;
private int mStatusBarIconDrawingSizeIncreased = 1;
private int mStatusBarIconDrawingSize = 1;
private int mStatusBarIconSize = 1;
Expand Down Expand Up @@ -439,7 +441,15 @@ public static Drawable getIcon(Context sysuiContext,
userId = UserHandle.USER_SYSTEM;
}

Drawable icon = statusBarIcon.icon.loadDrawableAsUser(context, userId);
Drawable icon;
String pkgName = statusBarIcon.pkg;
mIsSystemUI = pkgName.contains("systemui");
try {
icon = mIsSystemUI ? statusBarIcon.icon.loadDrawableAsUser(context, userId)
: context.getPackageManager().getApplicationIcon(pkgName);
} catch (android.content.pm.PackageManager.NameNotFoundException e) {
icon = statusBarIcon.icon.loadDrawableAsUser(context, userId);
}

TypedValue typedValue = new TypedValue();
sysuiContext.getResources().getValue(R.dimen.status_bar_icon_scale_factor,
Expand Down Expand Up @@ -612,9 +622,11 @@ public void setDecorColor(int iconTint) {

private void initializeDecorColor() {
if (mNotification != null) {
setDecorColor(getContext().getColor(mNightMode
? com.android.internal.R.color.notification_default_color_dark
: com.android.internal.R.color.notification_default_color_light));
if (mNotification.getPackageName().contains("systemui")) {
setDecorColor(getContext().getColor(mNightMode
? com.android.internal.R.color.notification_default_color_dark
: com.android.internal.R.color.notification_default_color_light));
}
}
}

Expand All @@ -634,16 +646,22 @@ private void updateDecorColor() {
* transitioning this also immediately sets the color.
*/
public void setStaticDrawableColor(int color) {
mDrawableColor = color;
setColorInternal(color);
updateContrastedStaticColor();
mIconColor = color;
mDozer.setColor(color);
if (mNotification == null) return;
if (mNotification.getPackageName().contains("systemui")) { //if (mIsSystemUI) {
mDrawableColor = color;
setColorInternal(color);
updateContrastedStaticColor();
mIconColor = color;
mDozer.setColor(color);
}
}

private void setColorInternal(int color) {
mCurrentSetColor = color;
updateIconColor();
if (mNotification == null) return;
if (mNotification.getPackageName().contains("systemui")) { //if (mIsSystemUI) {
mCurrentSetColor = color;
updateIconColor();
}
}

private void updateIconColor() {
Expand All @@ -652,19 +670,22 @@ private void updateIconColor() {
return;
}

if (mCurrentSetColor != NO_COLOR) {
if (mMatrixColorFilter == null) {
mMatrix = new float[4 * 5];
mMatrixColorFilter = new ColorMatrixColorFilter(mMatrix);
if (mNotification == null) return;
if (mNotification.getPackageName().contains("systemui")) { //if (mIsSystemUI) {
if (mCurrentSetColor != NO_COLOR) {
if (mMatrixColorFilter == null) {
mMatrix = new float[4 * 5];
mMatrixColorFilter = new ColorMatrixColorFilter(mMatrix);
}
int color = NotificationUtils.interpolateColors(
mCurrentSetColor, Color.WHITE, mDozeAmount);
updateTintMatrix(mMatrix, color, DARK_ALPHA_BOOST * mDozeAmount);
mMatrixColorFilter.setColorMatrixArray(mMatrix);
setColorFilter(null); // setColorFilter only invalidates if the instance changed.
setColorFilter(mMatrixColorFilter);
} else {
mDozer.updateGrayscale(this, mDozeAmount);
}
int color = NotificationUtils.interpolateColors(
mCurrentSetColor, Color.WHITE, mDozeAmount);
updateTintMatrix(mMatrix, color, DARK_ALPHA_BOOST * mDozeAmount);
mMatrixColorFilter.setColorMatrixArray(mMatrix);
setColorFilter(null); // setColorFilter only invalidates if the instance changed.
setColorFilter(mMatrixColorFilter);
} else {
mDozer.updateGrayscale(this, mDozeAmount);
}
}

Expand All @@ -681,36 +702,40 @@ private static void updateTintMatrix(float[] array, int color, float alphaBoost)
}

public void setIconColor(int iconColor, boolean animate) {
if (mIconColor != iconColor) {
mIconColor = iconColor;
if (mColorAnimator != null) {
mColorAnimator.cancel();
}
if (mCurrentSetColor == iconColor) {
return;
}
if (animate && mCurrentSetColor != NO_COLOR) {
mAnimationStartColor = mCurrentSetColor;
mColorAnimator = ValueAnimator.ofFloat(0.0f, 1.0f);
mColorAnimator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN);
mColorAnimator.setDuration(ANIMATION_DURATION_FAST);
mColorAnimator.addUpdateListener(mColorUpdater);
mColorAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
mColorAnimator = null;
mAnimationStartColor = NO_COLOR;
}
});
mColorAnimator.start();
} else {
setColorInternal(iconColor);
if (mNotification == null) return;
if (mNotification.getPackageName().contains("systemui")) { //if (mIsSystemUI) {
if (mIconColor != iconColor) {
mIconColor = iconColor;
if (mColorAnimator != null) {
mColorAnimator.cancel();
}
if (mCurrentSetColor == iconColor) {
return;
}
if (animate && mCurrentSetColor != NO_COLOR) {
mAnimationStartColor = mCurrentSetColor;
mColorAnimator = ValueAnimator.ofFloat(0.0f, 1.0f);
mColorAnimator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN);
mColorAnimator.setDuration(ANIMATION_DURATION_FAST);
mColorAnimator.addUpdateListener(mColorUpdater);
mColorAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
mColorAnimator = null;
mAnimationStartColor = NO_COLOR;
}
});
mColorAnimator.start();
} else {
setColorInternal(iconColor);
}
}
}
}

public int getStaticDrawableColor() {
return mDrawableColor;
if (mNotification == null) return mDrawableColor;
return mNotification.getPackageName().contains("systemui") /*mIsSystemUI*/ ? mDrawableColor : 0;
}

/**
Expand All @@ -729,26 +754,29 @@ int getContrastedStaticDrawableColor(int backgroundColor) {
}

private void updateContrastedStaticColor() {
if (Color.alpha(mCachedContrastBackgroundColor) != 255) {
mContrastedDrawableColor = mDrawableColor;
return;
}
// We'll modify the color if it doesn't pass GAR
int contrastedColor = mDrawableColor;
if (!ContrastColorUtil.satisfiesTextContrast(mCachedContrastBackgroundColor,
contrastedColor)) {
float[] hsl = new float[3];
ColorUtils.colorToHSL(mDrawableColor, hsl);
// This is basically a light grey, pushing the color will only distort it.
// Best thing to do in here is to fallback to the default color.
if (hsl[1] < 0.2f) {
contrastedColor = Notification.COLOR_DEFAULT;
if (mNotification == null) return;
if (mNotification.getPackageName().contains("systemui")) { //if (mIsSystemUI) {
if (Color.alpha(mCachedContrastBackgroundColor) != 255) {
mContrastedDrawableColor = mDrawableColor;
return;
}
// We'll modify the color if it doesn't pass GAR
int contrastedColor = mDrawableColor;
if (!ContrastColorUtil.satisfiesTextContrast(mCachedContrastBackgroundColor,
contrastedColor)) {
float[] hsl = new float[3];
ColorUtils.colorToHSL(mDrawableColor, hsl);
// This is basically a light grey, pushing the color will only distort it.
// Best thing to do in here is to fallback to the default color.
if (hsl[1] < 0.2f) {
contrastedColor = Notification.COLOR_DEFAULT;
}
boolean isDark = !ContrastColorUtil.isColorLight(mCachedContrastBackgroundColor);
contrastedColor = ContrastColorUtil.resolveContrastColor(mContext,
contrastedColor, mCachedContrastBackgroundColor, isDark);
}
boolean isDark = !ContrastColorUtil.isColorLight(mCachedContrastBackgroundColor);
contrastedColor = ContrastColorUtil.resolveContrastColor(mContext,
contrastedColor, mCachedContrastBackgroundColor, isDark);
mContrastedDrawableColor = contrastedColor;
}
mContrastedDrawableColor = contrastedColor;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,12 @@ private void updateTintForIcon(StatusBarIconView v, int tint) {
if (colorize) {
color = DarkIconDispatcher.getTint(mTintArea, v, tint);
}
v.setStaticDrawableColor(color);
v.setDecorColor(tint);
if (v.getStatusBarIcon().pkg.contains("systemui")) {
v.setStaticDrawableColor(color);
v.setDecorColor(tint);
} else {
return;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,7 @@ && indexOfChild(view) > mCannedAnimationStartIndex
}
}
icon.setVisibleState(visibleState, animationsAllowed);
if (icon.getStatusBarIcon().pkg.contains("systemui"))
icon.setIconColor(mInNotificationIconShelf ? mThemedTextColorPrimary : iconColor,
needsCannedAnimation && animationsAllowed);
if (animate) {
Expand All @@ -810,7 +811,11 @@ && indexOfChild(view) > mCannedAnimationStartIndex
public void initFrom(View view) {
super.initFrom(view);
if (view instanceof StatusBarIconView) {
iconColor = ((StatusBarIconView) view).getStaticDrawableColor();
StatusBarIconView icon = (StatusBarIconView) view;
if (icon.getStatusBarIcon().pkg.contains("systemui"))
iconColor = ((StatusBarIconView) view).getStaticDrawableColor();
else
return;
}
}
}
Expand Down

0 comments on commit 718c21b

Please sign in to comment.