-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHDLauncherActivity.java
154 lines (121 loc) · 4.98 KB
/
HDLauncherActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package com.zebra.dw_webview;
import static android.widget.Toast.makeText;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.FileProvider;
import android.annotation.SuppressLint;
import android.app.ActivityOptions;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.pm.PackageInfo;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.text.format.DateFormat;
import android.util.Log;
import android.view.View;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;
import android.widget.Toast;
import com.zebra.arcore.psspoc.helpers.BarcodeReceiverKt;
import java.util.Objects;
//chrome://inspect/#devices for webview debugging
public class HDLauncherActivity extends AppCompatActivity {
Intent starterIntent;
WebView webView;
//@SuppressLint("JavascriptInterface")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
starterIntent = getIntent();
setContentView(R.layout.activity_hdlauncher);
webView = findViewById(R.id.web_interface);
webView.loadUrl("file:///android_asset/asset_code_quantity.html");
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setSupportZoom(true);
webView.addJavascriptInterface(this, "DATAWEDGE");
BarcodeReceiverKt.createDataWedgeProfile(this, new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String acquiredbarcode = Objects.requireNonNull(intent.getStringExtra("com.symbol.datawedge.data_string"));
//acquiredbarcode = filterOutNonPrintableCharactersWIthRegex(acquiredbarcode);
//acquiredbarcode = filterOutNonAlphaNumericCharactersWIthRegex(acquiredbarcode);
//acquiredbarcode = encodeString(acquiredbarcode);
Log.i("onReceive", "barcode="+ acquiredbarcode);
//printAsciiValues(acquiredbarcode);
webView.loadUrl("javascript:formFill('"+acquiredbarcode+"')");
}
});
}
public String filterOutNonPrintableCharactersWIthRegex(String input) {
return input.replaceAll("[^\\x24-\\x7e]", "_");
}
//filterout all characters that not numbers or letters with regex
public String filterOutNonAlphaNumericCharactersWIthRegex(String input) {
return input.replaceAll("[^a-zA-Z0-9]", "");
}
//encode string
public String encodeString(String input) {
return Uri.encode(input);
}
//print the ascii value of each character in the string
public void printAsciiValues(String input) {
for (int i = 0; i < input.length(); i++) {
char c = input.charAt(i);
int ascii = (int) c;
Log.i("printAsciiValues", "ascii10="+ascii);
}
}
@JavascriptInterface
public String getWebviewVersion() {
PackageInfo info = WebView.getCurrentWebViewPackage();
return "WEBVIEW version " + info.versionName+"\n"+ Build.FINGERPRINT;
}
@JavascriptInterface
public void showMsg(String _bc, String _qty) {
AlertDialog.Builder builder = new AlertDialog.Builder(HDLauncherActivity.this);
builder.setTitle("Confirmation").setMessage("Barcode:\t" + _bc + "\nQuantity:\t" + _qty)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(getApplicationContext(), " Data Saved Locally", Toast.LENGTH_SHORT).show();
// You can use shared preference or db here to store The Data
}
})
;
builder.create().show();
}
public void onClickbtn_SCAN(View v) {
try {
String softScanTrigger = "com.symbol.datawedge.api.ACTION";
String extraData = "com.symbol.datawedge.api.SOFT_SCAN_TRIGGER";
// create the intent
Intent i = new Intent();
// set the action to perform
i.setAction(softScanTrigger);
// add additional info
i.putExtra(extraData, "START_SCANNING");
// send the intent to DataWedge
this.sendBroadcast(i);
} catch (Exception e) {
Log.e("TAG", "onClickbtn_SCAN "+e.getMessage());
}
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
@Override
protected void onDestroy() {
super.onDestroy();
}
}