OSDN Git Service

Adding icons to sim color selection in settings UI.
authorSanket Padawe <sanketpadawe@google.com>
Mon, 17 Nov 2014 18:43:37 +0000 (10:43 -0800)
committerSanket Padawe <sanketpadawe@google.com>
Mon, 17 Nov 2014 18:43:37 +0000 (10:43 -0800)
Adding icons to sim color selection of sim settings UI.

Bug: 18380838
Change-Id: I98f07721aa234ff58a64a0c694206b085385bdec

res/layout/multi_sim_dialog.xml
res/layout/select_account_list_item.xml
res/layout/settings_color_picker_item.xml [new file with mode: 0644]
res/values/dimens.xml
src/com/android/settings/sim/SimSettings.java

index c373edd..b17b86e 100644 (file)
@@ -21,7 +21,6 @@
     <LinearLayout
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:padding="@dimen/sim_dialog_padding"
             android:orientation="vertical">
 
         <LinearLayout android:id="@+id/type"
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
                     android:layout_marginTop="@dimen/sim_dialog_margin_top"
-                    android:paddingStart="@dimen/sim_label_padding"
-                    android:text="@string/sim_editor_name"
-                    style="?android:attr/textAppearanceMedium" />
+                    android:paddingStart="@dimen/sim_content_padding"
+                    android:text="@string/sim_editor_name" />
 
             <EditText android:id="@+id/sim_name"
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
                     android:singleLine="true"
-                    android:layout_marginStart="@dimen/sim_content_padding"
+                    android:paddingStart="@dimen/sim_content_padding"
                     android:paddingBottom="@dimen/sim_dialog_margin_bottom"
                     android:hint="@string/wifi_ssid_hint"
                     android:inputType="textNoSuggestions"
-                    android:maxLength="@integer/sim_name_length" />
+                    android:maxLength="@integer/sim_name_length"
+                    android:textColor="@android:color/black"
+                    style="?android:attr/textAppearanceMedium" />
 
         </LinearLayout>
 
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:layout_marginTop="@dimen/sim_dialog_margin_top"
-                android:paddingStart="@dimen/sim_label_padding"
-                android:text="@string/color_title"
-                style="?android:attr/textAppearanceMedium" />
+                android:paddingStart="@dimen/sim_content_padding"
+                android:text="@string/color_title" />
 
             <Spinner
                 android:id="@+id/spinner"
-                android:layout_width="wrap_content"
+                android:layout_width="@dimen/color_picker_width"
                 android:layout_height="wrap_content"
-                android:layout_marginTop="@dimen/sim_dialog_margin_top"
-                android:paddingStart="@dimen/sim_label_padding" />
+                android:paddingStart="@dimen/sim_content_padding" />
 
         </LinearLayout>
 
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
                     android:layout_marginTop="@dimen/sim_dialog_margin_top"
-                    android:paddingStart="@dimen/sim_label_padding"
+                    android:paddingStart="@dimen/sim_content_padding"
                     android:text="@string/sim_editor_carrier" />
 
             <TextView android:id="@+id/carrier"
                     android:textColor="@android:color/black"
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
-                    android:paddingStart="@dimen/sim_label_padding"
+                    android:paddingStart="@dimen/sim_content_padding"
                     android:paddingBottom="@dimen/sim_dialog_margin_bottom"
                     android:singleLine="true"
                     style="?android:attr/textAppearanceMedium" />
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
                     android:layout_marginTop="@dimen/sim_dialog_margin_top"
-                    android:paddingStart="@dimen/sim_label_padding"
+                    android:paddingStart="@dimen/sim_content_padding"
                     android:text="@string/sim_editor_number" />
 
             <TextView android:id="@+id/number"
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
                     android:paddingBottom="@dimen/sim_dialog_margin_bottom"
-                    android:paddingStart="@dimen/sim_label_padding"
+                    android:paddingStart="@dimen/sim_content_padding"
                     android:singleLine="true"
                     android:textColor="@android:color/black"
                     style="?android:attr/textAppearanceMedium" />
index 55484b1..3587e55 100644 (file)
@@ -19,8 +19,7 @@
     android:orientation="horizontal"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
-    android:background="?android:attr/selectableItemBackground"
-    android:padding="4dp" >
+    android:background="?android:attr/selectableItemBackground" >
 
     <ImageView android:id="@+id/icon"
         android:layout_width="48dp"
diff --git a/res/layout/settings_color_picker_item.xml b/res/layout/settings_color_picker_item.xml
new file mode 100644 (file)
index 0000000..c171950
--- /dev/null
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2014 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.
+-->
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:orientation="horizontal"
+    android:background="?android:attr/selectableItemBackground" >
+
+    <ImageView
+        android:id="@+id/color_icon"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:paddingRight="8dp"
+        android:paddingLeft="6dp"
+        android:paddingTop="8dp"
+        android:paddingBottom="8dp"
+        android:layout_gravity="center_vertical" />
+
+    <TextView
+        android:id="@+id/color_text"
+        android:gravity="center_vertical"
+        android:layout_height="wrap_content"
+        android:layout_width="0dp"
+        android:layout_weight="1"
+        android:paddingTop="8dp"
+        android:paddingBottom="8dp"
+        android:paddingRight="8dp"
+        android:paddingLeft="8dp"
+        android:textColor="@android:color/black"
+        style="?android:attr/textAppearanceMedium" />
+
+</LinearLayout>
\ No newline at end of file
index 4076845..4c4dbda 100755 (executable)
     <!-- SIM Dialog padding -->
     <dimen name="sim_dialog_padding">8dip</dimen>
     <dimen name="sim_label_padding">16dip</dimen>
-    <dimen name="sim_content_padding">12dip</dimen>
+    <dimen name="sim_content_padding">24dip</dimen>
     <!-- Sim Card Name length -->
     <integer name="sim_name_length">32</integer>
 
 
     <dimen name="wifi_divider_height">1px</dimen>
 
+    <!-- Color picker -->
+    <dimen name="color_swatch_size">16dp</dimen>
+    <dimen name="color_swatch_stroke_width">4dp</dimen>
+    <dimen name="color_picker_width">156dp</dimen>
+
 </resources>
index 6de0cc1..2320380 100644 (file)
@@ -22,7 +22,10 @@ import android.content.ContentUris;
 import android.content.DialogInterface;
 import android.content.res.Resources;
 import android.database.Cursor;
+import android.graphics.Paint;
 import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.ShapeDrawable;
+import android.graphics.drawable.shapes.OvalShape;
 import android.net.Uri;
 import android.os.Bundle;
 import android.preference.Preference;
@@ -415,8 +418,10 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable
     private class SimPreference extends Preference{
         private SubscriptionInfo mSubInfoRecord;
         private int mSlotId;
-        private int[] tintArr;
+        private int[] mTintArr;
         Context mContext;
+        private String[] mColorStrings;
+        private int mTintSelectorPos;
 
         public SimPreference(Context context, SubscriptionInfo subInfoRecord, int slotId) {
             super(context);
@@ -426,7 +431,9 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable
             mSlotId = slotId;
             setKey("sim" + mSlotId);
             update();
-            tintArr = context.getResources().getIntArray(com.android.internal.R.array.sim_colors);
+            mTintArr = context.getResources().getIntArray(com.android.internal.R.array.sim_colors);
+            mColorStrings = context.getResources().getStringArray(R.array.color_picker);
+            mTintSelectorPos = 0;
         }
 
         public void update() {
@@ -467,14 +474,15 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable
             nameText.setText(mSubInfoRecord.getDisplayName());
 
             final Spinner tintSpinner = (Spinner) dialogLayout.findViewById(R.id.spinner);
-            ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getContext(),
-                    R.array.color_picker, android.R.layout.simple_spinner_item);
+            SelectColorAdapter adapter = new SelectColorAdapter(getContext(),
+                     R.layout.settings_color_picker_item, mColorStrings);
             adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
             tintSpinner.setAdapter(adapter);
 
-            for (int i = 0; i < tintArr.length; i++) {
-                if (tintArr[i] == mSubInfoRecord.getIconTint()) {
+            for (int i = 0; i < mTintArr.length; i++) {
+                if (mTintArr[i] == mSubInfoRecord.getIconTint()) {
                     tintSpinner.setSelection(i);
+                    mTintSelectorPos = i;
                     break;
                 }
             }
@@ -484,6 +492,7 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable
                 public void onItemSelected(AdapterView<?> parent, View view,
                     int pos, long id){
                     tintSpinner.setSelection(pos);
+                    mTintSelectorPos = pos;
                 }
 
                 @Override
@@ -519,7 +528,7 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable
 
                     final int tintSelected = tintSpinner.getSelectedItemPosition();
                     int subscriptionId = mSubInfoRecord.getSubscriptionId();
-                    int tint = tintArr[tintSelected];
+                    int tint = mTintArr[tintSelected];
                     mSubInfoRecord.setIconTint(tint);
                     SubscriptionManager.setIconTint(tint, subscriptionId);
                     Utils.findRecordBySubId(subscriptionId).setIconTint(tint);
@@ -538,6 +547,76 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable
 
             builder.create().show();
         }
+
+        private class SelectColorAdapter extends ArrayAdapter<CharSequence> {
+            private Context mContext;
+            private int mResId;
+
+            public SelectColorAdapter(
+                Context context, int resource, String[] arr) {
+                super(context, resource, arr);
+                mContext = context;
+                mResId = resource;
+            }
+
+            @Override
+            public View getView(int position, View convertView, ViewGroup parent) {
+                LayoutInflater inflater = (LayoutInflater)
+                    mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+
+                View rowView;
+                final ViewHolder holder;
+                Resources res = getResources();
+                int iconSize = res.getDimensionPixelSize(R.dimen.color_swatch_size);
+                int strokeWidth = res.getDimensionPixelSize(R.dimen.color_swatch_stroke_width);
+
+                if (convertView == null) {
+                    // Cache views for faster scrolling
+                    rowView = inflater.inflate(mResId, null);
+                    holder = new ViewHolder();
+                    ShapeDrawable drawable = new ShapeDrawable(new OvalShape());
+                    drawable.setIntrinsicHeight(iconSize);
+                    drawable.setIntrinsicWidth(iconSize);
+                    drawable.getPaint().setStrokeWidth(strokeWidth);
+                    holder.label = (TextView) rowView.findViewById(R.id.color_text);
+                    holder.icon = (ImageView) rowView.findViewById(R.id.color_icon);
+                    holder.swatch = drawable;
+                    rowView.setTag(holder);
+                } else {
+                    rowView = convertView;
+                    holder = (ViewHolder) rowView.getTag();
+                }
+
+                holder.label.setText(getItem(position));
+                holder.swatch.getPaint().setColor(mTintArr[position]);
+                holder.swatch.getPaint().setStyle(Paint.Style.FILL_AND_STROKE);
+                holder.icon.setVisibility(View.VISIBLE);
+                holder.icon.setImageDrawable(holder.swatch);
+                return rowView;
+            }
+
+            @Override
+            public View getDropDownView(int position, View convertView, ViewGroup parent) {
+                View rowView = getView(position, convertView, parent);
+                final ViewHolder holder = (ViewHolder) rowView.getTag();
+
+                if (mTintSelectorPos == position) {
+                    holder.swatch.getPaint().setStyle(Paint.Style.FILL_AND_STROKE);
+                } else {
+                    holder.swatch.getPaint().setStyle(Paint.Style.STROKE);
+                }
+                holder.icon.setVisibility(View.VISIBLE);
+                return rowView;
+            }
+
+            private class ViewHolder {
+                TextView label;
+                ImageView icon;
+                ShapeDrawable swatch;
+            }
+        }
+
+
     }
 
     /**