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 | 6a83d52 | 2013-07-02 12:03:32 -0700 | [diff] [blame] | 19 | import android.app.AlertDialog; |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 20 | import android.graphics.Bitmap; |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 21 | import android.graphics.Matrix; |
| 22 | import android.graphics.SurfaceTexture; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 23 | import android.hardware.Camera; |
| 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; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 30 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 31 | import com.android.camera.FocusOverlayManager.FocusUI; |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 32 | import com.android.camera.app.CameraManager; |
Angus Kong | 2bca210 | 2014-03-11 16:27:30 -0700 | [diff] [blame^] | 33 | import com.android.camera.debug.Log; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 34 | import com.android.camera.ui.FaceView; |
Doris Liu | f9e4f8f | 2013-12-04 18:04:22 -0800 | [diff] [blame] | 35 | import com.android.camera.ui.PreviewOverlay; |
Doris Liu | 06db742 | 2013-12-09 19:36:25 -0800 | [diff] [blame] | 36 | import com.android.camera.ui.PreviewStatusListener; |
Angus Kong | b50b5cb | 2013-08-09 14:55:20 -0700 | [diff] [blame] | 37 | import com.android.camera.util.CameraUtil; |
Sascha Haeberling | 8e963a5 | 2013-08-06 11:43:02 -0700 | [diff] [blame] | 38 | import com.android.camera2.R; |
Angus Kong | b50b5cb | 2013-08-09 14:55:20 -0700 | [diff] [blame] | 39 | |
| 40 | import java.util.List; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 41 | |
Doris Liu | 482de02 | 2013-12-18 19:18:16 -0800 | [diff] [blame] | 42 | public class PhotoUI implements PreviewStatusListener, |
Angus Kong | 9e76552 | 2013-07-31 14:05:20 -0700 | [diff] [blame] | 43 | CameraManager.CameraFaceDetectionCallback { |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 44 | |
Angus Kong | 2bca210 | 2014-03-11 16:27:30 -0700 | [diff] [blame^] | 45 | private static final Log.Tag TAG = new Log.Tag("PhotoUI"); |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 46 | private static final int DOWN_SAMPLE_FACTOR = 4; |
Doris Liu | 70da918 | 2013-12-17 18:41:15 -0800 | [diff] [blame] | 47 | private static final float UNSET = 0f; |
Spike Sprague | 0f3c4b4 | 2013-12-10 19:50:17 -0800 | [diff] [blame] | 48 | |
Doris Liu | f9e4f8f | 2013-12-04 18:04:22 -0800 | [diff] [blame] | 49 | private final PreviewOverlay mPreviewOverlay; |
Doris Liu | 482de02 | 2013-12-18 19:18:16 -0800 | [diff] [blame] | 50 | private final FocusUI mFocusUI; |
Sascha Haeberling | e2914fd | 2014-01-17 19:03:52 -0800 | [diff] [blame] | 51 | private final CameraActivity mActivity; |
| 52 | private final PhotoController mController; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 53 | |
Sascha Haeberling | e2914fd | 2014-01-17 19:03:52 -0800 | [diff] [blame] | 54 | private final View mRootView; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 55 | |
Doris Liu | d27ea7b | 2014-02-25 11:46:11 -0800 | [diff] [blame] | 56 | // TODO: Remove face view logic if UX does not bring it back within a month. |
| 57 | private FaceView mFaceView = null; |
Doris Liu | 36e56fb | 2013-09-11 17:38:08 -0700 | [diff] [blame] | 58 | private DecodeImageForReview mDecodeTaskForReview = null; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 59 | |
| 60 | private int mZoomMax; |
| 61 | private List<Integer> mZoomRatios; |
| 62 | |
| 63 | private int mPreviewWidth = 0; |
| 64 | private int mPreviewHeight = 0; |
Doris Liu | 70da918 | 2013-12-17 18:41:15 -0800 | [diff] [blame] | 65 | private float mAspectRatio = UNSET; |
Marco Nelissen | 0744e4a | 2013-11-22 01:47:37 +0000 | [diff] [blame] | 66 | |
Doris Liu | 06db742 | 2013-12-09 19:36:25 -0800 | [diff] [blame] | 67 | private final GestureDetector.OnGestureListener mPreviewGestureListener |
| 68 | = new GestureDetector.SimpleOnGestureListener() { |
| 69 | @Override |
| 70 | public boolean onSingleTapUp(MotionEvent ev) { |
| 71 | mController.onSingleTapUp(null, (int) ev.getX(), (int) ev.getY()); |
| 72 | return true; |
| 73 | } |
| 74 | }; |
Marco Nelissen | 0744e4a | 2013-11-22 01:47:37 +0000 | [diff] [blame] | 75 | |
Doris Liu | 06db742 | 2013-12-09 19:36:25 -0800 | [diff] [blame] | 76 | @Override |
| 77 | public GestureDetector.OnGestureListener getGestureListener() { |
| 78 | return mPreviewGestureListener; |
| 79 | } |
| 80 | |
Doris Liu | 4a010db | 2013-12-16 18:44:49 -0800 | [diff] [blame] | 81 | @Override |
Erin Dahlgren | d8de077 | 2014-02-03 10:12:27 -0800 | [diff] [blame] | 82 | public View.OnTouchListener getTouchListener() { |
| 83 | return null; |
| 84 | } |
| 85 | |
| 86 | @Override |
Doris Liu | 4a010db | 2013-12-16 18:44:49 -0800 | [diff] [blame] | 87 | public void onPreviewLayoutChanged(View v, int left, int top, int right, |
| 88 | int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { |
| 89 | int width = right - left; |
| 90 | int height = bottom - top; |
| 91 | if (mPreviewWidth != width || mPreviewHeight != height) { |
| 92 | mPreviewWidth = width; |
| 93 | mPreviewHeight = height; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 94 | } |
Doris Liu | 4a010db | 2013-12-16 18:44:49 -0800 | [diff] [blame] | 95 | } |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 96 | |
Doris Liu | 70da918 | 2013-12-17 18:41:15 -0800 | [diff] [blame] | 97 | @Override |
| 98 | public boolean shouldAutoAdjustTransformMatrixOnLayout() { |
| 99 | return true; |
| 100 | } |
| 101 | |
| 102 | @Override |
| 103 | public boolean shouldAutoAdjustBottomBar() { |
| 104 | return true; |
| 105 | } |
| 106 | |
Doris Liu | 11ddd73 | 2014-01-07 10:52:11 -0800 | [diff] [blame] | 107 | @Override |
| 108 | public void onPreviewFlipped() { |
| 109 | mController.updateCameraOrientation(); |
| 110 | } |
| 111 | |
Doris Liu | 36e56fb | 2013-09-11 17:38:08 -0700 | [diff] [blame] | 112 | private class DecodeTask extends AsyncTask<Void, Void, Bitmap> { |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 113 | private final byte [] mData; |
Sascha Haeberling | e2914fd | 2014-01-17 19:03:52 -0800 | [diff] [blame] | 114 | private final int mOrientation; |
| 115 | private final boolean mMirror; |
Doris Liu | c2e9abd | 2013-06-19 14:20:51 -0700 | [diff] [blame] | 116 | |
Doris Liu | 29da2db | 2013-08-28 14:28:45 -0700 | [diff] [blame] | 117 | public DecodeTask(byte[] data, int orientation, boolean mirror) { |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 118 | mData = data; |
Doris Liu | ce2acbc | 2013-08-21 18:45:29 -0700 | [diff] [blame] | 119 | mOrientation = orientation; |
Doris Liu | 29da2db | 2013-08-28 14:28:45 -0700 | [diff] [blame] | 120 | mMirror = mirror; |
Doris Liu | c2e9abd | 2013-06-19 14:20:51 -0700 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | @Override |
Doris Liu | 36e56fb | 2013-09-11 17:38:08 -0700 | [diff] [blame] | 124 | protected Bitmap doInBackground(Void... params) { |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 125 | // Decode image in background. |
Doris Liu | ce2acbc | 2013-08-21 18:45:29 -0700 | [diff] [blame] | 126 | Bitmap bitmap = CameraUtil.downSample(mData, DOWN_SAMPLE_FACTOR); |
Doris Liu | 29da2db | 2013-08-28 14:28:45 -0700 | [diff] [blame] | 127 | if (mOrientation != 0 || mMirror) { |
Doris Liu | ce2acbc | 2013-08-21 18:45:29 -0700 | [diff] [blame] | 128 | Matrix m = new Matrix(); |
Doris Liu | 29da2db | 2013-08-28 14:28:45 -0700 | [diff] [blame] | 129 | if (mMirror) { |
| 130 | // Flip horizontally |
| 131 | m.setScale(-1f, 1f); |
| 132 | } |
Andy Huibers | cec75e4 | 2013-10-29 16:03:58 -0700 | [diff] [blame] | 133 | m.preRotate(mOrientation); |
Doris Liu | ce2acbc | 2013-08-21 18:45:29 -0700 | [diff] [blame] | 134 | return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, |
| 135 | false); |
| 136 | } |
| 137 | return bitmap; |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 138 | } |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 139 | } |
Doris Liu | c2e9abd | 2013-06-19 14:20:51 -0700 | [diff] [blame] | 140 | |
Doris Liu | 36e56fb | 2013-09-11 17:38:08 -0700 | [diff] [blame] | 141 | private class DecodeImageForReview extends DecodeTask { |
| 142 | public DecodeImageForReview(byte[] data, int orientation, boolean mirror) { |
| 143 | super(data, orientation, mirror); |
| 144 | } |
| 145 | |
| 146 | @Override |
| 147 | protected void onPostExecute(Bitmap bitmap) { |
| 148 | if (isCancelled()) { |
| 149 | return; |
| 150 | } |
Doris Liu | 36e56fb | 2013-09-11 17:38:08 -0700 | [diff] [blame] | 151 | mDecodeTaskForReview = null; |
| 152 | } |
| 153 | } |
| 154 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 155 | public PhotoUI(CameraActivity activity, PhotoController controller, View parent) { |
| 156 | mActivity = activity; |
| 157 | mController = controller; |
| 158 | mRootView = parent; |
| 159 | |
Doris Liu | f55f3c4 | 2013-11-20 00:24:46 -0800 | [diff] [blame] | 160 | ViewGroup moduleRoot = (ViewGroup) mRootView.findViewById(R.id.module_layout); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 161 | mActivity.getLayoutInflater().inflate(R.layout.photo_module, |
Sascha Haeberling | e2914fd | 2014-01-17 19:03:52 -0800 | [diff] [blame] | 162 | moduleRoot, true); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 163 | initIndicators(); |
Doris Liu | 482de02 | 2013-12-18 19:18:16 -0800 | [diff] [blame] | 164 | mFocusUI = (FocusUI) mRootView.findViewById(R.id.focus_overlay); |
Doris Liu | f9e4f8f | 2013-12-04 18:04:22 -0800 | [diff] [blame] | 165 | mPreviewOverlay = (PreviewOverlay) mRootView.findViewById(R.id.preview_overlay); |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 166 | } |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 167 | |
Doris Liu | 482de02 | 2013-12-18 19:18:16 -0800 | [diff] [blame] | 168 | public FocusUI getFocusUI() { |
| 169 | return mFocusUI; |
| 170 | } |
| 171 | |
Doris Liu | d053a5b | 2013-10-25 20:20:43 -0700 | [diff] [blame] | 172 | public void updatePreviewAspectRatio(float aspectRatio) { |
| 173 | if (aspectRatio <= 0) { |
| 174 | Log.e(TAG, "Invalid aspect ratio: " + aspectRatio); |
| 175 | return; |
| 176 | } |
| 177 | if (aspectRatio < 1f) { |
| 178 | aspectRatio = 1f / aspectRatio; |
| 179 | } |
| 180 | |
| 181 | if (mAspectRatio != aspectRatio) { |
| 182 | mAspectRatio = aspectRatio; |
| 183 | // Update transform matrix with the new aspect ratio. |
Doris Liu | 70da918 | 2013-12-17 18:41:15 -0800 | [diff] [blame] | 184 | mController.updatePreviewAspectRatio(mAspectRatio); |
Doris Liu | d053a5b | 2013-10-25 20:20:43 -0700 | [diff] [blame] | 185 | } |
| 186 | } |
| 187 | |
Angus Kong | dcccc51 | 2013-08-08 17:06:03 -0700 | [diff] [blame] | 188 | @Override |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 189 | public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { |
Erin Dahlgren | d8de077 | 2014-02-03 10:12:27 -0800 | [diff] [blame] | 190 | mController.onPreviewUIReady(); |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Angus Kong | dcccc51 | 2013-08-08 17:06:03 -0700 | [diff] [blame] | 193 | @Override |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 194 | public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { |
| 195 | // Ignored, Camera does all the work for us |
| 196 | } |
| 197 | |
Angus Kong | dcccc51 | 2013-08-08 17:06:03 -0700 | [diff] [blame] | 198 | @Override |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 199 | public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { |
Erin Dahlgren | d8de077 | 2014-02-03 10:12:27 -0800 | [diff] [blame] | 200 | mController.onPreviewUIDestroyed(); |
| 201 | return true; |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 202 | } |
| 203 | |
ztenghui | 7b265a6 | 2013-09-09 14:58:44 -0700 | [diff] [blame] | 204 | @Override |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 205 | public void onSurfaceTextureUpdated(SurfaceTexture surface) { |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | public View getRootView() { |
| 209 | return mRootView; |
| 210 | } |
| 211 | |
| 212 | private void initIndicators() { |
Marco Nelissen | 0744e4a | 2013-11-22 01:47:37 +0000 | [diff] [blame] | 213 | // TODO init toggle buttons on bottom bar here |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 214 | } |
| 215 | |
Erin Dahlgren | b1641f5 | 2014-01-14 15:58:52 -0800 | [diff] [blame] | 216 | public void onCameraOpened(Camera.Parameters params) { |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 217 | initializeZoom(params); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 218 | } |
| 219 | |
Erin Dahlgren | 0a6a8d8 | 2014-01-09 22:17:38 -0800 | [diff] [blame] | 220 | public void animateCapture(final byte[] jpegData, int orientation, boolean mirror) { |
| 221 | // Decode jpeg byte array and then animate the jpeg |
| 222 | DecodeTask task = new DecodeTask(jpegData, orientation, mirror); |
| 223 | task.execute(); |
Spike Sprague | eb3134f | 2013-12-12 11:14:27 -0800 | [diff] [blame] | 224 | } |
| 225 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 226 | // called from onResume but only the first time |
Kevin Gabayan | ffbc43c | 2013-12-09 11:41:50 -0800 | [diff] [blame] | 227 | public void initializeFirstTime() { |
Marco Nelissen | 0744e4a | 2013-11-22 01:47:37 +0000 | [diff] [blame] | 228 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | // called from onResume every other time |
| 232 | public void initializeSecondTime(Camera.Parameters params) { |
| 233 | initializeZoom(params); |
| 234 | if (mController.isImageCaptureIntent()) { |
| 235 | hidePostCaptureAlert(); |
| 236 | } |
Erin Dahlgren | 357b767 | 2013-11-20 17:38:14 -0800 | [diff] [blame] | 237 | // Removes pie menu. |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 238 | } |
| 239 | |
Doris Liu | 6a83d52 | 2013-07-02 12:03:32 -0700 | [diff] [blame] | 240 | public void showLocationDialog() { |
Erin Dahlgren | 491c628 | 2013-11-25 13:22:07 -0800 | [diff] [blame] | 241 | AlertDialog alert = mActivity.getFirstTimeLocationAlert(); |
| 242 | alert.show(); |
Doris Liu | 6a83d52 | 2013-07-02 12:03:32 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 245 | public void initializeZoom(Camera.Parameters params) { |
Doris Liu | f9e4f8f | 2013-12-04 18:04:22 -0800 | [diff] [blame] | 246 | if ((params == null) || !params.isZoomSupported()) return; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 247 | mZoomMax = params.getMaxZoom(); |
| 248 | mZoomRatios = params.getZoomRatios(); |
| 249 | // Currently we use immediate zoom for fast zooming to get better UX and |
| 250 | // there is no plan to take advantage of the smooth zoom. |
Doris Liu | f9e4f8f | 2013-12-04 18:04:22 -0800 | [diff] [blame] | 251 | // TODO: Need to setup a path to AppUI to do this |
| 252 | mPreviewOverlay.setupZoom(mZoomMax, params.getZoom(), mZoomRatios, new ZoomChangeListener()); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 253 | } |
| 254 | |
Doris Liu | c2e9abd | 2013-06-19 14:20:51 -0700 | [diff] [blame] | 255 | public void animateFlash() { |
Doris Liu | 1dfe782 | 2013-12-12 00:02:08 -0800 | [diff] [blame] | 256 | mController.startPreCaptureAnimation(); |
Doris Liu | c2e9abd | 2013-06-19 14:20:51 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 259 | public boolean onBackPressed() { |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 260 | // In image capture mode, back button should: |
| 261 | // 1) if there is any popup, dismiss them, 2) otherwise, get out of |
| 262 | // image capture |
| 263 | if (mController.isImageCaptureIntent()) { |
Doris Liu | c3679c0 | 2013-08-08 18:08:43 -0700 | [diff] [blame] | 264 | mController.onCaptureCancelled(); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 265 | return true; |
| 266 | } else if (!mController.isCameraIdle()) { |
| 267 | // ignore backs while we're taking a picture |
| 268 | return true; |
| 269 | } else { |
Doris Liu | c3679c0 | 2013-08-08 18:08:43 -0700 | [diff] [blame] | 270 | return false; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 271 | } |
| 272 | } |
| 273 | |
Doris Liu | 36e56fb | 2013-09-11 17:38:08 -0700 | [diff] [blame] | 274 | protected void showCapturedImageForReview(byte[] jpegData, int orientation, boolean mirror) { |
| 275 | mDecodeTaskForReview = new DecodeImageForReview(jpegData, orientation, mirror); |
| 276 | mDecodeTaskForReview.execute(); |
Erin Dahlgren | 4efa8b5 | 2013-12-17 18:31:35 -0800 | [diff] [blame] | 277 | |
Erin Dahlgren | 4efa8b5 | 2013-12-17 18:31:35 -0800 | [diff] [blame] | 278 | mActivity.getCameraAppUI().transitionToIntentReviewLayout(); |
Doris Liu | d31cdfe | 2013-05-14 11:31:19 -0700 | [diff] [blame] | 279 | pauseFaceDetection(); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | protected void hidePostCaptureAlert() { |
Doris Liu | 36e56fb | 2013-09-11 17:38:08 -0700 | [diff] [blame] | 283 | if (mDecodeTaskForReview != null) { |
| 284 | mDecodeTaskForReview.cancel(true); |
| 285 | } |
Doris Liu | d31cdfe | 2013-05-14 11:31:19 -0700 | [diff] [blame] | 286 | resumeFaceDetection(); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | public void setDisplayOrientation(int orientation) { |
| 290 | if (mFaceView != null) { |
| 291 | mFaceView.setDisplayOrientation(orientation); |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | // shutter button handling |
| 296 | |
| 297 | public boolean isShutterPressed() { |
Marco Nelissen | 0744e4a | 2013-11-22 01:47:37 +0000 | [diff] [blame] | 298 | return false; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 299 | } |
| 300 | |
Sascha Haeberling | 8890194 | 2013-08-28 17:49:00 -0700 | [diff] [blame] | 301 | /** |
| 302 | * Enables or disables the shutter button. |
| 303 | */ |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 304 | public void enableShutter(boolean enabled) { |
Marco Nelissen | 0744e4a | 2013-11-22 01:47:37 +0000 | [diff] [blame] | 305 | |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 306 | } |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 307 | |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 308 | public void pressShutterButton() { |
Marco Nelissen | 0744e4a | 2013-11-22 01:47:37 +0000 | [diff] [blame] | 309 | |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 310 | } |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 311 | |
Doris Liu | f9e4f8f | 2013-12-04 18:04:22 -0800 | [diff] [blame] | 312 | private class ZoomChangeListener implements PreviewOverlay.OnZoomChangedListener { |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 313 | @Override |
| 314 | public void onZoomValueChanged(int index) { |
Doris Liu | f9e4f8f | 2013-12-04 18:04:22 -0800 | [diff] [blame] | 315 | mController.onZoomChanged(index); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | @Override |
| 319 | public void onZoomStart() { |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | @Override |
| 323 | public void onZoomEnd() { |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 324 | } |
| 325 | } |
| 326 | |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 327 | public void setSwipingEnabled(boolean enable) { |
| 328 | mActivity.setSwipingEnabled(enable); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 329 | } |
| 330 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 331 | public void onPause() { |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 332 | if (mFaceView != null) mFaceView.clear(); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 333 | } |
| 334 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 335 | public void clearFaces() { |
Marco Nelissen | 0744e4a | 2013-11-22 01:47:37 +0000 | [diff] [blame] | 336 | if (mFaceView != null) { |
| 337 | mFaceView.clear(); |
| 338 | } |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 339 | } |
| 340 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 341 | public void pauseFaceDetection() { |
| 342 | if (mFaceView != null) mFaceView.pause(); |
| 343 | } |
| 344 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 345 | public void resumeFaceDetection() { |
| 346 | if (mFaceView != null) mFaceView.resume(); |
| 347 | } |
| 348 | |
| 349 | public void onStartFaceDetection(int orientation, boolean mirror) { |
Doris Liu | d27ea7b | 2014-02-25 11:46:11 -0800 | [diff] [blame] | 350 | if (mFaceView != null) { |
| 351 | mFaceView.clear(); |
| 352 | mFaceView.setVisibility(View.VISIBLE); |
| 353 | mFaceView.setDisplayOrientation(orientation); |
| 354 | mFaceView.setMirror(mirror); |
| 355 | mFaceView.resume(); |
| 356 | } |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | @Override |
Angus Kong | 9e76552 | 2013-07-31 14:05:20 -0700 | [diff] [blame] | 360 | public void onFaceDetection(Face[] faces, CameraManager.CameraProxy camera) { |
Doris Liu | d27ea7b | 2014-02-25 11:46:11 -0800 | [diff] [blame] | 361 | if (mFaceView != null) { |
| 362 | mFaceView.setFaces(faces); |
| 363 | } |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 364 | } |
| 365 | |
Doris Liu | 5940104 | 2014-01-14 17:51:32 -0800 | [diff] [blame] | 366 | /** |
Angus Kong | 2bacca7 | 2014-03-06 12:57:29 -0800 | [diff] [blame] | 367 | * Returns a {@link com.android.camera.ui.PreviewStatusListener.PreviewAreaChangedListener} |
Doris Liu | 5940104 | 2014-01-14 17:51:32 -0800 | [diff] [blame] | 368 | * that should be registered to listen to preview area change. |
| 369 | */ |
Angus Kong | 2bacca7 | 2014-03-06 12:57:29 -0800 | [diff] [blame] | 370 | public PreviewAreaChangedListener getPreviewAreaSizeChangedListener() { |
Doris Liu | 5940104 | 2014-01-14 17:51:32 -0800 | [diff] [blame] | 371 | return mFaceView; |
| 372 | } |
| 373 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 374 | } |