diff options
author | Owen Lin <owenlin@google.com> | 2010-01-20 06:37:36 +0800 |
---|---|---|
committer | Owen Lin <owenlin@google.com> | 2010-01-25 10:37:05 -0800 |
commit | 73e782de608cbe2ddffd75c055009ff2e208f78b (patch) | |
tree | cae88b5801e3f9aa6364774cf47a72b06d936459 /src/com | |
parent | a9c2f922763d3f7d19c237f9c5bd46611b5076fd (diff) | |
download | LegacyCamera-73e782de608cbe2ddffd75c055009ff2e208f78b.zip LegacyCamera-73e782de608cbe2ddffd75c055009ff2e208f78b.tar.gz LegacyCamera-73e782de608cbe2ddffd75c055009ff2e208f78b.tar.bz2 |
Unbundle with the PreferenceManager.
Change-Id: Ib415bf36147f35cbf1681cd87514124822ac48c6
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/camera/Camera.java | 8 | ||||
-rw-r--r-- | src/com/android/camera/CameraPreference.java | 54 | ||||
-rw-r--r-- | src/com/android/camera/CameraSettings.java | 83 | ||||
-rw-r--r-- | src/com/android/camera/IconListPreference.java | 1 | ||||
-rw-r--r-- | src/com/android/camera/ListPreference.java | 108 | ||||
-rw-r--r-- | src/com/android/camera/OnScreenSettings.java | 40 | ||||
-rw-r--r-- | src/com/android/camera/PreferenceGroup.java | 72 | ||||
-rw-r--r-- | src/com/android/camera/PreferenceInflater.java | 108 | ||||
-rw-r--r-- | src/com/android/camera/RecordLocationPreference.java | 6 | ||||
-rw-r--r-- | src/com/android/camera/Util.java | 9 | ||||
-rw-r--r-- | src/com/android/camera/VideoCamera.java | 17 |
11 files changed, 414 insertions, 92 deletions
diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java index 8155885..92389b7 100644 --- a/src/com/android/camera/Camera.java +++ b/src/com/android/camera/Camera.java @@ -1085,9 +1085,9 @@ public class Camera extends NoSearchActivity implements View.OnClickListener, 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); } @@ -1106,8 +1106,8 @@ public class Camera extends NoSearchActivity implements View.OnClickListener, 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(); diff --git a/src/com/android/camera/CameraPreference.java b/src/com/android/camera/CameraPreference.java new file mode 100644 index 0000000..e44700b --- /dev/null +++ b/src/com/android/camera/CameraPreference.java @@ -0,0 +1,54 @@ +/* + * 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; + } +} diff --git a/src/com/android/camera/CameraSettings.java b/src/com/android/camera/CameraSettings.java index d8a0e91..fd5cfc6 100644 --- a/src/com/android/camera/CameraSettings.java +++ b/src/com/android/camera/CameraSettings.java @@ -23,11 +23,7 @@ import android.graphics.drawable.Drawable; 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; @@ -37,7 +33,6 @@ import java.util.List; * 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"; @@ -73,19 +68,18 @@ public class CameraSettings { 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( @@ -109,14 +103,8 @@ public class CameraSettings { } 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( @@ -134,21 +122,14 @@ public class CameraSettings { 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 @@ -163,47 +144,49 @@ public class CameraSettings { // 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(); @@ -211,7 +194,7 @@ public class CameraSettings { // 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; } diff --git a/src/com/android/camera/IconListPreference.java b/src/com/android/camera/IconListPreference.java index 9e8109e..25c641c 100644 --- a/src/com/android/camera/IconListPreference.java +++ b/src/com/android/camera/IconListPreference.java @@ -20,7 +20,6 @@ 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; /** A {@code ListPreference} where each entry has a corresponding icon. */ diff --git a/src/com/android/camera/ListPreference.java b/src/com/android/camera/ListPreference.java new file mode 100644 index 0000000..4076277 --- /dev/null +++ b/src/com/android/camera/ListPreference.java @@ -0,0 +1,108 @@ +/* + * 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(); + } +} diff --git a/src/com/android/camera/OnScreenSettings.java b/src/com/android/camera/OnScreenSettings.java index 49f07af..83eb2b9 100644 --- a/src/com/android/camera/OnScreenSettings.java +++ b/src/com/android/camera/OnScreenSettings.java @@ -21,11 +21,7 @@ import android.content.SharedPreferences; 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; @@ -276,24 +272,24 @@ public class OnScreenSettings { // 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); @@ -308,10 +304,10 @@ public class OnScreenSettings { 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; } @@ -319,7 +315,7 @@ public class OnScreenSettings { 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); @@ -351,8 +347,7 @@ public class OnScreenSettings { 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); @@ -363,7 +358,8 @@ public class OnScreenSettings { 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()); @@ -394,7 +390,7 @@ public class OnScreenSettings { // 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); } @@ -414,7 +410,7 @@ public class OnScreenSettings { @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(); @@ -455,7 +451,7 @@ public class OnScreenSettings { 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, diff --git a/src/com/android/camera/PreferenceGroup.java b/src/com/android/camera/PreferenceGroup.java new file mode 100644 index 0000000..d4972f8 --- /dev/null +++ b/src/com/android/camera/PreferenceGroup.java @@ -0,0 +1,72 @@ +/* + * 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; + } +} diff --git a/src/com/android/camera/PreferenceInflater.java b/src/com/android/camera/PreferenceInflater.java new file mode 100644 index 0000000..b0c92de --- /dev/null +++ b/src/com/android/camera/PreferenceInflater.java @@ -0,0 +1,108 @@ +/* + * 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); + } + } +} diff --git a/src/com/android/camera/RecordLocationPreference.java b/src/com/android/camera/RecordLocationPreference.java index 6a668e7..552e739 100644 --- a/src/com/android/camera/RecordLocationPreference.java +++ b/src/com/android/camera/RecordLocationPreference.java @@ -19,7 +19,6 @@ package com.android.camera; 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; @@ -48,11 +47,6 @@ public class RecordLocationPreference extends ListPreference { 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); diff --git a/src/com/android/camera/Util.java b/src/com/android/camera/Util.java index 4492091..362914a 100644 --- a/src/com/android/camera/Util.java +++ b/src/com/android/camera/Util.java @@ -352,4 +352,13 @@ public class Util { 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)); + } } diff --git a/src/com/android/camera/VideoCamera.java b/src/com/android/camera/VideoCamera.java index 333b2a9..a2e490c 100644 --- a/src/com/android/camera/VideoCamera.java +++ b/src/com/android/camera/VideoCamera.java @@ -42,7 +42,6 @@ import android.os.StatFs; 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; @@ -1085,9 +1084,9 @@ public class VideoCamera extends NoSearchActivity 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); @@ -1105,20 +1104,20 @@ public class VideoCamera extends NoSearchActivity 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, |