Skip to content

Commit 5659b12

Browse files
committed
Merge branch 'feature/avs-ble-cosmetic-changes' into 'versions/avs-ble'
Feature/avs ble cosmetic changes See merge request idf/esp-idf-provisioning-android!16
2 parents c82a8b1 + 760dc29 commit 5659b12

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1405
-983
lines changed

.gitignore

+29-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
.DS_Store
2-
31
# Built application files
42
*.apk
53
*.ap_
@@ -67,3 +65,32 @@ fastlane/test_output
6765
fastlane/readme.md
6866

6967
app/src/main/assets/api_key.txt
68+
69+
# Built application files
70+
/*/build/
71+
72+
# Crashlytics configuations
73+
com_crashlytics_export_strings.xml
74+
75+
# Local configuration file (sdk path, etc)
76+
local.properties
77+
78+
# Gradle generated files
79+
.gradle/
80+
81+
# Signing files
82+
.signing/
83+
84+
# User-specific configurations
85+
.idea/*
86+
*.iml
87+
88+
# OS-specific files
89+
.DS_Storegit add
90+
.DS_Store
91+
.D
92+
._*
93+
.Spotlight-V100
94+
.Trashes
95+
ehthumbs.db
96+
Thumbs.db

app/build.gradle

+10-7
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,20 @@ android {
1010
keyPassword 'password'
1111
}
1212
}
13-
compileSdkVersion 27
13+
compileSdkVersion 28
14+
1415
defaultConfig {
15-
applicationId "com.espressif.provavsble"
16+
applicationId "com.espressif.provbleavs"
1617
minSdkVersion 21
1718
targetSdkVersion 27
18-
versionCode 5
19-
versionName "1.3"
19+
versionCode 7
20+
versionName "1.3.2"
2021
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
2122
signingConfig signingConfigs.config
2223
}
2324
buildTypes {
2425
release {
26+
debuggable false
2527
minifyEnabled false
2628
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
2729
resValue "string", "proof_of_possesion", "abcd1234"
@@ -34,10 +36,11 @@ android {
3436
resValue "string", "ble_scanconfig_uuid", "0000ff50-0000-1000-8000-00805f9b34fb"
3537
resValue "string", "ble_device_name_prefix", "ESP-Alexa-"
3638
signingConfig signingConfigs.config
37-
debuggable true
3839
}
3940
debug {
4041
debuggable true
42+
minifyEnabled false
43+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
4144
resValue "string", "proof_of_possesion", "abcd1234"
4245
resValue "string", "wifi_base_url", "192.168.4.1:80"
4346
resValue "string", "wifi_network_name_prefix", "ESP-Alexa-"
@@ -100,9 +103,9 @@ protobuf {
100103

101104
dependencies {
102105
implementation fileTree(include: ['*.jar'], dir: 'libs')
103-
implementation 'com.android.support:appcompat-v7:27.1.1'
106+
implementation 'com.android.support:appcompat-v7:28.0.0'
104107
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
105-
implementation 'com.android.support:design:27.1.1'
108+
implementation 'com.android.support:design:28.0.0'
106109
testImplementation 'junit:junit:4.12'
107110
androidTestImplementation 'com.android.support.test:runner:1.0.2'
108111
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

app/src/main/AndroidManifest.xml

+30-17
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
android:label="@string/app_name"
1818
android:roundIcon="@mipmap/ic_launcher_round"
1919
android:supportsRtl="true"
20-
android:theme="@style/AppTheme">
20+
android:theme="@style/AppTheme"
21+
android:usesCleartextTraffic="true">
2122
<activity
22-
android:name="com.espressif.ui.MainActivity"
23+
android:name="com.espressif.ui.activities.EspMainActivity"
2324
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
2425
android:label="@string/app_name"
26+
android:screenOrientation="portrait"
2527
android:theme="@style/AppTheme.NoActionBar">
2628
<intent-filter>
2729
<action android:name="android.intent.action.MAIN" />
@@ -33,6 +35,7 @@
3335
android:name="com.amazon.identity.auth.device.workflow.WorkflowActivity"
3436
android:allowTaskReparenting="true"
3537
android:launchMode="singleTask"
38+
android:screenOrientation="portrait"
3639
android:theme="@android:style/Theme.NoDisplay">
3740
<intent-filter>
3841
<action android:name="android.intent.action.VIEW" />
@@ -46,44 +49,54 @@
4649
</intent-filter>
4750
</activity>
4851
<activity
49-
android:name="com.espressif.ui.ProvisionLanding"
52+
android:name="com.espressif.ui.activities.ProvisionLanding"
5053
android:label="@string/title_activity_provision_landing"
54+
android:screenOrientation="portrait"
5155
android:theme="@style/AppTheme.NoActionBar" />
5256
<activity
53-
android:name="com.espressif.ui.ProvisionActivity"
54-
android:label="@string/provision_activity_title"
57+
android:name="com.espressif.ui.activities.ProvisionActivity"
58+
android:label="@string/title_activity_provision"
59+
android:screenOrientation="portrait"
5560
android:theme="@style/AppTheme.NoActionBar" />
5661
<activity
57-
android:name="com.espressif.ui.WiFiScanList"
58-
android:label="Wi-Fi Scan List"
62+
android:name="com.espressif.ui.activities.WiFiScanActivity"
63+
android:label="@string/title_activity_wifi_scan_list"
64+
android:screenOrientation="portrait"
5965
android:theme="@style/AppTheme.NoActionBar" />
6066
<activity
61-
android:name="com.espressif.ui.ScanLocalDevices"
62-
android:label="Manage Devices"
67+
android:name="com.espressif.ui.activities.ScanLocalDevices"
68+
android:label="@string/title_activity_manage_devices"
69+
android:screenOrientation="portrait"
6370
android:theme="@style/AppTheme.NoActionBar" />
6471
<activity
65-
android:name="com.espressif.ui.ManageDevices"
66-
android:label="Manage Devices"
72+
android:name="com.espressif.ui.activities.ManageDevices"
73+
android:label="@string/title_activity_manage_devices"
74+
android:screenOrientation="portrait"
6775
android:theme="@style/AppTheme.NoActionBar" />
6876
<activity
69-
android:name="com.espressif.ui.LoginWithAmazon"
77+
android:name="com.espressif.ui.activities.LoginWithAmazon"
7078
android:label="@string/title_activity_login_with_amazon"
79+
android:screenOrientation="portrait"
7180
android:theme="@style/AppTheme.NoActionBar" />
7281
<activity
73-
android:name="com.espressif.ui.AlexaActivity"
82+
android:name="com.espressif.ui.activities.AlexaActivity"
7483
android:label="@string/title_activity_alexa"
84+
android:screenOrientation="portrait"
7585
android:theme="@style/AppTheme.NoActionBar" />
7686
<activity
77-
android:name="com.espressif.ui.ProvisionSuccessActivity"
87+
android:name="com.espressif.ui.activities.ProvisionSuccessActivity"
7888
android:label="@string/title_activity_provision_success"
89+
android:screenOrientation="portrait"
7990
android:theme="@style/AppTheme.NoActionBar" />
8091
<activity
81-
android:name="com.espressif.ui.BLEProvisionLanding"
82-
android:label="@string/title_activity_bleprovision_landing"
92+
android:name="com.espressif.ui.activities.BLEProvisionLanding"
93+
android:label="@string/title_activity_connect_device"
94+
android:screenOrientation="portrait"
8395
android:theme="@style/AppTheme.NoActionBar" />
8496
<activity
85-
android:name="com.espressif.ui.ProofOfPossessionActivity"
97+
android:name="com.espressif.ui.activities.ProofOfPossessionActivity"
8698
android:label="@string/title_activity_pop"
99+
android:screenOrientation="portrait"
87100
android:theme="@style/AppTheme.NoActionBar" />
88101

89102
</application>

app/src/main/java/com/espressif/AppConstants.java

+1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ public class AppConstants {
1313
// Keys used to pass data between activities and to store data in SharedPreference.
1414
public static final String KEY_PROOF_OF_POSSESSION = "proof_of_possession";
1515
public static final String KEY_WIFI_SECURITY_TYPE = "wifi_security";
16+
public static final String KEY_STATUS_MSG = "status_msg";
1617
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.espressif.ble_scanner;
2+
3+
import android.bluetooth.BluetoothDevice;
4+
import android.bluetooth.le.ScanResult;
5+
6+
/**
7+
* Interface for BLE device scanning.
8+
*/
9+
public interface BleScanListener {
10+
11+
/**
12+
* Called when any BLE peripheral will be found.
13+
*
14+
* @param device BluetoothDevice
15+
* @param scanResult Scan result.
16+
*/
17+
void onPeripheralFound(BluetoothDevice device, ScanResult scanResult);
18+
19+
/**
20+
* Callback method for scan completed.
21+
*/
22+
void scanCompleted();
23+
24+
/**
25+
* Failed to scan for BLE bluetoothDevices.
26+
*
27+
* @param e Exception
28+
*/
29+
void onFailure(Exception e);
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package com.espressif.ble_scanner;
2+
3+
import android.bluetooth.BluetoothAdapter;
4+
import android.bluetooth.BluetoothManager;
5+
import android.bluetooth.le.BluetoothLeScanner;
6+
import android.bluetooth.le.ScanCallback;
7+
import android.bluetooth.le.ScanFilter;
8+
import android.bluetooth.le.ScanResult;
9+
import android.bluetooth.le.ScanSettings;
10+
import android.content.Context;
11+
import android.os.Handler;
12+
import android.text.TextUtils;
13+
import android.util.Log;
14+
15+
import java.util.ArrayList;
16+
import java.util.List;
17+
18+
public class BleScanner {
19+
20+
private static final String TAG = BleScanner.class.getSimpleName();
21+
22+
private Context context;
23+
private BleScanListener bleScanListener;
24+
private BluetoothAdapter bluetoothAdapter;
25+
private BluetoothLeScanner bluetoothLeScanner;
26+
27+
private long scanTimeout;
28+
private boolean isScanning = false;
29+
30+
public BleScanner(Context context, long scanTimeoutInMillis, BleScanListener bleScannerListener) {
31+
32+
this.context = context;
33+
this.scanTimeout = scanTimeoutInMillis;
34+
this.bleScanListener = bleScannerListener;
35+
36+
final BluetoothManager bluetoothManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE);
37+
bluetoothAdapter = bluetoothManager.getAdapter();
38+
}
39+
40+
public void startScan() {
41+
42+
Log.d(TAG, "startScan");
43+
44+
bluetoothLeScanner = bluetoothAdapter.getBluetoothLeScanner();
45+
List<ScanFilter> filters = new ArrayList<>();
46+
ScanSettings settings = new ScanSettings.Builder()
47+
.setScanMode(ScanSettings.SCAN_MODE_LOW_POWER)
48+
.build();
49+
50+
isScanning = true;
51+
bluetoothLeScanner.startScan(filters, settings, scanCallback);
52+
Handler someHandler = new Handler();
53+
someHandler.postDelayed(new Runnable() {
54+
55+
@Override
56+
public void run() {
57+
58+
stopScan();
59+
}
60+
}, scanTimeout);
61+
}
62+
63+
public void stopScan() {
64+
65+
Log.d(TAG, "onStopBleScan()");
66+
67+
if (bluetoothLeScanner != null && bluetoothAdapter != null && bluetoothAdapter.isEnabled()) {
68+
try {
69+
bluetoothLeScanner.stopScan(scanCallback);
70+
} catch (Exception e) {
71+
Log.e(TAG, e.toString());
72+
}
73+
}
74+
isScanning = false;
75+
bleScanListener.scanCompleted();
76+
}
77+
78+
public boolean isScanning() {
79+
return isScanning;
80+
}
81+
82+
final ScanCallback scanCallback = new ScanCallback() {
83+
84+
@Override
85+
public void onScanResult(int callbackType, ScanResult result) {
86+
87+
if (result.getDevice() != null && !TextUtils.isEmpty(result.getDevice().getName())) {
88+
89+
Log.d(TAG, "onScanResult");
90+
bleScanListener.onPeripheralFound(result.getDevice(), result);
91+
}
92+
}
93+
94+
@Override
95+
public void onBatchScanResults(List<ScanResult> results) {
96+
super.onBatchScanResults(results);
97+
Log.d(TAG, "onBatchScanResults()");
98+
}
99+
100+
@Override
101+
public void onScanFailed(int errorCode) {
102+
super.onScanFailed(errorCode);
103+
Log.d(TAG, "onScanFailed errorCode:" + errorCode);
104+
bleScanListener.onFailure(new Exception("BLE connect failed with error code : " + errorCode));
105+
}
106+
};
107+
}

0 commit comments

Comments
 (0)