blob: 8e8ba7df650fdd754d69bac9eac5cd76e113223c [file] [log] [blame]
Erin Dahlgren18e2ef62013-12-05 14:53:38 -08001/*
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
17package com.android.camera;
18
Erin Dahlgren0a6a8d82014-01-09 22:17:38 -080019import android.content.Context;
Erin Dahlgren18e2ef62013-12-05 14:53:38 -080020import android.view.View;
21import android.widget.ImageButton;
22
Spike Sprague6b174192014-01-09 11:54:17 -080023import com.android.camera.ShutterButton;
Erin Dahlgren0a6a8d82014-01-09 22:17:38 -080024import com.android.camera.app.AppController;
25import com.android.camera.module.ModuleController;
Erin Dahlgren18e2ef62013-12-05 14:53:38 -080026import com.android.camera.settings.SettingsManager;
Erin Dahlgren8a2933b2013-12-06 12:07:33 -080027
Spike Sprague39f8a762014-01-13 14:22:18 -080028
Erin Dahlgren1648c362014-01-06 15:06:04 -080029import com.android.camera2.R;
30
Erin Dahlgren18e2ef62013-12-05 14:53:38 -080031/**
32 * A class for generating pre-initialized
33 * {@link #android.widget.ImageButton}s.
34 */
Erin Dahlgren1648c362014-01-06 15:06:04 -080035public class ButtonManager implements SettingsManager.OnSettingChangedListener {
Erin Dahlgren18e2ef62013-12-05 14:53:38 -080036
Erin Dahlgren18e2ef62013-12-05 14:53:38 -080037 public static final int BUTTON_FLASH = 0;
Spike Sprague0f3c4b42013-12-10 19:50:17 -080038 public static final int BUTTON_TORCH = 1;
39 public static final int BUTTON_CAMERA = 2;
40 public static final int BUTTON_HDRPLUS = 3;
Erin Dahlgrenb1641f52014-01-14 15:58:52 -080041 public static final int BUTTON_HDR = 4;
42 public static final int BUTTON_REFOCUS = 5;
43 public static final int BUTTON_CANCEL = 6;
44 public static final int BUTTON_DONE = 7;
45 public static final int BUTTON_RETAKE = 8;
46 public static final int BUTTON_REVIEW = 9;
Erin Dahlgrena1fab412014-01-21 09:31:11 -080047 public static final int BUTTON_PANO_HORIZONTAL = 10;
48 public static final int BUTTON_PANO_VERTICAL = 11;
Erin Dahlgren4efa8b52013-12-17 18:31:35 -080049
Erin Dahlgren18484942014-01-07 11:46:57 -080050 /** For two state MultiToggleImageButtons, the off index. */
Erin Dahlgren4efa8b52013-12-17 18:31:35 -080051 public static final int OFF = 0;
Erin Dahlgren18484942014-01-07 11:46:57 -080052 /** For two state MultiToggleImageButtons, the on index. */
Erin Dahlgren4efa8b52013-12-17 18:31:35 -080053 public static final int ON = 1;
Erin Dahlgren18e2ef62013-12-05 14:53:38 -080054
Erin Dahlgren18e2ef62013-12-05 14:53:38 -080055 /** A reference to the application's settings manager. */
Sascha Haeberling58598dc2013-12-18 17:26:28 -080056 private final SettingsManager mSettingsManager;
Erin Dahlgren18e2ef62013-12-05 14:53:38 -080057
Erin Dahlgrena1fab412014-01-21 09:31:11 -080058 /** Bottom bar options toggle buttons. */
59 private MultiToggleImageButton mButtonPos1;
60 private MultiToggleImageButton mButtonPos2;
61 private MultiToggleImageButton mButtonPos3;
62 private MultiToggleImageButton mButtonPos4;
Erin Dahlgren18484942014-01-07 11:46:57 -080063
64 /** Intent UI buttons. */
65 private ImageButton mButtonCancel;
66 private ImageButton mButtonDone;
67 private ImageButton mButtonRetake; // same as review.
68
69 /** A listener for button enabled and visibility
70 state changes. */
71 private ButtonStatusListener mListener;
72
Erin Dahlgren0a6a8d82014-01-09 22:17:38 -080073 /** An reference to the gcam mode index. */
74 private static int sGcamIndex;
75
Spike Sprague6b174192014-01-09 11:54:17 -080076 private ShutterButton mShutterButton;
Erin Dahlgren0a6a8d82014-01-09 22:17:38 -080077 private AppController mAppController;
Spike Sprague6b174192014-01-09 11:54:17 -080078
Erin Dahlgren8a2933b2013-12-06 12:07:33 -080079 /**
80 * Get a new global ButtonManager.
81 */
Erin Dahlgren0a6a8d82014-01-09 22:17:38 -080082 public ButtonManager(AppController app) {
83 mAppController = app;
84
85 Context context = app.getAndroidContext();
86 sGcamIndex = context.getResources().getInteger(R.integer.camera_mode_gcam);
87
Erin Dahlgren0a6a8d82014-01-09 22:17:38 -080088 mSettingsManager = app.getSettingsManager();
Erin Dahlgren1648c362014-01-06 15:06:04 -080089 mSettingsManager.addListener(this);
90 }
91
Erin Dahlgren18484942014-01-07 11:46:57 -080092 /**
Erin Dahlgrenf1b2e402014-01-14 11:08:59 -080093 * Load references to buttons under a root View.
94 * Call this after the root clears/reloads all of its children
95 * to prevent stale references button views.
96 */
97 public void load(View root) {
98 getButtonsReferences(root);
99 }
100
101 /**
Erin Dahlgren18484942014-01-07 11:46:57 -0800102 * ButtonStatusListener provides callbacks for when button's
103 * visibility changes and enabled status changes.
104 */
105 public interface ButtonStatusListener {
106 /**
107 * A button's visibility has changed.
108 */
109 public void onButtonVisibilityChanged(ButtonManager buttonManager, int buttonId);
110
111 /**
112 * A button's enabled state has changed.
113 */
114 public void onButtonEnabledChanged(ButtonManager buttonManager, int buttonId);
115 }
116
117 /**
118 * Sets the ButtonStatusListener.
119 */
120 public void setListener(ButtonStatusListener listener) {
121 mListener = listener;
122 }
123
124 /**
125 * Gets references to all known buttons.
126 */
Erin Dahlgren0a6a8d82014-01-09 22:17:38 -0800127 private void getButtonsReferences(View root) {
Erin Dahlgrena1fab412014-01-21 09:31:11 -0800128 mButtonPos1
Erin Dahlgren0a6a8d82014-01-09 22:17:38 -0800129 = (MultiToggleImageButton) root.findViewById(R.id.camera_toggle_button);
Erin Dahlgrena1fab412014-01-21 09:31:11 -0800130 mButtonPos2
131 = (MultiToggleImageButton) root.findViewById(R.id.flash_toggle_button);
132 mButtonPos3
Erin Dahlgren0a6a8d82014-01-09 22:17:38 -0800133 = (MultiToggleImageButton) root.findViewById(R.id.hdr_plus_toggle_button);
Erin Dahlgrena1fab412014-01-21 09:31:11 -0800134 mButtonPos4
Erin Dahlgren0a6a8d82014-01-09 22:17:38 -0800135 = (MultiToggleImageButton) root.findViewById(R.id.refocus_toggle_button);
Erin Dahlgren18484942014-01-07 11:46:57 -0800136 mButtonCancel
Erin Dahlgren0a6a8d82014-01-09 22:17:38 -0800137 = (ImageButton) root.findViewById(R.id.cancel_button);
Erin Dahlgren18484942014-01-07 11:46:57 -0800138 mButtonDone
Erin Dahlgren0a6a8d82014-01-09 22:17:38 -0800139 = (ImageButton) root.findViewById(R.id.done_button);
Erin Dahlgren18484942014-01-07 11:46:57 -0800140 mButtonRetake
Erin Dahlgren0a6a8d82014-01-09 22:17:38 -0800141 = (ImageButton) root.findViewById(R.id.retake_button);
142 mShutterButton
143 = (ShutterButton) root.findViewById(R.id.shutter_button);
Erin Dahlgren18484942014-01-07 11:46:57 -0800144 }
Erin Dahlgren1648c362014-01-06 15:06:04 -0800145
146 @Override
147 public void onSettingChanged(SettingsManager settingsManager, int id) {
148 MultiToggleImageButton button = null;
149 int index = 0;
150
151 switch (id) {
152 case SettingsManager.SETTING_FLASH_MODE: {
153 index = mSettingsManager.getStringValueIndex(id);
Erin Dahlgren18484942014-01-07 11:46:57 -0800154 button = getButtonOrError(BUTTON_FLASH);
Erin Dahlgren1648c362014-01-06 15:06:04 -0800155 break;
156 }
157 case SettingsManager.SETTING_VIDEOCAMERA_FLASH_MODE: {
158 index = mSettingsManager.getStringValueIndex(id);
Erin Dahlgren18484942014-01-07 11:46:57 -0800159 button = getButtonOrError(BUTTON_TORCH);
Erin Dahlgren1648c362014-01-06 15:06:04 -0800160 break;
161 }
162 case SettingsManager.SETTING_CAMERA_ID: {
163 index = mSettingsManager.getStringValueIndex(id);
Erin Dahlgren18484942014-01-07 11:46:57 -0800164 button = getButtonOrError(BUTTON_CAMERA);
Erin Dahlgren1648c362014-01-06 15:06:04 -0800165 break;
166 }
167 case SettingsManager.SETTING_CAMERA_HDR: {
168 index = mSettingsManager.getStringValueIndex(id);
Erin Dahlgren18484942014-01-07 11:46:57 -0800169 button = getButtonOrError(BUTTON_HDRPLUS);
Erin Dahlgren1648c362014-01-06 15:06:04 -0800170 break;
171 }
172 case SettingsManager.SETTING_CAMERA_REFOCUS: {
173 index = mSettingsManager.getStringValueIndex(id);
Erin Dahlgren18484942014-01-07 11:46:57 -0800174 button = getButtonOrError(BUTTON_REFOCUS);
Erin Dahlgren1648c362014-01-06 15:06:04 -0800175 break;
176 }
177 default: {
178 // Do nothing.
179 }
180 }
181
182 // In case SharedPreferences has changed but the button hasn't been toggled,
183 // make sure the toggle state is in sync.
184 if (button != null && button.getState() != index) {
185 button.setState(Math.max(index, 0), false);
186 }
Erin Dahlgren18e2ef62013-12-05 14:53:38 -0800187 }
188
189 /**
190 * A callback executed in the state listener of a button.
Erin Dahlgren18484942014-01-07 11:46:57 -0800191
Erin Dahlgren8a2933b2013-12-06 12:07:33 -0800192 * Used by a module to set specific behavior when a button's
Erin Dahlgren18e2ef62013-12-05 14:53:38 -0800193 * state changes.
194 */
195 public interface ButtonCallback {
196 public void onStateChanged(int state);
197 }
198
Erin Dahlgren18484942014-01-07 11:46:57 -0800199 /**
200 * Returns the appropriate {@link com.android.camera.MultiToggleImageButton}
201 * based on button id. An IllegalStateException will be throw if the
202 * button could not be found in the view hierarchy.
203 */
204 private MultiToggleImageButton getButtonOrError(int buttonId) {
205 switch (buttonId) {
206 case BUTTON_FLASH:
Erin Dahlgrena1fab412014-01-21 09:31:11 -0800207 if (mButtonPos2 == null) {
Erin Dahlgren8a2933b2013-12-06 12:07:33 -0800208 throw new IllegalStateException("Flash button could not be found.");
Erin Dahlgren18484942014-01-07 11:46:57 -0800209 }
Erin Dahlgrena1fab412014-01-21 09:31:11 -0800210 return mButtonPos2;
Erin Dahlgren18484942014-01-07 11:46:57 -0800211 case BUTTON_TORCH:
Erin Dahlgrena1fab412014-01-21 09:31:11 -0800212 if (mButtonPos2 == null) {
Spike Sprague0f3c4b42013-12-10 19:50:17 -0800213 throw new IllegalStateException("Torch button could not be found.");
Erin Dahlgren18484942014-01-07 11:46:57 -0800214 }
Erin Dahlgrena1fab412014-01-21 09:31:11 -0800215 return mButtonPos2;
Erin Dahlgren18484942014-01-07 11:46:57 -0800216 case BUTTON_CAMERA:
Erin Dahlgrena1fab412014-01-21 09:31:11 -0800217 if (mButtonPos1 == null) {
Erin Dahlgren8a2933b2013-12-06 12:07:33 -0800218 throw new IllegalStateException("Camera button could not be found.");
Erin Dahlgren18484942014-01-07 11:46:57 -0800219 }
Erin Dahlgrena1fab412014-01-21 09:31:11 -0800220 return mButtonPos1;
Erin Dahlgren18484942014-01-07 11:46:57 -0800221 case BUTTON_HDRPLUS:
Erin Dahlgrena1fab412014-01-21 09:31:11 -0800222 if (mButtonPos3 == null) {
223 throw new IllegalStateException("Hdr plus button could not be found.");
Erin Dahlgren18484942014-01-07 11:46:57 -0800224 }
Erin Dahlgrena1fab412014-01-21 09:31:11 -0800225 return mButtonPos3;
Erin Dahlgrenb1641f52014-01-14 15:58:52 -0800226 case BUTTON_HDR:
Erin Dahlgrena1fab412014-01-21 09:31:11 -0800227 if (mButtonPos3 == null) {
Erin Dahlgrenb1641f52014-01-14 15:58:52 -0800228 throw new IllegalStateException("Hdr button could not be found.");
229 }
Erin Dahlgrena1fab412014-01-21 09:31:11 -0800230 return mButtonPos3;
Erin Dahlgren18484942014-01-07 11:46:57 -0800231 case BUTTON_REFOCUS:
Erin Dahlgrena1fab412014-01-21 09:31:11 -0800232 if (mButtonPos4 == null) {
Erin Dahlgren4efa8b52013-12-17 18:31:35 -0800233 throw new IllegalStateException("Refocus button could not be found.");
Erin Dahlgren18484942014-01-07 11:46:57 -0800234 }
Erin Dahlgrena1fab412014-01-21 09:31:11 -0800235 return mButtonPos4;
Erin Dahlgren18484942014-01-07 11:46:57 -0800236 default:
237 throw new IllegalArgumentException("button not known by id=" + buttonId);
Erin Dahlgren18e2ef62013-12-05 14:53:38 -0800238 }
239 }
240
Erin Dahlgren18484942014-01-07 11:46:57 -0800241 /**
242 * Returns the appropriate {@link android.widget.ImageButton}
243 * based on button id. An IllegalStateException will be throw if the
244 * button could not be found in the view hierarchy.
245 */
246 private ImageButton getImageButtonOrError(int buttonId) {
247 switch (buttonId) {
Erin Dahlgrena1fab412014-01-21 09:31:11 -0800248 case BUTTON_PANO_VERTICAL:
249 if (mButtonPos1 == null) {
250 throw new IllegalStateException("Flash button could not be found.");
251 }
252 return (ImageButton) mButtonPos1;
253 case BUTTON_PANO_HORIZONTAL:
254 if (mButtonPos2 == null) {
255 throw new IllegalStateException("Flash button could not be found.");
256 }
257 return (ImageButton) mButtonPos2;
Erin Dahlgren18484942014-01-07 11:46:57 -0800258 case BUTTON_CANCEL:
259 if (mButtonCancel == null) {
Spike Spragueeb3134f2013-12-12 11:14:27 -0800260 throw new IllegalStateException("Cancel button could not be found.");
Erin Dahlgren18484942014-01-07 11:46:57 -0800261 }
262 return mButtonCancel;
263 case BUTTON_DONE:
264 if (mButtonDone == null) {
Spike Spragueeb3134f2013-12-12 11:14:27 -0800265 throw new IllegalStateException("Done button could not be found.");
Erin Dahlgren18484942014-01-07 11:46:57 -0800266 }
267 return mButtonDone;
268 case BUTTON_RETAKE:
269 if (mButtonRetake == null) {
Spike Spragueeb3134f2013-12-12 11:14:27 -0800270 throw new IllegalStateException("Retake button could not be found.");
Erin Dahlgren18484942014-01-07 11:46:57 -0800271 }
272 return mButtonRetake;
273 case BUTTON_REVIEW:
274 if (mButtonRetake == null) {
Spike Spraguedb44ef52013-12-13 18:08:40 -0800275 throw new IllegalStateException("Review button could not be found.");
Erin Dahlgren18484942014-01-07 11:46:57 -0800276 }
277 return mButtonRetake;
278 default:
279 throw new IllegalArgumentException("button not known by id=" + buttonId);
Spike Spragueeb3134f2013-12-12 11:14:27 -0800280 }
Spike Spragueeb3134f2013-12-12 11:14:27 -0800281 }
282
Erin Dahlgren18e2ef62013-12-05 14:53:38 -0800283 /**
Erin Dahlgren8a2933b2013-12-06 12:07:33 -0800284 * Enable a known button by id, with a state change callback and
285 * a resource id that points to an array of drawables.
Erin Dahlgren18e2ef62013-12-05 14:53:38 -0800286 */
Erin Dahlgrenb1641f52014-01-14 15:58:52 -0800287 public void enableButton(int buttonId, ButtonCallback cb) {
Erin Dahlgren18484942014-01-07 11:46:57 -0800288 MultiToggleImageButton button = getButtonOrError(buttonId);
Erin Dahlgren8a2933b2013-12-06 12:07:33 -0800289 switch (buttonId) {
290 case BUTTON_FLASH:
Erin Dahlgrenb1641f52014-01-14 15:58:52 -0800291 enableFlashButton(button, cb, R.array.camera_flashmode_icons);
Erin Dahlgren8a2933b2013-12-06 12:07:33 -0800292 break;
Erin Dahlgren18484942014-01-07 11:46:57 -0800293 case BUTTON_TORCH:
Erin Dahlgrenb1641f52014-01-14 15:58:52 -0800294 enableTorchButton(button, cb, R.array.video_flashmode_icons);
Erin Dahlgren18484942014-01-07 11:46:57 -0800295 break;
Erin Dahlgren8a2933b2013-12-06 12:07:33 -0800296 case BUTTON_CAMERA:
Erin Dahlgrenb1641f52014-01-14 15:58:52 -0800297 enableCameraButton(button, cb, R.array.camera_id_icons);
Erin Dahlgren8a2933b2013-12-06 12:07:33 -0800298 break;
299 case BUTTON_HDRPLUS:
Erin Dahlgrenb1641f52014-01-14 15:58:52 -0800300 enableHdrPlusButton(button, cb, R.array.pref_camera_hdr_plus_icons);
301 break;
302 case BUTTON_HDR:
Erin Dahlgrene7d745c2014-01-21 14:04:55 -0800303 enableHdrPlusButton(button, cb, R.array.pref_camera_hdr_icons);
Erin Dahlgren8a2933b2013-12-06 12:07:33 -0800304 break;
Erin Dahlgren4efa8b52013-12-17 18:31:35 -0800305 case BUTTON_REFOCUS:
Erin Dahlgrenb1641f52014-01-14 15:58:52 -0800306 enableRefocusButton(button, cb, R.array.refocus_icons);
Erin Dahlgren4efa8b52013-12-17 18:31:35 -0800307 break;
Erin Dahlgren8a2933b2013-12-06 12:07:33 -0800308 default:
309 throw new IllegalArgumentException("button not known by id=" + buttonId);
Erin Dahlgren18e2ef62013-12-05 14:53:38 -0800310 }
Erin Dahlgren18484942014-01-07 11:46:57 -0800311
312 if (!button.isEnabled()) {
313 button.setEnabled(true);
314 if (mListener != null) {
315 mListener.onButtonEnabledChanged(this, buttonId);
316 }
317 }
Erin Dahlgrena1fab412014-01-21 09:31:11 -0800318 button.setTag(R.string.tag_enabled_id, (Integer) buttonId);
Erin Dahlgren18484942014-01-07 11:46:57 -0800319
320 if (button.getVisibility() != View.VISIBLE) {
321 button.setVisibility(View.VISIBLE);
322 if (mListener != null) {
323 mListener.onButtonVisibilityChanged(this, buttonId);
324 }
325 }
Erin Dahlgren8a2933b2013-12-06 12:07:33 -0800326 }
327
Erin Dahlgren4efa8b52013-12-17 18:31:35 -0800328 /**
329 * Enable a known button with a click listener and a resource id.
330 * Sets the button visible.
331 */
Erin Dahlgren18484942014-01-07 11:46:57 -0800332 public void enablePushButton(int buttonId, View.OnClickListener cb,
Erin Dahlgren4efa8b52013-12-17 18:31:35 -0800333 int imageId) {
Erin Dahlgren18484942014-01-07 11:46:57 -0800334 ImageButton button = getImageButtonOrError(buttonId);
Erin Dahlgren4efa8b52013-12-17 18:31:35 -0800335 button.setOnClickListener(cb);
Erin Dahlgren4efa8b52013-12-17 18:31:35 -0800336 button.setImageResource(imageId);
Erin Dahlgren18484942014-01-07 11:46:57 -0800337
338 if (!button.isEnabled()) {
339 button.setEnabled(true);
340 if (mListener != null) {
341 mListener.onButtonEnabledChanged(this, buttonId);
342 }
343 }
Erin Dahlgrena1fab412014-01-21 09:31:11 -0800344 button.setTag(R.string.tag_enabled_id, (Integer) buttonId);
345
346 if (button.getVisibility() != View.VISIBLE) {
347 button.setVisibility(View.VISIBLE);
348 if (mListener != null) {
349 mListener.onButtonVisibilityChanged(this, buttonId);
350 }
351 }
Erin Dahlgren4efa8b52013-12-17 18:31:35 -0800352 }
353
354 /**
355 * Enable a known button with a click listener. Sets the button visible.
356 */
Erin Dahlgren18484942014-01-07 11:46:57 -0800357 public void enablePushButton(int buttonId, View.OnClickListener cb) {
358 ImageButton button = getImageButtonOrError(buttonId);
Spike Spragueeb3134f2013-12-12 11:14:27 -0800359 button.setOnClickListener(cb);
Erin Dahlgren18484942014-01-07 11:46:57 -0800360
361 if (!button.isEnabled()) {
362 button.setEnabled(true);
363 if (mListener != null) {
364 mListener.onButtonEnabledChanged(this, buttonId);
365 }
366 }
Erin Dahlgrena1fab412014-01-21 09:31:11 -0800367 button.setTag(R.string.tag_enabled_id, (Integer) buttonId);
368
369 if (button.getVisibility() != View.VISIBLE) {
370 button.setVisibility(View.VISIBLE);
371 if (mListener != null) {
372 mListener.onButtonVisibilityChanged(this, buttonId);
373 }
374 }
Spike Spragueeb3134f2013-12-12 11:14:27 -0800375 }
376
Erin Dahlgren8a2933b2013-12-06 12:07:33 -0800377 /**
Erin Dahlgren4efa8b52013-12-17 18:31:35 -0800378 * Sets a button in its disabled (greyed out) state.
Erin Dahlgren8a2933b2013-12-06 12:07:33 -0800379 */
Erin Dahlgren18484942014-01-07 11:46:57 -0800380 public void disableButton(int buttonId) {
381 MultiToggleImageButton button = getButtonOrError(buttonId);
382 if (button.isEnabled()) {
383 button.setEnabled(false);
384 if (mListener != null) {
385 mListener.onButtonEnabledChanged(this, buttonId);
386 }
387 }
Erin Dahlgrena1fab412014-01-21 09:31:11 -0800388 button.setTag(R.string.tag_enabled_id, null);
Erin Dahlgren4efa8b52013-12-17 18:31:35 -0800389
Erin Dahlgren18484942014-01-07 11:46:57 -0800390 if (button.getVisibility() != View.VISIBLE) {
391 button.setVisibility(View.VISIBLE);
392 if (mListener != null) {
393 mListener.onButtonVisibilityChanged(this, buttonId);
394 }
395 }
Erin Dahlgren4efa8b52013-12-17 18:31:35 -0800396 }
397
398 /**
399 * Hide a button by id.
400 */
Erin Dahlgren18484942014-01-07 11:46:57 -0800401 public void hideButton(int buttonId) {
Erin Dahlgrena1fab412014-01-21 09:31:11 -0800402 View button;
403 try {
404 button = (View) getButtonOrError(buttonId);
405 } catch (IllegalArgumentException e) {
406 button = (View) getImageButtonOrError(buttonId);
407 }
Erin Dahlgren18484942014-01-07 11:46:57 -0800408 if (button.getVisibility() == View.VISIBLE) {
409 button.setVisibility(View.INVISIBLE);
410 if (mListener != null) {
411 mListener.onButtonVisibilityChanged(this, buttonId);
412 }
413 }
414 }
415
416 /**
Erin Dahlgrena1fab412014-01-21 09:31:11 -0800417 * Check if a button is enabled with the given button id..
Erin Dahlgren18484942014-01-07 11:46:57 -0800418 */
419 public boolean isEnabled(int buttonId) {
Erin Dahlgrena1fab412014-01-21 09:31:11 -0800420 View button;
421 try {
422 button = (View) getButtonOrError(buttonId);
423 } catch (IllegalArgumentException e) {
424 button = (View) getImageButtonOrError(buttonId);
425 }
426
427 Integer enabledId = (Integer) button.getTag(R.string.tag_enabled_id);
428 if (enabledId != null) {
429 return (enabledId.intValue() == buttonId) && button.isEnabled();
430 } else {
431 return false;
432 }
Erin Dahlgren18484942014-01-07 11:46:57 -0800433 }
434
435 /**
436 * Check if a button is visible.
437 */
438 public boolean isVisible(int buttonId) {
Erin Dahlgrena1fab412014-01-21 09:31:11 -0800439 View button;
440 try {
441 button = (View) getButtonOrError(buttonId);
442 } catch (IllegalArgumentException e) {
443 button = (View) getImageButtonOrError(buttonId);
444 }
Erin Dahlgren18484942014-01-07 11:46:57 -0800445 return (button.getVisibility() == View.VISIBLE);
Erin Dahlgren8a2933b2013-12-06 12:07:33 -0800446 }
447
448 /**
449 * Enable a flash button.
450 */
451 private void enableFlashButton(MultiToggleImageButton button,
452 final ButtonCallback cb, int resIdImages) {
Erin Dahlgren18e2ef62013-12-05 14:53:38 -0800453
454 if (resIdImages > 0) {
Erin Dahlgren8a2933b2013-12-06 12:07:33 -0800455 button.overrideImageIds(resIdImages);
Erin Dahlgren18e2ef62013-12-05 14:53:38 -0800456 }
Spike Sprague79718f62014-01-28 18:48:22 -0800457 button.overrideContentDescriptions(R.array.camera_flash_descriptions);
458
Erin Dahlgren18e2ef62013-12-05 14:53:38 -0800459 int index = mSettingsManager.getStringValueIndex(SettingsManager.SETTING_FLASH_MODE);
Erin Dahlgren4efa8b52013-12-17 18:31:35 -0800460 button.setState(index >= 0 ? index : 0, false);
461
Erin Dahlgren8a2933b2013-12-06 12:07:33 -0800462 button.setOnStateChangeListener(new MultiToggleImageButton.OnStateChangeListener() {
Spike Sprague6b174192014-01-09 11:54:17 -0800463 @Override
464 public void stateChanged(View view, int state) {
465 mSettingsManager.setStringValueIndex(SettingsManager.SETTING_FLASH_MODE, state);
466 if (cb != null) {
467 cb.onStateChanged(state);
Erin Dahlgren18e2ef62013-12-05 14:53:38 -0800468 }
Spike Sprague6b174192014-01-09 11:54:17 -0800469 }
470 });
Erin Dahlgren18e2ef62013-12-05 14:53:38 -0800471 }
472
473 /**
Spike Sprague0f3c4b42013-12-10 19:50:17 -0800474 * Enable video torch button
475 */
476 private void enableTorchButton(MultiToggleImageButton button,
477 final ButtonCallback cb, int resIdImages) {
Erin Dahlgren4efa8b52013-12-17 18:31:35 -0800478
Spike Sprague0f3c4b42013-12-10 19:50:17 -0800479 if (resIdImages > 0) {
480 button.overrideImageIds(resIdImages);
481 }
Spike Sprague79718f62014-01-28 18:48:22 -0800482 button.overrideContentDescriptions(R.array.video_flash_descriptions);
483
Spike Sprague0f3c4b42013-12-10 19:50:17 -0800484 int index = mSettingsManager.getStringValueIndex(
485 SettingsManager.SETTING_VIDEOCAMERA_FLASH_MODE);
Erin Dahlgren4efa8b52013-12-17 18:31:35 -0800486 button.setState(index >= 0 ? index : 0, false);
487
Spike Sprague0f3c4b42013-12-10 19:50:17 -0800488 button.setOnStateChangeListener(new MultiToggleImageButton.OnStateChangeListener() {
Spike Sprague6b174192014-01-09 11:54:17 -0800489 @Override
490 public void stateChanged(View view, int state) {
491 mSettingsManager.setStringValueIndex(
492 SettingsManager.SETTING_VIDEOCAMERA_FLASH_MODE, state);
493 if(cb != null) {
494 cb.onStateChanged(state);
Spike Sprague0f3c4b42013-12-10 19:50:17 -0800495 }
Spike Sprague6b174192014-01-09 11:54:17 -0800496 }
497 });
Spike Sprague0f3c4b42013-12-10 19:50:17 -0800498 }
499
500 /**
Erin Dahlgren8a2933b2013-12-06 12:07:33 -0800501 * Enable a camera button.
Erin Dahlgren18e2ef62013-12-05 14:53:38 -0800502 */
Erin Dahlgren8a2933b2013-12-06 12:07:33 -0800503 private void enableCameraButton(MultiToggleImageButton button,
504 final ButtonCallback cb, int resIdImages) {
Erin Dahlgren18e2ef62013-12-05 14:53:38 -0800505
506 if (resIdImages > 0) {
Erin Dahlgren8a2933b2013-12-06 12:07:33 -0800507 button.overrideImageIds(resIdImages);
Erin Dahlgren18e2ef62013-12-05 14:53:38 -0800508 }
Erin Dahlgren8a2933b2013-12-06 12:07:33 -0800509
Erin Dahlgren18e2ef62013-12-05 14:53:38 -0800510 int index = mSettingsManager.getStringValueIndex(SettingsManager.SETTING_CAMERA_ID);
Erin Dahlgren4efa8b52013-12-17 18:31:35 -0800511 button.setState(index >= 0 ? index : 0, false);
Erin Dahlgren8a2933b2013-12-06 12:07:33 -0800512
513 button.setOnStateChangeListener(new MultiToggleImageButton.OnStateChangeListener() {
Spike Sprague6b174192014-01-09 11:54:17 -0800514 @Override
515 public void stateChanged(View view, int state) {
516 mSettingsManager.setStringValueIndex(SettingsManager.SETTING_CAMERA_ID, state);
517 int cameraId = Integer.parseInt(mSettingsManager.get(
Erin Dahlgren18e2ef62013-12-05 14:53:38 -0800518 SettingsManager.SETTING_CAMERA_ID));
Spike Sprague6b174192014-01-09 11:54:17 -0800519 if (cb != null) {
520 cb.onStateChanged(cameraId);
Erin Dahlgren18e2ef62013-12-05 14:53:38 -0800521 }
Erin Dahlgrenb1641f52014-01-14 15:58:52 -0800522 mAppController.getCameraAppUI().onChangeCamera();
Spike Sprague6b174192014-01-09 11:54:17 -0800523 }
524 });
Erin Dahlgren18e2ef62013-12-05 14:53:38 -0800525 }
526
527 /**
Erin Dahlgren8a2933b2013-12-06 12:07:33 -0800528 * Enable an hdr plus button.
Erin Dahlgren18e2ef62013-12-05 14:53:38 -0800529 */
Erin Dahlgren8a2933b2013-12-06 12:07:33 -0800530 private void enableHdrPlusButton(MultiToggleImageButton button,
531 final ButtonCallback cb, int resIdImages) {
Erin Dahlgren18e2ef62013-12-05 14:53:38 -0800532
533 if (resIdImages > 0) {
Erin Dahlgren8a2933b2013-12-06 12:07:33 -0800534 button.overrideImageIds(resIdImages);
Erin Dahlgren18e2ef62013-12-05 14:53:38 -0800535 }
Spike Sprague79718f62014-01-28 18:48:22 -0800536 button.overrideContentDescriptions(R.array.hdr_plus_descriptions);
Erin Dahlgren8a2933b2013-12-06 12:07:33 -0800537
Erin Dahlgren18e2ef62013-12-05 14:53:38 -0800538 int index = mSettingsManager.getStringValueIndex(SettingsManager.SETTING_CAMERA_HDR);
Erin Dahlgren4efa8b52013-12-17 18:31:35 -0800539 button.setState(index >= 0 ? index : 0, false);
Erin Dahlgren8a2933b2013-12-06 12:07:33 -0800540
541 button.setOnStateChangeListener(new MultiToggleImageButton.OnStateChangeListener() {
Spike Sprague6b174192014-01-09 11:54:17 -0800542 @Override
543 public void stateChanged(View view, int state) {
544 mSettingsManager.setStringValueIndex(SettingsManager.SETTING_CAMERA_HDR, state);
545 if (cb != null) {
546 cb.onStateChanged(state);
Erin Dahlgren18e2ef62013-12-05 14:53:38 -0800547 }
Spike Sprague6b174192014-01-09 11:54:17 -0800548 }
549 });
Erin Dahlgren18e2ef62013-12-05 14:53:38 -0800550 }
Erin Dahlgren4efa8b52013-12-17 18:31:35 -0800551
552 /**
553 * Enable a refocus button.
554 */
555 private void enableRefocusButton(MultiToggleImageButton button,
556 final ButtonCallback cb, int resIdImages) {
557
558 if (resIdImages > 0) {
559 button.overrideImageIds(resIdImages);
560 }
561
562 int index = mSettingsManager.getStringValueIndex(SettingsManager.SETTING_CAMERA_REFOCUS);
563 button.setState(index >= 0 ? index : 0, false);
564
565 button.setOnStateChangeListener(new MultiToggleImageButton.OnStateChangeListener() {
Spike Sprague6b174192014-01-09 11:54:17 -0800566 @Override
567 public void stateChanged(View view, int state) {
568 mSettingsManager.setStringValueIndex(SettingsManager.SETTING_CAMERA_REFOCUS, state);
569 if (cb != null) {
570 cb.onStateChanged(state);
Erin Dahlgren4efa8b52013-12-17 18:31:35 -0800571 }
Spike Sprague6b174192014-01-09 11:54:17 -0800572 }
573 });
Erin Dahlgren4efa8b52013-12-17 18:31:35 -0800574 }
Erin Dahlgren18e2ef62013-12-05 14:53:38 -0800575}