OSDN Git Service

Disable security handle when swiping into camera widget.
authorJohn Spurlock <jspurlock@google.com>
Wed, 31 Oct 2012 13:46:15 +0000 (09:46 -0400)
committerJohn Spurlock <jspurlock@google.com>
Fri, 2 Nov 2012 13:00:04 +0000 (09:00 -0400)
Bug:7444313
Change-Id: I3eb268a41bc8b8a4323e55577a775c5ab3cef10d

policy/src/com/android/internal/policy/impl/keyguard/CameraWidgetFrame.java
policy/src/com/android/internal/policy/impl/keyguard/KeyguardHostView.java
policy/src/com/android/internal/policy/impl/keyguard/KeyguardViewStateManager.java
policy/src/com/android/internal/policy/impl/keyguard/KeyguardWidgetFrame.java
policy/src/com/android/internal/policy/impl/keyguard/KeyguardWidgetPager.java
policy/src/com/android/internal/policy/impl/keyguard/PagedView.java
policy/src/com/android/internal/policy/impl/keyguard/SlidingChallengeLayout.java

index 2728bfc..893df26 100644 (file)
@@ -53,13 +53,14 @@ public class CameraWidgetFrame extends KeyguardWidgetFrame implements View.OnCli
     private final Callbacks mCallbacks;
     private final WindowManager mWindowManager;
     private final Point mRenderedSize = new Point();
+    private final int[] mScreenLocation = new int[2];
 
     private View mWidgetView;
     private long mLaunchCameraStart;
     private boolean mActive;
-    private boolean mChallengeActive;
     private boolean mTransitioning;
     private boolean mDown;
+    private boolean mWindowFocused;
 
     private final Runnable mLaunchCameraRunnable = new Runnable() {
         @Override
@@ -186,7 +187,7 @@ public class CameraWidgetFrame extends KeyguardWidgetFrame implements View.OnCli
     }
 
     private void transitionToCamera() {
-        if (mTransitioning || mChallengeActive || mDown) return;
+        if (mTransitioning || mDown) return;
 
         mTransitioning = true;
 
@@ -233,7 +234,7 @@ public class CameraWidgetFrame extends KeyguardWidgetFrame implements View.OnCli
     public void onClick(View v) {
         if (DEBUG) Log.d(TAG, "clicked");
         if (mTransitioning) return;
-        if (mActive && !mChallengeActive) {
+        if (mActive) {
             cancelTransitionToCamera();
             transitionToCamera();
         }
@@ -242,6 +243,7 @@ public class CameraWidgetFrame extends KeyguardWidgetFrame implements View.OnCli
     @Override
     public void onWindowFocusChanged(boolean hasWindowFocus) {
         super.onWindowFocusChanged(hasWindowFocus);
+        mWindowFocused = hasWindowFocus;
         if (DEBUG) Log.d(TAG, "onWindowFocusChanged: " + hasWindowFocus);
         if (!hasWindowFocus) {
             mTransitioning = false;
@@ -265,13 +267,29 @@ public class CameraWidgetFrame extends KeyguardWidgetFrame implements View.OnCli
     }
 
     @Override
-    public boolean onUserInteraction(int action) {
-        if (mTransitioning) return true;
-        if (DEBUG) Log.d(TAG, "onUserInteraction " + action);
+    public boolean onUserInteraction(MotionEvent event) {
+        if (!mWindowFocused) {
+            if (DEBUG) Log.d(TAG, "onUserInteraction eaten: !mWindowFocused");
+            return true;
+        }
+        if (mTransitioning) {
+            if (DEBUG) Log.d(TAG, "onUserInteraction eaten: mTransitioning");
+            return true;
+        }
+
+        getLocationOnScreen(mScreenLocation);
+        int rawBottom = mScreenLocation[1] + getHeight();
+        if (event.getRawY() > rawBottom) {
+            if (DEBUG) Log.d(TAG, "onUserInteraction eaten: below widget");
+            return true;
+        }
+
+        int action = event.getAction();
         mDown = action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_MOVE;
-        if (mActive && !mChallengeActive) {
+        if (mActive) {
             rescheduleTransitionToCamera();
         }
+        if (DEBUG) Log.d(TAG, "onUserInteraction observed, not eaten");
         return false;
     }
 
@@ -282,20 +300,6 @@ public class CameraWidgetFrame extends KeyguardWidgetFrame implements View.OnCli
         super.onFocusLost();
     }
 
-    @Override
-    public void onChallengeActive(boolean challengeActive) {
-        if (DEBUG) Log.d(TAG, "onChallengeActive: " + challengeActive);
-        mChallengeActive = challengeActive;
-        if (mTransitioning) return;
-        if (mActive) {
-            if (mChallengeActive) {
-                cancelTransitionToCamera();
-            } else {
-                rescheduleTransitionToCamera();
-            }
-        }
-    }
-
     public void onScreenTurnedOff() {
         if (DEBUG) Log.d(TAG, "onScreenTurnedOff");
         reset();
@@ -321,7 +325,6 @@ public class CameraWidgetFrame extends KeyguardWidgetFrame implements View.OnCli
         if (DEBUG) Log.d(TAG, "reset");
         mLaunchCameraStart = 0;
         mTransitioning = false;
-        mChallengeActive = false;
         mDown = false;
         cancelTransitionToCamera();
         animate().cancel();
@@ -347,6 +350,7 @@ public class CameraWidgetFrame extends KeyguardWidgetFrame implements View.OnCli
         WindowManager.LayoutParams wlp = (WindowManager.LayoutParams) lp;
         int newWindowAnimations = isEnabled ? com.android.internal.R.style.Animation_LockScreen : 0;
         if (newWindowAnimations != wlp.windowAnimations) {
+            if (DEBUG) Log.d(TAG, "setting windowAnimations to: " + newWindowAnimations);
             wlp.windowAnimations = newWindowAnimations;
             mWindowManager.updateViewLayout(root, wlp);
         }
index 86f3259..08d388b 100644 (file)
@@ -837,6 +837,10 @@ public class KeyguardHostView extends KeyguardViewBase {
                 if (isCameraPage(mAppWidgetContainer.getCurrentPage())) {
                     mAppWidgetContainer.scrollLeft();
                 }
+                SlidingChallengeLayout slider = locateSlider();
+                if (slider != null) {
+                    slider.setHandleAlpha(1);
+                }
                 mShowSecurityWhenReturn = true;
             }
 
index a531558..ddded8e 100644 (file)
@@ -101,7 +101,14 @@ public class KeyguardViewStateManager implements SlidingChallengeLayout.OnChalle
         ((View) mKeyguardSecurityContainer).animate().alpha(1f).setDuration(duration);
     }
 
-    public void onPageSwitch(View newPage, int newPageIndex) {
+    public void onPageSwitching(View newPage, int newPageIndex) {
+        if (mPagedView != null && mChallengeLayout instanceof SlidingChallengeLayout) {
+            boolean isCameraPage = newPage instanceof CameraWidgetFrame;
+            ((SlidingChallengeLayout) mChallengeLayout).setChallengeInteractive(!isCameraPage);
+        }
+    }
+
+    public void onPageSwitched(View newPage, int newPageIndex) {
         // Reset the previous page size and ensure the current page is sized appropriately.
         // We only modify the page state if it is not currently under control by the slider.
         // This prevents conflicts.
@@ -166,7 +173,6 @@ public class KeyguardViewStateManager implements SlidingChallengeLayout.OnChalle
             if (!challengeOverlapping) {
                 frame.resetSize();
             }
-            frame.onChallengeActive(mChallengeLayout.isChallengeShowing());
             frame.hideFrame(this);
 
             if (challengeOverlapping) {
@@ -200,8 +206,6 @@ public class KeyguardViewStateManager implements SlidingChallengeLayout.OnChalle
             }
             // View is on the move.  Pause the security view until it completes.
             mKeyguardSecurityContainer.onPause();
-
-            frame.onChallengeActive(true);
         }
         mLastScrollState = scrollState;
     }
index 5657242..b6ea9ba 100644 (file)
@@ -418,12 +418,8 @@ public class KeyguardWidgetFrame extends FrameLayout {
         // hook for subclasses
     }
 
-    public boolean onUserInteraction(int action) {
+    public boolean onUserInteraction(MotionEvent event) {
         // hook for subclasses
         return false;
     }
-
-    public void onChallengeActive(boolean challengeActive) {
-        // hook for subclasses
-    }
 }
index e3e7cd4..a6d1a02 100644 (file)
@@ -119,7 +119,14 @@ public class KeyguardWidgetPager extends PagedView implements PagedView.PageSwit
     }
 
     @Override
-    public void onPageSwitch(View newPage, int newPageIndex) {
+    public void onPageSwitching(View newPage, int newPageIndex) {
+        if (mViewStateManager != null) {
+            mViewStateManager.onPageSwitching(newPage, newPageIndex);
+        }
+    }
+
+    @Override
+    public void onPageSwitched(View newPage, int newPageIndex) {
         boolean showingStatusWidget = false;
         if (newPage instanceof ViewGroup) {
             ViewGroup vg = (ViewGroup) newPage;
@@ -158,7 +165,7 @@ public class KeyguardWidgetPager extends PagedView implements PagedView.PageSwit
             }
         }
         if (mViewStateManager != null) {
-            mViewStateManager.onPageSwitch(newPage, newPageIndex);
+            mViewStateManager.onPageSwitched(newPage, newPageIndex);
         }
     }
 
@@ -179,7 +186,7 @@ public class KeyguardWidgetPager extends PagedView implements PagedView.PageSwit
     @Override
     public boolean onTouchEvent(MotionEvent ev) {
         KeyguardWidgetFrame currentWidgetPage = getWidgetPageAt(getCurrentPage());
-        if (currentWidgetPage != null && currentWidgetPage.onUserInteraction(ev.getAction())) {
+        if (currentWidgetPage != null && currentWidgetPage.onUserInteraction(ev)) {
             return true;
         }
         return super.onTouchEvent(ev);
index 6eeada5..bad50e8 100644 (file)
@@ -239,7 +239,8 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
     private boolean mIsFlingingToDelete = false;
 
     public interface PageSwitchListener {
-        void onPageSwitch(View newPage, int newPageIndex);
+        void onPageSwitching(View newPage, int newPageIndex);
+        void onPageSwitched(View newPage, int newPageIndex);
     }
 
     public PagedView(Context context) {
@@ -356,7 +357,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
     public void setPageSwitchListener(PageSwitchListener pageSwitchListener) {
         mPageSwitchListener = pageSwitchListener;
         if (mPageSwitchListener != null) {
-            mPageSwitchListener.onPageSwitch(getPageAt(mCurrentPage), mCurrentPage);
+            mPageSwitchListener.onPageSwitched(getPageAt(mCurrentPage), mCurrentPage);
         }
     }
 
@@ -415,6 +416,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
      * Sets the current page.
      */
     void setCurrentPage(int currentPage) {
+        notifyPageSwitching(currentPage);
         if (!mScroller.isFinished()) {
             mScroller.abortAnimation();
         }
@@ -428,7 +430,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
         mCurrentPage = Math.max(0, Math.min(currentPage, getPageCount() - 1));
         updateCurrentPageScroll();
         updateScrollingIndicator();
-        notifyPageSwitchListener();
+        notifyPageSwitched();
         invalidate();
     }
 
@@ -436,9 +438,15 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
         mOnlyAllowEdgeSwipes = enable;
     }
 
-    protected void notifyPageSwitchListener() {
+    protected void notifyPageSwitching(int whichPage) {
         if (mPageSwitchListener != null) {
-            mPageSwitchListener.onPageSwitch(getPageAt(mCurrentPage), mCurrentPage);
+            mPageSwitchListener.onPageSwitching(getPageAt(whichPage), whichPage);
+        }
+    }
+
+    protected void notifyPageSwitched() {
+        if (mPageSwitchListener != null) {
+            mPageSwitchListener.onPageSwitched(getPageAt(mCurrentPage), mCurrentPage);
         }
     }
 
@@ -532,7 +540,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
         } else if (mNextPage != INVALID_PAGE) {
             mCurrentPage = Math.max(0, Math.min(mNextPage, getPageCount() - 1));
             mNextPage = INVALID_PAGE;
-            notifyPageSwitchListener();
+            notifyPageSwitched();
 
             // We don't want to trigger a page end moving unless the page has settled
             // and the user has stopped scrolling
@@ -1743,7 +1751,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
     }
     protected void snapToPage(int whichPage, int delta, int duration, boolean immediate) {
         mNextPage = whichPage;
-
+        notifyPageSwitching(whichPage);
         View focusedChild = getFocusedChild();
         if (focusedChild != null && whichPage != mCurrentPage &&
                 focusedChild == getPageAt(mCurrentPage)) {
@@ -1761,7 +1769,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
         if (!mScroller.isFinished()) mScroller.abortAnimation();
         mScroller.startScroll(mUnboundedScrollX, 0, delta, 0, duration);
 
-        notifyPageSwitchListener();
+        notifyPageSwitched();
 
         // Trigger a compute() to finish switching pages if necessary
         if (immediate) {
index fd87646..85997b8 100644 (file)
@@ -122,6 +122,7 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout
     private final Rect mTempRect = new Rect();
 
     private boolean mHasGlowpad;
+    private boolean mChallengeInteractive = true;
 
     static final Property<SlidingChallengeLayout, Float> HANDLE_ALPHA =
             new FloatProperty<SlidingChallengeLayout>("handleAlpha") {
@@ -186,7 +187,7 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout
     private final OnClickListener mExpandChallengeClickListener = new OnClickListener() {
         @Override
         public void onClick(View v) {
-            if (!isChallengeShowing()) {
+            if (!isChallengeShowing() && mChallengeInteractive) {
                 showChallenge(true);
             }
         }
@@ -275,6 +276,10 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout
         }
     }
 
+    public void setChallengeInteractive(boolean interactive) {
+        mChallengeInteractive = interactive;
+    }
+
     void animateHandle(boolean visible) {
         if (mHandleAnimation != null) {
             mHandleAnimation.cancel();
@@ -579,7 +584,7 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout
                 for (int i = 0; i < count; i++) {
                     final float x = ev.getX(i);
                     final float y = ev.getY(i);
-                    if (!mIsBouncing && mActivePointerId == INVALID_POINTER
+                    if (!mIsBouncing && mChallengeInteractive && mActivePointerId == INVALID_POINTER
                                 && (crossedDragHandle(x, y, mGestureStartY)
                                 || (isInChallengeView(x, y) &&
                                         mScrollState == SCROLL_STATE_SETTLING))) {
@@ -627,7 +632,7 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout
                 break;
 
             case MotionEvent.ACTION_CANCEL:
-                if (mDragging) {
+                if (mDragging && mChallengeInteractive) {
                     showChallenge(0);
                 }
                 resetTouch();
@@ -638,7 +643,7 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout
                     break;
                 }
             case MotionEvent.ACTION_UP:
-                if (mDragging) {
+                if (mDragging && mChallengeInteractive) {
                     mVelocityTracker.computeCurrentVelocity(1000, mMaxVelocity);
                     showChallenge((int) mVelocityTracker.getYVelocity(mActivePointerId));
                 }
@@ -654,7 +659,8 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout
 
                         if ((isInDragHandle(x, y) || crossedDragHandle(x, y, mGestureStartY) ||
                                 (isInChallengeView(x, y) && mScrollState == SCROLL_STATE_SETTLING))
-                                && mActivePointerId == INVALID_POINTER) {
+                                && mActivePointerId == INVALID_POINTER
+                                && mChallengeInteractive) {
                             mGestureStartX = x;
                             mGestureStartY = y;
                             mActivePointerId = ev.getPointerId(i);