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 | |
| 17 | |
| 18 | package com.android.camera; |
| 19 | |
Doris Liu | 6a83d52 | 2013-07-02 12:03:32 -0700 | [diff] [blame] | 20 | import android.app.AlertDialog; |
| 21 | import android.content.DialogInterface; |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 22 | import android.graphics.Bitmap; |
Doris Liu | c3679c0 | 2013-08-08 18:08:43 -0700 | [diff] [blame] | 23 | import android.graphics.Color; |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 24 | import android.graphics.Matrix; |
Doris Liu | 36ebcb1 | 2013-10-28 14:44:24 -0700 | [diff] [blame] | 25 | import android.graphics.RectF; |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 26 | import android.graphics.SurfaceTexture; |
Doris Liu | c3679c0 | 2013-08-08 18:08:43 -0700 | [diff] [blame] | 27 | import android.graphics.drawable.ColorDrawable; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 28 | import android.hardware.Camera; |
| 29 | import android.hardware.Camera.Face; |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 30 | import android.os.AsyncTask; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 31 | import android.util.Log; |
| 32 | import android.view.Gravity; |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 33 | import android.view.TextureView; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 34 | import android.view.View; |
| 35 | import android.view.View.OnClickListener; |
| 36 | import android.view.View.OnLayoutChangeListener; |
| 37 | import android.view.ViewGroup; |
| 38 | import android.view.ViewStub; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 39 | import android.widget.FrameLayout.LayoutParams; |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 40 | import android.widget.ImageView; |
Doris Liu | c3679c0 | 2013-08-08 18:08:43 -0700 | [diff] [blame] | 41 | import android.widget.PopupWindow; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 42 | import android.widget.Toast; |
| 43 | |
| 44 | import com.android.camera.CameraPreference.OnPreferenceChangedListener; |
| 45 | import com.android.camera.FocusOverlayManager.FocusUI; |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame^] | 46 | import com.android.camera.app.CameraManager; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 47 | import com.android.camera.ui.AbstractSettingPopup; |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 48 | import com.android.camera.ui.CameraControls; |
Angus Kong | 9e76552 | 2013-07-31 14:05:20 -0700 | [diff] [blame] | 49 | import com.android.camera.ui.CameraRootView; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 50 | import com.android.camera.ui.CountDownView; |
| 51 | import com.android.camera.ui.CountDownView.OnCountDownFinishedListener; |
| 52 | import com.android.camera.ui.FaceView; |
| 53 | import com.android.camera.ui.FocusIndicator; |
| 54 | import com.android.camera.ui.PieRenderer; |
| 55 | import com.android.camera.ui.PieRenderer.PieListener; |
| 56 | import com.android.camera.ui.RenderOverlay; |
| 57 | import com.android.camera.ui.ZoomRenderer; |
Angus Kong | b50b5cb | 2013-08-09 14:55:20 -0700 | [diff] [blame] | 58 | import com.android.camera.util.CameraUtil; |
Sascha Haeberling | 8e963a5 | 2013-08-06 11:43:02 -0700 | [diff] [blame] | 59 | import com.android.camera2.R; |
Angus Kong | b50b5cb | 2013-08-09 14:55:20 -0700 | [diff] [blame] | 60 | |
| 61 | import java.util.List; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 62 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 63 | public class PhotoUI implements PieListener, |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 64 | PreviewGestures.SingleTapListener, |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 65 | FocusUI, TextureView.SurfaceTextureListener, |
| 66 | LocationManager.Listener, CameraRootView.MyDisplayListener, |
Angus Kong | 9e76552 | 2013-07-31 14:05:20 -0700 | [diff] [blame] | 67 | CameraManager.CameraFaceDetectionCallback { |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 68 | |
| 69 | private static final String TAG = "CAM_UI"; |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 70 | private static final int DOWN_SAMPLE_FACTOR = 4; |
| 71 | private final AnimationManager mAnimationManager; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 72 | private CameraActivity mActivity; |
| 73 | private PhotoController mController; |
| 74 | private PreviewGestures mGestures; |
| 75 | |
| 76 | private View mRootView; |
Angus Kong | dcccc51 | 2013-08-08 17:06:03 -0700 | [diff] [blame] | 77 | private SurfaceTexture mSurfaceTexture; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 78 | |
Doris Liu | c3679c0 | 2013-08-08 18:08:43 -0700 | [diff] [blame] | 79 | private PopupWindow mPopup; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 80 | private ShutterButton mShutterButton; |
| 81 | private CountDownView mCountDownView; |
| 82 | |
| 83 | private FaceView mFaceView; |
| 84 | private RenderOverlay mRenderOverlay; |
| 85 | private View mReviewCancelButton; |
| 86 | private View mReviewDoneButton; |
| 87 | private View mReviewRetakeButton; |
Doris Liu | 36e56fb | 2013-09-11 17:38:08 -0700 | [diff] [blame] | 88 | private ImageView mReviewImage; |
| 89 | private DecodeImageForReview mDecodeTaskForReview = null; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 90 | |
| 91 | private View mMenuButton; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 92 | private PhotoMenu mMenu; |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 93 | private CameraControls mCameraControls; |
Doris Liu | 6a83d52 | 2013-07-02 12:03:32 -0700 | [diff] [blame] | 94 | private AlertDialog mLocationDialog; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 95 | |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 96 | // Small indicators which show the camera settings in the viewfinder. |
Sascha Haeberling | c7965e2 | 2013-04-22 14:27:36 -0700 | [diff] [blame] | 97 | private OnScreenIndicators mOnScreenIndicators; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 98 | |
| 99 | private PieRenderer mPieRenderer; |
| 100 | private ZoomRenderer mZoomRenderer; |
| 101 | private Toast mNotSelectableToast; |
| 102 | |
| 103 | private int mZoomMax; |
| 104 | private List<Integer> mZoomRatios; |
| 105 | |
| 106 | private int mPreviewWidth = 0; |
| 107 | private int mPreviewHeight = 0; |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 108 | private float mSurfaceTextureUncroppedWidth; |
| 109 | private float mSurfaceTextureUncroppedHeight; |
| 110 | |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 111 | private ImageView mPreviewThumb; |
Doris Liu | c2e9abd | 2013-06-19 14:20:51 -0700 | [diff] [blame] | 112 | private View mFlashOverlay; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 113 | |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 114 | private SurfaceTextureSizeChangedListener mSurfaceTextureSizeListener; |
| 115 | private TextureView mTextureView; |
| 116 | private Matrix mMatrix = null; |
| 117 | private float mAspectRatio = 4f / 3f; |
Doris Liu | 3a45c33 | 2013-10-15 19:10:28 -0700 | [diff] [blame] | 118 | private View mPreviewCover; |
Erin Dahlgren | b09b53e | 2013-11-06 11:57:51 -0800 | [diff] [blame] | 119 | private final Object mSurfaceTextureLock = new Object(); |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 120 | |
| 121 | public interface SurfaceTextureSizeChangedListener { |
| 122 | public void onSurfaceTextureSizeChanged(int uncroppedWidth, int uncroppedHeight); |
| 123 | } |
| 124 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 125 | private OnLayoutChangeListener mLayoutListener = new OnLayoutChangeListener() { |
| 126 | @Override |
| 127 | public void onLayoutChange(View v, int left, int top, int right, |
| 128 | int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { |
| 129 | int width = right - left; |
| 130 | int height = bottom - top; |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 131 | if (mPreviewWidth != width || mPreviewHeight != height) { |
| 132 | mPreviewWidth = width; |
| 133 | mPreviewHeight = height; |
Doris Liu | 13ca71e | 2013-08-20 11:14:07 -0700 | [diff] [blame] | 134 | setTransformMatrix(width, height); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 135 | } |
| 136 | } |
| 137 | }; |
| 138 | |
Doris Liu | 36e56fb | 2013-09-11 17:38:08 -0700 | [diff] [blame] | 139 | private class DecodeTask extends AsyncTask<Void, Void, Bitmap> { |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 140 | private final byte [] mData; |
Doris Liu | ce2acbc | 2013-08-21 18:45:29 -0700 | [diff] [blame] | 141 | private int mOrientation; |
Doris Liu | 29da2db | 2013-08-28 14:28:45 -0700 | [diff] [blame] | 142 | private boolean mMirror; |
Doris Liu | c2e9abd | 2013-06-19 14:20:51 -0700 | [diff] [blame] | 143 | |
Doris Liu | 29da2db | 2013-08-28 14:28:45 -0700 | [diff] [blame] | 144 | public DecodeTask(byte[] data, int orientation, boolean mirror) { |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 145 | mData = data; |
Doris Liu | ce2acbc | 2013-08-21 18:45:29 -0700 | [diff] [blame] | 146 | mOrientation = orientation; |
Doris Liu | 29da2db | 2013-08-28 14:28:45 -0700 | [diff] [blame] | 147 | mMirror = mirror; |
Doris Liu | c2e9abd | 2013-06-19 14:20:51 -0700 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | @Override |
Doris Liu | 36e56fb | 2013-09-11 17:38:08 -0700 | [diff] [blame] | 151 | protected Bitmap doInBackground(Void... params) { |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 152 | // Decode image in background. |
Doris Liu | ce2acbc | 2013-08-21 18:45:29 -0700 | [diff] [blame] | 153 | Bitmap bitmap = CameraUtil.downSample(mData, DOWN_SAMPLE_FACTOR); |
Doris Liu | 29da2db | 2013-08-28 14:28:45 -0700 | [diff] [blame] | 154 | if (mOrientation != 0 || mMirror) { |
Doris Liu | ce2acbc | 2013-08-21 18:45:29 -0700 | [diff] [blame] | 155 | Matrix m = new Matrix(); |
Doris Liu | 29da2db | 2013-08-28 14:28:45 -0700 | [diff] [blame] | 156 | if (mMirror) { |
| 157 | // Flip horizontally |
| 158 | m.setScale(-1f, 1f); |
| 159 | } |
Andy Huibers | cec75e4 | 2013-10-29 16:03:58 -0700 | [diff] [blame] | 160 | m.preRotate(mOrientation); |
Doris Liu | ce2acbc | 2013-08-21 18:45:29 -0700 | [diff] [blame] | 161 | return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, |
| 162 | false); |
| 163 | } |
| 164 | return bitmap; |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 165 | } |
Doris Liu | c2e9abd | 2013-06-19 14:20:51 -0700 | [diff] [blame] | 166 | |
| 167 | @Override |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 168 | protected void onPostExecute(Bitmap bitmap) { |
| 169 | mPreviewThumb.setImageBitmap(bitmap); |
| 170 | mAnimationManager.startCaptureAnimation(mPreviewThumb); |
| 171 | } |
| 172 | } |
Doris Liu | c2e9abd | 2013-06-19 14:20:51 -0700 | [diff] [blame] | 173 | |
Doris Liu | 36e56fb | 2013-09-11 17:38:08 -0700 | [diff] [blame] | 174 | private class DecodeImageForReview extends DecodeTask { |
| 175 | public DecodeImageForReview(byte[] data, int orientation, boolean mirror) { |
| 176 | super(data, orientation, mirror); |
| 177 | } |
| 178 | |
| 179 | @Override |
| 180 | protected void onPostExecute(Bitmap bitmap) { |
| 181 | if (isCancelled()) { |
| 182 | return; |
| 183 | } |
| 184 | mReviewImage.setImageBitmap(bitmap); |
| 185 | mReviewImage.setVisibility(View.VISIBLE); |
| 186 | mDecodeTaskForReview = null; |
| 187 | } |
| 188 | } |
| 189 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 190 | public PhotoUI(CameraActivity activity, PhotoController controller, View parent) { |
| 191 | mActivity = activity; |
| 192 | mController = controller; |
| 193 | mRootView = parent; |
| 194 | |
| 195 | mActivity.getLayoutInflater().inflate(R.layout.photo_module, |
| 196 | (ViewGroup) mRootView, true); |
| 197 | mRenderOverlay = (RenderOverlay) mRootView.findViewById(R.id.render_overlay); |
Doris Liu | c2e9abd | 2013-06-19 14:20:51 -0700 | [diff] [blame] | 198 | mFlashOverlay = mRootView.findViewById(R.id.flash_overlay); |
Doris Liu | 3a45c33 | 2013-10-15 19:10:28 -0700 | [diff] [blame] | 199 | mPreviewCover = mRootView.findViewById(R.id.preview_cover); |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 200 | // display the view |
| 201 | mTextureView = (TextureView) mRootView.findViewById(R.id.preview_content); |
| 202 | mTextureView.setSurfaceTextureListener(this); |
| 203 | mTextureView.addOnLayoutChangeListener(mLayoutListener); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 204 | initIndicators(); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 205 | |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 206 | mShutterButton = (ShutterButton) mRootView.findViewById(R.id.shutter_button); |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 207 | mMenuButton = mRootView.findViewById(R.id.menu); |
Sascha Haeberling | 638e6f0 | 2013-09-18 14:28:51 -0700 | [diff] [blame] | 208 | ViewStub faceViewStub = (ViewStub) mRootView |
| 209 | .findViewById(R.id.face_view_stub); |
| 210 | if (faceViewStub != null) { |
| 211 | faceViewStub.inflate(); |
| 212 | mFaceView = (FaceView) mRootView.findViewById(R.id.face_view); |
| 213 | setSurfaceTextureSizeChangedListener(mFaceView); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 214 | } |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 215 | mCameraControls = (CameraControls) mRootView.findViewById(R.id.camera_controls); |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 216 | mAnimationManager = new AnimationManager(); |
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 | |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 219 | public void setSurfaceTextureSizeChangedListener(SurfaceTextureSizeChangedListener listener) { |
| 220 | mSurfaceTextureSizeListener = listener; |
| 221 | } |
| 222 | |
Doris Liu | d053a5b | 2013-10-25 20:20:43 -0700 | [diff] [blame] | 223 | public void updatePreviewAspectRatio(float aspectRatio) { |
| 224 | if (aspectRatio <= 0) { |
| 225 | Log.e(TAG, "Invalid aspect ratio: " + aspectRatio); |
| 226 | return; |
| 227 | } |
| 228 | if (aspectRatio < 1f) { |
| 229 | aspectRatio = 1f / aspectRatio; |
| 230 | } |
| 231 | |
| 232 | if (mAspectRatio != aspectRatio) { |
| 233 | mAspectRatio = aspectRatio; |
| 234 | // Update transform matrix with the new aspect ratio. |
| 235 | if (mPreviewWidth != 0 && mPreviewHeight != 0) { |
| 236 | setTransformMatrix(mPreviewWidth, mPreviewHeight); |
| 237 | } |
| 238 | } |
| 239 | } |
| 240 | |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 241 | private void setTransformMatrix(int width, int height) { |
| 242 | mMatrix = mTextureView.getTransform(mMatrix); |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 243 | float scaleX = 1f, scaleY = 1f; |
| 244 | float scaledTextureWidth, scaledTextureHeight; |
| 245 | if (width > height) { |
| 246 | scaledTextureWidth = Math.max(width, |
| 247 | (int) (height * mAspectRatio)); |
| 248 | scaledTextureHeight = Math.max(height, |
| 249 | (int)(width / mAspectRatio)); |
| 250 | } else { |
| 251 | scaledTextureWidth = Math.max(width, |
| 252 | (int) (height / mAspectRatio)); |
| 253 | scaledTextureHeight = Math.max(height, |
| 254 | (int) (width * mAspectRatio)); |
| 255 | } |
| 256 | |
| 257 | if (mSurfaceTextureUncroppedWidth != scaledTextureWidth || |
| 258 | mSurfaceTextureUncroppedHeight != scaledTextureHeight) { |
| 259 | mSurfaceTextureUncroppedWidth = scaledTextureWidth; |
| 260 | mSurfaceTextureUncroppedHeight = scaledTextureHeight; |
| 261 | if (mSurfaceTextureSizeListener != null) { |
| 262 | mSurfaceTextureSizeListener.onSurfaceTextureSizeChanged( |
| 263 | (int) mSurfaceTextureUncroppedWidth, (int) mSurfaceTextureUncroppedHeight); |
| 264 | } |
| 265 | } |
| 266 | scaleX = scaledTextureWidth / width; |
| 267 | scaleY = scaledTextureHeight / height; |
| 268 | mMatrix.setScale(scaleX, scaleY, (float) width / 2, (float) height / 2); |
| 269 | mTextureView.setTransform(mMatrix); |
Doris Liu | 36ebcb1 | 2013-10-28 14:44:24 -0700 | [diff] [blame] | 270 | |
| 271 | // Calculate the new preview rectangle. |
| 272 | RectF previewRect = new RectF(0, 0, width, height); |
| 273 | mMatrix.mapRect(previewRect); |
| 274 | mController.onPreviewRectChanged(CameraUtil.rectFToRect(previewRect)); |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Erin Dahlgren | b09b53e | 2013-11-06 11:57:51 -0800 | [diff] [blame] | 277 | protected Object getSurfaceTextureLock() { |
| 278 | return mSurfaceTextureLock; |
| 279 | } |
| 280 | |
Angus Kong | dcccc51 | 2013-08-08 17:06:03 -0700 | [diff] [blame] | 281 | @Override |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 282 | public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { |
Erin Dahlgren | b09b53e | 2013-11-06 11:57:51 -0800 | [diff] [blame] | 283 | synchronized (mSurfaceTextureLock) { |
| 284 | Log.v(TAG, "SurfaceTexture ready."); |
Erin Dahlgren | b09b53e | 2013-11-06 11:57:51 -0800 | [diff] [blame] | 285 | mSurfaceTexture = surface; |
| 286 | mController.onPreviewUIReady(); |
| 287 | // Workaround for b/11168275, see b/10981460 for more details |
| 288 | if (mPreviewWidth != 0 && mPreviewHeight != 0) { |
| 289 | // Re-apply transform matrix for new surface texture |
| 290 | setTransformMatrix(mPreviewWidth, mPreviewHeight); |
| 291 | } |
Doris Liu | 18f20b9 | 2013-10-09 20:51:23 -0700 | [diff] [blame] | 292 | } |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 293 | } |
| 294 | |
Angus Kong | dcccc51 | 2013-08-08 17:06:03 -0700 | [diff] [blame] | 295 | @Override |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 296 | public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { |
| 297 | // Ignored, Camera does all the work for us |
| 298 | } |
| 299 | |
Angus Kong | dcccc51 | 2013-08-08 17:06:03 -0700 | [diff] [blame] | 300 | @Override |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 301 | public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { |
Erin Dahlgren | b09b53e | 2013-11-06 11:57:51 -0800 | [diff] [blame] | 302 | synchronized (mSurfaceTextureLock) { |
| 303 | mSurfaceTexture = null; |
| 304 | mController.onPreviewUIDestroyed(); |
| 305 | Log.w(TAG, "SurfaceTexture destroyed"); |
| 306 | return true; |
| 307 | } |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 308 | } |
| 309 | |
ztenghui | 7b265a6 | 2013-09-09 14:58:44 -0700 | [diff] [blame] | 310 | @Override |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 311 | public void onSurfaceTextureUpdated(SurfaceTexture surface) { |
Andy Huibers | fccf83b | 2013-11-06 14:37:26 -0800 | [diff] [blame] | 312 | // Make sure preview cover is hidden if preview data is available. |
| 313 | if (mPreviewCover.getVisibility() != View.GONE) { |
| 314 | mPreviewCover.setVisibility(View.GONE); |
| 315 | } |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | public View getRootView() { |
| 319 | return mRootView; |
| 320 | } |
| 321 | |
| 322 | private void initIndicators() { |
Michael Kolb | eb8adc1 | 2013-04-26 11:09:29 -0700 | [diff] [blame] | 323 | mOnScreenIndicators = new OnScreenIndicators(mActivity, |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 324 | mRootView.findViewById(R.id.on_screen_indicators)); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | public void onCameraOpened(PreferenceGroup prefGroup, ComboPreferences prefs, |
| 328 | Camera.Parameters params, OnPreferenceChangedListener listener) { |
| 329 | if (mPieRenderer == null) { |
| 330 | mPieRenderer = new PieRenderer(mActivity); |
| 331 | mPieRenderer.setPieListener(this); |
Michael Kolb | e3974bb | 2013-03-22 10:56:12 -0700 | [diff] [blame] | 332 | mRenderOverlay.addRenderer(mPieRenderer); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 333 | } |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 334 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 335 | if (mMenu == null) { |
| 336 | mMenu = new PhotoMenu(mActivity, this, mPieRenderer); |
| 337 | mMenu.setListener(listener); |
| 338 | } |
| 339 | mMenu.initialize(prefGroup); |
| 340 | |
| 341 | if (mZoomRenderer == null) { |
| 342 | mZoomRenderer = new ZoomRenderer(mActivity); |
Michael Kolb | e3974bb | 2013-03-22 10:56:12 -0700 | [diff] [blame] | 343 | mRenderOverlay.addRenderer(mZoomRenderer); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 344 | } |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 345 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 346 | if (mGestures == null) { |
| 347 | // this will handle gesture disambiguation and dispatching |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 348 | mGestures = new PreviewGestures(mActivity, this, mZoomRenderer, mPieRenderer); |
| 349 | mRenderOverlay.setGestures(mGestures); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 350 | } |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 351 | mGestures.setZoomEnabled(params.isZoomSupported()); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 352 | mGestures.setRenderOverlay(mRenderOverlay); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 353 | mRenderOverlay.requestLayout(); |
| 354 | |
| 355 | initializeZoom(params); |
Michael Kolb | eb8adc1 | 2013-04-26 11:09:29 -0700 | [diff] [blame] | 356 | updateOnScreenIndicators(params, prefGroup, prefs); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 357 | } |
| 358 | |
Doris Liu | 29da2db | 2013-08-28 14:28:45 -0700 | [diff] [blame] | 359 | public void animateCapture(final byte[] jpegData, int orientation, boolean mirror) { |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 360 | // Decode jpeg byte array and then animate the jpeg |
Doris Liu | 29da2db | 2013-08-28 14:28:45 -0700 | [diff] [blame] | 361 | DecodeTask task = new DecodeTask(jpegData, orientation, mirror); |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 362 | task.execute(); |
| 363 | } |
| 364 | |
Michael Kolb | 3bc96b2 | 2013-03-12 10:24:42 -0700 | [diff] [blame] | 365 | private void openMenu() { |
| 366 | if (mPieRenderer != null) { |
| 367 | // If autofocus is not finished, cancel autofocus so that the |
| 368 | // subsequent touch can be handled by PreviewGestures |
| 369 | if (mController.getCameraState() == PhotoController.FOCUSING) { |
| 370 | mController.cancelAutoFocus(); |
| 371 | } |
| 372 | mPieRenderer.showInCenter(); |
| 373 | } |
| 374 | } |
| 375 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 376 | public void initializeControlByIntent() { |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 377 | mPreviewThumb = (ImageView) mRootView.findViewById(R.id.preview_thumb); |
Michael Kolb | 78a5b22 | 2013-04-30 15:34:19 -0700 | [diff] [blame] | 378 | mPreviewThumb.setOnClickListener(new OnClickListener() { |
| 379 | @Override |
| 380 | public void onClick(View v) { |
Angus Kong | 734598c | 2013-08-21 15:25:05 -0700 | [diff] [blame] | 381 | mActivity.gotoGallery(); |
Michael Kolb | 78a5b22 | 2013-04-30 15:34:19 -0700 | [diff] [blame] | 382 | } |
| 383 | }); |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 384 | mMenuButton = mRootView.findViewById(R.id.menu); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 385 | mMenuButton.setOnClickListener(new OnClickListener() { |
| 386 | @Override |
| 387 | public void onClick(View v) { |
Michael Kolb | 3bc96b2 | 2013-03-12 10:24:42 -0700 | [diff] [blame] | 388 | openMenu(); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 389 | } |
| 390 | }); |
| 391 | if (mController.isImageCaptureIntent()) { |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 392 | ViewGroup cameraControls = (ViewGroup) mRootView.findViewById(R.id.camera_controls); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 393 | mActivity.getLayoutInflater().inflate(R.layout.review_module_control, cameraControls); |
| 394 | |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 395 | mReviewDoneButton = mRootView.findViewById(R.id.btn_done); |
| 396 | mReviewCancelButton = mRootView.findViewById(R.id.btn_cancel); |
| 397 | mReviewRetakeButton = mRootView.findViewById(R.id.btn_retake); |
Doris Liu | 36e56fb | 2013-09-11 17:38:08 -0700 | [diff] [blame] | 398 | mReviewImage = (ImageView) mRootView.findViewById(R.id.review_image); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 399 | mReviewCancelButton.setVisibility(View.VISIBLE); |
| 400 | |
| 401 | mReviewDoneButton.setOnClickListener(new OnClickListener() { |
| 402 | @Override |
| 403 | public void onClick(View v) { |
| 404 | mController.onCaptureDone(); |
| 405 | } |
| 406 | }); |
| 407 | mReviewCancelButton.setOnClickListener(new OnClickListener() { |
| 408 | @Override |
| 409 | public void onClick(View v) { |
| 410 | mController.onCaptureCancelled(); |
| 411 | } |
| 412 | }); |
| 413 | |
| 414 | mReviewRetakeButton.setOnClickListener(new OnClickListener() { |
| 415 | @Override |
| 416 | public void onClick(View v) { |
| 417 | mController.onCaptureRetake(); |
| 418 | } |
| 419 | }); |
| 420 | } |
| 421 | } |
| 422 | |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 423 | public void hideUI() { |
| 424 | mCameraControls.setVisibility(View.INVISIBLE); |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | public void showUI() { |
| 428 | mCameraControls.setVisibility(View.VISIBLE); |
| 429 | } |
| 430 | |
Erin Dahlgren | 3044d8c | 2013-10-10 18:23:45 -0700 | [diff] [blame] | 431 | public boolean arePreviewControlsVisible() { |
| 432 | return (mCameraControls.getVisibility() == View.VISIBLE); |
| 433 | } |
| 434 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 435 | // called from onResume but only the first time |
| 436 | public void initializeFirstTime() { |
| 437 | // Initialize shutter button. |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 438 | mShutterButton.setImageResource(R.drawable.btn_new_shutter); |
| 439 | mShutterButton.setOnShutterButtonListener(mController); |
| 440 | mShutterButton.setVisibility(View.VISIBLE); |
| 441 | } |
| 442 | |
| 443 | // called from onResume every other time |
| 444 | public void initializeSecondTime(Camera.Parameters params) { |
| 445 | initializeZoom(params); |
| 446 | if (mController.isImageCaptureIntent()) { |
| 447 | hidePostCaptureAlert(); |
| 448 | } |
| 449 | if (mMenu != null) { |
| 450 | mMenu.reloadPreferences(); |
| 451 | } |
| 452 | } |
| 453 | |
Doris Liu | 6a83d52 | 2013-07-02 12:03:32 -0700 | [diff] [blame] | 454 | public void showLocationDialog() { |
| 455 | mLocationDialog = new AlertDialog.Builder(mActivity) |
| 456 | .setTitle(R.string.remember_location_title) |
| 457 | .setMessage(R.string.remember_location_prompt) |
| 458 | .setPositiveButton(R.string.remember_location_yes, |
| 459 | new DialogInterface.OnClickListener() { |
| 460 | @Override |
| 461 | public void onClick(DialogInterface dialog, int arg1) { |
| 462 | mController.enableRecordingLocation(true); |
| 463 | mLocationDialog = null; |
| 464 | } |
| 465 | }) |
| 466 | .setNegativeButton(R.string.remember_location_no, |
| 467 | new DialogInterface.OnClickListener() { |
| 468 | @Override |
| 469 | public void onClick(DialogInterface dialog, int arg1) { |
| 470 | dialog.cancel(); |
| 471 | } |
| 472 | }) |
| 473 | .setOnCancelListener(new DialogInterface.OnCancelListener() { |
| 474 | @Override |
| 475 | public void onCancel(DialogInterface dialog) { |
| 476 | mController.enableRecordingLocation(false); |
| 477 | mLocationDialog = null; |
| 478 | } |
| 479 | }) |
| 480 | .show(); |
| 481 | } |
| 482 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 483 | public void initializeZoom(Camera.Parameters params) { |
| 484 | if ((params == null) || !params.isZoomSupported() |
| 485 | || (mZoomRenderer == null)) return; |
| 486 | mZoomMax = params.getMaxZoom(); |
| 487 | mZoomRatios = params.getZoomRatios(); |
| 488 | // Currently we use immediate zoom for fast zooming to get better UX and |
| 489 | // there is no plan to take advantage of the smooth zoom. |
| 490 | if (mZoomRenderer != null) { |
| 491 | mZoomRenderer.setZoomMax(mZoomMax); |
| 492 | mZoomRenderer.setZoom(params.getZoom()); |
| 493 | mZoomRenderer.setZoomValue(mZoomRatios.get(params.getZoom())); |
| 494 | mZoomRenderer.setOnZoomChangeListener(new ZoomChangeListener()); |
| 495 | } |
| 496 | } |
| 497 | |
ztenghui | 7b265a6 | 2013-09-09 14:58:44 -0700 | [diff] [blame] | 498 | @Override |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 499 | public void showGpsOnScreenIndicator(boolean hasSignal) { } |
| 500 | |
ztenghui | 7b265a6 | 2013-09-09 14:58:44 -0700 | [diff] [blame] | 501 | @Override |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 502 | public void hideGpsOnScreenIndicator() { } |
| 503 | |
| 504 | public void overrideSettings(final String ... keyvalues) { |
| 505 | mMenu.overrideSettings(keyvalues); |
| 506 | } |
| 507 | |
| 508 | public void updateOnScreenIndicators(Camera.Parameters params, |
Michael Kolb | eb8adc1 | 2013-04-26 11:09:29 -0700 | [diff] [blame] | 509 | PreferenceGroup group, ComboPreferences prefs) { |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 510 | if (params == null) return; |
Sascha Haeberling | c7965e2 | 2013-04-22 14:27:36 -0700 | [diff] [blame] | 511 | mOnScreenIndicators.updateSceneOnScreenIndicator(params.getSceneMode()); |
| 512 | mOnScreenIndicators.updateExposureOnScreenIndicator(params, |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 513 | CameraSettings.readExposure(prefs)); |
Sascha Haeberling | c7965e2 | 2013-04-22 14:27:36 -0700 | [diff] [blame] | 514 | mOnScreenIndicators.updateFlashOnScreenIndicator(params.getFlashMode()); |
Michael Kolb | eb8adc1 | 2013-04-26 11:09:29 -0700 | [diff] [blame] | 515 | int wbIndex = 2; |
| 516 | ListPreference pref = group.findPreference(CameraSettings.KEY_WHITE_BALANCE); |
| 517 | if (pref != null) { |
| 518 | wbIndex = pref.getCurrentIndex(); |
| 519 | } |
| 520 | mOnScreenIndicators.updateWBIndicator(wbIndex); |
Michael Kolb | 8788079 | 2013-04-30 15:38:49 -0700 | [diff] [blame] | 521 | boolean location = RecordLocationPreference.get( |
| 522 | prefs, mActivity.getContentResolver()); |
Michael Kolb | eb8adc1 | 2013-04-26 11:09:29 -0700 | [diff] [blame] | 523 | mOnScreenIndicators.updateLocationIndicator(location); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 524 | } |
| 525 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 526 | public void setCameraState(int state) { |
| 527 | } |
| 528 | |
Doris Liu | c2e9abd | 2013-06-19 14:20:51 -0700 | [diff] [blame] | 529 | public void animateFlash() { |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 530 | mAnimationManager.startFlashAnimation(mFlashOverlay); |
Doris Liu | c2e9abd | 2013-06-19 14:20:51 -0700 | [diff] [blame] | 531 | } |
| 532 | |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 533 | public void enableGestures(boolean enable) { |
| 534 | if (mGestures != null) { |
| 535 | mGestures.setEnabled(enable); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 536 | } |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | // forward from preview gestures to controller |
| 540 | @Override |
| 541 | public void onSingleTapUp(View view, int x, int y) { |
| 542 | mController.onSingleTapUp(view, x, y); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | public boolean onBackPressed() { |
| 546 | if (mPieRenderer != null && mPieRenderer.showsItems()) { |
| 547 | mPieRenderer.hide(); |
| 548 | return true; |
| 549 | } |
| 550 | // In image capture mode, back button should: |
| 551 | // 1) if there is any popup, dismiss them, 2) otherwise, get out of |
| 552 | // image capture |
| 553 | if (mController.isImageCaptureIntent()) { |
Doris Liu | c3679c0 | 2013-08-08 18:08:43 -0700 | [diff] [blame] | 554 | mController.onCaptureCancelled(); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 555 | return true; |
| 556 | } else if (!mController.isCameraIdle()) { |
| 557 | // ignore backs while we're taking a picture |
| 558 | return true; |
| 559 | } else { |
Doris Liu | c3679c0 | 2013-08-08 18:08:43 -0700 | [diff] [blame] | 560 | return false; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 561 | } |
| 562 | } |
| 563 | |
ztenghui | 7b265a6 | 2013-09-09 14:58:44 -0700 | [diff] [blame] | 564 | public void onPreviewFocusChanged(boolean previewFocused) { |
| 565 | if (previewFocused) { |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 566 | showUI(); |
| 567 | } else { |
| 568 | hideUI(); |
| 569 | } |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 570 | if (mFaceView != null) { |
ztenghui | 7b265a6 | 2013-09-09 14:58:44 -0700 | [diff] [blame] | 571 | mFaceView.setBlockDraw(!previewFocused); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 572 | } |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 573 | if (mGestures != null) { |
ztenghui | 7b265a6 | 2013-09-09 14:58:44 -0700 | [diff] [blame] | 574 | mGestures.setEnabled(previewFocused); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 575 | } |
| 576 | if (mRenderOverlay != null) { |
| 577 | // this can not happen in capture mode |
ztenghui | 7b265a6 | 2013-09-09 14:58:44 -0700 | [diff] [blame] | 578 | mRenderOverlay.setVisibility(previewFocused ? View.VISIBLE : View.GONE); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 579 | } |
| 580 | if (mPieRenderer != null) { |
ztenghui | 7b265a6 | 2013-09-09 14:58:44 -0700 | [diff] [blame] | 581 | mPieRenderer.setBlockFocus(!previewFocused); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 582 | } |
ztenghui | 7b265a6 | 2013-09-09 14:58:44 -0700 | [diff] [blame] | 583 | setShowMenu(previewFocused); |
| 584 | if (!previewFocused && mCountDownView != null) mCountDownView.cancelCountDown(); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 585 | } |
| 586 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 587 | public void showPopup(AbstractSettingPopup popup) { |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 588 | hideUI(); |
Doris Liu | c3679c0 | 2013-08-08 18:08:43 -0700 | [diff] [blame] | 589 | |
| 590 | if (mPopup == null) { |
| 591 | mPopup = new PopupWindow(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); |
| 592 | mPopup.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); |
| 593 | mPopup.setOutsideTouchable(true); |
| 594 | mPopup.setFocusable(true); |
| 595 | mPopup.setOnDismissListener(new PopupWindow.OnDismissListener() { |
| 596 | @Override |
| 597 | public void onDismiss() { |
| 598 | mPopup = null; |
| 599 | mMenu.popupDismissed(); |
| 600 | showUI(); |
Sascha Haeberling | 4ec139d | 2013-10-09 23:46:20 -0700 | [diff] [blame] | 601 | |
| 602 | // Switch back into fullscreen/lights-out mode after popup |
| 603 | // is dimissed. |
| 604 | mActivity.setSystemBarsVisibility(false); |
Doris Liu | c3679c0 | 2013-08-08 18:08:43 -0700 | [diff] [blame] | 605 | } |
| 606 | }); |
| 607 | } |
| 608 | popup.setVisibility(View.VISIBLE); |
| 609 | mPopup.setContentView(popup); |
| 610 | mPopup.showAtLocation(mRootView, Gravity.CENTER, 0, 0); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 611 | } |
| 612 | |
Michael Kolb | 7048972 | 2013-05-08 11:14:35 -0700 | [diff] [blame] | 613 | public void dismissPopup() { |
Doris Liu | c3679c0 | 2013-08-08 18:08:43 -0700 | [diff] [blame] | 614 | if (mPopup != null && mPopup.isShowing()) { |
| 615 | mPopup.dismiss(); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 616 | } |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | public void onShowSwitcherPopup() { |
| 620 | if (mPieRenderer != null && mPieRenderer.showsItems()) { |
| 621 | mPieRenderer.hide(); |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | private void setShowMenu(boolean show) { |
| 626 | if (mOnScreenIndicators != null) { |
| 627 | mOnScreenIndicators.setVisibility(show ? View.VISIBLE : View.GONE); |
| 628 | } |
| 629 | if (mMenuButton != null) { |
| 630 | mMenuButton.setVisibility(show ? View.VISIBLE : View.GONE); |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | public boolean collapseCameraControls() { |
| 635 | // Remove all the popups/dialog boxes |
| 636 | boolean ret = false; |
| 637 | if (mPopup != null) { |
Michael Kolb | 7048972 | 2013-05-08 11:14:35 -0700 | [diff] [blame] | 638 | dismissPopup(); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 639 | ret = true; |
| 640 | } |
Michael Kolb | b16bae9 | 2013-05-08 16:05:04 -0700 | [diff] [blame] | 641 | onShowSwitcherPopup(); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 642 | return ret; |
| 643 | } |
| 644 | |
Doris Liu | 36e56fb | 2013-09-11 17:38:08 -0700 | [diff] [blame] | 645 | protected void showCapturedImageForReview(byte[] jpegData, int orientation, boolean mirror) { |
| 646 | mDecodeTaskForReview = new DecodeImageForReview(jpegData, orientation, mirror); |
| 647 | mDecodeTaskForReview.execute(); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 648 | mOnScreenIndicators.setVisibility(View.GONE); |
| 649 | mMenuButton.setVisibility(View.GONE); |
Angus Kong | b50b5cb | 2013-08-09 14:55:20 -0700 | [diff] [blame] | 650 | CameraUtil.fadeIn(mReviewDoneButton); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 651 | mShutterButton.setVisibility(View.INVISIBLE); |
Angus Kong | b50b5cb | 2013-08-09 14:55:20 -0700 | [diff] [blame] | 652 | CameraUtil.fadeIn(mReviewRetakeButton); |
Doris Liu | d31cdfe | 2013-05-14 11:31:19 -0700 | [diff] [blame] | 653 | pauseFaceDetection(); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | protected void hidePostCaptureAlert() { |
Doris Liu | 36e56fb | 2013-09-11 17:38:08 -0700 | [diff] [blame] | 657 | if (mDecodeTaskForReview != null) { |
| 658 | mDecodeTaskForReview.cancel(true); |
| 659 | } |
| 660 | mReviewImage.setVisibility(View.GONE); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 661 | mOnScreenIndicators.setVisibility(View.VISIBLE); |
| 662 | mMenuButton.setVisibility(View.VISIBLE); |
Angus Kong | b50b5cb | 2013-08-09 14:55:20 -0700 | [diff] [blame] | 663 | CameraUtil.fadeOut(mReviewDoneButton); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 664 | mShutterButton.setVisibility(View.VISIBLE); |
Angus Kong | b50b5cb | 2013-08-09 14:55:20 -0700 | [diff] [blame] | 665 | CameraUtil.fadeOut(mReviewRetakeButton); |
Doris Liu | d31cdfe | 2013-05-14 11:31:19 -0700 | [diff] [blame] | 666 | resumeFaceDetection(); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | public void setDisplayOrientation(int orientation) { |
| 670 | if (mFaceView != null) { |
| 671 | mFaceView.setDisplayOrientation(orientation); |
| 672 | } |
| 673 | } |
| 674 | |
| 675 | // shutter button handling |
| 676 | |
| 677 | public boolean isShutterPressed() { |
| 678 | return mShutterButton.isPressed(); |
| 679 | } |
| 680 | |
Sascha Haeberling | 8890194 | 2013-08-28 17:49:00 -0700 | [diff] [blame] | 681 | /** |
| 682 | * Enables or disables the shutter button. |
| 683 | */ |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 684 | public void enableShutter(boolean enabled) { |
| 685 | if (mShutterButton != null) { |
| 686 | mShutterButton.setEnabled(enabled); |
| 687 | } |
| 688 | } |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 689 | |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 690 | public void pressShutterButton() { |
| 691 | if (mShutterButton.isInTouchMode()) { |
| 692 | mShutterButton.requestFocusFromTouch(); |
| 693 | } else { |
| 694 | mShutterButton.requestFocus(); |
| 695 | } |
| 696 | mShutterButton.setPressed(true); |
| 697 | } |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 698 | |
| 699 | private class ZoomChangeListener implements ZoomRenderer.OnZoomChangedListener { |
| 700 | @Override |
| 701 | public void onZoomValueChanged(int index) { |
| 702 | int newZoom = mController.onZoomChanged(index); |
| 703 | if (mZoomRenderer != null) { |
| 704 | mZoomRenderer.setZoomValue(mZoomRatios.get(newZoom)); |
| 705 | } |
| 706 | } |
| 707 | |
| 708 | @Override |
| 709 | public void onZoomStart() { |
| 710 | if (mPieRenderer != null) { |
| 711 | mPieRenderer.setBlockFocus(true); |
| 712 | } |
| 713 | } |
| 714 | |
| 715 | @Override |
| 716 | public void onZoomEnd() { |
| 717 | if (mPieRenderer != null) { |
| 718 | mPieRenderer.setBlockFocus(false); |
| 719 | } |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | @Override |
| 724 | public void onPieOpened(int centerX, int centerY) { |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 725 | setSwipingEnabled(false); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 726 | if (mFaceView != null) { |
| 727 | mFaceView.setBlockDraw(true); |
| 728 | } |
| 729 | } |
| 730 | |
| 731 | @Override |
| 732 | public void onPieClosed() { |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 733 | setSwipingEnabled(true); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 734 | if (mFaceView != null) { |
| 735 | mFaceView.setBlockDraw(false); |
| 736 | } |
| 737 | } |
| 738 | |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 739 | public void setSwipingEnabled(boolean enable) { |
| 740 | mActivity.setSwipingEnabled(enable); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 741 | } |
| 742 | |
Angus Kong | dcccc51 | 2013-08-08 17:06:03 -0700 | [diff] [blame] | 743 | public SurfaceTexture getSurfaceTexture() { |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 744 | return mSurfaceTexture; |
| 745 | } |
| 746 | |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 747 | // Countdown timer |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 748 | |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 749 | private void initializeCountDown() { |
| 750 | mActivity.getLayoutInflater().inflate(R.layout.count_down_to_capture, |
| 751 | (ViewGroup) mRootView, true); |
| 752 | mCountDownView = (CountDownView) (mRootView.findViewById(R.id.count_down_to_capture)); |
| 753 | mCountDownView.setCountDownFinishedListener((OnCountDownFinishedListener) mController); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | public boolean isCountingDown() { |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 757 | return mCountDownView != null && mCountDownView.isCountingDown(); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | public void cancelCountDown() { |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 761 | if (mCountDownView == null) return; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 762 | mCountDownView.cancelCountDown(); |
| 763 | } |
| 764 | |
| 765 | public void startCountDown(int sec, boolean playSound) { |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 766 | if (mCountDownView == null) initializeCountDown(); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 767 | mCountDownView.startCountDown(sec, playSound); |
| 768 | } |
| 769 | |
| 770 | public void showPreferencesToast() { |
| 771 | if (mNotSelectableToast == null) { |
| 772 | String str = mActivity.getResources().getString(R.string.not_selectable_in_scene_mode); |
| 773 | mNotSelectableToast = Toast.makeText(mActivity, str, Toast.LENGTH_SHORT); |
| 774 | } |
| 775 | mNotSelectableToast.show(); |
| 776 | } |
| 777 | |
Doris Liu | 3a45c33 | 2013-10-15 19:10:28 -0700 | [diff] [blame] | 778 | public void showPreviewCover() { |
| 779 | mPreviewCover.setVisibility(View.VISIBLE); |
| 780 | } |
| 781 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 782 | public void onPause() { |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 783 | cancelCountDown(); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 784 | |
| 785 | // Clear UI. |
| 786 | collapseCameraControls(); |
| 787 | if (mFaceView != null) mFaceView.clear(); |
| 788 | |
Doris Liu | 6a83d52 | 2013-07-02 12:03:32 -0700 | [diff] [blame] | 789 | if (mLocationDialog != null && mLocationDialog.isShowing()) { |
| 790 | mLocationDialog.dismiss(); |
| 791 | } |
| 792 | mLocationDialog = null; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 793 | } |
| 794 | |
Doris Liu | 5939006 | 2013-10-10 17:20:56 -0700 | [diff] [blame] | 795 | public void initDisplayChangeListener() { |
| 796 | ((CameraRootView) mRootView).setDisplayChangeListener(this); |
| 797 | } |
| 798 | |
| 799 | public void removeDisplayChangeListener() { |
| 800 | ((CameraRootView) mRootView).removeDisplayChangeListener(); |
| 801 | } |
| 802 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 803 | // focus UI implementation |
| 804 | |
| 805 | private FocusIndicator getFocusIndicator() { |
| 806 | return (mFaceView != null && mFaceView.faceExists()) ? mFaceView : mPieRenderer; |
| 807 | } |
| 808 | |
| 809 | @Override |
| 810 | public boolean hasFaces() { |
| 811 | return (mFaceView != null && mFaceView.faceExists()); |
| 812 | } |
| 813 | |
| 814 | public void clearFaces() { |
| 815 | if (mFaceView != null) mFaceView.clear(); |
| 816 | } |
| 817 | |
| 818 | @Override |
| 819 | public void clearFocus() { |
Michael Kolb | 2441ada | 2013-03-13 10:47:06 -0700 | [diff] [blame] | 820 | FocusIndicator indicator = getFocusIndicator(); |
| 821 | if (indicator != null) indicator.clear(); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | @Override |
| 825 | public void setFocusPosition(int x, int y) { |
| 826 | mPieRenderer.setFocus(x, y); |
| 827 | } |
| 828 | |
| 829 | @Override |
| 830 | public void onFocusStarted() { |
| 831 | getFocusIndicator().showStart(); |
| 832 | } |
| 833 | |
| 834 | @Override |
| 835 | public void onFocusSucceeded(boolean timeout) { |
| 836 | getFocusIndicator().showSuccess(timeout); |
| 837 | } |
| 838 | |
| 839 | @Override |
| 840 | public void onFocusFailed(boolean timeout) { |
| 841 | getFocusIndicator().showFail(timeout); |
| 842 | } |
| 843 | |
| 844 | @Override |
| 845 | public void pauseFaceDetection() { |
| 846 | if (mFaceView != null) mFaceView.pause(); |
| 847 | } |
| 848 | |
| 849 | @Override |
| 850 | public void resumeFaceDetection() { |
| 851 | if (mFaceView != null) mFaceView.resume(); |
| 852 | } |
| 853 | |
| 854 | public void onStartFaceDetection(int orientation, boolean mirror) { |
| 855 | mFaceView.clear(); |
| 856 | mFaceView.setVisibility(View.VISIBLE); |
| 857 | mFaceView.setDisplayOrientation(orientation); |
| 858 | mFaceView.setMirror(mirror); |
| 859 | mFaceView.resume(); |
| 860 | } |
| 861 | |
| 862 | @Override |
Angus Kong | 9e76552 | 2013-07-31 14:05:20 -0700 | [diff] [blame] | 863 | public void onFaceDetection(Face[] faces, CameraManager.CameraProxy camera) { |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 864 | mFaceView.setFaces(faces); |
| 865 | } |
| 866 | |
ztenghui | 7b265a6 | 2013-09-09 14:58:44 -0700 | [diff] [blame] | 867 | @Override |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 868 | public void onDisplayChanged() { |
Doris Liu | 0ba8eaa | 2013-10-16 12:51:02 -0700 | [diff] [blame] | 869 | Log.d(TAG, "Device flip detected."); |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 870 | mCameraControls.checkLayoutFlip(); |
| 871 | mController.updateCameraOrientation(); |
Michael Kolb | 3bc96b2 | 2013-03-12 10:24:42 -0700 | [diff] [blame] | 872 | } |
| 873 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 874 | } |