6
6
package org .qccoders .qcvoc ;
7
7
8
8
import android .content .Intent ;
9
+ import android .graphics .Bitmap ;
9
10
import android .support .v7 .app .AppCompatActivity ;
10
11
import android .os .Bundle ;
11
12
import android .util .Log ;
12
- import android .view .KeyCharacterMap ;
13
- import android .view .KeyEvent ;
13
+ import android .view .View ;
14
14
import android .webkit .JavascriptInterface ;
15
15
import android .webkit .WebView ;
16
16
import android .webkit .WebViewClient ;
17
+ import android .widget .ProgressBar ;
17
18
18
19
import com .google .android .gms .samples .vision .barcodereader .BarcodeCaptureActivity ;
19
20
import com .google .android .gms .vision .barcode .Barcode ;
20
21
21
22
public class MainActivity extends AppCompatActivity {
22
23
private WebView webview ;
24
+ private ProgressBar progressBar ;
23
25
24
26
@ Override
25
27
protected void onCreate (Bundle savedInstanceState ) {
26
28
super .onCreate (savedInstanceState );
27
29
setContentView (R .layout .activity_main );
28
30
31
+ progressBar = findViewById (R .id .loading_spinner );
32
+ progressBar .setVisibility (View .GONE );
33
+
29
34
webview = findViewById (R .id .webView );
35
+ webview .setWebViewClient (new WebViewClient () {
36
+ @ Override
37
+ public void onPageStarted (WebView view , String url , Bitmap favicon ) {
38
+ super .onPageStarted (view , url , favicon );
39
+ progressBar .setVisibility (View .VISIBLE );
40
+ }
41
+
42
+ @ Override
43
+ public void onPageFinished (WebView view , String url ) {
44
+ super .onPageFinished (view , url );
45
+ progressBar .setVisibility (View .GONE );
46
+ }
47
+ });
48
+
30
49
webview .addJavascriptInterface (this , "Android" );
31
- webview .setWebViewClient (new WebViewClient ());
32
50
webview .getSettings ().setJavaScriptEnabled (true );
33
51
webview .getSettings ().setDomStorageEnabled (true );
34
- webview .loadUrl ("http://dev.qcvoc.qccoders.org " );
52
+ webview .loadUrl ("http://qcvoc- dev.s3-website-us-east-1.amazonaws.com " );
35
53
}
36
54
37
55
@ JavascriptInterface
@@ -45,17 +63,13 @@ public void scanBarcode() {
45
63
@ Override
46
64
protected void onActivityResult (int requestCode , int resultCode , Intent data ) {
47
65
if (data != null ) {
48
- KeyCharacterMap keymap = KeyCharacterMap .load (KeyCharacterMap .VIRTUAL_KEYBOARD );
49
-
50
66
Barcode barcode = data .getParcelableExtra (BarcodeCaptureActivity .BarcodeObject );
51
- String outputString = "^" + barcode .displayValue + "$" ;
52
- KeyEvent [] outputKeyEvents = keymap .getEvents (outputString .toCharArray ());
53
67
54
- Log .d ("MainActivity" , outputString );
68
+ Log .d ("MainActivity" , barcode . displayValue );
55
69
56
- for ( int i = 0 ; i < outputKeyEvents . length ; i ++) {
57
- dispatchKeyEvent ( outputKeyEvents [ i ]);
58
- }
70
+ webview . evaluateJavascript (
71
+ "window.barcodeScanned(" + barcode . displayValue + ");" ,
72
+ null );
59
73
}
60
74
}
61
75
}
0 commit comments