优化小屏刷新
diff --git a/app/src/main/java/com/supwisdom/activities/auxscreen/AuxScreenController.kt b/app/src/main/java/com/supwisdom/activities/auxscreen/AuxScreenController.kt
index 2e81b1c..9f9ebc8 100644
--- a/app/src/main/java/com/supwisdom/activities/auxscreen/AuxScreenController.kt
+++ b/app/src/main/java/com/supwisdom/activities/auxscreen/AuxScreenController.kt
@@ -1,263 +1,297 @@
-package com.supwisdom.auxscreen
-
-import android.graphics.Color
-import com.newcapec.jni.AuxScreen
-import com.supwisdom.utils.CommonUtil
-import java.util.concurrent.locks.ReentrantLock
-
-/**
- * @author gqy
- * @version 1.0.1
- * @date 2018/7/11
- * @desc 小屏控制器
- */
-class AuxScreenController private constructor() {
- private var auxScreen = AuxScreen()
- private val xStart = 15
- private val xSecStart = 240
- private val sTitle = "refreshTitle"
- private val sContent = "refreshContent"
- private val sBottom = "refreshBottom"
- private val lock = ReentrantLock()
- private val refreshMap = hashMapOf<String, Any>()
- private val auxRunnable = AuxRunnable()
- private var isExit = false
- private var taskThread: Thread? = null
-
- companion object {
- @Volatile
- private var auxController: AuxScreenController? = null
-
- fun getInstance(): AuxScreenController {
- if (null == auxController) {
- synchronized(AuxScreenController::class.java) {
- if (null == auxController) {
- auxController = AuxScreenController()
- }
- }
- }
- return auxController!!
- }
- }
-
- /**
- * 刷新标题栏
- * @param title 标题
- */
- fun refreshTitle(title: String) {
- lock.lock()
- refreshMap[sTitle] = title
- lock.unlock()
- }
-
- private fun localRefreshTitle(title: String) {
- auxScreen.setBgcolor(Color.parseColor("#FFFFFF"))
- auxScreen.clrLine(0, 50)
- auxScreen.setBgcolor(Color.parseColor("#FFFFFF"))
- auxScreen.setFontSize(20)
- auxScreen.setFgcolor(Color.parseColor("#000000"))
- auxScreen.textOut(xStart, 15, title)
- }
-
- /**
- * 内容显示
- * @param list 显示内容 size<=5
- */
- fun refreshContent(list: List<String>) {
- lock.lock()
- refreshMap[sContent] = list
- lock.unlock()
- }
-
- private fun localRefreshContent(list: List<String>) {
- auxScreen.setBgcolor(Color.parseColor("#F2F2F2"))
- clearCenterContent()
-
- val size = list.size
- auxScreen.setFgcolor(Color.parseColor("#000000"))
- when (size) {
- 0 -> {
-
- }
- 1 -> {
- auxScreen.setFontSize(40)
- auxScreen.textOut(xStart, 140, getNotEmptyString(list[0]))
- }
- 2 -> {
- auxScreen.setFontSize(35)
- for (index in 0 until size) {
- auxScreen.textOut(xStart, 120 + 60 * index, getNotEmptyString(list[index]))
- }
- }
- 3 -> {
- auxScreen.setFontSize(30)
- for (index in 0 until size) {
- auxScreen.textOut(xStart, 100 + 50 * index, getNotEmptyString(list[index]))
- }
- }
- 4 -> {
- auxScreen.setFontSize(25)
- for (index in 0 until size) {
- auxScreen.textOut(xStart, 80 + 45 * index, getNotEmptyString(list[index]))
- }
- }
- 5 -> {
- auxScreen.setFontSize(20)
- for (index in 0 until size) {
- auxScreen.textOut(xStart, 70 + 40 * index, getNotEmptyString(list[index]))
- }
- }
- 6 -> {
- auxScreen.setFontSize(15)
- for (index in 0 until size) {
- auxScreen.textOut(xStart, 60 + 35 * index, getNotEmptyString(list[index]))
- }
- }
- 7, 8 -> {
- auxScreen.setFontSize(25)
- for (index in 0 until (size + 1) / 2) {
- auxScreen.textOut(xStart, 80 + 45 * index, getNotEmptyString(list[2 * index]))
- if (2 * index + 1 < size) {
- auxScreen.textOut(xSecStart, 80 + 45 * index, getNotEmptyString(list[2 * index + 1]))
- }
- }
- }
- 9, 10 -> {
- auxScreen.setFontSize(20)
- for (index in 0 until (size + 1) / 2) {
- auxScreen.textOut(xStart, 70 + 40 * index, getNotEmptyString(list[2 * index]))
- if (2 * index + 1 < size) {
- auxScreen.textOut(xSecStart, 70 + 40 * index, getNotEmptyString(list[2 * index + 1]))
- }
- }
- }
- else -> {
- auxScreen.setFontSize(15)
- for (index in 0 until (size + 1) / 2) {
- auxScreen.textOut(xStart, 60 + 35 * index, getNotEmptyString(list[2 * index]))
- if (2 * index + 1 < size) {
- auxScreen.textOut(xSecStart, 60 + 35 * index, getNotEmptyString(list[2 * index + 1]))
- }
- }
- }
- }
- }
-
- /**
- * 处理输入的空字符串
- */
- private fun getNotEmptyString(input: String?): String {
- if (input == null || input.isEmpty()) {
- return " "
- }
- return input
- }
-
- /**
- * 刷新底部状态
- * @param bottom 提示
- */
- fun refreshBottom(bottom: String) {
- lock.lock()
- refreshMap[sBottom] = bottom
- lock.unlock()
- }
-
- private fun localRefreshBootom(bottom: String) {
- auxScreen.setBgcolor(Color.parseColor("#FFFFFF"))
- auxScreen.clrLine(269, 319)
-
- auxScreen.setFontSize(20)
- auxScreen.setFgcolor(Color.parseColor("#000000"))
- auxScreen.textOut(15, 284, bottom)
- }
-
- /**
- * 清空中间的内容
- * @注意:此处必须一行一行的清除,底层bug
- */
- private fun clearCenterContent() {
- auxScreen.clrLine(50, 100)
- auxScreen.clrLine(100, 150)
- auxScreen.clrLine(150, 200)
- auxScreen.clrLine(200, 250)
- auxScreen.clrLine(250, 269)
- auxScreen.setFontSize(50)
- }
-
- /**
- * 打开小屏
- */
- fun open() {
- auxScreen.open()
- if (taskThread == null) {
- isExit = false
- taskThread = Thread(auxRunnable)
- taskThread!!.start()
- }
- }
-
- /**
- * 关闭小屏
- */
- fun close() {
- auxScreen.close()
- isExit = true
- taskThread?.interrupt()
- taskThread = null
- }
-
- /**
- * 初始化小屏
- */
- private fun init() {
- auxScreen.setBgcolor(Color.parseColor("#F2F2F2"))
- auxScreen.cls()
- auxScreen.setSpace(5, 5)
- auxScreen.selectFont(AuxScreen.FONT_CODE_UTF8)
- }
-
- inner class AuxRunnable : Runnable {
- override fun run() {
- init()
- while (!isExit) {
- try {
- try {
- lock.lock()
- val title = refreshMap[sTitle]
- if (title != null) {
- localRefreshTitle(title as String)
- refreshMap.remove(sTitle)
- }
- } finally {
- lock.unlock()
- }
- try {
- lock.lock()
- val content = refreshMap[sContent]
- if (content != null) {
- localRefreshContent(content as List<String>)
- refreshMap.remove(sContent)
- }
- } finally {
- lock.unlock()
- }
- try {
- lock.lock()
- val bottom = refreshMap[sBottom]
- if (bottom != null) {
- localRefreshBootom(bottom as String)
- refreshMap.remove(sBottom)
- }
- } finally {
- lock.unlock()
- }
- } catch (ex: Exception) {
- ex.printStackTrace()
- }
- CommonUtil.doSleep(25)
- }
- }
- }
-}
-
+package com.supwisdom.activities.auxscreen
+
+import android.graphics.Color
+import com.newcapec.jni.AuxScreen
+import com.supwisdom.utils.CommonUtil
+import com.supwisdom.utils.LogUtil
+import java.util.concurrent.locks.ReentrantLock
+
+/**
+ * @author gqy
+ * @version 1.0.1
+ * @date 2018/7/11
+ * @desc 小屏控制器
+ */
+class AuxScreenController private constructor() {
+ private val TAG = "AuxScreenController"
+ private var auxScreen = AuxScreen()
+ private val xStart = 15
+ private val xSecStart = 240
+ private val sTitle = "refreshTitle"
+ private val sContent = "refreshContent"
+ private val sBottom = "refreshBottom"
+ private val lock = ReentrantLock()
+ private val refreshMap = hashMapOf<String, Any>()
+ private val auxRunnable = AuxRunnable()
+ private var taskThread: Thread? = null
+
+ companion object {
+ @Volatile
+ private var auxController: AuxScreenController? = null
+
+ fun getInstance(): AuxScreenController {
+ if (null == auxController) {
+ synchronized(AuxScreenController::class.java) {
+ if (null == auxController) {
+ auxController = AuxScreenController()
+ }
+ }
+ }
+ return auxController!!
+ }
+ }
+
+ /**
+ * 刷新标题栏
+ * @param title 标题
+ */
+ fun refreshTitle(title: String) {
+ lock.lock()
+ refreshMap[sTitle] = title
+ lock.unlock()
+ }
+
+ private fun localRefreshTitle(title: String) {
+ auxScreen.setBgcolor(Color.parseColor("#FFFFFF"))
+ auxScreen.clrLine(0, 50)
+ auxScreen.setBgcolor(Color.parseColor("#FFFFFF"))
+ auxScreen.setFontSize(20)
+ auxScreen.setFgcolor(Color.parseColor("#000000"))
+ auxScreen.textOut(xStart, 15, title)
+ }
+
+ /**
+ * 内容显示
+ * @param list 显示内容 size<=5
+ */
+ fun refreshContent(list: List<String>) {
+ lock.lock()
+ refreshMap[sContent] = list
+ lock.unlock()
+ }
+
+ private fun localRefreshContent(list: List<String>) {
+ auxScreen.setBgcolor(Color.parseColor("#F2F2F2"))
+ clearCenterContent()
+
+ val size = list.size
+ auxScreen.setFgcolor(Color.parseColor("#000000"))
+ when (size) {
+ 0 -> {
+
+ }
+ 1 -> {
+ auxScreen.setFontSize(40)
+ auxScreen.textOut(xStart, 140, getNotEmptyString(list[0]))
+ }
+ 2 -> {
+ auxScreen.setFontSize(35)
+ for (index in 0 until size) {
+ auxScreen.textOut(xStart, 120 + 60 * index, getNotEmptyString(list[index]))
+ }
+ }
+ 3 -> {
+ auxScreen.setFontSize(30)
+ for (index in 0 until size) {
+ auxScreen.textOut(xStart, 100 + 50 * index, getNotEmptyString(list[index]))
+ }
+ }
+ 4 -> {
+ auxScreen.setFontSize(25)
+ for (index in 0 until size) {
+ auxScreen.textOut(xStart, 80 + 45 * index, getNotEmptyString(list[index]))
+ }
+ }
+ 5 -> {
+ auxScreen.setFontSize(20)
+ for (index in 0 until size) {
+ auxScreen.textOut(xStart, 70 + 40 * index, getNotEmptyString(list[index]))
+ }
+ }
+ 6 -> {
+ auxScreen.setFontSize(15)
+ for (index in 0 until size) {
+ auxScreen.textOut(xStart, 60 + 35 * index, getNotEmptyString(list[index]))
+ }
+ }
+ 7, 8 -> {
+ auxScreen.setFontSize(25)
+ for (index in 0 until (size + 1) / 2) {
+ auxScreen.textOut(xStart, 80 + 45 * index, getNotEmptyString(list[2 * index]))
+ if (2 * index + 1 < size) {
+ auxScreen.textOut(
+ xSecStart,
+ 80 + 45 * index,
+ getNotEmptyString(list[2 * index + 1])
+ )
+ }
+ }
+ }
+ 9, 10 -> {
+ auxScreen.setFontSize(20)
+ for (index in 0 until (size + 1) / 2) {
+ auxScreen.textOut(xStart, 70 + 40 * index, getNotEmptyString(list[2 * index]))
+ if (2 * index + 1 < size) {
+ auxScreen.textOut(
+ xSecStart,
+ 70 + 40 * index,
+ getNotEmptyString(list[2 * index + 1])
+ )
+ }
+ }
+ }
+ else -> {
+ auxScreen.setFontSize(15)
+ for (index in 0 until (size + 1) / 2) {
+ auxScreen.textOut(xStart, 60 + 35 * index, getNotEmptyString(list[2 * index]))
+ if (2 * index + 1 < size) {
+ auxScreen.textOut(
+ xSecStart,
+ 60 + 35 * index,
+ getNotEmptyString(list[2 * index + 1])
+ )
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * 处理输入的空字符串
+ */
+ private fun getNotEmptyString(input: String?): String {
+ if (input == null || input.isEmpty()) {
+ return " "
+ }
+ return input
+ }
+
+ /**
+ * 刷新底部状态
+ * @param bottom 提示
+ */
+ fun refreshBottom(bottom: String) {
+ lock.lock()
+ refreshMap[sBottom] = bottom
+ lock.unlock()
+ }
+
+ private fun localRefreshBootom(bottom: String) {
+ auxScreen.setBgcolor(Color.parseColor("#FFFFFF"))
+ auxScreen.clrLine(269, 319)
+
+ auxScreen.setFontSize(20)
+ auxScreen.setFgcolor(Color.parseColor("#000000"))
+ auxScreen.textOut(15, 284, bottom)
+ }
+
+ /**
+ * 清空中间的内容
+ * @注意:此处必须一行一行的清除,底层bug
+ */
+ private fun clearCenterContent() {
+ auxScreen.clrLine(50, 100)
+ auxScreen.clrLine(100, 150)
+ auxScreen.clrLine(150, 200)
+ auxScreen.clrLine(200, 250)
+ auxScreen.clrLine(250, 269)
+ auxScreen.setFontSize(50)
+ }
+
+ /**
+ * 打开小屏
+ */
+ @Synchronized
+ fun open() {
+ auxScreen.open()
+ if (taskThread == null) {
+ taskThread = Thread(auxRunnable)
+ taskThread!!.start()
+ }
+ }
+
+ /**
+ * 关闭小屏
+ */
+ @Synchronized
+ fun close() {
+ auxScreen.close()
+ taskThread?.interrupt()
+ taskThread = null
+ }
+
+ /**
+ * 初始化小屏
+ */
+ private fun init() {
+ auxScreen.setBgcolor(Color.parseColor("#F2F2F2"))
+ auxScreen.cls()
+ auxScreen.setSpace(5, 5)
+ auxScreen.selectFont(AuxScreen.FONT_CODE_UTF8)
+ }
+
+ private inner class AuxRunnable : Runnable {
+ override fun run() {
+ init()
+ var lastTitle = ""
+ var lastBottom = ""
+ while (!Thread.currentThread().isInterrupted) {
+ try {
+ if (lock.tryLock()) {
+ val title = refreshMap[sTitle]
+ if (title != null) {
+ if (lastTitle != title) {
+ localRefreshTitle(title as String)
+ lastTitle = title
+ }
+ refreshMap.remove(sTitle)
+ }
+ lock.unlock()
+ }
+ if (lock.tryLock()) {
+ val content = refreshMap[sContent]
+ if (content != null) {
+ localRefreshContent(content as List<String>)
+ refreshMap.remove(sContent)
+ }
+ lock.unlock()
+ }
+ if (lock.tryLock()) {
+ val bottom = refreshMap[sBottom]
+ if (bottom != null) {
+ if (lastBottom != bottom) {
+ localRefreshBootom(bottom as String)
+ lastBottom = bottom
+ }
+ refreshMap.remove(sBottom)
+ }
+ lock.unlock()
+ }
+ } catch (ex: InterruptedException) {
+ ex.printStackTrace()
+ LogUtil.e(
+ TAG,
+ "aux screen AuxRunnable InterruptedException,ex=${
+ CommonUtil.getExceptionStack(ex)
+ }"
+ )
+ return
+ }
+ try {
+ Thread.sleep(22)
+ } catch (ex: InterruptedException) {
+ ex.printStackTrace()
+ LogUtil.e(
+ TAG,
+ "aux screen AuxRunnable InterruptedException,ex=${
+ CommonUtil.getExceptionStack(ex)
+ }"
+ )
+ return
+ }
+ }
+ LogUtil.e(TAG, "aux screen runnable is close!!!!")
+ }
+ }
+}
+
diff --git a/app/src/main/java/com/supwisdom/activities/cardlib/CardlibActivity.kt b/app/src/main/java/com/supwisdom/activities/cardlib/CardlibActivity.kt
index 1417fe2..aeb5ef4 100644
--- a/app/src/main/java/com/supwisdom/activities/cardlib/CardlibActivity.kt
+++ b/app/src/main/java/com/supwisdom/activities/cardlib/CardlibActivity.kt
@@ -1,121 +1,122 @@
-package com.supwisdom.activities.cardlib
-
-import android.os.Bundle
-import android.view.KeyEvent
-import android.view.View
-import android.view.Window
-import android.widget.ProgressBar
-import android.widget.TextView
-import com.supwisdom.R
-import com.supwisdom.activities.BaseActivity
-import com.supwisdom.activities.SPApplication
-import com.supwisdom.activities.init.InitActivity
-import com.supwisdom.activities.load.LoadActivity
-import com.supwisdom.auxscreen.AuxScreenController
-import com.supwisdom.utils.AppExitUtil
-import com.supwisdom.utils.DateUtil
-import com.supwisdom.view.BigProgressDialog
-
-/**
- ** create by zzq on 2019/7/25
- ** @desc
- **/
-@Suppress("DEPRECATION")
-class CardlibActivity : BaseActivity(), ICardlibView {
- private val pos = SPApplication.getInstance().getPos()
- private lateinit var vResult: TextView
- private var vProgressBar: ProgressBar? = null
- private var presenter: CardlibPresenter? = null
- @Volatile
- private var isLoading = false
-
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- //在窗口标题上显示带进度的横向进度条
- requestWindowFeature(Window.FEATURE_PROGRESS)
- //显示不带进度的进度条
- requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS)
-
- setContentView(R.layout.activity_cardlib)
- initView()
- initData()
- }
-
- private fun initData() {
- presenter = CardlibPresenter(this)
- }
-
- private fun initView() {
- vProgressBar = this.findViewById(R.id.cardlib_bar) as ProgressBar
- vResult = this.findViewById(R.id.cardlib_result) as TextView
- }
-
- override fun showProgress(progress: Int) {
- vProgressBar!!.progress = progress
- }
-
- override fun onResume() {
- super.onResume()
- if (!isLoading) {
- isLoading = true
- refresh()
- presenter!!.initCardlib(this)
- }
- }
-
- override fun dispatchKeyEvent(event: KeyEvent): Boolean {
- if (event.action == KeyEvent.ACTION_DOWN) {
- if (isLoading) {
- return false
- }
- when (event.keyCode) {
- KeyEvent.KEYCODE_DEL -> {
- AppExitUtil.exit()
- }
- }
- }
- return super.dispatchKeyEvent(event)
- }
-
- private fun refresh() {
- AuxScreenController.getInstance().refreshTitle("卡库初始化")
- AuxScreenController.getInstance().refreshBottom(DateUtil.getNowDateTime())
- AuxScreenController.getInstance().refreshContent(listOf("加载硬件驱动", "请稍等..."))
- }
-
- override fun showInitCardlibResult(issuccess: Boolean, msg: String) {
- if (issuccess) {
- val record = pos.getConfigPara()
- if (record != null && record.initOK && pos.getDynamicPara() != null) {
- jumpActivity(LoadActivity::class.java)
- } else {
- jumpActivity(InitActivity::class.java)
- }
- } else {
- vResult.text = msg
- vResult.visibility = View.VISIBLE
- AuxScreenController.getInstance().refreshTitle("卡库初始化")
- AuxScreenController.getInstance().refreshBottom(DateUtil.getNowDateTime())
- AuxScreenController.getInstance().refreshContent(listOf("请联系管理员", "加载驱动失败", "原因:", msg))
- }
- isLoading = false
- }
-
- private var dialogProgress: BigProgressDialog? = null
-
- override fun showProgressDialog(msg: String) {
- if (dialogProgress == null) {
- dialogProgress = BigProgressDialog(this, msg, false)
- }
- dialogProgress!!.setMsg(msg)
- dialogProgress!!.show()
- }
-
- override fun closeProgressDialog() {
- dialogProgress?.dismiss()
- }
-
- override fun onDestroy() {
- super.onDestroy()
- }
+package com.supwisdom.activities.cardlib
+
+import android.os.Bundle
+import android.view.KeyEvent
+import android.view.View
+import android.view.Window
+import android.widget.ProgressBar
+import android.widget.TextView
+import com.supwisdom.R
+import com.supwisdom.activities.BaseActivity
+import com.supwisdom.activities.SPApplication
+import com.supwisdom.activities.auxscreen.AuxScreenController
+import com.supwisdom.activities.init.InitActivity
+import com.supwisdom.activities.load.LoadActivity
+import com.supwisdom.utils.AppExitUtil
+import com.supwisdom.utils.DateUtil
+import com.supwisdom.view.BigProgressDialog
+
+/**
+ ** create by zzq on 2019/7/25
+ ** @desc
+ **/
+@Suppress("DEPRECATION")
+class CardlibActivity : BaseActivity(), ICardlibView {
+ private val pos = SPApplication.getInstance().getPos()
+ private lateinit var vResult: TextView
+ private var vProgressBar: ProgressBar? = null
+ private var presenter: CardlibPresenter? = null
+
+ @Volatile
+ private var isLoading = false
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ //在窗口标题上显示带进度的横向进度条
+ requestWindowFeature(Window.FEATURE_PROGRESS)
+ //显示不带进度的进度条
+ requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS)
+
+ setContentView(R.layout.activity_cardlib)
+ initView()
+ initData()
+ }
+
+ private fun initData() {
+ presenter = CardlibPresenter(this)
+ }
+
+ private fun initView() {
+ vProgressBar = this.findViewById(R.id.cardlib_bar) as ProgressBar
+ vResult = this.findViewById(R.id.cardlib_result) as TextView
+ }
+
+ override fun showProgress(progress: Int) {
+ vProgressBar!!.progress = progress
+ }
+
+ override fun onResume() {
+ super.onResume()
+ if (!isLoading) {
+ isLoading = true
+ refresh()
+ presenter!!.initCardlib(this)
+ }
+ }
+
+ override fun dispatchKeyEvent(event: KeyEvent): Boolean {
+ if (event.action == KeyEvent.ACTION_DOWN) {
+ if (isLoading) {
+ return false
+ }
+ when (event.keyCode) {
+ KeyEvent.KEYCODE_DEL -> {
+ AppExitUtil.exit()
+ }
+ }
+ }
+ return super.dispatchKeyEvent(event)
+ }
+
+ private fun refresh() {
+ AuxScreenController.getInstance().refreshTitle("卡库初始化")
+ AuxScreenController.getInstance().refreshBottom(DateUtil.getNowDateTime())
+ AuxScreenController.getInstance().refreshContent(listOf("加载硬件驱动", "请稍等..."))
+ }
+
+ override fun showInitCardlibResult(issuccess: Boolean, msg: String) {
+ if (issuccess) {
+ val record = pos.getConfigPara()
+ if (record != null && record.initOK && pos.getDynamicPara() != null) {
+ jumpActivity(LoadActivity::class.java)
+ } else {
+ jumpActivity(InitActivity::class.java)
+ }
+ } else {
+ vResult.text = msg
+ vResult.visibility = View.VISIBLE
+ AuxScreenController.getInstance().refreshTitle("卡库初始化")
+ AuxScreenController.getInstance().refreshBottom(DateUtil.getNowDateTime())
+ AuxScreenController.getInstance().refreshContent(listOf("请联系管理员", "加载驱动失败", "原因:", msg))
+ }
+ isLoading = false
+ }
+
+ private var dialogProgress: BigProgressDialog? = null
+
+ override fun showProgressDialog(msg: String) {
+ if (dialogProgress == null) {
+ dialogProgress = BigProgressDialog(this, msg, false)
+ }
+ dialogProgress!!.setMsg(msg)
+ dialogProgress!!.show()
+ }
+
+ override fun closeProgressDialog() {
+ dialogProgress?.dismiss()
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/supwisdom/activities/checkMngpwd/CheckMngpwdActivity.kt b/app/src/main/java/com/supwisdom/activities/checkMngpwd/CheckMngpwdActivity.kt
index 007c9cd..6ca021f 100644
--- a/app/src/main/java/com/supwisdom/activities/checkMngpwd/CheckMngpwdActivity.kt
+++ b/app/src/main/java/com/supwisdom/activities/checkMngpwd/CheckMngpwdActivity.kt
@@ -1,138 +1,138 @@
-package com.supwisdom.activities.checkMngpwd
-
-import android.content.Intent
-import android.os.Bundle
-import android.os.CountDownTimer
-import android.view.KeyEvent
-import android.widget.TextView
-import com.supwisdom.R
-import com.supwisdom.activities.BaseActivity
-import com.supwisdom.activities.manage.ManageActivity
-import com.supwisdom.auxscreen.AuxScreenController
-import com.supwisdom.utils.CommonUtil
-import java.util.*
-
-/**
- ** create by zzq on 2019/7/26
- ** @desc
- **/
-class CheckMngpwdActivity : BaseActivity() {
- private var tmpPwd: String = ""
- private lateinit var vTitle: TextView
- private var password: String = ""
- private var mode: String? = null
- private var keyActive = true
-
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- this.setContentView(R.layout.activity_check_mngpwd)
- initView()
- }
-
- private fun initView() {
- vTitle = findViewById<TextView>(R.id.title)
- }
-
- override fun dispatchKeyEvent(event: KeyEvent): Boolean {
- if (event.action == KeyEvent.ACTION_DOWN) {
- if (!keyActive) {
- return super.dispatchKeyEvent(event)
- }
- resetCounter(200)
-
- val keyCode = event.keyCode
- when (keyCode) {
- KeyEvent.KEYCODE_0,
- KeyEvent.KEYCODE_1,
- KeyEvent.KEYCODE_2,
- KeyEvent.KEYCODE_3,
- KeyEvent.KEYCODE_4,
- KeyEvent.KEYCODE_5,
- KeyEvent.KEYCODE_6,
- KeyEvent.KEYCODE_7,
- KeyEvent.KEYCODE_8,
- KeyEvent.KEYCODE_9 -> {
- tmpPwd += keyCode - KeyEvent.KEYCODE_0
- if (tmpPwd.length >= 6) {
- if (checkMngPwd(tmpPwd)) {
- jumpActivity(ManageActivity::class.java)
- } else {
- AuxScreenController.getInstance().refreshContent(Arrays.asList<String>("维护密码:", "密码错误"))
- }
- tmpPwd = ""
- } else {
- AuxScreenController.getInstance()
- .refreshContent(Arrays.asList("维护密码:", CommonUtil.getPasswordStar(tmpPwd.length)))
- }
- }
- KeyEvent.KEYCODE_DEL -> {
- //cancel
- val len = tmpPwd.length
- when {
- len == 1 -> {
- tmpPwd = ""
- AuxScreenController.getInstance()
- .refreshContent(Arrays.asList("维护密码:", CommonUtil.getPasswordStar(tmpPwd.length)))
- }
- len > 1 -> {
- tmpPwd = tmpPwd.substring(0, len - 1)
- AuxScreenController.getInstance()
- .refreshContent(Arrays.asList("维护密码:", CommonUtil.getPasswordStar(tmpPwd.length)))
- }
- else -> finish()
- }
- }
- }
- }
- return super.dispatchKeyEvent(event)
- }
-
- override fun onResume() {
- super.onResume()
- keyActive = true
- password = this.intent.getStringExtra("password")
- mode = this.intent.getStringExtra("mode")
- refresh()
- }
-
- override fun onNewIntent(intent: Intent) {
- super.onNewIntent(intent)
- this.intent.putExtra("password", intent.getStringExtra("password"))
- this.intent.putExtra("mode", intent.getStringExtra("mode"))
- }
-
- private fun refresh() {
- tmpPwd = ""
- vTitle.text = "维护密码验证"
- AuxScreenController.getInstance().refreshTitle("维护密码验证")
- AuxScreenController.getInstance().refreshBottom("取消键返回上页")
- AuxScreenController.getInstance().refreshContent(Arrays.asList<String>("维护密码:", " "))
- }
-
- private fun checkMngPwd(inputPwd: String): Boolean {
- return inputPwd == password
- }
-
- private var counter: ContinuePressTimer? = null
-
- private fun resetCounter(timems: Long) {
- counter?.cancel()
- if (counter == null) {
- counter = ContinuePressTimer(timems, 100)
- }
- keyActive = false
- counter!!.start()
- }
-
- private inner class ContinuePressTimer internal constructor(millisInFuture: Long, countDownInterval: Long) :
- CountDownTimer(millisInFuture, countDownInterval) {
-
- override fun onTick(millisUntilFinished: Long) {
-
- }
-
- override fun onFinish() {
- keyActive = true
- }
- }
+package com.supwisdom.activities.checkMngpwd
+
+import android.content.Intent
+import android.os.Bundle
+import android.os.CountDownTimer
+import android.view.KeyEvent
+import android.widget.TextView
+import com.supwisdom.R
+import com.supwisdom.activities.BaseActivity
+import com.supwisdom.activities.auxscreen.AuxScreenController
+import com.supwisdom.activities.manage.ManageActivity
+import com.supwisdom.utils.CommonUtil
+import java.util.*
+
+/**
+ ** create by zzq on 2019/7/26
+ ** @desc
+ **/
+class CheckMngpwdActivity : BaseActivity() {
+ private var tmpPwd: String = ""
+ private lateinit var vTitle: TextView
+ private var password: String = ""
+ private var mode: String? = null
+ private var keyActive = true
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ this.setContentView(R.layout.activity_check_mngpwd)
+ initView()
+ }
+
+ private fun initView() {
+ vTitle = findViewById<TextView>(R.id.title)
+ }
+
+ override fun dispatchKeyEvent(event: KeyEvent): Boolean {
+ if (event.action == KeyEvent.ACTION_DOWN) {
+ if (!keyActive) {
+ return super.dispatchKeyEvent(event)
+ }
+ resetCounter(200)
+
+ val keyCode = event.keyCode
+ when (keyCode) {
+ KeyEvent.KEYCODE_0,
+ KeyEvent.KEYCODE_1,
+ KeyEvent.KEYCODE_2,
+ KeyEvent.KEYCODE_3,
+ KeyEvent.KEYCODE_4,
+ KeyEvent.KEYCODE_5,
+ KeyEvent.KEYCODE_6,
+ KeyEvent.KEYCODE_7,
+ KeyEvent.KEYCODE_8,
+ KeyEvent.KEYCODE_9 -> {
+ tmpPwd += keyCode - KeyEvent.KEYCODE_0
+ if (tmpPwd.length >= 6) {
+ if (checkMngPwd(tmpPwd)) {
+ jumpActivity(ManageActivity::class.java)
+ } else {
+ AuxScreenController.getInstance().refreshContent(Arrays.asList<String>("维护密码:", "密码错误"))
+ }
+ tmpPwd = ""
+ } else {
+ AuxScreenController.getInstance()
+ .refreshContent(Arrays.asList("维护密码:", CommonUtil.getPasswordStar(tmpPwd.length)))
+ }
+ }
+ KeyEvent.KEYCODE_DEL -> {
+ //cancel
+ val len = tmpPwd.length
+ when {
+ len == 1 -> {
+ tmpPwd = ""
+ AuxScreenController.getInstance()
+ .refreshContent(Arrays.asList("维护密码:", CommonUtil.getPasswordStar(tmpPwd.length)))
+ }
+ len > 1 -> {
+ tmpPwd = tmpPwd.substring(0, len - 1)
+ AuxScreenController.getInstance()
+ .refreshContent(Arrays.asList("维护密码:", CommonUtil.getPasswordStar(tmpPwd.length)))
+ }
+ else -> finish()
+ }
+ }
+ }
+ }
+ return super.dispatchKeyEvent(event)
+ }
+
+ override fun onResume() {
+ super.onResume()
+ keyActive = true
+ password = this.intent.getStringExtra("password")
+ mode = this.intent.getStringExtra("mode")
+ refresh()
+ }
+
+ override fun onNewIntent(intent: Intent) {
+ super.onNewIntent(intent)
+ this.intent.putExtra("password", intent.getStringExtra("password"))
+ this.intent.putExtra("mode", intent.getStringExtra("mode"))
+ }
+
+ private fun refresh() {
+ tmpPwd = ""
+ vTitle.text = "维护密码验证"
+ AuxScreenController.getInstance().refreshTitle("维护密码验证")
+ AuxScreenController.getInstance().refreshBottom("取消键返回上页")
+ AuxScreenController.getInstance().refreshContent(Arrays.asList<String>("维护密码:", " "))
+ }
+
+ private fun checkMngPwd(inputPwd: String): Boolean {
+ return inputPwd == password
+ }
+
+ private var counter: ContinuePressTimer? = null
+
+ private fun resetCounter(timems: Long) {
+ counter?.cancel()
+ if (counter == null) {
+ counter = ContinuePressTimer(timems, 100)
+ }
+ keyActive = false
+ counter!!.start()
+ }
+
+ private inner class ContinuePressTimer internal constructor(millisInFuture: Long, countDownInterval: Long) :
+ CountDownTimer(millisInFuture, countDownInterval) {
+
+ override fun onTick(millisUntilFinished: Long) {
+
+ }
+
+ override fun onFinish() {
+ keyActive = true
+ }
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/supwisdom/activities/checkShoppwd/CheckShoppwdActivity.kt b/app/src/main/java/com/supwisdom/activities/checkShoppwd/CheckShoppwdActivity.kt
index 746c06c..0df7c50 100644
--- a/app/src/main/java/com/supwisdom/activities/checkShoppwd/CheckShoppwdActivity.kt
+++ b/app/src/main/java/com/supwisdom/activities/checkShoppwd/CheckShoppwdActivity.kt
@@ -8,9 +8,9 @@
import com.supwisdom.R
import com.supwisdom.activities.BaseActivity
import com.supwisdom.activities.SPApplication
+import com.supwisdom.activities.auxscreen.AuxScreenController
import com.supwisdom.activities.consume.ConsumeActivity
import com.supwisdom.activities.consume.bean.CardUserInfoBean
-import com.supwisdom.auxscreen.AuxScreenController
import com.supwisdom.utils.CommonUtil
import com.supwisdom.utils.SoundUtil
import java.util.*
@@ -61,12 +61,18 @@
if (checkMngPwd(tmpPwd)) {
doReverse()
} else {
- AuxScreenController.getInstance().refreshContent(Arrays.asList<String>("商户密码:", "密码错误"))
+ AuxScreenController.getInstance()
+ .refreshContent(Arrays.asList<String>("商户密码:", "密码错误"))
}
tmpPwd = ""
} else {
AuxScreenController.getInstance()
- .refreshContent(Arrays.asList("商户密码:", CommonUtil.getPasswordStar(tmpPwd.length)))
+ .refreshContent(
+ Arrays.asList(
+ "商户密码:",
+ CommonUtil.getPasswordStar(tmpPwd.length)
+ )
+ )
}
}
KeyEvent.KEYCODE_DEL -> {
@@ -76,12 +82,22 @@
len == 1 -> {
tmpPwd = ""
AuxScreenController.getInstance()
- .refreshContent(Arrays.asList("商户密码:", CommonUtil.getPasswordStar(tmpPwd.length)))
+ .refreshContent(
+ Arrays.asList(
+ "商户密码:",
+ CommonUtil.getPasswordStar(tmpPwd.length)
+ )
+ )
}
len > 1 -> {
tmpPwd = tmpPwd.substring(0, len - 1)
AuxScreenController.getInstance()
- .refreshContent(Arrays.asList("商户密码:", CommonUtil.getPasswordStar(tmpPwd.length)))
+ .refreshContent(
+ Arrays.asList(
+ "商户密码:",
+ CommonUtil.getPasswordStar(tmpPwd.length)
+ )
+ )
}
else -> finish()
}
@@ -146,7 +162,10 @@
counter!!.start()
}
- private inner class ContinuePressTimer internal constructor(millisInFuture: Long, countDownInterval: Long) :
+ private inner class ContinuePressTimer internal constructor(
+ millisInFuture: Long,
+ countDownInterval: Long
+ ) :
CountDownTimer(millisInFuture, countDownInterval) {
override fun onTick(millisUntilFinished: Long) {
diff --git a/app/src/main/java/com/supwisdom/activities/communicate/CommunicateActivity.kt b/app/src/main/java/com/supwisdom/activities/communicate/CommunicateActivity.kt
index a591170..81af282 100644
--- a/app/src/main/java/com/supwisdom/activities/communicate/CommunicateActivity.kt
+++ b/app/src/main/java/com/supwisdom/activities/communicate/CommunicateActivity.kt
@@ -1,117 +1,117 @@
-package com.supwisdom.activities.communicate
-
-import android.os.Bundle
-import android.text.TextUtils
-import android.view.KeyEvent
-import android.view.View
-import android.widget.EditText
-import android.widget.TextView
-import com.supwisdom.R
-import com.supwisdom.activities.BaseActivity
-import com.supwisdom.activities.SPApplication
-import com.supwisdom.auxscreen.AuxScreenController
-import com.supwisdom.utils.CommonUtil
-import com.supwisdom.utils.PublicDef
-import com.supwisdom.view.SWToast
-
-/**
- ** create by zzq on 2019/7/25
- ** @desc 通讯参数配置
- **/
-class CommunicateActivity : BaseActivity() {
- private val pos = SPApplication.getInstance().getPos()
- private lateinit var vTenantid: TextView
- private lateinit var vDevphyid: TextView
- private lateinit var vEpayUrl: EditText
- private lateinit var vEpayUri: EditText
- private lateinit var vEpayPort: EditText
-
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_communicate)
- initView()
- initData()
- }
-
- private fun initView() {
- vTenantid = findViewById<View>(R.id.comm_tenantid) as TextView
- vDevphyid = findViewById<View>(R.id.comm_devphyid) as TextView
- vEpayUrl = findViewById<View>(R.id.comm_epay_url) as EditText
- vEpayUri = findViewById<View>(R.id.comm_epay_uri) as EditText
- vEpayPort = findViewById<View>(R.id.comm_epay_port) as EditText
-
- this.findViewById<View>(R.id.btn_cancel).setOnClickListener { finish() }
- this.findViewById<View>(R.id.btn_confirm).setOnClickListener(View.OnClickListener {
- val record = pos.getConfigPara()
- val url = CommonUtil.getEditView(vEpayUrl)
- if (TextUtils.isEmpty(url)) {
- showSWToastInfo("服务器地址不能为空", PublicDef.TOAST_SHOW_CRY)
- return@OnClickListener
- }
- record!!.epayIP = url
-
- val uri = CommonUtil.getEditView(vEpayUri)
- if (TextUtils.isEmpty(uri)) {
- showSWToastInfo("服务器标识不对", PublicDef.TOAST_SHOW_CRY)
- return@OnClickListener
- }
- record.epayUri = uri
-
- try {
- val port = Integer.valueOf(CommonUtil.getEditView(vEpayPort))
- if (port > 0xFFFF) {
- showSWToastInfo("服务器端口太大", PublicDef.TOAST_SHOW_CRY)
- return@OnClickListener
- }
- record.epayPort = port
- } catch (e: Exception) {
- showSWToastInfo("服务器端口不对", PublicDef.TOAST_SHOW_CRY)
- return@OnClickListener
- }
-
- if (!pos.replaceConfigPara(record)) {
- showSWToastInfo("保存失败", PublicDef.TOAST_SHOW_CRY)
- return@OnClickListener
- }
- showSWToastInfo("保存成功", PublicDef.TOAST_SHOW_SMILE)
- finish()
- })
- }
-
- public override fun onResume() {
- super.onResume()
- refresh()
- }
-
- private fun initData() {
- val record = pos.getConfigPara()
- vTenantid.text = record!!.tenantId
- vDevphyid.text = record.devphyid
- vEpayUrl.setText(record.epayIP)
- vEpayUri.setText(record.epayUri)
- vEpayPort.setText(record.epayPort.toString())
- }
-
- private fun refresh() {
- AuxScreenController.getInstance().refreshTitle("通讯参数设置")
- AuxScreenController.getInstance().refreshBottom("确定键返回上页")
- AuxScreenController.getInstance().refreshContent(listOf<String>("请到大屏进行配置"))
- }
-
- override fun dispatchKeyEvent(event: KeyEvent): Boolean {
- if (event.action == KeyEvent.ACTION_DOWN) {
- when (event.keyCode) {
- KeyEvent.KEYCODE_DEL -> {
- }
- KeyEvent.KEYCODE_ENTER -> finish()
- }//cancel
- //和触屏删除键冲突
- // finish();
- }
- return super.dispatchKeyEvent(event)
- }
-
- private fun showSWToastInfo(msg: String, showway: Int) {
- SWToast.show(applicationContext, msg, showway)
- }
+package com.supwisdom.activities.communicate
+
+import android.os.Bundle
+import android.text.TextUtils
+import android.view.KeyEvent
+import android.view.View
+import android.widget.EditText
+import android.widget.TextView
+import com.supwisdom.R
+import com.supwisdom.activities.BaseActivity
+import com.supwisdom.activities.SPApplication
+import com.supwisdom.activities.auxscreen.AuxScreenController
+import com.supwisdom.utils.CommonUtil
+import com.supwisdom.utils.PublicDef
+import com.supwisdom.view.SWToast
+
+/**
+ ** create by zzq on 2019/7/25
+ ** @desc 通讯参数配置
+ **/
+class CommunicateActivity : BaseActivity() {
+ private val pos = SPApplication.getInstance().getPos()
+ private lateinit var vTenantid: TextView
+ private lateinit var vDevphyid: TextView
+ private lateinit var vEpayUrl: EditText
+ private lateinit var vEpayUri: EditText
+ private lateinit var vEpayPort: EditText
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_communicate)
+ initView()
+ initData()
+ }
+
+ private fun initView() {
+ vTenantid = findViewById<View>(R.id.comm_tenantid) as TextView
+ vDevphyid = findViewById<View>(R.id.comm_devphyid) as TextView
+ vEpayUrl = findViewById<View>(R.id.comm_epay_url) as EditText
+ vEpayUri = findViewById<View>(R.id.comm_epay_uri) as EditText
+ vEpayPort = findViewById<View>(R.id.comm_epay_port) as EditText
+
+ this.findViewById<View>(R.id.btn_cancel).setOnClickListener { finish() }
+ this.findViewById<View>(R.id.btn_confirm).setOnClickListener(View.OnClickListener {
+ val record = pos.getConfigPara()
+ val url = CommonUtil.getEditView(vEpayUrl)
+ if (TextUtils.isEmpty(url)) {
+ showSWToastInfo("服务器地址不能为空", PublicDef.TOAST_SHOW_CRY)
+ return@OnClickListener
+ }
+ record!!.epayIP = url
+
+ val uri = CommonUtil.getEditView(vEpayUri)
+ if (TextUtils.isEmpty(uri)) {
+ showSWToastInfo("服务器标识不对", PublicDef.TOAST_SHOW_CRY)
+ return@OnClickListener
+ }
+ record.epayUri = uri
+
+ try {
+ val port = Integer.valueOf(CommonUtil.getEditView(vEpayPort))
+ if (port > 0xFFFF) {
+ showSWToastInfo("服务器端口太大", PublicDef.TOAST_SHOW_CRY)
+ return@OnClickListener
+ }
+ record.epayPort = port
+ } catch (e: Exception) {
+ showSWToastInfo("服务器端口不对", PublicDef.TOAST_SHOW_CRY)
+ return@OnClickListener
+ }
+
+ if (!pos.replaceConfigPara(record)) {
+ showSWToastInfo("保存失败", PublicDef.TOAST_SHOW_CRY)
+ return@OnClickListener
+ }
+ showSWToastInfo("保存成功", PublicDef.TOAST_SHOW_SMILE)
+ finish()
+ })
+ }
+
+ public override fun onResume() {
+ super.onResume()
+ refresh()
+ }
+
+ private fun initData() {
+ val record = pos.getConfigPara()
+ vTenantid.text = record!!.tenantId
+ vDevphyid.text = record.devphyid
+ vEpayUrl.setText(record.epayIP)
+ vEpayUri.setText(record.epayUri)
+ vEpayPort.setText(record.epayPort.toString())
+ }
+
+ private fun refresh() {
+ AuxScreenController.getInstance().refreshTitle("通讯参数设置")
+ AuxScreenController.getInstance().refreshBottom("确定键返回上页")
+ AuxScreenController.getInstance().refreshContent(listOf<String>("请到大屏进行配置"))
+ }
+
+ override fun dispatchKeyEvent(event: KeyEvent): Boolean {
+ if (event.action == KeyEvent.ACTION_DOWN) {
+ when (event.keyCode) {
+ KeyEvent.KEYCODE_DEL -> {
+ }
+ KeyEvent.KEYCODE_ENTER -> finish()
+ }//cancel
+ //和触屏删除键冲突
+ // finish();
+ }
+ return super.dispatchKeyEvent(event)
+ }
+
+ private fun showSWToastInfo(msg: String, showway: Int) {
+ SWToast.show(applicationContext, msg, showway)
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/supwisdom/activities/consume/ConsumeActivity.kt b/app/src/main/java/com/supwisdom/activities/consume/ConsumeActivity.kt
index 5b4a3b7..89be1a7 100644
--- a/app/src/main/java/com/supwisdom/activities/consume/ConsumeActivity.kt
+++ b/app/src/main/java/com/supwisdom/activities/consume/ConsumeActivity.kt
@@ -14,11 +14,11 @@
import com.supwisdom.R
import com.supwisdom.activities.BaseActivity
import com.supwisdom.activities.SPApplication
+import com.supwisdom.activities.auxscreen.AuxScreenController
import com.supwisdom.activities.consume.bean.CardStatus
import com.supwisdom.activities.consume.bean.CardUserInfoBean
import com.supwisdom.activities.menu.MenuActivity
import com.supwisdom.activities.transdtl.TransdtlActivity
-import com.supwisdom.auxscreen.AuxScreenController
import com.supwisdom.entity.PayStatus
import com.supwisdom.entity.PeriodFixPayRecord
import com.supwisdom.entity.ReversalFlag
@@ -59,13 +59,17 @@
private val pos = SPApplication.getInstance().getPos()
private var beepManager: BeepManager? = null
private val scanLock = ReentrantLock()
+
@Volatile
private var cardPaying = false
+
@Volatile
private var payStatusEnable = false
+
@Volatile
private var isBackRunning = false
private var addAmount: Int = 0
+
@Volatile
private var amount: Int = 0
private var payMode: PayMode? = null
@@ -676,7 +680,10 @@
private fun getCurAmount(): Int {
return try {
- CommonUtil.YuanToFen(java.lang.Double.parseDouble(amountTxt.text.toString().trim { it <= ' ' }))
+ CommonUtil.YuanToFen(
+ java.lang.Double.parseDouble(
+ amountTxt.text.toString().trim { it <= ' ' })
+ )
} catch (ex: Exception) {
ex.printStackTrace()
0
diff --git a/app/src/main/java/com/supwisdom/activities/consumeMode/ConsumeModeActivity.kt b/app/src/main/java/com/supwisdom/activities/consumeMode/ConsumeModeActivity.kt
index 7ce5604..79e632a 100644
--- a/app/src/main/java/com/supwisdom/activities/consumeMode/ConsumeModeActivity.kt
+++ b/app/src/main/java/com/supwisdom/activities/consumeMode/ConsumeModeActivity.kt
@@ -1,554 +1,554 @@
-package com.supwisdom.activities.consumeMode
-
-import android.annotation.SuppressLint
-import android.os.Bundle
-import android.os.CountDownTimer
-import android.text.TextUtils
-import android.view.KeyEvent
-import android.view.View
-import android.widget.*
-import com.supwisdom.R
-import com.supwisdom.activities.BaseActivity
-import com.supwisdom.activities.SPApplication
-import com.supwisdom.activities.consume.PayMode
-import com.supwisdom.auxscreen.AuxScreenController
-import com.supwisdom.entity.HotKeyPayRecord
-import com.supwisdom.entity.PeriodFixPayRecord
-import com.supwisdom.utils.CommonUtil
-import com.supwisdom.utils.DateUtil
-import com.supwisdom.utils.PublicDef
-import com.supwisdom.view.SWToast
-import java.util.*
-import kotlin.collections.ArrayList
-
-/**
- ** create by zzq on 2019/7/26
- ** @desc
- **/
-class ConsumeModeActivity : BaseActivity() {
- private lateinit var vPayamt: TextView
- private lateinit var vSpecialDesc: TextView
- private lateinit var rbHotkeyMode: RadioButton
- private lateinit var rbPeriodMode: RadioButton
- private lateinit var rbNormalMode: RadioButton
- private lateinit var rbFixMode: RadioButton
- private lateinit var llSpecialList: LinearLayout
- private lateinit var llFixMode: LinearLayout
- private lateinit var llSpecialMode: LinearLayout
- private val pos = SPApplication.getInstance().getPos()
- private var keyActive = true
- private var shoppwdPass = false
- private var specialMode = false
- private var tmpPwd = ""
- private var configMode = ConfigMode.NORMAL_FIX
- private val MAX_CHILD_COUNT = 6
-
-
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- this.setContentView(R.layout.activity_consume_mode)
- initView()
- initData()
- }
-
- private fun initData() {
-
- }
-
- private fun initView() {
- vPayamt = findViewById<TextView>(R.id.tv_consume_mode_payamt)
- llSpecialList = findViewById<LinearLayout>(R.id.ll_special_list)
- this.findViewById<TextView>(R.id.tv_hot_add).setOnClickListener {
- if (!shoppwdPass) {
- return@setOnClickListener
- }
- if (llSpecialList.childCount >= MAX_CHILD_COUNT) {
- SWToast.show(
- applicationContext,
- "最大支持${MAX_CHILD_COUNT}条规则",
- PublicDef.TOAST_SHOW_DOUBT
- )
- return@setOnClickListener
- }
- if (configMode == ConfigMode.PERIOD_FIX) {
- addPeriodFixRule()
- } else if (configMode == ConfigMode.HOT_KEY) {
- addHotkeyRule()
- }
- }
- this.findViewById<TextView>(R.id.tv_save).setOnClickListener {
- if (!shoppwdPass) {
- return@setOnClickListener
- }
- when (configMode) {
- ConfigMode.PERIOD_FIX -> {
- if (llSpecialList.childCount == 0) {
- SWToast.show(applicationContext, "请先添加波段规则", PublicDef.TOAST_SHOW_DOUBT)
- return@setOnClickListener
- }
- if (!savePeriodFixRule()) {
- return@setOnClickListener
- }
- }
- ConfigMode.HOT_KEY -> {
- if (llSpecialList.childCount == 0) {
- SWToast.show(applicationContext, "请先添加热键规则", PublicDef.TOAST_SHOW_DOUBT)
- return@setOnClickListener
- }
- if (!saveHotkeyRule()) {
- return@setOnClickListener
- }
- }
- ConfigMode.NORMAL_FIX -> {
- pos.replaceControlPara(PublicDef.CONTROL_FIXAMT, getFixAmount())
- }
- ConfigMode.NORMAL -> {
- pos.replaceControlPara(PublicDef.CONTROL_FIXAMT, PayMode.NORMAL.desc)
- }
- }
- finish()
- }
- this.findViewById<TextView>(R.id.tv_return).setOnClickListener {
- //showCurrentMode(ConfigMode.NORMAL_FIX)
- //refreshToSetAmount()
- finish()
- }
- this.findViewById<RadioGroup>(R.id.rg_special_mode)
- .setOnCheckedChangeListener { _, checkedId ->
- if (!shoppwdPass) {
- return@setOnCheckedChangeListener
- }
- when (checkedId) {
- R.id.rb_normal -> showCurrentMode(ConfigMode.NORMAL)
- R.id.rb_normal_fix -> showCurrentMode(ConfigMode.NORMAL_FIX)
- R.id.rb_hot_mode -> showCurrentMode(ConfigMode.HOT_KEY)
- R.id.rb_period_fix_mode -> showCurrentMode(ConfigMode.PERIOD_FIX)
- }
- }
- rbNormalMode = this.findViewById<RadioButton>(R.id.rb_normal)
- rbFixMode = this.findViewById<RadioButton>(R.id.rb_normal_fix)
- rbPeriodMode = this.findViewById<RadioButton>(R.id.rb_period_fix_mode)
- rbHotkeyMode = this.findViewById<RadioButton>(R.id.rb_hot_mode)
-
- llFixMode = this.findViewById<LinearLayout>(R.id.ll_fix_mode)
- llSpecialMode = this.findViewById<LinearLayout>(R.id.ll_hot_mode)
-
- vSpecialDesc = this.findViewById<TextView>(R.id.tv_special_desc)
- }
-
- private fun addHotkeyRule() {
- val item = View.inflate(this, R.layout.item_hotkey_pay, null)
- item.findViewById<TextView>(R.id.tv_hot_del).setOnClickListener {
- llSpecialList.removeView(item)
- for (loop in 0 until llSpecialList.childCount) {
- val item = llSpecialList.getChildAt(loop)
- val key = item.findViewById<TextView>(R.id.tv_hot_key)
- key.text = "${(loop + 1)}"
- }
- }
- val key = item.findViewById<TextView>(R.id.tv_hot_key)
- key.text = "${llSpecialList.childCount + 1}"
- llSpecialList.addView(item)
- }
-
- private fun addPeriodFixRule() {
- val item = View.inflate(this, R.layout.item_period_fix_pay, null)
- item.findViewById<TextView>(R.id.tv_del).setOnClickListener {
- llSpecialList.removeView(item)
- for (loop in 0 until llSpecialList.childCount) {
- val item = llSpecialList.getChildAt(loop)
- val key = item.findViewById<TextView>(R.id.tv_config)
- key.text = "规则${(loop + 1)}:"
- }
- }
- val key = item.findViewById<TextView>(R.id.tv_config)
- key.text = "规则${llSpecialList.childCount + 1}:"
- llSpecialList.addView(item)
- }
-
- private fun saveHotkeyRule(): Boolean {
- val list = ArrayList<HotKeyPayRecord>()
- for (loop in 0 until llSpecialList.childCount) {
- val record = HotKeyPayRecord()
- val item = llSpecialList.getChildAt(loop)
- var temp = item.findViewById<TextView>(R.id.tv_hot_key)
- record.key = Integer.parseInt(temp.text.toString())
- temp = item.findViewById<EditText>(R.id.tv_hot_amount)
- record.amount =
- CommonUtil.YuanToFen(java.lang.Double.parseDouble(CommonUtil.getEditView(temp)))
- list.add(record)
- }
- pos.replaceControlPara(PublicDef.CONTROL_FIXAMT, PayMode.HOTKEY.desc)
- if (!pos.saveHotkeyPay(list)) {
- SWToast.show(applicationContext, "保持配置失败", PublicDef.TOAST_SHOW_CRY)
- return false
- }
- return true
- }
-
- private fun savePeriodFixRule(): Boolean {
- val list = ArrayList<PeriodFixPayRecord>()
- for (loop in 0 until llSpecialList.childCount) {
- val record = PeriodFixPayRecord()
- val item = llSpecialList.getChildAt(loop)
- record.beginTime =
- CommonUtil.getEditView(item.findViewById<EditText>(R.id.tv_period_start))
- record.endTime = CommonUtil.getEditView(item.findViewById<EditText>(R.id.tv_period_end))
- val temp = item.findViewById<EditText>(R.id.tv_amount)
- record.amount =
- CommonUtil.YuanToFen(java.lang.Double.parseDouble(CommonUtil.getEditView(temp)))
- if (TextUtils.isEmpty(record.beginTime) || TextUtils.isEmpty(record.endTime)) {
- SWToast.show(applicationContext, "时间段不为空", PublicDef.TOAST_SHOW_CRY)
- return false
- }
- if (record.beginTime!!.length != 4 || record.endTime!!.length != 4) {
- SWToast.show(applicationContext, "时间段长度不对", PublicDef.TOAST_SHOW_CRY)
- return false
- }
- if (!("0000" <= record.beginTime!! && record.beginTime!! < record.endTime!! && record.endTime!! <= "2400")) {
- SWToast.show(applicationContext, "时间段不合法", PublicDef.TOAST_SHOW_CRY)
- return false
- }
- list.add(record)
- }
- pos.replaceControlPara(PublicDef.CONTROL_FIXAMT, PayMode.PERIODFIX.desc)
- if (!pos.savePeriodFixPay(list)) {
- SWToast.show(applicationContext, "保持配置失败", PublicDef.TOAST_SHOW_CRY)
- return false
- }
- return true
- }
-
- private fun loadHotkeyRule() {
- llSpecialList.removeAllViews()
- pos.getHotkeyPay()?.forEach {
- val item = View.inflate(this, R.layout.item_hotkey_pay, null)
- item.findViewById<TextView>(R.id.tv_hot_del).setOnClickListener {
- llSpecialList.removeView(item)
- for (loop in 0 until llSpecialList.childCount) {
- val item = llSpecialList.getChildAt(loop)
- val key = item.findViewById<TextView>(R.id.tv_hot_key)
- key.text = "${(loop + 1)}"
- }
- }
- val key = item.findViewById<TextView>(R.id.tv_hot_key)
- key.text = "${llSpecialList.childCount + 1}"
- val amt = item.findViewById<TextView>(R.id.tv_hot_amount)
- amt.text = String.format("%.02f", it.amount / 100.0f)
- llSpecialList.addView(item)
- }
- }
-
- private fun loadPeriodFixRule() {
- llSpecialList.removeAllViews()
- pos.getPeriodFixPay()?.forEach {
- val item = View.inflate(this, R.layout.item_period_fix_pay, null)
- item.findViewById<TextView>(R.id.tv_del).setOnClickListener {
- llSpecialList.removeView(item)
- for (loop in 0 until llSpecialList.childCount) {
- val item = llSpecialList.getChildAt(loop)
- val key = item.findViewById<TextView>(R.id.tv_config)
- key.text = "规则${(loop + 1)}:"
- }
- }
- val beginTime = item.findViewById<EditText>(R.id.tv_period_start)
- beginTime.setText(it.beginTime)
- val endTime = item.findViewById<EditText>(R.id.tv_period_end)
- endTime.setText(it.endTime)
- val amt = item.findViewById<EditText>(R.id.tv_amount)
- amt.setText(String.format("%.02f", it.amount / 100.0f))
- val key = item.findViewById<TextView>(R.id.tv_config)
- key.text = "规则${llSpecialList.childCount + 1}:"
- llSpecialList.addView(item)
- }
- }
-
-
- @SuppressLint("SetTextI18n")
- override fun dispatchKeyEvent(event: KeyEvent): Boolean {
- if (event.action == KeyEvent.ACTION_DOWN) {
- if (!keyActive) {
- return super.dispatchKeyEvent(event)
- }
- resetCounter(200)
- if (shoppwdPass) {
- setFixAmount(event.keyCode)
- } else {
- checkShopPwd(event.keyCode)
- }
- }
- return super.dispatchKeyEvent(event)
- }
-
- override fun onResume() {
- super.onResume()
- shoppwdPass = false
- keyActive = true
- showCurrentMode(ConfigMode.NORMAL_FIX)
- refreshToCheckPasswd()
- }
-
- private fun showCurrentMode(mode: ConfigMode) {
- configMode = mode
- when (mode) {
- ConfigMode.HOT_KEY -> {
- specialMode = true
- rbHotkeyMode.isChecked = true
- llFixMode.visibility = View.GONE
- llSpecialMode.visibility = View.VISIBLE
- vSpecialDesc.text = "设置快捷按键(单位:元)"
- loadHotkeyRule()
- }
- ConfigMode.PERIOD_FIX -> {
- specialMode = true
- rbPeriodMode.isChecked = true
- llFixMode.visibility = View.GONE
- llSpecialMode.visibility = View.VISIBLE
- vSpecialDesc.text = "设置波段定额(单位:元)"
- loadPeriodFixRule()
- }
- ConfigMode.NORMAL_FIX -> {
- specialMode = false
- rbFixMode.isChecked = true
- llSpecialMode.visibility = View.GONE
- llFixMode.visibility = View.VISIBLE
- }
- else -> {
- rbNormalMode.isChecked = true
- llSpecialMode.visibility = View.GONE
- llFixMode.visibility = View.VISIBLE
- specialMode = false
- }
- }
- }
-
- private fun checkShopPwd(keyCode: Int) {
- when (keyCode) {
- KeyEvent.KEYCODE_0,
- KeyEvent.KEYCODE_1,
- KeyEvent.KEYCODE_2,
- KeyEvent.KEYCODE_3,
- KeyEvent.KEYCODE_4,
- KeyEvent.KEYCODE_5,
- KeyEvent.KEYCODE_6,
- KeyEvent.KEYCODE_7,
- KeyEvent.KEYCODE_8,
- KeyEvent.KEYCODE_9 -> {
- tmpPwd += keyCode - KeyEvent.KEYCODE_0
- if (tmpPwd.length >= 6) {
- if (checkShoPwdValid(tmpPwd)) {
- shoppwdPass = true
- refreshToSetAmount()
- } else {
- AuxScreenController.getInstance()
- .refreshContent(Arrays.asList<String>("请输入商户密码:", "密码错误"))
- }
- tmpPwd = ""
- } else {
- AuxScreenController.getInstance()
- .refreshContent(
- Arrays.asList(
- "请输入商户密码:",
- CommonUtil.getPasswordStar(tmpPwd.length)
- )
- )
- }
- }
- KeyEvent.KEYCODE_DEL -> {
- //cancel
- val len = tmpPwd.length
- when {
- len == 1 -> {
- tmpPwd = ""
- AuxScreenController.getInstance()
- .refreshContent(
- Arrays.asList(
- "请输入商户密码:",
- CommonUtil.getPasswordStar(tmpPwd.length)
- )
- )
- }
- len > 1 -> {
- tmpPwd = tmpPwd.substring(0, len - 1)
- AuxScreenController.getInstance()
- .refreshContent(
- Arrays.asList(
- "请输入商户密码:",
- CommonUtil.getPasswordStar(tmpPwd.length)
- )
- )
- }
- else -> finish()
- }
- }
- }
- }
-
- private fun checkShoPwdValid(inputPwd: String): Boolean {
- return inputPwd == pos.getConfigPara()!!.shopPwd
- }
-
- private fun setFixAmount(keyCode: Int) {
- if (specialMode) {
- AuxScreenController.getInstance().refreshContent(Arrays.asList<String>("请到大屏设置"))
- return
- }
- when (keyCode) {
- KeyEvent.KEYCODE_0,
- KeyEvent.KEYCODE_1,
- KeyEvent.KEYCODE_2,
- KeyEvent.KEYCODE_3,
- KeyEvent.KEYCODE_4,
- KeyEvent.KEYCODE_5,
- KeyEvent.KEYCODE_6,
- KeyEvent.KEYCODE_7,
- KeyEvent.KEYCODE_8,
- KeyEvent.KEYCODE_9 -> addValueToEdit(keyCode - KeyEvent.KEYCODE_0)
- KeyEvent.KEYCODE_DEL -> delValueToEdit()
- KeyEvent.KEYCODE_POUND,
- KeyEvent.KEYCODE_PERIOD -> addDotToEdit()
- KeyEvent.KEYCODE_ENTER -> {
- pos.replaceControlPara(PublicDef.CONTROL_FIXAMT, getFixAmount())
-// jumpActivity(MenuActivity::class.java)
- finish()
- }
- KeyEvent.KEYCODE_DPAD_LEFT -> {
- //F1
- showCurrentMode(ConfigMode.HOT_KEY)
- AuxScreenController.getInstance().refreshContent(Arrays.asList<String>("请到大屏设置"))
- }
- }
- }
-
- private fun refreshToCheckPasswd() {
- AuxScreenController.getInstance().refreshTitle("消费模式设置")
- AuxScreenController.getInstance().refreshBottom(DateUtil.getNowDateTime())
- AuxScreenController.getInstance().refreshContent(Arrays.asList<String>("请输入商户密码:", " "))
- }
-
- private fun refreshToSetAmount() {
- vPayamt.text = PayMode.NORMAL.desc
- pos.getControlPara(PublicDef.CONTROL_FIXAMT)?.also {
- when {
- PayMode.FIXPAY.desc == it.paraval -> {
- vPayamt.text = String.format("%.02f", Integer.parseInt(it.paraval) / 100.0f)
- screenShowAmt()
- }
- PayMode.HOTKEY.desc == it.paraval -> {
- showCurrentMode(ConfigMode.HOT_KEY)
- AuxScreenController.getInstance()
- .refreshContent(Arrays.asList<String>("请到大屏设置"))
- return
- }
- PayMode.PERIODFIX.desc == it.paraval -> {
- showCurrentMode(ConfigMode.PERIOD_FIX)
- AuxScreenController.getInstance()
- .refreshContent(Arrays.asList<String>("请到大屏设置"))
- return
- }
- PayMode.NORMAL.desc == it.paraval -> {
-
- }
- }
- } ?: screenShowAmt()
- }
-
- private fun getFixAmount(): String {
- try {
- return Integer.toString(CommonUtil.YuanToFen(java.lang.Double.parseDouble(vPayamt.text.toString())))
- } catch (e: Exception) {
- e.printStackTrace()
- }
- return PayMode.NORMAL.desc
- }
-
- private fun addValueToEdit(value: Int) {
- var str = vPayamt.text.toString()
- if ("0" == str || PayMode.NORMAL.desc == str) {
- str = ""
- }
- //如果已经有小数点,则小数点后面不能超过两位
- if (str.indexOf(".") > 0) {
- if (str.length - str.indexOf(".") <= 2) {
- vPayamt.text = "$str$value"
- } else {
- vPayamt.text = value.toString()
- }
- } else {
- //限制消费金额<1000
- if (str.length < 3) {
- vPayamt.text = "$str$value"
- }
- }
- screenShowAmt()
- }
-
- private fun delValueToEdit() {
- val str = vPayamt.text.toString()
- if (PayMode.NORMAL.desc != str) {
- if (str.length <= 1) {
- vPayamt.text = PayMode.NORMAL.desc
- } else {
- vPayamt.text = str.substring(0, str.length - 1)
- }
- }
- screenShowAmt()
- }
-
- private fun addDotToEdit() {
- val str = vPayamt.text.toString()
- if (PayMode.NORMAL.desc == str) {
- vPayamt.text = "0."
- } else {
- if (str.length < 8 && str.indexOf('.') < 0) {
- vPayamt.text = "$str."
- }
- }
- screenShowAmt()
- }
-
- private fun screenShowAmt() {
- AuxScreenController.getInstance().refreshTitle("消费模式设置 F1-特殊模式")
- AuxScreenController.getInstance().refreshBottom(DateUtil.getNowDateTime())
- AuxScreenController.getInstance().refreshContent(
- Arrays.asList<String>(
- PayMode.NORMAL.desc + "-普通消费",
- "值-定额消费(元)",
- String.format("金额:%s", vPayamt.text.toString())
- )
- )
- }
-
- private var counter: ContinuePressTimer? = null
-
- private fun resetCounter(timems: Long) {
- counter?.cancel()
- if (counter == null) {
- counter = ContinuePressTimer(timems, 100)
- }
- keyActive = false
- counter!!.start()
- }
-
- private inner class ContinuePressTimer internal constructor(
- millisInFuture: Long,
- countDownInterval: Long
- ) :
- CountDownTimer(millisInFuture, countDownInterval) {
-
- override fun onTick(millisUntilFinished: Long) {
-
- }
-
- override fun onFinish() {
- keyActive = true
- }
- }
-}
-
-enum class ConfigMode {
- NORMAL,
- NORMAL_FIX,
- HOT_KEY,
- PERIOD_FIX,
+package com.supwisdom.activities.consumeMode
+
+import android.annotation.SuppressLint
+import android.os.Bundle
+import android.os.CountDownTimer
+import android.text.TextUtils
+import android.view.KeyEvent
+import android.view.View
+import android.widget.*
+import com.supwisdom.R
+import com.supwisdom.activities.BaseActivity
+import com.supwisdom.activities.SPApplication
+import com.supwisdom.activities.auxscreen.AuxScreenController
+import com.supwisdom.activities.consume.PayMode
+import com.supwisdom.entity.HotKeyPayRecord
+import com.supwisdom.entity.PeriodFixPayRecord
+import com.supwisdom.utils.CommonUtil
+import com.supwisdom.utils.DateUtil
+import com.supwisdom.utils.PublicDef
+import com.supwisdom.view.SWToast
+import java.util.*
+import kotlin.collections.ArrayList
+
+/**
+ ** create by zzq on 2019/7/26
+ ** @desc
+ **/
+class ConsumeModeActivity : BaseActivity() {
+ private lateinit var vPayamt: TextView
+ private lateinit var vSpecialDesc: TextView
+ private lateinit var rbHotkeyMode: RadioButton
+ private lateinit var rbPeriodMode: RadioButton
+ private lateinit var rbNormalMode: RadioButton
+ private lateinit var rbFixMode: RadioButton
+ private lateinit var llSpecialList: LinearLayout
+ private lateinit var llFixMode: LinearLayout
+ private lateinit var llSpecialMode: LinearLayout
+ private val pos = SPApplication.getInstance().getPos()
+ private var keyActive = true
+ private var shoppwdPass = false
+ private var specialMode = false
+ private var tmpPwd = ""
+ private var configMode = ConfigMode.NORMAL_FIX
+ private val MAX_CHILD_COUNT = 6
+
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ this.setContentView(R.layout.activity_consume_mode)
+ initView()
+ initData()
+ }
+
+ private fun initData() {
+
+ }
+
+ private fun initView() {
+ vPayamt = findViewById<TextView>(R.id.tv_consume_mode_payamt)
+ llSpecialList = findViewById<LinearLayout>(R.id.ll_special_list)
+ this.findViewById<TextView>(R.id.tv_hot_add).setOnClickListener {
+ if (!shoppwdPass) {
+ return@setOnClickListener
+ }
+ if (llSpecialList.childCount >= MAX_CHILD_COUNT) {
+ SWToast.show(
+ applicationContext,
+ "最大支持${MAX_CHILD_COUNT}条规则",
+ PublicDef.TOAST_SHOW_DOUBT
+ )
+ return@setOnClickListener
+ }
+ if (configMode == ConfigMode.PERIOD_FIX) {
+ addPeriodFixRule()
+ } else if (configMode == ConfigMode.HOT_KEY) {
+ addHotkeyRule()
+ }
+ }
+ this.findViewById<TextView>(R.id.tv_save).setOnClickListener {
+ if (!shoppwdPass) {
+ return@setOnClickListener
+ }
+ when (configMode) {
+ ConfigMode.PERIOD_FIX -> {
+ if (llSpecialList.childCount == 0) {
+ SWToast.show(applicationContext, "请先添加波段规则", PublicDef.TOAST_SHOW_DOUBT)
+ return@setOnClickListener
+ }
+ if (!savePeriodFixRule()) {
+ return@setOnClickListener
+ }
+ }
+ ConfigMode.HOT_KEY -> {
+ if (llSpecialList.childCount == 0) {
+ SWToast.show(applicationContext, "请先添加热键规则", PublicDef.TOAST_SHOW_DOUBT)
+ return@setOnClickListener
+ }
+ if (!saveHotkeyRule()) {
+ return@setOnClickListener
+ }
+ }
+ ConfigMode.NORMAL_FIX -> {
+ pos.replaceControlPara(PublicDef.CONTROL_FIXAMT, getFixAmount())
+ }
+ ConfigMode.NORMAL -> {
+ pos.replaceControlPara(PublicDef.CONTROL_FIXAMT, PayMode.NORMAL.desc)
+ }
+ }
+ finish()
+ }
+ this.findViewById<TextView>(R.id.tv_return).setOnClickListener {
+ //showCurrentMode(ConfigMode.NORMAL_FIX)
+ //refreshToSetAmount()
+ finish()
+ }
+ this.findViewById<RadioGroup>(R.id.rg_special_mode)
+ .setOnCheckedChangeListener { _, checkedId ->
+ if (!shoppwdPass) {
+ return@setOnCheckedChangeListener
+ }
+ when (checkedId) {
+ R.id.rb_normal -> showCurrentMode(ConfigMode.NORMAL)
+ R.id.rb_normal_fix -> showCurrentMode(ConfigMode.NORMAL_FIX)
+ R.id.rb_hot_mode -> showCurrentMode(ConfigMode.HOT_KEY)
+ R.id.rb_period_fix_mode -> showCurrentMode(ConfigMode.PERIOD_FIX)
+ }
+ }
+ rbNormalMode = this.findViewById<RadioButton>(R.id.rb_normal)
+ rbFixMode = this.findViewById<RadioButton>(R.id.rb_normal_fix)
+ rbPeriodMode = this.findViewById<RadioButton>(R.id.rb_period_fix_mode)
+ rbHotkeyMode = this.findViewById<RadioButton>(R.id.rb_hot_mode)
+
+ llFixMode = this.findViewById<LinearLayout>(R.id.ll_fix_mode)
+ llSpecialMode = this.findViewById<LinearLayout>(R.id.ll_hot_mode)
+
+ vSpecialDesc = this.findViewById<TextView>(R.id.tv_special_desc)
+ }
+
+ private fun addHotkeyRule() {
+ val item = View.inflate(this, R.layout.item_hotkey_pay, null)
+ item.findViewById<TextView>(R.id.tv_hot_del).setOnClickListener {
+ llSpecialList.removeView(item)
+ for (loop in 0 until llSpecialList.childCount) {
+ val item = llSpecialList.getChildAt(loop)
+ val key = item.findViewById<TextView>(R.id.tv_hot_key)
+ key.text = "${(loop + 1)}"
+ }
+ }
+ val key = item.findViewById<TextView>(R.id.tv_hot_key)
+ key.text = "${llSpecialList.childCount + 1}"
+ llSpecialList.addView(item)
+ }
+
+ private fun addPeriodFixRule() {
+ val item = View.inflate(this, R.layout.item_period_fix_pay, null)
+ item.findViewById<TextView>(R.id.tv_del).setOnClickListener {
+ llSpecialList.removeView(item)
+ for (loop in 0 until llSpecialList.childCount) {
+ val item = llSpecialList.getChildAt(loop)
+ val key = item.findViewById<TextView>(R.id.tv_config)
+ key.text = "规则${(loop + 1)}:"
+ }
+ }
+ val key = item.findViewById<TextView>(R.id.tv_config)
+ key.text = "规则${llSpecialList.childCount + 1}:"
+ llSpecialList.addView(item)
+ }
+
+ private fun saveHotkeyRule(): Boolean {
+ val list = ArrayList<HotKeyPayRecord>()
+ for (loop in 0 until llSpecialList.childCount) {
+ val record = HotKeyPayRecord()
+ val item = llSpecialList.getChildAt(loop)
+ var temp = item.findViewById<TextView>(R.id.tv_hot_key)
+ record.key = Integer.parseInt(temp.text.toString())
+ temp = item.findViewById<EditText>(R.id.tv_hot_amount)
+ record.amount =
+ CommonUtil.YuanToFen(java.lang.Double.parseDouble(CommonUtil.getEditView(temp)))
+ list.add(record)
+ }
+ pos.replaceControlPara(PublicDef.CONTROL_FIXAMT, PayMode.HOTKEY.desc)
+ if (!pos.saveHotkeyPay(list)) {
+ SWToast.show(applicationContext, "保持配置失败", PublicDef.TOAST_SHOW_CRY)
+ return false
+ }
+ return true
+ }
+
+ private fun savePeriodFixRule(): Boolean {
+ val list = ArrayList<PeriodFixPayRecord>()
+ for (loop in 0 until llSpecialList.childCount) {
+ val record = PeriodFixPayRecord()
+ val item = llSpecialList.getChildAt(loop)
+ record.beginTime =
+ CommonUtil.getEditView(item.findViewById<EditText>(R.id.tv_period_start))
+ record.endTime = CommonUtil.getEditView(item.findViewById<EditText>(R.id.tv_period_end))
+ val temp = item.findViewById<EditText>(R.id.tv_amount)
+ record.amount =
+ CommonUtil.YuanToFen(java.lang.Double.parseDouble(CommonUtil.getEditView(temp)))
+ if (TextUtils.isEmpty(record.beginTime) || TextUtils.isEmpty(record.endTime)) {
+ SWToast.show(applicationContext, "时间段不为空", PublicDef.TOAST_SHOW_CRY)
+ return false
+ }
+ if (record.beginTime!!.length != 4 || record.endTime!!.length != 4) {
+ SWToast.show(applicationContext, "时间段长度不对", PublicDef.TOAST_SHOW_CRY)
+ return false
+ }
+ if (!("0000" <= record.beginTime!! && record.beginTime!! < record.endTime!! && record.endTime!! <= "2400")) {
+ SWToast.show(applicationContext, "时间段不合法", PublicDef.TOAST_SHOW_CRY)
+ return false
+ }
+ list.add(record)
+ }
+ pos.replaceControlPara(PublicDef.CONTROL_FIXAMT, PayMode.PERIODFIX.desc)
+ if (!pos.savePeriodFixPay(list)) {
+ SWToast.show(applicationContext, "保持配置失败", PublicDef.TOAST_SHOW_CRY)
+ return false
+ }
+ return true
+ }
+
+ private fun loadHotkeyRule() {
+ llSpecialList.removeAllViews()
+ pos.getHotkeyPay()?.forEach {
+ val item = View.inflate(this, R.layout.item_hotkey_pay, null)
+ item.findViewById<TextView>(R.id.tv_hot_del).setOnClickListener {
+ llSpecialList.removeView(item)
+ for (loop in 0 until llSpecialList.childCount) {
+ val item = llSpecialList.getChildAt(loop)
+ val key = item.findViewById<TextView>(R.id.tv_hot_key)
+ key.text = "${(loop + 1)}"
+ }
+ }
+ val key = item.findViewById<TextView>(R.id.tv_hot_key)
+ key.text = "${llSpecialList.childCount + 1}"
+ val amt = item.findViewById<TextView>(R.id.tv_hot_amount)
+ amt.text = String.format("%.02f", it.amount / 100.0f)
+ llSpecialList.addView(item)
+ }
+ }
+
+ private fun loadPeriodFixRule() {
+ llSpecialList.removeAllViews()
+ pos.getPeriodFixPay()?.forEach {
+ val item = View.inflate(this, R.layout.item_period_fix_pay, null)
+ item.findViewById<TextView>(R.id.tv_del).setOnClickListener {
+ llSpecialList.removeView(item)
+ for (loop in 0 until llSpecialList.childCount) {
+ val item = llSpecialList.getChildAt(loop)
+ val key = item.findViewById<TextView>(R.id.tv_config)
+ key.text = "规则${(loop + 1)}:"
+ }
+ }
+ val beginTime = item.findViewById<EditText>(R.id.tv_period_start)
+ beginTime.setText(it.beginTime)
+ val endTime = item.findViewById<EditText>(R.id.tv_period_end)
+ endTime.setText(it.endTime)
+ val amt = item.findViewById<EditText>(R.id.tv_amount)
+ amt.setText(String.format("%.02f", it.amount / 100.0f))
+ val key = item.findViewById<TextView>(R.id.tv_config)
+ key.text = "规则${llSpecialList.childCount + 1}:"
+ llSpecialList.addView(item)
+ }
+ }
+
+
+ @SuppressLint("SetTextI18n")
+ override fun dispatchKeyEvent(event: KeyEvent): Boolean {
+ if (event.action == KeyEvent.ACTION_DOWN) {
+ if (!keyActive) {
+ return super.dispatchKeyEvent(event)
+ }
+ resetCounter(200)
+ if (shoppwdPass) {
+ setFixAmount(event.keyCode)
+ } else {
+ checkShopPwd(event.keyCode)
+ }
+ }
+ return super.dispatchKeyEvent(event)
+ }
+
+ override fun onResume() {
+ super.onResume()
+ shoppwdPass = false
+ keyActive = true
+ showCurrentMode(ConfigMode.NORMAL_FIX)
+ refreshToCheckPasswd()
+ }
+
+ private fun showCurrentMode(mode: ConfigMode) {
+ configMode = mode
+ when (mode) {
+ ConfigMode.HOT_KEY -> {
+ specialMode = true
+ rbHotkeyMode.isChecked = true
+ llFixMode.visibility = View.GONE
+ llSpecialMode.visibility = View.VISIBLE
+ vSpecialDesc.text = "设置快捷按键(单位:元)"
+ loadHotkeyRule()
+ }
+ ConfigMode.PERIOD_FIX -> {
+ specialMode = true
+ rbPeriodMode.isChecked = true
+ llFixMode.visibility = View.GONE
+ llSpecialMode.visibility = View.VISIBLE
+ vSpecialDesc.text = "设置波段定额(单位:元)"
+ loadPeriodFixRule()
+ }
+ ConfigMode.NORMAL_FIX -> {
+ specialMode = false
+ rbFixMode.isChecked = true
+ llSpecialMode.visibility = View.GONE
+ llFixMode.visibility = View.VISIBLE
+ }
+ else -> {
+ rbNormalMode.isChecked = true
+ llSpecialMode.visibility = View.GONE
+ llFixMode.visibility = View.VISIBLE
+ specialMode = false
+ }
+ }
+ }
+
+ private fun checkShopPwd(keyCode: Int) {
+ when (keyCode) {
+ KeyEvent.KEYCODE_0,
+ KeyEvent.KEYCODE_1,
+ KeyEvent.KEYCODE_2,
+ KeyEvent.KEYCODE_3,
+ KeyEvent.KEYCODE_4,
+ KeyEvent.KEYCODE_5,
+ KeyEvent.KEYCODE_6,
+ KeyEvent.KEYCODE_7,
+ KeyEvent.KEYCODE_8,
+ KeyEvent.KEYCODE_9 -> {
+ tmpPwd += keyCode - KeyEvent.KEYCODE_0
+ if (tmpPwd.length >= 6) {
+ if (checkShoPwdValid(tmpPwd)) {
+ shoppwdPass = true
+ refreshToSetAmount()
+ } else {
+ AuxScreenController.getInstance()
+ .refreshContent(Arrays.asList<String>("请输入商户密码:", "密码错误"))
+ }
+ tmpPwd = ""
+ } else {
+ AuxScreenController.getInstance()
+ .refreshContent(
+ Arrays.asList(
+ "请输入商户密码:",
+ CommonUtil.getPasswordStar(tmpPwd.length)
+ )
+ )
+ }
+ }
+ KeyEvent.KEYCODE_DEL -> {
+ //cancel
+ val len = tmpPwd.length
+ when {
+ len == 1 -> {
+ tmpPwd = ""
+ AuxScreenController.getInstance()
+ .refreshContent(
+ Arrays.asList(
+ "请输入商户密码:",
+ CommonUtil.getPasswordStar(tmpPwd.length)
+ )
+ )
+ }
+ len > 1 -> {
+ tmpPwd = tmpPwd.substring(0, len - 1)
+ AuxScreenController.getInstance()
+ .refreshContent(
+ Arrays.asList(
+ "请输入商户密码:",
+ CommonUtil.getPasswordStar(tmpPwd.length)
+ )
+ )
+ }
+ else -> finish()
+ }
+ }
+ }
+ }
+
+ private fun checkShoPwdValid(inputPwd: String): Boolean {
+ return inputPwd == pos.getConfigPara()!!.shopPwd
+ }
+
+ private fun setFixAmount(keyCode: Int) {
+ if (specialMode) {
+ AuxScreenController.getInstance().refreshContent(Arrays.asList<String>("请到大屏设置"))
+ return
+ }
+ when (keyCode) {
+ KeyEvent.KEYCODE_0,
+ KeyEvent.KEYCODE_1,
+ KeyEvent.KEYCODE_2,
+ KeyEvent.KEYCODE_3,
+ KeyEvent.KEYCODE_4,
+ KeyEvent.KEYCODE_5,
+ KeyEvent.KEYCODE_6,
+ KeyEvent.KEYCODE_7,
+ KeyEvent.KEYCODE_8,
+ KeyEvent.KEYCODE_9 -> addValueToEdit(keyCode - KeyEvent.KEYCODE_0)
+ KeyEvent.KEYCODE_DEL -> delValueToEdit()
+ KeyEvent.KEYCODE_POUND,
+ KeyEvent.KEYCODE_PERIOD -> addDotToEdit()
+ KeyEvent.KEYCODE_ENTER -> {
+ pos.replaceControlPara(PublicDef.CONTROL_FIXAMT, getFixAmount())
+// jumpActivity(MenuActivity::class.java)
+ finish()
+ }
+ KeyEvent.KEYCODE_DPAD_LEFT -> {
+ //F1
+ showCurrentMode(ConfigMode.HOT_KEY)
+ AuxScreenController.getInstance().refreshContent(Arrays.asList<String>("请到大屏设置"))
+ }
+ }
+ }
+
+ private fun refreshToCheckPasswd() {
+ AuxScreenController.getInstance().refreshTitle("消费模式设置")
+ AuxScreenController.getInstance().refreshBottom(DateUtil.getNowDateTime())
+ AuxScreenController.getInstance().refreshContent(Arrays.asList<String>("请输入商户密码:", " "))
+ }
+
+ private fun refreshToSetAmount() {
+ vPayamt.text = PayMode.NORMAL.desc
+ pos.getControlPara(PublicDef.CONTROL_FIXAMT)?.also {
+ when {
+ PayMode.FIXPAY.desc == it.paraval -> {
+ vPayamt.text = String.format("%.02f", Integer.parseInt(it.paraval) / 100.0f)
+ screenShowAmt()
+ }
+ PayMode.HOTKEY.desc == it.paraval -> {
+ showCurrentMode(ConfigMode.HOT_KEY)
+ AuxScreenController.getInstance()
+ .refreshContent(Arrays.asList<String>("请到大屏设置"))
+ return
+ }
+ PayMode.PERIODFIX.desc == it.paraval -> {
+ showCurrentMode(ConfigMode.PERIOD_FIX)
+ AuxScreenController.getInstance()
+ .refreshContent(Arrays.asList<String>("请到大屏设置"))
+ return
+ }
+ PayMode.NORMAL.desc == it.paraval -> {
+
+ }
+ }
+ } ?: screenShowAmt()
+ }
+
+ private fun getFixAmount(): String {
+ try {
+ return Integer.toString(CommonUtil.YuanToFen(java.lang.Double.parseDouble(vPayamt.text.toString())))
+ } catch (e: Exception) {
+ e.printStackTrace()
+ }
+ return PayMode.NORMAL.desc
+ }
+
+ private fun addValueToEdit(value: Int) {
+ var str = vPayamt.text.toString()
+ if ("0" == str || PayMode.NORMAL.desc == str) {
+ str = ""
+ }
+ //如果已经有小数点,则小数点后面不能超过两位
+ if (str.indexOf(".") > 0) {
+ if (str.length - str.indexOf(".") <= 2) {
+ vPayamt.text = "$str$value"
+ } else {
+ vPayamt.text = value.toString()
+ }
+ } else {
+ //限制消费金额<1000
+ if (str.length < 3) {
+ vPayamt.text = "$str$value"
+ }
+ }
+ screenShowAmt()
+ }
+
+ private fun delValueToEdit() {
+ val str = vPayamt.text.toString()
+ if (PayMode.NORMAL.desc != str) {
+ if (str.length <= 1) {
+ vPayamt.text = PayMode.NORMAL.desc
+ } else {
+ vPayamt.text = str.substring(0, str.length - 1)
+ }
+ }
+ screenShowAmt()
+ }
+
+ private fun addDotToEdit() {
+ val str = vPayamt.text.toString()
+ if (PayMode.NORMAL.desc == str) {
+ vPayamt.text = "0."
+ } else {
+ if (str.length < 8 && str.indexOf('.') < 0) {
+ vPayamt.text = "$str."
+ }
+ }
+ screenShowAmt()
+ }
+
+ private fun screenShowAmt() {
+ AuxScreenController.getInstance().refreshTitle("消费模式设置 F1-特殊模式")
+ AuxScreenController.getInstance().refreshBottom(DateUtil.getNowDateTime())
+ AuxScreenController.getInstance().refreshContent(
+ Arrays.asList<String>(
+ PayMode.NORMAL.desc + "-普通消费",
+ "值-定额消费(元)",
+ String.format("金额:%s", vPayamt.text.toString())
+ )
+ )
+ }
+
+ private var counter: ContinuePressTimer? = null
+
+ private fun resetCounter(timems: Long) {
+ counter?.cancel()
+ if (counter == null) {
+ counter = ContinuePressTimer(timems, 100)
+ }
+ keyActive = false
+ counter!!.start()
+ }
+
+ private inner class ContinuePressTimer internal constructor(
+ millisInFuture: Long,
+ countDownInterval: Long
+ ) :
+ CountDownTimer(millisInFuture, countDownInterval) {
+
+ override fun onTick(millisUntilFinished: Long) {
+
+ }
+
+ override fun onFinish() {
+ keyActive = true
+ }
+ }
+}
+
+enum class ConfigMode {
+ NORMAL,
+ NORMAL_FIX,
+ HOT_KEY,
+ PERIOD_FIX,
}
\ No newline at end of file
diff --git a/app/src/main/java/com/supwisdom/activities/control/ControlActivity.kt b/app/src/main/java/com/supwisdom/activities/control/ControlActivity.kt
index 0ab3436..7d4f566 100644
--- a/app/src/main/java/com/supwisdom/activities/control/ControlActivity.kt
+++ b/app/src/main/java/com/supwisdom/activities/control/ControlActivity.kt
@@ -1,118 +1,117 @@
-package com.supwisdom.activities.control
-
-import android.os.Bundle
-import android.view.KeyEvent
-import android.view.View
-import android.widget.RadioButton
-import android.widget.TextView
-import com.supwisdom.R
-import com.supwisdom.activities.BaseActivity
-import com.supwisdom.activities.SPApplication
-import com.supwisdom.auxscreen.AuxScreenController
-import com.supwisdom.entity.ControlParaRecord
-import com.supwisdom.utils.PublicDef
-import com.supwisdom.view.SWToast
-
-/**
- ** create by zzq on 2019/7/25
- ** @desc
- **/
-class ControlActivity : BaseActivity() {
- private val pos = SPApplication.getInstance().getPos()
- private lateinit var vDebugDisable: RadioButton
- private lateinit var vDebugEnable: RadioButton
- private lateinit var vOfflineEnable: RadioButton
- private lateinit var vOfflineDisable: RadioButton
-
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_control)
- initView()
- }
-
- private fun initData() {
- var record = pos.getControlPara(PublicDef.CONTROL_OFFLINE_DAY_DISABLE)
- if (record != null && "1" == record.paraval) {
- vOfflineDisable.isChecked = true
- } else {
- vOfflineEnable.isChecked = true
- }
- record = pos.getControlPara(PublicDef.CONTROL_DEBUG_ENABLE)
- if (record != null && "1" == record.paraval) {
- vDebugEnable.isChecked = true
- } else {
- vDebugDisable.isChecked = true
- }
- }
-
- private fun initView() {
- vOfflineEnable = this.findViewById<View>(R.id.rb_offline_enable) as RadioButton
- vOfflineDisable = this.findViewById<View>(R.id.rb_offline_disable) as RadioButton
- vDebugDisable = this.findViewById<View>(R.id.rb_debug_enable) as RadioButton
- vDebugEnable = this.findViewById<View>(R.id.rb_debug_disable) as RadioButton
- val ivBtn = this.findViewById<View>(R.id.btn_cancel) as TextView
- ivBtn.setOnClickListener { this@ControlActivity.finish() }
- //确定按钮
- this.findViewById<TextView>(R.id.btn_save).setOnClickListener {
- var flag = if (vOfflineDisable.isChecked) {
- "1"
- } else {
- "0"
- }
- if (!pos.replaceControlPara(PublicDef.CONTROL_OFFLINE_DAY_DISABLE, flag)) {
- showSWToastInfo("脱机天数判断保存失败", PublicDef.TOAST_SHOW_CRY)
- return@setOnClickListener
- }
-
- flag = if (vDebugEnable.isChecked) {
- "1"
- } else {
- "0"
- }
- if (!pos.replaceControlPara(PublicDef.CONTROL_DEBUG_ENABLE, flag)) {
- showSWToastInfo("日志调试保存失败", PublicDef.TOAST_SHOW_CRY)
- return@setOnClickListener
- }
- showSWToastInfo("保存成功", PublicDef.TOAST_SHOW_SMILE)
- this@ControlActivity.finish()
- }
-
- }
-
- override fun dispatchKeyEvent(event: KeyEvent): Boolean {
- if (event.action == KeyEvent.ACTION_DOWN) {
- when (event.keyCode) {
- KeyEvent.KEYCODE_DEL -> {
- }
- KeyEvent.KEYCODE_ENTER -> finish()
- }//cancel
- //和触屏删除键冲突
- // finish();
- }
- return super.dispatchKeyEvent(event)
- }
-
- private fun showSWToastInfo(msg: String, showway: Int) {
- SWToast.show(applicationContext, msg, showway)
- }
-
- override fun onResume() {
- super.onResume()
- refresh()
- initData()
- }
-
- override fun onStop() {
- super.onStop()
- }
-
- override fun onDestroy() {
- super.onDestroy()
- }
-
- private fun refresh() {
- AuxScreenController.getInstance().refreshTitle("控制参数设置")
- AuxScreenController.getInstance().refreshBottom("确定键返回上页")
- AuxScreenController.getInstance().refreshContent(listOf<String>("请到大屏进行配置"))
- }
+package com.supwisdom.activities.control
+
+import android.os.Bundle
+import android.view.KeyEvent
+import android.view.View
+import android.widget.RadioButton
+import android.widget.TextView
+import com.supwisdom.R
+import com.supwisdom.activities.BaseActivity
+import com.supwisdom.activities.SPApplication
+import com.supwisdom.activities.auxscreen.AuxScreenController
+import com.supwisdom.utils.PublicDef
+import com.supwisdom.view.SWToast
+
+/**
+ ** create by zzq on 2019/7/25
+ ** @desc
+ **/
+class ControlActivity : BaseActivity() {
+ private val pos = SPApplication.getInstance().getPos()
+ private lateinit var vDebugDisable: RadioButton
+ private lateinit var vDebugEnable: RadioButton
+ private lateinit var vOfflineEnable: RadioButton
+ private lateinit var vOfflineDisable: RadioButton
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_control)
+ initView()
+ }
+
+ private fun initData() {
+ var record = pos.getControlPara(PublicDef.CONTROL_OFFLINE_DAY_DISABLE)
+ if (record != null && "1" == record.paraval) {
+ vOfflineDisable.isChecked = true
+ } else {
+ vOfflineEnable.isChecked = true
+ }
+ record = pos.getControlPara(PublicDef.CONTROL_DEBUG_ENABLE)
+ if (record != null && "1" == record.paraval) {
+ vDebugEnable.isChecked = true
+ } else {
+ vDebugDisable.isChecked = true
+ }
+ }
+
+ private fun initView() {
+ vOfflineEnable = this.findViewById<View>(R.id.rb_offline_enable) as RadioButton
+ vOfflineDisable = this.findViewById<View>(R.id.rb_offline_disable) as RadioButton
+ vDebugDisable = this.findViewById<View>(R.id.rb_debug_enable) as RadioButton
+ vDebugEnable = this.findViewById<View>(R.id.rb_debug_disable) as RadioButton
+ val ivBtn = this.findViewById<View>(R.id.btn_cancel) as TextView
+ ivBtn.setOnClickListener { this@ControlActivity.finish() }
+ //确定按钮
+ this.findViewById<TextView>(R.id.btn_save).setOnClickListener {
+ var flag = if (vOfflineDisable.isChecked) {
+ "1"
+ } else {
+ "0"
+ }
+ if (!pos.replaceControlPara(PublicDef.CONTROL_OFFLINE_DAY_DISABLE, flag)) {
+ showSWToastInfo("脱机天数判断保存失败", PublicDef.TOAST_SHOW_CRY)
+ return@setOnClickListener
+ }
+
+ flag = if (vDebugEnable.isChecked) {
+ "1"
+ } else {
+ "0"
+ }
+ if (!pos.replaceControlPara(PublicDef.CONTROL_DEBUG_ENABLE, flag)) {
+ showSWToastInfo("日志调试保存失败", PublicDef.TOAST_SHOW_CRY)
+ return@setOnClickListener
+ }
+ showSWToastInfo("保存成功", PublicDef.TOAST_SHOW_SMILE)
+ this@ControlActivity.finish()
+ }
+
+ }
+
+ override fun dispatchKeyEvent(event: KeyEvent): Boolean {
+ if (event.action == KeyEvent.ACTION_DOWN) {
+ when (event.keyCode) {
+ KeyEvent.KEYCODE_DEL -> {
+ }
+ KeyEvent.KEYCODE_ENTER -> finish()
+ }//cancel
+ //和触屏删除键冲突
+ // finish();
+ }
+ return super.dispatchKeyEvent(event)
+ }
+
+ private fun showSWToastInfo(msg: String, showway: Int) {
+ SWToast.show(applicationContext, msg, showway)
+ }
+
+ override fun onResume() {
+ super.onResume()
+ refresh()
+ initData()
+ }
+
+ override fun onStop() {
+ super.onStop()
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ }
+
+ private fun refresh() {
+ AuxScreenController.getInstance().refreshTitle("控制参数设置")
+ AuxScreenController.getInstance().refreshBottom("确定键返回上页")
+ AuxScreenController.getInstance().refreshContent(listOf<String>("请到大屏进行配置"))
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/supwisdom/activities/init/InitActivity.kt b/app/src/main/java/com/supwisdom/activities/init/InitActivity.kt
index 1c83abd..ea5626d 100644
--- a/app/src/main/java/com/supwisdom/activities/init/InitActivity.kt
+++ b/app/src/main/java/com/supwisdom/activities/init/InitActivity.kt
@@ -1,245 +1,237 @@
-package com.supwisdom.activities.init
-
-import android.app.Activity
-import android.net.nsd.NsdServiceInfo
-import android.os.Bundle
-import android.support.v7.widget.LinearLayoutManager
-import android.support.v7.widget.RecyclerView
-import android.widget.Button
-import android.widget.EditText
-import android.widget.RadioButton
-import android.widget.TextView
-import com.supwisdom.R
-import com.supwisdom.activities.BaseActivity
-import com.supwisdom.activities.SPApplication
-import com.supwisdom.activities.init.adapter.NsdServerConfigAdapter
-import com.supwisdom.activities.init.mode.NsdClient
-import com.supwisdom.activities.init.mode.NsdClientApi
-import com.supwisdom.activities.load.LoadActivity
-import com.supwisdom.auxscreen.AuxScreenController
-import com.supwisdom.entity.ConfigParaRecord
-import com.supwisdom.service.NtpClient
-import com.supwisdom.utils.CommonUtil
-import com.supwisdom.utils.DateUtil
-import com.supwisdom.utils.PublicDef
-import com.supwisdom.utils.ThreadPool
-import com.supwisdom.view.BigSwDialog
-import com.supwisdom.view.SWToast
-import java.util.*
-
-/**
- ** create by zzq on 2019/7/24
- ** @desc
- **/
-@Suppress("DEPRECATION")
-class InitActivity : BaseActivity(), IInitView {
- private lateinit var presenter: InitPresenter
- private lateinit var vDevphyid: EditText
- private lateinit var vTenantId: EditText
- private lateinit var vServerIp: EditText
- private lateinit var vUri: EditText
- private lateinit var vPort: EditText
- private lateinit var vNsdResult: TextView
- private lateinit var vRadioPayMode: RadioButton
- private lateinit var vRadioDepositMode: RadioButton
- private lateinit var vRadioThirdPayMode: RadioButton
- private lateinit var vRadioThirdLoginMode: RadioButton
- private var nsdClient: NsdClient? = null
- private var nsdServiceIp: String? = null
- private var nsdServicePort: Int = 0
- private var dialogNsdConfig: BigSwDialog? = null
- private var nsdConfigAdapter: NsdServerConfigAdapter? = null
- private val pos = SPApplication.getInstance().getPos()
-
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_init)
- initView()
- initData()
- }
-
- private fun initData() {
- presenter = InitPresenter(this)
- var record = pos.getConfigPara()
- if (record == null) {
- record = ConfigParaRecord()
- record.mode = 0
- record.tenantId = "schema"
- record.devphyid = "12345678"
- record.epayIP = "127.0.0.1"
- record.epayPort = 8080
- record.epayUri = "restaurant"
- }
- record.initOK = false
- pos.replaceConfigPara(record)
- val cfgRecord = pos.getConfigPara()
-
-// when {
-// cfgRecord.mode == PublicDef.TERMINAL_DEPOSIT_MODE -> vRadioDepositMode.isChecked = true
-// cfgRecord.mode == PublicDef.TERMINAL_THIRD_PAY_MODE -> vRadioThirdPayMode.isChecked = true
-// cfgRecord.mode == PublicDef.TERMINAL_GATE_MODE -> vRadioGateMode.isChecked = true
-// cfgRecord.mode == PublicDef.TERMINAL_THIRD_LOGIN_MODE -> vRadioThirdLoginMode.isChecked = true
-// else -> vRadioPayMode.isChecked = true
-// }
- vTenantId.setText(cfgRecord!!.tenantId)
- vDevphyid.setText(cfgRecord.devphyid)
- vServerIp.setText(cfgRecord.epayIP)
- vUri.setText(cfgRecord.epayUri)
- vPort.setText(cfgRecord.epayPort.toString())
-
- nsdClient = NsdClient(this, "epay-reg-server", object : NsdClient.IServerFound {
- override fun onServerFound(serviceInfo: NsdServiceInfo) {
- nsdServiceIp = serviceInfo.host?.hostAddress
- nsdServicePort = serviceInfo.port
- if (nsdServiceIp != null) {
- asyncGetConfigName()
- }
- }
-
- override fun onServerFail() {
-
- }
- })
- }
-
- private fun initView() {
- this.findViewById<Button>(R.id.tv_settings).setOnClickListener {
- CommonUtil.startNetSetting(this@InitActivity)
- }
- this.findViewById<TextView>(R.id.btn_save).setOnClickListener {
- presenter.saveConfigParam(
- 0,
- CommonUtil.getEditView(vTenantId),
- CommonUtil.getEditView(vDevphyid), CommonUtil.getEditView(vServerIp),
- CommonUtil.getEditView(vUri), CommonUtil.getEditView(vPort)
- )
- }
- this.findViewById<Button>(R.id.tv_nsd_query).setOnClickListener {
- if (nsdServiceIp == null) {
- showSWToastInfo("nsd未连接", PublicDef.TOAST_SHOW_DOUBT)
- return@setOnClickListener
- }
- asyncGetConfigName()
- }
- vNsdResult = this.findViewById(R.id.tv_nsd_result) as TextView
- vRadioPayMode = this.findViewById(R.id.rb_pay_mode) as RadioButton
- vRadioDepositMode = this.findViewById(R.id.rb_deposit_mode) as RadioButton
- vRadioThirdPayMode = this.findViewById(R.id.rb_third_pay_mode) as RadioButton
- vRadioThirdLoginMode = this.findViewById(R.id.rb_third_login_mode) as RadioButton
- vTenantId = this.findViewById(R.id.tv_tenantid) as EditText
- vDevphyid = this.findViewById(R.id.tv_devphyid) as EditText
- vServerIp = this.findViewById(R.id.tv_server_ip) as EditText
- vUri = this.findViewById(R.id.tv_uri_root) as EditText
- vPort = this.findViewById(R.id.tv_server_port) as EditText
- }
-
- override fun onResume() {
- super.onResume()
- nsdClient!!.start()
- refresh()
- }
-
- override fun onStop() {
- super.onStop()
- nsdClient!!.stop()
- }
-
- private fun refresh() {
- AuxScreenController.getInstance().refreshTitle("通讯参数设置")
- AuxScreenController.getInstance().refreshBottom(DateUtil.getNowDateTime())
- AuxScreenController.getInstance()
- .refreshContent(Arrays.asList("设备第一次使用", "请联系管理员", "在大屏配置参数"))
- }
-
- private fun asyncGetConfigName() {
- ThreadPool.getShortPool().execute(Runnable {
- try {
- val ret = NsdClientApi(nsdServiceIp!!, nsdServicePort).getNsdServerConfigList()
- runOnUiThread {
- vNsdResult.text = ret.retmsg
- if (ret.retcode == PublicDef.SUCCESS) {
- if (ret.list!!.isEmpty()) {
- vNsdResult.text = "未找到配置项"
- return@runOnUiThread
- } else if (ret.list!!.size == 1) {
- asyncGetConfigFromNsdServer(ret.list!![0])
- return@runOnUiThread
- }
- vNsdResult.setTextColor(resources.getColor(R.color.light_blue2))
- if (dialogNsdConfig == null) {
- dialogNsdConfig = BigSwDialog(this, PublicDef.DIALOG_TYPE_NSD_CONFIG)
- val vConfigList =
- dialogNsdConfig!!.findViewById(R.id.rv_config_list) as RecyclerView
- vConfigList.layoutManager = LinearLayoutManager(this)
- vConfigList.addItemDecoration(NsdServerConfigAdapter.ItemDecoration(10))
- nsdConfigAdapter =
- NsdServerConfigAdapter(
- this,
- object : NsdServerConfigAdapter.ConfigNameListener {
- override fun callback(configName: String) {
- asyncGetConfigFromNsdServer(configName)
- dialogNsdConfig!!.dismiss()
- }
- })
- vConfigList.adapter = nsdConfigAdapter
- }
- nsdConfigAdapter!!.setList(ret.list)
- nsdConfigAdapter!!.notifyDataSetChanged()
- dialogNsdConfig!!.show()
- } else {
- vNsdResult.setTextColor(resources.getColor(R.color.cl_red))
- }
- }
- } catch (ex: Exception) {
- runOnUiThread {
- vNsdResult.text = "异常:${ex.message}"
- vNsdResult.setTextColor(resources.getColor(R.color.cl_red))
- }
- }
- })
- }
-
- private fun asyncGetConfigFromNsdServer(configName: String) {
- ThreadPool.getShortPool().execute(Runnable {
- try {
- val ret =
- NsdClientApi(nsdServiceIp!!, nsdServicePort).getEcardConfigParam(configName)
- NtpClient().startCalibrateTime(ret.systime)
- runOnUiThread {
- vNsdResult.text = ret.retmsg
- if (ret.retcode == PublicDef.SUCCESS) {
- vNsdResult.setTextColor(resources.getColor(R.color.light_blue2))
- if (ret.mode == 0) {
- vRadioPayMode.isChecked = true
- } else {
- vRadioDepositMode.isChecked = true
- }
- vDevphyid.setText(ret.devphyid)
- vServerIp.setText(ret.epayIP)
- vUri.setText(ret.epayUri)
- vPort.setText(ret.epayPort.toString())
- } else {
- vNsdResult.setTextColor(resources.getColor(R.color.cl_red))
- }
- }
- } catch (ex: Exception) {
- runOnUiThread {
- vNsdResult.text = "异常:${ex.message}"
- vNsdResult.setTextColor(resources.getColor(R.color.cl_red))
- }
- }
- })
- }
-
- override fun jumpToNextActivity() {
- jumpActivity(LoadActivity::class.java)
- }
-
- override fun getActivity(): Activity {
- return this
- }
-
- override fun showSWToastInfo(msg: String, showway: Int) {
- SWToast.show(applicationContext, msg, showway)
- }
+package com.supwisdom.activities.init
+
+import android.app.Activity
+import android.net.nsd.NsdServiceInfo
+import android.os.Bundle
+import android.support.v7.widget.LinearLayoutManager
+import android.support.v7.widget.RecyclerView
+import android.widget.Button
+import android.widget.EditText
+import android.widget.RadioButton
+import android.widget.TextView
+import com.supwisdom.R
+import com.supwisdom.activities.BaseActivity
+import com.supwisdom.activities.SPApplication
+import com.supwisdom.activities.auxscreen.AuxScreenController
+import com.supwisdom.activities.init.adapter.NsdServerConfigAdapter
+import com.supwisdom.activities.init.mode.NsdClient
+import com.supwisdom.activities.init.mode.NsdClientApi
+import com.supwisdom.activities.load.LoadActivity
+import com.supwisdom.entity.ConfigParaRecord
+import com.supwisdom.service.NtpClient
+import com.supwisdom.utils.CommonUtil
+import com.supwisdom.utils.DateUtil
+import com.supwisdom.utils.PublicDef
+import com.supwisdom.utils.ThreadPool
+import com.supwisdom.view.BigSwDialog
+import com.supwisdom.view.SWToast
+import java.util.*
+
+/**
+ ** create by zzq on 2019/7/24
+ ** @desc
+ **/
+@Suppress("DEPRECATION")
+class InitActivity : BaseActivity(), IInitView {
+ private lateinit var presenter: InitPresenter
+ private lateinit var vDevphyid: EditText
+ private lateinit var vTenantId: EditText
+ private lateinit var vServerIp: EditText
+ private lateinit var vUri: EditText
+ private lateinit var vPort: EditText
+ private lateinit var vNsdResult: TextView
+ private lateinit var vRadioPayMode: RadioButton
+ private lateinit var vRadioDepositMode: RadioButton
+ private lateinit var vRadioThirdPayMode: RadioButton
+ private lateinit var vRadioThirdLoginMode: RadioButton
+ private var nsdClient: NsdClient? = null
+ private var nsdServiceIp: String? = null
+ private var nsdServicePort: Int = 0
+ private var dialogNsdConfig: BigSwDialog? = null
+ private var nsdConfigAdapter: NsdServerConfigAdapter? = null
+ private val pos = SPApplication.getInstance().getPos()
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_init)
+ initView()
+ initData()
+ }
+
+ private fun initData() {
+ presenter = InitPresenter(this)
+ var record = pos.getConfigPara()
+ if (record == null) {
+ record = ConfigParaRecord()
+ record.mode = 0
+ record.tenantId = "schema"
+ record.devphyid = "12345678"
+ record.epayIP = "127.0.0.1"
+ record.epayPort = 8080
+ record.epayUri = "restaurant"
+ }
+ record.initOK = false
+ pos.replaceConfigPara(record)
+ val cfgRecord = pos.getConfigPara()
+ vTenantId.setText(cfgRecord!!.tenantId)
+ vDevphyid.setText(cfgRecord.devphyid)
+ vServerIp.setText(cfgRecord.epayIP)
+ vUri.setText(cfgRecord.epayUri)
+ vPort.setText(cfgRecord.epayPort.toString())
+
+ nsdClient = NsdClient(this, "epay-reg-server", object : NsdClient.IServerFound {
+ override fun onServerFound(serviceInfo: NsdServiceInfo) {
+ nsdServiceIp = serviceInfo.host?.hostAddress
+ nsdServicePort = serviceInfo.port
+ if (nsdServiceIp != null) {
+ asyncGetConfigName()
+ }
+ }
+
+ override fun onServerFail() {
+
+ }
+ })
+ }
+
+ private fun initView() {
+ this.findViewById<Button>(R.id.tv_settings).setOnClickListener {
+ CommonUtil.startNetSetting(this@InitActivity)
+ }
+ this.findViewById<TextView>(R.id.btn_save).setOnClickListener {
+ presenter.saveConfigParam(
+ 0,
+ CommonUtil.getEditView(vTenantId),
+ CommonUtil.getEditView(vDevphyid), CommonUtil.getEditView(vServerIp),
+ CommonUtil.getEditView(vUri), CommonUtil.getEditView(vPort)
+ )
+ }
+ this.findViewById<Button>(R.id.tv_nsd_query).setOnClickListener {
+ if (nsdServiceIp == null) {
+ showSWToastInfo("nsd未连接", PublicDef.TOAST_SHOW_DOUBT)
+ return@setOnClickListener
+ }
+ asyncGetConfigName()
+ }
+ vNsdResult = this.findViewById(R.id.tv_nsd_result) as TextView
+ vRadioPayMode = this.findViewById(R.id.rb_pay_mode) as RadioButton
+ vRadioDepositMode = this.findViewById(R.id.rb_deposit_mode) as RadioButton
+ vRadioThirdPayMode = this.findViewById(R.id.rb_third_pay_mode) as RadioButton
+ vRadioThirdLoginMode = this.findViewById(R.id.rb_third_login_mode) as RadioButton
+ vTenantId = this.findViewById(R.id.tv_tenantid) as EditText
+ vDevphyid = this.findViewById(R.id.tv_devphyid) as EditText
+ vServerIp = this.findViewById(R.id.tv_server_ip) as EditText
+ vUri = this.findViewById(R.id.tv_uri_root) as EditText
+ vPort = this.findViewById(R.id.tv_server_port) as EditText
+ }
+
+ override fun onResume() {
+ super.onResume()
+ nsdClient!!.start()
+ refresh()
+ }
+
+ override fun onStop() {
+ super.onStop()
+ nsdClient!!.stop()
+ }
+
+ private fun refresh() {
+ AuxScreenController.getInstance().refreshTitle("通讯参数设置")
+ AuxScreenController.getInstance().refreshBottom(DateUtil.getNowDateTime())
+ AuxScreenController.getInstance()
+ .refreshContent(Arrays.asList("设备第一次使用", "请联系管理员", "在大屏配置参数"))
+ }
+
+ private fun asyncGetConfigName() {
+ ThreadPool.getShortPool().execute(Runnable {
+ try {
+ val ret = NsdClientApi(nsdServiceIp!!, nsdServicePort).getNsdServerConfigList()
+ runOnUiThread {
+ vNsdResult.text = ret.retmsg
+ if (ret.retcode == PublicDef.SUCCESS) {
+ if (ret.list!!.isEmpty()) {
+ vNsdResult.text = "未找到配置项"
+ return@runOnUiThread
+ } else if (ret.list!!.size == 1) {
+ asyncGetConfigFromNsdServer(ret.list!![0])
+ return@runOnUiThread
+ }
+ vNsdResult.setTextColor(resources.getColor(R.color.light_blue2))
+ if (dialogNsdConfig == null) {
+ dialogNsdConfig = BigSwDialog(this, PublicDef.DIALOG_TYPE_NSD_CONFIG)
+ val vConfigList =
+ dialogNsdConfig!!.findViewById(R.id.rv_config_list) as RecyclerView
+ vConfigList.layoutManager = LinearLayoutManager(this)
+ vConfigList.addItemDecoration(NsdServerConfigAdapter.ItemDecoration(10))
+ nsdConfigAdapter =
+ NsdServerConfigAdapter(
+ this,
+ object : NsdServerConfigAdapter.ConfigNameListener {
+ override fun callback(configName: String) {
+ asyncGetConfigFromNsdServer(configName)
+ dialogNsdConfig!!.dismiss()
+ }
+ })
+ vConfigList.adapter = nsdConfigAdapter
+ }
+ nsdConfigAdapter!!.setList(ret.list)
+ nsdConfigAdapter!!.notifyDataSetChanged()
+ dialogNsdConfig!!.show()
+ } else {
+ vNsdResult.setTextColor(resources.getColor(R.color.cl_red))
+ }
+ }
+ } catch (ex: Exception) {
+ runOnUiThread {
+ vNsdResult.text = "异常:${ex.message}"
+ vNsdResult.setTextColor(resources.getColor(R.color.cl_red))
+ }
+ }
+ })
+ }
+
+ private fun asyncGetConfigFromNsdServer(configName: String) {
+ ThreadPool.getShortPool().execute(Runnable {
+ try {
+ val ret =
+ NsdClientApi(nsdServiceIp!!, nsdServicePort).getEcardConfigParam(configName)
+ NtpClient().startCalibrateTime(ret.systime)
+ runOnUiThread {
+ vNsdResult.text = ret.retmsg
+ if (ret.retcode == PublicDef.SUCCESS) {
+ vNsdResult.setTextColor(resources.getColor(R.color.light_blue2))
+ if (ret.mode == 0) {
+ vRadioPayMode.isChecked = true
+ } else {
+ vRadioDepositMode.isChecked = true
+ }
+ vDevphyid.setText(ret.devphyid)
+ vServerIp.setText(ret.epayIP)
+ vUri.setText(ret.epayUri)
+ vPort.setText(ret.epayPort.toString())
+ } else {
+ vNsdResult.setTextColor(resources.getColor(R.color.cl_red))
+ }
+ }
+ } catch (ex: Exception) {
+ runOnUiThread {
+ vNsdResult.text = "异常:${ex.message}"
+ vNsdResult.setTextColor(resources.getColor(R.color.cl_red))
+ }
+ }
+ })
+ }
+
+ override fun jumpToNextActivity() {
+ jumpActivity(LoadActivity::class.java)
+ }
+
+ override fun getActivity(): Activity {
+ return this
+ }
+
+ override fun showSWToastInfo(msg: String, showway: Int) {
+ SWToast.show(applicationContext, msg, showway)
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/supwisdom/activities/load/LoadActivity.kt b/app/src/main/java/com/supwisdom/activities/load/LoadActivity.kt
index 1e71cf2..33a11b5 100644
--- a/app/src/main/java/com/supwisdom/activities/load/LoadActivity.kt
+++ b/app/src/main/java/com/supwisdom/activities/load/LoadActivity.kt
@@ -1,100 +1,100 @@
-package com.supwisdom.activities.load
-
-import android.app.Activity
-import android.content.Intent
-import android.os.Bundle
-import android.view.View
-import android.widget.TextView
-import android.widget.Toast
-import com.supwisdom.R
-import com.supwisdom.activities.BaseActivity
-import com.supwisdom.activities.consume.ConsumeActivity
-import com.supwisdom.activities.unregister.UnregisterActivity
-import com.supwisdom.auxscreen.AuxScreenController
-import com.supwisdom.utils.DateUtil
-import java.util.*
-
-/**
- ** create by zzq on 2019/7/24
- ** @desc
- **/
-class LoadActivity : BaseActivity(), ILoadView {
- private lateinit var presenter: LoadPresenter
- private lateinit var vLoadPro: TextView
- private val procontent = StringBuilder()
- private val auxList = ArrayList<String>()
-
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_load)
-
- initView()
- initData()
- }
-
- override fun onResume() {
- super.onResume()
- presenter.start()
- refresh()
- }
-
- private fun refresh() {
- procontent.setLength(0)
- auxList.clear()
- AuxScreenController.getInstance().refreshTitle("设备参数加载")
- AuxScreenController.getInstance().refreshBottom(DateUtil.getNowDateTime())
- AuxScreenController.getInstance().refreshContent(auxList)
- }
-
- private fun initData() {
- presenter = LoadPresenter(this)
- }
-
- private fun initView() {
- this.findViewById<View>(R.id.btn_back).setOnClickListener {
- if (presenter.isLoading()) {
- Toast.makeText(applicationContext, "正在加载信息", Toast.LENGTH_SHORT).show()
- } else {
- this@LoadActivity.finish()
- }
- }
- vLoadPro = findViewById<View>(R.id.tv_load_pro) as TextView
- }
-
- override fun getActivity(): Activity {
- return this
- }
-
- override fun showProgress(hint: String, clearlast: Boolean) {
- procontent.append("\n").append(hint)
- vLoadPro.text = procontent.toString()
- if (clearlast) {
- if (auxList.size > 0) {
- auxList.removeAt(auxList.size - 1)
- }
- }
- auxList.add(hint)
- AuxScreenController.getInstance().refreshContent(showFormatAux())
- }
-
- override fun showFinish() {
- jumpActivity(ConsumeActivity::class.java)
- }
-
- override fun jumpToUnregister(errmsg: String) {
- val intent = Intent()
- intent.putExtra("errmsg", errmsg)
- intent.setClass(this, UnregisterActivity::class.java)
- startActivity(intent)
- }
-
- private fun showFormatAux(): List<String> {
- val list = ArrayList<String>()
- val size = auxList.size
- list.addAll(auxList)
- for (i in size..4) {
- list.add(" ")
- }
- return list
- }
+package com.supwisdom.activities.load
+
+import android.app.Activity
+import android.content.Intent
+import android.os.Bundle
+import android.view.View
+import android.widget.TextView
+import android.widget.Toast
+import com.supwisdom.R
+import com.supwisdom.activities.BaseActivity
+import com.supwisdom.activities.auxscreen.AuxScreenController
+import com.supwisdom.activities.consume.ConsumeActivity
+import com.supwisdom.activities.unregister.UnregisterActivity
+import com.supwisdom.utils.DateUtil
+import java.util.*
+
+/**
+ ** create by zzq on 2019/7/24
+ ** @desc
+ **/
+class LoadActivity : BaseActivity(), ILoadView {
+ private lateinit var presenter: LoadPresenter
+ private lateinit var vLoadPro: TextView
+ private val procontent = StringBuilder()
+ private val auxList = ArrayList<String>()
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_load)
+
+ initView()
+ initData()
+ }
+
+ override fun onResume() {
+ super.onResume()
+ presenter.start()
+ refresh()
+ }
+
+ private fun refresh() {
+ procontent.setLength(0)
+ auxList.clear()
+ AuxScreenController.getInstance().refreshTitle("设备参数加载")
+ AuxScreenController.getInstance().refreshBottom(DateUtil.getNowDateTime())
+ AuxScreenController.getInstance().refreshContent(auxList)
+ }
+
+ private fun initData() {
+ presenter = LoadPresenter(this)
+ }
+
+ private fun initView() {
+ this.findViewById<View>(R.id.btn_back).setOnClickListener {
+ if (presenter.isLoading()) {
+ Toast.makeText(applicationContext, "正在加载信息", Toast.LENGTH_SHORT).show()
+ } else {
+ this@LoadActivity.finish()
+ }
+ }
+ vLoadPro = findViewById<View>(R.id.tv_load_pro) as TextView
+ }
+
+ override fun getActivity(): Activity {
+ return this
+ }
+
+ override fun showProgress(hint: String, clearlast: Boolean) {
+ procontent.append("\n").append(hint)
+ vLoadPro.text = procontent.toString()
+ if (clearlast) {
+ if (auxList.size > 0) {
+ auxList.removeAt(auxList.size - 1)
+ }
+ }
+ auxList.add(hint)
+ AuxScreenController.getInstance().refreshContent(showFormatAux())
+ }
+
+ override fun showFinish() {
+ jumpActivity(ConsumeActivity::class.java)
+ }
+
+ override fun jumpToUnregister(errmsg: String) {
+ val intent = Intent()
+ intent.putExtra("errmsg", errmsg)
+ intent.setClass(this, UnregisterActivity::class.java)
+ startActivity(intent)
+ }
+
+ private fun showFormatAux(): List<String> {
+ val list = ArrayList<String>()
+ val size = auxList.size
+ list.addAll(auxList)
+ for (i in size..4) {
+ list.add(" ")
+ }
+ return list
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/supwisdom/activities/manage/ManageActivity.kt b/app/src/main/java/com/supwisdom/activities/manage/ManageActivity.kt
index f0f972b..c2021bf 100644
--- a/app/src/main/java/com/supwisdom/activities/manage/ManageActivity.kt
+++ b/app/src/main/java/com/supwisdom/activities/manage/ManageActivity.kt
@@ -7,11 +7,11 @@
import com.supwisdom.R
import com.supwisdom.activities.BaseActivity
import com.supwisdom.activities.SPApplication
+import com.supwisdom.activities.auxscreen.AuxScreenController
import com.supwisdom.activities.communicate.CommunicateActivity
import com.supwisdom.activities.control.ControlActivity
import com.supwisdom.activities.menu.MenuActivity
import com.supwisdom.activities.upgrade.UpgradeActivity
-import com.supwisdom.auxscreen.AuxScreenController
import com.supwisdom.utils.AppExitUtil
import com.supwisdom.utils.CommonUtil
import com.supwisdom.utils.DateUtil
diff --git a/app/src/main/java/com/supwisdom/activities/menu/MenuActivity.kt b/app/src/main/java/com/supwisdom/activities/menu/MenuActivity.kt
index 4c92368..63ef0ed 100644
--- a/app/src/main/java/com/supwisdom/activities/menu/MenuActivity.kt
+++ b/app/src/main/java/com/supwisdom/activities/menu/MenuActivity.kt
@@ -1,172 +1,175 @@
-package com.supwisdom.activities.menu
-
-import android.app.Activity
-import android.content.Intent
-import android.os.Bundle
-import android.os.CountDownTimer
-import android.view.KeyEvent
-import android.view.View
-import android.widget.TextView
-import com.supwisdom.R
-import com.supwisdom.activities.BaseActivity
-import com.supwisdom.activities.SPApplication
-import com.supwisdom.activities.checkMngpwd.CheckMngpwdActivity
-import com.supwisdom.activities.consume.ConsumeActivity
-import com.supwisdom.activities.consumeMode.ConsumeModeActivity
-import com.supwisdom.activities.passwd.PasswdActivity
-import com.supwisdom.activities.revenue.RevenueActivity
-import com.supwisdom.activities.syspara.SysparaActivity
-import com.supwisdom.auxscreen.AuxScreenController
-import com.supwisdom.utils.DateUtil
-import java.util.*
-
-/**
- ** create by zzq on 2019/7/25
- ** @desc
- **/
-class MenuActivity : BaseActivity(), IMenuView {
- private lateinit var presenter: MenuPresenter
- private val pos = SPApplication.getInstance().getPos()
- private var isRunning: Boolean = false
- private var flag: Boolean = false
- private lateinit var vReverse: TextView
- private var keyActive = true
-
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- this.setContentView(R.layout.activity_menu)
- initView()
- initData()
- }
-
- private fun initData() {
- presenter = MenuPresenter(this)
- }
-
- private fun initView() {
- vReverse = this.findViewById<View>(R.id.tv_reverse) as TextView
- }
-
- override fun dispatchKeyEvent(event: KeyEvent): Boolean {
- if (event.action == KeyEvent.ACTION_DOWN) {
- if (isRunning || !keyActive) {
- return super.dispatchKeyEvent(event)
- }
- resetCounter(200)
-
- val keyCode = event.keyCode
- if (flag) {
- return if (KeyEvent.KEYCODE_DEL == keyCode) {
- refresh()
- true
- } else {
- false
- }
- }
- when (keyCode) {
- KeyEvent.KEYCODE_1 -> jumpActivity(RevenueActivity::class.java)
- KeyEvent.KEYCODE_2 -> {
- isRunning = true
- presenter.uploadTransdtl()
- }
- KeyEvent.KEYCODE_3 -> {
- isRunning = true
- presenter.linkCheck()
- }
- KeyEvent.KEYCODE_4 -> {
- isRunning = true
- presenter.manualAuth()
- }
- KeyEvent.KEYCODE_5 -> jumpActivity(SysparaActivity::class.java)
- KeyEvent.KEYCODE_6 -> {
- val intent = Intent()
- intent.putExtra("password", pos.getSysPara()!!.mngPasswd)
- intent.setClass(this, CheckMngpwdActivity::class.java)
- startActivity(intent)
- }
- KeyEvent.KEYCODE_7 -> jumpActivity(PasswdActivity::class.java)
- KeyEvent.KEYCODE_8 -> jumpActivity(ConsumeModeActivity::class.java)
- KeyEvent.KEYCODE_9 -> if (isSupportReverse()) {
- presenter.doReverse()
- }
- KeyEvent.KEYCODE_DEL -> {
- //cancel
- jumpActivity(ConsumeActivity::class.java)
- }
- KeyEvent.KEYCODE_ENTER -> jumpActivity(ConsumeActivity::class.java)
- }
- }
- return super.dispatchKeyEvent(event)
- }
-
- override fun onResume() {
- super.onResume()
- keyActive = true
- refresh()
- }
-
- override fun showOperHint(title: String, result: String) {
- AuxScreenController.getInstance().refreshContent(Arrays.asList<String>(title, result))
- }
-
- override fun showOperResult(title: String, result: String) {
- flag = true
- isRunning = false
- AuxScreenController.getInstance().refreshContent(Arrays.asList<String>(title, result))
- }
-
- override fun getActivity(): Activity {
- return this
- }
-
- private fun refresh() {
- isRunning = false
- flag = false
- val secList = ArrayList<String>()
- secList.add(getString(R.string.consume_menu_revenue))
- secList.add(getString(R.string.consume_menu_transdtl_upload))
- secList.add(getString(R.string.consume_menu_link_check))
- secList.add(getString(R.string.consume_menu_auth))
- secList.add(getString(R.string.consume_menu_syspara_query))
- secList.add(getString(R.string.consume_menu_manage))
- secList.add(getString(R.string.consume_menu_shop_password_set))
- secList.add(getString(R.string.consume_menu_consume_mode))
- if (isSupportReverse()) {
- vReverse.visibility = View.VISIBLE
- secList.add(getString(R.string.consume_menu_reverse))
- } else {
- vReverse.visibility = View.GONE
- }
- AuxScreenController.getInstance().refreshTitle("设备管理界面")
- AuxScreenController.getInstance().refreshBottom(DateUtil.getNowDateTime())
- AuxScreenController.getInstance().refreshContent(secList)
- }
-
- private fun isSupportReverse(): Boolean {
- val sysRecord = SPApplication.getInstance().getPos().getSysPara()
- return sysRecord != null && sysRecord.returnFlag and 0x1 == 1
- }
-
- private var counter: ContinuePressTimer? = null
-
- private fun resetCounter(timems: Long) {
- counter?.cancel()
- if (counter == null) {
- counter = ContinuePressTimer(timems, 100)
- }
- keyActive = false
- counter!!.start()
- }
-
- private inner class ContinuePressTimer internal constructor(millisInFuture: Long, countDownInterval: Long) :
- CountDownTimer(millisInFuture, countDownInterval) {
-
- override fun onTick(millisUntilFinished: Long) {
-
- }
-
- override fun onFinish() {
- keyActive = true
- }
- }
+package com.supwisdom.activities.menu
+
+import android.app.Activity
+import android.content.Intent
+import android.os.Bundle
+import android.os.CountDownTimer
+import android.view.KeyEvent
+import android.view.View
+import android.widget.TextView
+import com.supwisdom.R
+import com.supwisdom.activities.BaseActivity
+import com.supwisdom.activities.SPApplication
+import com.supwisdom.activities.auxscreen.AuxScreenController
+import com.supwisdom.activities.checkMngpwd.CheckMngpwdActivity
+import com.supwisdom.activities.consume.ConsumeActivity
+import com.supwisdom.activities.consumeMode.ConsumeModeActivity
+import com.supwisdom.activities.passwd.PasswdActivity
+import com.supwisdom.activities.revenue.RevenueActivity
+import com.supwisdom.activities.syspara.SysparaActivity
+import com.supwisdom.utils.DateUtil
+import java.util.*
+
+/**
+ ** create by zzq on 2019/7/25
+ ** @desc
+ **/
+class MenuActivity : BaseActivity(), IMenuView {
+ private lateinit var presenter: MenuPresenter
+ private val pos = SPApplication.getInstance().getPos()
+ private var isRunning: Boolean = false
+ private var flag: Boolean = false
+ private lateinit var vReverse: TextView
+ private var keyActive = true
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ this.setContentView(R.layout.activity_menu)
+ initView()
+ initData()
+ }
+
+ private fun initData() {
+ presenter = MenuPresenter(this)
+ }
+
+ private fun initView() {
+ vReverse = this.findViewById<View>(R.id.tv_reverse) as TextView
+ }
+
+ override fun dispatchKeyEvent(event: KeyEvent): Boolean {
+ if (event.action == KeyEvent.ACTION_DOWN) {
+ if (isRunning || !keyActive) {
+ return super.dispatchKeyEvent(event)
+ }
+ resetCounter(200)
+
+ val keyCode = event.keyCode
+ if (flag) {
+ return if (KeyEvent.KEYCODE_DEL == keyCode) {
+ refresh()
+ true
+ } else {
+ false
+ }
+ }
+ when (keyCode) {
+ KeyEvent.KEYCODE_1 -> jumpActivity(RevenueActivity::class.java)
+ KeyEvent.KEYCODE_2 -> {
+ isRunning = true
+ presenter.uploadTransdtl()
+ }
+ KeyEvent.KEYCODE_3 -> {
+ isRunning = true
+ presenter.linkCheck()
+ }
+ KeyEvent.KEYCODE_4 -> {
+ isRunning = true
+ presenter.manualAuth()
+ }
+ KeyEvent.KEYCODE_5 -> jumpActivity(SysparaActivity::class.java)
+ KeyEvent.KEYCODE_6 -> {
+ val intent = Intent()
+ intent.putExtra("password", pos.getSysPara()!!.mngPasswd)
+ intent.setClass(this, CheckMngpwdActivity::class.java)
+ startActivity(intent)
+ }
+ KeyEvent.KEYCODE_7 -> jumpActivity(PasswdActivity::class.java)
+ KeyEvent.KEYCODE_8 -> jumpActivity(ConsumeModeActivity::class.java)
+ KeyEvent.KEYCODE_9 -> if (isSupportReverse()) {
+ presenter.doReverse()
+ }
+ KeyEvent.KEYCODE_DEL -> {
+ //cancel
+ jumpActivity(ConsumeActivity::class.java)
+ }
+ KeyEvent.KEYCODE_ENTER -> jumpActivity(ConsumeActivity::class.java)
+ }
+ }
+ return super.dispatchKeyEvent(event)
+ }
+
+ override fun onResume() {
+ super.onResume()
+ keyActive = true
+ refresh()
+ }
+
+ override fun showOperHint(title: String, result: String) {
+ AuxScreenController.getInstance().refreshContent(Arrays.asList<String>(title, result))
+ }
+
+ override fun showOperResult(title: String, result: String) {
+ flag = true
+ isRunning = false
+ AuxScreenController.getInstance().refreshContent(Arrays.asList<String>(title, result))
+ }
+
+ override fun getActivity(): Activity {
+ return this
+ }
+
+ private fun refresh() {
+ isRunning = false
+ flag = false
+ val secList = ArrayList<String>()
+ secList.add(getString(R.string.consume_menu_revenue))
+ secList.add(getString(R.string.consume_menu_transdtl_upload))
+ secList.add(getString(R.string.consume_menu_link_check))
+ secList.add(getString(R.string.consume_menu_auth))
+ secList.add(getString(R.string.consume_menu_syspara_query))
+ secList.add(getString(R.string.consume_menu_manage))
+ secList.add(getString(R.string.consume_menu_shop_password_set))
+ secList.add(getString(R.string.consume_menu_consume_mode))
+ if (isSupportReverse()) {
+ vReverse.visibility = View.VISIBLE
+ secList.add(getString(R.string.consume_menu_reverse))
+ } else {
+ vReverse.visibility = View.GONE
+ }
+ AuxScreenController.getInstance().refreshTitle("设备管理界面")
+ AuxScreenController.getInstance().refreshBottom(DateUtil.getNowDateTime())
+ AuxScreenController.getInstance().refreshContent(secList)
+ }
+
+ private fun isSupportReverse(): Boolean {
+ val sysRecord = SPApplication.getInstance().getPos().getSysPara()
+ return sysRecord != null && sysRecord.returnFlag and 0x1 == 1
+ }
+
+ private var counter: ContinuePressTimer? = null
+
+ private fun resetCounter(timems: Long) {
+ counter?.cancel()
+ if (counter == null) {
+ counter = ContinuePressTimer(timems, 100)
+ }
+ keyActive = false
+ counter!!.start()
+ }
+
+ private inner class ContinuePressTimer internal constructor(
+ millisInFuture: Long,
+ countDownInterval: Long
+ ) :
+ CountDownTimer(millisInFuture, countDownInterval) {
+
+ override fun onTick(millisUntilFinished: Long) {
+
+ }
+
+ override fun onFinish() {
+ keyActive = true
+ }
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/supwisdom/activities/passwd/PasswdActivity.kt b/app/src/main/java/com/supwisdom/activities/passwd/PasswdActivity.kt
index a288b3f..88d8b56 100644
--- a/app/src/main/java/com/supwisdom/activities/passwd/PasswdActivity.kt
+++ b/app/src/main/java/com/supwisdom/activities/passwd/PasswdActivity.kt
@@ -1,189 +1,212 @@
-package com.supwisdom.activities.passwd
-
-import android.os.Bundle
-import android.os.CountDownTimer
-import android.view.KeyEvent
-import com.supwisdom.R
-import com.supwisdom.activities.BaseActivity
-import com.supwisdom.activities.SPApplication
-import com.supwisdom.auxscreen.AuxScreenController
-import com.supwisdom.utils.CommonUtil
-import com.supwisdom.utils.DateUtil
-import java.util.*
-
-/**
- ** create by zzq on 2019/7/26
- ** @desc 商户密码修改
- **/
-class PasswdActivity : BaseActivity() {
- private lateinit var oldPwd: String
- private lateinit var newPwd: String
- private lateinit var newPwd1: String
- private lateinit var tmpPwd: String
- private lateinit var passwdHint: String
- private val pos = SPApplication.getInstance().getPos()
- private var step = 0
- private var keyActive = true
-
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- this.setContentView(R.layout.activity_password)
- }
-
- override fun dispatchKeyEvent(event: KeyEvent): Boolean {
- if (event.action == KeyEvent.ACTION_DOWN) {
- if (!keyActive) {
- return super.dispatchKeyEvent(event)
- }
- resetCounter(200)
-
- if (step == 3) {
- refresh()
- }
- val keyCode = event.keyCode
- when (keyCode) {
- KeyEvent.KEYCODE_0,
- KeyEvent.KEYCODE_1,
- KeyEvent.KEYCODE_2,
- KeyEvent.KEYCODE_3,
- KeyEvent.KEYCODE_4,
- KeyEvent.KEYCODE_5,
- KeyEvent.KEYCODE_6,
- KeyEvent.KEYCODE_7,
- KeyEvent.KEYCODE_8,
- KeyEvent.KEYCODE_9 -> {
- if (step == 4) {
- step = 0
- passwdHint = "输入原密码:"
- }
- tmpPwd += keyCode - KeyEvent.KEYCODE_0
- if (tmpPwd.length == 6) {
- when (step) {
- 0 -> {
- oldPwd = tmpPwd
- tmpPwd = ""
- if (checkOldPasswd()) {
- step = 1
- passwdHint = "输入新密码:"
- AuxScreenController.getInstance().refreshContent(Arrays.asList<String>(passwdHint, " "))
- return true
- } else {
- step = 4
- }
- return true
- }
- 1 -> {
- newPwd = tmpPwd
- tmpPwd = ""
- step = 2
- passwdHint = "确认新密码:"
- AuxScreenController.getInstance().refreshContent(Arrays.asList<String>(passwdHint, " "))
- return true
- }
- 2 -> {
- newPwd1 = tmpPwd
- step = 3
- tmpPwd = ""
- if (checkAndUpdate()) {
- AuxScreenController.getInstance()
- .refreshContent(Arrays.asList<String>("密码修改成功", " "))
- step = 3
- return true
- }
- step = 4
- return true
- }
- else -> tmpPwd = ""
- }
- }
- AuxScreenController.getInstance()
- .refreshContent(Arrays.asList(passwdHint, CommonUtil.getPasswordStar(tmpPwd.length)))
- return true
- }
- KeyEvent.KEYCODE_ENTER -> {
- }
- KeyEvent.KEYCODE_DEL -> {
- val len = tmpPwd.length
- when {
- len == 1 -> {
- tmpPwd = ""
- AuxScreenController.getInstance()
- .refreshContent(Arrays.asList(passwdHint, CommonUtil.getPasswordStar(tmpPwd.length)))
- }
- len > 1 -> {
- tmpPwd = tmpPwd.substring(0, len - 1)
- AuxScreenController.getInstance()
- .refreshContent(Arrays.asList(passwdHint, CommonUtil.getPasswordStar(tmpPwd.length)))
- }
- else -> finish()
- }
- return true
- }
- }
- }
- return super.dispatchKeyEvent(event)
- }
-
- override fun onResume() {
- super.onResume()
- keyActive = true
- refresh()
- }
-
- private fun refresh() {
- step = 0
- oldPwd = ""
- newPwd = ""
- newPwd1 = ""
- tmpPwd = ""
- passwdHint = "输入原密码"
- AuxScreenController.getInstance().refreshTitle("商户密码修改")
- AuxScreenController.getInstance().refreshBottom(DateUtil.getNowDateTime())
- AuxScreenController.getInstance().refreshContent(Arrays.asList<String>(passwdHint, " "))
- }
-
- private fun checkOldPasswd(): Boolean {
- if (oldPwd != pos.getConfigPara()!!.shopPwd) {
- AuxScreenController.getInstance().refreshContent(Arrays.asList<String>("修改密码错误", "原密码错误"))
- return false
- }
- return true
- }
-
- private fun checkAndUpdate(): Boolean {
- if (newPwd != newPwd1) {
- AuxScreenController.getInstance().refreshContent(Arrays.asList<String>("修改密码错误", "新密码不一致"))
- return false
- }
- val record = pos.getConfigPara()
- record!!.shopPwd = newPwd
- if (!pos.replaceConfigPara(record)) {
- AuxScreenController.getInstance().refreshContent(Arrays.asList<String>("修改密码错误", "密码保存失败"))
- return false
- }
- return true
- }
-
- private var counter: ContinuePressTimer? = null
-
- private fun resetCounter(timems: Long) {
- if (counter == null) {
- counter = ContinuePressTimer(timems, 100)
- }
- counter!!.cancel()
- keyActive = false
- counter!!.start()
- }
-
- private inner class ContinuePressTimer internal constructor(millisInFuture: Long, countDownInterval: Long) :
- CountDownTimer(millisInFuture, countDownInterval) {
-
- override fun onTick(millisUntilFinished: Long) {
-
- }
-
- override fun onFinish() {
- keyActive = true
- }
- }
+package com.supwisdom.activities.passwd
+
+import android.os.Bundle
+import android.os.CountDownTimer
+import android.view.KeyEvent
+import com.supwisdom.R
+import com.supwisdom.activities.BaseActivity
+import com.supwisdom.activities.SPApplication
+import com.supwisdom.activities.auxscreen.AuxScreenController
+import com.supwisdom.utils.CommonUtil
+import com.supwisdom.utils.DateUtil
+import java.util.*
+
+/**
+ ** create by zzq on 2019/7/26
+ ** @desc 商户密码修改
+ **/
+class PasswdActivity : BaseActivity() {
+ private lateinit var oldPwd: String
+ private lateinit var newPwd: String
+ private lateinit var newPwd1: String
+ private lateinit var tmpPwd: String
+ private lateinit var passwdHint: String
+ private val pos = SPApplication.getInstance().getPos()
+ private var step = 0
+ private var keyActive = true
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ this.setContentView(R.layout.activity_password)
+ }
+
+ override fun dispatchKeyEvent(event: KeyEvent): Boolean {
+ if (event.action == KeyEvent.ACTION_DOWN) {
+ if (!keyActive) {
+ return super.dispatchKeyEvent(event)
+ }
+ resetCounter(200)
+
+ if (step == 3) {
+ refresh()
+ }
+ val keyCode = event.keyCode
+ when (keyCode) {
+ KeyEvent.KEYCODE_0,
+ KeyEvent.KEYCODE_1,
+ KeyEvent.KEYCODE_2,
+ KeyEvent.KEYCODE_3,
+ KeyEvent.KEYCODE_4,
+ KeyEvent.KEYCODE_5,
+ KeyEvent.KEYCODE_6,
+ KeyEvent.KEYCODE_7,
+ KeyEvent.KEYCODE_8,
+ KeyEvent.KEYCODE_9 -> {
+ if (step == 4) {
+ step = 0
+ passwdHint = "输入原密码:"
+ }
+ tmpPwd += keyCode - KeyEvent.KEYCODE_0
+ if (tmpPwd.length == 6) {
+ when (step) {
+ 0 -> {
+ oldPwd = tmpPwd
+ tmpPwd = ""
+ if (checkOldPasswd()) {
+ step = 1
+ passwdHint = "输入新密码:"
+ AuxScreenController.getInstance()
+ .refreshContent(Arrays.asList<String>(passwdHint, " "))
+ return true
+ } else {
+ step = 4
+ }
+ return true
+ }
+ 1 -> {
+ newPwd = tmpPwd
+ tmpPwd = ""
+ step = 2
+ passwdHint = "确认新密码:"
+ AuxScreenController.getInstance()
+ .refreshContent(Arrays.asList<String>(passwdHint, " "))
+ return true
+ }
+ 2 -> {
+ newPwd1 = tmpPwd
+ step = 3
+ tmpPwd = ""
+ if (checkAndUpdate()) {
+ AuxScreenController.getInstance()
+ .refreshContent(Arrays.asList<String>("密码修改成功", " "))
+ step = 3
+ return true
+ }
+ step = 4
+ return true
+ }
+ else -> tmpPwd = ""
+ }
+ }
+ AuxScreenController.getInstance()
+ .refreshContent(
+ Arrays.asList(
+ passwdHint,
+ CommonUtil.getPasswordStar(tmpPwd.length)
+ )
+ )
+ return true
+ }
+ KeyEvent.KEYCODE_ENTER -> {
+ }
+ KeyEvent.KEYCODE_DEL -> {
+ val len = tmpPwd.length
+ when {
+ len == 1 -> {
+ tmpPwd = ""
+ AuxScreenController.getInstance()
+ .refreshContent(
+ Arrays.asList(
+ passwdHint,
+ CommonUtil.getPasswordStar(tmpPwd.length)
+ )
+ )
+ }
+ len > 1 -> {
+ tmpPwd = tmpPwd.substring(0, len - 1)
+ AuxScreenController.getInstance()
+ .refreshContent(
+ Arrays.asList(
+ passwdHint,
+ CommonUtil.getPasswordStar(tmpPwd.length)
+ )
+ )
+ }
+ else -> finish()
+ }
+ return true
+ }
+ }
+ }
+ return super.dispatchKeyEvent(event)
+ }
+
+ override fun onResume() {
+ super.onResume()
+ keyActive = true
+ refresh()
+ }
+
+ private fun refresh() {
+ step = 0
+ oldPwd = ""
+ newPwd = ""
+ newPwd1 = ""
+ tmpPwd = ""
+ passwdHint = "输入原密码"
+ AuxScreenController.getInstance().refreshTitle("商户密码修改")
+ AuxScreenController.getInstance().refreshBottom(DateUtil.getNowDateTime())
+ AuxScreenController.getInstance().refreshContent(Arrays.asList<String>(passwdHint, " "))
+ }
+
+ private fun checkOldPasswd(): Boolean {
+ if (oldPwd != pos.getConfigPara()!!.shopPwd) {
+ AuxScreenController.getInstance()
+ .refreshContent(Arrays.asList<String>("修改密码错误", "原密码错误"))
+ return false
+ }
+ return true
+ }
+
+ private fun checkAndUpdate(): Boolean {
+ if (newPwd != newPwd1) {
+ AuxScreenController.getInstance()
+ .refreshContent(Arrays.asList<String>("修改密码错误", "新密码不一致"))
+ return false
+ }
+ val record = pos.getConfigPara()
+ record!!.shopPwd = newPwd
+ if (!pos.replaceConfigPara(record)) {
+ AuxScreenController.getInstance()
+ .refreshContent(Arrays.asList<String>("修改密码错误", "密码保存失败"))
+ return false
+ }
+ return true
+ }
+
+ private var counter: ContinuePressTimer? = null
+
+ private fun resetCounter(timems: Long) {
+ if (counter == null) {
+ counter = ContinuePressTimer(timems, 100)
+ }
+ counter!!.cancel()
+ keyActive = false
+ counter!!.start()
+ }
+
+ private inner class ContinuePressTimer internal constructor(
+ millisInFuture: Long,
+ countDownInterval: Long
+ ) :
+ CountDownTimer(millisInFuture, countDownInterval) {
+
+ override fun onTick(millisUntilFinished: Long) {
+
+ }
+
+ override fun onFinish() {
+ keyActive = true
+ }
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/supwisdom/activities/revenue/RevenueActivity.kt b/app/src/main/java/com/supwisdom/activities/revenue/RevenueActivity.kt
index 895d5b4..34516e4 100644
--- a/app/src/main/java/com/supwisdom/activities/revenue/RevenueActivity.kt
+++ b/app/src/main/java/com/supwisdom/activities/revenue/RevenueActivity.kt
@@ -1,148 +1,169 @@
-package com.supwisdom.activities.revenue
-
-import android.os.Bundle
-import android.view.KeyEvent
-import android.widget.TextView
-import com.supwisdom.R
-import com.supwisdom.activities.BaseActivity
-import com.supwisdom.activities.menu.MenuActivity
-import com.supwisdom.activities.revenue.bean.RevenueAmtRetBean
-import com.supwisdom.auxscreen.AuxScreenController
-import com.supwisdom.utils.DateUtil
-import java.util.*
-
-/**
- ** create by zzq on 2019/7/26
- ** @desc
- **/
-class RevenueActivity : BaseActivity(), IRevenueView {
- private lateinit var vContent: TextView
- private lateinit var vSearchDate: TextView
- private lateinit var presenter: RevenuePresenter
- private var isSearching: Boolean = false
-
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- this.setContentView(R.layout.activity_revenue)
- initView()
- initData()
- }
-
- private fun initData() {
- presenter = RevenuePresenter(this)
- }
-
- private fun initView() {
- vContent = this.findViewById<TextView>(R.id.revenue_content)
- vSearchDate = this.findViewById<TextView>(R.id.revenue_date)
- }
-
- private fun refresh() {
- AuxScreenController.getInstance().refreshTitle("营业额查询")
- AuxScreenController.getInstance().refreshBottom("F3/F4 切换日期")
- AuxScreenController.getInstance()
- .refreshContent(Arrays.asList<String>("查询日期:" + DateUtil.getNowDateSpecFormat(), "正在查询.", "请稍等...", " "))
-
- val searchDate = DateUtil.getNowDateNoFormat()
- vSearchDate.text = searchDate
- isSearching = false
- presenter.queryRevenue(searchDate)
- }
-
- override fun dispatchKeyEvent(event: KeyEvent): Boolean {
- if (event.action == KeyEvent.ACTION_DOWN) {
- if (isSearching) {
- return false
- }
- when (event.keyCode) {
- //case KeyEvent.KEYCODE_DPAD_UP:
- //F2
- KeyEvent.KEYCODE_DPAD_DOWN -> {
- //F3
- movePredate()
- return true
- }
- KeyEvent.KEYCODE_DPAD_RIGHT -> {
- //F4
- moveNextDate()
- return true
- }
- KeyEvent.KEYCODE_DEL -> {
- //cancel
- jumpActivity(MenuActivity::class.java)
- return true
- }
- }//case KeyEvent.KEYCODE_ENTER:
- //ok
- // return true;
- }
- return super.dispatchKeyEvent(event)
- }
-
- private fun moveNextDate() {
- val date = getSearchDate()
- if (date >= DateUtil.getNowDateNoFormat()) {
- return
- }
- isSearching = true
- val nextdate = DateUtil.getSpecifiedDayAfter(date)
- vSearchDate.text = nextdate
- AuxScreenController.getInstance()
- .refreshContent(Arrays.asList<String>("查询日期:" + convertDateToShow(nextdate), "正在查询", "请稍等...", " "))
- presenter.queryRevenue(nextdate)
- }
-
- private fun movePredate() {
- isSearching = true
- val predate = DateUtil.getSpecifiedDayBefore(getSearchDate())
- vSearchDate.text = predate
- AuxScreenController.getInstance()
- .refreshContent(Arrays.asList<String>("查询日期:" + convertDateToShow(predate), "正在查询", "请稍等...", " "))
- presenter.queryRevenue(predate)
- }
-
- private fun convertDateToShow(date: String): String {
- return date.substring(0, 4) + "/" + date.substring(4, 6) + "/" + date.substring(6)
- }
-
- override fun onResume() {
- super.onResume()
- refresh()
- }
-
- override fun onDestroy() {
- super.onDestroy()
- }
-
- override fun showRevenueFail(msg: String) {
- isSearching = false
- vContent.text = "查询失败\n原因: $msg"
- AuxScreenController.getInstance().refreshContent(
- Arrays.asList<String>(
- "查询日期:" + convertDateToShow(getSearchDate()),
- "查询失败:", "原因:$msg", " "
- )
- )
- }
-
- override fun showRevenueSuc(record: RevenueAmtRetBean) {
- isSearching = false
- val sb = StringBuilder("查询成功\n")
- sb.append("有效笔数 : ").append(record.salescnt).append("笔\n")
- .append("营业汇总 : ").append(String.format("%.02f 元", record.salesamt / 100.0f))
- vContent.text = sb.toString()
-
- AuxScreenController.getInstance().refreshContent(
- Arrays.asList<String>(
- "查询日期:" + convertDateToShow(getSearchDate()),
- "查询成功:",
- "有效笔数:" + record.salescnt + "笔",
- "营业汇总:" + String.format("%.02f元", record.salesamt / 100.0f)
- )
- )
- }
-
- private fun getSearchDate(): String {
- return vSearchDate.text.toString()
- }
+package com.supwisdom.activities.revenue
+
+import android.os.Bundle
+import android.view.KeyEvent
+import android.widget.TextView
+import com.supwisdom.R
+import com.supwisdom.activities.BaseActivity
+import com.supwisdom.activities.auxscreen.AuxScreenController
+import com.supwisdom.activities.menu.MenuActivity
+import com.supwisdom.activities.revenue.bean.RevenueAmtRetBean
+import com.supwisdom.utils.DateUtil
+import java.util.*
+
+/**
+ ** create by zzq on 2019/7/26
+ ** @desc
+ **/
+class RevenueActivity : BaseActivity(), IRevenueView {
+ private lateinit var vContent: TextView
+ private lateinit var vSearchDate: TextView
+ private lateinit var presenter: RevenuePresenter
+ private var isSearching: Boolean = false
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ this.setContentView(R.layout.activity_revenue)
+ initView()
+ initData()
+ }
+
+ private fun initData() {
+ presenter = RevenuePresenter(this)
+ }
+
+ private fun initView() {
+ vContent = this.findViewById<TextView>(R.id.revenue_content)
+ vSearchDate = this.findViewById<TextView>(R.id.revenue_date)
+ }
+
+ private fun refresh() {
+ AuxScreenController.getInstance().refreshTitle("营业额查询")
+ AuxScreenController.getInstance().refreshBottom("F3/F4 切换日期")
+ AuxScreenController.getInstance()
+ .refreshContent(
+ Arrays.asList<String>(
+ "查询日期:" + DateUtil.getNowDateSpecFormat(),
+ "正在查询.",
+ "请稍等...",
+ " "
+ )
+ )
+
+ val searchDate = DateUtil.getNowDateNoFormat()
+ vSearchDate.text = searchDate
+ isSearching = false
+ presenter.queryRevenue(searchDate)
+ }
+
+ override fun dispatchKeyEvent(event: KeyEvent): Boolean {
+ if (event.action == KeyEvent.ACTION_DOWN) {
+ if (isSearching) {
+ return false
+ }
+ when (event.keyCode) {
+ //case KeyEvent.KEYCODE_DPAD_UP:
+ //F2
+ KeyEvent.KEYCODE_DPAD_DOWN -> {
+ //F3
+ movePredate()
+ return true
+ }
+ KeyEvent.KEYCODE_DPAD_RIGHT -> {
+ //F4
+ moveNextDate()
+ return true
+ }
+ KeyEvent.KEYCODE_DEL -> {
+ //cancel
+ jumpActivity(MenuActivity::class.java)
+ return true
+ }
+ }//case KeyEvent.KEYCODE_ENTER:
+ //ok
+ // return true;
+ }
+ return super.dispatchKeyEvent(event)
+ }
+
+ private fun moveNextDate() {
+ val date = getSearchDate()
+ if (date >= DateUtil.getNowDateNoFormat()) {
+ return
+ }
+ isSearching = true
+ val nextdate = DateUtil.getSpecifiedDayAfter(date)
+ vSearchDate.text = nextdate
+ AuxScreenController.getInstance()
+ .refreshContent(
+ Arrays.asList<String>(
+ "查询日期:" + convertDateToShow(nextdate),
+ "正在查询",
+ "请稍等...",
+ " "
+ )
+ )
+ presenter.queryRevenue(nextdate)
+ }
+
+ private fun movePredate() {
+ isSearching = true
+ val predate = DateUtil.getSpecifiedDayBefore(getSearchDate())
+ vSearchDate.text = predate
+ AuxScreenController.getInstance()
+ .refreshContent(
+ Arrays.asList<String>(
+ "查询日期:" + convertDateToShow(predate),
+ "正在查询",
+ "请稍等...",
+ " "
+ )
+ )
+ presenter.queryRevenue(predate)
+ }
+
+ private fun convertDateToShow(date: String): String {
+ return date.substring(0, 4) + "/" + date.substring(4, 6) + "/" + date.substring(6)
+ }
+
+ override fun onResume() {
+ super.onResume()
+ refresh()
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ }
+
+ override fun showRevenueFail(msg: String) {
+ isSearching = false
+ vContent.text = "查询失败\n原因: $msg"
+ AuxScreenController.getInstance().refreshContent(
+ Arrays.asList<String>(
+ "查询日期:" + convertDateToShow(getSearchDate()),
+ "查询失败:", "原因:$msg", " "
+ )
+ )
+ }
+
+ override fun showRevenueSuc(record: RevenueAmtRetBean) {
+ isSearching = false
+ val sb = StringBuilder("查询成功\n")
+ sb.append("有效笔数 : ").append(record.salescnt).append("笔\n")
+ .append("营业汇总 : ").append(String.format("%.02f 元", record.salesamt / 100.0f))
+ vContent.text = sb.toString()
+
+ AuxScreenController.getInstance().refreshContent(
+ Arrays.asList<String>(
+ "查询日期:" + convertDateToShow(getSearchDate()),
+ "查询成功:",
+ "有效笔数:" + record.salescnt + "笔",
+ "营业汇总:" + String.format("%.02f元", record.salesamt / 100.0f)
+ )
+ )
+ }
+
+ private fun getSearchDate(): String {
+ return vSearchDate.text.toString()
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/supwisdom/activities/splash/SplashActivity.kt b/app/src/main/java/com/supwisdom/activities/splash/SplashActivity.kt
index fd80a3a..b4710ba 100644
--- a/app/src/main/java/com/supwisdom/activities/splash/SplashActivity.kt
+++ b/app/src/main/java/com/supwisdom/activities/splash/SplashActivity.kt
@@ -1,84 +1,89 @@
-package com.supwisdom.activities.splash
-
-import android.Manifest
-import android.content.pm.PackageManager
-import android.os.Build
-import android.os.Bundle
-import android.view.View
-import android.widget.TextView
-import com.supwisdom.R
-import com.supwisdom.activities.BaseActivity
-import com.supwisdom.activities.cardlib.CardlibActivity
-import com.supwisdom.auxscreen.AuxScreenController
-import com.supwisdom.utils.CommonUtil
-import com.supwisdom.utils.DateUtil
-
-/**
- ** create by zzq on 2019/7/25
- ** @desc
- **/
-class SplashActivity : BaseActivity() {
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_splash)
- initView()
- }
-
- override fun onResume() {
- super.onResume()
- refresh()
- if (hasSdcardPermession()) {
- processStart()
- }
- }
-
- private fun processStart() {
- CommonUtil.writeLinnuuxParams()
- jumpActivity(CardlibActivity::class.java)
- }
-
- private fun refresh() {
- AuxScreenController.getInstance().refreshTitle("新开普智能设备")
- AuxScreenController.getInstance().refreshBottom(DateUtil.getNowDateTime())
- AuxScreenController.getInstance().refreshContent(listOf<String>("欢迎使用智能设备"))
- }
-
- private fun initView() {
- val tv = findViewById<View>(R.id.versionNumber) as TextView
- tv.text = CommonUtil.getVersionName(applicationContext)
- AuxScreenController.getInstance().open()
- }
-
- private val REQUEST_RETCODE = 99
-
- private fun hasSdcardPermession(): Boolean {
- /**
- * 动态获取权限,Android 6.0 新特性,一些保护权限,除了要在AndroidManifest中声明权限,还要使用如下代码动态获取
- */
- if (Build.VERSION.SDK_INT >= 23) {
- val permissions = arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA)
- //验证是否许可权限
- for (str in permissions) {
- if (this.checkSelfPermission(str) != PackageManager.PERMISSION_GRANTED) {
- //申请权限
- this.requestPermissions(permissions, REQUEST_RETCODE)
- return false
- }
- }
- }
- return true
- }
-
- override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
- super.onRequestPermissionsResult(requestCode, permissions, grantResults)
- if (requestCode == REQUEST_RETCODE) {
- for (i in grantResults.indices) {
- if (grantResults[i] != PackageManager.PERMISSION_GRANTED) {
- return
- }
- }
- // 请求权限的结果 true代表用户同意了
- processStart()
- }
- }
+package com.supwisdom.activities.splash
+
+import android.Manifest
+import android.content.pm.PackageManager
+import android.os.Build
+import android.os.Bundle
+import android.view.View
+import android.widget.TextView
+import com.supwisdom.R
+import com.supwisdom.activities.BaseActivity
+import com.supwisdom.activities.auxscreen.AuxScreenController
+import com.supwisdom.activities.cardlib.CardlibActivity
+import com.supwisdom.utils.CommonUtil
+import com.supwisdom.utils.DateUtil
+
+/**
+ ** create by zzq on 2019/7/25
+ ** @desc
+ **/
+class SplashActivity : BaseActivity() {
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_splash)
+ initView()
+ }
+
+ override fun onResume() {
+ super.onResume()
+ refresh()
+ if (hasSdcardPermession()) {
+ processStart()
+ }
+ }
+
+ private fun processStart() {
+ CommonUtil.writeLinnuuxParams()
+ jumpActivity(CardlibActivity::class.java)
+ }
+
+ private fun refresh() {
+ AuxScreenController.getInstance().refreshTitle("新开普智能设备")
+ AuxScreenController.getInstance().refreshBottom(DateUtil.getNowDateTime())
+ AuxScreenController.getInstance().refreshContent(listOf<String>("欢迎使用智能设备"))
+ }
+
+ private fun initView() {
+ val tv = findViewById<View>(R.id.versionNumber) as TextView
+ tv.text = CommonUtil.getVersionName(applicationContext)
+ AuxScreenController.getInstance().open()
+ }
+
+ private val REQUEST_RETCODE = 99
+
+ private fun hasSdcardPermession(): Boolean {
+ /**
+ * 动态获取权限,Android 6.0 新特性,一些保护权限,除了要在AndroidManifest中声明权限,还要使用如下代码动态获取
+ */
+ if (Build.VERSION.SDK_INT >= 23) {
+ val permissions =
+ arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA)
+ //验证是否许可权限
+ for (str in permissions) {
+ if (this.checkSelfPermission(str) != PackageManager.PERMISSION_GRANTED) {
+ //申请权限
+ this.requestPermissions(permissions, REQUEST_RETCODE)
+ return false
+ }
+ }
+ }
+ return true
+ }
+
+ override fun onRequestPermissionsResult(
+ requestCode: Int,
+ permissions: Array<String>,
+ grantResults: IntArray
+ ) {
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults)
+ if (requestCode == REQUEST_RETCODE) {
+ for (i in grantResults.indices) {
+ if (grantResults[i] != PackageManager.PERMISSION_GRANTED) {
+ return
+ }
+ }
+ // 请求权限的结果 true代表用户同意了
+ processStart()
+ }
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/supwisdom/activities/syspara/SysparaActivity.kt b/app/src/main/java/com/supwisdom/activities/syspara/SysparaActivity.kt
index 6c0b764..c3a16c7 100644
--- a/app/src/main/java/com/supwisdom/activities/syspara/SysparaActivity.kt
+++ b/app/src/main/java/com/supwisdom/activities/syspara/SysparaActivity.kt
@@ -7,9 +7,9 @@
import com.supwisdom.R
import com.supwisdom.activities.BaseActivity
import com.supwisdom.activities.SPApplication
+import com.supwisdom.activities.auxscreen.AuxScreenController
import com.supwisdom.activities.menu.MenuActivity
import com.supwisdom.activities.syspara.adapter.SysparaAdapter
-import com.supwisdom.auxscreen.AuxScreenController
import com.supwisdom.entity.ControlParaRecord
import com.supwisdom.utils.CommonUtil
import com.supwisdom.utils.PublicDef
diff --git a/app/src/main/java/com/supwisdom/activities/transdtl/TransdtlActivity.kt b/app/src/main/java/com/supwisdom/activities/transdtl/TransdtlActivity.kt
index 35a0be7..877e944 100644
--- a/app/src/main/java/com/supwisdom/activities/transdtl/TransdtlActivity.kt
+++ b/app/src/main/java/com/supwisdom/activities/transdtl/TransdtlActivity.kt
@@ -1,234 +1,234 @@
-package com.supwisdom.activities.transdtl
-
-import android.os.AsyncTask
-import android.os.Bundle
-import android.os.CountDownTimer
-import android.view.KeyEvent
-import android.widget.TextView
-import com.supwisdom.R
-import com.supwisdom.activities.BaseActivity
-import com.supwisdom.activities.SPApplication
-import com.supwisdom.activities.consume.ConsumeActivity
-import com.supwisdom.auxscreen.AuxScreenController
-import com.supwisdom.entity.PayStatus
-import com.supwisdom.entity.ReversalFlag
-import com.supwisdom.entity.TransdtlUnionRecord
-import com.supwisdom.utils.DateUtil
-import java.util.*
-
-/**
- ** create by zzq on 2019/7/26
- ** @desc
- **/
-class TransdtlActivity : BaseActivity() {
- private val pos = SPApplication.getInstance().getPos()
- private lateinit var vSeqno: TextView
- private lateinit var vContent: TextView
- private var isSearching: Boolean = false
- @Volatile
- private var keyActive = true
- private var hasdtlFlag = true
- private val MAX_SEARCH_NUM = 19
-
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- this.setContentView(R.layout.activity_transdtl)
- initView()
- }
-
- private fun initView() {
- vSeqno = findViewById<TextView>(R.id.transdtl_seqno)
- vContent = findViewById<TextView>(R.id.transdtl_content)
- }
-
- private fun refresh() {
- setShowSeqno(1)
- doSearch(1)
- }
-
- private fun showCustomQuery(seqno: Int) {
- AuxScreenController.getInstance().refreshTitle("流水记录查询")
- AuxScreenController.getInstance().refreshBottom("F3/F4 切换记录")
- AuxScreenController.getInstance()
- .refreshContent(Arrays.asList<String>("流水索引号:$seqno", "正在查询", "请稍等...", " ", " ", " "))
- }
-
- override fun dispatchKeyEvent(event: KeyEvent): Boolean {
- if (event.action == KeyEvent.ACTION_DOWN) {
- if (isSearching || !keyActive) {
- return super.dispatchKeyEvent(event)
- }
- resetCounter(200)
-
- when (event.keyCode) {
- KeyEvent.KEYCODE_DPAD_UP -> {
- }
- KeyEvent.KEYCODE_DPAD_DOWN ->
- //F3
- movePreSeqno()
- KeyEvent.KEYCODE_DPAD_RIGHT ->
- //F4
- moveNextSeqno()
- KeyEvent.KEYCODE_DEL ->
- //cancel
- jumpActivity(ConsumeActivity::class.java)
- }//F2
- }
- return super.dispatchKeyEvent(event)
- }
-
- private fun moveNextSeqno() {
- if (!hasdtlFlag) {
- return
- }
- var seqno = getShowSeqno()
- if (seqno > MAX_SEARCH_NUM) {
- return
- }
- seqno += 1
- setShowSeqno(seqno)
- doSearch(seqno)
- }
-
- private fun movePreSeqno() {
- var seqno = getShowSeqno()
- if (seqno > 1) {
- seqno -= 1
- setShowSeqno(seqno)
- doSearch(seqno)
- }
- }
-
- private fun doSearch(seqno: Int) {
- isSearching = true
- showCustomQuery(seqno)
- queryTransdtl(seqno - 1)
- }
-
- override fun onDestroy() {
- super.onDestroy()
- }
-
- override fun onResume() {
- super.onResume()
- hasdtlFlag = true
- keyActive = true
- refresh()
- }
-
- fun showTransdtlResult(record: TransdtlUnionRecord?) {
- isSearching = false
- if (record == null) {
- hasdtlFlag = false
- vContent.text = "未找到消费记录"
- AuxScreenController.getInstance().refreshContent(
- Arrays.asList<String>(
- "流水索引号:" + getShowSeqno(),
- "查询失败:", "未找到消费记录", " ", " ", " "
- )
- )
- } else {
- hasdtlFlag = true
- val transdatetime = StringBuilder()
- transdatetime.append(record.transdate!!.substring(0, 4)).append("-")
- .append(record.transdate!!.substring(4, 6)).append("-")
- .append(record.transdate!!.substring(6)).append(" ")
- .append(record.transtime!!.substring(0, 2)).append(":")
- .append(record.transtime!!.substring(2, 4)).append(":")
- .append(record.transtime!!.substring(4))
- val result = if (record.status == PayStatus.SUC) {
- if (record.reversalflag == ReversalFlag.AUTO ||
- record.reversalflag == ReversalFlag.MANUAL
- ) {
- "已退款"
- } else {
- "消费成功"
- }
- } else {
- if (record.reversalflag == ReversalFlag.AUTO ||
- record.reversalflag == ReversalFlag.MANUAL
- ) {
- "冲正失败"
- } else {
- "消费失败"
- }
- }
- val payWay = if (record.payway == "code") {
- "二维码"
- } else {
- "市民卡"
- }
- val sb = StringBuilder("查询成功 \n")
- if (record.username != null) {
- sb.append("姓名: ").append(record.username)
- } else {
- sb.append("卡号: ").append(record.cardno)
- }
- sb.append("\n").append("支付方式: ").append(payWay).append("\n")
- .append(String.format("支付金额: %.02f元", record.payamt / 100.0f)).append("\n")
- .append("支付时间: ").append(transdatetime.toString()).append("\n")
- .append("支付结果: ").append(result)
- vContent.text = sb.toString()
-
- AuxScreenController.getInstance().refreshContent(
- Arrays.asList(
- "时间:$transdatetime",
- "姓名:" + record.username,
- String.format("金额:%.02f元", record.payamt / 100.0f),
- "方式:$payWay", "结果:$result"
- )
- )
- }
- }
-
- private fun getShowSeqno(): Int {
- return Integer.parseInt(vSeqno.text.toString())
- }
-
- private fun setShowSeqno(seqno: Int) {
- vSeqno.text = seqno.toString()
- }
-
- private fun queryTransdtl(seqno: Int) {
- AsyncTransdtl().execute(seqno)
- }
-
- private inner class AsyncTransdtl : AsyncTask<Int, Void, TransdtlUnionRecord?>() {
- override fun onPostExecute(record: TransdtlUnionRecord?) {
- showTransdtlResult(record)
- }
-
- override fun doInBackground(vararg integers: Int?): TransdtlUnionRecord? {
- val searchSeqno = integers[0]!!
- val list = pos.getTransdtlUnion(DateUtil.getNowDateNoFormat(), searchSeqno, 1, 1)
- return if (list.isNotEmpty()) {
- list[0]
- } else {
- null
- }
- }
- }
-
- private var counter: ContinuePressTimer? = null
-
- private fun resetCounter(timems: Long) {
- counter?.cancel()
- if (counter == null) {
- counter = ContinuePressTimer(timems, 100)
- }
- keyActive = false
- counter!!.start()
- }
-
- private inner class ContinuePressTimer internal constructor(millisInFuture: Long, countDownInterval: Long) :
- CountDownTimer(millisInFuture, countDownInterval) {
-
- override fun onTick(millisUntilFinished: Long) {
-
- }
-
- override fun onFinish() {
- keyActive = true
- }
- }
+package com.supwisdom.activities.transdtl
+
+import android.os.AsyncTask
+import android.os.Bundle
+import android.os.CountDownTimer
+import android.view.KeyEvent
+import android.widget.TextView
+import com.supwisdom.R
+import com.supwisdom.activities.BaseActivity
+import com.supwisdom.activities.SPApplication
+import com.supwisdom.activities.auxscreen.AuxScreenController
+import com.supwisdom.activities.consume.ConsumeActivity
+import com.supwisdom.entity.PayStatus
+import com.supwisdom.entity.ReversalFlag
+import com.supwisdom.entity.TransdtlUnionRecord
+import com.supwisdom.utils.DateUtil
+import java.util.*
+
+/**
+ ** create by zzq on 2019/7/26
+ ** @desc
+ **/
+class TransdtlActivity : BaseActivity() {
+ private val pos = SPApplication.getInstance().getPos()
+ private lateinit var vSeqno: TextView
+ private lateinit var vContent: TextView
+ private var isSearching: Boolean = false
+ @Volatile
+ private var keyActive = true
+ private var hasdtlFlag = true
+ private val MAX_SEARCH_NUM = 19
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ this.setContentView(R.layout.activity_transdtl)
+ initView()
+ }
+
+ private fun initView() {
+ vSeqno = findViewById<TextView>(R.id.transdtl_seqno)
+ vContent = findViewById<TextView>(R.id.transdtl_content)
+ }
+
+ private fun refresh() {
+ setShowSeqno(1)
+ doSearch(1)
+ }
+
+ private fun showCustomQuery(seqno: Int) {
+ AuxScreenController.getInstance().refreshTitle("流水记录查询")
+ AuxScreenController.getInstance().refreshBottom("F3/F4 切换记录")
+ AuxScreenController.getInstance()
+ .refreshContent(Arrays.asList<String>("流水索引号:$seqno", "正在查询", "请稍等...", " ", " ", " "))
+ }
+
+ override fun dispatchKeyEvent(event: KeyEvent): Boolean {
+ if (event.action == KeyEvent.ACTION_DOWN) {
+ if (isSearching || !keyActive) {
+ return super.dispatchKeyEvent(event)
+ }
+ resetCounter(200)
+
+ when (event.keyCode) {
+ KeyEvent.KEYCODE_DPAD_UP -> {
+ }
+ KeyEvent.KEYCODE_DPAD_DOWN ->
+ //F3
+ movePreSeqno()
+ KeyEvent.KEYCODE_DPAD_RIGHT ->
+ //F4
+ moveNextSeqno()
+ KeyEvent.KEYCODE_DEL ->
+ //cancel
+ jumpActivity(ConsumeActivity::class.java)
+ }//F2
+ }
+ return super.dispatchKeyEvent(event)
+ }
+
+ private fun moveNextSeqno() {
+ if (!hasdtlFlag) {
+ return
+ }
+ var seqno = getShowSeqno()
+ if (seqno > MAX_SEARCH_NUM) {
+ return
+ }
+ seqno += 1
+ setShowSeqno(seqno)
+ doSearch(seqno)
+ }
+
+ private fun movePreSeqno() {
+ var seqno = getShowSeqno()
+ if (seqno > 1) {
+ seqno -= 1
+ setShowSeqno(seqno)
+ doSearch(seqno)
+ }
+ }
+
+ private fun doSearch(seqno: Int) {
+ isSearching = true
+ showCustomQuery(seqno)
+ queryTransdtl(seqno - 1)
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ }
+
+ override fun onResume() {
+ super.onResume()
+ hasdtlFlag = true
+ keyActive = true
+ refresh()
+ }
+
+ fun showTransdtlResult(record: TransdtlUnionRecord?) {
+ isSearching = false
+ if (record == null) {
+ hasdtlFlag = false
+ vContent.text = "未找到消费记录"
+ AuxScreenController.getInstance().refreshContent(
+ Arrays.asList<String>(
+ "流水索引号:" + getShowSeqno(),
+ "查询失败:", "未找到消费记录", " ", " ", " "
+ )
+ )
+ } else {
+ hasdtlFlag = true
+ val transdatetime = StringBuilder()
+ transdatetime.append(record.transdate!!.substring(0, 4)).append("-")
+ .append(record.transdate!!.substring(4, 6)).append("-")
+ .append(record.transdate!!.substring(6)).append(" ")
+ .append(record.transtime!!.substring(0, 2)).append(":")
+ .append(record.transtime!!.substring(2, 4)).append(":")
+ .append(record.transtime!!.substring(4))
+ val result = if (record.status == PayStatus.SUC) {
+ if (record.reversalflag == ReversalFlag.AUTO ||
+ record.reversalflag == ReversalFlag.MANUAL
+ ) {
+ "已退款"
+ } else {
+ "消费成功"
+ }
+ } else {
+ if (record.reversalflag == ReversalFlag.AUTO ||
+ record.reversalflag == ReversalFlag.MANUAL
+ ) {
+ "冲正失败"
+ } else {
+ "消费失败"
+ }
+ }
+ val payWay = if (record.payway == "code") {
+ "二维码"
+ } else {
+ "市民卡"
+ }
+ val sb = StringBuilder("查询成功 \n")
+ if (record.username != null) {
+ sb.append("姓名: ").append(record.username)
+ } else {
+ sb.append("卡号: ").append(record.cardno)
+ }
+ sb.append("\n").append("支付方式: ").append(payWay).append("\n")
+ .append(String.format("支付金额: %.02f元", record.payamt / 100.0f)).append("\n")
+ .append("支付时间: ").append(transdatetime.toString()).append("\n")
+ .append("支付结果: ").append(result)
+ vContent.text = sb.toString()
+
+ AuxScreenController.getInstance().refreshContent(
+ Arrays.asList(
+ "时间:$transdatetime",
+ "姓名:" + record.username,
+ String.format("金额:%.02f元", record.payamt / 100.0f),
+ "方式:$payWay", "结果:$result"
+ )
+ )
+ }
+ }
+
+ private fun getShowSeqno(): Int {
+ return Integer.parseInt(vSeqno.text.toString())
+ }
+
+ private fun setShowSeqno(seqno: Int) {
+ vSeqno.text = seqno.toString()
+ }
+
+ private fun queryTransdtl(seqno: Int) {
+ AsyncTransdtl().execute(seqno)
+ }
+
+ private inner class AsyncTransdtl : AsyncTask<Int, Void, TransdtlUnionRecord?>() {
+ override fun onPostExecute(record: TransdtlUnionRecord?) {
+ showTransdtlResult(record)
+ }
+
+ override fun doInBackground(vararg integers: Int?): TransdtlUnionRecord? {
+ val searchSeqno = integers[0]!!
+ val list = pos.getTransdtlUnion(DateUtil.getNowDateNoFormat(), searchSeqno, 1, 1)
+ return if (list.isNotEmpty()) {
+ list[0]
+ } else {
+ null
+ }
+ }
+ }
+
+ private var counter: ContinuePressTimer? = null
+
+ private fun resetCounter(timems: Long) {
+ counter?.cancel()
+ if (counter == null) {
+ counter = ContinuePressTimer(timems, 100)
+ }
+ keyActive = false
+ counter!!.start()
+ }
+
+ private inner class ContinuePressTimer internal constructor(millisInFuture: Long, countDownInterval: Long) :
+ CountDownTimer(millisInFuture, countDownInterval) {
+
+ override fun onTick(millisUntilFinished: Long) {
+
+ }
+
+ override fun onFinish() {
+ keyActive = true
+ }
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/supwisdom/activities/unregister/UnregisterActivity.kt b/app/src/main/java/com/supwisdom/activities/unregister/UnregisterActivity.kt
index 14e8c6f..8eff856 100644
--- a/app/src/main/java/com/supwisdom/activities/unregister/UnregisterActivity.kt
+++ b/app/src/main/java/com/supwisdom/activities/unregister/UnregisterActivity.kt
@@ -1,60 +1,60 @@
-package com.supwisdom.activities.unregister
-
-import android.content.Intent
-import android.os.Bundle
-import android.view.KeyEvent
-import android.widget.TextView
-import com.supwisdom.R
-import com.supwisdom.activities.BaseActivity
-import com.supwisdom.activities.init.InitActivity
-import com.supwisdom.auxscreen.AuxScreenController
-import com.supwisdom.utils.DateUtil
-
-/**
- ** create by zzq on 2019/7/24
- ** @desc
- **/
-class UnregisterActivity:BaseActivity() {
- private lateinit var vErrmsg: TextView
-
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- this.setContentView(R.layout.activity_unregister)
-
- initView()
- }
-
- private fun initView() {
- val backBtn = this.findViewById(R.id.tv_back) as TextView
- backBtn.setOnClickListener {
- jumpActivity(InitActivity::class.java)
- }
- vErrmsg = this.findViewById(R.id.tv_errmsg) as TextView
- }
-
- override fun dispatchKeyEvent(event: KeyEvent?): Boolean {
- return super.dispatchKeyEvent(event)
- }
-
- override fun onDestroy() {
- super.onDestroy()
- }
-
- override fun onResume() {
- super.onResume()
- val errmsg = intent.getStringExtra("errmsg")
- refresh(errmsg)
- vErrmsg.text = errmsg
- }
-
- private fun refresh(errmsg: String) {
- AuxScreenController.getInstance().refreshTitle("设备注册状态")
- AuxScreenController.getInstance().refreshBottom(DateUtil.getNowDateTime())
- AuxScreenController.getInstance().refreshContent(listOf("设备未注册", errmsg))
- }
-
- override fun onNewIntent(intent: Intent) {
- super.onNewIntent(intent)
- this.intent.putExtra("errmsg", intent.getStringExtra("errmsg"))
- }
+package com.supwisdom.activities.unregister
+
+import android.content.Intent
+import android.os.Bundle
+import android.view.KeyEvent
+import android.widget.TextView
+import com.supwisdom.R
+import com.supwisdom.activities.BaseActivity
+import com.supwisdom.activities.auxscreen.AuxScreenController
+import com.supwisdom.activities.init.InitActivity
+import com.supwisdom.utils.DateUtil
+
+/**
+ ** create by zzq on 2019/7/24
+ ** @desc
+ **/
+class UnregisterActivity : BaseActivity() {
+ private lateinit var vErrmsg: TextView
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ this.setContentView(R.layout.activity_unregister)
+
+ initView()
+ }
+
+ private fun initView() {
+ val backBtn = this.findViewById(R.id.tv_back) as TextView
+ backBtn.setOnClickListener {
+ jumpActivity(InitActivity::class.java)
+ }
+ vErrmsg = this.findViewById(R.id.tv_errmsg) as TextView
+ }
+
+ override fun dispatchKeyEvent(event: KeyEvent?): Boolean {
+ return super.dispatchKeyEvent(event)
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ }
+
+ override fun onResume() {
+ super.onResume()
+ val errmsg = intent.getStringExtra("errmsg")
+ refresh(errmsg)
+ vErrmsg.text = errmsg
+ }
+
+ private fun refresh(errmsg: String) {
+ AuxScreenController.getInstance().refreshTitle("设备注册状态")
+ AuxScreenController.getInstance().refreshBottom(DateUtil.getNowDateTime())
+ AuxScreenController.getInstance().refreshContent(listOf("设备未注册", errmsg))
+ }
+
+ override fun onNewIntent(intent: Intent) {
+ super.onNewIntent(intent)
+ this.intent.putExtra("errmsg", intent.getStringExtra("errmsg"))
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/supwisdom/activities/upgrade/UpgradeActivity.kt b/app/src/main/java/com/supwisdom/activities/upgrade/UpgradeActivity.kt
index 91f304d..e271bdb 100644
--- a/app/src/main/java/com/supwisdom/activities/upgrade/UpgradeActivity.kt
+++ b/app/src/main/java/com/supwisdom/activities/upgrade/UpgradeActivity.kt
@@ -1,187 +1,196 @@
-package com.supwisdom.activities.upgrade
-
-import android.content.Intent
-import android.net.Uri
-import android.os.Build
-import android.os.Bundle
-import android.os.CountDownTimer
-import android.support.v4.content.FileProvider
-import android.view.KeyEvent
-import android.widget.Button
-import android.widget.TextView
-import com.supwisdom.R
-import com.supwisdom.activities.BaseActivity
-import com.supwisdom.activities.SPApplication
-import com.supwisdom.activities.upgrade.mode.EpayUpgradeApi
-import com.supwisdom.auxscreen.AuxScreenController
-import com.supwisdom.utils.CommonUtil
-import com.supwisdom.utils.DateUtil
-import com.supwisdom.utils.ThreadPool
-import java.io.File
-import java.util.*
-
-/**
- ** create by zzq on 2019/7/24
- ** @desc
- **/
-@Suppress("DEPRECATION")
-class UpgradeActivity : BaseActivity() {
- private val pos = SPApplication.getInstance().getPos()
- private lateinit var vResult: TextView
- private lateinit var vUpgradeMsg: TextView
- private lateinit var vServerUrl: TextView
- private lateinit var vPosOldVersion: TextView
- private lateinit var vPosVersion: TextView
- @Volatile
- private var isUpgrading = false
- @Volatile
- private var keyActive = true
-
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_upgrade)
- initView()
- initData()
- }
-
- private fun initData() {
- vPosOldVersion.text = CommonUtil.getVersionName(this)
- }
-
- private fun initView() {
- vResult = this.findViewById(R.id.tv_result) as TextView
- vUpgradeMsg = this.findViewById(R.id.tv_upgrade_msg) as TextView
-
- vServerUrl = this.findViewById(R.id.tv_server_url) as TextView
- vPosOldVersion = this.findViewById(R.id.tv_old_version) as TextView
- vPosVersion = this.findViewById(R.id.tv_pos_version) as TextView
- this.findViewById<Button>(R.id.tv_upgrade).setOnClickListener {
- asyncUpgrade()
- }
- }
-
- override fun dispatchKeyEvent(event: KeyEvent): Boolean {
- if (event.action == KeyEvent.ACTION_DOWN) {
- if (isUpgrading || !keyActive) {
- return super.dispatchKeyEvent(event)
- }
- resetCounter(200)
-
- when (event.keyCode) {
- KeyEvent.KEYCODE_DEL ->
- //cancel
- finish()
- KeyEvent.KEYCODE_ENTER -> {
- //ok
- asyncUpgrade()
- }
- }
- }
- return super.dispatchKeyEvent(event)
- }
-
- override fun onResume() {
- super.onResume()
- keyActive = true
- refresh()
- }
-
- private fun refresh() {
- isUpgrading = false
- AuxScreenController.getInstance().refreshTitle("应用在线升级")
- AuxScreenController.getInstance().refreshBottom(DateUtil.getNowDateTime())
- AuxScreenController.getInstance().refreshContent(
- Arrays.asList(
- "当前版本>>", CommonUtil.getVersionName(applicationContext),
- "确认 --应用升级", "取消 --退出"
- )
- )
- }
-
- private val upgradeApiCallback = object : EpayUpgradeApi.CallbackInterface {
- override fun progresss(pro: Int) {
- runOnUiThread {
- vUpgradeMsg.text = "$pro%"
- vUpgradeMsg.setTextColor(resources.getColor(R.color.black))
- AuxScreenController.getInstance().refreshContent(Arrays.asList<String>("正在下载", "$pro%"))
- }
- }
-
- override fun success(filepath: String) {
- runOnUiThread {
- isUpgrading = false
- vUpgradeMsg.text = "下载成功"
- vUpgradeMsg.setTextColor(resources.getColor(R.color.black))
- AuxScreenController.getInstance().refreshContent(Arrays.asList<String>("下载应用成功", "请在大屏确认升级"))
- val apkFile = File(filepath)
- installAPK(apkFile)
- }
- }
-
- override fun failed(errmsg: String) {
- runOnUiThread {
- isUpgrading = false
- vUpgradeMsg.text = errmsg
- vUpgradeMsg.setTextColor(resources.getColor(R.color.cl_red))
- AuxScreenController.getInstance().refreshContent(Arrays.asList<String>("升级失败", "原因:", errmsg))
- }
- }
- }
-
- /**
- * 开始下载apk
- */
- fun asyncUpgrade() {
- if (!isUpgrading) {
- isUpgrading = true
- AuxScreenController.getInstance().refreshContent(Arrays.asList<String>("正在升级", "请稍等..."))
- ThreadPool.getDownloadPool().execute(Runnable {
- EpayUpgradeApi(upgradeApiCallback).upgrade(
- pos.getConfigPara()!!.devphyid!!,
- CommonUtil.getVersionName(this)
- )
- })
- }
- }
-
- /**
- * 安装apk
- */
- private fun installAPK(apkFile: File) {
- val intent = Intent(Intent.ACTION_VIEW)
- intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
- intent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
- val contentUri = FileProvider.getUriForFile(
- this, "com.supwisdom.charge.fileprovider", apkFile
- )
- intent.setDataAndType(contentUri, "application/vnd.android.package-archive")
- } else {
- intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive")
- }
- startActivity(intent)
- }
-
- private var counter: ContinuePressTimer? = null
-
- private fun resetCounter(timems: Long) {
- counter?.cancel()
- if (counter == null) {
- counter = ContinuePressTimer(timems, 100)
- }
- keyActive = false
- counter!!.start()
- }
-
- private inner class ContinuePressTimer internal constructor(millisInFuture: Long, countDownInterval: Long) :
- CountDownTimer(millisInFuture, countDownInterval) {
-
- override fun onTick(millisUntilFinished: Long) {
-
- }
-
- override fun onFinish() {
- keyActive = true
- }
- }
+package com.supwisdom.activities.upgrade
+
+import android.content.Intent
+import android.net.Uri
+import android.os.Build
+import android.os.Bundle
+import android.os.CountDownTimer
+import android.support.v4.content.FileProvider
+import android.view.KeyEvent
+import android.widget.Button
+import android.widget.TextView
+import com.supwisdom.R
+import com.supwisdom.activities.BaseActivity
+import com.supwisdom.activities.SPApplication
+import com.supwisdom.activities.auxscreen.AuxScreenController
+import com.supwisdom.activities.upgrade.mode.EpayUpgradeApi
+import com.supwisdom.utils.CommonUtil
+import com.supwisdom.utils.DateUtil
+import com.supwisdom.utils.ThreadPool
+import java.io.File
+import java.util.*
+
+/**
+ ** create by zzq on 2019/7/24
+ ** @desc
+ **/
+@Suppress("DEPRECATION")
+class UpgradeActivity : BaseActivity() {
+ private val pos = SPApplication.getInstance().getPos()
+ private lateinit var vResult: TextView
+ private lateinit var vUpgradeMsg: TextView
+ private lateinit var vServerUrl: TextView
+ private lateinit var vPosOldVersion: TextView
+ private lateinit var vPosVersion: TextView
+
+ @Volatile
+ private var isUpgrading = false
+
+ @Volatile
+ private var keyActive = true
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_upgrade)
+ initView()
+ initData()
+ }
+
+ private fun initData() {
+ vPosOldVersion.text = CommonUtil.getVersionName(this)
+ }
+
+ private fun initView() {
+ vResult = this.findViewById(R.id.tv_result) as TextView
+ vUpgradeMsg = this.findViewById(R.id.tv_upgrade_msg) as TextView
+
+ vServerUrl = this.findViewById(R.id.tv_server_url) as TextView
+ vPosOldVersion = this.findViewById(R.id.tv_old_version) as TextView
+ vPosVersion = this.findViewById(R.id.tv_pos_version) as TextView
+ this.findViewById<Button>(R.id.tv_upgrade).setOnClickListener {
+ asyncUpgrade()
+ }
+ }
+
+ override fun dispatchKeyEvent(event: KeyEvent): Boolean {
+ if (event.action == KeyEvent.ACTION_DOWN) {
+ if (isUpgrading || !keyActive) {
+ return super.dispatchKeyEvent(event)
+ }
+ resetCounter(200)
+
+ when (event.keyCode) {
+ KeyEvent.KEYCODE_DEL ->
+ //cancel
+ finish()
+ KeyEvent.KEYCODE_ENTER -> {
+ //ok
+ asyncUpgrade()
+ }
+ }
+ }
+ return super.dispatchKeyEvent(event)
+ }
+
+ override fun onResume() {
+ super.onResume()
+ keyActive = true
+ refresh()
+ }
+
+ private fun refresh() {
+ isUpgrading = false
+ AuxScreenController.getInstance().refreshTitle("应用在线升级")
+ AuxScreenController.getInstance().refreshBottom(DateUtil.getNowDateTime())
+ AuxScreenController.getInstance().refreshContent(
+ Arrays.asList(
+ "当前版本>>", CommonUtil.getVersionName(applicationContext),
+ "确认 --应用升级", "取消 --退出"
+ )
+ )
+ }
+
+ private val upgradeApiCallback = object : EpayUpgradeApi.CallbackInterface {
+ override fun progresss(pro: Int) {
+ runOnUiThread {
+ vUpgradeMsg.text = "$pro%"
+ vUpgradeMsg.setTextColor(resources.getColor(R.color.black))
+ AuxScreenController.getInstance()
+ .refreshContent(Arrays.asList<String>("正在下载", "$pro%"))
+ }
+ }
+
+ override fun success(filepath: String) {
+ runOnUiThread {
+ isUpgrading = false
+ vUpgradeMsg.text = "下载成功"
+ vUpgradeMsg.setTextColor(resources.getColor(R.color.black))
+ AuxScreenController.getInstance()
+ .refreshContent(Arrays.asList<String>("下载应用成功", "请在大屏确认升级"))
+ val apkFile = File(filepath)
+ installAPK(apkFile)
+ }
+ }
+
+ override fun failed(errmsg: String) {
+ runOnUiThread {
+ isUpgrading = false
+ vUpgradeMsg.text = errmsg
+ vUpgradeMsg.setTextColor(resources.getColor(R.color.cl_red))
+ AuxScreenController.getInstance()
+ .refreshContent(Arrays.asList<String>("升级失败", "原因:", errmsg))
+ }
+ }
+ }
+
+ /**
+ * 开始下载apk
+ */
+ fun asyncUpgrade() {
+ if (!isUpgrading) {
+ isUpgrading = true
+ AuxScreenController.getInstance()
+ .refreshContent(Arrays.asList<String>("正在升级", "请稍等..."))
+ ThreadPool.getDownloadPool().execute(Runnable {
+ EpayUpgradeApi(upgradeApiCallback).upgrade(
+ pos.getConfigPara()!!.devphyid!!,
+ CommonUtil.getVersionName(this)
+ )
+ })
+ }
+ }
+
+ /**
+ * 安装apk
+ */
+ private fun installAPK(apkFile: File) {
+ val intent = Intent(Intent.ACTION_VIEW)
+ intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+ intent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
+ val contentUri = FileProvider.getUriForFile(
+ this, "com.supwisdom.charge.fileprovider", apkFile
+ )
+ intent.setDataAndType(contentUri, "application/vnd.android.package-archive")
+ } else {
+ intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive")
+ }
+ startActivity(intent)
+ }
+
+ private var counter: ContinuePressTimer? = null
+
+ private fun resetCounter(timems: Long) {
+ counter?.cancel()
+ if (counter == null) {
+ counter = ContinuePressTimer(timems, 100)
+ }
+ keyActive = false
+ counter!!.start()
+ }
+
+ private inner class ContinuePressTimer internal constructor(
+ millisInFuture: Long,
+ countDownInterval: Long
+ ) :
+ CountDownTimer(millisInFuture, countDownInterval) {
+
+ override fun onTick(millisUntilFinished: Long) {
+
+ }
+
+ override fun onFinish() {
+ keyActive = true
+ }
+ }
}
\ No newline at end of file