diff --git a/KUASWifiAutoLogin/.idea/workspace.xml b/KUASWifiAutoLogin/.idea/workspace.xml
index 02c574d..e5f1a87 100644
--- a/KUASWifiAutoLogin/.idea/workspace.xml
+++ b/KUASWifiAutoLogin/.idea/workspace.xml
@@ -6,7 +6,7 @@
-
+
@@ -36,43 +36,31 @@
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
+
@@ -545,6 +533,11 @@
+
+
+
+
+
@@ -555,6 +548,11 @@
+
+
+
+
+
@@ -1086,6 +1084,11 @@
+
+
+
+
+
@@ -1096,6 +1099,11 @@
+
+
+
+
+
@@ -1240,7 +1248,7 @@
-
-
+
+
+
+
+
@@ -1502,18 +1513,24 @@
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
+
+
@@ -1556,7 +1573,10 @@
+
+
+
@@ -1574,12 +1594,67 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
@@ -1602,6 +1677,14 @@
+
+
+
+
+
+
+
+
@@ -1793,7 +1876,7 @@
-
+
@@ -1807,7 +1890,7 @@
-
+
@@ -1837,43 +1920,12 @@
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1893,19 +1945,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -1917,21 +1957,19 @@
-
-
-
-
+
+
+
-
@@ -1939,20 +1977,18 @@
-
-
-
-
-
+
+
+
@@ -1964,15 +2000,7 @@
-
-
-
-
-
-
-
-
-
+
@@ -1980,19 +2008,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -2004,21 +2020,19 @@
-
-
-
-
+
+
+
-
@@ -2026,20 +2040,18 @@
-
-
-
-
-
+
+
+
@@ -2048,33 +2060,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -2083,21 +2068,19 @@
-
-
-
-
+
+
+
-
-
+
@@ -2105,134 +2088,172 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
+
-
+
+
-
+
-
-
+
+
-
-
-
-
+
-
+
-
+
-
+
-
-
+
+
-
-
-
-
+
-
-
+
+
-
+
-
+
-
+
-
+
-
-
+
+
-
+
+
-
-
-
+
-
+
-
-
+
-
-
-
-
+
-
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
+
@@ -2243,69 +2264,58 @@
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
+
-
+
-
+
+
-
+
-
+
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
diff --git a/KUASWifiAutoLogin/app/app.iml b/KUASWifiAutoLogin/app/app.iml
index 27c25e5..a56ed2c 100644
--- a/KUASWifiAutoLogin/app/app.iml
+++ b/KUASWifiAutoLogin/app/app.iml
@@ -72,8 +72,10 @@
+
+
@@ -93,14 +95,17 @@
+
+
+
\ No newline at end of file
diff --git a/KUASWifiAutoLogin/app/build.gradle b/KUASWifiAutoLogin/app/build.gradle
index 4214ac3..e9942ec 100644
--- a/KUASWifiAutoLogin/app/build.gradle
+++ b/KUASWifiAutoLogin/app/build.gradle
@@ -22,9 +22,11 @@ android {
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.2.0'
- compile 'com.jakewharton:butterknife:6.1.0'
compile 'com.loopj.android:android-async-http:1.4.7'
- compile 'com.nineoldandroids:library:2.4.0'
compile 'com.daimajia.easing:library:1.0.2'
compile 'com.google.android.gms:play-services-analytics:7.5.0'
+ compile 'org.jsoup:jsoup:1.8.2'
+ compile 'com.github.rey5137:material:1.1.1'
+ compile 'com.jakewharton:butterknife:6.1.0'
+ compile 'com.nineoldandroids:parent:2.4.0'
}
diff --git a/KUASWifiAutoLogin/app/src/main/AndroidManifest.xml b/KUASWifiAutoLogin/app/src/main/AndroidManifest.xml
index 3f7ea72..a834334 100644
--- a/KUASWifiAutoLogin/app/src/main/AndroidManifest.xml
+++ b/KUASWifiAutoLogin/app/src/main/AndroidManifest.xml
@@ -5,7 +5,6 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/KUASWifiAutoLogin/app/src/main/java/tw/edu/kuas/wifiautologin/MainActivity.java b/KUASWifiAutoLogin/app/src/main/java/tw/edu/kuas/wifiautologin/MainActivity.java
index 0b26904..287410c 100644
--- a/KUASWifiAutoLogin/app/src/main/java/tw/edu/kuas/wifiautologin/MainActivity.java
+++ b/KUASWifiAutoLogin/app/src/main/java/tw/edu/kuas/wifiautologin/MainActivity.java
@@ -1,15 +1,11 @@
package tw.edu.kuas.wifiautologin;
import android.app.Activity;
-import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.KeyEvent;
-import android.view.MenuItem;
import android.view.View;
-import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
-import android.widget.Button;
import android.widget.EditText;
import android.widget.TableLayout;
import android.widget.TextView;
@@ -19,18 +15,22 @@
import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.HitBuilders;
import com.google.android.gms.analytics.Tracker;
+import com.rey.material.widget.Button;
+import com.rey.material.widget.ProgressView;
import butterknife.ButterKnife;
import butterknife.InjectView;
+import butterknife.OnClick;
import tw.edu.kuas.wifiautologin.callbacks.Constant;
import tw.edu.kuas.wifiautologin.callbacks.GeneralCallback;
import tw.edu.kuas.wifiautologin.callbacks.Memory;
import tw.edu.kuas.wifiautologin.libs.LoginHelper;
+import tw.edu.kuas.wifiautologin.libs.Utils;
-public class MainActivity extends Activity implements OnClickListener {
+public class MainActivity extends Activity {
@InjectView(R.id.button_login)
- Button mLoginButton;
+ Button mLoginButton;
@InjectView(R.id.editText_user)
EditText mUsernameEditText;
@@ -44,6 +44,9 @@ public class MainActivity extends Activity implements OnClickListener {
@InjectView(R.id.tableLayout)
TableLayout mTableLayout;
+ @InjectView(R.id.progressView)
+ ProgressView mProgressView;
+
public static GoogleAnalytics analytics;
public static Tracker tracker;
@@ -57,22 +60,20 @@ protected void onCreate(Bundle savedInstanceState) {
}
private void setUpViews() {
- mLoginButton.setOnClickListener(this);
mUsernameEditText.setText(Memory.getString(this, Constant.MEMORY_KEY_USER, ""));
mPasswordEditText.setText(Memory.getString(this, Constant.MEMORY_KEY_PASSWORD, ""));
mPasswordEditText.setImeActionLabel(getText(R.string.ime_submit), KeyEvent.KEYCODE_ENTER);
mPasswordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
-
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
- saveAndLogin();
+ mLoginButton.performClick();
return false;
}
});
// init GA
analytics = GoogleAnalytics.getInstance(this);
- analytics.setLocalDispatchPeriod(1);
+ analytics.setLocalDispatchPeriod(30);
tracker = analytics.newTracker("UA-46334408-1");
tracker.enableExceptionReporting(true);
@@ -88,46 +89,26 @@ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
.build());
}
- /*
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.main, menu);
- return true;
- }
- */
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- int id = item.getItemId();
- switch (id) {
- case R.id.about:
- startActivity(new Intent(this, AboutActivity.class));
- return true;
-
- default:
- return super.onOptionsItemSelected(item);
- }
-
- }
+ @OnClick (R.id.button_login)
+ public void submit() {
+ tracker.send(new HitBuilders.EventBuilder()
+ .setCategory("UX")
+ .setAction("Click")
+ .setLabel("Save & Login")
+ .build());
- @Override
- public void onClick(View v) {
- if (v == mLoginButton) {
- tracker.send(new HitBuilders.EventBuilder()
- .setCategory("UX")
- .setAction("Click")
- .setLabel("Save & Login")
- .build());
-
- mDebugTextView.setVisibility(View.GONE);
- mLoginButton.setEnabled(false);
- mTableLayout.setEnabled(false);
- InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
- imm.hideSoftInputFromWindow(mUsernameEditText.getWindowToken(), 0);
- imm.hideSoftInputFromWindow(mPasswordEditText.getWindowToken(), 0);
- saveAndLogin();
- }
- }
+ mDebugTextView.setVisibility(View.GONE);
+ mLoginButton.setEnabled(false);
+ mTableLayout.setEnabled(false);
+ mLoginButton.setBackgroundResource(R.drawable.button_bluegrey);
+ mProgressView.setVisibility(View.VISIBLE);
+ InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
+ imm.hideSoftInputFromWindow(mUsernameEditText.getWindowToken(), 0);
+ imm.hideSoftInputFromWindow(mPasswordEditText.getWindowToken(), 0);
+ mUsernameEditText.clearFocus();
+ mPasswordEditText.clearFocus();
+ saveAndLogin();
+ }
private void saveAndLogin() {
Memory.setString(this, Constant.MEMORY_KEY_USER, mUsernameEditText.getText().toString());
@@ -144,8 +125,15 @@ private void saveAndLogin() {
else
userData = tranUser(mUsernameEditText.getText().toString());
+ String loginType = userData.split(",")[2];
+ String ssid = Utils.getCurrentSsid(this);
+
+ if (ssid != null)
+ if (ssid.equals(Constant.EXPECTED_SSIDS[2]))
+ loginType = "Dorm";
+
LoginHelper.login(this, userData.split(",")[1], userData.split(",")[0],
- password, userData.split(",")[2], new GeneralCallback() {
+ password, loginType, new GeneralCallback() {
@Override
public void onSuccess(String message) {
@@ -190,6 +178,8 @@ private void showMessage(CharSequence message, boolean shake) {
YoYo.with(Techniques.Shake).duration(700).playOn(mDebugTextView);
mLoginButton.setEnabled(true);
mTableLayout.setEnabled(true);
+ mProgressView.setVisibility(View.GONE);
+ mLoginButton.setBackgroundResource(R.drawable.button_blue);
tracker.send(new HitBuilders.EventBuilder()
.setCategory("UX")
@@ -197,4 +187,4 @@ private void showMessage(CharSequence message, boolean shake) {
.setLabel(message.toString())
.build());
}
-}
+}
\ No newline at end of file
diff --git a/KUASWifiAutoLogin/app/src/main/java/tw/edu/kuas/wifiautologin/WifiReceiver.java b/KUASWifiAutoLogin/app/src/main/java/tw/edu/kuas/wifiautologin/WifiReceiver.java
index 77b441d..4760345 100644
--- a/KUASWifiAutoLogin/app/src/main/java/tw/edu/kuas/wifiautologin/WifiReceiver.java
+++ b/KUASWifiAutoLogin/app/src/main/java/tw/edu/kuas/wifiautologin/WifiReceiver.java
@@ -7,7 +7,6 @@
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;
import android.util.Log;
-import android.widget.Toast;
import tw.edu.kuas.wifiautologin.callbacks.Constant;
import tw.edu.kuas.wifiautologin.callbacks.Memory;
@@ -28,15 +27,16 @@ public void onReceive(final Context context, Intent intent) {
String ssid = manager.getConnectionInfo().getSSID().replace("\"", "");
if (Utils.isExpectedSsid(ssid)) {
// connected
- String infoString =
- String.format(context.getString(R.string.connected_to_ssid), ssid);
- Toast.makeText(context, infoString, Toast.LENGTH_SHORT).show();
String user = Memory.getString(context, Constant.MEMORY_KEY_USER, null);
String password = Memory.getString(context, Constant.MEMORY_KEY_PASSWORD, null);
if (user != null && password != null) {
String userData = tranUser(user);
- LoginHelper.login(context, userData.split(",")[1], userData.split(",")[0],
- password, userData.split(",")[2], null);
+ if (ssid.equals(Constant.EXPECTED_SSIDS[2]))
+ LoginHelper.login(context, userData.split(",")[1], userData.split(",")[0],
+ password, "Dorm", null);
+ else
+ LoginHelper.login(context, userData.split(",")[1], userData.split(",")[0],
+ password, userData.split(",")[2], null);
}
}
}
diff --git a/KUASWifiAutoLogin/app/src/main/java/tw/edu/kuas/wifiautologin/callbacks/Constant.java b/KUASWifiAutoLogin/app/src/main/java/tw/edu/kuas/wifiautologin/callbacks/Constant.java
index 685c43b..ecf7d8c 100644
--- a/KUASWifiAutoLogin/app/src/main/java/tw/edu/kuas/wifiautologin/callbacks/Constant.java
+++ b/KUASWifiAutoLogin/app/src/main/java/tw/edu/kuas/wifiautologin/callbacks/Constant.java
@@ -5,10 +5,16 @@ public class Constant {
public static final String[] EXPECTED_SSIDS = {"kuas_wireless", "KUAS", "KUAS-Dorm"};
public static final String TAG = "HearSilent";
+ public static final String USER_AGENT = "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0";
+ public static final int TIMEOUT = 5000;
+ public static final String JIANGONG_WIFI_SERVER = "172.16.61.253";
+ public static final String YANCHAO_WIFI_SERVER = "172.16.109.253";
+
// Notification IDs
public static final int NOTIFICATION_LOGIN_ID = 100;
// Memory (Shared Preferences) Keys
public static final String MEMORY_KEY_USER = "MEMORY_KEY_USER";
public static final String MEMORY_KEY_PASSWORD = "MEMORY_KEY_PASSWORD";
+
}
diff --git a/KUASWifiAutoLogin/app/src/main/java/tw/edu/kuas/wifiautologin/libs/LoginHelper.java b/KUASWifiAutoLogin/app/src/main/java/tw/edu/kuas/wifiautologin/libs/LoginHelper.java
index b9ab0d6..e21d56d 100644
--- a/KUASWifiAutoLogin/app/src/main/java/tw/edu/kuas/wifiautologin/libs/LoginHelper.java
+++ b/KUASWifiAutoLogin/app/src/main/java/tw/edu/kuas/wifiautologin/libs/LoginHelper.java
@@ -9,6 +9,8 @@
import android.net.Uri;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
+import android.os.Handler;
+import android.os.Looper;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import android.widget.Toast;
@@ -18,9 +20,14 @@
import com.google.android.gms.analytics.Tracker;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
-import com.loopj.android.http.RequestParams;
import org.apache.http.Header;
+import org.jsoup.Connection;
+import org.jsoup.Jsoup;
+
+import java.io.IOException;
+import java.util.LinkedHashMap;
+import java.util.Map;
import tw.edu.kuas.wifiautologin.MainActivity;
import tw.edu.kuas.wifiautologin.R;
@@ -29,7 +36,6 @@
public class LoginHelper {
private static AsyncHttpClient mClient = init();
- private static AsyncHttpClient mTestClient = initTest();
private static NotificationManager mNotificationManager;
private static NotificationCompat.Builder mBuilder;
@@ -39,16 +45,8 @@ public class LoginHelper {
private static AsyncHttpClient init() {
AsyncHttpClient client = new AsyncHttpClient();
- client.addHeader("Connection", "Keep-Alive");
- client.setTimeout(7500);
- client.setEnableRedirects(false);
- return client;
- }
-
- private static AsyncHttpClient initTest() {
- AsyncHttpClient client = new AsyncHttpClient();
- client.addHeader("Connection", "Keep-Alive");
- client.setTimeout(5000);
+ client.setTimeout(Constant.TIMEOUT);
+ client.setUserAgent(Constant.USER_AGENT);
client.setEnableRedirects(false);
return client;
}
@@ -57,7 +55,7 @@ public static void login(final Context context, String idType, String user, Stri
final String loginType, final GeneralCallback callback) {
// init GA
analytics = GoogleAnalytics.getInstance(context);
- analytics.setLocalDispatchPeriod(1);
+ analytics.setLocalDispatchPeriod(30);
tracker = analytics.newTracker("UA-46334408-1");
tracker.enableExceptionReporting(true);
@@ -79,14 +77,11 @@ public static void login(final Context context, String idType, String user, Stri
return;
}
- Log.d(Constant.TAG, getIPAddress(context));
-
- final RequestParams params = new RequestParams();
- params.put("idtype", idType);
- params.put("username", user);
- params.put("userpwd", password);
- params.put("login", "登入");
- params.put("orig_referer", "http://www.kuas.edu.tw/bin/home.php");
+ final Map paramsMap = new LinkedHashMap<>();
+ paramsMap.put("username", user);
+ paramsMap.put("userpwd", password);
+ paramsMap.put("login", "");
+ paramsMap.put("orig_referer", "");
mNotificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
@@ -95,7 +90,10 @@ public static void login(final Context context, String idType, String user, Stri
String.format(context.getString(R.string.login_to_ssid), currentSsid))
.setSmallIcon(R.drawable.ic_stat_login).setProgress(0, 0, true).setOngoing(false);
- mTestClient.get(context, "http://www.example.com", new AsyncHttpResponseHandler() {
+ mClient.get(context, "http://www.example.com", new AsyncHttpResponseHandler() {
+ String _IP = getIPAddress(context);
+ String loginServer = "";
+
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] bytes) {
String resultString = context.getString(R.string.login_ready);
@@ -112,16 +110,14 @@ public void onSuccess(int statusCode, Header[] headers, byte[] bytes) {
if (callback != null)
callback.onSuccess(resultString);
- loginSuccess(context, loginType, callback, "建工", resultString, true);
+ loginSuccess(context, loginType, callback, "建工", resultString, false);
Toast.makeText(context, resultString, Toast.LENGTH_SHORT).show();
} else {
mNotificationManager.notify(Constant.NOTIFICATION_LOGIN_ID, mBuilder.build());
- String loginServer = "";
if (headers != null) {
for (Header header : headers) {
- if (header.getName().toLowerCase().equals("location"))
- {
+ if (header.getName().toLowerCase().equals("location")) {
Uri uri = Uri.parse(header.getValue());
loginServer = uri.getAuthority();
break;
@@ -130,12 +126,11 @@ public void onSuccess(int statusCode, Header[] headers, byte[] bytes) {
}
if (!loginServer.equals(""))
- loginWithHeader(context, params, loginType, callback, false, loginServer);
+ loginWithHeader(context, paramsMap, loginType, callback, false, loginServer);
+ else if (_IP.split("\\.")[0].equals("172") && _IP.split("\\.")[1].equals("17"))
+ loginWithHeader(context, paramsMap, loginType, callback, true, Constant.JIANGONG_WIFI_SERVER);
else
- if (_IP.split("\\.")[0].equals("172") && _IP.split("\\.")[1].equals("17"))
- loginJiangong(context, params, loginType, callback, true);
- else
- loginYanchao(context, params, loginType, callback, true);
+ loginWithHeader(context, paramsMap, loginType, callback, true, Constant.YANCHAO_WIFI_SERVER);
}
}
@@ -143,12 +138,9 @@ public void onSuccess(int statusCode, Header[] headers, byte[] bytes) {
public void onFailure(int statusCode, Header[] headers, byte[] bytes, Throwable throwable) {
mNotificationManager.notify(Constant.NOTIFICATION_LOGIN_ID, mBuilder.build());
- String _IP = getIPAddress(context);
- String loginServer = "";
if (headers != null) {
for (Header header : headers) {
- if (header.getName().toLowerCase().equals("location"))
- {
+ if (header.getName().toLowerCase().equals("location")) {
Uri uri = Uri.parse(header.getValue());
loginServer = uri.getAuthority();
break;
@@ -157,150 +149,95 @@ public void onFailure(int statusCode, Header[] headers, byte[] bytes, Throwable
}
if (!loginServer.equals(""))
- loginWithHeader(context, params, loginType, callback, false, loginServer);
+ loginWithHeader(context, paramsMap, loginType, callback, false, loginServer);
+ else if (_IP.split("\\.")[0].equals("172") && _IP.split("\\.")[1].equals("17"))
+ loginWithHeader(context, paramsMap, loginType, callback, true, Constant.JIANGONG_WIFI_SERVER);
else
- if (_IP.split("\\.")[0].equals("172") && _IP.split("\\.")[1].equals("17"))
- loginJiangong(context, params, loginType, callback, true);
- else
- loginYanchao(context, params, loginType, callback, true);
+ loginWithHeader(context, paramsMap, loginType, callback, true, Constant.YANCHAO_WIFI_SERVER);
}
});
}
- private static void loginWithHeader(final Context context, final RequestParams params, final String loginType,
- final GeneralCallback callback, final boolean firstCheck, final String loginServer) {
- Log.d(Constant.TAG, "loginWithHeader");
-
- mClient.post(context, "http://" + loginServer + "/cgi-bin/ace_web_auth.cgi", params,
- new AsyncHttpResponseHandler() {
-
- @Override
- public void onSuccess(int statusCode, Header[] headers, byte[] response) {
-
- mTestClient.get(context, "http://www.example.com", new AsyncHttpResponseHandler() {
- @Override
- public void onSuccess(int statusCode, Header[] headers, byte[] bytes) {
- if (statusCode == 200)
- loginSuccess(context, loginType, callback, loginServer, "", true);
- else
- retryLogin(context, params, loginType, callback, firstCheck, loginServer, statusCode);
- }
-
- @Override
- public void onFailure(int statusCode, Header[] headers, byte[] bytes, Throwable e) {
- e.printStackTrace();
-
- retryLogin(context, params, loginType, callback, firstCheck, loginServer, statusCode);
+ private static void loginWithHeader(final Context context, final Map paramsMap, final String loginType,
+ final GeneralCallback callback, final boolean retry, final String loginServer) {
+ final Handler refresh = new Handler(Looper.getMainLooper());
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ try{
+ Connection.Response response = Jsoup.connect(String.format("http://%s/cgi-bin/ace_web_auth.cgi", loginServer))
+ .data(paramsMap)
+ .userAgent(Constant.USER_AGENT)
+ .timeout(Constant.TIMEOUT)
+ .followRedirects(false)
+ .ignoreContentType(true)
+ .ignoreHttpErrors(true)
+ .method(Connection.Method.POST)
+ .execute();
+
+ final int statusCode = response.statusCode();
+
+ if(statusCode != 200) {
+ refresh.post(new Runnable() {
+ public void run() {
+ mClient.get(context, "http://www.example.com/", new AsyncHttpResponseHandler() {
+ @Override
+ public void onSuccess(final int statusCode, Header[] headers, byte[] bytes) {
+ if (statusCode == 200)
+ loginSuccess(context, loginType, callback, loginServer, "", true);
+ else
+ retryLogin(context, paramsMap, loginType, callback, retry, loginServer, "");
+ }
+
+ @Override
+ public void onFailure(final int statusCode, Header[] headers, byte[] bytes, Throwable e) {
+ e.printStackTrace();
+
+ retryLogin(context, paramsMap, loginType, callback, retry, loginServer, "");
+ }
+ });
}
});
}
-
- @Override
- public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {
- e.printStackTrace();
-
- retryLogin(context, params, loginType, callback, firstCheck, loginServer, statusCode);
+ else {
+ refresh.post(new Runnable() {
+ public void run() {
+ retryLogin(context, paramsMap, loginType, callback, retry, loginServer, "");
+ }
+ });
}
- });
- }
-
- private static void loginJiangong(final Context context, final RequestParams params,
- final String loginType, final GeneralCallback callback, final boolean firstCheck) {
- Log.d(Constant.TAG, "loginJiangong");
-
- mClient.post(context, "http://172.16.61.253/cgi-bin/ace_web_auth.cgi", params,
- new AsyncHttpResponseHandler() {
-
- @Override
- public void onSuccess(int statusCode, Header[] headers, byte[] response) {
-
- mTestClient.get(context, "http://www.example.com", new AsyncHttpResponseHandler() {
- @Override
- public void onSuccess(int statusCode, Header[] headers, byte[] bytes) {
- if (statusCode == 200)
- loginSuccess(context, loginType, callback, "建工", "", true);
- else
- retryLogin(context, params, loginType, callback, firstCheck, "建工", statusCode);
- }
-
- @Override
- public void onFailure(int statusCode, Header[] headers, byte[] bytes, Throwable e) {
- e.printStackTrace();
-
- retryLogin(context, params, loginType, callback, firstCheck, "建工", statusCode);
- }
- });
- }
-
- @Override
- public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {
+ } catch (IOException e) {
e.printStackTrace();
-
- retryLogin(context, params, loginType, callback, firstCheck, "建工", statusCode);
- }
- });
- }
-
- private static void loginYanchao(final Context context, final RequestParams params,
- final String loginType, final GeneralCallback callback, final boolean firstCheck) {
- Log.d(Constant.TAG, "loginYanchao");
-
- mClient.post(context, "http://172.16.109.253/cgi-bin/ace_web_auth.cgi", params,
- new AsyncHttpResponseHandler() {
-
- @Override
- public void onSuccess(int statusCode, Header[] headers, final byte[] response) {
-
- mTestClient.get(context, "http://www.example.com", new AsyncHttpResponseHandler() {
- @Override
- public void onSuccess(int statusCode, Header[] headers, byte[] bytes) {
- if (statusCode == 200)
- loginSuccess(context, loginType, callback, "燕巢", "", true);
- else
- retryLogin(context, params, loginType, callback, firstCheck, "燕巢", statusCode);
- }
-
- @Override
- public void onFailure(int statusCode, Header[] headers, byte[] bytes, Throwable e) {
- e.printStackTrace();
-
- retryLogin(context, params, loginType, callback, firstCheck, "燕巢", statusCode);
+ refresh.post(new Runnable() {
+ public void run() {
+ retryLogin(context, paramsMap, loginType, callback, retry, loginServer,
+ context.getString(R.string.login_timeout));
}
});
}
-
- @Override
- public void onFailure(int statusCode, Header[] headers, byte[] errorResponse,
- Throwable e) {
- e.printStackTrace();
-
- retryLogin(context, params, loginType, callback, firstCheck, "燕巢", statusCode);
- }
- });
+ }
+ }).start();
}
- private static void retryLogin(Context context, RequestParams params, String loginType,
- GeneralCallback callback, boolean firstCheck, String loginSpace, int statusCode)
+ private static void retryLogin(Context context, final Map paramsMap, String loginType,
+ GeneralCallback callback, boolean retry, String loginServer, String resultString)
{
- String _IP = getIPAddress(context);
-
- if (firstCheck) {
+ if (retry) {
tracker.send(new HitBuilders.EventBuilder()
.setCategory("retryLogin")
.setAction("onTry")
- .setLabel(loginSpace + statusCode + "/" + _IP + "/" + loginType)
+ .setLabel((loginServer.equals(Constant.JIANGONG_WIFI_SERVER) ? "建工" : "燕巢") + "/" + loginType)
.build());
- if (loginSpace.equals("燕巢"))
- loginJiangong(context, params, loginType, callback, false);
+ if (loginServer.equals(Constant.JIANGONG_WIFI_SERVER))
+ loginWithHeader(context, paramsMap, loginType, callback, false, Constant.YANCHAO_WIFI_SERVER);
else
- loginYanchao(context, params, loginType, callback, false);
+ loginWithHeader(context, paramsMap, loginType, callback, false, Constant.JIANGONG_WIFI_SERVER);
return;
}
- String resultString;
-
- resultString = context.getString(R.string.failed_to_login);
+ if (resultString.equals(""))
+ resultString = context.getString(R.string.failed_to_login);
mBuilder.setContentTitle(context.getString(R.string.app_name))
.setContentText(resultString).setSmallIcon(R.drawable.ic_stat_login)
.setContentIntent(getFailPendingIntent(context))
@@ -322,24 +259,36 @@ private static void retryLogin(Context context, RequestParams params, String log
tracker.send(new HitBuilders.EventBuilder()
.setCategory("UX")
.setAction("onFailure")
- .setLabel(loginSpace + "/" + _IP + "/" + loginType)
+ .setLabel((loginServer.equals(Constant.JIANGONG_WIFI_SERVER) ? "建工" : "燕巢") + "/" + loginType)
.build());
}
- private static void loginSuccess(Context context, String loginType, GeneralCallback callback, String loginSpace, String resultString, boolean vibrate)
+ private static void loginSuccess(Context context, String loginType, GeneralCallback callback,
+ String loginServer, String resultString, boolean notify)
{
if (resultString.equals(""))
{
switch (loginType)
{
case "Student":
- resultString = context.getString(R.string.login_successfully);
+ resultString = String.format(context.getString(R.string.login_successfully),
+ (loginServer.equals(Constant.JIANGONG_WIFI_SERVER) ? context.getString(R.string.jiangong) :
+ context.getString(R.string.yanchao)));
break;
case "Cyber":
- resultString = context.getString(R.string.login_cyber_successfully);
+ resultString = String.format(context.getString(R.string.login_cyber_successfully),
+ (loginServer.equals(Constant.JIANGONG_WIFI_SERVER) ? context.getString(R.string.jiangong) :
+ context.getString(R.string.yanchao)));
+ break;
+ case "Dorm":
+ resultString = String.format(context.getString(R.string.login_dorm_successfully),
+ (loginServer.equals(Constant.JIANGONG_WIFI_SERVER) ? context.getString(R.string.jiangong) :
+ context.getString(R.string.yanchao)));
break;
default:
- resultString = context.getString(R.string.login_guest_successfully);
+ resultString = String.format(context.getString(R.string.login_guest_successfully),
+ (loginServer.equals(Constant.JIANGONG_WIFI_SERVER) ? context.getString(R.string.jiangong) :
+ context.getString(R.string.yanchao)));
}
}
@@ -352,10 +301,7 @@ private static void loginSuccess(Context context, String loginType, GeneralCallb
.setAutoCancel(true)
.setProgress(0, 0, false);
- mNotificationManager
- .notify(Constant.NOTIFICATION_LOGIN_ID, mBuilder.build());
-
- if (vibrate)
+ if (notify)
{
mBuilder.setVibrate(new long[]{300, 200, 300, 200})
.setLights(Color.GREEN, 800, 800)
@@ -364,9 +310,15 @@ private static void loginSuccess(Context context, String loginType, GeneralCallb
tracker.send(new HitBuilders.EventBuilder()
.setCategory("UX")
.setAction("onSuccess")
- .setLabel(loginSpace + "/" + loginType)
+ .setLabel((loginServer.equals(Constant.JIANGONG_WIFI_SERVER) ? "建工" : "燕巢") + "/" + loginType)
.build());
}
+
+ mBuilder.setStyle(new NotificationCompat.BigTextStyle()
+ .bigText(resultString));
+
+ mNotificationManager
+ .notify(Constant.NOTIFICATION_LOGIN_ID, mBuilder.build());
}
public static String getIPAddress(Context context) {
diff --git a/KUASWifiAutoLogin/app/src/main/res/drawable/button_blue.xml b/KUASWifiAutoLogin/app/src/main/res/drawable/button_blue.xml
index 2ff4480..e67164f 100644
--- a/KUASWifiAutoLogin/app/src/main/res/drawable/button_blue.xml
+++ b/KUASWifiAutoLogin/app/src/main/res/drawable/button_blue.xml
@@ -9,7 +9,7 @@
android:type="radial"
android:gradientRadius="20"
android:angle="270" />
-
+
+ -
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/KUASWifiAutoLogin/app/src/main/res/drawable/login_table_bottom.xml b/KUASWifiAutoLogin/app/src/main/res/drawable/login_table_bottom.xml
index 66e1e63..f927ddc 100644
--- a/KUASWifiAutoLogin/app/src/main/res/drawable/login_table_bottom.xml
+++ b/KUASWifiAutoLogin/app/src/main/res/drawable/login_table_bottom.xml
@@ -3,6 +3,9 @@
-
+
@@ -19,6 +22,9 @@
android:right="12dp"
android:bottom="12dp" />
+
diff --git a/KUASWifiAutoLogin/app/src/main/res/drawable/login_table_top.xml b/KUASWifiAutoLogin/app/src/main/res/drawable/login_table_top.xml
index a8a5f2e..807abdb 100644
--- a/KUASWifiAutoLogin/app/src/main/res/drawable/login_table_top.xml
+++ b/KUASWifiAutoLogin/app/src/main/res/drawable/login_table_top.xml
@@ -6,6 +6,9 @@
+
+
diff --git a/KUASWifiAutoLogin/app/src/main/res/layout-land/activity_main.xml b/KUASWifiAutoLogin/app/src/main/res/layout-land/activity_main.xml
index ea6fa6b..abb81c8 100644
--- a/KUASWifiAutoLogin/app/src/main/res/layout-land/activity_main.xml
+++ b/KUASWifiAutoLogin/app/src/main/res/layout-land/activity_main.xml
@@ -2,6 +2,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
@@ -16,8 +17,8 @@
android:orientation="vertical">
@@ -51,6 +52,7 @@
android:layout_marginLeft="20sp"
android:layout_marginRight="20sp"
android:id="@+id/tableLayout">
+
+
-
+ android:layout_marginRight="20sp"
+ app:rd_enable="true"/>
+
+
+
\ No newline at end of file
diff --git a/KUASWifiAutoLogin/app/src/main/res/layout/activity_main.xml b/KUASWifiAutoLogin/app/src/main/res/layout/activity_main.xml
index 71a36d2..a8ee597 100644
--- a/KUASWifiAutoLogin/app/src/main/res/layout/activity_main.xml
+++ b/KUASWifiAutoLogin/app/src/main/res/layout/activity_main.xml
@@ -1,5 +1,6 @@
@@ -7,6 +8,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
+ android:focusable="true"
+ android:focusableInTouchMode="true"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical"
@@ -16,8 +19,10 @@
tools:context="com.devandroid.ncuwlogin.MainActivity">
@@ -37,6 +42,7 @@
android:layout_marginLeft="40sp"
android:layout_marginRight="40sp"
android:id="@+id/tableLayout">
+
+
-
+ android:layout_marginRight="40sp"
+ app:rd_enable="true"/>
+
+
登出
高應無線通
登入成功。
- Wi-Fi 登入成功, 歡迎來到高雄應用科技大學!
- 賓客登入成功, 歡迎來到高雄應用科技大學!
- 漫遊登入成功, 歡迎來到高雄應用科技大學!
- 宿舍登入成功, 歡迎回到宿舍!
+ 建工
+ 燕巢
+ Wi-Fi 登入成功, 歡迎來到高應大%s校區!
+ 賓客登入成功, 歡迎來到高應大%s校區!
+ 漫遊登入成功, 歡迎來到高應大%s校區!
+ 宿舍登入成功, 歡迎回到高應大%s宿舍!
您已經登入或是有可用網路了。
登出成功。
已連接到 %s。
@@ -20,6 +22,7 @@
正在登入 %s….
已經登入了。
登入失敗,請再嘗試一次。
+ 請求 Wi-Fi 伺服器的連線逾時。
已經登出了。
登出失敗。
關於
diff --git a/KUASWifiAutoLogin/app/src/main/res/values/colors.xml b/KUASWifiAutoLogin/app/src/main/res/values/colors.xml
index 7879e92..4038e36 100644
--- a/KUASWifiAutoLogin/app/src/main/res/values/colors.xml
+++ b/KUASWifiAutoLogin/app/src/main/res/values/colors.xml
@@ -1,9 +1,310 @@
- #3f51b5
- #303f9f
- #5c6bc0
- #ffffff
+ @color/md_indigo_500
+ @color/md_indigo_700
+ @color/md_indigo_400
+ @color/md_white
+
+
+ - #FF3F8AF8
+ - #FFD8433C
+ - #FFF2AF3A
+ - #FF279B5E
+
+
+
+ #fde0dc
+ #f9bdbb
+ #f69988
+ #f36c60
+ #e84e40
+ #e51c23
+ #dd191d
+ #d01716
+ #c41411
+ #b0120a
+ #ff7997
+ #ff5177
+ #ff2d6f
+ #e00032
+
+
+ #fce4ec
+ #f8bbd0
+ #f48fb1
+ #f06292
+ #ec407a
+ #e91e63
+ #d81b60
+ #c2185b
+ #ad1457
+ #880e4f
+ #ff80ab
+ #ff4081
+ #f50057
+ #c51162
+
+
+ #f3e5f5
+ #e1bee7
+ #ce93d8
+ #ba68c8
+ #ab47bc
+ #9c27b0
+ #8e24aa
+ #7b1fa2
+ #6a1b9a
+ #4a148c
+ #ea80fc
+ #e040fb
+ #d500f9
+ #aa00ff
+
+
+ #ede7f6
+ #d1c4e9
+ #b39ddb
+ #9575cd
+ #7e57c2
+ #673ab7
+ #5e35b1
+ #512da8
+ #4527a0
+ #311b92
+ #b388ff
+ #7c4dff
+ #651fff
+ #6200ea
+
+
+ #e8eaf6
+ #c5cae9
+ #9fa8da
+ #7986cb
+ #5c6bc0
+ #3f51b5
+ #3949ab
+ #303f9f
+ #283593
+ #1a237e
+ #8c9eff
+ #536dfe
+ #3d5afe
+ #304ffe
+
+
+ #e7e9fd
+ #d0d9ff
+ #afbfff
+ #91a7ff
+ #738ffe
+ #5677fc
+ #4e6cef
+ #455ede
+ #3b50ce
+ #2a36b1
+ #a6baff
+ #6889ff
+ #4d73ff
+ #4d69ff
+
+
+ #e1f5fe
+ #b3e5fc
+ #81d4fa
+ #4fc3f7
+ #29b6f6
+ #03a9f4
+ #039be5
+ #0288d1
+ #0277bd
+ #01579b
+ #80d8ff
+ #40c4ff
+ #00b0ff
+ #0091ea
+
+
+ #e0f7fa
+ #b2ebf2
+ #80deea
+ #4dd0e1
+ #26c6da
+ #00bcd4
+ #00acc1
+ #0097a7
+ #00838f
+ #006064
+ #84ffff
+ #18ffff
+ #00e5ff
+ #00b8d4
+
+
+ #e0f2f1
+ #b2dfdb
+ #80cbc4
+ #4db6ac
+ #26a69a
+ #009688
+ #00897b
+ #00796b
+ #00695c
+ #004d40
+ #a7ffeb
+ #64ffda
+ #1de9b6
+ #00bfa5
+
+
+ #d0f8ce
+ #a3e9a4
+ #72d572
+ #42bd41
+ #2baf2b
+ #259b24
+ #0a8f08
+ #0a7e07
+ #056f00
+ #0d5302
+ #a2f78d
+ #5af158
+ #14e715
+ #12c700
+
+
+ #f1f8e9
+ #dcedc8
+ #c5e1a5
+ #aed581
+ #9ccc65
+ #8bc34a
+ #7cb342
+ #689f38
+ #558b2f
+ #33691e
+ #ccff90
+ #b2ff59
+ #76ff03
+ #64dd17
+
+
+ #f9fbe7
+ #f0f4c3
+ #e6ee9c
+ #dce775
+ #d4e157
+ #cddc39
+ #c0ca33
+ #afb42b
+ #9e9d24
+ #827717
+ #f4ff81
+ #eeff41
+ #c6ff00
+ #aeea00
+
+
+ #fffde7
+ #fff9c4
+ #fff59d
+ #fff176
+ #ffee58
+ #ffeb3b
+ #fdd835
+ #fbc02d
+ #f9a825
+ #f57f17
+ #ffff8d
+ #ffff00
+ #ffea00
+ #ffd600
+
+
+ #fff8e1
+ #ffecb3
+ #ffe082
+ #ffd54f
+ #ffca28
+ #ffc107
+ #ffb300
+ #ffa000
+ #ff8f00
+ #ff6f00
+ #ffe57f
+ #ffd740
+ #ffc400
+ #ffab00
+
+
+ #fff3e0
+ #ffe0b2
+ #ffcc80
+ #ffb74d
+ #ffa726
+ #ff9800
+ #fb8c00
+ #f57c00
+ #ef6c00
+ #e65100
+ #ffd180
+ #ffab40
+ #ff9100
+ #ff6d00
+
+
+ #fbe9e7
+ #ffccbc
+ #ffab91
+ #ff8a65
+ #ff7043
+ #ff5722
+ #f4511e
+ #e64a19
+ #d84315
+ #bf360c
+ #ff9e80
+ #ff6e40
+ #ff3d00
+ #dd2c00
+
+
+ #efebe9
+ #d7ccc8
+ #bcaaa4
+ #a1887f
+ #8d6e63
+ #795548
+ #6d4c41
+ #5d4037
+ #4e342e
+ #3e2723
+
+
+ #fafafa
+ #f5f5f5
+ #eeeeee
+ #e0e0e0
+ #bdbdbd
+ #9e9e9e
+ #757575
+ #616161
+ #424242
+ #212121
+ #000000
+ #ffffff
+
+
+ #eceff1
+ #cfd8dc
+ #b0bec5
+ #90a4ae
+ #78909c
+ #607d8b
+ #546e7a
+ #455a64
+ #37474f
+ #263238
\ No newline at end of file
diff --git a/KUASWifiAutoLogin/app/src/main/res/values/strings.xml b/KUASWifiAutoLogin/app/src/main/res/values/strings.xml
index 7efbbbe..2257814 100644
--- a/KUASWifiAutoLogin/app/src/main/res/values/strings.xml
+++ b/KUASWifiAutoLogin/app/src/main/res/values/strings.xml
@@ -9,10 +9,12 @@
Logout
KUAS Wi-Fi Login
Login successful.
- Wi-Fi login successful, Welcome to KUAS!
- Guest login successful, Welcome to KUAS!
- Cyber login successful, Welcome to KUAS!
- Dorm login successful, Welcome back to Dorm!
+ JianGong
+ YanChao
+ Wi-Fi login successful, Welcome to KUAS %s!
+ Guest login successful, Welcome to KUAS %s!
+ Cyber login successful, Welcome to KUAS %s!
+ Dorm login successful, Welcome back to KUAS %s Dorm!
Already logged in.
Logout successful.
Connected to %s.
@@ -20,6 +22,7 @@
Login to %s….
Already logged in.
Failed to login.
+ Connection Timeout.
Already logged out.
Failed to logout.
About
diff --git a/KUASWifiAutoLogin/app/src/main/res/values/styles.xml b/KUASWifiAutoLogin/app/src/main/res/values/styles.xml
index b42bdf6..365364a 100644
--- a/KUASWifiAutoLogin/app/src/main/res/values/styles.xml
+++ b/KUASWifiAutoLogin/app/src/main/res/values/styles.xml
@@ -9,4 +9,17 @@
- @color/accent
+
+
+
+
+
\ No newline at end of file