Commit 6d3a69d6 by onuma

アプリがバックグラウンドになった時にタイマーを止める、Bluetoothを切る。

parent 3d1f0f8f
......@@ -34,16 +34,17 @@ public class AlcoholCheckerTimerTask extends TimerTask {
break;
case F_BLE_COM_RP_START:
// RP Command Send
listener.onUpdateSendMessage("TIMER F_BLE_COM_RP_COMMAND");
Logger.d(TAG,"F_BLE_COM_RP_START");
alcoholCheckerUtil.sendMessage(F_BLE_COM_RP_COMMAND);
break;
case AlcoholCheckerUtil.F_BLE_COM_RD_START:
// RD Command Send
listener.onUpdateSendMessage("TIMER F_BLE_COM_RD_COMMAND");
Logger.d(TAG,"F_BLE_COM_RD_START");
alcoholCheckerUtil.sendMessage(F_BLE_COM_RD_COMMAND);
break;
case AlcoholCheckerUtil.F_BLE_COM_FC_START:
listener.onUpdateSendMessage("TIMER F_BLE_COM_FC_COMMAND");
// Fc Command Send
Logger.d(TAG,"F_BLE_COM_FC_START");
alcoholCheckerUtil.sendMessage(AlcoholCheckerUtil.F_BLE_COM_FC_COMMAND_F11);
break;
// case F_BLE_COM_RECONNECT1:
......
......@@ -14,6 +14,7 @@ import java.util.Timer;
import java.util.UUID;
import jp.agentec.abook.abv.bl.common.log.Logger;
import jp.agentec.adf.util.StringUtil;
public class AlcoholCheckerUtil {
public static final String TAG = "AlcoholCheckerUtil";
......@@ -134,6 +135,14 @@ public class AlcoholCheckerUtil {
private AlcoholCheckerTimerTask alcoholCheckerTimerTask = null;
public boolean isConnected = false;
// ステータス
public static final int fugo_wait_connect = 0;
public static final int fugo_conntected = 1;
public static final int fugo_wait_go = 2;
public static final int fugo_fu_error = 3;
public static final int fugo_restart = 4;
public int alcStatus = 0;
public AlcoholCheckerUtil(Context context, AlcoholCheckerUtilListener listener) {
this.context = context;
isConnected = false;
......@@ -146,11 +155,6 @@ public class AlcoholCheckerUtil {
disconnect(true);
}
// public void dispose() {
// bleManagerUtil = null;
// listener = null;
// }
// Bluetoothアダプタの取得処理
public boolean startGetDeviceInfo() {
......@@ -265,6 +269,10 @@ public class AlcoholCheckerUtil {
}
}
sub_rx_chk(rx);
if (gi_status == F_BLE_COM_FC_WAIT) {
Logger.d(TAG,"FC_WAIT");
}
}
@Override
......@@ -406,16 +414,19 @@ public class AlcoholCheckerUtil {
// @Mode Change
switch (gi_status) {
case F_BLE_COM_RP_START:
listener.onUpdateStatus("sendMessage = F_BLE_COM_RP_WAIT");
//listener.onUpdateStatus("sendMessage = F_BLE_COM_RP_WAIT");
gi_status = F_BLE_COM_RP_WAIT;
Logger.d(TAG,"F_BLE_COM_RP_WAIT:" + gi_status);
break;
case F_BLE_COM_RD_START:
listener.onUpdateStatus("sendMessage = F_BLE_COM_RD_WAIT");
//listener.onUpdateStatus("sendMessage = F_BLE_COM_RD_WAIT");
gi_status = F_BLE_COM_RD_WAIT;
Logger.d(TAG,"F_BLE_COM_RD_WAIT:" + gi_status);
break;
case F_BLE_COM_FC_START:
listener.onUpdateStatus("sendMessage = F_BLE_COM_FC_WAIT");
//listener.onUpdateStatus("sendMessage = F_BLE_COM_FC_WAIT");
gi_status = F_BLE_COM_FC_WAIT;
Logger.d(TAG,"F_BLE_COM_FC_WAIT:" + gi_status);
break;
default:
// None
......@@ -517,7 +528,7 @@ public class AlcoholCheckerUtil {
sub_rx_data_gen(rxdata);
// Mode
Logger.i(TAG,"gi_status = " + gi_status);
Logger.i(TAG,"sub_rx_chk gi_status = " + gi_status);
switch (gi_status) {
case F_BLE_COM_INIT:
// BLE Init
......@@ -713,9 +724,10 @@ public class AlcoholCheckerUtil {
byte[] res = hex2string(rxdata);
for (byte b: rxdata) {
str_msg += Byte.toString(b);
//str_msg += Byte.toString(b);
Logger.d(TAG,"%s, " + Byte.toString(b));
}
Logger.i(TAG, "fn_rx_fc_chk = " + str_msg);
//Logger.i(TAG, "fn_rx_fc_chk = " + str_msg);
// 01 72 70 02 rp 上位
// 01 114 112 02
......@@ -743,9 +755,12 @@ public class AlcoholCheckerUtil {
}
//Logger.i(TAG, "fc=" + fcWaitMode);
listener.onGetDeviceInfo(alcol);
if (StringUtil.isNullOrEmpty(alcol)) {
si_ret = F_BLE_COM_FC_START;
} else {
si_ret = F_BLE_COM_RP_START;
}
fcWaitMode = 0;
si_ret = F_BLE_COM_RP_START;
}
}
return si_ret;
......
......@@ -2,16 +2,13 @@ package jp.agentec.abook.abv.cl.util;
public interface AlcoholCheckerUtilListener {
void onConnectionError(int status); // ディバイス接続エラー
void onMeasurementError(String txt); // 吹付エラー
void onBreakDownError(String txt); // 機器の故障
void onLowBatteryError(String txt); // バッテリー不足
void onOverUsedError(String txt); // 使用回数超過
void onPowerOff(String txt); // 機器の電源がOFF
void onStartMeasurement();
void onMeasurementError(String txt); // 吹付エラー
void onBreakDownError(String txt); // 機器の故障
void onLowBatteryError(String txt); // バッテリー不足
void onOverUsedError(String txt); // 使用回数超過
void onPowerOff(String txt); // 機器の電源がOFF
void onStartMeasurement(); // 吹付開始
void onUpdateTBVCalc(String text);
void onUpdateStatus(String text);
void onUpdateSendMessage(String text);
void onUpdateReceivedData(String text);
void onServicesDiscovered(int status);
void onGetDeviceInfo(String alcohol);
}
......@@ -188,14 +188,6 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
// 二重起動防止フラグ(アルコールチェッカー)
private boolean isAlcBlock = false;
// ステータス
private static final int fugo_wait_connect = 0;
private static final int fugo_conntected = 1;
private static final int fugo_wait_go = 2;
private static final int fugo_fu_error = 3;
private static final int fugo_restart = 4;
private int alcStatus = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -277,29 +269,14 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
@Override
public void onUpdateTBVCalc(String text) {
Logger.i(TAG, "onUpdateTBVCalc = %s", text);
}
@Override
public void onUpdateStatus(String text) {
Logger.d(TAG, "onUpdateStatus = %s", text);
}
@Override
public void onUpdateSendMessage(String text) {
Logger.d(TAG, "onUpdateSendMessage = %s", text);
}
@Override
public void onUpdateReceivedData(String text) {
Logger.d(TAG, "onUpdateReceivedData = %s", text);
Logger.d(TAG, "onUpdateTBVCalc = %s", text);
}
@Override
public void onServicesDiscovered(int status) {
Logger.d(TAG, "onServicesDiscovered = %s", status);
if (alcStatus == fugo_wait_connect) {
alcStatus = fugo_conntected;
if (alcoholCheckerUtil.alcStatus == AlcoholCheckerUtil.fugo_wait_connect) {
alcoholCheckerUtil.alcStatus = AlcoholCheckerUtil.fugo_conntected;
} else {
return;
}
......@@ -320,14 +297,18 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
@Override
public void onGetDeviceInfo(String alcohol) {
Logger.d(TAG, "測定完了 = " + alcohol);
successAfterAbookCheckApi(alcohol, false);
if (!alcohol.equals("")) {
successAfterAbookCheckApi(alcohol, false);
} else {
}
}
@Override
public void onStartMeasurement() {
Logger.d(TAG, "onStartMeasurement");
if (alcStatus == fugo_conntected) {
alcStatus = fugo_wait_go;
if (alcoholCheckerUtil.alcStatus == AlcoholCheckerUtil.fugo_conntected) {
alcoholCheckerUtil.alcStatus = AlcoholCheckerUtil.fugo_wait_go;
} else {
return;
}
......@@ -360,7 +341,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
public void onMeasurementError(String text) {
Logger.d(TAG,"onMeasurementError = " + text);
if (mMeasureDialog != null) {
alcStatus = fugo_fu_error;
alcoholCheckerUtil.alcStatus = AlcoholCheckerUtil.fugo_fu_error;
runOnUiThread(new Runnable() {
@Override
public void run() {
......@@ -392,8 +373,8 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
});
}
private void closeAllDialog() {
private void dismissAllDialog() {
Logger.d(TAG,"dismissAllDialog");
runOnUiThread(new Runnable() {
@Override
public void run() {
......@@ -422,8 +403,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
runOnUiThread(new Runnable() {
@Override
public void run() {
closeAllDialog();
dismissAllDialog();
JSONObject responseJson = new JSONObject();
responseJson.put(ABookKeys.TASK_QUESTION_ID, mQid);
responseJson.put("value", value);
......@@ -442,7 +422,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
runOnUiThread(new Runnable() {
@Override
public void run() {
closeAllDialog();
dismissAllDialog();
alcoholCheckerUtil.sendMessage(AlcoholCheckerUtil.F_BLE_COM_FC_COMMAND_F11);
afterABookCheckApi(mCmd, "", 1, errorMessage, null);
Logger.e(TAG,errorMessage);
......@@ -556,10 +536,10 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
return;
}
BluetoothPairingDeviceInfoDto dto = getABVUIDataCache().getPairingBluetoothDeviceInfo(Constant.DeviceType.alcoholChecker);
alcStatus = fugo_wait_connect;
alcoholCheckerUtil.alcStatus = AlcoholCheckerUtil.fugo_wait_connect;
if (alcoholCheckerUtil.isConnected) {
Logger.d(TAG, "isConnection = true");
alcStatus = fugo_conntected;
alcoholCheckerUtil.alcStatus = AlcoholCheckerUtil.fugo_conntected;
showWaitMeasureDialog(getString(R.string.alcohol_checker), getString(R.string.connection_completed));
} else {
Logger.d(TAG, "isConnection = false");
......@@ -633,17 +613,38 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
@Override
protected void onStop() {
Logger.d(TAG,"-------------------------------------------------");
Logger.d(TAG,"onStop");
Logger.d(TAG,"-------------------------------------------------");
super.onStop();
if (!DeviceInfo.isForegrdound(getApplicationContext()) && readingLogFlg) {
ContentReadingLogLogic logic = AbstractLogic.getLogic(ContentReadingLogLogic.class);
logic.pauseContentReadLog(contentId);
}
// ダイアログ閉じる
dismissAllDialog();
// タイマーにFCコマンド
if (alcoholCheckerUtil != null) {
isAlcBlock = false; // false にしないと2回目押せない
alcoholCheckerUtil.gi_status = AlcoholCheckerUtil.F_BLE_COM_FC_START;
handler.postDelayed(new Runnable() {
@Override
public void run() {
// チェッカーも終了
alcoholCheckerUtil.finish();
}
}, 1000);
}
}
@Override
protected void onDestroy() {
Logger.d(TAG, "onDestroy");
Logger.d(TAG,"-------------------------------------------------");
Logger.d(TAG,"onDestroy");
Logger.d(TAG,"-------------------------------------------------");
//Logger.d(TAG, "onDestroy");
if (readingLogFlg) {
ContentReadingLogLogic logic = AbstractLogic.getLogic(ContentReadingLogLogic.class);
logic.endContentReadLog(contentId);
......@@ -1940,12 +1941,4 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
this.mPhotoEditDialog.show();
}
}
// public void disconnectBluetoothDevice() {
// Logger.d(TAG, "disconnectBluetoothDevice");
//
// if (alcoholCheckerUtil != null) {
// alcoholCheckerUtil.sendMessage(AlcoholCheckerUtil.F_BLE_COM_FC_COMMAND_F11);
// alcoholCheckerUtil.finish();
// }
// }
}
\ No newline at end of file
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 to comment