Commit 2e8949610fa000998f9a83968a25b99705d8e5af

Authored by perry.werneck@gmail.com
1 parent 60a98c98

Android - Corrigindo problemas com o diálogo de popup (segfaults & cia)

android/jni/globals.h
... ... @@ -47,7 +47,6 @@
47 47  
48 48 #define pw3270_jni_call_void(name, sig, ...) pw3270_jni_active->env->CallVoidMethod(pw3270_jni_active->obj,lib3270_getmethodID(name,sig), __VA_ARGS__)
49 49 #define pw3270_jni_call_int(name, sig, ...) pw3270_jni_active->env->CallIntMethod(pw3270_jni_active->obj,lib3270_getmethodID(name,sig), __VA_ARGS__)
50   - #define pw3270_jni_new_string(str) pw3270_jni_active->env->NewStringUTF(str)
51 50 #define pw3270_jni_new_byte_array(len) pw3270_jni_active->env->NewByteArray(len)
52 51  
53 52 typedef struct _pw3270_jni
... ... @@ -62,9 +61,9 @@
62 61  
63 62 extern PW3270_JNI *pw3270_jni_active;
64 63  
65   - int pw3270_jni_lock(JNIEnv *env, jobject obj);
66   - void pw3270_jni_unlock();
67   - void pw3270_jni_post_message(int msgid, int arg1 = 0, int arg2 = 0);
68   -
69   - jmethodID lib3270_getmethodID(const char *name, const char *sig);
  64 + int pw3270_jni_lock(JNIEnv *env, jobject obj);
  65 + void pw3270_jni_unlock();
  66 + void pw3270_jni_post_message(int msgid, int arg1 = 0, int arg2 = 0);
  67 + jstring pw3270_jni_new_string(const char *str);
  68 + jmethodID lib3270_getmethodID(const char *name, const char *sig);
70 69  
... ...
android/jni/main.cpp
... ... @@ -105,12 +105,6 @@ static int popuphandler(H3270 *session, void *terminal, LIB3270_NOTIFY type, con
105 105 static const char *sig = "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V";
106 106 char * descr = lib3270_vsprintf(fmt, args);
107 107  
108   - trace("%s: title=\"%s\"",__FUNCTION__,title);
109   - trace("%s: msg=\"%s\"",__FUNCTION__,msg);
110   - trace("%s: descr=\"%s\"",__FUNCTION__,descr);
111   -
112   -
113   -
114 108 if(msg)
115 109 {
116 110 pw3270_jni_call_void( "postPopup",
... ... @@ -431,3 +425,7 @@ void pw3270_jni_unlock(void)
431 425 lib3270_free(datablock);
432 426 }
433 427  
  428 +jstring pw3270_jni_new_string(const char *str)
  429 +{
  430 + return pw3270_jni_active->env->NewStringUTF(str ? str : "");
  431 +}
... ...
android/src/br/com/bb/pw3270/PW3270Activity.java
... ... @@ -30,7 +30,7 @@ public class PW3270Activity extends Activity
30 30 private Resources res;
31 31 private WebView view;
32 32 private terminal host;
33   -// private Activity mainact;
  33 + private Activity mainact = this;
34 34 private ProgressDialog dlgProgress;
35 35  
36 36 private class terminal extends lib3270
... ... @@ -84,21 +84,24 @@ public class PW3270Activity extends Activity
84 84 return true;
85 85 }
86 86  
87   - protected void popupMessage(int type, String title, String text, String info)
  87 + protected void showPopupMessage(int type, String title, String text, String info)
88 88 {
  89 + Log.v(TAG,"Popup Message:");
89 90 Log.v(TAG,title);
90 91 Log.v(TAG,text);
91 92 Log.v(TAG,info);
92   - /*
  93 +
93 94 AlertDialog d = new AlertDialog.Builder(mainact).create();
94 95  
95   - d.setTitle(title);
96   - d.setMessage(text);
  96 + if(title != "")
  97 + d.setTitle(title);
  98 +
  99 + if(text != "")
  100 + d.setMessage(text);
97 101  
98 102 d.setCancelable(true);
99 103 hideProgressDialog();
100 104 d.show();
101   - */
102 105 }
103 106  
104 107 @SuppressWarnings("unused")
... ... @@ -174,7 +177,6 @@ public class PW3270Activity extends Activity
174 177 id = R.raw.theme;
175 178 }
176 179  
177   -
178 180 // http://developer.android.com/reference/android/webkit/WebResourceResponse.html
179 181 return new WebResourceResponse(mime,"utf-8",getResources().openRawResource(id));
180 182 }
... ... @@ -184,7 +186,7 @@ public class PW3270Activity extends Activity
184 186 setContentView(view);
185 187 view.loadUrl("file:index.html");
186 188  
187   - // host.connect();
  189 + host.connect();
188 190  
189 191 }
190 192  
... ...
android/src/br/com/bb/pw3270/lib3270.java
... ... @@ -82,7 +82,7 @@ public class lib3270
82 82  
83 83 case 3: // Popup
84 84 popupMessageInfo popup = (popupMessageInfo) msg.obj;
85   - popupMessage(msg.arg1, popup.title, popup.text, popup.info);
  85 + showPopupMessage(msg.arg1, popup.title, popup.text, popup.info);
86 86 break;
87 87  
88 88 case 4: // erase
... ... @@ -347,16 +347,9 @@ public class lib3270
347 347  
348 348 mainloop = null;
349 349 info(TAG, "Network thread stopped");
350   - }
351   -
352   - public void postPopup(int type, String title, String text, String info)
353   - {
354   - Message msg = mHandler.obtainMessage();
355   -
356   - msg.what = 3;
357   - msg.arg1 = type;
358   - msg.obj = new popupMessageInfo(title, text, info);
359   - mHandler.sendMessage(msg);
  350 +
  351 + postPopup(0,"","Desconectado","");
  352 +
360 353 }
361 354  
362 355 }
... ... @@ -372,11 +365,11 @@ public class lib3270
372 365  
373 366 public void postPopup(int type, String title, String text, String info)
374 367 {
375   - Log.d(TAG, "Type:" + type);
376   - Log.d(TAG, "Title:" + title);
377   - Log.d(TAG, "Text:" + text);
378   - Log.d(TAG, "Info:" + info);
379   - mainloop.postPopup(type, title, text, info);
  368 + Message msg = mHandler.obtainMessage();
  369 + msg.what = 3;
  370 + msg.arg1 = type;
  371 + msg.obj = new popupMessageInfo(title, text, info);
  372 + mHandler.sendMessage(msg);
380 373 }
381 374  
382 375 /*---[ Signal methods ]--------------------------------------------------*/
... ... @@ -425,7 +418,7 @@ public class lib3270
425 418 return true;
426 419 }
427 420  
428   - protected void popupMessage(int type, String title, String text, String info)
  421 + protected void showPopupMessage(int type, String title, String text, String info)
429 422 {
430 423 }
431 424  
... ...