Skip to content

Commit 6cf53bb

Browse files
author
Winson Chung
committed
Using screen dimensions to calculate the expanded PagedView dimensions.
- Disallowing taps/interaction outside of the viewport (Bug 7459448) - Fixing regression in incorrect pivot for Camera page - Fixing issue where the bouncer was both scaling and shrinking widget pages. Change-Id: Iefee62061962625b622ff2cf9a307d9429c2ad54
1 parent 088fb91 commit 6cf53bb

File tree

4 files changed

+66
-39
lines changed

4 files changed

+66
-39
lines changed

policy/src/com/android/internal/policy/impl/keyguard/KeyguardHostView.java

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ public void onLaunchingCamera() {
843843

844844
@Override
845845
public void onCameraLaunchedSuccessfully() {
846-
if (isCameraPage(mAppWidgetContainer.getCurrentPage())) {
846+
if (mAppWidgetContainer.isCameraPage(mAppWidgetContainer.getCurrentPage())) {
847847
mAppWidgetContainer.scrollLeft();
848848
}
849849
setSliderHandleAlpha(1);
@@ -932,7 +932,8 @@ private void addTransportToWidgetPager() {
932932
int lastWidget = mAppWidgetContainer.getChildCount() - 1;
933933
int position = 0; // handle no widget case
934934
if (lastWidget >= 0) {
935-
position = isCameraPage(lastWidget) ? lastWidget : lastWidget + 1;
935+
position = mAppWidgetContainer.isCameraPage(lastWidget) ?
936+
lastWidget : lastWidget + 1;
936937
}
937938
mAppWidgetContainer.addWidget(mTransportControl, position);
938939
mTransportControl.setVisibility(View.VISIBLE);
@@ -1146,7 +1147,7 @@ private void showAppropriateWidgetPage() {
11461147

11471148
private CameraWidgetFrame findCameraPage() {
11481149
for (int i = mAppWidgetContainer.getChildCount() - 1; i >= 0; i--) {
1149-
if (isCameraPage(i)) {
1150+
if (mAppWidgetContainer.isCameraPage(i)) {
11501151
return (CameraWidgetFrame) mAppWidgetContainer.getChildAt(i);
11511152
}
11521153
}
@@ -1162,20 +1163,6 @@ private boolean isWidgetPage(int pageIndex) {
11621163
return false;
11631164
}
11641165

1165-
private boolean isCameraPage(int pageIndex) {
1166-
View v = mAppWidgetContainer.getChildAt(pageIndex);
1167-
return v != null && v instanceof CameraWidgetFrame;
1168-
}
1169-
1170-
private boolean isAddPage(int pageIndex) {
1171-
View v = mAppWidgetContainer.getChildAt(pageIndex);
1172-
return v != null && v.getId() == R.id.keyguard_add_widget;
1173-
}
1174-
1175-
private boolean isMusicPage(int pageIndex) {
1176-
return pageIndex >= 0 && pageIndex == getWidgetPosition(R.id.keyguard_transport_control);
1177-
}
1178-
11791166
private int getStickyWidget() {
11801167
// The first time we query the persistent state. From that point, we use a locally updated
11811168
// notion of the sticky widget page.
@@ -1190,10 +1177,10 @@ public void updateStickyWidget(int index) {
11901177
if (index < 0 || index >= mAppWidgetContainer.getChildCount()) {
11911178
return;
11921179
}
1193-
if (isAddPage(index)) {
1180+
if (mAppWidgetContainer.isAddPage(index)) {
11941181
return;
11951182
}
1196-
if (isCameraPage(index)) {
1183+
if (mAppWidgetContainer.isCameraPage(index)) {
11971184
return;
11981185
}
11991186
if (isMusicPage(index)) {
@@ -1203,6 +1190,10 @@ public void updateStickyWidget(int index) {
12031190
mLocalStickyWidget = index;
12041191
}
12051192

1193+
boolean isMusicPage(int pageIndex) {
1194+
return pageIndex >= 0 && pageIndex == getWidgetPosition(R.id.keyguard_transport_control);
1195+
}
1196+
12061197
private int getAppropriateWidgetPage(boolean isMusicPlaying) {
12071198
// assumes at least one widget (besides camera + add)
12081199

@@ -1216,15 +1207,15 @@ private int getAppropriateWidgetPage(boolean isMusicPlaying) {
12161207
int stickyWidgetIndex = getStickyWidget();
12171208
if (stickyWidgetIndex > -1
12181209
&& stickyWidgetIndex < mAppWidgetContainer.getChildCount()
1219-
&& !isAddPage(stickyWidgetIndex)
1220-
&& !isCameraPage(stickyWidgetIndex)) {
1210+
&& !mAppWidgetContainer.isAddPage(stickyWidgetIndex)
1211+
&& !mAppWidgetContainer.isCameraPage(stickyWidgetIndex)) {
12211212
if (DEBUG) Log.d(TAG, "Valid sticky widget found, show page " + stickyWidgetIndex);
12221213
return stickyWidgetIndex;
12231214
}
12241215

12251216
// else show the right-most widget (except for camera)
12261217
int rightMost = mAppWidgetContainer.getChildCount() - 1;
1227-
if (isCameraPage(rightMost)) {
1218+
if (mAppWidgetContainer.isCameraPage(rightMost)) {
12281219
rightMost--;
12291220
}
12301221
if (DEBUG) Log.d(TAG, "Show right-most page " + rightMost);

policy/src/com/android/internal/policy/impl/keyguard/KeyguardWidgetPager.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,4 +758,19 @@ void zoomOutToBouncer() {
758758
mZoomInOutAnim.start();
759759
}
760760
}
761+
762+
boolean isAddPage(int pageIndex) {
763+
View v = getChildAt(pageIndex);
764+
return v != null && v.getId() == R.id.keyguard_add_widget;
765+
}
766+
767+
boolean isCameraPage(int pageIndex) {
768+
View v = getChildAt(pageIndex);
769+
return v != null && v instanceof CameraWidgetFrame;
770+
}
771+
772+
@Override
773+
protected boolean shouldSetTopAlignedPivotForWidget(int childIndex) {
774+
return !isCameraPage(childIndex) && super.shouldSetTopAlignedPivotForWidget(childIndex);
775+
}
761776
}

policy/src/com/android/internal/policy/impl/keyguard/PagedView.java

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import android.os.Parcel;
3535
import android.os.Parcelable;
3636
import android.util.AttributeSet;
37+
import android.util.DisplayMetrics;
3738
import android.util.Log;
3839
import android.view.InputDevice;
3940
import android.view.KeyEvent;
@@ -577,6 +578,10 @@ public void computeScroll() {
577578
computeScrollHelper();
578579
}
579580

581+
protected boolean shouldSetTopAlignedPivotForWidget(int childIndex) {
582+
return mTopAlignPageWhenShrinkingForBouncer;
583+
}
584+
580585
@Override
581586
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
582587
if (!mIsDataReady || getChildCount() == 0) {
@@ -593,8 +598,10 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
593598
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
594599
// NOTE: We multiply by 1.5f to account for the fact that depending on the offset of the
595600
// viewport, we can be at most one and a half screens offset once we scale down
596-
int parentWidthSize = (int) (1.5f * parent.getMeasuredWidth());
597-
int parentHeightSize = parent.getMeasuredHeight();
601+
DisplayMetrics dm = getResources().getDisplayMetrics();
602+
int maxSize = Math.max(dm.widthPixels, dm.heightPixels);
603+
int parentWidthSize = (int) (1.5f * maxSize);
604+
int parentHeightSize = maxSize;
598605
int scaledWidthSize = (int) (parentWidthSize / mMinScale);
599606
int scaledHeightSize = (int) (parentHeightSize / mMinScale);
600607
mViewport.set(0, 0, widthSize, heightSize);
@@ -651,7 +658,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
651658
MeasureSpec.makeMeasureSpec(heightSize - verticalPadding, childHeightMode);
652659

653660
child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
654-
if (mTopAlignPageWhenShrinkingForBouncer) {
661+
if (shouldSetTopAlignedPivotForWidget(i)) {
655662
child.setPivotX(child.getWidth() / 2);
656663
child.setPivotY(0f);
657664
}
@@ -1015,6 +1022,17 @@ protected boolean hitsNextPage(float x, float y) {
10151022
return (x > (getViewportOffsetX() + getViewportWidth() - getRelativeChildOffset(mCurrentPage) + mPageSpacing));
10161023
}
10171024

1025+
/** Returns whether x and y originated within the buffered/unbuffered viewport */
1026+
private boolean isTouchPointInViewport(int x, int y, boolean buffer) {
1027+
if (buffer) {
1028+
mTmpRect.set(mViewport.left - mViewport.width() / 2, mViewport.top,
1029+
mViewport.right + mViewport.width() / 2, mViewport.bottom);
1030+
return mTmpRect.contains(x, y);
1031+
} else {
1032+
return mViewport.contains(x, y);
1033+
}
1034+
}
1035+
10181036
@Override
10191037
public boolean onInterceptTouchEvent(MotionEvent ev) {
10201038
if (DISABLE_TOUCH_INTERACTION) {
@@ -1093,7 +1111,11 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
10931111
mTouchState = TOUCH_STATE_REST;
10941112
mScroller.abortAnimation();
10951113
} else {
1096-
mTouchState = TOUCH_STATE_SCROLLING;
1114+
if (isTouchPointInViewport((int) mDownMotionX, (int) mDownMotionY, true)) {
1115+
mTouchState = TOUCH_STATE_SCROLLING;
1116+
} else {
1117+
mTouchState = TOUCH_STATE_REST;
1118+
}
10971119
}
10981120

10991121
// check if this can be the beginning of a tap on the side of the pages
@@ -1115,6 +1137,10 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
11151137
case MotionEvent.ACTION_UP:
11161138
case MotionEvent.ACTION_CANCEL:
11171139
resetTouchState();
1140+
// Just intercept the touch event on up if we tap outside the strict viewport
1141+
if (!isTouchPointInViewport((int) mLastMotionX, (int) mLastMotionY, false)) {
1142+
return true;
1143+
}
11181144
break;
11191145

11201146
case MotionEvent.ACTION_POINTER_UP:
@@ -1139,24 +1165,19 @@ protected void determineScrollingStart(MotionEvent ev) {
11391165
* user moves their touch point too far.
11401166
*/
11411167
protected void determineScrollingStart(MotionEvent ev, float touchSlopScale) {
1142-
/*
1143-
* Locally do absolute value. mLastMotionX is set to the y value
1144-
* of the down event.
1145-
*/
1168+
// Disallow scrolling if we don't have a valid pointer index
11461169
final int pointerIndex = ev.findPointerIndex(mActivePointerId);
1170+
if (pointerIndex == -1) return;
11471171

1148-
if (pointerIndex == -1) {
1149-
return;
1150-
}
1172+
// Disallow scrolling if we started the gesture from outside the viewport
1173+
final float x = ev.getX(pointerIndex);
1174+
final float y = ev.getY(pointerIndex);
1175+
if (!isTouchPointInViewport((int) x, (int) y, true)) return;
11511176

11521177
// If we're only allowing edge swipes, we break out early if the down event wasn't
11531178
// at the edge.
1154-
if (mOnlyAllowEdgeSwipes && !mDownEventOnEdge) {
1155-
return;
1156-
}
1179+
if (mOnlyAllowEdgeSwipes && !mDownEventOnEdge) return;
11571180

1158-
final float x = ev.getX(pointerIndex);
1159-
final float y = ev.getY(pointerIndex);
11601181
final int xDiff = (int) Math.abs(x - mLastMotionX);
11611182
final int yDiff = (int) Math.abs(y - mLastMotionY);
11621183

policy/src/com/android/internal/policy/impl/keyguard/SlidingChallengeLayout.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,8 @@ public boolean isBouncing() {
469469
public void showBouncer() {
470470
if (mIsBouncing) return;
471471
mWasChallengeShowing = mChallengeShowing;
472-
showChallenge(true);
473472
mIsBouncing = true;
473+
showChallenge(true);
474474
if (mScrimView != null) {
475475
mScrimView.setVisibility(VISIBLE);
476476
}

0 commit comments

Comments
 (0)