44
44
import java .util .concurrent .BlockingQueue ;
45
45
import java .util .concurrent .LinkedBlockingQueue ;
46
46
47
+ import android .app .Activity ;
48
+ import android .content .Context ;
49
+ import android .os .Handler ;
47
50
import android .util .Log ;
51
+ import android .view .inputmethod .InputMethodManager ;
48
52
import android .webkit .WebView ;
49
53
50
54
/**
@@ -206,6 +210,10 @@ public enum Draft {
206
210
* The readyState attribute represents the state of the connection.
207
211
*/
208
212
private int readyState = WEBSOCKET_STATE_CONNECTING ;
213
+
214
+ private boolean keyboardIsShowing = false ;
215
+
216
+ private Handler handler = null ;
209
217
210
218
/**
211
219
* Constructor.
@@ -222,10 +230,11 @@ public enum Draft {
222
230
* @param id
223
231
* unique id for this instance
224
232
*/
225
- protected WebSocket (WebView appView , URI uri , Draft draft , String id ) {
233
+ protected WebSocket (Handler handler , WebView appView , URI uri , Draft draft , String id ) {
226
234
this .appView = appView ;
227
235
this .uri = uri ;
228
236
this .draft = draft ;
237
+ this .handler = handler ;
229
238
230
239
// port
231
240
port = uri .getPort ();
@@ -288,6 +297,11 @@ public void run() {
288
297
}
289
298
}
290
299
300
+
301
+ public void setKeyboardStatus (boolean status ){
302
+ keyboardIsShowing = status ;
303
+ Log .d ("websocket" , "keyboardIsShowing: " +keyboardIsShowing );
304
+ }
291
305
/**
292
306
* Closes connection with server
293
307
*/
@@ -339,6 +353,9 @@ public void onMessage(String msg) {
339
353
appView .post (new Runnable () {
340
354
public void run () {
341
355
appView .loadUrl (buildJavaScriptData (EVENT_ON_MESSAGE , data ));
356
+ if (keyboardIsShowing ){
357
+ handler .sendEmptyMessage (3 );
358
+ }
342
359
}
343
360
});
344
361
}
@@ -348,6 +365,9 @@ public void onOpen() {
348
365
appView .post (new Runnable () {
349
366
public void run () {
350
367
appView .loadUrl (buildJavaScriptData (EVENT_ON_OPEN , BLANK_MESSAGE ));
368
+ if (keyboardIsShowing ){
369
+ handler .sendEmptyMessage (3 );
370
+ }
351
371
}
352
372
});
353
373
}
@@ -356,6 +376,9 @@ public void onClose() {
356
376
appView .post (new Runnable () {
357
377
public void run () {
358
378
appView .loadUrl (buildJavaScriptData (EVENT_ON_CLOSE , BLANK_MESSAGE ));
379
+ if (keyboardIsShowing ){
380
+ handler .sendEmptyMessage (3 );
381
+ }
359
382
}
360
383
});
361
384
}
@@ -367,6 +390,9 @@ public void onError(Throwable t) {
367
390
appView .post (new Runnable () {
368
391
public void run () {
369
392
appView .loadUrl (buildJavaScriptData (EVENT_ON_ERROR , msg ));
393
+ if (keyboardIsShowing ){
394
+ handler .sendEmptyMessage (3 );
395
+ }
370
396
}
371
397
});
372
398
}
0 commit comments