summaryrefslogtreecommitdiffstats
path: root/services/java/com/android/server/accessibility/ScreenMagnifier.java
diff options
context:
space:
mode:
authorSvetoslav Ganov <svetoslavganov@google.com>2012-09-10 18:16:02 -0700
committerSvetoslav Ganov <svetoslavganov@google.com>2012-09-10 18:16:05 -0700
commit36e614c110dad174dea6017eb701f55339aee200 (patch)
tree93e9aaa78d1090cc4fce72e9fe88fab26032ca7c /services/java/com/android/server/accessibility/ScreenMagnifier.java
parent86fe9e14f1a816df32b08e0eb677989cc7444948 (diff)
downloadframeworks_base-36e614c110dad174dea6017eb701f55339aee200.zip
frameworks_base-36e614c110dad174dea6017eb701f55339aee200.tar.gz
frameworks_base-36e614c110dad174dea6017eb701f55339aee200.tar.bz2
Screen magnification should disengage on screen off.
1. When the screen goes off the user will be in a completely different context upon turning the screen on. Therefore, if magnification auto update is enabled magnification will be disengaged on screen off. bug:7139088 Change-Id: I790cfa5b3cf31d34e95fc9548e6246a84096c37b
Diffstat (limited to 'services/java/com/android/server/accessibility/ScreenMagnifier.java')
-rw-r--r--services/java/com/android/server/accessibility/ScreenMagnifier.java71
1 files changed, 63 insertions, 8 deletions
diff --git a/services/java/com/android/server/accessibility/ScreenMagnifier.java b/services/java/com/android/server/accessibility/ScreenMagnifier.java
index aa3c82b..8301211 100644
--- a/services/java/com/android/server/accessibility/ScreenMagnifier.java
+++ b/services/java/com/android/server/accessibility/ScreenMagnifier.java
@@ -21,7 +21,10 @@ import android.animation.Animator.AnimatorListener;
import android.animation.ObjectAnimator;
import android.animation.TypeEvaluator;
import android.animation.ValueAnimator;
+import android.content.BroadcastReceiver;
import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.PixelFormat;
@@ -144,6 +147,7 @@ public final class ScreenMagnifier implements EventStreamTransformation {
private final MagnificationController mMagnificationController;
private final DisplayContentObserver mDisplayContentObserver;
+ private final ScreenStateObserver mScreenStateObserver;
private final Viewport mViewport;
private final int mTapTimeSlop = ViewConfiguration.getTapTimeout();
@@ -187,6 +191,8 @@ public final class ScreenMagnifier implements EventStreamTransformation {
mDisplayContentObserver = new DisplayContentObserver(mContext, mViewport,
mMagnificationController, mWindowManagerService, mDisplayProvider,
mLongAnimationDuration, mWindowAnimationScale);
+ mScreenStateObserver = new ScreenStateObserver(mContext, mViewport,
+ mMagnificationController);
mGestureDetector = new GestureDetector(context);
@@ -247,6 +253,7 @@ public final class ScreenMagnifier implements EventStreamTransformation {
mViewport.setFrameShown(false, true);
mDisplayProvider.destroy();
mDisplayContentObserver.destroy();
+ mScreenStateObserver.destroy();
}
private void handleMotionEventStateDelegating(MotionEvent event, int policyFlags) {
@@ -786,6 +793,12 @@ public final class ScreenMagnifier implements EventStreamTransformation {
DEFAULT_MAGNIFICATION_SCALE);
}
+ private static boolean isScreenMagnificationAutoUpdateEnabled(Context context) {
+ return (Settings.Secure.getInt(context.getContentResolver(),
+ Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_AUTO_UPDATE,
+ DEFAULT_SCREEN_MAGNIFICATION_AUTO_UPDATE) == 1);
+ }
+
private static final class MotionEventInfo {
private static final int MAX_POOL_SIZE = 10;
@@ -844,6 +857,54 @@ public final class ScreenMagnifier implements EventStreamTransformation {
}
}
+ private static final class ScreenStateObserver extends BroadcastReceiver {
+
+ private static final int MESSAGE_ON_SCREEN_STATE_CHANGE = 1;
+
+ private final Handler mHandler = new Handler() {
+ @Override
+ public void handleMessage(Message message) {
+ switch (message.what) {
+ case MESSAGE_ON_SCREEN_STATE_CHANGE: {
+ String action = (String) message.obj;
+ handleOnScreenStateChange(action);
+ } break;
+ }
+ }
+ };
+
+ private final Context mContext;
+ private final Viewport mViewport;
+ private final MagnificationController mMagnificationController;
+
+ public ScreenStateObserver(Context context, Viewport viewport,
+ MagnificationController magnificationController) {
+ mContext = context;
+ mViewport = viewport;
+ mMagnificationController = magnificationController;
+ mContext.registerReceiver(this, new IntentFilter(Intent.ACTION_SCREEN_OFF));
+ }
+
+ public void destroy() {
+ mContext.unregisterReceiver(this);
+ }
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ mHandler.obtainMessage(MESSAGE_ON_SCREEN_STATE_CHANGE,
+ intent.getAction()).sendToTarget();
+ }
+
+ private void handleOnScreenStateChange(String action) {
+ if (action.equals(Intent.ACTION_SCREEN_OFF)
+ && mMagnificationController.isMagnifying()
+ && isScreenMagnificationAutoUpdateEnabled(mContext)) {
+ mMagnificationController.reset(false);
+ mViewport.setFrameShown(false, false);
+ }
+ }
+ }
+
private static final class DisplayContentObserver {
private static final int MESSAGE_SHOW_VIEWPORT_FRAME = 1;
@@ -972,7 +1033,7 @@ public final class ScreenMagnifier implements EventStreamTransformation {
switch (transition) {
case WindowManagerPolicy.TRANSIT_ENTER:
case WindowManagerPolicy.TRANSIT_SHOW: {
- if (!magnifying || !screenMagnificationAutoUpdateEnabled(mContext)) {
+ if (!magnifying || !isScreenMagnificationAutoUpdateEnabled(mContext)) {
break;
}
final int type = info.type;
@@ -1060,18 +1121,12 @@ public final class ScreenMagnifier implements EventStreamTransformation {
private void resetMagnificationIfNeeded() {
if (mMagnificationController.isMagnifying()
- && screenMagnificationAutoUpdateEnabled(mContext)) {
+ && isScreenMagnificationAutoUpdateEnabled(mContext)) {
mMagnificationController.reset(true);
mViewport.setFrameShown(false, true);
}
}
- private boolean screenMagnificationAutoUpdateEnabled(Context context) {
- return (Settings.Secure.getInt(context.getContentResolver(),
- Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_AUTO_UPDATE,
- DEFAULT_SCREEN_MAGNIFICATION_AUTO_UPDATE) == 1);
- }
-
private String windowTransitionToString(int transition) {
switch (transition) {
case WindowManagerPolicy.TRANSIT_UNSET: {