start flutter plugin
parent
b09646b475
commit
c3cf63fdbe
|
|
@ -0,0 +1,77 @@
|
||||||
|
package kz.com.aman.kassa.bank;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import io.flutter.plugin.common.MethodCall;
|
||||||
|
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
|
||||||
|
import io.flutter.plugin.common.MethodChannel.Result;
|
||||||
|
import kz.com.aman.kassa.bank.permissions.PermissionsManager;
|
||||||
|
import kz.com.aman.kassa.bank.permissions.PermissionsManagerImpl;
|
||||||
|
import ru.m4bank.mpos.library.M4BankMposClientInterfaceFacade;
|
||||||
|
|
||||||
|
public class BankNfcPlugins implements MethodCallHandler {
|
||||||
|
//main activity
|
||||||
|
private Activity activity;
|
||||||
|
|
||||||
|
private String timer;
|
||||||
|
|
||||||
|
//main client all work with him
|
||||||
|
private M4BankMposClientInterfaceFacade clientInterface;
|
||||||
|
//permissions
|
||||||
|
private PermissionsManager permissionsManager;
|
||||||
|
|
||||||
|
public BankNfcPlugins(Activity activity) {
|
||||||
|
this.activity = activity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMethodCall(MethodCall call, Result result) {
|
||||||
|
switch (call.method) {
|
||||||
|
case "init":
|
||||||
|
PermissionsManager.PermissionsCheckResultHandler permissionsCheckResultHandler =
|
||||||
|
new PermissionsManager.PermissionsCheckResultHandler() {
|
||||||
|
@Override
|
||||||
|
public void onPermissionsGranted() {
|
||||||
|
System.out.println("granted");
|
||||||
|
activity.runOnUiThread(() -> Toast.makeText(activity, "Granted", Toast.LENGTH_SHORT).show());
|
||||||
|
//init();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPermissionsDeclined() {
|
||||||
|
System.out.println("Declined");
|
||||||
|
//init();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
permissionsManager = new PermissionsManagerImpl(this.activity);
|
||||||
|
permissionsManager.checkPermissions(permissionsCheckResultHandler);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if(timer==null){
|
||||||
|
timer = "inited)";
|
||||||
|
activity.runOnUiThread(() -> Toast.makeText(activity, "Initialize", Toast.LENGTH_SHORT).show());
|
||||||
|
} else {
|
||||||
|
activity.runOnUiThread(() -> Toast.makeText(activity, "Already Initialize", Toast.LENGTH_SHORT).show());
|
||||||
|
}
|
||||||
|
|
||||||
|
result.success("pong - 3");
|
||||||
|
break;
|
||||||
|
case "get":
|
||||||
|
final List<Object> json = new ArrayList<>();
|
||||||
|
for (int i =0; i < 2 ; i++) {
|
||||||
|
json.add("{\"name:\":\"test\" }"); // Map<String, Object> entries
|
||||||
|
}
|
||||||
|
result.success(json);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
result.notImplemented();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Other methods elided.
|
||||||
|
}
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
package kz.com.aman.kassa.bank;
|
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
public class MusicPlugin implements MethodCallHandler {
|
|
||||||
@Override
|
|
||||||
public void onMethodCall(MethodCall call, Result result) {
|
|
||||||
switch (call.method) {
|
|
||||||
case "ping":
|
|
||||||
|
|
||||||
result.success("pong - 3");
|
|
||||||
break;
|
|
||||||
case "get":
|
|
||||||
final List<Object> json = new ArrayList<>();
|
|
||||||
for (int i =0; i < 2 ; i++) {
|
|
||||||
json.add("{\"name:\":\"test\" }"); // Map<String, Object> entries
|
|
||||||
}
|
|
||||||
result.success(json);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
result.notImplemented();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Other methods elided.
|
|
||||||
}
|
|
||||||
|
|
@ -8,7 +8,7 @@ import io.flutter.embedding.engine.FlutterEngine
|
||||||
import io.flutter.plugin.common.MethodChannel
|
import io.flutter.plugin.common.MethodChannel
|
||||||
import io.flutter.plugins.GeneratedPluginRegistrant
|
import io.flutter.plugins.GeneratedPluginRegistrant
|
||||||
import kz.com.aman.kassa.bank.M4BankActivity
|
import kz.com.aman.kassa.bank.M4BankActivity
|
||||||
import kz.com.aman.kassa.bank.MusicPlugin
|
import kz.com.aman.kassa.bank.BankNfcPlugins
|
||||||
|
|
||||||
|
|
||||||
class MainActivity: FlutterActivity() {
|
class MainActivity: FlutterActivity() {
|
||||||
|
|
@ -19,7 +19,7 @@ class MainActivity: FlutterActivity() {
|
||||||
|
|
||||||
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
|
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
|
||||||
GeneratedPluginRegistrant.registerWith(flutterEngine);
|
GeneratedPluginRegistrant.registerWith(flutterEngine);
|
||||||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, BANK_CHANNEL).setMethodCallHandler(MusicPlugin());
|
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, BANK_CHANNEL).setMethodCallHandler(BankNfcPlugins(this.activity));
|
||||||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, ACTIVITY_CHANNEL).setMethodCallHandler {
|
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, ACTIVITY_CHANNEL).setMethodCallHandler {
|
||||||
// Note: this method is invoked on the main thread.
|
// Note: this method is invoked on the main thread.
|
||||||
call, result ->
|
call, result ->
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ class _BankViewState extends State<BankView> {
|
||||||
setState(() {
|
setState(() {
|
||||||
loading = true;
|
loading = true;
|
||||||
});
|
});
|
||||||
String result = await _channel.invokeMethod('ping');
|
String result = await _channel.invokeMethod('init');
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
value = result ?? 'none';
|
value = result ?? 'none';
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue