Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.camera; |
| 18 | |
Sascha Haeberling | 8e963a5 | 2013-08-06 11:43:02 -0700 | [diff] [blame] | 19 | import java.util.Locale; |
| 20 | |
Michael Kolb | 10f4ba0 | 2013-04-10 08:50:51 -0700 | [diff] [blame] | 21 | import android.content.res.Resources; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 22 | import android.hardware.Camera.Parameters; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 23 | |
| 24 | import com.android.camera.ui.AbstractSettingPopup; |
Michael Kolb | 7048972 | 2013-05-08 11:14:35 -0700 | [diff] [blame] | 25 | import com.android.camera.ui.CountdownTimerPopup; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 26 | import com.android.camera.ui.ListPrefSettingPopup; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 27 | import com.android.camera.ui.PieItem; |
| 28 | import com.android.camera.ui.PieItem.OnClickListener; |
| 29 | import com.android.camera.ui.PieRenderer; |
Sascha Haeberling | 8e963a5 | 2013-08-06 11:43:02 -0700 | [diff] [blame] | 30 | import com.android.camera2.R; |
Michael Kolb | 7048972 | 2013-05-08 11:14:35 -0700 | [diff] [blame] | 31 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 32 | public class PhotoMenu extends PieController |
Michael Kolb | 7048972 | 2013-05-08 11:14:35 -0700 | [diff] [blame] | 33 | implements CountdownTimerPopup.Listener, |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 34 | ListPrefSettingPopup.Listener { |
| 35 | private static String TAG = "CAM_photomenu"; |
Michael Kolb | 3daa351 | 2013-04-02 16:03:04 -0700 | [diff] [blame] | 36 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 37 | private final String mSettingOff; |
| 38 | |
| 39 | private PhotoUI mUI; |
Michael Kolb | 7048972 | 2013-05-08 11:14:35 -0700 | [diff] [blame] | 40 | private AbstractSettingPopup mPopup; |
Doris Liu | 753bb8a | 2013-03-14 21:01:35 -0700 | [diff] [blame] | 41 | private CameraActivity mActivity; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 42 | |
| 43 | public PhotoMenu(CameraActivity activity, PhotoUI ui, PieRenderer pie) { |
| 44 | super(activity, pie); |
| 45 | mUI = ui; |
| 46 | mSettingOff = activity.getString(R.string.setting_off_value); |
Doris Liu | 753bb8a | 2013-03-14 21:01:35 -0700 | [diff] [blame] | 47 | mActivity = activity; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | public void initialize(PreferenceGroup group) { |
| 51 | super.initialize(group); |
| 52 | mPopup = null; |
Michael Kolb | 3bc96b2 | 2013-03-12 10:24:42 -0700 | [diff] [blame] | 53 | PieItem item = null; |
Michael Kolb | 10f4ba0 | 2013-04-10 08:50:51 -0700 | [diff] [blame] | 54 | final Resources res = mActivity.getResources(); |
Michael Kolb | 7048972 | 2013-05-08 11:14:35 -0700 | [diff] [blame] | 55 | Locale locale = res.getConfiguration().locale; |
Michael Kolb | b7c4999 | 2013-04-30 09:23:23 -0700 | [diff] [blame] | 56 | // the order is from left to right in the menu |
| 57 | |
| 58 | // hdr |
| 59 | if (group.findPreference(CameraSettings.KEY_CAMERA_HDR) != null) { |
| 60 | item = makeSwitchItem(CameraSettings.KEY_CAMERA_HDR, true); |
Michael Kolb | 3bc96b2 | 2013-03-12 10:24:42 -0700 | [diff] [blame] | 61 | mRenderer.addItem(item); |
| 62 | } |
| 63 | // exposure compensation |
Michael Kolb | 5cf3c47 | 2013-04-05 09:52:55 -0700 | [diff] [blame] | 64 | if (group.findPreference(CameraSettings.KEY_EXPOSURE) != null) { |
Michael Kolb | b7c4999 | 2013-04-30 09:23:23 -0700 | [diff] [blame] | 65 | item = makeItem(CameraSettings.KEY_EXPOSURE); |
Michael Kolb | 10f4ba0 | 2013-04-10 08:50:51 -0700 | [diff] [blame] | 66 | item.setLabel(res.getString(R.string.pref_exposure_label)); |
Michael Kolb | 5cf3c47 | 2013-04-05 09:52:55 -0700 | [diff] [blame] | 67 | mRenderer.addItem(item); |
| 68 | } |
Michael Kolb | b7c4999 | 2013-04-30 09:23:23 -0700 | [diff] [blame] | 69 | // more settings |
| 70 | PieItem more = makeItem(R.drawable.ic_settings_holo_light); |
| 71 | more.setLabel(res.getString(R.string.camera_menu_more_label)); |
| 72 | mRenderer.addItem(more); |
| 73 | // flash |
| 74 | if (group.findPreference(CameraSettings.KEY_FLASH_MODE) != null) { |
| 75 | item = makeItem(CameraSettings.KEY_FLASH_MODE); |
| 76 | item.setLabel(res.getString(R.string.pref_camera_flashmode_label)); |
| 77 | mRenderer.addItem(item); |
| 78 | } |
Michael Kolb | 3bc96b2 | 2013-03-12 10:24:42 -0700 | [diff] [blame] | 79 | // camera switcher |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 80 | if (group.findPreference(CameraSettings.KEY_CAMERA_ID) != null) { |
Michael Kolb | b7c4999 | 2013-04-30 09:23:23 -0700 | [diff] [blame] | 81 | item = makeSwitchItem(CameraSettings.KEY_CAMERA_ID, false); |
Michael Kolb | 10f4ba0 | 2013-04-10 08:50:51 -0700 | [diff] [blame] | 82 | final PieItem fitem = item; |
Michael Kolb | 3bc96b2 | 2013-03-12 10:24:42 -0700 | [diff] [blame] | 83 | item.setOnClickListener(new OnClickListener() { |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 84 | @Override |
| 85 | public void onClick(PieItem item) { |
| 86 | // Find the index of next camera. |
| 87 | ListPreference pref = mPreferenceGroup |
Michael Kolb | 25c0ec4 | 2013-04-18 12:31:10 -0700 | [diff] [blame] | 88 | .findPreference(CameraSettings.KEY_CAMERA_ID); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 89 | if (pref != null) { |
Michael Kolb | 25c0ec4 | 2013-04-18 12:31:10 -0700 | [diff] [blame] | 90 | int index = pref.findIndexOfValue(pref.getValue()); |
| 91 | CharSequence[] values = pref.getEntryValues(); |
| 92 | index = (index + 1) % values.length; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 93 | pref.setValueIndex(index); |
Michael Kolb | 25c0ec4 | 2013-04-18 12:31:10 -0700 | [diff] [blame] | 94 | mListener.onCameraPickerClicked(index); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 95 | } |
Michael Kolb | 25c0ec4 | 2013-04-18 12:31:10 -0700 | [diff] [blame] | 96 | updateItem(fitem, CameraSettings.KEY_CAMERA_ID); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 97 | } |
| 98 | }); |
Michael Kolb | 3bc96b2 | 2013-03-12 10:24:42 -0700 | [diff] [blame] | 99 | mRenderer.addItem(item); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 100 | } |
Michael Kolb | 25c0ec4 | 2013-04-18 12:31:10 -0700 | [diff] [blame] | 101 | // location |
| 102 | if (group.findPreference(CameraSettings.KEY_RECORD_LOCATION) != null) { |
Michael Kolb | b7c4999 | 2013-04-30 09:23:23 -0700 | [diff] [blame] | 103 | item = makeSwitchItem(CameraSettings.KEY_RECORD_LOCATION, true); |
Michael Kolb | 25c0ec4 | 2013-04-18 12:31:10 -0700 | [diff] [blame] | 104 | more.addItem(item); |
Michael Kolb | 7048972 | 2013-05-08 11:14:35 -0700 | [diff] [blame] | 105 | if (mActivity.isSecureCamera()) { |
| 106 | // Prevent location preference from getting changed in secure camera mode |
| 107 | item.setEnabled(false); |
| 108 | } |
Michael Kolb | 25c0ec4 | 2013-04-18 12:31:10 -0700 | [diff] [blame] | 109 | } |
Michael Kolb | 7048972 | 2013-05-08 11:14:35 -0700 | [diff] [blame] | 110 | // countdown timer |
| 111 | final ListPreference ctpref = group.findPreference(CameraSettings.KEY_TIMER); |
| 112 | final ListPreference beeppref = group.findPreference(CameraSettings.KEY_TIMER_SOUND_EFFECTS); |
| 113 | item = makeItem(R.drawable.ic_timer); |
| 114 | item.setLabel(res.getString(R.string.pref_camera_timer_title).toUpperCase(locale)); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 115 | item.setOnClickListener(new OnClickListener() { |
| 116 | @Override |
| 117 | public void onClick(PieItem item) { |
Michael Kolb | 7048972 | 2013-05-08 11:14:35 -0700 | [diff] [blame] | 118 | CountdownTimerPopup timerPopup = (CountdownTimerPopup) mActivity.getLayoutInflater().inflate( |
| 119 | R.layout.countdown_setting_popup, null, false); |
| 120 | timerPopup.initialize(ctpref, beeppref); |
| 121 | timerPopup.setSettingChangedListener(PhotoMenu.this); |
| 122 | mUI.dismissPopup(); |
| 123 | mPopup = timerPopup; |
| 124 | mUI.showPopup(mPopup); |
| 125 | } |
| 126 | }); |
| 127 | more.addItem(item); |
| 128 | // image size |
| 129 | item = makeItem(R.drawable.ic_imagesize); |
| 130 | final ListPreference sizePref = group.findPreference(CameraSettings.KEY_PICTURE_SIZE); |
| 131 | item.setLabel(res.getString(R.string.pref_camera_picturesize_title).toUpperCase(locale)); |
| 132 | item.setOnClickListener(new OnClickListener() { |
| 133 | @Override |
| 134 | public void onClick(PieItem item) { |
| 135 | ListPrefSettingPopup popup = (ListPrefSettingPopup) mActivity.getLayoutInflater().inflate( |
| 136 | R.layout.list_pref_setting_popup, null, false); |
| 137 | popup.initialize(sizePref); |
| 138 | popup.setSettingChangedListener(PhotoMenu.this); |
| 139 | mUI.dismissPopup(); |
| 140 | mPopup = popup; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 141 | mUI.showPopup(mPopup); |
| 142 | } |
| 143 | }); |
Michael Kolb | 3bc96b2 | 2013-03-12 10:24:42 -0700 | [diff] [blame] | 144 | more.addItem(item); |
Michael Kolb | b7c4999 | 2013-04-30 09:23:23 -0700 | [diff] [blame] | 145 | // white balance |
| 146 | if (group.findPreference(CameraSettings.KEY_WHITE_BALANCE) != null) { |
| 147 | item = makeItem(CameraSettings.KEY_WHITE_BALANCE); |
| 148 | item.setLabel(res.getString(R.string.pref_camera_whitebalance_label)); |
| 149 | more.addItem(item); |
| 150 | } |
| 151 | // scene mode |
| 152 | if (group.findPreference(CameraSettings.KEY_SCENE_MODE) != null) { |
| 153 | IconListPreference pref = (IconListPreference) group.findPreference( |
| 154 | CameraSettings.KEY_SCENE_MODE); |
| 155 | pref.setUseSingleIcon(true); |
| 156 | item = makeItem(CameraSettings.KEY_SCENE_MODE); |
| 157 | more.addItem(item); |
| 158 | } |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | @Override |
Michael Kolb | 7048972 | 2013-05-08 11:14:35 -0700 | [diff] [blame] | 162 | // Hit when an item in a popup gets selected |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 163 | public void onListPrefChanged(ListPreference pref) { |
Michael Kolb | 7048972 | 2013-05-08 11:14:35 -0700 | [diff] [blame] | 164 | if (mPopup != null) { |
| 165 | mUI.dismissPopup(); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 166 | } |
| 167 | onSettingChanged(pref); |
| 168 | } |
| 169 | |
Michael Kolb | 7048972 | 2013-05-08 11:14:35 -0700 | [diff] [blame] | 170 | public void popupDismissed() { |
Michael Kolb | 7048972 | 2013-05-08 11:14:35 -0700 | [diff] [blame] | 171 | if (mPopup != null) { |
| 172 | mPopup = null; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 173 | } |
| 174 | } |
| 175 | |
| 176 | // Return true if the preference has the specified key but not the value. |
| 177 | private static boolean notSame(ListPreference pref, String key, String value) { |
| 178 | return (key.equals(pref.getKey()) && !value.equals(pref.getValue())); |
| 179 | } |
| 180 | |
| 181 | private void setPreference(String key, String value) { |
| 182 | ListPreference pref = mPreferenceGroup.findPreference(key); |
| 183 | if (pref != null && !value.equals(pref.getValue())) { |
| 184 | pref.setValue(value); |
| 185 | reloadPreferences(); |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | @Override |
| 190 | public void onSettingChanged(ListPreference pref) { |
| 191 | // Reset the scene mode if HDR is set to on. Reset HDR if scene mode is |
| 192 | // set to non-auto. |
| 193 | if (notSame(pref, CameraSettings.KEY_CAMERA_HDR, mSettingOff)) { |
| 194 | setPreference(CameraSettings.KEY_SCENE_MODE, Parameters.SCENE_MODE_AUTO); |
| 195 | } else if (notSame(pref, CameraSettings.KEY_SCENE_MODE, Parameters.SCENE_MODE_AUTO)) { |
| 196 | setPreference(CameraSettings.KEY_CAMERA_HDR, mSettingOff); |
| 197 | } |
| 198 | super.onSettingChanged(pref); |
| 199 | } |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 200 | } |