From 34c6bdee7e58a5a213cb5bca0e10aa2343445a80 Mon Sep 17 00:00:00 2001 From: kwaky Date: Tue, 7 Jan 2020 13:42:31 -0800 Subject: [PATCH] Support Unseen Indicator Icon in all CarNavigationButtons Bug: 146508662 Test: Manual + Unit Tests Change-Id: I464f4f080f739923492daf2715753e3892ada7dd --- .../drawable/car_ic_notification_selected.xml | 25 -------------- .../car_ic_notification_selected_unseen.xml | 34 ------------------- ...unseen.xml => car_ic_unseen_indicator.xml} | 5 +-- .../res/layout/car_navigation_bar.xml | 6 ++-- .../res/layout/car_navigation_button.xml | 28 +++++++++++---- packages/CarSystemUI/res/values/colors.xml | 4 +-- .../car/CarNavigationButton.java | 19 +++++------ .../car/CarNavigationButtonTest.java | 17 ++++++++++ 8 files changed, 51 insertions(+), 87 deletions(-) delete mode 100644 packages/CarSystemUI/res/drawable/car_ic_notification_selected.xml delete mode 100644 packages/CarSystemUI/res/drawable/car_ic_notification_selected_unseen.xml rename packages/CarSystemUI/res/drawable/{car_ic_notification_unseen.xml => car_ic_unseen_indicator.xml} (69%) diff --git a/packages/CarSystemUI/res/drawable/car_ic_notification_selected.xml b/packages/CarSystemUI/res/drawable/car_ic_notification_selected.xml deleted file mode 100644 index dd2254509d834..0000000000000 --- a/packages/CarSystemUI/res/drawable/car_ic_notification_selected.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - \ No newline at end of file diff --git a/packages/CarSystemUI/res/drawable/car_ic_notification_selected_unseen.xml b/packages/CarSystemUI/res/drawable/car_ic_notification_selected_unseen.xml deleted file mode 100644 index c5d7728515ff9..0000000000000 --- a/packages/CarSystemUI/res/drawable/car_ic_notification_selected_unseen.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - diff --git a/packages/CarSystemUI/res/drawable/car_ic_notification_unseen.xml b/packages/CarSystemUI/res/drawable/car_ic_unseen_indicator.xml similarity index 69% rename from packages/CarSystemUI/res/drawable/car_ic_notification_unseen.xml rename to packages/CarSystemUI/res/drawable/car_ic_unseen_indicator.xml index 25d1af3fcd83d..025fc9c4ea3b5 100644 --- a/packages/CarSystemUI/res/drawable/car_ic_notification_unseen.xml +++ b/packages/CarSystemUI/res/drawable/car_ic_unseen_indicator.xml @@ -19,14 +19,11 @@ android:viewportHeight="44" android:width="44dp" android:height="44dp"> - diff --git a/packages/CarSystemUI/res/layout/car_navigation_bar.xml b/packages/CarSystemUI/res/layout/car_navigation_bar.xml index 27ad4fc16532f..e2e9a336d614e 100644 --- a/packages/CarSystemUI/res/layout/car_navigation_bar.xml +++ b/packages/CarSystemUI/res/layout/car_navigation_bar.xml @@ -114,7 +114,6 @@ style="@style/NavigationBarButton" systemui:icon="@drawable/car_ic_notification" systemui:longIntent="intent:#Intent;component=com.android.car.bugreport/.BugReportActivity;end" - systemui:selectedIcon="@drawable/car_ic_notification_selected" /> - - + android:visibility="gone" + /> \ No newline at end of file diff --git a/packages/CarSystemUI/res/layout/car_navigation_button.xml b/packages/CarSystemUI/res/layout/car_navigation_button.xml index bafbb6408f77d..837252b6d7160 100644 --- a/packages/CarSystemUI/res/layout/car_navigation_button.xml +++ b/packages/CarSystemUI/res/layout/car_navigation_button.xml @@ -18,13 +18,12 @@ --> - @@ -32,20 +31,35 @@ android:id="@+id/car_nav_button_icon_image" android:layout_height="wrap_content" android:layout_width="match_parent" + android:layout_gravity="center" android:animateLayoutChanges="true" android:background="@android:color/transparent" - android:scaleType="fitCenter"> - + android:scaleType="fitCenter" + android:clickable="false" + /> - + android:scaleType="fitCenter" + android:clickable="false" + /> - + + + diff --git a/packages/CarSystemUI/res/values/colors.xml b/packages/CarSystemUI/res/values/colors.xml index 5fcf38fce3cca..7972e09869d39 100644 --- a/packages/CarSystemUI/res/values/colors.xml +++ b/packages/CarSystemUI/res/values/colors.xml @@ -43,8 +43,8 @@ @*android:color/notification_action_list - - #e25142 + + #e25142 @color/ripple_material_light diff --git a/packages/CarSystemUI/src/com/android/systemui/navigationbar/car/CarNavigationButton.java b/packages/CarSystemUI/src/com/android/systemui/navigationbar/car/CarNavigationButton.java index d08fbbc8091f3..b4d478572daf3 100644 --- a/packages/CarSystemUI/src/com/android/systemui/navigationbar/car/CarNavigationButton.java +++ b/packages/CarSystemUI/src/com/android/systemui/navigationbar/car/CarNavigationButton.java @@ -48,13 +48,11 @@ public class CarNavigationButton extends LinearLayout { private static final String BUTTON_FILTER_DELIMITER = ";"; private static final String EXTRA_BUTTON_CATEGORIES = "categories"; private static final String EXTRA_BUTTON_PACKAGES = "packages"; - 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 AlphaOptimizedImageButton mIcon; private AlphaOptimizedImageButton mMoreIcon; + private ImageView mUnseenIcon; private String mIntent; private String mLongIntent; private boolean mBroadcastIntent; @@ -265,23 +263,22 @@ public class CarNavigationButton extends LinearLayout { mIcon = findViewById(R.id.car_nav_button_icon_image); mIcon.setScaleType(ImageView.ScaleType.CENTER); - mIcon.setClickable(false); // Always apply selected alpha if the button does not toggle alpha based on selection state. mIcon.setAlpha(mHighlightWhenSelected ? mUnselectedAlpha : mSelectedAlpha); mIcon.setImageResource(mIconResourceId); mMoreIcon = findViewById(R.id.car_nav_button_more_icon); - mMoreIcon.setClickable(false); mMoreIcon.setAlpha(mSelectedAlpha); mMoreIcon.setVisibility(GONE); + + mUnseenIcon = findViewById(R.id.car_nav_button_unseen_icon); + + mUnseenIcon.setVisibility(mHasUnseen ? VISIBLE : GONE); } private void updateImage() { - if (mHasUnseen) { - mIcon.setImageResource(mSelected ? UNSEEN_SELECTED_ICON_RESOURCE_ID - : UNSEEN_ICON_RESOURCE_ID); - } else { - mIcon.setImageResource(mSelected ? mSelectedIconResourceId : mIconResourceId); - } + mIcon.setImageResource(mSelected ? mSelectedIconResourceId : mIconResourceId); + mUnseenIcon.setVisibility(mHasUnseen ? VISIBLE : GONE); } + } diff --git a/packages/CarSystemUI/tests/src/com/android/systemui/navigationbar/car/CarNavigationButtonTest.java b/packages/CarSystemUI/tests/src/com/android/systemui/navigationbar/car/CarNavigationButtonTest.java index e1ee6162ddcca..96d567d3a8b57 100644 --- a/packages/CarSystemUI/tests/src/com/android/systemui/navigationbar/car/CarNavigationButtonTest.java +++ b/packages/CarSystemUI/tests/src/com/android/systemui/navigationbar/car/CarNavigationButtonTest.java @@ -31,6 +31,7 @@ import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; import android.view.LayoutInflater; import android.view.View; +import android.widget.ImageView; import android.widget.LinearLayout; import androidx.test.filters.SmallTest; @@ -216,6 +217,22 @@ public class CarNavigationButtonTest extends SysuiTestCase { }), any()); } + @Test + public void onSetUnseen_hasUnseen_showsUnseenIndicator() { + mDefaultButton.setUnseen(true); + ImageView hasUnseenIndicator = mDefaultButton.findViewById(R.id.car_nav_button_unseen_icon); + + assertThat(hasUnseenIndicator.getVisibility()).isEqualTo(View.VISIBLE); + } + + @Test + public void onSetUnseen_doesNotHaveUnseen_hidesUnseenIndicator() { + mDefaultButton.setUnseen(false); + ImageView hasUnseenIndicator = mDefaultButton.findViewById(R.id.car_nav_button_unseen_icon); + + assertThat(hasUnseenIndicator.getVisibility()).isEqualTo(View.GONE); + } + private String getCurrentActivityName() { return mActivityManager.getRunningTasks(1).get(0).topActivity.flattenToShortString(); }