diff options
author | Chung-yih Wang <cywang@google.com> | 2011-07-20 07:02:18 +0800 |
---|---|---|
committer | Chung-yih Wang <cywang@google.com> | 2011-08-04 08:47:34 +0800 |
commit | bed7386688cd7810cba23732ab71f370fe3222ff (patch) | |
tree | 2ff1db2d188e4e6f570f4fa393277c7165853cff /src/com | |
parent | 2989c0da86939dea7af264d7b9b25593f8aff2f7 (diff) | |
download | LegacyCamera-bed7386688cd7810cba23732ab71f370fe3222ff.zip LegacyCamera-bed7386688cd7810cba23732ab71f370fe3222ff.tar.gz LegacyCamera-bed7386688cd7810cba23732ab71f370fe3222ff.tar.bz2 |
Merge the indicator bar implementations.
bug:5039235
Originally we have the GLView-implemented indicators for Phone-based UI.
Based on the current UI design, we would like to merge the look on all
devices for the dialog of the camera setting. Therefore, a refactor of
how to handle the popup window is required here and this will simplify our
UI work for handling different layout/resolution.
Change-Id: I6f9e6ebed7600be460ddd906505cdc44f81098ad
Diffstat (limited to 'src/com')
19 files changed, 380 insertions, 1833 deletions
diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java index da114b5..a89c676 100644 --- a/src/com/android/camera/Camera.java +++ b/src/com/android/camera/Camera.java @@ -16,12 +16,9 @@ package com.android.camera; -import com.android.camera.ui.CameraHeadUpDisplay; -import com.android.camera.ui.CameraPicker; import com.android.camera.ui.FocusRectangle; import com.android.camera.ui.GLRootView; -import com.android.camera.ui.HeadUpDisplay; -import com.android.camera.ui.IndicatorWheel; +import com.android.camera.ui.IndicatorControl; import com.android.camera.ui.RotateImageView; import com.android.camera.ui.SharePopup; import com.android.camera.ui.ZoomControllerListener; @@ -184,9 +181,6 @@ public class Camera extends ActivityBase implements View.OnClickListener, private View mGpsNoSignalView; private View mGpsHasSignalView; - // Front/Back camera picker for w1024dp layout - private CameraPicker mCameraPicker; - /** * An unpublished intent flag requesting to return as soon as capturing * is completed. @@ -255,9 +249,7 @@ public class Camera extends ActivityBase implements View.OnClickListener, private Toast mNoShareToast; private final Handler mHandler = new MainHandler(); - // w1024dp devices use indicator wheel. Other devices use head-up display. - private CameraHeadUpDisplay mHeadUpDisplay; - private IndicatorWheel mIndicatorWheel; + private IndicatorControl mIndicatorControl; private PreferenceGroup mPreferenceGroup; // multiple cameras support @@ -335,11 +327,8 @@ public class Camera extends ActivityBase implements View.OnClickListener, Editor editor = mPreferences.edit(); editor.putString(CameraSettings.KEY_EXPOSURE, "0"); editor.apply(); - if (mHeadUpDisplay != null) { - mHeadUpDisplay.reloadPreferences(); - } - if (mIndicatorWheel != null) { - mIndicatorWheel.reloadPreferences(); + if (mIndicatorControl != null) { + mIndicatorControl.reloadPreferences(); } } } @@ -401,14 +390,7 @@ public class Camera extends ActivityBase implements View.OnClickListener, installIntentFilter(); initializeFocusTone(); initializeZoom(); - // w1024dp devices use indicator wheel. Other devices use head-up display. - if (mIndicatorWheel == null) { - mHeadUpDisplay = new CameraHeadUpDisplay(this); - mHeadUpDisplay.setListener(new MyHeadUpDisplayListener()); - initializeHeadUpDisplay(); - } mFirstTimeInitialized = true; - changeHeadUpDisplayState(); addIdleHandler(); } @@ -457,7 +439,6 @@ public class Camera extends ActivityBase implements View.OnClickListener, installIntentFilter(); initializeFocusTone(); initializeZoom(); - changeHeadUpDisplayState(); keepMediaProviderInstance(); checkStorage(); @@ -536,17 +517,17 @@ public class Camera extends ActivityBase implements View.OnClickListener, @Override public boolean onDown(MotionEvent e) { // Check if the popup window is visible. - View popup = mIndicatorWheel.getActiveSettingPopup(); + View popup = mIndicatorControl.getActiveSettingPopup(); if (popup == null) return false; - // Let popup window, indicator wheel or preview frame handle the + // Let popup window, indicator control or preview frame handle the // event by themselves. Dismiss the popup window if users touch on // other areas. if (!Util.pointInView(e.getX(), e.getY(), popup) - && !Util.pointInView(e.getX(), e.getY(), mIndicatorWheel) + && !Util.pointInView(e.getX(), e.getY(), mIndicatorControl) && !Util.pointInView(e.getX(), e.getY(), mPreviewFrame)) { - mIndicatorWheel.dismissSettingPopup(); + mIndicatorControl.dismissSettingPopup(); // Let event fall through. } return false; @@ -585,19 +566,6 @@ public class Camera extends ActivityBase implements View.OnClickListener, } }; - private void initializeCameraPicker() { - mCameraPicker = (CameraPicker) findViewById(R.id.camera_picker); - if (mCameraPicker != null) { - mCameraPicker.setImageResource(R.drawable.camera_toggle); - ListPreference pref = mPreferenceGroup.findPreference( - CameraSettings.KEY_CAMERA_ID); - if (pref != null) { - mCameraPicker.initialize(pref); - mCameraPicker.setListener(new MyCameraPickerListener()); - } - } - } - private void initializeZoomPicker() { View zoomIncrement = findViewById(R.id.zoom_increment); View zoomDecrement = findViewById(R.id.zoom_decrement); @@ -1061,37 +1029,14 @@ public class Camera extends ActivityBase implements View.OnClickListener, // Do this after starting preview because it depends on camera // parameters. - initializeIndicatorWheel(); - initializeCameraPicker(); + initializeIndicatorControl(); initializeZoomPicker(); } - private void changeHeadUpDisplayState() { - if (mHeadUpDisplay == null) return; - // If the camera resumes behind the lock screen, the orientation - // will be portrait. That causes OOM when we try to allocation GPU - // memory for the GLSurfaceView again when the orientation changes. So, - // we delayed initialization of HeadUpDisplay until the orientation - // becomes landscape. - Configuration config = getResources().getConfiguration(); - if (config.orientation == Configuration.ORIENTATION_LANDSCAPE - && !mPausing && mFirstTimeInitialized) { - if (mGLRootView == null) attachHeadUpDisplay(); - } else if (mGLRootView != null) { - detachHeadUpDisplay(); - } - } - private void overrideCameraSettings(final String flashMode, final String whiteBalance, final String focusMode) { - if (mHeadUpDisplay != null) { - mHeadUpDisplay.overrideSettings( - CameraSettings.KEY_FLASH_MODE, flashMode, - CameraSettings.KEY_WHITE_BALANCE, whiteBalance, - CameraSettings.KEY_FOCUS_MODE, focusMode); - } - if (mIndicatorWheel != null) { - mIndicatorWheel.overrideSettings( + if (mIndicatorControl != null) { + mIndicatorControl.overrideSettings( CameraSettings.KEY_FLASH_MODE, flashMode, CameraSettings.KEY_WHITE_BALANCE, whiteBalance, CameraSettings.KEY_FOCUS_MODE, focusMode); @@ -1115,81 +1060,50 @@ public class Camera extends ActivityBase implements View.OnClickListener, mPreferenceGroup = settings.getPreferenceGroup(R.xml.camera_preferences); } - private void initializeIndicatorWheel() { - mIndicatorWheel = (IndicatorWheel) findViewById(R.id.indicator_wheel); - if (mIndicatorWheel == null) return; + private void initializeIndicatorControl() { + // setting the indicator buttons. + mIndicatorControl = (IndicatorControl) findViewById(R.id.indicator_control); + if (mIndicatorControl == null) return; loadCameraPreferences(); - - final String[] SETTING_KEYS = { - CameraSettings.KEY_FLASH_MODE}; - final String[] OTHER_SETTING_KEYS = { - CameraSettings.KEY_WHITE_BALANCE, - CameraSettings.KEY_COLOR_EFFECT, - CameraSettings.KEY_SCENE_MODE, - CameraSettings.KEY_RECORD_LOCATION, - CameraSettings.KEY_FOCUS_MODE, - CameraSettings.KEY_EXPOSURE, - CameraSettings.KEY_PICTURE_SIZE}; - mIndicatorWheel.initialize(this, mPreferenceGroup, SETTING_KEYS, - OTHER_SETTING_KEYS); - mIndicatorWheel.setListener(new MyIndicatorWheelListener()); - mPopupGestureDetector = new GestureDetector(this, - new PopupGestureListener()); - updateSceneModeUI(); - } - - private void initializeHeadUpDisplay() { - if (mHeadUpDisplay == null) return; - loadCameraPreferences(); - - float[] zoomRatios = null; - if(mParameters.isZoomSupported()) { - zoomRatios = Util.convertZoomRatios(mParameters.getZoomRatios()); - } - mHeadUpDisplay.initialize(this, mPreferenceGroup, - zoomRatios, mOrientationCompensation); - if (mParameters.isZoomSupported()) { - mHeadUpDisplay.setZoomListener(new ZoomControllerListener() { - public void onZoomChanged( - int index, float ratio, boolean isMoving) { - onZoomValueChanged(index); - } - }); - } - updateSceneModeUI(); - } - - private void attachHeadUpDisplay() { - mHeadUpDisplay.setOrientation(mOrientationCompensation); - if (mParameters.isZoomSupported()) { - mHeadUpDisplay.setZoomIndex(mZoomValue); + final String[] SETTING_KEYS, OTHER_SETTING_KEYS; + if (Util.isTabletUI()) { + SETTING_KEYS = new String[] { + CameraSettings.KEY_FLASH_MODE}; + OTHER_SETTING_KEYS = new String[] { + CameraSettings.KEY_WHITE_BALANCE, + CameraSettings.KEY_COLOR_EFFECT, + CameraSettings.KEY_SCENE_MODE, + CameraSettings.KEY_RECORD_LOCATION, + CameraSettings.KEY_FOCUS_MODE, + CameraSettings.KEY_EXPOSURE, + CameraSettings.KEY_PICTURE_SIZE}; + } else { + SETTING_KEYS = new String[] { + CameraSettings.KEY_FLASH_MODE, + CameraSettings.KEY_CAMERA_ID, + CameraSettings.KEY_COLOR_EFFECT, + CameraSettings.KEY_WHITE_BALANCE}; + OTHER_SETTING_KEYS = new String[] { + CameraSettings.KEY_FOCUS_MODE, + CameraSettings.KEY_EXPOSURE, + CameraSettings.KEY_SCENE_MODE, + CameraSettings.KEY_PICTURE_SIZE, + CameraSettings.KEY_RECORD_LOCATION}; } - ViewGroup frame = (ViewGroup) findViewById(R.id.frame); - mGLRootView = new GLRootView(this); - mGLRootView.setContentPane(mHeadUpDisplay); - frame.addView(mGLRootView); - } - - private void detachHeadUpDisplay() { - mHeadUpDisplay.collapse(); - ((ViewGroup) mGLRootView.getParent()).removeView(mGLRootView); - mGLRootView = null; + mIndicatorControl.initialize(this, mPreferenceGroup, SETTING_KEYS, + OTHER_SETTING_KEYS); + mIndicatorControl.setListener(new MyIndicatorControlListener()); } private boolean collapseCameraControls() { - if (mHeadUpDisplay != null && mHeadUpDisplay.collapse()) { - return true; - } - if (mIndicatorWheel != null && mIndicatorWheel.dismissSettingPopup()) { + if (mIndicatorControl != null && mIndicatorControl.dismissSettingPopup()) { return true; } return false; } private void enableCameraControls(boolean enable) { - if (mHeadUpDisplay != null) mHeadUpDisplay.setEnabled(enable); - if (mIndicatorWheel != null) mIndicatorWheel.setEnabled(enable); - if (mCameraPicker != null) mCameraPicker.setEnabled(enable); + if (mIndicatorControl != null) mIndicatorControl.setEnabled(enable); if (mZoomPicker != null) mZoomPicker.setEnabled(enable); if (mModePicker != null) mModePicker.setEnabled(enable); } @@ -1217,20 +1131,17 @@ public class Camera extends ActivityBase implements View.OnClickListener, + Util.getDisplayRotation(Camera.this); if (mOrientationCompensation != orientationCompensation) { mOrientationCompensation = orientationCompensation; - if (!mIsImageCaptureIntent) { - setOrientationIndicator(mOrientationCompensation); - } + setOrientationIndicator(mOrientationCompensation); } } } private void setOrientationIndicator(int degree) { - if (mHeadUpDisplay != null) mHeadUpDisplay.setOrientation(mOrientationCompensation); if (mThumbnailView != null) mThumbnailView.setDegree(degree); if (mShareIcon != null) mShareIcon.setDegree(degree); if (mModePicker != null) mModePicker.setDegree(degree); if (mSharePopup != null) mSharePopup.setOrientation(degree); - if (mIndicatorWheel != null) mIndicatorWheel.setDegree(degree); + if (mIndicatorControl != null) mIndicatorControl.setDegree(degree); } @Override @@ -1482,12 +1393,6 @@ public class Camera extends ActivityBase implements View.OnClickListener, } @Override - public void onConfigurationChanged(Configuration config) { - super.onConfigurationChanged(config); - changeHeadUpDisplayState(); - } - - @Override protected void onPause() { mPausing = true; stopPreview(); @@ -1495,7 +1400,6 @@ public class Camera extends ActivityBase implements View.OnClickListener, closeCamera(); resetScreenOn(); collapseCameraControls(); - changeHeadUpDisplayState(); if (mFirstTimeInitialized) { mOrientationListener.disable(); @@ -2215,10 +2119,10 @@ public class Camera extends ActivityBase implements View.OnClickListener, private void showPostCaptureAlert() { if (mIsImageCaptureIntent) { - if (mIndicatorWheel == null) { - mShutterButton.setVisibility(View.INVISIBLE); - } else { + if (Util.isTabletUI()) { mShutterButton.setEnabled(false); + } else { + mShutterButton.setVisibility(View.INVISIBLE); } int[] pickIds = {R.id.btn_retake, R.id.btn_done}; for (int id : pickIds) { @@ -2234,10 +2138,10 @@ public class Camera extends ActivityBase implements View.OnClickListener, private void hidePostCaptureAlert() { if (mIsImageCaptureIntent) { - if (mIndicatorWheel == null) { - mShutterButton.setVisibility(View.VISIBLE); - } else { + if (Util.isTabletUI()) { mShutterButton.setEnabled(true); + } else { + mShutterButton.setVisibility(View.VISIBLE); } int[] pickIds = {R.id.btn_retake, R.id.btn_done}; for (int id : pickIds) { @@ -2381,20 +2285,6 @@ public class Camera extends ActivityBase implements View.OnClickListener, mHandler.sendEmptyMessageDelayed(CLEAR_SCREEN_DELAY, SCREEN_DELAY); } - private class MyHeadUpDisplayListener implements HeadUpDisplay.Listener { - - public void onSharedPreferenceChanged() { - Camera.this.onSharedPreferenceChanged(); - } - - public void onRestorePreferencesClicked() { - Camera.this.onRestorePreferencesClicked(); - } - - public void onPopupWindowVisibilityChanged(int visibility) { - } - } - protected void onRestorePreferencesClicked() { if (mPausing) return; Runnable runnable = new Runnable() { @@ -2415,16 +2305,11 @@ public class Camera extends ActivityBase implements View.OnClickListener, setCameraParametersWhenIdle(UPDATE_PARAM_ZOOM); if (mZoomPicker != null) mZoomPicker.setZoomIndex(0); } - - if (mHeadUpDisplay != null) { - mHeadUpDisplay.restorePreferences(mParameters); - } - - if (mIndicatorWheel != null) { - mIndicatorWheel.dismissSettingPopup(); + if (mIndicatorControl != null) { + mIndicatorControl.dismissSettingPopup(); CameraSettings.restorePreferences(Camera.this, mPreferences, mParameters); - initializeIndicatorWheel(); + initializeIndicatorControl(); onSharedPreferenceChanged(); } } @@ -2447,7 +2332,7 @@ public class Camera extends ActivityBase implements View.OnClickListener, mSharePopup.showAtLocation(mThumbnailView, Gravity.NO_GRAVITY, 0, 0); } - private class MyIndicatorWheelListener implements IndicatorWheel.Listener { + private class MyIndicatorControlListener implements IndicatorControl.Listener { public void onSharedPreferenceChanged() { Camera.this.onSharedPreferenceChanged(); } @@ -2460,10 +2345,4 @@ public class Camera extends ActivityBase implements View.OnClickListener, Camera.this.onOverriddenPreferencesClicked(); } } - - private class MyCameraPickerListener implements CameraPicker.Listener { - public void onSharedPreferenceChanged() { - Camera.this.onSharedPreferenceChanged(); - } - } } diff --git a/src/com/android/camera/CameraAppImpl.java b/src/com/android/camera/CameraAppImpl.java new file mode 100644 index 0000000..d38cdf0 --- /dev/null +++ b/src/com/android/camera/CameraAppImpl.java @@ -0,0 +1,30 @@ +/* + * 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 android.app.Application; + +public class CameraAppImpl extends Application { + + @Override + public void onCreate() { + super.onCreate(); + Util.initialize(this); + } +} + + diff --git a/src/com/android/camera/ModePicker.java b/src/com/android/camera/ModePicker.java index 594c813..e6b3e0e 100644 --- a/src/com/android/camera/ModePicker.java +++ b/src/com/android/camera/ModePicker.java @@ -146,7 +146,7 @@ public class ModePicker extends RelativeLayout implements View.OnClickListener { view.setEnabled(enabled); // render disabled effect for tablet only. - if (mContext.getResources().getConfiguration().screenWidthDp < 1024) return; + if (!Util.isTabletUI()) return; Drawable drawable = ((ImageView) view).getDrawable(); if (enabled) { diff --git a/src/com/android/camera/Util.java b/src/com/android/camera/Util.java index 36bc7be..d3fa24e 100644 --- a/src/com/android/camera/Util.java +++ b/src/com/android/camera/Util.java @@ -61,9 +61,19 @@ public class Util { private static final String EXTRAS_CAMERA_FACING = "android.intent.extras.CAMERA_FACING"; + private static boolean sIsTabletUI; + private Util() { } + public static void initialize(Context context) { + sIsTabletUI = (context.getResources().getConfiguration().screenWidthDp >= 1024); + } + + public static boolean isTabletUI() { + return sIsTabletUI; + } + // Rotates the bitmap by the specified degree. // If a new bitmap is created, the original bitmap is recycled. public static Bitmap rotate(Bitmap b, int degrees) { diff --git a/src/com/android/camera/VideoCamera.java b/src/com/android/camera/VideoCamera.java index 7de8553..54871f2 100644 --- a/src/com/android/camera/VideoCamera.java +++ b/src/com/android/camera/VideoCamera.java @@ -16,10 +16,8 @@ package com.android.camera; -import com.android.camera.ui.CamcorderHeadUpDisplay; -import com.android.camera.ui.CameraPicker; import com.android.camera.ui.GLRootView; -import com.android.camera.ui.HeadUpDisplay; +import com.android.camera.ui.IndicatorControl; import com.android.camera.ui.IndicatorWheel; import com.android.camera.ui.RotateImageView; import com.android.camera.ui.SharePopup; @@ -142,11 +140,7 @@ public class VideoCamera extends ActivityBase private PreviewFrameLayout mPreviewFrameLayout; private SurfaceHolder mSurfaceHolder = null; private GLRootView mGLRootView; - // w1024dp devices use indicator wheel. Other devices use head-up display. - private CamcorderHeadUpDisplay mHeadUpDisplay; - private IndicatorWheel mIndicatorWheel; - // Front/back camera picker for w1024dp layout. - private CameraPicker mCameraPicker; + private IndicatorControl mIndicatorControl; private View mReviewControl; private Toast mNoShareToast; @@ -460,46 +454,10 @@ public class VideoCamera extends ActivityBase mFrontCameraId = CameraHolder.instance().getFrontCameraId(); // Initialize after startPreview becuase this need mParameters. - initializeIndicatorWheel(); - // w1024dp devices use indicator wheel. Other devices use head-up display. - if (mIndicatorWheel == null) { - mHeadUpDisplay = new CamcorderHeadUpDisplay(this); - mHeadUpDisplay.setListener(new MyHeadUpDisplayListener()); - initializeHeadUpDisplay(); - } - initializeCameraPicker(); + initializeIndicatorControl(); initializeZoomPicker(); } - private void changeHeadUpDisplayState() { - if (mHeadUpDisplay == null) return; - // If the camera resumes behind the lock screen, the orientation - // will be portrait. That causes OOM when we try to allocation GPU - // memory for the GLSurfaceView again when the orientation changes. So, - // we delayed initialization of HeadUpDisplay until the orientation - // becomes landscape. - Configuration config = getResources().getConfiguration(); - if (config.orientation == Configuration.ORIENTATION_LANDSCAPE - && !mPausing) { - if (mGLRootView == null) attachHeadUpDisplay(); - } else if (mGLRootView != null) { - detachHeadUpDisplay(); - } - } - - private void initializeCameraPicker() { - mCameraPicker = (CameraPicker) findViewById(R.id.camera_picker); - if (mCameraPicker != null) { - mCameraPicker.setImageResource(R.drawable.camera_toggle_video); - ListPreference pref = mPreferenceGroup.findPreference( - CameraSettings.KEY_CAMERA_ID); - if (pref != null) { - mCameraPicker.initialize(pref); - mCameraPicker.setListener(new MyCameraPickerListener()); - } - } - } - private void initializeZoomPicker() { View zoomIncrement = findViewById(R.id.zoom_increment); View zoomDecrement = findViewById(R.id.zoom_decrement); @@ -515,59 +473,41 @@ public class VideoCamera extends ActivityBase mPreferenceGroup = settings.getPreferenceGroup(R.xml.video_preferences); } - private void initializeHeadUpDisplay() { - if (mHeadUpDisplay == null) return; - loadCameraPreferences(); - - if (mIsVideoCaptureIntent) { - mPreferenceGroup = filterPreferenceScreenByIntent(mPreferenceGroup); - } - mHeadUpDisplay.initialize(this, mPreferenceGroup, mOrientationCompensation); - } - - private void attachHeadUpDisplay() { - mHeadUpDisplay.setOrientation(mOrientationCompensation); - ViewGroup frame = (ViewGroup) findViewById(R.id.frame); - mGLRootView = new GLRootView(this); - frame.addView(mGLRootView); - mGLRootView.setContentPane(mHeadUpDisplay); - } - - private void detachHeadUpDisplay() { - mHeadUpDisplay.collapse(); - ((ViewGroup) mGLRootView.getParent()).removeView(mGLRootView); - mGLRootView = null; - } - private boolean collapseCameraControls() { - if (mHeadUpDisplay != null && mHeadUpDisplay.collapse()) { - return true; - } - if (mIndicatorWheel != null && mIndicatorWheel.dismissSettingPopup()) { + if (mIndicatorControl != null && mIndicatorControl.dismissSettingPopup()) { return true; } return false; } private void enableCameraControls(boolean enable) { - if (mHeadUpDisplay != null) mHeadUpDisplay.setEnabled(enable); - if (mIndicatorWheel != null) mIndicatorWheel.setEnabled(enable); - if (mCameraPicker != null) mCameraPicker.setEnabled(enable); + if (mIndicatorControl != null) mIndicatorControl.setEnabled(enable); if (mModePicker != null) mModePicker.setEnabled(enable); } - private void initializeIndicatorWheel() { - mIndicatorWheel = (IndicatorWheel) findViewById(R.id.indicator_wheel); - if (mIndicatorWheel == null) return; + private void initializeIndicatorControl() { + mIndicatorControl = (IndicatorControl) findViewById(R.id.indicator_control); + if (mIndicatorControl == null) return; loadCameraPreferences(); - final String[] SETTING_KEYS = {CameraSettings.KEY_VIDEOCAMERA_FLASH_MODE}; - final String[] OTHER_SETTING_KEYS = { - CameraSettings.KEY_VIDEO_QUALITY, - CameraSettings.KEY_WHITE_BALANCE, - CameraSettings.KEY_VIDEO_TIME_LAPSE_FRAME_INTERVAL}; - mIndicatorWheel.initialize(this, mPreferenceGroup, SETTING_KEYS, OTHER_SETTING_KEYS); - mIndicatorWheel.setListener(new MyIndicatorWheelListener()); + final String[] SETTING_KEYS, OTHER_SETTING_KEYS; + if (Util.isTabletUI()) { + SETTING_KEYS = new String[] {CameraSettings.KEY_VIDEOCAMERA_FLASH_MODE}; + OTHER_SETTING_KEYS = new String[] { + CameraSettings.KEY_VIDEO_QUALITY, + CameraSettings.KEY_WHITE_BALANCE, + CameraSettings.KEY_VIDEO_TIME_LAPSE_FRAME_INTERVAL}; + } else { + SETTING_KEYS = new String[] { + CameraSettings.KEY_WHITE_BALANCE, + CameraSettings.KEY_VIDEOCAMERA_FLASH_MODE, + CameraSettings.KEY_VIDEO_QUALITY, + CameraSettings.KEY_CAMERA_ID}; + OTHER_SETTING_KEYS = new String[] { + CameraSettings.KEY_VIDEO_TIME_LAPSE_FRAME_INTERVAL}; + } + mIndicatorControl.initialize(this, mPreferenceGroup, SETTING_KEYS, OTHER_SETTING_KEYS); + mIndicatorControl.setListener(new MyIndicatorControlListener()); mPopupGestureDetector = new GestureDetector(this, new PopupGestureListener()); } @@ -596,19 +536,17 @@ public class VideoCamera extends ActivityBase + Util.getDisplayRotation(VideoCamera.this); if (mOrientationCompensation != orientationCompensation) { mOrientationCompensation = orientationCompensation; - if (!mIsVideoCaptureIntent) { - setOrientationIndicator(mOrientationCompensation); - } + setOrientationIndicator(mOrientationCompensation); } } } private void setOrientationIndicator(int degree) { - if (mHeadUpDisplay != null) mHeadUpDisplay.setOrientation(mOrientationCompensation); if (mThumbnailView != null) mThumbnailView.setDegree(degree); if (mShareIcon != null) mShareIcon.setDegree(degree); if (mModePicker != null) mModePicker.setDegree(degree); if (mSharePopup != null) mSharePopup.setOrientation(degree); + if (mIndicatorControl != null) mIndicatorControl.setDegree(degree); } private void startPlayVideoActivity() { @@ -886,8 +824,6 @@ public class VideoCamera extends ActivityBase } }, 200); - changeHeadUpDisplayState(); - if (!mIsVideoCaptureIntent) { updateThumbnailButton(); // Update the last video thumbnail. mModePicker.setCurrentMode(ModePicker.MODE_VIDEO); @@ -965,8 +901,7 @@ public class VideoCamera extends ActivityBase super.onPause(); mPausing = true; - changeHeadUpDisplayState(); - if (mIndicatorWheel != null) mIndicatorWheel.dismissSettingPopup(); + if (mIndicatorControl != null) mIndicatorControl.dismissSettingPopup(); finishRecorderAndCloseCamera(); @@ -1466,9 +1401,11 @@ public class VideoCamera extends ActivityBase mRecordingTimeView.setVisibility(View.VISIBLE); if (mReviewControl != null) mReviewControl.setVisibility(View.GONE); if (mCaptureTimeLapse) { - mIndicatorWheel.startTimeLapseAnimation( - mTimeBetweenTimeLapseFrameCaptureMs, - mRecordingStartTime); + if (Util.isTabletUI()) { + ((IndicatorWheel) mIndicatorControl).startTimeLapseAnimation( + mTimeBetweenTimeLapseFrameCaptureMs, + mRecordingStartTime); + } } } else { mShutterButton.setImageDrawable(getResources().getDrawable( @@ -1477,7 +1414,9 @@ public class VideoCamera extends ActivityBase mRecordingTimeView.setVisibility(View.GONE); if (mReviewControl != null) mReviewControl.setVisibility(View.VISIBLE); if (mCaptureTimeLapse) { - mIndicatorWheel.stopTimeLapseAnimation(); + if (Util.isTabletUI()) { + ((IndicatorWheel) mIndicatorControl).stopTimeLapseAnimation(); + } } } } @@ -1494,7 +1433,7 @@ public class VideoCamera extends ActivityBase } private void showAlert() { - if (mIndicatorWheel == null) { + if (!Util.isTabletUI()) { fadeOut(findViewById(R.id.shutter_button)); } if (mCurrentVideoFilename != null) { @@ -1805,40 +1744,12 @@ public class VideoCamera extends ActivityBase @Override public void onConfigurationChanged(Configuration config) { super.onConfigurationChanged(config); - - // If the camera resumes behind the lock screen, the orientation - // will be portrait. That causes OOM when we try to allocation GPU - // memory for the GLSurfaceView again when the orientation changes. So, - // we delayed initialization of HeadUpDisplay until the orientation - // becomes landscape. - changeHeadUpDisplayState(); } public void onSizeChanged() { // TODO: update the content on GLRootView } - private class MyHeadUpDisplayListener implements HeadUpDisplay.Listener { - public void onSharedPreferenceChanged() { - mHandler.post(new Runnable() { - public void run() { - VideoCamera.this.onSharedPreferenceChanged(); - } - }); - } - - public void onRestorePreferencesClicked() { - mHandler.post(new Runnable() { - public void run() { - VideoCamera.this.onRestorePreferencesClicked(); - } - }); - } - - public void onPopupWindowVisibilityChanged(final int visibility) { - } - } - private void onRestorePreferencesClicked() { Runnable runnable = new Runnable() { public void run() { @@ -1859,15 +1770,11 @@ public class VideoCamera extends ActivityBase if (mZoomPicker != null) mZoomPicker.setZoomIndex(0); } - if (mHeadUpDisplay != null) { - mHeadUpDisplay.restorePreferences(mParameters); - } - - if (mIndicatorWheel != null) { - mIndicatorWheel.dismissSettingPopup(); + if (mIndicatorControl != null) { + mIndicatorControl.dismissSettingPopup(); CameraSettings.restorePreferences(VideoCamera.this, mPreferences, mParameters); - initializeIndicatorWheel(); + initializeIndicatorControl(); onSharedPreferenceChanged(); } } @@ -1931,7 +1838,7 @@ public class VideoCamera extends ActivityBase mSharePopup.showAtLocation(mThumbnailView, Gravity.NO_GRAVITY, 0, 0); } - private class MyIndicatorWheelListener implements IndicatorWheel.Listener { + private class MyIndicatorControlListener implements IndicatorControl.Listener { public void onSharedPreferenceChanged() { VideoCamera.this.onSharedPreferenceChanged(); } @@ -1944,12 +1851,6 @@ public class VideoCamera extends ActivityBase } } - private class MyCameraPickerListener implements CameraPicker.Listener { - public void onSharedPreferenceChanged() { - VideoCamera.this.onSharedPreferenceChanged(); - } - } - @Override public boolean dispatchTouchEvent(MotionEvent m) { // Check if the popup window should be dismissed first. @@ -1965,15 +1866,15 @@ public class VideoCamera extends ActivityBase @Override public boolean onDown(MotionEvent e) { // Check if the popup window is visible. - View popup = mIndicatorWheel.getActiveSettingPopup(); + View popup = mIndicatorControl.getActiveSettingPopup(); if (popup == null) return false; // Let popup window or indicator wheel handle the event by // themselves. Dismiss the popup window if users touch on other // areas. if (!Util.pointInView(e.getX(), e.getY(), popup) - && !Util.pointInView(e.getX(), e.getY(), mIndicatorWheel)) { - mIndicatorWheel.dismissSettingPopup(); + && !Util.pointInView(e.getX(), e.getY(), mIndicatorControl)) { + mIndicatorControl.dismissSettingPopup(); // Let event fall through. } return false; diff --git a/src/com/android/camera/ui/AbstractIndicator.java b/src/com/android/camera/ui/AbstractIndicator.java deleted file mode 100644 index 1608e80..0000000 --- a/src/com/android/camera/ui/AbstractIndicator.java +++ /dev/null @@ -1,88 +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.ui; - -import android.content.Context; -import android.graphics.Matrix; -import android.graphics.Rect; -import android.view.animation.AlphaAnimation; -import android.view.animation.Transformation; - -import javax.microedition.khronos.opengles.GL11; - -abstract class AbstractIndicator extends GLView { - private static final int DEFAULT_PADDING = 3; - private int mOrientation = 0; - - abstract protected BitmapTexture getIcon(); - - public AbstractIndicator(Context context) { - int padding = GLRootView.dpToPixel(context, DEFAULT_PADDING); - setPaddings(padding, 0, padding, 0); - } - - @Override - protected void onMeasure(int widthSpec, int heightSpec) { - BitmapTexture icon = getIcon(); - new MeasureHelper(this) - .setPreferredContentSize(icon.getWidth(), icon.getHeight()) - .measure(widthSpec, heightSpec); - } - - @Override - protected void render(GLRootView root, GL11 gl) { - BitmapTexture icon = getIcon(); - if (icon != null) { - Rect p = mPaddings; - int width = getWidth() - p.left - p.right; - int height = getHeight() - p.top - p.bottom; - if (mOrientation != 0) { - Transformation trans = root.pushTransform(); - Matrix matrix = trans.getMatrix(); - matrix.preTranslate(p.left + width / 2, p.top + height / 2); - matrix.preRotate(-mOrientation); - icon.draw(root, -icon.getWidth() / 2, -icon.getHeight() / 2); - root.popTransform(); - } else { - icon.draw(root, - p.left + (width - icon.getWidth()) / 2, - p.top + (height - icon.getHeight()) / 2); - } - } - } - - public void setOrientation(int orientation) { - if (orientation % 90 != 0) throw new IllegalArgumentException(); - orientation = orientation % 360; - if (orientation < 0) orientation += 360; - - if (mOrientation == orientation) return; - mOrientation = orientation; - - if (getGLRootView() != null) { - AlphaAnimation anim = new AlphaAnimation(0.2f, 1); - anim.setDuration(200); - startAnimation(anim); - } - } - - abstract public GLView getPopupContent(); - - abstract public void overrideSettings(String key, String settings); - - abstract public void reloadPreferences(); -} diff --git a/src/com/android/camera/ui/AbstractIndicatorButton.java b/src/com/android/camera/ui/AbstractIndicatorButton.java index efed757..414ec4e 100644 --- a/src/com/android/camera/ui/AbstractIndicatorButton.java +++ b/src/com/android/camera/ui/AbstractIndicatorButton.java @@ -90,7 +90,9 @@ public abstract class AbstractIndicatorButton extends RotateImageView { @Override public void setDegree(int degree) { super.setDegree(degree); - if (mPopup != null) mPopup.setRotation(-degree); + if (mPopup != null) { + mPopup.setOrientation(degree); + } } abstract protected void initializePopup(); @@ -98,12 +100,11 @@ public abstract class AbstractIndicatorButton extends RotateImageView { private void showPopup() { if (mPopup == null) initializePopup(); - mPopup.setRotation(-getDegree()); + mPopup.setVisibility(View.VISIBLE); + mPopup.setOrientation(getDegree()); mPopup.clearAnimation(); mPopup.startAnimation(mFadeIn); - mPopup.setVisibility(View.VISIBLE); setColorFilter(HIGHLIGHT_COLOR); - invalidate(); } public boolean dismissPopup() { diff --git a/src/com/android/camera/ui/AbstractSettingPopup.java b/src/com/android/camera/ui/AbstractSettingPopup.java index 794152e..7cc4010 100644 --- a/src/com/android/camera/ui/AbstractSettingPopup.java +++ b/src/com/android/camera/ui/AbstractSettingPopup.java @@ -29,7 +29,7 @@ import android.widget.TextView; import com.android.camera.R; // A popup window that shows one or more camera settings. -abstract public class AbstractSettingPopup extends LinearLayout { +abstract public class AbstractSettingPopup extends RotateLayout { protected ViewGroup mSettingList; protected TextView mTitle; diff --git a/src/com/android/camera/ui/BasicIndicator.java b/src/com/android/camera/ui/BasicIndicator.java deleted file mode 100644 index 9f076b8..0000000 --- a/src/com/android/camera/ui/BasicIndicator.java +++ /dev/null @@ -1,142 +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.ui; - -import android.content.Context; - -import com.android.camera.IconListPreference; -import com.android.camera.ListPreference; -import com.android.camera.R; -import com.android.camera.Util; -import com.android.camera.ui.GLListView.OnItemSelectedListener; - -class BasicIndicator extends AbstractIndicator { - private static final float FONT_SIZE = 18; - private static final int FONT_COLOR = 0xA8FFFFFF; - private static final int COLOR_OPTION_ITEM_HIGHLIGHT = 0xFF181818; - - private final ResourceTexture mIcon[]; - private final ListPreference mPreference; - protected int mIndex; - private GLListView mPopupContent; - private PreferenceAdapter mModel; - private String mOverride; - private int mTitleIndex; - private StringTexture mTitle; - private final float mFontSize; - private boolean mIsIconListMode; - - public BasicIndicator(Context context, ListPreference preference) { - super(context); - mPreference = preference; - mIndex = preference.findIndexOfValue(preference.getValue()); - if (preference instanceof IconListPreference) { - mIsIconListMode = true; - mIcon = new ResourceTexture[((IconListPreference) preference).getLargeIconIds().length]; - mFontSize = 0; - } else { - mIsIconListMode = false; - mIcon = null; - mFontSize = GLRootView.dpToPixel(context, FONT_SIZE); - mTitleIndex = -1; - } - } - - // Set the override and/or reload the value from preferences. - private void updateContent(String override, boolean reloadValue) { - if (!reloadValue && Util.equals(mOverride, override)) return; - ListPreference pref = mPreference; - mOverride = override; - int index = pref.findIndexOfValue( - override == null ? pref.getValue() : override); - if (mIndex != index) { - mIndex = index; - invalidate(); - } - } - - @Override - public void overrideSettings(String key, String settings) { - ListPreference pref = mPreference; - if (!pref.getKey().equals(key)) return; - updateContent(settings, false); - } - - @Override - public void reloadPreferences() { - if (mModel != null) mModel.reload(); - updateContent(null, true); - } - - @Override - public GLView getPopupContent() { - if (mPopupContent == null) { - Context context = getGLRootView().getContext(); - mPopupContent = new GLListView(context); - mPopupContent.setHighLight( - new ColorTexture(COLOR_OPTION_ITEM_HIGHLIGHT)); - mPopupContent.setScroller(new NinePatchTexture( - context, R.drawable.scrollbar_handle_vertical)); - mModel = new PreferenceAdapter(context, mPreference); - mPopupContent.setOnItemSelectedListener(new MyListener(mModel)); - mPopupContent.setDataModel(mModel); - } - mModel.overrideSettings(mOverride); - return mPopupContent; - } - - protected void onPreferenceChanged(int newIndex) { - if (newIndex == mIndex) return; - mIndex = newIndex; - invalidate(); - } - - private class MyListener implements OnItemSelectedListener { - - private final PreferenceAdapter mAdapter; - - public MyListener(PreferenceAdapter adapter) { - mAdapter = adapter; - } - - public void onItemSelected(GLView view, int position) { - mAdapter.onItemSelected(view, position); - onPreferenceChanged(position - 1); - } - } - - @Override - protected BitmapTexture getIcon() { - if (mIsIconListMode) { - int index = mIndex; - if (mIcon[index] == null) { - Context context = getGLRootView().getContext(); - mIcon[index] = new ResourceTexture( - context, ((IconListPreference) mPreference).getLargeIconIds()[index]); - } - return mIcon[index]; - } else { - if (mTitleIndex != mIndex) { - mTitleIndex = mIndex; - if (mTitle != null) mTitle.deleteFromGL(); - String value = mPreference.getEntry(); - mTitle = StringTexture.newInstance(value, mFontSize, FONT_COLOR); - } - return mTitle; - } - } -} diff --git a/src/com/android/camera/ui/CamcorderHeadUpDisplay.java b/src/com/android/camera/ui/CamcorderHeadUpDisplay.java deleted file mode 100644 index 689fe3d..0000000 --- a/src/com/android/camera/ui/CamcorderHeadUpDisplay.java +++ /dev/null @@ -1,69 +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.ui; - -import com.android.camera.CameraSettings; -import com.android.camera.ListPreference; -import com.android.camera.PreferenceGroup; - -import android.content.Context; - -public class CamcorderHeadUpDisplay extends HeadUpDisplay { - - private static final String TAG = "CamcorderHeadUpDisplay"; - - private OtherSettingsIndicator mOtherSettings; - private int mInitialOrientation; - - public CamcorderHeadUpDisplay(Context context) { - super(context); - } - - public void initialize(Context context, PreferenceGroup group, int initialOrientation) { - mInitialOrientation = initialOrientation; - super.initialize(context, group); - } - - @Override - protected void initializeIndicatorBar( - Context context, PreferenceGroup group) { - super.initializeIndicatorBar(context, group); - - ListPreference[] prefs = getListPreferences(group, - CameraSettings.KEY_FOCUS_MODE, - CameraSettings.KEY_EXPOSURE, - CameraSettings.KEY_SCENE_MODE, - CameraSettings.KEY_PICTURE_SIZE); - - mOtherSettings = new OtherSettingsIndicator(context, prefs); - mOtherSettings.setOnRestorePreferencesClickedRunner(new Runnable() { - public void run() { - if (mListener != null) { - mListener.onRestorePreferencesClicked(); - } - } - }); - mIndicatorBar.addComponent(mOtherSettings); - - addIndicator(context, group, CameraSettings.KEY_WHITE_BALANCE); - addIndicator(context, group, CameraSettings.KEY_VIDEOCAMERA_FLASH_MODE); - addIndicator(context, group, CameraSettings.KEY_VIDEO_QUALITY); - addIndicator(context, group, CameraSettings.KEY_CAMERA_ID); - - mIndicatorBar.setOrientation(mInitialOrientation); - } -} diff --git a/src/com/android/camera/ui/CameraHeadUpDisplay.java b/src/com/android/camera/ui/CameraHeadUpDisplay.java deleted file mode 100644 index 500d09e..0000000 --- a/src/com/android/camera/ui/CameraHeadUpDisplay.java +++ /dev/null @@ -1,123 +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.ui; - -import android.content.Context; - -import com.android.camera.CameraSettings; -import com.android.camera.IconListPreference; -import com.android.camera.ListPreference; -import com.android.camera.PreferenceGroup; - -public class CameraHeadUpDisplay extends HeadUpDisplay { - - private static final String TAG = "CamcoderHeadUpDisplay"; - - private OtherSettingsIndicator mOtherSettings; - private ZoomIndicator mZoomIndicator; - private Context mContext; - private float[] mInitialZoomRatios; - private int mInitialOrientation; - - public CameraHeadUpDisplay(Context context) { - super(context); - mContext = context; - } - - public void initialize(Context context, PreferenceGroup group, - float[] initialZoomRatios, int initialOrientation) { - mInitialZoomRatios = initialZoomRatios; - mInitialOrientation = initialOrientation; - super.initialize(context, group); - } - - @Override - protected void initializeIndicatorBar( - Context context, PreferenceGroup group) { - super.initializeIndicatorBar(context, group); - - ListPreference prefs[] = getListPreferences(group, - CameraSettings.KEY_FOCUS_MODE, - CameraSettings.KEY_EXPOSURE, - CameraSettings.KEY_SCENE_MODE, - CameraSettings.KEY_PICTURE_SIZE, - CameraSettings.KEY_COLOR_EFFECT, - CameraSettings.KEY_RECORD_LOCATION); - - mOtherSettings = new OtherSettingsIndicator(context, prefs); - mOtherSettings.setOnRestorePreferencesClickedRunner(new Runnable() { - public void run() { - if (mListener != null) { - mListener.onRestorePreferencesClicked(); - } - } - }); - mIndicatorBar.addComponent(mOtherSettings); - - addIndicator(context, group, CameraSettings.KEY_WHITE_BALANCE); - addIndicator(context, group, CameraSettings.KEY_FLASH_MODE); - - if (mInitialZoomRatios != null) { - mZoomIndicator = new ZoomIndicator(mContext); - mZoomIndicator.setZoomRatios(mInitialZoomRatios); - mIndicatorBar.addComponent(mZoomIndicator); - } else { - mZoomIndicator = null; - } - - addIndicator(context, group, CameraSettings.KEY_CAMERA_ID); - - mIndicatorBar.setOrientation(mInitialOrientation); - } - - public void setZoomListener(ZoomControllerListener listener) { - // The rendering thread won't access listener variable, so we don't - // need to do concurrency protection here - mZoomIndicator.setZoomListener(listener); - } - - public void setZoomIndex(int index) { - GLRootView root = getGLRootView(); - if (root != null) { - synchronized (root) { - mZoomIndicator.setZoomIndex(index); - } - } else { - mZoomIndicator.setZoomIndex(index); - } - } - - /** - * Sets the zoom rations the camera driver provides. This methods must be - * called before <code>setZoomListener()</code> and - * <code>setZoomIndex()</code> - */ - public void setZoomRatios(float[] zoomRatios) { - GLRootView root = getGLRootView(); - if (root != null) { - synchronized(root) { - setZoomRatiosLocked(zoomRatios); - } - } else { - setZoomRatiosLocked(zoomRatios); - } - } - - private void setZoomRatiosLocked(float[] zoomRatios) { - mZoomIndicator.setZoomRatios(zoomRatios); - } -} diff --git a/src/com/android/camera/ui/HeadUpDisplay.java b/src/com/android/camera/ui/HeadUpDisplay.java deleted file mode 100644 index 04ca677..0000000 --- a/src/com/android/camera/ui/HeadUpDisplay.java +++ /dev/null @@ -1,425 +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.ui; - -import static com.android.camera.ui.GLRootView.dpToPixel; -import com.android.camera.CameraSettings; -import com.android.camera.ComboPreferences; -import com.android.camera.ListPreference; -import com.android.camera.PreferenceGroup; -import com.android.camera.R; - -import android.content.Context; -import android.content.SharedPreferences; -import android.content.SharedPreferences.OnSharedPreferenceChangeListener; -import android.graphics.Rect; -import android.hardware.Camera.Parameters; -import android.os.Handler; -import android.os.Message; -import android.util.DisplayMetrics; -import android.util.Log; -import android.view.MotionEvent; -import android.view.View.MeasureSpec; -import android.view.animation.AlphaAnimation; -import android.view.animation.Animation; -import java.util.ArrayList; - -// This is the UI for the on-screen settings. Since the rendering is run in the -// GL thread. If any values will be changed in the main thread, it needs to -// synchronize on the <code>GLRootView</code> instance. -public class HeadUpDisplay extends GLView { - private static final int INDICATOR_BAR_TIMEOUT = 5500; - private static final int POPUP_WINDOW_TIMEOUT = 5000; - private static final int INDICATOR_BAR_RIGHT_MARGIN = 10; - private static final int POPUP_WINDOW_OVERLAP = 20; - private static final int POPUP_TRIANGLE_OFFSET = 16; - - private static final int COLOR_ICONBAR_HIGHLIGHT = 0x9A2B2B2B; - - private static final float MAX_HEIGHT_RATIO = 0.85f; - private static final float MAX_WIDTH_RATIO = 0.8f; - - private static final int DESELECT_INDICATOR = 0; - private static final int DEACTIVATE_INDICATOR_BAR = 1; - - private static int sIndicatorBarRightMargin = -1; - private static int sPopupWindowOverlap; - private static int sPopupTriangleOffset; - - private static final String TAG = "HeadUpDisplay"; - - protected IndicatorBar mIndicatorBar; - - private ComboPreferences mSharedPrefs; - private PreferenceGroup mPreferenceGroup; - - private GLPopupWindow mPopupWindow; - - private GLView mAnchorView; - private int mOrientation = 0; - private boolean mEnabled = true; - - protected Listener mListener; - - private Handler mHandler = new Handler() { - @Override - public void handleMessage(Message msg) { - GLRootView root = getGLRootView(); - if (root != null) { - synchronized (root) { - handleMessageLocked(msg); - } - } else { - handleMessageLocked(msg); - } - } - - private void handleMessageLocked(Message msg) { - switch(msg.what) { - case DESELECT_INDICATOR: - mIndicatorBar.setSelectedIndex(IndicatorBar.INDEX_NONE); - break; - case DEACTIVATE_INDICATOR_BAR: - if (mIndicatorBar != null) { - mIndicatorBar.setActivated(false); - } - break; - } - } - }; - - private final OnSharedPreferenceChangeListener mSharedPreferenceChangeListener = - new OnSharedPreferenceChangeListener() { - public void onSharedPreferenceChanged( - SharedPreferences sharedPreferences, String key) { - if (mListener != null) { - mListener.onSharedPreferenceChanged(); - } - } - }; - - public HeadUpDisplay(Context context) { - initializeStaticVariables(context); - } - - private static void initializeStaticVariables(Context context) { - if (sIndicatorBarRightMargin >= 0) return; - - sIndicatorBarRightMargin = dpToPixel(context, INDICATOR_BAR_RIGHT_MARGIN); - sPopupWindowOverlap = dpToPixel(context, POPUP_WINDOW_OVERLAP); - sPopupTriangleOffset = dpToPixel(context, POPUP_TRIANGLE_OFFSET); - } - - /** - * The callback interface. All the callbacks will be called from the - * GLThread. - */ - static public interface Listener { - public void onPopupWindowVisibilityChanged(int visibility); - public void onRestorePreferencesClicked(); - public void onSharedPreferenceChanged(); - } - - public void overrideSettings(final String ... keyvalues) { - GLRootView root = getGLRootView(); - if (root != null) { - synchronized (root) { - overrideSettingsLocked(keyvalues); - } - } else { - overrideSettingsLocked(keyvalues); - } - } - - public void overrideSettingsLocked(final String ... keyvalues) { - if (keyvalues.length % 2 != 0) { - throw new IllegalArgumentException(); - } - for (int i = 0, n = keyvalues.length; i < n; i += 2) { - mIndicatorBar.overrideSettings(keyvalues[i], keyvalues[i + 1]); - } - } - - @Override - protected void onLayout( - boolean changed, int left, int top, int right, int bottom) { - int width = right - left; - int height = bottom - top; - mIndicatorBar.measure( - MeasureSpec.makeMeasureSpec(width / 3, MeasureSpec.AT_MOST), - MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)); - DisplayMetrics metrics = getGLRootView().getDisplayMetrics(); - int rightMargin = (int) (metrics.density * INDICATOR_BAR_RIGHT_MARGIN); - - mIndicatorBar.layout( - width - mIndicatorBar.getMeasuredWidth() - rightMargin, 0, - width - rightMargin, height); - - if(mPopupWindow != null - && mPopupWindow.getVisibility() == GLView.VISIBLE) { - layoutPopupWindow(mAnchorView); - } - } - - public void initialize(Context context, PreferenceGroup preferenceGroup) { - mPreferenceGroup = preferenceGroup; - mSharedPrefs = ComboPreferences.get(context); - mPopupWindow = null; - clearComponents(); - initializeIndicatorBar(context, preferenceGroup); - requestLayout(); - } - - private void layoutPopupWindow(GLView anchorView) { - - mAnchorView = anchorView; - Rect rect = new Rect(); - getBoundsOf(anchorView, rect); - - int anchorX = rect.left + sPopupWindowOverlap; - int anchorY = (rect.top + rect.bottom) / 2; - - int width = (int) (getWidth() * MAX_WIDTH_RATIO + .5); - int height = (int) (getHeight() * MAX_HEIGHT_RATIO + .5); - - mPopupWindow.measure( - MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST), - MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST)); - - width = mPopupWindow.getMeasuredWidth(); - height = mPopupWindow.getMeasuredHeight(); - - int xoffset = Math.max(anchorX - width, 0); - int yoffset = Math.max(0, anchorY - height / 2); - - if (yoffset + height > getHeight()) { - yoffset = getHeight() - height; - } - mPopupWindow.setAnchorPosition(anchorY - yoffset); - mPopupWindow.layout( - xoffset, yoffset, xoffset + width, yoffset + height); - } - - private void showPopupWindow(GLView anchorView) { - layoutPopupWindow(anchorView); - mPopupWindow.popup(); - mSharedPrefs.registerOnSharedPreferenceChangeListener( - mSharedPreferenceChangeListener); - if (mListener != null) { - mListener.onPopupWindowVisibilityChanged(GLView.VISIBLE); - } - } - - private void hidePopupWindow() { - mPopupWindow.popoff(); - // Unregister is important to avoid leaking activities. - // ComboPreference.sMap->ComboPreference->HeadUpDisplay->Activity - mSharedPrefs.unregisterOnSharedPreferenceChangeListener( - mSharedPreferenceChangeListener); - if (mListener != null) { - mListener.onPopupWindowVisibilityChanged(GLView.INVISIBLE); - } - } - - private void scheduleDeactiviateIndicatorBar() { - mHandler.removeMessages(DESELECT_INDICATOR); - mHandler.sendEmptyMessageDelayed( - DESELECT_INDICATOR, POPUP_WINDOW_TIMEOUT); - mHandler.removeMessages(DEACTIVATE_INDICATOR_BAR); - mHandler.sendEmptyMessageDelayed( - DEACTIVATE_INDICATOR_BAR, INDICATOR_BAR_TIMEOUT); - } - - public void setOrientation(int orientation) { - GLRootView root = getGLRootView(); - if (root != null) { - synchronized (root) { - setOrientationLocked(orientation); - } - } else { - setOrientationLocked(orientation); - } - } - - private void setOrientationLocked(int orientation) { - mOrientation = orientation; - mIndicatorBar.setOrientation(orientation); - if (mPopupWindow == null) return; - if (mPopupWindow.getVisibility() == GLView.VISIBLE) { - Animation alpha = new AlphaAnimation(0.2f, 1); - alpha.setDuration(250); - mPopupWindow.startAnimation(alpha); - scheduleDeactiviateIndicatorBar(); - } - mPopupWindow.setOrientation(orientation); - } - - private void initializePopupWindow(Context context) { - mPopupWindow = new GLPopupWindow(); - mPopupWindow.setBackground( - new NinePatchTexture(context, R.drawable.menu_popup)); - mPopupWindow.setAnchor(new ResourceTexture( - context, R.drawable.menu_popup_triangle), sPopupTriangleOffset); - mPopupWindow.setVisibility(GLView.INVISIBLE); - mPopupWindow.setOrientation(mOrientation); - addComponent(mPopupWindow); - } - - @Override - protected boolean dispatchTouchEvent(MotionEvent event) { - if (mEnabled && super.dispatchTouchEvent(event)) { - scheduleDeactiviateIndicatorBar(); - return true; - } - return false; - } - - public void setEnabled(boolean enabled) { - // The mEnabled variable is not related to the rendering thread, so we - // don't need to synchronize on the GLRootView. - if (mEnabled == enabled) return; - mEnabled = enabled; - } - - @Override - protected boolean onTouch(MotionEvent event) { - if (mPopupWindow == null - || mPopupWindow.getVisibility() == GLView.INVISIBLE) { - return false; - } - - switch (event.getAction()) { - case MotionEvent.ACTION_UP: - hidePopupWindow(); - mIndicatorBar.setSelectedIndex(IndicatorBar.INDEX_NONE); - mIndicatorBar.setActivated(false); - break; - } - return true; - } - - protected static ListPreference[] getListPreferences( - PreferenceGroup group, String ... prefKeys) { - ArrayList<ListPreference> list = new ArrayList<ListPreference>(); - for (String key : prefKeys) { - ListPreference pref = group.findPreference(key); - if (pref != null && pref.getEntries().length > 0) { - list.add(pref); - } - } - return list.toArray(new ListPreference[list.size()]); - } - - protected BasicIndicator addIndicator( - Context context, PreferenceGroup group, String key) { - ListPreference iconPref = group.findPreference(key); - if (iconPref == null) return null; - BasicIndicator indicator = new BasicIndicator(context, iconPref); - mIndicatorBar.addComponent(indicator); - return indicator; - } - - protected void initializeIndicatorBar( - Context context, PreferenceGroup group) { - mIndicatorBar = new IndicatorBar(); - - mIndicatorBar.setBackground(new NinePatchTexture( - context, R.drawable.ic_viewfinder_iconbar)); - mIndicatorBar.setHighlight(new ColorTexture(COLOR_ICONBAR_HIGHLIGHT)); - addComponent(mIndicatorBar); - mIndicatorBar.setOnItemSelectedListener(new IndicatorBarListener()); - } - - private class IndicatorBarListener - implements IndicatorBar.OnItemSelectedListener { - - public void onItemSelected(GLView view, int position) { - - AbstractIndicator indicator = (AbstractIndicator) view; - if (mPopupWindow == null) { - initializePopupWindow(getGLRootView().getContext()); - } - mPopupWindow.setContent(indicator.getPopupContent()); - - if (mPopupWindow.getVisibility() == GLView.VISIBLE) { - layoutPopupWindow(indicator); - } else { - showPopupWindow(indicator); - } - } - - public void onNothingSelected() { - hidePopupWindow(); - } - } - - public boolean collapse() { - // We don't need to synchronize on GLRootView, since both the - // <code>isActivated()</code> and rendering thread are read-only to - // the variables inside. - if (!mIndicatorBar.isActivated()) return false; - mHandler.removeMessages(DESELECT_INDICATOR); - mHandler.removeMessages(DEACTIVATE_INDICATOR_BAR); - GLRootView root = getGLRootView(); - if (root != null) { - synchronized (root) { - mIndicatorBar.setSelectedIndex(IndicatorBar.INDEX_NONE); - mIndicatorBar.setActivated(false); - } - } else { - mIndicatorBar.setSelectedIndex(IndicatorBar.INDEX_NONE); - mIndicatorBar.setActivated(false); - } - return true; - } - - public void setListener(Listener listener) { - // No synchronization: mListener won't be accessed in rendering thread - mListener = listener; - } - - public void restorePreferences(final Parameters param) { - // Do synchronization in "reloadPreferences()" - - OnSharedPreferenceChangeListener l = - mSharedPreferenceChangeListener; - // Unregister the listener since "upgrade preference" will - // change bunch of preferences. We can handle them with one - // onSharedPreferenceChanged(); - mSharedPrefs.unregisterOnSharedPreferenceChangeListener(l); - Context context = getGLRootView().getContext(); - CameraSettings.restorePreferences(context, mSharedPrefs, param); - reloadPreferences(); - if (mListener != null) { - mListener.onSharedPreferenceChanged(); - } - mSharedPrefs.registerOnSharedPreferenceChangeListener(l); - } - - public void reloadPreferences() { - GLRootView root = getGLRootView(); - if (root != null) { - synchronized (root) { - mPreferenceGroup.reloadValue(); - mIndicatorBar.reloadPreferences(); - } - } else { - mPreferenceGroup.reloadValue(); - mIndicatorBar.reloadPreferences(); - } - } -} diff --git a/src/com/android/camera/ui/IndicatorBar.java b/src/com/android/camera/ui/IndicatorBar.java index fb748e8..1e52f9c 100644 --- a/src/com/android/camera/ui/IndicatorBar.java +++ b/src/com/android/camera/ui/IndicatorBar.java @@ -16,202 +16,70 @@ package com.android.camera.ui; -import javax.microedition.khronos.opengles.GL11; - -import android.graphics.Rect; -import android.util.Log; +import android.content.Context; +import android.util.AttributeSet; import android.view.MotionEvent; -import android.view.View.MeasureSpec; -import android.view.animation.AlphaAnimation; - -class IndicatorBar extends GLView { - private static final String TAG ="IndicatorBar"; - public static final int INDEX_NONE = -1; - - private NinePatchTexture mBackground; - private Texture mHighlight; - private int mSelectedIndex = INDEX_NONE; - - private OnItemSelectedListener mSelectedListener; - private boolean mActivated = false; - private boolean mSelectionChanged = false; - - private class Background extends GLView { - @Override - protected void render(GLRootView root, GL11 gl) { - mBackground.draw(root, 0, 0, getWidth(), getHeight()); - - if (mActivated && mSelectedIndex != INDEX_NONE - && mHighlight != null) { - Rect bounds = IndicatorBar.this.getComponent( - mSelectedIndex + 1).mBounds; - mHighlight.draw(root, bounds.left, bounds.top, - bounds.width(), bounds.height()); - } - } - } - - public interface OnItemSelectedListener { - public void onItemSelected(GLView view, int position); - public void onNothingSelected(); - } - - public IndicatorBar() { - GLView background = new Background(); - background.setVisibility(GLView.INVISIBLE); - addComponent(background); - } +import java.util.ArrayList; - public void overrideSettings(String key, String value) { - for (int i = 1, n = getComponentCount(); i < n; ++i) { - AbstractIndicator indicator = (AbstractIndicator) getComponent(i); - indicator.overrideSettings(key, value); - } - } - - public void setOnItemSelectedListener(OnItemSelectedListener l) { - mSelectedListener = l; - } +/** + * A view that contains camera setting indicators which are spread over a + * vertical bar in preview frame. + */ +public class IndicatorBar extends IndicatorControl { + private static final String TAG = "IndicatorBar"; + int mSelectedIndex = -1; - public void setBackground(NinePatchTexture background) { - if (mBackground == background) return; - mBackground = background; - if (background != null) { - setPaddings(background.getPaddings()); - } else { - setPaddings(0, 0, 0, 0); - } - invalidate(); + public IndicatorBar(Context context) { + super(context); } - public void setHighlight(Texture highlight) { - if (mHighlight == highlight) return; - mHighlight = highlight; - invalidate(); + public IndicatorBar(Context context, AttributeSet attrs) { + super(context, attrs); } @Override - protected void onMeasure(int widthSpec, int heightSpec) { - int width = 0; - int height = 0; - for (int i = 1, n = getComponentCount(); i < n; ++i) { - GLView component = getComponent(i); - component.measure( - MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); - width = Math.max(width, component.getMeasuredWidth()); - height += component.getMeasuredHeight(); + public boolean dispatchTouchEvent(MotionEvent event) { + if (!onFilterTouchEventForSecurity(event)) return false; + + int action = event.getAction(); + + if (!isEnabled()) return false; + + double x = (double) event.getX(); + double y = (double) event.getY(); + if (x > getWidth() || x < 0) return false; + if (y > getHeight() || y < 0) return false; + + int index = (int) (y * getChildCount()) / getHeight(); + AbstractIndicatorButton b = (AbstractIndicatorButton) getChildAt(index); + b.dispatchTouchEvent(event); + if ((mSelectedIndex != -1) && (index != mSelectedIndex)) { + AbstractIndicatorButton c = (AbstractIndicatorButton) getChildAt(mSelectedIndex); + event.setAction(MotionEvent.ACTION_CANCEL); + c.dispatchTouchEvent(event); + c.dismissPopup(); + + if (action == MotionEvent.ACTION_MOVE) { + event.setAction(MotionEvent.ACTION_DOWN); + b.dispatchTouchEvent(event); + } } - new MeasureHelper(this) - .setPreferredContentSize(width, height) - .measure(widthSpec, heightSpec); + mSelectedIndex = index; + return true; } @Override protected void onLayout( boolean changed, int left, int top, int right, int bottom) { - // Background - getComponent(0).layout(0, 0, right - left, bottom - top); - - int count = getComponentCount(); - Rect p = mPaddings; - int cBottom = bottom - top - p.bottom; - int cRight = right - left - p.right; - int yoffset = mPaddings.top; - int xoffset = mPaddings.left; - for (int i = 1; i < count; ++i) { - int cHeight = (cBottom - yoffset) / (count - i); - int nextYoffset = yoffset + cHeight; - getComponent(i).layout(xoffset, yoffset, cRight, nextYoffset); - yoffset = nextYoffset; - } - } - - private void setSelectedItem(GLView view, int index) { - if (index == mSelectedIndex) return; - mSelectionChanged = true; - mSelectedIndex = index; - if (mSelectedListener != null) { - if (index == INDEX_NONE) { - mSelectedListener.onNothingSelected(); - } else { - mSelectedListener.onItemSelected(view, index); - } + int count = getChildCount(); + if (count == 0) return; + int width = right - left; + int height = bottom - top; + int h = height / count; + for (int i = 0; i < count; i++) { + getChildAt(i).layout(0, top + i * height / count, width, + top + i * height / count + h); } - invalidate(); - } - - public void setSelectedIndex(int index) { - if (index == mSelectedIndex) return; - setSelectedItem(index == INDEX_NONE ? null :getComponent(index), index); - } - - public void setActivated(boolean activated) { - if (activated == mActivated) return; - mActivated = activated; - if (activated) { - GLView background = getComponent(0); - background.setVisibility(GLView.VISIBLE); - AlphaAnimation anim = new AlphaAnimation(0, 1); - anim.setDuration(200); - background.startAnimation(anim); - } else { - GLView background = getComponent(0); - background.setVisibility(GLView.INVISIBLE); - AlphaAnimation anim = new AlphaAnimation(1, 0); - anim.setDuration(200); - background.startAnimation(anim); - } - } - - public boolean isActivated() { - return mActivated; - } - - @Override - protected boolean dispatchTouchEvent(MotionEvent event) { - // Do not pass motion events to children - return onTouch(event); - } - - @Override @SuppressWarnings("fallthrough") - protected boolean onTouch(MotionEvent event) { - int y = (int) event.getY(); - switch (event.getAction()) { - case MotionEvent.ACTION_DOWN: - mSelectionChanged = false; - setActivated(true); - case MotionEvent.ACTION_MOVE: - for (int i = 1, n = getComponentCount(); i < n; ++i) { - GLView component = getComponent(i); - if (y <= component.mBounds.bottom) { - setSelectedItem(component, i - 1); - return true; - } - } - setSelectedItem(null, INDEX_NONE); - break; - case MotionEvent.ACTION_UP: - if (mSelectionChanged == false) { - setSelectedItem(null, INDEX_NONE); - } - } - return true; - } - - public void reloadPreferences() { - for (int i = 1, n = getComponentCount(); i < n; ++i) { - ((AbstractIndicator) getComponent(i)).reloadPreferences(); - } - } - - public void setOrientation(int orientation) { - for (int i = 1, n = getComponentCount(); i < n; ++i) { - ((AbstractIndicator) getComponent(i)).setOrientation(orientation); - } - } - - public int getSelectedIndex() { - return mSelectedIndex; } } diff --git a/src/com/android/camera/ui/IndicatorButton.java b/src/com/android/camera/ui/IndicatorButton.java index deb2344..2a7abe1 100644 --- a/src/com/android/camera/ui/IndicatorButton.java +++ b/src/com/android/camera/ui/IndicatorButton.java @@ -98,7 +98,7 @@ public class IndicatorButton extends AbstractIndicatorButton implements BasicSet protected void initializePopup() { LayoutInflater inflater = (LayoutInflater) mContext.getSystemService( Context.LAYOUT_INFLATER_SERVICE); - ViewGroup root = (ViewGroup) getRootView().findViewById(R.id.app_root); + ViewGroup root = (ViewGroup) getRootView().findViewById(R.id.frame); BasicSettingPopup popup = (BasicSettingPopup) inflater.inflate( R.layout.basic_setting_popup, root, false); diff --git a/src/com/android/camera/ui/IndicatorControl.java b/src/com/android/camera/ui/IndicatorControl.java new file mode 100644 index 0000000..2791c20 --- /dev/null +++ b/src/com/android/camera/ui/IndicatorControl.java @@ -0,0 +1,177 @@ +/* + * 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.ui; + +import com.android.camera.IconListPreference; +import com.android.camera.PreferenceGroup; +import com.android.camera.R; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.View; +import android.view.ViewGroup; + +import java.util.ArrayList; + +/** + * A view that contains camera setting indicators. The indicators are spreaded + * differently based on the screen resolution. + */ +public abstract class IndicatorControl extends ViewGroup implements + IndicatorButton.Listener, OtherSettingsPopup.Listener { + private static final String TAG = "IndicatorControl"; + + private Context mContext; + private Listener mListener; + + private PreferenceGroup mPreferenceGroup; + + ArrayList<AbstractIndicatorButton> mIndicators = + new ArrayList<AbstractIndicatorButton>(); + + static public interface Listener { + public void onSharedPreferenceChanged(); + public void onRestorePreferencesClicked(); + public void onOverriddenPreferencesClicked(); + } + + public void setListener(Listener listener) { + mListener = listener; + } + + public IndicatorControl(Context context) { + super(context); + mContext = context; + } + + public IndicatorControl(Context context, AttributeSet attrs) { + super(context, attrs); + mContext = context; + } + + public void setDegree(int degree) { + int count = getChildCount(); + for (int i = 0 ; i < count ; ++i) { + View view = getChildAt(i); + if (view instanceof RotateImageView) { + ((RotateImageView) view).setDegree(degree); + } + } + } + + public void initialize(Context context, PreferenceGroup group, + String[] keys, String[] otherSettingKeys) { + // Reset the variables and states. + dismissSettingPopup(); + removeIndicators(); + + // Initialize all variables and icons. + mPreferenceGroup = group; + // Add other settings indicator. + if (otherSettingKeys != null) { + addOtherSettingIndicator(context, R.drawable.ic_viewfinder_settings, otherSettingKeys); + } + + for (int i = 0; i < keys.length; i++) { + IconListPreference pref = (IconListPreference) group.findPreference(keys[i]); + if (pref != null) { + addIndicator(context, pref); + } + } + + requestLayout(); + } + + private void removeIndicators() { + for (View v: mIndicators) { + removeView(v); + } + mIndicators.clear(); + } + + @Override + public boolean shouldDelayChildPressedState() { + // Return false so the pressed feedback of the back/front camera switch + // can be showed right away. + return false; + } + + public void addIndicator(Context context, IconListPreference pref) { + IndicatorButton b = new IndicatorButton(context, pref); + b.setSettingChangedListener(this); + addView(b); + mIndicators.add(b); + } + + public void addOtherSettingIndicator(Context context, int resId, String[] keys) { + OtherSettingIndicatorButton b = new OtherSettingIndicatorButton(context, resId, + mPreferenceGroup, keys); + b.setSettingChangedListener(this); + addView(b); + mIndicators.add(b); + } + + @Override + public void onRestorePreferencesClicked() { + if (mListener != null) { + mListener.onRestorePreferencesClicked(); + } + } + + @Override + public void onSettingChanged() { + if (mListener != null) { + mListener.onSharedPreferenceChanged(); + } + } + + public boolean dismissSettingPopup() { + for (AbstractIndicatorButton v: mIndicators) { + if (v.dismissPopup()) { + invalidate(); + return true; + } + } + return false; + } + + public View getActiveSettingPopup() { + for (AbstractIndicatorButton v: mIndicators) { + View result = v.getPopupWindow(); + if (result != null) return result; + } + return null; + } + + // Scene mode may override other camera settings (ex: flash mode). + public void overrideSettings(final String ... keyvalues) { + if (keyvalues.length % 2 != 0) { + throw new IllegalArgumentException(); + } + + for (AbstractIndicatorButton b: mIndicators) { + b.overrideSettings(keyvalues); + } + } + + public void reloadPreferences() { + mPreferenceGroup.reloadValue(); + for (AbstractIndicatorButton b: mIndicators) { + b.reloadPreferences(); + } + } +} diff --git a/src/com/android/camera/ui/IndicatorWheel.java b/src/com/android/camera/ui/IndicatorWheel.java index 1f66550..ac336c1 100644 --- a/src/com/android/camera/ui/IndicatorWheel.java +++ b/src/com/android/camera/ui/IndicatorWheel.java @@ -16,8 +16,6 @@ package com.android.camera.ui; -import com.android.camera.IconListPreference; -import com.android.camera.PreferenceGroup; import com.android.camera.R; import android.content.Context; @@ -29,7 +27,6 @@ import android.os.SystemClock; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; -import android.view.ViewGroup; import java.util.ArrayList; @@ -38,9 +35,9 @@ import java.util.ArrayList; * indicators are spreaded around the shutter button. The first child is always * the shutter button. */ -public class IndicatorWheel extends ViewGroup implements - IndicatorButton.Listener, OtherSettingsPopup.Listener { +public class IndicatorWheel extends IndicatorControl { private static final String TAG = "IndicatorWheel"; + // The width of the edges on both sides of the wheel, which has less alpha. private static final float EDGE_STROKE_WIDTH = 6f; private static final int HIGHLIGHT_WIDTH = 4; @@ -50,7 +47,6 @@ public class IndicatorWheel extends ViewGroup implements private final int HIGHLIGHT_COLOR; private final int TIME_LAPSE_ARC_COLOR; - private Listener mListener; // The center of the shutter button. private int mCenterX, mCenterY; // The width of the wheel stroke. @@ -70,25 +66,12 @@ public class IndicatorWheel extends ViewGroup implements private long mRecordingStartTime = 0; private long mNumberOfFrames = 0; - private PreferenceGroup mPreferenceGroup; - private ArrayList<AbstractIndicatorButton> mIndicators = - new ArrayList<AbstractIndicatorButton>(); - - static public interface Listener { - public void onSharedPreferenceChanged(); - public void onRestorePreferencesClicked(); - public void onOverriddenPreferencesClicked(); - } - - public void setListener(Listener listener) { - mListener = listener; - } - public IndicatorWheel(Context context, AttributeSet attrs) { super(context, attrs); Resources resources = context.getResources(); HIGHLIGHT_COLOR = resources.getColor(R.color.review_control_pressed_color); TIME_LAPSE_ARC_COLOR = resources.getColor(R.color.time_lapse_arc); + setWillNotDraw(false); mBackgroundPaint = new Paint(); @@ -98,7 +81,7 @@ public class IndicatorWheel extends ViewGroup implements mBackgroundRect = new RectF(); } - public boolean isInsideShutterButton(MotionEvent ev) { + private boolean isInsideShutterButton(MotionEvent ev) { float x = ev.getX(); float y = ev.getY(); float shutterButtonX = mShutterButton.getX(); @@ -111,16 +94,6 @@ public class IndicatorWheel extends ViewGroup implements return false; } - public void setDegree(int degree) { - int count = getChildCount(); - for (int i = 0 ; i < count ; ++i) { - View view = getChildAt(i); - if (view instanceof RotateImageView) { - ((RotateImageView) view).setDegree(degree); - } - } - } - @Override public boolean dispatchTouchEvent(MotionEvent event) { if (!onFilterTouchEventForSecurity(event)) return false; @@ -211,13 +184,6 @@ public class IndicatorWheel extends ViewGroup implements invalidate(); } - private void removeIndicators() { - for (View v: mIndicators) { - removeView(v); - } - mIndicators.clear(); - } - @Override protected void onMeasure(int widthSpec, int heightSpec) { // Measure all children. @@ -384,108 +350,4 @@ public class IndicatorWheel extends ViewGroup implements super.onDraw(canvas); } - - @Override - public boolean shouldDelayChildPressedState() { - // Return false so the pressed feedback of the back/front camera switch - // can be showed right away. - return false; - } - - @Override - public void setEnabled(boolean enabled) { - super.setEnabled(enabled); - // Do not disable shutter button because it will block its performClick. - for (int i = 1; i < getChildCount(); i++) { - getChildAt(i).setEnabled(enabled); - } - } - - private void addIndicator(Context context, IconListPreference pref) { - IndicatorButton b = new IndicatorButton(context, pref); - b.setSettingChangedListener(this); - addView(b); - mIndicators.add(b); - } - - private void addOtherSettingIndicator(Context context, int resId, String[] keys) { - OtherSettingIndicatorButton b = new OtherSettingIndicatorButton(context, resId, - mPreferenceGroup, keys); - b.setSettingChangedListener(this); - addView(b); - mIndicators.add(b); - } - - public void initialize(Context context, PreferenceGroup group, - String[] keys, String[] otherSettingKeys) { - // Reset the variables and states. - dismissSettingPopup(); - removeIndicators(); - - // Initialize all variables and icons. - mPreferenceGroup = group; - for (int i = 0; i < keys.length; i++) { - IconListPreference pref = (IconListPreference) group.findPreference(keys[i]); - if (pref != null) { - addIndicator(context, pref); - } - } - - // Add other settings indicator. - if (otherSettingKeys != null) { - addOtherSettingIndicator(context, R.drawable.ic_viewfinder_settings, otherSettingKeys); - } - - requestLayout(); - } - - @Override - public void onRestorePreferencesClicked() { - if (mListener != null) { - mListener.onRestorePreferencesClicked(); - } - } - - @Override - public void onSettingChanged() { - if (mListener != null) { - mListener.onSharedPreferenceChanged(); - } - } - - public boolean dismissSettingPopup() { - for (AbstractIndicatorButton v: mIndicators) { - if (v.dismissPopup()) { - invalidate(); - return true; - } - } - return false; - } - - public View getActiveSettingPopup() { - for (AbstractIndicatorButton v: mIndicators) { - View result = v.getPopupWindow(); - if (result != null) return result; - } - return null; - } - - // Scene mode may override other camera settings (ex: flash mode). - public void overrideSettings(final String ... keyvalues) { - if (keyvalues.length % 2 != 0) { - throw new IllegalArgumentException(); - } - - for (AbstractIndicatorButton b: mIndicators) { - b.overrideSettings(keyvalues); - } - } - - public void reloadPreferences() { - mPreferenceGroup.reloadValue(); - for (AbstractIndicatorButton b: mIndicators) { - b.reloadPreferences(); - } - } } diff --git a/src/com/android/camera/ui/OtherSettingIndicatorButton.java b/src/com/android/camera/ui/OtherSettingIndicatorButton.java index d77af89..e020f94 100644 --- a/src/com/android/camera/ui/OtherSettingIndicatorButton.java +++ b/src/com/android/camera/ui/OtherSettingIndicatorButton.java @@ -53,7 +53,7 @@ public class OtherSettingIndicatorButton extends AbstractIndicatorButton { protected void initializePopup() { LayoutInflater inflater = (LayoutInflater) mContext.getSystemService( Context.LAYOUT_INFLATER_SERVICE); - ViewGroup root = (ViewGroup) getRootView().findViewById(R.id.app_root); + ViewGroup root = (ViewGroup) getRootView().findViewById(R.id.frame); OtherSettingsPopup popup = (OtherSettingsPopup) inflater.inflate( R.layout.other_setting_popup, root, false); diff --git a/src/com/android/camera/ui/OtherSettingsIndicator.java b/src/com/android/camera/ui/OtherSettingsIndicator.java deleted file mode 100644 index 5cf4628..0000000 --- a/src/com/android/camera/ui/OtherSettingsIndicator.java +++ /dev/null @@ -1,189 +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.ui; - -import android.content.Context; - -import com.android.camera.ListPreference; -import com.android.camera.R; - -import java.util.HashMap; - -class OtherSettingsIndicator extends AbstractIndicator { - private static final int COLOR_OPTION_ITEM_HIGHLIGHT = 0xFF181818; - - private final ListPreference mPreference[]; - private final GLListView.Model mAdapters[]; - private ResourceTexture mIcon; - private GLListView mPopupContent; - private Runnable mOnRestorePrefsClickedRunner; - private final HashMap<String, String> mOverrides = new HashMap<String, String>(); - - public OtherSettingsIndicator( - Context context, ListPreference preference[]) { - super(context); - mPreference = preference; - // One extra for the restore settings - mAdapters = new GLListView.Model[preference.length + 1]; - } - - @Override - protected ResourceTexture getIcon() { - if (mIcon == null) { - Context context = getGLRootView().getContext(); - mIcon = new ResourceTexture( - context, R.drawable.ic_viewfinder_settings); - } - return mIcon; - } - - @Override - public void reloadPreferences() { - if (mPopupContent != null) { - ListPreference prefs[] = mPreference; - for (int i = 0, n = prefs.length; i < n; ++i) { - ((PreferenceAdapter) mAdapters[i]).reload(); - } - } - } - - @Override - public void overrideSettings(String key, String value) { - if (value == null) { - mOverrides.remove(key); - } else { - mOverrides.put(key, value); - } - if (mPopupContent != null) { - ListPreference prefs[] = mPreference; - for (int i = 0, n = prefs.length; i < n; ++i) { - if (!prefs[i].getKey().equals(key)) continue; - ((PreferenceAdapter) mAdapters[i]).overrideSettings(value); - break; - } - } - } - - private UberAdapter buildUberAdapter() { - ListPreference prefs[] = mPreference; - GLListView.Model adapters[] = mAdapters; - Context context = getGLRootView().getContext(); - for (int i = 0, n = prefs.length; i < n; ++i) { - adapters[i] = new PreferenceAdapter(context, prefs[i]); - String override = mOverrides.get(prefs[i].getKey()); - if (override != null) { - ((PreferenceAdapter) adapters[i]).overrideSettings(override); - } - } - adapters[prefs.length] = new RestoreSettingsModel(context); - return new UberAdapter(); - } - - @Override - public GLView getPopupContent() { - if (mPopupContent == null) { - Context context = getGLRootView().getContext(); - mPopupContent = new GLListView(context); - mPopupContent.setHighLight( - new ColorTexture(COLOR_OPTION_ITEM_HIGHLIGHT)); - mPopupContent.setScroller(new NinePatchTexture( - context, R.drawable.scrollbar_handle_vertical)); - UberAdapter adapter = buildUberAdapter(); - mPopupContent.setOnItemSelectedListener(adapter); - mPopupContent.setDataModel(adapter); - } - return mPopupContent; - } - - private class UberAdapter implements - GLListView.Model, GLListView.OnItemSelectedListener { - - public GLView getView(int index) { - for (GLListView.Model adapter : mAdapters) { - if (index < adapter.size()) { - return adapter.getView(index); - } - index -= adapter.size(); - } - return null; - } - - public boolean isSelectable(int index) { - for (GLListView.Model adapter : mAdapters) { - if (index < adapter.size()) { - return adapter.isSelectable(index); - } - index -= adapter.size(); - } - return true; - } - - public int size() { - int size = 0; - for (GLListView.Model adapter : mAdapters) { - size += adapter.size(); - } - return size; - } - - public void onItemSelected(GLView view, int position) { - for (GLListView.Model adapter : mAdapters) { - if (position < adapter.size()) { - ((GLListView.OnItemSelectedListener) - adapter).onItemSelected(view, position); - return; - } - position -= adapter.size(); - } - } - } - - private class RestoreSettingsModel - implements GLListView.Model, GLListView.OnItemSelectedListener { - private final GLView mHeader; - private final GLView mItem; - - public RestoreSettingsModel(Context context) { - mHeader = new GLOptionHeader(context, - context.getString(R.string.pref_restore_title)); - mItem = new RestoreSettingsItem( - context, context.getString(R.string.pref_restore_detail)); - } - - public GLView getView(int index) { - return index == 0 ? mHeader : mItem; - } - - public boolean isSelectable(int index) { - return index != 0; - } - - public int size() { - return 2; - } - - public void onItemSelected(GLView view, int position) { - if (mOnRestorePrefsClickedRunner != null) { - mOnRestorePrefsClickedRunner.run(); - } - } - } - - public void setOnRestorePreferencesClickedRunner(Runnable l) { - mOnRestorePrefsClickedRunner = l; - } -} diff --git a/src/com/android/camera/ui/ZoomIndicator.java b/src/com/android/camera/ui/ZoomIndicator.java deleted file mode 100644 index e2decf1..0000000 --- a/src/com/android/camera/ui/ZoomIndicator.java +++ /dev/null @@ -1,145 +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.ui; - -import android.content.Context; -import android.util.Log; - -import com.android.camera.R; -import com.android.camera.ui.ZoomControllerListener; - -import java.text.DecimalFormat; - -class ZoomIndicator extends AbstractIndicator { - private static final DecimalFormat sZoomFormat = new DecimalFormat("#.#x"); - private static final float FONT_SIZE = 18; - private static final int FONT_COLOR = 0xA8FFFFFF; - private static final int COLOR_OPTION_HEADER = 0xFF2B2B2B; - - protected static final String TAG = "ZoomIndicator"; - - private final float mFontSize; - - private ZoomController mZoomController; - private GLLinearLayout mPopupContent; - private ZoomControllerListener mZoomListener; - private int mZoomIndex = 0; - private int mDrawIndex = -1; - private float mZoomRatios[]; - - private StringTexture mTitle; - - public ZoomIndicator(Context context) { - super(context); - mFontSize = GLRootView.dpToPixel(context, FONT_SIZE); - } - - @Override - protected void onMeasure(int widthSpec, int heightSpec) { - int maxWidth = 0; - int maxHeight = 0; - int n = mZoomRatios == null ? 0: mZoomRatios.length; - for (int i = 0; i < n; ++i) { - float value = mZoomRatios[i]; - BitmapTexture tex = StringTexture.newInstance( - sZoomFormat.format(value), mFontSize, FONT_COLOR); - if (maxWidth < tex.getWidth()) maxWidth = tex.getWidth(); - if (maxHeight < tex.getHeight()) maxHeight = tex.getHeight(); - } - new MeasureHelper(this) - .setPreferredContentSize(maxWidth, maxHeight) - .measure(widthSpec, heightSpec); - } - - @Override - protected BitmapTexture getIcon() { - if (mDrawIndex != mZoomIndex) { - mDrawIndex = mZoomIndex; - if (mTitle != null) mTitle.deleteFromGL(); - float value = mZoomRatios[mZoomIndex]; - mTitle = StringTexture.newInstance( - sZoomFormat.format(value), mFontSize, FONT_COLOR); - } - return mTitle; - } - - @Override - public GLView getPopupContent() { - if (mZoomController == null) { - Context context = getGLRootView().getContext(); - mZoomController = new ZoomController(context); - mZoomController.setAvailableZoomRatios(mZoomRatios); - mZoomController.setPaddings(15, 6, 15, 6); - - mPopupContent = new GLLinearLayout(); - GLOptionHeader header = new GLOptionHeader(context, - context.getString(R.string.zoom_control_title)); - header.setBackground(new ColorTexture(COLOR_OPTION_HEADER)); - header.setPaddings(6, 3, 6, 3); - mPopupContent.addComponent(header); - mPopupContent.addComponent(mZoomController); - - mZoomController.setZoomListener(new MyZoomListener()); - mZoomController.setZoomIndex(mZoomIndex); - } - return mPopupContent; - } - - @Override - public void overrideSettings(String key, String settings) { - // do nothing - } - - @Override - public void reloadPreferences() { - // do nothing - } - - public void setZoomRatios(float[] ratios) { - mZoomRatios = ratios; - mDrawIndex = -1; - invalidate(); - } - - private class MyZoomListener implements ZoomControllerListener { - public void onZoomChanged(int index, float value, boolean isMoving) { - if (mZoomListener != null) { - mZoomListener.onZoomChanged(index, value, isMoving); - } - if (mZoomIndex != index) onZoomIndexChanged(index); - } - } - - private void onZoomIndexChanged(int index) { - if (mZoomIndex == index) return; - mZoomIndex = index; - invalidate(); - } - - public void setZoomListener(ZoomControllerListener listener) { - mZoomListener = listener; - } - - public void setZoomIndex(int index) { - if (mZoomIndex == index) return; - if (mZoomController != null) { - mZoomController.setZoomIndex(index); - } else { - onZoomIndexChanged(index); - } - } -} |