Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 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; |
Sascha Haeberling | 8e963a5 | 2013-08-06 11:43:02 -0700 | [diff] [blame] | 29 | import com.android.camera2.R; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 30 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 31 | public class VideoMenu extends PieController |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 32 | implements MoreSettingPopup.Listener, |
| 33 | ListPrefSettingPopup.Listener, |
| 34 | TimeIntervalPopup.Listener { |
| 35 | |
Doris Liu | 6827ce2 | 2013-03-12 19:24:28 -0700 | [diff] [blame] | 36 | private static String TAG = "CAM_VideoMenu"; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 37 | |
Doris Liu | 6827ce2 | 2013-03-12 19:24:28 -0700 | [diff] [blame] | 38 | private VideoUI mUI; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 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; |
Doris Liu | 753bb8a | 2013-03-14 21:01:35 -0700 | [diff] [blame] | 46 | private CameraActivity mActivity; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 47 | |
Doris Liu | 6827ce2 | 2013-03-12 19:24:28 -0700 | [diff] [blame] | 48 | public VideoMenu(CameraActivity activity, VideoUI ui, PieRenderer pie) { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 49 | super(activity, pie); |
Doris Liu | 6827ce2 | 2013-03-12 19:24:28 -0700 | [diff] [blame] | 50 | mUI = ui; |
Doris Liu | 753bb8a | 2013-03-14 21:01:35 -0700 | [diff] [blame] | 51 | mActivity = activity; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 52 | } |
| 53 | |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 54 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 55 | public void initialize(PreferenceGroup group) { |
| 56 | super.initialize(group); |
| 57 | mPopup = null; |
| 58 | mPopupStatus = POPUP_NONE; |
Jason Noguchi | 4205d50 | 2013-04-11 17:39:20 -0700 | [diff] [blame] | 59 | PieItem item = null; |
Jason Noguchi | 4205d50 | 2013-04-11 17:39:20 -0700 | [diff] [blame] | 60 | // white balance |
| 61 | if (group.findPreference(CameraSettings.KEY_WHITE_BALANCE) != null) { |
Michael Kolb | b7c4999 | 2013-04-30 09:23:23 -0700 | [diff] [blame] | 62 | item = makeItem(CameraSettings.KEY_WHITE_BALANCE); |
Jason Noguchi | 4205d50 | 2013-04-11 17:39:20 -0700 | [diff] [blame] | 63 | mRenderer.addItem(item); |
| 64 | } |
Michael Kolb | b7c4999 | 2013-04-30 09:23:23 -0700 | [diff] [blame] | 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); |
Michael Kolb | 3bc96b2 | 2013-03-12 10:24:42 -0700 | [diff] [blame] | 85 | // camera switcher |
Jason Noguchi | 4205d50 | 2013-04-11 17:39:20 -0700 | [diff] [blame] | 86 | if (group.findPreference(CameraSettings.KEY_CAMERA_ID) != null) { |
Michael Kolb | 172d37e | 2013-04-17 16:01:32 -0700 | [diff] [blame] | 87 | item = makeItem(R.drawable.ic_switch_back); |
Michael Kolb | 172d37e | 2013-04-17 16:01:32 -0700 | [diff] [blame] | 88 | IconListPreference lpref = (IconListPreference) group.findPreference( |
| 89 | CameraSettings.KEY_CAMERA_ID); |
Michael Kolb | 0408c9a | 2013-04-15 13:17:27 -0700 | [diff] [blame] | 90 | item.setLabel(lpref.getLabel()); |
Michael Kolb | 172d37e | 2013-04-17 16:01:32 -0700 | [diff] [blame] | 91 | item.setImageResource(mActivity, |
| 92 | ((IconListPreference) lpref).getIconIds() |
| 93 | [lpref.findIndexOfValue(lpref.getValue())]); |
| 94 | |
Michael Kolb | 0408c9a | 2013-04-15 13:17:27 -0700 | [diff] [blame] | 95 | final PieItem fitem = item; |
Jason Noguchi | 4205d50 | 2013-04-11 17:39:20 -0700 | [diff] [blame] | 96 | item.setOnClickListener(new OnClickListener() { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 97 | |
Jason Noguchi | 4205d50 | 2013-04-11 17:39:20 -0700 | [diff] [blame] | 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]); |
Michael Kolb | 172d37e | 2013-04-17 16:01:32 -0700 | [diff] [blame] | 108 | fitem.setImageResource(mActivity, |
| 109 | ((IconListPreference) pref).getIconIds()[index]); |
Michael Kolb | 0408c9a | 2013-04-15 13:17:27 -0700 | [diff] [blame] | 110 | fitem.setLabel(pref.getLabel()); |
Michael Kolb | 172d37e | 2013-04-17 16:01:32 -0700 | [diff] [blame] | 111 | mListener.onCameraPickerClicked(newCameraId); |
Jason Noguchi | 4205d50 | 2013-04-11 17:39:20 -0700 | [diff] [blame] | 112 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 113 | } |
Jason Noguchi | 4205d50 | 2013-04-11 17:39:20 -0700 | [diff] [blame] | 114 | }); |
| 115 | mRenderer.addItem(item); |
| 116 | } |
Michael Kolb | b7c4999 | 2013-04-30 09:23:23 -0700 | [diff] [blame] | 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 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 122 | } |
| 123 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 124 | @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 Liu | 6827ce2 | 2013-03-12 19:24:28 -0700 | [diff] [blame] | 147 | mUI.dismissPopup(true); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 148 | } |
| 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 Liu | 6827ce2 | 2013-03-12 19:24:28 -0700 | [diff] [blame] | 173 | if (topPopupOnly) mUI.showPopup(mPopup); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 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 |
| 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 Liu | 6827ce2 | 2013-03-12 19:24:28 -0700 | [diff] [blame] | 191 | mUI.dismissPopup(true); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 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); |
Doris Liu | 6827ce2 | 2013-03-12 19:24:28 -0700 | [diff] [blame] | 198 | mUI.dismissPopup(true); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 199 | mPopup = basic; |
| 200 | } |
Doris Liu | 6827ce2 | 2013-03-12 19:24:28 -0700 | [diff] [blame] | 201 | mUI.showPopup(mPopup); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 202 | mPopupStatus = POPUP_SECOND_LEVEL; |
| 203 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 204 | } |