diff options
author | Wu-cheng Li <wuchengli@google.com> | 2010-12-06 19:39:55 +0800 |
---|---|---|
committer | Wu-cheng Li <wuchengli@google.com> | 2010-12-08 17:21:20 +0800 |
commit | 003dd5a52457c024a0f99a2bb222bfc6ad70bbe5 (patch) | |
tree | 952554b326cb6c46c59f424c17740bb556fdc905 | |
parent | 5030bd7b700869feb50083571a680fa55730229b (diff) | |
download | LegacyCamera-003dd5a52457c024a0f99a2bb222bfc6ad70bbe5.zip LegacyCamera-003dd5a52457c024a0f99a2bb222bfc6ad70bbe5.tar.gz LegacyCamera-003dd5a52457c024a0f99a2bb222bfc6ad70bbe5.tar.bz2 |
Add restore default in other settings.
Also change the theme to Holo.
bug:3156672
Change-Id: Ied6f2d3543c3a3282c62b2cc31e5cf4cc30c3172
-rw-r--r-- | res/layout-xlarge/other_setting_popup.xml | 6 | ||||
-rw-r--r-- | res/values-xlarge/styles.xml | 2 | ||||
-rw-r--r-- | src/com/android/camera/Camera.java | 38 | ||||
-rw-r--r-- | src/com/android/camera/CameraHolder.java | 17 | ||||
-rw-r--r-- | src/com/android/camera/CameraSettings.java | 47 | ||||
-rw-r--r-- | src/com/android/camera/VideoCamera.java | 37 | ||||
-rw-r--r-- | src/com/android/camera/ui/ControlPanel.java | 9 | ||||
-rw-r--r-- | src/com/android/camera/ui/HeadUpDisplay.java | 6 | ||||
-rw-r--r-- | src/com/android/camera/ui/OtherSettingsPopup.java | 40 |
9 files changed, 136 insertions, 66 deletions
diff --git a/res/layout-xlarge/other_setting_popup.xml b/res/layout-xlarge/other_setting_popup.xml index 3927e3d..0a28974 100644 --- a/res/layout-xlarge/other_setting_popup.xml +++ b/res/layout-xlarge/other_setting_popup.xml @@ -58,5 +58,11 @@ style="@style/SettingRow" /> <com.android.camera.ui.InLineSettingPicker camera:prefKey="pref_camera_jpegquality_key" style="@style/SettingRow" /> + <TextView + android:text="@string/pref_restore_detail" + android:gravity="center" + android:textSize="22dp" + style="@style/SettingRow"> + </TextView> </LinearLayout> </com.android.camera.ui.OtherSettingsPopup> diff --git a/res/values-xlarge/styles.xml b/res/values-xlarge/styles.xml index 60b1bdd..d394910 100644 --- a/res/values-xlarge/styles.xml +++ b/res/values-xlarge/styles.xml @@ -18,7 +18,7 @@ --> <resources xmlns:android="http://schemas.android.com/apk/res/android"> - <style name="ThemeCamera" parent="android:Theme.Black.NoTitleBar"> + <style name="ThemeCamera" parent="android:Theme.Holo.NoActionBar"> <item name="android:windowBackground">@drawable/bg_camera_pattern</item> </style> </resources> diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java index 1598d93..47f7124 100644 --- a/src/com/android/camera/Camera.java +++ b/src/com/android/camera/Camera.java @@ -1037,6 +1037,9 @@ public class Camera extends NoSearchActivity implements View.OnClickListener, // ignore } + mBackCameraId = CameraHolder.instance().getBackCameraId(); + mFrontCameraId = CameraHolder.instance().getFrontCameraId(); + // Do this after starting preview because it depends on camera // parameters. initializeControlPanel(); @@ -1094,18 +1097,7 @@ public class Camera extends NoSearchActivity implements View.OnClickListener, private void loadCameraPreferences() { CameraSettings settings = new CameraSettings(this, mInitialParams, mCameraId, CameraHolder.instance().getCameraInfo()); - // Only need to load camera IDs once - if (mPreferenceGroup == null) { - mPreferenceGroup = settings.getPreferenceGroup( - R.xml.camera_preferences); - mFrontCameraId = - settings.getCameraIdByIndex(CameraInfo.CAMERA_FACING_FRONT); - mBackCameraId = - settings.getCameraIdByIndex(CameraInfo.CAMERA_FACING_BACK); - } else { - mPreferenceGroup = settings.getPreferenceGroup( - R.xml.camera_preferences); - } + mPreferenceGroup = settings.getPreferenceGroup(R.xml.camera_preferences); } private void initializeControlPanel() { @@ -2320,9 +2312,7 @@ public class Camera extends NoSearchActivity implements View.OnClickListener, if (mPausing) return; Runnable runnable = new Runnable() { public void run() { - if (mHeadUpDisplay != null) { - mHeadUpDisplay.restorePreferences(mParameters); - } + restorePreferences(); } }; MenuHelper.confirmAction(this, @@ -2331,10 +2321,28 @@ public class Camera extends NoSearchActivity implements View.OnClickListener, runnable); } + private void restorePreferences() { + if (mHeadUpDisplay != null) { + mHeadUpDisplay.restorePreferences(mParameters); + } + + if (mControlPanel != null) { + mControlPanel.dismissSettingPopup(); + CameraSettings.restorePreferences(Camera.this, mPreferences, + mParameters); + initializeControlPanel(); + onSharedPreferenceChanged(); + } + } + private class MyControlPanelListener implements ControlPanel.Listener { public void onSharedPreferenceChanged() { Camera.this.onSharedPreferenceChanged(); } + + public void onRestorePreferencesClicked() { + Camera.this.onRestorePreferencesClicked(); + } } private class MyCameraPickerListener implements CameraPicker.Listener { diff --git a/src/com/android/camera/CameraHolder.java b/src/com/android/camera/CameraHolder.java index a1c1fb8..1aa2a06 100644 --- a/src/com/android/camera/CameraHolder.java +++ b/src/com/android/camera/CameraHolder.java @@ -49,7 +49,8 @@ public class CameraHolder { private final Handler mHandler; private int mUsers = 0; // number of open() - number of release() private int mNumberOfCameras; - private int mCameraId = -1; + private int mCameraId = -1; // current camera id + private int mBackCameraId = -1, mFrontCameraId = -1; private CameraInfo[] mInfo; // We store the camera parameters when we actually open the device, @@ -99,6 +100,12 @@ public class CameraHolder { for (int i = 0; i < mNumberOfCameras; i++) { mInfo[i] = new CameraInfo(); android.hardware.Camera.getCameraInfo(i, mInfo[i]); + if (mBackCameraId == -1 && mInfo[i].facing == CameraInfo.CAMERA_FACING_BACK) { + mBackCameraId = i; + } + if (mFrontCameraId == -1 && mInfo[i].facing == CameraInfo.CAMERA_FACING_FRONT) { + mFrontCameraId = i; + } } } @@ -189,4 +196,12 @@ public class CameraHolder { // Keep the camera instance for 3 seconds. mKeepBeforeTime = System.currentTimeMillis() + 3000; } + + public int getBackCameraId() { + return mBackCameraId; + } + + public int getFrontCameraId() { + return mFrontCameraId; + } } diff --git a/src/com/android/camera/CameraSettings.java b/src/com/android/camera/CameraSettings.java index afeb28b..c4426fe 100644 --- a/src/com/android/camera/CameraSettings.java +++ b/src/com/android/camera/CameraSettings.java @@ -77,7 +77,6 @@ public class CameraSettings { private final Parameters mParameters; private final CameraInfo[] mCameraInfo; private final int mCameraId; - private int[] mCameraIdByIndex; public CameraSettings(Activity activity, Parameters parameters, int cameraId, CameraInfo[] cameraInfo) { @@ -253,7 +252,6 @@ public class CameraSettings { } CharSequence[] entryValues = new CharSequence[2]; - mCameraIdByIndex = new int[2]; for (int i = 0 ; i < mCameraInfo.length ; ++i) { int index = (mCameraInfo[i].facing == CameraInfo.CAMERA_FACING_FRONT) @@ -261,21 +259,12 @@ public class CameraSettings { : CameraInfo.CAMERA_FACING_BACK; if (entryValues[index] == null) { entryValues[index] = "" + i; - mCameraIdByIndex[index] = i; if (entryValues[((index == 1) ? 0 : 1)] != null) break; } } preference.setEntryValues(entryValues); } - int getCameraIdByIndex(int facingIndex) { - if (facingIndex > CameraInfo.CAMERA_FACING_FRONT || facingIndex < 0) { - Log.e(TAG, "Unsupported camera facing index " + facingIndex); - return mCameraIdByIndex[CameraInfo.CAMERA_FACING_BACK]; - } - return mCameraIdByIndex[facingIndex]; - } - private static boolean removePreference(PreferenceGroup group, String key) { for (int i = 0, n = group.size(); i < n; i++) { CameraPreference child = group.get(i); @@ -382,11 +371,6 @@ public class CameraSettings { editor.apply(); } - public static void upgradeAllPreferences(ComboPreferences pref) { - upgradeGlobalPreferences(pref.getGlobal()); - upgradeLocalPreferences(pref.getLocal()); - } - public static boolean getVideoQuality(String quality) { return VIDEO_QUALITY_YOUTUBE.equals( quality) || VIDEO_QUALITY_HIGH.equals(quality); @@ -411,4 +395,35 @@ public class CameraSettings { editor.putString(KEY_CAMERA_ID, Integer.toString(cameraId)); editor.apply(); } + + + public static void restorePreferences(Context context, + ComboPreferences preferences, Parameters parameters) { + int currentCameraId = readPreferredCameraId(preferences); + + // Clear the preferences of both cameras. + int backCameraId = CameraHolder.instance().getBackCameraId(); + if (backCameraId != -1) { + preferences.setLocalId(context, backCameraId); + Editor editor = preferences.edit(); + editor.clear(); + editor.apply(); + } + int frontCameraId = CameraHolder.instance().getFrontCameraId(); + if (frontCameraId != -1) { + preferences.setLocalId(context, frontCameraId); + Editor editor = preferences.edit(); + editor.clear(); + editor.apply(); + } + + upgradeGlobalPreferences(preferences.getGlobal()); + upgradeLocalPreferences(preferences.getLocal()); + + // Write back the current camera id because parameters are related to + // the camera. Otherwise, we may switch to the front camera but the + // initial picture size is that of the back camera. + initialCameraPictureSize(context, parameters); + writePreferredCameraId(preferences, currentCameraId); + } } diff --git a/src/com/android/camera/VideoCamera.java b/src/com/android/camera/VideoCamera.java index db6cffd..5dfca52 100644 --- a/src/com/android/camera/VideoCamera.java +++ b/src/com/android/camera/VideoCamera.java @@ -389,6 +389,9 @@ public class VideoCamera extends NoSearchActivity resizeForPreviewAspectRatio(); + mBackCameraId = CameraHolder.instance().getBackCameraId(); + mFrontCameraId = CameraHolder.instance().getFrontCameraId(); + // Initialize after startPreview becuase this need mParameters. initializeControlPanel(); // xlarge devices use control panel. Other devices use head-up display. @@ -432,17 +435,7 @@ public class VideoCamera extends NoSearchActivity private void loadCameraPreferences() { CameraSettings settings = new CameraSettings(this, mParameters, mCameraId, CameraHolder.instance().getCameraInfo()); - - // Only need to load camera ID's once - if (mPreferenceGroup == null) { - mPreferenceGroup = settings.getPreferenceGroup(R.xml.video_preferences); - mFrontCameraId = - settings.getCameraIdByIndex(CameraInfo.CAMERA_FACING_FRONT); - mBackCameraId = - settings.getCameraIdByIndex(CameraInfo.CAMERA_FACING_BACK); - } else { - mPreferenceGroup = settings.getPreferenceGroup(R.xml.video_preferences); - } + mPreferenceGroup = settings.getPreferenceGroup(R.xml.video_preferences); } private void initializeHeadUpDisplay() { @@ -1826,9 +1819,7 @@ public class VideoCamera extends NoSearchActivity private void onRestorePreferencesClicked() { Runnable runnable = new Runnable() { public void run() { - if (mHeadUpDisplay != null) { - mHeadUpDisplay.restorePreferences(mParameters); - } + restorePreferences(); } }; MenuHelper.confirmAction(this, @@ -1837,6 +1828,20 @@ public class VideoCamera extends NoSearchActivity runnable); } + private void restorePreferences() { + if (mHeadUpDisplay != null) { + mHeadUpDisplay.restorePreferences(mParameters); + } + + if (mControlPanel != null) { + mControlPanel.dismissSettingPopup(); + CameraSettings.restorePreferences(VideoCamera.this, mPreferences, + mParameters); + initializeControlPanel(); + onSharedPreferenceChanged(); + } + } + private void onSharedPreferenceChanged() { // ignore the events after "onPause()" or preview has not started yet if (mPausing) return; @@ -1869,6 +1874,10 @@ public class VideoCamera extends NoSearchActivity public void onSharedPreferenceChanged() { VideoCamera.this.onSharedPreferenceChanged(); } + + public void onRestorePreferencesClicked() { + VideoCamera.this.onRestorePreferencesClicked(); + } } private class MyCameraPickerListener implements CameraPicker.Listener { diff --git a/src/com/android/camera/ui/ControlPanel.java b/src/com/android/camera/ui/ControlPanel.java index d3e8ac9..adbfed6 100644 --- a/src/com/android/camera/ui/ControlPanel.java +++ b/src/com/android/camera/ui/ControlPanel.java @@ -44,7 +44,6 @@ public class ControlPanel extends RelativeLayout OtherSettingsPopup.Listener,PopupWindow.OnDismissListener { private static final String TAG = "ControlPanel"; private Context mContext; - private ComboPreferences mSharedPrefs; private PreferenceGroup mPreferenceGroup; private ArrayList<String> mPreferenceKeys; private Listener mListener; @@ -55,6 +54,7 @@ public class ControlPanel extends RelativeLayout static public interface Listener { public void onSharedPreferenceChanged(); + public void onRestorePreferencesClicked(); } public void setListener(Listener listener) { @@ -100,7 +100,6 @@ public class ControlPanel extends RelativeLayout // Initialize all variables and icons. mPreferenceGroup = group; - mSharedPrefs = ComboPreferences.get(context); for (int i = 0; i < keys.length; i++) { if (addIndicator(context, group, keys[i])) { mPreferenceKeys.add(keys[i]); @@ -120,6 +119,12 @@ public class ControlPanel extends RelativeLayout } } + public void onRestorePreferencesClicked() { + if (mListener != null) { + mListener.onRestorePreferencesClicked(); + } + } + public void onSettingChanged() { mIndicatorWheel.updateIndicator(mActiveIndicator); if (mListener != null) { diff --git a/src/com/android/camera/ui/HeadUpDisplay.java b/src/com/android/camera/ui/HeadUpDisplay.java index 2f9ac86..dd12926 100644 --- a/src/com/android/camera/ui/HeadUpDisplay.java +++ b/src/com/android/camera/ui/HeadUpDisplay.java @@ -403,11 +403,7 @@ public class HeadUpDisplay extends GLView { // onSharedPreferenceChanged(); mSharedPrefs.unregisterOnSharedPreferenceChangeListener(l); Context context = getGLRootView().getContext(); - Editor editor = mSharedPrefs.edit(); - editor.clear(); - editor.apply(); - CameraSettings.upgradeAllPreferences(mSharedPrefs); - CameraSettings.initialCameraPictureSize(context, param); + CameraSettings.restorePreferences(context, mSharedPrefs, param); reloadPreferences(); if (mListener != null) { mListener.onSharedPreferenceChanged(); diff --git a/src/com/android/camera/ui/OtherSettingsPopup.java b/src/com/android/camera/ui/OtherSettingsPopup.java index 3d37373..c0935c2 100644 --- a/src/com/android/camera/ui/OtherSettingsPopup.java +++ b/src/com/android/camera/ui/OtherSettingsPopup.java @@ -30,12 +30,13 @@ import android.widget.LinearLayout; /* A popup window that contains several camera settings. */ public class OtherSettingsPopup extends AbstractSettingPopup - implements InLineSettingPicker.Listener { + implements InLineSettingPicker.Listener, View.OnClickListener { private static final String TAG = "OtherSettingsPopup"; private Listener mListener; static public interface Listener { public void onOtherSettingChanged(); + public void onRestorePreferencesClicked(); } public void setOtherSettingChangedListener(Listener listener) { @@ -49,13 +50,18 @@ public class OtherSettingsPopup extends AbstractSettingPopup public void initialize(PreferenceGroup group) { // Initialize each camera setting. for (int i = mContentPanel.getChildCount() - 1; i >= 0; i--) { - InLineSettingPicker picker = (InLineSettingPicker) mContentPanel.getChildAt(i); - ListPreference pref = group.findPreference(picker.getKey()); - if (pref != null) { - picker.setSettingChangedListener(this); - picker.initialize(pref); - } else { // remove the row if the preference is not supported - mContentPanel.removeViewAt(i); + View v = mContentPanel.getChildAt(i); + if (v instanceof InLineSettingPicker) { + InLineSettingPicker picker = (InLineSettingPicker) v; + ListPreference pref = group.findPreference(picker.getKey()); + if (pref != null) { + picker.setSettingChangedListener(this); + picker.initialize(pref); + } else { // remove the row if the preference is not supported + mContentPanel.removeViewAt(i); + } + } else { // This row is restore defaults. + v.setOnClickListener(this); } } requestLayout(); @@ -70,11 +76,21 @@ public class OtherSettingsPopup extends AbstractSettingPopup // Scene mode can override other camera settings (ex: flash mode). public void overrideSettings(String key, String value) { int count = mContentPanel.getChildCount(); - for (int j = 1; j < count; j++) { - InLineSettingPicker v = (InLineSettingPicker) mContentPanel.getChildAt(j); - if (key.equals(v.getKey())) { - v.overrideSettings(value); + for (int i = 0; i < count; i++) { + View v = mContentPanel.getChildAt(i); + if (v instanceof InLineSettingPicker) { + InLineSettingPicker picker = (InLineSettingPicker) v; + if (key.equals(picker.getKey())) { + picker.overrideSettings(value); + } } } } + + @Override + public void onClick(View v) { + if (mListener != null) { + mListener.onRestorePreferencesClicked(); + } + } } |