android BankActivity.kt

backend_nfc
Serik.Uvaissov 2020-07-10 09:36:27 +06:00
parent 9b2b0a805d
commit 8d6ec6bfe1
10 changed files with 179 additions and 103 deletions

View File

@ -74,6 +74,9 @@ flutter {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'

View File

@ -1,46 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.aman_kassa_flutter">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
<!--
io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
FlutterApplication and put your custom class here.
-->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<application
android:name="io.flutter.app.FlutterApplication"
android:label="Аман Касса"
android:icon="@mipmap/ic_launcher"
android:label="Аман Касса"
android:roundIcon="@mipmap/ic_launcher_rounded"
android:usesCleartextTraffic="true">
<activity android:name=".bank.BankActivity" android:theme="@android:style/Theme.Black.NoTitleBar"></activity>
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:theme="@style/LaunchTheme"
android:windowSoftInputMode="adjustResize">
<!-- <meta-data
<!--
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/> -->
<!-- <meta-data
/>
-->
<!--
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/splash"
/> -->
/>
-->
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<!--
Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java
-->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
</manifest>

View File

@ -0,0 +1,33 @@
package com.example.aman_kassa_flutter.bank
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.View
import com.example.aman_kassa_flutter.R
import io.flutter.app.FlutterActivity
class BankActivity : FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Log.i("BankActivity","onCreate")
setContentView(R.layout.activity_bank)
}
fun myClickHandler(view: View) {
Log.i("BankActivity","closed")
val returnIntent = Intent()
returnIntent.putExtra("result", "abrakadabra")
setResult(Activity.RESULT_OK, returnIntent)
finish()
}
override fun onDestroy() {
val returnIntent = Intent()
returnIntent.putExtra("result", "abrakadabra")
setResult(Activity.RESULT_CANCELED, returnIntent)
super.onDestroy()
}
}

View File

@ -1,15 +1,10 @@
package com.example.aman_kassa_flutter
import android.content.Context
import android.content.ContextWrapper
import android.app.Activity
import android.content.Intent
import android.content.IntentFilter
import android.content.pm.PackageManager
import android.net.Uri
import android.os.BatteryManager
import android.os.Build.VERSION
import android.os.Build.VERSION_CODES
import androidx.annotation.NonNull
import com.example.aman_kassa_flutter.bank.BankActivity
import com.example.aman_kassa_flutter.bank.MusicPlugin
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
@ -17,67 +12,44 @@ import io.flutter.plugins.GeneratedPluginRegistrant
class MainActivity: FlutterActivity() {
private val CHANNEL = "samples.flutter.dev/battery"
private val BANK_CHANNEL = "channel:com.amanKassa/bank"
private val ACTIVITY_CHANNEL = "channel:com.amanKassa/activity"
private lateinit var _result: MethodChannel.Result
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler {
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, BANK_CHANNEL).setMethodCallHandler(MusicPlugin());
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, ACTIVITY_CHANNEL).setMethodCallHandler {
// Note: this method is invoked on the main thread.
call, result ->
if (call.method == "getBatteryLevel") {
val batteryLevel = getBatteryLevel()
if (batteryLevel != -1) {
result.success(batteryLevel)
} else {
result.error("UNAVAILABLE", "Battery level not available.", null)
}
} else if (call.method == "sendMessage") {
val batteryLevel = sendMessage()
if (batteryLevel != -1) {
result.success(batteryLevel)
} else {
result.error("UNAVAILABLE", "Battery level not available.", null)
}
if (call.method == "start") {
_result = result
val intent= Intent(this, BankActivity::class.java)
startActivityForResult(intent, 8989)
//result.success("ActivityStarted")
} else {
result.notImplemented()
}
}
}
private fun getBatteryLevel(): Int {
val batteryLevel: Int
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
val batteryManager = getSystemService(Context.BATTERY_SERVICE) as BatteryManager
batteryLevel = batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY)
} else {
val intent = ContextWrapper(applicationContext).registerReceiver(null, IntentFilter(Intent.ACTION_BATTERY_CHANGED))
batteryLevel = intent!!.getIntExtra(BatteryManager.EXTRA_LEVEL, -1) * 100 / intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1)
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if(requestCode == 8989) {
if (resultCode == Activity.RESULT_OK) {
_result.success(data?.getStringExtra("result"))
} else if (resultCode == Activity.RESULT_CANCELED) {
_result.error("008", "123","aaa")
} else
_result.success(null)
}
println("batteryLevel");
println(batteryLevel);
return batteryLevel
}
private fun sendMessage(): Int {
val packageManager: PackageManager = context.packageManager
val i = Intent(Intent.ACTION_VIEW)
try {
val mobileNo: String = "77774904900" //call.argument("mobileNo")
val message: String = "Hello world" //call.argument("message")
//https://wa.me/919167370647?text=Yes%20We'll%20do%20this%20in%20frag4%20inOCW
println("mobileNo: $mobileNo message: $message")
val url = "https://wa.me/" + mobileNo.trim { it <= ' ' } + "?text=" + message.trim { it <= ' ' }
i.setPackage("com.whatsapp")
i.data = Uri.parse(url)
if (i.resolveActivity(packageManager) != null) {
context.startActivity(i)
}
println("finish method - 2")
} catch (e: Exception) {
e.printStackTrace()
}
return 25
}
}

View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/design_default_color_background"
tools:context=".bank.BankActivity"
>
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="32dp"
android:layout_marginRight="20dp">
<Button
android:id="@+id/buttonClose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="myClickHandler"
tools:text="@android:string/cancel" />
<ImageView
android:layout_width="82dp"
android:layout_height="82dp"
android:layout_alignParentRight="true"
android:src="@mipmap/ic_launcher_foreground" />
</RelativeLayout>
</androidx.appcompat.widget.LinearLayoutCompat>
</ScrollView>

View File

@ -0,0 +1 @@
<resources></resources>

View File

@ -5,4 +5,5 @@ const String PaymentViewRoute = "PaymentView";
const String HistoryViewRoute = "HistoryView";
const String InfoKkmViewRoute = "InfoKkmViewRoute";
const String QrViewRoute = "QrViewRoute";
const String BankViewRoute = "BankViewRoute";
// Generate the views here

View File

@ -1,3 +1,4 @@
import 'package:aman_kassa_flutter/views/bank_view/bank_view.dart';
import 'package:aman_kassa_flutter/views/check/image_show_container.dart';
import 'package:aman_kassa_flutter/views/history/history_view.dart';
import 'package:aman_kassa_flutter/views/info_kkm/info_kkm_view.dart';
@ -15,7 +16,9 @@ Route<dynamic> generateRoute(RouteSettings settings) {
LoginModel model = settings.arguments as LoginModel;
return _getPageRoute(
routeName: settings.name,
viewToShow: LoginView(loginModel: model,),
viewToShow: LoginView(
loginModel: model,
),
);
case HomeViewRoute:
return _getPageRoute(
@ -38,6 +41,11 @@ Route<dynamic> generateRoute(RouteSettings settings) {
routeName: settings.name,
viewToShow: InfoKkmView(),
);
case BankViewRoute:
return _getPageRoute(
routeName: settings.name,
viewToShow: BankView(),
);
case QrViewRoute:
ImageShowModel data = settings.arguments as ImageShowModel;
return _getPageRoute(

View File

@ -5,13 +5,13 @@ import 'package:flutter/material.dart';
const List<Choice> choices = const <Choice>[
//const Choice(title: 'Обновить номенклатуру', icon: Icons.update, command: 'update'),
//const Choice(title: 'Помощь', icon: Icons.help, command: 'help'),
const Choice(title: 'Информацио о ККМ', icon: Icons.info_outline, command: 'infokkm'),
//const Choice(title: 'Язык', icon: Icons.language, command: 'language'),
const Choice(
title: 'Информацио о ККМ', icon: Icons.info_outline, command: 'infokkm'),
const Choice(title: 'Bank', icon: Icons.text_fields, command: 'bank'),
const Choice(title: 'Выйти', icon: Icons.exit_to_app, command: 'exit')
];
class PopupMenu extends StatelessWidget {
final void Function(Choice value) onSelectChoice;
PopupMenu({this.onSelectChoice});
@ -28,11 +28,18 @@ class PopupMenu extends StatelessWidget {
return choices.map((Choice choice) {
return PopupMenuItem<Choice>(
value: choice,
child: Row(children: <Widget>[
Icon(choice.icon, color: primaryColor,),
SizedBox(width: 5,),
Text(choice.title)
], ),
child: Row(
children: <Widget>[
Icon(
choice.icon,
color: primaryColor,
),
SizedBox(
width: 5,
),
Text(choice.title)
],
),
);
}).toList();
},

View File

@ -57,13 +57,16 @@ class _HomeViewState extends State<HomeView> {
void _onSelectChoice(Choice choice) async {
if (choice.command == 'exit') {
Dialogs.showLoadingDialog(context, _keyLoader);
Response<dynamic> result = await _api.logout(Redux.store.state.userState.user.token);
if(result.operation && result.status == 200) {
Response<dynamic> result =
await _api.logout(Redux.store.state.userState.user.token);
if (result.operation && result.status == 200) {
Redux.store.dispatch(logoutAction);
}
Navigator.of(_keyLoader.currentContext, rootNavigator: true).pop();
} else if (choice.command == 'infokkm') {
_navigatorService.push(InfoKkmViewRoute);
} else if (choice.command == 'bank') {
_navigatorService.push(BankViewRoute);
}
}
@ -81,26 +84,25 @@ class _HomeViewState extends State<HomeView> {
],
backgroundColor: fillColor,
),
body:StoreConnector<AppState, SettingState>(
converter: (store) => store.state.settingState,
builder: (context, vm) {
return PageView(
onPageChanged: (index) {
setState(() {
selectedTabIndex = index;
});
},
controller: pageController,
children: <Widget>[
vm.mode == SettingModeKassa ? KassaTab(0) : CalculatorTab(0),
AdditionalTab(1),
],
);
}
),
body: StoreConnector<AppState, SettingState>(
converter: (store) => store.state.settingState,
builder: (context, vm) {
return PageView(
onPageChanged: (index) {
setState(() {
selectedTabIndex = index;
});
},
controller: pageController,
children: <Widget>[
vm.mode == SettingModeKassa ? KassaTab(0) : CalculatorTab(0),
AdditionalTab(1),
],
);
}),
bottomNavigationBar: BottomBar(
pageController: pageController,
selectedTabIndex: selectedTabIndex,
pageController: pageController,
selectedTabIndex: selectedTabIndex,
),
);
}