Skip to content

Commit 0d16767

Browse files
committed
v2.4.1 for Android 5.0+ release!
1 parent 44667bf commit 0d16767

12 files changed

Lines changed: 155 additions & 73 deletions

File tree

BUILDING.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## Building the app
2+
1. 安装以下软件:
3+
- Android SDK:
4+
http://developer.android.com/sdk/index.html
5+
- Gradle:
6+
http://www.gradle.org/downloads
7+
- Android Studio:
8+
http://developer.android.com/sdk/installing/studio.html
9+
2. 运行sdk manager(可以在Android Studio中工具栏上点击按钮或者在命令行中输入android打开),确保以下内容已安装:
10+
- Tools > Android SDK Platform-tools (rev 22 or above)
11+
- Tools > Android SDK Tools (rev 24.3.3 or above)
12+
- Tools > Android SDK Build-tools version 20
13+
- Tools > Android SDK Build-tools version 21 (rev 22.0.1 or above)
14+
- Android 4.0.3 > SDK Platform (API 15)
15+
- Android 5.0.1 > SDK Platform (API 21)
16+
3. 将工程导入Android Studio:
17+
1. 点击 File > Import Project
18+
2. 切换到工程中的 settings.gradle 文件并选择
19+
3. 点击 OK
20+
4. 点击运行或者使用快捷键shift+F10

app/app-release.apk

-80.9 KB
Binary file not shown.

app/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ android {
1717
applicationId "com.padeoe.autoconnect"
1818
minSdkVersion 21
1919
targetSdkVersion 23
20-
versionCode 1
21-
versionName "2.4"
20+
versionCode 2112241
21+
versionName "2.4.1"
2222
}
2323
buildTypes {
2424
release {
@@ -38,5 +38,5 @@ dependencies {
3838
compile 'cn.leancloud.android:avoscloud-sdk:v3.3+'
3939
compile 'cn.leancloud.android:Java-WebSocket:1.2.0-leancloud'
4040
compile 'cn.leancloud.android:avoscloud-statistics:v3.3+@aar'
41-
compile 'com.android.support:support-v4:23.0.0'
41+
compile 'com.android.support:support-v4:23.1.1'
4242
}

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
</activity>
4343

4444
<service
45-
android:name=".service.WiFiDetectService"
45+
android:name=".service.ConnectService"
4646
android:enabled="true"
4747
android:exported="true">
4848
<intent-filter>

app/src/main/java/com/padeoe/autoconnect/activity/App.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@
33
import android.app.Application;
44
import android.content.Context;
55

6+
import com.avos.avoscloud.AVOSCloud;
7+
68
/**
79
* Created by padeoe on 2015/7/2.
810
*/
911
public class App extends Application {
10-
public static final String LOGINURL = "http://219.219.114.15/portal_io/login";
11-
public static final String LOGOUTURL = "http://219.219.114.15/portal_io/logout";
1212
public static Context context;
1313

1414
@Override
1515
public void onCreate() {
1616
super.onCreate();
1717
context = getApplicationContext();
18+
//添加LeanCloud用户统计分析,下面一行代码中的key仅用于测试,发布的apk中使用的不同
19+
AVOSCloud.initialize(this, "rfdbmj8hpdbo3dwx2unrqmvhfb2y8r6d3xrsaiwwoewr2bc4", "c6n60q7onyffn97vey1jywk3bje590xlntp8ddasdo0hnvcy");
1820
}
1921

2022
}

app/src/main/java/com/padeoe/autoconnect/activity/MainActivity.java

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@
3838
import com.avos.avoscloud.AVObject;
3939
import com.avos.avoscloud.AVQuery;
4040
import com.avos.avoscloud.FindCallback;
41+
import com.padeoe.autoconnect.service.ConnectService;
4142
import com.padeoe.autoconnect.service.InstallService;
4243
import com.padeoe.autoconnect.ui.CaptivePortalLoginFragment;
4344
import com.padeoe.autoconnect.ui.ExplainPermissionFragment;
4445
import com.padeoe.autoconnect.util.ResultUtils;
4546
import com.padeoe.autoconnect.R;
46-
import com.padeoe.autoconnect.service.WiFiDetectService;
4747
import com.padeoe.autoconnect.ui.AboutDialogFragment;
4848
import com.padeoe.autoconnect.ui.CheckUpdateFragment;
4949
import com.padeoe.autoconnect.ui.SettingDialogFragment;
@@ -66,23 +66,26 @@ public class MainActivity extends Activity implements CheckUpdateFragment.Update
6666

6767
@Override
6868
protected void onCreate(Bundle savedInstanceState) {
69+
/* Log.e("time", "开始计时");
70+
Timer t = new Timer();
71+
t.start();*/
72+
6973
super.onCreate(savedInstanceState);
7074
setContentView(R.layout.activity_main);
71-
//添加LeanCloud用户统计分析,下面一行代码中的key仅用于测试,发布的apk中使用的不同
72-
AVOSCloud.initialize(this, "rfdbmj8hpdbo3dwx2unrqmvhfb2y8r6d3xrsaiwwoewr2bc4", "c6n60q7onyffn97vey1jywk3bje590xlntp8ddasdo0hnvcy");
73-
7475
//获取现有配置
7576
sharedPreferences = App.context.getSharedPreferences("DataFile", MODE_PRIVATE);
7677
editor = sharedPreferences.edit();
77-
String username = sharedPreferences.getString("username", null);
78-
String password = sharedPreferences.getString("password", null);
78+
/* String username = sharedPreferences.getString("username", null);
79+
String password = sharedPreferences.getString("password", null);*/
80+
String username=ConnectService.getUsername();
81+
String password=ConnectService.getPassword();
7982
//显示现有配置
8083
usernameEdit = (EditText) findViewById(R.id.username);
8184
passwordEdit = (EditText) findViewById(R.id.password);
8285
if (username != null) usernameEdit.setText(username);
8386
if (password != null) passwordEdit.setText(password);
8487
if (username != null & password != null) {
85-
this.startService(new Intent(this, WiFiDetectService.class));
88+
this.startService(new Intent(this, ConnectService.class));
8689
}
8790

8891
final ListView listview = (ListView) findViewById(R.id.listview);
@@ -138,7 +141,7 @@ public void onClick(DialogInterface dialog, int id) {
138141
AlertDialog dialog = builder.create();
139142
dialog.show();
140143
}
141-
144+
/*Log.e("time", t.end() + "ms");*/
142145
}
143146

144147
/**
@@ -161,7 +164,7 @@ public void updateClick(DialogFragment dialog) {
161164
*/
162165
@Override
163166
public void explainOverClick(DialogFragment dialog) {
164-
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
167+
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
165168
}
166169

167170
private class StableArrayAdapter extends ArrayAdapter<String> {
@@ -265,7 +268,7 @@ public void connectNow() {
265268
ReturnData returnData = null;
266269
returnData = ReturnData.getFromJson(connectResult);
267270
if (returnData != null && returnData.getReply_message().equals("登录成功!")) {
268-
App.context.startService(new Intent(App.context, WiFiDetectService.class));
271+
App.context.startService(new Intent(App.context, ConnectService.class));
269272
if (sharedPreferences.getString("username", null) == null) {
270273
storeInfo();
271274
}
@@ -290,14 +293,10 @@ public void connectNow() {
290293
public void storeInfo() {
291294
String username = usernameEdit.getText().toString();
292295
String password = passwordEdit.getText().toString();
293-
editor.putString("username", username);
294-
editor.putString("password", password);
295-
editor.commit();
296296
if (username.length() > 0 && password.length() > 0) {
297-
editor.putString("username", username);
298-
editor.putString("password", password);
299-
editor.commit();
300-
App.context.startService(new Intent(App.context, WiFiDetectService.class));
297+
ConnectService.setUsername(username);
298+
ConnectService.setPassword(password);
299+
App.context.startService(new Intent(App.context, ConnectService.class));
301300
Log.i("配置文件", "保存了用户名密码");
302301
Log.i("保存", " 保存后开启了服务");
303302
ShowOnMainActivity((String) getResources().getText(R.string.saved_success));
@@ -368,8 +367,7 @@ public void allowStatics(View view) {
368367
}
369368

370369
public void staticsButtonOnClicked(boolean allow) {
371-
editor.putBoolean("allow_statistics", allow);
372-
editor.commit();
370+
ConnectService.setAllowStatistics(allow);
373371
if (allow) {
374372
Toast.makeText(App.context, (String) getResources().getText(R.string.have_allowed_statistics), Toast.LENGTH_SHORT).show();
375373
AVObject Like = new AVObject("AllowData");
@@ -444,7 +442,6 @@ private void downloadNow() {
444442
* @param permissions
445443
* @param grantResults
446444
*/
447-
448445
@Override
449446
public void onRequestPermissionsResult(int requestCode,
450447
String permissions[], int[] grantResults) {
@@ -527,3 +524,17 @@ public void done(List<AVObject> avObjects, AVException e) {
527524

528525
};
529526

527+
/**
528+
* 用于实验缓存多大时文件读写速度最快,测量所用时间
529+
*/
530+
/*class Timer {
531+
long s;
532+
public long start() {
533+
s = System.currentTimeMillis();
534+
return s;
535+
}
536+
public long end() {
537+
return System.currentTimeMillis() - s;
538+
}
539+
}*/
540+

app/src/main/java/com/padeoe/autoconnect/receiver/BootReceiver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import android.content.Intent;
66
import android.content.SharedPreferences;
77

8-
import com.padeoe.autoconnect.service.WiFiDetectService;
8+
import com.padeoe.autoconnect.service.ConnectService;
99

1010
public class BootReceiver extends BroadcastReceiver {
1111
@Override
@@ -15,7 +15,7 @@ public void onReceive(Context context, Intent intent) {
1515
boolean isBanned = sharedPreferences.getBoolean("isBanned", false);
1616
String PostData = sharedPreferences.getString("PostData", null);
1717
if (!isBanned && PostData != null && PostData.length() > 0) {
18-
context.startService(new Intent(context, WiFiDetectService.class));
18+
context.startService(new Intent(context, ConnectService.class));
1919
}
2020
}
2121
}

app/src/main/java/com/padeoe/autoconnect/receiver/NetworkConnectChangedReceiver.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import android.util.Log;
1111

1212
import com.avos.avoscloud.AVAnalytics;
13-
import com.padeoe.autoconnect.service.WiFiDetectService;
13+
import com.padeoe.autoconnect.service.ConnectService;
1414
import com.padeoe.nicservice.njuwlan.service.LoginService;
1515

1616
/**
@@ -32,19 +32,19 @@ public void onReceive(final Context context, Intent intent) {
3232
WifiInfo wifiInfo = mWifi.getConnectionInfo();
3333
Log.d("wifiInfo:", wifiInfo.getSSID());
3434
if (wifiInfo.getSSID().equals("\"NJU-FAST\"") || wifiInfo.getSSID().equals("\"NJU-WLAN\"")) {
35-
Log.d("后台wifi连接检测", "是目标wifi");
35+
Log.i("后台登陆", "是目标ssid");
3636
if (i == 1) {
3737
new Thread() {
3838
@Override
3939
public void run() {
4040
try {
41-
if (WiFiDetectService.username != null & WiFiDetectService.password != null) {
41+
if (ConnectService.getUsername() != null & ConnectService.getPassword() != null) {
4242
Thread.sleep(200);
4343
for (int i = 0; i < 5; i++) {
4444
Log.i("后台登陆","第"+i+"次尝试");
45-
if (LoginService.getInstance().isLoginSuccess(LoginService.getInstance().connect(WiFiDetectService.username, WiFiDetectService.password))) {
45+
if (LoginService.isLoginSuccess(LoginService.getInstance().connect(ConnectService.getUsername(), ConnectService.getPassword()))) {
4646
Log.i("后台登陆","后台登陆成功");
47-
if (WiFiDetectService.allowStatistics) {
47+
if (ConnectService.isAllowStatistics()) {
4848
AVAnalytics.onEvent(context, "后台自动登陆NJU-WLAN成功");
4949
}
5050
break;
@@ -65,7 +65,7 @@ public void run() {
6565
} else
6666
i++;
6767
} else {
68-
Log.i("RESULT", "SSID不是目标");
68+
Log.i("RESULT", "SSID不是目标,SSID是"+wifiInfo.getSSID());
6969
}
7070
}
7171
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package com.padeoe.autoconnect.service;
2+
3+
import android.app.Service;
4+
import android.content.Intent;
5+
import android.content.IntentFilter;
6+
import android.content.SharedPreferences;
7+
import android.net.wifi.WifiManager;
8+
import android.os.IBinder;
9+
10+
import com.padeoe.autoconnect.activity.App;
11+
import com.padeoe.autoconnect.receiver.NetworkConnectChangedReceiver;
12+
13+
public class ConnectService extends Service {
14+
private static boolean allowStatistics=false;
15+
private static String username;
16+
private static String password;
17+
static final SharedPreferences sharedPreferences = App.context.getSharedPreferences("DataFile", 0);
18+
static SharedPreferences.Editor editor = sharedPreferences.edit();
19+
NetworkConnectChangedReceiver networkConnectChangedReceiver=new NetworkConnectChangedReceiver();
20+
@Override
21+
public IBinder onBind(Intent intent) {
22+
// TODO: Return the communication channel to the service.
23+
throw new UnsupportedOperationException("Not yet implemented");
24+
}
25+
26+
@Override
27+
public void onCreate() {
28+
System.out.println("onCreate"+"正在读文件");
29+
// TODO Auto-generated method stub
30+
super.onCreate();
31+
username = sharedPreferences.getString("username", null);
32+
password = sharedPreferences.getString("password", null);
33+
allowStatistics = sharedPreferences.getBoolean("allow_statistics", false);
34+
35+
IntentFilter filter = new IntentFilter();
36+
filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
37+
filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
38+
registerReceiver(networkConnectChangedReceiver, filter);
39+
}
40+
41+
@Override
42+
public void onDestroy() {
43+
super.onDestroy();
44+
System.out.println("onDestroyed");
45+
unregisterReceiver(networkConnectChangedReceiver);
46+
}
47+
48+
public static boolean isAllowStatistics() {
49+
return allowStatistics;
50+
}
51+
52+
public static void setAllowStatistics(boolean allowStatistics) {
53+
ConnectService.allowStatistics = allowStatistics;
54+
editor.putBoolean("allow_statistics",allowStatistics);
55+
editor.apply();
56+
}
57+
58+
public static String getUsername() {
59+
if(username==null){
60+
System.out.println("正在读文件");
61+
username=sharedPreferences.getString("username",null);
62+
}
63+
return username;
64+
}
65+
66+
public static void setUsername(String username) {
67+
ConnectService.username = username;
68+
editor.putString("username",username);
69+
editor.apply();
70+
}
71+
72+
public static String getPassword() {
73+
if(password==null){
74+
System.out.println("正在读文件");
75+
password=sharedPreferences.getString("password",null);
76+
}
77+
return password;
78+
}
79+
80+
public static void setPassword(String password) {
81+
ConnectService.password = password;
82+
editor.putString("password", password);
83+
editor.apply();
84+
}
85+
86+
}
87+

app/src/main/java/com/padeoe/autoconnect/service/WiFiDetectService.java

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)