diff options
author | Wu-cheng Li <wuchengli@google.com> | 2010-10-04 20:35:34 +0800 |
---|---|---|
committer | Wu-cheng Li <wuchengli@google.com> | 2010-10-06 17:21:28 +0800 |
commit | c5019f4d58412da6227b3f2e6461bba5b7c671a3 (patch) | |
tree | 7dd6069c58588803fbacb41dceb4c8ec84f84191 | |
parent | e6da834b082439299bb60529e690845e14dfdbc4 (diff) | |
download | LegacyCamera-c5019f4d58412da6227b3f2e6461bba5b7c671a3.zip LegacyCamera-c5019f4d58412da6227b3f2e6461bba5b7c671a3.tar.gz LegacyCamera-c5019f4d58412da6227b3f2e6461bba5b7c671a3.tar.bz2 |
Add zoom picker for xlarge layout.
The zoom of on-screen controls is not created if zoom picker
exists.
Change-Id: I229108aa8bc3eac7175acec46e14240627c7da7c
-rwxr-xr-x | res/drawable-mdpi/zoompicker_down_normal.9.png | bin | 0 -> 795 bytes | |||
-rwxr-xr-x | res/drawable-mdpi/zoompicker_down_pressed.9.png | bin | 0 -> 1161 bytes | |||
-rwxr-xr-x | res/drawable-mdpi/zoompicker_up_normal.9.png | bin | 0 -> 989 bytes | |||
-rwxr-xr-x | res/drawable-mdpi/zoompicker_up_pressed.9.png | bin | 0 -> 1433 bytes | |||
-rw-r--r-- | res/drawable/btn_zoom_picker_down.xml | 20 | ||||
-rw-r--r-- | res/drawable/btn_zoom_picker_up.xml | 20 | ||||
-rw-r--r-- | res/layout-xlarge/camera_control.xml | 11 | ||||
-rw-r--r-- | res/layout-xlarge/zoom_picker.xml | 43 | ||||
-rw-r--r-- | res/values/colors.xml | 1 | ||||
-rw-r--r-- | res/values/strings.xml | 2 | ||||
-rw-r--r-- | src/com/android/camera/Camera.java | 28 | ||||
-rw-r--r-- | src/com/android/camera/ZoomPicker.java | 156 |
12 files changed, 277 insertions, 4 deletions
diff --git a/res/drawable-mdpi/zoompicker_down_normal.9.png b/res/drawable-mdpi/zoompicker_down_normal.9.png Binary files differnew file mode 100755 index 0000000..f17e8f9 --- /dev/null +++ b/res/drawable-mdpi/zoompicker_down_normal.9.png diff --git a/res/drawable-mdpi/zoompicker_down_pressed.9.png b/res/drawable-mdpi/zoompicker_down_pressed.9.png Binary files differnew file mode 100755 index 0000000..777bcf5 --- /dev/null +++ b/res/drawable-mdpi/zoompicker_down_pressed.9.png diff --git a/res/drawable-mdpi/zoompicker_up_normal.9.png b/res/drawable-mdpi/zoompicker_up_normal.9.png Binary files differnew file mode 100755 index 0000000..dcd26e0 --- /dev/null +++ b/res/drawable-mdpi/zoompicker_up_normal.9.png diff --git a/res/drawable-mdpi/zoompicker_up_pressed.9.png b/res/drawable-mdpi/zoompicker_up_pressed.9.png Binary files differnew file mode 100755 index 0000000..7dac778 --- /dev/null +++ b/res/drawable-mdpi/zoompicker_up_pressed.9.png diff --git a/res/drawable/btn_zoom_picker_down.xml b/res/drawable/btn_zoom_picker_down.xml new file mode 100644 index 0000000..38f1270 --- /dev/null +++ b/res/drawable/btn_zoom_picker_down.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2008 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<selector xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:state_pressed="true" android:drawable="@drawable/zoompicker_down_pressed" /> + <item android:drawable="@drawable/zoompicker_down_normal" /> +</selector> diff --git a/res/drawable/btn_zoom_picker_up.xml b/res/drawable/btn_zoom_picker_up.xml new file mode 100644 index 0000000..0a2249b --- /dev/null +++ b/res/drawable/btn_zoom_picker_up.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2008 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<selector xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:state_pressed="true" android:drawable="@drawable/zoompicker_up_pressed" /> + <item android:drawable="@drawable/zoompicker_up_normal" /> +</selector> diff --git a/res/layout-xlarge/camera_control.xml b/res/layout-xlarge/camera_control.xml index b30ac3c..91e11ce 100644 --- a/res/layout-xlarge/camera_control.xml +++ b/res/layout-xlarge/camera_control.xml @@ -36,6 +36,17 @@ android:gravity="center"> </ListView> + <ViewStub android:id="@+id/zoom_stub" + android:inflatedId="@+id/zoom_picker" + android:layout="@layout/zoom_picker" + android:layout_alignParentTop="true" + android:layout_alignParentRight="true" + android:layout_toRightOf="@id/image_list" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="10dp" + android:layout_centerInParent="true"/> + <com.android.camera.ShutterButton android:id="@+id/shutter_button" android:layout_centerInParent="true" android:layout_alignParentRight="true" diff --git a/res/layout-xlarge/zoom_picker.xml b/res/layout-xlarge/zoom_picker.xml new file mode 100644 index 0000000..50766d4 --- /dev/null +++ b/res/layout-xlarge/zoom_picker.xml @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +** +** Copyright 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. +*/ +--> + +<com.android.camera.ZoomPicker xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:orientation="vertical"> + + <TextView android:id="@+id/zoom_ratio" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:gravity="center" + android:singleLine="true" + android:textColor="@android:color/white" + android:textSize="24dp" /> + + <Button android:id="@+id/increment" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginTop="10dp" + android:background="@drawable/btn_zoom_picker_up" /> + + <Button android:id="@+id/decrement" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:background="@drawable/btn_zoom_picker_down" /> +</com.android.camera.ZoomPicker> diff --git a/res/values/colors.xml b/res/values/colors.xml index 7193b7c..c5572ca 100644 --- a/res/values/colors.xml +++ b/res/values/colors.xml @@ -20,4 +20,5 @@ <resources> <color name="recording_time_elapsed_text">#FFFFFFFF</color> <color name="recording_time_remaining_text">#FFFF0033</color> + <color name="zoom_picker_btn_pressed">#FFFFAD00</color> </resources> diff --git a/res/values/strings.xml b/res/values/strings.xml index 0d8d19a..a39461a 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -361,6 +361,8 @@ <!-- The title show on the zoom controller --> <string name="zoom_control_title">Zoom</string> + <string name="zoom_increment" translable="false">+</string> + <string name="zoom_decrement" translable="false">-</string> <string name="switch_to_camera_lable">Switch to camera</string> <string name="switch_to_video_lable">Switch to video</string> diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java index 2aa2e8e..aecb386 100644 --- a/src/com/android/camera/Camera.java +++ b/src/com/android/camera/Camera.java @@ -71,6 +71,7 @@ import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.View; import android.view.ViewGroup; +import android.view.ViewStub; import android.view.Window; import android.view.WindowManager; import android.view.MenuItem.OnMenuItemClickListener; @@ -131,6 +132,7 @@ public class Camera extends NoSearchActivity implements View.OnClickListener, private int mZoomValue; // The current zoom value. private int mZoomMax; private int mTargetZoomValue; + private ZoomPicker mZoomPicker; private Parameters mParameters; private Parameters mInitialParams; @@ -471,6 +473,17 @@ public class Camera extends NoSearchActivity implements View.OnClickListener, mZoomMax = mParameters.getMaxZoom(); mSmoothZoomSupported = mParameters.isSmoothZoomSupported(); mGestureDetector = new GestureDetector(this, new ZoomGestureListener()); + ViewStub zoomStub = (ViewStub) findViewById(R.id.zoom_stub); + if (zoomStub != null) { + mZoomPicker = (ZoomPicker) zoomStub.inflate(); + mZoomPicker.setZoomRatios(getZoomRatios()); + mZoomPicker.setOnZoomChangeListener( + new ZoomPicker.OnZoomChangedListener() { + public void onZoomChanged(int index) { + onZoomValueChanged(index); + } + }); + } mCameraDevice.setZoomChangeListener(mZoomListener); } @@ -525,7 +538,11 @@ public class Camera extends NoSearchActivity implements View.OnClickListener, setCameraParametersWhenIdle(UPDATE_PARAM_ZOOM); - mHeadUpDisplay.setZoomIndex(mZoomValue); + if (mZoomPicker != null) { + mZoomPicker.setZoomIndex(mZoomValue); + } else { + mHeadUpDisplay.setZoomIndex(mZoomValue); + } return true; } } @@ -1056,10 +1073,13 @@ public class Camera extends NoSearchActivity implements View.OnClickListener, private void initializeHeadUpDisplay() { CameraSettings settings = new CameraSettings(this, mInitialParams, mCameraId, CameraHolder.instance().getCameraInfo()); + // If we have zoom picker, do not show zoom control on head-up display. + float[] zoomRatios = null; + if (mZoomPicker == null) zoomRatios = getZoomRatios(); mHeadUpDisplay.initialize(this, settings.getPreferenceGroup(R.xml.camera_preferences), - getZoomRatios(), mOrientationCompensation); - if (mParameters.isZoomSupported()) { + zoomRatios, mOrientationCompensation); + if (mZoomPicker == null && mParameters.isZoomSupported()) { mHeadUpDisplay.setZoomListener(new ZoomControllerListener() { public void onZoomChanged( int index, float ratio, boolean isMoving) { @@ -1072,7 +1092,7 @@ public class Camera extends NoSearchActivity implements View.OnClickListener, private void attachHeadUpDisplay() { mHeadUpDisplay.setOrientation(mOrientationCompensation); - if (mParameters.isZoomSupported()) { + if (mZoomPicker == null && mParameters.isZoomSupported()) { mHeadUpDisplay.setZoomIndex(mZoomValue); } FrameLayout frame = (FrameLayout) findViewById(R.id.frame); diff --git a/src/com/android/camera/ZoomPicker.java b/src/com/android/camera/ZoomPicker.java new file mode 100644 index 0000000..b0b66df --- /dev/null +++ b/src/com/android/camera/ZoomPicker.java @@ -0,0 +1,156 @@ +/* + * 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.os.Handler; +import android.util.AttributeSet; +import android.util.Log; +import android.view.View; +import android.view.MotionEvent; +import android.view.ViewConfiguration; +import android.view.View.OnTouchListener; +import android.widget.Button; +import android.widget.LinearLayout; +import android.widget.TextView; + +import java.util.Formatter; + +/** + * A view for increasing or decresing zoom + */ +public class ZoomPicker extends LinearLayout { + private final String TAG = "ZoomPicker"; + private TextView mText; + private int mZoomMax, mZoomIndex; + private float[] mZoomRatios; + private OnZoomChangedListener mListener; + private boolean mIncrement, mDecrement; + private final StringBuilder mBuilder = new StringBuilder(); + private final Formatter mFormatter = new Formatter(mBuilder); + private final Object[] mFormatterArgs = new Object[1]; + + private Handler mHandler; + private final Runnable mRunnable = new Runnable() { + public void run() { + if (mIncrement) { + if (changeZoomIndex(mZoomIndex + 1)) { + mHandler.postDelayed(this, 65); + } + } else if (mDecrement) { + if (changeZoomIndex(mZoomIndex - 1)) { + mHandler.postDelayed(this, 65); + } + } + } + }; + + public ZoomPicker(Context context) { + this(context, null); + } + + public ZoomPicker(Context context, AttributeSet attrs) { + super(context, attrs); + } + + @Override + protected void onFinishInflate() { + super.onFinishInflate(); + mHandler = new Handler(); + + OnTouchListener incrementTouchListener = new OnTouchListener() { + public boolean onTouch(View v, MotionEvent event) { + if (event.getAction() == MotionEvent.ACTION_DOWN) { + if (!mIncrement && changeZoomIndex(mZoomIndex + 1)) { + mIncrement = true; + // Give bigger delay so users can tap to change only one + // zoom step. + mHandler.postDelayed(mRunnable, 200); + } + } else if (event.getAction() == MotionEvent.ACTION_UP) { + mIncrement = false; + } + return false; + } + }; + + OnTouchListener decrementTouchListener = new OnTouchListener() { + public boolean onTouch(View v, MotionEvent event) { + if (event.getAction() == MotionEvent.ACTION_DOWN) { + if (!mDecrement && changeZoomIndex(mZoomIndex - 1)) { + mDecrement = true; + // Give bigger delay so users can tap to change only one + // zoom step. + mHandler.postDelayed(mRunnable, 200); + } + } else if (event.getAction() == MotionEvent.ACTION_UP) { + mDecrement = false; + } + return false; + } + }; + + Button incrementButton = (Button) findViewById(R.id.increment); + incrementButton.setOnTouchListener(incrementTouchListener); + Button decrementButton = (Button) findViewById(R.id.decrement); + decrementButton.setOnTouchListener(decrementTouchListener); + mText = (TextView) findViewById(R.id.zoom_ratio); + } + + public void setOnZoomChangeListener(OnZoomChangedListener listener) { + mListener = listener; + } + + public interface OnZoomChangedListener { + void onZoomChanged(int index); + } + + public void setZoomRatios(float[] zoomRatios) { + mZoomMax = zoomRatios.length - 1; + mZoomRatios = zoomRatios; + updateView(); + } + + public void setZoomIndex(int index) { + if (index < 0 || index > mZoomMax) { + throw new IllegalArgumentException("Invalid zoom value:" + index); + } + mZoomIndex = index; + updateView(); + } + + private boolean changeZoomIndex(int index) { + if (index > mZoomMax || index < 0) return false; + mZoomIndex = index; + if (mListener != null) { + mListener.onZoomChanged(mZoomIndex); + } + updateView(); + return true; + } + + private void updateView() { + mText.setText(formatZoomRatio(mZoomRatios[mZoomIndex])); + } + + private String formatZoomRatio(float value) { + mFormatterArgs[0] = value; + mBuilder.delete(0, mBuilder.length()); + mFormatter.format("%2.1fx", mFormatterArgs); + return mFormatter.toString(); + } +} |