diff options
author | Chung-yih Wang <cywang@google.com> | 2011-08-31 01:34:57 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-08-31 01:34:57 -0700 |
commit | c2f9a6866c8c0ea970f50645c33cf6296721bd91 (patch) | |
tree | 8df6a47fb116673fafc2d83b9ee31d5e8517b22d /src | |
parent | 6229b81d1fb6e8307d85ab5de35f5a6b48d27c23 (diff) | |
parent | d2202f9677fcc5f3f2b3e950c35aefe80da14a8a (diff) | |
download | packages_apps_LegacyCamera-c2f9a6866c8c0ea970f50645c33cf6296721bd91.zip packages_apps_LegacyCamera-c2f9a6866c8c0ea970f50645c33cf6296721bd91.tar.gz packages_apps_LegacyCamera-c2f9a6866c8c0ea970f50645c33cf6296721bd91.tar.bz2 |
Merge "Add ZoomIndexBar for phone UI."
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/camera/ui/IndicatorControlBar.java | 10 | ||||
-rw-r--r-- | src/com/android/camera/ui/IndicatorControlBarContainer.java | 8 | ||||
-rw-r--r-- | src/com/android/camera/ui/ZoomControl.java | 19 | ||||
-rw-r--r-- | src/com/android/camera/ui/ZoomControlBar.java | 23 | ||||
-rw-r--r-- | src/com/android/camera/ui/ZoomControlWheel.java | 3 | ||||
-rw-r--r-- | src/com/android/camera/ui/ZoomIndexBar.java | 68 |
6 files changed, 117 insertions, 14 deletions
diff --git a/src/com/android/camera/ui/IndicatorControlBar.java b/src/com/android/camera/ui/IndicatorControlBar.java index 748e23c..ed47f96 100644 --- a/src/com/android/camera/ui/IndicatorControlBar.java +++ b/src/com/android/camera/ui/IndicatorControlBar.java @@ -60,14 +60,20 @@ public class IndicatorControlBar extends IndicatorControl implements requestLayout(); } + @Override + public boolean dispatchTouchEvent(MotionEvent event) { + super.dispatchTouchEvent(event); + // We need to consume the event, or it will trigger tap-to-focus. + return true; + } + public boolean onTouch(View v, MotionEvent event) { dismissSettingPopup(); if (event.getAction() == MotionEvent.ACTION_DOWN) { mOnIndicatorEventListener.onIndicatorEvent( OnIndicatorEventListener.EVENT_ENTER_ZOOM_CONTROL); - return true; } - return false; + return true; } public void onClick(View view) { diff --git a/src/com/android/camera/ui/IndicatorControlBarContainer.java b/src/com/android/camera/ui/IndicatorControlBarContainer.java index 0ca378d..56e887d 100644 --- a/src/com/android/camera/ui/IndicatorControlBarContainer.java +++ b/src/com/android/camera/ui/IndicatorControlBarContainer.java @@ -38,6 +38,7 @@ public class IndicatorControlBarContainer extends IndicatorControlContainer private Animation mFadeIn, mFadeOut; private IndicatorControlBar mIndicatorControlBar; private ZoomControlBar mZoomControlBar; + private ZoomIndexBar mZoomIndexBar; private SecondLevelIndicatorControlBar mSecondLevelIndicatorControlBar; public IndicatorControlBarContainer(Context context, AttributeSet attrs) { @@ -51,6 +52,8 @@ public class IndicatorControlBarContainer extends IndicatorControlContainer mZoomControlBar = (ZoomControlBar) findViewById(R.id.zoom_control); mZoomControlBar.setOnIndicatorEventListener(this); + mZoomIndexBar = (ZoomIndexBar) findViewById(R.id.zoom_index_bar); + mZoomControlBar.setOnZoomIndexChangeListener(mZoomIndexBar); // We need to show/hide the zoom slider icon accordingly. // From UI spec, we have camera_flash setting on the first level. @@ -76,6 +79,7 @@ public class IndicatorControlBarContainer extends IndicatorControlContainer mIndicatorControlBar.setDegree(degree); mSecondLevelIndicatorControlBar.setDegree(degree); mZoomControlBar.setDegree(degree); + mZoomIndexBar.setDegree(degree); } @Override @@ -87,7 +91,7 @@ public class IndicatorControlBarContainer extends IndicatorControlContainer } else if (mZoomControlBar.getVisibility() == View.VISIBLE) { return mZoomControlBar.dispatchTouchEvent(event); } - return false; + return true; } public void onIndicatorEvent(int event) { @@ -107,11 +111,13 @@ public class IndicatorControlBarContainer extends IndicatorControlContainer case OnIndicatorEventListener.EVENT_ENTER_ZOOM_CONTROL: mIndicatorControlBar.setVisibility(View.GONE); mZoomControlBar.setVisibility(View.VISIBLE); + mZoomIndexBar.setVisibility(View.VISIBLE); mZoomControlBar.startZoomControl(); break; case OnIndicatorEventListener.EVENT_LEAVE_ZOOM_CONTROL: mZoomControlBar.setVisibility(View.GONE); + mZoomIndexBar.setVisibility(View.GONE); mIndicatorControlBar.setVisibility(View.VISIBLE); break; } diff --git a/src/com/android/camera/ui/ZoomControl.java b/src/com/android/camera/ui/ZoomControl.java index 6bb22a9..0c8a765 100644 --- a/src/com/android/camera/ui/ZoomControl.java +++ b/src/com/android/camera/ui/ZoomControl.java @@ -46,9 +46,17 @@ public abstract class ZoomControl extends RelativeLayout { void onZoomStateChanged(int state); // only for smooth zoom } + // The interface OnZoomIndexChangedListener is used to inform the + // ZoomIndexBar about the zoom index change. The index position is between + // 0 (the index is zero) and 1.0 (the index is mZoomMax). + public interface OnZoomIndexChangedListener { + void onZoomIndexChanged(double indexPosition); + } + protected int mZoomMax, mZoomIndex; private boolean mSmoothZoomSupported; private OnZoomChangedListener mListener; + private OnZoomIndexChangedListener mIndexListener; // The state of zoom button. public static final int ZOOM_IN = 0; @@ -84,6 +92,7 @@ public abstract class ZoomControl extends RelativeLayout { public void startZoomControl() { mZoomSlider.setPressed(true); mHandler.postDelayed(mRunnable, ZOOMING_INTERVAL); + setZoomIndex(mZoomIndex); // Update the zoom index bar. } protected ImageView addImageView(Context context, int iconResourceId) { @@ -110,6 +119,10 @@ public abstract class ZoomControl extends RelativeLayout { mListener = listener; } + public void setOnZoomIndexChangeListener(OnZoomIndexChangedListener listener) { + mIndexListener = listener; + } + public void setOnIndicatorEventListener(OnIndicatorEventListener listener) { mOnIndicatorEventListener = listener; } @@ -119,6 +132,9 @@ public abstract class ZoomControl extends RelativeLayout { throw new IllegalArgumentException("Invalid zoom value:" + index); } mZoomIndex = index; + if (mIndexListener != null) { + mIndexListener.onZoomIndexChanged(1.0d * mZoomIndex / mZoomMax); + } invalidate(); } @@ -150,8 +166,7 @@ public abstract class ZoomControl extends RelativeLayout { } } else { mListener.onZoomStateChanged(index); - mZoomIndex = index; - invalidate(); + setZoomIndex(index); } } return true; diff --git a/src/com/android/camera/ui/ZoomControlBar.java b/src/com/android/camera/ui/ZoomControlBar.java index fdfeb50..7046985 100644 --- a/src/com/android/camera/ui/ZoomControlBar.java +++ b/src/com/android/camera/ui/ZoomControlBar.java @@ -17,6 +17,7 @@ package com.android.camera.ui; import com.android.camera.R; +import com.android.camera.Util; import android.content.Context; import android.util.AttributeSet; @@ -28,6 +29,8 @@ import android.view.View; */ public class ZoomControlBar extends ZoomControl { private static final String TAG = "ZoomControlBar"; + private static final int STOP_ZOOM_BUFFER = Util.dpToPixel(30); + private View mBar; public ZoomControlBar(Context context, AttributeSet attrs) { @@ -56,11 +59,15 @@ public class ZoomControlBar extends ZoomControl { // For left-hand users, as the device is rotated for 180 degree for // landscape mode, the zoom-in bottom should be on the top, so the // position should be reversed. + int delta; if (mDegree == 180) { - mSliderPosition = offset - (int) y; + delta = offset - (int) y; } else { - mSliderPosition = (int) y - offset; + delta = (int) y - offset; } + // We need some space to stop zooming. + mSliderPosition = (Math.abs(delta) < STOP_ZOOM_BUFFER) ? 0 : delta; + // TODO: add fast zoom change here switch (action) { @@ -102,11 +109,13 @@ public class ZoomControlBar extends ZoomControl { mZoomOut.layout(0, bottom - width, width, bottom); } mBar.layout(0, top + width, width, bottom - width); - if (pos < width) { - pos = width; - } else if (pos > (height - 2 * width)) { - pos = height - 2 * width; + + // TODO: fix the pos once we have correct zoom_big asset. + if (pos < 3 * width / 4) { + pos = 3 * width / 4; + } else if (pos > (height - (7 * width / 4))) { + pos = height - (7 * width / 4); } mZoomSlider.layout(0, pos, width, pos + width); - } + } } diff --git a/src/com/android/camera/ui/ZoomControlWheel.java b/src/com/android/camera/ui/ZoomControlWheel.java index 40c1124..621ab3a 100644 --- a/src/com/android/camera/ui/ZoomControlWheel.java +++ b/src/com/android/camera/ui/ZoomControlWheel.java @@ -166,8 +166,7 @@ public class ZoomControlWheel extends ZoomControl { @Override protected void onDraw(Canvas canvas) { - // Draw slider highlight. - float delta = mStrokeWidth * 0.5f; + // Draw zoom index highlight. float radius = (float) (mWheelRadius + mStrokeWidth * 0.5 + EDGE_STROKE_WIDTH); int degree = (int) Math.toDegrees(getZoomIndexAngle()); drawArc(canvas, (-degree - HIGHLIGHT_DEGREES / 2), HIGHLIGHT_DEGREES, diff --git a/src/com/android/camera/ui/ZoomIndexBar.java b/src/com/android/camera/ui/ZoomIndexBar.java new file mode 100644 index 0000000..8a81c50 --- /dev/null +++ b/src/com/android/camera/ui/ZoomIndexBar.java @@ -0,0 +1,68 @@ +/* + * 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.R; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.View; +import android.widget.FrameLayout; + +/** + * An indicator bar that indicates the current zoom index. + */ +public class ZoomIndexBar extends FrameLayout implements + ZoomControl.OnZoomIndexChangedListener { + private static final int BAR_HEIGHT_FACTOR = 7; + private View mIndexBar; + private double mIndexPosition; // The index position is between 0 and 1.0. + private int mDegree; + + public ZoomIndexBar(Context context, AttributeSet attrs) { + super(context, attrs); + } + + @Override + protected void onFinishInflate() { + mIndexBar = findViewById(R.id.zoom_index); + } + + public void onZoomIndexChanged(double indexPosition) { + mIndexPosition = indexPosition; + requestLayout(); + } + + @Override + protected void onLayout( + boolean changed, int left, int top, int right, int bottom) { + int height = bottom - top; + int barHeight = height / BAR_HEIGHT_FACTOR; + int barTop = (int) ((height - barHeight) * (1 - mIndexPosition)); + if (mDegree == 180) { + mIndexBar.layout(left, bottom - barTop - barHeight, right, + bottom - barTop); + } else { + mIndexBar.layout(left, barTop, right, barTop + barHeight); + } + } + + public void setDegree(int degree) { + if ((degree != mDegree) && ((degree == 180) || (mDegree == 180))) requestLayout(); + mDegree = degree; + } +} |