Skip to content

Commit 6d04712

Browse files
committed
Allow simultaneous scale and pan in magnified state.
1. Before in magnified state the user was able to only scale or pan. Based on user input this change allows performing pan or scale or both. If the user scales more than a threshold we are performing a scale and independently of that if the use pans more than a threshold we are performing a pan. bug:7138928 Change-Id: Ic1511500ba3369091dcfd070669d3e4f0286fbe5
1 parent 0c38150 commit 6d04712

File tree

1 file changed

+46
-60
lines changed

1 file changed

+46
-60
lines changed

services/java/com/android/server/accessibility/ScreenMagnifier.java

Lines changed: 46 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,15 @@ public final class ScreenMagnifier implements EventStreamTransformation {
114114
private static final boolean DEBUG_VIEWPORT_WINDOW = false;
115115
private static final boolean DEBUG_WINDOW_TRANSITIONS = false;
116116
private static final boolean DEBUG_ROTATION = false;
117-
private static final boolean DEBUG_GESTURE_DETECTOR = false;
117+
private static final boolean DEBUG_SCALE_GESTURE_DETECTOR = false;
118118
private static final boolean DEBUG_MAGNIFICATION_CONTROLLER = false;
119119

120120
private static final String LOG_TAG = ScreenMagnifier.class.getSimpleName();
121121

122122
private static final int STATE_DELEGATING = 1;
123123
private static final int STATE_DETECTING = 2;
124-
private static final int STATE_SCALING = 3;
125124
private static final int STATE_VIEWPORT_DRAGGING = 4;
126-
private static final int STATE_PANNING = 5;
127-
private static final int STATE_DECIDE_PAN_OR_SCALE = 6;
125+
private static final int STATE_MAGNIFIED_INTERACTION = 6;
128126

129127
private static final float DEFAULT_MAGNIFICATION_SCALE = 2.0f;
130128
private static final int DEFAULT_SCREEN_MAGNIFICATION_AUTO_UPDATE = 1;
@@ -203,12 +201,10 @@ public void onMotionEvent(MotionEvent event, int policyFlags) {
203201
case STATE_VIEWPORT_DRAGGING: {
204202
mStateViewportDraggingHandler.onMotionEvent(event, policyFlags);
205203
} break;
206-
case STATE_SCALING:
207-
case STATE_PANNING:
208-
case STATE_DECIDE_PAN_OR_SCALE: {
204+
case STATE_MAGNIFIED_INTERACTION: {
209205
// Handled by the gesture detector. Since the detector
210206
// needs all touch events to work properly we cannot
211-
// call it only for these states.
207+
// call it only for this state.
212208
} break;
213209
default: {
214210
throw new IllegalStateException("Unknown state: " + mCurrentState);
@@ -326,14 +322,8 @@ private void transitionToState(int state) {
326322
case STATE_VIEWPORT_DRAGGING: {
327323
Slog.i(LOG_TAG, "mCurrentState: STATE_VIEWPORT_DRAGGING");
328324
} break;
329-
case STATE_SCALING: {
330-
Slog.i(LOG_TAG, "mCurrentState: STATE_SCALING");
331-
} break;
332-
case STATE_PANNING: {
333-
Slog.i(LOG_TAG, "mCurrentState: STATE_PANNING");
334-
} break;
335-
case STATE_DECIDE_PAN_OR_SCALE: {
336-
Slog.i(LOG_TAG, "mCurrentState: STATE_DECIDE_PAN_OR_SCALE");
325+
case STATE_MAGNIFIED_INTERACTION: {
326+
Slog.i(LOG_TAG, "mCurrentState: STATE_MAGNIFIED_INTERACTION");
337327
} break;
338328
default: {
339329
throw new IllegalArgumentException("Unknown state: " + state);
@@ -347,7 +337,7 @@ private final class GestureDetector implements OnScaleGestureListener {
347337
private static final float MIN_SCALE = 1.3f;
348338
private static final float MAX_SCALE = 5.0f;
349339

350-
private static final float DETECT_SCALING_THRESHOLD = 0.25f;
340+
private static final float DETECT_SCALING_THRESHOLD = 0.30f;
351341
private static final int DETECT_PANNING_THRESHOLD_DIP = 30;
352342

353343
private final float mScaledDetectPanningThreshold;
@@ -366,6 +356,9 @@ private final class GestureDetector implements OnScaleGestureListener {
366356
private float mScaleFocusX = Float.NaN;
367357
private float mScaleFocusY = Float.NaN;
368358

359+
private boolean mScaling;
360+
private boolean mPanning;
361+
369362
public GestureDetector(Context context) {
370363
final float density = context.getResources().getDisplayMetrics().density;
371364
mScaledDetectPanningThreshold = DETECT_PANNING_THRESHOLD_DIP * density;
@@ -383,8 +376,9 @@ public void onMotionEvent(MotionEvent event) {
383376
}
384377
if (event.getActionMasked() == MotionEvent.ACTION_UP) {
385378
clear();
386-
if (mCurrentState == STATE_SCALING) {
387-
persistScale(mMagnificationController.getScale());
379+
final float scale = mMagnificationController.getScale();
380+
if (scale != getPersistedScale()) {
381+
persistScale(scale);
388382
}
389383
transitionToState(STATE_DETECTING);
390384
}
@@ -398,71 +392,63 @@ public boolean onScale(ScaleGestureDetector detector) {
398392
case STATE_VIEWPORT_DRAGGING: {
399393
return true;
400394
}
401-
case STATE_DECIDE_PAN_OR_SCALE: {
395+
case STATE_MAGNIFIED_INTERACTION: {
402396
mCurrScaleFactor = mScaleGestureDetector.getScaleFactor();
403397
final float scaleDelta = Math.abs(1.0f - mCurrScaleFactor * mPrevScaleFactor);
404-
if (DEBUG_GESTURE_DETECTOR) {
398+
if (DEBUG_SCALE_GESTURE_DETECTOR) {
405399
Slog.i(LOG_TAG, "scaleDelta: " + scaleDelta);
406400
}
407-
if (scaleDelta > DETECT_SCALING_THRESHOLD) {
408-
performScale(detector, true);
409-
clear();
410-
transitionToState(STATE_SCALING);
401+
if (!mScaling && scaleDelta > DETECT_SCALING_THRESHOLD) {
402+
mScaling = true;
403+
clearContextualState();
411404
return true;
412405
}
406+
if (mScaling) {
407+
performScale(detector);
408+
}
413409
mCurrPan = (float) MathUtils.dist(
414410
mScaleGestureDetector.getFocusX(),
415411
mScaleGestureDetector.getFocusY(),
416412
mInitialFocus.x, mInitialFocus.y);
417413
final float panDelta = mCurrPan + mPrevPan;
418-
if (DEBUG_GESTURE_DETECTOR) {
414+
if (DEBUG_SCALE_GESTURE_DETECTOR) {
419415
Slog.i(LOG_TAG, "panDelta: " + panDelta);
420416
}
421-
if (panDelta > mScaledDetectPanningThreshold) {
422-
performPan(detector, true);
423-
clear();
424-
transitionToState(STATE_PANNING);
417+
if (!mPanning && panDelta > mScaledDetectPanningThreshold) {
418+
mPanning = true;
419+
clearContextualState();
425420
return true;
426421
}
427-
} break;
428-
case STATE_SCALING: {
429-
performScale(detector, false);
430-
} break;
431-
case STATE_PANNING: {
432-
performPan(detector, false);
422+
if (mPanning) {
423+
performPan(detector);
424+
}
433425
} break;
434426
}
435427
return false;
436428
}
437429

438430
@Override
439431
public boolean onScaleBegin(ScaleGestureDetector detector) {
440-
switch (mCurrentState) {
441-
case STATE_DECIDE_PAN_OR_SCALE: {
442-
mPrevScaleFactor *= mCurrScaleFactor;
443-
mPrevPan += mCurrPan;
444-
mPrevFocus.x = mInitialFocus.x = detector.getFocusX();
445-
mPrevFocus.y = mInitialFocus.y = detector.getFocusY();
446-
} break;
447-
case STATE_SCALING: {
448-
mPrevScaleFactor = 1.0f;
449-
mCurrScale = Float.NaN;
450-
} break;
451-
case STATE_PANNING: {
452-
mPrevPan += mCurrPan;
453-
mPrevFocus.x = mInitialFocus.x = detector.getFocusX();
454-
mPrevFocus.y = mInitialFocus.y = detector.getFocusY();
455-
} break;
456-
}
432+
mPrevScaleFactor *= mCurrScaleFactor;
433+
mCurrScale = Float.NaN;
434+
mPrevPan += mCurrPan;
435+
mPrevFocus.x = mInitialFocus.x = detector.getFocusX();
436+
mPrevFocus.y = mInitialFocus.y = detector.getFocusY();
457437
return true;
458438
}
459439

460440
@Override
461441
public void onScaleEnd(ScaleGestureDetector detector) {
462-
clear();
442+
clearContextualState();
463443
}
464444

465445
public void clear() {
446+
clearContextualState();
447+
mScaling = false;
448+
mPanning = false;
449+
}
450+
451+
private void clearContextualState() {
466452
mCurrScaleFactor = 1.0f;
467453
mPrevScaleFactor = 1.0f;
468454
mPrevPan = 0;
@@ -474,7 +460,7 @@ public void clear() {
474460
mScaleFocusY = Float.NaN;
475461
}
476462

477-
private void performPan(ScaleGestureDetector detector, boolean animate) {
463+
private void performPan(ScaleGestureDetector detector) {
478464
if (Float.compare(mPrevFocus.x, Float.NaN) == 0
479465
&& Float.compare(mPrevFocus.y, Float.NaN) == 0) {
480466
mPrevFocus.set(detector.getFocusX(), detector.getFocusY());
@@ -491,11 +477,11 @@ private void performPan(ScaleGestureDetector detector, boolean animate) {
491477
Slog.i(LOG_TAG, "Panned content by scrollX: " + scrollX
492478
+ " scrollY: " + scrollY);
493479
}
494-
mMagnificationController.setMagnifiedRegionCenter(centerX, centerY, animate);
480+
mMagnificationController.setMagnifiedRegionCenter(centerX, centerY, false);
495481
mPrevFocus.set(detector.getFocusX(), detector.getFocusY());
496482
}
497483

498-
private void performScale(ScaleGestureDetector detector, boolean animate) {
484+
private void performScale(ScaleGestureDetector detector) {
499485
if (Float.compare(mCurrScale, Float.NaN) == 0) {
500486
mCurrScale = mMagnificationController.getScale();
501487
return;
@@ -513,7 +499,7 @@ private void performScale(ScaleGestureDetector detector, boolean animate) {
513499
mScaleFocusY = detector.getFocusY();
514500
}
515501
mMagnificationController.setScale(normalizedNewScale, mScaleFocusX,
516-
mScaleFocusY, animate);
502+
mScaleFocusY, false);
517503
}
518504
}
519505

@@ -528,7 +514,7 @@ private void onMotionEvent(MotionEvent event, int policyFlags) {
528514
}
529515
case MotionEvent.ACTION_POINTER_DOWN: {
530516
clear();
531-
transitionToState(STATE_SCALING);
517+
transitionToState(STATE_MAGNIFIED_INTERACTION);
532518
} break;
533519
case MotionEvent.ACTION_MOVE: {
534520
if (event.getPointerCount() != 1) {
@@ -632,7 +618,7 @@ public void onMotionEvent(MotionEvent event, int policyFlags) {
632618
} break;
633619
case MotionEvent.ACTION_POINTER_DOWN: {
634620
if (mMagnificationController.isMagnifying()) {
635-
transitionToState(STATE_DECIDE_PAN_OR_SCALE);
621+
transitionToState(STATE_MAGNIFIED_INTERACTION);
636622
clear();
637623
} else {
638624
transitionToDelegatingStateAndClear();

0 commit comments

Comments
 (0)