diff options
author | junjiez <junjiez@codeaurora.org> | 2016-12-20 15:55:31 +0800 |
---|---|---|
committer | Gerrit - the friendly Code Review server <code-review@localhost> | 2016-12-27 00:55:28 -0800 |
commit | 929d67931a209e6830b8b83d9a2a0f3dbd38c841 (patch) | |
tree | d7df65e5cff16dc167fc45575ff369b40dd03baa /src/com/android/camera/CaptureUI.java | |
parent | ec1cdf7f6b81e42e90c6d0627955eae5fac1f294 (diff) | |
download | android_packages_apps_Snap-929d67931a209e6830b8b83d9a2a0f3dbd38c841.tar.gz android_packages_apps_Snap-929d67931a209e6830b8b83d9a2a0f3dbd38c841.tar.bz2 android_packages_apps_Snap-929d67931a209e6830b8b83d9a2a0f3dbd38c841.zip |
SnapdragonCamera: add features for 3rd-party apps
Add capture and recording features for 3rd-party app.
Change-Id: Iefedbed2cb17cca17941e70f861448a2b8f97da2
CRs-Fixed: 1095457
Diffstat (limited to 'src/com/android/camera/CaptureUI.java')
-rwxr-xr-x[-rw-r--r--] | src/com/android/camera/CaptureUI.java | 159 |
1 files changed, 153 insertions, 6 deletions
diff --git a/src/com/android/camera/CaptureUI.java b/src/com/android/camera/CaptureUI.java index 1cb7d7510..8bbbf1753 100644..100755 --- a/src/com/android/camera/CaptureUI.java +++ b/src/com/android/camera/CaptureUI.java @@ -20,17 +20,23 @@ package com.android.camera; import android.animation.Animator; +import android.app.Activity; import android.app.AlertDialog; +import android.content.ActivityNotFoundException; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Resources; +import android.graphics.Bitmap; import android.graphics.ImageFormat; +import android.graphics.Matrix; +import android.graphics.Paint; import android.graphics.Point; import android.graphics.Rect; import android.graphics.drawable.AnimationDrawable; import android.hardware.Camera.Face; +import android.os.AsyncTask; import android.preference.PreferenceManager; import android.renderscript.Allocation; import android.renderscript.Element; @@ -196,6 +202,16 @@ public class CaptureUI implements FocusOverlayManager.FocusUI, private ImageView mSceneModeLabelCloseIcon; private AlertDialog mSceneModeInstructionalDialog = null; + private ImageView mCancelButton; + private View mReviewCancelButton; + private View mReviewDoneButton; + private View mReviewRetakeButton; + private View mReviewPlayButton; + private FrameLayout mPreviewLayout; + private ImageView mReviewImage; + private int mDownSampleFactor = 4; + private DecodeImageForReview mDecodeTaskForReview = null; + int mPreviewWidth; int mPreviewHeight; private boolean mIsVideoUI = false; @@ -204,11 +220,13 @@ public class CaptureUI implements FocusOverlayManager.FocusUI, private void previewUIReady() { if((mSurfaceHolder != null && mSurfaceHolder.getSurface().isValid())) { mModule.onPreviewUIReady(); - if (mIsVideoUI && mThumbnail != null) { + if ((mIsVideoUI || mModule.getCurrentIntentMode() != CaptureModule.INTENT_MODE_NORMAL) + && mThumbnail != null){ mThumbnail.setVisibility(View.INVISIBLE); mThumbnail = null; mActivity.updateThumbnail(mThumbnail); - } else if (!mIsVideoUI){ + } else if (!mIsVideoUI && + mModule.getCurrentIntentMode() == CaptureModule.INTENT_MODE_NORMAL){ if (mThumbnail == null) mThumbnail = (ImageView) mRootView.findViewById(R.id.preview_thumb); mActivity.updateThumbnail(mThumbnail); @@ -361,6 +379,56 @@ public class CaptureUI implements FocusOverlayManager.FocusUI, mCameraControls = (OneUICameraControls) mRootView.findViewById(R.id.camera_controls); mFaceView = (Camera2FaceView) mRootView.findViewById(R.id.face_view); + mCancelButton = (ImageView) mRootView.findViewById(R.id.cancel_button); + int intentMode = mModule.getCurrentIntentMode(); + if (intentMode != CaptureModule.INTENT_MODE_NORMAL) { + mCameraControls.setIntentMode(intentMode); + mCameraControls.setVideoMode(false); + mCancelButton.setVisibility(View.VISIBLE); + mReviewCancelButton = mRootView.findViewById(R.id.preview_btn_cancel); + mReviewDoneButton = mRootView.findViewById(R.id.preview_btn_done); + mReviewRetakeButton = mRootView.findViewById(R.id.preview_btn_retake); + mReviewPlayButton = mRootView.findViewById(R.id.preview_play); + mPreviewLayout = (FrameLayout)mRootView.findViewById(R.id.preview_of_intent); + mReviewImage = (ImageView)mRootView.findViewById(R.id.preview_content); + mReviewCancelButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + mActivity.setResultEx(Activity.RESULT_CANCELED, new Intent()); + mActivity.finish(); + } + }); + mReviewRetakeButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + mPreviewLayout.setVisibility(View.GONE); + mReviewImage.setImageBitmap(null); + } + }); + mReviewDoneButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (intentMode == CaptureModule.INTENT_MODE_CAPTURE) { + mModule.onCaptureDone(); + } else if (intentMode == CaptureModule.INTENT_MODE_VIDEO) { + mModule.onRecordingDone(true); + } + } + }); + mReviewPlayButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + mModule.startPlayVideoActivity(); + } + }); + mCancelButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + mModule.cancelCapture(); + } + }); + } + mActivity.getWindowManager().getDefaultDisplay().getSize(mDisplaySize); mScreenRatio = CameraUtil.determineRatio(mDisplaySize.x, mDisplaySize.y); if (mScreenRatio == CameraUtil.RATIO_16_9) { @@ -405,6 +473,22 @@ public class CaptureUI implements FocusOverlayManager.FocusUI, showFirstTimeHelp(); } + protected void showCapturedImageForReview(byte[] jpegData, int orientation, boolean mirror) { + mDecodeTaskForReview = new CaptureUI.DecodeImageForReview(jpegData, orientation, mirror); + mDecodeTaskForReview.execute(); + mPreviewLayout.setVisibility(View.VISIBLE); + CameraUtil.fadeIn(mReviewDoneButton); + CameraUtil.fadeIn(mReviewRetakeButton); + } + + protected void showRecordVideoForReview(Bitmap preview) { + mReviewImage.setImageBitmap(preview); + mPreviewLayout.setVisibility(View.VISIBLE); + mReviewPlayButton.setVisibility(View.VISIBLE); + CameraUtil.fadeIn(mReviewDoneButton); + CameraUtil.fadeIn(mReviewRetakeButton); + } + private void toggleMakeup() { String value = mSettingsManager.getValue(SettingsManager.KEY_MAKEUP); if(value != null && !mIsVideoUI) { @@ -471,16 +555,25 @@ public class CaptureUI implements FocusOverlayManager.FocusUI, public void initializeProMode(boolean promode) { mCameraControls.setProMode(promode); - if (promode) mVideoButton.setVisibility(View.INVISIBLE); - else mVideoButton.setVisibility(View.VISIBLE); + if (promode) + mVideoButton.setVisibility(View.INVISIBLE); + else if (mModule.getCurrentIntentMode() == CaptureModule.INTENT_MODE_NORMAL) + mVideoButton.setVisibility(View.VISIBLE); } // called from onResume but only the first time public void initializeFirstTime() { // Initialize shutter button. + int intentMode = mModule.getCurrentIntentMode(); + if (intentMode == CaptureModule.INTENT_MODE_CAPTURE) { + mVideoButton.setVisibility(View.INVISIBLE); + } else if (intentMode == CaptureModule.INTENT_MODE_VIDEO) { + mShutterButton.setVisibility(View.INVISIBLE); + } else { + mShutterButton.setVisibility(View.VISIBLE); + mVideoButton.setVisibility(View.VISIBLE); + } mShutterButton.setOnShutterButtonListener(mModule); - mShutterButton.setVisibility(View.VISIBLE); - mVideoButton.setVisibility(View.VISIBLE); mShutterButton.setImageResource(R.drawable.one_ui_shutter_anim); mShutterButton.setOnClickListener(new View.OnClickListener() { @Override @@ -531,6 +624,9 @@ public class CaptureUI implements FocusOverlayManager.FocusUI, } public void openSettingsMenu() { + if (mPreviewLayout.getVisibility() == View.VISIBLE) { + return; + } clearFocus(); removeFilterMenu(false); Intent intent = new Intent(mActivity, SettingsActivity.class); @@ -1011,6 +1107,9 @@ public class CaptureUI implements FocusOverlayManager.FocusUI, mActivity.gotoGallery(); } }); + if (mModule.getCurrentIntentMode() != CaptureModule.INTENT_MODE_NORMAL) { + mCameraControls.setIntentMode(mModule.getCurrentIntentMode()); + } } public void doShutterAnimation() { @@ -1599,6 +1698,54 @@ public class CaptureUI implements FocusOverlayManager.FocusUI, } } + private class DecodeTask extends AsyncTask<Void, Void, Bitmap> { + private final byte [] mData; + private int mOrientation; + private boolean mMirror; + + public DecodeTask(byte[] data, int orientation, boolean mirror) { + mData = data; + mOrientation = orientation; + mMirror = mirror; + } + + @Override + protected Bitmap doInBackground(Void... params) { + Bitmap bitmap = CameraUtil.downSample(mData, mDownSampleFactor); + // Decode image in background. + if ((mOrientation != 0 || mMirror) && (bitmap != null)) { + Matrix m = new Matrix(); + if (mMirror) { + // Flip horizontally + m.setScale(-1f, 1f); + } + m.preRotate(mOrientation); + return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, + false); + } + return bitmap; + } + + @Override + protected void onPostExecute(Bitmap bitmap) { + } + } + + private class DecodeImageForReview extends CaptureUI.DecodeTask { + public DecodeImageForReview(byte[] data, int orientation, boolean mirror) { + super(data, orientation, mirror); + } + + @Override + protected void onPostExecute(Bitmap bitmap) { + if (isCancelled()) { + return; + } + mReviewImage.setImageBitmap(bitmap); + mReviewImage.setVisibility(View.VISIBLE); + mDecodeTaskForReview = null; + } + } public ImageView getVideoButton() { return mVideoButton; |