limitations under the License.
-->
<resources>
+ <declare-styleable name="CameraPreference">
+ <attr name="title" format="string" />
+ </declare-styleable>
+ <declare-styleable name="ListPreference">
+ <attr name="key" format="string" />
+ <attr name="defaultValue" format="string" />
+ <attr name="entryValues" format="reference" />
+ <attr name="entries" format="reference" />
+ </declare-styleable>
<declare-styleable name="IconIndicator">
<attr name="icons" format="reference" />
<attr name="modes" format="reference" />
limitations under the License.
-->
-<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">
- <com.android.camera.IconListPreference
- android:key="pref_camera_flashmode_key"
- android:defaultValue="@string/pref_camera_flashmode_default"
- android:title="@string/pref_camera_flashmode_title"
+<PreferenceGroup
+ xmlns:camera="http://schemas.android.com/apk/res/com.android.camera" >
+ <PreferenceGroup
+ camera:title="@string/pref_camera_settings_category">
+ <IconListPreference
+ camera:key="pref_camera_flashmode_key"
+ camera:defaultValue="@string/pref_camera_flashmode_default"
+ camera: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" />
+ camera:entries="@array/pref_camera_flashmode_entries"
+ camera:entryValues="@array/pref_camera_flashmode_entryvalues" />
<ListPreference
- android:key="pref_camera_scenemode_key"
- android:defaultValue="@string/pref_camera_scenemode_default"
- android:title="@string/pref_camera_scenemode_title"
- android:entries="@array/pref_camera_scenemode_entries"
- android:entryValues="@array/pref_camera_scenemode_entryvalues"
- android:dialogTitle="@string/pref_camera_scenemode_dialogtitle" />
- <com.android.camera.IconListPreference
- android:key="pref_camera_whitebalance_key"
- android:defaultValue="@string/pref_camera_whitebalance_default"
- android:title="@string/pref_camera_whitebalance_title"
+ camera:key="pref_camera_scenemode_key"
+ camera:defaultValue="@string/pref_camera_scenemode_default"
+ camera:title="@string/pref_camera_scenemode_title"
+ camera:entries="@array/pref_camera_scenemode_entries"
+ camera:entryValues="@array/pref_camera_scenemode_entryvalues" />
+ <IconListPreference
+ camera:key="pref_camera_whitebalance_key"
+ camera:defaultValue="@string/pref_camera_whitebalance_default"
+ camera:title="@string/pref_camera_whitebalance_title"
camera:icons="@array/pref_camera_whitebalance_icons"
- android:entries="@array/pref_camera_whitebalance_entries"
- android:entryValues="@array/pref_camera_whitebalance_entryvalues"
- android:dialogTitle="@string/pref_camera_whitebalance_dialogtitle" />
+ camera:entries="@array/pref_camera_whitebalance_entries"
+ camera:entryValues="@array/pref_camera_whitebalance_entryvalues" />
<ListPreference
- android:key="pref_camera_coloreffect_key"
- android:defaultValue="@string/pref_camera_coloreffect_default"
- android:title="@string/pref_camera_coloreffect_title"
- android:entries="@array/pref_camera_coloreffect_entries"
- android:entryValues="@array/pref_camera_coloreffect_entryvalues"
- android:dialogTitle="@string/pref_camera_coloreffect_dialogtitle" />
- <com.android.camera.RecordLocationPreference
- android:key="pref_camera_recordlocation_key"
- android:defaultValue="@string/pref_camera_recordlocation_default"
- android:title="@string/pref_camera_recordlocation_title"
- android:entries="@array/pref_camera_recordlocation_entries"
- android:entryValues="@array/pref_camera_recordlocation_entryvalues" />
+ camera:key="pref_camera_coloreffect_key"
+ camera:defaultValue="@string/pref_camera_coloreffect_default"
+ camera:title="@string/pref_camera_coloreffect_title"
+ camera:entries="@array/pref_camera_coloreffect_entries"
+ camera:entryValues="@array/pref_camera_coloreffect_entryvalues" />
+ <RecordLocationPreference
+ camera:key="pref_camera_recordlocation_key"
+ camera:defaultValue="@string/pref_camera_recordlocation_default"
+ camera:title="@string/pref_camera_recordlocation_title"
+ camera:entries="@array/pref_camera_recordlocation_entries"
+ camera:entryValues="@array/pref_camera_recordlocation_entryvalues" />
<ListPreference
- android:key="pref_camera_picturesize_key"
- android:title="@string/pref_camera_picturesize_title"
- android:entries="@array/pref_camera_picturesize_entries"
- android:entryValues="@array/pref_camera_picturesize_entryvalues"
- android:dialogTitle="@string/pref_camera_picturesize_dialogtitle" />
+ camera:key="pref_camera_picturesize_key"
+ camera:title="@string/pref_camera_picturesize_title"
+ camera:entries="@array/pref_camera_picturesize_entries"
+ camera:entryValues="@array/pref_camera_picturesize_entryvalues" />
<ListPreference
- android:key="pref_camera_jpegquality_key"
- android:defaultValue="@string/pref_camera_jpegquality_default"
- android:title="@string/pref_camera_jpegquality_title"
- android:entries="@array/pref_camera_jpegquality_entries"
- android:entryValues="@array/pref_camera_jpegquality_entryvalues"
- android:dialogTitle="@string/pref_camera_jpegquality_dialogtitle" />
- <com.android.camera.IconListPreference
- android:key="pref_camera_focusmode_key"
- android:defaultValue="@string/pref_camera_focusmode_default"
- android:title="@string/pref_camera_focusmode_title"
+ camera:key="pref_camera_jpegquality_key"
+ camera:defaultValue="@string/pref_camera_jpegquality_default"
+ camera:title="@string/pref_camera_jpegquality_title"
+ camera:entries="@array/pref_camera_jpegquality_entries"
+ camera:entryValues="@array/pref_camera_jpegquality_entryvalues" />
+ <IconListPreference
+ camera:key="pref_camera_focusmode_key"
+ camera:defaultValue="@string/pref_camera_focusmode_default"
+ camera:title="@string/pref_camera_focusmode_title"
camera:icons="@array/pref_camera_focusmode_icons"
- android:entries="@array/pref_camera_focusmode_entries"
- android:entryValues="@array/pref_camera_focusmode_entryvalues"
- android:dialogTitle="@string/pref_camera_focusmode_dialogtitle" />
- </PreferenceCategory>
-</PreferenceScreen>
+ camera:entries="@array/pref_camera_focusmode_entries"
+ camera:entryValues="@array/pref_camera_focusmode_entryvalues" />
+ </PreferenceGroup>
+</PreferenceGroup>
limitations under the License.
-->
-<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_camcorder_settings_category">
+<PreferenceGroup
+ xmlns:camera="http://schemas.android.com/apk/res/com.android.camera" >
+ <PreferenceGroup
+ camera:title="@string/pref_camcorder_settings_category">
<ListPreference
- android:key="pref_camera_videoquality_key"
- android:defaultValue="@string/pref_camera_videoquality_default"
- android:title="@string/pref_camera_videoquality_title"
- android:entries="@array/pref_camera_videoquality_entries"
- android:entryValues="@array/pref_camera_videoquality_entryvalues"
- android:dialogTitle="@string/pref_camera_videoquality_dialogtitle" />
+ camera:key="pref_camera_videoquality_key"
+ camera:defaultValue="@string/pref_camera_videoquality_default"
+ camera:title="@string/pref_camera_videoquality_title"
+ camera:entries="@array/pref_camera_videoquality_entries"
+ camera:entryValues="@array/pref_camera_videoquality_entryvalues"/>
<ListPreference
- android:key="pref_camera_video_duration_key"
- android:defaultValue="@string/pref_camera_video_duration_default"
- android:title="@string/pref_camera_video_duration_title"
- android:entries="@array/pref_camera_video_duration_entries"
- android:entryValues="@array/pref_camera_video_duration_entryvalues"
- android:dialogTitle="@string/pref_camera_video_duration_dialogtitle" />
- <com.android.camera.IconListPreference
- android:key="pref_camera_video_flashmode_key"
- android:defaultValue="@string/pref_camera_video_flashmode_default"
- android:title="@string/pref_camera_flashmode_title"
+ camera:key="pref_camera_video_duration_key"
+ camera:defaultValue="@string/pref_camera_video_duration_default"
+ camera:title="@string/pref_camera_video_duration_title"
+ camera:entries="@array/pref_camera_video_duration_entries"
+ camera:entryValues="@array/pref_camera_video_duration_entryvalues"/>
+ <IconListPreference
+ camera:key="pref_camera_video_flashmode_key"
+ camera:defaultValue="@string/pref_camera_video_flashmode_default"
+ camera:title="@string/pref_camera_flashmode_title"
camera:icons="@array/pref_camera_video_flashmode_icons"
- android:entries="@array/pref_camera_video_flashmode_entries"
- android:entryValues="@array/pref_camera_video_flashmode_entryvalues"
- android:dialogTitle="@string/pref_camera_flashmode_dialogtitle" />
- <com.android.camera.IconListPreference
- android:key="pref_camera_whitebalance_key"
- android:defaultValue="@string/pref_camera_whitebalance_default"
- android:title="@string/pref_camera_whitebalance_title"
+ camera:entries="@array/pref_camera_video_flashmode_entries"
+ camera:entryValues="@array/pref_camera_video_flashmode_entryvalues"/>
+ <IconListPreference
+ camera:key="pref_camera_whitebalance_key"
+ camera:defaultValue="@string/pref_camera_whitebalance_default"
+ camera:title="@string/pref_camera_whitebalance_title"
camera:icons="@array/pref_camera_whitebalance_icons"
- android:entries="@array/pref_camera_whitebalance_entries"
- android:entryValues="@array/pref_camera_whitebalance_entryvalues"
- android:dialogTitle="@string/pref_camera_whitebalance_dialogtitle" />
+ camera:entries="@array/pref_camera_whitebalance_entries"
+ camera:entryValues="@array/pref_camera_whitebalance_entryvalues"/>
<ListPreference
- android:key="pref_camera_coloreffect_key"
- android:defaultValue="@string/pref_camera_coloreffect_default"
- android:title="@string/pref_camera_coloreffect_title"
- android:entries="@array/pref_camera_coloreffect_entries"
- android:entryValues="@array/pref_camera_coloreffect_entryvalues"
- android:dialogTitle="@string/pref_camera_coloreffect_dialogtitle" />
- </PreferenceCategory>
-</PreferenceScreen>
+ camera:key="pref_camera_coloreffect_key"
+ camera:defaultValue="@string/pref_camera_coloreffect_default"
+ camera:title="@string/pref_camera_coloreffect_title"
+ camera:entries="@array/pref_camera_coloreffect_entries"
+ camera:entryValues="@array/pref_camera_coloreffect_entryvalues"/>
+ </PreferenceGroup>
+</PreferenceGroup>
setCameraParameters();
// We reload the preference again to reload the new data
- mSettings.setPreferenceScreen(
+ mSettings.setPreferenceGroup(
new CameraSettings(this, mParameters)
- .getPreferenceScreen(R.xml.camera_preferences));
+ .getPreferenceGroup(R.xml.camera_preferences));
mPreferences.registerOnSharedPreferenceChangeListener(this);
}
CameraSettings helper =
new CameraSettings(this, mInitialParams);
- mSettings.setPreferenceScreen(helper
- .getPreferenceScreen(R.xml.camera_preferences));
+ mSettings.setPreferenceGroup(helper
+ .getPreferenceGroup(R.xml.camera_preferences));
mSettings.setOnVisibilityChangedListener(this);
String sceneMode = mParameters.getSceneMode();
--- /dev/null
+/*
+ * 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.SharedPreferences;
+import android.content.res.TypedArray;
+import android.preference.PreferenceManager;
+import android.util.AttributeSet;
+
+/**
+ * The base class of all Preferences used in Camera. The preferences can be
+ * loaded from XML resource by <code>PreferenceInflater</code>.
+ */
+public abstract class CameraPreference {
+
+ private String mTitle;
+ private SharedPreferences mSharedPreferences;
+ private Context mContext;
+
+ public CameraPreference(Context context, AttributeSet attrs) {
+ mContext = context;
+ TypedArray a = context.obtainStyledAttributes(
+ attrs, R.styleable.CameraPreference, 0, 0);
+ mTitle = a.getString(R.styleable.CameraPreference_title);
+ a.recycle();
+ }
+
+ public String getTitle() {
+ return mTitle;
+ }
+
+ protected SharedPreferences getSharedPreferences() {
+ if (mSharedPreferences == null) {
+ mSharedPreferences =
+ PreferenceManager.getDefaultSharedPreferences(mContext);
+ }
+ return mSharedPreferences;
+ }
+}
import android.hardware.Camera.Parameters;
import android.hardware.Camera.Size;
import android.os.SystemProperties;
-import android.preference.ListPreference;
-import android.preference.Preference;
-import android.preference.PreferenceGroup;
import android.preference.PreferenceManager;
-import android.preference.PreferenceScreen;
import android.util.Log;
import java.util.ArrayList;
* Provides utilities and keys for Camera settings.
*/
public class CameraSettings {
- private static final int FIRST_REQUEST_CODE = 100;
private static final int NOT_FOUND = -1;
public static final String KEY_VERSION = "pref_version_key";
private final Context mContext;
private final Parameters mParameters;
- private final PreferenceManager mManager;
public CameraSettings(Activity activity, Parameters parameters) {
mContext = activity;
mParameters = parameters;
- mManager = new PreferenceManager(activity, FIRST_REQUEST_CODE);
}
- public PreferenceScreen getPreferenceScreen(int preferenceRes) {
- PreferenceScreen screen = mManager.createPreferenceScreen(mContext);
- mManager.inflateFromResource(mContext, preferenceRes, screen);
- initPreference(screen);
- return screen;
+ public PreferenceGroup getPreferenceGroup(int preferenceRes) {
+ PreferenceInflater inflater = new PreferenceInflater(mContext);
+ PreferenceGroup group =
+ (PreferenceGroup) inflater.inflate(preferenceRes);
+ initPreference(group);
+ return group;
}
public static void initialCameraPictureSize(
}
public static void removePreferenceFromScreen(
- PreferenceScreen screen, String key) {
- Preference pref = screen.findPreference(key);
- if (pref == null) {
- Log.i(TAG, "No preference found based the key : " + key);
- throw new IllegalArgumentException();
- } else {
- removePreference(screen, pref);
- }
+ PreferenceGroup group, String key) {
+ removePreference(group, key);
}
public static boolean setCameraPictureSize(
return false;
}
- private void initPreference(PreferenceScreen screen) {
- ListPreference videoDuration =
- (ListPreference) screen.findPreference(KEY_VIDEO_DURATION);
- ListPreference pictureSize =
- (ListPreference) screen.findPreference(KEY_PICTURE_SIZE);
- ListPreference whiteBalance =
- (ListPreference) screen.findPreference(KEY_WHITE_BALANCE);
- ListPreference colorEffect =
- (ListPreference) screen.findPreference(KEY_COLOR_EFFECT);
- ListPreference sceneMode =
- (ListPreference) screen.findPreference(KEY_SCENE_MODE);
- ListPreference flashMode =
- (ListPreference) screen.findPreference(KEY_FLASH_MODE);
- ListPreference focusMode =
- (ListPreference) screen.findPreference(KEY_FOCUS_MODE);
+ private void initPreference(PreferenceGroup group) {
+ ListPreference videoDuration = group.findPreference(KEY_VIDEO_DURATION);
+ ListPreference pictureSize = group.findPreference(KEY_PICTURE_SIZE);
+ ListPreference whiteBalance = group.findPreference(KEY_WHITE_BALANCE);
+ ListPreference colorEffect = group.findPreference(KEY_COLOR_EFFECT);
+ ListPreference sceneMode = group.findPreference(KEY_SCENE_MODE);
+ ListPreference flashMode = group.findPreference(KEY_FLASH_MODE);
+ ListPreference focusMode = group.findPreference(KEY_FOCUS_MODE);
// Since the screen could be loaded from different resources, we need
// to check if the preference is available here
// Filter out unsupported settings / options
if (pictureSize != null) {
- filterUnsupportedOptions(screen, pictureSize, sizeListToStringList(
+ filterUnsupportedOptions(group, pictureSize, sizeListToStringList(
mParameters.getSupportedPictureSizes()));
}
if (whiteBalance != null) {
- filterUnsupportedOptions(screen,
+ filterUnsupportedOptions(group,
whiteBalance, mParameters.getSupportedWhiteBalance());
}
if (colorEffect != null) {
- filterUnsupportedOptions(screen,
+ filterUnsupportedOptions(group,
colorEffect, mParameters.getSupportedColorEffects());
}
if (sceneMode != null) {
- filterUnsupportedOptions(screen,
+ filterUnsupportedOptions(group,
sceneMode, mParameters.getSupportedSceneModes());
}
if (flashMode != null) {
- filterUnsupportedOptions(screen,
+ filterUnsupportedOptions(group,
flashMode, mParameters.getSupportedFlashModes());
}
if (focusMode != null) {
- filterUnsupportedOptions(screen,
+ filterUnsupportedOptions(group,
focusMode, mParameters.getSupportedFocusModes());
}
}
- private static boolean removePreference(PreferenceGroup group,
- Preference remove) {
- if (group.removePreference(remove)) return true;
-
- for (int i = 0; i < group.getPreferenceCount(); i++) {
- final Preference child = group.getPreference(i);
+ private static boolean removePreference(PreferenceGroup group, String key) {
+ for (int i = 0, n = group.size(); i < n; i++) {
+ CameraPreference child = group.get(i);
if (child instanceof PreferenceGroup) {
- if (removePreference((PreferenceGroup) child, remove)) {
+ if (removePreference((PreferenceGroup) child, key)) {
return true;
}
}
+ if (child instanceof ListPreference &&
+ ((ListPreference) child).getKey().equals(key)) {
+ group.removePreference(i);
+ return true;
+ }
}
return false;
}
- private void filterUnsupportedOptions(PreferenceScreen screen,
+ private void filterUnsupportedOptions(PreferenceGroup group,
ListPreference pref, List<String> supported) {
CharSequence[] allEntries = pref.getEntries();
// Remove the preference if the parameter is not supported or there is
// only one options for the settings.
if (supported == null || supported.size() <= 1) {
- removePreference(screen, pref);
+ removePreference(group, pref.getKey());
return;
}
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
-import android.preference.ListPreference;
import android.util.AttributeSet;
/** A {@code ListPreference} where each entry has a corresponding icon. */
--- /dev/null
+/*
+ * 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.SharedPreferences;
+import android.content.res.TypedArray;
+import android.util.AttributeSet;
+
+/**
+ * A type of <code>CameraPreference</code> whose number of possible values
+ * is limited.
+ */
+public class ListPreference extends CameraPreference {
+
+ private String mKey;
+ private String mValue;
+ private String mDefaultValue;
+
+ private CharSequence[] mEntries;
+ private CharSequence[] mEntryValues;
+ private boolean mLoaded = false;
+
+ public ListPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+
+ TypedArray a = context.obtainStyledAttributes(
+ attrs, R.styleable.ListPreference, 0, 0);
+
+ mKey = Util.checkNotNull(
+ a.getString(R.styleable.ListPreference_key));
+ mDefaultValue = a.getString(R.styleable.ListPreference_defaultValue);
+
+ setEntries(a.getTextArray(R.styleable.ListPreference_entries));
+ setEntryValues(a.getTextArray(
+ R.styleable.ListPreference_entryValues));
+ a.recycle();
+ }
+
+ public String getKey() {
+ return mKey;
+ }
+
+ public CharSequence[] getEntries() {
+ return mEntries;
+ }
+
+ public CharSequence[] getEntryValues() {
+ return mEntryValues;
+ }
+
+ public void setEntries(CharSequence entries[]) {
+ mEntries = Util.checkNotNull(entries);
+ }
+
+ public void setEntryValues(CharSequence values[]) {
+ mEntryValues = Util.checkNotNull(values);
+ }
+
+ public String getValue() {
+ if (!mLoaded) {
+ mValue = getSharedPreferences().getString(mKey, mDefaultValue);
+ mLoaded = true;
+ }
+ return mValue;
+ }
+
+ public void setValue(String value) {
+ if (findIndexOfValue(value) < 0) throw new IllegalArgumentException();
+ mValue = value;
+ persistStringValue(value);
+ }
+
+ public void setValueIndex(int index) {
+ setValue(mEntryValues[index].toString());
+ }
+
+ public int findIndexOfValue(String value) {
+ for (int i = 0, n = mEntryValues.length; i < n; ++i) {
+ if (Util.equals(mEntryValues[i], value)) return i;
+ }
+ return -1;
+ }
+
+ public String getEntry() {
+ return mEntries[findIndexOfValue(getValue())].toString();
+ }
+
+ protected void persistStringValue(String value) {
+ SharedPreferences.Editor editor = getSharedPreferences().edit();
+ editor.putString(mKey, value);
+ editor.commit();
+ }
+}
import android.graphics.PixelFormat;
import android.os.Handler;
import android.os.Message;
-import android.preference.ListPreference;
-import android.preference.Preference;
-import android.preference.PreferenceGroup;
import android.preference.PreferenceManager;
-import android.preference.PreferenceScreen;
import android.util.Log;
import android.view.Display;
import android.view.Gravity;
// Add the preference and it's children recursively to the given list. So
// that we can show the preference (and it's children) in the list view.
private static void addPreference(
- Preference preference, ArrayList<Preference> list) {
+ CameraPreference preference, ArrayList<CameraPreference> list) {
list.add(preference);
if (preference instanceof PreferenceGroup) {
PreferenceGroup group = (PreferenceGroup) preference;
- for (int i = 0, n = group.getPreferenceCount(); i < n; ++i) {
- Preference child = group.getPreference(i);
+ for (int i = 0, n = group.size(); i < n; ++i) {
+ CameraPreference child = group.get(i);
addPreference(child, list);
}
}
}
- public void setPreferenceScreen(PreferenceScreen screen) {
- ArrayList<Preference> list = new ArrayList<Preference>();
+ public void setPreferenceGroup(PreferenceGroup group) {
+ ArrayList<CameraPreference> list = new ArrayList<CameraPreference>();
- // We don't want the screen add to the list, we add the first level
- // preference here.
- for (int i = 0, n = screen.getPreferenceCount(); i < n; ++i) {
- addPreference(screen.getPreference(i), list);
+ // We don't want the root group added to the list. So, we add the
+ // children of the root here
+ for (int i = 0, n = group.size(); i < n; ++i) {
+ addPreference(group.get(i), list);
}
mMainAdapter = new MainMenuAdapter(mContext, list);
mMainMenu.setAdapter(mMainAdapter);
private class MainMenuAdapter extends BaseAdapter
implements OnItemClickListener {
- private final ArrayList<Preference> mPreferences;
+ private final ArrayList<CameraPreference> mPreferences;
public MainMenuAdapter(
- Context context, ArrayList<Preference> preferences) {
+ Context context, ArrayList<CameraPreference> preferences) {
mPreferences = preferences;
}
AdapterView<?> parent, View view, int position, long id) {
// If not the last item (restore settings)
if (position < mPreferences.size()) {
- Preference preference = mPreferences.get(position);
+ CameraPreference preference = mPreferences.get(position);
SubMenuAdapter adapter = new SubMenuAdapter(
mContext, (ListPreference) preference);
mSubMenu.setAdapter(adapter);
return convertView;
}
- Preference preference = mPreferences.get(position);
-
+ CameraPreference preference = mPreferences.get(position);
if (preference instanceof PreferenceGroup) {
convertView = inflateIfNeed(convertView,
R.layout.on_screen_menu_header, parent, false);
convertView = inflateIfNeed(convertView,
R.layout.on_screen_menu_list_item, parent, false);
- String override = mOverride.get(preference.getKey());
+ String override = mOverride.get(
+ ((ListPreference) preference).getKey());
TextView title = (TextView)
convertView.findViewById(R.id.title);
title.setText(preference.getTitle());
// The last item (restore default)
if (position == mPreferences.size()) return true;
- Preference preference = mPreferences.get(position);
+ CameraPreference preference = mPreferences.get(position);
return !(preference instanceof PreferenceGroup);
}
@Override
public int getItemViewType(int position) {
if (position == mPreferences.size()) return 1;
- Preference pref = mPreferences.get(position);
+ CameraPreference pref = mPreferences.get(position);
if (pref instanceof PreferenceGroup) return 0;
if (pref instanceof ListPreference) return 1;
throw new IllegalStateException();
convertView = inflateIfNeed(convertView,
R.layout.on_screen_menu_header, parent, false);
((TextView) convertView.findViewById(
- R.id.title)).setText(mPreference.getDialogTitle());
+ R.id.title)).setText(mPreference.getTitle());
} else {
int index = position - 1;
convertView = inflateIfNeed(convertView,
--- /dev/null
+/*
+ * 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 java.util.ArrayList;
+
+import android.content.Context;
+import android.util.AttributeSet;
+
+/**
+ * A collection of <code>CameraPreference</code>s. It may contain other
+ * <code>PreferenceGroup</code> and form a tree structure.
+ */
+public class PreferenceGroup extends CameraPreference {
+ private ArrayList<CameraPreference> list =
+ new ArrayList<CameraPreference>();
+
+ public PreferenceGroup(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public void addChild(CameraPreference child) {
+ list.add(child);
+ }
+
+ public void removePreference(int index) {
+ list.remove(index);
+ }
+
+ public CameraPreference get(int index) {
+ return list.get(index);
+ }
+
+ public int size() {
+ return list.size();
+ }
+
+ /**
+ * Finds the preference with the given key recursively. Returns
+ * <code>null</code> if cannot find.
+ */
+ public ListPreference findPreference(String key) {
+ // Find a leaf preference with the given key. Currently, the base
+ // type of all "leaf" preference is "ListPreference". If we add some
+ // other types later, we need to change the code.
+ for (CameraPreference pref : list) {
+ if (pref instanceof ListPreference) {
+ ListPreference listPref = (ListPreference) pref;
+ if(listPref.getKey().equals(key)) return listPref;
+ } else if(pref instanceof PreferenceGroup) {
+ ListPreference listPref =
+ ((PreferenceGroup) pref).findPreference(key);
+ if (listPref != null) return listPref;
+ }
+ }
+ return null;
+ }
+}
--- /dev/null
+/*
+ * 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;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.util.Xml;
+import android.view.InflateException;
+
+/**
+ * Inflate <code>CameraPreference</code> from XML resource.
+ */
+public class PreferenceInflater {
+ private static final String PACKAGE_NAME =
+ PreferenceInflater.class.getPackage().getName();
+
+ private static final Class<?>[] CTOR_SIGNATURE =
+ new Class[] {Context.class, AttributeSet.class};
+ private static final HashMap<String, Constructor<?>> sConstructorMap =
+ new HashMap<String, Constructor<?>>();
+
+ private Context mContext;
+
+ public PreferenceInflater(Context context) {
+ mContext = context;
+ }
+
+ public CameraPreference inflate(int resId) {
+ return inflate(mContext.getResources().getXml(resId));
+ }
+
+ private CameraPreference newPreference(String tagName, Object[] args) {
+ String name = PACKAGE_NAME + "." + tagName;
+ Constructor<?> constructor = sConstructorMap.get(name);
+ try {
+ if (constructor == null) {
+ // Class not found in the cache, see if it's real, and try to
+ // add it
+ Class<?> clazz = mContext.getClassLoader().loadClass(name);
+ constructor = clazz.getConstructor(CTOR_SIGNATURE);
+ sConstructorMap.put(name, constructor);
+ }
+ return (CameraPreference) constructor.newInstance(args);
+ } catch (NoSuchMethodException e) {
+ throw new InflateException("Error inflating class " + name, e);
+ } catch (ClassNotFoundException e) {
+ throw new InflateException("No such class: " + name, e);
+ } catch (Exception e) {
+ throw new InflateException("While create instance of" + name, e);
+ }
+ }
+
+ private CameraPreference inflate(XmlPullParser parser) {
+
+ AttributeSet attrs = Xml.asAttributeSet(parser);
+ ArrayList<CameraPreference> list = new ArrayList<CameraPreference>();
+ Object args[] = new Object[]{mContext, attrs};
+
+ try {
+ for (int type = parser.next();
+ type != XmlPullParser.END_DOCUMENT; type = parser.next()) {
+ if (type != XmlPullParser.START_TAG) continue;
+ CameraPreference pref = newPreference(parser.getName(), args);
+
+ int depth = parser.getDepth();
+ if (depth > list.size()) {
+ list.add(pref);
+ } else {
+ list.set(depth - 1, pref);
+ }
+ if (depth > 1) {
+ ((PreferenceGroup) list.get(depth - 2)).addChild(pref);
+ }
+ }
+
+ if (list.size() == 0) {
+ throw new InflateException("No root element found");
+ }
+ return list.get(0);
+ } catch (XmlPullParserException e) {
+ throw new InflateException(e);
+ } catch (IOException e) {
+ throw new InflateException(parser.getPositionDescription(), e);
+ }
+ }
+}
import android.content.Context;
import android.content.ContentResolver;
import android.content.SharedPreferences;
-import android.preference.ListPreference;
import android.provider.Settings;
import android.util.AttributeSet;
import android.util.Log;
return get(getSharedPreferences(), mResolver) ? VALUE_ON : VALUE_OFF;
}
- @Override
- public CharSequence getEntry() {
- return getEntries()[findIndexOfValue(getValue())];
- }
-
public static boolean get(
SharedPreferences pref, ContentResolver resolver) {
String value = pref.getString(KEY, VALUE_NONE);
view.startAnimation(anim);
return anim;
}
+
+ public static <T> T checkNotNull(T object) {
+ if (object == null) throw new NullPointerException();
+ return object;
+ }
+
+ public static boolean equals(Object a, Object b) {
+ return (a == b) || (a == null ? false : a.equals(b));
+ }
}
import android.os.SystemClock;
import android.os.SystemProperties;
import android.preference.PreferenceManager;
-import android.preference.PreferenceScreen;
import android.provider.MediaStore;
import android.provider.MediaStore.Video;
import android.provider.Settings;
mHandler.post(new Runnable() {
public void run() {
// We reload the preference again to reload the new data
- mSettings.setPreferenceScreen(
+ mSettings.setPreferenceGroup(
new CameraSettings(VideoCamera.this, mParameters)
- .getPreferenceScreen(R.xml.video_preferences));
+ .getPreferenceGroup(R.xml.video_preferences));
}
});
mPreferences.registerOnSharedPreferenceChangeListener(this);
mSettings.setRestoreRunner(resetPreferences);
CameraSettings helper = new CameraSettings(this, mParameters);
- PreferenceScreen screen = helper
- .getPreferenceScreen(R.xml.video_preferences);
+ PreferenceGroup group = helper
+ .getPreferenceGroup(R.xml.video_preferences);
if (mIsVideoCaptureIntent) {
- screen = filterPreferenceScreenByIntent(screen);
+ group = filterPreferenceScreenByIntent(group);
}
- mSettings.setPreferenceScreen(screen);
+ mSettings.setPreferenceGroup(group);
mSettings.setOnVisibilityChangedListener(this);
}
mSettings.setVisible(true);
}
- private PreferenceScreen filterPreferenceScreenByIntent(
- PreferenceScreen screen) {
+ private PreferenceGroup filterPreferenceScreenByIntent(
+ PreferenceGroup screen) {
Intent intent = getIntent();
if (intent.hasExtra(MediaStore.EXTRA_VIDEO_QUALITY)) {
CameraSettings.removePreferenceFromScreen(screen,