From 818ac1855fe674ea316af51b408f660d90b42c1d Mon Sep 17 00:00:00 2001 From: theodore_hu <1206842201@qq.com> Date: Tue, 7 May 2019 16:59:27 +0800 Subject: [PATCH] add new sdk demo --- .gitignore | 11 + .idea/gradle.xml | 18 ++ .idea/inspectionProfiles/Project_Default.xml | 36 +++ .idea/misc.xml | 38 +++ .idea/runConfigurations.xml | 12 + .idea/vcs.xml | 6 + README.en.md | 39 +++ README.md | 41 +++ app/.gitignore | 2 + app/build.gradle | 44 +++ app/proguard-rules.pro | 21 ++ .../ExampleInstrumentedTest.java | 26 ++ app/src/main/AndroidManifest.xml | 61 +++++ .../main/java/ttlock/demo/AuthActivity.java | 70 +++++ .../main/java/ttlock/demo/BaseActivity.java | 72 +++++ .../main/java/ttlock/demo/IndexActivity.java | 25 ++ .../main/java/ttlock/demo/MainActivity.java | 34 +++ .../main/java/ttlock/demo/MyApplication.java | 41 +++ .../demo/fingerprint/FingerprintActivity.java | 192 ++++++++++++++ .../FingerprintModifyActivity.java | 121 +++++++++ .../demo/fingerprint/FinggerprintAdapter.java | 85 ++++++ .../MyFingerprintListActivity.java | 86 ++++++ .../fingerprint/model/FingerpintListObj.java | 16 ++ .../fingerprint/model/FingerprintObj.java | 46 ++++ .../FirmwareUpdateActivity.java | 197 ++++++++++++++ .../demo/firmwareupdate/LockUpgradeObj.java | 76 ++++++ .../ttlock/demo/gateway/GatewayActivity.java | 119 +++++++++ .../demo/gateway/GatewayDfuActivity.java | 134 ++++++++++ .../demo/gateway/InitGatewayActivity.java | 103 +++++++ .../demo/gateway/UserGatewayActivity.java | 78 ++++++ .../gateway/adapter/GatewayListAdapter.java | 200 ++++++++++++++ .../adapter/UserGatewayListAdapter.java | 77 ++++++ .../demo/gateway/model/GatewayUpgradeObj.java | 81 ++++++ .../ttlock/demo/iccard/ICCardActivity.java | 186 +++++++++++++ .../ttlock/demo/iccard/ICCardListAdapter.java | 84 ++++++ .../demo/iccard/ICCardModifyActivity.java | 148 +++++++++++ .../demo/iccard/MyICCardListActivity.java | 85 ++++++ .../demo/iccard/model/ICCardListObj.java | 16 ++ .../ttlock/demo/iccard/model/ICCardObj.java | 46 ++++ .../EnableDisableSomeLockFuncionActivity.java | 165 ++++++++++++ .../ttlock/demo/lock/LockApiActivity.java | 251 ++++++++++++++++++ .../ttlock/demo/lock/LockTimeActivity.java | 94 +++++++ .../ttlock/demo/lock/PassageModeActivity.java | 128 +++++++++ .../ttlock/demo/lock/ScanLockActivity.java | 216 +++++++++++++++ .../java/ttlock/demo/lock/UnlockActivity.java | 137 ++++++++++ .../ttlock/demo/lock/UserLockActivity.java | 78 ++++++ .../demo/lock/adapter/LockListAdapter.java | 185 +++++++++++++ .../lock/adapter/UserLockListAdapter.java | 77 ++++++ .../ttlock/demo/lock/model/KeyListObj.java | 22 ++ .../java/ttlock/demo/lock/model/KeyObj.java | 131 +++++++++ .../demo/lock/model/LockInitResultObj.java | 19 ++ .../java/ttlock/demo/model/AccountInfo.java | 104 ++++++++ .../java/ttlock/demo/model/GatewayObj.java | 73 +++++ .../main/java/ttlock/demo/model/LockObj.java | 153 +++++++++++ .../ttlock/demo/model/LockVersionObj.java | 83 ++++++ .../java/ttlock/demo/model/ServerError.java | 41 +++ .../demo/passcode/AdminPasscodeActivity.java | 125 +++++++++ .../CreateCustomPasscodeActivity.java | 72 +++++ .../demo/passcode/ModifyPasscodeActivity.java | 115 ++++++++ .../demo/passcode/PasscodeActivity.java | 142 ++++++++++ .../ttlock/demo/retrofit/ApiRequtest.java | 49 ++++ .../ttlock/demo/retrofit/ApiResponse.java | 19 ++ .../java/ttlock/demo/retrofit/ApiResult.java | 105 ++++++++ .../java/ttlock/demo/retrofit/ApiService.java | 119 +++++++++ .../demo/retrofit/RetrofitAPIManager.java | 63 +++++ .../demo/retrofit/onRequestResponse.java | 9 + .../retrofit/onServerRequestCallBack.java | 9 + .../drawable-v24/ic_launcher_foreground.xml | 34 +++ app/src/main/res/drawable/btn_bg_normal.xml | 6 + app/src/main/res/drawable/btn_bg_pressed.xml | 7 + app/src/main/res/drawable/btn_bg_selector.xml | 5 + .../res/drawable/ic_launcher_background.xml | 170 ++++++++++++ app/src/main/res/drawable/ic_setting_more.png | Bin 0 -> 486 bytes .../res/layout/activity_admin_passcode.xml | 42 +++ app/src/main/res/layout/activity_auth.xml | 49 ++++ .../activity_create_custom_passcode.xml | 60 +++++ ...ivity_enable_disable_some_lock_funcion.xml | 90 +++++++ .../main/res/layout/activity_fingerprint.xml | 43 +++ .../layout/activity_fingerprint_modify.xml | 23 ++ .../res/layout/activity_firmware_update.xml | 47 ++++ app/src/main/res/layout/activity_gateway.xml | 35 +++ .../main/res/layout/activity_gateway_dfu.xml | 59 ++++ app/src/main/res/layout/activity_iccard.xml | 42 +++ .../res/layout/activity_iccard_modify.xml | 24 ++ app/src/main/res/layout/activity_index.xml | 22 ++ .../main/res/layout/activity_init_gateway.xml | 109 ++++++++ app/src/main/res/layout/activity_key.xml | 9 + app/src/main/res/layout/activity_lock_api.xml | 84 ++++++ .../main/res/layout/activity_lock_time.xml | 33 +++ app/src/main/res/layout/activity_main.xml | 47 ++++ .../res/layout/activity_modify_passcode.xml | 74 ++++++ .../layout/activity_my_fingerprint_list.xml | 21 ++ .../res/layout/activity_my_iccard_list.xml | 21 ++ .../main/res/layout/activity_passage_mode.xml | 40 +++ app/src/main/res/layout/activity_passcode.xml | 67 +++++ .../main/res/layout/activity_scan_lock.xml | 40 +++ app/src/main/res/layout/activity_unlock.xml | 51 ++++ .../main/res/layout/activity_user_gateway.xml | 22 ++ .../main/res/layout/activity_user_lock.xml | 23 ++ .../main/res/layout/attachment_list_item.xml | 13 + app/src/main/res/layout/choose_net_dialog.xml | 50 ++++ .../res/layout/gateway_scan_list_item.xml | 35 +++ app/src/main/res/layout/item_scan_wifi.xml | 40 +++ .../main/res/layout/lock_add_list_item.xml | 35 +++ .../res/layout/user_gateway_list_item.xml | 26 ++ .../main/res/layout/user_lock_list_item.xml | 26 ++ .../res/mipmap-anydpi-v26/ic_launcher.xml | 5 + .../mipmap-anydpi-v26/ic_launcher_round.xml | 5 + app/src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 2963 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 4905 bytes app/src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2060 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 2783 bytes app/src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4490 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 6895 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 6387 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 10413 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 9128 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 15132 bytes .../main/res/mipmap-xxxhdpi/icon_right.png | Bin 0 -> 909 bytes app/src/main/res/values-zh-rCN/strings.xml | 104 ++++++++ app/src/main/res/values/colors.xml | 10 + app/src/main/res/values/strings.xml | 103 +++++++ app/src/main/res/values/styles.xml | 18 ++ .../com/ttlocksdkdemo/ExampleUnitTest.java | 17 ++ build.gradle | 41 +++ gradle.properties | 16 ++ gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 54329 bytes gradle/wrapper/gradle-wrapper.properties | 5 + gradlew | 172 ++++++++++++ gradlew.bat | 84 ++++++ settings.gradle | 1 + 131 files changed, 7762 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/gradle.xml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/runConfigurations.xml create mode 100644 .idea/vcs.xml create mode 100644 README.en.md create mode 100644 README.md create mode 100644 app/.gitignore create mode 100644 app/build.gradle create mode 100644 app/proguard-rules.pro create mode 100644 app/src/androidTest/java/tool/pubhouse/com/ttlocksdkdemo/ExampleInstrumentedTest.java create mode 100644 app/src/main/AndroidManifest.xml create mode 100644 app/src/main/java/ttlock/demo/AuthActivity.java create mode 100644 app/src/main/java/ttlock/demo/BaseActivity.java create mode 100644 app/src/main/java/ttlock/demo/IndexActivity.java create mode 100644 app/src/main/java/ttlock/demo/MainActivity.java create mode 100644 app/src/main/java/ttlock/demo/MyApplication.java create mode 100644 app/src/main/java/ttlock/demo/fingerprint/FingerprintActivity.java create mode 100644 app/src/main/java/ttlock/demo/fingerprint/FingerprintModifyActivity.java create mode 100644 app/src/main/java/ttlock/demo/fingerprint/FinggerprintAdapter.java create mode 100644 app/src/main/java/ttlock/demo/fingerprint/MyFingerprintListActivity.java create mode 100644 app/src/main/java/ttlock/demo/fingerprint/model/FingerpintListObj.java create mode 100644 app/src/main/java/ttlock/demo/fingerprint/model/FingerprintObj.java create mode 100644 app/src/main/java/ttlock/demo/firmwareupdate/FirmwareUpdateActivity.java create mode 100644 app/src/main/java/ttlock/demo/firmwareupdate/LockUpgradeObj.java create mode 100644 app/src/main/java/ttlock/demo/gateway/GatewayActivity.java create mode 100644 app/src/main/java/ttlock/demo/gateway/GatewayDfuActivity.java create mode 100644 app/src/main/java/ttlock/demo/gateway/InitGatewayActivity.java create mode 100644 app/src/main/java/ttlock/demo/gateway/UserGatewayActivity.java create mode 100644 app/src/main/java/ttlock/demo/gateway/adapter/GatewayListAdapter.java create mode 100644 app/src/main/java/ttlock/demo/gateway/adapter/UserGatewayListAdapter.java create mode 100644 app/src/main/java/ttlock/demo/gateway/model/GatewayUpgradeObj.java create mode 100644 app/src/main/java/ttlock/demo/iccard/ICCardActivity.java create mode 100644 app/src/main/java/ttlock/demo/iccard/ICCardListAdapter.java create mode 100644 app/src/main/java/ttlock/demo/iccard/ICCardModifyActivity.java create mode 100644 app/src/main/java/ttlock/demo/iccard/MyICCardListActivity.java create mode 100644 app/src/main/java/ttlock/demo/iccard/model/ICCardListObj.java create mode 100644 app/src/main/java/ttlock/demo/iccard/model/ICCardObj.java create mode 100644 app/src/main/java/ttlock/demo/lock/EnableDisableSomeLockFuncionActivity.java create mode 100644 app/src/main/java/ttlock/demo/lock/LockApiActivity.java create mode 100644 app/src/main/java/ttlock/demo/lock/LockTimeActivity.java create mode 100644 app/src/main/java/ttlock/demo/lock/PassageModeActivity.java create mode 100644 app/src/main/java/ttlock/demo/lock/ScanLockActivity.java create mode 100644 app/src/main/java/ttlock/demo/lock/UnlockActivity.java create mode 100644 app/src/main/java/ttlock/demo/lock/UserLockActivity.java create mode 100644 app/src/main/java/ttlock/demo/lock/adapter/LockListAdapter.java create mode 100644 app/src/main/java/ttlock/demo/lock/adapter/UserLockListAdapter.java create mode 100644 app/src/main/java/ttlock/demo/lock/model/KeyListObj.java create mode 100644 app/src/main/java/ttlock/demo/lock/model/KeyObj.java create mode 100644 app/src/main/java/ttlock/demo/lock/model/LockInitResultObj.java create mode 100644 app/src/main/java/ttlock/demo/model/AccountInfo.java create mode 100644 app/src/main/java/ttlock/demo/model/GatewayObj.java create mode 100644 app/src/main/java/ttlock/demo/model/LockObj.java create mode 100644 app/src/main/java/ttlock/demo/model/LockVersionObj.java create mode 100644 app/src/main/java/ttlock/demo/model/ServerError.java create mode 100644 app/src/main/java/ttlock/demo/passcode/AdminPasscodeActivity.java create mode 100644 app/src/main/java/ttlock/demo/passcode/CreateCustomPasscodeActivity.java create mode 100644 app/src/main/java/ttlock/demo/passcode/ModifyPasscodeActivity.java create mode 100644 app/src/main/java/ttlock/demo/passcode/PasscodeActivity.java create mode 100644 app/src/main/java/ttlock/demo/retrofit/ApiRequtest.java create mode 100644 app/src/main/java/ttlock/demo/retrofit/ApiResponse.java create mode 100644 app/src/main/java/ttlock/demo/retrofit/ApiResult.java create mode 100644 app/src/main/java/ttlock/demo/retrofit/ApiService.java create mode 100644 app/src/main/java/ttlock/demo/retrofit/RetrofitAPIManager.java create mode 100644 app/src/main/java/ttlock/demo/retrofit/onRequestResponse.java create mode 100644 app/src/main/java/ttlock/demo/retrofit/onServerRequestCallBack.java create mode 100644 app/src/main/res/drawable-v24/ic_launcher_foreground.xml create mode 100644 app/src/main/res/drawable/btn_bg_normal.xml create mode 100644 app/src/main/res/drawable/btn_bg_pressed.xml create mode 100644 app/src/main/res/drawable/btn_bg_selector.xml create mode 100644 app/src/main/res/drawable/ic_launcher_background.xml create mode 100644 app/src/main/res/drawable/ic_setting_more.png create mode 100644 app/src/main/res/layout/activity_admin_passcode.xml create mode 100644 app/src/main/res/layout/activity_auth.xml create mode 100644 app/src/main/res/layout/activity_create_custom_passcode.xml create mode 100644 app/src/main/res/layout/activity_enable_disable_some_lock_funcion.xml create mode 100644 app/src/main/res/layout/activity_fingerprint.xml create mode 100644 app/src/main/res/layout/activity_fingerprint_modify.xml create mode 100644 app/src/main/res/layout/activity_firmware_update.xml create mode 100644 app/src/main/res/layout/activity_gateway.xml create mode 100644 app/src/main/res/layout/activity_gateway_dfu.xml create mode 100644 app/src/main/res/layout/activity_iccard.xml create mode 100644 app/src/main/res/layout/activity_iccard_modify.xml create mode 100644 app/src/main/res/layout/activity_index.xml create mode 100644 app/src/main/res/layout/activity_init_gateway.xml create mode 100644 app/src/main/res/layout/activity_key.xml create mode 100644 app/src/main/res/layout/activity_lock_api.xml create mode 100644 app/src/main/res/layout/activity_lock_time.xml create mode 100644 app/src/main/res/layout/activity_main.xml create mode 100644 app/src/main/res/layout/activity_modify_passcode.xml create mode 100644 app/src/main/res/layout/activity_my_fingerprint_list.xml create mode 100644 app/src/main/res/layout/activity_my_iccard_list.xml create mode 100644 app/src/main/res/layout/activity_passage_mode.xml create mode 100644 app/src/main/res/layout/activity_passcode.xml create mode 100644 app/src/main/res/layout/activity_scan_lock.xml create mode 100644 app/src/main/res/layout/activity_unlock.xml create mode 100644 app/src/main/res/layout/activity_user_gateway.xml create mode 100644 app/src/main/res/layout/activity_user_lock.xml create mode 100644 app/src/main/res/layout/attachment_list_item.xml create mode 100644 app/src/main/res/layout/choose_net_dialog.xml create mode 100644 app/src/main/res/layout/gateway_scan_list_item.xml create mode 100644 app/src/main/res/layout/item_scan_wifi.xml create mode 100644 app/src/main/res/layout/lock_add_list_item.xml create mode 100644 app/src/main/res/layout/user_gateway_list_item.xml create mode 100644 app/src/main/res/layout/user_lock_list_item.xml create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/icon_right.png create mode 100644 app/src/main/res/values-zh-rCN/strings.xml create mode 100644 app/src/main/res/values/colors.xml create mode 100644 app/src/main/res/values/strings.xml create mode 100644 app/src/main/res/values/styles.xml create mode 100644 app/src/test/java/tool/pubhouse/com/ttlocksdkdemo/ExampleUnitTest.java create mode 100644 build.gradle create mode 100644 gradle.properties create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100644 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fd45b12 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +*.iml +.gradle +/local.properties +/.idea/caches/build_file_checksums.ser +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..7ac24c7 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..6560a98 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,36 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..eb655f9 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.en.md b/README.en.md new file mode 100644 index 0000000..ac4813c --- /dev/null +++ b/README.en.md @@ -0,0 +1,39 @@ +# NewSDKAndroidDemo + +#### Description +New SDK Android Demo + +#### Software Architecture +Software architecture description +1.Lock Operate Api:TTLockClient +2.Lock firmware update Api:LockDfuClient +3.Gateway Api:GatewayClient + +#### IDE +Android Studio + +#### Minimum SDK Version +18 + +#### Installation +1. \ implementation 'com.tongtonglock:ttlock:3.0.0' +2. add permission in manifest + \
+ \
+ \ + \
+ \ + +3. before use sdk,make sure bluetooth is enabled. + +#### Instructions + +1. init sdk : \GatewayClient.getDefault().prepareBTService(getApplicationContext()); +2. use api:\TTLockClient.getDefault().startScanLock(new ScanLockCallback() { + @Override + public void onScanLockSuccess(ExtendedBluetoothDevice device) { + + } + }); +3. when Activity finished,you should close SDK service:\TTLockClient.getDefault().stopBTService(); + diff --git a/README.md b/README.md new file mode 100644 index 0000000..45a4edd --- /dev/null +++ b/README.md @@ -0,0 +1,41 @@ +# NewSDKAndroidDemo + +#### 介绍 +新版SDK Android端Demo +1.锁操作相关: TTLockClient +2.锁固件升级相关:LockDfuClient +3.网关操作相关:GatewayClient + +#### IDE +Android Studio + +#### Minimum SDK Version +18 + +## 使用说明 +### 引入SDK +\ implementation 'com.tongtonglock:ttlock:3.0.0' + +### manifest配置 +#### 添加Permission +\
+\
+\ +\
+\ + +### SDK初始化 +#### 1)确保蓝牙开启 +#### 2)SDK初始化 \GatewayClient.getDefault().prepareBTService(getApplicationContext()); + +#### 3)开始调用接口 比如扫描周围蓝牙智能锁: +\TTLockClient.getDefault().startScanLock(new ScanLockCallback() { + @Override + public void onScanLockSuccess(ExtendedBluetoothDevice device) { + + } + }); +### 重置SDK服务 +#### 3)退出页面之后记得关闭SDK服务 \TTLockClient.getDefault().stopBTService(); + + diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..a774788 --- /dev/null +++ b/app/.gitignore @@ -0,0 +1,2 @@ +/build + diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..4e8cab9 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,44 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 27 + defaultConfig { + applicationId "ttlock.demo" + minSdkVersion 23 + targetSdkVersion 27 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + buildConfigField "String", "API_URL", '"http://120.26.119.23:8085"' + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + + dataBinding { + enabled true + } + + compileOptions { + targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_1_8 + } +} + +dependencies { + implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion" + implementation "com.android.support:recyclerview-v7:$rootProject.supportLibraryVersion" + implementation "com.android.support:design:$rootProject.supportLibraryVersion" + implementation 'com.android.support.constraint:constraint-layout:1.1.3' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'com.android.support.test:runner:1.0.2' + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + implementation 'com.google.code.gson:gson:2.6.2' + implementation 'com.tongtonglock:ttlock:3.0.0' + implementation 'com.squareup.retrofit2:retrofit:2.4.0' + implementation 'com.squareup.retrofit2:converter-gson:2.4.0' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/src/androidTest/java/tool/pubhouse/com/ttlocksdkdemo/ExampleInstrumentedTest.java b/app/src/androidTest/java/tool/pubhouse/com/ttlocksdkdemo/ExampleInstrumentedTest.java new file mode 100644 index 0000000..27cc584 --- /dev/null +++ b/app/src/androidTest/java/tool/pubhouse/com/ttlocksdkdemo/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package tool.pubhouse.com.ttlocksdkdemo; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("tool.pubhouse.com.ttlocksdkdemo", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..4afd41d --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/ttlock/demo/AuthActivity.java b/app/src/main/java/ttlock/demo/AuthActivity.java new file mode 100644 index 0000000..28a497b --- /dev/null +++ b/app/src/main/java/ttlock/demo/AuthActivity.java @@ -0,0 +1,70 @@ +package ttlock.demo; + +import android.databinding.DataBindingUtil; +import android.os.Bundle; +import android.view.View; + +import com.ttlock.bl.sdk.util.DigitUtil; +import com.ttlock.bl.sdk.util.GsonUtil; + +import retrofit2.Call; +import retrofit2.Callback; +import ttlock.demo.databinding.ActivityAuthBinding; +import ttlock.demo.model.AccountInfo; +import ttlock.demo.retrofit.ApiService; +import ttlock.demo.retrofit.RetrofitAPIManager; + +public class AuthActivity extends BaseActivity { + + ActivityAuthBinding binding; + public AccountInfo accountInfo; + private String password; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + binding = DataBindingUtil.setContentView(this, R.layout.activity_auth); + initListener(); + } + + private void initListener() { + binding.btnAuth.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + auth(); + } + }); + } + + private void auth() { + ApiService apiService = RetrofitAPIManager.provideClientApi(); + String account = binding.etAccount.getText().toString().trim(); + password = binding.etPassword.getText().toString().trim(); + password = DigitUtil.getMD5(password); + Call call = apiService.auth(ApiService.CLIENT_ID, ApiService.CLIENT_SECRET, "password", account, password, ApiService.REDIRECT_URI); + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, retrofit2.Response response) { + String json = response.body(); + accountInfo = GsonUtil.toObject(json, AccountInfo.class); + if (accountInfo != null) { + if (accountInfo.errcode == 0) { + accountInfo.setMd5Pwd(password); + MyApplication.getmInstance().setAccountInfo(accountInfo); + makeToast(accountInfo.toString()); + startTargetActivity(IndexActivity.class); + } else { + makeToast(accountInfo.errmsg); + } + } else { + makeToast(response.message()); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + makeToast(t.getMessage()); + } + }); + } +} diff --git a/app/src/main/java/ttlock/demo/BaseActivity.java b/app/src/main/java/ttlock/demo/BaseActivity.java new file mode 100644 index 0000000..3616593 --- /dev/null +++ b/app/src/main/java/ttlock/demo/BaseActivity.java @@ -0,0 +1,72 @@ +package ttlock.demo; + +import android.content.Intent; +import android.content.pm.ActivityInfo; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.widget.Toast; + +import com.ttlock.bl.sdk.api.TTLockClient; +import com.ttlock.bl.sdk.entity.LockError; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; + +import ttlock.demo.model.LockObj; + +/** + * Created on 2019/4/12 0012 10:52 + * + * @author theodre + */ +public class BaseActivity extends AppCompatActivity { + + public final static String LOCK_OBJ = "lock_obj_data"; + public LockObj mCurrentLock; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + mCurrentLock = MyApplication.getmInstance().getChoosedLock(); + } + + + + @Override + public void setContentView(int layoutResID) { + super.setContentView(layoutResID); + } + + public void startTargetActivity(Class targetClass) { + Intent mIntent = new Intent(getApplicationContext(), targetClass); + startActivity(mIntent); + } + + public void makeToast(String content){ + Toast.makeText(this,content,Toast.LENGTH_LONG).show(); + } + + public void makeErrorToast(LockError error){ + Toast.makeText(this,error.getDescription(),Toast.LENGTH_LONG).show(); + } + + + /** + * make sure Bluetooth is enabled. + */ + public void ensureBluetoothIsEnabled(){ + if(!TTLockClient.getDefault().isBLEEnabled(this)){ + TTLockClient.getDefault().requestBleEnable(this); + } + } + + public String getDateFormat(long timestamp) { + SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm", Locale.getDefault()); + return sDateFormat.format(new Date(timestamp)); + } + + public void showConnectLockToast(){ + makeToast("start connect lock..."); + } +} diff --git a/app/src/main/java/ttlock/demo/IndexActivity.java b/app/src/main/java/ttlock/demo/IndexActivity.java new file mode 100644 index 0000000..7eef0d2 --- /dev/null +++ b/app/src/main/java/ttlock/demo/IndexActivity.java @@ -0,0 +1,25 @@ +package ttlock.demo; + +import android.databinding.DataBindingUtil; +import android.os.Bundle; + +import ttlock.demo.databinding.ActivityIndexBinding; +import ttlock.demo.gateway.UserGatewayActivity; +import ttlock.demo.lock.UserLockActivity; + +public class IndexActivity extends BaseActivity { + + private ActivityIndexBinding binding; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + binding = DataBindingUtil.setContentView(this, R.layout.activity_index); + initListener(); + } + + private void initListener() { + binding.btnLock.setOnClickListener(v -> {startTargetActivity(UserLockActivity.class);}); + binding.btnGateway.setOnClickListener(v -> {startTargetActivity(UserGatewayActivity.class);}); + } +} diff --git a/app/src/main/java/ttlock/demo/MainActivity.java b/app/src/main/java/ttlock/demo/MainActivity.java new file mode 100644 index 0000000..54d6d1c --- /dev/null +++ b/app/src/main/java/ttlock/demo/MainActivity.java @@ -0,0 +1,34 @@ +package ttlock.demo; + +import android.databinding.DataBindingUtil; +import android.os.Bundle; + +import ttlock.demo.databinding.ActivityMainBinding; +import ttlock.demo.fingerprint.FingerprintActivity; +import ttlock.demo.firmwareupdate.FirmwareUpdateActivity; +import ttlock.demo.gateway.UserGatewayActivity; +import ttlock.demo.iccard.ICCardActivity; +import ttlock.demo.lock.LockApiActivity; +import ttlock.demo.passcode.PasscodeActivity; + +; + +public class MainActivity extends BaseActivity { + ActivityMainBinding binding; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + binding = DataBindingUtil.setContentView(this,R.layout.activity_main); + initListener(); + } + + private void initListener(){ + binding.btnLock.setOnClickListener(v -> startTargetActivity(LockApiActivity.class)); + binding.btnPasscode.setOnClickListener(v -> startTargetActivity(PasscodeActivity.class)); + binding.btnFirmware.setOnClickListener(v -> startTargetActivity(FirmwareUpdateActivity.class)); + binding.btnFingerprint.setOnClickListener(v -> startTargetActivity(FingerprintActivity.class)); + binding.btnIc.setOnClickListener(v -> startTargetActivity(ICCardActivity.class)); + binding.btnGateway.setOnClickListener(v -> startTargetActivity(UserGatewayActivity.class)); + } +} diff --git a/app/src/main/java/ttlock/demo/MyApplication.java b/app/src/main/java/ttlock/demo/MyApplication.java new file mode 100644 index 0000000..b3fcaa7 --- /dev/null +++ b/app/src/main/java/ttlock/demo/MyApplication.java @@ -0,0 +1,41 @@ +package ttlock.demo; + +import android.app.Application; + +import ttlock.demo.model.AccountInfo; +import ttlock.demo.model.LockObj; + +/** + * Created by TTLock on 2019/4/23. + */ + +public class MyApplication extends Application { + private static MyApplication mInstance; + private AccountInfo accountInfo; + private LockObj mTestLockObj; + @Override + public void onCreate() { + super.onCreate(); + mInstance = this; + } + + public static MyApplication getmInstance() { + return mInstance; + } + + public AccountInfo getAccountInfo() { + return accountInfo; + } + + public void setAccountInfo(AccountInfo accountInfo) { + this.accountInfo = accountInfo; + } + + public void saveChoosedLock(LockObj lockObj){ + this.mTestLockObj = lockObj; + } + + public LockObj getChoosedLock(){ + return this.mTestLockObj; + } +} diff --git a/app/src/main/java/ttlock/demo/fingerprint/FingerprintActivity.java b/app/src/main/java/ttlock/demo/fingerprint/FingerprintActivity.java new file mode 100644 index 0000000..6135f80 --- /dev/null +++ b/app/src/main/java/ttlock/demo/fingerprint/FingerprintActivity.java @@ -0,0 +1,192 @@ +package ttlock.demo.fingerprint; + +import android.databinding.DataBindingUtil; +import android.os.Bundle; + +import com.google.gson.reflect.TypeToken; +import com.ttlock.bl.sdk.api.TTLockClient; +import com.ttlock.bl.sdk.callback.AddFingerprintCallback; +import com.ttlock.bl.sdk.callback.ClearAllFingerprintCallback; +import com.ttlock.bl.sdk.callback.GetAllValidFingerprintCallback; +import com.ttlock.bl.sdk.entity.LockError; + +import java.util.HashMap; + +import okhttp3.ResponseBody; +import retrofit2.Call; +import ttlock.demo.BaseActivity; +import ttlock.demo.MyApplication; + +import ttlock.demo.R;; +import ttlock.demo.databinding.ActivityFingerprintBinding; +import ttlock.demo.retrofit.ApiService; +import ttlock.demo.retrofit.RetrofitAPIManager; + +public class FingerprintActivity extends BaseActivity { + ActivityFingerprintBinding binding; + private final static int ADD_PERMANENT = 1; + private final static int ADD_TIMED = 2; + private long theAddedFingerprintNum = 39912140898304L; + long addStartDate = 0; + long addEndDate = 0; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + binding = DataBindingUtil.setContentView(this,R.layout.activity_fingerprint); + TTLockClient.getDefault().prepareBTService(getApplicationContext()); + initListener(); + } + + private void initListener(){ + binding.btnAddPermanent.setOnClickListener(v -> addFingerprint(ADD_PERMANENT)); + binding.btnAddTimed.setOnClickListener(v -> addFingerprint(ADD_TIMED)); + binding.btnGetAll.setOnClickListener(v -> getAllFingerprints()); + binding.btnClear.setOnClickListener(v -> clearAllFingerprints()); + binding.btnMyList.setOnClickListener(v -> startTargetActivity(MyFingerprintListActivity.class)); + } + + /** + * startDate the card active date + * endDate the card expired date + *startDate and endDate set 0 means the fingerprint will be valid for ever. + * onEnterAddMode:the lock is ready to add a card. + * totalCount: lock collect your fingerprint needed. + * currentCount : current count the lock is collecting. + * + * @param type + */ + private void addFingerprint(int type){ + ensureBluetoothIsEnabled(); + showConnectLockToast(); + switch (type){ + case ADD_PERMANENT: + break; + case ADD_TIMED: + addStartDate = System.currentTimeMillis(); + //means 2 minutes later this card will expired. + addEndDate = addStartDate + 2 * 60 * 1000; + break; + default: + break; + } + + + TTLockClient.getDefault().addFingerprint(addStartDate, addEndDate, mCurrentLock.getLockData(), mCurrentLock.getLockMac(), new AddFingerprintCallback() { + + @Override + public void onEnterAddMode(int totalCount) { + makeToast("==put your fingerprint on lock=" + totalCount); + } + + @Override + public void onCollectFingerprint(int currentCount) { + makeToast("==currentCount is " + currentCount); + } + + @Override + public void onAddFingerpintFinished(long fingerprintNum) { + uploadFingerprint2Server(addStartDate,addEndDate,fingerprintNum); + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + } + + private void uploadFingerprint2Server(long startDate,long endDate,long fingerprintNumber){ + ApiService apiService = RetrofitAPIManager.provideClientApi(); + HashMap params = new HashMap<>(8); + params.put("clientId",ApiService.CLIENT_ID); + params.put("accessToken",MyApplication.getmInstance().getAccountInfo().getAccess_token()); + params.put("lockId",String.valueOf(mCurrentLock.getLockId())); + params.put("fingerprintNumber",String.valueOf(fingerprintNumber)); + params.put("fingerprintName","myTestFingerprint" + System.currentTimeMillis()); + if(startDate > 0 && endDate > 0){ + params.put("startDate",String.valueOf(addStartDate)); + params.put("endDate",String.valueOf(addEndDate)); + } + params.put("date",String.valueOf(System.currentTimeMillis())); + + + Call call = apiService.addFingerprint(params); + RetrofitAPIManager.enqueue(call, new TypeToken() { + }, result -> { + if (!result.success) { + makeToast("-add fail -" + result.getMsg()); + //if upload fail you should cache lockData and upload again until success,or you should reset lock and do init again. + return; + } + makeToast("-fingerprint is added success " ); + + + }, requestError -> { + makeToast(requestError.getMessage()); + }); + } + + + + private void getAllFingerprints(){ + showConnectLockToast(); + TTLockClient.getDefault().getAllValidFingerprints( mCurrentLock.getLockData(), mCurrentLock.getLockMac(), new GetAllValidFingerprintCallback() { + @Override + public void onGetAllFingerprintsSuccess(String fingerprintStr) { + makeToast("-get-all fingerprints-success-" + fingerprintStr); + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + } + + private void clearAllFingerprints(){ + showConnectLockToast(); + TTLockClient.getDefault().clearAllFingerprints( mCurrentLock.getLockData(), mCurrentLock.getLockMac(), new ClearAllFingerprintCallback() { + + @Override + public void onClearAllFingerprintSuccess() { + makeToast("--clear all fingerprints-"); + //this must be done + uploadClear2Server(); + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + } + + private void uploadClear2Server(){ + ApiService apiService = RetrofitAPIManager.provideClientApi(); + + Call call = apiService.clearFingerprints(ApiService.CLIENT_ID, MyApplication.getmInstance().getAccountInfo().getAccess_token(), mCurrentLock.getLockId(),System.currentTimeMillis()); + RetrofitAPIManager.enqueue(call, new TypeToken(){}, result -> { + if(!result.success){ + makeToast("--clear my fingerprint fail-" + result.getMsg()); + return; + } + + makeToast("-upload to server success-"); + + + }, requestError -> { + makeToast("--clear my fingerprint fail-" + requestError.getMessage()); + }); + } + + + + /** + * stopBTService should be called when Activity is finishing to release Bluetooth resource. + */ + @Override + public void onDestroy(){ + super.onDestroy(); + TTLockClient.getDefault().stopBTService(); + } +} diff --git a/app/src/main/java/ttlock/demo/fingerprint/FingerprintModifyActivity.java b/app/src/main/java/ttlock/demo/fingerprint/FingerprintModifyActivity.java new file mode 100644 index 0000000..6652f04 --- /dev/null +++ b/app/src/main/java/ttlock/demo/fingerprint/FingerprintModifyActivity.java @@ -0,0 +1,121 @@ +package ttlock.demo.fingerprint; + +import android.content.Context; +import android.content.Intent; +import android.databinding.DataBindingUtil; +import android.os.Bundle; + +import com.google.gson.reflect.TypeToken; +import com.ttlock.bl.sdk.api.TTLockClient; +import com.ttlock.bl.sdk.callback.DeleteFingerprintCallback; +import com.ttlock.bl.sdk.callback.ModifyFingerprintPeriodCallback; +import com.ttlock.bl.sdk.entity.LockError; + +import java.util.HashMap; + +import okhttp3.ResponseBody; +import retrofit2.Call; +import ttlock.demo.BaseActivity; +import ttlock.demo.MyApplication; + +import ttlock.demo.R;; + +import ttlock.demo.databinding.ActivityFingerprintModifyBinding; +import ttlock.demo.fingerprint.model.FingerprintObj; +import ttlock.demo.retrofit.ApiService; +import ttlock.demo.retrofit.RetrofitAPIManager; + +public class FingerprintModifyActivity extends BaseActivity { + ActivityFingerprintModifyBinding binding; + FingerprintObj mSelectFingerprintObj; + private final static String SELECT_PARAM = "select_param"; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + binding = DataBindingUtil.setContentView(this,R.layout.activity_fingerprint_modify); + TTLockClient.getDefault().prepareBTService(getApplicationContext()); + mSelectFingerprintObj = (FingerprintObj)getIntent().getSerializableExtra(SELECT_PARAM); + initListener(); + } + + private void initListener(){ + binding.btnDelete.setOnClickListener(v -> deleteFingerprint()); + binding.btnModifyPeriod.setOnClickListener(v -> modifyPeriod()); + } + + public static void launch(Context context,FingerprintObj fingerprintObj){ + Intent intent = new Intent(context,FingerprintModifyActivity.class); + intent.putExtra(SELECT_PARAM,fingerprintObj); + context.startActivity(intent); + } + + private void modifyPeriod(){ + showConnectLockToast(); + long newStartDate = System.currentTimeMillis(); + long newEndDate = newStartDate + 5 * 60 * 1000; + TTLockClient.getDefault().modifyFingerprintValidityPeriod(newStartDate, newEndDate, mSelectFingerprintObj.getFingerprintNumber(), mCurrentLock.getLockData(), mCurrentLock.getLockMac(), new ModifyFingerprintPeriodCallback() { + + @Override + public void onModifyPeriodSuccess() { + makeToast("-modify success-"); + //call server api to update modify data + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + } + + + private void deleteFingerprint(){ + showConnectLockToast(); + TTLockClient.getDefault().deleteFingerprint(mSelectFingerprintObj.getFingerprintNumber(), mCurrentLock.getLockData(), mCurrentLock.getLockMac(), new DeleteFingerprintCallback() { + @Override + public void onDeleteFingerprintSuccess() { + makeToast("--fingerprint is deleted by lock-"); + //this must be done + notifyDelete2Server(); + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + } + + private void notifyDelete2Server(){ + ApiService apiService = RetrofitAPIManager.provideClientApi(); + HashMap param = new HashMap<>(6); + param.put("clientId",ApiService.CLIENT_ID); + param.put("accessToken",MyApplication.getmInstance().getAccountInfo().getAccess_token()); + param.put("lockId",String.valueOf(mCurrentLock.getLockId())); + param.put("fingerprintId",String.valueOf(mSelectFingerprintObj.getFingerprintId())); + param.put("date",String.valueOf(System.currentTimeMillis())); + Call call = apiService.deleteFingerprint(param); + RetrofitAPIManager.enqueue(call, new TypeToken(){}, result -> { + if(!result.success){ + makeToast("--delete my fingerprint fail-" + result.getMsg()); + return; + } + + makeToast("-lock and server-delete success-"); + finish(); + + + }, requestError -> { + makeToast("--delete my fingerprint fail-" + requestError.getMessage()); + }); + } + + /** + * stopBTService should be called when Activity is finishing to release Bluetooth resource. + */ + @Override + public void onDestroy(){ + super.onDestroy(); + TTLockClient.getDefault().stopBTService(); + } +} diff --git a/app/src/main/java/ttlock/demo/fingerprint/FinggerprintAdapter.java b/app/src/main/java/ttlock/demo/fingerprint/FinggerprintAdapter.java new file mode 100644 index 0000000..522f25f --- /dev/null +++ b/app/src/main/java/ttlock/demo/fingerprint/FinggerprintAdapter.java @@ -0,0 +1,85 @@ +package ttlock.demo.fingerprint; + +import android.app.Activity; +import android.databinding.DataBindingUtil; +import android.support.annotation.NonNull; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import java.util.ArrayList; + + +import ttlock.demo.R;; + +import ttlock.demo.databinding.AttachmentListItemBinding; +import ttlock.demo.fingerprint.model.FingerprintObj; + + +/** + * Created on 2019/4/28 0028 16:03 + * + * @author theodre + */ +public class FinggerprintAdapter extends RecyclerView.Adapter { + + public ArrayList mDataList = new ArrayList<>(); + private Activity mContext; + onListItemClick mListener; + public FinggerprintAdapter (Activity context){ + mContext = context; + } + + interface onListItemClick{ + void onItemClick(FingerprintObj fingerprintObj); + } + + public void setOnListItemClick(onListItemClick listItemClick){ + this.mListener = listItemClick; + } + + public void updateData(ArrayList list){ + mDataList.clear(); + mDataList.addAll(list); + notifyDataSetChanged(); + } + + @NonNull + @Override + public FingerprintViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View mView = LayoutInflater.from(mContext).inflate(R.layout.attachment_list_item,parent,false); + return new FingerprintViewHolder(mView); + } + + @Override + public void onBindViewHolder(@NonNull FingerprintViewHolder holder, int position) { + FingerprintObj fingerprintObj = mDataList.get(position); + holder.onBind(fingerprintObj); + } + + @Override + public int getItemCount() { + return mDataList.size(); + } + + + class FingerprintViewHolder extends RecyclerView.ViewHolder { + + AttachmentListItemBinding itemBinding; + + public FingerprintViewHolder(View itemView) { + super(itemView); + itemBinding = DataBindingUtil.bind(itemView); + } + + public void onBind(FingerprintObj fingerprintObj){ + itemBinding.tvItem.setText(fingerprintObj.getFingerprintName()); + itemBinding.tvItem.setOnClickListener(v -> { + if(mListener != null){ + mListener.onItemClick(fingerprintObj); + } + }); + } + } +} diff --git a/app/src/main/java/ttlock/demo/fingerprint/MyFingerprintListActivity.java b/app/src/main/java/ttlock/demo/fingerprint/MyFingerprintListActivity.java new file mode 100644 index 0000000..16c245e --- /dev/null +++ b/app/src/main/java/ttlock/demo/fingerprint/MyFingerprintListActivity.java @@ -0,0 +1,86 @@ +package ttlock.demo.fingerprint; + +import android.databinding.DataBindingUtil; +import android.os.Bundle; +import android.support.v7.widget.LinearLayoutManager; +import android.util.Log; + +import com.google.gson.reflect.TypeToken; + +import java.util.ArrayList; +import java.util.HashMap; + +import okhttp3.ResponseBody; +import retrofit2.Call; +import ttlock.demo.BaseActivity; +import ttlock.demo.MyApplication; + +import ttlock.demo.R;; + +import ttlock.demo.databinding.ActivityMyFingerprintListBinding; +import ttlock.demo.fingerprint.model.FingerpintListObj; +import ttlock.demo.fingerprint.model.FingerprintObj; +import ttlock.demo.retrofit.ApiService; +import ttlock.demo.retrofit.RetrofitAPIManager; + +public class MyFingerprintListActivity extends BaseActivity implements FinggerprintAdapter.onListItemClick{ + + FinggerprintAdapter mListAdapter; + ActivityMyFingerprintListBinding binding; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + binding = DataBindingUtil.setContentView(this,R.layout.activity_my_fingerprint_list); + initView(); + } + + @Override + public void onResume(){ + super.onResume(); + getFingerprintList(); + } + + private void initView(){ + mListAdapter = new FinggerprintAdapter(this); + binding.rvFingerprintList.setAdapter(mListAdapter); + binding.rvFingerprintList.setLayoutManager(new LinearLayoutManager(this)); + mListAdapter.setOnListItemClick(this); + } + + private void getFingerprintList(){ + ApiService apiService = RetrofitAPIManager.provideClientApi(); + HashMap param = new HashMap<>(6); + param.put("clientId",ApiService.CLIENT_ID); + param.put("accessToken",MyApplication.getmInstance().getAccountInfo().getAccess_token()); + param.put("lockId",String.valueOf(mCurrentLock.getLockId())); + param.put("pageNo","1"); + param.put("pageSize","1000"); + param.put("date",String.valueOf(System.currentTimeMillis())); + + Call call = apiService.getUserFingerprintList(param); + RetrofitAPIManager.enqueue(call, new TypeToken(){}, result -> { + if(!result.success){ + makeToast("--get my fingerprint list fail-" + result.getMsg()); + return; + } + Log.d("OMG","===result===" + result.getResult() + "===" + result); + FingerpintListObj fingerpintListObj = result.getResult(); + ArrayList myFingerprintList = fingerpintListObj.getList(); + if(myFingerprintList.isEmpty()){ + makeToast("- please add fingerprint first --"); + } + mListAdapter.updateData(myFingerprintList); + + }, requestError -> { + makeToast("--get my fingerprint list fail-" + requestError.getMessage()); + }); + } + + + @Override + public void onItemClick(FingerprintObj fingerprintObj) { + if(fingerprintObj != null){ + FingerprintModifyActivity.launch(MyFingerprintListActivity.this,fingerprintObj); + } + } +} diff --git a/app/src/main/java/ttlock/demo/fingerprint/model/FingerpintListObj.java b/app/src/main/java/ttlock/demo/fingerprint/model/FingerpintListObj.java new file mode 100644 index 0000000..f62db64 --- /dev/null +++ b/app/src/main/java/ttlock/demo/fingerprint/model/FingerpintListObj.java @@ -0,0 +1,16 @@ +package ttlock.demo.fingerprint.model; + +import java.util.ArrayList; + +/** + * Created on 2019/4/28 0028 16:06 + * + * @author theodre + */ +public class FingerpintListObj { + ArrayList list; + + public ArrayList getList() { + return list; + } +} diff --git a/app/src/main/java/ttlock/demo/fingerprint/model/FingerprintObj.java b/app/src/main/java/ttlock/demo/fingerprint/model/FingerprintObj.java new file mode 100644 index 0000000..e89838d --- /dev/null +++ b/app/src/main/java/ttlock/demo/fingerprint/model/FingerprintObj.java @@ -0,0 +1,46 @@ +package ttlock.demo.fingerprint.model; + +import java.io.Serializable; + +/** + * Created on 2019/4/28 0028 16:06 + * + * @author theodre + */ +public class FingerprintObj implements Serializable { + int fingerprintId; + int lockId; + String fingerprintNumber; + String fingerprintName; + long startDate; + long endDate; + long createDate; + + public int getFingerprintId() { + return fingerprintId; + } + + public int getLockId() { + return lockId; + } + + public String getFingerprintNumber() { + return fingerprintNumber; + } + + public String getFingerprintName() { + return fingerprintName; + } + + public long getStartDate() { + return startDate; + } + + public long getEndDate() { + return endDate; + } + + public long getCreateDate() { + return createDate; + } +} diff --git a/app/src/main/java/ttlock/demo/firmwareupdate/FirmwareUpdateActivity.java b/app/src/main/java/ttlock/demo/firmwareupdate/FirmwareUpdateActivity.java new file mode 100644 index 0000000..6bde54f --- /dev/null +++ b/app/src/main/java/ttlock/demo/firmwareupdate/FirmwareUpdateActivity.java @@ -0,0 +1,197 @@ +package ttlock.demo.firmwareupdate; + +import android.databinding.DataBindingUtil; +import android.os.Bundle; +import android.view.View; + +import com.ttlock.bl.sdk.api.LockDfuClient; +import com.ttlock.bl.sdk.api.TTLockClient; +import com.ttlock.bl.sdk.callback.DfuCallback; +import com.ttlock.bl.sdk.callback.GetLockSystemInfoCallback; +import com.ttlock.bl.sdk.entity.DeviceInfo; +import com.ttlock.bl.sdk.entity.LockError; +import com.ttlock.bl.sdk.util.GsonUtil; +import com.ttlock.bl.sdk.util.LogUtil; + +import retrofit2.Call; +import retrofit2.Callback; +import ttlock.demo.BaseActivity; +import ttlock.demo.MyApplication; +import ttlock.demo.R; +import ttlock.demo.databinding.ActivityFirmwareUpdateBinding; +import ttlock.demo.lock.UserLockActivity; +import ttlock.demo.retrofit.ApiService; +import ttlock.demo.retrofit.RetrofitAPIManager; + + +public class FirmwareUpdateActivity extends BaseActivity { + + private ActivityFirmwareUpdateBinding binding; + private LockUpgradeObj lockUpgradeObj; + private boolean isFailure; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + binding = DataBindingUtil.setContentView(this, R.layout.activity_firmware_update); + TTLockClient.getDefault().prepareBTService(getApplicationContext()); + + check(); + initListener(); + } + + private void check() { + ApiService apiService = RetrofitAPIManager.provideClientApi(); + Call call = apiService.lockUpgradeCheck(ApiService.CLIENT_ID, MyApplication.getmInstance().getAccountInfo().getAccess_token(), mCurrentLock.getLockId(), System.currentTimeMillis()); + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, retrofit2.Response response) { + String json = response.body(); + lockUpgradeObj = GsonUtil.toObject(json, LockUpgradeObj.class); + if (lockUpgradeObj != null) { + if (lockUpgradeObj.errcode == 0){ + updateUI(); + }else { + makeToast(lockUpgradeObj.errmsg); + } + } + } + + @Override + public void onFailure(Call call, Throwable t) { + makeToast(t.getMessage()); + } + }); + } + + private void checkAgain(DeviceInfo deviceInfo) { + ApiService apiService = RetrofitAPIManager.provideClientApi(); + Call call = apiService.lockUpgradeCheckAgain(ApiService.CLIENT_ID, MyApplication.getmInstance().getAccountInfo().getAccess_token(), deviceInfo.getDeviceInfo(), mCurrentLock.getLockId(), System.currentTimeMillis()); + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, retrofit2.Response response) { + String json = response.body(); + lockUpgradeObj = GsonUtil.toObject(json, LockUpgradeObj.class); + if (lockUpgradeObj != null) { + if (lockUpgradeObj.errcode == 0){ + updateUI(); + }else{ + makeToast(lockUpgradeObj.errmsg); + } + } + } + + @Override + public void onFailure(Call call, Throwable t) { + makeToast(t.getMessage()); + } + }); + } + + private void updateUI() { + if (lockUpgradeObj != null) { + binding.getRoot().setVisibility(View.VISIBLE); + binding.version.setText(lockUpgradeObj.getVersion()); + switch (lockUpgradeObj.getNeedUpgrade()) { + case 0: + binding.status.setText(R.string.no_updates); + binding.btnUpgrade.setVisibility(View.GONE); + break; + case 1: + binding.status.setText(R.string.new_version_found); + binding.btnUpgrade.setVisibility(View.VISIBLE); + binding.btnUpgrade.setText(R.string.upgrade); + break; + case 2: + binding.status.setText(R.string.unknown_lock_version); + binding.btnUpgrade.setVisibility(View.VISIBLE); + binding.btnUpgrade.setText(R.string.recheck_version); + break; + default: + break; + } + } + } + + private void getLockSysInfo() { + if (mCurrentLock != null) { + LockDfuClient.getDefault().getLockSystemInfo(mCurrentLock.getLockData(), mCurrentLock.getLockMac(), new GetLockSystemInfoCallback() { + @Override + public void onGetLockSystemInfoSuccess(DeviceInfo info) { + LogUtil.d("info:" + info); + checkAgain(info); + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + } + } + + private void startDfu() { + if (mCurrentLock != null) { + LockDfuClient.getDefault().startDfu(getApplicationContext(), ApiService.CLIENT_ID, MyApplication.getmInstance().getAccountInfo().getAccess_token(), mCurrentLock.getLockId(), mCurrentLock.getLockData(), mCurrentLock.getLockMac(), new DfuCallback() { + @Override + public void onDfuSuccess(String deviceAddress) { + makeToast("dfu success"); + startTargetActivity(UserLockActivity.class); + } + + @Override + public void onStatusChanged(int status) { + + } + + @Override + public void onDfuAborted(String deviceAddress) { + + } + + @Override + public void onProgressChanged(String deviceAddress, int percent, float speed, float avgSpeed, int currentPart, int partsTotal) { + LogUtil.d("percent:" + percent); + } + + @Override + public void onError(int errorCode, String errorContent) { + makeToast(errorContent); + isFailure = true; + binding.btnUpgrade.setText(R.string.retry); + } + }); + } + } + + private void initListener(){ + binding.btnUpgrade.setOnClickListener(v -> { + if (isFailure) { + makeToast("retry"); + LockDfuClient.getDefault().retry(); + } else { + switch (lockUpgradeObj.getNeedUpgrade()) { + case 1: + makeToast("start dfu"); + startDfu(); + break; + case 2: + makeToast("check version again"); + getLockSysInfo(); + break; + default: + break; + } + } + }); + } + + /** + * stopBTService should be called when Activity is finishing to release Bluetooth resource. + */ + @Override + public void onDestroy(){ + super.onDestroy(); + TTLockClient.getDefault().stopBTService(); + } +} diff --git a/app/src/main/java/ttlock/demo/firmwareupdate/LockUpgradeObj.java b/app/src/main/java/ttlock/demo/firmwareupdate/LockUpgradeObj.java new file mode 100644 index 0000000..2ce80be --- /dev/null +++ b/app/src/main/java/ttlock/demo/firmwareupdate/LockUpgradeObj.java @@ -0,0 +1,76 @@ +package ttlock.demo.firmwareupdate; + +import com.ttlock.bl.sdk.entity.DeviceInfo; + +import ttlock.demo.model.ServerError; + +/** + * Created by TTLock on 2019/5/6. + */ + +public class LockUpgradeObj extends ServerError { + //TODO: + /** + * needUpgrade : 1 + * modelNum : SN118_PV53 + * hardwareRevision : 1.3 + * firmwareInfo : {"modelNum":"SN118_PV53","hardwareRevision":"1.3","firmwareRevision":"4.0.17.0721"} + * version : 4.1.29.0722 + * firmwareRevision : 4.0.17.0721 + */ + + private int needUpgrade; + private String modelNum; + private String hardwareRevision; + private DeviceInfo firmwareInfo; + private String version; + private String firmwareRevision; + + public int getNeedUpgrade() { + return needUpgrade; + } + + public void setNeedUpgrade(int needUpgrade) { + this.needUpgrade = needUpgrade; + } + + public String getModelNum() { + return modelNum; + } + + public void setModelNum(String modelNum) { + this.modelNum = modelNum; + } + + public String getHardwareRevision() { + return hardwareRevision; + } + + public void setHardwareRevision(String hardwareRevision) { + this.hardwareRevision = hardwareRevision; + } + + public DeviceInfo getFirmwareInfo() { + return firmwareInfo; + } + + public void setFirmwareInfo(DeviceInfo firmwareInfo) { + this.firmwareInfo = firmwareInfo; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getFirmwareRevision() { + return firmwareRevision; + } + + public void setFirmwareRevision(String firmwareRevision) { + this.firmwareRevision = firmwareRevision; + } +} diff --git a/app/src/main/java/ttlock/demo/gateway/GatewayActivity.java b/app/src/main/java/ttlock/demo/gateway/GatewayActivity.java new file mode 100644 index 0000000..3a7fb80 --- /dev/null +++ b/app/src/main/java/ttlock/demo/gateway/GatewayActivity.java @@ -0,0 +1,119 @@ +package ttlock.demo.gateway; + +import android.Manifest; +import android.annotation.TargetApi; +import android.app.Activity; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.databinding.DataBindingUtil; +import android.os.Build; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.v4.content.ContextCompat; +import android.support.v7.widget.LinearLayoutManager; + +import com.ttlock.bl.sdk.gateway.api.GatewayClient; +import com.ttlock.bl.sdk.gateway.callback.ScanGatewayCallback; +import com.ttlock.bl.sdk.api.ExtendedBluetoothDevice; + +import ttlock.demo.BaseActivity; + +import ttlock.demo.R;; +import ttlock.demo.databinding.ActivityGatewayBinding; +import ttlock.demo.gateway.adapter.GatewayListAdapter; + + +public class GatewayActivity extends BaseActivity { + + private ActivityGatewayBinding binding; + private GatewayListAdapter mListApapter; + protected static final int REQUEST_PERMISSION_REQ_CODE = 11; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + binding = DataBindingUtil.setContentView(this, R.layout.activity_gateway); + GatewayClient.getDefault().prepareBTService(getApplicationContext()); + initListener(); + initList(); + } + + private void initList(){ + mListApapter = new GatewayListAdapter(this); + binding.rvGatewayList.setAdapter(mListApapter); + binding.rvGatewayList.setLayoutManager(new LinearLayoutManager(this)); + } + + private void initListener() { + binding.btnScan.setOnClickListener(v -> { + boolean isBtEnable = GatewayClient.getDefault().isBLEEnabled(GatewayActivity.this); + if(isBtEnable){ + startScan(); + } else { + GatewayClient.getDefault().requestBleEnable(GatewayActivity.this); + } + }); + } + + /** + * before call startScanGateway,the location permission should be granted. + */ + @TargetApi(Build.VERSION_CODES.M) + private void startScan(){ + if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, REQUEST_PERMISSION_REQ_CODE); + return; + } + getScanGatewayCallback(); + } + + /** + * start scan BT lock + */ + private void getScanGatewayCallback(){ + GatewayClient.getDefault().startScanGateway(new ScanGatewayCallback() { + @Override + public void onScanGatewaySuccess(ExtendedBluetoothDevice device) { +// LogUtil.d("device:" + device); + if (mListApapter != null) + mListApapter.updateData(device); + } + + @Override + public void onScanFailed(int errorCode) { + + } + }); + } + + @Override + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults); + if(grantResults.length == 0 ){ + return; + } + + switch (requestCode) { + case REQUEST_PERMISSION_REQ_CODE: { + if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { + getScanGatewayCallback(); + } else { + if (permissions[0].equals(Manifest.permission.ACCESS_COARSE_LOCATION)){ + + } + } + break; + } + default: + break; + } + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (requestCode == GatewayClient.REQUEST_ENABLE_BT && requestCode == Activity.RESULT_OK) { + startScan(); + } + } +} diff --git a/app/src/main/java/ttlock/demo/gateway/GatewayDfuActivity.java b/app/src/main/java/ttlock/demo/gateway/GatewayDfuActivity.java new file mode 100644 index 0000000..0a7d096 --- /dev/null +++ b/app/src/main/java/ttlock/demo/gateway/GatewayDfuActivity.java @@ -0,0 +1,134 @@ +package ttlock.demo.gateway; + +import android.app.Activity; +import android.content.Intent; +import android.databinding.DataBindingUtil; +import android.os.Bundle; +import android.view.View; + +import com.ttlock.bl.sdk.gateway.api.GatewayDfuClient; +import com.ttlock.bl.sdk.gateway.callback.DfuCallback; +import com.ttlock.bl.sdk.util.GsonUtil; + +import retrofit2.Call; +import retrofit2.Callback; +import ttlock.demo.BaseActivity; +import ttlock.demo.MyApplication; +import ttlock.demo.R; +import ttlock.demo.databinding.ActivityGatewayDfuBinding; +import ttlock.demo.gateway.model.GatewayUpgradeObj; +import ttlock.demo.model.GatewayObj; +import ttlock.demo.retrofit.ApiService; +import ttlock.demo.retrofit.RetrofitAPIManager; + +public class GatewayDfuActivity extends BaseActivity { + + private GatewayUpgradeObj gatewayUpgradeObj; + private GatewayObj gatewayObj; + private ActivityGatewayDfuBinding binding; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + binding = DataBindingUtil.setContentView(this, R.layout.activity_gateway_dfu); + parseIntent(getIntent()); + check(); + initListener(); + } + + private void updateUI() { + if (gatewayUpgradeObj != null) { + binding.getRoot().setVisibility(View.VISIBLE); + binding.version.setText(gatewayUpgradeObj.getVersion()); + switch (gatewayUpgradeObj.getNeedUpgrade()) { + case 0: + binding.status.setText(R.string.no_updates); + binding.btnUpgrade.setVisibility(View.GONE); + break; + case 1: + binding.status.setText(R.string.new_version_found); + binding.btnUpgrade.setVisibility(View.VISIBLE); + break; + case 2: + binding.status.setText(R.string.unknown_lock_version); + binding.btnUpgrade.setVisibility(View.VISIBLE); + break; + } + } + } + + private void initListener(){ + binding.btnUpgrade.setOnClickListener(v -> { + makeToast("start dfu"); + startDfu(); + }); + + binding.btnRetryByBle.setOnClickListener(v->{ + //use retryEnterDfuModeByBle,need Re Connect the Power + GatewayDfuClient.getDefault().retryEnterDfuModeByBle(); + }); + + binding.btnRetryByNet.setOnClickListener(v -> { + GatewayDfuClient.getDefault().retryEnterDfuModeByNet(); + }); + + } + + private void parseIntent(Intent intent) { + gatewayObj = (GatewayObj) intent.getSerializableExtra(GatewayObj.class.getName()); + } + + public static void launch(Activity activity, GatewayObj gatewayObj) { + Intent intent = new Intent(activity, GatewayDfuActivity.class); + intent.putExtra(GatewayObj.class.getName(), gatewayObj); + activity.startActivity(intent); + } + + private void startDfu() { + GatewayDfuClient.getDefault().startDfu(GatewayDfuActivity.this, ApiService.CLIENT_ID, MyApplication.getmInstance().getAccountInfo().getAccess_token(), gatewayObj.getGatewayId(), gatewayObj.getGatewayMac(), new DfuCallback() { + @Override + public void onDfuSuccess(String deviceAddress) { + makeToast("dfu completed"); + } + + @Override + public void onDfuAborted(String deviceAddress) { + makeToast("dfu aborted"); + } + + @Override + public void onProgressChanged(String deviceAddress, int percent, float speed, float avgSpeed, int currentPart, int partsTotal) { + + } + + @Override + public void onError() { + binding.llRetry.setVisibility(View.VISIBLE); + makeToast("dfu error"); + } + }); + } + + private void check() { + ApiService apiService = RetrofitAPIManager.provideClientApi(); + Call call = apiService.gatewayUpgradeCheck(ApiService.CLIENT_ID, MyApplication.getmInstance().getAccountInfo().getAccess_token(), 311, System.currentTimeMillis()); + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, retrofit2.Response response) { + String json = response.body(); + gatewayUpgradeObj = GsonUtil.toObject(json, GatewayUpgradeObj.class); + if (gatewayUpgradeObj != null) { + if (gatewayUpgradeObj.errcode == 0) + updateUI(); + else makeToast(gatewayUpgradeObj.errmsg); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + makeToast(t.getMessage()); + } + }); + } + +} diff --git a/app/src/main/java/ttlock/demo/gateway/InitGatewayActivity.java b/app/src/main/java/ttlock/demo/gateway/InitGatewayActivity.java new file mode 100644 index 0000000..c26744a --- /dev/null +++ b/app/src/main/java/ttlock/demo/gateway/InitGatewayActivity.java @@ -0,0 +1,103 @@ +package ttlock.demo.gateway; + +import android.app.Activity; +import android.content.Intent; +import android.databinding.DataBindingUtil; +import android.os.Bundle; + +import com.ttlock.bl.sdk.api.ExtendedBluetoothDevice; +import com.ttlock.bl.sdk.gateway.api.GatewayClient; +import com.ttlock.bl.sdk.gateway.callback.InitGatewayCallback; +import com.ttlock.bl.sdk.gateway.model.ConfigureGatewayInfo; +import com.ttlock.bl.sdk.gateway.model.DeviceInfo; +import com.ttlock.bl.sdk.gateway.model.GatewayError; +import com.ttlock.bl.sdk.util.LogUtil; +import com.ttlock.bl.sdk.util.NetworkUtil; + +import retrofit2.Call; +import retrofit2.Callback; +import ttlock.demo.BaseActivity; +import ttlock.demo.MyApplication; +import ttlock.demo.R; +import ttlock.demo.databinding.ActivityInitGatewayBinding; +import ttlock.demo.retrofit.ApiService; +import ttlock.demo.retrofit.RetrofitAPIManager; + + +public class InitGatewayActivity extends BaseActivity { + + private ActivityInitGatewayBinding binding; + private ConfigureGatewayInfo configureGatewayInfo; + private ExtendedBluetoothDevice device; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + binding = DataBindingUtil.setContentView(this, R.layout.activity_init_gateway); + device = getIntent().getParcelableExtra(ExtendedBluetoothDevice.class.getName()); + configureGatewayInfo = new ConfigureGatewayInfo(); + initView(); + initListener(); + } + + private void initView() { + if (NetworkUtil.isWifiConnected(this)) { + binding.wifiName.setText(NetworkUtil.getWifiSSid(this)); + } + } + + private void isInitSuccess(DeviceInfo deviceInfo) { + ApiService apiService = RetrofitAPIManager.provideClientApi(); +// reverseMac(); + Call call = apiService.gatewayIsInitSuccess(ApiService.CLIENT_ID, MyApplication.getmInstance().getAccountInfo().getAccess_token(), device.getAddress(), System.currentTimeMillis()); + LogUtil.d("call server isSuccess api"); + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, retrofit2.Response response) { + String json = response.body(); + makeToast(json); + //TODO: + } + + @Override + public void onFailure(Call call, Throwable t) { + makeToast(t.getMessage()); + LogUtil.d("t.getMessage():" + t.getMessage()); + } + }); + } + + private void initListener() { + binding.btnInitGateway.setOnClickListener(v -> { + configureGatewayInfo.uid = MyApplication.getmInstance().getAccountInfo().getUid(); + configureGatewayInfo.userPwd = MyApplication.getmInstance().getAccountInfo().getMd5Pwd(); + + configureGatewayInfo.ssid = binding.wifiName.getText().toString().trim(); +// configureGatewayInfo.plugName = binding.gatewayName.getText().toString().trim(); + configureGatewayInfo.wifiPwd = binding.wifiPwd.getText().toString().trim(); + + //TODO: + configureGatewayInfo.plugName = device.getAddress(); + + GatewayClient.getDefault().initGateway(configureGatewayInfo, new InitGatewayCallback() { + @Override + public void onInitGatewaySuccess(DeviceInfo deviceInfo) { + LogUtil.d("gateway init success"); + isInitSuccess(deviceInfo); + } + + @Override + public void onFail(GatewayError error) { + makeToast(error.getDescription()); + finish(); + } + }); + }); + } + + public static void launch(Activity activity, ExtendedBluetoothDevice device) { + Intent intent = new Intent(activity, InitGatewayActivity.class); + intent.putExtra(ExtendedBluetoothDevice.class.getName(), device); + activity.startActivity(intent); + } +} diff --git a/app/src/main/java/ttlock/demo/gateway/UserGatewayActivity.java b/app/src/main/java/ttlock/demo/gateway/UserGatewayActivity.java new file mode 100644 index 0000000..487b944 --- /dev/null +++ b/app/src/main/java/ttlock/demo/gateway/UserGatewayActivity.java @@ -0,0 +1,78 @@ +package ttlock.demo.gateway; + +import android.databinding.DataBindingUtil; +import android.os.Bundle; +import android.support.v7.widget.LinearLayoutManager; + +import com.google.gson.reflect.TypeToken; +import com.ttlock.bl.sdk.util.GsonUtil; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; + +import retrofit2.Call; +import retrofit2.Callback; +import ttlock.demo.BaseActivity; +import ttlock.demo.MyApplication; +import ttlock.demo.R; +import ttlock.demo.databinding.ActivityUserGatewayBinding; +import ttlock.demo.gateway.adapter.UserGatewayListAdapter; +import ttlock.demo.model.GatewayObj; +import ttlock.demo.retrofit.ApiService; +import ttlock.demo.retrofit.RetrofitAPIManager; + +public class UserGatewayActivity extends BaseActivity { + + private int pageNo = 1; + private int pageSize = 100; + private UserGatewayListAdapter mListApapter; + private ActivityUserGatewayBinding binding; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + binding = DataBindingUtil.setContentView(this, R.layout.activity_user_gateway); + binding.btnScan.setOnClickListener(v -> {startTargetActivity(GatewayActivity.class);}); + initList(); + gatewayList(); + } + + private void initList() { + mListApapter = new UserGatewayListAdapter(this); + binding.rvGatewayList.setAdapter(mListApapter); + binding.rvGatewayList.setLayoutManager(new LinearLayoutManager(this)); + } + + private void gatewayList() { + ApiService apiService = RetrofitAPIManager.provideClientApi(); + Call call = apiService.getGatewayList(ApiService.CLIENT_ID, MyApplication.getmInstance().getAccountInfo().getAccess_token(), pageNo, pageSize, System.currentTimeMillis()); + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, retrofit2.Response response) { + String json = response.body(); + if (json.contains("list")) { + try { + JSONObject jsonObject = new JSONObject(json); + JSONArray array = jsonObject.getJSONArray("list"); + ArrayList gatewayObjs = GsonUtil.toObject(array.toString(), new TypeToken>(){}); + mListApapter.updateData(gatewayObjs); + } catch (JSONException e) { + e.printStackTrace(); + } + } else { + makeToast(json); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + makeToast(t.getMessage()); + } + }); + } + + +} diff --git a/app/src/main/java/ttlock/demo/gateway/adapter/GatewayListAdapter.java b/app/src/main/java/ttlock/demo/gateway/adapter/GatewayListAdapter.java new file mode 100644 index 0000000..cfb4fde --- /dev/null +++ b/app/src/main/java/ttlock/demo/gateway/adapter/GatewayListAdapter.java @@ -0,0 +1,200 @@ +package ttlock.demo.gateway.adapter; + +import android.app.Activity; +import android.databinding.DataBindingUtil; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Toast; + +import com.ttlock.bl.sdk.api.ExtendedBluetoothDevice; +import com.ttlock.bl.sdk.gateway.api.GatewayClient; +import com.ttlock.bl.sdk.gateway.callback.ConnectCallback; +import com.ttlock.bl.sdk.util.LogUtil; + +import java.util.LinkedList; + +import ttlock.demo.R; +import ttlock.demo.databinding.GatewayScanListItemBinding; +import ttlock.demo.gateway.InitGatewayActivity; + +/** + * Created on 2019/4/12 0012 14:19 + * + * @author theodre + */ +public class GatewayListAdapter extends RecyclerView.Adapter{ + + public LinkedList mDataList = new LinkedList<>(); + + private Activity mContext; + private static final int TIMEOUT = 5000; + private LinkedList mAddStatusList = new LinkedList<>(); + private LinkedList mNormalStatusList = new LinkedList<>(); + private long lastSyncTimeStamp = 0; + + public GatewayListAdapter(Activity context){ + mContext = context; + } + + public synchronized void updateData(ExtendedBluetoothDevice device){ + if(device != null) { + if(device.isSettingMode()){ + addOrSortLock(device,mAddStatusList); + removeOtherStatusLock(device,mNormalStatusList); + }else { + addOrSortLock(device,mNormalStatusList); + removeOtherStatusLock(device,mAddStatusList); + } + + long currentTime = System.currentTimeMillis(); + if((currentTime - lastSyncTimeStamp) >= 800 ){ + if(!mDataList.isEmpty()){ + mDataList.clear(); + } + + mDataList.addAll(0,mAddStatusList); + mDataList.addAll(mNormalStatusList); + notifyDataSetChanged(); + lastSyncTimeStamp = currentTime; + } + } + } + + + /** + * you can sort the lock that be discovered by signal value. + */ + private void addOrSortLock(ExtendedBluetoothDevice scanDevice,LinkedList lockList){ + boolean isContained = false; + int length = lockList.size(); + ExtendedBluetoothDevice mTopOneDevice; + scanDevice.setDate(System.currentTimeMillis()); + if(length > 0){ + + mTopOneDevice = lockList.get(0); + + for(int i = 0;i < length;i++) { + if(i >= length){ + break; + } + + ExtendedBluetoothDevice currentDevice = lockList.get(i); + + if(scanDevice.getAddress().equals(currentDevice.getAddress()) ){ + isContained = true; + if(i != 0 && scanDevice.getRssi() > mTopOneDevice.getRssi()){ + lockList.remove(i); + lockList.add(0,scanDevice); + }else { + currentDevice.setDate(System.currentTimeMillis()); + lockList.set(i,currentDevice); + } + }else { + if(System.currentTimeMillis() - currentDevice.getDate() >= TIMEOUT) { + lockList.remove(i); + length = lockList.size(); + } + } + } + + if(!isContained){ + if(scanDevice.getRssi() > mTopOneDevice.getRssi()){ + lockList.add(0,scanDevice); + }else { + lockList.add(scanDevice); + } + } + + }else { + lockList.add(scanDevice); + } + + } + + /** + * the lock mode will be changed,so should update the list when lock mode changed. + * @param scanDevice the lock that be discovered. + */ + private void removeOtherStatusLock(ExtendedBluetoothDevice scanDevice,LinkedList lockList){ + if(!lockList.isEmpty()){ + int length = lockList.size(); + for(int i = 0; i < length ; i++){ + ExtendedBluetoothDevice device = lockList.get(i); + if(device.getAddress().equals(scanDevice.getAddress())){ + lockList.remove(i); + length --; + }else { + if(System.currentTimeMillis() - device.getDate() >= TIMEOUT) { + lockList.remove(i); + length --; + } + } + } + } + } + + @Override + public DeviceViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View mView = LayoutInflater.from(mContext).inflate(R.layout.gateway_scan_list_item, parent, false); + return new DeviceViewHolder(mView); + } + + @Override + public void onBindViewHolder(DeviceViewHolder _holder, int position) { + final ExtendedBluetoothDevice item = mDataList.get(position); + _holder.Bind(item); + } + + @Override + public int getItemCount() { + return mDataList.size(); + } + + public class DeviceViewHolder extends RecyclerView.ViewHolder { + + GatewayScanListItemBinding itemBinding; + + + public DeviceViewHolder(View itemView){ + super(itemView); + itemBinding = DataBindingUtil.bind(itemView); + } + + public void Bind(ExtendedBluetoothDevice item){ + itemBinding.tvGatewayName.setText(item.getName()); + itemBinding.ivSettingMode.setVisibility(item.isSettingMode() ? View.VISIBLE : View.GONE); + + if(item.isSettingMode()){ + itemBinding.getRoot().setOnClickListener(view -> { + if(!item.isSettingMode()){ + return; + } + + Toast.makeText(mContext,"--connect gateway--",Toast.LENGTH_LONG).show(); + GatewayClient.getDefault().connectGateway(item, new ConnectCallback() { + @Override + public void onConnectSuccess(ExtendedBluetoothDevice device) { + InitGatewayActivity.launch(mContext, item); + LogUtil.d("connect success"); + } + + @Override + public void onDisconnected() { + Toast.makeText(mContext, R.string.gateway_out_of_time, Toast.LENGTH_LONG).show(); + } + +// @Override +// public void onFail(GatewayError error) { +// //TODO: +// Toast.makeText(mContext, R.string.gateway_out_of_time, Toast.LENGTH_LONG).show(); +// } + }); + }); + } + } + + } + +} diff --git a/app/src/main/java/ttlock/demo/gateway/adapter/UserGatewayListAdapter.java b/app/src/main/java/ttlock/demo/gateway/adapter/UserGatewayListAdapter.java new file mode 100644 index 0000000..87d96cb --- /dev/null +++ b/app/src/main/java/ttlock/demo/gateway/adapter/UserGatewayListAdapter.java @@ -0,0 +1,77 @@ +package ttlock.demo.gateway.adapter; + +import android.app.Activity; +import android.content.Context; +import android.databinding.DataBindingUtil; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import java.util.ArrayList; + +import ttlock.demo.R; +import ttlock.demo.databinding.UserGatewayListItemBinding; +import ttlock.demo.gateway.GatewayDfuActivity; +import ttlock.demo.model.GatewayObj; + +; + +/** + * Created on 2019/4/12 0012 14:19 + * + * @author theodre + */ +public class UserGatewayListAdapter extends RecyclerView.Adapter{ + + public ArrayList mDataList = new ArrayList<>(); + + private Context mContext; + public UserGatewayListAdapter(Context context){ + mContext = context; + } + + public void updateData(ArrayList gatewayList) { + if (gatewayList != null) { + mDataList.clear(); + mDataList.addAll(gatewayList); + notifyDataSetChanged(); + } + } + + @Override + public DeviceViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View mView = LayoutInflater.from(mContext).inflate(R.layout.user_gateway_list_item, parent, false); + return new DeviceViewHolder(mView); + } + + @Override + public void onBindViewHolder(DeviceViewHolder _holder, int position) { + final GatewayObj item = mDataList.get(position); + _holder.Bind(item); + } + + @Override + public int getItemCount() { + return mDataList.size(); + } + + class DeviceViewHolder extends RecyclerView.ViewHolder { + + UserGatewayListItemBinding itemBinding; + + public DeviceViewHolder(View itemView){ + super(itemView); + itemBinding = DataBindingUtil.bind(itemView); + } + + public void Bind(GatewayObj item){ + itemBinding.tvGatewayName.setText(item.getGatewayMac()); + itemBinding.getRoot().setOnClickListener(view -> { + //G2 gateway has dfu function + if (item.getGatewayVersion() == 2) + GatewayDfuActivity.launch((Activity) mContext, item); + }); + } + } +} diff --git a/app/src/main/java/ttlock/demo/gateway/model/GatewayUpgradeObj.java b/app/src/main/java/ttlock/demo/gateway/model/GatewayUpgradeObj.java new file mode 100644 index 0000000..0718a8e --- /dev/null +++ b/app/src/main/java/ttlock/demo/gateway/model/GatewayUpgradeObj.java @@ -0,0 +1,81 @@ +package ttlock.demo.gateway.model; + +import com.ttlock.bl.sdk.gateway.model.DeviceInfo; + +import ttlock.demo.model.ServerError; + +/** + * Created by TTLock on 2019/4/30. + */ + +public class GatewayUpgradeObj extends ServerError { + /** + * needUpgrade : 1 + * firmwareInfo : {"modelNum":"SN227","hardwareRevision":"1.1","firmwareRevision":"1.0.19.0404"} + * version : 1.3 + */ + + private int needUpgrade; + private DeviceInfo firmwareInfo; + private String version; + + public int getNeedUpgrade() { + return needUpgrade; + } + + public void setNeedUpgrade(int needUpgrade) { + this.needUpgrade = needUpgrade; + } + + public DeviceInfo getFirmwareInfo() { + return firmwareInfo; + } + + public void setFirmwareInfo(DeviceInfo firmwareInfo) { + this.firmwareInfo = firmwareInfo; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public static class FirmwareInfoBean { + /** + * modelNum : SN227 + * hardwareRevision : 1.1 + * firmwareRevision : 1.0.19.0404 + */ + + private String modelNum; + private String hardwareRevision; + private String firmwareRevision; + + public String getModelNum() { + return modelNum; + } + + public void setModelNum(String modelNum) { + this.modelNum = modelNum; + } + + public String getHardwareRevision() { + return hardwareRevision; + } + + public void setHardwareRevision(String hardwareRevision) { + this.hardwareRevision = hardwareRevision; + } + + public String getFirmwareRevision() { + return firmwareRevision; + } + + public void setFirmwareRevision(String firmwareRevision) { + this.firmwareRevision = firmwareRevision; + } + } +} diff --git a/app/src/main/java/ttlock/demo/iccard/ICCardActivity.java b/app/src/main/java/ttlock/demo/iccard/ICCardActivity.java new file mode 100644 index 0000000..0a47460 --- /dev/null +++ b/app/src/main/java/ttlock/demo/iccard/ICCardActivity.java @@ -0,0 +1,186 @@ +package ttlock.demo.iccard; + +import android.databinding.DataBindingUtil; +import android.os.Bundle; + +import com.google.gson.reflect.TypeToken; +import com.ttlock.bl.sdk.api.TTLockClient; +import com.ttlock.bl.sdk.callback.AddICCardCallback; +import com.ttlock.bl.sdk.callback.ClearAllICCardCallback; +import com.ttlock.bl.sdk.callback.GetAllValidICCardCallback; +import com.ttlock.bl.sdk.entity.LockError; + +import java.util.HashMap; + +import okhttp3.ResponseBody; +import retrofit2.Call; +import ttlock.demo.BaseActivity; +import ttlock.demo.MyApplication; + +import ttlock.demo.R;; + +import ttlock.demo.databinding.ActivityIccardBinding; +import ttlock.demo.retrofit.ApiService; +import ttlock.demo.retrofit.RetrofitAPIManager; + +public class ICCardActivity extends BaseActivity { + ActivityIccardBinding binding; + private final static int ADD_PERMANENT = 1; + private final static int ADD_TIMED = 2; + long addStartDate = 0; + long addEndDate = 0; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + binding = DataBindingUtil.setContentView(this,R.layout.activity_iccard); + TTLockClient.getDefault().prepareBTService(getApplicationContext()); + initListener(); + } + + private void initListener(){ + binding.btnMyList.setOnClickListener(v -> startTargetActivity(MyICCardListActivity.class)); + binding.btnAddPermanent.setOnClickListener(v -> addICCard(ADD_PERMANENT)); + binding.btnAddTimed.setOnClickListener(v -> addICCard(ADD_TIMED)); + binding.btnGetAllCards.setOnClickListener(v -> getAllCards()); + binding.btnClearCard.setOnClickListener(v -> clearAllCards()); + + } + + /** + * startDate the card active date + * endDate the card expired date + *startDate and endDate set 0 means the card will be valid for ever. + * onEnterAddMode:the lock is ready to add a card. + * + * @param type + */ + private void addICCard(int type){ + ensureBluetoothIsEnabled(); + showConnectLockToast(); + switch (type){ + case ADD_PERMANENT: + + break; + case ADD_TIMED: + addStartDate = System.currentTimeMillis(); + //means 2 minutes later this card will expired. + addEndDate = addStartDate + 2 * 60 * 1000; + break; + default: + break; + } + + + TTLockClient.getDefault().addICCard(addStartDate, addEndDate, mCurrentLock.getLockData(), mCurrentLock.getLockMac(), new AddICCardCallback() { + @Override + public void onEnterAddMode() { + makeToast("-you can put ic card on lock now-"); + } + + @Override + public void onAddICCardSuccess(long cardNum) { + makeToast("card is added to lock -" + cardNum); + uploadICCard2Server(addStartDate,addEndDate,cardNum); + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + } + + private void uploadICCard2Server(long startDate,long endDate,long cardNumber){ + ApiService apiService = RetrofitAPIManager.provideClientApi(); + HashMap params = new HashMap<>(8); + params.put("clientId",ApiService.CLIENT_ID); + params.put("accessToken",MyApplication.getmInstance().getAccountInfo().getAccess_token()); + params.put("lockId",String.valueOf(mCurrentLock.getLockId())); + params.put("cardNumber",String.valueOf(cardNumber)); + params.put("cardName","MyTestICCard " + System.currentTimeMillis()); + if(startDate > 0 && endDate > 0){ + params.put("startDate",String.valueOf(startDate)); + params.put("endDate",String.valueOf(endDate)); + } + params.put("date",String.valueOf(System.currentTimeMillis())); + + + Call call = apiService.addICCard(params); + RetrofitAPIManager.enqueue(call, new TypeToken() { + }, result -> { + if (!result.success) { + makeToast("-add fail -" + result.getMsg()); + //if upload fail you should cache lockData and upload again until success,or you should reset lock and do init again. + return; + } + makeToast("-card is added success to server" ); + + + }, requestError -> { + makeToast(requestError.getMessage()); + }); + } + + + + private void getAllCards(){ + showConnectLockToast(); + TTLockClient.getDefault().getAllValidICCards(mCurrentLock.getLockData(), mCurrentLock.getLockMac(), new GetAllValidICCardCallback() { + @Override + public void onGetAllValidICCardSuccess(String cardDataStr) { + makeToast("-all ic cards info " + cardDataStr); + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + } + + private void clearAllCards(){ + showConnectLockToast(); + TTLockClient.getDefault().clearAllICCard(mCurrentLock.getLockData(), mCurrentLock.getLockMac(), new ClearAllICCardCallback() { + @Override + public void onClearAllICCardSuccess() { +// makeToast("--all ic cards have been cleared success-"); + //this must be done + uploadClear2Server(); + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + } + + private void uploadClear2Server(){ + ApiService apiService = RetrofitAPIManager.provideClientApi(); + + Call call = apiService.clearICCards(ApiService.CLIENT_ID, MyApplication.getmInstance().getAccountInfo().getAccess_token(), mCurrentLock.getLockId(),System.currentTimeMillis()); + RetrofitAPIManager.enqueue(call, new TypeToken(){}, result -> { + if(!result.success){ + makeToast("--clear my cards fail-" + result.getMsg()); + return; + } + + makeToast("-upload to server success-"); + + + }, requestError -> { + makeToast("--clear cards fail-" + requestError.getMessage()); + }); + } + + + + /** + * stopBTService should be called when Activity is finishing to release Bluetooth resource. + */ + @Override + public void onDestroy(){ + super.onDestroy(); + TTLockClient.getDefault().stopBTService(); + } +} diff --git a/app/src/main/java/ttlock/demo/iccard/ICCardListAdapter.java b/app/src/main/java/ttlock/demo/iccard/ICCardListAdapter.java new file mode 100644 index 0000000..eba3f0a --- /dev/null +++ b/app/src/main/java/ttlock/demo/iccard/ICCardListAdapter.java @@ -0,0 +1,84 @@ +package ttlock.demo.iccard; + +import android.app.Activity; +import android.databinding.DataBindingUtil; +import android.support.annotation.NonNull; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import java.util.ArrayList; + + +import ttlock.demo.R;; + +import ttlock.demo.databinding.AttachmentListItemBinding; + +import ttlock.demo.iccard.model.ICCardObj; + +/** + * Created on 2019/4/28 0028 17:07 + * + * @author theodre + */ +public class ICCardListAdapter extends RecyclerView.Adapter { + + public ArrayList mDataList = new ArrayList<>(); + private Activity mContext; + onListItemClick mListener; + public ICCardListAdapter (Activity context){ + mContext = context; + } + + interface onListItemClick{ + void onItemClick(ICCardObj cardObj); + } + + public void setOnListItemClick(onListItemClick listItemClick){ + this.mListener = listItemClick; + } + + public void updateData(ArrayList list){ + mDataList.clear(); + mDataList.addAll(list); + notifyDataSetChanged(); + } + + @NonNull + @Override + public CardViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View mView = LayoutInflater.from(mContext).inflate(R.layout.attachment_list_item,parent,false); + return new CardViewHolder(mView); + } + + @Override + public void onBindViewHolder(@NonNull CardViewHolder holder, int position) { + ICCardObj cardObj = mDataList.get(position); + holder.onBind(cardObj); + } + + @Override + public int getItemCount() { + return mDataList.size(); + } + + class CardViewHolder extends RecyclerView.ViewHolder { + + AttachmentListItemBinding itemBinding; + + public CardViewHolder(View itemView) { + super(itemView); + itemBinding = DataBindingUtil.bind(itemView); + } + + public void onBind(ICCardObj cardObj){ + itemBinding.tvItem.setText(cardObj.getCardName()); + itemBinding.tvItem.setOnClickListener(v -> { + if(mListener != null){ + mListener.onItemClick(cardObj); + } + }); + } + } +} diff --git a/app/src/main/java/ttlock/demo/iccard/ICCardModifyActivity.java b/app/src/main/java/ttlock/demo/iccard/ICCardModifyActivity.java new file mode 100644 index 0000000..0cc4346 --- /dev/null +++ b/app/src/main/java/ttlock/demo/iccard/ICCardModifyActivity.java @@ -0,0 +1,148 @@ +package ttlock.demo.iccard; + +import android.content.Context; +import android.content.Intent; +import android.databinding.DataBindingUtil; +import android.os.Bundle; + +import com.google.gson.reflect.TypeToken; +import com.ttlock.bl.sdk.api.TTLockClient; +import com.ttlock.bl.sdk.callback.DeleteICCardCallback; +import com.ttlock.bl.sdk.callback.ModifyICCardPeriodCallback; +import com.ttlock.bl.sdk.entity.LockError; + +import java.util.HashMap; + +import okhttp3.ResponseBody; +import retrofit2.Call; +import ttlock.demo.BaseActivity; +import ttlock.demo.MyApplication; + +import ttlock.demo.R;; + +import ttlock.demo.databinding.ActivityIccardModifyBinding; +import ttlock.demo.iccard.model.ICCardObj; +import ttlock.demo.retrofit.ApiService; +import ttlock.demo.retrofit.RetrofitAPIManager; + +public class ICCardModifyActivity extends BaseActivity { + + ActivityIccardModifyBinding binding; + ICCardObj mSelectCardObj; + private final static String SELECT_PARAM = "select_param"; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + binding = DataBindingUtil.setContentView(this,R.layout.activity_iccard_modify); + TTLockClient.getDefault().prepareBTService(getApplicationContext()); + mSelectCardObj = (ICCardObj)getIntent().getSerializableExtra(SELECT_PARAM); + initListener(); + } + + private void initListener(){ + binding.btnDeleteCard.setOnClickListener(v -> deleteCard()); + binding.btnModifyPeriod.setOnClickListener(v -> modifyPeriod()); + } + + public static void launch(Context context, ICCardObj cardObj){ + Intent intent = new Intent(context,ICCardModifyActivity.class); + intent.putExtra(SELECT_PARAM,cardObj); + context.startActivity(intent); + } + + private void modifyPeriod(){ + showConnectLockToast(); + long newStartDate = System.currentTimeMillis(); + long newEndDate = newStartDate + 5 * 60 * 1000; + TTLockClient.getDefault().modifyICCardValidityPeriod(newStartDate, newEndDate, mSelectCardObj.getCardNumber(), mCurrentLock.getLockData(), mCurrentLock.getLockMac(), new ModifyICCardPeriodCallback() { + @Override + public void onModifyICCardPeriodSuccess() { +// makeToast("-lock-modify success--"); + //this must be done to upload to server + notifyModifyDate2Server(newStartDate,newEndDate); + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + } + + + private void deleteCard(){ + showConnectLockToast(); + TTLockClient.getDefault().deleteICCard(mSelectCardObj.getCardNumber(), mCurrentLock.getLockData(), mCurrentLock.getLockMac(), new DeleteICCardCallback() { + @Override + public void onDeleteICCardSuccess() { + makeToast("--IC card is deleted-"); + //this must be done + notifyDelete2Server(); + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + } + + private void notifyDelete2Server(){ + ApiService apiService = RetrofitAPIManager.provideClientApi(); + HashMap param = new HashMap<>(6); + param.put("clientId",ApiService.CLIENT_ID); + param.put("accessToken",MyApplication.getmInstance().getAccountInfo().getAccess_token()); + param.put("lockId",String.valueOf(mCurrentLock.getLockId())); + param.put("cardId",String.valueOf(mSelectCardObj.getCardId())); + param.put("date",String.valueOf(System.currentTimeMillis())); + Call call = apiService.deleteICCard(param); + RetrofitAPIManager.enqueue(call, new TypeToken(){}, result -> { + if(!result.success){ + makeToast("--delete my card fail-" + result.getMsg()); + return; + } + + makeToast("-lock and server-delete success-"); + finish(); + + + }, requestError -> { + makeToast("--delete my card fail-" + requestError.getMessage()); + }); + } + + private void notifyModifyDate2Server(long startDate,long endDate){ + ApiService apiService = RetrofitAPIManager.provideClientApi(); + HashMap param = new HashMap<>(6); + param.put("clientId",ApiService.CLIENT_ID); + param.put("accessToken",MyApplication.getmInstance().getAccountInfo().getAccess_token()); + param.put("lockId",String.valueOf(mCurrentLock.getLockId())); + param.put("cardId",String.valueOf(mSelectCardObj.getCardId())); + param.put("startDate",String.valueOf(startDate)); + param.put("endDate",String.valueOf(endDate)); + param.put("date",String.valueOf(System.currentTimeMillis())); + Call call = apiService.modifyICCardPeriod(param); + RetrofitAPIManager.enqueue(call, new TypeToken(){}, result -> { + if(!result.success){ + makeToast("--modify my card fail-" + result.getMsg()); + return; + } + + makeToast("-lock and server-modified success-"); + + + }, requestError -> { + makeToast("--modify my card fail-" + requestError.getMessage()); + }); + } + + /** + * stopBTService should be called when Activity is finishing to release Bluetooth resource. + */ + @Override + public void onDestroy(){ + super.onDestroy(); + TTLockClient.getDefault().stopBTService(); + } + +} diff --git a/app/src/main/java/ttlock/demo/iccard/MyICCardListActivity.java b/app/src/main/java/ttlock/demo/iccard/MyICCardListActivity.java new file mode 100644 index 0000000..686b11c --- /dev/null +++ b/app/src/main/java/ttlock/demo/iccard/MyICCardListActivity.java @@ -0,0 +1,85 @@ +package ttlock.demo.iccard; + +import android.os.Bundle; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.util.Log; + +import com.google.gson.reflect.TypeToken; + +import java.util.ArrayList; +import java.util.HashMap; + +import okhttp3.ResponseBody; +import retrofit2.Call; +import ttlock.demo.BaseActivity; +import ttlock.demo.MyApplication; + +import ttlock.demo.R;; + +import ttlock.demo.iccard.model.ICCardListObj; +import ttlock.demo.iccard.model.ICCardObj; +import ttlock.demo.retrofit.ApiService; +import ttlock.demo.retrofit.RetrofitAPIManager; + +public class MyICCardListActivity extends BaseActivity implements ICCardListAdapter.onListItemClick{ + +// ActivityMyIccardListBinding binding; + ICCardListAdapter mListAdapter; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_my_iccard_list); + initView(); + } + + @Override + public void onResume(){ + super.onResume(); + getICCardList(); + } + + private void initView(){ + mListAdapter = new ICCardListAdapter(this); + RecyclerView rvCardList = findViewById(R.id.rv_card_list); + rvCardList.setAdapter(mListAdapter); + rvCardList.setLayoutManager(new LinearLayoutManager(this)); + mListAdapter.setOnListItemClick(this); + } + + private void getICCardList(){ + ApiService apiService = RetrofitAPIManager.provideClientApi(); + HashMap param = new HashMap<>(6); + param.put("clientId",ApiService.CLIENT_ID); + param.put("accessToken",MyApplication.getmInstance().getAccountInfo().getAccess_token()); + param.put("lockId",String.valueOf(mCurrentLock.getLockId())); + param.put("pageNo","1"); + param.put("pageSize","1000"); + param.put("date",String.valueOf(System.currentTimeMillis())); + + Call call = apiService.getUserICCardList(param); + RetrofitAPIManager.enqueue(call, new TypeToken(){}, result -> { + if(!result.success){ + makeToast("--get my fingerprint list fail-" + result.getMsg()); + return; + } + Log.d("OMG","===result===" + result.getResult() + "===" + result); + ICCardListObj icCardListObj = result.getResult(); + ArrayList myCardList = icCardListObj.getList(); + if(myCardList.isEmpty()){ + makeToast("- please add IC Card first --"); + } + mListAdapter.updateData(myCardList); + + }, requestError -> { + makeToast("--get my fingerprint list fail-" + requestError.getMessage()); + }); + } + + @Override + public void onItemClick(ICCardObj cardObj) { + if(cardObj != null){ + ICCardModifyActivity.launch(MyICCardListActivity.this,cardObj); + } + } +} diff --git a/app/src/main/java/ttlock/demo/iccard/model/ICCardListObj.java b/app/src/main/java/ttlock/demo/iccard/model/ICCardListObj.java new file mode 100644 index 0000000..4302b5b --- /dev/null +++ b/app/src/main/java/ttlock/demo/iccard/model/ICCardListObj.java @@ -0,0 +1,16 @@ +package ttlock.demo.iccard.model; + +import java.util.ArrayList; + +/** + * Created on 2019/4/28 0028 17:07 + * + * @author theodre + */ +public class ICCardListObj { + ArrayList list; + + public ArrayList getList() { + return list; + } +} diff --git a/app/src/main/java/ttlock/demo/iccard/model/ICCardObj.java b/app/src/main/java/ttlock/demo/iccard/model/ICCardObj.java new file mode 100644 index 0000000..8b4a027 --- /dev/null +++ b/app/src/main/java/ttlock/demo/iccard/model/ICCardObj.java @@ -0,0 +1,46 @@ +package ttlock.demo.iccard.model; + +import java.io.Serializable; + +/** + * Created on 2019/4/28 0028 17:07 + * + * @author theodre + */ +public class ICCardObj implements Serializable { + int cardId; + int lockId; + String cardNumber; + String cardName; + long startDate; + long endDate; + long createDate; + + public int getCardId() { + return cardId; + } + + public int getLockId() { + return lockId; + } + + public String getCardNumber() { + return cardNumber; + } + + public String getCardName() { + return cardName; + } + + public long getStartDate() { + return startDate; + } + + public long getEndDate() { + return endDate; + } + + public long getCreateDate() { + return createDate; + } +} diff --git a/app/src/main/java/ttlock/demo/lock/EnableDisableSomeLockFuncionActivity.java b/app/src/main/java/ttlock/demo/lock/EnableDisableSomeLockFuncionActivity.java new file mode 100644 index 0000000..d7081c3 --- /dev/null +++ b/app/src/main/java/ttlock/demo/lock/EnableDisableSomeLockFuncionActivity.java @@ -0,0 +1,165 @@ +package ttlock.demo.lock; + +import android.databinding.DataBindingUtil; +import android.os.Bundle; + +import com.ttlock.bl.sdk.api.TTLockClient; +import com.ttlock.bl.sdk.callback.GetLockMuteModeStateCallback; +import com.ttlock.bl.sdk.callback.GetRemoteUnlockStateCallback; +import com.ttlock.bl.sdk.callback.SetLockMuteModeCallback; +import com.ttlock.bl.sdk.callback.SetRemoteUnlockSwitchCallback; +import com.ttlock.bl.sdk.entity.LockError; +import com.ttlock.bl.sdk.util.DigitUtil; + +import ttlock.demo.BaseActivity; + +import ttlock.demo.R; + +import ttlock.demo.databinding.ActivityEnableDisableSomeLockFuncionBinding; + +public class EnableDisableSomeLockFuncionActivity extends BaseActivity { + ActivityEnableDisableSomeLockFuncionBinding binding; + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + binding = DataBindingUtil.setContentView(this,R.layout.activity_enable_disable_some_lock_funcion); + TTLockClient.getDefault().prepareBTService(getApplicationContext()); + initListener(); + } + + + private void initListener(){ + binding.btnGetMuteState.setOnClickListener(v -> { + if(!DigitUtil.isSupportAudioManagement(mCurrentLock.getSpecialValue())){ + makeToast("this lock does not support this feature"); + }else { + makeToast("get mute mode state.."); + getLockMuteModeState(); + } + }); + binding.swAudio.setOnCheckedChangeListener((buttonView, isChecked) -> { + if(!DigitUtil.isSupportAudioManagement(mCurrentLock.getSpecialValue())){ + makeToast("this lock does not support this feature"); + }else { + makeToast("switch mute mode..."); + setMuteMode(isChecked); + } + }); + + binding.btnRemoteUnlockState.setOnClickListener(v -> { + if(!DigitUtil.isSupportRemoteUnlockSwitch(mCurrentLock.getSpecialValue())){ + makeToast("this lock does not support this feature"); + }else { + makeToast("get remote unlock state.."); + getRemoteUnlockState(); + } + }); + + binding.swRemoteUnlock.setOnCheckedChangeListener((buttonView, isChecked) -> { + if(!DigitUtil.isSupportRemoteUnlockSwitch(mCurrentLock.getSpecialValue())){ + makeToast("this lock does not support this feature"); + }else { + makeToast("switch remote unlock function ..."); + setRemoteUnlockFunction(isChecked); + } + }); + } + + /** + * before query or set Lock Property such as setAudioSwitchState / setRemoteUnlockSwitchState,you should use specialValue to judge if the lock is support or not. + */ + private void getLockMuteModeState(){ + if(!DigitUtil.isSupportAudioManagement(mCurrentLock.getSpecialValue())){ + makeToast("this lock does not support mute mode"); + return; + } + + if(!TTLockClient.getDefault().isBLEEnabled(this)){ + return; + } + + TTLockClient.getDefault().getMuteModeState( mCurrentLock.getLockData(), mCurrentLock.getLockMac(), new GetLockMuteModeStateCallback() { + @Override + public void onGetMuteModeStateSuccess(boolean enabled) { + + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + } + + /** + * send data to Bluetooth should one by one.It only support one connect.So the TTLockSDK Api should be called one by one. + */ + private void getRemoteUnlockState(){ + if(!DigitUtil.isSupportAudioManagement(mCurrentLock.getSpecialValue())){ + makeToast("this lock does not support remote unlock"); + + return; + } + + TTLockClient.getDefault().getRemoteUnlockSwitchState( mCurrentLock.getLockData(), mCurrentLock.getLockMac(),new GetRemoteUnlockStateCallback() { + @Override + public void onGetRemoteUnlockSwitchStateSuccess(boolean enabled) { + + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + } + + /** + * set lock mute mode + * @param enable true means the lock will be mute,false means lock volume > 0. + */ + private void setMuteMode(boolean enable){ + TTLockClient.getDefault().setMuteMode(enable, mCurrentLock.getLockData(), mCurrentLock.getLockMac(),new SetLockMuteModeCallback() { + @Override + public void onSetMuteModeSuccess(boolean enabled) { + makeToast("--set lock mute state Success-is mute-" + enable); + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + } + + /** NOTICE !!!!!!!! + * remote unlock feature switch on/off will change the specialValue.So you should update the latest specialValue to your Server in time. + * @param enable the remote unlock feature on/off true means on,false means off. + */ + private void setRemoteUnlockFunction(final boolean enable){ + TTLockClient.getDefault().setRemoteUnlockSwitchState(enable, mCurrentLock.getLockData(), mCurrentLock.getLockMac(),new SetRemoteUnlockSwitchCallback() { + @Override + public void onSetRemoteUnlockSwitchSuccess(int specialValue) { + makeToast("--remote unlock switch has been changed success--specialValue is ===" + specialValue); + + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + } + + /** + * stopBTService should be called when Activity is finishing to release Bluetooth resource. + */ + @Override + public void onDestroy(){ + super.onDestroy(); + TTLockClient.getDefault().stopBTService(); + } + +} diff --git a/app/src/main/java/ttlock/demo/lock/LockApiActivity.java b/app/src/main/java/ttlock/demo/lock/LockApiActivity.java new file mode 100644 index 0000000..437d706 --- /dev/null +++ b/app/src/main/java/ttlock/demo/lock/LockApiActivity.java @@ -0,0 +1,251 @@ +package ttlock.demo.lock; + +import android.databinding.DataBindingUtil; +import android.os.Bundle; +import android.util.Log; + +import com.google.gson.reflect.TypeToken; +import com.ttlock.bl.sdk.api.TTLockClient; +import com.ttlock.bl.sdk.callback.GetBatteryLevelCallback; +import com.ttlock.bl.sdk.callback.GetLockStatusCallback; +import com.ttlock.bl.sdk.callback.GetLockSystemInfoCallback; +import com.ttlock.bl.sdk.callback.GetOperationLogCallback; +import com.ttlock.bl.sdk.callback.ResetKeyCallback; +import com.ttlock.bl.sdk.callback.ResetLockCallback; +import com.ttlock.bl.sdk.callback.SetAutoLockingPeriodCallback; +import com.ttlock.bl.sdk.constant.LogType; +import com.ttlock.bl.sdk.entity.DeviceInfo; +import com.ttlock.bl.sdk.entity.LockError; +import com.ttlock.bl.sdk.util.DigitUtil; + +import okhttp3.ResponseBody; +import retrofit2.Call; +import ttlock.demo.BaseActivity; +import ttlock.demo.MyApplication; + +import ttlock.demo.R;; + +import ttlock.demo.databinding.ActivityLockApiBinding; +import ttlock.demo.retrofit.ApiService; +import ttlock.demo.retrofit.RetrofitAPIManager; + +public class LockApiActivity extends BaseActivity { + + ActivityLockApiBinding binding; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + binding = DataBindingUtil.setContentView(this,R.layout.activity_lock_api); + if(mCurrentLock == null){ + makeToast("please choose at least one initialized lock first"); + } + /** + * this should be called first,to make sure Bluetooth configuration is ready. + */ + TTLockClient.getDefault().prepareBTService(getApplicationContext()); + initListener(); + } + + + private void initListener(){ + binding.btnResetKey.setOnClickListener(v -> resetEKey()); + binding.btnResetLock.setOnClickListener(v -> resetLock()); + binding.btnUnlock.setOnClickListener(v -> startTargetActivity(UnlockActivity.class)); + binding.btnLockProperty.setOnClickListener(v -> startTargetActivity(EnableDisableSomeLockFuncionActivity.class)); + binding.btnPassageMode.setOnClickListener(v -> startTargetActivity(PassageModeActivity.class)); + binding.btnTime.setOnClickListener(v -> startTargetActivity(LockTimeActivity.class)); + binding.btnLog.setOnClickListener(v -> getOperationLog()); + binding.btnBattery.setOnClickListener(v -> getLockBatteryLevel()); + binding.btnLockInfo.setOnClickListener(v -> getLockSystemInfo()); + binding.btnLockStatus.setOnClickListener(v -> getLockStatus()); + binding.btnSetAutoLockTime.setOnClickListener(v -> setAutoLockingPeriod()); + } + + /** + * ensure Bluetooth is enabled + * + * NOTICE !!!!!!!! + * after resetEKey success,the lockFlagPos should upload to Server to update lock data. + */ + private void resetEKey(){ + ensureBluetoothIsEnabled(); + showConnectLockToast(); + TTLockClient.getDefault().resetEkey(mCurrentLock.getLockData(),mCurrentLock.getLockMac(), new ResetKeyCallback() { + @Override + public void onResetKeySuccess(int lockFlagPos) { + uploadResetEkeyResult2Server(); + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + } + + /** + * call https://api.sciener.cn/v3/lock/resetKey this api to notify server resetKey has been done. + * + */ + private void uploadResetEkeyResult2Server(){ + ApiService apiService = RetrofitAPIManager.provideClientApi(); + Call call = apiService.restEkey(ApiService.CLIENT_ID, MyApplication.getmInstance().getAccountInfo().getAccess_token(), mCurrentLock.getLockId(),System.currentTimeMillis()); + RetrofitAPIManager.enqueue(call, new TypeToken() { + }, result -> { + if (!result.success) { + makeToast("-init fail-upload to server-" + result.getMsg()); + //if upload fail you should cache lockData and upload again until success,or you should reset lock and do init again. + return; + } + makeToast("--reset key and notify server success--"); + + }, requestError -> { + makeToast(requestError.getMessage()); + }); + } + + /** + * resetLock + * means the lock will be reset to factory mode and if you want to use it,you should do initLock. + */ + private void resetLock(){ + ensureBluetoothIsEnabled(); + showConnectLockToast(); + TTLockClient.getDefault().resetLock(mCurrentLock.getLockData(), mCurrentLock.getLockMac(),new ResetLockCallback() { + @Override + public void onResetLockSuccess() { + makeToast("-lock is reset and now upload to server -"); + uploadResetLock2Server(); + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + } + + /** + * this must be done after resetLock is called success. + */ + private void uploadResetLock2Server(){ + ApiService apiService = RetrofitAPIManager.provideClientApi(); + Call call = apiService.deleteLock(ApiService.CLIENT_ID, MyApplication.getmInstance().getAccountInfo().getAccess_token(), mCurrentLock.getLockId(),System.currentTimeMillis()); + RetrofitAPIManager.enqueue(call, new TypeToken() { + }, result -> { + if (!result.success) { + makeToast("-reset lock -" + result.getMsg()); + //if upload fail you should cache lockData and upload again until success,or you should reset lock and do init again. + return; + } + makeToast("--reset lock and notify server success--"); + + }, requestError -> { + makeToast(requestError.getMessage()); + }); + } + + /** + * logType ALL - all the operation record from lock is initialized. + * NEW - only the new added operation record from last time you get log. + */ + private void getOperationLog(){ + showConnectLockToast(); + TTLockClient.getDefault().getOperationLog(LogType.NEW, mCurrentLock.getLockData(),mCurrentLock.getLockMac(), new GetOperationLogCallback() { + @Override + public void onGetLogSuccess(String log) { + makeToast("Get log success!"); + Log.d("OMG","===log==" + log); + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + } + + private void getLockBatteryLevel(){ + showConnectLockToast(); + TTLockClient.getDefault().getBatteryLevel(mCurrentLock.getLockData(),mCurrentLock.getLockMac(), new GetBatteryLevelCallback() { + @Override + public void onGetBatteryLevelSuccess(int electricQuantity) { + makeToast("lock battery is " + electricQuantity + "%"); + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + } + + private void getLockSystemInfo(){ + showConnectLockToast(); + TTLockClient.getDefault().getLockSystemInfo(mCurrentLock.getLockData(), mCurrentLock.getLockMac(),new GetLockSystemInfoCallback() { + @Override + public void onGetLockSystemInfoSuccess(DeviceInfo info) { + makeToast(info.toString()); + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + } + + /** + * query lock status,such as unlock,lock. + * + * status :0-lock 1-unlock 2-unknown status 3-unlocked,has car top(this is only for car parking lock) + */ + private void getLockStatus(){ + showConnectLockToast(); + TTLockClient.getDefault().getLockStatus(mCurrentLock.getLockData(),mCurrentLock.getLockMac(), new GetLockStatusCallback() { + @Override + public void onGetLockStatusSuccess(int status) { + makeToast("lock status is now " + status); + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + } + + /** + * set Automatic locking period. + * + */ + private void setAutoLockingPeriod(){ + if(!DigitUtil.isSupportAutoLock(mCurrentLock.getSpecialValue())){ + makeToast("this lock dose not support automatic locking"); + } + showConnectLockToast(); + TTLockClient.getDefault().setAutomaticLockingPeriod(5, mCurrentLock.getLockData(), mCurrentLock.getLockMac(),new SetAutoLockingPeriodCallback() { + @Override + public void onSetAutoLockingPeriodSuccess() { + makeToast("set automatic locking period success"); + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + } + + + + /** + * stopBTService should be called when Activity is finishing to release Bluetooth resource. + */ + @Override + public void onDestroy(){ + super.onDestroy(); + TTLockClient.getDefault().stopBTService(); + } +} diff --git a/app/src/main/java/ttlock/demo/lock/LockTimeActivity.java b/app/src/main/java/ttlock/demo/lock/LockTimeActivity.java new file mode 100644 index 0000000..06f6896 --- /dev/null +++ b/app/src/main/java/ttlock/demo/lock/LockTimeActivity.java @@ -0,0 +1,94 @@ +package ttlock.demo.lock; + +import android.databinding.DataBindingUtil; +import android.os.Bundle; + +import com.ttlock.bl.sdk.api.TTLockClient; +import com.ttlock.bl.sdk.callback.GetLockTimeCallback; +import com.ttlock.bl.sdk.callback.SetLockTimeCallback; +import com.ttlock.bl.sdk.entity.LockError; + +import ttlock.demo.BaseActivity; + +import ttlock.demo.R;; + +import ttlock.demo.databinding.ActivityLockTimeBinding; + +public class LockTimeActivity extends BaseActivity { + + ActivityLockTimeBinding binding; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + binding = DataBindingUtil.setContentView(this,R.layout.activity_lock_time); + if(mCurrentLock == null){ + makeToast("please choose at least one initialized lock first"); + } + initListener(); + } + + private void initListener(){ + binding.btnGetTime.setOnClickListener(v -> getLockTime()); + binding.btnSetLockTime.setOnClickListener(v -> setLockTime()); + } + + private void getLockTime(){ + if(!TTLockClient.getDefault().isBLEEnabled(this)){ + /** + * this operation is asynchronous,so make sure Bluetooth is enabled before call TTLock api. + */ + TTLockClient.getDefault().requestBleEnable(this); + } + makeToast("is query time of lock.."); + TTLockClient.getDefault().getLockTime(mCurrentLock.getLockData(),mCurrentLock.getLockMac(), new GetLockTimeCallback() { + @Override + public void onGetLockTimeSuccess(long lockTimestamp) { + binding.tvLockTime.setText(getResources().getString(R.string.lock_time_is) + getDateFormat(lockTimestamp)); + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + + } + + private void setLockTime(){ + if(!TTLockClient.getDefault().isBLEEnabled(this)){ + /** + * this operation is asynchronous,so make sure Bluetooth is enabled before call TTLock api. + */ + TTLockClient.getDefault().requestBleEnable(this); + } + + makeToast("is correcting lock time.."); + + /** + * the time you want to correct lock time ,should be get from your server. + */ + long currentTimeStamp = System.currentTimeMillis(); + TTLockClient.getDefault().setLockTime(currentTimeStamp, mCurrentLock.getLockData(),mCurrentLock.getLockMac(), new SetLockTimeCallback() { + @Override + public void onSetTimeSuccess() { + makeToast("lock time is corrected"); + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + } + + + + @Override + public void onDestroy(){ + super.onDestroy(); + /** + * BT service should be released before Activity finished. + */ + TTLockClient.getDefault().stopBTService(); + } +} diff --git a/app/src/main/java/ttlock/demo/lock/PassageModeActivity.java b/app/src/main/java/ttlock/demo/lock/PassageModeActivity.java new file mode 100644 index 0000000..26fda76 --- /dev/null +++ b/app/src/main/java/ttlock/demo/lock/PassageModeActivity.java @@ -0,0 +1,128 @@ +package ttlock.demo.lock; + + +import android.databinding.DataBindingUtil; + +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; + +import ttlock.demo.R; + + +import com.ttlock.bl.sdk.api.TTLockClient; +import com.ttlock.bl.sdk.callback.ClearPassageModeCallback; +import com.ttlock.bl.sdk.callback.DeletePassageModeCallback; +import com.ttlock.bl.sdk.callback.GetPassageModeCallback; +import com.ttlock.bl.sdk.callback.SetPassageModeCallback; +import com.ttlock.bl.sdk.entity.LockError; +import com.ttlock.bl.sdk.entity.PassageModeConfig; +import com.ttlock.bl.sdk.entity.PassageModeType; +import com.ttlock.bl.sdk.util.GsonUtil; + + +import ttlock.demo.BaseActivity; +import ttlock.demo.R; +import ttlock.demo.databinding.ActivityPassageModeBinding; + +public class PassageModeActivity extends BaseActivity { + + ActivityPassageModeBinding binding; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + binding = DataBindingUtil.setContentView(this,R.layout.activity_passage_mode); + /** + * this should be called first,to make sure Bluetooth configuration is ready. + */ + ensureBluetoothIsEnabled(); + TTLockClient.getDefault().prepareBTService(getApplicationContext()); + initListener(); + } + + private void initListener(){ + binding.btnGet.setOnClickListener(v -> getPassageModeSettingInLock()); + binding.btnSet.setOnClickListener(v -> setPassageMode2Lock()); + binding.btnDelete.setOnClickListener(v -> deleteOnePassageModeSetting()); + binding.btnClear.setOnClickListener(v -> clearAllPassageModeInLock()); + } + + private void getPassageModeSettingInLock(){ + showConnectLockToast(); + TTLockClient.getDefault().getPassageMode(mCurrentLock.getLockData(), mCurrentLock.getLockMac(), new GetPassageModeCallback() { + @Override + public void onGetPassageModeSuccess(String passageModeData) { + makeToast("--get--success--" + passageModeData); + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + } + + /** + * PassageModeConfig params: + * type PassageModeType + * weekly effective value from 1 to 7,1 means Monday 2 means Tuesday ,...,7 means Sunday + * monthly effective value ║from 1 to 12 + */ + private void setPassageMode2Lock(){ + PassageModeConfig modeData = new PassageModeConfig(); + modeData.setStartDate(System.currentTimeMillis()); + modeData.setEndDate(System.currentTimeMillis() + 7 * 24 * 60 * 60 * 1000); + modeData.setModeType(PassageModeType.Weekly); + //if mode is Weekly,then the WeekDays is + int[] mCircleWeeksArray = {1,2,3,4,5}; + modeData.setRepeatWeekOrDays(GsonUtil.toJson(mCircleWeeksArray)); + showConnectLockToast(); + TTLockClient.getDefault().setPassageMode(modeData, mCurrentLock.getLockData(), mCurrentLock.getLockMac(), new SetPassageModeCallback() { + @Override + public void onSetPassageModeSuccess() { + makeToast("-set passage mode success-"); + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + } + + private void deleteOnePassageModeSetting(){ + PassageModeConfig modeData = new PassageModeConfig(); + modeData.setStartDate(System.currentTimeMillis()); + modeData.setEndDate(System.currentTimeMillis() + 7 * 24 * 60 * 60 * 1000); + modeData.setModeType(PassageModeType.Weekly); + //if mode is Weekly,then the WeekDays is + int[] mCircleWeeksArray = {2,3,4,5,6}; + modeData.setRepeatWeekOrDays(GsonUtil.toJson(mCircleWeeksArray)); + showConnectLockToast(); + TTLockClient.getDefault().deletePassageMode(modeData, mCurrentLock.getLockData(), mCurrentLock.getLockMac(), new DeletePassageModeCallback() { + @Override + public void onDeletePassageModeSuccess() { + makeToast("-delete passage mode success-"); + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + } + + private void clearAllPassageModeInLock(){ + showConnectLockToast(); + TTLockClient.getDefault().clearPassageMode(mCurrentLock.getLockData(), mCurrentLock.getLockMac(), new ClearPassageModeCallback() { + @Override + public void onClearPassageModeSuccess() { + makeToast("--all passage mode are cleared success-"); + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + } +} diff --git a/app/src/main/java/ttlock/demo/lock/ScanLockActivity.java b/app/src/main/java/ttlock/demo/lock/ScanLockActivity.java new file mode 100644 index 0000000..e4dd169 --- /dev/null +++ b/app/src/main/java/ttlock/demo/lock/ScanLockActivity.java @@ -0,0 +1,216 @@ +package ttlock.demo.lock; + +import android.Manifest; +import android.annotation.TargetApi; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.databinding.DataBindingUtil; +import android.os.Build; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.v4.content.ContextCompat; +import android.support.v7.widget.LinearLayoutManager; +import android.util.Log; + +import com.google.gson.reflect.TypeToken; +import com.ttlock.bl.sdk.api.TTLockClient; +import com.ttlock.bl.sdk.callback.InitLockCallback; +import com.ttlock.bl.sdk.callback.ScanLockCallback; +import com.ttlock.bl.sdk.callback.SetNBServerCallback; +import com.ttlock.bl.sdk.constant.Feature; +import com.ttlock.bl.sdk.entity.LockError; +import com.ttlock.bl.sdk.api.ExtendedBluetoothDevice; + +import com.ttlock.bl.sdk.util.SpecialValueUtil; + +import okhttp3.ResponseBody; +import retrofit2.Call; +import ttlock.demo.BaseActivity; +import ttlock.demo.MyApplication; +import ttlock.demo.R; + +import ttlock.demo.databinding.ActivityScanLockBinding; +import ttlock.demo.lock.adapter.LockListAdapter; +import ttlock.demo.lock.model.LockInitResultObj; +import ttlock.demo.retrofit.ApiService; +import ttlock.demo.retrofit.RetrofitAPIManager; + +public class ScanLockActivity extends BaseActivity implements LockListAdapter.onLockItemClick{ + ActivityScanLockBinding binding; + protected static final int REQUEST_PERMISSION_REQ_CODE = 11; + private LockListAdapter mListApapter; + private String mInitLockData; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + binding = DataBindingUtil.setContentView(this,R.layout.activity_scan_lock); + initList(); + initBtService(); + initListener(); + + } + + private void initList(){ + mListApapter = new LockListAdapter(this); + binding.rvLockList.setAdapter(mListApapter); + binding.rvLockList.setLayoutManager(new LinearLayoutManager(this)); + mListApapter.setOnLockItemClick(this); + } + + /** + * prepareBTService should be called first,or all TTLock SDK function will not be run correctly + */ + private void initBtService(){ + TTLockClient.getDefault().prepareBTService(getApplicationContext()); + } + + private void initListener(){ + binding.btnEnableBle.setOnClickListener(v -> { + boolean isBtEnable = TTLockClient.getDefault().isBLEEnabled(ScanLockActivity.this); + if(!isBtEnable){ + TTLockClient.getDefault().requestBleEnable(ScanLockActivity.this); + } + }); + + binding.btnStartScan.setOnClickListener(v -> startScan()); + binding.btnStopScan.setOnClickListener(v -> TTLockClient.getDefault().stopScanLock()); + } + + + /** + * before call startScanLock,the location permission should be granted. + */ + @TargetApi(Build.VERSION_CODES.M) + private void startScan(){ + if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, REQUEST_PERMISSION_REQ_CODE); + return; + } + + getScanLockCallback(); + } + + /** + * start scan BT lock + */ + private void getScanLockCallback(){ + TTLockClient.getDefault().startScanLock(new ScanLockCallback() { + @Override + public void onScanLockSuccess(ExtendedBluetoothDevice device) { + if(mListApapter != null){ + mListApapter.updateData(device); + } + } + }); + } + + @Override + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults); + if(grantResults.length == 0 ){ + + return; + } + + switch (requestCode) { + case REQUEST_PERMISSION_REQ_CODE: { + if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { + getScanLockCallback(); + } else { + if (permissions[0].equals(Manifest.permission.ACCESS_COARSE_LOCATION)){ + + } + } + break; + } + default: + break; + } + } + + @Override + public void onDestroy(){ + super.onDestroy(); + /** + * BT service should be released before Activity finished. + */ + TTLockClient.getDefault().stopBTService(); + } + + @Override + public void onClick(ExtendedBluetoothDevice device) { + makeToast("--start init lock--"); + /** + * lockData: the server api lockData param need + * isNBLock: is a NB-IoT lock. + */ + TTLockClient.getDefault().initLock(device, new InitLockCallback() { + @Override + public void onInitLockSuccess(String lockData,int specialValue) { + Log.d("OMG","-init -success-lockData-isNBLock-" + SpecialValueUtil.isSupportFeature(specialValue,Feature.NB_LOCK)); + //this must be done after lock is initialized,call server api to post to your server + if(SpecialValueUtil.isSupportFeature(specialValue,Feature.NB_LOCK)){ + setNBServerForNBLock(lockData,device.getAddress()); + }else { + makeToast("--lock is initialized success--"); + upload2Server(lockData); + } + + + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + } + + /** + * if a NB-IoT lock you'd better do set NB-IoT server before upload lockData to server to active NB-IoT lock service. + * And no matter callback is success or fail,upload lockData to server. + * @param lockData + * @param lockMac + */ + private void setNBServerForNBLock(String lockData,String lockMac){ + //NB server port + short mNBServerPort = 8011; + String mNBServerAddress = "192.127.123.11"; + TTLockClient.getDefault().setNBServerInfo(mNBServerPort, mNBServerAddress, lockData, lockMac, new SetNBServerCallback() { + @Override + public void onSetNBServerSuccess(int battery) { + makeToast("--set NB server success--"); + upload2Server(lockData); + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + //no matter callback is success or fail,upload lockData to server. + upload2Server(lockData); + } + }); + } + + private void upload2Server(String lockData){ + String lockAlias = "MyTestLock"; + ApiService apiService = RetrofitAPIManager.provideClientApi(); + Call call = apiService.lockInit(ApiService.CLIENT_ID, MyApplication.getmInstance().getAccountInfo().getAccess_token(), lockData,lockAlias,System.currentTimeMillis()); + RetrofitAPIManager.enqueue(call, new TypeToken() { + }, result -> { + if (!result.success) { + makeToast("-init fail-to server-" + result.getMsg()); + //if upload fail you should cache lockData and upload again until success,or you should reset lock and do init again. + return; + } + makeToast("--init lock success--"); + Intent intent = new Intent(this,UserLockActivity.class); + startActivity(intent); + finish(); + + }, requestError -> { + + }); + } +} diff --git a/app/src/main/java/ttlock/demo/lock/UnlockActivity.java b/app/src/main/java/ttlock/demo/lock/UnlockActivity.java new file mode 100644 index 0000000..9d0dcca --- /dev/null +++ b/app/src/main/java/ttlock/demo/lock/UnlockActivity.java @@ -0,0 +1,137 @@ +package ttlock.demo.lock; + +import android.databinding.DataBindingUtil; +import android.os.Bundle; +import android.util.Log; +import android.widget.Toast; + +import com.google.gson.reflect.TypeToken; +import com.ttlock.bl.sdk.api.TTLockClient; +import com.ttlock.bl.sdk.callback.ControlLockCallback; +import com.ttlock.bl.sdk.constant.ControlAction; +import com.ttlock.bl.sdk.entity.LockError; + +import java.util.ArrayList; +import java.util.HashMap; + +import okhttp3.ResponseBody; +import retrofit2.Call; +import ttlock.demo.databinding.ActivityUnlockBinding; +import ttlock.demo.BaseActivity; +import ttlock.demo.MyApplication; +import ttlock.demo.R; + +import ttlock.demo.databinding.ActivityUnlockBinding; + +import ttlock.demo.lock.model.KeyListObj; +import ttlock.demo.lock.model.KeyObj; +import ttlock.demo.retrofit.ApiService; +import ttlock.demo.retrofit.RetrofitAPIManager; + +public class UnlockActivity extends BaseActivity { + ActivityUnlockBinding binding; + //demo only add one lock,so we just get key for one lock,and the key is admin key. + KeyObj mMyTestLockEKey; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + getUserKeyList(); + binding = DataBindingUtil.setContentView(this, R.layout.activity_unlock); + TTLockClient.getDefault().prepareBTService(getApplicationContext()); + initListener(); + } + + private void initListener(){ + binding.btnUnlock.setOnClickListener(v -> doUnlock()); + binding.btnLock.setOnClickListener(v -> doLockLock()); + } + + //user should get a key list and show them with a list.In demo,we just have one admin key. + private void getUserKeyList(){ + ApiService apiService = RetrofitAPIManager.provideClientApi(); + HashMap param = new HashMap<>(6); + param.put("clientId",ApiService.CLIENT_ID); + param.put("accessToken",MyApplication.getmInstance().getAccountInfo().getAccess_token()); + param.put("pageNo","1"); + param.put("pageSize","1000"); + param.put("date",String.valueOf(System.currentTimeMillis())); + + Call call = apiService.getUserKeyList(param); + RetrofitAPIManager.enqueue(call, new TypeToken(){}, result -> { + if(!result.success){ + makeToast("--get my key list fail-" + result.getMsg()); + return; + } + Log.d("OMG","===result===" + result.getResult() + "===" + result); + KeyListObj keyListObj = result.getResult(); + ArrayList myKeyList = keyListObj.getList(); + if(!myKeyList.isEmpty()){ + for(KeyObj keyObj : myKeyList){ + if(keyObj.getLockId() == mCurrentLock.getLockId()){ + mMyTestLockEKey = keyObj; + } + } + } + }, requestError -> { + makeToast("--get key list fail-" + requestError.getMessage()); + }); + } + + /** + * use eKey for controlLock interface + */ + private void doUnlock(){ + if(mMyTestLockEKey == null){ + makeToast(" you should get your key list first "); + return; + } + ensureBluetoothIsEnabled(); + showConnectLockToast(); + TTLockClient.getDefault().controlLock(ControlAction.UNLOCK, mMyTestLockEKey.getLockData(), mMyTestLockEKey.getLockMac(),new ControlLockCallback() { + @Override + public void onControlLockSuccess(int lockAction, int battery, int uniqueId) { + Toast.makeText(UnlockActivity.this,"lock is unlock success!",Toast.LENGTH_LONG).show(); + } + + @Override + public void onFail(LockError error) { + Toast.makeText(UnlockActivity.this,"unLock fail!--" + error.getDescription(),Toast.LENGTH_LONG).show(); + } + }); + } + + /** + * use eKey for controlLock interface + */ + private void doLockLock(){ + if(mMyTestLockEKey == null){ + makeToast(" you should get your key list first "); + return; + } + ensureBluetoothIsEnabled(); + showConnectLockToast(); + TTLockClient.getDefault().controlLock(ControlAction.LOCK, mMyTestLockEKey.getLockData(), mMyTestLockEKey.getLockMac(),new ControlLockCallback() { + @Override + public void onControlLockSuccess(int lockAction, int battery, int uniqueId) { + Toast.makeText(UnlockActivity.this,"lock is locked!",Toast.LENGTH_LONG).show(); + } + + @Override + public void onFail(LockError error) { + Toast.makeText(UnlockActivity.this,"lock lock fail!--" + error.getDescription(),Toast.LENGTH_LONG).show(); + } + }); + } + + + /** + * stopBTService should be called when Activity is finishing to release Bluetooth resource. + */ + @Override + public void onDestroy(){ + super.onDestroy(); + TTLockClient.getDefault().stopBTService(); + } + + +} diff --git a/app/src/main/java/ttlock/demo/lock/UserLockActivity.java b/app/src/main/java/ttlock/demo/lock/UserLockActivity.java new file mode 100644 index 0000000..f1a6812 --- /dev/null +++ b/app/src/main/java/ttlock/demo/lock/UserLockActivity.java @@ -0,0 +1,78 @@ +package ttlock.demo.lock; + +import android.databinding.DataBindingUtil; +import android.os.Bundle; +import android.support.v7.widget.LinearLayoutManager; + +import com.google.gson.reflect.TypeToken; +import com.ttlock.bl.sdk.util.GsonUtil; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; + +import retrofit2.Call; +import retrofit2.Callback; +import ttlock.demo.BaseActivity; +import ttlock.demo.MyApplication; + +import ttlock.demo.R;; + +import ttlock.demo.databinding.ActivityUserLockBinding; +import ttlock.demo.lock.adapter.UserLockListAdapter; +import ttlock.demo.model.LockObj; +import ttlock.demo.retrofit.ApiService; +import ttlock.demo.retrofit.RetrofitAPIManager; + +public class UserLockActivity extends BaseActivity { + + private int pageNo = 1; + private int pageSize = 100; + private UserLockListAdapter mListApapter; + ActivityUserLockBinding binding; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + binding = DataBindingUtil.setContentView(this, R.layout.activity_user_lock); + initList(); + lockList(); + binding.btnScan.setOnClickListener(v -> startTargetActivity(ScanLockActivity.class)); + } + + private void initList(){ + mListApapter = new UserLockListAdapter(this); + binding.rvLockList.setAdapter(mListApapter); + binding.rvLockList.setLayoutManager(new LinearLayoutManager(this)); + } + + private void lockList() { + ApiService apiService = RetrofitAPIManager.provideClientApi(); + Call call = apiService.getLockList(ApiService.CLIENT_ID, MyApplication.getmInstance().getAccountInfo().getAccess_token(), pageNo, pageSize, System.currentTimeMillis()); + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, retrofit2.Response response) { + String json = response.body(); + if (json.contains("list")) { + try { + JSONObject jsonObject = new JSONObject(json); + JSONArray array = jsonObject.getJSONArray("list"); + ArrayList lockObjs = GsonUtil.toObject(array.toString(), new TypeToken>(){}); + mListApapter.updateData(lockObjs); + } catch (JSONException e) { + e.printStackTrace(); + } + } else { + makeToast(json); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + makeToast(t.getMessage()); + } + }); + } +} diff --git a/app/src/main/java/ttlock/demo/lock/adapter/LockListAdapter.java b/app/src/main/java/ttlock/demo/lock/adapter/LockListAdapter.java new file mode 100644 index 0000000..5c1f0df --- /dev/null +++ b/app/src/main/java/ttlock/demo/lock/adapter/LockListAdapter.java @@ -0,0 +1,185 @@ +package ttlock.demo.lock.adapter; + +import android.app.Activity; +import android.databinding.DataBindingUtil; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import com.ttlock.bl.sdk.api.ExtendedBluetoothDevice; + +import java.util.LinkedList; + +import ttlock.demo.R; + +import ttlock.demo.databinding.LockAddListItemBinding; + +/** + * Created on 2019/4/12 0012 14:19 + * + * @author theodre + */ +public class LockListAdapter extends RecyclerView.Adapter{ + + private LinkedList mDataList = new LinkedList<>(); + + private Activity mContext; + private static final int TIMEOUT = 5000; + private LinkedList mAddStatusList = new LinkedList<>(); + private LinkedList mNormalStatusList = new LinkedList<>(); + private long lastSyncTimeStamp = 0; + private onLockItemClick mListener; + public interface onLockItemClick { + void onClick(ExtendedBluetoothDevice device); + } + + public void setOnLockItemClick(onLockItemClick click){ + this.mListener = click; + } + + public LockListAdapter (Activity context){ + mContext = context; + } + + public synchronized void updateData(ExtendedBluetoothDevice device){ + if(device != null) { + if(device.isSettingMode()){ + addOrSortLock(device,mAddStatusList); + removeOtherStatusLock(device,mNormalStatusList); + }else { + addOrSortLock(device,mNormalStatusList); + removeOtherStatusLock(device,mAddStatusList); + } + + long currentTime = System.currentTimeMillis(); + if((currentTime - lastSyncTimeStamp) >= 800 ){ + if(!mDataList.isEmpty()){ + mDataList.clear(); + } + + mDataList.addAll(0,mAddStatusList); + mDataList.addAll(mNormalStatusList); + notifyDataSetChanged(); + lastSyncTimeStamp = currentTime; + } + } + } + + + /** + * you can sort the lock that be discovered by signal value. + */ + private void addOrSortLock(ExtendedBluetoothDevice scanDevice,LinkedList lockList){ + boolean isContained = false; + int length = lockList.size(); + ExtendedBluetoothDevice mTopOneDevice; + scanDevice.setDate(System.currentTimeMillis()); + if(length > 0){ + + mTopOneDevice = lockList.get(0); + + for(int i = 0;i < length;i++) { + + ExtendedBluetoothDevice currentDevice = lockList.get(i); + + if(scanDevice.getAddress().equals(currentDevice.getAddress()) ){ + isContained = true; + if(i != 0 && scanDevice.getRssi() > mTopOneDevice.getRssi()){ + lockList.remove(i); + lockList.add(0,scanDevice); + }else { + currentDevice.setDate(System.currentTimeMillis()); + lockList.set(i,currentDevice); + } + }else { + if(System.currentTimeMillis() - currentDevice.getDate() >= TIMEOUT) { + lockList.remove(i); + length = lockList.size(); + } + } + } + + if(!isContained){ + if(scanDevice.getRssi() > mTopOneDevice.getRssi()){ + lockList.add(0,scanDevice); + }else { + lockList.add(scanDevice); + } + } + + }else { + lockList.add(scanDevice); + } + + } + + /** + * the lock mode will be changed,so should update the list when lock mode changed. + * @param scanDevice the lock that be discovered. + */ + private void removeOtherStatusLock(ExtendedBluetoothDevice scanDevice,LinkedList lockList){ + if(!lockList.isEmpty()){ + int length = lockList.size(); + for(int i = 0; i < length ; i++){ + ExtendedBluetoothDevice device = lockList.get(i); + if(device.getAddress().equals(scanDevice.getAddress())){ + lockList.remove(i); + length --; + }else { + if(System.currentTimeMillis() - device.getDate() >= TIMEOUT) { + lockList.remove(i); + length --; + } + } + } + } + } + + @Override + public DeviceViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View mView = LayoutInflater.from(mContext).inflate(R.layout.lock_add_list_item, parent, false); + return new DeviceViewHolder(mView); + } + + @Override + public void onBindViewHolder(DeviceViewHolder _holder, int position) { + final ExtendedBluetoothDevice item = mDataList.get(position); + _holder.Bind(item); + } + + @Override + public int getItemCount() { + return mDataList.size(); + } + + class DeviceViewHolder extends RecyclerView.ViewHolder { + + LockAddListItemBinding itemBinding; + + + public DeviceViewHolder(View itemView){ + super(itemView); + itemBinding = DataBindingUtil.bind(itemView); + } + + public void Bind(ExtendedBluetoothDevice item){ + itemBinding.tvLockName.setText(item.getName()); + itemBinding.ivSettingMode.setVisibility(item.isSettingMode() ? View.VISIBLE : View.GONE); + + if(item.isSettingMode()){ + itemBinding.getRoot().setOnClickListener(view -> { + if(!item.isSettingMode()){ + return; + } + if(mListener != null){ + mListener.onClick(item); + } + + }); + } + } + + } + +} diff --git a/app/src/main/java/ttlock/demo/lock/adapter/UserLockListAdapter.java b/app/src/main/java/ttlock/demo/lock/adapter/UserLockListAdapter.java new file mode 100644 index 0000000..9b37db2 --- /dev/null +++ b/app/src/main/java/ttlock/demo/lock/adapter/UserLockListAdapter.java @@ -0,0 +1,77 @@ +package ttlock.demo.lock.adapter; + +import android.content.Context; +import android.databinding.DataBindingUtil; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import java.util.ArrayList; + +import ttlock.demo.BaseActivity; +import ttlock.demo.MainActivity; +import ttlock.demo.MyApplication; + +import ttlock.demo.R;; + +import ttlock.demo.databinding.UserLockListItemBinding; +import ttlock.demo.model.LockObj; + +/** + * Created on 2019/4/12 0012 14:19 + * + * @author theodre + */ +public class UserLockListAdapter extends RecyclerView.Adapter{ + + public ArrayList mDataList = new ArrayList<>(); + + private Context mContext; + public UserLockListAdapter(Context context){ + mContext = context; + } + + public void updateData(ArrayList lockList) { + if (lockList != null) { + mDataList.clear(); + mDataList.addAll(lockList); + notifyDataSetChanged(); + } + } + + @Override + public DeviceViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View mView = LayoutInflater.from(mContext).inflate(R.layout.user_lock_list_item, parent, false); + return new DeviceViewHolder(mView); + } + + @Override + public void onBindViewHolder(DeviceViewHolder _holder, int position) { + final LockObj item = mDataList.get(position); + _holder.Bind(item); + } + + @Override + public int getItemCount() { + return mDataList.size(); + } + + class DeviceViewHolder extends RecyclerView.ViewHolder { + + UserLockListItemBinding itemBinding; + + public DeviceViewHolder(View itemView){ + super(itemView); + itemBinding = DataBindingUtil.bind(itemView); + } + + public void Bind(LockObj item){ + itemBinding.tvLockName.setText(item.getLockAlias()); + itemBinding.getRoot().setOnClickListener(view -> { + MyApplication.getmInstance().saveChoosedLock(item); + ((BaseActivity) mContext).startTargetActivity(MainActivity.class); + }); + } + } +} diff --git a/app/src/main/java/ttlock/demo/lock/model/KeyListObj.java b/app/src/main/java/ttlock/demo/lock/model/KeyListObj.java new file mode 100644 index 0000000..8075002 --- /dev/null +++ b/app/src/main/java/ttlock/demo/lock/model/KeyListObj.java @@ -0,0 +1,22 @@ +package ttlock.demo.lock.model; + +import java.util.ArrayList; + +/** + * Created on 2019/4/28 0028 14:26 + * + * @author theodre + */ +public class KeyListObj { + int total; + int pages; + int pageNo; + int pageSize; + + ArrayList list; + + public ArrayList getList() { + return list; + } + +} diff --git a/app/src/main/java/ttlock/demo/lock/model/KeyObj.java b/app/src/main/java/ttlock/demo/lock/model/KeyObj.java new file mode 100644 index 0000000..55b88e7 --- /dev/null +++ b/app/src/main/java/ttlock/demo/lock/model/KeyObj.java @@ -0,0 +1,131 @@ +package ttlock.demo.lock.model; + +import ttlock.demo.model.LockVersionObj; + +/** + * Created on 2019/4/28 0028 14:01 + * + * @author theodre + */ +public class KeyObj { + int keyId; + int lockId; + String userType; + String keyStatus; + String lockName; + String lockAlias; + String lockData; + String lockKey; + String lockMac; + int lockFlagPos; + String adminPwd; + String noKeyPwd; + String deletePwd; + int electricQuantity; + String aesKeyStr; + LockVersionObj lockVersion; + long startDate; + long endDate; + long timezoneRawOffset; + String remarks; + int keyRight; + int keyboardPwdVersion; + int specialValue; + int remoteEnable; + + public int getKeyId() { + return keyId; + } + + public int getLockId() { + return lockId; + } + + public String getUserType() { + return userType; + } + + public String getKeyStatus() { + return keyStatus; + } + + public String getLockName() { + return lockName; + } + + public String getLockAlias() { + return lockAlias; + } + + public String getLockData() { + return lockData; + } + + public String getLockKey() { + return lockKey; + } + + public String getLockMac() { + return lockMac; + } + + public int getLockFlagPos() { + return lockFlagPos; + } + + public String getAdminPwd() { + return adminPwd; + } + + public String getNoKeyPwd() { + return noKeyPwd; + } + + public String getDeletePwd() { + return deletePwd; + } + + public int getElectricQuantity() { + return electricQuantity; + } + + public String getAesKeyStr() { + return aesKeyStr; + } + + public LockVersionObj getLockVersion() { + return lockVersion; + } + + public long getStartDate() { + return startDate; + } + + public long getEndDate() { + return endDate; + } + + public long getTimezoneRawOffset() { + return timezoneRawOffset; + } + + public String getRemarks() { + return remarks; + } + + public int getKeyRight() { + return keyRight; + } + + public int getKeyboardPwdVersion() { + return keyboardPwdVersion; + } + + public int getSpecialValue() { + return specialValue; + } + + public int getRemoteEnable() { + return remoteEnable; + } +} diff --git a/app/src/main/java/ttlock/demo/lock/model/LockInitResultObj.java b/app/src/main/java/ttlock/demo/lock/model/LockInitResultObj.java new file mode 100644 index 0000000..069a4f9 --- /dev/null +++ b/app/src/main/java/ttlock/demo/lock/model/LockInitResultObj.java @@ -0,0 +1,19 @@ +package ttlock.demo.lock.model; + +/** + * Created on 2019/4/28 0028 11:36 + * + * @author theodore + */ +public class LockInitResultObj { + int lockId; + int keyId; + + public int getLockId() { + return lockId; + } + + public int getKeyId() { + return keyId; + } +} diff --git a/app/src/main/java/ttlock/demo/model/AccountInfo.java b/app/src/main/java/ttlock/demo/model/AccountInfo.java new file mode 100644 index 0000000..d280404 --- /dev/null +++ b/app/src/main/java/ttlock/demo/model/AccountInfo.java @@ -0,0 +1,104 @@ +package ttlock.demo.model; + +/** + * Created by TTLock on 2019/4/23. + */ + +public class AccountInfo extends ServerError { + /** + * access_token : e335b88621994a689e42ffcb57ecdf6e + * refresh_token : 5119b4d9015b73cabd6bf69dedb6a1c9 + * uid : 2458 + * openid : 1146717084 + * scope : user,key,room + * token_type : Bearer + * expires_in : 2849185 + */ + + private String access_token; + private String refresh_token; + private int uid; + private int openid; + private String scope; + private String token_type; + private int expires_in; + + private String md5Pwd; + + public String getAccess_token() { + return access_token; + } + + public void setAccess_token(String access_token) { + this.access_token = access_token; + } + + public String getRefresh_token() { + return refresh_token; + } + + public void setRefresh_token(String refresh_token) { + this.refresh_token = refresh_token; + } + + public int getUid() { + return uid; + } + + public void setUid(int uid) { + this.uid = uid; + } + + public int getOpenid() { + return openid; + } + + public void setOpenid(int openid) { + this.openid = openid; + } + + public String getScope() { + return scope; + } + + public void setScope(String scope) { + this.scope = scope; + } + + public String getToken_type() { + return token_type; + } + + public void setToken_type(String token_type) { + this.token_type = token_type; + } + + public int getExpires_in() { + return expires_in; + } + + public void setExpires_in(int expires_in) { + this.expires_in = expires_in; + } + + public String getMd5Pwd() { + return md5Pwd; + } + + public void setMd5Pwd(String md5Pwd) { + this.md5Pwd = md5Pwd; + } + + @Override + public String toString() { + return "AccountInfo{" + + "access_token='" + access_token + '\'' + + ", refresh_token='" + refresh_token + '\'' + + ", uid=" + uid + + ", openid=" + openid + + ", scope='" + scope + '\'' + + ", token_type='" + token_type + '\'' + + ", expires_in=" + expires_in + + '}'; + } +} diff --git a/app/src/main/java/ttlock/demo/model/GatewayObj.java b/app/src/main/java/ttlock/demo/model/GatewayObj.java new file mode 100644 index 0000000..ae72f0e --- /dev/null +++ b/app/src/main/java/ttlock/demo/model/GatewayObj.java @@ -0,0 +1,73 @@ +package ttlock.demo.model; + +import java.io.Serializable; + +/** + * Created by TTLock on 2019/5/5. + */ + +public class GatewayObj implements Serializable { + /** + * gatewayMac : 0B:91:C7:BD:61:FF + * lockNum : 0 + * gatewayName : ttt + * isOnline : 0 + * gatewayVersion : 2 + * gatewayId : 299 + */ + + private String gatewayMac; + private int lockNum; + private String gatewayName; + private int isOnline; + private int gatewayVersion; + private int gatewayId; + + public String getGatewayMac() { + return gatewayMac; + } + + public void setGatewayMac(String gatewayMac) { + this.gatewayMac = gatewayMac; + } + + public int getLockNum() { + return lockNum; + } + + public void setLockNum(int lockNum) { + this.lockNum = lockNum; + } + + public String getGatewayName() { + return gatewayName; + } + + public void setGatewayName(String gatewayName) { + this.gatewayName = gatewayName; + } + + public int getIsOnline() { + return isOnline; + } + + public void setIsOnline(int isOnline) { + this.isOnline = isOnline; + } + + public int getGatewayVersion() { + return gatewayVersion; + } + + public void setGatewayVersion(int gatewayVersion) { + this.gatewayVersion = gatewayVersion; + } + + public int getGatewayId() { + return gatewayId; + } + + public void setGatewayId(int gatewayId) { + this.gatewayId = gatewayId; + } +} diff --git a/app/src/main/java/ttlock/demo/model/LockObj.java b/app/src/main/java/ttlock/demo/model/LockObj.java new file mode 100644 index 0000000..be5d32f --- /dev/null +++ b/app/src/main/java/ttlock/demo/model/LockObj.java @@ -0,0 +1,153 @@ +package ttlock.demo.model; + +import java.io.Serializable; + +/** + * Created by TTLock on 2019/4/23. + */ + +public class LockObj implements Serializable{ + /** + * date : 1534470870000 + * specialValue : 21729 + * lockAlias : AS1003_84e13c + * modelNum : SN139-M101-T1_PV53 + * lockMac : D3:58:7F:58:DE:B9 + * lockId : 24409 + * electricQuantity : 75 + * lockData : Djksy80snK7hKn9QdPutr6QI9YsRHDy+id/vo3o330AeQjMd4vgjWh/9ydA6b5H4e1+eVOyMgFlUjI2f8sfw8jkm/3RrPYeZ8wuSGN9yDiwYibmPx7QJGF/Pw7vQTyT7zSKgisAjOxWIk+AnDbNajZ3bhBH+AzP+APWl4FywDykIFLigO/8rCO7//o4Ziz932ynSOWiX15mirIjOz3tghwZMi6nl6m/cLxQWv1flKVt8MJdLr4G3ezdizHk8wEvOuNSK+F75ToJ+esUTK6tL50++8qNb6FBsB4Y3cmuLI1sTTZ6swtnmUALc7V2oijznmX89qG7I4y7SFDUEhVlkhy1zkHrq53ZMUgqutRCDdad7GAkTqtSL9eNYl3lfdSe5mAzz2cZ4l6CiE+yJo5GGcFkv9n31/sf//eNecJ7G0ulmH9+H5vaJ7SvMYuLUkw/FigQ9++0p5SiibEx1ZMTPC32mr8UoN0ZiAvhWQ3qeGj4MyoxEm1lw0I5o7VU/xuUA1p6+EDaGCyaYbU3GyemvH/sZsJj331zvImykLVCX9GB5Js7pzHSkAD/QcBgE49GsYlelBnC+4ZZj68eArtaIm0eT91F2FqeD/r+odA8VHiXTWH9Y3rk= + * keyboardPwdVersion : 4 + * hardwareRevision : 1.1 + * lockVersion : {"showAdminKbpwdFlag":true,"groupId":1,"protocolVersion":3,"protocolType":5,"orgId":1,"logoUrl":"","scene":2} + * userType : 110301 + * lockName : M101T_b9de58 + * firmwareRevision : 4.1.18.0131 + */ + + private long date; + private int specialValue; + private String lockAlias; + private String modelNum; + private String lockMac; + private int lockId; + private int electricQuantity; + private String lockData; + private int keyboardPwdVersion; + private String hardwareRevision; + private LockVersionObj lockVersion; + private String userType; + private String lockName; + private String firmwareRevision; + + public long getDate() { + return date; + } + + public void setDate(long date) { + this.date = date; + } + + public int getSpecialValue() { + return specialValue; + } + + public void setSpecialValue(int specialValue) { + this.specialValue = specialValue; + } + + public String getLockAlias() { + return lockAlias; + } + + public void setLockAlias(String lockAlias) { + this.lockAlias = lockAlias; + } + + public String getModelNum() { + return modelNum; + } + + public void setModelNum(String modelNum) { + this.modelNum = modelNum; + } + + public String getLockMac() { + return lockMac; + } + + public void setLockMac(String lockMac) { + this.lockMac = lockMac; + } + + public int getLockId() { + return lockId; + } + + public void setLockId(int lockId) { + this.lockId = lockId; + } + + public int getElectricQuantity() { + return electricQuantity; + } + + public void setElectricQuantity(int electricQuantity) { + this.electricQuantity = electricQuantity; + } + + public String getLockData() { + return lockData; + } + + public void setLockData(String lockData) { + this.lockData = lockData; + } + + public int getKeyboardPwdVersion() { + return keyboardPwdVersion; + } + + public void setKeyboardPwdVersion(int keyboardPwdVersion) { + this.keyboardPwdVersion = keyboardPwdVersion; + } + + public String getHardwareRevision() { + return hardwareRevision; + } + + public void setHardwareRevision(String hardwareRevision) { + this.hardwareRevision = hardwareRevision; + } + + public LockVersionObj getLockVersion() { + return lockVersion; + } + + public void setLockVersion(LockVersionObj lockVersion) { + this.lockVersion = lockVersion; + } + + public String getUserType() { + return userType; + } + + public void setUserType(String userType) { + this.userType = userType; + } + + public String getLockName() { + return lockName; + } + + public void setLockName(String lockName) { + this.lockName = lockName; + } + + public String getFirmwareRevision() { + return firmwareRevision; + } + + public void setFirmwareRevision(String firmwareRevision) { + this.firmwareRevision = firmwareRevision; + } +} diff --git a/app/src/main/java/ttlock/demo/model/LockVersionObj.java b/app/src/main/java/ttlock/demo/model/LockVersionObj.java new file mode 100644 index 0000000..be9b7c7 --- /dev/null +++ b/app/src/main/java/ttlock/demo/model/LockVersionObj.java @@ -0,0 +1,83 @@ +package ttlock.demo.model; + +import java.io.Serializable; + +/** + * Created by TTLock on 2019/4/23. + */ + +public class LockVersionObj implements Serializable { + /** + * showAdminKbpwdFlag : true + * groupId : 1 + * protocolVersion : 3 + * protocolType : 5 + * orgId : 1 + * logoUrl : + * scene : 2 + */ + + private boolean showAdminKbpwdFlag; + private int groupId; + private int protocolVersion; + private int protocolType; + private int orgId; + private String logoUrl; + private int scene; + + public boolean isShowAdminKbpwdFlag() { + return showAdminKbpwdFlag; + } + + public void setShowAdminKbpwdFlag(boolean showAdminKbpwdFlag) { + this.showAdminKbpwdFlag = showAdminKbpwdFlag; + } + + public int getGroupId() { + return groupId; + } + + public void setGroupId(int groupId) { + this.groupId = groupId; + } + + public int getProtocolVersion() { + return protocolVersion; + } + + public void setProtocolVersion(int protocolVersion) { + this.protocolVersion = protocolVersion; + } + + public int getProtocolType() { + return protocolType; + } + + public void setProtocolType(int protocolType) { + this.protocolType = protocolType; + } + + public int getOrgId() { + return orgId; + } + + public void setOrgId(int orgId) { + this.orgId = orgId; + } + + public String getLogoUrl() { + return logoUrl; + } + + public void setLogoUrl(String logoUrl) { + this.logoUrl = logoUrl; + } + + public int getScene() { + return scene; + } + + public void setScene(int scene) { + this.scene = scene; + } +} diff --git a/app/src/main/java/ttlock/demo/model/ServerError.java b/app/src/main/java/ttlock/demo/model/ServerError.java new file mode 100644 index 0000000..28edbb2 --- /dev/null +++ b/app/src/main/java/ttlock/demo/model/ServerError.java @@ -0,0 +1,41 @@ +package ttlock.demo.model; + +/** + * Created by TTLock on 2019/4/23. + */ + +public class ServerError { + /** + * errcode : 10000 + * errmsg : invalid client_id + * description : client_id不存在 + */ + + public int errcode; + public String errmsg; + public String description; + + public int getErrcode() { + return errcode; + } + + public void setErrcode(int errcode) { + this.errcode = errcode; + } + + public String getErrmsg() { + return errmsg; + } + + public void setErrmsg(String errmsg) { + this.errmsg = errmsg; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +} diff --git a/app/src/main/java/ttlock/demo/passcode/AdminPasscodeActivity.java b/app/src/main/java/ttlock/demo/passcode/AdminPasscodeActivity.java new file mode 100644 index 0000000..e93ee55 --- /dev/null +++ b/app/src/main/java/ttlock/demo/passcode/AdminPasscodeActivity.java @@ -0,0 +1,125 @@ +package ttlock.demo.passcode; + +import android.databinding.DataBindingUtil; +import android.os.Bundle; +import android.text.TextUtils; + +import com.google.gson.reflect.TypeToken; +import com.ttlock.bl.sdk.api.TTLockClient; +import com.ttlock.bl.sdk.callback.GetAdminPasscodeCallback; +import com.ttlock.bl.sdk.callback.ModifyAdminPasscodeCallback; +import com.ttlock.bl.sdk.constant.Feature; +import com.ttlock.bl.sdk.entity.LockError; +import com.ttlock.bl.sdk.util.DigitUtil; +import com.ttlock.bl.sdk.util.SpecialValueUtil; + +import java.util.HashMap; + +import okhttp3.ResponseBody; +import retrofit2.Call; +import ttlock.demo.BaseActivity; +import ttlock.demo.MyApplication; + +import ttlock.demo.R;; + +import ttlock.demo.databinding.ActivityAdminPasscodeBinding; +import ttlock.demo.retrofit.ApiService; +import ttlock.demo.retrofit.RetrofitAPIManager; + +public class AdminPasscodeActivity extends BaseActivity { + ActivityAdminPasscodeBinding binding; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + binding = DataBindingUtil.setContentView(this,R.layout.activity_admin_passcode); + TTLockClient.getDefault().prepareBTService(getApplicationContext()); + initListener(); + } + + private void initListener(){ + binding.btnGet.setOnClickListener(v -> getAdminPasscode()); + binding.btnModify.setOnClickListener(v -> modifyAdminPasscode()); + } + + /** + * this operation may be not support this operation. + */ + private void getAdminPasscode(){ + ensureBluetoothIsEnabled(); + showConnectLockToast(); + if(!SpecialValueUtil.isSupportFeature(mCurrentLock.getSpecialValue(),Feature.GET_ADMIN_CODE)){ + makeToast("--this lock does not support this operation--"); + return; + } + TTLockClient.getDefault().getAdminPasscode(mCurrentLock.getLockData(), mCurrentLock.getLockMac(), new GetAdminPasscodeCallback() { + @Override + public void onGetAdminPasscodeSuccess(String passcode) { + makeToast("admin passcode get success="); + binding.tvAdminPasscode.setText(passcode); + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + } + + private void modifyAdminPasscode(){ + ensureBluetoothIsEnabled(); + showConnectLockToast(); + String newAdminPasscode = binding.edtNewPasscode.getText().toString(); + if(TextUtils.isEmpty(newAdminPasscode)){ + makeToast("-please input new admin passcode-"); + return; + } + TTLockClient.getDefault().modifyAdminPasscode(newAdminPasscode, mCurrentLock.getLockData(), mCurrentLock.getLockMac(), new ModifyAdminPasscodeCallback() { + @Override + public void onModifyAdminPasscodeSuccess(String passcode) { + //this must be done after callback success. + uploadNewAdminPasscode2Server(passcode); + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + } + + private void uploadNewAdminPasscode2Server(String adminPasscode){ + ApiService apiService = RetrofitAPIManager.provideClientApi(); + HashMap params = new HashMap<>(6); + params.put("clientId",ApiService.CLIENT_ID); + params.put("accessToken",MyApplication.getmInstance().getAccountInfo().getAccess_token()); + params.put("lockId",String.valueOf(mCurrentLock.getLockId())); + params.put("password",adminPasscode); + params.put("date",String.valueOf(System.currentTimeMillis())); + + + Call call = apiService.changeAdminPasscode(params); + RetrofitAPIManager.enqueue(call, new TypeToken() { + }, result -> { + if (!result.success) { + makeToast("-modify admin passcode fail -" + result.getMsg()); + //if upload fail you should cache lockData and upload again until success,or you should reset lock and do init again. + return; + } + makeToast("--modify admin passcode and notify server success--"); + binding.tvAdminPasscode.setText(adminPasscode); + + + }, requestError -> { + makeToast(requestError.getMessage()); + }); + } + + /** + * stopBTService should be called when Activity is finishing to release Bluetooth resource. + */ + @Override + public void onDestroy(){ + super.onDestroy(); + TTLockClient.getDefault().stopBTService(); + } +} diff --git a/app/src/main/java/ttlock/demo/passcode/CreateCustomPasscodeActivity.java b/app/src/main/java/ttlock/demo/passcode/CreateCustomPasscodeActivity.java new file mode 100644 index 0000000..4167877 --- /dev/null +++ b/app/src/main/java/ttlock/demo/passcode/CreateCustomPasscodeActivity.java @@ -0,0 +1,72 @@ +package ttlock.demo.passcode; + +import android.databinding.DataBindingUtil; +import android.os.Bundle; +import android.text.TextUtils; + +import com.ttlock.bl.sdk.api.TTLockClient; +import com.ttlock.bl.sdk.callback.CreateCustomPasscodeCallback; +import com.ttlock.bl.sdk.entity.LockError; + +import ttlock.demo.BaseActivity; + +import ttlock.demo.R;; + +import ttlock.demo.databinding.ActivityCreateCustomPasscodeBinding; + +public class CreateCustomPasscodeActivity extends BaseActivity { + ActivityCreateCustomPasscodeBinding binding; + long passcodeActivePeriodOneHour = 60 * 60 * 1000; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + binding = DataBindingUtil.setContentView(this,R.layout.activity_create_custom_passcode); + TTLockClient.getDefault().prepareBTService(getApplicationContext()); + initView(); + } + + private void initView(){ + long startDate = System.currentTimeMillis(); + long endDate = startDate + passcodeActivePeriodOneHour; + binding.tvStartDate.setText(getDateFormat(startDate)); + binding.tvEndDate.setText(getDateFormat(endDate)); + binding.btnCustom.setOnClickListener(v -> createCustomPasscode(startDate,endDate)); + } + + /** NOTICE !! + * Passcode range : 4 - 9 Digits in length. + * @param startDate the active date for passcode + * @param endDate the expiring date for passcod + */ + private void createCustomPasscode(long startDate,long endDate){ + ensureBluetoothIsEnabled(); + showConnectLockToast(); + String passcode = binding.edtCustom.getText().toString(); + if(TextUtils.isEmpty(passcode)){ + makeToast("passcode is required"); + return; + } + + TTLockClient.getDefault().createCustomPasscode(passcode, startDate, endDate, mCurrentLock.getLockData(), mCurrentLock.getLockMac(), new CreateCustomPasscodeCallback() { + @Override + public void onCreateCustomPasscodeSuccess(String passcode) { + makeToast(" passcode is created : " + passcode + " you can try it on lock now"); + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + } + + /** + * stopBTService should be called when Activity is finishing to release Bluetooth resource. + */ + @Override + public void onDestroy(){ + super.onDestroy(); + TTLockClient.getDefault().stopBTService(); + } +} diff --git a/app/src/main/java/ttlock/demo/passcode/ModifyPasscodeActivity.java b/app/src/main/java/ttlock/demo/passcode/ModifyPasscodeActivity.java new file mode 100644 index 0000000..7d29638 --- /dev/null +++ b/app/src/main/java/ttlock/demo/passcode/ModifyPasscodeActivity.java @@ -0,0 +1,115 @@ +package ttlock.demo.passcode; + +import android.databinding.DataBindingUtil; +import android.os.Bundle; +import android.text.TextUtils; + +import com.ttlock.bl.sdk.api.TTLockClient; +import com.ttlock.bl.sdk.callback.ModifyPasscodeCallback; +import com.ttlock.bl.sdk.entity.LockError; + +import ttlock.demo.BaseActivity; + +import ttlock.demo.R; + +import ttlock.demo.databinding.ActivityModifyPasscodeBinding; + +public class ModifyPasscodeActivity extends BaseActivity { + + ActivityModifyPasscodeBinding binding; + private final static int MODIFY_DATE_ONLY = 1; + private final static int MODIFY_PASSCODE_ONLY = 1 << 1; + private final static int MODIFY_BOTH = 1 << 2; + + String originalPasscode = "2356"; + String passcodeNew; + long startDate = System.currentTimeMillis(); + long endDate = startDate + 60 * 60 * 1000; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + binding = DataBindingUtil.setContentView(this,R.layout.activity_modify_passcode); + TTLockClient.getDefault().prepareBTService(getApplicationContext()); + initView(); + } + + private void initView(){ + binding.tvStartDate.setText(getDateFormat(startDate)); + binding.tvEndDate.setText(getDateFormat(endDate)); + binding.btnDateChange.setOnClickListener(v -> modifyPasscode(MODIFY_DATE_ONLY)); + binding.btnPasscodeChange.setOnClickListener(v -> modifyPasscode(MODIFY_PASSCODE_ONLY)); + binding.btnModifyBoth.setOnClickListener(v -> modifyPasscode(MODIFY_BOTH)); + } + + + /** + * + * * @param originalPasscode old passcode + * * @param newPasscode new passcode ,Passcode range : 4 - 9 Digits in length.If you do not need to modify the password, set the value to null + * * @param startDate The time when it becomes valid. If you do not need to modify the time, set the value to 0 + * * @param endDate The time when it becomes expired. If you do not need to modify the time, set the value to 0 + * + * + */ + private void modifyPasscode(int modifyType){ + ensureBluetoothIsEnabled(); + /** + * if newPasscode is null or "" means you do not want to change original passcode. + */ + String newPasscode = null; + /** + * startDate + * endDate + * values are both 0 means you do not want to change expired date,or both values should not be 0. + */ + long newStartDate = 0; + long newEndDate = 0; + + switch (modifyType){ + case MODIFY_DATE_ONLY: + newStartDate = startDate - 60 * 1000; + newEndDate = newStartDate + 2 * 60 * 60 * 1000; + break; + case MODIFY_PASSCODE_ONLY: + newPasscode = binding.edtNewPasscode.getText().toString(); + if(TextUtils.isEmpty(newPasscode)){ + makeToast("new passcode is required or it won't be changed"); + return; + } + break; + case MODIFY_BOTH: + newStartDate = startDate - 60 * 1000; + newEndDate = newStartDate + 2 * 60 * 60 * 1000; + newPasscode = binding.edtNewPasscode.getText().toString(); + if(TextUtils.isEmpty(newPasscode)){ + makeToast("new passcode is required or it won't be changed"); + return; + } + break; + default: + break; + } + showConnectLockToast(); + TTLockClient.getDefault().modifyPasscode(originalPasscode, newPasscode, newStartDate, newEndDate, mCurrentLock.getLockData(), mCurrentLock.getLockMac(), new ModifyPasscodeCallback() { + @Override + public void onModifyPasscodeSuccess() { + makeToast("passcode is modified success"); + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + } + + /** + * stopBTService should be called when Activity is finishing to release Bluetooth resource. + */ + @Override + public void onDestroy(){ + super.onDestroy(); + TTLockClient.getDefault().stopBTService(); + } +} diff --git a/app/src/main/java/ttlock/demo/passcode/PasscodeActivity.java b/app/src/main/java/ttlock/demo/passcode/PasscodeActivity.java new file mode 100644 index 0000000..7efc853 --- /dev/null +++ b/app/src/main/java/ttlock/demo/passcode/PasscodeActivity.java @@ -0,0 +1,142 @@ +package ttlock.demo.passcode; + +import android.databinding.DataBindingUtil; +import android.os.Bundle; + +import com.google.gson.reflect.TypeToken; +import com.ttlock.bl.sdk.api.TTLockClient; +import com.ttlock.bl.sdk.callback.DeletePasscodeCallback; +import com.ttlock.bl.sdk.callback.GetAllValidPasscodeCallback; +import com.ttlock.bl.sdk.callback.GetPasscodeVerificationInfoCallback; +import com.ttlock.bl.sdk.callback.ResetPasscodeCallback; +import com.ttlock.bl.sdk.entity.LockError; + +import okhttp3.ResponseBody; +import retrofit2.Call; +import ttlock.demo.BaseActivity; +import ttlock.demo.MyApplication; + +import ttlock.demo.R;; + +import ttlock.demo.databinding.ActivityPasscodeBinding; +import ttlock.demo.retrofit.ApiService; +import ttlock.demo.retrofit.RetrofitAPIManager; + +public class PasscodeActivity extends BaseActivity { + + ActivityPasscodeBinding binding; + private final String passcode = "4321"; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + binding = DataBindingUtil.setContentView(this,R.layout.activity_passcode); + TTLockClient.getDefault().prepareBTService(getApplicationContext()); + initListener(); + } + + private void initListener(){ + binding.btnAdmin.setOnClickListener(v -> startTargetActivity(AdminPasscodeActivity.class)); + binding.btnCustom.setOnClickListener(v -> startTargetActivity(CreateCustomPasscodeActivity.class)); + binding.btnModify.setOnClickListener(v -> startTargetActivity(ModifyPasscodeActivity.class)); + binding.btnDeletePasscode.setOnClickListener(v -> deletePasscode()); + binding.btnGetAllPasscodes.setOnClickListener(v -> getAllValidPasscodes()); + binding.btnResetPasscode.setOnClickListener(v -> resetPasscodes()); + binding.btnGetPwdInfo.setOnClickListener(v -> getPwdInfo()); + } + + private void deletePasscode(){ + ensureBluetoothIsEnabled(); + showConnectLockToast(); + TTLockClient.getDefault().deletePasscode(passcode, mCurrentLock.getLockData(), mCurrentLock.getLockMac(), new DeletePasscodeCallback() { + @Override + public void onDeletePasscodeSuccess() { + makeToast(" passcode is deleted"); + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + } + + /** + * get all valid passcodes in lock . + */ + private void getAllValidPasscodes(){ + showConnectLockToast(); + TTLockClient.getDefault().getAllValidPasscodes(mCurrentLock.getLockData(), mCurrentLock.getLockMac(), new GetAllValidPasscodeCallback() { + @Override + public void onGetAllValidPasscodeSuccess(String passcodeStr) { + makeToast("- Success passcodes are " + passcodeStr); + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + } + + /** + * NOTICE !!!!!!!! + * all passcodes will be invalid + * you should upload pwdInfo and timestamp to you server to update lock data. + */ + private void resetPasscodes(){ + showConnectLockToast(); + TTLockClient.getDefault().resetPasscode(mCurrentLock.getLockData(), mCurrentLock.getLockMac(), new ResetPasscodeCallback() { + @Override + public void onResetPasscodeSuccess(String pwdInfo, long timestamp) { + //this must be done after callback success,or the lock passcode would be work well. + uploadResetPasscodeResult2Server(pwdInfo,timestamp); + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + } + + private void uploadResetPasscodeResult2Server(String pwdInfo, long timestamp){ + ApiService apiService = RetrofitAPIManager.provideClientApi(); + Call call = apiService.resetPasscode(ApiService.CLIENT_ID, MyApplication.getmInstance().getAccountInfo().getAccess_token(), mCurrentLock.getLockId(),pwdInfo,timestamp,System.currentTimeMillis()); + RetrofitAPIManager.enqueue(call, new TypeToken() { + }, result -> { + if (!result.success) { + makeToast("-reset passcode fail -" + result.getMsg()); + //if upload fail you should cache lockData and upload again until success,or you should reset lock and do init again. + return; + } + makeToast("--reset passcode and notify server success--"); + + }, requestError -> { + makeToast(requestError.getMessage()); + }); + } + + private void getPwdInfo(){ + showConnectLockToast(); + TTLockClient.getDefault().getPasscodeVerificationParams(mCurrentLock.getLockData(), mCurrentLock.getLockMac(), new GetPasscodeVerificationInfoCallback() { + @Override + public void onGetInfoSuccess(String pwdInfo, long timestamp) { + makeToast("--success--pwdInfo-" + pwdInfo); + } + + @Override + public void onFail(LockError error) { + makeErrorToast(error); + } + }); + } + + /** + * stopBTService should be called when Activity is finishing to release Bluetooth resource. + */ + @Override + public void onDestroy(){ + super.onDestroy(); + TTLockClient.getDefault().stopBTService(); + } +} diff --git a/app/src/main/java/ttlock/demo/retrofit/ApiRequtest.java b/app/src/main/java/ttlock/demo/retrofit/ApiRequtest.java new file mode 100644 index 0000000..5404983 --- /dev/null +++ b/app/src/main/java/ttlock/demo/retrofit/ApiRequtest.java @@ -0,0 +1,49 @@ +package ttlock.demo.retrofit; + +import android.util.Log; + +import com.google.gson.reflect.TypeToken; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.IOException; + +import okhttp3.ResponseBody; +import retrofit2.Call; +import retrofit2.Callback; + + +public class ApiRequtest { + private static final String TAG = ApiRequtest.class.getSimpleName(); + + private TypeToken mResultType; + + public ApiRequtest (Call call, TypeToken resultType, final ApiResponse.Listener> listener, final ApiResponse.ErrorListener errorListener){ + mResultType = resultType; + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, retrofit2.Response response) { + try { + ResponseBody responseBody = response.body(); + if(responseBody != null){ + String jsonString = response.body().string(); + final ApiResult result = new ApiResult<>(new JSONObject(jsonString), mResultType); + listener.onResponse(result); + } + + }catch (IOException e){ + }catch (JSONException e) { + } + } + + @Override + public void onFailure(Call call, Throwable t) { + errorListener.onErrorResponse(t); + } + }); + } + + + +} diff --git a/app/src/main/java/ttlock/demo/retrofit/ApiResponse.java b/app/src/main/java/ttlock/demo/retrofit/ApiResponse.java new file mode 100644 index 0000000..06c23bc --- /dev/null +++ b/app/src/main/java/ttlock/demo/retrofit/ApiResponse.java @@ -0,0 +1,19 @@ +package ttlock.demo.retrofit; + +public class ApiResponse { + + /** + * network request error response + */ + public interface ErrorListener { + void onErrorResponse(Throwable requestError); + } + + /** + * network request success response result + * @param data result + */ + public interface Listener { + void onResponse(T result); + } +} diff --git a/app/src/main/java/ttlock/demo/retrofit/ApiResult.java b/app/src/main/java/ttlock/demo/retrofit/ApiResult.java new file mode 100644 index 0000000..419da18 --- /dev/null +++ b/app/src/main/java/ttlock/demo/retrofit/ApiResult.java @@ -0,0 +1,105 @@ +package ttlock.demo.retrofit; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; + + +import org.json.JSONObject; + + +/** + * + */ +public class ApiResult { + + private final static String TAG = ApiResult.class.getSimpleName(); + + public static final int OK = 0; + + public Boolean success = true; + private Integer code = OK; + private String msg=""; + private T result; + private String msgJson; + private static Gson gson = new Gson(); + + + public ApiResult() { + super(); + // TODO Auto-generated constructor stub + } + + public ApiResult(JSONObject jsonObject, TypeToken typeToken) { + super(); + try{ + if (jsonObject.has("errcode")){ + code = jsonObject.getInt("errcode"); + if (code != OK) { + if (jsonObject.has("errmsg")) { + msg = jsonObject.getString("errmsg"); + } + + success = false; + + } + }else{ + + } + + if (code == OK){ + try { + result = gson.fromJson(jsonObject.toString(), typeToken.getType()); + }catch (Exception ex){ + + } + + } + }catch (Exception e) { + // TODO: handle exception + } + + } + private T testDefault(String msg){ + Gson gson = new Gson(); + result = gson.fromJson(msg,new TypeToken(){}.getType()); + return result; + } + private T test(String msg, TypeToken typeToken){ + Gson gson = new Gson(); + result = gson.fromJson(msg,typeToken.getType()); + return result; + } + + public Integer getCode() { + return code; + } + public void setCode(Integer code) { + this.code = code; + } + public String getMsg() { + return msg; + } + public void setMsg(String msg) { + this.msg = msg; + } + + public T getResult() { + return result; + } + + public void setResult(T result) { + this.result = result; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public String getMsgJson() { + return msgJson; + } +} diff --git a/app/src/main/java/ttlock/demo/retrofit/ApiService.java b/app/src/main/java/ttlock/demo/retrofit/ApiService.java new file mode 100644 index 0000000..1e1dfc1 --- /dev/null +++ b/app/src/main/java/ttlock/demo/retrofit/ApiService.java @@ -0,0 +1,119 @@ +package ttlock.demo.retrofit; + +import java.util.Map; + +import okhttp3.ResponseBody; +import retrofit2.Call; +import retrofit2.http.Field; +import retrofit2.http.FieldMap; +import retrofit2.http.FormUrlEncoded; +import retrofit2.http.GET; +import retrofit2.http.POST; +import retrofit2.http.QueryMap; + +/** + * Created by + */ +public interface ApiService { + + + /** + * development environment + */ + public static final String CLIENT_ID = "439063e312444f1f85050a52efcecd2e"; + public static final String CLIENT_SECRET = "0ef1c49b70c02ae6314bde603d4e9b05"; + public static final String REDIRECT_URI = "http://open.ttlock.com.cn"; + + @POST("/lockRecords/fromLock") + @FormUrlEncoded + Call uploadRecords(@Field("lockId") int lockId, @Field("records") String records); + + @POST("/room/registerNb") + @FormUrlEncoded + Call registerNb(@Field("lockId") int lockId, @Field("nbNodeId") String nbNodeId, @Field("nbCardNumber") String nbCardNumber, @Field("nbRssi") int nbRssi, @Field("nbOperator") String nbOperator); + + @POST("/oauth2/token") + @FormUrlEncoded + Call auth(@Field("client_id") String clientId, @Field("client_secret") String clientSecret, @Field("grant_type") String grantType, @Field("username") String username, @Field("password") String password, @Field("redirect_uri") String redirectUri); + + @POST("/v3/lock/list") + @FormUrlEncoded + Call getLockList(@Field("clientId") String clientId, @Field("accessToken") String accessToken, @Field("pageNo") int pageNo, @Field("pageSize") int pageSize, @Field("date") long date); + + @POST("/v3/lock/initialize") + @FormUrlEncoded + Call lockInit(@Field("clientId") String clientId, @Field("accessToken") String accessToken, @Field("lockData") String lockData, @Field("lockAlias") String alias, @Field("date") long date); + + @GET("/v3/key/list") + Call getUserKeyList(@QueryMap Map params); + + @POST("/v3/lock/resetKey") + @FormUrlEncoded + Call restEkey(@Field("clientId") String clientId, @Field("accessToken") String accessToken,@Field("lockId") int lockId, @Field("date") long date); + + @POST("/v3/lock/delete") + @FormUrlEncoded + Call deleteLock(@Field("clientId") String clientId, @Field("accessToken") String accessToken,@Field("lockId") int lockId, @Field("date") long date); + + @POST("/v3/lock/resetKeyboardPwd") + @FormUrlEncoded + Call resetPasscode(@Field("clientId") String clientId, @Field("accessToken") String accessToken,@Field("lockId") int lockId, @Field("pwdInfo") String pwdInfo,@Field("timestamp") long timestamp, @Field("date") long date); + + @POST("/v3/lock/changeAdminKeyboardPwd") + @FormUrlEncoded + Call changeAdminPasscode(@FieldMap Map params); + + @POST("/v3/fingerprint/add") + @FormUrlEncoded + Call addFingerprint(@FieldMap Map params); + + @GET("/v3/fingerprint/list") + Call getUserFingerprintList(@QueryMap Map params); + + @POST("/v3/fingerprint/delete") + @FormUrlEncoded + Call deleteFingerprint(@FieldMap Map params); + + @POST("/v3/fingerprint/clear") + @FormUrlEncoded + Call clearFingerprints(@Field("clientId") String clientId, @Field("accessToken") String accessToken,@Field("lockId") int lockId, @Field("date") long date); + + @POST("/v3/identityCard/add") + @FormUrlEncoded + Call addICCard(@FieldMap Map params); + + @GET("/v3/identityCard/list") + Call getUserICCardList(@QueryMap Map params); + + @POST("/v3/identityCard/delete") + @FormUrlEncoded + Call deleteICCard(@FieldMap Map params); + + @POST("/v3/identityCard/changePeriod ") + @FormUrlEncoded + Call modifyICCardPeriod(@FieldMap Map params); + + @POST("/v3/identityCard/clear") + @FormUrlEncoded + Call clearICCards(@Field("clientId") String clientId, @Field("accessToken") String accessToken,@Field("lockId") int lockId, @Field("date") long date); + + @POST("/v3/gateway/upgradeCheck") + @FormUrlEncoded + Call gatewayUpgradeCheck(@Field("clientId") String clientId, @Field("accessToken") String accessToken,@Field("gatewayId") int gatewayId, @Field("date") long date); + + @POST("/v3/gateway/isInitSuccess") + @FormUrlEncoded + Call gatewayIsInitSuccess(@Field("clientId") String clientId, @Field("accessToken") String accessToken, @Field("gatewayNetMac") String gatewayNetMac, @Field("date") long date); + + @POST("/v3/gateway/list") + @FormUrlEncoded + Call getGatewayList(@Field("clientId") String clientId, @Field("accessToken") String accessToken, @Field("pageNo") int pageNo, @Field("pageSize") int pageSize, @Field("date") long date); + + @POST("/v3/lock/upgradeCheck") + @FormUrlEncoded + Call lockUpgradeCheck(@Field("clientId") String clientId, @Field("accessToken") String accessToken, @Field("lockId") int lockId, @Field("date") long date); + + @POST("/v3/lock/upgradeRecheck") + @FormUrlEncoded + Call lockUpgradeCheckAgain(@Field("clientId") String clientId, @Field("accessToken") String accessToken, @Field("firmwareInfo") String firmwareInfo, @Field("lockId") int lockId, @Field("date") long date); +} diff --git a/app/src/main/java/ttlock/demo/retrofit/RetrofitAPIManager.java b/app/src/main/java/ttlock/demo/retrofit/RetrofitAPIManager.java new file mode 100644 index 0000000..1753aa6 --- /dev/null +++ b/app/src/main/java/ttlock/demo/retrofit/RetrofitAPIManager.java @@ -0,0 +1,63 @@ +package ttlock.demo.retrofit; + +import com.google.gson.reflect.TypeToken; +import com.ttlock.bl.sdk.util.LogUtil; + +import java.io.IOException; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; +import java.util.concurrent.TimeUnit; + +import okhttp3.OkHttpClient; +import okhttp3.ResponseBody; +import retrofit2.Call; +import retrofit2.Converter; +import retrofit2.Retrofit; + +/** + * Created by TTLock on 2018/9/5. + */ + +public class RetrofitAPIManager { + + public static final String SERVER_URL = "https://api.ttlock.com.cn"; + + public static ApiService provideClientApi() { + Retrofit retrofit = new Retrofit.Builder() + .client(genericClient()) + .baseUrl(SERVER_URL) + .addConverterFactory( + new Converter.Factory() {//Converter转换器 + @Override + public Converter responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) { + return new Converter() { + + @Override + public String convert(ResponseBody value) throws IOException { + String json = value.string(); + LogUtil.d("json:" + json); + return json; + } + }; + } + } + ) + .build(); + return retrofit.create(ApiService.class); + } + + public static OkHttpClient genericClient() { + OkHttpClient httpClient = new OkHttpClient.Builder() + .connectTimeout(35, TimeUnit.SECONDS) + .readTimeout(35, TimeUnit.SECONDS) + .writeTimeout(35, TimeUnit.SECONDS) + .build(); + + return httpClient; + } + + public static ApiRequtest enqueue(Call call, TypeToken resultType, ApiResponse.Listener> listener, ApiResponse.ErrorListener errorListener ){ + ApiRequtest request = new ApiRequtest<>(call,resultType,listener,errorListener); + return request; + } +} \ No newline at end of file diff --git a/app/src/main/java/ttlock/demo/retrofit/onRequestResponse.java b/app/src/main/java/ttlock/demo/retrofit/onRequestResponse.java new file mode 100644 index 0000000..25f7b93 --- /dev/null +++ b/app/src/main/java/ttlock/demo/retrofit/onRequestResponse.java @@ -0,0 +1,9 @@ +package ttlock.demo.retrofit; + +/** + * Created by Administrator on 2018/1/17 0017. + */ + +public interface onRequestResponse { + void onResult(boolean success); +} diff --git a/app/src/main/java/ttlock/demo/retrofit/onServerRequestCallBack.java b/app/src/main/java/ttlock/demo/retrofit/onServerRequestCallBack.java new file mode 100644 index 0000000..c974778 --- /dev/null +++ b/app/src/main/java/ttlock/demo/retrofit/onServerRequestCallBack.java @@ -0,0 +1,9 @@ +package ttlock.demo.retrofit; + +/** + * Created by Administrator on 2018/1/17 0017. + */ + +public interface onServerRequestCallBack { + void onResult(int resultCode); +} diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..1f6bb29 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/app/src/main/res/drawable/btn_bg_normal.xml b/app/src/main/res/drawable/btn_bg_normal.xml new file mode 100644 index 0000000..5fc9a07 --- /dev/null +++ b/app/src/main/res/drawable/btn_bg_normal.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/btn_bg_pressed.xml b/app/src/main/res/drawable/btn_bg_pressed.xml new file mode 100644 index 0000000..13beb8f --- /dev/null +++ b/app/src/main/res/drawable/btn_bg_pressed.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/btn_bg_selector.xml b/app/src/main/res/drawable/btn_bg_selector.xml new file mode 100644 index 0000000..34f3607 --- /dev/null +++ b/app/src/main/res/drawable/btn_bg_selector.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..0d025f9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_setting_more.png b/app/src/main/res/drawable/ic_setting_more.png new file mode 100644 index 0000000000000000000000000000000000000000..5294e20d75c6e21f35ec43c42a7c83de8cd4a225 GIT binary patch literal 486 zcmeAS@N?(olHy`uVBq!ia0vp^9w5xY1|&n@ZgvM!k|nMYCBgY=CFO}lsSJ)O`AMk? zp1FzXsX?iUDV2pMQ*9U+7&|;&978H@y}4uS#q7v%^kbx_@*75%FHDpCx<$Ig!pdHW zu6eWO3iA#2?DY%EZbkgK7_p-Fo`RB`1Lv(Z`EvwaBzSrz&t3DMy?=xB3AOzxX-vXF zA)%=r7Rdq(ECLP;PiKd{=zH4yf9tNfxgs@9ZnYg}SDU|@y+8IuRR^zS@T-+kzaB?^ zb(tGjUDMPP`M>S6X!V|B0>zU2bLKO2cuFZWFeouFf(!x?EI=+32Z-pXNxM+HF|+h) zOSyc~W(kY?f!l>+H?NnQ9slhv8{;PHIc37@*F5Bn`Q$s*w$ycRmt@l2Sp{tqFYVvA z!g9sk51GqkxxZW}SnxYyf$rC(3oX8t<{tCAH2v7$Q-{_iP41kRp}t{K>}v7Obw9s^ zub%Odf7ARAbMJ66%w4^^Ch*B@6QFBcpbi1Lh6Ca_kPA<;t&q3)&okll!e750&#|>* zI`Q=4j`+wstKPqwYya-*-y>0yyyd%_t*76X3HiVuvL*@aE#=w#jBE^->J7Uc?`^&a Pj5r2QS3j3^P6 + + +