Skip to content

Commit

Permalink
修正燕巢校區無法登入問題 (Jsoup), 優化使用者提示, 增加按鍵觸碰感
Browse files Browse the repository at this point in the history
  • Loading branch information
hearsilent committed Jun 12, 2015
1 parent a841749 commit 4bcb122
Show file tree
Hide file tree
Showing 21 changed files with 865 additions and 484 deletions.
488 changes: 249 additions & 239 deletions KUASWifiAutoLogin/.idea/workspace.xml

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions KUASWifiAutoLogin/app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/cardview-v7/21.0.2/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/22.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.daimajia.easing/library/1.0.2/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.github.rey5137/material/1.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-analytics/7.5.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-base/7.5.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
Expand All @@ -93,14 +95,17 @@
</content>
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="jsoup-1.8.2" level="project" />
<orderEntry type="library" exported="" name="library-2.4.0" level="project" />
<orderEntry type="library" exported="" name="butterknife-6.1.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.2.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-22.2.0" level="project" />
<orderEntry type="library" exported="" name="library-1.0.2" level="project" />
<orderEntry type="library" exported="" name="play-services-base-7.5.0" level="project" />
<orderEntry type="library" exported="" name="material-1.1.1" level="project" />
<orderEntry type="library" exported="" name="play-services-analytics-7.5.0" level="project" />
<orderEntry type="library" exported="" name="android-async-http-1.4.7" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-22.2.0" level="project" />
<orderEntry type="library" exported="" name="cardview-v7-21.0.2" level="project" />
</component>
</module>
6 changes: 4 additions & 2 deletions KUASWifiAutoLogin/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
19 changes: 18 additions & 1 deletion KUASWifiAutoLogin/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.VIBRATE"/>

<application
android:allowBackup="true"
Expand Down Expand Up @@ -41,6 +40,24 @@
</intent-filter>
</receiver>

<receiver android:name="com.google.android.gms.analytics.AnalyticsReceiver"
android:enabled="true">
<intent-filter>
<action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH" />
</intent-filter>
</receiver>
<service android:name="com.google.android.gms.analytics.AnalyticsService"
android:enabled="true"
android:exported="false"/>

<receiver android:name="com.google.android.gms.analytics.CampaignTrackingReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
<service android:name="com.google.android.gms.analytics.CampaignTrackingService" />

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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;

Expand All @@ -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);
Expand All @@ -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());
Expand All @@ -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) {
Expand Down Expand Up @@ -190,11 +178,13 @@ 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")
.setAction("showMessage")
.setLabel(message.toString())
.build());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

}
Loading

0 comments on commit 4bcb122

Please sign in to comment.