summaryrefslogtreecommitdiffstats
path: root/core/java/com/android/internal/widget/PointerLocationView.java
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2012-04-12 17:32:48 -0700
committerJeff Brown <jeffbrown@google.com>2012-04-12 18:54:54 -0700
commitaf9e8d38184c6ba4d2d3eb5bde7014a66dd8a78b (patch)
tree50cf9dd27d673bc5b3f75e6e18e9577873eecd6c /core/java/com/android/internal/widget/PointerLocationView.java
parentcc1169831921d9295b2fc01c1eaf7e9b00836f53 (diff)
downloadframeworks_base-af9e8d38184c6ba4d2d3eb5bde7014a66dd8a78b.zip
frameworks_base-af9e8d38184c6ba4d2d3eb5bde7014a66dd8a78b.tar.gz
frameworks_base-af9e8d38184c6ba4d2d3eb5bde7014a66dd8a78b.tar.bz2
Notify applications when input devices change.
This change allows the InputManager to keep track of what input devices are registered with the system and when they change. It needs to do this so that it can properly clear its cache of input device properties (especially the key map!) when changes occur. Added new API so that applications can register listeners for input device changes. Fixed a minor bug in EventHub where it didn't handle EPOLLHUP properly so it would spam the log about unsupposed epoll events until inotify noticed that the device was gone and removed it. Change-Id: I937d8c601f7185d4299038bce6a2934fe4fdd2b3
Diffstat (limited to 'core/java/com/android/internal/widget/PointerLocationView.java')
-rw-r--r--core/java/com/android/internal/widget/PointerLocationView.java68
1 files changed, 54 insertions, 14 deletions
diff --git a/core/java/com/android/internal/widget/PointerLocationView.java b/core/java/com/android/internal/widget/PointerLocationView.java
index 0524c25..1d6af90 100644
--- a/core/java/com/android/internal/widget/PointerLocationView.java
+++ b/core/java/com/android/internal/widget/PointerLocationView.java
@@ -21,6 +21,8 @@ import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Paint.FontMetricsInt;
+import android.hardware.input.InputManager;
+import android.hardware.input.InputManager.InputDeviceListener;
import android.util.Log;
import android.view.InputDevice;
import android.view.KeyEvent;
@@ -32,7 +34,7 @@ import android.view.MotionEvent.PointerCoords;
import java.util.ArrayList;
-public class PointerLocationView extends View {
+public class PointerLocationView extends View implements InputDeviceListener {
private static final String TAG = "Pointer";
public static class PointerState {
@@ -82,6 +84,8 @@ public class PointerLocationView extends View {
private final int ESTIMATE_FUTURE_POINTS = 2;
private final float ESTIMATE_INTERVAL = 0.02f;
+ private final InputManager mIm;
+
private final ViewConfiguration mVC;
private final Paint mTextPaint;
private final Paint mTextBackgroundPaint;
@@ -108,6 +112,8 @@ public class PointerLocationView extends View {
super(c);
setFocusableInTouchMode(true);
+ mIm = (InputManager)c.getSystemService(Context.INPUT_SERVICE);
+
mVC = ViewConfiguration.get(c);
mTextPaint = new Paint();
mTextPaint.setAntiAlias(true);
@@ -139,18 +145,6 @@ public class PointerLocationView extends View {
mActivePointerId = 0;
mVelocity = VelocityTracker.obtain();
-
- logInputDeviceCapabilities();
- }
-
- private void logInputDeviceCapabilities() {
- int[] deviceIds = InputDevice.getDeviceIds();
- for (int i = 0; i < deviceIds.length; i++) {
- InputDevice device = InputDevice.getDevice(deviceIds[i]);
- if (device != null) {
- Log.i(TAG, device.toString());
- }
- }
}
public void setPrintCoords(boolean state) {
@@ -631,7 +625,53 @@ public class PointerLocationView extends View {
logMotionEvent("Trackball", event);
return true;
}
-
+
+ @Override
+ protected void onAttachedToWindow() {
+ super.onAttachedToWindow();
+
+ mIm.registerInputDeviceListener(this, getHandler());
+ logInputDevices();
+ }
+
+ @Override
+ protected void onDetachedFromWindow() {
+ super.onDetachedFromWindow();
+
+ mIm.unregisterInputDeviceListener(this);
+ }
+
+ @Override
+ public void onInputDeviceAdded(int deviceId) {
+ logInputDeviceState(deviceId, "Device Added");
+ }
+
+ @Override
+ public void onInputDeviceChanged(int deviceId) {
+ logInputDeviceState(deviceId, "Device Changed");
+ }
+
+ @Override
+ public void onInputDeviceRemoved(int deviceId) {
+ logInputDeviceState(deviceId, "Device Removed");
+ }
+
+ private void logInputDevices() {
+ int[] deviceIds = InputDevice.getDeviceIds();
+ for (int i = 0; i < deviceIds.length; i++) {
+ logInputDeviceState(deviceIds[i], "Device Enumerated");
+ }
+ }
+
+ private void logInputDeviceState(int deviceId, String state) {
+ InputDevice device = mIm.getInputDevice(deviceId);
+ if (device != null) {
+ Log.i(TAG, state + ": " + device);
+ } else {
+ Log.i(TAG, state + ": " + deviceId);
+ }
+ }
+
// HACK
// A quick and dirty string builder implementation optimized for GC.
// Using String.format causes the application grind to a halt when