Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 1 | /* |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 2 | * Copyright (C) 2012 The Android Open Source Project |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 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 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 17 | package com.android.camera; |
| 18 | |
Doris Liu | db8f975 | 2014-05-12 15:25:13 -0700 | [diff] [blame] | 19 | import android.app.Dialog; |
| 20 | import android.content.DialogInterface; |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 21 | import android.graphics.Bitmap; |
Doris Liu | 6c75164 | 2014-05-05 18:43:26 -0700 | [diff] [blame] | 22 | import android.graphics.RectF; |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 23 | import android.graphics.SurfaceTexture; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 24 | import android.hardware.Camera.Face; |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 25 | import android.os.AsyncTask; |
Doris Liu | f9e4f8f | 2013-12-04 18:04:22 -0800 | [diff] [blame] | 26 | import android.view.GestureDetector; |
| 27 | import android.view.MotionEvent; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 28 | import android.view.View; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 29 | import android.view.ViewGroup; |
Spike Sprague | b4a2222 | 2014-05-22 14:40:53 -0700 | [diff] [blame] | 30 | import android.widget.FrameLayout; |
| 31 | import android.widget.ImageView; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 32 | |
Senpo Hu | 00a764a | 2015-02-19 16:13:40 -0800 | [diff] [blame] | 33 | import com.android.camera.captureintent.PictureDecoder; |
Andy Huibers | 62b4c3c | 2014-08-25 15:01:25 -0700 | [diff] [blame] | 34 | import com.android.camera.debug.DebugPropertyHelper; |
Angus Kong | 5596b4c | 2014-03-11 16:27:30 -0700 | [diff] [blame] | 35 | import com.android.camera.debug.Log; |
Doris Liu | 6c75164 | 2014-05-05 18:43:26 -0700 | [diff] [blame] | 36 | import com.android.camera.ui.CountDownView; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 37 | import com.android.camera.ui.FaceView; |
Doris Liu | f9e4f8f | 2013-12-04 18:04:22 -0800 | [diff] [blame] | 38 | import com.android.camera.ui.PreviewOverlay; |
Doris Liu | 06db742 | 2013-12-09 19:36:25 -0800 | [diff] [blame] | 39 | import com.android.camera.ui.PreviewStatusListener; |
Paul Rohde | 987ee64 | 2014-12-05 12:17:15 -0800 | [diff] [blame] | 40 | import com.android.camera.ui.focus.FocusRing; |
Sascha Haeberling | 8e963a5 | 2013-08-06 11:43:02 -0700 | [diff] [blame] | 41 | import com.android.camera2.R; |
Sol Boucher | 5a34496 | 2014-06-17 14:05:08 -0700 | [diff] [blame] | 42 | import com.android.ex.camera2.portability.CameraAgent; |
Sascha Haeberling | 4c1bffe | 2014-08-21 10:01:00 -0700 | [diff] [blame] | 43 | import com.android.ex.camera2.portability.CameraCapabilities; |
Sol Boucher | 5a34496 | 2014-06-17 14:05:08 -0700 | [diff] [blame] | 44 | import com.android.ex.camera2.portability.CameraSettings; |
Angus Kong | b50b5cb | 2013-08-09 14:55:20 -0700 | [diff] [blame] | 45 | |
Doris Liu | 482de02 | 2013-12-18 19:18:16 -0800 | [diff] [blame] | 46 | public class PhotoUI implements PreviewStatusListener, |
Sol Boucher | 5a34496 | 2014-06-17 14:05:08 -0700 | [diff] [blame] | 47 | CameraAgent.CameraFaceDetectionCallback, PreviewStatusListener.PreviewAreaChangedListener { |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 48 | |
Angus Kong | 5596b4c | 2014-03-11 16:27:30 -0700 | [diff] [blame] | 49 | private static final Log.Tag TAG = new Log.Tag("PhotoUI"); |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 50 | private static final int DOWN_SAMPLE_FACTOR = 4; |
Doris Liu | 70da918 | 2013-12-17 18:41:15 -0800 | [diff] [blame] | 51 | private static final float UNSET = 0f; |
Spike Sprague | 0f3c4b4 | 2013-12-10 19:50:17 -0800 | [diff] [blame] | 52 | |
Doris Liu | f9e4f8f | 2013-12-04 18:04:22 -0800 | [diff] [blame] | 53 | private final PreviewOverlay mPreviewOverlay; |
Paul Rohde | 987ee64 | 2014-12-05 12:17:15 -0800 | [diff] [blame] | 54 | private final FocusRing mFocusRing; |
Sascha Haeberling | e2914fd | 2014-01-17 19:03:52 -0800 | [diff] [blame] | 55 | private final CameraActivity mActivity; |
| 56 | private final PhotoController mController; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 57 | |
Sascha Haeberling | e2914fd | 2014-01-17 19:03:52 -0800 | [diff] [blame] | 58 | private final View mRootView; |
Doris Liu | db8f975 | 2014-05-12 15:25:13 -0700 | [diff] [blame] | 59 | private Dialog mDialog = null; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 60 | |
Doris Liu | d27ea7b | 2014-02-25 11:46:11 -0800 | [diff] [blame] | 61 | // TODO: Remove face view logic if UX does not bring it back within a month. |
Andy Huibers | 62b4c3c | 2014-08-25 15:01:25 -0700 | [diff] [blame] | 62 | private final FaceView mFaceView; |
Doris Liu | 36e56fb | 2013-09-11 17:38:08 -0700 | [diff] [blame] | 63 | private DecodeImageForReview mDecodeTaskForReview = null; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 64 | |
Sol Boucher | 2192fba | 2014-08-19 17:24:07 -0700 | [diff] [blame] | 65 | private float mZoomMax; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 66 | |
| 67 | private int mPreviewWidth = 0; |
| 68 | private int mPreviewHeight = 0; |
Doris Liu | 70da918 | 2013-12-17 18:41:15 -0800 | [diff] [blame] | 69 | private float mAspectRatio = UNSET; |
Marco Nelissen | 0744e4a | 2013-11-22 01:47:37 +0000 | [diff] [blame] | 70 | |
Spike Sprague | b4a2222 | 2014-05-22 14:40:53 -0700 | [diff] [blame] | 71 | private ImageView mIntentReviewImageView; |
| 72 | |
Doris Liu | 06db742 | 2013-12-09 19:36:25 -0800 | [diff] [blame] | 73 | private final GestureDetector.OnGestureListener mPreviewGestureListener |
| 74 | = new GestureDetector.SimpleOnGestureListener() { |
| 75 | @Override |
| 76 | public boolean onSingleTapUp(MotionEvent ev) { |
| 77 | mController.onSingleTapUp(null, (int) ev.getX(), (int) ev.getY()); |
| 78 | return true; |
| 79 | } |
| 80 | }; |
Doris Liu | db8f975 | 2014-05-12 15:25:13 -0700 | [diff] [blame] | 81 | private final DialogInterface.OnDismissListener mOnDismissListener |
| 82 | = new DialogInterface.OnDismissListener() { |
| 83 | @Override |
| 84 | public void onDismiss(DialogInterface dialog) { |
| 85 | mDialog = null; |
| 86 | } |
| 87 | }; |
Sascha Haeberling | 4c1bffe | 2014-08-21 10:01:00 -0700 | [diff] [blame] | 88 | private final CountDownView mCountdownView; |
Marco Nelissen | 0744e4a | 2013-11-22 01:47:37 +0000 | [diff] [blame] | 89 | |
Doris Liu | 06db742 | 2013-12-09 19:36:25 -0800 | [diff] [blame] | 90 | @Override |
| 91 | public GestureDetector.OnGestureListener getGestureListener() { |
| 92 | return mPreviewGestureListener; |
| 93 | } |
| 94 | |
Doris Liu | 4a010db | 2013-12-16 18:44:49 -0800 | [diff] [blame] | 95 | @Override |
Erin Dahlgren | d8de077 | 2014-02-03 10:12:27 -0800 | [diff] [blame] | 96 | public View.OnTouchListener getTouchListener() { |
| 97 | return null; |
| 98 | } |
| 99 | |
| 100 | @Override |
Doris Liu | 4a010db | 2013-12-16 18:44:49 -0800 | [diff] [blame] | 101 | public void onPreviewLayoutChanged(View v, int left, int top, int right, |
| 102 | int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { |
| 103 | int width = right - left; |
| 104 | int height = bottom - top; |
| 105 | if (mPreviewWidth != width || mPreviewHeight != height) { |
| 106 | mPreviewWidth = width; |
| 107 | mPreviewHeight = height; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 108 | } |
Doris Liu | 4a010db | 2013-12-16 18:44:49 -0800 | [diff] [blame] | 109 | } |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 110 | |
Doris Liu | 70da918 | 2013-12-17 18:41:15 -0800 | [diff] [blame] | 111 | @Override |
| 112 | public boolean shouldAutoAdjustTransformMatrixOnLayout() { |
| 113 | return true; |
| 114 | } |
| 115 | |
| 116 | @Override |
Doris Liu | 11ddd73 | 2014-01-07 10:52:11 -0800 | [diff] [blame] | 117 | public void onPreviewFlipped() { |
| 118 | mController.updateCameraOrientation(); |
| 119 | } |
| 120 | |
Doris Liu | 08b0cdd | 2014-05-13 19:19:55 -0700 | [diff] [blame] | 121 | /** |
Doris Liu | 6c75164 | 2014-05-05 18:43:26 -0700 | [diff] [blame] | 122 | * Starts the countdown timer. |
| 123 | * |
| 124 | * @param sec seconds to countdown |
| 125 | */ |
| 126 | public void startCountdown(int sec) { |
| 127 | mCountdownView.startCountDown(sec); |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Sets a listener that gets notified when the countdown is finished. |
| 132 | */ |
| 133 | public void setCountdownFinishedListener(CountDownView.OnCountDownStatusListener listener) { |
| 134 | mCountdownView.setCountDownStatusListener(listener); |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Returns whether the countdown is on-going. |
| 139 | */ |
| 140 | public boolean isCountingDown() { |
| 141 | return mCountdownView.isCountingDown(); |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Cancels the on-going countdown, if any. |
| 146 | */ |
| 147 | public void cancelCountDown() { |
| 148 | mCountdownView.cancelCountDown(); |
| 149 | } |
| 150 | |
| 151 | @Override |
| 152 | public void onPreviewAreaChanged(RectF previewArea) { |
| 153 | if (mFaceView != null) { |
| 154 | mFaceView.onPreviewAreaChanged(previewArea); |
| 155 | } |
| 156 | mCountdownView.onPreviewAreaChanged(previewArea); |
| 157 | } |
| 158 | |
Doris Liu | 36e56fb | 2013-09-11 17:38:08 -0700 | [diff] [blame] | 159 | private class DecodeTask extends AsyncTask<Void, Void, Bitmap> { |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 160 | private final byte [] mData; |
Sascha Haeberling | e2914fd | 2014-01-17 19:03:52 -0800 | [diff] [blame] | 161 | private final int mOrientation; |
| 162 | private final boolean mMirror; |
Doris Liu | c2e9abd | 2013-06-19 14:20:51 -0700 | [diff] [blame] | 163 | |
Doris Liu | 29da2db | 2013-08-28 14:28:45 -0700 | [diff] [blame] | 164 | public DecodeTask(byte[] data, int orientation, boolean mirror) { |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 165 | mData = data; |
Doris Liu | ce2acbc | 2013-08-21 18:45:29 -0700 | [diff] [blame] | 166 | mOrientation = orientation; |
Doris Liu | 29da2db | 2013-08-28 14:28:45 -0700 | [diff] [blame] | 167 | mMirror = mirror; |
Doris Liu | c2e9abd | 2013-06-19 14:20:51 -0700 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | @Override |
Doris Liu | 36e56fb | 2013-09-11 17:38:08 -0700 | [diff] [blame] | 171 | protected Bitmap doInBackground(Void... params) { |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 172 | // Decode image in background. |
Senpo Hu | 00a764a | 2015-02-19 16:13:40 -0800 | [diff] [blame] | 173 | return PictureDecoder.decode(mData, DOWN_SAMPLE_FACTOR, mOrientation, mMirror); |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 174 | } |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 175 | } |
Doris Liu | c2e9abd | 2013-06-19 14:20:51 -0700 | [diff] [blame] | 176 | |
Doris Liu | 36e56fb | 2013-09-11 17:38:08 -0700 | [diff] [blame] | 177 | private class DecodeImageForReview extends DecodeTask { |
| 178 | public DecodeImageForReview(byte[] data, int orientation, boolean mirror) { |
| 179 | super(data, orientation, mirror); |
| 180 | } |
| 181 | |
| 182 | @Override |
| 183 | protected void onPostExecute(Bitmap bitmap) { |
| 184 | if (isCancelled()) { |
| 185 | return; |
| 186 | } |
Spike Sprague | b4a2222 | 2014-05-22 14:40:53 -0700 | [diff] [blame] | 187 | |
| 188 | mIntentReviewImageView.setImageBitmap(bitmap); |
| 189 | showIntentReviewImageView(); |
| 190 | |
Doris Liu | 36e56fb | 2013-09-11 17:38:08 -0700 | [diff] [blame] | 191 | mDecodeTaskForReview = null; |
| 192 | } |
| 193 | } |
| 194 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 195 | public PhotoUI(CameraActivity activity, PhotoController controller, View parent) { |
| 196 | mActivity = activity; |
| 197 | mController = controller; |
| 198 | mRootView = parent; |
| 199 | |
Doris Liu | f55f3c4 | 2013-11-20 00:24:46 -0800 | [diff] [blame] | 200 | ViewGroup moduleRoot = (ViewGroup) mRootView.findViewById(R.id.module_layout); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 201 | mActivity.getLayoutInflater().inflate(R.layout.photo_module, |
Sascha Haeberling | e2914fd | 2014-01-17 19:03:52 -0800 | [diff] [blame] | 202 | moduleRoot, true); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 203 | initIndicators(); |
Paul Rohde | 987ee64 | 2014-12-05 12:17:15 -0800 | [diff] [blame] | 204 | mFocusRing = (FocusRing) mRootView.findViewById(R.id.focus_ring); |
Doris Liu | f9e4f8f | 2013-12-04 18:04:22 -0800 | [diff] [blame] | 205 | mPreviewOverlay = (PreviewOverlay) mRootView.findViewById(R.id.preview_overlay); |
Doris Liu | 6c75164 | 2014-05-05 18:43:26 -0700 | [diff] [blame] | 206 | mCountdownView = (CountDownView) mRootView.findViewById(R.id.count_down_view); |
Andy Huibers | 62b4c3c | 2014-08-25 15:01:25 -0700 | [diff] [blame] | 207 | // Show faces if we are in debug mode. |
| 208 | if (DebugPropertyHelper.showCaptureDebugUI()) { |
| 209 | mFaceView = (FaceView) mRootView.findViewById(R.id.face_view); |
| 210 | } else { |
| 211 | mFaceView = null; |
| 212 | } |
Spike Sprague | b4a2222 | 2014-05-22 14:40:53 -0700 | [diff] [blame] | 213 | |
| 214 | if (mController.isImageCaptureIntent()) { |
Spike Sprague | 02b9b9a | 2014-07-02 11:26:28 -0700 | [diff] [blame] | 215 | initIntentReviewImageView(); |
Spike Sprague | b4a2222 | 2014-05-22 14:40:53 -0700 | [diff] [blame] | 216 | } |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 217 | } |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 218 | |
Spike Sprague | 02b9b9a | 2014-07-02 11:26:28 -0700 | [diff] [blame] | 219 | private void initIntentReviewImageView() { |
| 220 | mIntentReviewImageView = (ImageView) mRootView.findViewById(R.id.intent_review_imageview); |
Spike Sprague | b4a2222 | 2014-05-22 14:40:53 -0700 | [diff] [blame] | 221 | mActivity.getCameraAppUI().addPreviewAreaChangedListener( |
| 222 | new PreviewStatusListener.PreviewAreaChangedListener() { |
| 223 | @Override |
| 224 | public void onPreviewAreaChanged(RectF previewArea) { |
| 225 | FrameLayout.LayoutParams params = |
| 226 | (FrameLayout.LayoutParams) mIntentReviewImageView.getLayoutParams(); |
| 227 | params.width = (int) previewArea.width(); |
| 228 | params.height = (int) previewArea.height(); |
| 229 | params.setMargins((int) previewArea.left, (int) previewArea.top, 0, 0); |
| 230 | mIntentReviewImageView.setLayoutParams(params); |
| 231 | } |
| 232 | }); |
| 233 | } |
| 234 | |
| 235 | /** |
| 236 | * Show the image review over the live preview for intent captures. |
| 237 | */ |
| 238 | public void showIntentReviewImageView() { |
| 239 | if (mIntentReviewImageView != null) { |
| 240 | mIntentReviewImageView.setVisibility(View.VISIBLE); |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * Hide the image review over the live preview for intent captures. |
| 246 | */ |
| 247 | public void hideIntentReviewImageView() { |
| 248 | if (mIntentReviewImageView != null) { |
| 249 | mIntentReviewImageView.setVisibility(View.INVISIBLE); |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | |
Paul Rohde | 987ee64 | 2014-12-05 12:17:15 -0800 | [diff] [blame] | 254 | public FocusRing getFocusRing() { |
| 255 | return mFocusRing; |
Doris Liu | 482de02 | 2013-12-18 19:18:16 -0800 | [diff] [blame] | 256 | } |
| 257 | |
Doris Liu | d053a5b | 2013-10-25 20:20:43 -0700 | [diff] [blame] | 258 | public void updatePreviewAspectRatio(float aspectRatio) { |
| 259 | if (aspectRatio <= 0) { |
| 260 | Log.e(TAG, "Invalid aspect ratio: " + aspectRatio); |
| 261 | return; |
| 262 | } |
| 263 | if (aspectRatio < 1f) { |
| 264 | aspectRatio = 1f / aspectRatio; |
| 265 | } |
| 266 | |
| 267 | if (mAspectRatio != aspectRatio) { |
| 268 | mAspectRatio = aspectRatio; |
| 269 | // Update transform matrix with the new aspect ratio. |
Doris Liu | 70da918 | 2013-12-17 18:41:15 -0800 | [diff] [blame] | 270 | mController.updatePreviewAspectRatio(mAspectRatio); |
Doris Liu | d053a5b | 2013-10-25 20:20:43 -0700 | [diff] [blame] | 271 | } |
| 272 | } |
| 273 | |
Angus Kong | dcccc51 | 2013-08-08 17:06:03 -0700 | [diff] [blame] | 274 | @Override |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 275 | public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { |
Erin Dahlgren | d8de077 | 2014-02-03 10:12:27 -0800 | [diff] [blame] | 276 | mController.onPreviewUIReady(); |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 277 | } |
| 278 | |
Angus Kong | dcccc51 | 2013-08-08 17:06:03 -0700 | [diff] [blame] | 279 | @Override |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 280 | public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { |
| 281 | // Ignored, Camera does all the work for us |
| 282 | } |
| 283 | |
Angus Kong | dcccc51 | 2013-08-08 17:06:03 -0700 | [diff] [blame] | 284 | @Override |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 285 | public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { |
Erin Dahlgren | d8de077 | 2014-02-03 10:12:27 -0800 | [diff] [blame] | 286 | mController.onPreviewUIDestroyed(); |
| 287 | return true; |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 288 | } |
| 289 | |
ztenghui | 7b265a6 | 2013-09-09 14:58:44 -0700 | [diff] [blame] | 290 | @Override |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 291 | public void onSurfaceTextureUpdated(SurfaceTexture surface) { |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | private void initIndicators() { |
Marco Nelissen | 0744e4a | 2013-11-22 01:47:37 +0000 | [diff] [blame] | 295 | // TODO init toggle buttons on bottom bar here |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 296 | } |
| 297 | |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 298 | public void onCameraOpened(CameraCapabilities capabilities, CameraSettings settings) { |
| 299 | initializeZoom(capabilities, settings); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 300 | } |
| 301 | |
Erin Dahlgren | 0a6a8d8 | 2014-01-09 22:17:38 -0800 | [diff] [blame] | 302 | public void animateCapture(final byte[] jpegData, int orientation, boolean mirror) { |
| 303 | // Decode jpeg byte array and then animate the jpeg |
| 304 | DecodeTask task = new DecodeTask(jpegData, orientation, mirror); |
| 305 | task.execute(); |
Spike Sprague | eb3134f | 2013-12-12 11:14:27 -0800 | [diff] [blame] | 306 | } |
| 307 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 308 | // called from onResume but only the first time |
Kevin Gabayan | ffbc43c | 2013-12-09 11:41:50 -0800 | [diff] [blame] | 309 | public void initializeFirstTime() { |
Marco Nelissen | 0744e4a | 2013-11-22 01:47:37 +0000 | [diff] [blame] | 310 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | // called from onResume every other time |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 314 | public void initializeSecondTime(CameraCapabilities capabilities, CameraSettings settings) { |
| 315 | initializeZoom(capabilities, settings); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 316 | if (mController.isImageCaptureIntent()) { |
| 317 | hidePostCaptureAlert(); |
| 318 | } |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 319 | } |
| 320 | |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 321 | public void initializeZoom(CameraCapabilities capabilities, CameraSettings settings) { |
| 322 | if ((capabilities == null) || settings == null || |
| 323 | !capabilities.supports(CameraCapabilities.Feature.ZOOM)) { |
Sascha Haeberling | 1d94364 | 2014-05-19 11:56:53 -0700 | [diff] [blame] | 324 | return; |
| 325 | } |
Sol Boucher | 2192fba | 2014-08-19 17:24:07 -0700 | [diff] [blame] | 326 | mZoomMax = capabilities.getMaxZoomRatio(); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 327 | // Currently we use immediate zoom for fast zooming to get better UX and |
| 328 | // there is no plan to take advantage of the smooth zoom. |
Doris Liu | f9e4f8f | 2013-12-04 18:04:22 -0800 | [diff] [blame] | 329 | // TODO: Need to setup a path to AppUI to do this |
Sol Boucher | 2192fba | 2014-08-19 17:24:07 -0700 | [diff] [blame] | 330 | mPreviewOverlay.setupZoom(mZoomMax, settings.getCurrentZoomRatio(), |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 331 | new ZoomChangeListener()); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 332 | } |
| 333 | |
Doris Liu | c2e9abd | 2013-06-19 14:20:51 -0700 | [diff] [blame] | 334 | public void animateFlash() { |
Doris Liu | 1dfe782 | 2013-12-12 00:02:08 -0800 | [diff] [blame] | 335 | mController.startPreCaptureAnimation(); |
Doris Liu | c2e9abd | 2013-06-19 14:20:51 -0700 | [diff] [blame] | 336 | } |
| 337 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 338 | public boolean onBackPressed() { |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 339 | // In image capture mode, back button should: |
| 340 | // 1) if there is any popup, dismiss them, 2) otherwise, get out of |
| 341 | // image capture |
| 342 | if (mController.isImageCaptureIntent()) { |
Doris Liu | c3679c0 | 2013-08-08 18:08:43 -0700 | [diff] [blame] | 343 | mController.onCaptureCancelled(); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 344 | return true; |
| 345 | } else if (!mController.isCameraIdle()) { |
| 346 | // ignore backs while we're taking a picture |
| 347 | return true; |
| 348 | } else { |
Doris Liu | c3679c0 | 2013-08-08 18:08:43 -0700 | [diff] [blame] | 349 | return false; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 350 | } |
| 351 | } |
| 352 | |
Doris Liu | 36e56fb | 2013-09-11 17:38:08 -0700 | [diff] [blame] | 353 | protected void showCapturedImageForReview(byte[] jpegData, int orientation, boolean mirror) { |
| 354 | mDecodeTaskForReview = new DecodeImageForReview(jpegData, orientation, mirror); |
| 355 | mDecodeTaskForReview.execute(); |
Erin Dahlgren | 4efa8b5 | 2013-12-17 18:31:35 -0800 | [diff] [blame] | 356 | |
Erin Dahlgren | 4efa8b5 | 2013-12-17 18:31:35 -0800 | [diff] [blame] | 357 | mActivity.getCameraAppUI().transitionToIntentReviewLayout(); |
Doris Liu | d31cdfe | 2013-05-14 11:31:19 -0700 | [diff] [blame] | 358 | pauseFaceDetection(); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | protected void hidePostCaptureAlert() { |
Doris Liu | 36e56fb | 2013-09-11 17:38:08 -0700 | [diff] [blame] | 362 | if (mDecodeTaskForReview != null) { |
| 363 | mDecodeTaskForReview.cancel(true); |
| 364 | } |
Doris Liu | d31cdfe | 2013-05-14 11:31:19 -0700 | [diff] [blame] | 365 | resumeFaceDetection(); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | public void setDisplayOrientation(int orientation) { |
| 369 | if (mFaceView != null) { |
| 370 | mFaceView.setDisplayOrientation(orientation); |
| 371 | } |
| 372 | } |
| 373 | |
Doris Liu | f9e4f8f | 2013-12-04 18:04:22 -0800 | [diff] [blame] | 374 | private class ZoomChangeListener implements PreviewOverlay.OnZoomChangedListener { |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 375 | @Override |
Sol Boucher | 2192fba | 2014-08-19 17:24:07 -0700 | [diff] [blame] | 376 | public void onZoomValueChanged(float ratio) { |
| 377 | mController.onZoomChanged(ratio); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | @Override |
| 381 | public void onZoomStart() { |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | @Override |
| 385 | public void onZoomEnd() { |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 386 | } |
| 387 | } |
| 388 | |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 389 | public void setSwipingEnabled(boolean enable) { |
| 390 | mActivity.setSwipingEnabled(enable); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 391 | } |
| 392 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 393 | public void onPause() { |
Sascha Haeberling | 1d94364 | 2014-05-19 11:56:53 -0700 | [diff] [blame] | 394 | if (mFaceView != null) { |
| 395 | mFaceView.clear(); |
| 396 | } |
Doris Liu | db8f975 | 2014-05-12 15:25:13 -0700 | [diff] [blame] | 397 | if (mDialog != null) { |
| 398 | mDialog.dismiss(); |
| 399 | } |
Alan Newberger | 7351415 | 2014-09-10 15:03:27 -0700 | [diff] [blame] | 400 | // recalculate aspect ratio when restarting. |
| 401 | mAspectRatio = 0.0f; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 402 | } |
| 403 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 404 | public void clearFaces() { |
Marco Nelissen | 0744e4a | 2013-11-22 01:47:37 +0000 | [diff] [blame] | 405 | if (mFaceView != null) { |
| 406 | mFaceView.clear(); |
| 407 | } |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 408 | } |
| 409 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 410 | public void pauseFaceDetection() { |
Sascha Haeberling | 1d94364 | 2014-05-19 11:56:53 -0700 | [diff] [blame] | 411 | if (mFaceView != null) { |
| 412 | mFaceView.pause(); |
| 413 | } |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 414 | } |
| 415 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 416 | public void resumeFaceDetection() { |
Sascha Haeberling | 1d94364 | 2014-05-19 11:56:53 -0700 | [diff] [blame] | 417 | if (mFaceView != null) { |
| 418 | mFaceView.resume(); |
| 419 | } |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | public void onStartFaceDetection(int orientation, boolean mirror) { |
Doris Liu | d27ea7b | 2014-02-25 11:46:11 -0800 | [diff] [blame] | 423 | if (mFaceView != null) { |
| 424 | mFaceView.clear(); |
| 425 | mFaceView.setVisibility(View.VISIBLE); |
| 426 | mFaceView.setDisplayOrientation(orientation); |
| 427 | mFaceView.setMirror(mirror); |
| 428 | mFaceView.resume(); |
| 429 | } |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | @Override |
Sol Boucher | 5a34496 | 2014-06-17 14:05:08 -0700 | [diff] [blame] | 433 | public void onFaceDetection(Face[] faces, CameraAgent.CameraProxy camera) { |
Doris Liu | d27ea7b | 2014-02-25 11:46:11 -0800 | [diff] [blame] | 434 | if (mFaceView != null) { |
| 435 | mFaceView.setFaces(faces); |
| 436 | } |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 437 | } |
| 438 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 439 | } |