Merge "Add face enroll accessibility dialog" into rvc-qpr-dev
diff --git a/res/layout/notif_priority_conversation_preference.xml b/res/layout/notif_priority_conversation_preference.xml
index f68dbde..9c1a302 100644
--- a/res/layout/notif_priority_conversation_preference.xml
+++ b/res/layout/notif_priority_conversation_preference.xml
@@ -32,7 +32,7 @@
         android:clickable="true"
         android:focusable="true">
         <ImageView
-            android:id="@+id/priority_icon"
+            android:id="@+id/icon"
             android:src="@drawable/ic_important_outline"
             android:background="@android:color/transparent"
             android:layout_gravity="center"
@@ -41,19 +41,19 @@
             android:clickable="false"
             android:focusable="false"/>
         <TextView
-            android:id="@+id/priority_label"
+            android:id="@+id/label"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:ellipsize="end"
             android:maxLines="1"
             android:clickable="false"
             android:focusable="false"
-            android:layout_toEndOf="@id/priority_icon"
+            android:layout_toEndOf="@id/icon"
             android:layout_marginStart="@dimen/notification_importance_drawable_padding"
             android:textAppearance="@style/TextAppearance.NotificationImportanceButton.Unselected"
             android:text="@string/notification_priority_title"/>
         <TextView
-            android:id="@+id/priority_summary"
+            android:id="@+id/summary"
             android:paddingTop="@dimen/notification_importance_button_padding"
             android:text="@string/notification_channel_summary_priority"
             android:layout_width="match_parent"
@@ -62,7 +62,7 @@
             android:focusable="false"
             android:ellipsize="end"
             android:maxLines="3"
-            android:layout_below="@id/priority_icon"
+            android:layout_below="@id/icon"
             android:textAppearance="@style/TextAppearance.NotificationImportanceDetail"
             android:visibility="gone" />
     </com.android.settings.notification.NotificationButtonRelativeLayout>
@@ -76,7 +76,7 @@
         android:clickable="true"
         android:focusable="true">
         <ImageView
-            android:id="@+id/alert_icon"
+            android:id="@+id/icon"
             android:src="@drawable/ic_notifications_alert"
             android:background="@android:color/transparent"
             android:layout_gravity="center"
@@ -85,19 +85,19 @@
             android:clickable="false"
             android:focusable="false"/>
         <TextView
-            android:id="@+id/alert_label"
+            android:id="@+id/label"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:ellipsize="end"
             android:maxLines="1"
             android:clickable="false"
             android:focusable="false"
-            android:layout_toEndOf="@id/alert_icon"
+            android:layout_toEndOf="@id/icon"
             android:layout_marginStart="@dimen/notification_importance_drawable_padding"
             android:textAppearance="@style/TextAppearance.NotificationImportanceButton.Unselected"
             android:text="@string/notification_alert_title"/>
         <TextView
-            android:id="@+id/alert_summary"
+            android:id="@+id/summary"
             android:paddingTop="@dimen/notification_importance_button_padding"
             android:text="@string/notification_channel_summary_default"
             android:layout_width="match_parent"
@@ -106,7 +106,7 @@
             android:focusable="false"
             android:ellipsize="end"
             android:maxLines="2"
-            android:layout_below="@id/alert_icon"
+            android:layout_below="@id/icon"
             android:textAppearance="@style/TextAppearance.NotificationImportanceDetail"
             android:visibility="gone" />
     </com.android.settings.notification.NotificationButtonRelativeLayout>
@@ -120,7 +120,7 @@
         android:clickable="true"
         android:focusable="true">
         <ImageView
-            android:id="@+id/silence_icon"
+            android:id="@+id/icon"
             android:src="@drawable/ic_notifications_off_24dp"
             android:background="@android:color/transparent"
             android:layout_gravity="center"
@@ -129,19 +129,19 @@
             android:clickable="false"
             android:focusable="false"/>
         <TextView
-            android:id="@+id/silence_label"
+            android:id="@+id/label"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:ellipsize="end"
             android:maxLines="1"
             android:clickable="false"
             android:focusable="false"
-            android:layout_toEndOf="@id/silence_icon"
+            android:layout_toEndOf="@id/icon"
             android:layout_marginStart="@dimen/notification_importance_drawable_padding"
             android:textAppearance="@style/TextAppearance.NotificationImportanceButton.Unselected"
             android:text="@string/notification_silence_title"/>
         <TextView
-            android:id="@+id/silence_summary"
+            android:id="@+id/summary"
             android:paddingTop="@dimen/notification_importance_button_padding"
             android:text="@string/notification_conversation_summary_low"
             android:layout_width="match_parent"
@@ -150,7 +150,7 @@
             android:focusable="false"
             android:ellipsize="end"
             android:maxLines="2"
-            android:layout_below="@id/silence_icon"
+            android:layout_below="@id/icon"
             android:textAppearance="@style/TextAppearance.NotificationImportanceDetail"
             android:visibility="gone" />
     </com.android.settings.notification.NotificationButtonRelativeLayout>
diff --git a/src/com/android/settings/notification/app/ConversationPriorityPreference.java b/src/com/android/settings/notification/app/ConversationPriorityPreference.java
index 307abec..67bffbf 100644
--- a/src/com/android/settings/notification/app/ConversationPriorityPreference.java
+++ b/src/com/android/settings/notification/app/ConversationPriorityPreference.java
@@ -50,8 +50,6 @@
     private View mAlertButton;
     private View mPriorityButton;
     private Context mContext;
-    Drawable selectedBackground;
-    Drawable unselectedBackground;
     private static final int BUTTON_ANIM_TIME_MS = 100;
 
     public ConversationPriorityPreference(Context context, AttributeSet attrs,
@@ -77,8 +75,6 @@
 
     private void init(Context context) {
         mContext = context;
-        selectedBackground = mContext.getDrawable(R.drawable.button_border_selected);
-        unselectedBackground = mContext.getDrawable(R.drawable.button_border_unselected);
         setLayoutResource(R.layout.notif_priority_conversation_preference);
     }
 
@@ -148,86 +144,43 @@
             TransitionManager.beginDelayedTransition(parent, transition);
         }
 
-        ColorStateList colorAccent = getAccentTint();
-        ColorStateList colorNormal = getRegularTint();
-        ImageView silenceIcon = parent.findViewById(R.id.silence_icon);
-        TextView silenceLabel = parent.findViewById(R.id.silence_label);
-        TextView silenceSummary = parent.findViewById(R.id.silence_summary);
-        ImageView alertIcon = parent.findViewById(R.id.alert_icon);
-        TextView alertLabel = parent.findViewById(R.id.alert_label);
-        TextView alertSummary = parent.findViewById(R.id.alert_summary);
-        ImageView priorityIcon = parent.findViewById(R.id.priority_icon);
-        TextView priorityLabel = parent.findViewById(R.id.priority_label);
-        TextView prioritySummary = parent.findViewById(R.id.priority_summary);
-
         if (importance <= IMPORTANCE_LOW && importance > IMPORTANCE_UNSPECIFIED) {
-            alertSummary.setVisibility(GONE);
-            alertIcon.setImageTintList(colorNormal);
-            alertLabel.setTextColor(colorNormal);
-
-            prioritySummary.setVisibility(GONE);
-            priorityIcon.setImageTintList(colorNormal);
-            priorityLabel.setTextColor(colorNormal);
-
-            silenceIcon.setImageTintList(colorAccent);
-            silenceLabel.setTextColor(colorAccent);
-            silenceSummary.setVisibility(VISIBLE);
-
-            mAlertButton.setBackground(unselectedBackground);
-            mPriorityButton.setBackground(unselectedBackground);
-            mSilenceButton.setBackground(selectedBackground);
-            // a11y service won't always read the newly appearing text in the right order if the
-            // selection happens too soon (readback happens on a different thread as layout). post
-            // the selection to make that conflict less likely
-            parent.post(() -> {
-                mSilenceButton.setSelected(true);
-                mAlertButton.setSelected(false);
-                mPriorityButton.setSelected(false);
-            });
+            setSelected(mPriorityButton, false);
+            setSelected(mAlertButton, false);
+            setSelected(mSilenceButton, true);
         } else {
             if (isPriority) {
-                alertSummary.setVisibility(GONE);
-                alertIcon.setImageTintList(colorNormal);
-                alertLabel.setTextColor(colorNormal);
-
-                prioritySummary.setVisibility(VISIBLE);
-                priorityIcon.setImageTintList(colorAccent);
-                priorityLabel.setTextColor(colorAccent);
-
-                silenceIcon.setImageTintList(colorNormal);
-                silenceLabel.setTextColor(colorNormal);
-                silenceSummary.setVisibility(GONE);
-
-                mAlertButton.setBackground(unselectedBackground);
-                mPriorityButton.setBackground(selectedBackground);
-                mSilenceButton.setBackground(unselectedBackground);
-                parent.post(() -> {
-                    mSilenceButton.setSelected(false);
-                    mAlertButton.setSelected(false);
-                    mPriorityButton.setSelected(true);
-                });
+                setSelected(mPriorityButton, true);
+                setSelected(mAlertButton, false);
+                setSelected(mSilenceButton, false);
             } else {
-                alertSummary.setVisibility(VISIBLE);
-                alertIcon.setImageTintList(colorAccent);
-                alertLabel.setTextColor(colorAccent);
-
-                prioritySummary.setVisibility(GONE);
-                priorityIcon.setImageTintList(colorNormal);
-                priorityLabel.setTextColor(colorNormal);
-
-                silenceIcon.setImageTintList(colorNormal);
-                silenceLabel.setTextColor(colorNormal);
-                silenceSummary.setVisibility(GONE);
-
-                mAlertButton.setBackground(selectedBackground);
-                mPriorityButton.setBackground(unselectedBackground);
-                mSilenceButton.setBackground(unselectedBackground);
-                parent.post(() -> {
-                    mSilenceButton.setSelected(false);
-                    mAlertButton.setSelected(true);
-                    mPriorityButton.setSelected(false);
-                });
+                setSelected(mPriorityButton, false);
+                setSelected(mAlertButton, true);
+                setSelected(mSilenceButton, false);
             }
         }
     }
+
+    void setSelected(View view, boolean selected) {
+        ColorStateList colorAccent = getAccentTint();
+        ColorStateList colorNormal = getRegularTint();
+
+        ImageView icon = view.findViewById(R.id.icon);
+        TextView label = view.findViewById(R.id.label);
+        TextView summary = view.findViewById(R.id.summary);
+
+        icon.setImageTintList(selected ? colorAccent : colorNormal);
+        label.setTextColor(selected ? colorAccent : colorNormal);
+        summary.setVisibility(selected ? VISIBLE : GONE);
+
+        view.setBackground(mContext.getDrawable(selected
+                ? R.drawable.button_border_selected
+                : R.drawable.button_border_unselected));
+        // a11y service won't always read the newly appearing text in the right order if the
+        // selection happens too soon (readback happens on a different thread as layout). post
+        // the selection to make that conflict less likely
+        view.post(() -> {
+            view.setSelected(selected);
+        });
+    }
 }
diff --git a/src/com/android/settings/users/UserSettings.java b/src/com/android/settings/users/UserSettings.java
index 910917a..9669190 100644
--- a/src/com/android/settings/users/UserSettings.java
+++ b/src/com/android/settings/users/UserSettings.java
@@ -1064,6 +1064,7 @@
             }
             return true;
         } else if (pref == mAddGuest) {
+            mAddGuest.setEnabled(false); // prevent multiple tap issue
             UserInfo guest = mUserManager.createGuest(
                     getContext(), getString(com.android.settingslib.R.string.user_guest));
             openUserDetails(guest, true);
diff --git a/tests/robotests/src/com/android/settings/notification/app/ConversationPriorityPreferenceTest.java b/tests/robotests/src/com/android/settings/notification/app/ConversationPriorityPreferenceTest.java
index 12e1f35..2d2fcc8 100644
--- a/tests/robotests/src/com/android/settings/notification/app/ConversationPriorityPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/notification/app/ConversationPriorityPreferenceTest.java
@@ -68,10 +68,6 @@
         final LayoutInflater inflater = LayoutInflater.from(mContext);
         PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
                 inflater.inflate(preference.getLayoutResource(), null));
-        Drawable unselected = mock(Drawable.class);
-        Drawable selected = mock(Drawable.class);
-        preference.selectedBackground = selected;
-        preference.unselectedBackground = unselected;
 
         preference.setConfigurable(false);
         preference.setImportance(IMPORTANCE_DEFAULT);
@@ -81,35 +77,6 @@
         assertThat(holder.itemView.findViewById(R.id.silence).isEnabled()).isFalse();
         assertThat(holder.itemView.findViewById(R.id.priority_group).isEnabled()).isFalse();
         assertThat(holder.itemView.findViewById(R.id.alert).isEnabled()).isFalse();
-
-        assertThat(holder.itemView.findViewById(R.id.priority_group).getBackground())
-                .isEqualTo(selected);
-        assertThat(holder.itemView.findViewById(R.id.alert).getBackground()).isEqualTo(unselected);
-        assertThat(holder.itemView.findViewById(R.id.silence).getBackground())
-                .isEqualTo(unselected);
-
-        // other button
-        preference.setPriorityConversation(false);
-        holder = PreferenceViewHolder.createInstanceForTests(
-                inflater.inflate(preference.getLayoutResource(), null));
-        preference.onBindViewHolder(holder);
-
-        assertThat(holder.itemView.findViewById(R.id.alert).getBackground()).isEqualTo(selected);
-        assertThat(holder.itemView.findViewById(R.id.silence).getBackground())
-                .isEqualTo(unselected);
-        assertThat(holder.itemView.findViewById(R.id.priority_group).getBackground())
-                .isEqualTo(unselected);
-
-        // other other button
-        preference.setImportance(IMPORTANCE_LOW);
-        holder = PreferenceViewHolder.createInstanceForTests(
-                inflater.inflate(preference.getLayoutResource(), null));
-        preference.onBindViewHolder(holder);
-
-        assertThat(holder.itemView.findViewById(R.id.priority_group).getBackground())
-                .isEqualTo(unselected);
-        assertThat(holder.itemView.findViewById(R.id.alert).getBackground()).isEqualTo(unselected);
-        assertThat(holder.itemView.findViewById(R.id.silence).getBackground()).isEqualTo(selected);
     }
 
     @Test
@@ -119,10 +86,6 @@
         final LayoutInflater inflater = LayoutInflater.from(mContext);
         final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
                 inflater.inflate(preference.getLayoutResource(), null));
-        Drawable unselected = mock(Drawable.class);
-        Drawable selected = mock(Drawable.class);
-        preference.selectedBackground = selected;
-        preference.unselectedBackground = unselected;
 
         preference.setConfigurable(true);
         preference.setImportance(IMPORTANCE_LOW);
@@ -130,12 +93,8 @@
 
         preference.onBindViewHolder(holder);
 
-        assertThat(holder.itemView.findViewById(R.id.priority_group).getBackground())
-                .isEqualTo(unselected);
-        assertThat(holder.itemView.findViewById(R.id.alert).getBackground()).isEqualTo(unselected);
-        assertThat(holder.itemView.findViewById(R.id.silence).getBackground())
-                .isEqualTo(selected);
-        assertThat(holder.itemView.findViewById(R.id.silence_summary).getVisibility())
+        assertThat(holder.itemView.findViewById(R.id.silence)
+                .findViewById(R.id.summary).getVisibility())
                 .isEqualTo(View.VISIBLE);
     }
 
@@ -146,10 +105,6 @@
         final LayoutInflater inflater = LayoutInflater.from(mContext);
         final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
                 inflater.inflate(preference.getLayoutResource(), null));
-        Drawable unselected = mock(Drawable.class);
-        Drawable selected = mock(Drawable.class);
-        preference.selectedBackground = selected;
-        preference.unselectedBackground = unselected;
 
         preference.setConfigurable(true);
         preference.setImportance(IMPORTANCE_DEFAULT);
@@ -161,12 +116,6 @@
 
         silenceButton.callOnClick();
 
-        assertThat(holder.itemView.findViewById(R.id.alert).getBackground()).isEqualTo(unselected);
-        assertThat(holder.itemView.findViewById(R.id.priority_group).getBackground())
-                .isEqualTo(unselected);
-        assertThat(holder.itemView.findViewById(R.id.silence).getBackground())
-                .isEqualTo(selected);
-
         verify(preference, times(1)).callChangeListener(new Pair(IMPORTANCE_LOW, false));
     }
 }