Support Unseen Indicator Icon in all CarNavigationButtons

Bug: 146508662
Test: Manual + Unit Tests
Change-Id: I464f4f080f739923492daf2715753e3892ada7dd
This commit is contained in:
kwaky
2020-01-07 13:42:31 -08:00
parent b130bfbeb5
commit 34c6bdee7e
8 changed files with 51 additions and 87 deletions

View File

@@ -1,25 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2019 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:viewportWidth="44"
android:viewportHeight="44"
android:width="44dp"
android:height="44dp">
<path
android:pathData="M22 39.125C23.925 39.125 25.5 37.55 25.5 35.625L18.5 35.625C18.5 37.55 20.0575 39.125 22 39.125ZM32.5 28.625L32.5 19.875C32.5 14.5025 29.63 10.005 24.625 8.815L24.625 7.625C24.625 6.1725 23.4525 5 22 5C20.5475 5 19.375 6.1725 19.375 7.625L19.375 8.815C14.3525 10.005 11.5 14.485 11.5 19.875L11.5 28.625L8 32.125L8 33.875L36 33.875L36 32.125L32.5 28.625Z"
android:fillColor="@color/car_nav_icon_fill_color_selected" />
</vector>

View File

@@ -1,34 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2019 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:viewportWidth="44"
android:viewportHeight="44"
android:width="44dp"
android:height="44dp">
<path
android:pathData="M22 39.125C23.925 39.125 25.5 37.55 25.5 35.625L18.5 35.625C18.5 37.55 20.0575 39.125 22 39.125ZM32.5 28.625L32.5 19.875C32.5 14.5025 29.63 10.005 24.625 8.815L24.625 7.625C24.625 6.1725 23.4525 5 22 5C20.5475 5 19.375 6.1725 19.375 7.625L19.375 8.815C14.3525 10.005 11.5 14.485 11.5 19.875L11.5 28.625L8 32.125L8 33.875L36 33.875L36 32.125L32.5 28.625Z"
android:fillColor="@color/car_nav_icon_fill_color_selected" />
<group
android:translateX="30"
android:translateY="2">
<path
android:fillColor="@color/car_nav_notification_unseen_indicator_color"
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" />
</group>
</vector>

View File

@@ -19,14 +19,11 @@
android:viewportHeight="44"
android:width="44dp"
android:height="44dp">
<path
android:pathData="M22 39.125C23.925 39.125 25.5 37.55 25.5 35.625L18.5 35.625C18.5 37.55 20.0575 39.125 22 39.125ZM32.5 28.625L32.5 19.875C32.5 14.5025 29.63 10.005 24.625 8.815L24.625 7.625C24.625 6.1725 23.4525 5 22 5C20.5475 5 19.375 6.1725 19.375 7.625L19.375 8.815C14.3525 10.005 11.5 14.485 11.5 19.875L11.5 28.625L8 32.125L8 33.875L36 33.875L36 32.125L32.5 28.625Z"
android:fillColor="@color/car_nav_icon_fill_color" />
<group
android:translateX="30"
android:translateY="2">
<path
android:fillColor="@color/car_nav_notification_unseen_indicator_color"
android:fillColor="@color/car_nav_unseen_indicator_color"
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" />
</group>

View File

@@ -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"
/>
<Space
@@ -138,8 +137,7 @@
android:paddingStart="@dimen/car_keyline_1"
android:paddingEnd="@dimen/car_keyline_1"
android:gravity="center"
android:visibility="gone">
</LinearLayout>
android:visibility="gone"
/>
</com.android.systemui.navigationbar.car.CarNavigationBarView>

View File

@@ -18,13 +18,12 @@
-->
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/car_nav_button_icon"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:animateLayoutChanges="true"
android:orientation="vertical">
@@ -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">
</com.android.keyguard.AlphaOptimizedImageButton>
android:scaleType="fitCenter"
android:clickable="false"
/>
<com.android.keyguard.AlphaOptimizedImageButton
android:id="@+id/car_nav_button_more_icon"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_gravity="center"
android:animateLayoutChanges="true"
android:src="@drawable/car_ic_arrow"
android:background="@android:color/transparent"
android:scaleType="fitCenter">
</com.android.keyguard.AlphaOptimizedImageButton>
android:scaleType="fitCenter"
android:clickable="false"
/>
</LinearLayout>
<ImageView
android:id="@+id/car_nav_button_unseen_icon"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_gravity="center"
android:src="@drawable/car_ic_unseen_indicator"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
android:clickable="false"
/>
</FrameLayout>
</merge>

View File

@@ -43,8 +43,8 @@
<!-- The color of the dividing line between grouped notifications. -->
<color name="notification_divider_color">@*android:color/notification_action_list</color>
<!-- The color for the unseen notification indicator. -->
<color name="car_nav_notification_unseen_indicator_color">#e25142</color>
<!-- The color for the unseen indicator. -->
<color name="car_nav_unseen_indicator_color">#e25142</color>
<!-- The color of the ripples on the untinted notifications -->
<color name="notification_ripple_untinted_color">@color/ripple_material_light</color>

View File

@@ -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);
}
}

View File

@@ -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();
}