From 9bea3523bb7a52d628c8ccc818d4abd3e12fc468 Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Fri, 17 Aug 2012 19:31:29 +0000 Subject: [PATCH] Android - Corrigindo desconexão ao rodar a tela --- android/jni/main.cpp | 7 ------- android/src/br/com/bb/pw3270/PW3270Activity.java | 46 +++++++++++++++++++++++++++++++++------------- android/src/br/com/bb/pw3270/lib3270.java | 64 ++++++++++++++++++++++++++++++---------------------------------- src/include/lib3270.h | 6 +++++- 4 files changed, 68 insertions(+), 55 deletions(-) diff --git a/android/jni/main.cpp b/android/jni/main.cpp index d457ce7..bf735e9 100644 --- a/android/jni/main.cpp +++ b/android/jni/main.cpp @@ -80,14 +80,7 @@ static void changed(H3270 *session, int offset, int len) char *text = lib3270_get_as_html(session,(LIB3270_HTML_OPTION) (LIB3270_HTML_OPTION_ALL|LIB3270_HTML_OPTION_FORM)); if(text) - { - trace("Screen:\n%s\n",text); lib3270_free(text); - } - else - { - trace("%s returns NULL","lib3270_get_as_html"); - } } pw3270_jni_post_message(2,offset,len); diff --git a/android/src/br/com/bb/pw3270/PW3270Activity.java b/android/src/br/com/bb/pw3270/PW3270Activity.java index b4729ea..fe52b57 100644 --- a/android/src/br/com/bb/pw3270/PW3270Activity.java +++ b/android/src/br/com/bb/pw3270/PW3270Activity.java @@ -53,13 +53,14 @@ import android.view.MenuItem; public class PW3270Activity extends Activity { - private static final String TAG = "pw3270"; + private static final String TAG = "pw3270"; + + private static terminal host; - private Resources res; - private WebView view; - private terminal host; - private Activity mainact = this; - private ProgressDialog dlgSysMessage; + private Resources res ; + private WebView view; + private Activity mainact = this; + private ProgressDialog dlgSysMessage; private class terminal extends lib3270 { @@ -225,13 +226,6 @@ public class PW3270Activity extends Activity } - @Override - public void onConfigurationChanged(Configuration newConfig) - { - super.onConfigurationChanged(newConfig); - initUI(); - } - @Override public boolean onCreateOptionsMenu(Menu menu) { @@ -267,4 +261,30 @@ public class PW3270Activity extends Activity } + @Override + public void onConfigurationChanged(Configuration newConfig) + { + Log.d(TAG, "Configuration Changed"); + super.onConfigurationChanged(newConfig); + initUI(); + } + + @Override + protected void onSaveInstanceState(Bundle outState) + { + super.onSaveInstanceState(outState); + // Save the state of the WebView + view.saveState(outState); + } + + @Override + protected void onRestoreInstanceState(Bundle savedInstanceState) + { + super.onRestoreInstanceState(savedInstanceState); + // Restore the state of the WebView + view.restoreState(savedInstanceState); + } + + + } diff --git a/android/src/br/com/bb/pw3270/lib3270.java b/android/src/br/com/bb/pw3270/lib3270.java index a9bd9a9..0f67c05 100644 --- a/android/src/br/com/bb/pw3270/lib3270.java +++ b/android/src/br/com/bb/pw3270/lib3270.java @@ -45,17 +45,20 @@ import java.io.DataOutputStream; public class lib3270 { - private NetworkThread mainloop = null; private static final String TAG = "lib3270"; - protected int screenState = 0; - private boolean connected = false; - private boolean refresh = true; - private Socket sock = null; - private lib3270 hSession = this; - DataOutputStream outData = null; - DataInputStream inData = null; + protected int screenState = -1; + + private lib3270 hSession = this; + + private static NetworkThread mainloop = null; + private static boolean connected = false; + private static boolean refresh = true; + private static Socket sock = null; + + private static DataOutputStream outData = null; + private static DataInputStream inData = null; protected SharedPreferences settings; @@ -67,7 +70,7 @@ public class lib3270 switch (msg.what) { case 0: // Reconnect - connect(); + Log.d(TAG,"----------------------------Reconnecting"); break; case 1: // OIA message has changed @@ -80,15 +83,8 @@ public class lib3270 break; case 3: // Popup - if(msg.arg1 == 1 && settings.getBoolean("reconnect",false)) - { - postMessage(0, 1, 0); - } - else - { - popupMessageInfo popup = (popupMessageInfo) msg.obj; - showPopupMessage(msg.arg1, popup.title, popup.text, popup.info); - } + popupMessageInfo popup = (popupMessageInfo) msg.obj; + showPopupMessage(msg.arg1, popup.title, popup.text, popup.info); break; case 4: // erase @@ -127,12 +123,11 @@ public class lib3270 lib3270(SharedPreferences settings) { - String toggle[] = { "dstrace", "screentrace", "eventtrace", "reconnect" }; - - this.settings = settings; - this.screenState = 0; - this.mainloop = null; - + String toggle[] = { "dstrace", "screentrace", "eventtrace", "reconnect" }; + + this.settings = settings; + this.screenState = -1; + for(int f = 0; f < toggle.length; f++) setToggle(toggle[f],settings.getBoolean(toggle[f],false)); @@ -220,7 +215,7 @@ public class lib3270 SocketFactory socketFactory; String hostname = settings.getString("hostname",""); Integer port = new Integer(settings.getString("port","23")); - + if (hostname == "" || port == 0) return false; @@ -259,8 +254,6 @@ public class lib3270 postPopup(0, "Erro na conexão", "Não foi possível conectar", msg); - postMessage(0, 0, 0); - return false; } @@ -271,9 +264,10 @@ public class lib3270 public void run() { + boolean reconnect = false; info(TAG, "Network thread started"); - connected = connect(); + reconnect = connected = connect(); if (connected) { @@ -301,8 +295,7 @@ public class lib3270 procRecvdata(in,sz); } - // postPopup(0,"","Desconectado",""); - + } Log.v(TAG, "Exiting communication thread"); @@ -321,7 +314,10 @@ public class lib3270 mainloop = null; info(TAG, "Network thread stopped"); - + + if(reconnect) + postMessage(0, 0, 0); // Pede por reconexão + } } @@ -513,13 +509,13 @@ public class lib3270 protected void newTimer(long id, int msec) { Message msg = mHandler.obtainMessage(); - + msg.what = 9; // MSG_CREATETIMER msg.arg1 = msec; msg.obj = new Long(id); - + mHandler.sendMessage(msg); - + } private native void timerFinish(long id); diff --git a/src/include/lib3270.h b/src/include/lib3270.h index c04d958..75f4482 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -262,7 +262,11 @@ #include - #if defined(_WIN32) + #if defined( ANDROID ) + + #define LIB3270_EXPORT __attribute__((visibility("hidden"))) extern + + #elif defined(_WIN32) #include #define LIB3270_EXPORT __declspec (dllexport) -- libgit2 0.21.2