diff --git a/README.md b/README.md index db3019c..b0d5f6c 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ The devices need run smart config: [esp-idf](https://github.com/espressif/esp-id implementation 'com.github.EspressifApp:lib-esptouch-android:1.0.0' ``` ``` - implementation 'com.github.EspressifApp:lib-esptouch-v2-android:2.0.0' + implementation 'com.github.EspressifApp:lib-esptouch-v2-android:2.1.0' ``` ## Lib Source Code diff --git a/app/build.gradle b/app/build.gradle index a82f9c4..d268e00 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,8 +7,8 @@ android { applicationId "com.espressif.esptouch.android" minSdkVersion 21 targetSdkVersion 30 - versionCode 26 - versionName "v2.0.0" + versionCode 29 + versionName "v2.3.0" } signingConfigs { @@ -32,19 +32,17 @@ android { viewBinding true } compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_11 + targetCompatibility JavaVersion.VERSION_11 } } dependencies { implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs') - implementation 'com.google.android.material:material:1.3.0' - implementation 'androidx.appcompat:appcompat:1.3.0' - implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation 'com.google.android.material:material:1.4.0' + implementation 'androidx.appcompat:appcompat:1.3.1' + implementation 'androidx.constraintlayout:constraintlayout:2.1.0' implementation 'com.github.EspressifApp:lib-esptouch-android:1.0.0' - implementation 'com.github.EspressifApp:lib-esptouch-v2-android:2.0.0' -// implementation project(':esptouch') -// implementation project(':esptouch-v2') + implementation 'com.github.EspressifApp:lib-esptouch-v2-android:2.1.0' } diff --git a/app/src/main/java/com/espressif/esptouch/android/v2/EspProvisioningActivity.java b/app/src/main/java/com/espressif/esptouch/android/v2/EspProvisioningActivity.java index 3338447..a9466e3 100644 --- a/app/src/main/java/com/espressif/esptouch/android/v2/EspProvisioningActivity.java +++ b/app/src/main/java/com/espressif/esptouch/android/v2/EspProvisioningActivity.java @@ -35,6 +35,7 @@ public class EspProvisioningActivity extends AppCompatActivity { public static final String KEY_PROVISION = "provision"; public static final String KEY_PROVISION_REQUEST = "provision_request"; + public static final String KEY_DEVICE_COUNT = "device_count"; private List mStations; private StationAdapter mStationAdapter; @@ -51,6 +52,8 @@ public class EspProvisioningActivity extends AppCompatActivity { private long mTime; + private int mWillProvisioningCount = -1; + @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -62,6 +65,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { } EspProvisioningRequest request = getIntent().getParcelableExtra(KEY_PROVISION_REQUEST); + mWillProvisioningCount = getIntent().getIntExtra(KEY_DEVICE_COUNT, -1); assert request != null; mProvisioner = new EspProvisioner(getApplicationContext()); @@ -171,6 +175,10 @@ public void onResponse(EspProvisioningResult result) { runOnUiThread(() -> { mStations.add(result); mStationAdapter.notifyItemInserted(mStations.size() - 1); + + if (mWillProvisioningCount > 0 && mStations.size() >= mWillProvisioningCount) { + mProvisioner.stopProvisioning(); + } }); } diff --git a/app/src/main/java/com/espressif/esptouch/android/v2/EspTouch2Activity.java b/app/src/main/java/com/espressif/esptouch/android/v2/EspTouch2Activity.java index d6dd855..96961bc 100644 --- a/app/src/main/java/com/espressif/esptouch/android/v2/EspTouch2Activity.java +++ b/app/src/main/java/com/espressif/esptouch/android/v2/EspTouch2Activity.java @@ -3,10 +3,11 @@ import android.Manifest; import android.content.Intent; import android.os.Bundle; -import android.text.TextUtils; import android.util.Log; import android.view.View; +import androidx.activity.result.ActivityResultLauncher; +import androidx.activity.result.contract.ActivityResultContracts; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; @@ -29,7 +30,6 @@ public class EspTouch2Activity extends EspTouchActivityAbs { private static final String TAG = EspTouch2Activity.class.getSimpleName(); private static final int REQUEST_PERMISSION = 0x01; - private static final int REQUEST_PROVISIONING = 0x02; private EspProvisioner mProvisioner; @@ -43,25 +43,25 @@ public class EspTouch2Activity extends EspTouchActivityAbs { private int mMessageVisible; private int mControlVisible; + private ActivityResultLauncher mProvisionLauncher; + @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); mBinding = ActivityEsptouch2Binding.inflate(getLayoutInflater()); setContentView(mBinding.getRoot()); + + mProvisionLauncher = registerForActivityResult( + new ActivityResultContracts.StartActivityForResult(), + result -> mBinding.confirmBtn.setEnabled(true) + ); + mBinding.controlGroup.setVisibility(View.INVISIBLE); mBinding.confirmBtn.setOnClickListener(v -> { - EspProvisioningRequest request = genRequest(); - if (request == null) { - return; + if (launchProvisioning()) { + mBinding.confirmBtn.setEnabled(false); } - if (mProvisioner != null) { - mProvisioner.close(); - } - Intent intent = new Intent(EspTouch2Activity.this, EspProvisioningActivity.class); - intent.putExtra(EspProvisioningActivity.KEY_PROVISION_REQUEST, request); - startActivityForResult(intent, REQUEST_PROVISIONING); - mBinding.confirmBtn.setEnabled(false); }); ActionBar actionBar = getSupportActionBar(); @@ -110,18 +110,25 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis } @Override - protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { - if (requestCode == REQUEST_PROVISIONING) { - mBinding.confirmBtn.setEnabled(true); - return; + protected String getEspTouchVersion() { + return getString(R.string.esptouch2_about_version, IEspProvisioner.ESPTOUCH_VERSION); + } + + private boolean launchProvisioning() { + EspProvisioningRequest request = genRequest(); + if (request == null) { + return false; + } + if (mProvisioner != null) { + mProvisioner.close(); } - super.onActivityResult(requestCode, resultCode, data); - } + Intent intent = new Intent(EspTouch2Activity.this, EspProvisioningActivity.class); + intent.putExtra(EspProvisioningActivity.KEY_PROVISION_REQUEST, request); + intent.putExtra(EspProvisioningActivity.KEY_DEVICE_COUNT, getDeviceCount()); + mProvisionLauncher.launch(intent); - @Override - protected String getEspTouchVersion() { - return getString(R.string.esptouch2_about_version, IEspProvisioner.ESPTOUCH_VERSION); + return true; } private boolean checkState() { @@ -190,7 +197,7 @@ private EspProvisioningRequest genRequest() { CharSequence aesKeyChars = mBinding.aesKeyEdit.getText(); byte[] aesKey = null; - if (!TextUtils.isEmpty(aesKeyChars)) { + if (aesKeyChars != null && aesKeyChars.length() > 0) { aesKey = aesKeyChars.toString().getBytes(); } if (aesKey != null && aesKey.length != 16) { @@ -200,11 +207,12 @@ private EspProvisioningRequest genRequest() { CharSequence customDataChars = mBinding.customDataEdit.getText(); byte[] customData = null; - if (!TextUtils.isEmpty(customDataChars)) { + if (customDataChars != null && customDataChars.length() > 0) { customData = customDataChars.toString().getBytes(); } - if (customData != null && customDataChars.length() > 127) { - mBinding.customDataEdit.setError(getString(R.string.esptouch2_custom_data_error)); + int customDataMaxLen = EspProvisioningRequest.RESERVED_LENGTH_MAX; + if (customData != null && customData.length > customDataMaxLen) { + mBinding.customDataEdit.setError(getString(R.string.esptouch2_custom_data_error, customDataMaxLen)); return null; } @@ -218,8 +226,21 @@ private EspProvisioningRequest genRequest() { .build(); } + private int getDeviceCount() { + CharSequence deviceCountStr = mBinding.deviceCountEdit.getText(); + int deviceCount = -1; + if (deviceCountStr != null && deviceCountStr.length() > 0) { + try { + deviceCount = Integer.parseInt(deviceCountStr.toString()); + } catch (Exception e) { + e.printStackTrace(); + } + } + return deviceCount; + } + private static class SyncListener implements EspSyncListener { - private WeakReference provisioner; + private final WeakReference provisioner; SyncListener(EspProvisioner provisioner) { this.provisioner = new WeakReference<>(provisioner); diff --git a/app/src/main/res/layout/activity_esptouch2.xml b/app/src/main/res/layout/activity_esptouch2.xml index a9a78a2..a63c6db 100644 --- a/app/src/main/res/layout/activity_esptouch2.xml +++ b/app/src/main/res/layout/activity_esptouch2.xml @@ -11,7 +11,7 @@ android:id="@+id/controlGroup" android:layout_width="wrap_content" android:layout_height="wrap_content" - app:constraint_referenced_ids="apSsidLabel,apSsidText,apBssidLabel,apBssidText,ipLabel,ipText,apPasswordLayout,aesKeyLayout,customDataLayout,confirmBtn" /> + app:constraint_referenced_ids="apSsidLabel,apSsidText,apBssidLabel,apBssidText,ipLabel,ipText,apPasswordLayout,aesKeyLayout,customDataLayout,confirmBtn,deviceCountLayout" /> + + + + + AES 密钥 AES 密钥必须为空或者16字节数据 自定义数据 - 自定义数据不能超过127字节 + 自定义数据不能超过%d字节 + 需要配网的设备数量 配网 停止 @@ -48,4 +49,4 @@ Wi-Fi 连接已断开 BSSID: %1$s 地址: %1$s - \ No newline at end of file + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 29c1052..c578fbb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -39,7 +39,8 @@ AES Key AES Key must be null or 16 bytes data Custom Data - Custom data can\'t be more than 127 bytes + Custom data can\'t be more than %d bytes + Device Count for Provisioning Provision Stop diff --git a/build.gradle b/build.gradle index 6cb8d8b..f4832b5 100644 --- a/build.gradle +++ b/build.gradle @@ -3,9 +3,10 @@ buildscript { repositories { google() mavenCentral() + maven { url = uri("https://jitpack.io") } } dependencies { - classpath 'com.android.tools.build:gradle:4.2.2' + classpath 'com.android.tools.build:gradle:7.0.2' } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 4053750..ffd3a0d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip diff --git a/jitpack.yml b/jitpack.yml new file mode 100644 index 0000000..adb3fe1 --- /dev/null +++ b/jitpack.yml @@ -0,0 +1,2 @@ +jdk: + - openjdk11 diff --git a/log/log-en.md b/log/log-en.md index 39e3715..2a8fb8a 100644 --- a/log/log-en.md +++ b/log/log-en.md @@ -2,6 +2,12 @@ # Update Log +## v2.3.0 +- EspTouchV2 + - Support set device count for provisioning + - Change custom data max length to 64 bytes + - Update esptouch-v2 lib to 2.1.0 + ## v2.0.0 - Support EspTouchV2 - EspTouchV2 is not compatible with EspTouch diff --git a/log/log-zh-rCN.md b/log/log-zh-rCN.md index 841e9d1..1f70a46 100644 --- a/log/log-zh-rCN.md +++ b/log/log-zh-rCN.md @@ -2,6 +2,12 @@ # Update Log +## v2.3.0 +- EspTouchV2 + - 增加设置配网设备个数 + - 自定义数据最大长度改为 64 字节 + - 更新 esptouch-v2 lib 到 2.1.0 + ## v2.0.0 - 支持 EspTouchV2 协议 - 注: EspTouchV2 与 EspTouch 不能兼容