Added 'new' badge to navigation drawer.
Added 'new' badge to navigation drawer for
assistant. The badge will show until the
welcome assistant card is dismissed.
Test: Manual, verified badge is displayed until user dismisses the
welcome card.
Bug: 32542932
Change-Id: I5145ebaefc88444773a1d25ff2bfb11e6e6b0678
diff --git a/src/com/android/contacts/ContactsDrawerActivity.java b/src/com/android/contacts/ContactsDrawerActivity.java
index caaa326..29ac4f8 100644
--- a/src/com/android/contacts/ContactsDrawerActivity.java
+++ b/src/com/android/contacts/ContactsDrawerActivity.java
@@ -28,11 +28,13 @@
import android.support.annotation.LayoutRes;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
+import android.support.v4.view.MenuItemCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
+import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
@@ -40,6 +42,7 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
+import android.widget.TextView;
import android.widget.Toast;
import com.android.contacts.activities.ActionBarAdapter;
@@ -138,6 +141,7 @@
// overlaid by the action bar of the newly-created fragment.
stopSearchAndSelection();
updateStatusBarBackground();
+ initializeAssistantNewBadge();
}
private void stopSearchAndSelection() {
@@ -198,6 +202,9 @@
// The account the new group will be created under.
private AccountWithDataSet mNewGroupAccount;
+ // Recycle badge if possible
+ private TextView mAssistantNewBadge;
+
// Checkable menu item lookup maps. Every map declared here should be added to
// clearCheckedMenus() so that they can be cleared.
// TODO find a better way to handle selected menu item state, when switching to fragments.
@@ -247,6 +254,7 @@
mNavigationView.setNavigationItemSelectedListener(this);
setUpMenu();
+ initializeAssistantNewBadge();
loadGroupsAndFilters();
if (savedState != null && savedState.containsKey(KEY_NEW_GROUP_ACCOUNT)) {
@@ -255,6 +263,25 @@
}
}
+ private void initializeAssistantNewBadge() {
+ if (!Flags.getInstance().getBoolean(Experiments.ASSISTANT)) {
+ return;
+ }
+ final LinearLayout newBadgeFrame = (LinearLayout) MenuItemCompat.getActionView(
+ mNavigationView.getMenu().findItem(R.id.nav_assistant));
+ final boolean showWelcomeBadge = !SharedPreferenceUtil.isWelcomeCardDismissed(this);
+ if (showWelcomeBadge && newBadgeFrame.getChildCount() == 0) {
+ if (mAssistantNewBadge == null) {
+ mAssistantNewBadge = (TextView) LayoutInflater.from(this)
+ .inflate(R.layout.assistant_new_badge, null);
+ }
+ newBadgeFrame.setGravity(Gravity.CENTER_VERTICAL);
+ newBadgeFrame.addView(mAssistantNewBadge);
+ } else if (!showWelcomeBadge && newBadgeFrame.getChildCount() > 0) {
+ newBadgeFrame.removeAllViews();
+ }
+ }
+
public void setDrawerLockMode(boolean enabled) {
// Prevent drawer from being opened by sliding from the start of screen.
mDrawer.setDrawerLockMode(enabled ? DrawerLayout.LOCK_MODE_UNLOCKED