2 * Copyright (C) 2013 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.app.Activity;
20 import android.content.Context;
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.TimeIntervalPopup;
30 import com.android.gallery3d.R;
32 public class NewVideoMenu extends PieController
33 implements MoreSettingPopup.Listener,
34 ListPrefSettingPopup.Listener,
35 TimeIntervalPopup.Listener {
37 private static String TAG = "CAM_VideoMenu";
38 private static final int POS_WB = 1;
39 private static final int POS_SET = 2;
40 private static final int POS_FLASH = 3;
41 private static final int POS_SWITCH = 4;
43 private NewVideoUI mUI;
44 private String[] mOtherKeys;
45 private AbstractSettingPopup mPopup;
47 private static final int POPUP_NONE = 0;
48 private static final int POPUP_FIRST_LEVEL = 1;
49 private static final int POPUP_SECOND_LEVEL = 2;
50 private int mPopupStatus;
51 private NewCameraActivity mActivity;
53 public NewVideoMenu(NewCameraActivity activity, NewVideoUI ui, PieRenderer pie) {
59 public void initialize(PreferenceGroup group) {
60 super.initialize(group);
62 mPopupStatus = POPUP_NONE;
65 if (group.findPreference(CameraSettings.KEY_WHITE_BALANCE) != null) {
66 item = makeItem(CameraSettings.KEY_WHITE_BALANCE);
67 mRenderer.addItem(item);
70 mOtherKeys = new String[] {
71 CameraSettings.KEY_VIDEO_EFFECT,
72 CameraSettings.KEY_VIDEO_TIME_LAPSE_FRAME_INTERVAL,
73 CameraSettings.KEY_VIDEO_QUALITY,
74 CameraSettings.KEY_RECORD_LOCATION
76 item = makeItem(R.drawable.ic_settings_holo_light);
77 item.setLabel(mActivity.getResources().getString(R.string.camera_menu_settings_label));
78 item.setOnClickListener(new OnClickListener() {
80 public void onClick(PieItem item) {
81 if (mPopup == null || mPopupStatus != POPUP_FIRST_LEVEL) {
83 mPopupStatus = POPUP_FIRST_LEVEL;
85 mUI.showPopup(mPopup);
88 mRenderer.addItem(item);
90 if (group.findPreference(CameraSettings.KEY_CAMERA_ID) != null) {
91 item = makeItem(R.drawable.ic_switch_back);
92 IconListPreference lpref = (IconListPreference) group.findPreference(
93 CameraSettings.KEY_CAMERA_ID);
94 item.setLabel(lpref.getLabel());
95 item.setImageResource(mActivity,
96 ((IconListPreference) lpref).getIconIds()
97 [lpref.findIndexOfValue(lpref.getValue())]);
99 final PieItem fitem = item;
100 item.setOnClickListener(new OnClickListener() {
103 public void onClick(PieItem item) {
104 // Find the index of next camera.
105 ListPreference pref =
106 mPreferenceGroup.findPreference(CameraSettings.KEY_CAMERA_ID);
108 int index = pref.findIndexOfValue(pref.getValue());
109 CharSequence[] values = pref.getEntryValues();
110 index = (index + 1) % values.length;
111 int newCameraId = Integer.parseInt((String) values[index]);
112 fitem.setImageResource(mActivity,
113 ((IconListPreference) pref).getIconIds()[index]);
114 fitem.setLabel(pref.getLabel());
115 mListener.onCameraPickerClicked(newCameraId);
119 mRenderer.addItem(item);
122 if (group.findPreference(CameraSettings.KEY_VIDEOCAMERA_FLASH_MODE) != null) {
123 item = makeItem(CameraSettings.KEY_VIDEOCAMERA_FLASH_MODE);
124 mRenderer.addItem(item);
129 public void reloadPreferences() {
130 super.reloadPreferences();
131 if (mPopup != null) {
132 mPopup.reloadPreference();
137 public void overrideSettings(final String ... keyvalues) {
138 super.overrideSettings(keyvalues);
139 if (mPopup == null || mPopupStatus != POPUP_FIRST_LEVEL) {
140 mPopupStatus = POPUP_FIRST_LEVEL;
143 ((MoreSettingPopup) mPopup).overrideSettings(keyvalues);
147 // Hit when an item in the second-level popup gets selected
148 public void onListPrefChanged(ListPreference pref) {
149 if (mPopup != null) {
150 if (mPopupStatus == POPUP_SECOND_LEVEL) {
151 mUI.dismissPopup(true);
154 super.onSettingChanged(pref);
157 protected void initializePopup() {
158 LayoutInflater inflater = (LayoutInflater) mActivity.getSystemService(
159 Context.LAYOUT_INFLATER_SERVICE);
161 MoreSettingPopup popup = (MoreSettingPopup) inflater.inflate(
162 R.layout.more_setting_popup, null, false);
163 popup.setSettingChangedListener(this);
164 popup.initialize(mPreferenceGroup, mOtherKeys);
165 if (mActivity.isSecureCamera()) {
166 // Prevent location preference from getting changed in secure camera mode
167 popup.setPreferenceEnabled(CameraSettings.KEY_RECORD_LOCATION, false);
172 public void popupDismissed(boolean topPopupOnly) {
173 // if the 2nd level popup gets dismissed
174 if (mPopupStatus == POPUP_SECOND_LEVEL) {
176 mPopupStatus = POPUP_FIRST_LEVEL;
177 if (topPopupOnly) mUI.showPopup(mPopup);
182 // Hit when an item in the first-level popup gets selected, then bring up
183 // the second-level popup
184 public void onPreferenceClicked(ListPreference pref) {
185 if (mPopupStatus != POPUP_FIRST_LEVEL) return;
187 LayoutInflater inflater = (LayoutInflater) mActivity.getSystemService(
188 Context.LAYOUT_INFLATER_SERVICE);
190 if (CameraSettings.KEY_VIDEO_TIME_LAPSE_FRAME_INTERVAL.equals(pref.getKey())) {
191 TimeIntervalPopup timeInterval = (TimeIntervalPopup) inflater.inflate(
192 R.layout.time_interval_popup, null, false);
193 timeInterval.initialize((IconListPreference) pref);
194 timeInterval.setSettingChangedListener(this);
195 mUI.dismissPopup(true);
196 mPopup = timeInterval;
198 ListPrefSettingPopup basic = (ListPrefSettingPopup) inflater.inflate(
199 R.layout.list_pref_setting_popup, null, false);
200 basic.initialize(pref);
201 basic.setSettingChangedListener(this);
202 mUI.dismissPopup(true);
205 mUI.showPopup(mPopup);
206 mPopupStatus = POPUP_SECOND_LEVEL;