Commit 2cf7edce75f042af0e5a8e771fa7837eadf5a0ad
1 parent
0a216085
Exists in
master
and in
5 other branches
Android, iniciando interação entre o código javascript e a jni
Showing
5 changed files
with
130 additions
and
82 deletions
Show diff stats
android/res/raw/index.html
| @@ -4,38 +4,42 @@ | @@ -4,38 +4,42 @@ | ||
| 4 | <meta http-equiv="content-type" content="text/html;charset=utf-8"/> | 4 | <meta http-equiv="content-type" content="text/html;charset=utf-8"/> |
| 5 | <meta name="author" content="Perry Werneck, perry@werneck.eti.br"> | 5 | <meta name="author" content="Perry Werneck, perry@werneck.eti.br"> |
| 6 | <link rel="stylesheet" type="text/css" href="file:theme.css" /> | 6 | <link rel="stylesheet" type="text/css" href="file:theme.css" /> |
| 7 | + <script type="text/javascript" src="file:jsmain.js"></script> | ||
| 7 | <title>pw3270</title> | 8 | <title>pw3270</title> |
| 8 | </head> | 9 | </head> |
| 9 | 10 | ||
| 10 | -<body> | 11 | +<body onload="initialize()"> |
| 11 | <div id="terminal"> | 12 | <div id="terminal"> |
| 13 | +</div> | ||
| 12 | 14 | ||
| 13 | - <span style="color:green;background-color:black"> </span><span style="color:deepSkyBlue;background-color:black"> COEM7010 SISBB - Sistema de Informacoes Banco do Brasil 06/07/2012<br /> | ||
| 14 | - C1103788</span><span style="color:green;background-color:black"> </span><span style="color:white;background-color:black"> Correio Eletronico </span><span style="color:green;background-color:black"> </span><span style="color:deepSkyBlue;background-color:black">15:29:03<br /> | ||
| 15 | - ----------------------- Indicadores - Ler Matéria ------------------ Pag.: 1<br /> | ||
| 16 | - Período:</span><span style="color:green;background-color:black"><input type="text" name="F0251" value="05072012" maxlength="8" class="IW008"></input></span><span style="color:deepSkyBlue;background-color:black">a</span><span style="color:green;background-color:black"><input type="text" name="F0262" value="06072012" maxlength="8" class="IW008"></input> </span><span style="color:white;background-color:black">(Alteravel)</span><span style="color:green;background-color:black"> </span><span style="color:deepSkyBlue;background-color:black"> Parte título:</span><span style="color:green;background-color:black"><input type="text" name="F0300" maxlength="20" class="IW020"></input><br /> | ||
| 17 | - <br /> | ||
| 18 | - </span><span style="color:deepSkyBlue;background-color:black"> Assunto:</span><span style="color:green;background-color:black"><input type="text" name="F0411" maxlength="40" class="IW040"></input></span><span style="color:deepSkyBlue;background-color:black">(+)<br /> | ||
| 19 | - Nr. Título Data Hora<br /> | ||
| 20 | - ---- ------------------------------------------------------------- -----------<br /> | ||
| 21 | - 1</span><span style="color:green;background-color:black"> </span><span style="color:white;background-color:black">Rentabilidade fundos BB 06/07 00:00<br /> | ||
| 22 | - </span><span style="color:green;background-color:black"> </span><span style="color:deepSkyBlue;background-color:black"> 2</span><span style="color:green;background-color:black"> </span><span style="color:white;background-color:black">Rentabilidade comparada fundos BB 06/07 00:00<br /> | ||
| 23 | - </span><span style="color:green;background-color:black"> </span><span style="color:deepSkyBlue;background-color:black"> 3</span><span style="color:green;background-color:black"> </span><span style="color:white;background-color:black">Indices Economicos 06/07 00:00<br /> | ||
| 24 | - </span><span style="color:green;background-color:black"> </span><span style="color:deepSkyBlue;background-color:black"> 4 ACF - ADIANTAMENTO DE CONTRATO DE FORNECIMENTO - 06-07-2012 06/07 00:00<br /> | ||
| 25 | - 5 CDF - CRÉDITO DIRETO AO FORNECEDOR - 06-07-2012 06/07 00:00<br /> | ||
| 26 | - 6 Depositos a Prazo - Taxas Pos Fixadas 06/07 00:00<br /> | ||
| 27 | - 7 Depositos a Prazo - Entes Publicos - Taxas Negociadas 06/07 00:00<br /> | ||
| 28 | - 8 Depositos a Prazo - Taxas não Negociadas 06/07 00:00<br /> | ||
| 29 | - 9 Depositos a Prazo - Nivel 2 - Taxas Negociadas 06/07 00:00<br /> | ||
| 30 | - 10 Depositos a Prazo - Nivel 1 - Taxas Negociadas 06/07 00:00<br /> | ||
| 31 | - 11 Depositos a Prazo - Taxas não Negociadas - BB CDB DI PARCERIA 06/07 00:00<br /> | ||
| 32 | - 12 Inadimplemento - Comissão de Permanência - 06/07/2012 06/07 00:00<br /> | ||
| 33 | - Informe número (Nr.):</span><span style="color:green;background-color:black"><input type="text" name="F1624" maxlength="4" class="IW004"></input><br /> | ||
| 34 | - </span><span style="color:deepSkyBlue;background-color:black"> ------------------------------------------------------------------------------<br /> | ||
| 35 | - </span><span style="color:green;background-color:black"> </span><span style="color:white;background-color:black"> F1 Ajuda F9 Origem<br /> | ||
| 36 | - </span><span style="color:green;background-color:black"> <input type="button" name="PF03" value="F3" maxlength="2" class="IW002"></input></span><span style="color:deepSkyBlue;background-color:black">Sai</span><span style="color:green;background-color:black"><input type="button" name="PF04" value="F4" maxlength="2" class="IW002"></input></span><span style="color:deepSkyBlue;background-color:black">Seleciona(+)</span><span style="color:green;background-color:black"><input type="button" name="PF05" value="F5" maxlength="2" class="IW002"></input></span><span style="color:deepSkyBlue;background-color:black">Encerra</span><span style="color:green;background-color:black"><input type="button" name="PF06" value="F6" maxlength="2" class="IW002"></input></span><span style="color:deepSkyBlue;background-color:black">Imprime</span><span style="color:green;background-color:black"><input type="button" name="PF07" value="F7" maxlength="2" class="IW002"></input></span><span style="color:deepSkyBlue;background-color:black">Pag.Ant</span><span style="color:green;background-color:black"><input type="button" name="PF08" value="F8" maxlength="2" class="IW002"></input></span><span style="color:deepSkyBlue;background-color:black">Prox.Pag<br /> | ||
| 37 | - </span> | ||
| 38 | - | 15 | +<div id="pfbar"> |
| 16 | +<div class="pfkey"><a href="#" onclick="return pfkey(1)">PF1</a></div> | ||
| 17 | +<div class="pfkey"><a href="#" onclick="return pfkey(2)">PF2</a></div> | ||
| 18 | +<div class="pfkey"><a href="#" onclick="return pfkey(3)">PF3</a></div> | ||
| 19 | +<div class="pfkey"><a href="#" onclick="return pfkey(4)">PF4</a></div> | ||
| 20 | +<div class="pfkey"><a href="#" onclick="return pfkey(5)">PF5</a></div> | ||
| 21 | +<div class="pfkey"><a href="#" onclick="return pfkey(6)">PF6</a></div> | ||
| 22 | +<div class="pfkey"><a href="#" onclick="return pfkey(7)">PF7</a></div> | ||
| 23 | +<div class="pfkey"><a href="#" onclick="return pfkey(8)">PF8</a></div> | ||
| 24 | +<div class="pfkey"><a href="#" onclick="return pfkey(9)">PF9</a></div> | ||
| 25 | +<div class="pfkey"><a href="#" onclick="return pfkey(10)">PF10</a></div> | ||
| 26 | +<div class="pfkey"><a href="#" onclick="return pfkey(11)">PF11</a></div> | ||
| 27 | +<div class="pfkey"><a href="#" onclick="return pfkey(12)">PF12</a></div> | ||
| 28 | +<div class="pfkey"><a href="#" onclick="return xmit()">ENTER</a></div> | ||
| 29 | +<br /> | ||
| 30 | +<div class="pfkey"><a href="#" onclick="return pfkey(13)">PF13</a></div> | ||
| 31 | +<div class="pfkey"><a href="#" onclick="return pfkey(14)">PF14</a></div> | ||
| 32 | +<div class="pfkey"><a href="#" onclick="return pfkey(15)">PF15</a></div> | ||
| 33 | +<div class="pfkey"><a href="#" onclick="return pfkey(16)">PF16</a></div> | ||
| 34 | +<div class="pfkey"><a href="#" onclick="return pfkey(17)">PF17</a></div> | ||
| 35 | +<div class="pfkey"><a href="#" onclick="return pfkey(18)">PF18</a></div> | ||
| 36 | +<div class="pfkey"><a href="#" onclick="return pfkey(19)">PF19</a></div> | ||
| 37 | +<div class="pfkey"><a href="#" onclick="return pfkey(20)">PF20</a></div> | ||
| 38 | +<div class="pfkey"><a href="#" onclick="return pfkey(21)">PF21</a></div> | ||
| 39 | +<div class="pfkey"><a href="#" onclick="return pfkey(22)">PF22</a></div> | ||
| 40 | +<div class="pfkey"><a href="#" onclick="return pfkey(23)">PF23</a></div> | ||
| 41 | +<div class="pfkey"><a href="#" onclick="return pfkey(24)">PF24</a></div> | ||
| 42 | +<div class="pfkey"><a href="#" onclick="return eraseinput()">Clear</a></div> | ||
| 39 | </div> | 43 | </div> |
| 40 | </body> | 44 | </body> |
| 41 | </html> | 45 | </html> |
android/res/raw/jsmain.js
| @@ -0,0 +1,28 @@ | @@ -0,0 +1,28 @@ | ||
| 1 | + | ||
| 2 | +function initialize() | ||
| 3 | +{ | ||
| 4 | + updateScreen(); | ||
| 5 | +} | ||
| 6 | + | ||
| 7 | +function updateScreen() | ||
| 8 | +{ | ||
| 9 | + document.getElementById("terminal").innerHTML = pw3270.getscreencontents(); | ||
| 10 | +} | ||
| 11 | + | ||
| 12 | +function pfkey(id) | ||
| 13 | +{ | ||
| 14 | + pw3270.pfkey(id); | ||
| 15 | + return false; | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +function xmit() | ||
| 19 | +{ | ||
| 20 | + pw3270.xmit(); | ||
| 21 | + return false; | ||
| 22 | +} | ||
| 23 | + | ||
| 24 | +function eraseinput() | ||
| 25 | +{ | ||
| 26 | + return false; | ||
| 27 | +} | ||
| 28 | + |
android/res/raw/theme.css
| @@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
| 2 | body | 2 | body |
| 3 | { | 3 | { |
| 4 | background-color: black; | 4 | background-color: black; |
| 5 | + color: green; | ||
| 5 | } | 6 | } |
| 6 | 7 | ||
| 7 | body, input | 8 | body, input |
| @@ -55,3 +56,30 @@ input[type="text"] | @@ -55,3 +56,30 @@ input[type="text"] | ||
| 55 | width: 24em; | 56 | width: 24em; |
| 56 | } | 57 | } |
| 57 | 58 | ||
| 59 | +#pfbar | ||
| 60 | +{ | ||
| 61 | + width: 49em; | ||
| 62 | + background: black; | ||
| 63 | + color: white; | ||
| 64 | + text-align: center; | ||
| 65 | + border-top: 1px solid #fff; | ||
| 66 | +} | ||
| 67 | + | ||
| 68 | +a | ||
| 69 | +{ | ||
| 70 | + text-decoration: none; | ||
| 71 | + color: black; | ||
| 72 | +} | ||
| 73 | + | ||
| 74 | +.pfkey | ||
| 75 | +{ | ||
| 76 | + margin: 1px; | ||
| 77 | + background: gray; | ||
| 78 | + color: black; | ||
| 79 | + width: 4em; | ||
| 80 | + border: 1px solid darkgray; | ||
| 81 | + text-decoration: none; | ||
| 82 | + font-size: 15px; | ||
| 83 | + font-family: arial; | ||
| 84 | + display: inline-block; | ||
| 85 | +} |
android/src/br/com/bb/pw3270/PW3270Activity.java
| @@ -19,19 +19,18 @@ import java.io.InputStream; | @@ -19,19 +19,18 @@ import java.io.InputStream; | ||
| 19 | 19 | ||
| 20 | public class PW3270Activity extends Activity | 20 | public class PW3270Activity extends Activity |
| 21 | { | 21 | { |
| 22 | + private static final String TAG = "pw3270"; | ||
| 23 | + | ||
| 22 | private Resources res; | 24 | private Resources res; |
| 23 | private WebView view; | 25 | private WebView view; |
| 24 | private terminal host; | 26 | private terminal host; |
| 25 | - private static final String TAG = "pw3270"; | 27 | + private Activity mainact; |
| 26 | 28 | ||
| 27 | private class terminal extends lib3270 | 29 | private class terminal extends lib3270 |
| 28 | { | 30 | { |
| 29 | 31 | ||
| 30 | - Activity Main; | ||
| 31 | - | ||
| 32 | - terminal(Activity Main) | 32 | + terminal() |
| 33 | { | 33 | { |
| 34 | - this.Main = Main; | ||
| 35 | } | 34 | } |
| 36 | 35 | ||
| 37 | protected void updateProgramMessage(int id) | 36 | protected void updateProgramMessage(int id) |
| @@ -46,7 +45,7 @@ public class PW3270Activity extends Activity | @@ -46,7 +45,7 @@ public class PW3270Activity extends Activity | ||
| 46 | 45 | ||
| 47 | protected void popupMessage(int type, String title, String text, String info) | 46 | protected void popupMessage(int type, String title, String text, String info) |
| 48 | { | 47 | { |
| 49 | - AlertDialog d = new AlertDialog.Builder(Main).create(); | 48 | + AlertDialog d = new AlertDialog.Builder(mainact).create(); |
| 50 | 49 | ||
| 51 | d.setTitle(title); | 50 | d.setTitle(title); |
| 52 | d.setMessage(text); | 51 | d.setMessage(text); |
| @@ -55,26 +54,25 @@ public class PW3270Activity extends Activity | @@ -55,26 +54,25 @@ public class PW3270Activity extends Activity | ||
| 55 | d.show(); | 54 | d.show(); |
| 56 | } | 55 | } |
| 57 | 56 | ||
| 58 | - protected void redraw() | 57 | + public String getscreencontents() |
| 59 | { | 58 | { |
| 59 | + String text; | ||
| 60 | + | ||
| 60 | try | 61 | try |
| 61 | { | 62 | { |
| 62 | - String text = new String(getText(),getEncoding()); | ||
| 63 | -// Log.i(TAG,text); | ||
| 64 | - } catch(Exception e) { } | 63 | + text = new String(getHTML(),getEncoding()); |
| 64 | + } catch(Exception e) { text = ""; } | ||
| 65 | + | ||
| 66 | + return text; | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + protected void redraw() | ||
| 70 | + { | ||
| 71 | + view.reload(); | ||
| 65 | } | 72 | } |
| 66 | - | ||
| 67 | 73 | ||
| 68 | }; | 74 | }; |
| 69 | 75 | ||
| 70 | - /* | ||
| 71 | - private terminal host; | ||
| 72 | - private EditText uri; | ||
| 73 | - private Resources res; | ||
| 74 | - private String[] message; | ||
| 75 | - private WebView view; | ||
| 76 | - | ||
| 77 | -*/ | ||
| 78 | 76 | ||
| 79 | 77 | ||
| 80 | /** Called when the activity is first created. */ | 78 | /** Called when the activity is first created. */ |
| @@ -90,6 +88,11 @@ public class PW3270Activity extends Activity | @@ -90,6 +88,11 @@ public class PW3270Activity extends Activity | ||
| 90 | view = new WebView(this); | 88 | view = new WebView(this); |
| 91 | 89 | ||
| 92 | view.setWebChromeClient(new WebChromeClient()); | 90 | view.setWebChromeClient(new WebChromeClient()); |
| 91 | + | ||
| 92 | + view.getSettings().setBuiltInZoomControls(true); | ||
| 93 | + view.getSettings().setSupportZoom(true); | ||
| 94 | + view.getSettings().setUseWideViewPort(true); | ||
| 95 | + view.getSettings().setLoadWithOverviewMode(true); | ||
| 93 | 96 | ||
| 94 | view.setWebViewClient(new WebViewClient() | 97 | view.setWebViewClient(new WebViewClient() |
| 95 | { | 98 | { |
| @@ -99,14 +102,18 @@ public class PW3270Activity extends Activity | @@ -99,14 +102,18 @@ public class PW3270Activity extends Activity | ||
| 99 | { | 102 | { |
| 100 | int id = R.raw.index; | 103 | int id = R.raw.index; |
| 101 | String mime = "text/html"; | 104 | String mime = "text/html"; |
| 105 | + int pos = url.lastIndexOf("/"); | ||
| 106 | + | ||
| 107 | + if(pos >=0 ) | ||
| 108 | + url = url.substring(pos+1); | ||
| 102 | 109 | ||
| 103 | Log.i(TAG,"Loading [" + url + "]"); | 110 | Log.i(TAG,"Loading [" + url + "]"); |
| 104 | 111 | ||
| 105 | - if(url.equalsIgnoreCase("file://jsmain.js")) | 112 | + if(url.equalsIgnoreCase("jsmain.js")) |
| 106 | { | 113 | { |
| 107 | id = R.raw.jsmain; | 114 | id = R.raw.jsmain; |
| 108 | } | 115 | } |
| 109 | - else if(url.equalsIgnoreCase("file://theme.css")) | 116 | + else if(url.equalsIgnoreCase("theme.css")) |
| 110 | { | 117 | { |
| 111 | mime = "text/css"; | 118 | mime = "text/css"; |
| 112 | id = R.raw.theme; | 119 | id = R.raw.theme; |
| @@ -120,44 +127,15 @@ public class PW3270Activity extends Activity | @@ -120,44 +127,15 @@ public class PW3270Activity extends Activity | ||
| 120 | }); | 127 | }); |
| 121 | 128 | ||
| 122 | view.getSettings().setJavaScriptEnabled(true); | 129 | view.getSettings().setJavaScriptEnabled(true); |
| 123 | - | ||
| 124 | - setContentView(view); | ||
| 125 | - view.loadUrl("file://index.html"); | ||
| 126 | - | ||
| 127 | - // setContentView(R.layout.main); | ||
| 128 | 130 | ||
| 129 | -// Log.i("pw3270","Activity started"); | ||
| 130 | - | ||
| 131 | - | ||
| 132 | -// view = (WebView) findViewById(R.id.view); | 131 | + setContentView(view); |
| 132 | + view.loadUrl("file:index.html"); | ||
| 133 | 133 | ||
| 134 | -// String summary = "<html><body>Welcome to <b>pw3270</b>.</body></html>" ; | ||
| 135 | - | ||
| 136 | - // res.getString(R.string.hello); | 134 | + host = new terminal(); |
| 135 | + view.addJavascriptInterface(host, "pw3270"); | ||
| 136 | + host.connect(); | ||
| 137 | 137 | ||
| 138 | - // ; | ||
| 139 | - // view.loadData("<html><body>Welcome to <b>pw3270</b>.</body></html>", "text/html", null); | ||
| 140 | - | ||
| 141 | - /* | ||
| 142 | - message = res.getStringArray(R.array.program_msg); | ||
| 143 | - uri = (EditText) findViewById(R.id.hostname); | ||
| 144 | - | ||
| 145 | - // Set button | ||
| 146 | - Button btn = (Button) findViewById(R.id.connect); | ||
| 147 | - btn.setOnClickListener((View.OnClickListener) this); | ||
| 148 | - | ||
| 149 | - host = new terminal((TextView) findViewById(R.id.msgbox),this); | ||
| 150 | - | ||
| 151 | - */ | ||
| 152 | - } | ||
| 153 | 138 | ||
| 154 | - /* | ||
| 155 | - public void onClick(View v) | ||
| 156 | - { | ||
| 157 | - // Perform action on click | ||
| 158 | - // host.setHost(uri.getText().toString()); | ||
| 159 | - host.connect(); | ||
| 160 | } | 139 | } |
| 161 | - */ | ||
| 162 | 140 | ||
| 163 | } | 141 | } |
| 164 | \ No newline at end of file | 142 | \ No newline at end of file |
android/src/br/com/bb/pw3270/lib3270.java
| @@ -313,6 +313,16 @@ public class lib3270 | @@ -313,6 +313,16 @@ public class lib3270 | ||
| 313 | { | 313 | { |
| 314 | } | 314 | } |
| 315 | 315 | ||
| 316 | + public void pfkey(int id) | ||
| 317 | + { | ||
| 318 | + Log.i(TAG,"PF "+id); | ||
| 319 | + } | ||
| 320 | + | ||
| 321 | + public void xmit() | ||
| 322 | + { | ||
| 323 | + Log.i(TAG,"XMIT"); | ||
| 324 | + } | ||
| 325 | + | ||
| 316 | /*---[ External methods ]------------------------------------------------*/ | 326 | /*---[ External methods ]------------------------------------------------*/ |
| 317 | 327 | ||
| 318 | public int connect() | 328 | public int connect() |