Commit 20980a6e21ee9923ace6faa9f9a9cd3c5d610fc2

Authored by perry.werneck@gmail.com
1 parent eb180443

Iniciando a implementação da caixa de diálogo modal durante comunicação com o host

android/jni/main.cpp
@@ -127,6 +127,12 @@ static void ctlr_done(H3270 *session) @@ -127,6 +127,12 @@ static void ctlr_done(H3270 *session)
127 post_message(4); 127 post_message(4);
128 } 128 }
129 129
  130 +void update_status(H3270 *session, LIB3270_MESSAGE id)
  131 +{
  132 + __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "Status changed to %d",(int) id);
  133 + post_message(1,(int) id);
  134 +}
  135 +
130 static int write_buffer(H3270 *session, unsigned const char *buf, int len) 136 static int write_buffer(H3270 *session, unsigned const char *buf, int len)
131 { 137 {
132 int rc = -1; 138 int rc = -1;
@@ -276,6 +282,7 @@ JNIEXPORT jint JNICALL Java_br_com_bb_pw3270_lib3270_init(JNIEnv *env, jclass ob @@ -276,6 +282,7 @@ JNIEXPORT jint JNICALL Java_br_com_bb_pw3270_lib3270_init(JNIEnv *env, jclass ob
276 session->changed = changed; 282 session->changed = changed;
277 session->erase = erase; 283 session->erase = erase;
278 session->ctlr_done = ctlr_done; 284 session->ctlr_done = ctlr_done;
  285 + session->update_status = update_status;
279 286
280 PW3270_JNI_END 287 PW3270_JNI_END
281 288
android/res/values/strings.xml
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 <resources> 2 <resources>
3 <string name="app_name">PW3270</string> 3 <string name="app_name">PW3270</string>
4 <string-array name="program_msg"> 4 <string-array name="program_msg">
5 - <item>LIB3270_MESSAGE_NONE</item> 5 + <item></item>
6 <item>X System</item> 6 <item>X System</item>
7 <item>X Aguarde</item> 7 <item>X Aguarde</item>
8 <item>Conectado</item> 8 <item>Conectado</item>
android/src/br/com/bb/pw3270/PW3270Activity.java
@@ -14,22 +14,24 @@ import android.webkit.WebView; @@ -14,22 +14,24 @@ import android.webkit.WebView;
14 import android.webkit.WebViewClient; 14 import android.webkit.WebViewClient;
15 import android.webkit.WebResourceResponse; 15 import android.webkit.WebResourceResponse;
16 import android.webkit.WebChromeClient; 16 import android.webkit.WebChromeClient;
  17 +import android.app.ProgressDialog;
17 // import java.io.InputStream; 18 // import java.io.InputStream;
18 19
19 // import android.app.Dialog; 20 // import android.app.Dialog;
20 21
21 -public class PW3270Activity extends Activity 22 +public class PW3270Activity extends Activity
22 { 23 {
23 private static final String TAG = "pw3270"; 24 private static final String TAG = "pw3270";
24 25
25 - private Resources res;  
26 - private WebView view;  
27 - private terminal host;  
28 - private Activity mainact;  
29 - 26 + private Resources res;
  27 + private WebView view;
  28 + private terminal host;
  29 + private Activity mainact;
  30 + private ProgressDialog dlgProgress;
  31 +
30 private class terminal extends lib3270 32 private class terminal extends lib3270
31 { 33 {
32 - 34 +
33 terminal() 35 terminal()
34 { 36 {
35 SharedPreferences settings = getSharedPreferences(TAG, 0); 37 SharedPreferences settings = getSharedPreferences(TAG, 0);
@@ -43,20 +45,47 @@ public class PW3270Activity extends Activity @@ -43,20 +45,47 @@ public class PW3270Activity extends Activity
43 45
44 } 46 }
45 47
  48 + public void hideProgressDialog()
  49 + {
  50 + dlgProgress.hide();
  51 + }
  52 +
  53 + public void showProgressDialog(String msg)
  54 + {
  55 + dlgProgress.setMessage(msg);
  56 + Log.v(TAG,msg);
  57 + dlgProgress.show();
  58 + }
  59 +
46 protected void updateProgramMessage(int id) 60 protected void updateProgramMessage(int id)
47 { 61 {
48 - /*  
49 - try 62 + if(id == 0)
50 { 63 {
51 - // this.msgbox.setText(message[id]);  
52 - } catch(Exception e) { this.msgbox.setText("Estado inesperado"); }  
53 - */ 64 + if(changed)
  65 + {
  66 + dlgProgress.setMessage("Aguarde...");
  67 + changed = false;
  68 + view.reload();
  69 + hideProgressDialog();
  70 + }
  71 + }
  72 + else
  73 + {
  74 + String message[] = res.getStringArray(R.array.program_msg);
  75 + try
  76 + {
  77 + showProgressDialog(message[id]);
  78 + } catch(Exception e)
  79 + {
  80 + showProgressDialog("Aguarde...");
  81 + }
  82 + }
54 } 83 }
55 84
56 protected void popupMessage(int type, String title, String text, String info) 85 protected void popupMessage(int type, String title, String text, String info)
57 { 86 {
58 AlertDialog d = new AlertDialog.Builder(mainact).create(); 87 AlertDialog d = new AlertDialog.Builder(mainact).create();
59 - 88 +
60 d.setTitle(title); 89 d.setTitle(title);
61 d.setMessage(text); 90 d.setMessage(text);
62 91
@@ -67,58 +96,56 @@ public class PW3270Activity extends Activity @@ -67,58 +96,56 @@ public class PW3270Activity extends Activity
67 public String getscreencontents() 96 public String getscreencontents()
68 { 97 {
69 String text; 98 String text;
70 - 99 +
71 try 100 try
72 { 101 {
73 text = new String(getHTML(),getEncoding()); 102 text = new String(getHTML(),getEncoding());
74 } catch(Exception e) { text = ""; } 103 } catch(Exception e) { text = ""; }
75 - 104 +
76 return text; 105 return text;
77 } 106 }
78 -  
79 - protected void redraw()  
80 - {  
81 - view.reload();  
82 - }  
83 - 107 +
84 }; 108 };
85 109
86 -  
87 -  
88 /** Called when the activity is first created. */ 110 /** Called when the activity is first created. */
89 @Override 111 @Override
90 - public void onCreate(Bundle savedInstanceState) 112 + public void onCreate(Bundle savedInstanceState)
91 { 113 {
92 super.onCreate(savedInstanceState); 114 super.onCreate(savedInstanceState);
93 - 115 +
94 res = getResources(); 116 res = getResources();
95 117
  118 + dlgProgress = new ProgressDialog(this);
  119 + dlgProgress.setMessage("Aguarde...");
  120 + dlgProgress.setCancelable(false);
  121 +// dlgProgress.show();
  122 +
96 // Reference: 123 // Reference:
97 // http://developer.android.com/reference/android/webkit/WebView.html 124 // http://developer.android.com/reference/android/webkit/WebView.html
98 view = new WebView(this); 125 view = new WebView(this);
99 - 126 +
100 view.setWebChromeClient(new WebChromeClient()); 127 view.setWebChromeClient(new WebChromeClient());
101 128
102 view.getSettings().setBuiltInZoomControls(true); 129 view.getSettings().setBuiltInZoomControls(true);
103 - view.getSettings().setSupportZoom(true); 130 + view.getSettings().setSupportZoom(true);
104 view.getSettings().setUseWideViewPort(true); 131 view.getSettings().setUseWideViewPort(true);
105 - view.getSettings().setLoadWithOverviewMode(true);  
106 -  
107 - view.setWebViewClient(new WebViewClient() 132 + view.getSettings().setLoadWithOverviewMode(true);
  133 +
  134 + view.setWebViewClient(new WebViewClient()
108 { 135 {
109 - 136 +
110 @Override 137 @Override
111 public WebResourceResponse shouldInterceptRequest(WebView view, String url) 138 public WebResourceResponse shouldInterceptRequest(WebView view, String url)
112 { 139 {
113 int id = R.raw.index; 140 int id = R.raw.index;
114 String mime = "text/html"; 141 String mime = "text/html";
115 int pos = url.lastIndexOf("/"); 142 int pos = url.lastIndexOf("/");
116 - 143 +
117 if(pos >=0 ) 144 if(pos >=0 )
118 url = url.substring(pos+1); 145 url = url.substring(pos+1);
119 - 146 +
120 Log.i(TAG,"Loading [" + url + "]"); 147 Log.i(TAG,"Loading [" + url + "]");
121 - 148 +
122 if(url.equalsIgnoreCase("jsmain.js")) 149 if(url.equalsIgnoreCase("jsmain.js"))
123 { 150 {
124 id = R.raw.jsmain; 151 id = R.raw.jsmain;
@@ -129,23 +156,23 @@ public class PW3270Activity extends Activity @@ -129,23 +156,23 @@ public class PW3270Activity extends Activity
129 id = R.raw.theme; 156 id = R.raw.theme;
130 } 157 }
131 158
132 - 159 +
133 // http://developer.android.com/reference/android/webkit/WebResourceResponse.html 160 // http://developer.android.com/reference/android/webkit/WebResourceResponse.html
134 return new WebResourceResponse(mime,"utf-8",getResources().openRawResource(id)); 161 return new WebResourceResponse(mime,"utf-8",getResources().openRawResource(id));
135 } 162 }
136 - 163 +
137 }); 164 });
138 - 165 +
139 view.getSettings().setJavaScriptEnabled(true); 166 view.getSettings().setJavaScriptEnabled(true);
140 167
141 setContentView(view); 168 setContentView(view);
142 view.loadUrl("file:index.html"); 169 view.loadUrl("file:index.html");
143 - 170 +
144 host = new terminal(); 171 host = new terminal();
145 view.addJavascriptInterface(host, "pw3270"); 172 view.addJavascriptInterface(host, "pw3270");
146 host.connect(); 173 host.connect();
147 - 174 +
148 175
149 } 176 }
150 177
151 -}  
152 \ No newline at end of file 178 \ No newline at end of file
  179 +}
android/src/br/com/bb/pw3270/lib3270.java
@@ -17,7 +17,7 @@ public class lib3270 @@ -17,7 +17,7 @@ public class lib3270
17 private NetworkThread mainloop; 17 private NetworkThread mainloop;
18 private static final String TAG = "lib3270"; 18 private static final String TAG = "lib3270";
19 19
20 - private boolean changed; 20 + protected boolean changed;
21 private boolean connected = false; 21 private boolean connected = false;
22 private boolean refresh = true; 22 private boolean refresh = true;
23 23
@@ -147,10 +147,10 @@ public class lib3270 @@ -147,10 +147,10 @@ public class lib3270
147 { 147 {
148 // Connecta no host 148 // Connecta no host
149 SocketFactory socketFactory; 149 SocketFactory socketFactory;
150 - 150 +
151 if(hostname == "") 151 if(hostname == "")
152 return false; 152 return false;
153 - 153 +
154 if(ssl) 154 if(ssl)
155 { 155 {
156 // Host é SSL 156 // Host é SSL
@@ -295,8 +295,6 @@ public class lib3270 @@ -295,8 +295,6 @@ public class lib3270
295 case 2: // Screen changed 295 case 2: // Screen changed
296 Log.d(TAG,"Screen changed"); 296 Log.d(TAG,"Screen changed");
297 changed = true; 297 changed = true;
298 - if(refresh)  
299 - redraw();  
300 break; 298 break;
301 299
302 case 3: // Popup 300 case 3: // Popup
@@ -311,11 +309,6 @@ public class lib3270 @@ -311,11 +309,6 @@ public class lib3270
311 309
312 case 5: // ctlr_done 310 case 5: // ctlr_done
313 Log.d(TAG,"ctlr_done"); 311 Log.d(TAG,"ctlr_done");
314 - if(changed)  
315 - {  
316 - changed = false;  
317 - redraw();  
318 - }  
319 break; 312 break;
320 313
321 case 6: // recv_data 314 case 6: // recv_data
@@ -350,10 +343,6 @@ public class lib3270 @@ -350,10 +343,6 @@ public class lib3270
350 Log.i(TAG,"Erase screen"); 343 Log.i(TAG,"Erase screen");
351 } 344 }
352 345
353 - protected void redraw()  
354 - {  
355 - }  
356 -  
357 public void pfkey(int id) 346 public void pfkey(int id)
358 { 347 {
359 Log.d(TAG,"PF"+id); 348 Log.d(TAG,"PF"+id);
src/lib3270/html.c
@@ -386,9 +386,11 @@ @@ -386,9 +386,11 @@
386 else 386 else
387 { 387 {
388 append_element(&info,HTML_ELEMENT_LINE_BREAK); 388 append_element(&info,HTML_ELEMENT_LINE_BREAK);
  389 +/*
389 #if defined(DEBUG) || defined(ANDROID) 390 #if defined(DEBUG) || defined(ANDROID)
390 append_string(&info,"\n"); 391 append_string(&info,"\n");
391 #endif // DEBUG 392 #endif // DEBUG
  393 +*/
392 } 394 }
393 395
394 } 396 }
@@ -420,6 +422,7 @@ @@ -420,6 +422,7 @@
420 422
421 info.text = lib3270_realloc(info.text,strlen(info.text)+2); 423 info.text = lib3270_realloc(info.text,strlen(info.text)+2);
422 424
  425 +/*
423 #if defined(DEBUG) || defined(ANDROID) 426 #if defined(DEBUG) || defined(ANDROID)
424 { 427 {
425 char *text = strdup(info.text); 428 char *text = strdup(info.text);
@@ -434,6 +437,7 @@ @@ -434,6 +437,7 @@
434 free(text); 437 free(text);
435 } 438 }
436 #endif // DEBUG 439 #endif // DEBUG
  440 +*/
437 441
438 return info.text; 442 return info.text;
439 } 443 }