• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 package com.android.camera;
18 
19 import android.content.Context;
20 import android.view.LayoutInflater;
21 
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.camera2.R;
30 
31 public class VideoMenu extends PieController
32         implements MoreSettingPopup.Listener,
33         ListPrefSettingPopup.Listener,
34         TimeIntervalPopup.Listener {
35 
36     private static String TAG = "CAM_VideoMenu";
37 
38     private VideoUI mUI;
39     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;
46     private CameraActivity mActivity;
47 
VideoMenu(CameraActivity activity, VideoUI ui, PieRenderer pie)48     public VideoMenu(CameraActivity activity, VideoUI ui, PieRenderer pie) {
49         super(activity, pie);
50         mUI = ui;
51         mActivity = activity;
52     }
53 
54 
initialize(PreferenceGroup group)55     public void initialize(PreferenceGroup group) {
56         super.initialize(group);
57         mPopup = null;
58         mPopupStatus = POPUP_NONE;
59         PieItem item = null;
60         // white balance
61         if (group.findPreference(CameraSettings.KEY_WHITE_BALANCE) != null) {
62             item = makeItem(CameraSettings.KEY_WHITE_BALANCE);
63             mRenderer.addItem(item);
64         }
65         // 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);
85         // camera switcher
86         if (group.findPreference(CameraSettings.KEY_CAMERA_ID) != null) {
87             item = makeItem(R.drawable.ic_switch_back);
88             IconListPreference lpref = (IconListPreference) group.findPreference(
89                     CameraSettings.KEY_CAMERA_ID);
90             item.setLabel(lpref.getLabel());
91             item.setImageResource(mActivity,
92                     ((IconListPreference) lpref).getIconIds()
93                     [lpref.findIndexOfValue(lpref.getValue())]);
94 
95             final PieItem fitem = item;
96             item.setOnClickListener(new OnClickListener() {
97 
98                 @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]);
108                         fitem.setImageResource(mActivity,
109                                 ((IconListPreference) pref).getIconIds()[index]);
110                         fitem.setLabel(pref.getLabel());
111                         mListener.onCameraPickerClicked(newCameraId);
112                     }
113                 }
114             });
115             mRenderer.addItem(item);
116         }
117         // flash
118         if (group.findPreference(CameraSettings.KEY_VIDEOCAMERA_FLASH_MODE) != null) {
119             item = makeItem(CameraSettings.KEY_VIDEOCAMERA_FLASH_MODE);
120             mRenderer.addItem(item);
121         }
122     }
123 
124     @Override
reloadPreferences()125     public void reloadPreferences() {
126         super.reloadPreferences();
127         if (mPopup != null) {
128             mPopup.reloadPreference();
129         }
130     }
131 
132     @Override
overrideSettings(final String ... keyvalues)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
onListPrefChanged(ListPreference pref)144     public void onListPrefChanged(ListPreference pref) {
145         if (mPopup != null) {
146             if (mPopupStatus == POPUP_SECOND_LEVEL) {
147                 mUI.dismissPopup(true);
148             }
149         }
150         super.onSettingChanged(pref);
151     }
152 
initializePopup()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 
popupDismissed(boolean topPopupOnly)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;
173             if (topPopupOnly) mUI.showPopup(mPopup);
174         }
175     }
176 
177     @Override
178     // Hit when an item in the first-level popup gets selected, then bring up
179     // the second-level popup
onPreferenceClicked(ListPreference pref)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);
191             mUI.dismissPopup(true);
192             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);
198             mUI.dismissPopup(true);
199             mPopup = basic;
200         }
201         mUI.showPopup(mPopup);
202         mPopupStatus = POPUP_SECOND_LEVEL;
203     }
204 }
205