summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/camera/CameraSettings.java26
-rw-r--r--src/com/android/camera/IconListPreference.java51
-rw-r--r--src/com/android/camera/IntArray.java45
-rw-r--r--src/com/android/camera/ListPreference.java17
4 files changed, 88 insertions, 51 deletions
diff --git a/src/com/android/camera/CameraSettings.java b/src/com/android/camera/CameraSettings.java
index 9641def..5abe73c 100644
--- a/src/com/android/camera/CameraSettings.java
+++ b/src/com/android/camera/CameraSettings.java
@@ -19,7 +19,6 @@ 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.media.CamcorderProfile;
@@ -247,30 +246,7 @@ public class CameraSettings {
return;
}
- 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.
- 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]));
- }
+ pref.filterUnsupported(supported);
// 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
index d4ffca0..5a8d383 100644
--- a/src/com/android/camera/IconListPreference.java
+++ b/src/com/android/camera/IconListPreference.java
@@ -19,45 +19,30 @@ 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.util.AttributeSet;
import com.android.camera.R;
+import java.util.List;
+
/** A {@code ListPreference} where each entry has a corresponding icon. */
public class IconListPreference extends ListPreference {
- private final int mIconIds[];
- private final int mLargeIconIds[];
-
- private Drawable mIcons[];
- private final Resources mResources;
+ private int mIconIds[];
+ private int mLargeIconIds[];
public IconListPreference(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(
attrs, R.styleable.IconListPreference, 0, 0);
- mResources = context.getResources();
- mIconIds = getIconIds(a.getResourceId(
+ Resources res = context.getResources();
+ mIconIds = getIconIds(res, a.getResourceId(
R.styleable.IconListPreference_icons, 0));
- mLargeIconIds = getIconIds(a.getResourceId(
+ mLargeIconIds = getIconIds(res, a.getResourceId(
R.styleable.IconListPreference_largeIcons, 0));
a.recycle();
}
- public Drawable[] getIcons() {
- if (mIcons == null) {
- int n = mIconIds.length;
- Drawable[] drawable = new Drawable[n];
- int[] id = mIconIds;
- for (int i = 0; i < n; ++i) {
- drawable[i] = id[i] == 0 ? null : mResources.getDrawable(id[i]);
- }
- mIcons = drawable;
- }
- return mIcons;
- }
-
public int[] getLargeIconIds() {
return mLargeIconIds;
}
@@ -66,9 +51,9 @@ public class IconListPreference extends ListPreference {
return mIconIds;
}
- private int[] getIconIds(int iconsRes) {
+ private int[] getIconIds(Resources res, int iconsRes) {
if (iconsRes == 0) return null;
- TypedArray array = mResources.obtainTypedArray(iconsRes);
+ TypedArray array = res.obtainTypedArray(iconsRes);
int n = array.length();
int ids[] = new int[n];
for (int i = 0; i < n; ++i) {
@@ -78,7 +63,21 @@ public class IconListPreference extends ListPreference {
return ids;
}
- public void setIcons(Drawable[] icons) {
- mIcons = icons;
+ @Override
+ public void filterUnsupported(List<String> supported) {
+ CharSequence entryValues[] = getEntryValues();
+ IntArray iconIds = new IntArray();
+ IntArray largeIconIds = new IntArray();
+
+ for (int i = 0, len = entryValues.length; i < len; i++) {
+ if (supported.indexOf(entryValues[i].toString()) >= 0) {
+ iconIds.add(mIconIds[i]);
+ largeIconIds.add(mLargeIconIds[i]);
+ }
+ }
+ int size = iconIds.size();
+ mIconIds = iconIds.toArray(new int[size]);
+ mLargeIconIds = iconIds.toArray(new int[size]);
+ super.filterUnsupported(supported);
}
}
diff --git a/src/com/android/camera/IntArray.java b/src/com/android/camera/IntArray.java
new file mode 100644
index 0000000..a2550db
--- /dev/null
+++ b/src/com/android/camera/IntArray.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2010 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;
+
+public class IntArray {
+ private static final int INIT_CAPACITY = 8;
+
+ private int mData[] = new int[INIT_CAPACITY];
+ private int mSize = 0;
+
+ public void add(int value) {
+ if (mData.length == mSize) {
+ int temp[] = new int[mSize + mSize];
+ System.arraycopy(mData, 0, temp, 0, mSize);
+ mData = temp;
+ }
+ mData[mSize++] = value;
+ }
+
+ public int size() {
+ return mSize;
+ }
+
+ public int[] toArray(int[] result) {
+ if (result == null || result.length < mSize) {
+ result = new int[mSize];
+ }
+ System.arraycopy(mData, 0, result, 0, mSize);
+ return result;
+ }
+}
diff --git a/src/com/android/camera/ListPreference.java b/src/com/android/camera/ListPreference.java
index 1402cd9..d84cc61 100644
--- a/src/com/android/camera/ListPreference.java
+++ b/src/com/android/camera/ListPreference.java
@@ -23,6 +23,9 @@ import android.util.AttributeSet;
import com.android.camera.R;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* A type of <code>CameraPreference</code> whose number of possible values
* is limited.
@@ -112,4 +115,18 @@ public class ListPreference extends CameraPreference {
public void reloadValue() {
this.mLoaded = false;
}
+
+ public void filterUnsupported(List<String> supported) {
+ ArrayList<CharSequence> entries = new ArrayList<CharSequence>();
+ ArrayList<CharSequence> entryValues = new ArrayList<CharSequence>();
+ for (int i = 0, len = mEntryValues.length; i < len; i++) {
+ if (supported.indexOf(mEntryValues[i].toString()) >= 0) {
+ entries.add(mEntries[i]);
+ entryValues.add(mEntryValues[i]);
+ }
+ }
+ int size = entries.size();
+ mEntries = entries.toArray(new CharSequence[size]);
+ mEntryValues = entryValues.toArray(new CharSequence[size]);
+ }
}