diff options
author | calderwoodra <calderwoodra@google.com> | 2018-01-30 14:00:24 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-01-30 17:43:15 -0800 |
commit | 5e550aadbb9a99885b2c719501d00a491d2ba9db (patch) | |
tree | cc9aac3387613f533cae64f0d717488717cf50aa /java | |
parent | 54e90e5c61b563a432ad70066505f08b352837c3 (diff) |
Added badge count feature to bottom nav.
This Change doesn't actually fetch the badge counts, but it's now possible to
set badge counts.
Bug: 72525595
Test: manual
PiperOrigin-RevId: 183887322
Change-Id: I452ca6352133befc8cc2a39c44cd84a33fd66d42
Diffstat (limited to 'java')
4 files changed, 73 insertions, 5 deletions
diff --git a/java/com/android/dialer/main/impl/BottomNavBar.java b/java/com/android/dialer/main/impl/BottomNavBar.java index 66a57becd..a4ddc0652 100644 --- a/java/com/android/dialer/main/impl/BottomNavBar.java +++ b/java/com/android/dialer/main/impl/BottomNavBar.java @@ -119,6 +119,20 @@ final class BottomNavBar extends LinearLayout { } } + void setNotificationCount(@TabIndex int tab, int count) { + if (tab == TabIndex.SPEED_DIAL) { + speedDial.setNotificationCount(count); + } else if (tab == TabIndex.HISTORY) { + callLog.setNotificationCount(count); + } else if (tab == TabIndex.CONTACTS) { + contacts.setNotificationCount(count); + } else if (tab == TabIndex.VOICEMAIL) { + voicemail.setNotificationCount(count); + } else { + throw new IllegalStateException("Invalid tab: " + tab); + } + } + void setOnTabSelectedListener(OnBottomNavTabSelectedListener listener) { this.listener = listener; } diff --git a/java/com/android/dialer/main/impl/BottomNavItem.java b/java/com/android/dialer/main/impl/BottomNavItem.java index 14706ab34..af7399b6c 100644 --- a/java/com/android/dialer/main/impl/BottomNavItem.java +++ b/java/com/android/dialer/main/impl/BottomNavItem.java @@ -22,15 +22,18 @@ import android.support.annotation.DrawableRes; import android.support.annotation.Nullable; import android.support.annotation.StringRes; import android.util.AttributeSet; +import android.view.View; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; +import com.android.dialer.common.Assert; /** Navigation item in a bottom nav. */ final class BottomNavItem extends LinearLayout { private ImageView image; private TextView text; + private TextView notificationBadge; public BottomNavItem(Context context, @Nullable AttributeSet attrs) { super(context, attrs); @@ -41,6 +44,7 @@ final class BottomNavItem extends LinearLayout { super.onFinishInflate(); image = findViewById(R.id.bottom_nav_item_image); text = findViewById(R.id.bottom_nav_item_text); + notificationBadge = findViewById(R.id.notification_badge); } @Override @@ -56,4 +60,14 @@ final class BottomNavItem extends LinearLayout { text.setText(stringRes); image.setImageResource(drawableRes); } + + void setNotificationCount(int count) { + Assert.checkArgument(count >= 0, "Invalid count: " + count); + if (count == 0) { + notificationBadge.setVisibility(View.GONE); + } else { + notificationBadge.setVisibility(View.VISIBLE); + notificationBadge.setText(String.format(Integer.toString(count))); + } + } } diff --git a/java/com/android/dialer/main/impl/res/drawable/notification_badge.xml b/java/com/android/dialer/main/impl/res/drawable/notification_badge.xml new file mode 100644 index 000000000..2d0dafe93 --- /dev/null +++ b/java/com/android/dialer/main/impl/res/drawable/notification_badge.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2018 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 + --> +<shape + xmlns:android="http://schemas.android.com/apk/res/android" + android:shape="oval"> + <solid android:color="@color/dialer_secondary_color"/> + <size android:height="14dp" android:width="14dp"/> +</shape>
\ No newline at end of file diff --git a/java/com/android/dialer/main/impl/res/layout/bottom_nav_item.xml b/java/com/android/dialer/main/impl/res/layout/bottom_nav_item.xml index f9f2b6102..2d9998af2 100644 --- a/java/com/android/dialer/main/impl/res/layout/bottom_nav_item.xml +++ b/java/com/android/dialer/main/impl/res/layout/bottom_nav_item.xml @@ -25,13 +25,31 @@ android:paddingStart="12dp" android:paddingEnd="12dp" android:gravity="center" + android:theme="@style/Theme.AppCompat" android:background="?android:selectableItemBackgroundBorderless"> - <ImageView - android:id="@+id/bottom_nav_item_image" - android:layout_width="24dp" - android:layout_height="24dp" - android:layout_marginBottom="6dp"/> + <FrameLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginBottom="2dp"> + + <ImageView + android:id="@+id/bottom_nav_item_image" + android:layout_width="24dp" + android:layout_height="24dp" + android:layout_margin="4dp"/> + + <TextView + android:id="@+id/notification_badge" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="top|end" + android:gravity="center" + android:textSize="12sp" + android:textColor="@color/dialer_primary_text_color_white" + android:background="@drawable/notification_badge" + android:visibility="gone"/> + </FrameLayout> <TextView android:id="@+id/bottom_nav_item_text" |