implement secret taps (on ScannerAcvitivty toolbar) for scanner backend change, refs #9991
This commit is contained in:
@@ -8,6 +8,7 @@ import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import com.dinect.checker.zbar.CameraActivity;
|
||||
import com.dinect.checker.zxing.ScannerActivity;
|
||||
|
||||
import io.flutter.app.FlutterActivity;
|
||||
import io.flutter.plugins.GeneratedPluginRegistrant;
|
||||
@@ -15,12 +16,16 @@ import io.flutter.plugin.common.MethodCall;
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
|
||||
import io.flutter.plugin.common.MethodChannel.Result;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.ArrayList;
|
||||
import java.lang.System;
|
||||
import java.util.Set;
|
||||
|
||||
public class MainActivity extends FlutterActivity {
|
||||
|
||||
static final String TAG = "Checker.MainActivity";
|
||||
|
||||
private static final int START_SCANNER_REQUEST_CODE = 2017;
|
||||
private static final String PREF_POS_MERCHANT_ID = "pref_pos_merchant_id";
|
||||
private static final String PREF_DOC_ID = "pref_doc_id";
|
||||
@@ -29,6 +34,12 @@ public class MainActivity extends FlutterActivity {
|
||||
static final String PREF_APP_TOKEN = "pres_app_token";
|
||||
static final String PREF_POS_TOKEN = "pref_pos_token";
|
||||
|
||||
static final Class[] SCANNER_BACKEND = {
|
||||
ScannerActivity.class,
|
||||
CameraActivity.class,
|
||||
};
|
||||
static final String SCANNER_BACKEND_KEY = "scanner_backend_idx";
|
||||
|
||||
private MethodChannel mChannel;
|
||||
private SharedPreferences mPreferences;
|
||||
|
||||
@@ -39,66 +50,73 @@ public class MainActivity extends FlutterActivity {
|
||||
|
||||
mPreferences = getPreferences(Context.MODE_PRIVATE);
|
||||
|
||||
Log.d(TAG, "application prefs:");
|
||||
for(final Map.Entry<String, ?> kv: mPreferences.getAll().entrySet()){
|
||||
Log.d(TAG, " key = " + kv.getKey() + ", value = " + kv.getValue().toString());
|
||||
}
|
||||
|
||||
mChannel = new MethodChannel(getFlutterView(), "com.dinect.checker/instance_id");
|
||||
mChannel.setMethodCallHandler(
|
||||
new MethodCallHandler() {
|
||||
@Override
|
||||
public void onMethodCall(MethodCall call, Result result) {
|
||||
switch (call.method) {
|
||||
case "saveToken":
|
||||
Map tokenArguments = call.arguments();
|
||||
mPreferences.edit().putString(PREF_POS_TOKEN, (String) tokenArguments.get("token")).apply();
|
||||
break;
|
||||
case "getToken":
|
||||
result.success(mPreferences.getString(PREF_POS_TOKEN, null));
|
||||
break;
|
||||
case "saveMerchantID":
|
||||
Map merchantIDArguments = call.arguments();
|
||||
mPreferences.edit().putString(PREF_POS_MERCHANT_ID, (String) merchantIDArguments.get("merchantID")).apply();
|
||||
break;
|
||||
case "getMerchantID":
|
||||
result.success(mPreferences.getString(PREF_POS_MERCHANT_ID, null));
|
||||
break;
|
||||
case "startScanner":
|
||||
Map arguments = call.arguments();
|
||||
Intent cameraIntent = new Intent(MainActivity.this, CameraActivity.class);
|
||||
cameraIntent.putExtra(PREF_API_URL, (String) arguments.get("url"));
|
||||
cameraIntent.putExtra(PREF_APP_TOKEN, (String) arguments.get("appToken"));
|
||||
cameraIntent.putExtra(PREF_POS_TOKEN, (String) arguments.get("token"));
|
||||
startActivityForResult(cameraIntent, START_SCANNER_REQUEST_CODE);
|
||||
break;
|
||||
case "removeKeys":
|
||||
mPreferences.edit().remove(PREF_POS_TOKEN).apply();
|
||||
mPreferences.edit().remove(PREF_POS_MERCHANT_ID).apply();
|
||||
mPreferences.edit().remove(PREF_DOC_ID).apply();
|
||||
mPreferences.edit().remove(PREF_POS_ID).apply();
|
||||
result.success(null);
|
||||
break;
|
||||
case "getDocID":
|
||||
int docId = mPreferences.getInt(PREF_DOC_ID, 0) + 1;
|
||||
mPreferences.edit().putInt(PREF_DOC_ID, docId).apply();
|
||||
result.success(String.valueOf(docId));
|
||||
break;
|
||||
case "isOnline":
|
||||
boolean online = Utils.isOnline(MainActivity.this);
|
||||
if (!online) {
|
||||
Toast.makeText(MainActivity.this, "Проверьте интернет соединение", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
result.success(online);
|
||||
break;
|
||||
case "getPosID":
|
||||
String posId = mPreferences.getString(PREF_POS_ID, null);
|
||||
if (posId == null) {
|
||||
posId = String.valueOf(System.currentTimeMillis());
|
||||
}
|
||||
mPreferences.edit().putString(PREF_POS_ID, posId).apply();
|
||||
result.success(posId);
|
||||
break;
|
||||
default:
|
||||
result.notImplemented();
|
||||
break;
|
||||
new MethodCallHandler() {
|
||||
@Override
|
||||
public void onMethodCall(MethodCall call, Result result) {
|
||||
switch (call.method) {
|
||||
case "saveToken":
|
||||
Map tokenArguments = call.arguments();
|
||||
mPreferences.edit().putString(PREF_POS_TOKEN, (String) tokenArguments.get("token")).apply();
|
||||
break;
|
||||
case "getToken":
|
||||
result.success(mPreferences.getString(PREF_POS_TOKEN, null));
|
||||
break;
|
||||
case "saveMerchantID":
|
||||
Map merchantIDArguments = call.arguments();
|
||||
mPreferences.edit().putString(PREF_POS_MERCHANT_ID, (String) merchantIDArguments.get("merchantID")).apply();
|
||||
break;
|
||||
case "getMerchantID":
|
||||
result.success(mPreferences.getString(PREF_POS_MERCHANT_ID, null));
|
||||
break;
|
||||
case "startScanner":
|
||||
final Map arguments = call.arguments();
|
||||
final int idx = mPreferences.getInt(SCANNER_BACKEND_KEY, 0);
|
||||
Log.d(TAG, "use " + SCANNER_BACKEND[idx].toString() + " backend, with idx = " + idx);
|
||||
Intent cameraIntent = new Intent(MainActivity.this, SCANNER_BACKEND[idx]);
|
||||
cameraIntent.putExtra(PREF_API_URL, (String) arguments.get("url"));
|
||||
cameraIntent.putExtra(PREF_APP_TOKEN, (String) arguments.get("appToken"));
|
||||
cameraIntent.putExtra(PREF_POS_TOKEN, (String) arguments.get("token"));
|
||||
startActivityForResult(cameraIntent, START_SCANNER_REQUEST_CODE);
|
||||
break;
|
||||
case "removeKeys":
|
||||
mPreferences.edit().remove(PREF_POS_TOKEN).apply();
|
||||
mPreferences.edit().remove(PREF_POS_MERCHANT_ID).apply();
|
||||
mPreferences.edit().remove(PREF_DOC_ID).apply();
|
||||
mPreferences.edit().remove(PREF_POS_ID).apply();
|
||||
result.success(null);
|
||||
break;
|
||||
case "getDocID":
|
||||
int docId = mPreferences.getInt(PREF_DOC_ID, 0) + 1;
|
||||
mPreferences.edit().putInt(PREF_DOC_ID, docId).apply();
|
||||
result.success(String.valueOf(docId));
|
||||
break;
|
||||
case "isOnline":
|
||||
boolean online = Utils.isOnline(MainActivity.this);
|
||||
if (!online) {
|
||||
Toast.makeText(MainActivity.this, "Проверьте интернет соединение", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
result.success(online);
|
||||
break;
|
||||
case "getPosID":
|
||||
String posId = mPreferences.getString(PREF_POS_ID, null);
|
||||
if (posId == null) {
|
||||
posId = String.valueOf(System.currentTimeMillis());
|
||||
}
|
||||
mPreferences.edit().putString(PREF_POS_ID, posId).apply();
|
||||
result.success(posId);
|
||||
break;
|
||||
default:
|
||||
result.notImplemented();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -117,7 +135,7 @@ public class MainActivity extends FlutterActivity {
|
||||
mChannel.invokeMethod("purchase", args);
|
||||
} else {
|
||||
String menuItem = data.getExtras().getString("item", null);
|
||||
Log.d("item", menuItem);
|
||||
Log.d(TAG, menuItem);
|
||||
if (menuItem != null) {
|
||||
mChannel.invokeMethod(menuItem, null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user