Emergency info button design change

Title of Emergency information become subtitle of button, using
anonymous avatar to replace default user icon, using black background
with 85 percent opacity, and change the layout parameter to match UI
guideline.

- Re-layout emergency information button.
- EmergencyInfoGroup refactoring.
- Apply black background with 85 percent opacity, and always using
light text theme without updating theme.

Test: Manually
Bug: 80406570
Change-Id: Ie7b52f312696db06fe0d2b856b56f5bf2be2df8f
Merged-In: Ie7b52f312696db06fe0d2b856b56f5bf2be2df8f
diff --git a/src/com/android/phone/EmergencyDialer.java b/src/com/android/phone/EmergencyDialer.java
index 19c4983..b91f927 100644
--- a/src/com/android/phone/EmergencyDialer.java
+++ b/src/com/android/phone/EmergencyDialer.java
@@ -31,6 +31,7 @@
 import android.content.IntentFilter;
 import android.database.ContentObserver;
 import android.database.Cursor;
+import android.graphics.Color;
 import android.graphics.Point;
 import android.media.AudioManager;
 import android.media.ToneGenerator;
@@ -135,6 +136,9 @@
     /** 90% opacity, different from other gradients **/
     private static final int BACKGROUND_GRADIENT_ALPHA = 230;
 
+    /** 85% opacity for black background **/
+    private static final int BLACK_BACKGROUND_GRADIENT_ALPHA = 217;
+
     ResizingTextEditText mDigits;
     private View mDialButton;
     private View mDelete;
@@ -231,10 +235,20 @@
         // Allow turning screen on
         setTurnScreenOn(true);
 
+        mAreEmergencyDialerShortcutsEnabled = Settings.Global.getInt(getContentResolver(),
+                Settings.Global.FASTER_EMERGENCY_PHONE_CALL_ENABLED, 0) != 0;
+
         mColorExtractor = new ColorExtractor(this);
-        GradientColors lockScreenColors = mColorExtractor.getColors(WallpaperManager.FLAG_LOCK,
-                ColorExtractor.TYPE_EXTRA_DARK);
-        updateTheme(lockScreenColors.supportsDarkText());
+
+        // It does not support dark text theme, when emergency dialer shortcuts are enabled.
+        // And the background color is black with 85% opacity.
+        if (mAreEmergencyDialerShortcutsEnabled) {
+            updateTheme(false);
+        } else {
+            GradientColors lockScreenColors = mColorExtractor.getColors(WallpaperManager.FLAG_LOCK,
+                    ColorExtractor.TYPE_EXTRA_DARK);
+            updateTheme(lockScreenColors.supportsDarkText());
+        }
 
         setContentView(R.layout.emergency_dialer);
 
@@ -252,7 +266,8 @@
         ((WindowManager) getSystemService(Context.WINDOW_SERVICE))
                 .getDefaultDisplay().getSize(displaySize);
         mBackgroundGradient.setScreenSize(displaySize.x, displaySize.y);
-        mBackgroundGradient.setAlpha(BACKGROUND_GRADIENT_ALPHA);
+        mBackgroundGradient.setAlpha(mAreEmergencyDialerShortcutsEnabled
+                ? BLACK_BACKGROUND_GRADIENT_ALPHA : BACKGROUND_GRADIENT_ALPHA);
         getWindow().setBackgroundDrawable(mBackgroundGradient);
 
         // Check for the presence of the keypad
@@ -318,9 +333,6 @@
 
         mEmergencyActionGroup = (EmergencyActionGroup) findViewById(R.id.emergency_action_group);
 
-        mAreEmergencyDialerShortcutsEnabled = Settings.Global.getInt(getContentResolver(),
-                Settings.Global.FASTER_EMERGENCY_PHONE_CALL_ENABLED, 0) != 0;
-
         if (mAreEmergencyDialerShortcutsEnabled) {
             setupEmergencyShortcutsView();
         }
@@ -483,6 +495,7 @@
                 return;
             }
             case R.id.floating_action_button_dialpad: {
+                mDigits.getText().clear();
                 switchView(mDialpadView, mEmergencyShortcutView, true);
                 return;
             }
@@ -588,13 +601,19 @@
     @Override
     protected void onStart() {
         super.onStart();
-
-        mColorExtractor.addOnColorsChangedListener(this);
-        GradientColors lockScreenColors = mColorExtractor.getColors(WallpaperManager.FLAG_LOCK,
-                ColorExtractor.TYPE_EXTRA_DARK);
-        // Do not animate when view isn't visible yet, just set an initial state.
-        mBackgroundGradient.setColors(lockScreenColors, false);
-        updateTheme(lockScreenColors.supportsDarkText());
+        // It does not support dark text theme, when emergency dialer shortcuts are enabled.
+        // And set background color to black.
+        if (mAreEmergencyDialerShortcutsEnabled) {
+            mBackgroundGradient.setColors(Color.BLACK, Color.BLACK, false);
+            updateTheme(false);
+        } else {
+            mColorExtractor.addOnColorsChangedListener(this);
+            GradientColors lockScreenColors = mColorExtractor.getColors(WallpaperManager.FLAG_LOCK,
+                    ColorExtractor.TYPE_EXTRA_DARK);
+            // Do not animate when view isn't visible yet, just set an initial state.
+            mBackgroundGradient.setColors(lockScreenColors, false);
+            updateTheme(lockScreenColors.supportsDarkText());
+        }
     }
 
     @Override
@@ -630,7 +649,6 @@
     @Override
     protected void onStop() {
         super.onStop();
-
         mColorExtractor.removeOnColorsChangedListener(this);
     }
 
@@ -1071,7 +1089,7 @@
                 super.onPostExecute(result);
                 if (!isFinishing() && !isDestroyed()) {
                     // Update emergency info with emergency info name
-                    EmergencyInfoGroup group = findViewById(R.id.emergency_info_group);
+                    EmergencyInfoGroup group = findViewById(R.id.emergency_info_button);
                     if (group != null) {
                         group.updateEmergencyInfo(result);
                     }
diff --git a/src/com/android/phone/EmergencyInfoGroup.java b/src/com/android/phone/EmergencyInfoGroup.java
index 9940b3f..73fa92a 100644
--- a/src/com/android/phone/EmergencyInfoGroup.java
+++ b/src/com/android/phone/EmergencyInfoGroup.java
@@ -28,8 +28,8 @@
 import android.text.TextUtils;
 import android.util.AttributeSet;
 import android.view.View;
+import android.widget.FrameLayout;
 import android.widget.ImageView;
-import android.widget.LinearLayout;
 import android.widget.TextView;
 
 import androidx.core.graphics.drawable.RoundedBitmapDrawable;
@@ -43,13 +43,10 @@
  * EmergencyInfoGroup display user icon and user name. And it is an entry point to
  * Emergency Information.
  */
-public class EmergencyInfoGroup extends LinearLayout {
-
+public class EmergencyInfoGroup extends FrameLayout {
     private ImageView mEmergencyInfoImage;
-    private TextView mEmergencyInfoNameTextView;
-    private View mEmergencyInfoTitle;
+    private TextView mEmergencyInfoName;
     private View mEmergencyInfoButton;
-    private String mDefaultEmergencyInfoName;
 
     public EmergencyInfoGroup(Context context, @Nullable AttributeSet attrs) {
         super(context, attrs);
@@ -58,12 +55,9 @@
     @Override
     protected void onFinishInflate() {
         super.onFinishInflate();
-        mEmergencyInfoTitle = findViewById(R.id.emergency_info_title);
         mEmergencyInfoButton = findViewById(R.id.emergency_info_button);
         mEmergencyInfoImage = (ImageView) findViewById(R.id.emergency_info_image);
-        mEmergencyInfoNameTextView = (TextView) findViewById(R.id.emergency_info_name);
-        mDefaultEmergencyInfoName = getContext().getResources().getString(
-                R.string.emergency_information_title);
+        mEmergencyInfoName = (TextView) findViewById(R.id.emergency_info_name);
     }
 
     @Override
@@ -91,24 +85,44 @@
                     .setPackage(packageName);
             mEmergencyInfoButton.setTag(R.id.tag_intent, intent);
             mEmergencyInfoImage.setImageDrawable(getCircularUserIcon());
+
             visible = true;
         }
 
         setVisibility(visible ? View.VISIBLE : View.GONE);
     }
 
+    /**
+     * Get user icon.
+     *
+     * @return user icon, or anonymous avatar if user do not set photo.
+     */
     private Drawable getCircularUserIcon() {
+        final int userId = UserHandle.getCallingUserId();
+
         final UserManager userManager = (UserManager) getContext().getSystemService(
                 Context.USER_SERVICE);
-        Bitmap bitmapUserIcon = userManager.getUserIcon(UserHandle.getCallingUserId());
+
+        // get user icon.
+        Bitmap bitmapUserIcon = userManager.getUserIcon(userId);
 
         if (bitmapUserIcon == null) {
-            // get default user icon.
-            final Drawable defaultUserIcon = UserIcons.getDefaultUserIcon(
-                    getContext().getResources(), UserHandle.getCallingUserId(), false);
-            bitmapUserIcon = UserIcons.convertToBitmap(defaultUserIcon);
+            // use anonymous avatar.
+            return getContext().getDrawable(R.drawable.logo_avatar_anonymous_120);
         }
 
+        // get default user icon.
+        Drawable drawableDefaultUserIcon = UserIcons.getDefaultUserIcon(
+                getContext().getResources(), userId, false);
+        Bitmap bitmapDefaultUserIcon = UserIcons.convertToBitmap(drawableDefaultUserIcon);
+
+        // User icon is default icon that means user do not set photo, replacing default icon
+        // with anonymous avatar on emergency info button.
+        if (bitmapUserIcon.sameAs(bitmapDefaultUserIcon)) {
+            return getContext().getDrawable(R.drawable.logo_avatar_anonymous_120);
+        }
+
+        // set user icon circular.
         RoundedBitmapDrawable drawableUserIcon = RoundedBitmapDrawableFactory.create(
                 getContext().getResources(), bitmapUserIcon);
         drawableUserIcon.setCircular(true);
@@ -117,17 +131,13 @@
     }
 
     void updateEmergencyInfo(String emergencyInfoName) {
-        String infoNameDescription;
         if (TextUtils.isEmpty(emergencyInfoName)) {
-            mEmergencyInfoTitle.setVisibility(View.INVISIBLE);
-            mEmergencyInfoNameTextView.setText(mDefaultEmergencyInfoName);
-            infoNameDescription = mDefaultEmergencyInfoName;
-        } else {
-            mEmergencyInfoTitle.setVisibility(View.VISIBLE);
-            mEmergencyInfoNameTextView.setText(emergencyInfoName);
-            infoNameDescription = getContext().getString(
-                    R.string.emergency_information_button_content_description, emergencyInfoName);
+            emergencyInfoName = getContext().getString(R.string.emergency_information_owner_hint);
         }
-        mEmergencyInfoNameTextView.setContentDescription(infoNameDescription);
+        mEmergencyInfoName.setText(emergencyInfoName);
+
+        final String infoNameDescription = getContext().getString(
+                R.string.emergency_information_owner_content_description, emergencyInfoName);
+        mEmergencyInfoName.setContentDescription(infoNameDescription);
     }
 }
\ No newline at end of file