diff options
author | Chung-yih Wang <cywang@google.com> | 2011-09-21 11:56:31 +0800 |
---|---|---|
committer | Chung-yih Wang <cywang@google.com> | 2011-09-22 02:10:08 +0800 |
commit | 606093cd434a89f5ca941d3a6d6e8470eb768c67 (patch) | |
tree | 0fee2c946b1693aff799d950c7d81f0e26e3c056 | |
parent | 9e9aff5145a9c3e1e4e99fbd779cd3b9b3c20848 (diff) | |
download | LegacyCamera-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
34 files changed, 122 insertions, 38 deletions
diff --git a/res/drawable-hdpi/ic_zoom_big.9.png b/res/drawable-hdpi/ic_zoom_big.9.png Binary files differindex cc40dec..8e6380e 100644 --- a/res/drawable-hdpi/ic_zoom_big.9.png +++ b/res/drawable-hdpi/ic_zoom_big.9.png diff --git a/res/drawable-hdpi/ic_zoom_big_dark.9.png b/res/drawable-hdpi/ic_zoom_big_dark.9.png Binary files differnew file mode 100644 index 0000000..340254b --- /dev/null +++ b/res/drawable-hdpi/ic_zoom_big_dark.9.png diff --git a/res/drawable-hdpi/ic_zoom_in_holo_dark.png b/res/drawable-hdpi/ic_zoom_in_holo_dark.png Binary files differnew file mode 100644 index 0000000..89b5f15 --- /dev/null +++ b/res/drawable-hdpi/ic_zoom_in_holo_dark.png diff --git a/res/drawable-hdpi/ic_zoom_in_holo_light.png b/res/drawable-hdpi/ic_zoom_in_holo_light.png Binary files differindex 89b5f15..b96da3b 100644 --- a/res/drawable-hdpi/ic_zoom_in_holo_light.png +++ b/res/drawable-hdpi/ic_zoom_in_holo_light.png diff --git a/res/drawable-hdpi/ic_zoom_out_holo_dark.png b/res/drawable-hdpi/ic_zoom_out_holo_dark.png Binary files differnew file mode 100644 index 0000000..f4a2589 --- /dev/null +++ b/res/drawable-hdpi/ic_zoom_out_holo_dark.png diff --git a/res/drawable-hdpi/ic_zoom_out_holo_light.png b/res/drawable-hdpi/ic_zoom_out_holo_light.png Binary files differindex f4a2589..2f6a7b5 100644 --- a/res/drawable-hdpi/ic_zoom_out_holo_light.png +++ b/res/drawable-hdpi/ic_zoom_out_holo_light.png diff --git a/res/drawable-mdpi/ic_zoom_big.9.png b/res/drawable-mdpi/ic_zoom_big.9.png Binary files differindex 9c2019c..e551fd0 100644 --- a/res/drawable-mdpi/ic_zoom_big.9.png +++ b/res/drawable-mdpi/ic_zoom_big.9.png diff --git a/res/drawable-mdpi/ic_zoom_big_dark.9.png b/res/drawable-mdpi/ic_zoom_big_dark.9.png Binary files differnew file mode 100644 index 0000000..4c12ae5 --- /dev/null +++ b/res/drawable-mdpi/ic_zoom_big_dark.9.png diff --git a/res/drawable-mdpi/ic_zoom_in_holo_dark.png b/res/drawable-mdpi/ic_zoom_in_holo_dark.png Binary files differnew file mode 100644 index 0000000..4f33278 --- /dev/null +++ b/res/drawable-mdpi/ic_zoom_in_holo_dark.png diff --git a/res/drawable-mdpi/ic_zoom_in_holo_light.png b/res/drawable-mdpi/ic_zoom_in_holo_light.png Binary files differindex 4f33278..fb840e1 100644 --- a/res/drawable-mdpi/ic_zoom_in_holo_light.png +++ b/res/drawable-mdpi/ic_zoom_in_holo_light.png diff --git a/res/drawable-mdpi/ic_zoom_out_holo_dark.png b/res/drawable-mdpi/ic_zoom_out_holo_dark.png Binary files differnew file mode 100644 index 0000000..2631894 --- /dev/null +++ b/res/drawable-mdpi/ic_zoom_out_holo_dark.png diff --git a/res/drawable-mdpi/ic_zoom_out_holo_light.png b/res/drawable-mdpi/ic_zoom_out_holo_light.png Binary files differindex 2631894..55bc997 100644 --- a/res/drawable-mdpi/ic_zoom_out_holo_light.png +++ b/res/drawable-mdpi/ic_zoom_out_holo_light.png diff --git a/res/drawable-w1024dp-hdpi/ic_zoom_in_holo_dark.png b/res/drawable-w1024dp-hdpi/ic_zoom_in_holo_dark.png Binary files differnew file mode 100644 index 0000000..99d5ef4 --- /dev/null +++ b/res/drawable-w1024dp-hdpi/ic_zoom_in_holo_dark.png diff --git a/res/drawable-w1024dp-hdpi/ic_zoom_in_holo_light.png b/res/drawable-w1024dp-hdpi/ic_zoom_in_holo_light.png Binary files differindex 99d5ef4..42c0a75 100644 --- a/res/drawable-w1024dp-hdpi/ic_zoom_in_holo_light.png +++ b/res/drawable-w1024dp-hdpi/ic_zoom_in_holo_light.png diff --git a/res/drawable-w1024dp-hdpi/ic_zoom_out_holo_dark.png b/res/drawable-w1024dp-hdpi/ic_zoom_out_holo_dark.png Binary files differnew file mode 100644 index 0000000..5fa4c95 --- /dev/null +++ b/res/drawable-w1024dp-hdpi/ic_zoom_out_holo_dark.png diff --git a/res/drawable-w1024dp-hdpi/ic_zoom_out_holo_light.png b/res/drawable-w1024dp-hdpi/ic_zoom_out_holo_light.png Binary files differindex 5fa4c95..5a8eac8 100644 --- a/res/drawable-w1024dp-hdpi/ic_zoom_out_holo_light.png +++ b/res/drawable-w1024dp-hdpi/ic_zoom_out_holo_light.png diff --git a/res/drawable-w1024dp-mdpi/ic_zoom_in_holo_dark.png b/res/drawable-w1024dp-mdpi/ic_zoom_in_holo_dark.png Binary files differnew file mode 100644 index 0000000..fd35207 --- /dev/null +++ b/res/drawable-w1024dp-mdpi/ic_zoom_in_holo_dark.png diff --git a/res/drawable-w1024dp-mdpi/ic_zoom_in_holo_light.png b/res/drawable-w1024dp-mdpi/ic_zoom_in_holo_light.png Binary files differindex fd35207..3d55439 100644 --- a/res/drawable-w1024dp-mdpi/ic_zoom_in_holo_light.png +++ b/res/drawable-w1024dp-mdpi/ic_zoom_in_holo_light.png diff --git a/res/drawable-w1024dp-mdpi/ic_zoom_out_holo_dark.png b/res/drawable-w1024dp-mdpi/ic_zoom_out_holo_dark.png Binary files differnew file mode 100644 index 0000000..e282872 --- /dev/null +++ b/res/drawable-w1024dp-mdpi/ic_zoom_out_holo_dark.png diff --git a/res/drawable-w1024dp-mdpi/ic_zoom_out_holo_light.png b/res/drawable-w1024dp-mdpi/ic_zoom_out_holo_light.png Binary files differindex e282872..1a5475b 100644 --- a/res/drawable-w1024dp-mdpi/ic_zoom_out_holo_light.png +++ b/res/drawable-w1024dp-mdpi/ic_zoom_out_holo_light.png diff --git a/res/drawable-w1024dp-xhdpi/ic_zoom_out_holo_dark.png b/res/drawable-w1024dp-xhdpi/ic_zoom_out_holo_dark.png Binary files differnew file mode 100644 index 0000000..34064d7 --- /dev/null +++ b/res/drawable-w1024dp-xhdpi/ic_zoom_out_holo_dark.png diff --git a/res/drawable-w1024dp-xhdpi/ic_zoom_out_holo_light.png b/res/drawable-w1024dp-xhdpi/ic_zoom_out_holo_light.png Binary files differindex 34064d7..6297de4 100644 --- a/res/drawable-w1024dp-xhdpi/ic_zoom_out_holo_light.png +++ b/res/drawable-w1024dp-xhdpi/ic_zoom_out_holo_light.png diff --git a/res/drawable-xhdpi/ic_zoom_big.9.png b/res/drawable-xhdpi/ic_zoom_big.9.png Binary files differindex 1e27378..48b9e24 100644 --- a/res/drawable-xhdpi/ic_zoom_big.9.png +++ b/res/drawable-xhdpi/ic_zoom_big.9.png diff --git a/res/drawable-xhdpi/ic_zoom_big_dark.9.png b/res/drawable-xhdpi/ic_zoom_big_dark.9.png Binary files differnew file mode 100644 index 0000000..b33b546 --- /dev/null +++ b/res/drawable-xhdpi/ic_zoom_big_dark.9.png diff --git a/res/drawable-xhdpi/ic_zoom_in_holo_dark.png b/res/drawable-xhdpi/ic_zoom_in_holo_dark.png Binary files differnew file mode 100644 index 0000000..78178cd --- /dev/null +++ b/res/drawable-xhdpi/ic_zoom_in_holo_dark.png diff --git a/res/drawable-xhdpi/ic_zoom_in_holo_light.png b/res/drawable-xhdpi/ic_zoom_in_holo_light.png Binary files differindex 78178cd..e950b13 100644 --- a/res/drawable-xhdpi/ic_zoom_in_holo_light.png +++ b/res/drawable-xhdpi/ic_zoom_in_holo_light.png diff --git a/res/drawable-xhdpi/ic_zoom_out_holo_dark.png b/res/drawable-xhdpi/ic_zoom_out_holo_dark.png Binary files differnew file mode 100644 index 0000000..426aac8 --- /dev/null +++ b/res/drawable-xhdpi/ic_zoom_out_holo_dark.png diff --git a/res/drawable-xhdpi/ic_zoom_out_holo_light.png b/res/drawable-xhdpi/ic_zoom_out_holo_light.png Binary files differindex 426aac8..c06ca66 100644 --- a/res/drawable-xhdpi/ic_zoom_out_holo_light.png +++ b/res/drawable-xhdpi/ic_zoom_out_holo_light.png diff --git a/res/drawable/ic_zoom_in.xml b/res/drawable/ic_zoom_in.xml new file mode 100644 index 0000000..7ba87ae --- /dev/null +++ b/res/drawable/ic_zoom_in.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- 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. +--> + +<selector xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:state_activated="true" android:drawable="@drawable/ic_zoom_in_holo_light" /> + <item android:drawable="@drawable/ic_zoom_in_holo_dark" /> +</selector> + diff --git a/res/drawable/ic_zoom_out.xml b/res/drawable/ic_zoom_out.xml new file mode 100644 index 0000000..1d46cbc --- /dev/null +++ b/res/drawable/ic_zoom_out.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- 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. +--> + +<selector xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:state_activated="true" android:drawable="@drawable/ic_zoom_out_holo_light" /> + <item android:drawable="@drawable/ic_zoom_out_holo_dark" /> +</selector> + diff --git a/res/drawable/zoom_slider_bar.xml b/res/drawable/zoom_slider_bar.xml new file mode 100644 index 0000000..234fd0f --- /dev/null +++ b/res/drawable/zoom_slider_bar.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- 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. +--> + +<selector xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:state_activated="true" android:drawable="@drawable/ic_zoom_big" /> + <item android:drawable="@drawable/ic_zoom_big_dark" /> +</selector> + diff --git a/res/layout/indicator_bar.xml b/res/layout/indicator_bar.xml index c39fb93..11276e3 100644 --- a/res/layout/indicator_bar.xml +++ b/res/layout/indicator_bar.xml @@ -49,7 +49,6 @@ android:id="@+id/zoom_control" android:layout_width="match_parent" android:layout_height="match_parent" - android:layout_centerHorizontal="true" android:visibility="gone" /> <com.android.camera.ui.RotateImageView android:id="@+id/second_level_indicator_bar_icon" 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)); } } |