Commit e5b0579c by patpat

增加支付结果语音提示,增加按键调节音量,增加碧桂园logo

parent 4c9f3709
*.apk
*.iml *.iml
.gradle .gradle
/**/output.json
/local.properties /local.properties
/.idea/caches /.idea/caches
/.idea/libraries /.idea/libraries
......
...@@ -11,7 +11,7 @@ android { ...@@ -11,7 +11,7 @@ android {
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 28 targetSdkVersion 28
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
} }
buildTypes { buildTypes {
......
package com.bgycc.smartcanteen package com.bgycc.smartcanteen
import android.app.ActivityManager
import android.app.Application import android.app.Application
import android.content.Context
import com.bgycc.smartcanteen.Storage.PayStorage import com.bgycc.smartcanteen.Storage.PayStorage
import com.bgycc.smartcanteen.helper.WifiHelpler import com.bgycc.smartcanteen.helper.WifiHelpler
import com.bgycc.smartcanteen.util.LogUtil import com.bgycc.smartcanteen.util.LogUtil
import com.example.zhoukai.modemtooltest.ModemToolTest import com.example.zhoukai.modemtooltest.ModemToolTest
import com.example.zhoukai.modemtooltest.NvConstants import com.example.zhoukai.modemtooltest.NvConstants
import java.lang.Exception
class App : Application() { class App : Application() {
companion object { companion object {
private lateinit var sDefault: App
private val sInstances = HashMap<String, App>()
private var sVersionName = "0.0.0"
private var sVersionCode = 0
fun getDefault(): App {
return sDefault
}
fun getInstance(processName: String): App? {
return sInstances[processName]
}
fun getDeviceSN(): String { fun getDeviceSN(): String {
return ModemToolTest.getItem(NvConstants.REQUEST_GET_SN); return ModemToolTest.getItem(NvConstants.REQUEST_GET_SN)
}
fun getVersionName(): String {
return sVersionName
}
fun getVersionCode(): Int {
return sVersionCode
} }
} }
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
if (isMainProcess()) {
sDefault = this
readVersion()
}
sInstances[getProcessNameCompat()] = this
LogUtil.setEnable(AppConfig.DEBUG) LogUtil.setEnable(AppConfig.DEBUG)
WifiHelpler.initialize(this) WifiHelpler.initialize(this)
PayStorage.initialize(this) PayStorage.initialize(this)
} }
fun isMainProcess(): Boolean {
return packageName == getProcessNameCompat()
}
fun getProcessNameCompat(): String {
if (android.os.Build.VERSION.SDK_INT >= 28) {
return getProcessName()
} else {
var processName = ""
val pid = android.os.Process.myPid()
val manager = getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
for (process in manager.runningAppProcesses) {
if (process.pid == pid) {
processName = process.processName
}
}
return processName
}
}
private fun readVersion() {
try {
val pi = packageManager.getPackageInfo(packageName, 0)
sVersionName = pi.versionName.toUpperCase()
sVersionCode = pi.versionCode
} catch (e: Exception) {}
}
} }
\ No newline at end of file
...@@ -6,15 +6,15 @@ public class AppConfig { ...@@ -6,15 +6,15 @@ public class AppConfig {
TEST, TEST,
PROD PROD
} }
public static final Server SERVER = Server.DEV; public static final Server SERVER = Server.PROD;
public static final boolean DEBUG = true; public static final boolean DEBUG = false;
public static String getMainWebSocketServerUrl() { public static String getMainWebSocketServerUrl() {
switch (SERVER) { switch (SERVER) {
case DEV: return "ws://l-patpat.cn:5000/websocket/%s"; case DEV: return "ws://10.187.30.128:9001/websocket/%s";
case TEST: return "ws://10.187.18.204:9001/websocket/%s"; case TEST: return "ws://diningservicetest.bgy.com.cn:9001/websocket/%s";
default: default:
case PROD: return "ws://10.187.18.204:9001/websocket/%s"; case PROD: return "ws://10.10.182.48:9001/websocket/%s";
} }
} }
} }
package com.bgycc.smartcanteen.Storage;
import android.content.Context;
public class AppStorage extends Storage {
protected AppStorage(String name, Context context) {
super(name, context);
}
}
...@@ -4,13 +4,17 @@ import com.bgycc.smartcanteen.App; ...@@ -4,13 +4,17 @@ import com.bgycc.smartcanteen.App;
import com.bgycc.smartcanteen.Storage.PayStorage; import com.bgycc.smartcanteen.Storage.PayStorage;
import com.bgycc.smartcanteen.event.PayStateEvent; import com.bgycc.smartcanteen.event.PayStateEvent;
import com.bgycc.smartcanteen.server.websocket.MainWebSocket; import com.bgycc.smartcanteen.server.websocket.MainWebSocket;
import com.bgycc.smartcanteen.task.QRCodeTask;
import com.bgycc.smartcanteen.util.DateUtil;
import com.bgycc.smartcanteen.util.LogUtil; import com.bgycc.smartcanteen.util.LogUtil;
import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.EventBus;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Locale; import java.util.Locale;
public class PayOfflineAction extends Action { public class PayOfflineAction extends Action {
...@@ -25,18 +29,25 @@ public class PayOfflineAction extends Action { ...@@ -25,18 +29,25 @@ public class PayOfflineAction extends Action {
return sInstance; return sInstance;
} }
private ArrayList<String> mPayCodeHistory = new ArrayList<>();
public PayOfflineAction() { public PayOfflineAction() {
super(ActionEnum.PAY_OFFLINE.name()); super(ActionEnum.PAY_OFFLINE.name());
} }
@Override
protected void setState(State state) { protected void setState(State state) {
setState(state, "");
}
protected void setState(State state, String message) {
if (state != getState()) { if (state != getState()) {
switch (state) { switch (state) {
case INITED: case INITED:
EventBus.getDefault().post(new PayStateEvent(PayStateEvent.StateEnum.IDLE, "")); EventBus.getDefault().post(new PayStateEvent(PayStateEvent.StateEnum.IDLE, message));
break; break;
case FAIL: case FAIL:
EventBus.getDefault().post(new PayStateEvent(PayStateEvent.StateEnum.FAIL, "")); EventBus.getDefault().post(new PayStateEvent(PayStateEvent.StateEnum.FAIL, message));
timeout(new Runnable() { timeout(new Runnable() {
@Override @Override
public void run() { public void run() {
...@@ -45,7 +56,7 @@ public class PayOfflineAction extends Action { ...@@ -45,7 +56,7 @@ public class PayOfflineAction extends Action {
}, 3000); }, 3000);
break; break;
case RESQUEST_SUCCESS: case RESQUEST_SUCCESS:
EventBus.getDefault().post(new PayStateEvent(PayStateEvent.StateEnum.SUCCESS, "")); EventBus.getDefault().post(new PayStateEvent(PayStateEvent.StateEnum.SUCCESS, message));
timeout(new Runnable() { timeout(new Runnable() {
@Override @Override
public void run() { public void run() {
...@@ -59,13 +70,24 @@ public class PayOfflineAction extends Action { ...@@ -59,13 +70,24 @@ public class PayOfflineAction extends Action {
} }
public void exec(String payCode, String payCodeType) { public void exec(String payCode, String payCodeType) {
if (!QRCodeTask.TYPE_BHPAY.equals(payCodeType)) {
setState(State.FAIL);
return;
}
if (mPayCodeHistory.contains(payCode)) {
clearTimeoutPayCodeHistory();
setState(State.FAIL, "请不要重复扫码");
return;
}
mPayCodeHistory.add(payCode);
try { try {
setState(State.STARTED); setState(State.STARTED);
JSONObject params = new JSONObject(); JSONObject params = new JSONObject();
params.put("equipmentNo", App.Companion.getDeviceSN()); params.put("equipmentNo", App.Companion.getDeviceSN());
params.put("payCode", payCode); params.put("payCode", payCode);
params.put("terminalType", payCodeType); params.put("terminalType", payCodeType);
params.put("time", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.getDefault()).format(new Date())); params.put("time", DateUtil.getCurrentTimestamp());
PayStorage.getInstance().add(params); PayStorage.getInstance().add(params);
PayStorage.getInstance().savePayList(); PayStorage.getInstance().savePayList();
setState(State.RESQUEST_SUCCESS); setState(State.RESQUEST_SUCCESS);
...@@ -94,4 +116,10 @@ public class PayOfflineAction extends Action { ...@@ -94,4 +116,10 @@ public class PayOfflineAction extends Action {
MainWebSocket.action(getAction(), list, response); MainWebSocket.action(getAction(), list, response);
LogUtil.i(TAG, list.toString()); LogUtil.i(TAG, list.toString());
} }
private void clearTimeoutPayCodeHistory() {
if (mPayCodeHistory.size() > 100) {
mPayCodeHistory.remove(0);
}
}
} }
package com.bgycc.smartcanteen.action; package com.bgycc.smartcanteen.action;
import android.util.Log;
import com.bgycc.smartcanteen.App; import com.bgycc.smartcanteen.App;
import com.bgycc.smartcanteen.event.PayStateEvent; import com.bgycc.smartcanteen.event.PayStateEvent;
import com.bgycc.smartcanteen.server.websocket.MainWebSocket; import com.bgycc.smartcanteen.server.websocket.MainWebSocket;
import com.bgycc.smartcanteen.util.DateUtil;
import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.EventBus;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -12,6 +14,8 @@ import java.util.Locale; ...@@ -12,6 +14,8 @@ import java.util.Locale;
public class PayOnlineAction extends Action { public class PayOnlineAction extends Action {
private static final String TAG = PayOnlineAction.class.getSimpleName();
private static PayOnlineAction sInstance; private static PayOnlineAction sInstance;
public static PayOnlineAction getDefault() { public static PayOnlineAction getDefault() {
if (sInstance == null) { if (sInstance == null) {
...@@ -21,6 +25,7 @@ public class PayOnlineAction extends Action { ...@@ -21,6 +25,7 @@ public class PayOnlineAction extends Action {
} }
private String mPayCode; private String mPayCode;
private boolean mWaitResponse;
public PayOnlineAction() { public PayOnlineAction() {
super(ActionEnum.PAY_ONLINE.name()); super(ActionEnum.PAY_ONLINE.name());
...@@ -35,9 +40,23 @@ public class PayOnlineAction extends Action { ...@@ -35,9 +40,23 @@ public class PayOnlineAction extends Action {
break; break;
case STARTED: case STARTED:
EventBus.getDefault().post(new PayStateEvent(PayStateEvent.StateEnum.WAIT, message)); EventBus.getDefault().post(new PayStateEvent(PayStateEvent.StateEnum.WAIT, message));
mWaitResponse = false;
break;
case RESQUEST_SUCCESS:
mWaitResponse = true;
timeout(new Runnable() {
@Override
public void run() {
if (!mWaitResponse) return;
setState(State.RESPONSE_TIMEOUT, "交易失败");
}
}, 10000);
break; break;
case RESPONSE_SUCCESS: case RESPONSE_SUCCESS:
EventBus.getDefault().post(new PayStateEvent(PayStateEvent.StateEnum.SUCCESS, message)); EventBus.getDefault().post(new PayStateEvent(PayStateEvent.StateEnum.SUCCESS, message));
mWaitResponse = false;
mPayCode = "";
success(message); success(message);
timeout(new Runnable() { timeout(new Runnable() {
@Override @Override
...@@ -51,6 +70,8 @@ public class PayOnlineAction extends Action { ...@@ -51,6 +70,8 @@ public class PayOnlineAction extends Action {
case RESPONSE_FAIL: case RESPONSE_FAIL:
case RESPONSE_TIMEOUT: case RESPONSE_TIMEOUT:
EventBus.getDefault().post(new PayStateEvent(PayStateEvent.StateEnum.FAIL, message)); EventBus.getDefault().post(new PayStateEvent(PayStateEvent.StateEnum.FAIL, message));
mWaitResponse = false;
mPayCode = "";
fail(message); fail(message);
timeout(new Runnable() { timeout(new Runnable() {
@Override @Override
...@@ -65,7 +86,12 @@ public class PayOnlineAction extends Action { ...@@ -65,7 +86,12 @@ public class PayOnlineAction extends Action {
} }
public void exec(String payCode, String payCodeType, ActionResult result) { public void exec(String payCode, String payCodeType, ActionResult result) {
if (getState() != State.INITED) return; if (getState() != State.INITED) {
if (result != null) {
result.onFail("正在忙");
}
return;
}
setState(State.STARTED, ""); setState(State.STARTED, "");
setActionResult(result); setActionResult(result);
...@@ -98,7 +124,7 @@ public class PayOnlineAction extends Action { ...@@ -98,7 +124,7 @@ public class PayOnlineAction extends Action {
params.put("equipmentNo", App.Companion.getDeviceSN()); params.put("equipmentNo", App.Companion.getDeviceSN());
params.put("payCode", payCode); params.put("payCode", payCode);
params.put("terminalType", payCodeType); params.put("terminalType", payCodeType);
params.put("time", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.getDefault()).format(new Date())); params.put("time", DateUtil.getCurrentTimestamp());
setState(State.RESQUEST, ""); setState(State.RESQUEST, "");
MainWebSocket.action(getAction(), params, response); MainWebSocket.action(getAction(), params, response);
} catch (Exception e) { } catch (Exception e) {
......
...@@ -3,13 +3,40 @@ package com.bgycc.smartcanteen.activity ...@@ -3,13 +3,40 @@ package com.bgycc.smartcanteen.activity
import android.app.Activity import android.app.Activity
import android.view.View import android.view.View
import android.view.Window import android.view.Window
import android.view.WindowManager
open class BaseActivity : Activity() { open class BaseActivity : Activity() {
protected fun fullscreen() { fun translucentStatusBar() {
if (android.os.Build.VERSION.SDK_INT >= 19) {
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
}
}
fun lightStatusBar() {
if (android.os.Build.VERSION.SDK_INT >= 23) {
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
}
}
fun hideStatusBar() {
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
}
fun hideActionBar() {
requestWindowFeature(Window.FEATURE_NO_TITLE) requestWindowFeature(Window.FEATURE_NO_TITLE)
}
fun hideNavigation() {
val decorView = window.decorView val decorView = window.decorView
val uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or View.SYSTEM_UI_FLAG_FULLSCREEN val uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
decorView.systemUiVisibility = uiOptions decorView.systemUiVisibility = uiOptions
} }
fun keepScreenOn(on: Boolean) {
when (on) {
true -> window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
false -> window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}
}
} }
\ No newline at end of file
...@@ -3,18 +3,23 @@ package com.bgycc.smartcanteen.activity ...@@ -3,18 +3,23 @@ package com.bgycc.smartcanteen.activity
import android.media.AudioManager import android.media.AudioManager
import android.media.SoundPool import android.media.SoundPool
import android.os.Bundle import android.os.Bundle
import android.util.Log import android.os.Handler
import android.view.View import android.view.View
import android.widget.TextView import android.view.animation.Animation
import android.view.animation.RotateAnimation
import com.bgycc.smartcanteen.App import com.bgycc.smartcanteen.App
import com.bgycc.smartcanteen.AppConfig import com.bgycc.smartcanteen.AppConfig
import com.bgycc.smartcanteen.QRCodeEvent import com.bgycc.smartcanteen.QRCodeEvent
import com.bgycc.smartcanteen.R import com.bgycc.smartcanteen.R
import com.bgycc.smartcanteen.event.LogEvent
import com.bgycc.smartcanteen.event.PayStateEvent import com.bgycc.smartcanteen.event.PayStateEvent
import com.bgycc.smartcanteen.event.WifiStateEvent
import com.bgycc.smartcanteen.helper.WifiHelpler
import com.bgycc.smartcanteen.server.websocket.event.ConnectStateEvent import com.bgycc.smartcanteen.server.websocket.event.ConnectStateEvent
import com.bgycc.smartcanteen.server.websocket.MainWebSocket import com.bgycc.smartcanteen.server.websocket.MainWebSocket
import com.bgycc.smartcanteen.server.websocket.event.RecvMessageEvent import com.bgycc.smartcanteen.server.websocket.event.RecvMessageEvent
import com.bgycc.smartcanteen.server.websocket.event.SendMessageEvent import com.bgycc.smartcanteen.server.websocket.event.SendMessageEvent
import com.bgycc.smartcanteen.task.ButtonTask
import com.bgycc.smartcanteen.task.QRCodeTask import com.bgycc.smartcanteen.task.QRCodeTask
import com.bgycc.smartcanteen.util.StringUtil import com.bgycc.smartcanteen.util.StringUtil
import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.EventBus
...@@ -22,6 +27,8 @@ import org.greenrobot.eventbus.Subscribe ...@@ -22,6 +27,8 @@ import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode import org.greenrobot.eventbus.ThreadMode
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.* import java.util.*
import kotlinx.android.synthetic.main.activity_main.*
import java.text.DateFormat
class MainActivity : BaseActivity() { class MainActivity : BaseActivity() {
...@@ -29,47 +36,74 @@ class MainActivity : BaseActivity() { ...@@ -29,47 +36,74 @@ class MainActivity : BaseActivity() {
var TAG: String = MainActivity::class.java.simpleName var TAG: String = MainActivity::class.java.simpleName
} }
lateinit var mDebugLayout: View private val mSoundPool: SoundPool = SoundPool(1, AudioManager.STREAM_SYSTEM, 0)
lateinit var mMessageTextView: TextView private var mBeepSoundId = 0
lateinit var mQRCodeTextView: TextView private var mPaySuccessSoundId = 0
lateinit var mServerTextView: TextView private var mPayFailSoundId = 0
lateinit var mSendTextView: TextView private var mTimer: Timer? = null
lateinit var mRecvTextView: TextView private val mHandler = Handler()
val mSoundPool: SoundPool = SoundPool(1, AudioManager.STREAM_SYSTEM, 0)
var mBeepSoundId = 0
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
hideActionBar()
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
fullscreen()
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
hideStatusBar()
initView() initView()
EventBus.getDefault().register(this) EventBus.getDefault().register(this)
init() init()
initTimer()
} }
override fun onDestroy() { override fun onDestroy() {
uninitTimer()
EventBus.getDefault().unregister(this) EventBus.getDefault().unregister(this)
super.onDestroy() super.onDestroy()
} }
fun init() { private fun init() {
mBeepSoundId = mSoundPool.load(getAssets().openFd("beep.mp3"), 1) mBeepSoundId = mSoundPool.load(assets.openFd("beep.mp3"), 1)
// WifiHelpler.connect("BGY-802.1X", "dengquanye", "pat2019@", "wpa_eap") mPaySuccessSoundId = mSoundPool.load(assets.openFd("pay-success.mp3"), 1)
mPayFailSoundId = mSoundPool.load(assets.openFd("pay-fail.mp3"), 1)
WifiHelpler.connect("BGY-802.1X", "dengquanye", "pat2019@@", "wpa_eap")
MainWebSocket.initialize() MainWebSocket.initialize()
QRCodeTask.getInstance().start() QRCodeTask.getInstance().start()
ButtonTask.getInstance().start()
} }
fun initView() { private fun initView() {
mMessageTextView = findViewById(R.id.message)
mQRCodeTextView = findViewById(R.id.qrcode)
mServerTextView = findViewById(R.id.server)
mSendTextView = findViewById(R.id.send_msg)
mRecvTextView = findViewById(R.id.recv_msg)
mDebugLayout = findViewById(R.id.debug)
if (!AppConfig.DEBUG) { if (!AppConfig.DEBUG) {
mDebugLayout.visibility = View.GONE _debug.visibility = View.GONE
}
_setting.alpha = 0f
_setting_img.post{
val anim = RotateAnimation(0f, 360f, 0.5f * _setting_img.width, 0.5f * _setting_img.height)
anim.duration = 2000
anim.repeatMode = Animation.RESTART
anim.repeatCount = -1
_setting_img.startAnimation(anim)
} }
_version.text = "Version: v${App.getVersionName()}(${App.getVersionCode()})"
_mac.text = "Wifi Mac: ${WifiHelpler.getMacAddress()}"
}
private fun initTimer() {
if (mTimer == null) {
mTimer = Timer()
mTimer!!.scheduleAtFixedRate(object: TimerTask() {
override fun run() {
mHandler.post {
_time.text = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).format(Date())
}
}
}, 0, 1000)
}
}
private fun uninitTimer() {
mTimer ?: return
mTimer!!.cancel()
mTimer = null
} }
fun printQRCode(event: QRCodeEvent) { fun printQRCode(event: QRCodeEvent) {
...@@ -77,7 +111,7 @@ class MainActivity : BaseActivity() { ...@@ -77,7 +111,7 @@ class MainActivity : BaseActivity() {
if (event.payCodeType != null) { if (event.payCodeType != null) {
msg += String.format(" (%s)", event.payCodeType) msg += String.format(" (%s)", event.payCodeType)
} }
mQRCodeTextView.text = msg _qrcode.text = msg
} }
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
...@@ -89,40 +123,63 @@ class MainActivity : BaseActivity() { ...@@ -89,40 +123,63 @@ class MainActivity : BaseActivity() {
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
fun onMessageEvent(event: PayStateEvent) { fun onMessageEvent(event: PayStateEvent) {
if (event.state == PayStateEvent.StateEnum.IDLE) { if (event.state == PayStateEvent.StateEnum.IDLE) {
mMessageTextView.setTextColor(0xFF333333.toInt()) _message.setTextColor(0xFF333333.toInt())
mMessageTextView.text = "请出示付款码" _message.text = "请出示付款码"
} else if (event.state == PayStateEvent.StateEnum.WAIT) { } else if (event.state == PayStateEvent.StateEnum.WAIT) {
mMessageTextView.setTextColor(0xFF333333.toInt()) _message.setTextColor(0xFF333333.toInt())
mMessageTextView.text = "交易处理中" _message.text = "交易处理中"
} else if (event.state == PayStateEvent.StateEnum.SUCCESS) { } else if (event.state == PayStateEvent.StateEnum.SUCCESS) {
mMessageTextView.setTextColor(0xFF009900.toInt()) _message.setTextColor(0xFF009900.toInt())
if (StringUtil.isEmpty(event.message)) event.message = "支付成功" if (StringUtil.isEmpty(event.message)) event.message = "支付成功"
mMessageTextView.text = event.message _message.text = event.message
mSoundPool.play(mPaySuccessSoundId, 1f, 1f, 0, 0, 1f)
} else if (event.state == PayStateEvent.StateEnum.FAIL) { } else if (event.state == PayStateEvent.StateEnum.FAIL) {
mMessageTextView.setTextColor(0xFFFF0000.toInt()) _message.setTextColor(0xFFFF0000.toInt())
if (StringUtil.isEmpty(event.message)) event.message = "支付失败" if (StringUtil.isEmpty(event.message)) event.message = "支付失败"
mMessageTextView.text = event.message _message.text = event.message
mSoundPool.play(mPayFailSoundId, 1f, 1f, 0, 0, 1f)
} }
} }
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
fun onMessageEvent(event: ConnectStateEvent) { fun onMessageEvent(event: ConnectStateEvent) {
if (event.state == ConnectStateEvent.OFFLINE) mServerTextView.text = "Server: 未连接" val base = "Server: " + AppConfig.getMainWebSocketServerUrl() + " "
else if (event.state == ConnectStateEvent.CONNECTING) mServerTextView.text = "Server: 正在连接..." if (event.state == ConnectStateEvent.OFFLINE) _server.text = base + "未连接"
else if (event.state == ConnectStateEvent.CONNECTED) mServerTextView.text = "Server: 已连接" else if (event.state == ConnectStateEvent.CONNECTING) _server.text = base + "正在连接..."
else if (event.state == ConnectStateEvent.RECONNECTING) mServerTextView.text = "Server: 正在重连..." else if (event.state == ConnectStateEvent.CONNECTED) _server.text = base + "已连接"
else if (event.state == ConnectStateEvent.RECONNECTING) _server.text = base + "正在重连..."
} }
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
fun onMessageEvent(event: SendMessageEvent) { fun onMessageEvent(event: SendMessageEvent) {
val time = SimpleDateFormat("HH:mm:ss.SSS", Locale.getDefault()).format(Date()) val time = SimpleDateFormat("HH:mm:ss.SSS", Locale.getDefault()).format(Date())
mSendTextView.text = String.format("Send: %s - %s", time, event.message) _send_msg.text = String.format("Send: %s - %s", time, event.message)
} }
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
fun onMessageEvent(event: RecvMessageEvent) { fun onMessageEvent(event: RecvMessageEvent) {
val time = SimpleDateFormat("HH:mm:ss.SSS", Locale.getDefault()).format(Date()) val time = SimpleDateFormat("HH:mm:ss.SSS", Locale.getDefault()).format(Date())
mRecvTextView.text = String.format("Receive: %s - %s", time, event.message) _recv_msg.text = String.format("Receive: %s - %s", time, event.message)
}
@Subscribe(threadMode = ThreadMode.MAIN)
fun onMessageEvent(event: WifiStateEvent) {
if (event.progress < 0) {
_setting.animate().setDuration(300).alpha(0f)
} else {
_setting_msg.text = event.message
_setting.animate().setDuration(300).alpha(1f)
}
} }
@Subscribe(threadMode = ThreadMode.MAIN)
fun onMessageEvent(event: LogEvent) {
if (_debug.visibility == View.GONE) {
_logo.visibility = View.GONE
_debug.visibility = View.VISIBLE
} else {
_logo.visibility = View.VISIBLE
_debug.visibility = View.GONE
}
}
} }
package com.bgycc.smartcanteen.task;
import android.content.Context;
import android.media.AudioManager;
import android.util.Log;
import com.bgycc.smartcanteen.App;
import com.szxb.jni.libszxb;
import java.util.Timer;
import java.util.TimerTask;
public class ButtonTask {
private static final String TAG = ButtonTask.class.getSimpleName();
private static ButtonTask sInstance;
public static synchronized ButtonTask getInstance() {
if (sInstance == null) {
sInstance = new ButtonTask();
}
return sInstance;
}
private Timer mScanTimer;
private AudioManager mAudioManager;
private ButtonTask() {}
public void start() {
if (mScanTimer == null) {
mAudioManager = (AudioManager) App.Companion.getDefault().getSystemService(Context.AUDIO_SERVICE);
mScanTimer = new Timer();
mScanTimer.scheduleAtFixedRate(new LoopTimerTask(), 0, 200);
}
}
public void stop() {
mAudioManager = null;
if (mScanTimer != null) {
mScanTimer.cancel();
mScanTimer = null;
}
}
private class LoopTimerTask extends TimerTask {
@Override
public void run() {
try {
byte[] buf = new byte[5];
libszxb.devicekey(buf);
// Log.i(TAG, String.format("%02x %02x %02x %02x", buf[0], buf[1], buf[2], buf[3]));
if (buf[1] == 1) {
mAudioManager.adjustStreamVolume(AudioManager.STREAM_SYSTEM, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI);
}
if (buf[2] == 1) {
mAudioManager.adjustStreamVolume(AudioManager.STREAM_SYSTEM, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
package com.bgycc.smartcanteen.util;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
public class DateUtil {
public static String getISO8601Timestamp(Date date) {
TimeZone tz = TimeZone.getDefault();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
df.setTimeZone(tz);
String nowAsISO = df.format(date);
return nowAsISO;
}
public static long getCurrentTimestamp() {
return System.currentTimeMillis() / 1000;
}
}
...@@ -7,15 +7,23 @@ ...@@ -7,15 +7,23 @@
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".activity.MainActivity"> tools:context=".activity.MainActivity">
<LinearLayout android:id="@+id/debug" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="5dp"> <ImageView android:id="@+id/_logo" android:src="@mipmap/ic_bgy_logo" android:layout_width="300dp" android:layout_height="150dp" />
<TextView android:id="@+id/qrcode" android:text="QRCode: 扫描中..." android:textSize="18sp" android:textColor="#888" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:id="@+id/server" android:text="Server: 未连接" android:textSize="18sp" android:textColor="#888" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <FrameLayout android:layout_gravity="end" android:layout_width="wrap_content" android:layout_height="50dp">
<TextView android:id="@+id/send_msg" android:text="Send: null" android:textSize="18sp" android:textColor="#488" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/_time" android:text="2019-01-01 12:12:36" android:textColor="#666" android:textSize="22sp" android:layout_gravity="center_vertical" android:layout_marginEnd="10dp" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:id="@+id/recv_msg" android:text="Receive: null" android:textSize="18sp" android:textColor="#800" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </FrameLayout>
<LinearLayout android:id="@+id/_debug" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="5dp">
<TextView android:id="@+id/_version" android:text="Version: v0.0.0" android:textSize="18sp" android:textColor="#888" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:id="@+id/_mac" android:text="Wifi Mac: unknown" android:textSize="18sp" android:textColor="#888" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:id="@+id/_qrcode" android:text="QRCode: 扫描中..." android:textSize="18sp" android:textColor="#888" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:id="@+id/_server" android:text="Server: 未连接" android:textSize="18sp" android:textColor="#888" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:id="@+id/_send_msg" android:text="Send: null" android:textSize="18sp" android:textColor="#488" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:id="@+id/_recv_msg" android:text="Receive: null" android:textSize="18sp" android:textColor="#800" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout> </LinearLayout>
<TextView <TextView
android:id="@+id/message" android:id="@+id/_message"
android:text="请出示付款码" android:text="请出示付款码"
android:textSize="60sp" android:textSize="60sp"
android:textColor="#333" android:textColor="#333"
...@@ -23,4 +31,9 @@ ...@@ -23,4 +31,9 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center"/> android:layout_gravity="center"/>
<LinearLayout android:id="@+id/_setting" android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom">
<ImageView android:id="@+id/_setting_img" android:src="@mipmap/ic_setting" android:layout_width="50dp" android:layout_height="50dp" />
<TextView android:id="@+id/_setting_msg" android:text="正在设置wifi" android:textColor="#666" android:textSize="22sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" />
</LinearLayout>
</FrameLayout> </FrameLayout>
\ No newline at end of file
...@@ -9,6 +9,7 @@ buildscript { ...@@ -9,6 +9,7 @@ buildscript {
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.4.2' classpath 'com.android.tools.build:gradle:3.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment