Commit 6d3a69d6 by onuma

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

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