logout, индикатор загрузки на экране регистрации
This commit is contained in:
@@ -37,14 +37,15 @@ import net.sourceforge.zbar.Symbol;
|
|||||||
import net.sourceforge.zbar.SymbolSet;
|
import net.sourceforge.zbar.SymbolSet;
|
||||||
import net.sourceforge.zbar.Config;
|
import net.sourceforge.zbar.Config;
|
||||||
import android.graphics.YuvImage;
|
import android.graphics.YuvImage;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
|
||||||
import com.dinect.checker.R;
|
import com.dinect.checker.R;
|
||||||
|
|
||||||
public class CameraActivity extends AppCompatActivity {
|
public class CameraActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private Camera mCamera;
|
private Camera mCamera;
|
||||||
private Handler mAutoFocusHandler;
|
private Handler mAutoFocusHandler = new Handler();
|
||||||
private ImageScanner mScanner;
|
private ImageScanner mScanner = new ImageScanner();
|
||||||
private HashMap<String, Integer> mContours = new HashMap<>();
|
private HashMap<String, Integer> mContours = new HashMap<>();
|
||||||
|
|
||||||
private boolean mBarcodeScanned = false;
|
private boolean mBarcodeScanned = false;
|
||||||
@@ -56,13 +57,7 @@ public class CameraActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
setContentView(R.layout.a_scanner);
|
setContentView(R.layout.a_scanner);
|
||||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
|
||||||
|
|
||||||
mAutoFocusHandler = new Handler();
|
|
||||||
mCamera = getCameraInstance();
|
|
||||||
mScanner = new ImageScanner();
|
|
||||||
|
|
||||||
SurfaceView preview = (SurfaceView) findViewById(R.id.cameraPreview);
|
SurfaceView preview = (SurfaceView) findViewById(R.id.cameraPreview);
|
||||||
SurfaceHolder holder = preview.getHolder();
|
SurfaceHolder holder = preview.getHolder();
|
||||||
@@ -71,16 +66,18 @@ public class CameraActivity extends AppCompatActivity {
|
|||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
ActionBar actionBar = getSupportActionBar();
|
ActionBar actionBar = getSupportActionBar();
|
||||||
|
|
||||||
if (actionBar != null) {
|
if (actionBar != null) {
|
||||||
actionBar.setTitle(getString(R.string.scanner_title));
|
actionBar.setTitle(getString(R.string.scanner_title));
|
||||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
holder.addCallback(new SurfaceHolder.Callback() {
|
holder.addCallback(new SurfaceHolder.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void surfaceCreated(SurfaceHolder holder) {
|
public void surfaceCreated(SurfaceHolder holder) {
|
||||||
try {
|
try {
|
||||||
|
mCamera = getCameraInstance();
|
||||||
mCamera.setPreviewDisplay(holder);
|
mCamera.setPreviewDisplay(holder);
|
||||||
mCamera.startPreview();
|
mCamera.startPreview();
|
||||||
mCamera.setPreviewCallback(previewCallback);
|
mCamera.setPreviewCallback(previewCallback);
|
||||||
@@ -98,7 +95,7 @@ public class CameraActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void surfaceDestroyed(SurfaceHolder holder) {
|
public void surfaceDestroyed(SurfaceHolder holder) {
|
||||||
|
mCamera = null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -109,6 +106,16 @@ public class CameraActivity extends AppCompatActivity {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
if (item.getItemId() == R.id.logout) {
|
||||||
|
setResult(RESULT_OK);
|
||||||
|
finish();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void initCountours() {
|
private void initCountours() {
|
||||||
|
|
||||||
|
|||||||
@@ -7,72 +7,73 @@ import android.util.Log;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import com.dinect.checker.activity.CameraActivity;
|
import com.dinect.checker.activity.CameraActivity;
|
||||||
import com.dinect.checker.service.RegistrationIntentService;
|
import com.dinect.checker.service.RegistrationIntentService;
|
||||||
|
|
||||||
import io.flutter.app.FlutterActivity;
|
import io.flutter.app.FlutterActivity;
|
||||||
import io.flutter.plugins.GeneratedPluginRegistrant;
|
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 com.google.android.gms.iid.InstanceID;
|
import com.google.android.gms.iid.InstanceID;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class MainActivity extends FlutterActivity {
|
public class MainActivity extends FlutterActivity {
|
||||||
|
|
||||||
private static final String INSTANCE_ID_CHANNEL = "com.dinect.checker/instance_id";
|
private static final int START_SCANNER_REQUEST_CODE = 2017;
|
||||||
private static final String PREF_POS_TOKEN = "pref_pos_token";
|
|
||||||
|
private MethodChannel mChannel;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
GeneratedPluginRegistrant.registerWith(this);
|
GeneratedPluginRegistrant.registerWith(this);
|
||||||
|
|
||||||
|
final String INSTANCE_ID_CHANNEL = "com.dinect.checker/instance_id";
|
||||||
|
final String PREF_POS_TOKEN = "pref_pos_token";
|
||||||
final SharedPreferences preferences = getPreferences(Context.MODE_PRIVATE);
|
final SharedPreferences preferences = getPreferences(Context.MODE_PRIVATE);
|
||||||
|
|
||||||
new MethodChannel(getFlutterView(), INSTANCE_ID_CHANNEL).setMethodCallHandler(
|
mChannel = new MethodChannel(getFlutterView(), INSTANCE_ID_CHANNEL);
|
||||||
new MethodCallHandler() {
|
mChannel.setMethodCallHandler(
|
||||||
@Override
|
new MethodCallHandler() {
|
||||||
public void onMethodCall(MethodCall call, Result result) {
|
@Override
|
||||||
switch (call.method) {
|
public void onMethodCall(MethodCall call, Result result) {
|
||||||
|
switch (call.method) {
|
||||||
case "getInstanceID":
|
case "getInstanceID":
|
||||||
|
InstanceID instanceID = InstanceID.getInstance(MainActivity.this);
|
||||||
InstanceID instanceID = InstanceID.getInstance(MainActivity.this);
|
String id = instanceID.getId();
|
||||||
String id = instanceID.getId();
|
if (id != null) {
|
||||||
|
result.success(id);
|
||||||
if (id != null) {
|
} else {
|
||||||
result.success(id);
|
result.error("UNAVAILABLE", "Can't get instanceID.", null);
|
||||||
} else {
|
}
|
||||||
result.error("UNAVAILABLE", "Can't get instanceID.", null);
|
break;
|
||||||
}
|
case "saveToken":
|
||||||
break;
|
Map arguments = call.arguments();
|
||||||
|
String token = (String) arguments.get("token");
|
||||||
case "saveToken":
|
Log.d("kifio", token);
|
||||||
Map arguments = call.arguments();
|
preferences.edit().putString(PREF_POS_TOKEN, token).apply();
|
||||||
String token = (String) arguments.get("token");
|
break;
|
||||||
Log.d("kifio", token);
|
case "getToken":
|
||||||
preferences.edit().putString(PREF_POS_TOKEN, token).apply();
|
result.success(preferences.getString(PREF_POS_TOKEN, null));
|
||||||
break;
|
break;
|
||||||
|
case "startScanner":
|
||||||
case "getToken":
|
Intent cameraIntent = new Intent(MainActivity.this, CameraActivity.class);
|
||||||
result.success(preferences.getString(PREF_POS_TOKEN, null));
|
startActivityForResult(cameraIntent, START_SCANNER_REQUEST_CODE);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
case "startScanner":
|
result.notImplemented();
|
||||||
startActivity(new Intent(MainActivity.this, CameraActivity.class));
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
result.notImplemented();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
if (requestCode == START_SCANNER_REQUEST_CODE && resultCode == RESULT_OK) {
|
||||||
|
mChannel.invokeMethod("foo", null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void startScanner() {
|
public void startScanner() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 413 B |
Binary file not shown.
|
Before Width: | Height: | Size: 394 B |
Binary file not shown.
|
Before Width: | Height: | Size: 419 B |
Binary file not shown.
|
Before Width: | Height: | Size: 385 B |
@@ -1,17 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
|
|
||||||
<item android:state_pressed="true"><shape xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:shape="rectangle">
|
|
||||||
<corners android:radius="4dp"/>
|
|
||||||
<solid android:color="#3078c0"/>
|
|
||||||
</shape>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:shape="rectangle">
|
|
||||||
<corners android:radius="4dp"/>
|
|
||||||
<solid android:color="#4272e7"/>
|
|
||||||
</shape>
|
|
||||||
</item>
|
|
||||||
</selector>
|
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ void checkToken(BuildContext context, Callback callback) {
|
|||||||
callback.call(context);
|
callback.call(context);
|
||||||
} else {
|
} else {
|
||||||
// Запускается экран сканера, токен кассы активирован, с его помощью можно делать запросы к pos-api.
|
// Запускается экран сканера, токен кассы активирован, с его помощью можно делать запросы к pos-api.
|
||||||
startScanner();
|
startScanner(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
}).catchError((error) {
|
}).catchError((error) {
|
||||||
@@ -61,11 +61,24 @@ void checkToken(BuildContext context, Callback callback) {
|
|||||||
|
|
||||||
/// Запуск спецефичной для каждой платформы части приложения - сканера.
|
/// Запуск спецефичной для каждой платформы части приложения - сканера.
|
||||||
/// Может производиться с нескольких экранов (splash, finish_registration).
|
/// Может производиться с нескольких экранов (splash, finish_registration).
|
||||||
startScanner() async{
|
startScanner(BuildContext context) async{
|
||||||
const platform = const MethodChannel('com.dinect.checker/instance_id');
|
const platform = const MethodChannel('com.dinect.checker/instance_id');
|
||||||
|
platform.setMethodCallHandler((MethodCall call) async {
|
||||||
|
logout();
|
||||||
|
print(call.method);
|
||||||
|
// dynamic arguments = call.arguments;
|
||||||
|
// handle call then
|
||||||
|
return result;
|
||||||
|
// or
|
||||||
|
// throw new PlatformException(errorCode, anErrorMessage, someDetails);
|
||||||
|
});
|
||||||
await platform.invokeMethod('startScanner');
|
await platform.invokeMethod('startScanner');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logout() {
|
||||||
|
pushRute(_context, new RegistrationScreen());
|
||||||
|
}
|
||||||
|
|
||||||
/// Навигация по приложению.
|
/// Навигация по приложению.
|
||||||
/// widget - следующий экран приложения.
|
/// widget - следующий экран приложения.
|
||||||
pushRoute(BuildContext context, Widget widget) {
|
pushRoute(BuildContext context, Widget widget) {
|
||||||
@@ -77,7 +90,12 @@ pushRoute(BuildContext context, Widget widget) {
|
|||||||
|
|
||||||
class Checker extends StatelessWidget {
|
class Checker extends StatelessWidget {
|
||||||
@override Widget build(BuildContext context) {
|
@override Widget build(BuildContext context) {
|
||||||
return new MaterialApp(title: "DemoApp", home: new SplashScreen());
|
return new MaterialApp(title: "DemoApp",
|
||||||
|
home: new SplashScreen(),
|
||||||
|
theme: new ThemeData(
|
||||||
|
primaryColor: primaryColor,
|
||||||
|
accentColor: primaryColor
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,9 +105,6 @@ abstract class BaseState<T> extends State<StatefulWidget> {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void logout() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class Callback {
|
abstract class Callback {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ class RegistrationScreen extends StatefulWidget {
|
|||||||
class _RegistrationScreenState extends BaseState<RegistrationScreen> {
|
class _RegistrationScreenState extends BaseState<RegistrationScreen> {
|
||||||
|
|
||||||
String _merchantID = "";
|
String _merchantID = "";
|
||||||
|
bool _loading = false;
|
||||||
|
|
||||||
@override Widget build(BuildContext context) {
|
@override Widget build(BuildContext context) {
|
||||||
return new Scaffold(appBar: _getAppBar(), body: _getScreen(context));
|
return new Scaffold(appBar: _getAppBar(), body: _getScreen(context));
|
||||||
@@ -19,16 +20,14 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
|
|||||||
|
|
||||||
AppBar _getAppBar() {
|
AppBar _getAppBar() {
|
||||||
return new AppBar(title: new Text("Регистрация"),
|
return new AppBar(title: new Text("Регистрация"),
|
||||||
backgroundColor: primaryColor, actions: <Widget>[
|
actions: <Widget>[new IconButton(icon: new Icon(Icons.help_outline), onPressed: faq)]);
|
||||||
new IconButton(
|
|
||||||
icon: new Icon(Icons.help_outline),
|
|
||||||
tooltip: 'Air it',
|
|
||||||
onPressed: faq,
|
|
||||||
)
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _getScreen(BuildContext context) {
|
Widget _getScreen(BuildContext context) {
|
||||||
|
return new Stack(children: <Widget>[_getScreenContent(), _getProgressIndicator()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _getScreenContent() {
|
||||||
return new Container(height: 332.0,
|
return new Container(height: 332.0,
|
||||||
child: new ListView(reverse: true, children: <Widget>[
|
child: new ListView(reverse: true, children: <Widget>[
|
||||||
new Center(child: new Column(children: <Widget>[
|
new Center(child: new Column(children: <Widget>[
|
||||||
@@ -38,6 +37,10 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
|
|||||||
].reversed.toList()));
|
].reversed.toList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _getProgressIndicator() {
|
||||||
|
return new Center(child: _loading ? new CircularProgressIndicator() : null);
|
||||||
|
}
|
||||||
|
|
||||||
Widget _getLogo() {
|
Widget _getLogo() {
|
||||||
return new Container(height: 192.0, width: 156.0,
|
return new Container(height: 192.0, width: 156.0,
|
||||||
child: new Image.asset(logo_png, height: 24.0, width: 156.0));
|
child: new Image.asset(logo_png, height: 24.0, width: 156.0));
|
||||||
@@ -56,14 +59,6 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
|
|||||||
onChanged: (text) => _handleUserInput(text));
|
onChanged: (text) => _handleUserInput(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleUserInput(String text) {
|
|
||||||
if (text.length > 0) {
|
|
||||||
setState(() {
|
|
||||||
_merchantID = text;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Decoration _getDecoraionForInputField() {
|
Decoration _getDecoraionForInputField() {
|
||||||
return new BoxDecoration(color: Colors.white,
|
return new BoxDecoration(color: Colors.white,
|
||||||
border: new Border.all(color: const Color(0xffcfd8dc), width: 1.0,),
|
border: new Border.all(color: const Color(0xffcfd8dc), width: 1.0,),
|
||||||
@@ -71,19 +66,35 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _getButton(BuildContext context) {
|
Widget _getButton(BuildContext context) {
|
||||||
return new Container(margin: new EdgeInsets.only(top: 36.0), height: 42.0, padding: new EdgeInsets.only(left: 40.0, right: 40.0),
|
return new Container(margin: new EdgeInsets.only(top: 36.0), height: 42.0,
|
||||||
|
padding: new EdgeInsets.only(left: 40.0, right: 40.0),
|
||||||
child: new RaisedButton(child: new Text('ЗАРЕГИСТРИРОВАТЬ',
|
child: new RaisedButton(child: new Text('ЗАРЕГИСТРИРОВАТЬ',
|
||||||
style: new TextStyle(color: Colors.white)),
|
style: new TextStyle(color: Colors.white)),
|
||||||
onPressed: _isValidMerchantID() ? () => _registerShop(context, _merchantID) : null,
|
onPressed: _isValidMerchantID() ? () => _registerShop(context, _merchantID) : null,
|
||||||
color: primaryColor));
|
color: primaryColor));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _isValidMerchantID() {
|
Widget _getCircularProgressIndicator() {
|
||||||
|
return new Center(child: new CircularProgressIndicator());
|
||||||
|
}
|
||||||
|
|
||||||
|
_isValidMerchantID() {
|
||||||
return _merchantID.length == 5;
|
return _merchantID.length == 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _registerShop(BuildContext context, String merchantShop) {
|
_handleUserInput(String text) {
|
||||||
_register(context, merchantShop);
|
if (text.length > 0) {
|
||||||
|
setState(() {
|
||||||
|
_merchantID = text;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_registerShop(BuildContext context, String merchantShop) {
|
||||||
|
setState(() {
|
||||||
|
loading = true;
|
||||||
|
_register(context, merchantShop);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_register(BuildContext context, String merchantShop) async {
|
_register(BuildContext context, String merchantShop) async {
|
||||||
@@ -113,6 +124,9 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
|
|||||||
platform.invokeMethod('saveToken', {'token' : token}).then((value) {
|
platform.invokeMethod('saveToken', {'token' : token}).then((value) {
|
||||||
print(value.toString());
|
print(value.toString());
|
||||||
});
|
});
|
||||||
|
setState(() {
|
||||||
|
loading = false;
|
||||||
|
});
|
||||||
pushRoute(context, new FinishRegistrationScreen());
|
pushRoute(context, new FinishRegistrationScreen());
|
||||||
}).catchError((error) {
|
}).catchError((error) {
|
||||||
print(error.toString());
|
print(error.toString());
|
||||||
|
|||||||
@@ -27,11 +27,12 @@ class SplashScreen extends StatelessWidget {
|
|||||||
|
|
||||||
// В случае, если в приложении отсутствует токен,
|
// В случае, если в приложении отсутствует токен,
|
||||||
// необходимо запустить регистрацию кассы.
|
// необходимо запустить регистрацию кассы.
|
||||||
if (token == null) {
|
// if (token == null) {
|
||||||
pushRoute(context, new RegistrationScreen());
|
// pushRoute(context, new RegistrationScreen());
|
||||||
} else {
|
// } else {
|
||||||
checkToken(context, new CheckTokenCallback());
|
// checkToken(context, new CheckTokenCallback());
|
||||||
}
|
// }
|
||||||
|
startScanner(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -41,6 +42,7 @@ class CheckTokenCallback extends Callback {
|
|||||||
/// Запускается экран ожидания активации токена.
|
/// Запускается экран ожидания активации токена.
|
||||||
/// В реальности токен активируется в админке вручную,
|
/// В реальности токен активируется в админке вручную,
|
||||||
/// на тестовом сервере токен активируется через несколько минут после создания.
|
/// на тестовом сервере токен активируется через несколько минут после создания.
|
||||||
|
|
||||||
call(BuildContext context) {
|
call(BuildContext context) {
|
||||||
pushRoute(context, new FinishRegistrationScreen());
|
pushRoute(context, new FinishRegistrationScreen());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user