diff options
author | Jorim Jaggi <jjaggi@google.com> | 2015-02-04 11:46:55 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-02-04 11:46:56 +0000 |
commit | 3bef2929fa45fb10b9238d83970ae4d2a54f9274 (patch) | |
tree | 36e873de7c32051a8d2b4f1bb7d2a5d586fdbd9f /packages/SystemUI | |
parent | 406e1ed9883010928cfb42246cfd2710ebf3da74 (diff) | |
parent | dd0107a0dbe3084af8f5da005a4d96f8657f58a1 (diff) | |
download | frameworks_base-3bef2929fa45fb10b9238d83970ae4d2a54f9274.zip frameworks_base-3bef2929fa45fb10b9238d83970ae4d2a54f9274.tar.gz frameworks_base-3bef2929fa45fb10b9238d83970ae4d2a54f9274.tar.bz2 |
Merge "Add ability to colorize status bar"
Diffstat (limited to 'packages/SystemUI')
6 files changed, 128 insertions, 11 deletions
diff --git a/packages/SystemUI/res/values/colors.xml b/packages/SystemUI/res/values/colors.xml index a7783fc..5cb956f 100644 --- a/packages/SystemUI/res/values/colors.xml +++ b/packages/SystemUI/res/values/colors.xml @@ -30,7 +30,7 @@ <color name="notification_list_shadow_top">#80000000</color> <drawable name="recents_callout_line">#99ffffff</drawable> <drawable name="heads_up_notification_bg_pressed">#ff33B5E5</drawable> - <color name="batterymeter_frame_color">#66FFFFFF</color><!-- 40% white --> + <color name="batterymeter_frame_color">#4DFFFFFF</color><!-- 30% white --> <color name="batterymeter_charge_color">#FFFFFFFF</color> <color name="batterymeter_bolt_color">#FFFFFFFF</color> <color name="qs_batterymeter_frame_color">#FF404040</color> diff --git a/packages/SystemUI/res/values/ids.xml b/packages/SystemUI/res/values/ids.xml index 68dc269..aa53a3e 100644 --- a/packages/SystemUI/res/values/ids.xml +++ b/packages/SystemUI/res/values/ids.xml @@ -40,5 +40,11 @@ <item type="id" name="notification_power"/> <item type="id" name="notification_screenshot"/> <item type="id" name="notification_hidden"/> + + <!-- Whether the icon is from a notification for which targetSdk < L --> + <item type="id" name="icon_is_pre_L"/> + + <!-- For notification icons for which targetSdk < L, this caches whether the icon is grayscale --> + <item type="id" name="icon_is_grayscale" /> </resources> diff --git a/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java b/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java index 7bdbd0a..f2f087f 100755 --- a/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java +++ b/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java @@ -23,8 +23,12 @@ import android.content.IntentFilter; import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.ColorFilter; import android.graphics.Paint; import android.graphics.Path; +import android.graphics.PorterDuff; +import android.graphics.PorterDuffColorFilter; import android.graphics.RectF; import android.graphics.Typeface; import android.os.BatteryManager; @@ -56,12 +60,13 @@ public class BatteryMeterView extends View implements DemoMode, private float mSubpixelSmoothingRight; private final Paint mFramePaint, mBatteryPaint, mWarningTextPaint, mTextPaint, mBoltPaint; private float mTextHeight, mWarningTextHeight; + private int mIconTint = Color.WHITE; private int mHeight; private int mWidth; private String mWarningString; private final int mCriticalLevel; - private final int mChargeColor; + private int mChargeColor; private final float[] mBoltPoints; private final Path mBoltPath = new Path(); @@ -292,11 +297,27 @@ public class BatteryMeterView extends View implements DemoMode, for (int i=0; i<mColors.length; i+=2) { thresh = mColors[i]; color = mColors[i+1]; - if (percent <= thresh) return color; + if (percent <= thresh) { + + // Respect tinting for "normal" level + if (i == mColors.length-2) { + return mIconTint; + } else { + return color; + } + } } return color; } + public void setIconTint(int tint) { + mIconTint = tint; + mFramePaint.setColorFilter(new PorterDuffColorFilter(tint, PorterDuff.Mode.SRC_ATOP)); + mBoltPaint.setColor(tint); + mChargeColor = tint; + invalidate(); + } + @Override public void draw(Canvas c) { BatteryTracker tracker = mDemoMode ? mDemoTracker : mTracker; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java index dda52d4..a0ea25f 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java @@ -773,11 +773,7 @@ public abstract class BaseStatusBar extends SystemUI implements } if (entry.icon != null) { - if (entry.targetSdk >= Build.VERSION_CODES.LOLLIPOP) { - entry.icon.setColorFilter(mContext.getResources().getColor(android.R.color.white)); - } else { - entry.icon.setColorFilter(null); - } + entry.icon.setTag(R.id.icon_is_pre_L, entry.targetSdk < Build.VERSION_CODES.LOLLIPOP); } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/SignalClusterView.java b/packages/SystemUI/src/com/android/systemui/statusbar/SignalClusterView.java index 6310234..7286907 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/SignalClusterView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/SignalClusterView.java @@ -17,6 +17,9 @@ package com.android.systemui.statusbar; import android.content.Context; +import android.content.res.ColorStateList; +import android.graphics.Color; +import android.graphics.PorterDuff; import android.telephony.SubscriptionInfo; import android.util.AttributeSet; import android.util.Log; @@ -55,6 +58,7 @@ public class SignalClusterView private int mAirplaneContentDescription; private String mWifiDescription; private ArrayList<PhoneState> mPhoneStates = new ArrayList<PhoneState>(); + private int mIconTint = Color.WHITE; ViewGroup mWifiGroup; ImageView mVpn, mWifi, mAirplane, mNoSims; @@ -121,6 +125,7 @@ public class SignalClusterView } apply(); + applyIconTint(); } @Override @@ -187,6 +192,9 @@ public class SignalClusterView for (int i = 0; i < n; i++) { inflatePhoneState(subs.get(i).getSubscriptionId()); } + if (isAttachedToWindow()) { + applyIconTint(); + } } private PhoneState getOrInflateState(int subId) { @@ -315,6 +323,29 @@ public class SignalClusterView setPaddingRelative(0, 0, anythingVisible ? mEndPadding : mEndPaddingNothingVisible, 0); } + public void setIconTint(int tint) { + boolean changed = tint != mIconTint; + mIconTint = tint; + if (changed && isAttachedToWindow()) { + applyIconTint(); + } + } + + private void applyIconTint() { + setTint(mVpn, mIconTint); + setTint(mWifi, mIconTint); + setTint(mNoSims, mIconTint); + setTint(mAirplane, mIconTint); + for (int i = 0; i < mPhoneStates.size(); i++) { + mPhoneStates.get(i).setIconTint(mIconTint); + } + } + + private void setTint(ImageView v, int tint) { + v.setImageTintMode(PorterDuff.Mode.SRC_ATOP); + v.setImageTintList(ColorStateList.valueOf(tint)); + } + private class PhoneState { private final int mSubId; private boolean mMobileVisible = false; @@ -369,6 +400,11 @@ public class SignalClusterView event.getText().add(mMobileGroup.getContentDescription()); } } + + public void setIconTint(int tint) { + setTint(mMobile, tint); + setTint(mMobileType, tint); + } } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarIconController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarIconController.java index 6147e30..5622993 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarIconController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarIconController.java @@ -16,20 +16,26 @@ package com.android.systemui.statusbar.phone; -import android.app.Notification; import android.content.Context; +import android.content.res.ColorStateList; +import android.graphics.Color; +import android.graphics.PorterDuff; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; import android.view.animation.AnimationUtils; import android.view.animation.Interpolator; +import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import com.android.internal.statusbar.StatusBarIcon; +import com.android.internal.util.NotificationColorUtil; +import com.android.systemui.BatteryMeterView; import com.android.systemui.FontSizeUtils; import com.android.systemui.R; import com.android.systemui.statusbar.NotificationData; +import com.android.systemui.statusbar.SignalClusterView; import com.android.systemui.statusbar.StatusBarIconView; import java.io.PrintWriter; @@ -46,28 +52,37 @@ public class StatusBarIconController { private PhoneStatusBar mPhoneStatusBar; private Interpolator mLinearOutSlowIn; private DemoStatusIcons mDemoStatusIcons; + private NotificationColorUtil mNotificationColorUtil; private LinearLayout mSystemIconArea; private LinearLayout mStatusIcons; + private SignalClusterView mSignalCluster; private LinearLayout mStatusIconsKeyguard; private IconMerger mNotificationIcons; private View mNotificationIconArea; + private ImageView mMoreIcon; + private BatteryMeterView mBatteryMeterView; private TextView mClock; private int mIconSize; private int mIconHPadding; + private int mIconTint = Color.WHITE; + public StatusBarIconController(Context context, View statusBar, View keyguardStatusBar, PhoneStatusBar phoneStatusBar) { mContext = context; mPhoneStatusBar = phoneStatusBar; + mNotificationColorUtil = NotificationColorUtil.getInstance(context); mSystemIconArea = (LinearLayout) statusBar.findViewById(R.id.system_icon_area); mStatusIcons = (LinearLayout) statusBar.findViewById(R.id.statusIcons); + mSignalCluster = (SignalClusterView) statusBar.findViewById(R.id.signal_cluster); mNotificationIconArea = statusBar.findViewById(R.id.notification_icon_area_inner); mNotificationIcons = (IconMerger) statusBar.findViewById(R.id.notificationIcons); - View moreIcon = statusBar.findViewById(R.id.moreIcon); - mNotificationIcons.setOverflowIndicator(moreIcon); + mMoreIcon = (ImageView) statusBar.findViewById(R.id.moreIcon); + mNotificationIcons.setOverflowIndicator(mMoreIcon); mStatusIconsKeyguard = (LinearLayout) keyguardStatusBar.findViewById(R.id.statusIcons); + mBatteryMeterView = (BatteryMeterView) statusBar.findViewById(R.id.battery); mClock = (TextView) statusBar.findViewById(R.id.clock); mLinearOutSlowIn = AnimationUtils.loadInterpolator(mContext, android.R.interpolator.linear_out_slow_in); @@ -91,6 +106,7 @@ public class StatusBarIconController { view.set(icon); mStatusIconsKeyguard.addView(view, viewIndex, new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, mIconSize)); + applyIconTint(); } public void updateSystemIcon(String slot, int index, int viewIndex, @@ -99,6 +115,7 @@ public class StatusBarIconController { view.set(icon); view = (StatusBarIconView) mStatusIconsKeyguard.getChildAt(viewIndex); view.set(icon); + applyIconTint(); } public void removeSystemIcon(String slot, int index, int viewIndex) { @@ -156,6 +173,8 @@ public class StatusBarIconController { mNotificationIcons.removeView(expected); mNotificationIcons.addView(expected, i); } + + applyNotificationIconsTint(); } public void hideSystemIconArea(boolean animate) { @@ -247,4 +266,43 @@ public class StatusBarIconController { .start(); } } + + public void setIconTint(int tint) { + mIconTint = tint; + applyIconTint(); + } + + private void applyIconTint() { + for (int i = 0; i < mStatusIcons.getChildCount(); i++) { + StatusBarIconView v = (StatusBarIconView) mStatusIcons.getChildAt(i); + v.setImageTintList(ColorStateList.valueOf(mIconTint)); + } + mSignalCluster.setIconTint(mIconTint); + mMoreIcon.setImageTintList(ColorStateList.valueOf(mIconTint)); + mBatteryMeterView.setIconTint(mIconTint); + mClock.setTextColor(mIconTint); + applyNotificationIconsTint(); + } + + private void applyNotificationIconsTint() { + for (int i = 0; i < mNotificationIcons.getChildCount(); i++) { + StatusBarIconView v = (StatusBarIconView) mNotificationIcons.getChildAt(i); + boolean isPreL = Boolean.TRUE.equals(v.getTag(R.id.icon_is_pre_L)); + boolean colorize = !isPreL || isGrayscale(v); + if (colorize) { + v.setImageTintMode(PorterDuff.Mode.SRC_ATOP); + v.setImageTintList(ColorStateList.valueOf(mIconTint)); + } + } + } + + private boolean isGrayscale(StatusBarIconView v) { + Object isGrayscale = v.getTag(R.id.icon_is_grayscale); + if (isGrayscale != null) { + return Boolean.TRUE.equals(isGrayscale); + } + boolean grayscale = mNotificationColorUtil.isGrayscaleIcon(v.getDrawable()); + v.setTag(R.id.icon_is_grayscale, grayscale); + return grayscale; + } } |