Skip to content

Commit db7200c

Browse files
authored
Merge pull request #219 from qccoders/mobile-app
Android Progress Spinner, tweaks
2 parents 9795cbe + 1be9043 commit db7200c

File tree

5 files changed

+40
-16
lines changed

5 files changed

+40
-16
lines changed

mobile-new/app/src/main/java/org/qccoders/qcvoc/MainActivity.java

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,50 @@
66
package org.qccoders.qcvoc;
77

88
import android.content.Intent;
9+
import android.graphics.Bitmap;
910
import android.support.v7.app.AppCompatActivity;
1011
import android.os.Bundle;
1112
import android.util.Log;
12-
import android.view.KeyCharacterMap;
13-
import android.view.KeyEvent;
13+
import android.view.View;
1414
import android.webkit.JavascriptInterface;
1515
import android.webkit.WebView;
1616
import android.webkit.WebViewClient;
17+
import android.widget.ProgressBar;
1718

1819
import com.google.android.gms.samples.vision.barcodereader.BarcodeCaptureActivity;
1920
import com.google.android.gms.vision.barcode.Barcode;
2021

2122
public class MainActivity extends AppCompatActivity {
2223
private WebView webview;
24+
private ProgressBar progressBar;
2325

2426
@Override
2527
protected void onCreate(Bundle savedInstanceState) {
2628
super.onCreate(savedInstanceState);
2729
setContentView(R.layout.activity_main);
2830

31+
progressBar = findViewById(R.id.loading_spinner);
32+
progressBar.setVisibility(View.GONE);
33+
2934
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+
3049
webview.addJavascriptInterface(this, "Android");
31-
webview.setWebViewClient(new WebViewClient());
3250
webview.getSettings().setJavaScriptEnabled(true);
3351
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");
3553
}
3654

3755
@JavascriptInterface
@@ -45,17 +63,13 @@ public void scanBarcode() {
4563
@Override
4664
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
4765
if (data != null) {
48-
KeyCharacterMap keymap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
49-
5066
Barcode barcode = data.getParcelableExtra(BarcodeCaptureActivity.BarcodeObject);
51-
String outputString = "^" + barcode.displayValue + "$";
52-
KeyEvent[] outputKeyEvents = keymap.getEvents(outputString.toCharArray());
5367

54-
Log.d("MainActivity", outputString);
68+
Log.d("MainActivity", barcode.displayValue);
5569

56-
for (int i = 0; i < outputKeyEvents.length; i++) {
57-
dispatchKeyEvent(outputKeyEvents[i]);
58-
}
70+
webview.evaluateJavascript(
71+
"window.barcodeScanned(" + barcode.displayValue + ");",
72+
null);
5973
}
6074
}
6175
}

mobile-new/app/src/main/res/layout/activity_main.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,14 @@
1111
android:layout_width="match_parent"
1212
android:layout_height="match_parent"/>
1313

14+
<ProgressBar
15+
android:id="@+id/loading_spinner"
16+
style="?android:attr/progressBarStyle"
17+
android:layout_width="wrap_content"
18+
android:layout_height="wrap_content"
19+
app:layout_constraintLeft_toLeftOf="parent"
20+
app:layout_constraintRight_toRightOf="parent"
21+
app:layout_constraintTop_toTopOf="parent"
22+
app:layout_constraintBottom_toBottomOf="parent"/>
23+
1424
</android.support.constraint.ConstraintLayout>

mobile-new/app/src/main/res/values/styles.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<resources>
22

33
<!-- Base application theme. -->
4-
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
4+
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
55
<!-- Customize your theme here. -->
66
<item name="colorPrimary">@color/colorPrimary</item>
77
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>

mobile-new/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ buildscript {
77
jcenter()
88
}
99
dependencies {
10-
classpath 'com.android.tools.build:gradle:3.1.4'
10+
classpath 'com.android.tools.build:gradle:3.2.0'
1111

1212

1313
// NOTE: Do not place your application dependencies here; they belong
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Sat Sep 22 20:58:31 CDT 2018
1+
#Mon Sep 24 21:18:07 CDT 2018
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip

0 commit comments

Comments
 (0)