Adding icons to sim color selection in settings UI.
Adding icons to sim color selection of sim settings UI. Bug: 18380838 Change-Id: I98f07721aa234ff58a64a0c694206b085385bdec
This commit is contained in:
@@ -21,7 +21,6 @@
|
|||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:padding="@dimen/sim_dialog_padding"
|
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<LinearLayout android:id="@+id/type"
|
<LinearLayout android:id="@+id/type"
|
||||||
@@ -33,19 +32,20 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="@dimen/sim_dialog_margin_top"
|
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_name"
|
android:text="@string/sim_editor_name" />
|
||||||
style="?android:attr/textAppearanceMedium" />
|
|
||||||
|
|
||||||
<EditText android:id="@+id/sim_name"
|
<EditText android:id="@+id/sim_name"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
android:layout_marginStart="@dimen/sim_content_padding"
|
android:paddingStart="@dimen/sim_content_padding"
|
||||||
android:paddingBottom="@dimen/sim_dialog_margin_bottom"
|
android:paddingBottom="@dimen/sim_dialog_margin_bottom"
|
||||||
android:hint="@string/wifi_ssid_hint"
|
android:hint="@string/wifi_ssid_hint"
|
||||||
android:inputType="textNoSuggestions"
|
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>
|
</LinearLayout>
|
||||||
|
|
||||||
@@ -58,16 +58,14 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="@dimen/sim_dialog_margin_top"
|
android:layout_marginTop="@dimen/sim_dialog_margin_top"
|
||||||
android:paddingStart="@dimen/sim_label_padding"
|
android:paddingStart="@dimen/sim_content_padding"
|
||||||
android:text="@string/color_title"
|
android:text="@string/color_title" />
|
||||||
style="?android:attr/textAppearanceMedium" />
|
|
||||||
|
|
||||||
<Spinner
|
<Spinner
|
||||||
android:id="@+id/spinner"
|
android:id="@+id/spinner"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="@dimen/color_picker_width"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="@dimen/sim_dialog_margin_top"
|
android:paddingStart="@dimen/sim_content_padding" />
|
||||||
android:paddingStart="@dimen/sim_label_padding" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
@@ -80,14 +78,14 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="@dimen/sim_dialog_margin_top"
|
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" />
|
android:text="@string/sim_editor_carrier" />
|
||||||
|
|
||||||
<TextView android:id="@+id/carrier"
|
<TextView android:id="@+id/carrier"
|
||||||
android:textColor="@android:color/black"
|
android:textColor="@android:color/black"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
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:paddingBottom="@dimen/sim_dialog_margin_bottom"
|
||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
style="?android:attr/textAppearanceMedium" />
|
style="?android:attr/textAppearanceMedium" />
|
||||||
@@ -103,14 +101,14 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="@dimen/sim_dialog_margin_top"
|
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" />
|
android:text="@string/sim_editor_number" />
|
||||||
|
|
||||||
<TextView android:id="@+id/number"
|
<TextView android:id="@+id/number"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingBottom="@dimen/sim_dialog_margin_bottom"
|
android:paddingBottom="@dimen/sim_dialog_margin_bottom"
|
||||||
android:paddingStart="@dimen/sim_label_padding"
|
android:paddingStart="@dimen/sim_content_padding"
|
||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
android:textColor="@android:color/black"
|
android:textColor="@android:color/black"
|
||||||
style="?android:attr/textAppearanceMedium" />
|
style="?android:attr/textAppearanceMedium" />
|
||||||
|
@@ -19,8 +19,7 @@
|
|||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="?android:attr/selectableItemBackground"
|
android:background="?android:attr/selectableItemBackground" >
|
||||||
android:padding="4dp" >
|
|
||||||
|
|
||||||
<ImageView android:id="@+id/icon"
|
<ImageView android:id="@+id/icon"
|
||||||
android:layout_width="48dp"
|
android:layout_width="48dp"
|
||||||
|
47
res/layout/settings_color_picker_item.xml
Normal file
47
res/layout/settings_color_picker_item.xml
Normal file
@@ -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>
|
@@ -205,7 +205,7 @@
|
|||||||
<!-- SIM Dialog padding -->
|
<!-- SIM Dialog padding -->
|
||||||
<dimen name="sim_dialog_padding">8dip</dimen>
|
<dimen name="sim_dialog_padding">8dip</dimen>
|
||||||
<dimen name="sim_label_padding">16dip</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 -->
|
<!-- Sim Card Name length -->
|
||||||
<integer name="sim_name_length">32</integer>
|
<integer name="sim_name_length">32</integer>
|
||||||
|
|
||||||
@@ -227,4 +227,9 @@
|
|||||||
|
|
||||||
<dimen name="wifi_divider_height">1px</dimen>
|
<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>
|
</resources>
|
||||||
|
@@ -22,7 +22,10 @@ import android.content.ContentUris;
|
|||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
import android.graphics.Paint;
|
||||||
import android.graphics.drawable.BitmapDrawable;
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
|
import android.graphics.drawable.ShapeDrawable;
|
||||||
|
import android.graphics.drawable.shapes.OvalShape;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
@@ -415,8 +418,10 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable
|
|||||||
private class SimPreference extends Preference{
|
private class SimPreference extends Preference{
|
||||||
private SubscriptionInfo mSubInfoRecord;
|
private SubscriptionInfo mSubInfoRecord;
|
||||||
private int mSlotId;
|
private int mSlotId;
|
||||||
private int[] tintArr;
|
private int[] mTintArr;
|
||||||
Context mContext;
|
Context mContext;
|
||||||
|
private String[] mColorStrings;
|
||||||
|
private int mTintSelectorPos;
|
||||||
|
|
||||||
public SimPreference(Context context, SubscriptionInfo subInfoRecord, int slotId) {
|
public SimPreference(Context context, SubscriptionInfo subInfoRecord, int slotId) {
|
||||||
super(context);
|
super(context);
|
||||||
@@ -426,7 +431,9 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable
|
|||||||
mSlotId = slotId;
|
mSlotId = slotId;
|
||||||
setKey("sim" + mSlotId);
|
setKey("sim" + mSlotId);
|
||||||
update();
|
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() {
|
public void update() {
|
||||||
@@ -467,14 +474,15 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable
|
|||||||
nameText.setText(mSubInfoRecord.getDisplayName());
|
nameText.setText(mSubInfoRecord.getDisplayName());
|
||||||
|
|
||||||
final Spinner tintSpinner = (Spinner) dialogLayout.findViewById(R.id.spinner);
|
final Spinner tintSpinner = (Spinner) dialogLayout.findViewById(R.id.spinner);
|
||||||
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getContext(),
|
SelectColorAdapter adapter = new SelectColorAdapter(getContext(),
|
||||||
R.array.color_picker, android.R.layout.simple_spinner_item);
|
R.layout.settings_color_picker_item, mColorStrings);
|
||||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||||
tintSpinner.setAdapter(adapter);
|
tintSpinner.setAdapter(adapter);
|
||||||
|
|
||||||
for (int i = 0; i < tintArr.length; i++) {
|
for (int i = 0; i < mTintArr.length; i++) {
|
||||||
if (tintArr[i] == mSubInfoRecord.getIconTint()) {
|
if (mTintArr[i] == mSubInfoRecord.getIconTint()) {
|
||||||
tintSpinner.setSelection(i);
|
tintSpinner.setSelection(i);
|
||||||
|
mTintSelectorPos = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -484,6 +492,7 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable
|
|||||||
public void onItemSelected(AdapterView<?> parent, View view,
|
public void onItemSelected(AdapterView<?> parent, View view,
|
||||||
int pos, long id){
|
int pos, long id){
|
||||||
tintSpinner.setSelection(pos);
|
tintSpinner.setSelection(pos);
|
||||||
|
mTintSelectorPos = pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -519,7 +528,7 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable
|
|||||||
|
|
||||||
final int tintSelected = tintSpinner.getSelectedItemPosition();
|
final int tintSelected = tintSpinner.getSelectedItemPosition();
|
||||||
int subscriptionId = mSubInfoRecord.getSubscriptionId();
|
int subscriptionId = mSubInfoRecord.getSubscriptionId();
|
||||||
int tint = tintArr[tintSelected];
|
int tint = mTintArr[tintSelected];
|
||||||
mSubInfoRecord.setIconTint(tint);
|
mSubInfoRecord.setIconTint(tint);
|
||||||
SubscriptionManager.setIconTint(tint, subscriptionId);
|
SubscriptionManager.setIconTint(tint, subscriptionId);
|
||||||
Utils.findRecordBySubId(subscriptionId).setIconTint(tint);
|
Utils.findRecordBySubId(subscriptionId).setIconTint(tint);
|
||||||
@@ -538,6 +547,76 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable
|
|||||||
|
|
||||||
builder.create().show();
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user