CameraAppUI.java revision c91c8d273b8884468dfd66a5b82526dc8245934e
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
17package com.android.camera.app;
18
19import android.accessibilityservice.AccessibilityServiceInfo;
20import android.content.Context;
21import android.content.res.Resources;
22import android.graphics.Bitmap;
23import android.graphics.Canvas;
24import android.graphics.Matrix;
25import android.graphics.RectF;
26import android.graphics.SurfaceTexture;
27import android.hardware.display.DisplayManager;
28import android.util.CameraPerformanceTracker;
29import android.view.GestureDetector;
30import android.view.Gravity;
31import android.view.LayoutInflater;
32import android.view.MotionEvent;
33import android.view.TextureView;
34import android.view.View;
35import android.view.ViewConfiguration;
36import android.view.ViewGroup;
37import android.view.accessibility.AccessibilityManager;
38import android.widget.FrameLayout;
39
40import com.android.camera.AnimationManager;
41import com.android.camera.ButtonManager;
42import com.android.camera.CaptureLayoutHelper;
43import com.android.camera.ShutterButton;
44import com.android.camera.TextureViewHelper;
45import com.android.camera.debug.Log;
46import com.android.camera.filmstrip.FilmstripContentPanel;
47import com.android.camera.hardware.HardwareSpec;
48import com.android.camera.module.ModuleController;
49import com.android.camera.settings.Keys;
50import com.android.camera.settings.SettingsManager;
51import com.android.camera.ui.AbstractTutorialOverlay;
52import com.android.camera.ui.BottomBar;
53import com.android.camera.ui.BottomBarModeOptionsWrapper;
54import com.android.camera.ui.CaptureAnimationOverlay;
55import com.android.camera.ui.GridLines;
56import com.android.camera.ui.MainActivityLayout;
57import com.android.camera.ui.ModeListView;
58import com.android.camera.ui.ModeTransitionView;
59import com.android.camera.ui.PreviewOverlay;
60import com.android.camera.ui.PreviewStatusListener;
61import com.android.camera.ui.TouchCoordinate;
62import com.android.camera.util.ApiHelper;
63import com.android.camera.util.CameraUtil;
64import com.android.camera.util.Gusterpolator;
65import com.android.camera.util.PhotoSphereHelper;
66import com.android.camera.widget.Cling;
67import com.android.camera.widget.FilmstripLayout;
68import com.android.camera.widget.IndicatorIconController;
69import com.android.camera.widget.ModeOptionsOverlay;
70import com.android.camera.widget.PeekView;
71import com.android.camera2.R;
72
73import java.util.List;
74
75/**
76 * CameraAppUI centralizes control of views shared across modules. Whereas module
77 * specific views will be handled in each Module UI. For example, we can now
78 * bring the flash animation and capture animation up from each module to app
79 * level, as these animations are largely the same for all modules.
80 *
81 * This class also serves to disambiguate touch events. It recognizes all the
82 * swipe gestures that happen on the preview by attaching a touch listener to
83 * a full-screen view on top of preview TextureView. Since CameraAppUI has knowledge
84 * of how swipe from each direction should be handled, it can then redirect these
85 * events to appropriate recipient views.
86 */
87public class CameraAppUI implements ModeListView.ModeSwitchListener,
88                                    TextureView.SurfaceTextureListener,
89                                    ModeListView.ModeListOpenListener,
90                                    SettingsManager.OnSettingChangedListener,
91                                    ShutterButton.OnShutterButtonListener {
92
93    /**
94     * The bottom controls on the filmstrip.
95     */
96    public static interface BottomPanel {
97        /** Values for the view state of the button. */
98        public final int VIEWER_NONE = 0;
99        public final int VIEWER_PHOTO_SPHERE = 1;
100        public final int VIEWER_REFOCUS = 2;
101        public final int VIEWER_OTHER = 3;
102
103        /**
104         * Sets a new or replaces an existing listener for bottom control events.
105         */
106        void setListener(Listener listener);
107
108        /**
109         * Sets cling for external viewer button.
110         */
111        void setClingForViewer(int viewerType, Cling cling);
112
113        /**
114         * Clears cling for external viewer button.
115         */
116        void clearClingForViewer(int viewerType);
117
118        /**
119         * Returns a cling for the specified viewer type.
120         */
121        Cling getClingForViewer(int viewerType);
122
123        /**
124         * Set if the bottom controls are visible.
125         * @param visible {@code true} if visible.
126         */
127        void setVisible(boolean visible);
128
129        /**
130         * @param visible Whether the button is visible.
131         */
132        void setEditButtonVisibility(boolean visible);
133
134        /**
135         * @param enabled Whether the button is enabled.
136         */
137        void setEditEnabled(boolean enabled);
138
139        /**
140         * Sets the visibility of the view-photosphere button.
141         *
142         * @param state one of {@link #VIEWER_NONE}, {@link #VIEWER_PHOTO_SPHERE},
143         *            {@link #VIEWER_REFOCUS}.
144         */
145        void setViewerButtonVisibility(int state);
146
147        /**
148         * @param enabled Whether the button is enabled.
149         */
150        void setViewEnabled(boolean enabled);
151
152        /**
153         * @param enabled Whether the button is enabled.
154         */
155        void setTinyPlanetEnabled(boolean enabled);
156
157        /**
158         * @param visible Whether the button is visible.
159         */
160        void setDeleteButtonVisibility(boolean visible);
161
162        /**
163         * @param enabled Whether the button is enabled.
164         */
165        void setDeleteEnabled(boolean enabled);
166
167        /**
168         * @param visible Whether the button is visible.
169         */
170        void setShareButtonVisibility(boolean visible);
171
172        /**
173         * @param enabled Whether the button is enabled.
174         */
175        void setShareEnabled(boolean enabled);
176
177        /**
178         * Sets the texts for progress UI.
179         *
180         * @param text The text to show.
181         */
182        void setProgressText(CharSequence text);
183
184        /**
185         * Sets the progress.
186         *
187         * @param progress The progress value. Should be between 0 and 100.
188         */
189        void setProgress(int progress);
190
191        /**
192         * Replaces the progress UI with an error message.
193         */
194        void showProgressError(CharSequence message);
195
196        /**
197         * Hide the progress error message.
198         */
199        void hideProgressError();
200
201        /**
202         * Shows the progress.
203         */
204        void showProgress();
205
206        /**
207         * Hides the progress.
208         */
209        void hideProgress();
210
211        /**
212         * Shows the controls.
213         */
214        void showControls();
215
216        /**
217         * Hides the controls.
218         */
219        void hideControls();
220
221        /**
222         * Classes implementing this interface can listen for events on the bottom
223         * controls.
224         */
225        public static interface Listener {
226            /**
227             * Called when the user pressed the "view" button to e.g. view a photo
228             * sphere or RGBZ image.
229             */
230            public void onExternalViewer();
231
232            /**
233             * Called when the "edit" button is pressed.
234             */
235            public void onEdit();
236
237            /**
238             * Called when the "tiny planet" button is pressed.
239             */
240            public void onTinyPlanet();
241
242            /**
243             * Called when the "delete" button is pressed.
244             */
245            public void onDelete();
246
247            /**
248             * Called when the "share" button is pressed.
249             */
250            public void onShare();
251
252            /**
253             * Called when the progress error message is clicked.
254             */
255            public void onProgressErrorClicked();
256        }
257    }
258
259    /**
260     * BottomBarUISpec provides a structure for modules
261     * to specify their ideal bottom bar mode options layout.
262     *
263     * Once constructed by a module, this class should be
264     * treated as read only.
265     *
266     * The application then edits this spec according to
267     * hardware limitations and displays the final bottom
268     * bar ui.
269     */
270    public static class BottomBarUISpec {
271        /** Mode options UI */
272
273        /**
274         * Set true if the camera option should be enabled.
275         * If not set or false, and multiple cameras are supported,
276         * the camera option will be disabled.
277         *
278         * If multiple cameras are not supported, this preference
279         * is ignored and the camera option will not be visible.
280         */
281        public boolean enableCamera;
282
283        /**
284         * Set true if the camera option should not be visible, regardless
285         * of hardware limitations.
286         */
287        public boolean hideCamera;
288
289        /**
290         * Set true if the photo flash option should be enabled.
291         * If not set or false, the photo flash option will be
292         * disabled.
293         *
294         * If the hardware does not support multiple flash values,
295         * this preference is ignored and the flash option will
296         * be disabled.  It will not be made invisible in order to
297         * preserve a consistent experience across devices and between
298         * front and back cameras.
299         */
300        public boolean enableFlash;
301
302        /**
303         * Set true if the video flash option should be enabled.
304         * Same disable rules apply as the photo flash option.
305         */
306        public boolean enableTorchFlash;
307
308        /**
309         * Set true if the HDR+ flash option should be enabled.
310         * Same disable rules apply as the photo flash option.
311         */
312        public boolean enableHdrPlusFlash;
313
314        /**
315         * Set true if flash should not be visible, regardless of
316         * hardware limitations.
317         */
318        public boolean hideFlash;
319
320        /**
321         * Set true if the hdr/hdr+ option should be enabled.
322         * If not set or false, the hdr/hdr+ option will be disabled.
323         *
324         * Hdr or hdr+ will be chosen based on hardware limitations,
325         * with hdr+ prefered.
326         *
327         * If hardware supports neither hdr nor hdr+, then the hdr/hdr+
328         * will not be visible.
329         */
330        public boolean enableHdr;
331
332        /**
333         * Set true if hdr/hdr+ should not be visible, regardless of
334         * hardware limitations.
335         */
336        public boolean hideHdr;
337
338        /**
339         * Set true if grid lines should be visible.  Not setting this
340         * causes grid lines to be disabled.  This option is agnostic to
341         * the hardware.
342         */
343        public boolean enableGridLines;
344
345        /**
346         * Set true if grid lines should not be visible.
347         */
348        public boolean hideGridLines;
349
350        /**
351         * Set true if the panorama orientation option should be visible.
352         *
353         * This option is not constrained by hardware limitations.
354         */
355        public boolean enablePanoOrientation;
356
357        public boolean enableExposureCompensation;
358
359        /** Intent UI */
360
361        /**
362         * Set true if the intent ui cancel option should be visible.
363         */
364        public boolean showCancel;
365        /**
366         * Set true if the intent ui done option should be visible.
367         */
368        public boolean showDone;
369        /**
370         * Set true if the intent ui retake option should be visible.
371         */
372        public boolean showRetake;
373        /**
374         * Set true if the intent ui review option should be visible.
375         */
376        public boolean showReview;
377
378        /** Mode options callbacks */
379
380        /**
381         * A {@link com.android.camera.ButtonManager.ButtonCallback}
382         * that will be executed when the camera option is pressed. This
383         * callback can be null.
384         */
385        public ButtonManager.ButtonCallback cameraCallback;
386
387        /**
388         * A {@link com.android.camera.ButtonManager.ButtonCallback}
389         * that will be executed when the flash option is pressed. This
390         * callback can be null.
391         */
392        public ButtonManager.ButtonCallback flashCallback;
393
394        /**
395         * A {@link com.android.camera.ButtonManager.ButtonCallback}
396         * that will be executed when the hdr/hdr+ option is pressed. This
397         * callback can be null.
398         */
399        public ButtonManager.ButtonCallback hdrCallback;
400
401        /**
402         * A {@link com.android.camera.ButtonManager.ButtonCallback}
403         * that will be executed when the grid lines option is pressed. This
404         * callback can be null.
405         */
406        public ButtonManager.ButtonCallback gridLinesCallback;
407
408        /**
409         * A {@link com.android.camera.ButtonManager.ButtonCallback}
410         * that will execute when the panorama orientation option is pressed.
411         * This callback can be null.
412         */
413        public ButtonManager.ButtonCallback panoOrientationCallback;
414
415        /** Intent UI callbacks */
416
417        /**
418         * A {@link android.view.View.OnClickListener} that will execute
419         * when the cancel option is pressed. This callback can be null.
420         */
421        public View.OnClickListener cancelCallback;
422
423        /**
424         * A {@link android.view.View.OnClickListener} that will execute
425         * when the done option is pressed. This callback can be null.
426         */
427        public View.OnClickListener doneCallback;
428
429        /**
430         * A {@link android.view.View.OnClickListener} that will execute
431         * when the retake option is pressed. This callback can be null.
432         */
433        public View.OnClickListener retakeCallback;
434
435        /**
436         * A {@link android.view.View.OnClickListener} that will execute
437         * when the review option is pressed. This callback can be null.
438         */
439        public View.OnClickListener reviewCallback;
440
441        /**
442         * A ExposureCompensationSetCallback that will execute
443         * when an expsosure button is pressed. This callback can be null.
444         */
445        public interface ExposureCompensationSetCallback {
446            public void setExposure(int value);
447        }
448        public ExposureCompensationSetCallback exposureCompensationSetCallback;
449
450        /**
451         * Exposure compensation parameters.
452         */
453        public int minExposureCompensation;
454        public int maxExposureCompensation;
455        public float exposureCompensationStep;
456
457        /**
458         * Whether self-timer is enabled.
459         */
460        public boolean enableSelfTimer = false;
461
462        /**
463         * Whether the option for self-timer should show. If true and
464         * {@link #enableSelfTimer} is false, then the option should be shown
465         * disabled.
466         */
467        public boolean showSelfTimer = false;
468    }
469
470
471    private final static Log.Tag TAG = new Log.Tag("CameraAppUI");
472
473    private final AppController mController;
474    private final boolean mIsCaptureIntent;
475    private final AnimationManager mAnimationManager;
476
477    // Swipe states:
478    private final static int IDLE = 0;
479    private final static int SWIPE_UP = 1;
480    private final static int SWIPE_DOWN = 2;
481    private final static int SWIPE_LEFT = 3;
482    private final static int SWIPE_RIGHT = 4;
483    private boolean mSwipeEnabled = true;
484
485    // Shared Surface Texture properities.
486    private SurfaceTexture mSurface;
487    private int mSurfaceWidth;
488    private int mSurfaceHeight;
489
490    // Touch related measures:
491    private final int mSlop;
492    private final static int SWIPE_TIME_OUT_MS = 500;
493
494    // Mode cover states:
495    private final static int COVER_HIDDEN = 0;
496    private final static int COVER_SHOWN = 1;
497    private final static int COVER_WILL_HIDE_AT_NEXT_FRAME = 2;
498    private static final int COVER_WILL_HIDE_AT_NEXT_TEXTURE_UPDATE = 3;
499
500    /**
501     * Preview down-sample rate when taking a screenshot.
502     */
503    private final static int DOWN_SAMPLE_RATE_FOR_SCREENSHOT = 2;
504
505    // App level views:
506    private final FrameLayout mCameraRootView;
507    private final ModeTransitionView mModeTransitionView;
508    private final MainActivityLayout mAppRootView;
509    private final ModeListView mModeListView;
510    private final FilmstripLayout mFilmstripLayout;
511    private TextureView mTextureView;
512    private FrameLayout mModuleUI;
513    private ShutterButton mShutterButton;
514    private View mLetterBoxer1;
515    private View mLetterBoxer2;
516    private BottomBar mBottomBar;
517    private ModeOptionsOverlay mModeOptionsOverlay;
518    private IndicatorIconController mIndicatorIconController;
519    private View mFocusOverlay;
520    private FrameLayout mTutorialsPlaceHolderWrapper;
521    private BottomBarModeOptionsWrapper mIndicatorBottomBarWrapper;
522    private TextureViewHelper mTextureViewHelper;
523    private final GestureDetector mGestureDetector;
524    private DisplayManager.DisplayListener mDisplayListener;
525    private int mLastRotation;
526    private int mSwipeState = IDLE;
527    private PreviewOverlay mPreviewOverlay;
528    private GridLines mGridLines;
529    private CaptureAnimationOverlay mCaptureOverlay;
530    private PreviewStatusListener mPreviewStatusListener;
531    private int mModeCoverState = COVER_HIDDEN;
532    private final FilmstripBottomPanel mFilmstripBottomControls;
533    private final FilmstripContentPanel mFilmstripPanel;
534    private Runnable mHideCoverRunnable;
535    private final View.OnLayoutChangeListener mPreviewLayoutChangeListener
536            = new View.OnLayoutChangeListener() {
537        @Override
538        public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft,
539                int oldTop, int oldRight, int oldBottom) {
540            if (mPreviewStatusListener != null) {
541                mPreviewStatusListener.onPreviewLayoutChanged(v, left, top, right, bottom, oldLeft,
542                        oldTop, oldRight, oldBottom);
543            }
544        }
545    };
546    private View mModeOptionsToggle;
547    private final PeekView mPeekView;
548    private final CaptureLayoutHelper mCaptureLayoutHelper;
549    private boolean mAccessibilityEnabled;
550    private final View mAccessibilityAffordances;
551
552    /**
553     * Provides current preview frame and the controls/overlay from the module that
554     * are shown on top of the preview.
555     */
556    public interface CameraModuleScreenShotProvider {
557        /**
558         * Returns the current preview frame down-sampled using the given down-sample
559         * factor.
560         *
561         * @param downSampleFactor the down sample factor for down sampling the
562         *                         preview frame. (e.g. a down sample factor of
563         *                         2 means to scale down the preview frame to 1/2
564         *                         the width and height.)
565         * @return down-sampled preview frame
566         */
567        public Bitmap getPreviewFrame(int downSampleFactor);
568
569        /**
570         * @return the controls and overlays that are currently showing on top of
571         *         the preview drawn into a bitmap with no scaling applied.
572         */
573        public Bitmap getPreviewOverlayAndControls();
574
575        /**
576         * Returns a bitmap containing the current screenshot.
577         *
578         * @param previewDownSampleFactor the downsample factor applied on the
579         *                                preview frame when taking the screenshot
580         */
581        public Bitmap getScreenShot(int previewDownSampleFactor);
582    }
583
584    /**
585     * This listener gets called when the size of the window (excluding the system
586     * decor such as status bar and nav bar) has changed.
587     */
588    public interface NonDecorWindowSizeChangedListener {
589        public void onNonDecorWindowSizeChanged(int width, int height, int rotation);
590    }
591
592    private final CameraModuleScreenShotProvider mCameraModuleScreenShotProvider =
593            new CameraModuleScreenShotProvider() {
594                @Override
595                public Bitmap getPreviewFrame(int downSampleFactor) {
596                    if (mCameraRootView == null || mTextureView == null) {
597                        return null;
598                    }
599                    // Gets the bitmap from the preview TextureView.
600                    Bitmap preview = mTextureViewHelper.getPreviewBitmap(downSampleFactor);
601                    return preview;
602                }
603
604                @Override
605                public Bitmap getPreviewOverlayAndControls() {
606                    Bitmap overlays = Bitmap.createBitmap(mCameraRootView.getWidth(),
607                            mCameraRootView.getHeight(), Bitmap.Config.ARGB_8888);
608                    Canvas canvas = new Canvas(overlays);
609                    mCameraRootView.draw(canvas);
610                    return overlays;
611                }
612
613                @Override
614                public Bitmap getScreenShot(int previewDownSampleFactor) {
615                    Bitmap screenshot = Bitmap.createBitmap(mCameraRootView.getWidth(),
616                            mCameraRootView.getHeight(), Bitmap.Config.ARGB_8888);
617                    Canvas canvas = new Canvas(screenshot);
618                    canvas.drawARGB(255, 0, 0, 0);
619                    Bitmap preview = mTextureViewHelper.getPreviewBitmap(previewDownSampleFactor);
620                    if (preview != null) {
621                        canvas.drawBitmap(preview, null, mTextureViewHelper.getPreviewArea(), null);
622                    }
623                    Bitmap overlay = getPreviewOverlayAndControls();
624                    if (overlay != null) {
625                        canvas.drawBitmap(overlay, 0f, 0f, null);
626                    }
627                    return screenshot;
628                }
629            };
630
631    private long mCoverHiddenTime = -1; // System time when preview cover was hidden.
632
633    public long getCoverHiddenTime() {
634        return mCoverHiddenTime;
635    }
636
637    /**
638     * This resets the preview to have no applied transform matrix.
639     */
640    public void clearPreviewTransform() {
641        mTextureViewHelper.clearTransform();
642    }
643
644    public void updatePreviewAspectRatio(float aspectRatio) {
645        mTextureViewHelper.updateAspectRatio(aspectRatio);
646    }
647
648    /**
649     * WAR: Reset the SurfaceTexture's default buffer size to the current view dimensions of
650     * its TextureView.  This is necessary to get the expected behavior for the TextureView's
651     * HardwareLayer transform matrix (set by TextureView#setTransform) after configuring the
652     * SurfaceTexture as an output for the Camera2 API (which involves changing the default buffer
653     * size).
654     *
655     * b/17286155 - Tracking a fix for this in HardwareLayer.
656     */
657    public void setDefaultBufferSizeToViewDimens() {
658        if (mSurface == null || mTextureView == null) {
659            Log.w(TAG, "Could not set SurfaceTexture default buffer dimensions, not yet setup");
660            return;
661        }
662        mSurface.setDefaultBufferSize(mTextureView.getWidth(), mTextureView.getHeight());
663    }
664
665    /**
666     * Updates the preview matrix without altering it.
667     *
668     * @param matrix
669     * @param aspectRatio the desired aspect ratio for the preview.
670     */
671    public void updatePreviewTransformFullscreen(Matrix matrix, float aspectRatio) {
672        mTextureViewHelper.updateTransformFullScreen(matrix, aspectRatio);
673    }
674
675    /**
676     * @return the rect that will display the preview.
677     */
678    public RectF getFullscreenRect() {
679        return mTextureViewHelper.getFullscreenRect();
680    }
681
682    /**
683     * This is to support modules that calculate their own transform matrix because
684     * they need to use a transform matrix to rotate the preview.
685     *
686     * @param matrix transform matrix to be set on the TextureView
687     */
688    public void updatePreviewTransform(Matrix matrix) {
689        mTextureViewHelper.updateTransform(matrix);
690    }
691
692    public interface AnimationFinishedListener {
693        public void onAnimationFinished(boolean success);
694    }
695
696    private class MyTouchListener implements View.OnTouchListener {
697        private boolean mScaleStarted = false;
698        @Override
699        public boolean onTouch(View v, MotionEvent event) {
700            if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
701                mScaleStarted = false;
702            } else if (event.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) {
703                mScaleStarted = true;
704            }
705            return (!mScaleStarted) && mGestureDetector.onTouchEvent(event);
706        }
707    }
708
709    /**
710     * This gesture listener finds out the direction of the scroll gestures and
711     * sends them to CameraAppUI to do further handling.
712     */
713    private class MyGestureListener extends GestureDetector.SimpleOnGestureListener {
714        private MotionEvent mDown;
715
716        @Override
717        public boolean onScroll(MotionEvent e1, MotionEvent ev, float distanceX, float distanceY) {
718            if (ev.getEventTime() - ev.getDownTime() > SWIPE_TIME_OUT_MS
719                    || mSwipeState != IDLE
720                    || mIsCaptureIntent
721                    || !mSwipeEnabled) {
722                return false;
723            }
724
725            int deltaX = (int) (ev.getX() - mDown.getX());
726            int deltaY = (int) (ev.getY() - mDown.getY());
727            if (ev.getActionMasked() == MotionEvent.ACTION_MOVE) {
728                if (Math.abs(deltaX) > mSlop || Math.abs(deltaY) > mSlop) {
729                    // Calculate the direction of the swipe.
730                    if (deltaX >= Math.abs(deltaY)) {
731                        // Swipe right.
732                        setSwipeState(SWIPE_RIGHT);
733                    } else if (deltaX <= -Math.abs(deltaY)) {
734                        // Swipe left.
735                        setSwipeState(SWIPE_LEFT);
736                    }
737                }
738            }
739            return true;
740        }
741
742        private void setSwipeState(int swipeState) {
743            mSwipeState = swipeState;
744            // Notify new swipe detected.
745            onSwipeDetected(swipeState);
746        }
747
748        @Override
749        public boolean onDown(MotionEvent ev) {
750            mDown = MotionEvent.obtain(ev);
751            mSwipeState = IDLE;
752            return false;
753        }
754    }
755
756    public CameraAppUI(AppController controller, MainActivityLayout appRootView,
757            boolean isCaptureIntent) {
758        mSlop = ViewConfiguration.get(controller.getAndroidContext()).getScaledTouchSlop();
759        mController = controller;
760        mIsCaptureIntent = isCaptureIntent;
761
762        mAppRootView = appRootView;
763        mFilmstripLayout = (FilmstripLayout) appRootView.findViewById(R.id.filmstrip_layout);
764        mCameraRootView = (FrameLayout) appRootView.findViewById(R.id.camera_app_root);
765        mModeTransitionView = (ModeTransitionView)
766                mAppRootView.findViewById(R.id.mode_transition_view);
767        mFilmstripBottomControls = new FilmstripBottomPanel(controller,
768                (ViewGroup) mAppRootView.findViewById(R.id.filmstrip_bottom_panel));
769        mFilmstripPanel = (FilmstripContentPanel) mAppRootView.findViewById(R.id.filmstrip_layout);
770        mGestureDetector = new GestureDetector(controller.getAndroidContext(),
771                new MyGestureListener());
772        Resources res = controller.getAndroidContext().getResources();
773        mCaptureLayoutHelper = new CaptureLayoutHelper(
774                res.getDimensionPixelSize(R.dimen.bottom_bar_height_min),
775                res.getDimensionPixelSize(R.dimen.bottom_bar_height_max),
776                res.getDimensionPixelSize(R.dimen.bottom_bar_height_optimal));
777        mModeListView = (ModeListView) appRootView.findViewById(R.id.mode_list_layout);
778        if (mModeListView != null) {
779            mModeListView.setModeSwitchListener(this);
780            mModeListView.setModeListOpenListener(this);
781            mModeListView.setCameraModuleScreenShotProvider(mCameraModuleScreenShotProvider);
782            mModeListView.setCaptureLayoutHelper(mCaptureLayoutHelper);
783            boolean shouldShowSettingsCling = mController.getSettingsManager().getBoolean(
784                    SettingsManager.SCOPE_GLOBAL,
785                    Keys.KEY_SHOULD_SHOW_SETTINGS_BUTTON_CLING);
786            mModeListView.setShouldShowSettingsCling(shouldShowSettingsCling);
787        } else {
788            Log.e(TAG, "Cannot find mode list in the view hierarchy");
789        }
790        mAnimationManager = new AnimationManager();
791        mPeekView = (PeekView) appRootView.findViewById(R.id.peek_view);
792        mAppRootView.setNonDecorWindowSizeChangedListener(mCaptureLayoutHelper);
793        initDisplayListener();
794        mAccessibilityAffordances = mAppRootView.findViewById(R.id.accessibility_affordances);
795        View modeListToggle = mAppRootView.findViewById(R.id.accessibility_mode_toggle_button);
796        modeListToggle.setOnClickListener(new View.OnClickListener() {
797            @Override
798            public void onClick(View view) {
799                openModeList();
800            }
801        });
802        View filmstripToggle = mAppRootView.findViewById(
803                R.id.accessibility_filmstrip_toggle_button);
804        filmstripToggle.setOnClickListener(new View.OnClickListener() {
805            @Override
806            public void onClick(View view) {
807                showFilmstrip();
808            }
809        });
810    }
811
812
813    /**
814     * Freeze what is currently shown on screen until the next preview frame comes
815     * in.
816     */
817    public void freezeScreenUntilPreviewReady() {
818        Log.v(TAG, "freezeScreenUntilPreviewReady");
819        mModeTransitionView.setupModeCover(mCameraModuleScreenShotProvider
820                .getScreenShot(DOWN_SAMPLE_RATE_FOR_SCREENSHOT));
821        mHideCoverRunnable = new Runnable() {
822            @Override
823            public void run() {
824                mModeTransitionView.hideImageCover();
825            }
826        };
827        mModeCoverState = COVER_SHOWN;
828    }
829
830    /**
831     * Creates a cling for the specific viewer and links the cling to the corresponding
832     * button for layout position.
833     *
834     * @param viewerType defines which viewer the cling is for.
835     */
836    public void setupClingForViewer(int viewerType) {
837        if (viewerType == BottomPanel.VIEWER_REFOCUS) {
838            FrameLayout filmstripContent = (FrameLayout) mAppRootView
839                    .findViewById(R.id.camera_filmstrip_content_layout);
840            if (filmstripContent != null) {
841                // Creates refocus cling.
842                LayoutInflater inflater = (LayoutInflater) mController.getAndroidContext()
843                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
844                Cling refocusCling = (Cling) inflater.inflate(R.layout.cling_widget, null, false);
845                // Sets instruction text in the cling.
846                refocusCling.setText(mController.getAndroidContext().getResources()
847                        .getString(R.string.cling_text_for_refocus_editor_button));
848
849                // Adds cling into view hierarchy.
850                int clingWidth = mController.getAndroidContext()
851                        .getResources().getDimensionPixelSize(R.dimen.default_cling_width);
852                filmstripContent.addView(refocusCling, clingWidth,
853                        ViewGroup.LayoutParams.WRAP_CONTENT);
854                mFilmstripBottomControls.setClingForViewer(viewerType, refocusCling);
855            }
856        }
857    }
858
859    /**
860     * Clears the listeners for the cling and remove it from the view hierarchy.
861     *
862     * @param viewerType defines which viewer the cling is for.
863     */
864    public void clearClingForViewer(int viewerType) {
865        Cling clingToBeRemoved = mFilmstripBottomControls.getClingForViewer(viewerType);
866        if (clingToBeRemoved == null) {
867            // No cling is created for the specific viewer type.
868            return;
869        }
870        mFilmstripBottomControls.clearClingForViewer(viewerType);
871        clingToBeRemoved.setVisibility(View.GONE);
872        mAppRootView.removeView(clingToBeRemoved);
873    }
874
875    /**
876     * Enable or disable swipe gestures. We want to disable them e.g. while we
877     * record a video.
878     */
879    public void setSwipeEnabled(boolean enabled) {
880        mSwipeEnabled = enabled;
881        // TODO: This can be removed once we come up with a new design for handling swipe
882        // on shutter button and mode options. (More details: b/13751653)
883        mAppRootView.setSwipeEnabled(enabled);
884    }
885
886    public void onDestroy() {
887        ((DisplayManager) mController.getAndroidContext()
888                .getSystemService(Context.DISPLAY_SERVICE))
889                .unregisterDisplayListener(mDisplayListener);
890    }
891
892    /**
893     * Initializes the display listener to listen to display changes such as
894     * 180-degree rotation change, which will not have an onConfigurationChanged
895     * callback.
896     */
897    private void initDisplayListener() {
898        if (ApiHelper.HAS_DISPLAY_LISTENER) {
899            mLastRotation = CameraUtil.getDisplayRotation(mController.getAndroidContext());
900
901            mDisplayListener = new DisplayManager.DisplayListener() {
902                @Override
903                public void onDisplayAdded(int arg0) {
904                    // Do nothing.
905                }
906
907                @Override
908                public void onDisplayChanged(int displayId) {
909                    int rotation = CameraUtil.getDisplayRotation(
910                            mController.getAndroidContext());
911                    if ((rotation - mLastRotation + 360) % 360 == 180
912                            && mPreviewStatusListener != null) {
913                        mPreviewStatusListener.onPreviewFlipped();
914                        mIndicatorBottomBarWrapper.requestLayout();
915                        mModeListView.requestLayout();
916                        mTextureView.requestLayout();
917                    }
918                    mLastRotation = rotation;
919                }
920
921                @Override
922                public void onDisplayRemoved(int arg0) {
923                    // Do nothing.
924                }
925            };
926
927            ((DisplayManager) mController.getAndroidContext()
928                    .getSystemService(Context.DISPLAY_SERVICE))
929                    .registerDisplayListener(mDisplayListener, null);
930        }
931    }
932
933    /**
934     * Redirects touch events to appropriate recipient views based on swipe direction.
935     * More specifically, swipe up and swipe down will be handled by the view that handles
936     * mode transition; swipe left will be send to filmstrip; swipe right will be redirected
937     * to mode list in order to bring up mode list.
938     */
939    private void onSwipeDetected(int swipeState) {
940        if (swipeState == SWIPE_UP || swipeState == SWIPE_DOWN) {
941            // TODO: Polish quick switch after this release.
942            // Quick switch between modes.
943            int currentModuleIndex = mController.getCurrentModuleIndex();
944            final int moduleToTransitionTo =
945                    mController.getQuickSwitchToModuleId(currentModuleIndex);
946            if (currentModuleIndex != moduleToTransitionTo) {
947                mAppRootView.redirectTouchEventsTo(mModeTransitionView);
948
949                int shadeColorId = R.color.mode_cover_default_color;
950                int iconRes = CameraUtil.getCameraModeCoverIconResId(moduleToTransitionTo,
951                        mController.getAndroidContext());
952
953                AnimationFinishedListener listener = new AnimationFinishedListener() {
954                    @Override
955                    public void onAnimationFinished(boolean success) {
956                        if (success) {
957                            mHideCoverRunnable = new Runnable() {
958                                @Override
959                                public void run() {
960                                    mModeTransitionView.startPeepHoleAnimation();
961                                }
962                            };
963                            mModeCoverState = COVER_SHOWN;
964                            // Go to new module when the previous operation is successful.
965                            mController.onModeSelected(moduleToTransitionTo);
966                        }
967                    }
968                };
969                if (mSwipeState == SWIPE_UP) {
970                    mModeTransitionView.prepareToPullUpShade(shadeColorId, iconRes, listener);
971                } else {
972                    mModeTransitionView.prepareToPullDownShade(shadeColorId, iconRes, listener);
973                }
974            }
975        } else if (swipeState == SWIPE_LEFT) {
976            // Pass the touch sequence to filmstrip layout.
977            mAppRootView.redirectTouchEventsTo(mFilmstripLayout);
978        } else if (swipeState == SWIPE_RIGHT) {
979            // Pass the touch to mode switcher
980            mAppRootView.redirectTouchEventsTo(mModeListView);
981        }
982    }
983
984    /**
985     * Gets called when activity resumes in preview.
986     */
987    public void resume() {
988        // Show mode theme cover until preview is ready
989        showModeCoverUntilPreviewReady();
990
991        // Hide action bar first since we are in full screen mode first, and
992        // switch the system UI to lights-out mode.
993        mFilmstripPanel.hide();
994
995        // Show UI that is meant to only be used when spoken feedback is
996        // enabled.
997        mAccessibilityEnabled = isSpokenFeedbackAccessibilityEnabled();
998        mAccessibilityAffordances.setVisibility(mAccessibilityEnabled ? View.VISIBLE : View.GONE);
999    }
1000
1001    /**
1002     * @return Whether any spoken feedback accessibility feature is currently
1003     *         enabled.
1004     */
1005    private boolean isSpokenFeedbackAccessibilityEnabled() {
1006        AccessibilityManager accessibilityManager = (AccessibilityManager) mController
1007                .getAndroidContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
1008        List<AccessibilityServiceInfo> infos = accessibilityManager
1009                .getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_SPOKEN);
1010        return infos != null && !infos.isEmpty();
1011    }
1012
1013    /**
1014     * Opens the mode list (e.g. because of the menu button being pressed) and
1015     * adapts the rest of the UI.
1016     */
1017    public void openModeList() {
1018        mModeOptionsOverlay.closeModeOptions();
1019        mModeListView.onMenuPressed();
1020    }
1021
1022    /**
1023     * A cover view showing the mode theme color and mode icon will be visible on
1024     * top of preview until preview is ready (i.e. camera preview is started and
1025     * the first frame has been received).
1026     */
1027    private void showModeCoverUntilPreviewReady() {
1028        int modeId = mController.getCurrentModuleIndex();
1029        int colorId = R.color.mode_cover_default_color;;
1030        int iconId = CameraUtil.getCameraModeCoverIconResId(modeId, mController.getAndroidContext());
1031        mModeTransitionView.setupModeCover(colorId, iconId);
1032        mHideCoverRunnable = new Runnable() {
1033            @Override
1034            public void run() {
1035                mModeTransitionView.hideModeCover(null);
1036                showShimmyDelayed();
1037            }
1038        };
1039        mModeCoverState = COVER_SHOWN;
1040    }
1041
1042    private void showShimmyDelayed() {
1043        if (!mIsCaptureIntent) {
1044            // Show shimmy in SHIMMY_DELAY_MS
1045            mModeListView.showModeSwitcherHint();
1046        }
1047    }
1048
1049    private void hideModeCover() {
1050        if (mHideCoverRunnable != null) {
1051            mAppRootView.post(mHideCoverRunnable);
1052            mHideCoverRunnable = null;
1053        }
1054        mModeCoverState = COVER_HIDDEN;
1055        if (mCoverHiddenTime < 0) {
1056            mCoverHiddenTime = System.currentTimeMillis();
1057        }
1058    }
1059
1060
1061    public void onPreviewVisiblityChanged(int visibility) {
1062        if (visibility == ModuleController.VISIBILITY_HIDDEN) {
1063            setIndicatorBottomBarWrapperVisible(false);
1064            mAccessibilityAffordances.setVisibility(View.GONE);
1065        } else {
1066            setIndicatorBottomBarWrapperVisible(true);
1067            if (mAccessibilityEnabled) {
1068                mAccessibilityAffordances.setVisibility(View.VISIBLE);
1069            } else {
1070                mAccessibilityAffordances.setVisibility(View.GONE);
1071            }
1072        }
1073    }
1074
1075    /**
1076     * Call to stop the preview from being rendered.
1077     */
1078    public void pausePreviewRendering() {
1079        mTextureView.setVisibility(View.INVISIBLE);
1080    }
1081
1082    /**
1083     * Call to begin rendering the preview again.
1084     */
1085    public void resumePreviewRendering() {
1086        mTextureView.setVisibility(View.VISIBLE);
1087    }
1088
1089    /**
1090     * Returns the transform associated with the preview view.
1091     *
1092     * @param m the Matrix in which to copy the current transform.
1093     * @return The specified matrix if not null or a new Matrix instance
1094     *         otherwise.
1095     */
1096    public Matrix getPreviewTransform(Matrix m) {
1097        return mTextureView.getTransform(m);
1098    }
1099
1100    @Override
1101    public void onOpenFullScreen() {
1102        // Do nothing.
1103    }
1104
1105    @Override
1106    public void onModeListOpenProgress(float progress) {
1107        progress = 1 - progress;
1108        float interpolatedProgress = Gusterpolator.INSTANCE.getInterpolation(progress);
1109        mModeOptionsToggle.setAlpha(interpolatedProgress);
1110        // Change shutter button alpha linearly based on the mode list open progress:
1111        // set the alpha to disabled alpha when list is fully open, to enabled alpha
1112        // when the list is fully closed.
1113        mShutterButton.setAlpha(progress * ShutterButton.ALPHA_WHEN_ENABLED
1114                + (1 - progress) * ShutterButton.ALPHA_WHEN_DISABLED);
1115    }
1116
1117    @Override
1118    public void onModeListClosed() {
1119        // Make sure the alpha on mode options ellipse is reset when mode drawer
1120        // is closed.
1121        mModeOptionsToggle.setAlpha(1f);
1122        mShutterButton.setAlpha(ShutterButton.ALPHA_WHEN_ENABLED);
1123    }
1124
1125    /**
1126     * Called when the back key is pressed.
1127     *
1128     * @return Whether the UI responded to the key event.
1129     */
1130    public boolean onBackPressed() {
1131        if (mFilmstripLayout.getVisibility() == View.VISIBLE) {
1132            return mFilmstripLayout.onBackPressed();
1133        } else {
1134            return mModeListView.onBackPressed();
1135        }
1136    }
1137
1138    /**
1139     * Sets a {@link com.android.camera.ui.PreviewStatusListener} that
1140     * listens to SurfaceTexture changes. In addition, listeners are set on
1141     * dependent app ui elements.
1142     *
1143     * @param previewStatusListener the listener that gets notified when SurfaceTexture
1144     *                              changes
1145     */
1146    public void setPreviewStatusListener(PreviewStatusListener previewStatusListener) {
1147        mPreviewStatusListener = previewStatusListener;
1148        if (mPreviewStatusListener != null) {
1149            onPreviewListenerChanged();
1150        }
1151    }
1152
1153    /**
1154     * When the PreviewStatusListener changes, listeners need to be
1155     * set on the following app ui elements:
1156     * {@link com.android.camera.ui.PreviewOverlay},
1157     * {@link com.android.camera.ui.BottomBar},
1158     * {@link com.android.camera.ui.IndicatorIconController}.
1159     */
1160    private void onPreviewListenerChanged() {
1161        // Set a listener for recognizing preview gestures.
1162        GestureDetector.OnGestureListener gestureListener
1163            = mPreviewStatusListener.getGestureListener();
1164        if (gestureListener != null) {
1165            mPreviewOverlay.setGestureListener(gestureListener);
1166        }
1167        View.OnTouchListener touchListener = mPreviewStatusListener.getTouchListener();
1168        if (touchListener != null) {
1169            mPreviewOverlay.setTouchListener(touchListener);
1170        }
1171
1172        mTextureViewHelper.setAutoAdjustTransform(
1173                mPreviewStatusListener.shouldAutoAdjustTransformMatrixOnLayout());
1174    }
1175
1176    /**
1177     * This method should be called in onCameraOpened.  It defines CameraAppUI
1178     * specific changes that depend on the camera or camera settings.
1179     */
1180    public void onChangeCamera() {
1181        ModuleController moduleController = mController.getCurrentModuleController();
1182        applyModuleSpecs(moduleController.getHardwareSpec(), moduleController.getBottomBarSpec());
1183
1184        if (mIndicatorIconController != null) {
1185            // Sync the settings state with the indicator state.
1186            mIndicatorIconController.syncIndicators();
1187        }
1188    }
1189
1190    /**
1191     * Adds a listener to receive callbacks when preview area changes.
1192     */
1193    public void addPreviewAreaChangedListener(
1194            PreviewStatusListener.PreviewAreaChangedListener listener) {
1195        mTextureViewHelper.addPreviewAreaSizeChangedListener(listener);
1196    }
1197
1198    /**
1199     * Removes a listener that receives callbacks when preview area changes.
1200     */
1201    public void removePreviewAreaChangedListener(
1202            PreviewStatusListener.PreviewAreaChangedListener listener) {
1203        mTextureViewHelper.removePreviewAreaSizeChangedListener(listener);
1204    }
1205
1206    /**
1207     * This inflates generic_module layout, which contains all the shared views across
1208     * modules. Then each module inflates their own views in the given view group. For
1209     * now, this is called every time switching from a not-yet-refactored module to a
1210     * refactored module. In the future, this should only need to be done once per app
1211     * start.
1212     */
1213    public void prepareModuleUI() {
1214        mController.getSettingsManager().addListener(this);
1215        mModuleUI = (FrameLayout) mCameraRootView.findViewById(R.id.module_layout);
1216        mTextureView = (TextureView) mCameraRootView.findViewById(R.id.preview_content);
1217        mTextureViewHelper = new TextureViewHelper(mTextureView, mCaptureLayoutHelper,
1218                mController.getCameraProvider());
1219        mTextureViewHelper.setSurfaceTextureListener(this);
1220        mTextureViewHelper.setOnLayoutChangeListener(mPreviewLayoutChangeListener);
1221
1222        mBottomBar = (BottomBar) mCameraRootView.findViewById(R.id.bottom_bar);
1223        int unpressedColor = mController.getAndroidContext().getResources()
1224            .getColor(R.color.bottombar_unpressed);
1225        setBottomBarColor(unpressedColor);
1226        updateModeSpecificUIColors();
1227
1228        mBottomBar.setCaptureLayoutHelper(mCaptureLayoutHelper);
1229
1230        mModeOptionsOverlay
1231            = (ModeOptionsOverlay) mCameraRootView.findViewById(R.id.mode_options_overlay);
1232
1233        // Sets the visibility of the bottom bar and the mode options.
1234        resetBottomControls(mController.getCurrentModuleController(),
1235            mController.getCurrentModuleIndex());
1236        mModeOptionsOverlay.setCaptureLayoutHelper(mCaptureLayoutHelper);
1237
1238        mShutterButton = (ShutterButton) mCameraRootView.findViewById(R.id.shutter_button);
1239        addShutterListener(mController.getCurrentModuleController());
1240        addShutterListener(mModeOptionsOverlay);
1241        addShutterListener(this);
1242
1243        mLetterBoxer1 = mCameraRootView.findViewById(R.id.leftLetterBoxer1);
1244        mLetterBoxer2 = mCameraRootView.findViewById(R.id.leftLetterBoxer2);
1245
1246        mGridLines = (GridLines) mCameraRootView.findViewById(R.id.grid_lines);
1247        mTextureViewHelper.addPreviewAreaSizeChangedListener(mGridLines);
1248
1249        mPreviewOverlay = (PreviewOverlay) mCameraRootView.findViewById(R.id.preview_overlay);
1250        mPreviewOverlay.setOnTouchListener(new MyTouchListener());
1251        mPreviewOverlay.setOnPreviewTouchedListener(mModeOptionsOverlay);
1252
1253        mCaptureOverlay = (CaptureAnimationOverlay)
1254                mCameraRootView.findViewById(R.id.capture_overlay);
1255        mTextureViewHelper.addPreviewAreaSizeChangedListener(mPreviewOverlay);
1256        mTextureViewHelper.addPreviewAreaSizeChangedListener(mCaptureOverlay);
1257
1258        if (mIndicatorIconController == null) {
1259            mIndicatorIconController =
1260                new IndicatorIconController(mController, mAppRootView);
1261        }
1262
1263        mController.getButtonManager().load(mCameraRootView);
1264        mController.getButtonManager().setListener(mIndicatorIconController);
1265        mController.getSettingsManager().addListener(mIndicatorIconController);
1266
1267        mModeOptionsToggle = mCameraRootView.findViewById(R.id.mode_options_toggle);
1268        mFocusOverlay = mCameraRootView.findViewById(R.id.focus_overlay);
1269        mTutorialsPlaceHolderWrapper = (FrameLayout) mCameraRootView
1270                .findViewById(R.id.tutorials_placeholder_wrapper);
1271        mIndicatorBottomBarWrapper = (BottomBarModeOptionsWrapper) mAppRootView
1272                .findViewById(R.id.indicator_bottombar_wrapper);
1273        mIndicatorBottomBarWrapper.setCaptureLayoutHelper(mCaptureLayoutHelper);
1274        mTextureViewHelper.addPreviewAreaSizeChangedListener(
1275                new PreviewStatusListener.PreviewAreaChangedListener() {
1276                    @Override
1277                    public void onPreviewAreaChanged(RectF previewArea) {
1278                        mPeekView.setTranslationX(previewArea.right - mAppRootView.getRight());
1279                    }
1280                });
1281
1282        mTextureViewHelper.addPreviewAreaSizeChangedListener(mModeListView);
1283        mTextureViewHelper.addAspectRatioChangedListener(
1284                new PreviewStatusListener.PreviewAspectRatioChangedListener() {
1285                    @Override
1286                    public void onPreviewAspectRatioChanged(float aspectRatio) {
1287                        mModeOptionsOverlay.requestLayout();
1288                        mBottomBar.requestLayout();
1289                    }
1290                }
1291        );
1292    }
1293
1294    /**
1295     * Called indirectly from each module in their initialization to get a view group
1296     * to inflate the module specific views in.
1297     *
1298     * @return a view group for modules to attach views to
1299     */
1300    public FrameLayout getModuleRootView() {
1301        // TODO: Change it to mModuleUI when refactor is done
1302        return mCameraRootView;
1303    }
1304
1305    /**
1306     * Remove all the module specific views.
1307     */
1308    public void clearModuleUI() {
1309        if (mModuleUI != null) {
1310            mModuleUI.removeAllViews();
1311        }
1312        removeShutterListener(mController.getCurrentModuleController());
1313        mTutorialsPlaceHolderWrapper.removeAllViews();
1314        mTutorialsPlaceHolderWrapper.setVisibility(View.GONE);
1315
1316        setShutterButtonEnabled(true);
1317        mPreviewStatusListener = null;
1318        mPreviewOverlay.reset();
1319        mFocusOverlay.setVisibility(View.INVISIBLE);
1320    }
1321
1322    /**
1323     * Gets called when preview is ready to start. It sets up one shot preview callback
1324     * in order to receive a callback when the preview frame is available, so that
1325     * the preview cover can be hidden to reveal preview.
1326     *
1327     * An alternative for getting the timing to hide preview cover is through
1328     * {@link CameraAppUI#onSurfaceTextureUpdated(android.graphics.SurfaceTexture)},
1329     * which is less accurate but therefore is the fallback for modules that manage
1330     * their own preview callbacks (as setting one preview callback will override
1331     * any other installed preview callbacks), or use camera2 API.
1332     */
1333    public void onPreviewReadyToStart() {
1334        if (mModeCoverState == COVER_SHOWN) {
1335            mModeCoverState = COVER_WILL_HIDE_AT_NEXT_FRAME;
1336            mController.setupOneShotPreviewListener();
1337        }
1338    }
1339
1340    /**
1341     * Gets called when preview is started.
1342     */
1343    public void onPreviewStarted() {
1344        Log.v(TAG, "onPreviewStarted");
1345        if (mModeCoverState == COVER_SHOWN) {
1346            mModeCoverState = COVER_WILL_HIDE_AT_NEXT_TEXTURE_UPDATE;
1347        }
1348        enableModeOptions();
1349    }
1350
1351    /**
1352     * Gets notified when next preview frame comes in.
1353     */
1354    public void onNewPreviewFrame() {
1355        Log.v(TAG, "onNewPreviewFrame");
1356        CameraPerformanceTracker.onEvent(CameraPerformanceTracker.FIRST_PREVIEW_FRAME);
1357        hideModeCover();
1358        mModeCoverState = COVER_HIDDEN;
1359    }
1360
1361    /**
1362     * Set the mode options toggle clickable.
1363     */
1364    public void enableModeOptions() {
1365        /*
1366         * For modules using camera 1 api, this gets called in
1367         * onSurfaceTextureUpdated whenever the preview gets stopped and
1368         * started after each capture.  This also takes care of the
1369         * case where the mode options might be unclickable when we
1370         * switch modes
1371         *
1372         * For modules using camera 2 api, they're required to call this
1373         * method when a capture is "completed".  Unfortunately this differs
1374         * per module implementation.
1375         */
1376        mModeOptionsOverlay.setToggleClickable(true);
1377    }
1378
1379    @Override
1380    public void onShutterButtonClick() {
1381        /*
1382         * Set the mode options toggle unclickable, generally
1383         * throughout the app, whenever the shutter button is clicked.
1384         *
1385         * This could be done in the OnShutterButtonListener of the
1386         * ModeOptionsOverlay, but since it is very important that we
1387         * can clearly see when the toggle becomes clickable again,
1388         * keep all of that logic at this level.
1389         */
1390        mModeOptionsOverlay.setToggleClickable(false);
1391    }
1392
1393    @Override
1394    public void onShutterCoordinate(TouchCoordinate coord) {
1395        // Do nothing.
1396    }
1397
1398    @Override
1399    public void onShutterButtonFocus(boolean pressed) {
1400        // noop
1401    }
1402
1403    /**
1404     * Gets called when a mode is selected from {@link com.android.camera.ui.ModeListView}
1405     *
1406     * @param modeIndex mode index of the selected mode
1407     */
1408    @Override
1409    public void onModeSelected(int modeIndex) {
1410        mHideCoverRunnable = new Runnable() {
1411            @Override
1412            public void run() {
1413                mModeListView.startModeSelectionAnimation();
1414            }
1415        };
1416        mModeCoverState = COVER_SHOWN;
1417
1418        int lastIndex = mController.getCurrentModuleIndex();
1419        // Actual mode teardown / new mode initialization happens here
1420        mController.onModeSelected(modeIndex);
1421        int currentIndex = mController.getCurrentModuleIndex();
1422
1423        if (lastIndex == currentIndex) {
1424            hideModeCover();
1425        }
1426
1427        updateModeSpecificUIColors();
1428    }
1429
1430    private void updateModeSpecificUIColors() {
1431        // set up UI colors to match the current mode
1432        /*
1433        int colorId = CameraUtil.getCameraThemeColorId(mController.getCurrentModuleIndex(),
1434                mController.getAndroidContext());
1435        int pressedColor = mController.getAndroidContext().getResources().getColor(colorId);
1436        setBottomBarPressedColor(pressedColor);
1437        */
1438        setBottomBarColorsForModeIndex(mController.getCurrentModuleIndex());
1439    }
1440
1441    @Override
1442    public void onSettingsSelected() {
1443        mController.getSettingsManager().set(SettingsManager.SCOPE_GLOBAL,
1444                                             Keys.KEY_SHOULD_SHOW_SETTINGS_BUTTON_CLING, false);
1445        mModeListView.setShouldShowSettingsCling(false);
1446        mController.onSettingsSelected();
1447    }
1448
1449    @Override
1450    public int getCurrentModeIndex() {
1451        return mController.getCurrentModuleIndex();
1452    }
1453
1454    /********************** Capture animation **********************/
1455    /* TODO: This session is subject to UX changes. In addition to the generic
1456       flash animation and post capture animation, consider designating a parameter
1457       for specifying the type of animation, as well as an animation finished listener
1458       so that modules can have more knowledge of the status of the animation. */
1459
1460    /**
1461     * Starts the filmstrip peek animation.
1462     *
1463     * @param bitmap The bitmap to show.
1464     * @param strong Whether the animation shows more portion of the bitmap or
1465     *               not.
1466     * @param accessibilityString An accessibility String to be announced
1467                     during the peek animation.
1468     */
1469    public void startPeekAnimation(Bitmap bitmap, boolean strong, String accessibilityString) {
1470        if (mFilmstripLayout.getVisibility() == View.VISIBLE) {
1471            return;
1472        }
1473        mPeekView.startPeekAnimation(bitmap, strong, accessibilityString);
1474    }
1475
1476    /**
1477     * Starts the pre-capture animation.
1478     *
1479     * @param shortFlash show shortest possible flash instead of regular long version.
1480     */
1481    public void startPreCaptureAnimation(boolean shortFlash) {
1482        mCaptureOverlay.startFlashAnimation(shortFlash);
1483    }
1484
1485    /**
1486     * Cancels the pre-capture animation.
1487     */
1488    public void cancelPreCaptureAnimation() {
1489        mAnimationManager.cancelAnimations();
1490    }
1491
1492    /**
1493     * Cancels the post-capture animation.
1494     */
1495    public void cancelPostCaptureAnimation() {
1496        mAnimationManager.cancelAnimations();
1497    }
1498
1499    public FilmstripContentPanel getFilmstripContentPanel() {
1500        return mFilmstripPanel;
1501    }
1502
1503    /**
1504     * @return The {@link com.android.camera.app.CameraAppUI.BottomPanel} on the
1505     * bottom of the filmstrip.
1506     */
1507    public BottomPanel getFilmstripBottomControls() {
1508        return mFilmstripBottomControls;
1509    }
1510
1511    public void showBottomControls() {
1512        mFilmstripBottomControls.show();
1513    }
1514
1515    public void hideBottomControls() {
1516        mFilmstripBottomControls.hide();
1517    }
1518
1519    /**
1520     * @param listener The listener for bottom controls.
1521     */
1522    public void setFilmstripBottomControlsListener(BottomPanel.Listener listener) {
1523        mFilmstripBottomControls.setListener(listener);
1524    }
1525
1526    /***************************SurfaceTexture Api and Listener*********************************/
1527
1528    /**
1529     * Return the shared surface texture.
1530     */
1531    public SurfaceTexture getSurfaceTexture() {
1532        return mSurface;
1533    }
1534
1535    /**
1536     * Return the shared {@link android.graphics.SurfaceTexture}'s width.
1537     */
1538    public int getSurfaceWidth() {
1539        return mSurfaceWidth;
1540    }
1541
1542    /**
1543     * Return the shared {@link android.graphics.SurfaceTexture}'s height.
1544     */
1545    public int getSurfaceHeight() {
1546        return mSurfaceHeight;
1547    }
1548
1549    @Override
1550    public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
1551        mSurface = surface;
1552        mSurfaceWidth = width;
1553        mSurfaceHeight = height;
1554        Log.v(TAG, "SurfaceTexture is available");
1555        if (mPreviewStatusListener != null) {
1556            mPreviewStatusListener.onSurfaceTextureAvailable(surface, width, height);
1557        }
1558        enableModeOptions();
1559    }
1560
1561    @Override
1562    public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
1563        mSurface = surface;
1564        mSurfaceWidth = width;
1565        mSurfaceHeight = height;
1566        if (mPreviewStatusListener != null) {
1567            mPreviewStatusListener.onSurfaceTextureSizeChanged(surface, width, height);
1568        }
1569    }
1570
1571    @Override
1572    public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
1573        mSurface = null;
1574        Log.v(TAG, "SurfaceTexture is destroyed");
1575        if (mPreviewStatusListener != null) {
1576            return mPreviewStatusListener.onSurfaceTextureDestroyed(surface);
1577        }
1578        return false;
1579    }
1580
1581    @Override
1582    public void onSurfaceTextureUpdated(SurfaceTexture surface) {
1583        mSurface = surface;
1584        if (mModeCoverState == COVER_WILL_HIDE_AT_NEXT_TEXTURE_UPDATE) {
1585            Log.v(TAG, "hiding cover via onSurfaceTextureUpdated");
1586            CameraPerformanceTracker.onEvent(CameraPerformanceTracker.FIRST_PREVIEW_FRAME);
1587            hideModeCover();
1588            mModeCoverState = COVER_HIDDEN;
1589        }
1590        if (mPreviewStatusListener != null) {
1591            mPreviewStatusListener.onSurfaceTextureUpdated(surface);
1592        }
1593    }
1594
1595    /****************************Grid lines api ******************************/
1596
1597    /**
1598     * Show a set of evenly spaced lines over the preview.  The number
1599     * of lines horizontally and vertically is determined by
1600     * {@link com.android.camera.ui.GridLines}.
1601     */
1602    public void showGridLines() {
1603        if (mGridLines != null) {
1604            mGridLines.setVisibility(View.VISIBLE);
1605        }
1606    }
1607
1608    /**
1609     * Hide the set of evenly spaced grid lines overlaying the preview.
1610     */
1611    public void hideGridLines() {
1612        if (mGridLines != null) {
1613            mGridLines.setVisibility(View.INVISIBLE);
1614        }
1615    }
1616
1617    /**
1618     * Return a callback which shows or hide the preview grid lines
1619     * depending on whether the grid lines setting is set on.
1620     */
1621    public ButtonManager.ButtonCallback getGridLinesCallback() {
1622        return new ButtonManager.ButtonCallback() {
1623            @Override
1624            public void onStateChanged(int state) {
1625                if (Keys.areGridLinesOn(mController.getSettingsManager())) {
1626                    showGridLines();
1627                } else {
1628                    hideGridLines();
1629                }
1630            }
1631        };
1632    }
1633
1634    /***************************Mode options api *****************************/
1635
1636    /**
1637     * Set the mode options visible.
1638     */
1639    public void showModeOptions() {
1640        /* Make mode options clickable. */
1641        enableModeOptions();
1642        mModeOptionsOverlay.setVisibility(View.VISIBLE);
1643    }
1644
1645    /**
1646     * Set the mode options invisible.  This is necessary for modes
1647     * that don't show a bottom bar for the capture UI.
1648     */
1649    public void hideModeOptions() {
1650        mModeOptionsOverlay.setVisibility(View.INVISIBLE);
1651    }
1652
1653    /****************************Bottom bar api ******************************/
1654
1655    /**
1656     * Sets up the bottom bar and mode options with the correct
1657     * shutter button and visibility based on the current module.
1658     */
1659    public void resetBottomControls(ModuleController module, int moduleIndex) {
1660        if (areBottomControlsUsed(module)) {
1661            setBottomBarShutterIcon(moduleIndex);
1662            mCaptureLayoutHelper.setShowBottomBar(true);
1663        } else {
1664            mCaptureLayoutHelper.setShowBottomBar(false);
1665        }
1666    }
1667
1668    /**
1669     * Show or hide the mode options and bottom bar, based on
1670     * whether the current module is using the bottom bar.  Returns
1671     * whether the mode options and bottom bar are used.
1672     */
1673    private boolean areBottomControlsUsed(ModuleController module) {
1674        if (module.isUsingBottomBar()) {
1675            showBottomBar();
1676            showModeOptions();
1677            return true;
1678        } else {
1679            hideBottomBar();
1680            hideModeOptions();
1681            return false;
1682        }
1683    }
1684
1685    /**
1686     * Set the bottom bar visible.
1687     */
1688    public void showBottomBar() {
1689        mBottomBar.setVisibility(View.VISIBLE);
1690    }
1691
1692    /**
1693     * Set the bottom bar invisible.
1694     */
1695    public void hideBottomBar() {
1696        mBottomBar.setVisibility(View.INVISIBLE);
1697    }
1698
1699    /**
1700     * Sets the color of the bottom bar.
1701     */
1702    public void setBottomBarColor(int colorId) {
1703        mBottomBar.setBackgroundColor(colorId);
1704    }
1705
1706    /**
1707     * Sets the pressed color of the bottom bar for a camera mode index.
1708     */
1709    public void setBottomBarColorsForModeIndex(int index) {
1710        mBottomBar.setColorsForModeIndex(index);
1711    }
1712
1713    /**
1714     * Sets the shutter button icon on the bottom bar, based on
1715     * the mode index.
1716     */
1717    public void setBottomBarShutterIcon(int modeIndex) {
1718        int shutterIconId = CameraUtil.getCameraShutterIconId(modeIndex,
1719            mController.getAndroidContext());
1720        mBottomBar.setShutterButtonIcon(shutterIconId);
1721    }
1722
1723    public void animateBottomBarToVideoStop(int shutterIconId) {
1724        mBottomBar.animateToVideoStop(shutterIconId);
1725    }
1726
1727    public void animateBottomBarToFullSize(int shutterIconId) {
1728        mBottomBar.animateToFullSize(shutterIconId);
1729    }
1730
1731    public void setShutterButtonEnabled(final boolean enabled) {
1732        mBottomBar.post(new Runnable() {
1733
1734            @Override
1735            public void run() {
1736                mBottomBar.setShutterButtonEnabled(enabled);
1737            }
1738        });
1739    }
1740
1741    public void setShutterButtonImportantToA11y(boolean important) {
1742        mBottomBar.setShutterButtonImportantToA11y(important);
1743    }
1744
1745    public boolean isShutterButtonEnabled() {
1746        return mBottomBar.isShutterButtonEnabled();
1747    }
1748
1749    public void setIndicatorBottomBarWrapperVisible(boolean visible) {
1750        mIndicatorBottomBarWrapper.setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
1751    }
1752
1753    /**
1754     * Set the visibility of the bottom bar.
1755     */
1756    // TODO: needed for when panorama is managed by the generic module ui.
1757    public void setBottomBarVisible(boolean visible) {
1758        mBottomBar.setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
1759    }
1760
1761    /**
1762     * Add a {@link #ShutterButton.OnShutterButtonListener} to the shutter button.
1763     */
1764    public void addShutterListener(ShutterButton.OnShutterButtonListener listener) {
1765        mShutterButton.addOnShutterButtonListener(listener);
1766    }
1767
1768
1769    /**
1770     * This adds letterboxing around the preview, one on each side
1771     *
1772     * @param width the width in pixels of each letterboxing cover
1773     */
1774    public void addLetterboxing(int width) {
1775        FrameLayout.LayoutParams params1 = (FrameLayout.LayoutParams) mLetterBoxer1
1776                .getLayoutParams();
1777        FrameLayout.LayoutParams params2 = (FrameLayout.LayoutParams) mLetterBoxer2
1778                .getLayoutParams();
1779
1780        if (mCameraRootView.getWidth() < mCameraRootView.getHeight()) {
1781            params1.width = width;
1782            params1.height = mCameraRootView.getHeight();
1783            params1.gravity = Gravity.LEFT;
1784            mLetterBoxer1.setVisibility(View.VISIBLE);
1785
1786            params2.width = width;
1787            params2.height = mCameraRootView.getHeight();
1788            params2.gravity = Gravity.RIGHT;
1789            mLetterBoxer2.setVisibility(View.VISIBLE);
1790        } else {
1791            params1.height = width;
1792            params1.width = mCameraRootView.getWidth();
1793            params1.gravity = Gravity.TOP;
1794            mLetterBoxer1.setVisibility(View.VISIBLE);
1795
1796            params2.height = width;
1797            params2.width = mCameraRootView.getWidth();
1798            params2.gravity = Gravity.BOTTOM;
1799            mLetterBoxer2.setVisibility(View.VISIBLE);
1800        }
1801    }
1802
1803    /**
1804     * Remove the letter boxing strips if they happen to be present.
1805     */
1806    public void hideLetterboxing() {
1807        mLetterBoxer1.setVisibility(View.GONE);
1808        mLetterBoxer2.setVisibility(View.GONE);
1809    }
1810
1811    /**
1812     * Remove a {@link #ShutterButton.OnShutterButtonListener} from the shutter button.
1813     */
1814    public void removeShutterListener(ShutterButton.OnShutterButtonListener listener) {
1815        mShutterButton.removeOnShutterButtonListener(listener);
1816    }
1817
1818    /**
1819     * Performs a transition to the capture layout of the bottom bar.
1820     */
1821    public void transitionToCapture() {
1822        ModuleController moduleController = mController.getCurrentModuleController();
1823        applyModuleSpecs(moduleController.getHardwareSpec(),
1824            moduleController.getBottomBarSpec());
1825        mBottomBar.transitionToCapture();
1826    }
1827
1828    /**
1829     * Displays the Cancel button instead of the capture button.
1830     */
1831    public void transitionToCancel() {
1832        ModuleController moduleController = mController.getCurrentModuleController();
1833        applyModuleSpecs(moduleController.getHardwareSpec(),
1834                moduleController.getBottomBarSpec());
1835        mBottomBar.transitionToCancel();
1836    }
1837
1838    /**
1839     * Performs a transition to the global intent layout.
1840     */
1841    public void transitionToIntentCaptureLayout() {
1842        ModuleController moduleController = mController.getCurrentModuleController();
1843        applyModuleSpecs(moduleController.getHardwareSpec(),
1844            moduleController.getBottomBarSpec());
1845        mBottomBar.transitionToIntentCaptureLayout();
1846    }
1847
1848    /**
1849     * Performs a transition to the global intent review layout.
1850     */
1851    public void transitionToIntentReviewLayout() {
1852        ModuleController moduleController = mController.getCurrentModuleController();
1853        applyModuleSpecs(moduleController.getHardwareSpec(),
1854            moduleController.getBottomBarSpec());
1855        mBottomBar.transitionToIntentReviewLayout();
1856    }
1857
1858    /**
1859     * @return whether UI is in intent review mode
1860     */
1861    public boolean isInIntentReview() {
1862        return mBottomBar.isInIntentReview();
1863    }
1864
1865    @Override
1866    public void onSettingChanged(SettingsManager settingsManager, String key) {
1867        // Update the mode options based on the hardware spec,
1868        // when hdr changes to prevent flash from getting out of sync.
1869        if (key.equals(Keys.KEY_CAMERA_HDR)) {
1870            ModuleController moduleController = mController.getCurrentModuleController();
1871            applyModuleSpecs(moduleController.getHardwareSpec(),
1872                             moduleController.getBottomBarSpec());
1873        }
1874    }
1875
1876    /**
1877     * Applies a {@link com.android.camera.CameraAppUI.BottomBarUISpec}
1878     * to the bottom bar mode options based on limitations from a
1879     * {@link com.android.camera.hardware.HardwareSpec}.
1880     *
1881     * Options not supported by the hardware are either hidden
1882     * or disabled, depending on the option.
1883     *
1884     * Otherwise, the option is fully enabled and clickable.
1885     */
1886    public void applyModuleSpecs(final HardwareSpec hardwareSpec,
1887           final BottomBarUISpec bottomBarSpec) {
1888        if (hardwareSpec == null || bottomBarSpec == null) {
1889            return;
1890        }
1891
1892        ButtonManager buttonManager = mController.getButtonManager();
1893        SettingsManager settingsManager = mController.getSettingsManager();
1894
1895        buttonManager.setToInitialState();
1896
1897        /** Standard mode options */
1898        if (hardwareSpec.isFrontCameraSupported()) {
1899            if (bottomBarSpec.enableCamera) {
1900                buttonManager.initializeButton(ButtonManager.BUTTON_CAMERA,
1901                        bottomBarSpec.cameraCallback);
1902            } else {
1903                buttonManager.disableButton(ButtonManager.BUTTON_CAMERA);
1904            }
1905        } else {
1906            // Hide camera icon if front camera not available.
1907            buttonManager.hideButton(ButtonManager.BUTTON_CAMERA);
1908        }
1909
1910        boolean flashBackCamera = mController.getSettingsManager().getBoolean(
1911            SettingsManager.SCOPE_GLOBAL, Keys.KEY_FLASH_SUPPORTED_BACK_CAMERA);
1912        if (bottomBarSpec.hideFlash || !flashBackCamera) {
1913            buttonManager.hideButton(ButtonManager.BUTTON_FLASH);
1914        } else {
1915            if (hardwareSpec.isFlashSupported()) {
1916                if (bottomBarSpec.enableFlash) {
1917                    buttonManager.initializeButton(ButtonManager.BUTTON_FLASH,
1918                        bottomBarSpec.flashCallback);
1919                } else if (bottomBarSpec.enableTorchFlash) {
1920                    buttonManager.initializeButton(ButtonManager.BUTTON_TORCH,
1921                        bottomBarSpec.flashCallback);
1922                } else if (bottomBarSpec.enableHdrPlusFlash) {
1923                    buttonManager.initializeButton(ButtonManager.BUTTON_HDR_PLUS_FLASH,
1924                        bottomBarSpec.flashCallback);
1925                } else {
1926                    buttonManager.disableButton(ButtonManager.BUTTON_FLASH);
1927                }
1928            } else {
1929                // Disable flash icon if not supported by the hardware.
1930                buttonManager.disableButton(ButtonManager.BUTTON_FLASH);
1931            }
1932        }
1933
1934        if (bottomBarSpec.hideHdr || mIsCaptureIntent) {
1935            // Force hide hdr or hdr plus icon.
1936            buttonManager.hideButton(ButtonManager.BUTTON_HDR_PLUS);
1937        } else {
1938            if (hardwareSpec.isHdrPlusSupported()) {
1939                if (bottomBarSpec.enableHdr && Keys.isCameraBackFacing(settingsManager,
1940                                                                       mController.getModuleScope())) {
1941                    buttonManager.initializeButton(ButtonManager.BUTTON_HDR_PLUS,
1942                            bottomBarSpec.hdrCallback);
1943                } else {
1944                    buttonManager.disableButton(ButtonManager.BUTTON_HDR_PLUS);
1945                }
1946            } else if (hardwareSpec.isHdrSupported()) {
1947                if (bottomBarSpec.enableHdr && Keys.isCameraBackFacing(settingsManager,
1948                                                                       mController.getModuleScope())) {
1949                    buttonManager.initializeButton(ButtonManager.BUTTON_HDR,
1950                            bottomBarSpec.hdrCallback);
1951                } else {
1952                    buttonManager.disableButton(ButtonManager.BUTTON_HDR);
1953                }
1954            } else {
1955                // Hide hdr plus or hdr icon if neither are supported.
1956                buttonManager.hideButton(ButtonManager.BUTTON_HDR_PLUS);
1957            }
1958        }
1959
1960        if (bottomBarSpec.hideGridLines) {
1961            // Force hide grid lines icon.
1962            buttonManager.hideButton(ButtonManager.BUTTON_GRID_LINES);
1963            hideGridLines();
1964        } else {
1965            if (bottomBarSpec.enableGridLines) {
1966                buttonManager.initializeButton(ButtonManager.BUTTON_GRID_LINES,
1967                        bottomBarSpec.gridLinesCallback != null ?
1968                                bottomBarSpec.gridLinesCallback : getGridLinesCallback()
1969                );
1970            } else {
1971                buttonManager.disableButton(ButtonManager.BUTTON_GRID_LINES);
1972                hideGridLines();
1973            }
1974        }
1975
1976        if (bottomBarSpec.enableSelfTimer) {
1977            buttonManager.initializeButton(ButtonManager.BUTTON_COUNTDOWN, null);
1978        } else {
1979            if (bottomBarSpec.showSelfTimer) {
1980                buttonManager.disableButton(ButtonManager.BUTTON_COUNTDOWN);
1981            } else {
1982                buttonManager.hideButton(ButtonManager.BUTTON_COUNTDOWN);
1983            }
1984        }
1985
1986        if (bottomBarSpec.enablePanoOrientation
1987                && PhotoSphereHelper.getPanoramaOrientationOptionArrayId() > 0) {
1988            buttonManager.initializePanoOrientationButtons(bottomBarSpec.panoOrientationCallback);
1989        }
1990
1991        boolean enableExposureCompensation = bottomBarSpec.enableExposureCompensation &&
1992            !(bottomBarSpec.minExposureCompensation == 0 && bottomBarSpec.maxExposureCompensation == 0) &&
1993            mController.getSettingsManager().getBoolean(SettingsManager.SCOPE_GLOBAL,
1994                        Keys.KEY_EXPOSURE_COMPENSATION_ENABLED);
1995        if (enableExposureCompensation) {
1996            buttonManager.initializePushButton(ButtonManager.BUTTON_EXPOSURE_COMPENSATION, null);
1997            buttonManager.setExposureCompensationParameters(
1998                bottomBarSpec.minExposureCompensation,
1999                bottomBarSpec.maxExposureCompensation,
2000                bottomBarSpec.exposureCompensationStep);
2001
2002            buttonManager.setExposureCompensationCallback(
2003                    bottomBarSpec.exposureCompensationSetCallback);
2004            buttonManager.updateExposureButtons();
2005        } else {
2006            buttonManager.hideButton(ButtonManager.BUTTON_EXPOSURE_COMPENSATION);
2007            buttonManager.setExposureCompensationCallback(null);
2008        }
2009
2010        /** Intent UI */
2011        if (bottomBarSpec.showCancel) {
2012            buttonManager.initializePushButton(ButtonManager.BUTTON_CANCEL,
2013                    bottomBarSpec.cancelCallback);
2014        }
2015        if (bottomBarSpec.showDone) {
2016            buttonManager.initializePushButton(ButtonManager.BUTTON_DONE,
2017                    bottomBarSpec.doneCallback);
2018        }
2019        if (bottomBarSpec.showRetake) {
2020            buttonManager.initializePushButton(ButtonManager.BUTTON_RETAKE,
2021                    bottomBarSpec.retakeCallback);
2022        }
2023        if (bottomBarSpec.showReview) {
2024            buttonManager.initializePushButton(ButtonManager.BUTTON_REVIEW,
2025                    bottomBarSpec.reviewCallback,
2026                    R.drawable.ic_play);
2027        }
2028    }
2029
2030    /**
2031     * Shows the given tutorial on the screen.
2032     */
2033    public void showTutorial(AbstractTutorialOverlay tutorial, LayoutInflater inflater) {
2034        tutorial.show(mTutorialsPlaceHolderWrapper, inflater);
2035    }
2036
2037    /***************************Filmstrip api *****************************/
2038
2039    public void showFilmstrip() {
2040        mModeListView.onBackPressed();
2041        mFilmstripLayout.showFilmstrip();
2042    }
2043
2044    public void hideFilmstrip() {
2045        mFilmstripLayout.hideFilmstrip();
2046    }
2047}
2048