Commit 9bea3523bb7a52d628c8ccc818d4abd3e12fc468

Authored by perry.werneck@gmail.com
1 parent 2beb77e0

Android - Corrigindo desconexão ao rodar a tela

android/jni/main.cpp
@@ -80,14 +80,7 @@ static void changed(H3270 *session, int offset, int len) @@ -80,14 +80,7 @@ static void changed(H3270 *session, int offset, int len)
80 char *text = lib3270_get_as_html(session,(LIB3270_HTML_OPTION) (LIB3270_HTML_OPTION_ALL|LIB3270_HTML_OPTION_FORM)); 80 char *text = lib3270_get_as_html(session,(LIB3270_HTML_OPTION) (LIB3270_HTML_OPTION_ALL|LIB3270_HTML_OPTION_FORM));
81 81
82 if(text) 82 if(text)
83 - {  
84 - trace("Screen:\n%s\n",text);  
85 lib3270_free(text); 83 lib3270_free(text);
86 - }  
87 - else  
88 - {  
89 - trace("%s returns NULL","lib3270_get_as_html");  
90 - }  
91 } 84 }
92 85
93 pw3270_jni_post_message(2,offset,len); 86 pw3270_jni_post_message(2,offset,len);
android/src/br/com/bb/pw3270/PW3270Activity.java
@@ -53,13 +53,14 @@ import android.view.MenuItem; @@ -53,13 +53,14 @@ import android.view.MenuItem;
53 53
54 public class PW3270Activity extends Activity 54 public class PW3270Activity extends Activity
55 { 55 {
56 - private static final String TAG = "pw3270"; 56 + private static final String TAG = "pw3270";
  57 +
  58 + private static terminal host;
57 59
58 - private Resources res;  
59 - private WebView view;  
60 - private terminal host;  
61 - private Activity mainact = this;  
62 - private ProgressDialog dlgSysMessage; 60 + private Resources res ;
  61 + private WebView view;
  62 + private Activity mainact = this;
  63 + private ProgressDialog dlgSysMessage;
63 64
64 private class terminal extends lib3270 65 private class terminal extends lib3270
65 { 66 {
@@ -225,13 +226,6 @@ public class PW3270Activity extends Activity @@ -225,13 +226,6 @@ public class PW3270Activity extends Activity
225 226
226 } 227 }
227 228
228 - @Override  
229 - public void onConfigurationChanged(Configuration newConfig)  
230 - {  
231 - super.onConfigurationChanged(newConfig);  
232 - initUI();  
233 - }  
234 -  
235 @Override 229 @Override
236 public boolean onCreateOptionsMenu(Menu menu) 230 public boolean onCreateOptionsMenu(Menu menu)
237 { 231 {
@@ -267,4 +261,30 @@ public class PW3270Activity extends Activity @@ -267,4 +261,30 @@ public class PW3270Activity extends Activity
267 261
268 } 262 }
269 263
  264 + @Override
  265 + public void onConfigurationChanged(Configuration newConfig)
  266 + {
  267 + Log.d(TAG, "Configuration Changed");
  268 + super.onConfigurationChanged(newConfig);
  269 + initUI();
  270 + }
  271 +
  272 + @Override
  273 + protected void onSaveInstanceState(Bundle outState)
  274 + {
  275 + super.onSaveInstanceState(outState);
  276 + // Save the state of the WebView
  277 + view.saveState(outState);
  278 + }
  279 +
  280 + @Override
  281 + protected void onRestoreInstanceState(Bundle savedInstanceState)
  282 + {
  283 + super.onRestoreInstanceState(savedInstanceState);
  284 + // Restore the state of the WebView
  285 + view.restoreState(savedInstanceState);
  286 + }
  287 +
  288 +
  289 +
270 } 290 }
android/src/br/com/bb/pw3270/lib3270.java
@@ -45,17 +45,20 @@ import java.io.DataOutputStream; @@ -45,17 +45,20 @@ import java.io.DataOutputStream;
45 45
46 public class lib3270 46 public class lib3270
47 { 47 {
48 - private NetworkThread mainloop = null;  
49 private static final String TAG = "lib3270"; 48 private static final String TAG = "lib3270";
50 49
51 - protected int screenState = 0;  
52 - private boolean connected = false;  
53 - private boolean refresh = true;  
54 - private Socket sock = null;  
55 - private lib3270 hSession = this;  
56 50
57 - DataOutputStream outData = null;  
58 - DataInputStream inData = null; 51 + protected int screenState = -1;
  52 +
  53 + private lib3270 hSession = this;
  54 +
  55 + private static NetworkThread mainloop = null;
  56 + private static boolean connected = false;
  57 + private static boolean refresh = true;
  58 + private static Socket sock = null;
  59 +
  60 + private static DataOutputStream outData = null;
  61 + private static DataInputStream inData = null;
59 62
60 protected SharedPreferences settings; 63 protected SharedPreferences settings;
61 64
@@ -67,7 +70,7 @@ public class lib3270 @@ -67,7 +70,7 @@ public class lib3270
67 switch (msg.what) 70 switch (msg.what)
68 { 71 {
69 case 0: // Reconnect 72 case 0: // Reconnect
70 - connect(); 73 + Log.d(TAG,"----------------------------Reconnecting");
71 break; 74 break;
72 75
73 case 1: // OIA message has changed 76 case 1: // OIA message has changed
@@ -80,15 +83,8 @@ public class lib3270 @@ -80,15 +83,8 @@ public class lib3270
80 break; 83 break;
81 84
82 case 3: // Popup 85 case 3: // Popup
83 - if(msg.arg1 == 1 && settings.getBoolean("reconnect",false))  
84 - {  
85 - postMessage(0, 1, 0);  
86 - }  
87 - else  
88 - {  
89 - popupMessageInfo popup = (popupMessageInfo) msg.obj;  
90 - showPopupMessage(msg.arg1, popup.title, popup.text, popup.info);  
91 - } 86 + popupMessageInfo popup = (popupMessageInfo) msg.obj;
  87 + showPopupMessage(msg.arg1, popup.title, popup.text, popup.info);
92 break; 88 break;
93 89
94 case 4: // erase 90 case 4: // erase
@@ -127,12 +123,11 @@ public class lib3270 @@ -127,12 +123,11 @@ public class lib3270
127 123
128 lib3270(SharedPreferences settings) 124 lib3270(SharedPreferences settings)
129 { 125 {
130 - String toggle[] = { "dstrace", "screentrace", "eventtrace", "reconnect" };  
131 -  
132 - this.settings = settings;  
133 - this.screenState = 0;  
134 - this.mainloop = null;  
135 - 126 + String toggle[] = { "dstrace", "screentrace", "eventtrace", "reconnect" };
  127 +
  128 + this.settings = settings;
  129 + this.screenState = -1;
  130 +
136 for(int f = 0; f < toggle.length; f++) 131 for(int f = 0; f < toggle.length; f++)
137 setToggle(toggle[f],settings.getBoolean(toggle[f],false)); 132 setToggle(toggle[f],settings.getBoolean(toggle[f],false));
138 133
@@ -220,7 +215,7 @@ public class lib3270 @@ -220,7 +215,7 @@ public class lib3270
220 SocketFactory socketFactory; 215 SocketFactory socketFactory;
221 String hostname = settings.getString("hostname",""); 216 String hostname = settings.getString("hostname","");
222 Integer port = new Integer(settings.getString("port","23")); 217 Integer port = new Integer(settings.getString("port","23"));
223 - 218 +
224 if (hostname == "" || port == 0) 219 if (hostname == "" || port == 0)
225 return false; 220 return false;
226 221
@@ -259,8 +254,6 @@ public class lib3270 @@ -259,8 +254,6 @@ public class lib3270
259 254
260 postPopup(0, "Erro na conexão", "Não foi possível conectar", msg); 255 postPopup(0, "Erro na conexão", "Não foi possível conectar", msg);
261 256
262 - postMessage(0, 0, 0);  
263 -  
264 return false; 257 return false;
265 } 258 }
266 259
@@ -271,9 +264,10 @@ public class lib3270 @@ -271,9 +264,10 @@ public class lib3270
271 264
272 public void run() 265 public void run()
273 { 266 {
  267 + boolean reconnect = false;
274 268
275 info(TAG, "Network thread started"); 269 info(TAG, "Network thread started");
276 - connected = connect(); 270 + reconnect = connected = connect();
277 271
278 if (connected) 272 if (connected)
279 { 273 {
@@ -301,8 +295,7 @@ public class lib3270 @@ -301,8 +295,7 @@ public class lib3270
301 procRecvdata(in,sz); 295 procRecvdata(in,sz);
302 296
303 } 297 }
304 - // postPopup(0,"","Desconectado","");  
305 - 298 +
306 } 299 }
307 300
308 Log.v(TAG, "Exiting communication thread"); 301 Log.v(TAG, "Exiting communication thread");
@@ -321,7 +314,10 @@ public class lib3270 @@ -321,7 +314,10 @@ public class lib3270
321 314
322 mainloop = null; 315 mainloop = null;
323 info(TAG, "Network thread stopped"); 316 info(TAG, "Network thread stopped");
324 - 317 +
  318 + if(reconnect)
  319 + postMessage(0, 0, 0); // Pede por reconexão
  320 +
325 } 321 }
326 322
327 } 323 }
@@ -513,13 +509,13 @@ public class lib3270 @@ -513,13 +509,13 @@ public class lib3270
513 protected void newTimer(long id, int msec) 509 protected void newTimer(long id, int msec)
514 { 510 {
515 Message msg = mHandler.obtainMessage(); 511 Message msg = mHandler.obtainMessage();
516 - 512 +
517 msg.what = 9; // MSG_CREATETIMER 513 msg.what = 9; // MSG_CREATETIMER
518 msg.arg1 = msec; 514 msg.arg1 = msec;
519 msg.obj = new Long(id); 515 msg.obj = new Long(id);
520 - 516 +
521 mHandler.sendMessage(msg); 517 mHandler.sendMessage(msg);
522 - 518 +
523 } 519 }
524 520
525 private native void timerFinish(long id); 521 private native void timerFinish(long id);
src/include/lib3270.h
@@ -262,7 +262,11 @@ @@ -262,7 +262,11 @@
262 262
263 #include <lib3270/config.h> 263 #include <lib3270/config.h>
264 264
265 - #if defined(_WIN32) 265 + #if defined( ANDROID )
  266 +
  267 + #define LIB3270_EXPORT __attribute__((visibility("hidden"))) extern
  268 +
  269 + #elif defined(_WIN32)
266 270
267 #include <windows.h> 271 #include <windows.h>
268 #define LIB3270_EXPORT __declspec (dllexport) 272 #define LIB3270_EXPORT __declspec (dllexport)