Commit 4d7278ac by Kim Jinsung

#32918 置くだけセンサー

画面調整
parent dfbe01d8
......@@ -162,17 +162,16 @@ public class ContentRefresher {
// マスタデータの最新更新された時のFetchDateを一時に保存する。
Logger.d(TAG, "before fetchDate : " + ABVEnvironment.getInstance().tempMasterDataFetchDate);
try {
// CMSでメンテナンスされるHACCPマスタデータをアプリから取得できるようにJSONファイルを生成する。
String fetchDate = masterDataLogic.initializeMasterData(ABVEnvironment.getInstance().tempMasterDataFetchDate);
Logger.d(TAG, "after fetchDate : " + fetchDate);
// CMSでメンテナンスされるHACCPマスタデータをアプリから取得できるようにJSONファイルを生成する。
String fetchDate = masterDataLogic.initializeMasterData(ABVEnvironment.getInstance().tempMasterDataFetchDate);
Logger.d(TAG, "after fetchDate : " + fetchDate);
if (fetchDate != null) {
// マスタデータの最新更新された時のFetchDateを一時に保存する。
ABVEnvironment.getInstance().tempMasterDataFetchDate = fetchDate;
} catch (Exception e) {
// ログ表示
Logger.e(TAG, "initializeMasterData error : ", e);
}
if (interrupt) { // この時点で停止要求が来た場合先には進まない。(ServiceOption/Group/Categoryの更新は1セットで行う(トランザクションはそれぞれ別))
Logger.d(TAG, "stop refresh worker before content update.");
setFail();
......
......@@ -28,7 +28,7 @@ public class MasterDataLogic extends AbstractLogic {
* @throws Exception その他、例外です。
* @since 1.0.0
*/
public String initializeMasterData(String lastFetchDate) throws NetworkDisconnectedException, AcmsException, IOException {
public String initializeMasterData(String lastFetchDate) {
// コンテンツバージョン用lastFetchDateの取得
AcmsDao dao = AbstractDao.getDao(AcmsDao.class);
String daoLastFetchDate = dao.selectContentVersionLastFetchDate();
......@@ -38,25 +38,30 @@ public class MasterDataLogic extends AbstractLogic {
lastFetchDate = daoLastFetchDate;
}
FetchDateParameters param = new FetchDateParameters(cache.getMemberInfo().sid, lastFetchDate);
MasterDataJSON masterDataJson = AcmsClient.getInstance(cache.getUrlPath(), networkAdapter).masterData(param);
String fetchDate = null;
try {
FetchDateParameters param = new FetchDateParameters(cache.getMemberInfo().sid, lastFetchDate);
MasterDataJSON masterDataJson = AcmsClient.getInstance(cache.getUrlPath(), networkAdapter).masterData(param);
// get MAP
Map<String, String> masterDataMap = masterDataJson.masterDataMap;
// get MAP
Map<String, String> masterDataMap = masterDataJson.masterDataMap;
// Map に保存されたデータをJSONに変換する。
for (Map.Entry<String, String> entry : masterDataMap.entrySet()) {
System.out.println(entry.getKey() + ":" + entry.getValue());
try {
createMasterDataJson(entry.getKey(), entry.getValue());
} catch (IOException e) {
Logger.e(TAG, "masterDataJSON error : ", e);
throw e;
// Map に保存されたデータをJSONに変換する。
for (Map.Entry<String, String> entry : masterDataMap.entrySet()) {
System.out.println(entry.getKey() + ":" + entry.getValue());
try {
createMasterDataJson(entry.getKey(), entry.getValue());
} catch (IOException e) {
Logger.e(TAG, "masterDataJSON error : ", e);
throw e;
}
}
fetchDate = masterDataJson.fetchDate;
} catch (Exception e) {
Logger.e(TAG, "masterDataSend error : ", e);
}
// masterData の fetchDateを渡す。
return masterDataJson.fetchDate;
return fetchDate;
}
/**
......
......@@ -10,7 +10,7 @@ android {
buildToolsVersion '27.0.3'
defaultConfig {
minSdkVersion 15
minSdkVersion 18
targetSdkVersion 26
//abvEnvironments
resValue("string", "acms_address", "${acms_address}")
......
......@@ -1391,10 +1391,21 @@
<string name="ReportReply_5">報告(回答)(5)</string>
<!-- ABookCheck Sato 1.0.0 -->
<string name="set_pairing">機器連携</string>
<string name="scan">Scan</string>
<string name="stop">Stop</string>
<string name="thermometer">芯温計</string>
<string name="set_title_pairing">ペアリング</string>
<string name="set_pairing_central_thermometer">中心温度計</string>
<string name="pairing_search_scan">スキャン</string>
<string name="pairing_search_stop">中止</string>
<string name="pairing_save_thermometer">登録された温度計</string>
<string name="pairing_other_thermometer">その他温度計</string>
<string name="pairing_other_thermometer_searching">その他温度計(検索中..)</string>
<string name="ble_connect_fail">接続失敗</string>
<string name="ble_disconnect">未接続</string>
<string name="ble_connecting">接続中..</string>
<string name="ble_connect_success">接続済み</string>
<string name="msg_no_device_info">登録された中心温度計情報がありません。\n設定画面のペアリングの中心温度計から登録できます。</string>alert
<string name="ble_is_not_supported">BLEを支援しません。</string>
<string name="bluetooth_is_not_supported">ブルートゥースを支援しません。</string>
<string name="bluetooth_is_not_working">ブルートゥース機能がオンになっているか確認してください。</string>
......@@ -1404,7 +1415,7 @@
<string name="msg_permission_dialog_bluetooth">ブルートゥース利用権限が必要です。\nアプリ設定画面へ遷移します。</string>
<string name="sensor">センサー</string>
<string name="barcode">バーコード</string>
<string name="msg_device_search">ディバイスを検索中</string>
<string name="msg_device_connecting">ディバイスと接続中</string>
<string name="msg_no_device_info">登録された機器情報がありません。\n設定画面の機器連携から確認してください。</string>
</resources>
......@@ -1398,10 +1398,19 @@
<string name="ReportReply_5">보고(회답)(5)</string>
<!-- ABookCheck Sato 1.0.0 -->
<string name="set_pairing">기기연결</string>
<string name="scan">Scan</string>
<string name="stop">Stop</string>
<string name="thermometer">芯温計</string>
<string name="set_title_pairing">패어링</string>
<string name="set_pairing_central_thermometer">중심 온도계</string>
<string name="pairing_search_scan">스캔</string>
<string name="pairing_search_stop">중지</string>
<string name="pairing_save_thermometer">등록된 온도계</string>
<string name="pairing_other_thermometer">그 밖에 온도계</string>
<string name="pairing_other_thermometer_searching">그 밖에 온도계(검색중..)</string>
<string name="ble_connect_fail">접속 실패</string>
<string name="ble_disconnect">접속 안됨</string>
<string name="ble_connecting">접속 시도 중..</string>
<string name="ble_connect_success">접속 완료</string>
<string name="msg_no_device_info">등록된 중심 온도계 정보가 없습니다.\n 설정 화면의 페어링의 중심 온도계에서 등록 가능합니다.</string>
<string name="ble_is_not_supported">BLE는 지원되지 않습니다.</string>
<string name="bluetooth_is_not_supported">블루투스는 지원되지 않습니다.</string>
<string name="bluetooth_is_not_working">블루투스가 작동하지 않습니다.</string>
......@@ -1411,7 +1420,6 @@
<string name="msg_permission_dialog_bluetooth">블루투스이용권한이 필요합니다.\n설정화면으로 이동합니다.</string>
<string name="sensor">센서</string>
<string name="barcode">바코드</string>
<string name="msg_device_search">기기를 검색중\</string>
<string name="msg_device_connecting">기기와 접속중</string>
<string name="msg_no_device_info">등록된 기기정보가 없습니다.\n설정화면의 기기연결에서 확인해주세요.</string>
</resources>
\ No newline at end of file
......@@ -1397,10 +1397,20 @@
<string name="ReportReply_5">ReportReply(5)</string>
<!-- ABookCheck Sato 1.0.0 -->
<string name="set_pairing">Device Connect</string>
<string name="scan">Scan</string>
<string name="stop">Stop</string>
<string name="thermometer">Thermometer</string>
<string name="set_title_pairing">Pairing</string>
<string name="set_pairing_central_thermometer">Central thermometer</string>
<string name="pairing_search_scan">Scan</string>
<string name="pairing_search_stop">Stop</string>
<string name="pairing_save_thermometer">Saved thermometer</string>
<string name="pairing_other_thermometer">Other thermometer</string>
<string name="pairing_other_thermometer_searching">Other thermometer(Searching..)</string>
<string name="ble_connect_fail">Connect fail</string>
<string name="ble_disconnect">Disconnect</string>
<string name="ble_connecting">Connection..</string>
<string name="ble_connect_success">Connected</string>
<string name="msg_no_device_info">There is no registered central thermometer information. \n You can register in the center thermometer of the pairing of setting screen.</string>
<string name="ble_is_not_supported">BLE is not supported.</string>
<string name="bluetooth_is_not_supported">Bluetooth is not supported.</string>
<string name="bluetooth_is_not_working">Bluetooth is not working.</string>
......@@ -1410,7 +1420,6 @@
<string name="msg_permission_dialog_bluetooth">You need Bluetooth access authority. \nIt changes to the application setting.</string>
<string name="sensor">Sensor</string>
<string name="barcode">Barcode</string>
<string name="msg_device_search">Searching Device</string>
<string name="msg_device_connecting">Connecting Device</string>
<string name="msg_no_device_info">There is no registered device information. \nPlease confirm from the device cooperation of the setting screen.</string>
</resources>
\ No newline at end of file
......@@ -28,7 +28,7 @@ android {
buildToolsVersion '27.0.3'
defaultConfig {
minSdkVersion 15
minSdkVersion 18
targetSdkVersion 26
multiDexEnabled true
}
......
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="@android:color/darker_gray"
android:gravity="center_vertical"
android:minHeight="30dp"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<TextView
android:id="@+id/titleTxt"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:text="Main Title" />
<TextView
android:id="@+id/subTitleTxt"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_toRightOf="@+id/titleTxt"
android:gravity="right"
android:text="SubTitle" />
</RelativeLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="80dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:orientation="horizontal"
android:descendantFocusability="blocksDescendants">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="left|center_vertical"
android:layout_weight="1">
<TextView
android:id="@+id/bl_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:maxWidth="250dp"
android:padding="3dp"
android:text="Main Titledfsafsafsdfsdfsdfsd"
android:gravity="left|center_vertical"
android:textSize="20sp" />
<TextView
android:id="@+id/bl_subTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:padding="3dp"
android:text="connection.."
android:textColor="@android:color/darker_gray"
android:textSize="17sp" />
</LinearLayout>
<Button
android:id="@+id/bl_deleteBtn"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right|center_vertical"
android:layout_marginTop="2dp"
android:text="@string/delete" />
</LinearLayout>
\ No newline at end of file
......@@ -46,14 +46,15 @@
android:layout_alignParentRight="true"
android:layout_centerVertical="true">
<Button
android:id="@+id/btn_reload"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:background="@drawable/ic_reload_list" />
<Button
android:id="@+id/btn_reload"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:background="@android:color/transparent"
android:text="Scan"
android:textSize="18sp" />
</LinearLayout>
</RelativeLayout>
......@@ -75,8 +76,8 @@
<ListView
android:id="@+id/devicelist"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dp"
android:layout_weight="1" />
......
......@@ -58,10 +58,10 @@
android:title="@string/operation_manual" >
</PreferenceScreen>
</PreferenceCategory>
<PreferenceCategory android:title="@string/set_pairing" android:key="set_pairing">
<PreferenceCategory android:title="@string/set_title_pairing" android:key="set_pairing">
<PreferenceScreen
android:key="setPairing"
android:title="@string/set_pairing" >
android:title="@string/set_pairing_central_thermometer" >
</PreferenceScreen>
</PreferenceCategory>
</PreferenceScreen>
\ No newline at end of file
......@@ -154,14 +154,14 @@ public class BleManagerUtil {
if( BluetoothGatt.GATT_SUCCESS != status ) {
return;
}
if( UUID_CHARACTERISTIC_PRIVATE1.equals( characteristic.getUuid() ) ) {
final String strTemperature = byteToString(characteristic.getValue());
runOnUiThread( new Runnable() {
public void run() {
// 芯温計の温度を渡す。
listener.onGetDeviceInfo(strTemperature);
// 端末と接続時に呼ばれるのでコメント処理
// listener.onGetDeviceInfo(strTemperature);
}
});
......@@ -250,7 +250,8 @@ public class BleManagerUtil {
// ①「ユーザーの意思による切断」は、mBluetoothGattオブジェクトを解放する。再接続は、オブジェクト構築から。
// ②「接続可能範囲から外れた切断」は、内部処理でmBluetoothGatt.disconnect()処理が実施される。
// 切断時のコールバックでmBluetoothGatt.connect()を呼んでおくと、接続可能範囲に入ったら自動接続する。
mBluetoothGatt.close();
// mBluetoothGatt.close();
mBluetoothGatt.disconnect();
mBluetoothGatt = null;
runOnUiThread( new Runnable() {
......
......@@ -225,14 +225,15 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
bleManagerUtil = new BleManagerUtil(this, new BleManagerUtil.BleManagerUtilListener() {
@Override
public void onConnectionError() {
Logger.d(TAG, "onDisConnectionState");
Logger.d(TAG, "onConnectionError");
putUserPref(UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_CONNECTED, 0);
ABookAlertDialog alert = AlertDialogUtil.createAlertDialog(ABVContentViewActivity.this, R.string.thermometer);
alert.setMessage(String.format(getString(R.string.msg_ble_connect_error), getString(R.string.thermometer), getString(R.string.thermometer)));
ABookAlertDialog alert = AlertDialogUtil.createAlertDialog(ABVContentViewActivity.this, R.string.set_pairing_central_thermometer);
alert.setMessage(String.format(getString(R.string.msg_ble_connect_error), getString(R.string.set_pairing_central_thermometer), getString(R.string.set_pairing_central_thermometer)));
alert.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
setThermometerData("");
bleManagerUtil.disconnect();
}
});
alert.show();
......@@ -240,10 +241,10 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
@Override
public void onConnectionState() { // 接続
Logger.d(TAG, "onDisConnectionState");
Logger.d(TAG, "onConnectionState");
putUserPref(UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_CONNECTED, 1);
ABVToastUtil.showMakeText(getApplicationContext(),
String.format(getString(R.string.msg_connected_bluetooth), getString(R.string.thermometer)),
String.format(getString(R.string.msg_connected_bluetooth), getString(R.string.set_pairing_central_thermometer)),
Toast.LENGTH_SHORT);
}
......@@ -252,26 +253,29 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
Logger.d(TAG, "onDisConnectionState");
putUserPref(UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_CONNECTED, 0);
ABVToastUtil.showMakeText(getApplicationContext(), getString(R.string.msg_ble_not_connect), Toast.LENGTH_SHORT);
setThermometerData("");
}
@Override
public void onGetDeviceInfo(String strTemp) { // 機器のデータ
Logger.d(TAG, "onDisConnectionState");
Logger.d(TAG, "onGetDeviceInfo");
Toast.makeText( getApplicationContext(), strTemp, Toast.LENGTH_SHORT ).show();
Logger.d(TAG, "get temperature [%s]", strTemp);
setThermometerData(strTemp);
bleManagerUtil.disconnect();
}
@Override
public void onGetDeviceInfoFailed() { // 機器のエラー
Logger.d(TAG, "onDisConnectionState");
Logger.d(TAG, "onGetDeviceInfoFailed");
putUserPref(UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_CONNECTED, 0);
ABookAlertDialog alert = AlertDialogUtil.createAlertDialog(ABVContentViewActivity.this, R.string.thermometer);
alert.setMessage(String.format(getString(R.string.msg_ble_connect_error), getString(R.string.thermometer), getString(R.string.thermometer)));
ABookAlertDialog alert = AlertDialogUtil.createAlertDialog(ABVContentViewActivity.this, R.string.set_pairing_central_thermometer);
alert.setMessage(String.format(getString(R.string.msg_ble_connect_error), getString(R.string.set_pairing_central_thermometer), getString(R.string.set_pairing_central_thermometer)));
alert.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
setThermometerData("");
bleManagerUtil.disconnect();
}
});
alert.show();
......@@ -1080,6 +1084,9 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
if(isOperationPdf) {
onActionOperationPdfWebView(abookCheckParam, operationTaskDto);
}
if (Constant.XWalkWebViewDisplayStatus.TaskView != mStatusCode) {
bleManagerUtil.disconnect();
}
} else if (mCmd.equals(ABookKeys.CMD_SAVE_ATTACHED)) {
mAttachedFileName = abookCheckParam.get(ABookKeys.FILE_NAME);
getAttachedDataUrl();
......@@ -1434,24 +1441,15 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
protected void setThermometerDeviceInfo(final boolean showPermissionDialogFlg) {
ABookPermissionHelper helper = new ABookPermissionHelper(this, Constant.ABookPermissionType.Bluetooth, null);
if (helper.checkMultiPermissions(showPermissionDialogFlg)) {
if (getUserPref(UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_ADDRESS, "").length() > 0) {
String strDeviceName = getUserPref(UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_NAME, "");
// ローカルに保存されている場合保存されているディバイス情報を読み込んで処理する。
bleManagerUtil.mDeviceAddress = getUserPref(UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_ADDRESS, "");
int deviceUsed = getUserPref(UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_CONNECTED, 0);
// 取得したデバイスリストアクティビティからの情報をローカルに保存
setUserPref(strDeviceName, bleManagerUtil.mDeviceAddress, deviceUsed);
String deviceAddress = getUserPref(UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_ADDRESS, "");
if (deviceAddress.length() > 0) {
// Android端末のBluetooth機能の有効化要求
requestBluetoothFeature();
bleManagerUtil.mDeviceAddress = deviceAddress;
// 接続
bleManagerUtil.connect();
} else {
// 設定画面に遷移すること
// setPairingSetting(); // 接続するのために機器設定画面に遷移する。
// ディバイス情報がない場合
ABookAlertDialog alert = AlertDialogUtil.createAlertDialog(ABVContentViewActivity.this, R.string.thermometer);
ABookAlertDialog alert = AlertDialogUtil.createAlertDialog(ABVContentViewActivity.this, R.string.set_pairing_central_thermometer);
alert.setMessage(getString(R.string.msg_no_device_info));
alert.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.ok), new DialogInterface.OnClickListener() {
@Override
......@@ -1459,6 +1457,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
setThermometerData("");
}
});
alert.show();
}
} else {
Logger.w(TAG,"onGetDeviceInfoFailed Connect BLE Device false");
......
......@@ -145,4 +145,11 @@ public interface AppDefType {
interface UrlPattern {
String smart360 = "smart360";
}
interface BlueToothConnectStatus {
int CONNECT_FAIL = -1;
int DISCONNECT = 0;
int CONNECTING = 1;
int CONNECT_SUCCESS = 2;
}
}
......@@ -1079,7 +1079,7 @@ public class OperationListActivity extends ABVUIActivity {
* 360コンテンツ登録ダイアログ
*/
public void showPanoEntryDialog(final OperationDto operationDto) {
Logger.d(TAG, "*****************showPanoEntryDialog");
Logger.d(TAG, "showPanoEntryDialog");
if (contentRefresher != null && contentRefresher.isRefreshing()) {
// 新着更新処理が行っていれば、止める
contentRefresher.stopRefresh();
......
......@@ -4,11 +4,13 @@ import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothManager;
import android.bluetooth.le.BluetoothLeScanner;
import android.bluetooth.le.ScanCallback;
import android.bluetooth.le.ScanResult;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
......@@ -34,21 +36,26 @@ import java.util.Map;
import jp.agentec.abook.abv.bl.common.log.Logger;
import jp.agentec.abook.abv.cl.util.BleManagerUtil;
import jp.agentec.abook.abv.cl.util.PreferenceUtil;
import jp.agentec.abook.abv.launcher.android.R;
import jp.agentec.abook.abv.ui.common.activity.ABVContentViewActivity;
import jp.agentec.abook.abv.ui.common.activity.ABVNoAuthenticatedActivity;
import jp.agentec.abook.abv.ui.common.activity.ABVUIActivity;
import jp.agentec.abook.abv.ui.common.appinfo.AppDefType;
import jp.agentec.abook.abv.ui.common.dialog.ABookAlertDialog;
import jp.agentec.abook.abv.ui.common.util.ABVToastUtil;
import jp.agentec.abook.abv.ui.common.util.AlertDialogUtil;
import jp.agentec.abook.abv.ui.home.adapter.BleListAdapter;
import jp.agentec.abook.abv.ui.home.adapter.BleListRowData;
import jp.agentec.abook.abv.ui.home.adapter.common.SectionHeaderData;
import jp.agentec.abook.abv.ui.home.adapter.common.SectionRowData;
public class PairingSettingActivity extends ABVUIActivity implements AdapterView.OnItemClickListener {
public class PairingSettingActivity extends ABVUIActivity {
private static final String TAG = "PairingSettingActivity";
// 定数
private static final int REQUEST_ENABLEBLUETOOTH = 1; // Bluetooth機能の有効化要求時の識別コード
private static final long SCAN_PERIOD = 10000; // スキャン時間。単位はミリ秒。
private static final long SCAN_PERIOD = 20000; // スキャン時間。単位はミリ秒。
public static final String EXTRAS_DEVICE_NAME = "DEVICE_NAME";
public static final String EXTRAS_DEVICE_ADDRESS = "DEVICE_ADDRESS";
public static final String DEVICE_CONNECTED = "DEVICE_CONNECTED"; // ディバイスと接続可否
......@@ -63,6 +70,10 @@ public class PairingSettingActivity extends ABVUIActivity implements AdapterView
private BleManagerUtil bleManagerUtil;
private BleListAdapter mBleListAdapter; // Adapter
private int selectedDeviceListPostion;
private List<BluetoothDevice> mScanDeviceInfoList;
private String mSavedDeviceAddress; //登録した端末アドレス
private boolean mConnecting; //デバイス接続中
// デバイススキャンコールバック
private ScanCallback mLeScanCallback = new ScanCallback() {
......@@ -74,16 +85,22 @@ public class PairingSettingActivity extends ABVUIActivity implements AdapterView
@Override
public void run() {
BluetoothDevice device = result.getDevice();
Logger.d("mLeScanCallback device.getName() = " + device.getName());
// 識別商品名に絞る
if(device.getName() != null && device.getName().startsWith("MF500")) {
Map<String, String> map = new HashMap<String, String>();
map.put(EXTRAS_DEVICE_NAME, device.getName());
map.put(EXTRAS_DEVICE_ADDRESS, device.getAddress());
map.put(DEVICE_CONNECTED, "0");
if (device.getName() != null) {
mBleListAdapter.addDevice(map);
if (!device.getAddress().equals(mSavedDeviceAddress)) { //登録されたデバイスの場合、スキャン情報から除外する。
if (mScanDeviceInfoList == null || mScanDeviceInfoList.size() == 0) {
mScanDeviceInfoList.add(device);
} else {
for (BluetoothDevice savedDevice : mScanDeviceInfoList) {
if (!savedDevice.getAddress().equals(device.getAddress())) {
mScanDeviceInfoList.add(device);
}
}
}
reloadListView();
}
Logger.d("device.getName() = " + device.getName() + "device.getAddress() = " + device.getAddress() );
}
}
} );
......@@ -103,7 +120,10 @@ public class PairingSettingActivity extends ABVUIActivity implements AdapterView
setContentView(R.layout.pairing_setting);
TextView deviceTitle = (TextView) findViewById(R.id.device_toolbar_title);
deviceTitle.setText(R.string.thermometer);
deviceTitle.setText(R.string.set_pairing_central_thermometer);
//初期値(未接続状態)
putUserPref(AppDefType.UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_CONNECTED, AppDefType.BlueToothConnectStatus.DISCONNECT);
// 戻り値の初期化
setResult( Activity.RESULT_CANCELED );
......@@ -112,87 +132,82 @@ public class PairingSettingActivity extends ABVUIActivity implements AdapterView
Intent intent = getIntent();
mBeforeView = intent.getStringExtra("beforeView"); // 以前画面を確認する。以前画面によって接続するやり方が違う。
// リストビューの設定
Map<String, String> map;
List<Map<String, String>> listItem = new ArrayList<Map<String, String>>();
if (getUserPref(AppDefType.UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_NAME, "").length() > 0) {
map = new HashMap<String, String>();
map.put(EXTRAS_DEVICE_NAME, getUserPref(AppDefType.UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_NAME, ""));
map.put(EXTRAS_DEVICE_ADDRESS, getUserPref(AppDefType.UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_ADDRESS, ""));
map.put(DEVICE_CONNECTED, String.valueOf(getUserPref(AppDefType.UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_CONNECTED, 0)));
listItem.add(map);
}
mBleListAdapter = new BleListAdapter( this, listItem, new BleListAdapter.BleListAdapterListener() { // ビューアダプターの初期化
// リストの要素であるボタンクリック処理
List<SectionHeaderData> sectionList = getSectionListInfo();
List<List<BleListRowData>> rowList = getRowListInfo();
mBleListAdapter = new BleListAdapter( this, sectionList, rowList, new BleListAdapter.BleListAdapterListener() { // ビューアダプターの初期化
@Override
public void onConnect(int position) {
selectedDeviceListPostion = position;
deviceListClick(position, "");
// bleManagerUtil.connect();
}
public void onDeleteConnectInfo() { // 登録されたデバイス情報削除
if (mConnecting) { //接続中
return;
}
int status = getUserPref(AppDefType.UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_CONNECTED, 0);
if (status == AppDefType.BlueToothConnectStatus.CONNECT_SUCCESS) { //接続済み
bleManagerUtil.disconnect();
}
@Override
public void onDisconnect(int position) {
selectedDeviceListPostion = position;
bleManagerUtil.disconnect();
// setUserPref("", "", 0); // ディバイスと切断された場合、保存されているディバスの情報を消す。
putUserPref(AppDefType.UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_CONNECTED, 0); // ディバイスと切断された場合、保存されているディバスの接続情報を更新。
removeBleConnectInfoUserPref();
reloadListView();
//スキャン実行中ではない場合はスキャン実行
if (!mScanning) {
startScan();
}
}
});
ListView listView = (ListView) findViewById(R.id.devicelist); // リストビューの取得
listView.setAdapter(mBleListAdapter); // リストビューにビューアダプターをセット
listView.setOnItemClickListener(this); // クリックリスナーオブジェクトのセット
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
Logger.d(TAG, "position = " + position);
BleListRowData bleListRowData = (BleListRowData)parent.getItemAtPosition(position);
connectDevice(bleListRowData);
}
});
// Bluetoothと接続処理する
bleManagerUtil = new BleManagerUtil(this, new BleManagerUtil.BleManagerUtilListener() {
@Override
public void onConnectionError() {
public void onConnectionError() { //接続失敗
Logger.d(TAG, "onConnectionError");
closeProgressPopup();
if (mSavedDeviceAddress != null) {
setUserPref(bleManagerUtil.mDeviceName, bleManagerUtil.mDeviceAddress, AppDefType.BlueToothConnectStatus.CONNECT_FAIL);
}
//画面リロード
reloadListView();
mConnecting = false;
}
@Override
public void onConnectionState() { // 接続
Logger.d(TAG, "onConnectionState");
closeProgressPopup();
Map<String, String> map = new HashMap<String, String>();
map.put(EXTRAS_DEVICE_NAME, bleManagerUtil.mDeviceName);
map.put(EXTRAS_DEVICE_ADDRESS, bleManagerUtil.mDeviceAddress);
map.put(DEVICE_CONNECTED, "1"); // true
mBleListAdapter.updateDevice(selectedDeviceListPostion, map);
ABVToastUtil.showMakeText(getApplicationContext(),
String.format(getString(R.string.msg_connected_bluetooth), getString(R.string.thermometer)),
Toast.LENGTH_SHORT);
setUserPref(bleManagerUtil.mDeviceName, bleManagerUtil.mDeviceAddress, 1); // ローカルにディバイスの情報を保存する。
// ローカルにディバイスの情報を保存する。
setUserPref(bleManagerUtil.mDeviceName, bleManagerUtil.mDeviceAddress, AppDefType.BlueToothConnectStatus.CONNECT_SUCCESS);
//スキャン情報から削除
BluetoothDevice deleteDevice = null;
for (BluetoothDevice device : mScanDeviceInfoList) {
if (device.getAddress().equals(bleManagerUtil.mDeviceAddress)) {
mScanDeviceInfoList.remove(device);
}
}
//画面リロード
reloadListView();
mConnecting = false;
}
@Override
public void onDisConnectionState() { // 切断
Logger.d(TAG, "onDisConnectionState");
closeProgressPopup();
// mDeviceListAdapter.notifyDataSetChanged();
Map<String, String> map = new HashMap<String, String>();
map.put(EXTRAS_DEVICE_NAME, bleManagerUtil.mDeviceName);
map.put(EXTRAS_DEVICE_ADDRESS, bleManagerUtil.mDeviceAddress);
map.put(DEVICE_CONNECTED, "0"); // false
mBleListAdapter.updateDevice(selectedDeviceListPostion, map);
// 保存されているディバイスの接続が接続状態の場合トーストメッセじを表示する。
if (getUserPref(AppDefType.UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_CONNECTED, 0) == 1) {
ABVToastUtil.showMakeText(getApplicationContext(), getString(R.string.msg_ble_not_connect), Toast.LENGTH_SHORT);
}
putUserPref(AppDefType.UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_CONNECTED, 0);
// setUserPref("", "", 0); // ディバイスと切断された場合、保存されているディバスの情報を消す。
putUserPref(AppDefType.UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_CONNECTED, AppDefType.BlueToothConnectStatus.DISCONNECT);
reloadListView();
mConnecting = false;
}
@Override
public void onGetDeviceInfo(String strTemp) { // 機器のデータ
Logger.d(TAG, "onGetDeviceInfo");
closeProgressPopup();
// Toast.makeText( getApplicationContext(), R.string.msg_connected_bluetooth, Toast.LENGTH_SHORT ).show();
Logger.d(TAG, "get temperature [%s]", strTemp);
}
......@@ -200,7 +215,7 @@ public class PairingSettingActivity extends ABVUIActivity implements AdapterView
public void onGetDeviceInfoFailed() { // 機器のエラー
Logger.d(TAG, "onGetDeviceInfoFailed");
closeProgressPopup();
showConfirmAlert( R.string.thermometer, String.format(getString(R.string.msg_ble_connect_error), getString(R.string.thermometer), getString(R.string.thermometer)));
showConfirmAlert( R.string.set_pairing_central_thermometer, String.format(getString(R.string.msg_ble_connect_error), getString(R.string.set_pairing_central_thermometer), getString(R.string.set_pairing_central_thermometer)));
}
});
bleManagerUtil.startDeviceInfo();
......@@ -208,25 +223,21 @@ public class PairingSettingActivity extends ABVUIActivity implements AdapterView
// Reload Button
mButton_Scan = (Button)findViewById( R.id.btn_reload );
mButton_Scan.setAllCaps(false);
mButton_Scan.setText(getString(R.string.pairing_search_scan));
mButton_Scan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startScan();
if (mScanning) {
stopScan();
} else {
startScan();
}
}
});
// 保存されているディバイスの情報がある場合、リストに表示する。
if (getUserPref(AppDefType.UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_ADDRESS, "").length() > 0) {
Map<String, String> getUserDataMap = new HashMap<String, String>();
getUserDataMap.put(EXTRAS_DEVICE_NAME, getUserPref(AppDefType.UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_NAME, ""));
getUserDataMap.put(EXTRAS_DEVICE_ADDRESS, getUserPref(AppDefType.UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_ADDRESS, ""));
getUserDataMap.put(DEVICE_CONNECTED, String.valueOf(getUserPref(AppDefType.UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_CONNECTED, 0)));
mBleListAdapter.addDevice(getUserDataMap);
}
// UIスレッド操作ハンドラの作成(「一定時間後にスキャンをやめる処理」で使用する)
mHandler = new Handler();
this.mScanDeviceInfoList = new ArrayList<BluetoothDevice>();
}
// 初回表示時、および、ポーズからの復帰時
......@@ -279,8 +290,7 @@ public class PairingSettingActivity extends ABVUIActivity implements AdapterView
protected void onActivityResult( int requestCode, int resultCode, Intent data ) {
switch( requestCode ) {
case REQUEST_ENABLEBLUETOOTH: // Bluetooth有効化要求
if( Activity.RESULT_CANCELED == resultCode )
{ // 有効にされなかった
if( Activity.RESULT_CANCELED == resultCode ) { // 有効にされなかった
ABVToastUtil.showMakeText(getApplicationContext(), getString(R.string.bluetooth_is_not_working), Toast.LENGTH_SHORT);
return;
}
......@@ -291,33 +301,36 @@ public class PairingSettingActivity extends ABVUIActivity implements AdapterView
// スキャンの開始
private void startScan() {
// リストビューの内容を空にする。
// mBleListAdapter.clear();
//デバイス接続中にはスキャンさせない
if (mConnecting) {
return;
}
// BluetoothLeScannerの取得
// ※Runnableオブジェクト内でも使用できるようfinalオブジェクトとする。
final android.bluetooth.le.BluetoothLeScanner scanner = bleManagerUtil.mBluetoothAdapter.getBluetoothLeScanner();
if( null == scanner )
{
BluetoothLeScanner scanner = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
scanner = bleManagerUtil.mBluetoothAdapter.getBluetoothLeScanner();
}
if(scanner == null) {
return;
}
showProgressPopup(getRString(R.string.msg_device_search));
// スキャン開始(一定時間後にスキャン停止する)
mHandler.postDelayed( new Runnable() {
@Override
public void run() {
mScanning = false;
scanner.stopScan( mLeScanCallback );
Logger.d(TAG, "scan in 10 sec");
closeProgressPopup();
stopScan();
Logger.d(TAG, "scan in 20 sec");
}
}, SCAN_PERIOD );
mScanning = true;
scanner.startScan( mLeScanCallback );
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
scanner.startScan( mLeScanCallback );
}
mButton_Scan.setText(getString(R.string.pairing_search_stop));
reloadListView();
Logger.d(TAG, "start scan !!");
}
......@@ -327,57 +340,58 @@ public class PairingSettingActivity extends ABVUIActivity implements AdapterView
mHandler.removeCallbacksAndMessages( null );
// BluetoothLeScannerの取得
android.bluetooth.le.BluetoothLeScanner scanner = bleManagerUtil.mBluetoothAdapter.getBluetoothLeScanner();
if( null == scanner )
{
BluetoothLeScanner scanner = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
scanner = bleManagerUtil.mBluetoothAdapter.getBluetoothLeScanner();
}
if(scanner == null) {
return;
}
mScanning = false;
scanner.stopScan( mLeScanCallback );
mScanning = false;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
scanner.stopScan( mLeScanCallback );
}
mButton_Scan.setText(getString(R.string.pairing_search_scan));
reloadListView();
Logger.d(TAG, "stop scan !!");
}
private void connectDevice(BleListRowData bleListRowData) {
// リストビューのアイテムクリック時の処理
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id ) {
deviceListClick(position, DEVICE_LIST);
}
//スキャン中の場合、中止する。
if (mScanning) {
stopScan();
}
private void deviceListClick(int position, String selectItem) {
// クリックされたアイテムの取得
final Map<String, String> device = mBleListAdapter.getItem(position);
if ( null == device && getUserPref(AppDefType.UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_ADDRESS, "").length() == 0 ) {
//2重接続防止
if (mConnecting) {
return;
}
String deviceName = "";
String deviceAddress = "";
if (device.get(EXTRAS_DEVICE_NAME).length() > 0 ) {
deviceName = device.get(EXTRAS_DEVICE_NAME);
deviceAddress = device.get(EXTRAS_DEVICE_ADDRESS);
} else if (getUserPref(AppDefType.UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_ADDRESS, "").length() > 0) {
deviceName = getUserPref(AppDefType.UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_NAME, "");
deviceAddress = getUserPref(AppDefType.UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_ADDRESS, "");
//登録されたデバイス情報を選択した場合
if (bleListRowData.isSaved) {
//接続済み状態の場合、接続を切る
if (bleListRowData.subTitle.equals(getString(R.string.ble_connect_success))) {
bleManagerUtil.disconnect();
return;
}
}
if (mBeforeView.isEmpty() && selectItem.equals(DEVICE_LIST)) {
// 戻り値の設定
Intent intent = new Intent();
intent.putExtra(EXTRAS_DEVICE_NAME, deviceName);
intent.putExtra(EXTRAS_DEVICE_ADDRESS, deviceAddress);
setResult(Activity.RESULT_OK, intent);
finish();
} else {
bleManagerUtil.mDeviceAddress = deviceAddress;
bleManagerUtil.mDeviceName = deviceName;
showProgressPopup(getString(R.string.msg_device_connecting));
mConnecting = true;
String deviceName = bleListRowData.title;
String deviceAddress = bleListRowData.deviceAddress;
bleManagerUtil.mDeviceAddress = deviceAddress;
bleManagerUtil.mDeviceName = deviceName;
// デバイスのBluetooth機能の有効化要求
requestBluetoothFeature();
// 接続
bleManagerUtil.connect();
// デバイスのBluetooth機能の有効化要求
requestBluetoothFeature();
// 接続
bleManagerUtil.connect();
if (mSavedDeviceAddress != null) {
setUserPref(bleManagerUtil.mDeviceName, bleManagerUtil.mDeviceAddress, AppDefType.BlueToothConnectStatus.CONNECTING);
//画面リロード
reloadListView();
}
}
......@@ -400,6 +414,16 @@ public class PairingSettingActivity extends ABVUIActivity implements AdapterView
putUserPref(AppDefType.UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_CONNECTED, deviceConnected);
}
/**
* 機器連携の情報をローカルに削除する。
*/
private void removeBleConnectInfoUserPref() {
PreferenceUtil.removeUserPref(this, AppDefType.UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_NAME);
PreferenceUtil.removeUserPref(this, AppDefType.UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_ADDRESS);
PreferenceUtil.removeUserPref(this, AppDefType.UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_CONNECTED);
mSavedDeviceAddress = null;
}
// アラート表示処理
private void showConfirmAlert(final int dialogTitle, String dialogMessage) {
ABookAlertDialog alert = AlertDialogUtil.createAlertDialog(this, dialogTitle);
......@@ -407,5 +431,88 @@ public class PairingSettingActivity extends ABVUIActivity implements AdapterView
alert.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(R.string.confirm), (DialogInterface.OnClickListener) null);
showAlertDialog(alert);
}
/**
* ListViewのSectionデータを作成する。
* @return Rowデータリスト
*/
private List<SectionHeaderData> getSectionListInfo() {
List<SectionHeaderData> sectionList = new ArrayList<SectionHeaderData>();
if (getUserPref(AppDefType.UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_NAME, "").length() > 0) {
sectionList.add(new SectionHeaderData(getString(R.string.pairing_save_thermometer)));
}
if (mScanning) {
sectionList.add(new SectionHeaderData(getString(R.string.pairing_other_thermometer_searching)));
} else {
sectionList.add(new SectionHeaderData(getString(R.string.pairing_other_thermometer)));
}
return sectionList;
}
/**
* ListViewのRowデータを作成する。
* @return Rowデータリスト
*/
private List<List<BleListRowData>> getRowListInfo() {
List<List<BleListRowData>> rowList = new ArrayList<List<BleListRowData>>();
if (getUserPref(AppDefType.UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_NAME, "").length() > 0) {
List<BleListRowData> rowDataList = new ArrayList<BleListRowData>();
String deviceName = getUserPref(AppDefType.UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_NAME, "");
String deviceAddress = getUserPref(AppDefType.UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_ADDRESS, "");
int status = getUserPref(AppDefType.UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_CONNECTED, 0);
String deviceConnectStatus = null;
switch (status) {
case AppDefType.BlueToothConnectStatus.CONNECT_FAIL:
deviceConnectStatus = getString(R.string.ble_connect_fail);
break;
case AppDefType.BlueToothConnectStatus.DISCONNECT:
deviceConnectStatus = getString(R.string.ble_disconnect);
break;
case AppDefType.BlueToothConnectStatus.CONNECTING:
deviceConnectStatus = getString(R.string.ble_connecting);
break;
case AppDefType.BlueToothConnectStatus.CONNECT_SUCCESS:
deviceConnectStatus = getString(R.string.ble_connect_success);
break;
default:
deviceConnectStatus = getString(R.string.ble_disconnect);
break;
}
BleListRowData rowData = new BleListRowData(deviceName, deviceConnectStatus , deviceAddress);
rowDataList.add(rowData);
rowList.add(rowDataList);
this.mSavedDeviceAddress = deviceAddress;
}
if (mScanDeviceInfoList == null || mScanDeviceInfoList.size() == 0) {
List<BleListRowData> scanRowDataList = new ArrayList<BleListRowData>();
BleListRowData scanRowData = new BleListRowData("" , "" );
scanRowDataList.add(scanRowData);
rowList.add(scanRowDataList);
} else {
List<BleListRowData> scanRowDataList = new ArrayList<BleListRowData>();
for (BluetoothDevice bleDevice : mScanDeviceInfoList) {
BleListRowData scanRowData = new BleListRowData(bleDevice.getName() , bleDevice.getAddress());
scanRowDataList.add(scanRowData);
}
rowList.add(scanRowDataList);
}
return rowList;
}
/**
* ListViewをリロードする。
*/
private void reloadListView() {
List<SectionHeaderData> sectionList = getSectionListInfo();
List<List<BleListRowData>> rowList = getRowListInfo();
mBleListAdapter.setItem(sectionList, rowList);
}
}
......@@ -4,7 +4,7 @@ import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
......@@ -12,6 +12,9 @@ import java.util.List;
import java.util.Map;
import jp.agentec.abook.abv.launcher.android.R;
import jp.agentec.abook.abv.ui.home.adapter.common.BaseSectionAdapter;
import jp.agentec.abook.abv.ui.home.adapter.common.IndexPath;
import jp.agentec.abook.abv.ui.home.adapter.common.SectionHeaderData;
import static jp.agentec.abook.abv.ui.home.activity.PairingSettingActivity.DEVICE_CONNECTED;
import static jp.agentec.abook.abv.ui.home.activity.PairingSettingActivity.EXTRAS_DEVICE_ADDRESS;
......@@ -22,7 +25,7 @@ import static org.chromium.base.ThreadUtils.runOnUiThread;
* Created by kim, changgyun on 2018/11/15.
*/
public class BleListAdapter extends BaseAdapter {
public class BleListAdapter extends BaseSectionAdapter<SectionHeaderData, BleListRowData> {
private static final String TAG = "BleListAdapter";
protected BleListAdapter.BleListAdapterListener listener;
private Context mContext;
......@@ -34,142 +37,82 @@ public class BleListAdapter extends BaseAdapter {
private boolean savedDeviceConnected = false; // 保存されているディバスの接続可否
public interface BleListAdapterListener {
// 接続
void onConnect(int postion);
// 切断
void onDisconnect(int position);
// 登録されたデバイス情報削除
void onDeleteConnectInfo();
}
public BleListAdapter(Context context, List<Map<String, String>> listItem, BleListAdapterListener listener) {
mContext = context;
mListItem = listItem;
if (mListItem.size() > 0) {
savedDeviceAddress = mListItem.get(0).get(EXTRAS_DEVICE_ADDRESS);
savedDeviceName = mListItem.get(0).get(EXTRAS_DEVICE_NAME);
savedDeviceConnected = mListItem.get(0).get(DEVICE_CONNECTED) == "1" ? true : false;
}
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
public BleListAdapter(Context context, List<SectionHeaderData> sectionList,
List<List<BleListRowData>> rowList, BleListAdapterListener listener) {
super(context, sectionList, rowList);
this.listener = listener;
}
public List<Map<String, String>> getData() {
return mListItem;
}
// リストへの追加
public void addDevice( Map<String, String> deviceList ) {
if (!mListItem.contains(deviceList)) { // 加えられていなければ加える
mListItem.add(deviceList);
notifyDataSetChanged(); // ListViewの更新
}
}
public void updateDevice(int position, Map<String, String> deviceList) {
if (mListItem.get(position).get(EXTRAS_DEVICE_NAME).equals(deviceList.get(EXTRAS_DEVICE_NAME))) {
// if (mListItem.contains(deviceList)) { // 加えられていなければ加える
mListItem.set(position, deviceList);
savedDeviceAddress = deviceList.get(EXTRAS_DEVICE_ADDRESS);
savedDeviceName = deviceList.get(EXTRAS_DEVICE_NAME);
savedDeviceConnected = deviceList.get(DEVICE_CONNECTED) == "1" ? true : false;
notifyDataSetChanged();
}
}
@Override
public int getCount() {
return mListItem.size();
}
@Override
public Map<String, String> getItem(int position) {
return mListItem.get(position);
}
@Override
public long getItemId( int position ) {
return position;
}
public void setItem(List<Map<String, String>> listItem) {
mListItem= listItem;
}
// リストのクリア
public void clear() {
mListItem.clear();
notifyDataSetChanged(); // ListViewの更新
public View viewForHeaderInSection(View convertView, int section) {
ListHeaderViewHolder holder = null;
if (convertView == null) {
convertView = inflater.inflate(R.layout.ble_section_list_header, null);
holder = new ListHeaderViewHolder();
holder.titleTxt = (TextView) convertView.findViewById(R.id.titleTxt);
holder.subtitleTxt = (TextView) convertView.findViewById(R.id.subTitleTxt);
convertView.setTag(holder);
} else {
holder = (ListHeaderViewHolder) convertView.getTag();
}
SectionHeaderData headerData = sectionList.get(section);
holder.titleTxt.setText(headerData.title);
holder.subtitleTxt.setText(headerData.subTitle);
return convertView;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
public View cellForRowAtIndexPath(View convertView, IndexPath indexPath) {
ListRowViewHolder holder = null;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.pairing_device_list_item, parent, false);
holder = new ViewHolder();
holder.deviceName = (TextView) convertView.findViewById(R.id.textview_devicename);
holder.deviceAddress = (TextView) convertView.findViewById(R.id.textview_deviceaddress);
holder.isConnect = (ImageView) convertView.findViewById(R.id.btn_connect);
holder.isDisConnect = (ImageView) convertView.findViewById(R.id.btn_disconnect);
convertView = inflater.inflate(R.layout.ble_section_list_row, null);
holder = new ListRowViewHolder();
holder.bl_title = (TextView) convertView.findViewById(R.id.bl_title);
holder.bl_subTitle = (TextView) convertView.findViewById(R.id.bl_subTitle);
holder.bl_deleteBtn = (Button) convertView.findViewById(R.id.bl_deleteBtn);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
final Map<String, String> device = mListItem.get(position);
String deviceName = device.get(EXTRAS_DEVICE_NAME);
String deviceAddress = device.get(EXTRAS_DEVICE_ADDRESS);
// Logger.d(TAG, "deviceName : [" + deviceName);
// Logger.d(TAG, "deviceAddress : [" + deviceAddress);
// Logger.d(TAG, "defaultDeviceAddress : [" + savedDeviceAddress);
// Logger.d(TAG, "defaultDeviceName : [" + savedDeviceName);
if( null != deviceName && 0 < deviceName.length() && !deviceName.equals(savedDeviceName)) {
holder.deviceName.setText( deviceName );
holder.deviceAddress.setText( deviceAddress );
} else if (null != deviceName && deviceName.equals(savedDeviceName)) {
holder.deviceName.setText( savedDeviceName );
holder.deviceAddress.setText( savedDeviceAddress );
holder = (ListRowViewHolder) convertView.getTag();
}
if (holder.deviceAddress.getText().equals(savedDeviceAddress)) {
if (savedDeviceConnected) {
holder.isConnect.setVisibility(convertView.GONE);
holder.isDisConnect.setVisibility(convertView.VISIBLE);
} else {
holder.isConnect.setVisibility(convertView.VISIBLE);
holder.isDisConnect.setVisibility(convertView.GONE);
}
BleListRowData rowData = rowList.get(indexPath.section).get(indexPath.row);
holder.bl_title.setText(rowData.title);
holder.bl_subTitle.setText(rowData.subTitle);
//スキャンされた温度計表示時に削除ボタンと接続ステータス非表示
if (!rowData.isSaved) {
holder.bl_deleteBtn.setVisibility(View.INVISIBLE);
holder.bl_subTitle.setVisibility(View.GONE);
} else {
holder.isConnect.setVisibility(convertView.VISIBLE);
holder.isDisConnect.setVisibility(convertView.GONE);
holder.bl_deleteBtn.setVisibility(View.VISIBLE);
holder.bl_deleteBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.onDeleteConnectInfo();
}
});
holder.bl_subTitle.setVisibility(View.VISIBLE);
}
holder.isConnect.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.onConnect(position);
}
});
holder.isDisConnect.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.onDisconnect(position);
}
});
return convertView;
}
private static class ViewHolder {
TextView deviceName; // ディバイスの名
TextView deviceAddress; // ディバイスのアドレス
static class ListHeaderViewHolder {
TextView titleTxt;
TextView subtitleTxt;
}
ImageView isConnect; // ディバイスとの接続ボタン
ImageView isDisConnect; // ディバイスとの切断ボタン
static class ListRowViewHolder {
TextView bl_title;
TextView bl_subTitle;
Button bl_deleteBtn;
}
public void setAdapterListener(BleListAdapterListener listener) {
this.listener = listener;
public void setItem(List<SectionHeaderData> sectionList, List<List<BleListRowData>> rowList) {
settingSectionRowData(sectionList, rowList);
notifyDataSetChanged();
}
}
package jp.agentec.abook.abv.ui.home.adapter;
import jp.agentec.abook.abv.ui.home.adapter.common.SectionRowData;
public class BleListRowData extends SectionRowData {
public boolean isSaved;
public String deviceAddress;
/**
* 中心温度計(登録された温度計)
* @param title 温度計名
* @param deviceAddress デバイスアドレス
*/
public BleListRowData(String title, String deviceAddress) {
super(title, null);
this.deviceAddress = deviceAddress;
this.isSaved = false;
}
/**
* 中心温度計(スキャンされた温度計)
* @param title 温度計名
* @param subTitle 接続状態
* @param deviceAddress デバイスアドレス
*/
public BleListRowData(String title, String subTitle, String deviceAddress) {
super(title, subTitle);
this.deviceAddress = deviceAddress;
this.isSaved = true;
}
}
package jp.agentec.abook.abv.ui.home.adapter.common;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
public class BaseSectionAdapter<T1, T2> extends BaseAdapter {
/** インデックス行:ヘッダー */
private static final int INDEX_PATH_ROW_HEADER = -1;
/** ビュータイプ:ヘッダー行 */
private static final int ITEM_VIEW_TYPE_HEADER = 0;
/** ビュータイプ:データ行 */
private static final int ITEM_VIEW_TYPE_ROW = 1;
protected Context context;
protected LayoutInflater inflater;
/** ヘッダー行で使用するデータリスト */
protected List<T1> sectionList;
/** データ行で使用するデータリスト */
protected List<List<T2>> rowList;
private List<IndexPath> indexPathList;
public BaseSectionAdapter(Context context, List<T1> sectionList, List<List<T2>> rowList) {
super();
this.context = context;
this.inflater = LayoutInflater.from(context);
this.sectionList = sectionList;
this.rowList = rowList;
this.indexPathList = getIndexPathList(sectionList, rowList);
}
@Override
public int getCount() {
int count = indexPathList.size();
return count;
}
@Override
public Object getItem(int position) {
IndexPath indexPath = indexPathList.get(position);
if (isHeader(indexPath)) {
return sectionList.get(indexPath.section);
} else {
return rowList.get(indexPath.section).get(indexPath.row);
}
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
IndexPath indexPath = indexPathList.get(position);
// ヘッダー行とデータ行とで分岐します。
if (isHeader(indexPath)) {
return viewForHeaderInSection(convertView, indexPath.section);
} else {
return cellForRowAtIndexPath(convertView, indexPath);
}
}
/**
* ヘッダー行のViewを返します。
*
* @param convertView
* @param section
* @return ヘッダー行のView
*/
public View viewForHeaderInSection(View convertView, int section) {
if (convertView == null) {
convertView = inflater.inflate(android.R.layout.simple_list_item_1, null);
TextView castedConvertView = (TextView) convertView;
castedConvertView.setBackgroundColor(Color.GRAY);
castedConvertView.setTextColor(Color.WHITE);
}
TextView textView = (TextView) convertView;
textView.setText(sectionList.get(section).toString());
return convertView;
}
/**
* データ行のViewを返します。
*
* @param convertView
* @param indexPath
* @return データ行のView
*/
public View cellForRowAtIndexPath(View convertView, IndexPath indexPath) {
if (convertView == null) {
convertView = inflater.inflate(android.R.layout.simple_list_item_1, null);
}
TextView textView = (TextView) convertView;
textView.setText(rowList.get(indexPath.section).get(indexPath.row).toString());
return convertView;
}
@Override
public int getViewTypeCount() {
// ヘッダー行とデータ行の2種類なので、2を返します。
return 2;
}
@Override
public int getItemViewType(int position) {
// ビュータイプを返します。
if (isHeader(position)) {
return ITEM_VIEW_TYPE_HEADER;
} else {
return ITEM_VIEW_TYPE_ROW;
}
}
@Override
public boolean isEnabled(int position) {
if (isHeader(position)) {
// ヘッダー行の場合は、タップできないようにします。
return false;
} else {
IndexPath indexPath = indexPathList.get(position);
SectionRowData rowData = (SectionRowData) rowList.get(indexPath.section).get(indexPath.row);
if (rowData.title.isEmpty()) { //タイトルが空白の場合はタップ不能に設定
return false;
}
return super.isEnabled(position);
}
}
/**
* インデックスパスリストを取得します。
*
* @param sectionList
* @param rowList
* @return インデックスパスリスト
*/
private List<IndexPath> getIndexPathList(List<T1> sectionList, List<List<T2>> rowList) {
List<IndexPath> indexPathList = new ArrayList<IndexPath>();
for (int i = 0; i < sectionList.size(); i++) {
IndexPath sectionIndexPath = new IndexPath();
sectionIndexPath.section = i;
sectionIndexPath.row = INDEX_PATH_ROW_HEADER;
indexPathList.add(sectionIndexPath);
List<T2> rowListBySection = rowList.get(i);
for (int j = 0; j < rowListBySection.size(); j++) {
IndexPath rowIndexPath = new IndexPath();
rowIndexPath.section = i;
rowIndexPath.row = j;
indexPathList.add(rowIndexPath);
}
}
return indexPathList;
}
private boolean isHeader(int position) {
IndexPath indexPath = indexPathList.get(position);
return isHeader(indexPath);
}
private boolean isHeader(IndexPath indexPath) {
if (INDEX_PATH_ROW_HEADER == indexPath.row) {
return true;
} else {
return false;
}
}
protected void settingSectionRowData(List<T1> sectionList, List<List<T2>> rowList) {
this.sectionList = sectionList;
this.rowList = rowList;
this.indexPathList = getIndexPathList(sectionList, rowList);
}
}
package jp.agentec.abook.abv.ui.home.adapter.common;
public class IndexPath {
public int section;
public int row;
}
package jp.agentec.abook.abv.ui.home.adapter.common;
/**
* ListViewのAdapterで利用するSectionの値設定クラス
*/
public class SectionHeaderData {
/**
* 中心温度計用
* @param title タイトル
*/
public SectionHeaderData(String title) {
this.title = title;
}
/**
* 共通用
* @param title タイトル
* @param subTitle サブタイトル
*/
public SectionHeaderData(String title, String subTitle) {
this.title = title;
this.subTitle = subTitle;
}
public String title;
public String subTitle;
}
\ No newline at end of file
package jp.agentec.abook.abv.ui.home.adapter.common;
/**
* ListViewのAdapterで利用するRowの値設定クラス
*/
public class SectionRowData {
/**
* 共通用
* @param title タイトル
* @param subTitle サブタイトル
*/
public SectionRowData(String title, String subTitle) {
this.title = title;
this.subTitle = subTitle;
}
public String title;
public String subTitle;
}
......@@ -222,7 +222,7 @@ public class HTMLXWalkWebViewActivity extends ParentWebViewActivity {
public void openFileChooser(XWalkView view, ValueCallback<Uri> uploadFile,
String acceptType, String capture) {
super.openFileChooser(view, uploadFile, acceptType, capture);
Logger.d(TAG, "*********************commonOpenFileChooser");
Logger.d(TAG, "commonOpenFileChooser");
boolean result = false;
if (acceptType.toLowerCase().indexOf(ABookKeys.IMAGE) != -1) {
result = startCameraIntent(ABOOK_CHECK_TASK_IMAGE, "Camera", ABookKeys.IMAGE, true);
......
......@@ -38,12 +38,12 @@ app_versioncode=1
# abvEnvironments.xml
#cms server
acms_address=https://abook189.abook.bz/acms
download_server_address=https://abook189.abook.bz/acms
acms_address=https://check.abookcloud.com/acms
download_server_address=https://check.abookcloud.com/acms
#syncview server
websocket_server_http_url=https://abookplus.agentec.jp/v1
websocket_server_ws_url=wss://abookplus.agentec.jp/v1
websocket_server_http_url=https://abook188-1.abook.bz/v1
websocket_server_ws_url=wss://abook188-1.abook.bz/v1
#WebSocket debug出力
websocket_debug=false
......@@ -93,7 +93,7 @@ hope_page=http://www.agentec.jp
contact_email=abook-appsupport@agentec.jp
#Log Settings
log_level=2
log_level=0
default_log_name=abvje
#エラーレポート/Exportログ送信方法 1:acms 2:平文メール(開発・テスト時のみ) 3:暗号化添付メール
error_report_flg=1
......
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