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 @@ @@ -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"> + + -