• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

frameworks/base


Commit MetaInfo

修订版62b644ec4a2f4165b47d203a153c78f45fbb72f5 (tree)
时间2009-12-02 14:45:28
作者Bryan Hundven <bryanhundven@gmai...>
CommiterBryan Hundven

Log Message

Patch InputDevice.java to read calibration settings from pointercal. Patch
from git.koolu.org by Sean McNeals (applied in koolu freerunner by Brian
Code)

更改概述

差异

--- a/services/java/com/android/server/InputDevice.java
+++ b/services/java/com/android/server/InputDevice.java
@@ -22,10 +22,15 @@ import android.view.MotionEvent;
2222 import android.view.Surface;
2323 import android.view.WindowManagerPolicy;
2424
25+import java.io.FileInputStream;
26+import java.util.StringTokenizer;
27+
2528 public class InputDevice {
2629 /** Amount that trackball needs to move in order to generate a key event. */
2730 static final int TRACKBALL_MOVEMENT_THRESHOLD = 6;
2831
32+ static final String CALIBRATION_FILE = "/system/etc/pointercal";
33+
2934 final int id;
3035 final int classes;
3136 final String name;
@@ -33,6 +38,7 @@ public class InputDevice {
3338 final AbsoluteInfo absY;
3439 final AbsoluteInfo absPressure;
3540 final AbsoluteInfo absSize;
41+ final TransformInfo tInfo;
3642
3743 long mDownTime = 0;
3844 int mMetaKeysState = 0;
@@ -40,7 +46,7 @@ public class InputDevice {
4046 final MotionState mAbs = new MotionState(0, 0);
4147 final MotionState mRel = new MotionState(TRACKBALL_MOVEMENT_THRESHOLD,
4248 TRACKBALL_MOVEMENT_THRESHOLD);
43-
49+
4450 static class MotionState {
4551 int xPrecision;
4652 int yPrecision;
@@ -55,7 +61,7 @@ public class InputDevice {
5561 int y = 0;
5662 int pressure = 1;
5763 int size = 0;
58-
64+
5965 MotionState(int mx, int my) {
6066 xPrecision = mx;
6167 yPrecision = my;
@@ -69,7 +75,7 @@ public class InputDevice {
6975 if (!changed) {
7076 return null;
7177 }
72-
78+
7379 float scaledX = x;
7480 float scaledY = y;
7581 float temp;
@@ -86,11 +92,21 @@ public class InputDevice {
8692 h = tmp;
8793 }
8894 if (device.absX != null) {
89- scaledX = ((scaledX-device.absX.minValue)
95+ if (device.tInfo != null)
96+ scaledX = (device.tInfo.x1 * x +
97+ device.tInfo.y1 * y +
98+ device.tInfo.z1) / device.tInfo.s;
99+ else
100+ scaledX = ((scaledX-device.absX.minValue)
90101 / device.absX.range) * w;
91102 }
92103 if (device.absY != null) {
93- scaledY = ((scaledY-device.absY.minValue)
104+ if (device.tInfo != null)
105+ scaledY = (device.tInfo.x2 * x +
106+ device.tInfo.y2 * y +
107+ device.tInfo.z2) / device.tInfo.s;
108+ else
109+ scaledY = ((scaledY-device.absY.minValue)
94110 / device.absY.range) * h;
95111 }
96112 if (device.absPressure != null) {
@@ -198,7 +214,17 @@ public class InputDevice {
198214 int flat;
199215 int fuzz;
200216 };
201-
217+
218+ static class TransformInfo {
219+ float x1;
220+ float y1;
221+ float z1;
222+ float x2;
223+ float y2;
224+ float z2;
225+ float s;
226+ };
227+
202228 InputDevice(int _id, int _classes, String _name,
203229 AbsoluteInfo _absX, AbsoluteInfo _absY,
204230 AbsoluteInfo _absPressure, AbsoluteInfo _absSize) {
@@ -209,5 +235,34 @@ public class InputDevice {
209235 absY = _absY;
210236 absPressure = _absPressure;
211237 absSize = _absSize;
238+ TransformInfo t = null;
239+ try {
240+ FileInputStream is = new FileInputStream(CALIBRATION_FILE);
241+ byte[] mBuffer = new byte[64];
242+ int len = is.read(mBuffer);
243+ is.close();
244+ if (len > 0) {
245+ int i;
246+ for (i = 0 ; i < len ; i++) {
247+ if (mBuffer[i] == '\n' || mBuffer[i] == 0) {
248+ break;
249+ }
250+ }
251+ len = i;
252+ }
253+ StringTokenizer st = new StringTokenizer( new String(mBuffer, 0, 0, len) );
254+
255+ t = new TransformInfo ();
256+ t.x1 = Integer.parseInt( st.nextToken() );
257+ t.y1 = Integer.parseInt( st.nextToken() );
258+ t.z1 = Integer.parseInt( st.nextToken() );
259+ t.x2 = Integer.parseInt( st.nextToken() );
260+ t.y2 = Integer.parseInt( st.nextToken() );
261+ t.z2 = Integer.parseInt( st.nextToken() );
262+ t.s = Integer.parseInt( st.nextToken() );
263+ } catch (java.io.FileNotFoundException e) {
264+ } catch (java.io.IOException e) {
265+ }
266+ tInfo = t;
212267 }
213268 };
--- /dev/null
+++ b/services/java/com/android/server/InputDevice.java.orig
@@ -0,0 +1,213 @@
1+/*
2+ * Copyright (C) 2007 The Android Open Source Project
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+package com.android.server;
18+
19+import android.util.Log;
20+import android.view.Display;
21+import android.view.MotionEvent;
22+import android.view.Surface;
23+import android.view.WindowManagerPolicy;
24+
25+public class InputDevice {
26+ /** Amount that trackball needs to move in order to generate a key event. */
27+ static final int TRACKBALL_MOVEMENT_THRESHOLD = 6;
28+
29+ final int id;
30+ final int classes;
31+ final String name;
32+ final AbsoluteInfo absX;
33+ final AbsoluteInfo absY;
34+ final AbsoluteInfo absPressure;
35+ final AbsoluteInfo absSize;
36+
37+ long mDownTime = 0;
38+ int mMetaKeysState = 0;
39+
40+ final MotionState mAbs = new MotionState(0, 0);
41+ final MotionState mRel = new MotionState(TRACKBALL_MOVEMENT_THRESHOLD,
42+ TRACKBALL_MOVEMENT_THRESHOLD);
43+
44+ static class MotionState {
45+ int xPrecision;
46+ int yPrecision;
47+ float xMoveScale;
48+ float yMoveScale;
49+ MotionEvent currentMove = null;
50+ boolean changed = false;
51+ boolean down = false;
52+ boolean lastDown = false;
53+ long downTime = 0;
54+ int x = 0;
55+ int y = 0;
56+ int pressure = 1;
57+ int size = 0;
58+
59+ MotionState(int mx, int my) {
60+ xPrecision = mx;
61+ yPrecision = my;
62+ xMoveScale = mx != 0 ? (1.0f/mx) : 1.0f;
63+ yMoveScale = my != 0 ? (1.0f/my) : 1.0f;
64+ }
65+
66+ MotionEvent generateMotion(InputDevice device, long curTime,
67+ boolean isAbs, Display display, int orientation,
68+ int metaState) {
69+ if (!changed) {
70+ return null;
71+ }
72+
73+ float scaledX = x;
74+ float scaledY = y;
75+ float temp;
76+ float scaledPressure = 1.0f;
77+ float scaledSize = 0;
78+ int edgeFlags = 0;
79+ if (isAbs) {
80+ int w = display.getWidth()-1;
81+ int h = display.getHeight()-1;
82+ if (orientation == Surface.ROTATION_90
83+ || orientation == Surface.ROTATION_270) {
84+ int tmp = w;
85+ w = h;
86+ h = tmp;
87+ }
88+ if (device.absX != null) {
89+ scaledX = ((scaledX-device.absX.minValue)
90+ / device.absX.range) * w;
91+ }
92+ if (device.absY != null) {
93+ scaledY = ((scaledY-device.absY.minValue)
94+ / device.absY.range) * h;
95+ }
96+ if (device.absPressure != null) {
97+ scaledPressure =
98+ ((pressure-device.absPressure.minValue)
99+ / (float)device.absPressure.range);
100+ }
101+ if (device.absSize != null) {
102+ scaledSize =
103+ ((size-device.absSize.minValue)
104+ / (float)device.absSize.range);
105+ }
106+ switch (orientation) {
107+ case Surface.ROTATION_90:
108+ temp = scaledX;
109+ scaledX = scaledY;
110+ scaledY = w-temp;
111+ break;
112+ case Surface.ROTATION_180:
113+ scaledX = w-scaledX;
114+ scaledY = h-scaledY;
115+ break;
116+ case Surface.ROTATION_270:
117+ temp = scaledX;
118+ scaledX = h-scaledY;
119+ scaledY = temp;
120+ break;
121+ }
122+
123+ if (scaledX == 0) {
124+ edgeFlags += MotionEvent.EDGE_LEFT;
125+ } else if (scaledX == display.getWidth() - 1.0f) {
126+ edgeFlags += MotionEvent.EDGE_RIGHT;
127+ }
128+
129+ if (scaledY == 0) {
130+ edgeFlags += MotionEvent.EDGE_TOP;
131+ } else if (scaledY == display.getHeight() - 1.0f) {
132+ edgeFlags += MotionEvent.EDGE_BOTTOM;
133+ }
134+
135+ } else {
136+ scaledX *= xMoveScale;
137+ scaledY *= yMoveScale;
138+ switch (orientation) {
139+ case Surface.ROTATION_90:
140+ temp = scaledX;
141+ scaledX = scaledY;
142+ scaledY = -temp;
143+ break;
144+ case Surface.ROTATION_180:
145+ scaledX = -scaledX;
146+ scaledY = -scaledY;
147+ break;
148+ case Surface.ROTATION_270:
149+ temp = scaledX;
150+ scaledX = -scaledY;
151+ scaledY = temp;
152+ break;
153+ }
154+ }
155+
156+ changed = false;
157+ if (down != lastDown) {
158+ int action;
159+ lastDown = down;
160+ if (down) {
161+ action = MotionEvent.ACTION_DOWN;
162+ downTime = curTime;
163+ } else {
164+ action = MotionEvent.ACTION_UP;
165+ }
166+ currentMove = null;
167+ if (!isAbs) {
168+ x = y = 0;
169+ }
170+ return MotionEvent.obtain(downTime, curTime, action,
171+ scaledX, scaledY, scaledPressure, scaledSize, metaState,
172+ xPrecision, yPrecision, device.id, edgeFlags);
173+ } else {
174+ if (currentMove != null) {
175+ if (false) Log.i("InputDevice", "Adding batch x=" + scaledX
176+ + " y=" + scaledY + " to " + currentMove);
177+ currentMove.addBatch(curTime, scaledX, scaledY,
178+ scaledPressure, scaledSize, metaState);
179+ if (WindowManagerPolicy.WATCH_POINTER) {
180+ Log.i("KeyInputQueue", "Updating: " + currentMove);
181+ }
182+ return null;
183+ }
184+ MotionEvent me = MotionEvent.obtain(downTime, curTime,
185+ MotionEvent.ACTION_MOVE, scaledX, scaledY,
186+ scaledPressure, scaledSize, metaState,
187+ xPrecision, yPrecision, device.id, edgeFlags);
188+ currentMove = me;
189+ return me;
190+ }
191+ }
192+ }
193+
194+ static class AbsoluteInfo {
195+ int minValue;
196+ int maxValue;
197+ int range;
198+ int flat;
199+ int fuzz;
200+ };
201+
202+ InputDevice(int _id, int _classes, String _name,
203+ AbsoluteInfo _absX, AbsoluteInfo _absY,
204+ AbsoluteInfo _absPressure, AbsoluteInfo _absSize) {
205+ id = _id;
206+ classes = _classes;
207+ name = _name;
208+ absX = _absX;
209+ absY = _absY;
210+ absPressure = _absPressure;
211+ absSize = _absSize;
212+ }
213+};