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.hardware.Camera.Parameters;
21 import android.view.LayoutInflater;
23 import com.android.camera.ui.AbstractSettingPopup;
24 import com.android.camera.ui.ListPrefSettingPopup;
25 import com.android.camera.ui.MoreSettingPopup;
26 import com.android.camera.ui.PieItem;
27 import com.android.camera.ui.PieItem.OnClickListener;
28 import com.android.camera.ui.PieRenderer;
29 import com.android.camera.ui.TimerSettingPopup;
30 import com.android.gallery3d.R;
32 public class PhotoMenu extends PieController
33 implements MoreSettingPopup.Listener,
34 TimerSettingPopup.Listener,
35 ListPrefSettingPopup.Listener {
36 private static String TAG = "CAM_photomenu";
38 private static final int POS_HDR = 0;
39 private static final int POS_EXP = 1;
40 private static final int POS_MORE = 2;
41 private static final int POS_FLASH = 3;
42 private static final int POS_SWITCH = 4;
43 private static final int POS_WB = 1;
44 private static final int POS_SET = 2;
46 private final String mSettingOff;
49 private String[] mOtherKeys;
51 private MoreSettingPopup mPopup;
53 private AbstractSettingPopup mSecondPopup;
54 private CameraActivity mActivity;
56 public PhotoMenu(CameraActivity activity, PhotoUI ui, PieRenderer pie) {
59 mSettingOff = activity.getString(R.string.setting_off_value);
63 public void initialize(PreferenceGroup group) {
64 super.initialize(group);
69 if (group.findPreference(CameraSettings.KEY_FLASH_MODE) != null) {
70 item = makeItem(CameraSettings.KEY_FLASH_MODE, POS_FLASH, 5);
71 mRenderer.addItem(item);
73 // exposure compensation
74 if (group.findPreference(CameraSettings.KEY_EXPOSURE) != null) {
75 item = makeItem(CameraSettings.KEY_EXPOSURE, POS_EXP, 5);
76 mRenderer.addItem(item);
79 if (group.findPreference(CameraSettings.KEY_CAMERA_ID) != null) {
80 item = makeItem(R.drawable.ic_switch_photo_facing_holo_light);
81 item.setPosition(POS_SWITCH, 5);
82 item.setOnClickListener(new OnClickListener() {
84 public void onClick(PieItem item) {
85 // Find the index of next camera.
86 ListPreference camPref = mPreferenceGroup
87 .findPreference(CameraSettings.KEY_CAMERA_ID);
88 if (camPref != null) {
89 int index = camPref.findIndexOfValue(camPref.getValue());
90 CharSequence[] values = camPref.getEntryValues();
91 index = (index + 1) % values.length;
92 int newCameraId = Integer
93 .parseInt((String) values[index]);
94 mListener.onCameraPickerClicked(newCameraId);
98 mRenderer.addItem(item);
101 if (group.findPreference(CameraSettings.KEY_CAMERA_HDR) != null) {
102 item = makeItem(R.drawable.ic_hdr);
103 item.setPosition(POS_HDR, 5);
104 item.setOnClickListener(new OnClickListener() {
106 public void onClick(PieItem item) {
107 // Find the index of next camera.
108 ListPreference pref = mPreferenceGroup
109 .findPreference(CameraSettings.KEY_CAMERA_HDR);
112 int index = (pref.findIndexOfValue(pref.getValue()) + 1) % 2;
113 pref.setValueIndex(index);
114 onSettingChanged(pref);
118 mRenderer.addItem(item);
122 PieItem more = makeItem(R.drawable.ic_settings_holo_light);
123 more.setPosition(POS_MORE, 5);
124 mRenderer.addItem(more);
126 if (group.findPreference(CameraSettings.KEY_WHITE_BALANCE) != null) {
127 item = makeItem(CameraSettings.KEY_WHITE_BALANCE, POS_WB, 5);
131 mOtherKeys = new String[] {
132 CameraSettings.KEY_SCENE_MODE,
133 CameraSettings.KEY_RECORD_LOCATION,
134 CameraSettings.KEY_PICTURE_SIZE,
135 CameraSettings.KEY_FOCUS_MODE,
136 CameraSettings.KEY_TIMER,
137 CameraSettings.KEY_TIMER_SOUND_EFFECTS,
139 item = makeItem(R.drawable.ic_settings_holo_light);
140 item.setPosition(POS_SET, 5);
141 item.setOnClickListener(new OnClickListener() {
143 public void onClick(PieItem item) {
144 if (mPopup == null) {
147 mUI.showPopup(mPopup);
154 public void reloadPreferences() {
155 super.reloadPreferences();
156 if (mPopup != null) {
157 mPopup.reloadPreference();
162 // Hit when an item in the second-level popup gets selected
163 public void onListPrefChanged(ListPreference pref) {
164 if (mPopup != null && mSecondPopup != null) {
165 mUI.dismissPopup(true);
166 mPopup.reloadPreference();
168 onSettingChanged(pref);
172 public void overrideSettings(final String ... keyvalues) {
173 super.overrideSettings(keyvalues);
174 if (mPopup == null) initializePopup();
175 mPopup.overrideSettings(keyvalues);
178 protected void initializePopup() {
179 LayoutInflater inflater = (LayoutInflater) mActivity.getSystemService(
180 Context.LAYOUT_INFLATER_SERVICE);
182 MoreSettingPopup popup = (MoreSettingPopup) inflater.inflate(
183 R.layout.more_setting_popup, null, false);
184 popup.setSettingChangedListener(this);
185 popup.initialize(mPreferenceGroup, mOtherKeys);
186 if (mActivity.isSecureCamera()) {
187 // Prevent location preference from getting changed in secure camera mode
188 popup.setPreferenceEnabled(CameraSettings.KEY_RECORD_LOCATION, false);
193 public void popupDismissed(boolean topPopupOnly) {
194 // if the 2nd level popup gets dismissed
195 if (mSecondPopup != null) {
197 if (topPopupOnly) mUI.showPopup(mPopup);
201 // Return true if the preference has the specified key but not the value.
202 private static boolean notSame(ListPreference pref, String key, String value) {
203 return (key.equals(pref.getKey()) && !value.equals(pref.getValue()));
206 private void setPreference(String key, String value) {
207 ListPreference pref = mPreferenceGroup.findPreference(key);
208 if (pref != null && !value.equals(pref.getValue())) {
209 pref.setValue(value);
215 public void onSettingChanged(ListPreference pref) {
216 // Reset the scene mode if HDR is set to on. Reset HDR if scene mode is
218 if (notSame(pref, CameraSettings.KEY_CAMERA_HDR, mSettingOff)) {
219 setPreference(CameraSettings.KEY_SCENE_MODE, Parameters.SCENE_MODE_AUTO);
220 } else if (notSame(pref, CameraSettings.KEY_SCENE_MODE, Parameters.SCENE_MODE_AUTO)) {
221 setPreference(CameraSettings.KEY_CAMERA_HDR, mSettingOff);
223 super.onSettingChanged(pref);
227 // Hit when an item in the first-level popup gets selected, then bring up
228 // the second-level popup
229 public void onPreferenceClicked(ListPreference pref) {
230 if (mSecondPopup != null) return;
232 LayoutInflater inflater = (LayoutInflater) mActivity.getSystemService(
233 Context.LAYOUT_INFLATER_SERVICE);
234 if (CameraSettings.KEY_TIMER.equals(pref.getKey())) {
235 TimerSettingPopup timerPopup = (TimerSettingPopup) inflater.inflate(
236 R.layout.timer_setting_popup, null, false);
237 timerPopup.initialize(pref);
238 timerPopup.setSettingChangedListener(this);
239 mUI.dismissPopup(true);
240 mSecondPopup = timerPopup;
242 ListPrefSettingPopup basic = (ListPrefSettingPopup) inflater.inflate(
243 R.layout.list_pref_setting_popup, null, false);
244 basic.initialize(pref);
245 basic.setSettingChangedListener(this);
246 mUI.dismissPopup(true);
247 mSecondPopup = basic;
249 mUI.showPopup(mSecondPopup);