RG-3445 Добавлен ручной ввод кода с карты
This commit is contained in:
@@ -23,21 +23,22 @@ import android.content.Intent;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v7.app.ActionBar;
|
import android.support.v7.app.ActionBar;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
import android.view.KeyEvent;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
|
import android.widget.EditText;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.Toast;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.dinect.checker.net.ApiClient;
|
import com.dinect.checker.net.ApiClient;
|
||||||
|
|
||||||
@@ -45,8 +46,6 @@ import java.util.Queue;
|
|||||||
import java.util.concurrent.ArrayBlockingQueue;
|
import java.util.concurrent.ArrayBlockingQueue;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import static android.app.Activity.RESULT_OK;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by anonymous
|
* Created by anonymous
|
||||||
@@ -56,26 +55,14 @@ public abstract class AbstractScannerActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
private final static String TAG = "Checker.ScannerActivity";
|
private final static String TAG = "Checker.ScannerActivity";
|
||||||
|
|
||||||
private static final String[] CLICK_MESSAGES = {
|
private int counter;
|
||||||
"Там ничего нет.",
|
|
||||||
"Зачем ты это делаешь?",
|
|
||||||
"Перестань!",
|
|
||||||
"Ну и зачем?..",
|
|
||||||
};
|
|
||||||
|
|
||||||
private final AtomicInteger counter = new AtomicInteger(0);
|
|
||||||
private int mColor;
|
|
||||||
|
|
||||||
public static final String SCAN_MODES = "SCAN_MODES";
|
public static final String SCAN_MODES = "SCAN_MODES";
|
||||||
public static final String ERROR_INFO = "ERROR_INFO";
|
public static final String ERROR_INFO = "ERROR_INFO";
|
||||||
|
|
||||||
|
|
||||||
protected AppCompatActivity ctx;
|
|
||||||
protected ApiClient apiClient;
|
protected ApiClient apiClient;
|
||||||
protected NetworkThread networkThread;
|
protected NetworkThread networkThread;
|
||||||
protected DecrementCounterThread counterThread;
|
|
||||||
protected LogoutDialogFragment logoutDialog;
|
protected LogoutDialogFragment logoutDialog;
|
||||||
protected NotificationThread notificationThread;
|
|
||||||
|
|
||||||
boolean isCameraAvailable() {
|
boolean isCameraAvailable() {
|
||||||
Log.d(TAG, "isCameraAvailable");
|
Log.d(TAG, "isCameraAvailable");
|
||||||
@@ -88,7 +75,6 @@ public abstract class AbstractScannerActivity extends AppCompatActivity {
|
|||||||
final Intent response = new Intent();
|
final Intent response = new Intent();
|
||||||
response.putExtra(ERROR_INFO, message);
|
response.putExtra(ERROR_INFO, message);
|
||||||
setResult(RESULT_CANCELED, response);
|
setResult(RESULT_CANCELED, response);
|
||||||
notificationThread = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -105,9 +91,6 @@ public abstract class AbstractScannerActivity extends AppCompatActivity {
|
|||||||
cancelRequest("Camera unavailable");
|
cancelRequest("Camera unavailable");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ctx = this;
|
|
||||||
notificationThread = new NotificationThread(this);
|
|
||||||
notificationThread.start();
|
|
||||||
// Hide the window title.
|
// Hide the window title.
|
||||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
setContentView(layoutID);
|
setContentView(layoutID);
|
||||||
@@ -117,120 +100,65 @@ public abstract class AbstractScannerActivity extends AppCompatActivity {
|
|||||||
/**
|
/**
|
||||||
* Configure toolbar of app
|
* Configure toolbar of app
|
||||||
*/
|
*/
|
||||||
protected final void initToolbar(final int toolbarId, final @NonNull String title) {
|
protected final void initToolbar(Intent intent) {
|
||||||
Log.d(TAG, "initToolbar");
|
|
||||||
final Toolbar toolbar = (Toolbar) findViewById(toolbarId);
|
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||||
mColor = (int) getIntent().getLongExtra(MainActivity.PREF_APP_BAR_COLOR, 0xffffff);
|
toolbar.setBackgroundColor((int) intent.getLongExtra(MainActivity.PREF_APP_BAR_COLOR, 0xffffff));
|
||||||
toolbar.setBackgroundColor(mColor);
|
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
final ActionBar actionBar = getSupportActionBar();
|
final ActionBar actionBar = getSupportActionBar();
|
||||||
|
|
||||||
if (actionBar != null) {
|
if (actionBar != null) {
|
||||||
actionBar.setTitle(title);
|
actionBar.setTitle(null);
|
||||||
actionBar.setDisplayHomeAsUpEnabled(false);
|
actionBar.setDisplayHomeAsUpEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initManualInput();
|
||||||
setupSecretClickHandler(toolbar);
|
setupSecretClickHandler(toolbar);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupSecretClickHandler(final @NonNull Toolbar toolbar) {
|
private void initManualInput() {
|
||||||
|
EditText manualInput = (EditText) findViewById(R.id.manual_input);
|
||||||
|
|
||||||
|
|
||||||
|
manualInput.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||||
|
handleBarcode(v.getText().toString());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupSecretClickHandler(final @NonNull View toolbar) {
|
||||||
// Configure increment handler
|
// Configure increment handler
|
||||||
counterThread = new DecrementCounterThread(counter, 700L);
|
|
||||||
toolbar.setOnClickListener(new View.OnClickListener() {
|
toolbar.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
String toastMessage = null;
|
if (counter == 15) {
|
||||||
switch (counter.incrementAndGet()) {
|
|
||||||
case 1:
|
|
||||||
if (false == counterThread.isRunning()) {
|
|
||||||
counterThread.start();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
toastMessage = CLICK_MESSAGES[0];
|
|
||||||
break;
|
|
||||||
case 11:
|
|
||||||
toastMessage = CLICK_MESSAGES[1];
|
|
||||||
break;
|
|
||||||
case 17:
|
|
||||||
toastMessage = CLICK_MESSAGES[2];
|
|
||||||
break;
|
|
||||||
case 23:
|
|
||||||
toastMessage = null;
|
|
||||||
counterThread.pause();
|
|
||||||
Toast.makeText(ctx, CLICK_MESSAGES[3], Toast.LENGTH_SHORT).show();
|
|
||||||
switchScanner();
|
switchScanner();
|
||||||
break;
|
} else {
|
||||||
}
|
counter++;
|
||||||
Log.d(TAG, "toolbar clicked " + counter.get() + " times");
|
|
||||||
|
|
||||||
if (null != toastMessage) {
|
|
||||||
notificationThread.addMessage(toastMessage);
|
|
||||||
}
|
}
|
||||||
|
Log.d(TAG, "toolbar clicked " + counter + " times");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private class DecrementCounterThread extends Thread {
|
|
||||||
final long delay;
|
|
||||||
final AtomicInteger counter;
|
|
||||||
private boolean running = false;
|
|
||||||
private int previous = 0;
|
|
||||||
|
|
||||||
public DecrementCounterThread(final AtomicInteger counter, final long delay) {
|
|
||||||
// Configure decrement handler
|
|
||||||
Log.d(TAG, "setupSecretClickHandler: DecrementCounterThread()");
|
|
||||||
this.counter = counter;
|
|
||||||
this.delay = delay;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
running = true;
|
|
||||||
while (running) {
|
|
||||||
try {
|
|
||||||
Thread.sleep(delay);
|
|
||||||
if (counter.get() > 0) {
|
|
||||||
if (previous > counter.get()) {
|
|
||||||
previous = counter.decrementAndGet();
|
|
||||||
Log.d(TAG, "decrement counter, now " + counter.get());
|
|
||||||
} else {
|
|
||||||
previous = counter.get();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (final IllegalArgumentException | InterruptedException e) {
|
|
||||||
Log.d(TAG, "disable counter decrease Thread", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isRunning() {
|
|
||||||
return running;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void pause() {
|
|
||||||
Log.d(TAG, "pause decrementer");
|
|
||||||
running = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void switchScanner() {
|
private void switchScanner() {
|
||||||
final SharedPreferences prefs = getSharedPreferences("MainActivity", Context.MODE_PRIVATE);
|
|
||||||
int idx = prefs.getInt(MainActivity.SCANNER_BACKEND_KEY, 0);
|
|
||||||
|
|
||||||
Log.d(TAG, "current scanner backend " + idx + ", " + MainActivity.SCANNER_BACKEND[idx].toString());
|
final SharedPreferences prefs = getSharedPreferences("scanner", Context.MODE_PRIVATE);
|
||||||
if (idx >= MainActivity.SCANNER_BACKEND.length - 1) {
|
|
||||||
idx = 0;
|
int idx = (prefs.getInt(MainActivity.SCANNER_BACKEND_KEY, 0) == MainActivity.ZXING)
|
||||||
} else {
|
? MainActivity.ZBAR
|
||||||
idx++;
|
: MainActivity.ZXING;
|
||||||
}
|
|
||||||
Log.d(TAG, "switch to scanner backend " + idx + ", " + MainActivity.SCANNER_BACKEND[idx].toString());
|
Log.d(TAG, "switch to scanner backend " + idx + ", " + MainActivity.SCANNER_BACKEND[idx].toString());
|
||||||
prefs.edit().putInt(MainActivity.SCANNER_BACKEND_KEY, idx).apply();
|
prefs.edit().putInt(MainActivity.SCANNER_BACKEND_KEY, idx).apply();
|
||||||
|
|
||||||
final Intent response = new Intent();
|
|
||||||
response.putExtra("item", "restartScanner");
|
|
||||||
cancelRequest("Scanner backend changed");
|
cancelRequest("Scanner backend changed");
|
||||||
|
setResult(RESULT_OK);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,7 +198,6 @@ public abstract class AbstractScannerActivity extends AppCompatActivity {
|
|||||||
*/
|
*/
|
||||||
public void handleBarcode(final @NonNull String card) {
|
public void handleBarcode(final @NonNull String card) {
|
||||||
Log.d(TAG, "handleBarcode");
|
Log.d(TAG, "handleBarcode");
|
||||||
notificationThread.addMessage(card);
|
|
||||||
networkThread = new NetworkThread(this, apiClient);
|
networkThread = new NetworkThread(this, apiClient);
|
||||||
networkThread.card(card).start();
|
networkThread.card(card).start();
|
||||||
}
|
}
|
||||||
@@ -284,12 +211,7 @@ public abstract class AbstractScannerActivity extends AppCompatActivity {
|
|||||||
intent.putExtra("card", result.first);
|
intent.putExtra("card", result.first);
|
||||||
setResult(RESULT_OK, intent);
|
setResult(RESULT_OK, intent);
|
||||||
networkThread.cancel();
|
networkThread.cancel();
|
||||||
notificationThread.cancel();
|
|
||||||
finish();
|
finish();
|
||||||
} else {
|
|
||||||
if (null != result.second) {
|
|
||||||
notificationThread.addMessage(result.second);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -316,7 +238,8 @@ public abstract class AbstractScannerActivity extends AppCompatActivity {
|
|||||||
finish();
|
finish();
|
||||||
return true;
|
return true;
|
||||||
} else if (item.getItemId() == R.id.logout) {
|
} else if (item.getItemId() == R.id.logout) {
|
||||||
logoutDialog = LogoutDialogFragment.newInstance(mColor);
|
int color = (int) getIntent().getLongExtra(MainActivity.PREF_APP_BAR_COLOR, 0xffffff);
|
||||||
|
logoutDialog = LogoutDialogFragment.newInstance(color);
|
||||||
logoutDialog.show(getFragmentManager(), "logout");
|
logoutDialog.show(getFragmentManager(), "logout");
|
||||||
return true;
|
return true;
|
||||||
} else if (item.getItemId() == R.id.faq) {
|
} else if (item.getItemId() == R.id.faq) {
|
||||||
@@ -382,54 +305,4 @@ public abstract class AbstractScannerActivity extends AppCompatActivity {
|
|||||||
return builder.create();
|
return builder.create();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class NotificationThread extends Thread {
|
|
||||||
|
|
||||||
private final static int MAX_NOTIFICATION_MESSAGES = 2;
|
|
||||||
|
|
||||||
private boolean run = true;
|
|
||||||
private final Queue<String> queue;
|
|
||||||
private final AbstractScannerActivity ctx;
|
|
||||||
|
|
||||||
public NotificationThread(final @NonNull AbstractScannerActivity ctx) {
|
|
||||||
this.queue = new ArrayBlockingQueue<>(MAX_NOTIFICATION_MESSAGES);
|
|
||||||
this.ctx = ctx;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
while (run) {
|
|
||||||
if (null != queue.peek()) {
|
|
||||||
Log.d(TAG, "null != queue.peek()");
|
|
||||||
final String message = queue.poll();
|
|
||||||
Log.d(TAG, "message: " + message);
|
|
||||||
if (null != message) {
|
|
||||||
runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Toast.makeText(ctx, message, Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
Thread.sleep(300);
|
|
||||||
} catch (final InterruptedException ie) {
|
|
||||||
run = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addMessage(final @NonNull String message) {
|
|
||||||
if (queue.size() == MAX_NOTIFICATION_MESSAGES) {
|
|
||||||
Log.d(TAG, "Discard message: " + queue.poll());
|
|
||||||
}
|
|
||||||
queue.add(message);
|
|
||||||
Log.d(TAG, "Add message: " + message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void cancel() {
|
|
||||||
run = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +1,28 @@
|
|||||||
package com.dinect.checker;
|
package com.dinect.checker;
|
||||||
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.widget.Toast;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.Intent;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.NetworkInfo;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.dinect.checker.zbar.CameraActivity;
|
import com.dinect.checker.zbar.CameraActivity;
|
||||||
import com.dinect.checker.zxing.ScannerActivity;
|
import com.dinect.checker.zxing.ScannerActivity;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import io.flutter.app.FlutterActivity;
|
import io.flutter.app.FlutterActivity;
|
||||||
import io.flutter.plugins.GeneratedPluginRegistrant;
|
|
||||||
import io.flutter.plugin.common.MethodCall;
|
import io.flutter.plugin.common.MethodCall;
|
||||||
import io.flutter.plugin.common.MethodChannel;
|
import io.flutter.plugin.common.MethodChannel;
|
||||||
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
|
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
|
||||||
import io.flutter.plugin.common.MethodChannel.Result;
|
import io.flutter.plugin.common.MethodChannel.Result;
|
||||||
|
import io.flutter.plugins.GeneratedPluginRegistrant;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.lang.System;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class MainActivity extends FlutterActivity {
|
public class MainActivity extends FlutterActivity {
|
||||||
|
|
||||||
@@ -35,74 +35,81 @@ public class MainActivity extends FlutterActivity {
|
|||||||
static final String PREF_POS_TOKEN = "pref_pos_token";
|
static final String PREF_POS_TOKEN = "pref_pos_token";
|
||||||
static final String PREF_APP_BAR_COLOR = "pref_app_bar_color";
|
static final String PREF_APP_BAR_COLOR = "pref_app_bar_color";
|
||||||
|
|
||||||
|
public static final int ZXING = 0;
|
||||||
|
public static final int ZBAR = 1;
|
||||||
|
|
||||||
static final Class[] SCANNER_BACKEND = {
|
static final Class[] SCANNER_BACKEND = {
|
||||||
ScannerActivity.class,
|
ScannerActivity.class,
|
||||||
CameraActivity.class,
|
CameraActivity.class,
|
||||||
};
|
};
|
||||||
|
|
||||||
static final String SCANNER_BACKEND_KEY = "scanner_backend_idx";
|
static final String SCANNER_BACKEND_KEY = "scanner_backend_idx";
|
||||||
|
|
||||||
private MethodChannel mChannel;
|
private MethodChannel mChannel;
|
||||||
private SharedPreferences mPreferences;
|
private Map mScannerArgs;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
GeneratedPluginRegistrant.registerWith(this);
|
GeneratedPluginRegistrant.registerWith(this);
|
||||||
initLocale(this);
|
initLocale(this);
|
||||||
mPreferences = getPreferences(Context.MODE_PRIVATE);
|
|
||||||
|
|
||||||
mChannel = new MethodChannel(getFlutterView(), "com.dinect.checker/instance_id");
|
mChannel = new MethodChannel(getFlutterView(), "com.dinect.checker/instance_id");
|
||||||
mChannel.setMethodCallHandler(
|
mChannel.setMethodCallHandler(
|
||||||
new MethodCallHandler() {
|
new MethodCallHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void onMethodCall(MethodCall call, Result result) {
|
public void onMethodCall(MethodCall call, Result result) {
|
||||||
switch (call.method) {
|
callMethod(call, result);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void callMethod(MethodCall call, Result result) {
|
||||||
|
switch (call.method) {
|
||||||
case "getLocale":
|
case "getLocale":
|
||||||
result.success(BuildConfig.locale);
|
result.success(BuildConfig.locale);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "getFlavor":
|
case "getFlavor":
|
||||||
result.success(BuildConfig.flavor);
|
result.success(BuildConfig.flavor);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "getCurrency":
|
case "getCurrency":
|
||||||
result.success(BuildConfig.currency);
|
result.success(BuildConfig.currency);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "startScanner":
|
case "startScanner":
|
||||||
final Map arguments = call.arguments();
|
mScannerArgs = call.arguments();
|
||||||
final int idx = mPreferences.getInt(SCANNER_BACKEND_KEY, 0);
|
startScannerActivity();
|
||||||
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"));
|
|
||||||
cameraIntent.putExtra(PREF_APP_BAR_COLOR, (Long) arguments.get("color"));
|
|
||||||
startActivityForResult(cameraIntent, START_SCANNER_REQUEST_CODE);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "isOnline":
|
case "isOnline":
|
||||||
boolean online = Utils.isOnline(MainActivity.this);
|
checkInternetConnection(result);
|
||||||
if (!online) {
|
|
||||||
Toast.makeText(MainActivity.this, "Проверьте интернет соединение", Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
result.success(online);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
result.notImplemented();
|
result.notImplemented();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
private void checkInternetConnection(Result result) {
|
||||||
|
boolean connected = Utils.isOnline(this);
|
||||||
|
if (!connected)
|
||||||
|
Toast.makeText(this, "Проверьте интернет соединение", Toast.LENGTH_SHORT).show();
|
||||||
|
result.success(connected);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startScannerActivity() {
|
||||||
|
final int idx = getSharedPreferences("scanner", Context.MODE_PRIVATE).getInt(SCANNER_BACKEND_KEY, 0);
|
||||||
|
Intent cameraIntent = new Intent(MainActivity.this, SCANNER_BACKEND[idx]);
|
||||||
|
cameraIntent.putExtra(PREF_API_URL, (String) mScannerArgs.get("url"));
|
||||||
|
cameraIntent.putExtra(PREF_APP_TOKEN, (String) mScannerArgs.get("appToken"));
|
||||||
|
cameraIntent.putExtra(PREF_POS_TOKEN, (String) mScannerArgs.get("token"));
|
||||||
|
cameraIntent.putExtra(PREF_APP_BAR_COLOR, (Long) mScannerArgs.get("color"));
|
||||||
|
startActivityForResult(cameraIntent, START_SCANNER_REQUEST_CODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
if (requestCode == START_SCANNER_REQUEST_CODE && resultCode == RESULT_CANCELED) {
|
if (requestCode == START_SCANNER_REQUEST_CODE) {
|
||||||
|
if (resultCode == RESULT_CANCELED) {
|
||||||
finish();
|
finish();
|
||||||
} else if (requestCode == START_SCANNER_REQUEST_CODE && resultCode == RESULT_OK) {
|
} else if (resultCode == RESULT_OK) {
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
String user = data.getExtras().getString("user", null);
|
String user = data.getExtras().getString("user", null);
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
@@ -118,6 +125,9 @@ public class MainActivity extends FlutterActivity {
|
|||||||
mChannel.invokeMethod(menuItem, null);
|
mChannel.invokeMethod(menuItem, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
startScannerActivity();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,11 @@ public class Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isOnline(Context context) {
|
public static boolean isOnline(Context context) {
|
||||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
NetworkInfo netInfo = getConnectivityManager(context).getActiveNetworkInfo();
|
||||||
NetworkInfo netInfo = cm.getActiveNetworkInfo();
|
|
||||||
return netInfo != null && netInfo.isConnected();
|
return netInfo != null && netInfo.isConnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ConnectivityManager getConnectivityManager(Context context) {
|
||||||
|
return (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -93,7 +93,7 @@ public final class ApiClient {
|
|||||||
try {
|
try {
|
||||||
final Response response = http.newCall(request).execute();
|
final Response response = http.newCall(request).execute();
|
||||||
final String body = response.body().string();
|
final String body = response.body().string();
|
||||||
final String NOT_FOUND_MESSAGE = String.format(ctx.getString(R.string.identifier_not_found, card));
|
final String NOT_FOUND_MESSAGE = String.format(ctx.getString(R.string.identifier_not_found), card);
|
||||||
switch (response.code()) {
|
switch (response.code()) {
|
||||||
case 200:
|
case 200:
|
||||||
final JSONArray users = new JSONArray(body);
|
final JSONArray users = new JSONArray(body);
|
||||||
|
|||||||
@@ -79,8 +79,6 @@ public final class DinectAuthorizationInterceptor implements Interceptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final Request request = requestBuilder.url(url).headers(headers).build();
|
final Request request = requestBuilder.url(url).headers(headers).build();
|
||||||
final Response response = chain.proceed(request);
|
return chain.proceed(request);
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
package com.dinect.checker.zbar;
|
package com.dinect.checker.zbar;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.hardware.Camera;
|
import android.hardware.Camera;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.EditText;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.dinect.checker.AbstractScannerActivity;
|
import com.dinect.checker.AbstractScannerActivity;
|
||||||
@@ -19,7 +19,8 @@ import net.sourceforge.zbar.ImageScanner;
|
|||||||
import net.sourceforge.zbar.Symbol;
|
import net.sourceforge.zbar.Symbol;
|
||||||
import net.sourceforge.zbar.SymbolSet;
|
import net.sourceforge.zbar.SymbolSet;
|
||||||
|
|
||||||
public class CameraActivity extends AbstractScannerActivity implements Camera.PreviewCallback {
|
public class CameraActivity extends AbstractScannerActivity implements
|
||||||
|
Camera.PreviewCallback {
|
||||||
|
|
||||||
public static final String ERROR_INFO = "ERROR_INFO";
|
public static final String ERROR_INFO = "ERROR_INFO";
|
||||||
|
|
||||||
@@ -39,12 +40,12 @@ public class CameraActivity extends AbstractScannerActivity implements Camera.Pr
|
|||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
if (!init(R.layout.activity_zbar_scanner)) {
|
if (!init(R.layout.a_zbar)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
initNetwork(getIntent());
|
initNetwork(getIntent());
|
||||||
initToolbar(R.id.toolbar, getString(R.string.scanner_title));
|
initToolbar(getIntent());
|
||||||
|
|
||||||
mPreview = (CameraPreview) initScanner();
|
mPreview = (CameraPreview) initScanner();
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ package com.dinect.checker.zxing;
|
|||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.EditText;
|
||||||
|
|
||||||
import com.dinect.checker.AbstractScannerActivity;
|
import com.dinect.checker.AbstractScannerActivity;
|
||||||
import com.dinect.checker.R;
|
import com.dinect.checker.R;
|
||||||
@@ -42,11 +42,13 @@ public class ScannerActivity extends AbstractScannerActivity
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle state) {
|
public void onCreate(Bundle state) {
|
||||||
super.onCreate(state);
|
super.onCreate(state);
|
||||||
if (!init(R.layout.activity_zxing_scanner)) {
|
|
||||||
|
if (!init(R.layout.a_zxing)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
initNetwork(getIntent());
|
initNetwork(getIntent());
|
||||||
initToolbar(R.id.zxingToolbar, getString(R.string.scanner_title));
|
initToolbar(getIntent());
|
||||||
|
|
||||||
scannerView = (ZXingScannerView) initScanner();
|
scannerView = (ZXingScannerView) initScanner();
|
||||||
ArrayList<BarcodeFormat> formats = new ArrayList<>();
|
ArrayList<BarcodeFormat> formats = new ArrayList<>();
|
||||||
|
|||||||
@@ -41,11 +41,7 @@
|
|||||||
android:layout_marginTop="56dp"
|
android:layout_marginTop="56dp"
|
||||||
android:background="#00ff00" />
|
android:background="#00ff00" />
|
||||||
|
|
||||||
<android.support.v7.widget.Toolbar
|
<include layout="@layout/v_custom_toolbar" />
|
||||||
android:id="@+id/toolbar"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="?attr/actionBarSize"
|
|
||||||
app:titleTextColor="@android:color/white" />
|
|
||||||
|
|
||||||
<View
|
<View
|
||||||
android:id="@+id/toolbarShadow"
|
android:id="@+id/toolbarShadow"
|
||||||
@@ -6,11 +6,7 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="@android:color/white">
|
android:background="@android:color/white">
|
||||||
|
|
||||||
<android.support.v7.widget.Toolbar
|
<include layout="@layout/v_custom_toolbar" />
|
||||||
android:id="@+id/zxingToolbar"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="?attr/actionBarSize"
|
|
||||||
app:titleTextColor="@android:color/white" />
|
|
||||||
|
|
||||||
<View
|
<View
|
||||||
android:id="@+id/zxingToolbarShadow"
|
android:id="@+id/zxingToolbarShadow"
|
||||||
21
android/app/src/main/res/layout/v_custom_toolbar.xml
Normal file
21
android/app/src/main/res/layout/v_custom_toolbar.xml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:id="@+id/toolbar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="?attr/actionBarSize"
|
||||||
|
app:titleTextColor="@android:color/white">
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="?attr/actionBarSize"
|
||||||
|
android:id="@+id/manual_input"
|
||||||
|
android:hint="@string/enter_manual"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:inputType="text"
|
||||||
|
android:imeOptions="actionDone"
|
||||||
|
android:layout_marginLeft="72dp"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:textColorHint="@android:color/white"/>
|
||||||
|
|
||||||
|
</android.support.v7.widget.Toolbar>
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">AutoBonus</string>
|
<string name="app_name">AutoBonus</string>
|
||||||
<string name="scanner_title">Сканер карты</string>
|
<string name="scanner_title">Сканер карты</string>
|
||||||
<string name="scan">Сканировать</string>
|
<string name="scan">Сканировать</string>
|
||||||
@@ -10,4 +10,5 @@
|
|||||||
<string name="logout_yes">Да</string>
|
<string name="logout_yes">Да</string>
|
||||||
<string name="logout_no">Нет</string>
|
<string name="logout_no">Нет</string>
|
||||||
<string name="identifier_not_found">"Идентификатор %s не найден"</string>
|
<string name="identifier_not_found">"Идентификатор %s не найден"</string>
|
||||||
|
<string name="enter_manual">Введите штрихкод вручную</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ import 'package:flutter/material.dart';
|
|||||||
// Serious constants
|
// Serious constants
|
||||||
const String appName = "Autobonus";
|
const String appName = "Autobonus";
|
||||||
|
|
||||||
const String url = 'https://pos-api-autoclub.dinect.com/20130701/';
|
//const String url = 'https://pos-api-autoclub.dinect.com/20130701/';
|
||||||
const String appToken = 'bdea0f3ba9034b688019a7cac753d1209e2b227f';
|
//const String appToken = 'bdea0f3ba9034b688019a7cac753d1209e2b227f';
|
||||||
|
|
||||||
//const String url = 'https://pos-api-int.dinect.com/20130701/';
|
const String url = 'https://pos-api-int.dinect.com/20130701/';
|
||||||
//const String appToken = '9fec83cdca38c357e6b65dbb17514cdd36bf2a08';
|
const String appToken = '9fec83cdca38c357e6b65dbb17514cdd36bf2a08';
|
||||||
|
|
||||||
// Assets
|
// Assets
|
||||||
const String logout_png = 'assets/logout.png';
|
const String logout_png = 'assets/logout.png';
|
||||||
|
|||||||
Reference in New Issue
Block a user