From 307bda9cfc0000ea626bd343e65cbcee9128c998 Mon Sep 17 00:00:00 2001 From: Jonathan Koo Date: Tue, 14 May 2019 16:53:48 -0700 Subject: [PATCH] Visual update for the unseen notification indicator. bug: 131262206 Test: Manual Test. Change-Id: I686598206c29670f8b31280349f1d5adbfb73dba (cherry picked from commit 50cfe28e03a6221d047adc7ea5e983c0fa2f3c3e) --- .../car_ic_notification_selected_unseen.xml | 3 +- .../drawable/car_ic_notification_unseen.xml | 2 +- .../statusbar/car/CarNavigationBarView.java | 18 +++++++-- .../statusbar/car/CarNavigationButton.java | 37 +++++++++++++++++-- .../systemui/statusbar/car/CarStatusBar.java | 19 ++++++++-- 5 files changed, 65 insertions(+), 14 deletions(-) diff --git a/packages/CarSystemUI/res/drawable/car_ic_notification_selected_unseen.xml b/packages/CarSystemUI/res/drawable/car_ic_notification_selected_unseen.xml index 1c2586681f56c..c5d7728515ff9 100644 --- a/packages/CarSystemUI/res/drawable/car_ic_notification_selected_unseen.xml +++ b/packages/CarSystemUI/res/drawable/car_ic_notification_selected_unseen.xml @@ -30,4 +30,5 @@ android:strokeWidth="1" android:pathData="M 6 0 C 9.31370849898 0 12 2.68629150102 12 6 C 12 9.31370849898 9.31370849898 12 6 12 C 2.68629150102 12 0 9.31370849898 0 6 C 0 2.68629150102 2.68629150102 0 6 0 Z" /> - \ No newline at end of file + + diff --git a/packages/CarSystemUI/res/drawable/car_ic_notification_unseen.xml b/packages/CarSystemUI/res/drawable/car_ic_notification_unseen.xml index e2fd862a71981..25d1af3fcd83d 100644 --- a/packages/CarSystemUI/res/drawable/car_ic_notification_unseen.xml +++ b/packages/CarSystemUI/res/drawable/car_ic_notification_unseen.xml @@ -30,4 +30,4 @@ android:strokeWidth="1" android:pathData="M 6 0 C 9.31370849898 0 12 2.68629150102 12 6 C 12 9.31370849898 9.31370849898 12 6 12 C 2.68629150102 12 0 9.31370849898 0 6 C 0 2.68629150102 2.68629150102 0 6 0 Z" /> - \ No newline at end of file + diff --git a/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarNavigationBarView.java b/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarNavigationBarView.java index 6e7be060a2cb0..095e2e93df72a 100644 --- a/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarNavigationBarView.java +++ b/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarNavigationBarView.java @@ -35,7 +35,7 @@ import com.android.systemui.statusbar.phone.StatusBarIconController; */ class CarNavigationBarView extends LinearLayout { private View mNavButtons; - private View mNotificationsButton; + private CarNavigationButton mNotificationsButton; private CarStatusBar mCarStatusBar; private Context mContext; private View mLockScreenButtons; @@ -151,10 +151,20 @@ class CarNavigationBarView extends LinearLayout { * Nav buttons will be shown. */ public void hideKeyguardButtons() { - if (mLockScreenButtons == null) { - return; - } + if (mLockScreenButtons == null) return; + mNavButtons.setVisibility(View.VISIBLE); mLockScreenButtons.setVisibility(View.GONE); } + + /** + * Toggles the notification unseen indicator on/off. + * + * @param hasUnseen true if the unseen notification count is great than 0. + */ + void toggleNotificationUnseenIndicator(Boolean hasUnseen) { + if (mNotificationsButton == null) return; + + mNotificationsButton.setUnseen(hasUnseen); + } } diff --git a/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarNavigationButton.java b/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarNavigationButton.java index e640baa4327a4..8879742db00ac 100644 --- a/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarNavigationButton.java +++ b/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarNavigationButton.java @@ -34,12 +34,17 @@ import java.net.URISyntaxException; * code. */ public class CarNavigationButton extends com.android.keyguard.AlphaOptimizedImageButton { - private static final String TAG = "CarNavigationButton"; + + private static final int UNSEEN_ICON_RESOURCE_ID = R.drawable.car_ic_notification_unseen; + private static final int UNSEEN_SELECTED_ICON_RESOURCE_ID = + R.drawable.car_ic_notification_selected_unseen; + private Context mContext; private String mIntent; private String mLongIntent; private boolean mBroadcastIntent; + private boolean mHasUnseen = false; private boolean mSelected = false; private float mSelectedAlpha = 1f; private float mUnselectedAlpha = 1f; @@ -50,6 +55,8 @@ public class CarNavigationButton extends com.android.keyguard.AlphaOptimizedImag public CarNavigationButton(Context context, AttributeSet attrs) { super(context, attrs); mContext = context; + + // CarNavigationButton attrs TypedArray typedArray = context.obtainStyledAttributes( attrs, R.styleable.CarNavigationButton); mIntent = typedArray.getString(R.styleable.CarNavigationButton_intent); @@ -59,10 +66,15 @@ public class CarNavigationButton extends com.android.keyguard.AlphaOptimizedImag R.styleable.CarNavigationButton_selectedAlpha, mSelectedAlpha); mUnselectedAlpha = typedArray.getFloat( R.styleable.CarNavigationButton_unselectedAlpha, mUnselectedAlpha); - mIconResourceId = typedArray.getResourceId( - com.android.internal.R.styleable.ImageView_src, 0); mSelectedIconResourceId = typedArray.getResourceId( R.styleable.CarNavigationButton_selectedIcon, mIconResourceId); + typedArray.recycle(); + + // ImageView attrs + TypedArray a = context.obtainStyledAttributes( + attrs, com.android.internal.R.styleable.ImageView); + mIconResourceId = a.getResourceId(com.android.internal.R.styleable.ImageView_src, 0); + a.recycle(); } @@ -119,6 +131,23 @@ public class CarNavigationButton extends com.android.keyguard.AlphaOptimizedImag super.setSelected(selected); mSelected = selected; setAlpha(mSelected ? mSelectedAlpha : mUnselectedAlpha); - setImageResource(mSelected ? mSelectedIconResourceId : mIconResourceId); + updateImage(); + } + + /** + * @param hasUnseen true if should indicate if this is a Unseen state, false otherwise. + */ + public void setUnseen(boolean hasUnseen) { + mHasUnseen = hasUnseen; + updateImage(); + } + + private void updateImage() { + if (mHasUnseen) { + setImageResource(mSelected ? UNSEEN_SELECTED_ICON_RESOURCE_ID + : UNSEEN_ICON_RESOURCE_ID); + } else { + setImageResource(mSelected ? mSelectedIconResourceId : mIconResourceId); + } } } diff --git a/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java b/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java index 54e468eed75da..b6b34c7605945 100644 --- a/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java +++ b/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java @@ -311,7 +311,6 @@ public class CarStatusBar extends StatusBar implements return result; } - @Override public void showKeyguard() { super.showKeyguard(); @@ -451,9 +450,21 @@ public class CarStatusBar extends StatusBar implements mNotificationDataManager = new NotificationDataManager(); mNotificationDataManager.setOnUnseenCountUpdateListener( () -> { - // TODO: Update Notification Icon based on unseen count - Log.d(TAG, "unseen count: " + - mNotificationDataManager.getUnseenNotificationCount()); + if (mNavigationBarView != null && mNotificationDataManager != null) { + Boolean hasUnseen = + mNotificationDataManager.getUnseenNotificationCount() > 0; + if (mNavigationBarView != null) { + mNavigationBarView.toggleNotificationUnseenIndicator(hasUnseen); + } + + if (mLeftNavigationBarView != null) { + mLeftNavigationBarView.toggleNotificationUnseenIndicator(hasUnseen); + } + + if (mRightNavigationBarView != null) { + mRightNavigationBarView.toggleNotificationUnseenIndicator(hasUnseen); + } + } }); CarHeadsUpNotificationManager carHeadsUpNotificationManager =