<!-- 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>
<!-- 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 -->
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
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;
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
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;
}
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) {
@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) {
@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;
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);
// 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