summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCheng-Ru Lin <owenlin@google.com>2009-10-01 02:29:55 +0800
committerCheng-Ru Lin <owenlin@google.com>2009-10-01 08:36:13 +0800
commit2f3774c974a5a044a3b32ca68182a3f2180d0124 (patch)
tree72a6ce29ae1bab6508058df80ad0b4e7cf7b262f
parent25156f0e1bb921d3d8f7f5cc51e141522533b502 (diff)
downloadpackages_apps_LegacyCamera-2f3774c974a5a044a3b32ca68182a3f2180d0124.zip
packages_apps_LegacyCamera-2f3774c974a5a044a3b32ca68182a3f2180d0124.tar.gz
packages_apps_LegacyCamera-2f3774c974a5a044a3b32ca68182a3f2180d0124.tar.bz2
Revert "Revert "Add icon support for options in preference setting screen.""
This reverts commit 7af25641ec401d9f669497bd401020f2cb5933ef. Change-Id: I03381ffeee4aca787ea376bcd5fe150ff0f97dbf
-rw-r--r--res/layout/on_screen_submenu_item.xml6
-rw-r--r--res/values/arrays.xml6
-rw-r--r--res/values/attrs.xml3
-rw-r--r--res/xml/camera_preferences.xml6
-rw-r--r--src/com/android/camera/CameraSettings.java17
-rw-r--r--src/com/android/camera/IconListPreference.java58
-rw-r--r--src/com/android/camera/OnScreenSettings.java24
7 files changed, 110 insertions, 10 deletions
diff --git a/res/layout/on_screen_submenu_item.xml b/res/layout/on_screen_submenu_item.xml
index f5079b3..8e0470e 100644
--- a/res/layout/on_screen_submenu_item.xml
+++ b/res/layout/on_screen_submenu_item.xml
@@ -20,6 +20,12 @@
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical" >
+ <ImageView android:id="@+id/icon"
+ android:visibility="gone"
+ android:layout_marginRight="5dp"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_weight="0" />
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index 41e8dfe..aad2bad 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -103,6 +103,12 @@
<item>off</item>
</string-array>
+ <array name="pref_camera_flashmode_icons">
+ <item>@drawable/ic_viewfinder_flash_auto</item>
+ <item>0</item>
+ <item>@drawable/ic_viewfinder_flash_on</item>
+ </array>
+
<string-array name="pref_camera_recordlocation_entryvalues" translatable="false">
<item>false</item>
<item>true</item>
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index c780b7f..96f4ebf 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -18,6 +18,9 @@
<attr name="icons" format="reference" />
<attr name="modes" format="reference" />
</declare-styleable>
+ <declare-styleable name="IconListPreference">
+ <attr name="icons" />
+ </declare-styleable>
<declare-styleable name="EvenlySpacedLayout">
<attr name="orientation">
<enum name="horizontal" value="0" />
diff --git a/res/xml/camera_preferences.xml b/res/xml/camera_preferences.xml
index aae592a..edcb23f 100644
--- a/res/xml/camera_preferences.xml
+++ b/res/xml/camera_preferences.xml
@@ -14,12 +14,14 @@
limitations under the License.
-->
-<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:camera="http://schemas.android.com/apk/res/com.android.camera">
<PreferenceCategory android:title="@string/pref_camera_settings_category">
- <ListPreference
+ <com.android.camera.IconListPreference
android:key="pref_camera_flashmode_key"
android:defaultValue="@string/pref_camera_flashmode_default"
android:title="@string/pref_camera_flashmode_title"
+ camera:icons="@array/pref_camera_flashmode_icons"
android:entries="@array/pref_camera_flashmode_entries"
android:entryValues="@array/pref_camera_flashmode_entryvalues"
android:dialogTitle="@string/pref_camera_flashmode_dialogtitle" />
diff --git a/src/com/android/camera/CameraSettings.java b/src/com/android/camera/CameraSettings.java
index d81756d..e4737be 100644
--- a/src/com/android/camera/CameraSettings.java
+++ b/src/com/android/camera/CameraSettings.java
@@ -3,6 +3,7 @@ package com.android.camera;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
+import android.graphics.drawable.Drawable;
import android.hardware.Camera.Parameters;
import android.hardware.Camera.Size;
import android.os.SystemProperties;
@@ -187,19 +188,29 @@ public class CameraSettings {
// Prepare setting entries and entry values.
CharSequence[] allEntries = pref.getEntries();
CharSequence[] allEntryValues = pref.getEntryValues();
+ Drawable[] allIcons = (pref instanceof IconListPreference)
+ ? ((IconListPreference) pref).getIcons()
+ : null;
ArrayList<CharSequence> entries = new ArrayList<CharSequence>();
ArrayList<CharSequence> entryValues = new ArrayList<CharSequence>();
+ ArrayList<Drawable> icons =
+ allIcons == null ? null : new ArrayList<Drawable>();
for (int i = 0, len = allEntryValues.length; i < len; i++) {
if (supported.indexOf(allEntryValues[i].toString()) != NOT_FOUND) {
entries.add(allEntries[i]);
entryValues.add(allEntryValues[i]);
+ if (allIcons != null) icons.add(allIcons[i]);
}
}
// Set entries and entry values to list preference.
- pref.setEntries(entries.toArray(new CharSequence[entries.size()]));
- pref.setEntryValues(entryValues.toArray(
- new CharSequence[entryValues.size()]));
+ int size = entries.size();
+ pref.setEntries(entries.toArray(new CharSequence[size]));
+ pref.setEntryValues(entryValues.toArray(new CharSequence[size]));
+ if (allIcons != null) {
+ ((IconListPreference) pref)
+ .setIcons(icons.toArray(new Drawable[size]));
+ }
// Set the value to the first entry if it is invalid.
String value = pref.getValue();
diff --git a/src/com/android/camera/IconListPreference.java b/src/com/android/camera/IconListPreference.java
new file mode 100644
index 0000000..314b7a9
--- /dev/null
+++ b/src/com/android/camera/IconListPreference.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2009 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.
+ */
+
+package com.android.camera;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.content.res.TypedArray;
+import android.graphics.drawable.Drawable;
+import android.preference.ListPreference;
+import android.util.AttributeSet;
+
+public class IconListPreference extends ListPreference {
+ private Drawable mIcons[];
+ private Resources mResources;
+
+ public IconListPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ TypedArray a = context.obtainStyledAttributes(
+ attrs, R.styleable.IconListPreference, 0, 0);
+ mResources = context.getResources();
+ setIcons(a.getResourceId(R.styleable.IconListPreference_icons, 0));
+ a.recycle();
+ }
+
+ public Drawable[] getIcons() {
+ return mIcons;
+ }
+
+ private void setIcons(int iconsRes) {
+ TypedArray array = mResources.obtainTypedArray(iconsRes);
+ int n = array.length();
+ Drawable drawable[] = new Drawable[n];
+ for (int i = 0; i < n; ++i) {
+ int id = array.getResourceId(i, 0);
+ drawable[i] = id == 0 ? null : mResources.getDrawable(id);
+ }
+ array.recycle();
+ mIcons = drawable;
+ }
+
+ public void setIcons(Drawable[] icons) {
+ mIcons = icons;
+ }
+}
diff --git a/src/com/android/camera/OnScreenSettings.java b/src/com/android/camera/OnScreenSettings.java
index 40518a7..798b904 100644
--- a/src/com/android/camera/OnScreenSettings.java
+++ b/src/com/android/camera/OnScreenSettings.java
@@ -22,6 +22,7 @@ import android.view.WindowManager.LayoutParams;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
+import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.TextView;
@@ -329,9 +330,13 @@ public class OnScreenSettings {
private class SubMenuAdapter extends BaseAdapter
implements OnItemClickListener {
private final ListPreference mPreference;
+ private final IconListPreference mIconPreference;
public SubMenuAdapter(Context context, ListPreference preference) {
mPreference = preference;
+ mIconPreference = (preference instanceof IconListPreference)
+ ? (IconListPreference) preference
+ : null;
}
public View getView(int position, View convertView, ViewGroup parent) {
@@ -342,15 +347,24 @@ public class OnScreenSettings {
((TextView) convertView.findViewById(
R.id.title)).setText(mPreference.getDialogTitle());
} else {
+ int index = position - 1;
convertView = inflateIfNeed(convertView,
R.layout.on_screen_submenu_item, parent, false);
boolean checked = mPreference.getValue().equals(
- mPreference.getEntryValues()[position - 1]);
+ mPreference.getEntryValues()[index]);
((TextView) convertView.findViewById(
- R.id.title)).setText(entry[position - 1]);
- RadioButton radio = ((RadioButton)
- convertView.findViewById(R.id.radio_button));
- radio.setChecked(checked);
+ R.id.title)).setText(entry[index]);
+ ((RadioButton) convertView.findViewById(
+ R.id.radio_button)).setChecked(checked);
+ ImageView icon = (ImageView)
+ convertView.findViewById(R.id.icon);
+ if (mIconPreference != null) {
+ icon.setVisibility(View.VISIBLE);
+ icon.setImageDrawable(
+ mIconPreference.getIcons()[position-1]);
+ } else {
+ icon.setVisibility(View.GONE);
+ }
}
return convertView;
}