From a72d73cbac59db43d413291e4db66763be08143a Mon Sep 17 00:00:00 2001 From: repo sync Date: Wed, 27 Jul 2011 19:29:41 +0800 Subject: Add mode picker for camera/camcorder/panaramo +remove camera switcher +add menu item for panorama bug:5039225 Change-Id: Ib065074026760f7dc1bd1dfe694935f46bb8c407 --- res/drawable-hdpi/btn_ic_camera.png | Bin 0 -> 756 bytes res/drawable-hdpi/btn_ic_panorama.png | Bin 0 -> 1379 bytes res/drawable-hdpi/btn_ic_video.png | Bin 0 -> 389 bytes res/drawable-hdpi/btn_mode_background.png | Bin 0 -> 460 bytes res/drawable-mdpi/btn_ic_camera.png | Bin 0 -> 756 bytes res/drawable-mdpi/btn_ic_panorama.png | Bin 0 -> 1379 bytes res/drawable-mdpi/btn_ic_video.png | Bin 0 -> 389 bytes res/drawable-mdpi/btn_mode_background.png | Bin 0 -> 460 bytes res/layout-w1024dp/camera_control.xml | 30 +-- res/layout-w1024dp/mode_picker.xml | 54 ++++++ res/layout-w1024dp/pano_control.xml | 37 ++++ res/layout/camera_control.xml | 26 +-- res/layout/mode_picker.xml | 50 +++++ res/layout/pano_control.xml | 2 + res/layout/panorama.xml | 4 +- res/values/strings.xml | 10 +- src/com/android/camera/Camera.java | 54 +++--- src/com/android/camera/HorizontalSwitcher.java | 53 ------ src/com/android/camera/MenuHelper.java | 58 ++++-- src/com/android/camera/ModePicker.java | 158 ++++++++++++++++ src/com/android/camera/Switcher.java | 205 --------------------- src/com/android/camera/SwitcherSet.java | 105 ----------- src/com/android/camera/VideoCamera.java | 49 +++-- .../android/camera/panorama/PanoramaActivity.java | 25 ++- 24 files changed, 429 insertions(+), 491 deletions(-) create mode 100644 res/drawable-hdpi/btn_ic_camera.png create mode 100644 res/drawable-hdpi/btn_ic_panorama.png create mode 100644 res/drawable-hdpi/btn_ic_video.png create mode 100644 res/drawable-hdpi/btn_mode_background.png create mode 100644 res/drawable-mdpi/btn_ic_camera.png create mode 100644 res/drawable-mdpi/btn_ic_panorama.png create mode 100644 res/drawable-mdpi/btn_ic_video.png create mode 100644 res/drawable-mdpi/btn_mode_background.png create mode 100644 res/layout-w1024dp/mode_picker.xml create mode 100644 res/layout-w1024dp/pano_control.xml create mode 100644 res/layout/mode_picker.xml delete mode 100644 src/com/android/camera/HorizontalSwitcher.java create mode 100644 src/com/android/camera/ModePicker.java delete mode 100644 src/com/android/camera/Switcher.java delete mode 100644 src/com/android/camera/SwitcherSet.java diff --git a/res/drawable-hdpi/btn_ic_camera.png b/res/drawable-hdpi/btn_ic_camera.png new file mode 100644 index 0000000..cc6610f Binary files /dev/null and b/res/drawable-hdpi/btn_ic_camera.png differ diff --git a/res/drawable-hdpi/btn_ic_panorama.png b/res/drawable-hdpi/btn_ic_panorama.png new file mode 100644 index 0000000..e4db1ff Binary files /dev/null and b/res/drawable-hdpi/btn_ic_panorama.png differ diff --git a/res/drawable-hdpi/btn_ic_video.png b/res/drawable-hdpi/btn_ic_video.png new file mode 100644 index 0000000..dacc261 Binary files /dev/null and b/res/drawable-hdpi/btn_ic_video.png differ diff --git a/res/drawable-hdpi/btn_mode_background.png b/res/drawable-hdpi/btn_mode_background.png new file mode 100644 index 0000000..cd0c34e Binary files /dev/null and b/res/drawable-hdpi/btn_mode_background.png differ diff --git a/res/drawable-mdpi/btn_ic_camera.png b/res/drawable-mdpi/btn_ic_camera.png new file mode 100644 index 0000000..cc6610f Binary files /dev/null and b/res/drawable-mdpi/btn_ic_camera.png differ diff --git a/res/drawable-mdpi/btn_ic_panorama.png b/res/drawable-mdpi/btn_ic_panorama.png new file mode 100644 index 0000000..e4db1ff Binary files /dev/null and b/res/drawable-mdpi/btn_ic_panorama.png differ diff --git a/res/drawable-mdpi/btn_ic_video.png b/res/drawable-mdpi/btn_ic_video.png new file mode 100644 index 0000000..dacc261 Binary files /dev/null and b/res/drawable-mdpi/btn_ic_video.png differ diff --git a/res/drawable-mdpi/btn_mode_background.png b/res/drawable-mdpi/btn_mode_background.png new file mode 100644 index 0000000..cd0c34e Binary files /dev/null and b/res/drawable-mdpi/btn_mode_background.png differ diff --git a/res/layout-w1024dp/camera_control.xml b/res/layout-w1024dp/camera_control.xml index 5c2b3b5..2bcc6e5 100644 --- a/res/layout-w1024dp/camera_control.xml +++ b/res/layout-w1024dp/camera_control.xml @@ -60,34 +60,6 @@ android:layout_height="wrap_content" /> - - - - - + diff --git a/res/layout-w1024dp/mode_picker.xml b/res/layout-w1024dp/mode_picker.xml new file mode 100644 index 0000000..90cc008 --- /dev/null +++ b/res/layout-w1024dp/mode_picker.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + diff --git a/res/layout-w1024dp/pano_control.xml b/res/layout-w1024dp/pano_control.xml new file mode 100644 index 0000000..1882ff6 --- /dev/null +++ b/res/layout-w1024dp/pano_control.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + diff --git a/res/layout/camera_control.xml b/res/layout/camera_control.xml index f2790fb..283f77b 100644 --- a/res/layout/camera_control.xml +++ b/res/layout/camera_control.xml @@ -17,7 +17,7 @@ @@ -32,26 +32,6 @@ android:src="@drawable/btn_ic_camera_shutter" android:background="@drawable/btn_shutter"/> - - - - - + + diff --git a/res/layout/mode_picker.xml b/res/layout/mode_picker.xml new file mode 100644 index 0000000..f9f8530 --- /dev/null +++ b/res/layout/mode_picker.xml @@ -0,0 +1,50 @@ + + + + + + + + + + diff --git a/res/layout/pano_control.xml b/res/layout/pano_control.xml index 530ffc6..0faa595 100644 --- a/res/layout/pano_control.xml +++ b/res/layout/pano_control.xml @@ -29,4 +29,6 @@ android:focusable="true" android:src="@drawable/btn_ic_camera_shutter" android:background="@drawable/btn_shutter"/> + + diff --git a/res/layout/panorama.xml b/res/layout/panorama.xml index b92d81d..30f0bd7 100644 --- a/res/layout/panorama.xml +++ b/res/layout/panorama.xml @@ -14,7 +14,7 @@ limitations under the License. --> - - + diff --git a/res/values/strings.xml b/res/values/strings.xml index 8772f3a..f1758bd 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -283,8 +283,14 @@ Zoom %s - Switch to camera - Switch to video + + Switch to camera + + + Switch to video + + + Switch to panorama > < diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java index f7ceb7c..ed168df 100644 --- a/src/com/android/camera/Camera.java +++ b/src/com/android/camera/Camera.java @@ -92,7 +92,7 @@ import java.util.List; /** The Camera activity which can preview and take pictures. */ public class Camera extends ActivityBase implements View.OnClickListener, View.OnTouchListener, ShutterButton.OnShutterButtonListener, - SurfaceHolder.Callback, Switcher.OnSwitchListener { + SurfaceHolder.Callback, ModePicker.OnModeChangeListener { private static final String TAG = "camera"; @@ -145,9 +145,6 @@ public class Camera extends ActivityBase implements View.OnClickListener, private int mOrientationCompensation = 0; private ComboPreferences mPreferences; - private static final boolean SWITCH_CAMERA = true; - private static final boolean SWITCH_VIDEO = false; - private static final String sTempCropFilename = "crop-temp"; private android.hardware.Camera mCameraDevice; @@ -156,7 +153,6 @@ public class Camera extends ActivityBase implements View.OnClickListener, private ShutterButton mShutterButton; private ToneGenerator mFocusToneGenerator; private GestureDetector mPopupGestureDetector; - private SwitcherSet mSwitcher; private boolean mOpenCameraFail = false; private boolean mCameraDisabled = false; @@ -178,8 +174,7 @@ public class Camera extends ActivityBase implements View.OnClickListener, // An imageview showing showing the last captured picture thumbnail. private RotateImageView mThumbnailView; private RotateImageView mShareIcon; - private RotateImageView mCameraSwitchIcon; - private RotateImageView mVideoSwitchIcon; + private ModePicker mModePicker; // mCropValue and mSaveUri are used only if isImageCaptureIntent() is true. private String mCropValue; @@ -384,7 +379,6 @@ public class Camera extends ActivityBase implements View.OnClickListener, // Initialize last picture button. mContentResolver = getContentResolver(); if (!mIsImageCaptureIntent) { // no thumbnail in image capture intent - findViewById(R.id.camera_switch).setOnClickListener(this); initThumbnailButton(); } @@ -470,7 +464,7 @@ public class Camera extends ActivityBase implements View.OnClickListener, if (!mIsImageCaptureIntent) { updateThumbnailButton(); - mSwitcher.setSwitch(SWITCH_CAMERA); + mModePicker.setCurrentMode(ModePicker.MODE_CAMERA); } } @@ -986,8 +980,6 @@ public class Camera extends ActivityBase implements View.OnClickListener, mShareButton = findViewById(R.id.share_button); mThumbnailView = (RotateImageView) findViewById(R.id.thumbnail); mShareIcon = (RotateImageView) findViewById(R.id.share_icon); - mCameraSwitchIcon = (RotateImageView) findViewById(R.id.camera_switch_icon); - mVideoSwitchIcon = (RotateImageView) findViewById(R.id.video_switch_icon); mPreferences = new ComboPreferences(this); CameraSettings.upgradeGlobalPreferences(mPreferences.getGlobal()); @@ -1044,10 +1036,10 @@ public class Camera extends ActivityBase implements View.OnClickListener, findViewById(R.id.btn_retake).setOnClickListener(this); findViewById(R.id.btn_done).setOnClickListener(this); } else { - mSwitcher = (SwitcherSet) findViewById(R.id.camera_switch); - mSwitcher.setVisibility(View.VISIBLE); - mSwitcher.setOnSwitchListener(this); - mSwitcher.setSwitch(SWITCH_CAMERA); + mModePicker = (ModePicker) findViewById(R.id.mode_picker); + mModePicker.setVisibility(View.VISIBLE); + mModePicker.setOnModeChangeListener(this); + mModePicker.setCurrentMode(ModePicker.MODE_CAMERA); } // Make sure preview is started. @@ -1199,7 +1191,7 @@ public class Camera extends ActivityBase implements View.OnClickListener, if (mIndicatorWheel != null) mIndicatorWheel.setEnabled(enable); if (mCameraPicker != null) mCameraPicker.setEnabled(enable); if (mZoomPicker != null) mZoomPicker.setEnabled(enable); - if (mSwitcher != null) mSwitcher.setEnabled(enable); + if (mModePicker != null) mModePicker.setEnabled(enable); } public static int roundOrientation(int orientation) { @@ -1236,8 +1228,7 @@ public class Camera extends ActivityBase implements View.OnClickListener, if (mHeadUpDisplay != null) mHeadUpDisplay.setOrientation(mOrientationCompensation); if (mThumbnailView != null) mThumbnailView.setDegree(degree); if (mShareIcon != null) mShareIcon.setDegree(degree); - if (mCameraSwitchIcon != null) mCameraSwitchIcon.setDegree(degree); - if (mVideoSwitchIcon != null) mVideoSwitchIcon.setDegree(degree); + if (mModePicker != null) mModePicker.setDegree(degree); if (mSharePopup != null) mSharePopup.setOrientation(degree); if (mIndicatorWheel != null) mIndicatorWheel.setDegree(degree); } @@ -2286,14 +2277,17 @@ public class Camera extends ActivityBase implements View.OnClickListener, } private void addBaseMenuItems(Menu menu) { - MenuHelper.addSwitchModeMenuItem(menu, true, new Runnable() { + MenuHelper.addSwitchModeMenuItem(menu, ModePicker.MODE_VIDEO, new Runnable() { + public void run() { + switchToOtherMode(ModePicker.MODE_VIDEO); + } + }); + MenuHelper.addSwitchModeMenuItem(menu, ModePicker.MODE_PANORAMA, new Runnable() { public void run() { - switchToVideoMode(); + switchToOtherMode(ModePicker.MODE_PANORAMA); } }); - MenuItem gallery = menu.add(Menu.NONE, Menu.NONE, - MenuHelper.POSITION_GOTO_GALLERY, - R.string.camera_gallery_photos_text) + MenuItem gallery = menu.add(R.string.camera_gallery_photos_text) .setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { gotoGallery(); @@ -2304,9 +2298,7 @@ public class Camera extends ActivityBase implements View.OnClickListener, mGalleryItems.add(gallery); if (mNumberOfCameras > 1) { - menu.add(Menu.NONE, Menu.NONE, - MenuHelper.POSITION_SWITCH_CAMERA_ID, - R.string.switch_camera_id) + menu.add(R.string.switch_camera_id) .setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { CameraSettings.writePreferredCameraId(mPreferences, @@ -2319,17 +2311,17 @@ public class Camera extends ActivityBase implements View.OnClickListener, } } - private boolean switchToVideoMode() { + private boolean switchToOtherMode(int mode) { if (isFinishing() || !isCameraIdle()) return false; - MenuHelper.gotoVideoMode(Camera.this); + MenuHelper.gotoMode(mode, Camera.this); mHandler.removeMessages(FIRST_TIME_INIT); finish(); return true; } - public boolean onSwitchChanged(Switcher source, boolean onOff) { - if (onOff == SWITCH_VIDEO) { - return switchToVideoMode(); + public boolean onModeChanged(int mode) { + if (mode != ModePicker.MODE_CAMERA) { + return switchToOtherMode(mode); } else { return true; } diff --git a/src/com/android/camera/HorizontalSwitcher.java b/src/com/android/camera/HorizontalSwitcher.java deleted file mode 100644 index de618b6..0000000 --- a/src/com/android/camera/HorizontalSwitcher.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2010 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.view.MotionEvent; -import android.util.AttributeSet; - -/** - * A (horizontal) widget which switches between the {@code Camera} and the - * {@code VideoCamera} activities. - */ -public class HorizontalSwitcher extends Switcher { - public HorizontalSwitcher(Context context, AttributeSet attrs) { - super(context, attrs); - } - - @Override - protected int getAvailableLength() { - return getWidth() - getPaddingLeft() - getPaddingRight() - - getDrawable().getIntrinsicWidth(); - } - - @Override - protected int trackTouch(MotionEvent event) { - return (int) event.getX() - getPaddingLeft() - - (getDrawable().getIntrinsicWidth() / 2); - } - - @Override - protected int getOffsetTopToDraw() { - return (getHeight() - getDrawable().getIntrinsicHeight()) / 2; - } - - @Override - protected int getOffsetLeftToDraw() { - return getPaddingLeft() + getLogicalPosition(); - } -} diff --git a/src/com/android/camera/MenuHelper.java b/src/com/android/camera/MenuHelper.java index 860a642..62bd3f8 100644 --- a/src/com/android/camera/MenuHelper.java +++ b/src/com/android/camera/MenuHelper.java @@ -43,12 +43,9 @@ public class MenuHelper { private static final int INCLUDE_IMAGES = (1 << 0); private static final int INCLUDE_VIDEOS = (1 << 2); - public static final int POSITION_SWITCH_CAMERA_MODE = 1; - public static final int POSITION_GOTO_GALLERY = 2; - public static final int POSITION_SWITCH_CAMERA_ID = 3; - private static final int NO_ANIMATION = 0; private static final String CAMERA_CLASS = "com.android.camera.Camera"; + private static final String PANORAMA_CLASS = "com.android.camera.panorama.PanoramaActivity"; private static final String VIDEO_CAMERA_CLASS = "com.android.camera.VideoCamera"; public static void confirmAction(Context context, String title, @@ -71,17 +68,28 @@ public class MenuHelper { .show(); } - static void addSwitchModeMenuItem(Menu menu, boolean switchToVideo, + static void addSwitchModeMenuItem(Menu menu, int mode, final Runnable r) { - int labelId = switchToVideo - ? R.string.switch_to_video_lable - : R.string.switch_to_camera_lable; - int iconId = switchToVideo - ? R.drawable.ic_menu_camera_video_view - : android.R.drawable.ic_menu_camera; - MenuItem item = menu.add(Menu.NONE, Menu.NONE, - POSITION_SWITCH_CAMERA_MODE, labelId) - .setOnMenuItemClickListener(new OnMenuItemClickListener() { + int labelId, iconId; + switch(mode) { + case ModePicker.MODE_VIDEO: + labelId = R.string.switch_to_video_label; + iconId = R.drawable.ic_menu_camera_video_view; + break; + case ModePicker.MODE_CAMERA: + labelId = R.string.switch_to_camera_label; + iconId = android.R.drawable.ic_menu_camera; + break; + case ModePicker.MODE_PANORAMA: + labelId = R.string.switch_to_panorama_label; + iconId = R.drawable.btn_ic_panorama; + break; + default: + // incorrect mode, do nothing. + return; + } + MenuItem item = menu.add(labelId).setOnMenuItemClickListener( + new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { r.run(); return true; @@ -109,6 +117,28 @@ public class MenuHelper { activity.overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); } + public static void gotoMode(int mode, Activity activity) { + String action, className; + switch (mode) { + case ModePicker.MODE_PANORAMA: + action = PANORAMA_CLASS; + className = PANORAMA_CLASS; + break; + case ModePicker.MODE_VIDEO: + action = MediaStore.INTENT_ACTION_VIDEO_CAMERA; + className = VIDEO_CAMERA_CLASS; + break; + case ModePicker.MODE_CAMERA: + action = MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA; + className = CAMERA_CLASS; + break; + default: + Log.e(TAG, "unknown camera mode:" + mode); + return; + } + startCameraActivity(activity, new Intent(action), className); + } + public static void gotoVideoMode(Activity activity) { Intent intent = new Intent(MediaStore.INTENT_ACTION_VIDEO_CAMERA); startCameraActivity(activity, intent, VIDEO_CAMERA_CLASS); diff --git a/src/com/android/camera/ModePicker.java b/src/com/android/camera/ModePicker.java new file mode 100644 index 0000000..594c813 --- /dev/null +++ b/src/com/android/camera/ModePicker.java @@ -0,0 +1,158 @@ +/* + * Copyright (C) 2011 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 com.android.camera.ui.RotateImageView; + +import android.content.Context; +import android.graphics.PorterDuff; +import android.graphics.drawable.Drawable; +import android.util.AttributeSet; +import android.view.MotionEvent; +import android.view.View; +import android.widget.ImageView; +import android.widget.RelativeLayout; + +/** + * A widget that includes three mode selections {@code RotateImageView}'s and + * a current mode indicator. + */ +public class ModePicker extends RelativeLayout implements View.OnClickListener { + public static final int MODE_PANORAMA = 0; + public static final int MODE_VIDEO = 1; + public static final int MODE_CAMERA = 2; + + /** A callback to be called when the user wants to switch activity. */ + public interface OnModeChangeListener { + // Returns true if the listener agrees that the mode can be changed. + public boolean onModeChanged(int newMode); + } + + private final int DISABLED_COLOR; + + private OnModeChangeListener mListener; + private View mModeIcons[] = new View[3]; + private View mCurrentModeIcon; + private View mModeSelection; + private int mCurrentMode = MODE_CAMERA; + private Context mContext; + + public ModePicker(Context context, AttributeSet attrs) { + super(context, attrs); + mContext = context; + DISABLED_COLOR = context.getResources().getColor(R.color.icon_disabled_color); + } + + protected void onFinishInflate() { + super.onFinishInflate(); + + mModeSelection = findViewById(R.id.mode_selection); + + mCurrentModeIcon = findViewById(R.id.current_mode); + mCurrentModeIcon.setOnClickListener(this); + + mModeIcons[MODE_PANORAMA] = findViewById(R.id.mode_panorama); + mModeIcons[MODE_VIDEO] = findViewById(R.id.mode_video); + mModeIcons[MODE_CAMERA] = findViewById(R.id.mode_camera); + } + + private void enableModeSelection(boolean enabled) { + mCurrentModeIcon.setVisibility(enabled ? View.INVISIBLE : View.VISIBLE); + mCurrentModeIcon.setOnClickListener(enabled ? null : this); + mModeSelection.setVisibility(enabled ? View.VISIBLE : View.INVISIBLE); + for (int i = 0; i < 3; ++i) { + mModeIcons[i].setOnClickListener(enabled ? this : null); + highlightCurrentMode(mModeIcons[i], (i == mCurrentMode)); + } + } + + public void onClick(View view) { + for (int i = 0; i < 3; ++i) { + if (view == mModeIcons[i]) { + setCurrentMode(i); + enableModeSelection(false); + return; + } + } + if (view == mCurrentModeIcon) enableModeSelection(true); + } + + private void setMode(int mode) { + for (int i = 0; i < 3; ++i) mModeIcons[i].setSelected(mode == i); + } + + public void setOnModeChangeListener(OnModeChangeListener listener) { + mListener = listener; + } + + public void setCurrentMode(int mode) { + setMode(mode); + tryToSetMode(mode); + } + + private void tryToSetMode(int mode) { + if (mListener != null) { + if (!mListener.onModeChanged(mode)) { + setMode(mCurrentMode); + return; + } + } + ((RotateImageView) mCurrentModeIcon).setImageDrawable( + ((RotateImageView) mModeIcons[mode]).getDrawable()); + mCurrentMode = mode; + } + + public boolean onModeChanged(int mode) { + setCurrentMode(mode); + return true; + } + + public void setDegree(int degree) { + for (int i = 0 ; i < 3 ; ++i) { + ((RotateImageView) mModeIcons[i]).setDegree(degree); + } + ((RotateImageView) mCurrentModeIcon).setDegree(degree); + } + + @Override + public void setEnabled(boolean enabled) { + super.setEnabled(enabled); + } + + private void highlightCurrentMode(View view, boolean enabled) { + Drawable drawable = ((ImageView) view).getDrawable(); + if (enabled) { + drawable.clearColorFilter(); + } else { + drawable.setColorFilter(DISABLED_COLOR, PorterDuff.Mode.SRC_ATOP); + } + } + + public void setEnabled(View view, boolean enabled) { + view.setEnabled(enabled); + + // render disabled effect for tablet only. + if (mContext.getResources().getConfiguration().screenWidthDp < 1024) return; + + Drawable drawable = ((ImageView) view).getDrawable(); + if (enabled) { + drawable.clearColorFilter(); + } else { + drawable.setColorFilter(DISABLED_COLOR, PorterDuff.Mode.SRC_ATOP); + } + } +} diff --git a/src/com/android/camera/Switcher.java b/src/com/android/camera/Switcher.java deleted file mode 100644 index dee5f3e..0000000 --- a/src/com/android/camera/Switcher.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright (C) 2009 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.graphics.Canvas; -import android.graphics.PorterDuff; -import android.graphics.drawable.Drawable; -import android.util.AttributeSet; -import android.view.MotionEvent; -import android.view.View; -import android.view.animation.AnimationUtils; -import android.widget.ImageView; - -/** - * A (vertical) widget which switches between the {@code Camera} and the - * {@code VideoCamera} activities. - */ -public class Switcher extends ImageView implements View.OnTouchListener { - - @SuppressWarnings("unused") - private static final String TAG = "Switcher"; - - /** A callback to be called when the user wants to switch activity. */ - public interface OnSwitchListener { - // Returns true if the listener agrees that the switch can be changed. - public boolean onSwitchChanged(Switcher source, boolean onOff); - } - - private static final int ANIMATION_SPEED = 200; - private static final long NO_ANIMATION = -1; - - private final int DISABLED_COLOR; - - private boolean mSwitch = false; - private int mPosition = 0; - private long mAnimationStartTime = NO_ANIMATION; - private int mAnimationStartPosition; - private OnSwitchListener mListener; - - public Switcher(Context context, AttributeSet attrs) { - super(context, attrs); - DISABLED_COLOR = context.getResources().getColor(R.color.icon_disabled_color); - } - - public void setSwitch(boolean onOff) { - if (mSwitch == onOff) return; - mSwitch = onOff; - invalidate(); - } - - // Try to change the switch position. (The client can veto it.) - private void tryToSetSwitch(boolean onOff) { - try { - if (mSwitch == onOff) return; - - // Switch may be changed during the callback so set it before the - // callback. - mSwitch = onOff; - if (mListener != null) { - if (!mListener.onSwitchChanged(this, onOff)) { - mSwitch = !onOff; - return; - } - } - } finally { - startParkingAnimation(); - } - } - - public void setOnSwitchListener(OnSwitchListener listener) { - mListener = listener; - } - - @Override - public boolean onTouchEvent(MotionEvent event) { - if (!isEnabled()) return false; - - switch (event.getAction()) { - case MotionEvent.ACTION_DOWN: - mAnimationStartTime = NO_ANIMATION; - setPressed(true); - trackTouchEvent(event); - break; - - case MotionEvent.ACTION_MOVE: - trackTouchEvent(event); - break; - - case MotionEvent.ACTION_UP: - trackTouchEvent(event); - tryToSetSwitch(mPosition >= getAvailableLength() / 2); - setPressed(false); - break; - - case MotionEvent.ACTION_CANCEL: - tryToSetSwitch(mSwitch); - setPressed(false); - break; - } - return true; - } - - private void startParkingAnimation() { - mAnimationStartTime = AnimationUtils.currentAnimationTimeMillis(); - mAnimationStartPosition = mPosition; - } - - protected int getAvailableLength() { - return getHeight() - getPaddingTop() - getPaddingBottom() - - getDrawable().getIntrinsicHeight(); - } - - /** Returns the logical position of this switch. */ - protected int trackTouch(MotionEvent event) { - return (int) event.getY() - getPaddingTop() - - (getDrawable().getIntrinsicHeight() / 2); - } - - private void trackTouchEvent(MotionEvent event) { - final int available = getAvailableLength(); - mPosition = trackTouch(event); - if (mPosition < 0) { - mPosition = 0; - } else if (mPosition > available) { - mPosition = available; - } - invalidate(); - } - - protected int getOffsetTopToDraw() { - return getPaddingTop() + mPosition; - } - - protected int getOffsetLeftToDraw() { - return (getWidth() - getDrawable().getIntrinsicWidth()) / 2; - } - - protected int getLogicalPosition() { - return mPosition; - } - - @Override - protected void onDraw(Canvas canvas) { - - Drawable drawable = getDrawable(); - - if ((drawable.getIntrinsicHeight() == 0) - || (drawable.getIntrinsicWidth() == 0)) { - return; // nothing to draw (empty bounds) - } - - final int available = getAvailableLength(); - if (mAnimationStartTime != NO_ANIMATION) { - long time = AnimationUtils.currentAnimationTimeMillis(); - int deltaTime = (int) (time - mAnimationStartTime); - mPosition = mAnimationStartPosition + - ANIMATION_SPEED * (mSwitch ? deltaTime : -deltaTime) / 1000; - if (mPosition < 0) mPosition = 0; - if (mPosition > available) mPosition = available; - boolean done = (mPosition == (mSwitch ? available : 0)); - if (!done) { - invalidate(); - } else { - mAnimationStartTime = NO_ANIMATION; - } - } else if (!isPressed()){ - mPosition = mSwitch ? available : 0; - } - int saveCount = canvas.getSaveCount(); - canvas.save(); - canvas.translate(getOffsetLeftToDraw(), getOffsetTopToDraw()); - drawable.draw(canvas); - canvas.restoreToCount(saveCount); - } - - // Consume the touch events for the specified view. - public void addTouchView(View v) { - v.setOnTouchListener(this); - } - - // This implements View.OnTouchListener so we intercept the touch events - // of the parent and pass them to ourselves. - public boolean onTouch(View v, MotionEvent event) { - // Adjust the x and y because they are relative to the parent. - event.offsetLocation(-getLeft(), -getTop()); - onTouchEvent(event); - event.offsetLocation(getLeft(), getTop()); - return true; - } -} diff --git a/src/com/android/camera/SwitcherSet.java b/src/com/android/camera/SwitcherSet.java deleted file mode 100644 index 0371b43..0000000 --- a/src/com/android/camera/SwitcherSet.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (C) 2010 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.graphics.PorterDuff; -import android.graphics.drawable.Drawable; -import android.util.AttributeSet; -import android.view.View; -import android.widget.ImageView; -import android.widget.LinearLayout; - -/** - * A widget that includes two {@code RotateImageView}'s and a {@link Switcher}. - */ -public class SwitcherSet extends LinearLayout implements Switcher.OnSwitchListener { - private final int DISABLED_COLOR; - - private Switcher.OnSwitchListener mListener; - private View mOnView; - private View mOffView; - private Switcher mSwitcher; - private Context mContext; - - public SwitcherSet(Context context, AttributeSet attrs) { - super(context, attrs); - mContext = context; - DISABLED_COLOR = context.getResources().getColor(R.color.icon_disabled_color); - } - - protected void onFinishInflate() { - super.onFinishInflate(); - mSwitcher = (Switcher) findViewById(R.id.switcher); - if (mSwitcher == null) { - throw new NullPointerException("cannot find switcher in layout file"); - } - mSwitcher.setOnSwitchListener(this); - mSwitcher.addTouchView(this); - mOnView = findViewById(R.id.camera_switch_icon); - mOffView = findViewById(R.id.video_switch_icon); - } - - public void setSwitch(boolean onOff) { - mOnView.setSelected(onOff); - mOffView.setSelected(!onOff); - mSwitcher.setSwitch(onOff); - } - - public void setOnSwitchListener(Switcher.OnSwitchListener listener) { - mListener = listener; - } - - // Try to change the switch position. (The client can veto it.) - private void tryToSetSwitch(boolean onOff) { - if (mListener != null) { - if (!mListener.onSwitchChanged(mSwitcher, onOff)) { - setSwitch(!onOff); - } - } - } - - @Override - public boolean onSwitchChanged(Switcher source, boolean onOff) { - setSwitch(onOff); - tryToSetSwitch(onOff); - return true; - } - - @Override - public void setEnabled(boolean enabled) { - super.setEnabled(enabled); - - setEnabled(mSwitcher, enabled); - setEnabled(mOnView, enabled); - setEnabled(mOffView, enabled); - } - - public void setEnabled(View view, boolean enabled) { - view.setEnabled(enabled); - - // render disabled effect for tablet only. - if (mContext.getResources().getConfiguration().screenWidthDp < 1024) return; - - Drawable drawable = ((ImageView) view).getDrawable(); - if (enabled) { - drawable.clearColorFilter(); - } else { - drawable.setColorFilter(DISABLED_COLOR, PorterDuff.Mode.SRC_ATOP); - } - } -} diff --git a/src/com/android/camera/VideoCamera.java b/src/com/android/camera/VideoCamera.java index 2a722f2..fe61e42 100644 --- a/src/com/android/camera/VideoCamera.java +++ b/src/com/android/camera/VideoCamera.java @@ -87,7 +87,7 @@ public class VideoCamera extends ActivityBase implements View.OnClickListener, ShutterButton.OnShutterButtonListener, SurfaceHolder.Callback, MediaRecorder.OnErrorListener, MediaRecorder.OnInfoListener, - Switcher.OnSwitchListener, PreviewFrameLayout.OnSizeChangedListener { + ModePicker.OnModeChangeListener, PreviewFrameLayout.OnSizeChangedListener { private static final String TAG = "videocamera"; @@ -163,11 +163,9 @@ public class VideoCamera extends ActivityBase // An imageview showing showing the last captured picture thumbnail. private RotateImageView mThumbnailView; private RotateImageView mShareIcon; - private RotateImageView mCameraSwitchIcon; - private RotateImageView mVideoSwitchIcon; + private ModePicker mModePicker; private ShutterButton mShutterButton; private TextView mRecordingTimeView; - private SwitcherSet mSwitcher; private boolean mIsVideoCaptureIntent; private boolean mQuickCapture; @@ -407,9 +405,9 @@ public class VideoCamera extends ActivityBase initThumbnailButton(); mShareIcon = (RotateImageView) findViewById(R.id.share_icon); - mSwitcher = (SwitcherSet) findViewById(R.id.camera_switch); - mSwitcher.setVisibility(View.VISIBLE); - mSwitcher.setOnSwitchListener(this); + mModePicker = (ModePicker) findViewById(R.id.mode_picker); + mModePicker.setVisibility(View.VISIBLE); + mModePicker.setOnModeChangeListener(this); } mPreviewFrameLayout = (PreviewFrameLayout) @@ -419,8 +417,7 @@ public class VideoCamera extends ActivityBase mReviewImage = (ImageView) findViewById(R.id.review_image); mShareButton = findViewById(R.id.share_button); mShareIcon = (RotateImageView) findViewById(R.id.share_icon); - mCameraSwitchIcon = (RotateImageView) findViewById(R.id.camera_switch_icon); - mVideoSwitchIcon = (RotateImageView) findViewById(R.id.video_switch_icon); + mModePicker = (ModePicker) findViewById(R.id.mode_picker); // don't set mSurfaceHolder here. We have it set ONLY within // surfaceCreated / surfaceDestroyed, other parts of the code @@ -556,7 +553,7 @@ public class VideoCamera extends ActivityBase if (mHeadUpDisplay != null) mHeadUpDisplay.setEnabled(enable); if (mIndicatorWheel != null) mIndicatorWheel.setEnabled(enable); if (mCameraPicker != null) mCameraPicker.setEnabled(enable); - if (mSwitcher != null) mSwitcher.setEnabled(enable); + if (mModePicker != null) mModePicker.setEnabled(enable); } private void initializeIndicatorWheel() { @@ -610,8 +607,7 @@ public class VideoCamera extends ActivityBase if (mHeadUpDisplay != null) mHeadUpDisplay.setOrientation(mOrientationCompensation); if (mThumbnailView != null) mThumbnailView.setDegree(degree); if (mShareIcon != null) mShareIcon.setDegree(degree); - if (mCameraSwitchIcon != null) mCameraSwitchIcon.setDegree(degree); - if (mVideoSwitchIcon != null) mVideoSwitchIcon.setDegree(degree); + if (mModePicker != null) mModePicker.setDegree(degree); if (mSharePopup != null) mSharePopup.setOrientation(degree); } @@ -894,7 +890,7 @@ public class VideoCamera extends ActivityBase if (!mIsVideoCaptureIntent) { updateThumbnailButton(); // Update the last video thumbnail. - mSwitcher.setSwitch(SWITCH_VIDEO); + mModePicker.setCurrentMode(ModePicker.MODE_VIDEO); } if (mPreviewing) { @@ -1333,14 +1329,17 @@ public class VideoCamera extends ActivityBase } private void addBaseMenuItems(Menu menu) { - MenuHelper.addSwitchModeMenuItem(menu, false, new Runnable() { + MenuHelper.addSwitchModeMenuItem(menu, ModePicker.MODE_CAMERA, new Runnable() { public void run() { - switchToCameraMode(); + switchToOtherMode(ModePicker.MODE_CAMERA); } }); - MenuItem gallery = menu.add(Menu.NONE, Menu.NONE, - MenuHelper.POSITION_GOTO_GALLERY, - R.string.camera_gallery_photos_text) + MenuHelper.addSwitchModeMenuItem(menu, ModePicker.MODE_PANORAMA, new Runnable() { + public void run() { + switchToOtherMode(ModePicker.MODE_PANORAMA); + } + }); + MenuItem gallery = menu.add(R.string.camera_gallery_photos_text) .setOnMenuItemClickListener( new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { @@ -1352,9 +1351,7 @@ public class VideoCamera extends ActivityBase mGalleryItems.add(gallery); if (mNumberOfCameras > 1) { - menu.add(Menu.NONE, Menu.NONE, - MenuHelper.POSITION_SWITCH_CAMERA_ID, - R.string.switch_camera_id) + menu.add(R.string.switch_camera_id) .setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { CameraSettings.writePreferredCameraId(mPreferences, @@ -1787,16 +1784,16 @@ public class VideoCamera extends ActivityBase mParameters = mCameraDevice.getParameters(); } - private boolean switchToCameraMode() { + private boolean switchToOtherMode(int mode) { if (isFinishing() || mMediaRecorderRecording) return false; - MenuHelper.gotoCameraMode(VideoCamera.this); + MenuHelper.gotoMode(mode, VideoCamera.this); finish(); return true; } - public boolean onSwitchChanged(Switcher source, boolean onOff) { - if (onOff == SWITCH_CAMERA) { - return switchToCameraMode(); + public boolean onModeChanged(int mode) { + if (mode != ModePicker.MODE_VIDEO) { + return switchToOtherMode(mode); } else { return true; } diff --git a/src/com/android/camera/panorama/PanoramaActivity.java b/src/com/android/camera/panorama/PanoramaActivity.java index 4a87875..27c90e2 100644 --- a/src/com/android/camera/panorama/PanoramaActivity.java +++ b/src/com/android/camera/panorama/PanoramaActivity.java @@ -35,13 +35,16 @@ import android.widget.ImageView; import com.android.camera.CameraDisabledException; import com.android.camera.CameraHardwareException; import com.android.camera.CameraHolder; +import com.android.camera.MenuHelper; +import com.android.camera.ModePicker; import com.android.camera.R; import com.android.camera.ShutterButton; import com.android.camera.Util; import java.util.List; -public class PanoramaActivity extends Activity { +public class PanoramaActivity extends Activity implements + ModePicker.OnModeChangeListener { public static final int DEFAULT_SWEEP_ANGLE = 60; public static final int DEFAULT_BLEND_MODE = Mosaic.BLENDTYPE_HORIZONTAL; public static final int DEFAULT_CAPTURE_PIXELS = 960 * 720; @@ -58,6 +61,7 @@ public class PanoramaActivity extends Activity { private android.hardware.Camera mCameraDevice; private SensorManager mSensorManager; private Sensor mSensor; + private ModePicker mModePicker; @Override public void onCreate(Bundle icicle) { @@ -167,6 +171,21 @@ public class PanoramaActivity extends Activity { } } + private boolean switchToOtherMode(int mode) { + if (isFinishing()) return false; + MenuHelper.gotoMode(mode, this); + finish(); + return true; + } + + public boolean onModeChanged(int mode) { + if (mode != ModePicker.MODE_PANORAMA) { + return switchToOtherMode(mode); + } else { + return true; + } + } + private void createContentView() { setContentView(R.layout.panorama); @@ -185,6 +204,10 @@ public class PanoramaActivity extends Activity { mPreview.setCaptureStarted(DEFAULT_SWEEP_ANGLE, DEFAULT_BLEND_MODE); } }); + mModePicker = (ModePicker) findViewById(R.id.mode_picker); + mModePicker.setVisibility(View.VISIBLE); + mModePicker.setOnModeChangeListener(this); + mModePicker.setCurrentMode(ModePicker.MODE_PANORAMA); } public void showResultingMosaic(String uri) { -- cgit v1.1