diff options
author | Michael Bestas <mikeioannina@gmail.com> | 2014-10-09 14:41:15 +0300 |
---|---|---|
committer | Michael Bestas <mikeioannina@gmail.com> | 2014-10-16 06:04:33 +0300 |
commit | ee3eba725351d4517574cdb37dc8a8d382822413 (patch) | |
tree | 956b43bdf8d85bbbe40e8c9f020b6c8612cca9ec | |
parent | 69dca15a0ccd933b2a12d1bc42374d27cdd7fac0 (diff) | |
download | android_packages_apps_Camera2-ee3eba725351d4517574cdb37dc8a8d382822413.tar.gz android_packages_apps_Camera2-ee3eba725351d4517574cdb37dc8a8d382822413.tar.bz2 android_packages_apps_Camera2-ee3eba725351d4517574cdb37dc8a8d382822413.zip |
Camera: Add proper support for ListPreference
* The original code handled only IconListPreference, resulting in many issues
* Unlike AOSP, we use a lot of ListPreference menus, so we need to properly handle them
* Avoid code duplication in PhotoMenu & VideoMenu
* Correctly disable options when they should be disabled
* Correct MoreSettingPopup handling in both photo & video settings
Change-Id: I09d7280ca58af4e4fe81635980f35d394b114f2a
-rw-r--r-- | res/values/attrs.xml | 1 | ||||
-rw-r--r-- | res/xml/camera_preferences.xml | 4 | ||||
-rw-r--r-- | res/xml/video_preferences.xml | 2 | ||||
-rw-r--r-- | src/com/android/camera/ListPreference.java | 7 | ||||
-rw-r--r-- | src/com/android/camera/PhotoMenu.java | 184 | ||||
-rw-r--r-- | src/com/android/camera/PhotoUI.java | 50 | ||||
-rw-r--r-- | src/com/android/camera/PieController.java | 40 | ||||
-rw-r--r-- | src/com/android/camera/VideoMenu.java | 131 | ||||
-rw-r--r-- | src/com/android/camera/VideoUI.java | 21 | ||||
-rw-r--r-- | src/com/android/camera/ui/PieItem.java | 2 |
10 files changed, 263 insertions, 179 deletions
diff --git a/res/values/attrs.xml b/res/values/attrs.xml index 5a00a695a..5e10ec9fd 100644 --- a/res/values/attrs.xml +++ b/res/values/attrs.xml @@ -30,6 +30,7 @@ <attr name="entryValues" format="reference" /> <attr name="entries" format="reference" /> <attr name="labelList" format="reference" /> + <attr name="icon" format="reference" /> </declare-styleable> <declare-styleable name="IconIndicator"> <attr name="icons" format="reference" /> diff --git a/res/xml/camera_preferences.xml b/res/xml/camera_preferences.xml index 531dc2161..131685e10 100644 --- a/res/xml/camera_preferences.xml +++ b/res/xml/camera_preferences.xml @@ -35,6 +35,7 @@ camera:key="pref_camera_scenemode_key" camera:defaultValue="@string/pref_camera_scenemode_default" camera:title="@string/pref_camera_scenemode_title" + camera:icon="@drawable/ic_sce" camera:entries="@array/pref_camera_scenemode_entries" camera:entryValues="@array/pref_camera_scenemode_entryvalues" /> <IconListPreference @@ -58,6 +59,7 @@ <ListPreference camera:key="pref_camera_picturesize_key" camera:title="@string/pref_camera_picturesize_title" + camera:icon="@drawable/ic_imagesize" camera:entries="@array/pref_camera_picturesize_entries" camera:entryValues="@array/pref_camera_picturesize_entryvalues" /> <ListPreference @@ -127,6 +129,7 @@ camera:key="pref_camera_coloreffect_key" camera:defaultValue="@string/pref_camera_coloreffect_default" camera:title="@string/pref_camera_coloreffect_title" + camera:icon="@drawable/ic_tint" camera:entries="@array/pref_camera_coloreffect_entries" camera:entryValues="@array/pref_camera_coloreffect_entryvalues" /> <ListPreference @@ -250,6 +253,7 @@ camera:key="pref_camera_slow_shutter" camera:defaultValue="@string/pref_camera_slow_shutter_default" camera:title="@string/pref_camera_slow_shutter_title" + camera:icon="@drawable/ic_slowshutter_off" camera:entries="@array/pref_camera_slow_shutter_entries" camera:entryValues="@array/pref_camera_slow_shutter_entryvalues" /> <IconListPreference diff --git a/res/xml/video_preferences.xml b/res/xml/video_preferences.xml index 7f73aa5d3..f84f51794 100644 --- a/res/xml/video_preferences.xml +++ b/res/xml/video_preferences.xml @@ -20,6 +20,7 @@ <ListPreference camera:key="pref_video_quality_key" camera:title="@string/pref_video_quality_title" + camera:icon="@drawable/ic_imagesize" camera:entries="@array/pref_video_quality_entries" camera:entryValues="@array/pref_video_quality_entryvalues"/> <ListPreference @@ -113,6 +114,7 @@ camera:key="pref_camera_video_coloreffect_key" camera:defaultValue="@string/pref_camera_coloreffect_default" camera:title="@string/pref_camera_coloreffect_title" + camera:icon="@drawable/ic_tint" camera:entries="@array/pref_camera_coloreffect_entries" camera:entryValues="@array/pref_camera_coloreffect_entryvalues" /> <ListPreference diff --git a/src/com/android/camera/ListPreference.java b/src/com/android/camera/ListPreference.java index 1ff375203..de050b93e 100644 --- a/src/com/android/camera/ListPreference.java +++ b/src/com/android/camera/ListPreference.java @@ -44,6 +44,7 @@ public class ListPreference extends CameraPreference { private CharSequence[] mEntryValues; private CharSequence[] mUnfilteredEntryValues; private CharSequence[] mLabels; + private int mIconId; private boolean mLoaded = false; public ListPreference(Context context, AttributeSet attrs) { @@ -74,6 +75,8 @@ public class ListPreference extends CameraPreference { R.styleable.ListPreference_entryValues)); setLabels(a.getTextArray( R.styleable.ListPreference_labelList)); + mIconId = a.getResourceId( + R.styleable.ListPreference_icon, 0); a.recycle(); } @@ -93,6 +96,10 @@ public class ListPreference extends CameraPreference { return mLabels; } + public int getIcon() { + return mIconId; + } + public void setEntries(CharSequence entries[]) { mEntries = entries == null ? new CharSequence[0] : entries; } diff --git a/src/com/android/camera/PhotoMenu.java b/src/com/android/camera/PhotoMenu.java index 2246dc127..36b032e9d 100644 --- a/src/com/android/camera/PhotoMenu.java +++ b/src/com/android/camera/PhotoMenu.java @@ -43,13 +43,15 @@ public class PhotoMenu extends PieController private final String mSettingOff; private PhotoUI mUI; - private String[] mOtherKeys; + private String[] mSettingsKeys; private AbstractSettingPopup mPopup; + private MoreSettingPopup mSettingsPopup; private static final int POPUP_NONE = 0; private static final int POPUP_FIRST_LEVEL = 1; private static final int POPUP_SECOND_LEVEL = 2; private int mPopupStatus; + private CameraActivity mActivity; public PhotoMenu(CameraActivity activity, PhotoUI ui, PieRenderer pie) { @@ -62,6 +64,7 @@ public class PhotoMenu extends PieController public void initialize(PreferenceGroup group) { super.initialize(group); mPopup = null; + mSettingsPopup = null; mPopupStatus = POPUP_NONE; PieItem item = null; final Resources res = mActivity.getResources(); @@ -97,21 +100,11 @@ public class PhotoMenu extends PieController final ListPreference slowShutterPref = group.findPreference(CameraSettings.KEY_SLOW_SHUTTER); if (slowShutterPref != null) { - item = makeItem(R.drawable.ic_slowshutter_off); - item.setLabel(res.getString( - R.string.pref_camera_slow_shutter_title).toUpperCase(locale)); + item = makeListItem(CameraSettings.KEY_SLOW_SHUTTER); item.setOnClickListener(new OnClickListener() { @Override public void onClick(PieItem item) { - ListPrefSettingPopup popup = - (ListPrefSettingPopup) mActivity.getLayoutInflater().inflate( - R.layout.list_pref_setting_popup, null, false); - popup.initialize(slowShutterPref); - popup.setSettingChangedListener(PhotoMenu.this); - mUI.dismissPopup(); - mPopup = popup; - mPopupStatus = POPUP_SECOND_LEVEL; - mUI.showPopup(mPopup); + showListPopup(slowShutterPref); } }); enhance.addItem(item); @@ -124,21 +117,11 @@ public class PhotoMenu extends PieController // color effect final ListPreference colorPref = group.findPreference(CameraSettings.KEY_COLOR_EFFECT); if (colorPref != null) { - item = makeItem(R.drawable.ic_tint); - item.setLabel(res.getString( - R.string.pref_camera_coloreffect_title).toUpperCase(locale)); + item = makeListItem(CameraSettings.KEY_COLOR_EFFECT); item.setOnClickListener(new OnClickListener() { @Override public void onClick(PieItem item) { - ListPrefSettingPopup popup = - (ListPrefSettingPopup) mActivity.getLayoutInflater().inflate( - R.layout.list_pref_setting_popup, null, false); - popup.initialize(colorPref); - popup.setSettingChangedListener(PhotoMenu.this); - mUI.dismissPopup(); - mPopup = popup; - mPopupStatus = POPUP_SECOND_LEVEL; - mUI.showPopup(mPopup); + showListPopup(colorPref); } }); enhance.addItem(item); @@ -201,7 +184,6 @@ public class PhotoMenu extends PieController timerPopup.setSettingChangedListener(PhotoMenu.this); mUI.dismissPopup(); mPopup = timerPopup; - mPopupStatus = POPUP_SECOND_LEVEL; mUI.showPopup(mPopup); } }); @@ -209,21 +191,11 @@ public class PhotoMenu extends PieController // image size final ListPreference sizePref = group.findPreference(CameraSettings.KEY_PICTURE_SIZE); if (sizePref != null) { - item = makeItem(R.drawable.ic_imagesize); - item.setLabel(res.getString( - R.string.pref_camera_picturesize_title).toUpperCase(locale)); + item = makeListItem(CameraSettings.KEY_PICTURE_SIZE); item.setOnClickListener(new OnClickListener() { @Override public void onClick(PieItem item) { - ListPrefSettingPopup popup = - (ListPrefSettingPopup) mActivity.getLayoutInflater().inflate( - R.layout.list_pref_setting_popup, null, false); - popup.initialize(sizePref); - popup.setSettingChangedListener(PhotoMenu.this); - mUI.dismissPopup(); - mPopup = popup; - mPopupStatus = POPUP_SECOND_LEVEL; - mUI.showPopup(mPopup); + showListPopup(sizePref); } }); more.addItem(item); @@ -237,26 +209,17 @@ public class PhotoMenu extends PieController // scene mode final ListPreference scenePref = group.findPreference(CameraSettings.KEY_SCENE_MODE); if (scenePref != null) { - item = makeItem(R.drawable.ic_sce); - item.setLabel(res.getString(R.string.pref_camera_scenemode_title).toUpperCase(locale)); + item = makeListItem(CameraSettings.KEY_SCENE_MODE); item.setOnClickListener(new OnClickListener() { @Override public void onClick(PieItem item) { - LayoutInflater inflater = mActivity.getLayoutInflater(); - ListPrefSettingPopup popup = (ListPrefSettingPopup) inflater.inflate( - R.layout.list_pref_setting_popup, null, false); - popup.initialize(scenePref); - popup.setSettingChangedListener(PhotoMenu.this); - mUI.dismissPopup(); - mPopup = popup; - mPopupStatus = POPUP_SECOND_LEVEL; - mUI.showPopup(mPopup); + showListPopup(scenePref); } }); enhance.addItem(item); } // extra settings popup - mOtherKeys = new String[] { + mSettingsKeys = new String[] { CameraSettings.KEY_STORAGE, CameraSettings.KEY_POWER_SHUTTER, CameraSettings.KEY_FOCUS_MODE, @@ -270,47 +233,103 @@ public class PhotoMenu extends PieController CameraSettings.KEY_HISTOGRAM, CameraSettings.KEY_SUPERZOOM }; - item = makeItem(R.drawable.ic_settings_holo_light); - item.setLabel(res.getString(R.string.camera_menu_more_label).toUpperCase(locale)); - item.setOnClickListener(new OnClickListener() { + PieItem settings = makeItem(R.drawable.ic_settings_holo_light); + settings.setLabel(res.getString(R.string.camera_menu_more_label).toUpperCase(locale)); + settings.setOnClickListener(new OnClickListener() { @Override public void onClick(PieItem item) { - if (mPopup == null || mPopupStatus != POPUP_FIRST_LEVEL) { - LayoutInflater inflater = mActivity.getLayoutInflater(); - MoreSettingPopup popup = (MoreSettingPopup) inflater.inflate( - R.layout.more_setting_popup, null, false); - popup.initialize(mPreferenceGroup, mOtherKeys); - popup.setSettingChangedListener(PhotoMenu.this); - mPopup = popup; + if (mSettingsPopup == null || mPopupStatus != POPUP_FIRST_LEVEL) { + initializeSettingsPopup(); mPopupStatus = POPUP_FIRST_LEVEL; } - mUI.showPopup(mPopup); + mUI.showPopup(mSettingsPopup); } }); - more.addItem(item); + more.addItem(settings); // burst mode final ListPreference burstPref = group.findPreference(CameraSettings.KEY_BURST_MODE); mUI.updateBurstModeIcon(Integer.valueOf(burstPref.getValue())); } + public void popupDismissed() { + if (mPopupStatus == POPUP_SECOND_LEVEL) { + initializeSettingsPopup(); + mPopupStatus = POPUP_FIRST_LEVEL; + mUI.showPopup(mSettingsPopup); + if (mSettingsPopup != null) { + mSettingsPopup = null; + } + } else { + initializeSettingsPopup(); + if (mPopup != null) { + mPopup = null; + } + } + } + + @Override + public void reloadPreferences() { + super.reloadPreferences(); + if (mSettingsPopup != null) { + mSettingsPopup.reloadPreference(); + } + } + @Override - // Hit when an item in the second-level popup gets selected + public void overrideSettings(final String ... keyvalues) { + super.overrideSettings(keyvalues); + if (mSettingsPopup == null) { + initializeSettingsPopup(); + } + mSettingsPopup.overrideSettings(keyvalues); + } + + @Override + // Hit when an item in a popup gets selected public void onListPrefChanged(ListPreference pref) { - if (mPopup != null) { - if (mPopupStatus == POPUP_SECOND_LEVEL) { - mUI.dismissPopup(); - } + if (mPopup != null && mSettingsPopup != null) { + mUI.dismissPopup(); } onSettingChanged(pref); } - public void popupDismissed() { - // if the 2nd level popup gets dismissed - if (mPopup != null) { - if (mPopupStatus == POPUP_SECOND_LEVEL) { - mPopup = null; - } - } + @Override + // Hit when an item in the first-level popup gets selected, then bring up + // the second-level popup + public void onPreferenceClicked(ListPreference pref) { + if (mPopupStatus != POPUP_FIRST_LEVEL) return; + + ListPrefSettingPopup basic = + (ListPrefSettingPopup) mActivity.getLayoutInflater().inflate( + R.layout.list_pref_setting_popup, null, false); + basic.initialize(pref); + basic.setSettingChangedListener(this); + mUI.dismissPopup(); + mPopup = basic; + mUI.showPopup(mPopup); + mPopupStatus = POPUP_SECOND_LEVEL; + } + + // Initialize the second-level settings popup + protected void initializeSettingsPopup() { + MoreSettingPopup popup = + (MoreSettingPopup) mActivity.getLayoutInflater().inflate( + R.layout.more_setting_popup, null, false); + popup.initialize(mPreferenceGroup, mSettingsKeys); + popup.setSettingChangedListener(PhotoMenu.this); + mSettingsPopup = popup; + } + + // Show a popup options list + protected void showListPopup(ListPreference pref) { + ListPrefSettingPopup popup = + (ListPrefSettingPopup) mActivity.getLayoutInflater().inflate( + R.layout.list_pref_setting_popup, null, false); + popup.initialize(pref); + popup.setSettingChangedListener(PhotoMenu.this); + mUI.dismissPopup(); + mPopup = popup; + mUI.showPopup(mPopup); } // Return true if the preference has the specified key but not the value. @@ -371,21 +390,4 @@ public class PhotoMenu extends PieController mUI.updateBurstModeIcon(1); } - @Override - // Hit when an item in the first-level popup gets selected, then bring up - // the second-level popup - public void onPreferenceClicked(ListPreference pref) { - if (mPopupStatus != POPUP_FIRST_LEVEL) return; - - LayoutInflater inflater = mActivity.getLayoutInflater(); - ListPrefSettingPopup basic = (ListPrefSettingPopup) inflater.inflate( - R.layout.list_pref_setting_popup, null, false); - basic.initialize(pref); - basic.setSettingChangedListener(this); - mUI.dismissPopup(); - mPopup = basic; - mUI.showPopup(mPopup); - mPopupStatus = POPUP_SECOND_LEVEL; - } - } diff --git a/src/com/android/camera/PhotoUI.java b/src/com/android/camera/PhotoUI.java index 9b97a34ba..c4260effb 100644 --- a/src/com/android/camera/PhotoUI.java +++ b/src/com/android/camera/PhotoUI.java @@ -218,6 +218,29 @@ public class PhotoUI implements PieListener, } } + private class SettingsPopup extends PopupWindow { + public SettingsPopup(View popup) { + super(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); + setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); + setOutsideTouchable(true); + setFocusable(true); + popup.setVisibility(View.VISIBLE); + setContentView(popup); + showAtLocation(mRootView, Gravity.CENTER, 0, 0); + } + + public void dismiss() { + super.dismiss(); + popupDismissed(); + showUI(); + mMenu.popupDismissed(); + + // Switch back into fullscreen/lights-out mode after popup + // is dimissed. + mActivity.setSystemBarsVisibility(false); + } + } + public PhotoUI(CameraActivity activity, PhotoController controller, View parent) { mActivity = activity; mController = controller; @@ -669,27 +692,10 @@ public class PhotoUI implements PieListener, public void showPopup(AbstractSettingPopup popup) { hideUI(); - if (mPopup == null) { - mPopup = new PopupWindow(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); - mPopup.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); - mPopup.setOutsideTouchable(true); - mPopup.setFocusable(true); - mPopup.setOnDismissListener(new PopupWindow.OnDismissListener() { - @Override - public void onDismiss() { - mPopup = null; - mMenu.popupDismissed(); - showUI(); - - // Switch back into fullscreen/lights-out mode after popup - // is dimissed. - mActivity.setSystemBarsVisibility(false); - } - }); + if (mPopup != null) { + mPopup.dismiss(); } - popup.setVisibility(View.VISIBLE); - mPopup.setContentView(popup); - mPopup.showAtLocation(mRootView, Gravity.CENTER, 0, 0); + mPopup = new SettingsPopup(popup); } public void dismissPopup() { @@ -698,6 +704,10 @@ public class PhotoUI implements PieListener, } } + private void popupDismissed() { + mPopup = null; + } + public void onShowSwitcherPopup() { if (mPieRenderer != null && mPieRenderer.showsItems()) { mPieRenderer.hide(); diff --git a/src/com/android/camera/PieController.java b/src/com/android/camera/PieController.java index 622440151..e178649b3 100644 --- a/src/com/android/camera/PieController.java +++ b/src/com/android/camera/PieController.java @@ -1,5 +1,6 @@ /* * Copyright (C) 2012 The Android Open Source Project + * Copyright (C) 2014 The CyanogenMod Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,7 +34,7 @@ import java.util.Map; public class PieController { - private static String TAG = "CAM_piecontrol"; + private static String TAG = "CAM_PieController"; protected static final int MODE_PHOTO = 0; protected static final int MODE_VIDEO = 1; @@ -46,8 +47,11 @@ public class PieController { protected OnPreferenceChangedListener mListener; protected PieRenderer mRenderer; private List<IconListPreference> mPreferences; + private List<ListPreference> mListPreferences; private Map<IconListPreference, PieItem> mPreferenceMap; + private Map<ListPreference, PieItem> mListPreferenceMap; private Map<IconListPreference, String> mOverrides; + private Map<ListPreference, String> mListOverrides; public void setListener(OnPreferenceChangedListener listener) { mListener = listener; @@ -57,13 +61,17 @@ public class PieController { mActivity = activity; mRenderer = pie; mPreferences = new ArrayList<IconListPreference>(); + mListPreferences = new ArrayList<ListPreference>(); mPreferenceMap = new HashMap<IconListPreference, PieItem>(); + mListPreferenceMap = new HashMap<ListPreference, PieItem>(); mOverrides = new HashMap<IconListPreference, String>(); + mListOverrides = new HashMap<ListPreference, String>(); } public void initialize(PreferenceGroup group) { mRenderer.clearItems(); mPreferenceMap.clear(); + mListPreferenceMap.clear(); setPreferenceGroup(group); } @@ -132,6 +140,18 @@ public class PieController { return item; } + public PieItem makeListItem(final String prefKey) { + final ListPreference pref = + (ListPreference) mPreferenceGroup.findPreference(prefKey); + if (pref == null) return null; + // The preference only has a single icon to represent it. + PieItem item = makeItem(pref.getIcon()); + item.setLabel(pref.getTitle().toUpperCase()); + mListPreferences.add(pref); + mListPreferenceMap.put(pref, item); + return item; + } + public PieItem makeSwitchItem(final String prefKey, boolean addListener) { final IconListPreference pref = (IconListPreference) mPreferenceGroup.findPreference(prefKey); @@ -176,7 +196,6 @@ public class PieController { return item; } - public PieItem makeDialItem(ListPreference pref, int iconId, float center, float sweep) { PieItem item = makeItem(iconId); return item; @@ -243,6 +262,9 @@ public class PieController { for (IconListPreference pref : mPreferenceMap.keySet()) { override(pref, keyvalues); } + for (ListPreference pref : mListPreferenceMap.keySet()) { + overrideList(pref, keyvalues); + } } private void override(IconListPreference pref, final String ... keyvalues) { @@ -259,4 +281,18 @@ public class PieController { } reloadPreference(pref); } + + private void overrideList(ListPreference pref, final String ... keyvalues) { + mListOverrides.remove(pref); + for (int i = 0; i < keyvalues.length; i += 2) { + String key = keyvalues[i]; + String value = keyvalues[i + 1]; + if (key.equals(pref.getKey())) { + mListOverrides.put(pref, value); + PieItem item = mListPreferenceMap.get(pref); + item.setEnabled(value == null); + break; + } + } + } } diff --git a/src/com/android/camera/VideoMenu.java b/src/com/android/camera/VideoMenu.java index 3ed6b5875..cedb199dd 100644 --- a/src/com/android/camera/VideoMenu.java +++ b/src/com/android/camera/VideoMenu.java @@ -1,6 +1,6 @@ /* * Copyright (C) 2012 The Android Open Source Project - * Copyright (C) 2013 The CyanogenMod Project + * Copyright (C) 2013-2014 The CyanogenMod Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,13 +40,15 @@ public class VideoMenu extends PieController private static String TAG = "CAM_VideoMenu"; private VideoUI mUI; - private String[] mOtherKeys; + private String[] mSettingsKeys; private AbstractSettingPopup mPopup; + private MoreSettingPopup mSettingsPopup; private static final int POPUP_NONE = 0; private static final int POPUP_FIRST_LEVEL = 1; private static final int POPUP_SECOND_LEVEL = 2; private int mPopupStatus; + private CameraActivity mActivity; public VideoMenu(CameraActivity activity, VideoUI ui, PieRenderer pie) { @@ -58,6 +60,7 @@ public class VideoMenu extends PieController public void initialize(PreferenceGroup group) { super.initialize(group); mPopup = null; + mSettingsPopup = null; mPopupStatus = POPUP_NONE; PieItem item = null; final Resources res = mActivity.getResources(); @@ -88,21 +91,11 @@ public class VideoMenu extends PieController final ListPreference colorPref = group.findPreference(CameraSettings.KEY_VIDEOCAMERA_COLOR_EFFECT); if (colorPref != null) { - item = makeItem(R.drawable.ic_tint); - item.setLabel(res.getString( - R.string.pref_camera_coloreffect_title).toUpperCase(locale)); + item = makeListItem(CameraSettings.KEY_VIDEOCAMERA_COLOR_EFFECT); item.setOnClickListener(new OnClickListener() { @Override public void onClick(PieItem item) { - ListPrefSettingPopup popup = - (ListPrefSettingPopup) mActivity.getLayoutInflater().inflate( - R.layout.list_pref_setting_popup, null, false); - popup.initialize(colorPref); - popup.setSettingChangedListener(VideoMenu.this); - mUI.dismissPopup(); - mPopup = popup; - mPopupStatus = POPUP_SECOND_LEVEL; - mUI.showPopup(mPopup); + showListPopup(colorPref); } }); enhance.addItem(item); @@ -156,7 +149,6 @@ public class VideoMenu extends PieController timeInterval.setSettingChangedListener(VideoMenu.this); mUI.dismissPopup(); mPopup = timeInterval; - mPopupStatus = POPUP_SECOND_LEVEL; mUI.showPopup(mPopup); } }); @@ -164,21 +156,11 @@ public class VideoMenu extends PieController // video size final ListPreference sizePref = group.findPreference(CameraSettings.KEY_VIDEO_QUALITY); if (sizePref != null) { - item = makeItem(R.drawable.ic_imagesize); - item.setLabel(res.getString( - R.string.pref_video_quality_title).toUpperCase(locale)); + item = makeListItem(CameraSettings.KEY_VIDEO_QUALITY); item.setOnClickListener(new OnClickListener() { @Override public void onClick(PieItem item) { - ListPrefSettingPopup popup = - (ListPrefSettingPopup) mActivity.getLayoutInflater().inflate( - R.layout.list_pref_setting_popup, null, false); - popup.initialize(sizePref); - popup.setSettingChangedListener(VideoMenu.this); - mUI.dismissPopup(); - mPopup = popup; - mPopupStatus = POPUP_SECOND_LEVEL; - mUI.showPopup(mPopup); + showListPopup(sizePref); } }); more.addItem(item); @@ -190,7 +172,7 @@ public class VideoMenu extends PieController more.addItem(item); } // extra settings popup - mOtherKeys = new String[] { + mSettingsKeys = new String[] { CameraSettings.KEY_STORAGE, CameraSettings.KEY_POWER_SHUTTER, CameraSettings.KEY_DIS, @@ -200,44 +182,61 @@ public class VideoMenu extends PieController CameraSettings.KEY_JPEG_QUALITY, CameraSettings.KEY_VIDEO_HIGH_FRAME_RATE, }; - item = makeItem(R.drawable.ic_settings_holo_light); - item.setLabel(res.getString(R.string.camera_menu_more_label).toUpperCase(locale)); - item.setOnClickListener(new OnClickListener() { + PieItem settings = makeItem(R.drawable.ic_settings_holo_light); + settings.setLabel(res.getString(R.string.camera_menu_more_label).toUpperCase(locale)); + settings.setOnClickListener(new OnClickListener() { @Override public void onClick(PieItem item) { - if (mPopup == null || mPopupStatus != POPUP_FIRST_LEVEL) { - LayoutInflater inflater = mActivity.getLayoutInflater(); - MoreSettingPopup popup = (MoreSettingPopup) inflater.inflate( - R.layout.more_setting_popup, null, false); - popup.initialize(mPreferenceGroup, mOtherKeys); - popup.setSettingChangedListener(VideoMenu.this); - mPopup = popup; + if (mSettingsPopup == null || mPopupStatus != POPUP_FIRST_LEVEL) { + initializeSettingsPopup(); mPopupStatus = POPUP_FIRST_LEVEL; } - mUI.showPopup(mPopup); + mUI.showPopup(mSettingsPopup); } }); - more.addItem(item); + more.addItem(settings); } - @Override - // Hit when an item in the second-level popup gets selected - public void onListPrefChanged(ListPreference pref) { - if (mPopup != null) { - if (mPopupStatus == POPUP_SECOND_LEVEL) { - mUI.dismissPopup(); + public void popupDismissed() { + if (mPopupStatus == POPUP_SECOND_LEVEL) { + initializeSettingsPopup(); + mPopupStatus = POPUP_FIRST_LEVEL; + mUI.showPopup(mSettingsPopup); + if (mSettingsPopup != null) { + mSettingsPopup = null; + } + } else { + initializeSettingsPopup(); + if (mPopup != null) { + mPopup = null; } } - onSettingChanged(pref); } - public void popupDismissed() { - // if the 2nd level popup gets dismissed - if (mPopup != null) { - if (mPopupStatus == POPUP_SECOND_LEVEL) { - mPopup = null; - } + @Override + public void reloadPreferences() { + super.reloadPreferences(); + if (mSettingsPopup != null) { + mSettingsPopup.reloadPreference(); + } + } + + @Override + public void overrideSettings(final String ... keyvalues) { + super.overrideSettings(keyvalues); + if (mSettingsPopup == null) { + initializeSettingsPopup(); + } + mSettingsPopup.overrideSettings(keyvalues); + } + + @Override + // Hit when an item in a popup gets selected + public void onListPrefChanged(ListPreference pref) { + if (mPopup != null && mSettingsPopup != null) { + mUI.dismissPopup(); } + onSettingChanged(pref); } @Override @@ -246,8 +245,8 @@ public class VideoMenu extends PieController public void onPreferenceClicked(ListPreference pref) { if (mPopupStatus != POPUP_FIRST_LEVEL) return; - LayoutInflater inflater = mActivity.getLayoutInflater(); - ListPrefSettingPopup basic = (ListPrefSettingPopup) inflater.inflate( + ListPrefSettingPopup basic = + (ListPrefSettingPopup) mActivity.getLayoutInflater().inflate( R.layout.list_pref_setting_popup, null, false); basic.initialize(pref); basic.setSettingChangedListener(this); @@ -257,4 +256,26 @@ public class VideoMenu extends PieController mPopupStatus = POPUP_SECOND_LEVEL; } + // Initialize the second-level settings popup + protected void initializeSettingsPopup() { + MoreSettingPopup popup = + (MoreSettingPopup) mActivity.getLayoutInflater().inflate( + R.layout.more_setting_popup, null, false); + popup.initialize(mPreferenceGroup, mSettingsKeys); + popup.setSettingChangedListener(VideoMenu.this); + mSettingsPopup = popup; + } + + // Show a popup options list + protected void showListPopup(ListPreference pref) { + ListPrefSettingPopup popup = + (ListPrefSettingPopup) mActivity.getLayoutInflater().inflate( + R.layout.list_pref_setting_popup, null, false); + popup.initialize(pref); + popup.setSettingChangedListener(VideoMenu.this); + mUI.dismissPopup(); + mPopup = popup; + mUI.showPopup(mPopup); + } + } diff --git a/src/com/android/camera/VideoUI.java b/src/com/android/camera/VideoUI.java index 0d4c0f854..d4ac9d2aa 100644 --- a/src/com/android/camera/VideoUI.java +++ b/src/com/android/camera/VideoUI.java @@ -433,7 +433,8 @@ public class VideoUI implements PieRenderer.PieListener, ((CameraRootView) mRootView).removeDisplayChangeListener(); } - public void overrideSettings(final String... keyvalues) { + public void overrideSettings(final String ... keyvalues) { + if (mVideoMenu == null) return; mVideoMenu.overrideSettings(keyvalues); } @@ -556,6 +557,15 @@ public class VideoUI implements PieRenderer.PieListener, } } + public void showPopup(AbstractSettingPopup popup) { + hideUI(); + + if (mPopup != null) { + mPopup.dismiss(); + } + mPopup = new SettingsPopup(popup); + } + public void dismissPopup() { // In review mode, we do not want to bring up the camera UI if (mController.isInReviewMode()) return; @@ -568,15 +578,6 @@ public class VideoUI implements PieRenderer.PieListener, mPopup = null; } - public void showPopup(AbstractSettingPopup popup) { - hideUI(); - - if (mPopup != null) { - mPopup.dismiss(); - } - mPopup = new SettingsPopup(popup); - } - public void onShowSwitcherPopup() { hidePieRenderer(); } diff --git a/src/com/android/camera/ui/PieItem.java b/src/com/android/camera/ui/PieItem.java index 47fe06758..e62486a76 100644 --- a/src/com/android/camera/ui/PieItem.java +++ b/src/com/android/camera/ui/PieItem.java @@ -139,7 +139,7 @@ public class PieItem { } public void performClick() { - if (mOnClickListener != null) { + if (mOnClickListener != null && mEnabled) { mOnClickListener.onClick(this); } } |