Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
abook_check
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abook_android
abook_check
Commits
a01ca2f5
Commit
a01ca2f5
authored
Apr 18, 2019
by
Jeong Gilmo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#32960 ペアリング設定画面
- 設定画面から機器連携項目追加 - 機器連携画面で芯温計と接続処理追加 - BLE の機器と検索、接続、切断処理機能の追加
parent
49ba3b58
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
1130 additions
and
0 deletions
+1130
-0
ABVJE_Launcher_Android/AndroidManifest.xml
+7
-0
ABVJE_Res_Default_Android/res/values-ja/strings.xml
+13
-0
ABVJE_Res_Default_Android/res/values-ko/strings.xml
+14
-0
ABVJE_Res_Default_Android/res/values/strings.xml
+14
-0
ABVJE_UI_Android/res/layout/pairing_device_list_item.xml
+45
-0
ABVJE_UI_Android/res/layout/pairing_setting.xml
+114
-0
ABVJE_UI_Android/res/xml/pref.xml
+7
-0
ABVJE_UI_Android/src/jp/agentec/abook/abv/cl/util/BleManagerUtil.java
+294
-0
ABVJE_UI_Android/src/jp/agentec/abook/abv/ui/common/appinfo/AppDefType.java
+4
-0
ABVJE_UI_Android/src/jp/agentec/abook/abv/ui/home/activity/ABookSettingFragment.java
+27
-0
ABVJE_UI_Android/src/jp/agentec/abook/abv/ui/home/activity/PairingSettingActivity.java
+399
-0
ABVJE_UI_Android/src/jp/agentec/abook/abv/ui/home/adapter/BleListAdapter.java
+175
-0
ABVJE_UI_Android/src/jp/agentec/abook/abv/ui/home/helper/ABookPermissionHelper.java
+17
-0
No files found.
ABVJE_Launcher_Android/AndroidManifest.xml
View file @
a01ca2f5
...
@@ -30,6 +30,9 @@
...
@@ -30,6 +30,9 @@
<uses-permission
android:name=
"android.permission.CAMERA"
/>
<uses-permission
android:name=
"android.permission.CAMERA"
/>
<uses-permission
android:name=
"android.permission.FLASHLIGHT"
/>
<uses-permission
android:name=
"android.permission.FLASHLIGHT"
/>
<!-- BLE -->
<uses-feature
android:name=
"android.hardware.bluetooth_le"
android:required=
"true"
/>
<permission
<permission
android:name=
"${applicationId}.permission.C2D_MESSAGE"
android:name=
"${applicationId}.permission.C2D_MESSAGE"
android:protectionLevel=
"signature"
/>
android:protectionLevel=
"signature"
/>
...
@@ -210,5 +213,8 @@
...
@@ -210,5 +213,8 @@
<activity
android:name=
"jp.agentec.abook.abv.ui.viewer.activity.CheckOZDViewActivity"
android:configChanges=
"orientation|screenSize"
/>
<activity
android:name=
"jp.agentec.abook.abv.ui.viewer.activity.CheckOZDViewActivity"
android:configChanges=
"orientation|screenSize"
/>
<!-- ABookCheck1.0.0 Sato -->
<activity
android:name=
"jp.agentec.abook.abv.ui.home.activity.PairingSettingActivity"
android:theme=
"@style/AppTheme"
/>
</application>
</application>
</manifest>
</manifest>
\ No newline at end of file
ABVJE_Res_Default_Android/res/values-ja/strings.xml
View file @
a01ca2f5
...
@@ -1370,4 +1370,17 @@
...
@@ -1370,4 +1370,17 @@
<string
name=
"Report_5"
>
報告(5)
</string>
<string
name=
"Report_5"
>
報告(5)
</string>
<string
name=
"Routine_5"
>
定期点検(5)
</string>
<string
name=
"Routine_5"
>
定期点検(5)
</string>
<string
name=
"ReportReply_5"
>
報告(回答)(5)
</string>
<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=
"ble_is_not_supported"
>
BLEを支援しません。
</string>
<string
name=
"bluetooth_is_not_supported"
>
ブルートゥースを支援しません。
</string>
<string
name=
"bluetooth_is_not_working"
>
ブルートゥースが機能しません。
</string>
<string
name=
"msg_connected_bluetooth"
>
%sに接続されました。
</string>
<string
name=
"msg_ble_not_connect"
>
接続が停止しました。
</string>
<string
name=
"msg_ble_connect_error"
>
%sと接続されていません。\n%sと接続状態を設定画面の機器連携から確認してください。
</string>
</resources>
</resources>
ABVJE_Res_Default_Android/res/values-ko/strings.xml
View file @
a01ca2f5
...
@@ -1371,4 +1371,17 @@
...
@@ -1371,4 +1371,17 @@
<string
name=
"Report_5"
>
보고(5)
</string>
<string
name=
"Report_5"
>
보고(5)
</string>
<string
name=
"Routine_5"
>
정기점검(5)
</string>
<string
name=
"Routine_5"
>
정기점검(5)
</string>
<string
name=
"ReportReply_5"
>
보고(회답)(5)
</string>
<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=
"ble_is_not_supported"
>
BLE는 지원되지 않습니다.
</string>
<string
name=
"bluetooth_is_not_supported"
>
블루투스는 지원되지 않습니다.
</string>
<string
name=
"bluetooth_is_not_working"
>
블루투스가 작동하지 않습니다.
</string>
<string
name=
"msg_connected_bluetooth"
>
%s에 접속되었습니다
</string>
<string
name=
"msg_ble_not_connect"
>
접속이 정지되었습니다.
</string>
<string
name=
"msg_ble_connect_error"
>
%s랑 접속되지않습니다.\n%s와의 접속상태를 설정화면의 기기연결에서 확인해주세요.
</string>
</resources>
</resources>
\ No newline at end of file
ABVJE_Res_Default_Android/res/values/strings.xml
View file @
a01ca2f5
...
@@ -1370,4 +1370,17 @@
...
@@ -1370,4 +1370,17 @@
<string
name=
"Report_5"
>
Report(5)
</string>
<string
name=
"Report_5"
>
Report(5)
</string>
<string
name=
"Routine_5"
>
Routine(5)
</string>
<string
name=
"Routine_5"
>
Routine(5)
</string>
<string
name=
"ReportReply_5"
>
ReportReply(5)
</string>
<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=
"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>
<string
name=
"msg_connected_bluetooth"
>
Connected to %s
</string>
<string
name=
"msg_ble_not_connect"
>
The connection has stopped.
</string>
<string
name=
"msg_ble_connect_error"
>
Not connected with% %s. \nCheck %s and connection status from the device linkage on the setting screen.
</string>
</resources>
</resources>
\ No newline at end of file
ABVJE_UI_Android/res/layout/pairing_device_list_item.xml
0 → 100755
View file @
a01ca2f5
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:orientation=
"horizontal"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"horizontal"
>
<LinearLayout
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginLeft=
"15dp"
android:layout_weight=
"1"
android:orientation=
"vertical"
>
<TextView
android:id=
"@+id/textview_devicename"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:textSize=
"24dp"
/>
<TextView
android:id=
"@+id/textview_deviceaddress"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:textSize=
"12dp"
/>
</LinearLayout>
<ImageView
android:id=
"@+id/btn_connect"
android:layout_width=
"50dp"
android:layout_height=
"50dp"
android:padding=
"3dp"
android:background=
"@drawable/ic_reload_list"
/>
<ImageView
android:id=
"@+id/btn_disconnect"
android:layout_width=
"50dp"
android:layout_height=
"50dp"
android:padding=
"3dp"
android:background=
"@drawable/ic_delete"
/>
</LinearLayout>
</LinearLayout>
\ No newline at end of file
ABVJE_UI_Android/res/layout/pairing_setting.xml
0 → 100644
View file @
a01ca2f5
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:tools=
"http://schemas.android.com/tools"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
tools:context=
"jp.agentec.abook.abv.ui.home.activity.PairingSettingActivity"
>
<!--android:background="@drawable/setting_bg"-->
<!--android:layout_height="0dp"-->
<!--android:background="@drawable/setting_bg"-->
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:orientation=
"vertical"
>
<RelativeLayout
android:id=
"@+id/toolbar_layout"
style=
"@style/OperationSearchToolBar"
android:layout_width=
"match_parent"
android:layout_height=
"50dp"
>
<TextView
android:id=
"@+id/tv_toolbar_title"
style=
"@style/DialogToolBarTitle"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_centerHorizontal=
"true"
android:layout_centerVertical=
"true"
android:text=
"@string/set_pairing"
android:textColor=
"@color/edt_text"
android:textSize=
"@dimen/opeartion_title_text_size"
/>
<ImageButton
android:id=
"@+id/close_btn"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_alignParentLeft=
"true"
android:layout_centerVertical=
"true"
android:background=
"@drawable/ic_operation_close"
android:onClick=
"onClickCloseView"
/>
</RelativeLayout>
<LinearLayout
android:layout_width=
"fill_parent"
android:layout_height=
"match_parent"
android:layout_marginBottom=
"8dp"
android:layout_marginLeft=
"8dp"
android:layout_marginRight=
"8dp"
android:layout_weight=
"1"
android:orientation=
"vertical"
>
<RelativeLayout
android:id=
"@+id/toolbar2"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:minHeight=
"50dp"
android:visibility=
"visible"
>
<TextView
android:layout_width=
"fill_parent"
android:layout_height=
"wrap_content"
android:layout_margin=
"8dp"
android:gravity=
"left"
android:text=
"@string/thermometer"
android:textSize=
"20sp"
/>
<LinearLayout
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_alignParentEnd=
"true"
android:layout_alignParentRight=
"true"
android:layout_centerVertical=
"true"
>
<Button
android:id=
"@+id/scan_button"
android:layout_width=
"50dp"
android:layout_height=
"50dp"
android:layout_alignParentLeft=
"true"
android:layout_centerVertical=
"true"
android:layout_marginRight=
"5dp"
android:text=
"@string/scan"
/>
<Button
android:id=
"@+id/stop_button"
android:layout_width=
"50dp"
android:layout_height=
"50dp"
android:layout_alignParentLeft=
"true"
android:layout_centerVertical=
"true"
android:layout_marginRight=
"5dp"
android:text=
"@string/stop"
/>
</LinearLayout>
</RelativeLayout>
<View
android:layout_width=
"fill_parent"
android:layout_height=
"2dp"
android:layout_marginLeft=
"8dp"
android:layout_marginRight=
"8dp"
/>
<ListView
android:id=
"@+id/devicelist"
android:layout_width=
"fill_parent"
android:layout_height=
"0dp"
android:layout_margin=
"8dp"
android:layout_weight=
"1"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
ABVJE_UI_Android/res/xml/pref.xml
View file @
a01ca2f5
...
@@ -58,4 +58,10 @@
...
@@ -58,4 +58,10 @@
android:title=
"@string/operation_manual"
>
android:title=
"@string/operation_manual"
>
</PreferenceScreen>
</PreferenceScreen>
</PreferenceCategory>
</PreferenceCategory>
<PreferenceCategory
android:title=
"@string/set_pairing"
android:key=
"set_pairing"
>
<PreferenceScreen
android:key=
"setPairing"
android:title=
"@string/set_pairing"
>
</PreferenceScreen>
</PreferenceCategory>
</PreferenceScreen>
</PreferenceScreen>
\ No newline at end of file
ABVJE_UI_Android/src/jp/agentec/abook/abv/cl/util/BleManagerUtil.java
0 → 100644
View file @
a01ca2f5
package
jp
.
agentec
.
abook
.
abv
.
cl
.
util
;
import
java.nio.ByteBuffer
;
import
java.nio.ByteOrder
;
import
java.util.List
;
import
java.util.UUID
;
import
jp.agentec.abook.abv.bl.common.log.Logger
;
import
jp.agentec.abook.abv.launcher.android.R
;
import
android.bluetooth.BluetoothAdapter
;
import
android.bluetooth.BluetoothDevice
;
import
android.bluetooth.BluetoothGatt
;
import
android.bluetooth.BluetoothGattCallback
;
import
android.bluetooth.BluetoothGattCharacteristic
;
import
android.bluetooth.BluetoothGattDescriptor
;
import
android.bluetooth.BluetoothGattService
;
import
android.bluetooth.BluetoothManager
;
import
android.bluetooth.BluetoothProfile
;
import
android.content.Context
;
import
android.widget.Toast
;
import
static
org
.
chromium
.
base
.
ThreadUtils
.
runOnUiThread
;
public
class
BleManagerUtil
{
private
final
String
TAG
=
"BleManagerUtil"
;
private
BluetoothManager
bluetoothManager
;
private
Context
context
;
private
BleManagerUtilListener
listener
;
// 定数(Bluetooth LE Gatt UUID)
// Private Service
private
static
final
UUID
UUID_SERVICE_PRIVATE
=
UUID
.
fromString
(
"05fd8c58-9d23-11e7-abc4-cec278b6b50a"
);
private
static
final
UUID
UUID_CHARACTERISTIC_PRIVATE1
=
UUID
.
fromString
(
"05fd8f5a-9d23-11e7-abc4-cec278b6b50a"
);
private
static
final
UUID
UUID_CHARACTERISTIC_PRIVATE2
=
UUID
.
fromString
(
"05fd8f5a-9d23-11e7-abc4-cec278b6b50a"
);
// for Notification
private
static
final
UUID
UUID_NOTIFY
=
UUID
.
fromString
(
"05fd8f5a-9d23-11e7-abc4-cec278b6b50a"
);
private
static
final
UUID
UUID_NOTIRY_DESCRIPTOR
=
UUID
.
fromString
(
"00002902-0000-1000-8000-00805f9b34fb"
);
// battery
private
static
final
UUID
UUID_BATTERY_LEVEL
=
UUID
.
fromString
(
"00002A19-0000-1000-8000-00805f9b34fb"
);
// メンバー変数
public
BluetoothAdapter
mBluetoothAdapter
;
// BluetoothAdapter : Bluetooth処理で必要
public
String
mDeviceAddress
=
""
;
// デバイスアドレス
public
String
mDeviceName
=
""
;
// ディバイス名
public
BluetoothGatt
mBluetoothGatt
=
null
;
// Gattサービスの検索、キャラスタリスティックの読み書き
// BluetoothGattコールバック
private
final
BluetoothGattCallback
mGattcallback
=
new
BluetoothGattCallback
()
{
// 接続状態変更(connectGatt()の結果として呼ばれる。)
@Override
public
void
onConnectionStateChange
(
BluetoothGatt
gatt
,
int
status
,
int
newState
)
{
// if( BluetoothGatt.GATT_SUCCESS != status ) {
// runOnUiThread( new Runnable() {
// public void run() {
// listener.onGetDeviceInfoFailed();
// }
// });
// return;
// }
if
(
status
==
BluetoothGatt
.
GATT_SUCCESS
&&
BluetoothProfile
.
STATE_CONNECTED
==
newState
)
{
// 接続完了
if
(!
mBluetoothGatt
.
discoverServices
())
{
// サービス検索
runOnUiThread
(
new
Runnable
()
{
// 接続失敗
public
void
run
()
{
listener
.
onGetDeviceInfoFailed
();
}
});
}
runOnUiThread
(
new
Runnable
()
{
public
void
run
()
{
// 接続成功
listener
.
onConnectionState
();
}
}
);
return
;
}
if
(
BluetoothProfile
.
STATE_DISCONNECTED
==
newState
)
{
// 切断完了(接続可能範囲から外れて切断された)
// 接続可能範囲に入ったら自動接続するために、mBluetoothGatt.connect()を呼び出す。
mBluetoothGatt
.
connect
();
runOnUiThread
(
new
Runnable
()
{
public
void
run
()
{
// 切断トーストメッセージを表示する。
listener
.
onDisConnectionState
();
}
}
);
return
;
}
super
.
onConnectionStateChange
(
gatt
,
status
,
newState
);
}
// サービス検索が完了したときの処理(mBluetoothGatt.discoverServices()の結果として呼ばれる。)
@Override
public
void
onServicesDiscovered
(
BluetoothGatt
gatt
,
int
status
)
{
if
(
BluetoothGatt
.
GATT_SUCCESS
!=
status
)
{
return
;
}
// 発見されたサービスのループ
for
(
BluetoothGattService
service
:
gatt
.
getServices
()
)
{
// サービスごとに個別の処理
if
(
(
null
==
service
)
||
(
null
==
service
.
getUuid
()
)
)
{
continue
;
}
// GATTサービスのキャラクタリスティックを列挙
List
<
BluetoothGattCharacteristic
>
listCharacteristic
=
service
.
getCharacteristics
();
for
(
BluetoothGattCharacteristic
characteristic
:
listCharacteristic
)
{
// 利用したいものがあるはず!
Logger
.
d
(
TAG
,
"characteristic : [ "
+
characteristic
);
}
// プライベートサービス
if
(
UUID_SERVICE_PRIVATE
.
equals
(
service
.
getUuid
()
)
)
{
// 最初の読み取り
readCharacteristic
(
UUID_SERVICE_PRIVATE
,
UUID_CHARACTERISTIC_PRIVATE1
);
runOnUiThread
(
new
Runnable
()
{
public
void
run
()
{
// 渡すデータがある場合
}
});
continue
;
}
}
}
// キャラクタリスティックが読み込まれたときの処理
@Override
public
void
onCharacteristicRead
(
BluetoothGatt
gatt
,
BluetoothGattCharacteristic
characteristic
,
int
status
)
{
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
);
}
});
// 通知設定
setCharacteristicNotification
(
UUID_SERVICE_PRIVATE
,
UUID_NOTIFY
,
true
);
return
;
}
if
(
UUID_CHARACTERISTIC_PRIVATE2
.
equals
(
characteristic
.
getUuid
()
)
)
{
// キャラクタリスティック2:データサイズは、8バイト(文字列を想定。半角文字8文字)
final
String
strChara
=
characteristic
.
getStringValue
(
0
);
runOnUiThread
(
new
Runnable
()
{
public
void
run
()
{
// 渡すデータがある場合
}
});
return
;
}
}
// キャラクタリスティック変更が通知されたときの処理
@Override
public
void
onCharacteristicChanged
(
BluetoothGatt
gatt
,
BluetoothGattCharacteristic
characteristic
)
{
if
(
UUID_NOTIFY
.
equals
(
characteristic
.
getUuid
()
)
)
{
final
String
strTemperature
=
byteToString
(
characteristic
.
getValue
());
runOnUiThread
(
new
Runnable
()
{
public
void
run
()
{
// 芯温計の温度を渡す。
listener
.
onGetDeviceInfo
(
strTemperature
);
}
});
return
;
}
}
};
public
BleManagerUtil
(
Context
context
,
BleManagerUtilListener
listener
)
{
this
.
context
=
context
;
this
.
listener
=
listener
;
}
/**
* ディバイス情報の取得を開始します<br>
* 成功時にlistenerのonGetDeviceInfo、失敗時にlistenerのonGetDeviceInfoFailedが呼び出されます。
*
*/
public
interface
BleManagerUtilListener
{
void
onGetDeviceInfo
(
String
strTemperature
);
// ディバイスから渡す情報
void
onGetDeviceInfoFailed
();
// ディバイスと接続失敗時の情報渡す。
void
onConnectionState
();
// ディバイスと接続された時情報渡す。
void
onDisConnectionState
();
// ディバイスと切断時
}
// 接続
public
void
connect
()
{
if
(
mDeviceAddress
.
equals
(
""
)
)
{
// DeviceAddressが空の場合は処理しない
return
;
}
if
(
null
!=
mBluetoothGatt
)
{
// mBluetoothGattがnullでないなら接続済みか、接続中。
return
;
}
// mBluetoothGattのサービスと接続
BluetoothDevice
device
=
mBluetoothAdapter
.
getRemoteDevice
(
mDeviceAddress
);
mBluetoothGatt
=
device
.
connectGatt
(
context
,
false
,
mGattcallback
);
}
// 切断
public
void
disconnect
()
{
if
(
null
==
mBluetoothGatt
)
{
return
;
}
// 切断
// mBluetoothGatt.disconnect()ではなく、mBluetoothGatt.close()しオブジェクトを解放する。
// 理由:「ユーザーの意思による切断」と「接続範囲から外れた切断」を区別するため。
// ①「ユーザーの意思による切断」は、mBluetoothGattオブジェクトを解放する。再接続は、オブジェクト構築から。
// ②「接続可能範囲から外れた切断」は、内部処理でmBluetoothGatt.disconnect()処理が実施される。
// 切断時のコールバックでmBluetoothGatt.connect()を呼んでおくと、接続可能範囲に入ったら自動接続する。
mBluetoothGatt
.
close
();
mBluetoothGatt
=
null
;
runOnUiThread
(
new
Runnable
()
{
public
void
run
()
{
// 切断トーストメッセージを表示する。
listener
.
onDisConnectionState
();
}
}
);
}
// キャラクタリスティックの読み込み
private
void
readCharacteristic
(
UUID
uuid_service
,
UUID
uuid_characteristic
)
{
if
(
null
==
mBluetoothGatt
)
{
return
;
}
BluetoothGattCharacteristic
blechar
=
mBluetoothGatt
.
getService
(
uuid_service
).
getCharacteristic
(
uuid_characteristic
);
mBluetoothGatt
.
readCharacteristic
(
blechar
);
}
// キャラクタリスティック通知の設定
private
void
setCharacteristicNotification
(
UUID
uuid_service
,
UUID
uuid_characteristic
,
boolean
enable
)
{
if
(
null
==
mBluetoothGatt
)
{
return
;
}
BluetoothGattService
service
=
mBluetoothGatt
.
getService
(
uuid_service
);
if
(
service
==
null
)
{
return
;
}
BluetoothGattCharacteristic
blechar
=
service
.
getCharacteristic
(
uuid_characteristic
);
mBluetoothGatt
.
setCharacteristicNotification
(
blechar
,
enable
);
BluetoothGattDescriptor
descriptor
=
blechar
.
getDescriptor
(
UUID_NOTIRY_DESCRIPTOR
);
descriptor
.
setValue
(
BluetoothGattDescriptor
.
ENABLE_INDICATION_VALUE
);
mBluetoothGatt
.
writeDescriptor
(
descriptor
);
}
// Signed short (16-bit) Two's complement to short, String
public
String
byteToString
(
byte
[]
bytes
)
{
short
sht
=
ByteBuffer
.
wrap
(
bytes
).
order
(
ByteOrder
.
LITTLE_ENDIAN
).
getShort
();
float
flt
=
sht
/(
float
)
100
;
return
String
.
valueOf
(
flt
);
}
// Bluetoothアダプタの取得処理
public
void
startDeviceInfo
()
{
// disconnect();
// bluetoothManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE);
// // Android端末がBLEをサポートしてるかの確認
// if( !context.getPackageManager().hasSystemFeature( PackageManager.FEATURE_BLUETOOTH_LE ) ) {
// Toast.makeText( context, R.string.ble_is_not_supported, Toast.LENGTH_SHORT ).show();
// return;
// }
// Bluetoothアダプタの取得
BluetoothManager
bluetoothManager
=
(
BluetoothManager
)
context
.
getSystemService
(
Context
.
BLUETOOTH_SERVICE
);
mBluetoothAdapter
=
bluetoothManager
.
getAdapter
();
if
(
null
==
mBluetoothAdapter
)
{
// Android端末がBluetoothをサポートしていない
Toast
.
makeText
(
context
,
R
.
string
.
bluetooth_is_not_supported
,
Toast
.
LENGTH_SHORT
).
show
();
return
;
}
}
}
ABVJE_UI_Android/src/jp/agentec/abook/abv/ui/common/appinfo/AppDefType.java
View file @
a01ca2f5
...
@@ -56,6 +56,10 @@ public interface AppDefType {
...
@@ -56,6 +56,10 @@ public interface AppDefType {
String
OPERATION_REPORT_TYPES
=
"operationReportTypes"
;
String
OPERATION_REPORT_TYPES
=
"operationReportTypes"
;
String
RESOURCE_PATTERN_TYPE
=
"resourcePatternType"
;
// 文言リソースパターン
String
RESOURCE_PATTERN_TYPE
=
"resourcePatternType"
;
// 文言リソースパターン
String
BLUETOOTH_DEVICE_TEMPERATURE_NAME
=
"bleDeviceTemperatureName"
;
// 温度計機器の名
String
BLUETOOTH_DEVICE_TEMPERATURE_ADDRESS
=
"bleDeviceTemperatureAddress"
;
// 温度計機器のアドレス
String
BLUETOOTH_DEVICE_TEMPERATURE_CONNECTED
=
"bleDeviceTemperatureConnected"
;
// 芯温計機器と接続可否
}
}
/**
/**
...
...
ABVJE_UI_Android/src/jp/agentec/abook/abv/ui/home/activity/ABookSettingFragment.java
View file @
a01ca2f5
...
@@ -90,6 +90,9 @@ public class ABookSettingFragment extends PreferenceFragment {
...
@@ -90,6 +90,9 @@ public class ABookSettingFragment extends PreferenceFragment {
protected
AlertDialog
alertDialog
=
null
;
protected
AlertDialog
alertDialog
=
null
;
private
SharedPreferences
pref
;
private
SharedPreferences
pref
;
// 機器連携
private
static
final
String
SET_PAIRING
=
"setPairing"
;
@Override
@Override
public
void
onCreate
(
Bundle
savedInstanceState
)
{
public
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
super
.
onCreate
(
savedInstanceState
);
...
@@ -104,6 +107,9 @@ public class ABookSettingFragment extends PreferenceFragment {
...
@@ -104,6 +107,9 @@ public class ABookSettingFragment extends PreferenceFragment {
setLogInfoSetting
();
setLogInfoSetting
();
// アプリ情報
// アプリ情報
setAppInfoSetting
();
setAppInfoSetting
();
// ペアリング設定
setPairingSetting
();
}
}
@Override
@Override
...
@@ -461,4 +467,25 @@ public class ABookSettingFragment extends PreferenceFragment {
...
@@ -461,4 +467,25 @@ public class ABookSettingFragment extends PreferenceFragment {
Logger
.
d
(
TAG
,
"saveLeaveAppTime()"
);
Logger
.
d
(
TAG
,
"saveLeaveAppTime()"
);
PreferenceUtil
.
putUserPref
(
getActivity
(),
UserPrefKey
.
LEAVE_APP
,
System
.
currentTimeMillis
());
PreferenceUtil
.
putUserPref
(
getActivity
(),
UserPrefKey
.
LEAVE_APP
,
System
.
currentTimeMillis
());
}
}
// 機器連携のペアリング設定
private
void
setPairingSetting
()
{
PreferenceGroup
devicePairing
=
(
PreferenceGroup
)
findPreference
(
SET_PAIRING
);
devicePairing
.
setOnPreferenceClickListener
(
new
OnPreferenceClickListener
()
{
@Override
public
boolean
onPreferenceClick
(
Preference
preference
)
{
try
{
// ペアリング設定画面
Intent
intent
=
new
Intent
();
intent
.
setClass
(
getActivity
(),
PairingSettingActivity
.
class
);
intent
.
putExtra
(
"beforeView"
,
SET_PAIRING
);
startActivity
(
intent
);
}
catch
(
Exception
e
)
{
Logger
.
e
(
TAG
,
e
);
}
return
true
;
}
});
}
}
}
ABVJE_UI_Android/src/jp/agentec/abook/abv/ui/home/activity/PairingSettingActivity.java
0 → 100644
View file @
a01ca2f5
package
jp
.
agentec
.
abook
.
abv
.
ui
.
home
.
activity
;
import
android.app.Activity
;
import
android.bluetooth.BluetoothAdapter
;
import
android.bluetooth.BluetoothDevice
;
import
android.bluetooth.BluetoothManager
;
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.Bundle
;
import
android.os.Handler
;
import
android.view.LayoutInflater
;
import
android.view.Menu
;
import
android.view.MenuItem
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.AdapterView
;
import
android.widget.BaseAdapter
;
import
android.widget.Button
;
import
android.widget.ImageView
;
import
android.widget.ListView
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
org.json.JSONArray
;
import
org.json.adf.JSONObject
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
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.launcher.android.R
;
import
jp.agentec.abook.abv.ui.common.activity.ABVContentViewActivity
;
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
;
public
class
PairingSettingActivity
extends
ABVUIActivity
implements
AdapterView
.
OnItemClickListener
{
private
static
final
String
TAG
=
"PairingSettingActivity"
;
// 定数
private
static
final
int
REQUEST_ENABLEBLUETOOTH
=
1
;
// Bluetooth機能の有効化要求時の識別コード
private
static
final
long
SCAN_PERIOD
=
10000
;
// スキャン時間。単位はミリ秒。
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"
;
// ディバイスと接続可否
public
static
final
String
DEVICE_LIST
=
"DEVIVE_LIST"
;
// リストビュー
// メンバー変数
private
Handler
mHandler
;
// UIスレッド操作ハンドラ : 「一定時間後にスキャンをやめる処理」で必要
private
boolean
mScanning
=
false
;
// スキャン中かどうかのフラグ
private
Button
mButton_Scan
;
private
Button
mButton_Stop
;
private
String
mBeforeView
;
// 以前画面の情報
private
BleManagerUtil
bleManagerUtil
;
private
BleListAdapter
mBleListAdapter
;
// Adapter
private
int
selectedDeviceListPostion
;
// デバイススキャンコールバック
private
ScanCallback
mLeScanCallback
=
new
ScanCallback
()
{
// スキャンに成功(アドバタイジングは一定間隔で常に発行されているため、本関数は一定間隔で呼ばれ続ける)
@Override
public
void
onScanResult
(
int
callbackType
,
final
ScanResult
result
)
{
super
.
onScanResult
(
callbackType
,
result
);
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
BluetoothDevice
device
=
result
.
getDevice
();
// if(device.getName() != null && device.getName().startsWith("MF500B")) {
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
);
}
}
}
);
}
// スキャンに失敗
@Override
public
void
onScanFailed
(
int
errorCode
)
{
super
.
onScanFailed
(
errorCode
);
}
};
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
Logger
.
i
(
TAG
,
"onCreate"
);
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
pairing_setting
);
// 戻り値の初期化
setResult
(
Activity
.
RESULT_CANCELED
);
// 画像数の取得
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
()
{
// ビューアダプターの初期化
// リストの要素であるボタンクリック処理
@Override
public
void
onConnect
(
int
position
)
{
selectedDeviceListPostion
=
position
;
deviceListClick
(
position
,
""
);
// bleManagerUtil.connect();
}
@Override
public
void
onDisconnect
(
int
position
)
{
selectedDeviceListPostion
=
position
;
bleManagerUtil
.
disconnect
();
// setUserPref("", "", 0); // ディバイスと切断された場合、保存されているディバスの情報を消す。
putUserPref
(
AppDefType
.
UserPrefKey
.
BLUETOOTH_DEVICE_TEMPERATURE_CONNECTED
,
0
);
// ディバイスと切断された場合、保存されているディバスの接続情報を更新。
}
});
ListView
listView
=
(
ListView
)
findViewById
(
R
.
id
.
devicelist
);
// リストビューの取得
listView
.
setAdapter
(
mBleListAdapter
);
// リストビューにビューアダプターをセット
listView
.
setOnItemClickListener
(
this
);
// クリックリスナーオブジェクトのセット
// Bluetoothと接続処理する
bleManagerUtil
=
new
BleManagerUtil
(
this
,
new
BleManagerUtil
.
BleManagerUtilListener
()
{
@Override
public
void
onConnectionState
()
{
// 接続
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
);
// ローカルにディバイスの情報を保存する。
}
@Override
public
void
onDisConnectionState
()
{
// 切断
// 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); // ディバイスと切断された場合、保存されているディバスの情報を消す。
}
@Override
public
void
onGetDeviceInfo
(
String
strTemp
)
{
// 機器のデータ
// Toast.makeText( getApplicationContext(), R.string.msg_connected_bluetooth, Toast.LENGTH_SHORT ).show();
Logger
.
d
(
TAG
,
"get temperature [%s]"
,
strTemp
);
}
@Override
public
void
onGetDeviceInfoFailed
()
{
// 機器のエラー
showConfirmAlert
(
R
.
string
.
thermometer
,
String
.
format
(
getString
(
R
.
string
.
msg_ble_connect_error
),
getString
(
R
.
string
.
thermometer
),
getString
(
R
.
string
.
thermometer
)));
}
});
bleManagerUtil
.
startDeviceInfo
();
// Scan Button
mButton_Scan
=
(
Button
)
findViewById
(
R
.
id
.
scan_button
);
mButton_Scan
.
setAllCaps
(
false
);
mButton_Scan
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
startScan
();
}
});
// Stop Button
mButton_Stop
=
(
Button
)
findViewById
(
R
.
id
.
stop_button
);
mButton_Stop
.
setAllCaps
(
false
);
mButton_Stop
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
stopScan
();
}
});
// 設定画面が表示する場合、スキャンボタンが見えないように
mButton_Stop
.
setVisibility
(
View
.
GONE
);
// 保存されているディバイスの情報がある場合、リストに表示する。
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
();
}
// 初回表示時、および、ポーズからの復帰時
@Override
protected
void
onResume
()
{
super
.
onResume
();
// デバイスのBluetooth機能の有効化要求
requestBluetoothFeature
();
// スキャン開始
startScan
();
}
// 別のアクティビティ(か別のアプリ)に移行したことで、バックグラウンドに追いやられた時
@Override
protected
void
onPause
()
{
super
.
onPause
();
// スキャンの停止
stopScan
();
}
@Override
protected
void
onDestroy
()
{
super
.
onDestroy
();
// Gattサービスがある場合、切断するためnullにする。
if
(
null
!=
bleManagerUtil
.
mBluetoothGatt
)
{
bleManagerUtil
.
mBluetoothGatt
.
close
();
bleManagerUtil
.
mBluetoothGatt
=
null
;
putUserPref
(
AppDefType
.
UserPrefKey
.
BLUETOOTH_DEVICE_TEMPERATURE_CONNECTED
,
0
);
}
}
// デバイスのBluetooth機能の有効化要求
private
void
requestBluetoothFeature
()
{
if
(
bleManagerUtil
.
mBluetoothAdapter
.
isEnabled
()
)
{
return
;
}
// デバイスのBluetooth機能が有効になっていないときは、有効化要求(ダイアログ表示)
Intent
enableBtIntent
=
new
Intent
(
BluetoothAdapter
.
ACTION_REQUEST_ENABLE
);
startActivityForResult
(
enableBtIntent
,
REQUEST_ENABLEBLUETOOTH
);
}
// 機能の有効化ダイアログの操作結果
@Override
protected
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
data
)
{
switch
(
requestCode
)
{
case
REQUEST_ENABLEBLUETOOTH:
// Bluetooth有効化要求
if
(
Activity
.
RESULT_CANCELED
==
resultCode
)
{
// 有効にされなかった
ABVToastUtil
.
showMakeText
(
getApplicationContext
(),
getString
(
R
.
string
.
bluetooth_is_not_working
),
Toast
.
LENGTH_SHORT
);
return
;
}
break
;
}
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
);
}
// スキャンの開始
private
void
startScan
()
{
// リストビューの内容を空にする。
// mBleListAdapter.clear();
// BluetoothLeScannerの取得
// ※Runnableオブジェクト内でも使用できるようfinalオブジェクトとする。
final
android
.
bluetooth
.
le
.
BluetoothLeScanner
scanner
=
bleManagerUtil
.
mBluetoothAdapter
.
getBluetoothLeScanner
();
if
(
null
==
scanner
)
{
return
;
}
// スキャン開始(一定時間後にスキャン停止する)
mHandler
.
postDelayed
(
new
Runnable
()
{
@Override
public
void
run
()
{
mScanning
=
false
;
scanner
.
stopScan
(
mLeScanCallback
);
// ボタンの更新
mButton_Scan
.
setVisibility
(
View
.
VISIBLE
);
mButton_Stop
.
setVisibility
(
View
.
GONE
);
Logger
.
d
(
TAG
,
"scan in 10 sec"
);
}
},
SCAN_PERIOD
);
mScanning
=
true
;
scanner
.
startScan
(
mLeScanCallback
);
// ボタンの更新
mButton_Scan
.
setVisibility
(
View
.
GONE
);
mButton_Stop
.
setVisibility
(
View
.
VISIBLE
);
Logger
.
d
(
TAG
,
"start scan !!"
);
}
// スキャンの停止
private
void
stopScan
()
{
// 一定期間後にスキャン停止するためのHandlerのRunnableの削除
mHandler
.
removeCallbacksAndMessages
(
null
);
// BluetoothLeScannerの取得
android
.
bluetooth
.
le
.
BluetoothLeScanner
scanner
=
bleManagerUtil
.
mBluetoothAdapter
.
getBluetoothLeScanner
();
if
(
null
==
scanner
)
{
return
;
}
mScanning
=
false
;
scanner
.
stopScan
(
mLeScanCallback
);
// ボタンの更新
mButton_Scan
.
setVisibility
(
View
.
VISIBLE
);
mButton_Stop
.
setVisibility
(
View
.
GONE
);
Logger
.
d
(
TAG
,
"stop scan !!"
);
}
// リストビューのアイテムクリック時の処理
@Override
public
void
onItemClick
(
AdapterView
<?>
parent
,
View
view
,
int
position
,
long
id
)
{
deviceListClick
(
position
,
DEVICE_LIST
);
}
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
)
{
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
(
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
;
bleManagerUtil
.
connect
();
}
}
// 閉じるボタンの処理
public
void
onClickCloseView
(
View
v
)
{
finish
();
}
// 機器連携の情報をローカルに保存する。
public
void
setUserPref
(
String
deviceName
,
String
deviceAddress
,
int
deviceConnected
)
{
putUserPref
(
AppDefType
.
UserPrefKey
.
BLUETOOTH_DEVICE_TEMPERATURE_NAME
,
deviceName
);
putUserPref
(
AppDefType
.
UserPrefKey
.
BLUETOOTH_DEVICE_TEMPERATURE_ADDRESS
,
deviceAddress
);
putUserPref
(
AppDefType
.
UserPrefKey
.
BLUETOOTH_DEVICE_TEMPERATURE_CONNECTED
,
deviceConnected
);
}
// アラート表示処理
private
void
showConfirmAlert
(
final
int
dialogTitle
,
String
dialogMessage
)
{
ABookAlertDialog
alert
=
AlertDialogUtil
.
createAlertDialog
(
this
,
dialogTitle
);
alert
.
setMessage
(
dialogMessage
);
alert
.
setButton
(
DialogInterface
.
BUTTON_POSITIVE
,
getResources
().
getString
(
R
.
string
.
confirm
),
(
DialogInterface
.
OnClickListener
)
null
);
showAlertDialog
(
alert
);
}
}
ABVJE_UI_Android/src/jp/agentec/abook/abv/ui/home/adapter/BleListAdapter.java
0 → 100644
View file @
a01ca2f5
package
jp
.
agentec
.
abook
.
abv
.
ui
.
home
.
adapter
;
import
android.content.Context
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.BaseAdapter
;
import
android.widget.ImageView
;
import
android.widget.TextView
;
import
java.util.List
;
import
java.util.Map
;
import
jp.agentec.abook.abv.launcher.android.R
;
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
;
import
static
jp
.
agentec
.
abook
.
abv
.
ui
.
home
.
activity
.
PairingSettingActivity
.
EXTRAS_DEVICE_NAME
;
import
static
org
.
chromium
.
base
.
ThreadUtils
.
runOnUiThread
;
/**
* Created by kim, changgyun on 2018/11/15.
*/
public
class
BleListAdapter
extends
BaseAdapter
{
private
static
final
String
TAG
=
"BleListAdapter"
;
protected
BleListAdapter
.
BleListAdapterListener
listener
;
private
Context
mContext
;
private
LayoutInflater
mInflater
;
private
List
<
Map
<
String
,
String
>>
mListItem
;
private
String
savedDeviceAddress
=
""
;
// 保存されているディバイスのアドレス
private
String
savedDeviceName
=
""
;
// 保存されているディバイスの名
private
boolean
savedDeviceConnected
=
false
;
// 保存されているディバスの接続可否
public
interface
BleListAdapterListener
{
// 接続
void
onConnect
(
int
postion
);
// 切断
void
onDisconnect
(
int
position
);
}
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
);
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の更新
}
@Override
public
View
getView
(
final
int
position
,
View
convertView
,
ViewGroup
parent
)
{
final
ViewHolder
holder
;
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
.
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
);
}
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
);
}
}
else
{
holder
.
isConnect
.
setVisibility
(
convertView
.
VISIBLE
);
holder
.
isDisConnect
.
setVisibility
(
convertView
.
GONE
);
}
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
;
// ディバイスのアドレス
ImageView
isConnect
;
// ディバイスとの接続ボタン
ImageView
isDisConnect
;
// ディバイスとの切断ボタン
}
public
void
setAdapterListener
(
BleListAdapterListener
listener
)
{
this
.
listener
=
listener
;
}
}
ABVJE_UI_Android/src/jp/agentec/abook/abv/ui/home/helper/ABookPermissionHelper.java
View file @
a01ca2f5
package
jp
.
agentec
.
abook
.
abv
.
ui
.
home
.
helper
;
package
jp
.
agentec
.
abook
.
abv
.
ui
.
home
.
helper
;
import
android.Manifest
;
import
android.app.Activity
;
import
android.app.Activity
;
import
android.app.AlertDialog
;
import
android.app.AlertDialog
;
import
android.content.DialogInterface
;
import
android.content.DialogInterface
;
...
@@ -82,6 +83,11 @@ public class ABookPermissionHelper {
...
@@ -82,6 +83,11 @@ public class ABookPermissionHelper {
android
.
Manifest
.
permission
.
RECORD_AUDIO
)
!=
PackageManager
.
PERMISSION_GRANTED
)
{
android
.
Manifest
.
permission
.
RECORD_AUDIO
)
!=
PackageManager
.
PERMISSION_GRANTED
)
{
reqPermissions
.
add
(
android
.
Manifest
.
permission
.
RECORD_AUDIO
);
reqPermissions
.
add
(
android
.
Manifest
.
permission
.
RECORD_AUDIO
);
}
}
// Bluetooth
if
(
ContextCompat
.
checkSelfPermission
(
mActivity
,
android
.
Manifest
.
permission
.
BLUETOOTH
)
!=
PackageManager
.
PERMISSION_GRANTED
)
{
reqPermissions
.
add
(
android
.
Manifest
.
permission
.
BLUETOOTH
);
}
return
reqPermissions
;
return
reqPermissions
;
}
}
...
@@ -149,6 +155,17 @@ public class ABookPermissionHelper {
...
@@ -149,6 +155,17 @@ public class ABookPermissionHelper {
getUserPref
(
getApplicationContext
(),
AppDefType
.
UserPrefKey
.
RESOURCE_PATTERN_TYPE
,
0
));
getUserPref
(
getApplicationContext
(),
AppDefType
.
UserPrefKey
.
RESOURCE_PATTERN_TYPE
,
0
));
}
}
break
;
break
;
// Confirm Device Bluetooth
case
Constant
.
ABookPermissionType
.
Bluetooth
:
if
(
ContextCompat
.
checkSelfPermission
(
mActivity
,
Manifest
.
permission
.
BLUETOOTH
)
!=
PERMISSION_GRANTED
)
{
// リソースパターンの適用
permitionTextResourceId
=
PatternStringUtil
.
patternToInt
(
getApplicationContext
(),
R
.
string
.
msg_permission_dialog_bluetooth
,
getUserPref
(
getApplicationContext
(),
AppDefType
.
UserPrefKey
.
RESOURCE_PATTERN_TYPE
,
0
));
}
break
;
}
}
if
(
permitionTextResourceId
>
0
)
{
if
(
permitionTextResourceId
>
0
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment