2 * Copyright (C) 2012 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.camera;
19 import android.content.Context;
20 import android.content.res.Resources;
21 import android.hardware.Camera.Parameters;
22 import android.view.LayoutInflater;
24 import com.android.camera.ui.AbstractSettingPopup;
25 import com.android.camera.ui.ListPrefSettingPopup;
26 import com.android.camera.ui.MoreSettingPopup;
27 import com.android.camera.ui.PieItem;
28 import com.android.camera.ui.PieItem.OnClickListener;
29 import com.android.camera.ui.PieRenderer;
30 import com.android.camera.ui.TimerSettingPopup;
31 import com.android.gallery3d.R;
33 public class PhotoMenu extends PieController
34 implements MoreSettingPopup.Listener,
35 TimerSettingPopup.Listener,
36 ListPrefSettingPopup.Listener {
37 private static String TAG = "CAM_photomenu";
39 private static final int POS_HDR = 0;
40 private static final int POS_EXP = 1;
41 private static final int POS_MORE = 2;
42 private static final int POS_FLASH = 3;
43 private static final int POS_SWITCH = 4;
44 private static final int POS_WB = 1;
45 private static final int POS_SET = 2;
47 private final String mSettingOff;
50 private String[] mOtherKeys;
52 private MoreSettingPopup mPopup;
54 private AbstractSettingPopup mSecondPopup;
55 private CameraActivity mActivity;
57 public PhotoMenu(CameraActivity activity, PhotoUI ui, PieRenderer pie) {
60 mSettingOff = activity.getString(R.string.setting_off_value);
64 public void initialize(PreferenceGroup group) {
65 super.initialize(group);
69 final Resources res = mActivity.getResources();
71 if (group.findPreference(CameraSettings.KEY_FLASH_MODE) != null) {
72 item = makeItem(CameraSettings.KEY_FLASH_MODE, POS_FLASH, 5);
73 item.setLabel(res.getString(R.string.pref_camera_flashmode_label));
74 mRenderer.addItem(item);
76 // exposure compensation
77 if (group.findPreference(CameraSettings.KEY_EXPOSURE) != null) {
78 item = makeItem(CameraSettings.KEY_EXPOSURE, POS_EXP, 5);
79 item.setLabel(res.getString(R.string.pref_exposure_label));
80 mRenderer.addItem(item);
83 if (group.findPreference(CameraSettings.KEY_CAMERA_ID) != null) {
84 item = makeItem(R.drawable.ic_switch_back);
85 item.setPosition(POS_SWITCH, 5);
86 IconListPreference lpref = (IconListPreference) group.findPreference(
87 CameraSettings.KEY_CAMERA_ID);
88 item.setImageResource(mActivity,
89 ((IconListPreference) lpref).getIconIds()
90 [lpref.findIndexOfValue(lpref.getValue())]);
91 item.setLabel(lpref.getLabel());
92 final PieItem fitem = item;
93 item.setOnClickListener(new OnClickListener() {
95 public void onClick(PieItem item) {
96 // Find the index of next camera.
97 ListPreference camPref = mPreferenceGroup
98 .findPreference(CameraSettings.KEY_CAMERA_ID);
99 if (camPref != null) {
100 int index = camPref.findIndexOfValue(camPref.getValue());
101 CharSequence[] values = camPref.getEntryValues();
102 index = (index + 1) % values.length;
103 int newCameraId = Integer
104 .parseInt((String) values[index]);
105 fitem.setLabel(camPref.getLabel());
106 fitem.setImageResource(mActivity,
107 ((IconListPreference) camPref).getIconIds()[index]);
108 mListener.onCameraPickerClicked(newCameraId);
112 mRenderer.addItem(item);
115 if (group.findPreference(CameraSettings.KEY_CAMERA_HDR) != null) {
116 ListPreference lp = group.findPreference(CameraSettings.KEY_CAMERA_HDR);
117 item = makeItem(R.drawable.ic_hdr);
118 item.setLabel(lp.getLabel());
119 item.setPosition(POS_HDR, 5);
120 final PieItem fitem = item;
121 item.setOnClickListener(new OnClickListener() {
123 public void onClick(PieItem item) {
124 // Find the index of next camera.
125 ListPreference pref = mPreferenceGroup
126 .findPreference(CameraSettings.KEY_CAMERA_HDR);
129 int index = (pref.findIndexOfValue(pref.getValue()) + 1) % 2;
130 pref.setValueIndex(index);
131 onSettingChanged(pref);
132 fitem.setLabel(pref.getLabel());
136 mRenderer.addItem(item);
140 PieItem more = makeItem(R.drawable.ic_settings_holo_light);
141 more.setPosition(POS_MORE, 5);
142 more.setLabel(res.getString(R.string.camera_menu_more_label));
143 mRenderer.addItem(more);
145 if (group.findPreference(CameraSettings.KEY_WHITE_BALANCE) != null) {
146 item = makeItem(CameraSettings.KEY_WHITE_BALANCE, POS_WB, 5);
147 item.setLabel(res.getString(R.string.pref_camera_whitebalance_label));
151 mOtherKeys = new String[] {
152 CameraSettings.KEY_SCENE_MODE,
153 CameraSettings.KEY_RECORD_LOCATION,
154 CameraSettings.KEY_PICTURE_SIZE,
155 CameraSettings.KEY_FOCUS_MODE,
156 CameraSettings.KEY_TIMER,
157 CameraSettings.KEY_TIMER_SOUND_EFFECTS,
159 item = makeItem(R.drawable.ic_settings_holo_light);
160 item.setLabel(res.getString(R.string.camera_menu_settings_label));
161 item.setPosition(POS_SET, 5);
162 item.setOnClickListener(new OnClickListener() {
164 public void onClick(PieItem item) {
165 if (mPopup == null) {
168 mUI.showPopup(mPopup);
175 public void reloadPreferences() {
176 super.reloadPreferences();
177 if (mPopup != null) {
178 mPopup.reloadPreference();
183 // Hit when an item in the second-level popup gets selected
184 public void onListPrefChanged(ListPreference pref) {
185 if (mPopup != null && mSecondPopup != null) {
186 mUI.dismissPopup(true);
187 mPopup.reloadPreference();
189 onSettingChanged(pref);
193 public void overrideSettings(final String ... keyvalues) {
194 super.overrideSettings(keyvalues);
195 if (mPopup == null) initializePopup();
196 mPopup.overrideSettings(keyvalues);
199 protected void initializePopup() {
200 LayoutInflater inflater = (LayoutInflater) mActivity.getSystemService(
201 Context.LAYOUT_INFLATER_SERVICE);
203 MoreSettingPopup popup = (MoreSettingPopup) inflater.inflate(
204 R.layout.more_setting_popup, null, false);
205 popup.setSettingChangedListener(this);
206 popup.initialize(mPreferenceGroup, mOtherKeys);
207 if (mActivity.isSecureCamera()) {
208 // Prevent location preference from getting changed in secure camera mode
209 popup.setPreferenceEnabled(CameraSettings.KEY_RECORD_LOCATION, false);
214 public void popupDismissed(boolean topPopupOnly) {
215 // if the 2nd level popup gets dismissed
216 if (mSecondPopup != null) {
218 if (topPopupOnly) mUI.showPopup(mPopup);
222 // Return true if the preference has the specified key but not the value.
223 private static boolean notSame(ListPreference pref, String key, String value) {
224 return (key.equals(pref.getKey()) && !value.equals(pref.getValue()));
227 private void setPreference(String key, String value) {
228 ListPreference pref = mPreferenceGroup.findPreference(key);
229 if (pref != null && !value.equals(pref.getValue())) {
230 pref.setValue(value);
236 public void onSettingChanged(ListPreference pref) {
237 // Reset the scene mode if HDR is set to on. Reset HDR if scene mode is
239 if (notSame(pref, CameraSettings.KEY_CAMERA_HDR, mSettingOff)) {
240 setPreference(CameraSettings.KEY_SCENE_MODE, Parameters.SCENE_MODE_AUTO);
241 } else if (notSame(pref, CameraSettings.KEY_SCENE_MODE, Parameters.SCENE_MODE_AUTO)) {
242 setPreference(CameraSettings.KEY_CAMERA_HDR, mSettingOff);
244 super.onSettingChanged(pref);
248 // Hit when an item in the first-level popup gets selected, then bring up
249 // the second-level popup
250 public void onPreferenceClicked(ListPreference pref) {
251 if (mSecondPopup != null) return;
253 LayoutInflater inflater = (LayoutInflater) mActivity.getSystemService(
254 Context.LAYOUT_INFLATER_SERVICE);
255 if (CameraSettings.KEY_TIMER.equals(pref.getKey())) {
256 TimerSettingPopup timerPopup = (TimerSettingPopup) inflater.inflate(
257 R.layout.timer_setting_popup, null, false);
258 timerPopup.initialize(pref);
259 timerPopup.setSettingChangedListener(this);
260 mUI.dismissPopup(true);
261 mSecondPopup = timerPopup;
263 ListPrefSettingPopup basic = (ListPrefSettingPopup) inflater.inflate(
264 R.layout.list_pref_setting_popup, null, false);
265 basic.initialize(pref);
266 basic.setSettingChangedListener(this);
267 mUI.dismissPopup(true);
268 mSecondPopup = basic;
270 mUI.showPopup(mSecondPopup);