OSDN Git Service

3a220773b08004cf4114228273bb52935c083fe8
[android-x86/packages-apps-Gallery2.git] / src / com / android / camera / VideoController.java
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.gallery3d.R;
30
31 public class VideoController extends PieController
32         implements MoreSettingPopup.Listener,
33         ListPrefSettingPopup.Listener,
34         TimeIntervalPopup.Listener {
35
36
37     private static String TAG = "CAM_videocontrol";
38     private static float FLOAT_PI_DIVIDED_BY_TWO = (float) Math.PI / 2;
39
40     private VideoModule mModule;
41     private String[] mOtherKeys;
42     private AbstractSettingPopup mPopup;
43
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;
48
49     public VideoController(CameraActivity activity, VideoModule module, PieRenderer pie) {
50         super(activity, pie);
51         mModule = module;
52     }
53
54     public void initialize(PreferenceGroup group) {
55         super.initialize(group);
56         mPopup = null;
57         mPopupStatus = POPUP_NONE;
58         float sweep = FLOAT_PI_DIVIDED_BY_TWO / 2;
59
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() {
65
66             @Override
67             public void onClick(PieItem item) {
68                 // Find the index of next camera.
69                 ListPreference pref = mPreferenceGroup.findPreference(CameraSettings.KEY_CAMERA_ID);
70                 if (pref != null) {
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);
76                 }
77             }
78         });
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};
85
86         item = makeItem(R.drawable.ic_settings_holo_light);
87         item.setFixedSlice(FLOAT_PI_DIVIDED_BY_TWO * 3, sweep);
88         item.setOnClickListener(new OnClickListener() {
89             @Override
90             public void onClick(PieItem item) {
91                 if (mPopup == null || mPopupStatus != POPUP_FIRST_LEVEL) {
92                     initializePopup();
93                     mPopupStatus = POPUP_FIRST_LEVEL;
94                 }
95                 mModule.showPopup(mPopup);
96             }
97         });
98         mRenderer.addItem(item);
99     }
100
101     protected void setCameraId(int cameraId) {
102         ListPreference pref = mPreferenceGroup.findPreference(CameraSettings.KEY_CAMERA_ID);
103         pref.setValue("" + cameraId);
104     }
105
106     @Override
107     public void reloadPreferences() {
108         super.reloadPreferences();
109         if (mPopup != null) {
110             mPopup.reloadPreference();
111         }
112     }
113
114     @Override
115     public void overrideSettings(final String ... keyvalues) {
116         super.overrideSettings(keyvalues);
117         if (mPopup == null || mPopupStatus != POPUP_FIRST_LEVEL) {
118             mPopupStatus = POPUP_FIRST_LEVEL;
119             initializePopup();
120         }
121         ((MoreSettingPopup) mPopup).overrideSettings(keyvalues);
122     }
123
124     @Override
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);
130             }
131         }
132         super.onSettingChanged(pref);
133     }
134
135     protected void initializePopup() {
136         LayoutInflater inflater = (LayoutInflater) mActivity.getSystemService(
137                 Context.LAYOUT_INFLATER_SERVICE);
138
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);
146         }
147         mPopup = popup;
148     }
149
150     public void popupDismissed(boolean topPopupOnly) {
151         // if the 2nd level popup gets dismissed
152         if (mPopupStatus == POPUP_SECOND_LEVEL) {
153             initializePopup();
154             mPopupStatus = POPUP_FIRST_LEVEL;
155             if (topPopupOnly) mModule.showPopup(mPopup);
156         }
157     }
158
159     @Override
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;
164
165         LayoutInflater inflater = (LayoutInflater) mActivity.getSystemService(
166                 Context.LAYOUT_INFLATER_SERVICE);
167
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;
175         } else {
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);
181             mPopup = basic;
182         }
183         mModule.showPopup(mPopup);
184         mPopupStatus = POPUP_SECOND_LEVEL;
185     }
186
187 }