• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.camera;
18 
19 import android.graphics.Bitmap;
20 import android.graphics.Matrix;
21 import android.graphics.RectF;
22 import android.view.TextureView;
23 import android.view.View;
24 import android.view.ViewGroup;
25 
26 import com.android.camera.debug.Log;
27 import com.android.camera.ui.CountDownView;
28 import com.android.camera.ui.PreviewOverlay;
29 import com.android.camera.ui.PreviewOverlay.OnZoomChangedListener;
30 import com.android.camera.ui.PreviewStatusListener;
31 import com.android.camera.ui.ProgressOverlay;
32 import com.android.camera.ui.focus.FocusRing;
33 import com.android.camera2.R;
34 
35 /**
36  * Contains the UI for the CaptureModule.
37  */
38 public class CaptureModuleUI implements PreviewStatusListener.PreviewAreaChangedListener {
39 
40     public interface CaptureModuleUIListener {
onZoomRatioChanged(float zoomRatio)41         public void onZoomRatioChanged(float zoomRatio);
42     }
43 
44     private static final Log.Tag TAG = new Log.Tag("CaptureModuleUI");
45 
46     private final CameraActivity mActivity;
47     private final CaptureModuleUIListener mListener;
48     private final View mRootView;
49 
50     private final PreviewOverlay mPreviewOverlay;
51     private final ProgressOverlay mProgressOverlay;
52     private final TextureView mPreviewView;
53 
54     private final FocusRing mFocusRing;
55     private final CountDownView mCountdownView;
56 
57     private int mPreviewAreaWidth;
58     private int mPreviewAreaHeight;
59 
60     /** Maximum zoom; intialize to 1.0 (disabled) */
61     private float mMaxZoom = 1f;
62 
63     /** Set up listener to receive zoom changes from View and send to module. */
64     private final OnZoomChangedListener mZoomChangedListener = new OnZoomChangedListener() {
65         @Override
66         public void onZoomValueChanged(float ratio) {
67             mListener.onZoomRatioChanged(ratio);
68         }
69 
70         @Override
71         public void onZoomStart() {
72         }
73 
74         @Override
75         public void onZoomEnd() {
76         }
77     };
78 
CaptureModuleUI(CameraActivity activity, View parent, CaptureModuleUIListener listener)79     public CaptureModuleUI(CameraActivity activity, View parent, CaptureModuleUIListener listener) {
80         mActivity = activity;
81         mListener = listener;
82         mRootView = parent;
83 
84         ViewGroup moduleRoot = (ViewGroup) mRootView.findViewById(R.id.module_layout);
85         mActivity.getLayoutInflater().inflate(R.layout.capture_module, moduleRoot, true);
86 
87         mPreviewView = (TextureView) mRootView.findViewById(R.id.preview_content);
88 
89         mPreviewOverlay = (PreviewOverlay) mRootView.findViewById(R.id.preview_overlay);
90         mProgressOverlay = (ProgressOverlay) mRootView.findViewById(R.id.progress_overlay);
91 
92         mFocusRing = (FocusRing) mRootView.findViewById(R.id.focus_ring);
93         mCountdownView = (CountDownView) mRootView.findViewById(R.id.count_down_view);
94     }
95 
96     /**
97      * Getter for the camera activity this UI is drawn into
98      */
getActivity()99     public CameraActivity getActivity() {
100         return mActivity;
101     }
102 
103     /**
104      * Getter for the width of the visible area of the preview.
105      */
getPreviewAreaWidth()106     public int getPreviewAreaWidth() {
107         return mPreviewAreaWidth;
108     }
109 
110     /**
111      * Getter for the height of the visible area of the preview.
112      */
getPreviewAreaHeight()113     public int getPreviewAreaHeight() {
114         return mPreviewAreaHeight;
115     }
116 
getPreviewTransform(Matrix m)117     public Matrix getPreviewTransform(Matrix m) {
118         return mPreviewView.getTransform(m);
119     }
120 
getFocusRing()121     public FocusRing getFocusRing() {
122         return mFocusRing;
123     }
124 
showDebugMessage(String message)125     public void showDebugMessage(String message) {
126         /* NoOp */
127     }
128 
129     /**
130      * Starts the countdown timer.
131      *
132      * @param sec seconds to countdown
133      */
startCountdown(int sec)134     public void startCountdown(int sec) {
135         mCountdownView.startCountDown(sec);
136     }
137 
138     /**
139      * Sets a listener that gets notified when the countdown is finished.
140      */
setCountdownFinishedListener(CountDownView.OnCountDownStatusListener listener)141     public void setCountdownFinishedListener(CountDownView.OnCountDownStatusListener listener) {
142         mCountdownView.setCountDownStatusListener(listener);
143     }
144 
145     /**
146      * Returns whether the countdown is on-going.
147      */
isCountingDown()148     public boolean isCountingDown() {
149         return mCountdownView.isCountingDown();
150     }
151 
152     /**
153      * Cancels the on-going countdown, if any.
154      */
cancelCountDown()155     public void cancelCountDown() {
156         mCountdownView.cancelCountDown();
157     }
158 
159     /**
160      * Sets the progress of the gcam picture taking.
161      *
162      * @param percent amount of process done in percent 0-100.
163      */
setPictureTakingProgress(int percent)164     public void setPictureTakingProgress(int percent) {
165         mProgressOverlay.setProgress(percent);
166     }
167 
getBitMapFromPreview()168     public Bitmap getBitMapFromPreview() {
169         Matrix m = new Matrix();
170         m = getPreviewTransform(m);
171         Bitmap src = mPreviewView.getBitmap();
172         return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), m, true);
173     }
174 
175     /**
176      * Enables zoom UI, setting maximum zoom.
177      * Called from Module when camera is available.
178      *
179      * @param maxZoom maximum zoom value.
180      */
initializeZoom(float maxZoom)181     public void initializeZoom(float maxZoom) {
182         mMaxZoom = maxZoom;
183         mPreviewOverlay.setupZoom(mMaxZoom, 0, mZoomChangedListener);
184     }
185 
186     @Override
onPreviewAreaChanged(RectF previewArea)187     public void onPreviewAreaChanged(RectF previewArea) {
188         // TODO: mFaceView.onPreviewAreaChanged(previewArea);
189         mCountdownView.onPreviewAreaChanged(previewArea);
190         mProgressOverlay.setBounds(previewArea);
191     }
192 }
193