2 * Copyright (C) 2014 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.camera;
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;
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;
36 * Contains the UI for the CaptureModule.
38 public class CaptureModuleUI implements PreviewStatusListener.PreviewAreaChangedListener {
40 public interface CaptureModuleUIListener {
41 public void onZoomRatioChanged(float zoomRatio);
44 private static final Log.Tag TAG = new Log.Tag("CaptureModuleUI");
46 private final CameraActivity mActivity;
47 private final CaptureModuleUIListener mListener;
48 private final View mRootView;
50 private final PreviewOverlay mPreviewOverlay;
51 private final ProgressOverlay mProgressOverlay;
52 private final TextureView mPreviewView;
54 private final FocusRing mFocusRing;
55 private final CountDownView mCountdownView;
57 private int mPreviewAreaWidth;
58 private int mPreviewAreaHeight;
60 /** Maximum zoom; intialize to 1.0 (disabled) */
61 private float mMaxZoom = 1f;
63 /** Set up listener to receive zoom changes from View and send to module. */
64 private final OnZoomChangedListener mZoomChangedListener = new OnZoomChangedListener() {
66 public void onZoomValueChanged(float ratio) {
67 mListener.onZoomRatioChanged(ratio);
71 public void onZoomStart() {
75 public void onZoomEnd() {
79 public CaptureModuleUI(CameraActivity activity, View parent, CaptureModuleUIListener listener) {
84 ViewGroup moduleRoot = (ViewGroup) mRootView.findViewById(R.id.module_layout);
85 mActivity.getLayoutInflater().inflate(R.layout.capture_module, moduleRoot, true);
87 mPreviewView = (TextureView) mRootView.findViewById(R.id.preview_content);
89 mPreviewOverlay = (PreviewOverlay) mRootView.findViewById(R.id.preview_overlay);
90 mProgressOverlay = (ProgressOverlay) mRootView.findViewById(R.id.progress_overlay);
92 mFocusRing = (FocusRing) mRootView.findViewById(R.id.focus_ring);
93 mCountdownView = (CountDownView) mRootView.findViewById(R.id.count_down_view);
97 * Getter for the width of the visible area of the preview.
99 public int getPreviewAreaWidth() {
100 return mPreviewAreaWidth;
104 * Getter for the height of the visible area of the preview.
106 public int getPreviewAreaHeight() {
107 return mPreviewAreaHeight;
110 public Matrix getPreviewTransform(Matrix m) {
111 return mPreviewView.getTransform(m);
114 public FocusRing getFocusRing() {
118 public void showDebugMessage(String message) {
123 * Starts the countdown timer.
125 * @param sec seconds to countdown
127 public void startCountdown(int sec) {
128 mCountdownView.startCountDown(sec);
132 * Sets a listener that gets notified when the countdown is finished.
134 public void setCountdownFinishedListener(CountDownView.OnCountDownStatusListener listener) {
135 mCountdownView.setCountDownStatusListener(listener);
139 * Returns whether the countdown is on-going.
141 public boolean isCountingDown() {
142 return mCountdownView.isCountingDown();
146 * Cancels the on-going countdown, if any.
148 public void cancelCountDown() {
149 mCountdownView.cancelCountDown();
153 * Sets the progress of the gcam picture taking.
155 * @param percent amount of process done in percent 0-100.
157 public void setPictureTakingProgress(int percent) {
158 mProgressOverlay.setProgress(percent);
161 public Bitmap getBitMapFromPreview() {
162 Matrix m = new Matrix();
163 m = getPreviewTransform(m);
164 Bitmap src = mPreviewView.getBitmap();
165 return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), m, true);
169 * Enables zoom UI, setting maximum zoom.
170 * Called from Module when camera is available.
172 * @param maxZoom maximum zoom value.
174 public void initializeZoom(float maxZoom) {
176 mPreviewOverlay.setupZoom(mMaxZoom, 0, mZoomChangedListener);
180 public void onPreviewAreaChanged(RectF previewArea) {
181 // TODO: mFaceView.onPreviewAreaChanged(previewArea);
182 mCountdownView.onPreviewAreaChanged(previewArea);
183 mProgressOverlay.setBounds(previewArea);