Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
XuXiangJun committed Sep 18, 2019
1 parent 9384181 commit 262d0f3
Show file tree
Hide file tree
Showing 57 changed files with 283 additions and 3,784 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This is a demo app to control the ESP device which run [BluFi](https://github.co
- See [doc](doc/Introduction_to_the_EspBlufi_API_Interface_for_Android__en.md)

## Release APKS
- See [releases](https://github.com/EspressifApp/EspRelease/tree/master/EspBlufi)
- See [releases](https://github.com/EspressifApp/EspBlufiForAndroid/releases)

## Update Log
- See [Log](log/updatelog-en.md)
16 changes: 9 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 28
compileSdkVersion 29

defaultConfig {
applicationId "com.espressif.espblufi"
minSdkVersion 18
targetSdkVersion 28
versionCode 19
versionName "1.4.2"
targetSdkVersion 29
versionCode 20
versionName "1.4.3"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand All @@ -26,13 +26,15 @@ android {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')

implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.gridlayout:gridlayout:1.0.0'
implementation 'androidx.preference:preference:1.1.0'

implementation 'io.reactivex.rxjava2:rxjava:2.2.8'
implementation 'io.reactivex.rxjava2:rxjava:2.2.12'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'

implementation 'xxj.phiman:xxjtools:1.0.1'

implementation project(':blufilibrary')
implementation project(':apptools')
}
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />

<application
Expand Down
34 changes: 6 additions & 28 deletions app/src/main/java/com/espressif/espblufi/app/BlufiApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
import com.espressif.espblufi.constants.SettingsConstants;

import java.util.HashMap;
import java.util.Random;
import java.util.HashSet;
import java.util.Set;

import libs.espressif.utils.RandomUtil;

public class BlufiApp extends Application {
private static BlufiApp instance;

Expand Down Expand Up @@ -41,26 +39,6 @@ public void onTerminate() {
mCache.clear();
}

public String putCache(Object value) {
synchronized (mCache) {
int keyLength = new Random().nextInt(20) + 20;
String key = RandomUtil.randomString(keyLength);
mCache.put(key, value);
return key;
}
}

public Object takeCache(String key) {
synchronized (mCache) {
Object result = mCache.get(key);
if (result != null) {
mCache.remove(key);
}

return result;
}
}

public boolean settingsPut(String key, Object value) {
SharedPreferences.Editor editor = mSettingsShared.edit();
if (value instanceof String) {
Expand All @@ -75,12 +53,11 @@ public boolean settingsPut(String key, Object value) {
editor.putLong(key, (Long) value);
} else if (value instanceof Set) {
Set set = (Set) value;
if (!set.isEmpty()) {
if (!(set.iterator().next() instanceof String)) {
return false;
}
Set<String> newSet = new HashSet<>();
for (Object object : set) {
newSet.add((String)object);
}
editor.putStringSet(key, (Set<String>)set);
editor.putStringSet(key, newSet);
} else {
return false;
}
Expand All @@ -101,6 +78,7 @@ public Object settingsGet(String key, Object defaultValue) {
} else if (defaultValue instanceof Long) {
return mSettingsShared.getLong(key, (Long) defaultValue);
} else if (defaultValue instanceof Set) {
//noinspection unchecked
return mSettingsShared.getStringSet(key, (Set<String>) defaultValue);
} else {
return null;
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/com/espressif/espblufi/ui/BlufiActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.bluetooth.BluetoothProfile;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
Expand Down Expand Up @@ -39,13 +40,12 @@
import blufi.espressif.response.BlufiScanResult;
import blufi.espressif.response.BlufiStatusResponse;
import blufi.espressif.response.BlufiVersionResponse;
import libs.espressif.app.SdkUtil;
import libs.espressif.log.EspLog;
import tools.xxj.phiman.log.XxjLog;

public class BlufiActivity extends BaseActivity {
private static final int REQUEST_CONFIGURE = 0x20;

private final EspLog mLog = new EspLog(getClass());
private final XxjLog mLog = new XxjLog(getClass());

private BluetoothDevice mDevice;
private BluetoothGatt mGatt;
Expand Down Expand Up @@ -180,7 +180,7 @@ private void connectGatt() {
mGatt.close();
}
GattCallback callback = new GattCallback();
if (SdkUtil.isAtLeastM_23()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mGatt = mDevice.connectGatt(this, false, callback, BluetoothDevice.TRANSPORT_LE);
} else {
mGatt = mDevice.connectGatt(this, false, callback);
Expand Down Expand Up @@ -321,7 +321,7 @@ public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState
if (status == BluetoothGatt.GATT_SUCCESS) {
switch (newState) {
case BluetoothProfile.STATE_CONNECTED:
if (SdkUtil.isAtLeastL_21()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
gatt.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_HIGH);
int mtu = (int) BlufiApp.getInstance().settingsGet(
SettingsConstants.PREF_SETTINGS_KEY_MTU_LENGTH, BlufiConstants.DEFAULT_MTU_LENGTH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import libs.espressif.log.EspLog;
import libs.espressif.net.NetUtil;
import tools.xxj.phiman.log.XxjLog;
import tools.xxj.phiman.net.XxjNetUtil;

public class ConfigureOptionsActivity extends BaseActivity implements AdapterView.OnItemSelectedListener {
private static final int OP_MODE_POS_STA = 0;
Expand All @@ -62,7 +62,7 @@ public class ConfigureOptionsActivity extends BaseActivity implements AdapterVie

private static final String PREF_AP = "blufi_conf_aps";

private EspLog mLog = new EspLog(getClass());
private XxjLog mLog = new XxjLog(getClass());

private Spinner mDeviceModeSp;

Expand Down Expand Up @@ -141,7 +141,7 @@ public void afterTextChanged(Editable s) {
mStationSsidET.setText(getConnectionSSID());
WifiInfo info = ((WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE)).getConnectionInfo();
if (info != null) {
byte[] ssidBytes = NetUtil.getOriginalSsidBytes(info);
byte[] ssidBytes = XxjNetUtil.getOriginalSsidBytes(info);
mStationSsidET.setTag(ssidBytes);
}

Expand Down Expand Up @@ -323,7 +323,7 @@ private void showWifiListDialog() {
.setSingleChoiceItems(wifiSSIDs, checkedItem, (dialog, which) -> {
mStationSsidET.setText(wifiSSIDs[which]);
ScanResult scanResult = mWifiList.get(which);
byte[] ssidBytes = NetUtil.getOriginalSsidBytes(scanResult);
byte[] ssidBytes = XxjNetUtil.getOriginalSsidBytes(scanResult);
mStationSsidET.setTag(ssidBytes);
dialog.dismiss();
})
Expand Down Expand Up @@ -383,7 +383,7 @@ private boolean checkSta(BlufiConfigureParams params) {
}
}
}
if (NetUtil.is5GHz(freq)) {
if (XxjNetUtil.is5GHz(freq)) {
mStationSsidET.setError(getString(R.string.configure_station_wifi_5g_error));
new AlertDialog.Builder(this)
.setMessage(R.string.configure_station_wifi_5g_dialog_message)
Expand Down
46 changes: 22 additions & 24 deletions app/src/main/java/com/espressif/espblufi/ui/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.Manifest;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.le.ScanResult;
import android.content.Intent;
import android.location.LocationManager;
import android.os.Build;
Expand All @@ -22,6 +23,7 @@
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.location.LocationManagerCompat;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

Expand All @@ -39,10 +41,10 @@
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import libs.espressif.app.PermissionHelper;
import libs.espressif.ble.EspBleUtils;
import libs.espressif.ble.ScanListener;
import libs.espressif.log.EspLog;
import tools.xxj.phiman.app.XxjPermissionHelper;
import tools.xxj.phiman.ble.XxjBleScanListener;
import tools.xxj.phiman.ble.XxjBleUtils;
import tools.xxj.phiman.log.XxjLog;

public class MainActivity extends AppCompatActivity {
private static final long TIMEOUT_SCAN = 4000L;
Expand All @@ -52,9 +54,9 @@ public class MainActivity extends AppCompatActivity {

private static final int MENU_SETTINGS = 0x01;

private final EspLog mLog = new EspLog(getClass());
private final XxjLog mLog = new XxjLog(getClass());

private PermissionHelper mPermissionHelper;
private XxjPermissionHelper mPermissionHelper;

private SwipeRefreshLayout mRefreshLayout;

Expand Down Expand Up @@ -91,14 +93,14 @@ protected void onCreate(Bundle savedInstanceState) {
mDeviceRssiMap = new HashMap<>();
mScanCallback = new ScanCallback();

mPermissionHelper = new PermissionHelper(this, REQUEST_PERMISSION);
mPermissionHelper = new XxjPermissionHelper(this, REQUEST_PERMISSION);
mPermissionHelper.setOnPermissionsListener((permission, granted) -> {
if (granted && permission.equals(Manifest.permission.ACCESS_COARSE_LOCATION)) {
if (granted && permission.equals(Manifest.permission.ACCESS_FINE_LOCATION)) {
mRefreshLayout.setRefreshing(true);
scan();
}
});
mPermissionHelper.requestAuthorities(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION});
mPermissionHelper.requestAuthorities(new String[]{Manifest.permission.ACCESS_FINE_LOCATION});
}

@Override
Expand Down Expand Up @@ -151,16 +153,12 @@ private void scan() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// Check location enable
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
if (locationManager != null) {
boolean locationGPS = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
boolean locationNetwork = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (!locationGPS && !locationNetwork) {
Toast.makeText(this, R.string.main_location_disable_msg, Toast.LENGTH_SHORT).show();
mRefreshLayout.setRefreshing(false);
return;
}
boolean locationEnable = locationManager != null && LocationManagerCompat.isLocationEnabled(locationManager);
if (!locationEnable) {
Toast.makeText(this, R.string.main_location_disable_msg, Toast.LENGTH_SHORT).show();
mRefreshLayout.setRefreshing(false);
return;
}

}

mDeviceRssiMap.clear();
Expand All @@ -171,7 +169,7 @@ private void scan() {
mScanStartTime = SystemClock.elapsedRealtime();

mLog.d("Start scan ble");
EspBleUtils.startScanBle(mScanCallback);
XxjBleUtils.startScanBle(mScanCallback);
mUpdateFuture = mThreadPool.submit(() -> {
while (!Thread.currentThread().isInterrupted()) {
try {
Expand All @@ -189,14 +187,14 @@ private void scan() {
onIntervalScanUpdate(false);
}

EspBleUtils.stopScanBle(mScanCallback);
XxjBleUtils.stopScanBle(mScanCallback);
onIntervalScanUpdate(true);
mLog.d("Scan ble thread is interrupted");
});
}

private void stopScan() {
EspBleUtils.stopScanBle(mScanCallback);
XxjBleUtils.stopScanBle(mScanCallback);
if (mUpdateFuture != null) {
mUpdateFuture.cancel(true);
}
Expand Down Expand Up @@ -253,10 +251,10 @@ public void onClick(View v) {
}
}

private class ScanCallback implements ScanListener {
private class ScanCallback implements XxjBleScanListener {

@Override
public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) {
public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord, ScanResult scanResult) {
String name = device.getName();
if (!TextUtils.isEmpty(mBlufiFilter)) {
if (name == null || !name.startsWith(mBlufiFilter)) {
Expand All @@ -282,7 +280,7 @@ public void onBindViewHolder(@NonNull BleHolder holder, int position) {
BluetoothDevice device = mBleList.get(position);
holder.device = device;

String name = device.getName() == null ? getString(R.string.string_unknown) : device.getName();
String name = device.getName() == null ? getString(R.string.string_unknown) : device.getName();
holder.text1.setText(name);

SpannableStringBuilder info = new SpannableStringBuilder();
Expand Down
Loading

0 comments on commit 262d0f3

Please sign in to comment.