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.view.LayoutInflater;
22 import com.android.camera.ui.AbstractSettingPopup;
23 import com.android.camera.ui.ListPrefSettingPopup;
24 import com.android.camera.ui.MoreSettingPopup;
25 import com.android.camera.ui.PieItem;
26 import com.android.camera.ui.PieItem.OnClickListener;
27 import com.android.camera.ui.PieRenderer;
28 import com.android.camera.ui.TimeIntervalPopup;
29 import com.android.gallery3d.R;
31 public class VideoController extends PieController
32 implements MoreSettingPopup.Listener,
33 ListPrefSettingPopup.Listener,
34 TimeIntervalPopup.Listener {
37 private static String TAG = "CAM_videocontrol";
38 private static float FLOAT_PI_DIVIDED_BY_TWO = (float) Math.PI / 2;
40 private VideoModule mModule;
41 private String[] mOtherKeys;
42 private AbstractSettingPopup mPopup;
44 private static final int POPUP_NONE = 0;
45 private static final int POPUP_FIRST_LEVEL = 1;
46 private static final int POPUP_SECOND_LEVEL = 2;
47 private int mPopupStatus;
49 public VideoController(CameraActivity activity, VideoModule module, PieRenderer pie) {
54 public void initialize(PreferenceGroup group) {
55 super.initialize(group);
57 mPopupStatus = POPUP_NONE;
58 float sweep = FLOAT_PI_DIVIDED_BY_TWO / 2;
60 addItem(CameraSettings.KEY_VIDEOCAMERA_FLASH_MODE, FLOAT_PI_DIVIDED_BY_TWO - sweep, sweep);
61 addItem(CameraSettings.KEY_WHITE_BALANCE, 3 * FLOAT_PI_DIVIDED_BY_TWO + sweep, sweep);
62 PieItem item = makeItem(R.drawable.ic_switch_video_facing_holo_light);
63 item.setFixedSlice(FLOAT_PI_DIVIDED_BY_TWO + sweep, sweep);
64 item.setOnClickListener(new OnClickListener() {
67 public void onClick(PieItem item) {
68 // Find the index of next camera.
69 ListPreference pref = mPreferenceGroup.findPreference(CameraSettings.KEY_CAMERA_ID);
71 int index = pref.findIndexOfValue(pref.getValue());
72 CharSequence[] values = pref.getEntryValues();
73 index = (index + 1) % values.length;
74 int newCameraId = Integer.parseInt((String) values[index]);
75 mListener.onCameraPickerClicked(newCameraId);
79 mRenderer.addItem(item);
80 mOtherKeys = new String[] {
81 CameraSettings.KEY_VIDEO_EFFECT,
82 CameraSettings.KEY_VIDEO_TIME_LAPSE_FRAME_INTERVAL,
83 CameraSettings.KEY_VIDEO_QUALITY,
84 CameraSettings.KEY_RECORD_LOCATION};
86 item = makeItem(R.drawable.ic_settings_holo_light);
87 item.setFixedSlice(FLOAT_PI_DIVIDED_BY_TWO * 3, sweep);
88 item.setOnClickListener(new OnClickListener() {
90 public void onClick(PieItem item) {
91 if (mPopup == null || mPopupStatus != POPUP_FIRST_LEVEL) {
93 mPopupStatus = POPUP_FIRST_LEVEL;
95 mModule.showPopup(mPopup);
98 mRenderer.addItem(item);
101 protected void setCameraId(int cameraId) {
102 ListPreference pref = mPreferenceGroup.findPreference(CameraSettings.KEY_CAMERA_ID);
103 pref.setValue("" + cameraId);
107 public void reloadPreferences() {
108 super.reloadPreferences();
109 if (mPopup != null) {
110 mPopup.reloadPreference();
115 public void overrideSettings(final String ... keyvalues) {
116 super.overrideSettings(keyvalues);
117 if (mPopup == null || mPopupStatus != POPUP_FIRST_LEVEL) {
118 mPopupStatus = POPUP_FIRST_LEVEL;
121 ((MoreSettingPopup) mPopup).overrideSettings(keyvalues);
125 // Hit when an item in the second-level popup gets selected
126 public void onListPrefChanged(ListPreference pref) {
127 if (mPopup != null) {
128 if (mPopupStatus == POPUP_SECOND_LEVEL) {
129 mModule.dismissPopup(true);
132 super.onSettingChanged(pref);
135 protected void initializePopup() {
136 LayoutInflater inflater = (LayoutInflater) mActivity.getSystemService(
137 Context.LAYOUT_INFLATER_SERVICE);
139 MoreSettingPopup popup = (MoreSettingPopup) inflater.inflate(
140 R.layout.more_setting_popup, null, false);
141 popup.setSettingChangedListener(this);
142 popup.initialize(mPreferenceGroup, mOtherKeys);
143 if (mActivity.isSecureCamera()) {
144 // Prevent location preference from getting changed in secure camera mode
145 popup.setPreferenceEnabled(CameraSettings.KEY_RECORD_LOCATION, false);
150 public void popupDismissed(boolean topPopupOnly) {
151 // if the 2nd level popup gets dismissed
152 if (mPopupStatus == POPUP_SECOND_LEVEL) {
154 mPopupStatus = POPUP_FIRST_LEVEL;
155 if (topPopupOnly) mModule.showPopup(mPopup);
160 // Hit when an item in the first-level popup gets selected, then bring up
161 // the second-level popup
162 public void onPreferenceClicked(ListPreference pref) {
163 if (mPopupStatus != POPUP_FIRST_LEVEL) return;
165 LayoutInflater inflater = (LayoutInflater) mActivity.getSystemService(
166 Context.LAYOUT_INFLATER_SERVICE);
168 if (CameraSettings.KEY_VIDEO_TIME_LAPSE_FRAME_INTERVAL.equals(pref.getKey())) {
169 TimeIntervalPopup timeInterval = (TimeIntervalPopup) inflater.inflate(
170 R.layout.time_interval_popup, null, false);
171 timeInterval.initialize((IconListPreference) pref);
172 timeInterval.setSettingChangedListener(this);
173 mModule.dismissPopup(true);
174 mPopup = timeInterval;
176 ListPrefSettingPopup basic = (ListPrefSettingPopup) inflater.inflate(
177 R.layout.list_pref_setting_popup, null, false);
178 basic.initialize(pref);
179 basic.setSettingChangedListener(this);
180 mModule.dismissPopup(true);
183 mModule.showPopup(mPopup);
184 mPopupStatus = POPUP_SECOND_LEVEL;