diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2009-01-22 00:13:44 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-01-22 00:13:44 -0800 |
commit | 8250896ab37545f4499da79f54c19af2e5018b80 (patch) | |
tree | 6eeaf1ae7e7d40f061a8ea032a14a5d8d9814e51 /src | |
parent | 33e3e0b3f4f1f54e067bbc54c9b8b5a26660f9f0 (diff) | |
download | LegacyCamera-8250896ab37545f4499da79f54c19af2e5018b80.zip LegacyCamera-8250896ab37545f4499da79f54c19af2e5018b80.tar.gz LegacyCamera-8250896ab37545f4499da79f54c19af2e5018b80.tar.bz2 |
auto import from //branches/cupcake/...@127436
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/camera/Camera.java | 134 | ||||
-rw-r--r-- | src/com/android/camera/CropImage.java | 3 | ||||
-rwxr-xr-x | src/com/android/camera/ImageManager.java | 8 | ||||
-rw-r--r-- | src/com/android/camera/MenuHelper.java | 135 | ||||
-rw-r--r-- | src/com/android/camera/ShutterButton.java | 115 | ||||
-rw-r--r-- | src/com/android/camera/VideoCamera.java | 92 | ||||
-rw-r--r-- | src/com/android/camera/Wallpaper.java | 41 |
7 files changed, 366 insertions, 162 deletions
diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java index c06f5e5..11b1ccd 100644 --- a/src/com/android/camera/Camera.java +++ b/src/com/android/camera/Camera.java @@ -80,7 +80,8 @@ import android.widget.Toast; import com.android.camera.ImageManager.IImageList; -public class Camera extends Activity implements View.OnClickListener, SurfaceHolder.Callback { +public class Camera extends Activity implements View.OnClickListener, + ShutterButton.OnShutterButtonListener, SurfaceHolder.Callback { private static final String TAG = "camera"; @@ -110,51 +111,51 @@ public class Camera extends Activity implements View.OnClickListener, SurfaceHol public static final int MENU_SAVE_CAMERA_DONE = 36; public static final int MENU_SAVE_CAMERA_VIDEO_DONE = 37; - Toast mToast; - OrientationListener mOrientationListener; - int mLastOrientation = OrientationListener.ORIENTATION_UNKNOWN; - SharedPreferences mPreferences; + private Toast mToast; + private OrientationListener mOrientationListener; + private int mLastOrientation = OrientationListener.ORIENTATION_UNKNOWN; + private SharedPreferences mPreferences; - static final int IDLE = 1; - static final int SNAPSHOT_IN_PROGRESS = 2; - static final int SNAPSHOT_COMPLETED = 3; + private static final int IDLE = 1; + private static final int SNAPSHOT_IN_PROGRESS = 2; + private static final int SNAPSHOT_COMPLETED = 3; - int mStatus = IDLE; - static final String sTempCropFilename = "crop-temp"; + private int mStatus = IDLE; + private static final String sTempCropFilename = "crop-temp"; - android.hardware.Camera mCameraDevice; - VideoPreview mSurfaceView; - SurfaceHolder mSurfaceHolder = null; - ImageView mBlackout = null; + private android.hardware.Camera mCameraDevice; + private VideoPreview mSurfaceView; + private SurfaceHolder mSurfaceHolder = null; + private ImageView mBlackout = null; - int mOriginalViewFinderWidth, mOriginalViewFinderHeight; - int mViewFinderWidth, mViewFinderHeight; - boolean mPreviewing = false; + private int mOriginalViewFinderWidth, mOriginalViewFinderHeight; + private int mViewFinderWidth, mViewFinderHeight; + private boolean mPreviewing = false; - MediaPlayer mClickSound; + private MediaPlayer mClickSound; - Capturer mCaptureObject; - ImageCapture mImageCapture = null; + private Capturer mCaptureObject; + private ImageCapture mImageCapture = null; - boolean mPausing = false; + private boolean mPausing = false; - boolean mIsFocusing = false; - boolean mIsFocused = false; - boolean mIsFocusButtonPressed = false; - boolean mCaptureOnFocus = false; + private boolean mIsFocusing = false; + private boolean mIsFocused = false; + private boolean mIsFocusButtonPressed = false; + private boolean mCaptureOnFocus = false; - static ContentResolver mContentResolver; - boolean mDidRegister = false; + private static ContentResolver mContentResolver; + private boolean mDidRegister = false; - int mCurrentZoomIndex = 0; + private ArrayList<MenuItem> mGalleryItems = new ArrayList<MenuItem>(); - ArrayList<MenuItem> mGalleryItems = new ArrayList<MenuItem>(); + private boolean mMenuSelectionMade; - boolean mMenuSelectionMade; + private ImageView mLastPictureButton; + private Uri mLastPictureUri; + private LocationManager mLocationManager = null; - ImageView mLastPictureButton; - Uri mLastPictureUri; - LocationManager mLocationManager = null; + private ShutterButton mShutterButton; private Animation mFocusBlinkAnimation; private View mFocusIndicator; @@ -172,7 +173,7 @@ public class Camera extends Activity implements View.OnClickListener, SurfaceHol private Handler mHandler = new MainHandler(); private ProgressDialog mSavingProgress; - interface Capturer { + private interface Capturer { Uri getLastCaptureUri(); void onSnap(); void dismissFreezeFrame(boolean keep); @@ -466,7 +467,7 @@ public class Camera extends Activity implements View.OnClickListener, SurfaceHol } public void storeImage(byte[] data, android.hardware.Camera camera, Location loc) { - boolean captureOnly = isPickIntent(); + boolean captureOnly = isImageCaptureIntent(); if (!captureOnly) { storeImage(data, loc); @@ -662,7 +663,7 @@ public class Camera extends Activity implements View.OnClickListener, SurfaceHol mKeepAndRestartPreview = true; - boolean getContentAction = isPickIntent(); + boolean getContentAction = isImageCaptureIntent(); if (getContentAction) { mImageCapture.initiate(true); } else { @@ -743,7 +744,8 @@ public class Camera extends Activity implements View.OnClickListener, SurfaceHol mLastPictureButton.setOnClickListener(this); mLastPictureButton.setVisibility(View.INVISIBLE); - findViewById(R.id.mode_indicator).setOnClickListener(this); + mShutterButton = (ShutterButton) findViewById(R.id.mode_indicator); + mShutterButton.setOnShutterButtonListener(this); try { mClickSound = new MediaPlayer(); @@ -817,15 +819,28 @@ public class Camera extends Activity implements View.OnClickListener, SurfaceHol public void onClick(View v) { switch (v.getId()) { - case R.id.mode_indicator: - doSnap(true); - break; case R.id.last_picture_button: viewLastImage(); break; } } + public void onShutterButtonFocus(ShutterButton button, boolean pressed) { + switch (button.getId()) { + case R.id.mode_indicator: + doFocus(pressed); + break; + } + } + + public void onShutterButtonClick(ShutterButton button) { + switch (button.getId()) { + case R.id.mode_indicator: + doSnap(false); + break; + } + } + private void showStorageToast() { MenuHelper.showStorageToast(this); } @@ -987,20 +1002,13 @@ public class Camera extends Activity implements View.OnClickListener, SurfaceHol } break; case KeyEvent.KEYCODE_FOCUS: - mIsFocusButtonPressed = true; if (event.getRepeatCount() == 0) { - if (mPreviewing) { - autoFocus(); - } else if (mCaptureObject != null) { - // Save and restart preview - mCaptureObject.onSnap(); - } + doFocus(true); } return true; case KeyEvent.KEYCODE_CAMERA: - case KeyEvent.KEYCODE_DPAD_CENTER: if (event.getRepeatCount() == 0) { - doSnap(keyCode == KeyEvent.KEYCODE_DPAD_CENTER); + doSnap(false); } return true; } @@ -1012,8 +1020,7 @@ public class Camera extends Activity implements View.OnClickListener, SurfaceHol public boolean onKeyUp(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_FOCUS: - clearFocus(); - updateFocusIndicator(); + doFocus(false); return true; } return super.onKeyUp(keyCode, event); @@ -1043,6 +1050,21 @@ public class Camera extends Activity implements View.OnClickListener, SurfaceHol } } + private void doFocus(boolean pressed) { + if (pressed) { + mIsFocusButtonPressed = true; + if (mPreviewing) { + autoFocus(); + } else if (mCaptureObject != null) { + // Save and restart preview + mCaptureObject.onSnap(); + } + } else { + clearFocus(); + updateFocusIndicator(); + } + } + public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { // if we're creating the surface, start the preview as well. boolean preview = holder.isCreating(); @@ -1386,16 +1408,16 @@ public class Camera extends Activity implements View.OnClickListener, SurfaceHol return true; } - private boolean isPickIntent() { + private boolean isImageCaptureIntent() { String action = getIntent().getAction(); - return (Intent.ACTION_PICK.equals(action) || MediaStore.ACTION_IMAGE_CAPTURE.equals(action)); + return (MediaStore.ACTION_IMAGE_CAPTURE.equals(action)); } @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); - if (isPickIntent()) { + if (isImageCaptureIntent()) { menu.add(MenuHelper.IMAGE_SAVING_ITEM, MENU_SAVE_SELECT_PHOTOS , 0, R.string.camera_selectphoto).setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { Bitmap bitmap = mImageCapture.getLastBitmap(); @@ -1406,7 +1428,7 @@ public class Camera extends Activity implements View.OnClickListener, SurfaceHol Bundle myExtras = getIntent().getExtras(); if (myExtras != null) { - saveUri = (Uri) myExtras.getParcelable("output"); + saveUri = (Uri) myExtras.getParcelable(MediaStore.EXTRA_OUTPUT); cropValue = myExtras.getString("crop"); } @@ -1486,7 +1508,7 @@ public class Camera extends Activity implements View.OnClickListener, SurfaceHol if (cropValue.equals("circle")) newExtras.putString("circleCrop", "true"); if (saveUri != null) - newExtras.putParcelable("output", saveUri); + newExtras.putParcelable(MediaStore.EXTRA_OUTPUT, saveUri); else newExtras.putBoolean("return-data", true); diff --git a/src/com/android/camera/CropImage.java b/src/com/android/camera/CropImage.java index 489c644..9542ce0 100644 --- a/src/com/android/camera/CropImage.java +++ b/src/com/android/camera/CropImage.java @@ -35,6 +35,7 @@ import android.media.FaceDetector; import android.net.Uri; import android.os.Bundle; import android.os.Handler; +import android.provider.MediaStore; import android.util.AttributeSet; import android.util.Config; import android.util.Log; @@ -361,7 +362,7 @@ public class CropImage extends Activity { mAspectX = 1; mAspectY = 1; } - mSaveUri = (Uri) extras.getParcelable("output"); + mSaveUri = (Uri) extras.getParcelable(MediaStore.EXTRA_OUTPUT); if (mSaveUri != null) { String compressFormatString = extras.getString("outputFormat"); if (compressFormatString != null) diff --git a/src/com/android/camera/ImageManager.java b/src/com/android/camera/ImageManager.java index 4ceedb8..4354e92 100755 --- a/src/com/android/camera/ImageManager.java +++ b/src/com/android/camera/ImageManager.java @@ -1042,8 +1042,14 @@ public class ImageManager { retriever.setMode(MediaMetadataRetriever.MODE_CAPTURE_FRAME_ONLY); retriever.setDataSource(filePath); bitmap = retriever.captureFrame(); + } catch (RuntimeException ex) { + // Assume this is a corrupt video file. } finally { - retriever.release(); + try { + retriever.release(); + } catch (RuntimeException ex) { + // Ignore failures while cleaning up. + } } return bitmap; } diff --git a/src/com/android/camera/MenuHelper.java b/src/com/android/camera/MenuHelper.java index 034c441..1976444 100644 --- a/src/com/android/camera/MenuHelper.java +++ b/src/com/android/camera/MenuHelper.java @@ -290,74 +290,84 @@ public class MenuHelper { d.findViewById(R.id.details_codec_row).setVisibility(View.GONE); } else { MediaMetadataRetriever retriever = new MediaMetadataRetriever(); - retriever.setMode(MediaMetadataRetriever.MODE_GET_METADATA_ONLY); - retriever.setDataSource(image.getDataPath()); try { - dimensionWidth = Integer.parseInt( - retriever.extractMetadata( - MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH)); - dimensionHeight = Integer.parseInt( - retriever.extractMetadata( - MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT)); - } catch (NumberFormatException e) { - dimensionWidth = 0; - dimensionHeight = 0; - } - - try { - int durationMs = Integer.parseInt(retriever.extractMetadata( - MediaMetadataRetriever.METADATA_KEY_DURATION)); - String durationValue = formatDuration( - activity, durationMs); - ((TextView)d.findViewById(R.id.details_duration_value)) - .setText(durationValue); - } catch (NumberFormatException e) { - d.findViewById(R.id.details_frame_rate_row) - .setVisibility(View.GONE); - } + retriever.setMode(MediaMetadataRetriever.MODE_GET_METADATA_ONLY); + retriever.setDataSource(image.getDataPath()); + try { + dimensionWidth = Integer.parseInt( + retriever.extractMetadata( + MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH)); + dimensionHeight = Integer.parseInt( + retriever.extractMetadata( + MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT)); + } catch (NumberFormatException e) { + dimensionWidth = 0; + dimensionHeight = 0; + } - try { - String frame_rate = String.format( - activity.getString(R.string.details_fps), - Integer.parseInt( - retriever.extractMetadata( - MediaMetadataRetriever.METADATA_KEY_FRAME_RATE))); - ((TextView)d.findViewById(R.id.details_frame_rate_value)) - .setText(frame_rate); - } catch (NumberFormatException e) { - d.findViewById(R.id.details_frame_rate_row) - .setVisibility(View.GONE); - } + try { + int durationMs = Integer.parseInt(retriever.extractMetadata( + MediaMetadataRetriever.METADATA_KEY_DURATION)); + String durationValue = formatDuration( + activity, durationMs); + ((TextView)d.findViewById(R.id.details_duration_value)) + .setText(durationValue); + } catch (NumberFormatException e) { + d.findViewById(R.id.details_frame_rate_row) + .setVisibility(View.GONE); + } - try { - long bitRate = Long.parseLong(retriever.extractMetadata( - MediaMetadataRetriever.METADATA_KEY_BIT_RATE)); - String bps; - if (bitRate < 1000000) { - bps = String.format( - activity.getString(R.string.details_kbps), - bitRate / 1000); - } else { - bps = String.format( - activity.getString(R.string.details_mbps), - ((double) bitRate) / 1000000.0); + try { + String frame_rate = String.format( + activity.getString(R.string.details_fps), + Integer.parseInt( + retriever.extractMetadata( + MediaMetadataRetriever.METADATA_KEY_FRAME_RATE))); + ((TextView)d.findViewById(R.id.details_frame_rate_value)) + .setText(frame_rate); + } catch (NumberFormatException e) { + d.findViewById(R.id.details_frame_rate_row) + .setVisibility(View.GONE); } - ((TextView)d.findViewById(R.id.details_bit_rate_value)) - .setText(bps); - } catch (NumberFormatException e) { - d.findViewById(R.id.details_bit_rate_row) - .setVisibility(View.GONE); - } - String format = retriever.extractMetadata( - MediaMetadataRetriever.METADATA_KEY_VIDEO_FORMAT); - ((TextView)d.findViewById(R.id.details_format_value)) - .setText(format); + try { + long bitRate = Long.parseLong(retriever.extractMetadata( + MediaMetadataRetriever.METADATA_KEY_BIT_RATE)); + String bps; + if (bitRate < 1000000) { + bps = String.format( + activity.getString(R.string.details_kbps), + bitRate / 1000); + } else { + bps = String.format( + activity.getString(R.string.details_mbps), + ((double) bitRate) / 1000000.0); + } + ((TextView)d.findViewById(R.id.details_bit_rate_value)) + .setText(bps); + } catch (NumberFormatException e) { + d.findViewById(R.id.details_bit_rate_row) + .setVisibility(View.GONE); + } - String codec = retriever.extractMetadata( - MediaMetadataRetriever.METADATA_KEY_CODEC); - ((TextView)d.findViewById(R.id.details_codec_value)) - .setText(codec); + String format = retriever.extractMetadata( + MediaMetadataRetriever.METADATA_KEY_VIDEO_FORMAT); + ((TextView)d.findViewById(R.id.details_format_value)) + .setText(format); + + String codec = retriever.extractMetadata( + MediaMetadataRetriever.METADATA_KEY_CODEC); + ((TextView)d.findViewById(R.id.details_codec_value)) + .setText(codec); + } catch(RuntimeException ex) { + // Assume this is a corrupt video file. + } finally { + try { + retriever.release(); + } catch (RuntimeException ex) { + // Ignore failures while cleaning up. + } + } } String dimensionsString = String.format( @@ -512,6 +522,7 @@ public class MenuHelper { static void gotoStillImageCapture(Activity activity) { Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); try { activity.startActivity(intent); } catch (ActivityNotFoundException e) { diff --git a/src/com/android/camera/ShutterButton.java b/src/com/android/camera/ShutterButton.java new file mode 100644 index 0000000..bd8d042 --- /dev/null +++ b/src/com/android/camera/ShutterButton.java @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.camera; + +import android.content.Context; +import android.util.AttributeSet; +import android.widget.ImageView; + +/** + * A button designed to be used for the on-screen shutter button. + * It's currently an ImageView that can call a delegate when the pressed state changes. + */ +public class ShutterButton extends ImageView { + /** + * Interface definition for a callback to be invoked when a ModeButton's pressed state changes. + */ + public interface OnShutterButtonListener { + /** + * Called when a ShutterButton has been pressed. + * + * @param b The ShutterButton that was pressed. + */ + void onShutterButtonFocus(ShutterButton b, boolean pressed); + void onShutterButtonClick(ShutterButton b); + } + + private OnShutterButtonListener mListener; + private boolean mOldPressed; + + public ShutterButton(Context context) { + super(context); + } + + public ShutterButton(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public ShutterButton(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + public void setOnShutterButtonListener(OnShutterButtonListener listener) { + mListener = listener; + } + + /** + * Hook into the drawable state changing to get changes to isPressed -- the + * onPressed listener doesn't always get called when the pressed state changes. + */ + @Override + protected void drawableStateChanged() { + super.drawableStateChanged(); + final boolean pressed = isPressed(); + if (pressed != mOldPressed) { + if (!pressed) { + // When pressing the physical camera button the sequence of events is: + // focus pressed, optional camera pressed, focus released. + // We want to emulate this sequence of events with the shutter button. + // When clicking using a trackball button, the view system changes + // the the drawable state before posting click notification, so the + // sequence of events is: + // pressed(true), optional click, pressed(false) + // When clicking using touch events, the view system changes the + // drawable state after posting click notification, so the sequence of + // events is: + // pressed(true), pressed(false), optional click + // Since we're emulating the physical camera button, we want to have the + // same order of events. So we want the optional click callback to be delivered + // before the pressed(false) callback. + // + // To do this, we delay the posting of the pressed(false) event slightly by + // pushing it on the event queue. This moves it after the optional click + // notification, so our client always sees events in this sequence: + // pressed(true), optional click, pressed(false) + post(new Runnable() { + public void run() { + callShutterButtonFocus(pressed); + } + }); + } else { + callShutterButtonFocus(pressed); + } + mOldPressed = pressed; + } + } + + private void callShutterButtonFocus(boolean pressed) { + if (mListener != null) { + mListener.onShutterButtonFocus(this, pressed); + } + } + + @Override + public boolean performClick() { + boolean result = super.performClick(); + if (mListener != null) { + mListener.onShutterButtonClick(this); + } + return result; + } +} diff --git a/src/com/android/camera/VideoCamera.java b/src/com/android/camera/VideoCamera.java index 2880ec1..4828b71 100644 --- a/src/com/android/camera/VideoCamera.java +++ b/src/com/android/camera/VideoCamera.java @@ -18,6 +18,8 @@ package com.android.camera; import java.io.File; import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.util.ArrayList; import android.app.Activity; @@ -32,6 +34,7 @@ import android.content.IntentFilter; import android.content.SharedPreferences; import android.graphics.Bitmap; import android.graphics.drawable.ColorDrawable; +import android.graphics.drawable.Drawable; import android.location.LocationManager; import android.media.MediaMetadataRetriever; import android.media.MediaRecorder; @@ -117,7 +120,6 @@ public class VideoCamera extends Activity implements View.OnClickListener, Surfa int mCurrentZoomIndex = 0; private ImageView mModeIndicatorView; - private ImageView mRecordingIndicatorView; private TextView mRecordingTimeView; ArrayList<MenuItem> mGalleryItems = new ArrayList<MenuItem>(); @@ -234,14 +236,12 @@ public class VideoCamera extends Activity implements View.OnClickListener, Surfa mPostPictureAlert = findViewById(R.id.post_picture_panel); int[] ids = new int[]{R.id.play, R.id.share, R.id.discard, - R.id.cancel, R.id.attach, R.id.mode_indicator, - R.id.recording_indicator}; + R.id.cancel, R.id.attach, R.id.mode_indicator}; for (int id : ids) { findViewById(id).setOnClickListener(this); } mModeIndicatorView = (ImageView) findViewById(R.id.mode_indicator); - mRecordingIndicatorView = (ImageView) findViewById(R.id.recording_indicator); mRecordingTimeView = (TextView) findViewById(R.id.recording_time); mVideoFrame = (ImageView) findViewById(R.id.video_frame); } @@ -295,11 +295,11 @@ public class VideoCamera extends Activity implements View.OnClickListener, Surfa switch (v.getId()) { case R.id.attach: - doReturnToPicker(true); + doReturnToCaller(true); break; case R.id.cancel: - doReturnToPicker(false); + doReturnToCaller(false); break; case R.id.discard: { @@ -327,21 +327,19 @@ public class VideoCamera extends Activity implements View.OnClickListener, Surfa } case R.id.mode_indicator: - if (mVideoFrame.getVisibility() == View.VISIBLE) { + if (mMediaRecorderRecording) { + stopVideoRecordingAndDisplayDialog(); + } else if (mVideoFrame.getVisibility() == View.VISIBLE) { doStartCaptureMode(); } else { startVideoRecording(); } break; - - case R.id.recording_indicator: - stopVideoRecordingAndDisplayDialog(); - break; } } private void doStartCaptureMode() { - if (isPickIntent()) { + if (isVideoCaptureIntent()) { discardCurrentVideoAndStartPreview(); } else { hideVideoFrameAndStartPreview(); @@ -465,7 +463,6 @@ public class VideoCamera extends Activity implements View.OnClickListener, Surfa stopVideoRecordingAndDisplayDialog(); return true; } - hideVideoFrameAndStartPreview(); break; } @@ -545,17 +542,63 @@ public class VideoCamera extends Activity implements View.OnClickListener, Surfa return true; } - private boolean isPickIntent() { + private boolean isVideoCaptureIntent() { String action = getIntent().getAction(); - return (Intent.ACTION_PICK.equals(action) || MediaStore.ACTION_VIDEO_CAPTURE.equals(action)); + return (MediaStore.ACTION_VIDEO_CAPTURE.equals(action)); } - private void doReturnToPicker(boolean success) { + private void doReturnToCaller(boolean success) { Intent resultIntent = new Intent(); int resultCode; if (success) { resultCode = RESULT_OK; - resultIntent.setData(mCurrentVideoUri); + Uri saveUri = null; + + Bundle myExtras = getIntent().getExtras(); + if (myExtras != null) { + saveUri = (Uri) myExtras.getParcelable(MediaStore.EXTRA_OUTPUT); + } + + if (saveUri != null) { + // TODO: Record the video directly into the content provider stream when + // bug 1582062 is fixed. Until then we copy the video data from the + // original location to the requested location and then delete the original. + OutputStream outputStream = null; + InputStream inputStream = null; + + try { + inputStream = mContentResolver.openInputStream(mCurrentVideoUri); + outputStream = mContentResolver.openOutputStream(saveUri); + byte[] buffer = new byte[64*1024]; + while(true) { + int bytesRead = inputStream.read(buffer); + if (bytesRead < 0) { + break; + } + outputStream.write(buffer, 0, bytesRead); + } + } catch (IOException ex) { + Log.e(TAG, "Could not copy video file to Uri", ex); + } finally { + if (inputStream != null) { + try { + inputStream.close(); + } catch (IOException ex) { + Log.e(TAG, "Could not close video file", ex); + } + } + if (outputStream != null) { + try { + outputStream.close(); + } catch (IOException ex) { + Log.e(TAG, "Could not close output uri", ex); + } + } + deleteCurrentVideo(); + } + } else { + resultIntent.setData(mCurrentVideoUri); + } } else { resultCode = RESULT_CANCELED; } @@ -779,14 +822,20 @@ public class VideoCamera extends Activity implements View.OnClickListener, Surfa } mMediaRecorderRecording = true; mRecordingStartTime = SystemClock.uptimeMillis(); - mModeIndicatorView.setVisibility(View.GONE); - mRecordingIndicatorView.setVisibility(View.VISIBLE); + updateRecordingIndicator(true); mRecordingTimeView.setText(""); mRecordingTimeView.setVisibility(View.VISIBLE); mHandler.sendEmptyMessage(UPDATE_RECORD_TIME); } } + private void updateRecordingIndicator(boolean showRecording) { + int drawableId = showRecording ? R.drawable.ic_camera_bar_indicator_record + : R.drawable.ic_camera_indicator_video; + Drawable drawable = getResources().getDrawable(drawableId); + mModeIndicatorView.setImageDrawable(drawable); + } + private void stopVideoRecordingAndDisplayDialog() { Log.v(TAG, "stopVideoRecordingAndDisplayDialog"); if (mMediaRecorderRecording) { @@ -797,7 +846,7 @@ public class VideoCamera extends Activity implements View.OnClickListener, Surfa } private void showPostRecordingAlert() { - boolean isPick = isPickIntent(); + boolean isPick = isVideoCaptureIntent(); int pickVisible = isPick ? View.VISIBLE : View.GONE; int normalVisible = ! isPick ? View.VISIBLE : View.GONE; mPostPictureAlert.findViewById(R.id.share).setVisibility(normalVisible); @@ -827,8 +876,7 @@ public class VideoCamera extends Activity implements View.OnClickListener, Surfa mMediaRecorderRecording = false; } releaseMediaRecorder(); - mModeIndicatorView.setVisibility(View.VISIBLE); - mRecordingIndicatorView.setVisibility(View.GONE); + updateRecordingIndicator(false); mRecordingTimeView.setVisibility(View.GONE); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } diff --git a/src/com/android/camera/Wallpaper.java b/src/com/android/camera/Wallpaper.java index 1cc12fb..5c7d0e5 100644 --- a/src/com/android/camera/Wallpaper.java +++ b/src/com/android/camera/Wallpaper.java @@ -27,6 +27,7 @@ import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.os.Message; +import android.provider.MediaStore; import android.util.Log; import java.io.IOException; @@ -42,13 +43,13 @@ public class Wallpaper extends Activity { private static final String LOG_TAG = "Camera"; static final int PHOTO_PICKED = 1; static final int CROP_DONE = 2; - + static final int SHOW_PROGRESS = 0; static final int FINISH = 1; - + static final String sDoLaunchIcicle = "do_launch"; static final String sTempFilePathIcicle = "temp_file_path"; - + private ProgressDialog mProgressDialog = null; private boolean mDoLaunch = true; private String mTempFilePath; @@ -62,7 +63,7 @@ public class Wallpaper extends Activity { mProgressDialog = ProgressDialog.show(Wallpaper.this, "", c, true, false); break; } - + case FINISH: { closeProgressDialog(); setResult(RESULT_OK); @@ -72,20 +73,20 @@ public class Wallpaper extends Activity { } } }; - + static class SetWallpaperThread extends Thread { private final Bitmap mBitmap; private final Handler mHandler; private final Context mContext; private final File mFile; - + public SetWallpaperThread(Bitmap bitmap, Handler handler, Context context, File file) { mBitmap = bitmap; mHandler = handler; mContext = context; mFile = file; } - + @Override public void run() { try { @@ -98,14 +99,14 @@ public class Wallpaper extends Activity { } } } - + private synchronized void closeProgressDialog() { if (mProgressDialog != null) { mProgressDialog.dismiss(); mProgressDialog = null; - } + } } - + @Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); @@ -114,23 +115,23 @@ public class Wallpaper extends Activity { mTempFilePath = icicle.getString(sTempFilePathIcicle); } } - + @Override protected void onSaveInstanceState(Bundle icicle) { icicle.putBoolean(sDoLaunchIcicle, mDoLaunch); icicle.putString(sTempFilePathIcicle, mTempFilePath); } - + @Override protected void onPause() { closeProgressDialog(); super.onPause(); } - + @Override protected void onResume() { super.onResume(); - + if (!mDoLaunch) { return; } @@ -149,7 +150,7 @@ public class Wallpaper extends Activity { startActivityForResult(intent, PHOTO_PICKED); } } - + protected void formatIntent(Intent intent) { // TODO: A temporary file is NOT necessary // The CropImage intent should be able to set the wallpaper directly @@ -159,16 +160,16 @@ public class Wallpaper extends Activity { (new File(f.getParent())).mkdirs(); mTempFilePath = f.toString(); f.delete(); - + int width = getWallpaperDesiredMinimumWidth(); int height = getWallpaperDesiredMinimumHeight(); intent.putExtra("outputX", width); intent.putExtra("outputY", height); intent.putExtra("aspectX", width); intent.putExtra("aspectY", height); - intent.putExtra("scale", true); + intent.putExtra("scale", true); intent.putExtra("noFaceDetection", true); - intent.putExtra("output", Uri.parse("file:/" + mTempFilePath)); + intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.parse("file:/" + mTempFilePath)); intent.putExtra("outputFormat", Bitmap.CompressFormat.PNG.name()); // TODO: we should have an extra called "setWallpaper" to ask CropImage to // set the cropped image as a wallpaper directly @@ -193,9 +194,9 @@ public class Wallpaper extends Activity { } mDoLaunch = false; } catch (FileNotFoundException ex) { - + } catch (IOException ex) { - + } } else { setResult(RESULT_CANCELED); |