Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
XuXiangJun committed Apr 10, 2020
1 parent dc7d089 commit ed64bfd
Show file tree
Hide file tree
Showing 27 changed files with 1,157 additions and 487 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ This APP is used to configure ESP devices to connect target AP, the devices need
## Version Log
- See [Log](log/log-en.md)

## Modules
- EspTouch: [esptouch](esptouch)

## Releases
- See [releases](https://github.com/EspressifApp/EsptouchForAndroid/releases/latest), contain APK and aar
- For programmer, if you don't want use [esptouch](esptouch) module, download the aar into your own project.
13 changes: 6 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ android {

defaultConfig {
applicationId "com.espressif.iot_esptouch_demo"
minSdkVersion 14
minSdkVersion 21
targetSdkVersion 29
versionCode 22
versionName "v1.1.0"
versionCode 23
versionName "v1.1.1"
}

signingConfigs {
Expand All @@ -28,17 +28,16 @@ android {
signingConfig signingConfigs.debug
}
}

compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation project(':esptouch')
}
5 changes: 3 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.espressif.iot_esptouch_demo" >
package="com.espressif.iot_esptouch_demo">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
Expand All @@ -11,13 +11,14 @@
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application
android:name=".EspTouchApp"
android:allowBackup="true"
android:icon="@drawable/app_icon"
android:label="@string/app_name"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name="com.espressif.iot.esptouch.demo_activity.EsptouchDemoActivity"
android:name="com.espressif.esptouch.android.v1.EspTouchActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
package com.espressif.esptouch.android;

import android.Manifest;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.location.LocationManager;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.view.Menu;
import android.view.MenuItem;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.location.LocationManagerCompat;

import com.espressif.iot_esptouch_demo.R;
import com.espressif.iot_esptouch_demo.NetUtils;

import java.net.InetAddress;

public abstract class EspTouchActivityAbs extends AppCompatActivity {
private static final int MENU_ITEM_ABOUT = 0;

private WifiManager mWifiManager;

protected abstract String getEspTouchVersion();

protected static class StateResult {
public CharSequence message = null;

public boolean permissionGranted = false;

public boolean locationRequirement = false;

public boolean wifiConnected = false;
public boolean is5G = false;
public InetAddress address = null;
public String ssid = null;
public byte[] ssidBytes = null;
public String bssid = null;
}

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

mWifiManager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
}

private void showAboutDialog() {
String esptouchVerText = getEspTouchVersion();
String appVer = "";
PackageManager packageManager = getPackageManager();
try {
PackageInfo info = packageManager.getPackageInfo(getPackageName(), 0);
appVer = info.versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}

CharSequence[] items = new CharSequence[]{
getString(R.string.about_app_version, appVer),
esptouchVerText
};
new AlertDialog.Builder(this)
.setTitle(R.string.menu_item_about)
.setIcon(R.drawable.baseline_info_black_24)
.setItems(items, null)
.show();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(Menu.NONE, MENU_ITEM_ABOUT, 0, R.string.menu_item_about)
.setIcon(R.drawable.ic_info_outline_white_24dp)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
case MENU_ITEM_ABOUT:
showAboutDialog();
return true;
}

return super.onOptionsItemSelected(item);
}

protected StateResult checkPermission() {
StateResult result = new StateResult();
result.permissionGranted = false;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
boolean locationGranted = checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED;
if (!locationGranted) {
String[] splits = getString(R.string.esptouch_message_permission).split("\n");
if (splits.length != 2) {
throw new IllegalArgumentException("Invalid String @RES esptouch_message_permission");
}
SpannableStringBuilder ssb = new SpannableStringBuilder(splits[0]);
ssb.append('\n');
SpannableString clickMsg = new SpannableString(splits[1]);
ForegroundColorSpan clickSpan = new ForegroundColorSpan(0xFF0022FF);
clickMsg.setSpan(clickSpan, 0, clickMsg.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
ssb.append(clickMsg);
result.message = ssb;
return result;
}
}

result.permissionGranted = true;
return result;
}

protected StateResult checkLocation() {
StateResult result = new StateResult();
result.locationRequirement = true;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
LocationManager manager = getSystemService(LocationManager.class);
boolean enable = manager != null && LocationManagerCompat.isLocationEnabled(manager);
if (!enable) {
result.message = getString(R.string.esptouch_message_location);
return result;
}
}

result.locationRequirement = false;
return result;
}

protected StateResult checkWifi() {
StateResult result = new StateResult();
result.wifiConnected = false;
WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
boolean connected = NetUtils.isWifiConnected(mWifiManager);
if (!connected) {
result.message = getString(R.string.esptouch_message_wifi_connection);
return result;
}

String ssid = NetUtils.getSsidString(wifiInfo);
int ipValue = wifiInfo.getIpAddress();
if (ipValue != 0) {
result.address = NetUtils.getAddress(wifiInfo.getIpAddress());
} else {
result.address = NetUtils.getIPv4Address();
if (result.address == null) {
result.address = NetUtils.getIPv6Address();
}
}

result.wifiConnected = true;
result.message = "";
result.is5G = NetUtils.is5G(wifiInfo.getFrequency());
if (result.is5G) {
result.message = getString(R.string.esptouch_message_wifi_frequency);
}
result.ssid = ssid;
result.ssidBytes = NetUtils.getRawSsidBytesOrElse(wifiInfo, ssid.getBytes());
result.bssid = wifiInfo.getBSSID();

return result;
}
}
Loading

0 comments on commit ed64bfd

Please sign in to comment.