@@ -31,14 +31,14 @@ public class Hardware {
31
31
/**
32
32
* Vibrate for s seconds.
33
33
*/
34
- static void vibrate (double s ) {
34
+ public static void vibrate (double s ) {
35
35
Vibrator v = (Vibrator ) context .getSystemService (Context .VIBRATOR_SERVICE );
36
36
if (v != null ) {
37
37
v .vibrate ((int ) (1000 * s ));
38
38
}
39
39
}
40
40
41
- static SensorEvent lastEvent = null ;
41
+ public static SensorEvent lastEvent = null ;
42
42
43
43
static class AccelListener implements SensorEventListener {
44
44
public void onSensorChanged (SensorEvent ev ) {
@@ -55,7 +55,7 @@ public void onAccuracyChanged(Sensor sensor , int accuracy) {
55
55
/**
56
56
* Enable or Disable the accelerometer.
57
57
*/
58
- static void accelerometerEnable (boolean enable ) {
58
+ public static void accelerometerEnable (boolean enable ) {
59
59
SensorManager sm = (SensorManager ) context .getSystemService (Context .SENSOR_SERVICE );
60
60
Sensor accel = sm .getDefaultSensor (Sensor .TYPE_ACCELEROMETER );
61
61
@@ -72,7 +72,7 @@ static void accelerometerEnable(boolean enable) {
72
72
}
73
73
74
74
75
- static float [] accelerometerReading () {
75
+ public static float [] accelerometerReading () {
76
76
if (lastEvent != null ) {
77
77
return lastEvent .values ;
78
78
} else {
@@ -81,27 +81,109 @@ static float[] accelerometerReading() {
81
81
}
82
82
}
83
83
84
+ static SensorEvent lastOrientationEvent = null ;
85
+
86
+ static class OrientationListener implements SensorEventListener {
87
+ public void onSensorChanged (SensorEvent ev ) {
88
+ lastOrientationEvent = ev ;
89
+ }
90
+
91
+ public void onAccuracyChanged (Sensor sensor , int accuracy ) {
92
+ }
93
+ }
94
+
95
+ static OrientationListener orientationListener = new OrientationListener ();
96
+
97
+ /**
98
+ * Enable or Disable the OrientationSensor.
99
+ */
100
+ public static void orientationSensorEnable (boolean enable ) {
101
+ SensorManager sm = (SensorManager ) context .getSystemService (Context .SENSOR_SERVICE );
102
+ Sensor orientationSensor = sm .getDefaultSensor (Sensor .TYPE_ORIENTATION );
103
+
104
+ if (orientationSensor == null ) {
105
+ return ;
106
+ }
107
+
108
+ if (enable ) {
109
+ sm .registerListener (orientationListener , orientationSensor , SensorManager .SENSOR_DELAY_NORMAL );
110
+ } else {
111
+ sm .unregisterListener (orientationListener , orientationSensor );
112
+ }
113
+ }
114
+
115
+ public static float [] orientationSensorReading () {
116
+ if (lastOrientationEvent != null ) {
117
+ return lastOrientationEvent .values ;
118
+ } else {
119
+ float rv [] = { 0f , 0f , 0f };
120
+ return rv ;
121
+ }
122
+ }
123
+
124
+ static SensorEvent lastMagneticFieldEvent = null ;
125
+
126
+ static class MagneticFieldListener implements SensorEventListener {
127
+ public void onSensorChanged (SensorEvent ev ) {
128
+ lastMagneticFieldEvent = ev ;
129
+ }
130
+
131
+ public void onAccuracyChanged (Sensor sensor , int accuracy ) {
132
+ }
133
+ }
134
+
135
+ static MagneticFieldListener magneticFieldListener = new MagneticFieldListener ();
136
+
137
+ /**
138
+ * Enable or Disable the MagneticFieldSensor.
139
+ */
140
+ public static void magneticFieldSensorEnable (boolean enable ) {
141
+ SensorManager sm = (SensorManager ) context .getSystemService (Context .SENSOR_SERVICE );
142
+ Sensor magneticFieldSensor = sm .getDefaultSensor (Sensor .TYPE_MAGNETIC_FIELD );
143
+
144
+ if (magneticFieldSensor == null ) {
145
+ return ;
146
+ }
147
+
148
+ if (enable ) {
149
+ sm .registerListener (magneticFieldListener , magneticFieldSensor , SensorManager .SENSOR_DELAY_NORMAL );
150
+ } else {
151
+ sm .unregisterListener (magneticFieldListener , magneticFieldSensor );
152
+ }
153
+ }
154
+
155
+
156
+ public static float [] magneticFieldSensorReading () {
157
+ if (lastMagneticFieldEvent != null ) {
158
+ return lastMagneticFieldEvent .values ;
159
+ } else {
160
+ float rv [] = { 0f , 0f , 0f };
161
+ return rv ;
162
+ }
163
+ }
164
+
165
+
84
166
static DisplayMetrics metrics = new DisplayMetrics ();
85
167
86
168
/**
87
169
* Get display DPI.
88
170
*/
89
- static int getDPI () {
171
+ public static int getDPI () {
90
172
return metrics .densityDpi ;
91
173
}
92
174
93
175
/**
94
176
* Show the soft keyboard.
95
177
*/
96
- static void showKeyboard () {
178
+ public static void showKeyboard () {
97
179
InputMethodManager imm = (InputMethodManager ) context .getSystemService (Context .INPUT_METHOD_SERVICE );
98
180
imm .showSoftInput (view , InputMethodManager .SHOW_FORCED );
99
181
}
100
182
101
183
/**
102
184
* Hide the soft keyboard.
103
185
*/
104
- static void hideKeyboard () {
186
+ public static void hideKeyboard () {
105
187
InputMethodManager imm = (InputMethodManager ) context .getSystemService (Context .INPUT_METHOD_SERVICE );
106
188
imm .hideSoftInputFromWindow (view .getWindowToken (), 0 );
107
189
}
@@ -111,7 +193,7 @@ static void hideKeyboard() {
111
193
*/
112
194
static List <ScanResult > latestResult ;
113
195
114
- static void enableWifiScanner ()
196
+ public static void enableWifiScanner ()
115
197
{
116
198
IntentFilter i = new IntentFilter ();
117
199
i .addAction (WifiManager .SCAN_RESULTS_AVAILABLE_ACTION );
@@ -129,7 +211,7 @@ public void onReceive(Context c, Intent i) {
129
211
130
212
}
131
213
132
- static String scanWifi () {
214
+ public static String scanWifi () {
133
215
134
216
// Now you can call this and it should execute the broadcastReceiver's
135
217
// onReceive()
0 commit comments