OSDN Git Service

Fix new activity menus
[android-x86/packages-apps-Gallery2.git] / src / com / android / camera / NewVideoMenu.java
1 /*
2  * Copyright (C) 2013 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.app.Activity;
20 import android.content.Context;
21 import android.view.LayoutInflater;
22
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;
31
32 public class NewVideoMenu extends PieController
33         implements MoreSettingPopup.Listener,
34         ListPrefSettingPopup.Listener,
35         TimeIntervalPopup.Listener {
36
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;
42
43     private NewVideoUI mUI;
44     private String[] mOtherKeys;
45     private AbstractSettingPopup mPopup;
46
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;
52
53     public NewVideoMenu(NewCameraActivity activity, NewVideoUI ui, PieRenderer pie) {
54         super(activity, pie);
55         mUI = ui;
56         mActivity = activity;
57     }
58
59     public void initialize(PreferenceGroup group) {
60         super.initialize(group);
61         mPopup = null;
62         mPopupStatus = POPUP_NONE;
63         PieItem item = null;
64         // white balance
65         if (group.findPreference(CameraSettings.KEY_WHITE_BALANCE) != null) {
66             item = makeItem(CameraSettings.KEY_WHITE_BALANCE);
67             mRenderer.addItem(item);
68         }
69         // settings popup
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
75         };
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() {
79             @Override
80             public void onClick(PieItem item) {
81                 if (mPopup == null || mPopupStatus != POPUP_FIRST_LEVEL) {
82                     initializePopup();
83                     mPopupStatus = POPUP_FIRST_LEVEL;
84                 }
85                 mUI.showPopup(mPopup);
86             }
87         });
88         mRenderer.addItem(item);
89         // camera switcher
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())]);
98
99             final PieItem fitem = item;
100             item.setOnClickListener(new OnClickListener() {
101
102                 @Override
103                 public void onClick(PieItem item) {
104                     // Find the index of next camera.
105                     ListPreference pref =
106                             mPreferenceGroup.findPreference(CameraSettings.KEY_CAMERA_ID);
107                     if (pref != null) {
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);
116                     }
117                 }
118             });
119             mRenderer.addItem(item);
120         }
121         // flash
122         if (group.findPreference(CameraSettings.KEY_VIDEOCAMERA_FLASH_MODE) != null) {
123             item = makeItem(CameraSettings.KEY_VIDEOCAMERA_FLASH_MODE);
124             mRenderer.addItem(item);
125         }
126     }
127
128     @Override
129     public void reloadPreferences() {
130         super.reloadPreferences();
131         if (mPopup != null) {
132             mPopup.reloadPreference();
133         }
134     }
135
136     @Override
137     public void overrideSettings(final String ... keyvalues) {
138         super.overrideSettings(keyvalues);
139         if (mPopup == null || mPopupStatus != POPUP_FIRST_LEVEL) {
140             mPopupStatus = POPUP_FIRST_LEVEL;
141             initializePopup();
142         }
143         ((MoreSettingPopup) mPopup).overrideSettings(keyvalues);
144     }
145
146     @Override
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);
152             }
153         }
154         super.onSettingChanged(pref);
155     }
156
157     protected void initializePopup() {
158         LayoutInflater inflater = (LayoutInflater) mActivity.getSystemService(
159                 Context.LAYOUT_INFLATER_SERVICE);
160
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);
168         }
169         mPopup = popup;
170     }
171
172     public void popupDismissed(boolean topPopupOnly) {
173         // if the 2nd level popup gets dismissed
174         if (mPopupStatus == POPUP_SECOND_LEVEL) {
175             initializePopup();
176             mPopupStatus = POPUP_FIRST_LEVEL;
177             if (topPopupOnly) mUI.showPopup(mPopup);
178         }
179     }
180
181     @Override
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;
186
187         LayoutInflater inflater = (LayoutInflater) mActivity.getSystemService(
188                 Context.LAYOUT_INFLATER_SERVICE);
189
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;
197         } else {
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);
203             mPopup = basic;
204         }
205         mUI.showPopup(mPopup);
206         mPopupStatus = POPUP_SECOND_LEVEL;
207     }
208
209 }