1
1
package org .c_base .pymlgame .controller ;
2
2
3
+ import android .content .Context ;
3
4
import android .graphics .Rect ;
4
5
import android .os .Bundle ;
5
6
import android .support .v7 .app .ActionBarActivity ;
9
10
import android .view .ViewGroup ;
10
11
import android .widget .EditText ;
11
12
import android .widget .ImageView ;
13
+ import android .os .Vibrator ;
12
14
13
15
import java .io .IOException ;
14
16
import java .net .DatagramPacket ;
@@ -135,6 +137,8 @@ public void run() {
135
137
@ InjectView (R .id .buttonMenu )
136
138
ImageView buttonMenu ;
137
139
140
+ Vibrator vibrator ;
141
+
138
142
String buttonStates = "00000000000000" ;
139
143
String tempButtonStates = "00000000000000" ;
140
144
@@ -143,6 +147,8 @@ protected void onCreate(Bundle savedInstanceState) {
143
147
super .onCreate (savedInstanceState );
144
148
setContentView (R .layout .activity_main );
145
149
150
+ vibrator = (Vibrator ) getSystemService (Context .VIBRATOR_SERVICE );
151
+
146
152
ButterKnife .inject (this );
147
153
148
154
getWindow ().getDecorView ().findViewById (android .R .id .content ).setOnTouchListener (new View .OnTouchListener () {
@@ -179,9 +185,13 @@ private void checkView(View v, MotionEvent ev, int position, int index) {
179
185
if (contains ) {
180
186
if (ev .getAction () == MotionEvent .ACTION_UP ) {
181
187
tempButtonStates = tempButtonStates .substring (0 , position ) + "0" + tempButtonStates .substring (position + 1 );
182
- return ;
183
188
}
184
- tempButtonStates = tempButtonStates .substring (0 , position ) + "1" + tempButtonStates .substring (position + 1 );
189
+ else {
190
+ if (vibrator .hasVibrator () && buttonStates .charAt (position ) == '0' ) {
191
+ vibrator .vibrate (20 );
192
+ }
193
+ tempButtonStates = tempButtonStates .substring (0 , position ) + "1" + tempButtonStates .substring (position + 1 );
194
+ }
185
195
}
186
196
}
187
197
}
0 commit comments