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
diff --git a/java/com/android/dialer/main/impl/BottomNavBar.java b/java/com/android/dialer/main/impl/BottomNavBar.java
index 66a57be..a4ddc06 100644
--- a/java/com/android/dialer/main/impl/BottomNavBar.java
+++ b/java/com/android/dialer/main/impl/BottomNavBar.java
@@ -119,6 +119,20 @@
     }
   }
 
+  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 14706ab..af7399b 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.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 @@
     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 @@
     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 0000000..2d0dafe
--- /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 f9f2b61..2d9998a 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"