Merge "Change the SIM color for passing the GAR" into sc-qpr1-dev am: adc41a55d5

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/15751403

Change-Id: I5a889a42d677e064b7ef553405fc0a19996961ad
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index 4a8d933..1ecddf5 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -1179,14 +1179,24 @@
         <item>Cached (empty)</item>
     </string-array>
 
+    <!-- Array of color for sim color for multi-sim in light mode -->
+    <string-array name="sim_color_light">
+        <item>@color/SIM_color_cyan</item>
+        <item>@color/SIM_color_blue800</item>
+        <item>@color/SIM_color_green800</item>
+        <item>@color/SIM_color_purple800</item>
+        <item>@color/SIM_color_pink800</item>
+        <item>@color/SIM_color_orange</item>
+    </string-array>
+
     <!-- Array of titles for sim color for multi-sim -->
     <string-array name="color_picker">
-        <item>Teal</item>
+        <item>Cyan</item>
         <item>Blue</item>
-        <item>Indigo</item>
+        <item>Green</item>
         <item>Purple</item>
         <item>Pink</item>
-        <item>Red</item>
+        <item>Orange</item>
     </string-array>
 
     <!-- Automatic storage management settings. The amount of days for the automatic storage manager
diff --git a/res/values/colors.xml b/res/values/colors.xml
index adee07c..2114b96 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -184,13 +184,21 @@
     <color name="SIM_color_pink">#ffc2185b</color> <!-- Material Pink 700 -->
     <color name="SIM_color_red">#ffd32f2f</color> <!-- Material Red 700 -->
 
+    <!-- SIM colors updated for GAR -->
+    <color name="SIM_color_cyan">#ff006D74</color> <!-- Material Custom Cyan -->
+    <color name="SIM_color_blue800">#ff185ABC</color> <!-- Material Blue 800 -->
+    <color name="SIM_color_green800">#ff137333</color> <!-- Material Green 800 -->
+    <color name="SIM_color_purple800">#ff7627bb</color> <!-- Material Purple 800 -->
+    <color name="SIM_color_pink800">#ffb80672</color> <!-- Material Pink 800 -->
+    <color name="SIM_color_orange">#ff995400</color> <!-- Material Custom Orange -->
+
     <!-- Dark mode SIM colors -->
-    <color name="SIM_dark_mode_color_teal">#ff80cbc4</color> <!-- Material Teal 200 -->
-    <color name="SIM_dark_mode_color_blue">#ff90caf9</color> <!-- Material Blue 200 -->
-    <color name="SIM_dark_mode_color_indigo">#ffc5cae9</color> <!-- Material Indigo 100 -->
-    <color name="SIM_dark_mode_color_purple">#ffe1bee7</color> <!-- Material Purple 100 -->
-    <color name="SIM_dark_mode_color_pink">#fff48fb1</color> <!-- Material Pink 200 -->
-    <color name="SIM_dark_mode_color_red">#ffef9a9a</color> <!-- Material Red 200 -->
+    <color name="SIM_dark_mode_color_cyan">#ff4DD0E1</color> <!-- Material Cyan 300 -->
+    <color name="SIM_dark_mode_color_blue">#ff8AB4F8</color> <!-- Material Blue 300 -->
+    <color name="SIM_dark_mode_color_green">#ff81C995</color> <!-- Material Green 300 -->
+    <color name="SIM_dark_mode_color_purple">#ffC58AF9</color> <!-- Material Purple 300 -->
+    <color name="SIM_dark_mode_color_pink">#ffff8bcb</color> <!-- Material Pink 300 -->
+    <color name="SIM_dark_mode_color_orange">#fffcad70</color> <!-- Material Orange 300 -->
 
     <!-- Top app bar colors -->
     <color name="color_surface_header">@*android:color/surface_header_light</color>
diff --git a/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragment.java b/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragment.java
index c782b66..8e65605 100644
--- a/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragment.java
+++ b/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragment.java
@@ -52,6 +52,7 @@
 
 import com.google.common.collect.ImmutableMap;
 
+import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 
@@ -108,18 +109,18 @@
         mSubId = getArguments().getInt(KEY_SUBSCRIPTION_ID);
         Resources res = context.getResources();
         mLightDarkMap = ImmutableMap.<Integer, Integer>builder()
-                .put(res.getInteger(R.color.SIM_color_teal),
-                        res.getInteger(R.color.SIM_dark_mode_color_teal))
-                .put(res.getInteger(R.color.SIM_color_blue),
+                .put(res.getInteger(R.color.SIM_color_cyan),
+                        res.getInteger(R.color.SIM_dark_mode_color_cyan))
+                .put(res.getInteger(R.color.SIM_color_blue800),
                         res.getInteger(R.color.SIM_dark_mode_color_blue))
-                .put(res.getInteger(R.color.SIM_color_indigo),
-                        res.getInteger(R.color.SIM_dark_mode_color_indigo))
-                .put(res.getInteger(R.color.SIM_color_purple),
+                .put(res.getInteger(R.color.SIM_color_green800),
+                        res.getInteger(R.color.SIM_dark_mode_color_green))
+                .put(res.getInteger(R.color.SIM_color_purple800),
                         res.getInteger(R.color.SIM_dark_mode_color_purple))
-                .put(res.getInteger(R.color.SIM_color_pink),
+                .put(res.getInteger(R.color.SIM_color_pink800),
                         res.getInteger(R.color.SIM_dark_mode_color_pink))
-                .put(res.getInteger(R.color.SIM_color_red),
-                        res.getInteger(R.color.SIM_dark_mode_color_red))
+                .put(res.getInteger(R.color.SIM_color_orange),
+                        res.getInteger(R.color.SIM_dark_mode_color_orange))
                 .build();
     }
 
@@ -175,12 +176,7 @@
         final ColorAdapter adapter = new ColorAdapter(getContext(),
                 R.layout.dialog_mobile_network_color_picker_item, mColors);
         mColorSpinner.setAdapter(adapter);
-        for (int i = 0; i < mColors.length; i++) {
-            if (mColors[i].getColor() == info.getIconTint()) {
-                mColorSpinner.setSelection(i);
-                break;
-            }
-        }
+        mColorSpinner.setSelection(getSimColorIndex(info.getIconTint()));
 
         final TextView operatorName = view.findViewById(R.id.operator_name_value);
         mTelephonyManager = mTelephonyManager.createForSubscriptionId(mSubId);
@@ -239,7 +235,7 @@
 
     private Color[] getColors() {
         final Resources res = getContext().getResources();
-        final int[] colorInts = res.getIntArray(com.android.internal.R.array.sim_colors);
+        final int[] colorInts = res.getIntArray(R.array.sim_color_light);
         final String[] colorStrings = res.getStringArray(R.array.color_picker);
         final int iconSize = res.getDimensionPixelSize(R.dimen.color_swatch_size);
         final int strokeWidth = res.getDimensionPixelSize(R.dimen.color_swatch_stroke_width);
@@ -286,4 +282,31 @@
     private int getDarkColor(int lightColor) {
         return mLightDarkMap.getOrDefault(lightColor, lightColor);
     }
+
+    /*
+    * Get the color index from previous color that defined in Android OS
+    * (frameworks/base/core/res/res/values/arrays.xml). If can't find the color, continue to look
+    * for it in the new color plattee. If not, give it the first index.
+    */
+
+    private int getSimColorIndex(int color) {
+        int index = -1;
+        final int[] previousSimColorInts =
+                getContext().getResources().getIntArray(com.android.internal.R.array.sim_colors);
+        for (int i = 0; i < previousSimColorInts.length; i++) {
+            if (previousSimColorInts[i] == color) {
+                index = i;
+            }
+        }
+
+        if (index == -1) {
+            for (int i = 0; i < mColors.length; i++) {
+                if (mColors[i].getColor() == color) {
+                    index = i;
+                }
+            }
+        }
+
+        return index == -1 ? 0 : index;
+    }
 }
diff --git a/tests/robotests/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragmentTest.java b/tests/robotests/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragmentTest.java
index d0df92e..70b0598 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragmentTest.java
@@ -159,7 +159,7 @@
                 eq(SubscriptionManager.NAME_SOURCE_USER_INPUT));
         assertThat(captor.getValue()).isEqualTo("test2");
         verify(mSubscriptionMgr)
-                .setIconTint(eq(Color.parseColor("#ff00796b" /* teal */)), eq(mSubscriptionId));
+                .setIconTint(eq(Color.parseColor("#ff006D74" /* cyan */)), eq(mSubscriptionId));
     }
 
     @Test
@@ -174,6 +174,34 @@
         assertThat(view.findViewById(R.id.number_label).getVisibility()).isEqualTo(View.GONE);
     }
 
+    @Test
+    public void populateView_getPreviousSimColor_setCorrectSelection() {
+        final View view = LayoutInflater.from(mActivity).inflate(
+                R.layout.dialog_mobile_network_rename, null);
+        when(mSubscriptionInfo.getIconTint())
+                .thenReturn(Color.parseColor("#ff3367d6"/* blue700 */));
+
+        startDialog();
+        mFragment.populateView(view);
+
+        final Spinner colorSpinnerView = mFragment.getColorSpinnerView();
+        assertThat(colorSpinnerView.getSelectedItemPosition()).isEqualTo(1);
+    }
+
+    @Test
+    public void populateView_getUpdatedSimColor_setCorrectSelection() {
+        final View view = LayoutInflater.from(mActivity).inflate(
+                R.layout.dialog_mobile_network_rename, null);
+        when(mSubscriptionInfo.getIconTint())
+                .thenReturn(Color.parseColor("#ff137333"/* Green800 */));
+
+        startDialog();
+        mFragment.populateView(view);
+
+        final Spinner colorSpinnerView = mFragment.getColorSpinnerView();
+        assertThat(colorSpinnerView.getSelectedItemPosition()).isEqualTo(2);
+    }
+
     /**
      * Helper method to start the dialog
      */