summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChung-yih Wang <cywang@google.com>2011-09-21 11:56:31 +0800
committerChung-yih Wang <cywang@google.com>2011-09-22 02:10:08 +0800
commit606093cd434a89f5ca941d3a6d6e8470eb768c67 (patch)
tree0fee2c946b1693aff799d950c7d81f0e26e3c056 /src
parent9e9aff5145a9c3e1e4e99fbd779cd3b9b3c20848 (diff)
downloadLegacyCamera-606093cd434a89f5ca941d3a6d6e8470eb768c67.zip
LegacyCamera-606093cd434a89f5ca941d3a6d6e8470eb768c67.tar.gz
LegacyCamera-606093cd434a89f5ca941d3a6d6e8470eb768c67.tar.bz2
Fix the zoom control bar UI on phone.
+use drawable selector to activate/deactivate the zoom control bar +update/add zoom assets Change-Id: Ie429dd0d78c562c8d1045280f336ae74ea6ce898
Diffstat (limited to 'src')
-rw-r--r--src/com/android/camera/ui/ZoomControl.java18
-rw-r--r--src/com/android/camera/ui/ZoomControlBar.java78
2 files changed, 59 insertions, 37 deletions
diff --git a/src/com/android/camera/ui/ZoomControl.java b/src/com/android/camera/ui/ZoomControl.java
index 662ee92..4258fd9 100644
--- a/src/com/android/camera/ui/ZoomControl.java
+++ b/src/com/android/camera/ui/ZoomControl.java
@@ -20,7 +20,6 @@ import com.android.camera.R;
import android.content.Context;
import android.os.Handler;
-import android.os.SystemClock;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
@@ -75,9 +74,9 @@ public abstract class ZoomControl extends RelativeLayout {
public ZoomControl(Context context, AttributeSet attrs) {
super(context, attrs);
- mZoomIn = addImageView(context, R.drawable.ic_zoom_in_holo_light);
- mZoomSlider = addImageView(context, R.drawable.btn_zoom_slider);
- mZoomOut = addImageView(context, R.drawable.ic_zoom_out_holo_light);
+ mZoomIn = addImageView(context, R.drawable.ic_zoom_in);
+ mZoomSlider = addImageView(context, R.drawable.ic_zoom_slider);
+ mZoomOut = addImageView(context, R.drawable.ic_zoom_out);
mHandler = new Handler();
}
@@ -105,6 +104,10 @@ public abstract class ZoomControl extends RelativeLayout {
public void setZoomMax(int zoomMax) {
mZoomMax = zoomMax;
+
+ // Layout should be requested as the maximum zoom level is the key to
+ // show the correct zoom slider position.
+ requestLayout();
}
public void setOnZoomChangeListener(OnZoomChangedListener listener) {
@@ -219,4 +222,11 @@ public abstract class ZoomControl extends RelativeLayout {
}
}
}
+
+ @Override
+ public void setActivated(boolean activated) {
+ super.setActivated(activated);
+ mZoomIn.setActivated(activated);
+ mZoomOut.setActivated(activated);
+ }
}
diff --git a/src/com/android/camera/ui/ZoomControlBar.java b/src/com/android/camera/ui/ZoomControlBar.java
index 6bbb8f1..06cff0d 100644
--- a/src/com/android/camera/ui/ZoomControlBar.java
+++ b/src/com/android/camera/ui/ZoomControlBar.java
@@ -20,7 +20,6 @@ import com.android.camera.R;
import com.android.camera.Util;
import android.content.Context;
-import android.os.Handler;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
@@ -30,60 +29,76 @@ import android.view.View;
*/
public class ZoomControlBar extends ZoomControl {
private static final String TAG = "ZoomControlBar";
- private static int THRESHOLD_FIRST_MOVE = Util.dpToPixel(10); // pixels
+ private static final int THRESHOLD_FIRST_MOVE = Util.dpToPixel(10); // pixels
+ // Space between indicator icon and the zoom-in/out icon.
+ private static final int ICON_SPACING = Util.dpToPixel(12);
+
private View mBar;
private boolean mStartChanging;
+ private int mSliderLength;
public ZoomControlBar(Context context, AttributeSet attrs) {
super(context, attrs);
mBar = new View(context);
- mBar.setBackgroundResource(R.drawable.ic_zoom_big);
+ mBar.setBackgroundResource(R.drawable.zoom_slider_bar);
addView(mBar);
}
@Override
- public boolean dispatchTouchEvent(MotionEvent event) {
- if (!onFilterTouchEventForSecurity(event)) return false;
-
- int action = event.getAction();
-
- if (!isEnabled()) return false;
-
- double y = (double) event.getY();
+ public void setActivated(boolean activated) {
+ super.setActivated(activated);
+ mBar.setActivated(activated);
+ }
+ private int getSliderPosition(int y) {
// Calculate the absolute offset of the slider in the zoom control bar.
// 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 offset = 5 * getWidth() / 4; // the padding and the icon height
+ int totalIconHeight = mZoomIn.getHeight() + ICON_SPACING;
int height = getHeight();
- int range = height - 2 * offset; // the range of the zoom slider
int pos; // the relative position in the zoom slider bar
if (mDegree == 180) {
- pos = (int) y - offset;
+ pos = y - totalIconHeight;
} else {
- pos = height - (int) y - offset;
+ pos = height - totalIconHeight - y;
+ }
+ if (mSliderLength == 0) {
+ mSliderLength = height - (2 * totalIconHeight);
}
if (pos < 0) pos = 0;
- if (pos > range) pos = range;
+ if (pos > mSliderLength) pos = mSliderLength;
+ return pos;
+ }
+
+ @Override
+ public boolean dispatchTouchEvent(MotionEvent event) {
+ if (!onFilterTouchEventForSecurity(event)) return false;
+
+ int action = event.getAction();
+ if (!isEnabled() || (getHeight() == 0)) return false;
switch (action) {
case MotionEvent.ACTION_OUTSIDE:
case MotionEvent.ACTION_CANCEL:
+ case MotionEvent.ACTION_UP:
+ setActivated(false);
closeZoomControl();
break;
case MotionEvent.ACTION_DOWN:
+ setActivated(true);
mStartChanging = false;
case MotionEvent.ACTION_MOVE:
// Make sure the movement is large enough before we start
// changing the zoom.
+ int pos = getSliderPosition((int) event.getY());
if (!mStartChanging && (Math.abs(mSliderPosition - pos)
> THRESHOLD_FIRST_MOVE)) {
mStartChanging = true;
}
if (mStartChanging) {
- performZoom(1.0d * pos / range);
+ performZoom(1.0d * pos / mSliderLength);
mSliderPosition = pos;
}
requestLayout();
@@ -102,28 +117,25 @@ public class ZoomControlBar extends ZoomControl {
protected void onLayout(
boolean changed, int left, int top, int right, int bottom) {
if (mZoomMax == 0) return;
-
int width = right - left;
int height = bottom - top;
- int range = height - 10 * width / 4;
- int pos;
-
- // TODO: remove offset once we have correct ic_zoom_big.9.png.
- int offset = 3 * width / 4;
-
+ int iconHeight = mZoomIn.getMeasuredHeight();
+ mBar.layout(0, iconHeight + ICON_SPACING,
+ width, height - iconHeight - ICON_SPACING);
// For left-hand users, as the device is rotated for 180 degree,
// the zoom-in button should be on the top.
+ int pos; // slider position
if (mDegree == 180) {
- mZoomOut.layout(0, 0, width, width);
- mZoomIn.layout(0, height - width, width, height);
- pos = offset + mZoomIndex * range / mZoomMax;
- mZoomSlider.layout(0, pos, width, pos + width);
+ mZoomOut.layout(0, 0, width, iconHeight);
+ mZoomIn.layout(0, height - iconHeight, width, height);
+ pos = mBar.getTop() + mSliderPosition;
} else {
- mZoomIn.layout(0, 0, width, width);
- mZoomOut.layout(0, height - width, width, height);
- pos = offset + (mZoomMax - mZoomIndex) * range / mZoomMax;
- mZoomSlider.layout(0, pos, width, pos + width);
+ mZoomIn.layout(0, 0, width, iconHeight);
+ mZoomOut.layout(0, height - iconHeight, width, height);
+ pos = mBar.getBottom() - mSliderPosition;
}
- mBar.layout(0, width, width, bottom - top - width);
+ int sliderHeight = mZoomSlider.getMeasuredHeight();
+ mZoomSlider.layout(0, (pos - sliderHeight / 2),
+ width, (pos + sliderHeight / 2));
}
}