summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndroid (Google) Code Review <android-gerrit@google.com>2009-09-10 05:50:07 -0400
committerAndroid (Google) Code Review <android-gerrit@google.com>2009-09-10 05:50:07 -0400
commit3c4e277ddbe3145094ca37f6e4a08174dd515616 (patch)
tree9da4544752c5549935cb0977850bec548d42466f
parentbc1c71d614f9fc0f54b9e1c59721b1cc2e011fcf (diff)
parenteb9b537cf0b715354c179327020cb7cd4e0e5327 (diff)
downloadLegacyCamera-3c4e277ddbe3145094ca37f6e4a08174dd515616.zip
LegacyCamera-3c4e277ddbe3145094ca37f6e4a08174dd515616.tar.gz
LegacyCamera-3c4e277ddbe3145094ca37f6e4a08174dd515616.tar.bz2
Merge change 24507 into eclair
* changes: Add double tap to zoom.
-rw-r--r--res/layout/review_image.xml4
-rw-r--r--res/layout/viewimage.xml14
-rw-r--r--res/values/styles.xml1
-rw-r--r--src/com/android/camera/EvenlySpacedLayout.java77
-rw-r--r--src/com/android/camera/ImageViewTouchBase.java8
-rw-r--r--src/com/android/camera/ReviewImage.java87
-rw-r--r--src/com/android/camera/ViewImage.java94
7 files changed, 211 insertions, 74 deletions
diff --git a/res/layout/review_image.xml b/res/layout/review_image.xml
index 6e9926f..347c4b6 100644
--- a/res/layout/review_image.xml
+++ b/res/layout/review_image.xml
@@ -58,7 +58,7 @@
android:clickable="true"
android:focusable="true"
android:layout_width="wrap_content"
- android:layout_height="fill_parent"
+ android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:visibility="invisible"
@@ -68,7 +68,7 @@
android:clickable="true"
android:focusable="true"
android:layout_width="wrap_content"
- android:layout_height="fill_parent"
+ android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:visibility="invisible"
diff --git a/res/layout/viewimage.xml b/res/layout/viewimage.xml
index 483a3fa..d97d898 100644
--- a/res/layout/viewimage.xml
+++ b/res/layout/viewimage.xml
@@ -46,7 +46,7 @@
android:clickable="true"
android:focusable="true"
android:layout_width="wrap_content"
- android:layout_height="fill_parent"
+ android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:visibility="invisible"
@@ -57,23 +57,19 @@
android:clickable="true"
android:focusable="true"
android:layout_width="wrap_content"
- android:layout_height="fill_parent"
+ android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:visibility="invisible"
android:src="@drawable/btn_camera_arrow_right"
/>
- <LinearLayout
+ <com.android.camera.EvenlySpacedLayout
android:visibility="gone"
android:id="@+id/action_icon_panel"
- android:layout_alignParentRight="true"
android:layout_marginTop="20dp"
- android:layout_marginRight="30dp"
- android:layout_marginLeft="30dp"
android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal">
+ android:layout_height="wrap_content">
<com.android.camera.ActionMenuButton
android:id="@+id/setas"
android:visibility="gone"
@@ -116,6 +112,6 @@
android:text="@string/camera_cancel"
style="@style/OnscreenActionIcon"
/>
- </LinearLayout>
+ </com.android.camera.EvenlySpacedLayout>
</RelativeLayout>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index eaa98da..f042a33 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -48,7 +48,6 @@
<item name="android:gravity">center_horizontal</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
- <item name="android:layout_weight">1</item>
<item name="android:drawablePadding">3dip</item>
</style>
<style name="Theme.DeleteImageDialog" parent="android:style/Theme.Dialog.Alert">
diff --git a/src/com/android/camera/EvenlySpacedLayout.java b/src/com/android/camera/EvenlySpacedLayout.java
new file mode 100644
index 0000000..9a2399c
--- /dev/null
+++ b/src/com/android/camera/EvenlySpacedLayout.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2009 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.util.AttributeSet;
+import android.view.View;
+import android.view.ViewGroup;
+
+//
+// This is a layout which makes the children even spaced.
+// Currently it only supports putting children horizontally, and it does not
+// consider the padding parameters.
+//
+public class EvenlySpacedLayout extends ViewGroup {
+
+ public EvenlySpacedLayout(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ int count = getChildCount();
+ int width = 0;
+ int height = 0;
+ for (int i = 0; i < count; i++) {
+ View child = getChildAt(i);
+ if (child.getVisibility() == GONE) continue;
+ measureChild(child, widthMeasureSpec, heightMeasureSpec);
+ width += child.getMeasuredWidth();
+ height = Math.max(height, child.getMeasuredHeight());
+ }
+ setMeasuredDimension(resolveSize(width, widthMeasureSpec),
+ resolveSize(height, heightMeasureSpec));
+ }
+
+ @Override
+ protected void onLayout(boolean changed, int l, int t, int r, int b) {
+ int count = getChildCount();
+
+ int usedWidth = 0;
+ int usedChildren = 0;
+ for (int i = 0; i < count; i++) {
+ View child = getChildAt(i);
+ if (child.getVisibility() == GONE) continue;
+ usedWidth += child.getMeasuredWidth();
+ usedChildren += 1;
+ }
+
+ int spacing = (r - l - usedWidth) / (usedChildren + 1);
+ int left = spacing;
+ int top = 0;
+ for (int i = 0; i < count; i++) {
+ View child = getChildAt(i);
+ if (child.getVisibility() == GONE) continue;
+ int w = child.getMeasuredWidth();
+ int h = child.getMeasuredHeight();
+ child.layout(left, top, left + w, top + h);
+ left += w;
+ left += spacing;
+ }
+ }
+}
diff --git a/src/com/android/camera/ImageViewTouchBase.java b/src/com/android/camera/ImageViewTouchBase.java
index 1ca6843..d58d48e 100644
--- a/src/com/android/camera/ImageViewTouchBase.java
+++ b/src/com/android/camera/ImageViewTouchBase.java
@@ -334,6 +334,14 @@ abstract class ImageViewTouchBase extends ImageView {
zoomTo(scale, cx, cy);
}
+ protected void zoomToPoint(float scale, float pointX, float pointY) {
+ float cx = getWidth() / 2F;
+ float cy = getHeight() / 2F;
+
+ panBy(cx - pointX, cy - pointY);
+ zoomTo(scale, cx, cy);
+ }
+
protected void zoomIn() {
zoomIn(SCALE_RATE);
}
diff --git a/src/com/android/camera/ReviewImage.java b/src/com/android/camera/ReviewImage.java
index 9094375..711ef2c 100644
--- a/src/com/android/camera/ReviewImage.java
+++ b/src/com/android/camera/ReviewImage.java
@@ -193,11 +193,7 @@ public class ReviewImage extends Activity implements View.OnClickListener {
if (mZoomButtonsController.isVisible()) {
scheduleDismissOnScreenControls();
}
-
- if (!super.dispatchTouchEvent(m)) {
- return mGestureDetector.onTouchEvent(m);
- }
- return true;
+ return super.dispatchTouchEvent(m);
}
private void updateZoomButtonsEnabled() {
@@ -218,34 +214,19 @@ public class ReviewImage extends Activity implements View.OnClickListener {
super.onDestroy();
}
- private void setupOnScreenControls(final View rootView) {
- final OnTouchListener otListener = new OnTouchListener() {
- public boolean onTouch(View v, MotionEvent event) {
- scheduleDismissOnScreenControls();
- if (event.getAction() == MotionEvent.ACTION_DOWN) {
- showOnScreenControls();
- }
- return false;
- }
- };
- rootView.setOnTouchListener(otListener);
-
- setupZoomButtonController(rootView, otListener);
-
+ private void setupOnScreenControls(View rootView, View ownerView) {
mNextImageView = rootView.findViewById(R.id.next_image);
mPrevImageView = rootView.findViewById(R.id.prev_image);
mNextImageView.setOnClickListener(this);
mPrevImageView.setOnClickListener(this);
- mNextImageView.setOnTouchListener(otListener);
- mPrevImageView.setOnTouchListener(otListener);
- }
- private void setupZoomButtonController(
- final View rootView, final OnTouchListener otListener) {
+ setupZoomButtonController(ownerView);
+ setupOnTouchListeners(rootView);
+ }
- mGestureDetector = new GestureDetector(this, new MyGestureListener());
- mZoomButtonsController = new ZoomButtonsController(rootView);
+ private void setupZoomButtonController(final View ownerView) {
+ mZoomButtonsController = new ZoomButtonsController(ownerView);
mZoomButtonsController.setAutoDismissed(false);
mZoomButtonsController.setZoomSpeed(100);
mZoomButtonsController.setOnZoomListener(
@@ -253,8 +234,6 @@ public class ReviewImage extends Activity implements View.OnClickListener {
public void onVisibilityChanged(boolean visible) {
if (visible) {
updateZoomButtonsEnabled();
- } else {
- rootView.setOnTouchListener(otListener);
}
}
@@ -270,6 +249,37 @@ public class ReviewImage extends Activity implements View.OnClickListener {
});
}
+ private void setupOnTouchListeners(View rootView) {
+ mGestureDetector = new GestureDetector(this, new MyGestureListener());
+
+ // If the user touches anywhere on the panel (including the
+ // next/prev button). We show the on-screen controls. In addition
+ // to that, if the touch is not on the prev/next button, we
+ // pass the event to the gesture detector to detect double tap.
+ final OnTouchListener buttonListener = new OnTouchListener() {
+ public boolean onTouch(View v, MotionEvent event) {
+ scheduleDismissOnScreenControls();
+ return false;
+ }
+ };
+
+ OnTouchListener rootListener = new OnTouchListener() {
+ public boolean onTouch(View v, MotionEvent event) {
+ buttonListener.onTouch(v, event);
+ mGestureDetector.onTouchEvent(event);
+
+ // We do not use the return value of
+ // mGestureDetector.onTouchEvent because we will not receive
+ // the "up" event if we return false for the "down" event.
+ return true;
+ }
+ };
+
+ mNextImageView.setOnTouchListener(buttonListener);
+ mPrevImageView.setOnTouchListener(buttonListener);
+ rootView.setOnTouchListener(rootListener);
+ }
+
private class MyGestureListener extends
GestureDetector.SimpleOnGestureListener {
@@ -284,7 +294,22 @@ public class ReviewImage extends Activity implements View.OnClickListener {
}
@Override
- public boolean onSingleTapUp(MotionEvent e) {
+ public boolean onSingleTapConfirmed(MotionEvent e) {
+ showOnScreenControls();
+ scheduleDismissOnScreenControls();
+ return true;
+ }
+
+ @Override
+ public boolean onDoubleTap(MotionEvent e) {
+ ImageViewTouch2 imageView = mImageView;
+
+ // Switch between the original scale and 3x scale.
+ if (imageView.getScale() > 2F) {
+ mImageView.zoomTo(1f);
+ } else {
+ mImageView.zoomToPoint(3f, e.getX(), e.getY());
+ }
return true;
}
}
@@ -356,7 +381,7 @@ public class ReviewImage extends Activity implements View.OnClickListener {
MenuHelper.enableShareMenuItem(menu, MenuHelper.isWhiteListUri(uri));
MenuHelper.enableShowOnMapMenuItem(menu, MenuHelper.hasLatLngData(image));
-
+
return true;
}
@@ -498,7 +523,7 @@ public class ReviewImage extends Activity implements View.OnClickListener {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
- setupOnScreenControls(findViewById(R.id.mainPanel));
+ setupOnScreenControls(findViewById(R.id.mainPanel), mImageView);
}
private void setButtonPanelVisibility(int id, int visibility) {
diff --git a/src/com/android/camera/ViewImage.java b/src/com/android/camera/ViewImage.java
index fe5bf05..d2ac7e3 100644
--- a/src/com/android/camera/ViewImage.java
+++ b/src/com/android/camera/ViewImage.java
@@ -230,10 +230,7 @@ public class ViewImage extends Activity implements View.OnClickListener {
if (mZoomButtonsController.isVisible()) {
scheduleDismissOnScreenControls();
}
- if (!super.dispatchTouchEvent(m)) {
- return mGestureDetector.onTouchEvent(m);
- }
- return true;
+ return super.dispatchTouchEvent(m);
}
private void updateZoomButtonsEnabled() {
@@ -258,34 +255,19 @@ public class ViewImage extends Activity implements View.OnClickListener {
mHandler.postDelayed(mDismissOnScreenControlRunner, 2000);
}
- private void setupOnScreenControls(final View rootView) {
- final OnTouchListener otListener = new OnTouchListener() {
- public boolean onTouch(View v, MotionEvent event) {
- scheduleDismissOnScreenControls();
- if (event.getAction() == MotionEvent.ACTION_DOWN) {
- showOnScreenControls();
- }
- return false;
- }
- };
- rootView.setOnTouchListener(otListener);
-
- setupZoomButtonController(rootView, otListener);
-
- mNextImageView = findViewById(R.id.next_image);
- mPrevImageView = findViewById(R.id.prev_image);
+ private void setupOnScreenControls(View rootView, View ownerView) {
+ mNextImageView = rootView.findViewById(R.id.next_image);
+ mPrevImageView = rootView.findViewById(R.id.prev_image);
mNextImageView.setOnClickListener(this);
mPrevImageView.setOnClickListener(this);
- mNextImageView.setOnTouchListener(otListener);
- mPrevImageView.setOnTouchListener(otListener);
- }
- private void setupZoomButtonController(
- final View rootView, final OnTouchListener otListener) {
+ setupZoomButtonController(ownerView);
+ setupOnTouchListeners(rootView);
+ }
- mGestureDetector = new GestureDetector(this, new MyGestureListener());
- mZoomButtonsController = new ZoomButtonsController(rootView);
+ private void setupZoomButtonController(final View ownerView) {
+ mZoomButtonsController = new ZoomButtonsController(ownerView);
mZoomButtonsController.setAutoDismissed(false);
mZoomButtonsController.setZoomSpeed(100);
mZoomButtonsController.setOnZoomListener(
@@ -293,8 +275,6 @@ public class ViewImage extends Activity implements View.OnClickListener {
public void onVisibilityChanged(boolean visible) {
if (visible) {
updateZoomButtonsEnabled();
- } else {
- rootView.setOnTouchListener(otListener);
}
}
@@ -304,11 +284,43 @@ public class ViewImage extends Activity implements View.OnClickListener {
} else {
mImageView.zoomOut();
}
+ mZoomButtonsController.setVisible(true);
updateZoomButtonsEnabled();
}
});
}
+ private void setupOnTouchListeners(View rootView) {
+ mGestureDetector = new GestureDetector(this, new MyGestureListener());
+
+ // If the user touches anywhere on the panel (including the
+ // next/prev button). We show the on-screen controls. In addition
+ // to that, if the touch is not on the prev/next button, we
+ // pass the event to the gesture detector to detect double tap.
+ final OnTouchListener buttonListener = new OnTouchListener() {
+ public boolean onTouch(View v, MotionEvent event) {
+ scheduleDismissOnScreenControls();
+ return false;
+ }
+ };
+
+ OnTouchListener rootListener = new OnTouchListener() {
+ public boolean onTouch(View v, MotionEvent event) {
+ buttonListener.onTouch(v, event);
+ mGestureDetector.onTouchEvent(event);
+
+ // We do not use the return value of
+ // mGestureDetector.onTouchEvent because we will not receive
+ // the "up" event if we return false for the "down" event.
+ return true;
+ }
+ };
+
+ mNextImageView.setOnTouchListener(buttonListener);
+ mPrevImageView.setOnTouchListener(buttonListener);
+ rootView.setOnTouchListener(rootListener);
+ }
+
private class MyGestureListener extends
GestureDetector.SimpleOnGestureListener {
@@ -327,6 +339,26 @@ public class ViewImage extends Activity implements View.OnClickListener {
setMode(MODE_NORMAL);
return true;
}
+
+ @Override
+ public boolean onSingleTapConfirmed(MotionEvent e) {
+ showOnScreenControls();
+ scheduleDismissOnScreenControls();
+ return true;
+ }
+
+ @Override
+ public boolean onDoubleTap(MotionEvent e) {
+ ImageViewTouch imageView = mImageView;
+
+ // Switch between the original scale and 3x scale.
+ if (imageView.getScale() > 2F) {
+ mImageView.zoomTo(1f);
+ } else {
+ mImageView.zoomToPoint(3f, e.getX(), e.getY());
+ }
+ return true;
+ }
}
boolean isPickIntent() {
@@ -415,7 +447,7 @@ public class ViewImage extends Activity implements View.OnClickListener {
setMode(MODE_NORMAL);
IImage image = mAllImages.getImageAt(mCurrentPosition);
-
+
if (mImageMenuRunnable != null) {
mImageMenuRunnable.gettingReadyToOpen(menu, image);
}
@@ -605,7 +637,7 @@ public class ViewImage extends Activity implements View.OnClickListener {
}
}
- setupOnScreenControls(findViewById(R.id.abs));
+ setupOnScreenControls(findViewById(R.id.rootLayout), mImageView);
}
private void updateActionIcons() {