blob: f0c7db272c08770638c92d9223652b40d0dd6c81 [file] [log] [blame]
Michael Kolb8872c232013-01-29 10:33:22 -08001/*
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
17package com.android.camera;
18
19import android.content.Context;
20import android.view.LayoutInflater;
21
22import com.android.camera.ui.AbstractSettingPopup;
23import com.android.camera.ui.ListPrefSettingPopup;
24import com.android.camera.ui.MoreSettingPopup;
25import com.android.camera.ui.PieItem;
26import com.android.camera.ui.PieItem.OnClickListener;
27import com.android.camera.ui.PieRenderer;
28import com.android.camera.ui.TimeIntervalPopup;
Sascha Haeberling8e963a52013-08-06 11:43:02 -070029import com.android.camera2.R;
Michael Kolb8872c232013-01-29 10:33:22 -080030
Michael Kolbd6954f32013-03-08 20:43:01 -080031public class VideoMenu extends PieController
Michael Kolb8872c232013-01-29 10:33:22 -080032 implements MoreSettingPopup.Listener,
33 ListPrefSettingPopup.Listener,
34 TimeIntervalPopup.Listener {
35
Doris Liu6827ce22013-03-12 19:24:28 -070036 private static String TAG = "CAM_VideoMenu";
Michael Kolb8872c232013-01-29 10:33:22 -080037
Doris Liu6827ce22013-03-12 19:24:28 -070038 private VideoUI mUI;
Michael Kolb8872c232013-01-29 10:33:22 -080039 private String[] mOtherKeys;
40 private AbstractSettingPopup mPopup;
41
42 private static final int POPUP_NONE = 0;
43 private static final int POPUP_FIRST_LEVEL = 1;
44 private static final int POPUP_SECOND_LEVEL = 2;
45 private int mPopupStatus;
Doris Liu753bb8a2013-03-14 21:01:35 -070046 private CameraActivity mActivity;
Michael Kolb8872c232013-01-29 10:33:22 -080047
Doris Liu6827ce22013-03-12 19:24:28 -070048 public VideoMenu(CameraActivity activity, VideoUI ui, PieRenderer pie) {
Michael Kolb8872c232013-01-29 10:33:22 -080049 super(activity, pie);
Doris Liu6827ce22013-03-12 19:24:28 -070050 mUI = ui;
Doris Liu753bb8a2013-03-14 21:01:35 -070051 mActivity = activity;
Michael Kolb8872c232013-01-29 10:33:22 -080052 }
53
Doris Liu6432cd62013-06-13 17:20:31 -070054
Michael Kolb8872c232013-01-29 10:33:22 -080055 public void initialize(PreferenceGroup group) {
56 super.initialize(group);
57 mPopup = null;
58 mPopupStatus = POPUP_NONE;
Jason Noguchi4205d502013-04-11 17:39:20 -070059 PieItem item = null;
Jason Noguchi4205d502013-04-11 17:39:20 -070060 // white balance
61 if (group.findPreference(CameraSettings.KEY_WHITE_BALANCE) != null) {
Michael Kolbb7c49992013-04-30 09:23:23 -070062 item = makeItem(CameraSettings.KEY_WHITE_BALANCE);
Jason Noguchi4205d502013-04-11 17:39:20 -070063 mRenderer.addItem(item);
64 }
Michael Kolbb7c49992013-04-30 09:23:23 -070065 // settings popup
66 mOtherKeys = new String[] {
67 CameraSettings.KEY_VIDEO_EFFECT,
68 CameraSettings.KEY_VIDEO_TIME_LAPSE_FRAME_INTERVAL,
69 CameraSettings.KEY_VIDEO_QUALITY,
70 CameraSettings.KEY_RECORD_LOCATION
71 };
72 item = makeItem(R.drawable.ic_settings_holo_light);
73 item.setLabel(mActivity.getResources().getString(R.string.camera_menu_settings_label));
74 item.setOnClickListener(new OnClickListener() {
75 @Override
76 public void onClick(PieItem item) {
77 if (mPopup == null || mPopupStatus != POPUP_FIRST_LEVEL) {
78 initializePopup();
79 mPopupStatus = POPUP_FIRST_LEVEL;
80 }
81 mUI.showPopup(mPopup);
82 }
83 });
84 mRenderer.addItem(item);
Michael Kolb3bc96b22013-03-12 10:24:42 -070085 // camera switcher
Jason Noguchi4205d502013-04-11 17:39:20 -070086 if (group.findPreference(CameraSettings.KEY_CAMERA_ID) != null) {
Michael Kolb172d37e2013-04-17 16:01:32 -070087 item = makeItem(R.drawable.ic_switch_back);
Michael Kolb172d37e2013-04-17 16:01:32 -070088 IconListPreference lpref = (IconListPreference) group.findPreference(
89 CameraSettings.KEY_CAMERA_ID);
Michael Kolb0408c9a2013-04-15 13:17:27 -070090 item.setLabel(lpref.getLabel());
Michael Kolb172d37e2013-04-17 16:01:32 -070091 item.setImageResource(mActivity,
92 ((IconListPreference) lpref).getIconIds()
93 [lpref.findIndexOfValue(lpref.getValue())]);
94
Michael Kolb0408c9a2013-04-15 13:17:27 -070095 final PieItem fitem = item;
Jason Noguchi4205d502013-04-11 17:39:20 -070096 item.setOnClickListener(new OnClickListener() {
Michael Kolb8872c232013-01-29 10:33:22 -080097
Jason Noguchi4205d502013-04-11 17:39:20 -070098 @Override
99 public void onClick(PieItem item) {
100 // Find the index of next camera.
101 ListPreference pref =
102 mPreferenceGroup.findPreference(CameraSettings.KEY_CAMERA_ID);
103 if (pref != null) {
104 int index = pref.findIndexOfValue(pref.getValue());
105 CharSequence[] values = pref.getEntryValues();
106 index = (index + 1) % values.length;
107 int newCameraId = Integer.parseInt((String) values[index]);
Michael Kolb172d37e2013-04-17 16:01:32 -0700108 fitem.setImageResource(mActivity,
109 ((IconListPreference) pref).getIconIds()[index]);
Michael Kolb0408c9a2013-04-15 13:17:27 -0700110 fitem.setLabel(pref.getLabel());
Michael Kolb172d37e2013-04-17 16:01:32 -0700111 mListener.onCameraPickerClicked(newCameraId);
Jason Noguchi4205d502013-04-11 17:39:20 -0700112 }
Michael Kolb8872c232013-01-29 10:33:22 -0800113 }
Jason Noguchi4205d502013-04-11 17:39:20 -0700114 });
115 mRenderer.addItem(item);
116 }
Michael Kolbb7c49992013-04-30 09:23:23 -0700117 // flash
118 if (group.findPreference(CameraSettings.KEY_VIDEOCAMERA_FLASH_MODE) != null) {
119 item = makeItem(CameraSettings.KEY_VIDEOCAMERA_FLASH_MODE);
120 mRenderer.addItem(item);
121 }
Michael Kolb8872c232013-01-29 10:33:22 -0800122 }
123
Michael Kolb8872c232013-01-29 10:33:22 -0800124 @Override
125 public void reloadPreferences() {
126 super.reloadPreferences();
127 if (mPopup != null) {
128 mPopup.reloadPreference();
129 }
130 }
131
132 @Override
133 public void overrideSettings(final String ... keyvalues) {
134 super.overrideSettings(keyvalues);
135 if (mPopup == null || mPopupStatus != POPUP_FIRST_LEVEL) {
136 mPopupStatus = POPUP_FIRST_LEVEL;
137 initializePopup();
138 }
139 ((MoreSettingPopup) mPopup).overrideSettings(keyvalues);
140 }
141
142 @Override
143 // Hit when an item in the second-level popup gets selected
144 public void onListPrefChanged(ListPreference pref) {
145 if (mPopup != null) {
146 if (mPopupStatus == POPUP_SECOND_LEVEL) {
Doris Liu6827ce22013-03-12 19:24:28 -0700147 mUI.dismissPopup(true);
Michael Kolb8872c232013-01-29 10:33:22 -0800148 }
149 }
150 super.onSettingChanged(pref);
151 }
152
153 protected void initializePopup() {
154 LayoutInflater inflater = (LayoutInflater) mActivity.getSystemService(
155 Context.LAYOUT_INFLATER_SERVICE);
156
157 MoreSettingPopup popup = (MoreSettingPopup) inflater.inflate(
158 R.layout.more_setting_popup, null, false);
159 popup.setSettingChangedListener(this);
160 popup.initialize(mPreferenceGroup, mOtherKeys);
161 if (mActivity.isSecureCamera()) {
162 // Prevent location preference from getting changed in secure camera mode
163 popup.setPreferenceEnabled(CameraSettings.KEY_RECORD_LOCATION, false);
164 }
165 mPopup = popup;
166 }
167
168 public void popupDismissed(boolean topPopupOnly) {
169 // if the 2nd level popup gets dismissed
170 if (mPopupStatus == POPUP_SECOND_LEVEL) {
171 initializePopup();
172 mPopupStatus = POPUP_FIRST_LEVEL;
Doris Liu6827ce22013-03-12 19:24:28 -0700173 if (topPopupOnly) mUI.showPopup(mPopup);
Michael Kolb8872c232013-01-29 10:33:22 -0800174 }
175 }
176
177 @Override
178 // Hit when an item in the first-level popup gets selected, then bring up
179 // the second-level popup
180 public void onPreferenceClicked(ListPreference pref) {
181 if (mPopupStatus != POPUP_FIRST_LEVEL) return;
182
183 LayoutInflater inflater = (LayoutInflater) mActivity.getSystemService(
184 Context.LAYOUT_INFLATER_SERVICE);
185
186 if (CameraSettings.KEY_VIDEO_TIME_LAPSE_FRAME_INTERVAL.equals(pref.getKey())) {
187 TimeIntervalPopup timeInterval = (TimeIntervalPopup) inflater.inflate(
188 R.layout.time_interval_popup, null, false);
189 timeInterval.initialize((IconListPreference) pref);
190 timeInterval.setSettingChangedListener(this);
Doris Liu6827ce22013-03-12 19:24:28 -0700191 mUI.dismissPopup(true);
Michael Kolb8872c232013-01-29 10:33:22 -0800192 mPopup = timeInterval;
193 } else {
194 ListPrefSettingPopup basic = (ListPrefSettingPopup) inflater.inflate(
195 R.layout.list_pref_setting_popup, null, false);
196 basic.initialize(pref);
197 basic.setSettingChangedListener(this);
Doris Liu6827ce22013-03-12 19:24:28 -0700198 mUI.dismissPopup(true);
Michael Kolb8872c232013-01-29 10:33:22 -0800199 mPopup = basic;
200 }
Doris Liu6827ce22013-03-12 19:24:28 -0700201 mUI.showPopup(mPopup);
Michael Kolb8872c232013-01-29 10:33:22 -0800202 mPopupStatus = POPUP_SECOND_LEVEL;
203 }
Michael Kolb8872c232013-01-29 10:33:22 -0800204}