Commit 0d7ac68c4135111cd21a3f5dc0e411b18f88e155

Authored by perry.werneck@gmail.com
1 parent 66439b4d

Android - Work in progress

android/AndroidManifest.xml
@@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
5 android:versionName="1.0" > 5 android:versionName="1.0" >
6 6
7 <uses-sdk android:minSdkVersion="15" /> 7 <uses-sdk android:minSdkVersion="15" />
  8 + <uses-permission android:name="android.permission.INTERNET"></uses-permission>
8 9
9 <application 10 <application
10 android:icon="@drawable/ic_launcher" 11 android:icon="@drawable/ic_launcher"
android/Makefile
@@ -41,22 +41,22 @@ clean: @@ -41,22 +41,22 @@ clean:
41 @rm -f $(foreach DIR, $(RESOLUTION), res/drawable-$(DIR)/ic_launcher.png) 41 @rm -f $(foreach DIR, $(RESOLUTION), res/drawable-$(DIR)/ic_launcher.png)
42 42
43 res/drawable-xhdpi/ic_launcher.png: ../src/pw3270/pixmaps/pw3270.svg 43 res/drawable-xhdpi/ic_launcher.png: ../src/pw3270/pixmaps/pw3270.svg
44 - @echo " GEN `basename $@`" 44 + @echo " ICON xhdpi"
45 @$(MKDIR) `dirname $@` 45 @$(MKDIR) `dirname $@`
46 @$(CONVERT) --format=png --width=96 --height=96 --output=$@ $< 46 @$(CONVERT) --format=png --width=96 --height=96 --output=$@ $<
47 47
48 res/drawable-mdpi/ic_launcher.png: ../src/pw3270/pixmaps/pw3270.svg 48 res/drawable-mdpi/ic_launcher.png: ../src/pw3270/pixmaps/pw3270.svg
49 - @echo " GEN `basename $@`" 49 + @echo " ICON mdpi"
50 @$(MKDIR) `dirname $@` 50 @$(MKDIR) `dirname $@`
51 @$(CONVERT) --format=png --width=48 --height=48 --output=$@ $< 51 @$(CONVERT) --format=png --width=48 --height=48 --output=$@ $<
52 52
53 res/drawable-ldpi/ic_launcher.png: ../src/pw3270/pixmaps/pw3270.svg 53 res/drawable-ldpi/ic_launcher.png: ../src/pw3270/pixmaps/pw3270.svg
54 - @echo " GEN `basename $@`" 54 + @echo " ICON ldpi"
55 @$(MKDIR) `dirname $@` 55 @$(MKDIR) `dirname $@`
56 @$(CONVERT) --format=png --width=36 --height=36 --output=$@ $< 56 @$(CONVERT) --format=png --width=36 --height=36 --output=$@ $<
57 57
58 res/drawable-hdpi/ic_launcher.png: ../src/pw3270/pixmaps/pw3270.svg 58 res/drawable-hdpi/ic_launcher.png: ../src/pw3270/pixmaps/pw3270.svg
59 - @echo " GEN `basename $@`" 59 + @echo " ICON hdpi"
60 @$(MKDIR) `dirname $@` 60 @$(MKDIR) `dirname $@`
61 @$(CONVERT) --format=png --width=72 --height=72 --output=$@ $< 61 @$(CONVERT) --format=png --width=72 --height=72 --output=$@ $<
62 62
android/jni/Android.mk
@@ -34,7 +34,7 @@ LOCAL_DEFAULT_CPP_EXTENSION := cpp @@ -34,7 +34,7 @@ LOCAL_DEFAULT_CPP_EXTENSION := cpp
34 LOCAL_MODULE := lib3270 34 LOCAL_MODULE := lib3270
35 LOCAL_LDLIBS := -llog 35 LOCAL_LDLIBS := -llog
36 LOCAL_SRC_FILES := $(foreach SRC, $(TERMINAL_SOURCES) $(NETWORK_SOURCES), ../../src/lib3270/$(SRC)) \ 36 LOCAL_SRC_FILES := $(foreach SRC, $(TERMINAL_SOURCES) $(NETWORK_SOURCES), ../../src/lib3270/$(SRC)) \
37 - main.cpp misc.cpp 37 + main.cpp misc.cpp html.cpp
38 38
39 include $(BUILD_SHARED_LIBRARY) 39 include $(BUILD_SHARED_LIBRARY)
40 40
android/jni/globals.h
@@ -29,4 +29,27 @@ @@ -29,4 +29,27 @@
29 #include "lib3270jni.h" 29 #include "lib3270jni.h"
30 30
31 #include <lib3270.h> 31 #include <lib3270.h>
  32 + #include <lib3270/session.h>
  33 + #include <lib3270/log.h>
  34 +
  35 +/*--[ Defines ]--------------------------------------------------------------------------------------*/
  36 +
  37 + typedef struct _info
  38 + {
  39 + JNIEnv * env;
  40 + jobject obj;
  41 +
  42 + } INFO;
  43 +
  44 + #define session_request(env, obj) INFO jni_data = { env, obj }; \
  45 + H3270 * session = lib3270_get_default_session_handle(); \
  46 + session->widget = &jni_data;
  47 +
  48 + #define session_release() session->widget = 0;
  49 +
  50 +/*--[ Globals ]--------------------------------------------------------------------------------------*/
  51 +
  52 + extern const char *java_class_name;
  53 +
  54 +
32 55
android/jni/html.cpp 0 → 100644
@@ -0,0 +1,55 @@ @@ -0,0 +1,55 @@
  1 +/*
  2 + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
  3 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
  4 + * aplicativos mainframe. Registro no INPI sob o nome G3270. Registro no INPI sob o nome G3270.
  5 + *
  6 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  7 + *
  8 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  9 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  10 + * Free Software Foundation.
  11 + *
  12 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  13 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  14 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  15 + * obter mais detalhes.
  16 + *
  17 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  18 + * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple
  19 + * Place, Suite 330, Boston, MA, 02111-1307, USA
  20 + *
  21 + * Este programa está nomeado como main.cpp e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + *
  27 + */
  28 +
  29 + #include "globals.h"
  30 + #include <string.h>
  31 +
  32 +/*--[ Implement ]------------------------------------------------------------------------------------*/
  33 +
  34 +
  35 +JNIEXPORT jstring JNICALL Java_br_com_bb_pw3270_lib3270_getHTML(JNIEnv *env, jobject obj)
  36 +{
  37 + jstring ret;
  38 +
  39 + session_request(env,obj);
  40 +
  41 + if(session)
  42 + {
  43 + char *text = getHTML(session);
  44 + ret = env->NewStringUTF(text);
  45 + lib3270_free(text);
  46 + }
  47 + else
  48 + {
  49 + ret = env->NewStringUTF("<b>Invalid Session ID</b>");
  50 + }
  51 +
  52 + session_release();
  53 +
  54 + return ret;
  55 +}
android/jni/main.cpp
@@ -27,24 +27,7 @@ @@ -27,24 +27,7 @@
27 */ 27 */
28 28
29 #include "globals.h" 29 #include "globals.h"
30 - #include <lib3270/session.h>  
31 #include <lib3270/popup.h> 30 #include <lib3270/popup.h>
32 - #include <lib3270/log.h>  
33 -  
34 -/*--[ Defines ]--------------------------------------------------------------------------------------*/  
35 -  
36 - typedef struct _info  
37 - {  
38 - JNIEnv * env;  
39 - jobject obj;  
40 -  
41 - } INFO;  
42 -  
43 - #define session_request(env, obj) INFO jni_data = { env, obj }; \  
44 - H3270 * session = lib3270_get_default_session_handle(); \  
45 - session->widget = &jni_data;  
46 -  
47 - #define session_release() session->widget = 0;  
48 31
49 /*--[ Globals ]--------------------------------------------------------------------------------------*/ 32 /*--[ Globals ]--------------------------------------------------------------------------------------*/
50 33
@@ -74,6 +57,11 @@ static void changed(H3270 *session, int offset, int len) @@ -74,6 +57,11 @@ static void changed(H3270 *session, int offset, int len)
74 post_message(session,2,offset,len); 57 post_message(session,2,offset,len);
75 } 58 }
76 59
  60 +static void erase(H3270 *session)
  61 +{
  62 + post_message(session,4);
  63 +}
  64 +
77 static int popuphandler(H3270 *session, void *terminal, LIB3270_NOTIFY type, const char *title, const char *msg, const char *fmt, va_list args) 65 static int popuphandler(H3270 *session, void *terminal, LIB3270_NOTIFY type, const char *title, const char *msg, const char *fmt, va_list args)
78 { 66 {
79 if(session->widget) 67 if(session->widget)
@@ -98,6 +86,11 @@ static int popuphandler(H3270 *session, void *terminal, LIB3270_NOTIFY type, con @@ -98,6 +86,11 @@ static int popuphandler(H3270 *session, void *terminal, LIB3270_NOTIFY type, con
98 } 86 }
99 } 87 }
100 88
  89 +static void ctlr_done(H3270 *session)
  90 +{
  91 + post_message(session,4);
  92 +}
  93 +
101 JNIEXPORT jint JNICALL Java_br_com_bb_pw3270_lib3270_init(JNIEnv *env, jclass obj) 94 JNIEXPORT jint JNICALL Java_br_com_bb_pw3270_lib3270_init(JNIEnv *env, jclass obj)
102 { 95 {
103 H3270 * session = lib3270_session_new(""); 96 H3270 * session = lib3270_session_new("");
@@ -108,6 +101,8 @@ JNIEXPORT jint JNICALL Java_br_com_bb_pw3270_lib3270_init(JNIEnv *env, jclass ob @@ -108,6 +101,8 @@ JNIEXPORT jint JNICALL Java_br_com_bb_pw3270_lib3270_init(JNIEnv *env, jclass ob
108 101
109 session->changed = changed; 102 session->changed = changed;
110 session->update_status = update_status; 103 session->update_status = update_status;
  104 + session->erase = erase;
  105 + session->ctlr_done = ctlr_done;
111 106
112 return 0; 107 return 0;
113 } 108 }
@@ -153,3 +148,4 @@ JNIEXPORT jint JNICALL Java_br_com_bb_pw3270_lib3270_do_1connect(JNIEnv *env, jo @@ -153,3 +148,4 @@ JNIEXPORT jint JNICALL Java_br_com_bb_pw3270_lib3270_do_1connect(JNIEnv *env, jo
153 session_release(); 148 session_release();
154 return (jint) rc; 149 return (jint) rc;
155 } 150 }
  151 +
android/lib3270NDK.cbp
@@ -35,6 +35,7 @@ @@ -35,6 +35,7 @@
35 <Unit filename="Makefile" /> 35 <Unit filename="Makefile" />
36 <Unit filename="jni/Android.mk" /> 36 <Unit filename="jni/Android.mk" />
37 <Unit filename="jni/globals.h" /> 37 <Unit filename="jni/globals.h" />
  38 + <Unit filename="jni/html.cpp" />
38 <Unit filename="jni/main.cpp" /> 39 <Unit filename="jni/main.cpp" />
39 <Unit filename="jni/misc.cpp" /> 40 <Unit filename="jni/misc.cpp" />
40 <Unit filename="src/br/com/bb/pw3270/lib3270.java" /> 41 <Unit filename="src/br/com/bb/pw3270/lib3270.java" />
android/res/layout/main.xml
@@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
10 10
11 <EditText 11 <EditText
12 android:id="@+id/hostname" 12 android:id="@+id/hostname"
13 - android:layout_width="match_parent" 13 + android:layout_width="0dip"
14 android:layout_height="match_parent" 14 android:layout_height="match_parent"
15 android:layout_weight="1" 15 android:layout_weight="1"
16 android:ems="10" /> 16 android:ems="10" />
@@ -20,14 +20,19 @@ @@ -20,14 +20,19 @@
20 style="?android:attr/buttonStyleSmall" 20 style="?android:attr/buttonStyleSmall"
21 android:layout_width="80dp" 21 android:layout_width="80dp"
22 android:layout_height="match_parent" 22 android:layout_height="match_parent"
23 - android:text="Connect" /> 23 + android:text="@string/connect" />
24 24
25 </LinearLayout> 25 </LinearLayout>
26 26
27 - <TextView  
28 - android:id="@+id/text" 27 + <TextView
  28 + android:id="@+id/msgbox"
29 android:layout_width="fill_parent" 29 android:layout_width="fill_parent"
30 - android:layout_height="match_parent" 30 + android:layout_height="wrap_content"
31 android:text="@string/hello" /> 31 android:text="@string/hello" />
  32 +
  33 + <WebView
  34 + android:id="@+id/view"
  35 + android:layout_width="match_parent"
  36 + android:layout_height="match_parent" />
32 37
33 </LinearLayout> 38 </LinearLayout>
34 \ No newline at end of file 39 \ No newline at end of file
android/res/values/strings.xml
1 <?xml version="1.0" encoding="utf-8"?> 1 <?xml version="1.0" encoding="utf-8"?>
2 <resources> 2 <resources>
3 3
4 - <string name="hello">Hello World, PW3270Activity!</string> 4 + <string name="hello">Welcome to pw3270</string>
5 <string name="app_name">PW3270</string> 5 <string name="app_name">PW3270</string>
6 <string-array name="program_msg"> 6 <string-array name="program_msg">
7 <item>LIB3270_MESSAGE_NONE</item> 7 <item>LIB3270_MESSAGE_NONE</item>
8 - <item>LIB3270_MESSAGE_SYSWAIT</item>  
9 - <item>LIB3270_MESSAGE_TWAIT</item>  
10 - <item>LIB3270_MESSAGE_CONNECTED</item>  
11 - <item>LIB3270_MESSAGE_DISCONNECTED</item>  
12 - <item>LIB3270_MESSAGE_AWAITING_FIRST</item>  
13 - <item>LIB3270_MESSAGE_MINUS</item>  
14 - <item>LIB3270_MESSAGE_PROTECTED</item>  
15 - <item>LIB3270_MESSAGE_NUMERIC</item>  
16 - <item>LIB3270_MESSAGE_OVERFLOW</item>  
17 - <item>LIB3270_MESSAGE_INHIBIT</item>  
18 - <item>LIB3270_MESSAGE_KYBDLOCK</item>  
19 - <item>LIB3270_MESSAGE_X</item>  
20 - <item>LIB3270_MESSAGE_RESOLVING</item>  
21 - <item>LIB3270_MESSAGE_CONNECTING</item> 8 + <item>X System</item>
  9 + <item>X Aguarde</item>
  10 + <item>Conectado</item>
  11 + <item>Desconectado</item>
  12 + <item>X</item>
  13 + <item>X -f</item>
  14 + <item>X Protegido</item>
  15 + <item>X Numérico</item>
  16 + <item>X Overflow</item>
  17 + <item>X Inhibit</item>
  18 + <item>X</item>
  19 + <item>X</item>
  20 + <item>X Resolvendo</item>
  21 + <item>X Conectando</item>
22 </string-array> 22 </string-array>
  23 + <string name="connect">Connect</string>
23 24
24 25
25 </resources> 26 </resources>
26 \ No newline at end of file 27 \ No newline at end of file
android/src/br/com/bb/pw3270/PW3270Activity.java
@@ -9,29 +9,29 @@ import android.util.Log; @@ -9,29 +9,29 @@ import android.util.Log;
9 import android.view.View; 9 import android.view.View;
10 import android.content.res.*; 10 import android.content.res.*;
11 import android.app.AlertDialog; 11 import android.app.AlertDialog;
12 -import android.app.Dialog; 12 +import android.webkit.WebView;
  13 +// import android.app.Dialog;
13 14
14 public class PW3270Activity extends Activity implements View.OnClickListener 15 public class PW3270Activity extends Activity implements View.OnClickListener
15 { 16 {
16 private class terminal extends lib3270 17 private class terminal extends lib3270
17 { 18 {
18 - TextView view; 19 + TextView msgbox;
19 Activity Main; 20 Activity Main;
20 21
21 22
22 - terminal(TextView view, Activity Main) 23 + terminal(TextView msgbox, Activity Main)
23 { 24 {
24 - this.view = view; 25 + this.msgbox = msgbox;
25 this.Main = Main; 26 this.Main = Main;
26 -  
27 } 27 }
28 28
29 protected void updateProgramMessage(int id) 29 protected void updateProgramMessage(int id)
30 { 30 {
31 try 31 try
32 { 32 {
33 - this.view.setText(message[id]);  
34 - } catch(Exception e) { this.view.setText("Estado inesperado"); } 33 + this.msgbox.setText(message[id]);
  34 + } catch(Exception e) { this.msgbox.setText("Estado inesperado"); }
35 } 35 }
36 36
37 public void popupMessage(int type, String title, String text, String info) 37 public void popupMessage(int type, String title, String text, String info)
@@ -44,6 +44,12 @@ public class PW3270Activity extends Activity implements View.OnClickListener @@ -44,6 +44,12 @@ public class PW3270Activity extends Activity implements View.OnClickListener
44 d.setCancelable(true); 44 d.setCancelable(true);
45 d.show(); 45 d.show();
46 } 46 }
  47 +
  48 + protected void redraw()
  49 + {
  50 + String text = getHTML();
  51 + }
  52 +
47 53
48 54
49 }; 55 };
@@ -52,6 +58,7 @@ public class PW3270Activity extends Activity implements View.OnClickListener @@ -52,6 +58,7 @@ public class PW3270Activity extends Activity implements View.OnClickListener
52 private EditText uri; 58 private EditText uri;
53 private Resources res; 59 private Resources res;
54 private String[] message; 60 private String[] message;
  61 + private WebView view;
55 62
56 /** Called when the activity is first created. */ 63 /** Called when the activity is first created. */
57 @Override 64 @Override
@@ -70,7 +77,7 @@ public class PW3270Activity extends Activity implements View.OnClickListener @@ -70,7 +77,7 @@ public class PW3270Activity extends Activity implements View.OnClickListener
70 Button btn = (Button) findViewById(R.id.connect); 77 Button btn = (Button) findViewById(R.id.connect);
71 btn.setOnClickListener((View.OnClickListener) this); 78 btn.setOnClickListener((View.OnClickListener) this);
72 79
73 - host = new terminal((TextView) findViewById(R.id.text),this); 80 + host = new terminal((TextView) findViewById(R.id.msgbox),this);
74 81
75 82
76 } 83 }
android/src/br/com/bb/pw3270/lib3270.java
@@ -9,7 +9,8 @@ public class lib3270 @@ -9,7 +9,8 @@ public class lib3270
9 { 9 {
10 private NetworkThread mainloop; 10 private NetworkThread mainloop;
11 private static final String TAG = "lib3270"; 11 private static final String TAG = "lib3270";
12 - 12 + private boolean changed;
  13 +
13 static 14 static
14 { 15 {
15 System.loadLibrary("3270"); 16 System.loadLibrary("3270");
@@ -18,7 +19,8 @@ public class lib3270 @@ -18,7 +19,8 @@ public class lib3270
18 19
19 lib3270() 20 lib3270()
20 { 21 {
21 - mainloop = null; 22 + changed = false;
  23 + mainloop = null;
22 } 24 }
23 25
24 private class popupMessageInfo 26 private class popupMessageInfo
@@ -26,7 +28,7 @@ public class lib3270 @@ -26,7 +28,7 @@ public class lib3270
26 public String title; 28 public String title;
27 public String text; 29 public String text;
28 public String info; 30 public String info;
29 - 31 +
30 popupMessageInfo(String title, String text, String info) 32 popupMessageInfo(String title, String text, String info)
31 { 33 {
32 this.title = title; 34 this.title = title;
@@ -34,7 +36,7 @@ public class lib3270 @@ -34,7 +36,7 @@ public class lib3270
34 this.info = info; 36 this.info = info;
35 } 37 }
36 } 38 }
37 - 39 +
38 // Main Thread 40 // Main Thread
39 private class NetworkThread extends Thread 41 private class NetworkThread extends Thread
40 { 42 {
@@ -70,7 +72,7 @@ public class lib3270 @@ -70,7 +72,7 @@ public class lib3270
70 public void postPopup(int type, String title, String text, String info) 72 public void postPopup(int type, String title, String text, String info)
71 { 73 {
72 Message msg = mHandler.obtainMessage(); 74 Message msg = mHandler.obtainMessage();
73 - 75 +
74 msg.what = 3; 76 msg.what = 3;
75 msg.arg1 = type; 77 msg.arg1 = type;
76 msg.obj = new popupMessageInfo(title,text,info); 78 msg.obj = new popupMessageInfo(title,text,info);
@@ -108,12 +110,27 @@ public class lib3270 @@ -108,12 +110,27 @@ public class lib3270
108 break; 110 break;
109 111
110 case 2: // Screen changed 112 case 2: // Screen changed
  113 + Log.d(TAG,"Screen changed");
  114 + changed = true;
  115 + redraw();
111 break; 116 break;
112 117
113 case 3: // Popup 118 case 3: // Popup
114 popupMessageInfo popup = (popupMessageInfo) msg.obj; 119 popupMessageInfo popup = (popupMessageInfo) msg.obj;
115 popupMessage(msg.arg1, popup.title, popup.text, popup.info); 120 popupMessage(msg.arg1, popup.title, popup.text, popup.info);
116 break; 121 break;
  122 +
  123 + case 4: // erase
  124 + changed = false;
  125 + erase();
  126 +
  127 + case 5: // ctlr_done
  128 + Log.d(TAG,"ctlr_done");
  129 + if(changed)
  130 + {
  131 + changed = false;
  132 + redraw();
  133 + }
117 } 134 }
118 } 135 }
119 }; 136 };
@@ -127,17 +144,26 @@ public class lib3270 @@ -127,17 +144,26 @@ public class lib3270
127 public void popupMessage(int type, String title, String text, String info) 144 public void popupMessage(int type, String title, String text, String info)
128 { 145 {
129 } 146 }
130 - 147 +
131 protected void info(String tag, String msg) 148 protected void info(String tag, String msg)
132 { 149 {
133 Log.i(tag,msg); 150 Log.i(tag,msg);
134 } 151 }
135 - 152 +
136 protected void error(String tag, String msg) 153 protected void error(String tag, String msg)
137 { 154 {
138 Log.e(tag,msg); 155 Log.e(tag,msg);
139 } 156 }
140 157
  158 + protected void erase()
  159 + {
  160 + Log.i(TAG,"Erase screen");
  161 + }
  162 +
  163 + protected void redraw()
  164 + {
  165 + }
  166 +
141 /*---[ External methods ]------------------------------------------------*/ 167 /*---[ External methods ]------------------------------------------------*/
142 168
143 public int connect() 169 public int connect()
@@ -170,5 +196,8 @@ public class lib3270 @@ -170,5 +196,8 @@ public class lib3270
170 public native boolean isConnected(); 196 public native boolean isConnected();
171 public native boolean isTerminalReady(); 197 public native boolean isTerminalReady();
172 198
  199 + // Get/Set screen contents
  200 + public native String getHTML();
  201 +
173 202
174 } 203 }