diff options
Diffstat (limited to 'src/com/android')
-rw-r--r-- | src/com/android/camera/CameraSettings.java | 17 | ||||
-rw-r--r-- | src/com/android/camera/IconListPreference.java | 58 | ||||
-rw-r--r-- | src/com/android/camera/OnScreenSettings.java | 24 |
3 files changed, 91 insertions, 8 deletions
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; } |