Skip to content

Commit abc820f

Browse files
author
Jeremy Williams
committedSep 27, 2011
workaround for keyboard closing on loadUrl
1 parent 66d416f commit abc820f

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed
 

‎src/com/strumsoft/phonegap/websocket/WebSocket.java

+27-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@
4444
import java.util.concurrent.BlockingQueue;
4545
import java.util.concurrent.LinkedBlockingQueue;
4646

47+
import android.app.Activity;
48+
import android.content.Context;
49+
import android.os.Handler;
4750
import android.util.Log;
51+
import android.view.inputmethod.InputMethodManager;
4852
import android.webkit.WebView;
4953

5054
/**
@@ -206,6 +210,10 @@ public enum Draft {
206210
* The readyState attribute represents the state of the connection.
207211
*/
208212
private int readyState = WEBSOCKET_STATE_CONNECTING;
213+
214+
private boolean keyboardIsShowing = false;
215+
216+
private Handler handler = null;
209217

210218
/**
211219
* Constructor.
@@ -222,10 +230,11 @@ public enum Draft {
222230
* @param id
223231
* unique id for this instance
224232
*/
225-
protected WebSocket(WebView appView, URI uri, Draft draft, String id) {
233+
protected WebSocket(Handler handler, WebView appView, URI uri, Draft draft, String id) {
226234
this.appView = appView;
227235
this.uri = uri;
228236
this.draft = draft;
237+
this.handler = handler;
229238

230239
// port
231240
port = uri.getPort();
@@ -288,6 +297,11 @@ public void run() {
288297
}
289298
}
290299

300+
301+
public void setKeyboardStatus(boolean status){
302+
keyboardIsShowing = status;
303+
Log.d("websocket", "keyboardIsShowing: "+keyboardIsShowing);
304+
}
291305
/**
292306
* Closes connection with server
293307
*/
@@ -339,6 +353,9 @@ public void onMessage(String msg) {
339353
appView.post(new Runnable() {
340354
public void run() {
341355
appView.loadUrl(buildJavaScriptData(EVENT_ON_MESSAGE, data));
356+
if(keyboardIsShowing){
357+
handler.sendEmptyMessage(3);
358+
}
342359
}
343360
});
344361
}
@@ -348,6 +365,9 @@ public void onOpen() {
348365
appView.post(new Runnable() {
349366
public void run() {
350367
appView.loadUrl(buildJavaScriptData(EVENT_ON_OPEN, BLANK_MESSAGE));
368+
if(keyboardIsShowing){
369+
handler.sendEmptyMessage(3);
370+
}
351371
}
352372
});
353373
}
@@ -356,6 +376,9 @@ public void onClose() {
356376
appView.post(new Runnable() {
357377
public void run() {
358378
appView.loadUrl(buildJavaScriptData(EVENT_ON_CLOSE, BLANK_MESSAGE));
379+
if(keyboardIsShowing){
380+
handler.sendEmptyMessage(3);
381+
}
359382
}
360383
});
361384
}
@@ -367,6 +390,9 @@ public void onError(Throwable t) {
367390
appView.post(new Runnable() {
368391
public void run() {
369392
appView.loadUrl(buildJavaScriptData(EVENT_ON_ERROR, msg));
393+
if(keyboardIsShowing){
394+
handler.sendEmptyMessage(3);
395+
}
370396
}
371397
});
372398
}

‎src/com/strumsoft/phonegap/websocket/WebSocketFactory.java

+15-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828

2929
import java.net.URI;
3030
import java.util.Random;
31+
import java.util.Vector;
3132

33+
import android.app.Activity;
34+
import android.os.Handler;
3235
import android.webkit.WebView;
3336

3437
/**
@@ -39,6 +42,10 @@
3942
* @author Animesh Kumar
4043
*/
4144
public class WebSocketFactory {
45+
46+
private Vector<WebSocket> socketList = new Vector<WebSocket>();
47+
48+
private Handler handler;
4249

4350
/** The app view. */
4451
WebView appView;
@@ -49,8 +56,13 @@ public class WebSocketFactory {
4956
* @param appView
5057
* the app view
5158
*/
52-
public WebSocketFactory(WebView appView) {
59+
public WebSocketFactory(Handler h, WebView appView) {
5360
this.appView = appView;
61+
this.handler = h;
62+
}
63+
64+
public Vector<WebSocket> getSocketList() {
65+
return socketList;
5466
}
5567

5668
public WebSocket getInstance(String url) {
@@ -62,7 +74,8 @@ public WebSocket getInstance(String url, WebSocket.Draft draft) {
6274
WebSocket socket = null;
6375
Thread th = null;
6476
try {
65-
socket = new WebSocket(appView, new URI(url), draft, getRandonUniqueId());
77+
socket = new WebSocket(handler, appView, new URI(url), draft, getRandonUniqueId());
78+
socketList.add(socket);
6679
th = socket.connect();
6780
return socket;
6881
} catch (Exception e) {

0 commit comments

Comments
 (0)
Failed to load comments.