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