Commit 6f207f07af17370ac99651c1cdfadf02c347a287

Authored by perry.werneck@gmail.com
1 parent 5c783f96

Melhorando diálogo de configuração android

android/res/values/strings.xml
... ... @@ -18,7 +18,7 @@
18 18 <item>X Resolvendo</item>
19 19 <item>X Conectando</item>
20 20 </string-array>
21   - <string name="connect">Connect</string>
  21 + <string name="wait">Em processamento</string>
22 22  
23 23  
24 24 </resources>
25 25 \ No newline at end of file
... ...
android/res/xml/preferences.xml
... ... @@ -24,19 +24,30 @@
24 24  
25 25 <CheckBoxPreference
26 26 android:key="ssl"
27   - android:summary="Usar SSL nas conexões ao host"
  27 + android:summaryOff="Não usar SSL nas conexões ao host"
  28 + android:summaryOn="Usar SSL nas conexões ao host"
28 29 android:title="Conexão segura"
29 30 android:defaultValue="false"
30 31 />
31 32  
32 33 <CheckBoxPreference
33   - android:key="reconnect"
34   - android:summary="Conectar automaticamente"
35   - android:title="Conexão automática"
  34 + android:key="autoconnect"
  35 + android:summaryOn="Conectar ao iniciar"
  36 + android:summaryOff="Não conectar ao iniciar"
  37 + android:title="Conecta ao host ao iniciar"
36 38 android:defaultValue="true"
37 39 />
38 40  
39   - </PreferenceCategory>
  41 + <CheckBoxPreference
  42 + android:key="reconnect"
  43 + android:summaryOn="Reconectar automaticamente"
  44 + android:summaryOff="Não reconectar automaticamente"
  45 + android:title="Reconexão automática"
  46 + android:defaultValue="false"
  47 + />
  48 +
  49 +
  50 + </PreferenceCategory>
40 51  
41 52 </PreferenceScreen>
42 53  
... ...
android/src/br/com/bb/pw3270/PW3270Activity.java
... ... @@ -29,7 +29,7 @@ public class PW3270Activity extends Activity
29 29 private WebView view;
30 30 private terminal host;
31 31 private Activity mainact = this;
32   - private ProgressDialog dlgProgress;
  32 + private ProgressDialog dlgSysMessage;
33 33  
34 34 private class terminal extends lib3270
35 35 {
... ... @@ -41,14 +41,7 @@ public class PW3270Activity extends Activity
41 41  
42 42 public void hideProgressDialog()
43 43 {
44   - dlgProgress.hide();
45   - }
46   -
47   - public void showProgressDialog(String msg)
48   - {
49   - dlgProgress.setMessage(msg);
50   - Log.v(TAG,msg);
51   - dlgProgress.show();
  44 + dlgSysMessage.hide();
52 45 }
53 46  
54 47 protected void updateScreen()
... ... @@ -63,12 +56,12 @@ public class PW3270Activity extends Activity
63 56 String message[] = res.getStringArray(R.array.program_msg);
64 57 try
65 58 {
66   - showProgressDialog(message[id]);
  59 + dlgSysMessage.setMessage(message[id]);
67 60 } catch(Exception e)
68 61 {
69   - Log.e(TAG,e.getLocalizedMessage());
70   - showProgressDialog("?");
  62 + dlgSysMessage.setMessage(e.getLocalizedMessage());
71 63 }
  64 + dlgSysMessage.show();
72 65 }
73 66 return true;
74 67 }
... ... @@ -123,11 +116,23 @@ public class PW3270Activity extends Activity
123 116  
124 117 res = getResources();
125 118  
126   - dlgProgress = new ProgressDialog(this);
127   - dlgProgress.setMessage("Aguarde...");
128   - dlgProgress.setCancelable(false);
129   -// dlgProgress.show();
  119 + // Cria dialogo para as mensagems de sistema
  120 + dlgSysMessage = new ProgressDialog(this);
  121 + dlgSysMessage.setCancelable(false);
  122 + dlgSysMessage.setTitle(res.getString(R.string.wait));
  123 +
  124 + /*
  125 + dlgSysMessage.setButton(-2, "Desconectar", new DialogInterface.OnClickListener()
  126 + {
130 127  
  128 + public void onClick(DialogInterface dialog, int which)
  129 + {
  130 + // TODO Auto-generated method stub
  131 + }
  132 +
  133 + });
  134 + */
  135 +
131 136 // Reference:
132 137 // http://developer.android.com/reference/android/webkit/WebView.html
133 138 view = new WebView(this);
... ... @@ -177,7 +182,7 @@ public class PW3270Activity extends Activity
177 182 setContentView(view);
178 183 view.loadUrl("file:index.html");
179 184  
180   - if(settings.getString("hostname","") != "" && settings.getBoolean("reconnect",false))
  185 + if(settings.getString("hostname","") != "" && settings.getBoolean("autoconnect",false))
181 186 host.connect();
182 187  
183 188 }
... ...
android/src/br/com/bb/pw3270/SettingsActivity.java
1 1 package br.com.bb.pw3270;
2 2  
3 3 import android.os.Bundle;
  4 +import android.preference.Preference;
4 5 import android.preference.PreferenceFragment;
5 6 import android.app.Activity;
6 7  
7 8 public class SettingsActivity extends Activity
8 9 {
9   - public static class SettingsFragment extends PreferenceFragment
  10 + public static class SettingsFragment extends PreferenceFragment
10 11 {
  12 + private class stringSetting implements Preference.OnPreferenceChangeListener
  13 + {
  14 +
  15 + public stringSetting(Preference p)
  16 + {
  17 + p.setOnPreferenceChangeListener(this);
  18 + this.onPreferenceChange(p,null);
  19 + }
  20 +
  21 + public boolean onPreferenceChange(Preference p, Object arg1)
  22 + {
  23 + p.setSummary(p.getSharedPreferences().getString(p.getKey(),""));
  24 + return false;
  25 + }
  26 + }
  27 +
11 28 @Override
12 29 public void onCreate(Bundle savedInstanceState)
13 30 {
... ... @@ -15,7 +32,14 @@ public class SettingsActivity extends Activity
15 32  
16 33 // Load the preferences from an XML resource
17 34 addPreferencesFromResource(R.xml.preferences);
  35 +
  36 + // Update summary from settings
  37 + new stringSetting(findPreference("hostname"));
  38 + new stringSetting(findPreference("port"));
  39 +
18 40 }
  41 +
  42 +
19 43 }
20 44  
21 45 @Override
... ...
android/src/br/com/bb/pw3270/lib3270.java
... ... @@ -66,10 +66,9 @@ public class lib3270
66 66 {
67 67 switch (msg.what)
68 68 {
69   -/*
70   - case 0: // Connected/Disconnected
  69 + case 0: // Reconnect
  70 + connect();
71 71 break;
72   -*/
73 72  
74 73 case 1: // OIA message has changed
75 74 showProgramMessage(msg.arg1);
... ... @@ -81,8 +80,15 @@ public class lib3270
81 80 break;
82 81  
83 82 case 3: // Popup
84   - popupMessageInfo popup = (popupMessageInfo) msg.obj;
85   - showPopupMessage(msg.arg1, popup.title, popup.text, popup.info);
  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 92 break;
87 93  
88 94 case 4: // erase
... ... @@ -97,12 +103,6 @@ public class lib3270
97 103 Log.d(TAG, "ctlr_done");
98 104 break;
99 105  
100   -/*
101   - case 6: // recv_data
102   - procRecvdata(((byteMessage) msg.obj).getMessage(),((byteMessage) msg.obj).getLength());
103   - break;
104   -*/
105   -
106 106 case 7: // ready
107 107 hideProgressDialog();
108 108 break;
... ... @@ -203,7 +203,7 @@ public class lib3270
203 203  
204 204 Log.i(TAG, "Erro ao enviar dados: " + msg);
205 205  
206   - postPopup(0, "Erro na comunicação", "Não foi possível enviar dados", msg);
  206 + postPopup(1, "Desconectado", "Erro de comunicação ao enviar dados", msg);
207 207  
208 208 connected = false;
209 209  
... ... @@ -257,7 +257,7 @@ public class lib3270
257 257  
258 258 Log.i(TAG, "Erro ao conectar: " + msg);
259 259  
260   - postPopup(0, "Erro na conexão", msg, "");
  260 + postPopup(0, "Erro na conexão", "Não foi possível conectar", msg);
261 261  
262 262 postMessage(0, 0, 0);
263 263  
... ... @@ -286,14 +286,13 @@ public class lib3270
286 286  
287 287 try
288 288 {
289   - Log.v(TAG,"Aguardando dados...");
290 289 sz = inData.read(in, 0, 4096);
291 290  
292 291 } catch (Exception e)
293 292 {
294 293 String msg = e.getLocalizedMessage();
295 294 Log.i(TAG, "Erro ao receber dados do host: " + msg);
296   - postPopup(0, "Erro na comunicação", "Erro ao receber dados", msg);
  295 + postPopup(1, "Desconectado", "Erro de comunicação ao receber dados", msg);
297 296 connected = false;
298 297 sz = -1;
299 298 }
... ...