OSDN Git Service

Temp swipe interception to support swipe from capture button
authorDoris Liu <tianliu@google.com>
Tue, 1 Apr 2014 22:53:56 +0000 (15:53 -0700)
committerDoris Liu <tianliu@google.com>
Tue, 1 Apr 2014 23:54:07 +0000 (16:54 -0700)
Bug: 13535296
Change-Id: I911336ce407abbfe51759bb38ffff9a534a49de6

src/com/android/camera/app/CameraAppUI.java
src/com/android/camera/ui/MainActivityLayout.java
src/com/android/camera/ui/ModeListView.java

index e98d435..629e64b 100644 (file)
@@ -760,6 +760,9 @@ public class CameraAppUI implements ModeListView.ModeSwitchListener,
      */
     public void setSwipeEnabled(boolean enabled) {
         mSwipeEnabled = enabled;
+        // TODO: This can be removed once we come up with a new design for handling swipe
+        // on shutter button and mode options. (More details: b/13751653)
+        mAppRootView.setSwipeEnabled(enabled);
     }
 
     public void onDestroy() {
index d1f2f41..b12eb01 100644 (file)
 
 package com.android.camera.ui;
 
+import android.app.Activity;
 import android.content.Context;
+import android.content.Intent;
+import android.provider.MediaStore;
 import android.util.AttributeSet;
 import android.view.MotionEvent;
 import android.view.View;
+import android.view.ViewConfiguration;
 import android.widget.FrameLayout;
 
 import com.android.camera.debug.Log;
+import com.android.camera.util.UsageStatistics;
+import com.android.camera.widget.FilmstripLayout;
+import com.android.camera2.R;
+
+import com.google.common.logging.eventprotos;
 
 public class MainActivityLayout extends FrameLayout {
 
-    private MotionEvent mDown;
     private final Log.Tag TAG = new Log.Tag("MainActivityLayout");
+    // Only check for intercepting touch events within first 500ms
+    private static final int SWIPE_TIME_OUT = 500;
+
+    private ModeListView mModeList;
+    private FilmstripLayout mFilmstripLayout;
+    private boolean mCheckToIntercept;
+    private MotionEvent mDown;
+    private final int mSlop;
     private boolean mRequestToInterceptTouchEvents = false;
     private View mTouchReceiver = null;
+    private final boolean mIsCaptureIntent;
+
+    // TODO: This can be removed once we come up with a new design for b/13751653.
+    @Deprecated
+    private boolean mSwipeEnabled = true;
 
     public MainActivityLayout(Context context, AttributeSet attrs) {
         super(context, attrs);
+        mSlop = ViewConfiguration.get(context).getScaledTouchSlop();
+
+        Activity activity = (Activity) context;
+        Intent intent = activity.getIntent();
+        String action = intent.getAction();
+        mIsCaptureIntent = (MediaStore.ACTION_IMAGE_CAPTURE.equals(action)
+                || MediaStore.ACTION_IMAGE_CAPTURE_SECURE.equals(action)
+                || MediaStore.ACTION_VIDEO_CAPTURE.equals(action));
+    }
+
+    /**
+     * Enables or disables the swipe for modules not supporting the new swipe
+     * logic yet.
+     */
+    @Deprecated
+    public void setSwipeEnabled(boolean enabled) {
+        mSwipeEnabled = enabled;
     }
 
     @Override
     public boolean onInterceptTouchEvent(MotionEvent ev) {
         if (ev.getActionMasked() == MotionEvent.ACTION_DOWN) {
+            mCheckToIntercept = true;
             mDown = MotionEvent.obtain(ev);
             mTouchReceiver = null;
             mRequestToInterceptTouchEvents = false;
@@ -48,7 +87,38 @@ public class MainActivityLayout extends FrameLayout {
             return true;
         } else if (ev.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) {
             // Do not intercept touch once child is in zoom mode
+            mCheckToIntercept = false;
             return false;
+        } else {
+            // TODO: This can be removed once we come up with a new design for b/13751653.
+            if (!mCheckToIntercept) {
+                return false;
+            }
+            if (ev.getEventTime() - ev.getDownTime() > SWIPE_TIME_OUT) {
+                return false;
+            }
+            if (mIsCaptureIntent || !mSwipeEnabled) {
+                return false;
+            }
+            int deltaX = (int) (ev.getX() - mDown.getX());
+            int deltaY = (int) (ev.getY() - mDown.getY());
+            if (ev.getActionMasked() == MotionEvent.ACTION_MOVE
+                    && Math.abs(deltaX) > mSlop) {
+                // Intercept right swipe
+                if (deltaX >= Math.abs(deltaY) * 2) {
+                    mTouchReceiver = mModeList;
+                    onTouchEvent(mDown);
+                    return true;
+                }
+                // Intercept left swipe
+                else if (deltaX < -Math.abs(deltaY) * 2) {
+                    mTouchReceiver = mFilmstripLayout;
+                    UsageStatistics.changeScreen(eventprotos.NavigationChange.Mode.FILMSTRIP,
+                            eventprotos.CameraEvent.InteractionCause.SWIPE_LEFT);
+                    onTouchEvent(mDown);
+                    return true;
+                }
+            }
         }
         return false;
     }
@@ -62,6 +132,12 @@ public class MainActivityLayout extends FrameLayout {
         return false;
     }
 
+    @Override
+    public void onFinishInflate() {
+        mModeList = (ModeListView) findViewById(R.id.mode_list_layout);
+        mFilmstripLayout = (FilmstripLayout) findViewById(R.id.filmstrip_layout);
+    }
+
     public void redirectTouchEventsTo(View touchReceiver) {
         if (touchReceiver == null) {
             Log.e(TAG, "Cannot redirect touch to a null receiver.");
@@ -70,4 +146,4 @@ public class MainActivityLayout extends FrameLayout {
         mTouchReceiver = touchReceiver;
         mRequestToInterceptTouchEvents = true;
     }
-}
+}
\ No newline at end of file
index be45763..4166713 100644 (file)
@@ -1292,6 +1292,7 @@ public class ModeListView extends FrameLayout
         if (!mCurrentStateManager.getCurrentState().shouldHandleTouchEvent(ev)) {
             return false;
         }
+        getParent().requestDisallowInterceptTouchEvent(true);
         super.onTouchEvent(ev);
 
         // Pass all touch events to gesture detector for gesture handling.