summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen Lin <owenlin@google.com>2010-01-16 05:24:14 +0800
committerOwen Lin <owenlin@google.com>2010-01-21 19:06:55 -0800
commit85f7213b44515c06fee68a085065e5d96181465c (patch)
tree37bd3c0b2748af9fbbd86ef97f848e93e92a9815
parente2900e1761d73aec4d269d166981278dd27dffbc (diff)
downloadLegacyCamera-85f7213b44515c06fee68a085065e5d96181465c.tar.gz
Add restore default settings for Camera/Camcorder app.
Bug: 2167010 Change-Id: I1b59ddd23ee9a3b9cc34f911c048e269fb872cf8
-rw-r--r--res/values/strings.xml8
-rw-r--r--src/com/android/camera/Camera.java24
-rw-r--r--src/com/android/camera/OnScreenSettings.java59
-rw-r--r--src/com/android/camera/VideoCamera.java34
4 files changed, 118 insertions, 7 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 5cd38e7a..f7695d6f 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -78,6 +78,10 @@
<!-- Confirmation dialog message after deleting a video -->
<string name="confirm_delete_video_message">The video will be deleted.</string>
+ <!-- Confirmation dialog when restoring settings -->
+ <string name="confirm_restore_title">Restore Settings</string>
+ <string name="confirm_restore_message">Camera settings will be restored to default.</string>
+
<!-- button in review mode indicating that the picture just taken should be deleted -->
<string name="review_toss">DELETE</string>
@@ -308,6 +312,10 @@
<!-- Scene mode optimized for taking images of fireworks. -->
<string name="pref_camera_scenemode_entry_fireworks">Fireworks</string>
+ <!-- Restore settings item in preference -->
+ <string name="pref_restore_title">Restore settings</string>
+ <string name="pref_restore_detail">Restore camera settings to default</string>
+
<!-- Message to show when there's no lat/lng information in the image -->
<string name="no_location_image">No Location information contained in this image.</string>
<!-- Title of Details dialog -->
diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java
index a95c2b2a..fb3ede8d 100644
--- a/src/com/android/camera/Camera.java
+++ b/src/com/android/camera/Camera.java
@@ -1073,11 +1073,35 @@ public class Camera extends NoSearchActivity implements View.OnClickListener,
updateStorageHint(mPicturesRemaining);
}
+ private void restorePreferences() {
+ // Unregister the listener since "upgrade preference" will change
+ // a bunch of preferences. We can handle them with one
+ // setCameraParameters().
+ mPreferences.unregisterOnSharedPreferenceChangeListener(this);
+ mSettings.clearSettings();
+ CameraSettings.upgradePreferences(mPreferences);
+ setCameraParameters();
+
+ // We reload the preference again to reload the new data
+ mSettings.setPreferenceScreen(
+ new CameraSettings(this, mParameters)
+ .getPreferenceScreen(R.xml.camera_preferences));
+ mPreferences.registerOnSharedPreferenceChangeListener(this);
+ }
private void showOnScreenSettings() {
if (mSettings == null) {
mSettings = new OnScreenSettings(
findViewById(R.id.camera_preview));
+
+ Runnable resetPreferences = new Runnable() {
+ public void run() {
+ restorePreferences();
+ }
+ };
+
+ mSettings.setRestoreRunner(resetPreferences);
+
CameraSettings helper =
new CameraSettings(this, mInitialParams);
mSettings.setPreferenceScreen(helper
diff --git a/src/com/android/camera/OnScreenSettings.java b/src/com/android/camera/OnScreenSettings.java
index c5bbaf34..49f07af9 100644
--- a/src/com/android/camera/OnScreenSettings.java
+++ b/src/com/android/camera/OnScreenSettings.java
@@ -17,12 +17,14 @@
package com.android.camera;
import android.content.Context;
+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;
@@ -81,6 +83,7 @@ public class OnScreenSettings {
private MainMenuAdapter mMainAdapter;
private final LayoutInflater mInflater;
+ private Runnable mRestoreRunner;
// We store the override values here. For a given preference,
// if the mapping value of the preference key is not null, we will
@@ -114,6 +117,18 @@ public class OnScreenSettings {
mContainer = createContainer();
}
+ public void clearSettings() {
+ SharedPreferences.Editor editor = PreferenceManager
+ .getDefaultSharedPreferences(mContext).edit();
+ editor.clear();
+ editor.commit();
+ mOverride.clear();
+ }
+
+ public void setRestoreRunner(Runnable restorer) {
+ mRestoreRunner = restorer;
+ }
+
public boolean isVisible() {
return mIsVisible;
}
@@ -302,15 +317,40 @@ public class OnScreenSettings {
public void onItemClick(
AdapterView<?> parent, View view, int position, long id) {
- Preference preference = mPreferences.get(position);
- SubMenuAdapter adapter = new SubMenuAdapter(
- mContext, (ListPreference) preference);
- mSubMenu.setAdapter(adapter);
- mSubMenu.setOnItemClickListener(adapter);
- showSubMenu();
+ // If not the last item (restore settings)
+ if (position < mPreferences.size()) {
+ Preference preference = mPreferences.get(position);
+ SubMenuAdapter adapter = new SubMenuAdapter(
+ mContext, (ListPreference) preference);
+ mSubMenu.setAdapter(adapter);
+ mSubMenu.setOnItemClickListener(adapter);
+ showSubMenu();
+ } else {
+ MenuHelper.confirmAction(mContext,
+ mContext.getString(R.string.confirm_restore_title),
+ mContext.getString(R.string.confirm_restore_message),
+ mRestoreRunner);
+ }
}
public View getView(int position, View convertView, ViewGroup parent) {
+ // The last item in the view (i.e., restore settings)
+ if (position == mPreferences.size()) {
+ convertView = inflateIfNeed(convertView,
+ R.layout.on_screen_menu_list_item, parent, false);
+
+ ((TextView) convertView.findViewById(R.id.title)).setText(
+ mContext.getString(R.string.pref_restore_title));
+ ((TextView) convertView.findViewById(R.id.summary)).setText(
+ mContext.getString(R.string.pref_restore_detail));
+
+ // Make sure we didn't set focusable. Otherwise, it will
+ // consume all the events. See more detail in the comments
+ // below.
+ convertView.setFocusable(false);
+ return convertView;
+ }
+
Preference preference = mPreferences.get(position);
if (preference instanceof PreferenceGroup) {
@@ -351,12 +391,16 @@ public class OnScreenSettings {
@Override
public boolean isEnabled(int position) {
+ // The last item (restore default)
+ if (position == mPreferences.size()) return true;
+
Preference preference = mPreferences.get(position);
return !(preference instanceof PreferenceGroup);
}
public int getCount() {
- return mPreferences.size();
+ // The last one is "restore default"
+ return mPreferences.size() + 1;
}
public Object getItem(int position) {
@@ -369,6 +413,7 @@ public class OnScreenSettings {
@Override
public int getItemViewType(int position) {
+ if (position == mPreferences.size()) return 1;
Preference pref = mPreferences.get(position);
if (pref instanceof PreferenceGroup) return 0;
if (pref instanceof ListPreference) return 1;
diff --git a/src/com/android/camera/VideoCamera.java b/src/com/android/camera/VideoCamera.java
index 4e348267..333b2a9a 100644
--- a/src/com/android/camera/VideoCamera.java
+++ b/src/com/android/camera/VideoCamera.java
@@ -1069,10 +1069,41 @@ public class VideoCamera extends NoSearchActivity
item.setIcon(android.R.drawable.ic_menu_preferences);
}
+ private void restorePreferences() {
+ // Unregister the listener since "upgrade preference" will change
+ // a bunch of preferences. We can handle them with one
+ // setCameraParameters().
+ mPreferences.unregisterOnSharedPreferenceChangeListener(this);
+ mSettings.clearSettings();
+ CameraSettings.upgradePreferences(mPreferences);
+ readVideoPreferences();
+ resetCameraParameters();
+
+ // If we start preview and reload the settings UI in a row. The
+ // preview will become a white screen. So, we reload the settings UI
+ // later.
+ mHandler.post(new Runnable() {
+ public void run() {
+ // We reload the preference again to reload the new data
+ mSettings.setPreferenceScreen(
+ new CameraSettings(VideoCamera.this, mParameters)
+ .getPreferenceScreen(R.xml.video_preferences));
+ }
+ });
+ mPreferences.registerOnSharedPreferenceChangeListener(this);
+ }
+
private void showOnScreenSettings() {
if (mSettings == null) {
mSettings = new OnScreenSettings(
findViewById(R.id.camera_preview));
+ final Runnable resetPreferences = new Runnable() {
+ public void run() {
+ restorePreferences();
+ }
+ };
+ mSettings.setRestoreRunner(resetPreferences);
+
CameraSettings helper = new CameraSettings(this, mParameters);
PreferenceScreen screen = helper
.getPreferenceScreen(R.xml.video_preferences);
@@ -1510,7 +1541,10 @@ public class VideoCamera extends NoSearchActivity
// If mCameraDevice is not ready then we can set the parameter in
// startPreview().
if (mCameraDevice == null) return;
+ resetCameraParameters();
+ }
+ private void resetCameraParameters() {
// We need to restart the preview if preview size is changed.
Size size = mParameters.getPreviewSize();
if (size.width != mProfile.mVideoWidth