├── .gitignore ├── BUILDING.md ├── README.md ├── UPDATE.md ├── app ├── .gitignore ├── app-release.apk ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── padeoe │ │ └── autoconnect │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── padeoe │ │ ├── bookplus │ │ └── BookPlus.java │ │ ├── icroom │ │ ├── ICRoom.java │ │ ├── ICRoomUser.java │ │ └── util │ │ │ └── NetworkUtils.java │ │ ├── nicservice │ │ └── njuwlan │ │ │ ├── object │ │ │ ├── bras │ │ │ │ ├── Base.java │ │ │ │ ├── BrasIDInfo.java │ │ │ │ ├── BrasIDInfoRow.java │ │ │ │ ├── UserAppend.java │ │ │ │ ├── UserAppendDefine.java │ │ │ │ ├── list │ │ │ │ │ ├── AcctBras.java │ │ │ │ │ ├── AuthLogBras.java │ │ │ │ │ ├── BillsBras.java │ │ │ │ │ ├── OnlineBras.java │ │ │ │ │ └── RechargeBras.java │ │ │ │ └── row │ │ │ │ │ ├── AcctRowBras.java │ │ │ │ │ ├── AuthLogRowBras.java │ │ │ │ │ ├── BillsRowBras.java │ │ │ │ │ ├── OnlineRowBras.java │ │ │ │ │ └── RechargeRowBras.java │ │ │ └── portal │ │ │ │ ├── Base.java │ │ │ │ ├── BasicInfo.java │ │ │ │ ├── ReturnData.java │ │ │ │ ├── UserInfo.java │ │ │ │ ├── list │ │ │ │ ├── Acct.java │ │ │ │ ├── AuthLog.java │ │ │ │ ├── Bills.java │ │ │ │ ├── Online.java │ │ │ │ └── Recharge.java │ │ │ │ └── row │ │ │ │ ├── AcctRow.java │ │ │ │ ├── AuthLogRow.java │ │ │ │ ├── BasicInfoRow.java │ │ │ │ ├── BillsRow.java │ │ │ │ ├── OnlineRow.java │ │ │ │ └── RechargeRow.java │ │ │ ├── service │ │ │ ├── AccountService.java │ │ │ ├── DetailQuery.java │ │ │ ├── LoginService.java │ │ │ ├── OfflineQueryService.java │ │ │ └── OnlineQueryService.java │ │ │ └── utils │ │ │ ├── ConversionUtils.java │ │ │ └── NetworkUtils.java │ │ ├── njunet │ │ ├── App.java │ │ ├── connect │ │ │ ├── MainActivity.java │ │ │ ├── PermissionExplainFragment.java │ │ │ ├── StatusNotificationManager.java │ │ │ ├── controller │ │ │ │ ├── ConnectManager.java │ │ │ │ ├── ConnectService.java │ │ │ │ ├── UpdateInfo.java │ │ │ │ └── WiFiScanner.java │ │ │ ├── monitor │ │ │ │ ├── BootReceiver.java │ │ │ │ ├── NetworkConnectChangedReceiver.java │ │ │ │ ├── ScanResultReceiver.java │ │ │ │ └── WifiNetWorkCallBack.java │ │ │ └── uihandler │ │ │ │ ├── AuthFailHandle.java │ │ │ │ ├── BackgrReturnDataHandle.java │ │ │ │ ├── ClientLimitHandle.java │ │ │ │ ├── ConnectFailHandle.java │ │ │ │ ├── ConnectResultHandle.java │ │ │ │ ├── ErrorHandle.java │ │ │ │ ├── GetOnlineTimeFailHandle.java │ │ │ │ ├── NoPasswordHandle.java │ │ │ │ ├── OfflineHandle.java │ │ │ │ ├── OnlineTimeHandle.java │ │ │ │ ├── Reachable.java │ │ │ │ ├── ReturnDataHandle.java │ │ │ │ ├── UnknownErrorHandle.java │ │ │ │ ├── UnknownNetHandle.java │ │ │ │ ├── WifiAvailableHandle.java │ │ │ │ └── WifiLostHandle.java │ │ ├── deploy │ │ │ ├── AccountInputFragment.java │ │ │ ├── AccountTypeFragment.java │ │ │ ├── DeployFragment.java │ │ │ ├── FirstSettingActivity.java │ │ │ └── SettingFinishFragment.java │ │ ├── settings │ │ │ ├── AboutDialogFragment.java │ │ │ ├── AppCompatPreferenceActivity.java │ │ │ └── MySettingsActivity.java │ │ └── util │ │ │ ├── MyAnimation.java │ │ │ ├── MyObservable.java │ │ │ ├── MyObserver.java │ │ │ ├── NetworkTest.java │ │ │ ├── PrefFileManager.java │ │ │ └── ResultUtils.java │ │ ├── oa │ │ └── LoginService.java │ │ ├── service │ │ └── DictService.java │ │ └── utils │ │ ├── ConvertionUtils.java │ │ ├── LoginException.java │ │ ├── MyDate.java │ │ └── network │ │ ├── MyByteArray.java │ │ └── MyHttpRequest.java │ └── res │ ├── anim │ ├── fragment_slide_left_enter.xml │ ├── fragment_slide_left_exit.xml │ ├── fragment_slide_right_enter.xml │ └── fragment_slide_right_exit.xml │ ├── drawable-hdpi │ ├── connect.png │ ├── firstsetting.jpg │ └── open_source_icon.png │ ├── drawable-ldpi │ └── connect.png │ ├── drawable-mdpi │ └── connect.png │ ├── drawable-v21 │ ├── ic_info_black_24dp.xml │ ├── ic_notifications_black_24dp.xml │ └── ic_sync_black_24dp.xml │ ├── drawable-xhdpi │ └── connect.png │ ├── drawable-xxhdpi │ └── connect.png │ ├── drawable │ ├── amount_icon.png │ ├── clock.png │ ├── ic_settings.xml │ ├── ic_wifi_internet.xml │ ├── ic_wifi_off.xml │ ├── icon_wifi_nointernet.xml │ ├── ip.png │ ├── left.xml │ ├── location.png │ ├── noconnect.png │ ├── pc.png │ └── remote.png │ ├── layout-land │ ├── detail_layout.xml │ └── permission_dialog.xml │ ├── layout-large │ └── activity_first_setting.xml │ ├── layout-xlarge │ └── detail_layout.xml │ ├── layout │ ├── activity_first_setting.xml │ ├── activity_main.xml │ ├── content_main.xml │ ├── detail_layout.xml │ ├── dialog_about.xml │ ├── fragment_account_input.xml │ ├── fragment_account_type.xml │ ├── fragment_setting_finish.xml │ ├── permission_dialog.xml │ ├── portal_login_dialog.xml │ └── update_dialog.xml │ ├── menu │ └── menu_main.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ ├── values-large │ ├── dimens.xml │ └── textSize.xml │ ├── values-v21 │ └── styles.xml │ ├── values-w820dp │ └── dimens.xml │ ├── values-xlarge │ └── dimens.xml │ ├── values-zh │ ├── strings.xml │ ├── strings_account.xml │ ├── strings_connect.xml │ ├── strings_pref.xml │ └── strings_tip.xml │ ├── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ ├── strings_account.xml │ ├── strings_connect.xml │ ├── strings_pref.xml │ ├── strings_tip.xml │ ├── styles.xml │ └── textSize.xml │ └── xml │ └── pref_network.xml ├── build.gradle ├── screenshot1.png ├── screenshot2.png ├── screenshot3.png ├── screenshot4.png └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea/workspace.xml 4 | /.idea/libraries 5 | .DS_Store 6 | /build 7 | -------------------------------------------------------------------------------- /BUILDING.md: -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | NJUNet Android App 2 | ====================== 3 | NJUNet是一个用于安卓手机连接到南大校园网(包括宿舍WiFi)后自动登陆p.nju.edu.cn的Android程序,代替手动打开浏览器登陆的繁琐操作,做到有NJU-WLAN的地方总是保持网络连接。 4 | 5 |

适用平台

6 | Android 4.0+ 7 | 8 | ## See Also 9 | 10 | + [Windows](https://github.com/miaoxw/Auto-p.nju) 11 | + [Mac](https://github.com/Cee/PNJU-TodayWidget) 12 | + [iOS &  Watch](https://github.com/Cee/PNJU-Watch) 13 | + [Alfred Workflow](https://github.com/Cee/PNJU-Workflow) 14 | 15 | ## 截图 16 | 17 | 18 | 19 | 20 |

功能说明

21 | - 可手动进行登陆,下线,查看登陆数据(时长,余额等) 22 | - 默认开启后台服务,将在连接上南大校园网WLAN(包括宿舍路由器无线网)时自动登陆 23 | - 可以使用状态栏通知快捷登陆 24 | 25 |

下载

26 | 27 | [Get it on Google Play](https://play.google.com/store/apps/details?id=com.padeoe.njunet) 28 | 29 | 或 30 | 31 | [apk-v2.5.4](https://raw.githubusercontent.com/padeoe/AutoConnect/newUI/app/app-release.apk) 32 | 33 |

更新日志

34 | 35 | - [查看更新日志](https://github.com/padeoe/AutoConnect/blob/newUI/UPDATE.md) 36 | 37 |

如何使用源代码构建并运行

38 | 39 | - [查看build instruction](https://github.com/padeoe/AutoConnect/blob/newUI/BUILDING.md) 40 | 41 |

特别感谢

42 | 43 | - 技术顾问[@Nifury](https://github.com/Nifury) 44 | 45 | -------------------------------------------------------------------------------- /UPDATE.md: -------------------------------------------------------------------------------- 1 | 更新日志 2 | ==== 3 |

v2.5.4(2017年3月26日)

4 | 5 | - 修复了是否在线检测错误的bug,由 [KingGoldXu](https://github.com/KingGoldXu)修复的该bug,感谢! 6 | 7 |

v2.5.3(2017年3月26日)

8 | 9 | - 更新登录接口 10 | 11 |

v2.5.2(2016年6月6日)

12 | 13 | - 登陆前检查在线设备 14 | 15 |

v2.5.1(2016年6月4日)

16 | 修复了一些小问题 17 | 18 | - 修改账号信息后数据不能立即被更新 19 | - 退出程序时可能会产生一次后台登陆 20 | - 在主界面显示用户信息 21 | 22 |

v2.5(2016年6月1日)

23 | 24 | - 更新了所有界面及风格 25 | - 可以显示详单 26 | - 可以显示状态栏通知,快捷登陆,刷新,打开wifi等 27 | - 允许详细自定义设置,包括是否允许开机自启,是否开启后台服务,自定义网络参数等 28 | 29 |

v2.4.1(2015年11月21日)

30 | 31 | - 性能优化 32 | 33 |

v2.4(2015年10月28日)

34 | 35 | - 加密传输密码 36 | - DNS缓存 37 | - 全新的登陆,查询接口(但是目前没有界面显示),代码重构 38 | 39 |

v2.3(2015年9月21日)

40 | 41 | - 支持android 6.0 42 | - 新增检查更新 43 | - 代码重构 44 | 45 |

v2.2.1(2015年9月4日)

46 | 47 | - 修复安卓4.2之前版本三星等机型上识别SSID有误 48 | - 统一了不同尺寸设备上的背景南大logo大小 49 | - 删减冗余代码 50 | 51 |

v2.2.0(2015年6月26日)

52 | 53 | - 更改了界面主题颜色为南大紫,增加了南大logo 54 | - 删除了更换主题的功能 55 | 56 |

v2.1.9(2015年6月12日)

57 | 58 | - 更改了标题栏操作按钮的位置 59 | - 修复部分bug 60 | - 新增主题选择功能 61 | 62 |

v2.1.8(2015年6月6日)

63 | 64 | - 跟进p.nju.edu.cn网站改版,更新了登陆的POST请求,旧版本不再可用 65 | - 新增支持语言:英语 66 | 67 |

v2.1.7(2015年5月10日)

68 | 69 | - 新增浏览器打开p.nju.edu.cn功能 70 | - 新增用户数据统计(用户可关闭) 71 | - 新增立即下线功能 72 | 73 |

v2.1.6(2015年5月7日)

74 | 75 | - 修复了无网络连接时立即登陆导致崩溃 76 | 77 |

v2.1.5(2015年5月2日)

78 | 79 | - 初始版本,具有立即登陆与后台登陆功能 -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/app-release.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LilyStudio/AutoConnect-Android/f715462ffdfd0bc10e88c418889ce006b172b480/app/app-release.apk -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | buildToolsVersion "28.0.3" 6 | 7 | defaultConfig { 8 | applicationId "com.padeoe.njunet" 9 | minSdkVersion 14 10 | targetSdkVersion 26 11 | versionCode 1405 12 | versionName "2.5.4" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:26.1.0' 26 | compile 'com.android.support:design:26.1.0' 27 | compile 'com.alibaba:fastjson:1.2.9' 28 | compile 'com.android.support:cardview-v7:26.1.0' 29 | } 30 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LilyStudio/AutoConnect-Android/f715462ffdfd0bc10e88c418889ce006b172b480/app/proguard-rules.pro -------------------------------------------------------------------------------- /app/src/androidTest/java/com/padeoe/autoconnect/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.autoconnect; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 31 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/bookplus/BookPlus.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.bookplus; 2 | 3 | import com.padeoe.icroom.util.NetworkUtils; 4 | import com.padeoe.utils.LoginException; 5 | 6 | import java.io.IOException; 7 | import java.util.HashMap; 8 | 9 | /** 10 | * 该类用于实现南京大学图书馆Book+的接口 11 | * 12 | * @author padeoe 13 | * Date: 2016/3/10. 14 | */ 15 | public class BookPlus { 16 | private String cookie = null; 17 | 18 | /** 19 | * 使用用户名密码构造 20 | * 21 | * @param username 用户名:学号/工号 22 | * @param password 南京大学图书馆Book+的密码:初始密码是用户名 23 | * @throws LoginException 登陆失败 24 | */ 25 | public BookPlus(String username, String password) throws LoginException, IOException { 26 | String[] returnInfo = login(username, password); 27 | cookie = returnInfo[1]; 28 | } 29 | 30 | /** 31 | * 使用已有的cookie进行构造 32 | * 33 | * @param cookie cookie 34 | */ 35 | public BookPlus(String cookie) { 36 | this.cookie = cookie; 37 | } 38 | 39 | /** 40 | * 用于登陆南京大学图书馆Book+ 41 | * 42 | * @param username 用户名:学号/工号 43 | * @param password 南京大学图书馆Book+的密码:初始密码是用户名 44 | * @return 一个长度为2的字符数组,第一个元素是服务器返回的数据,第二个是获取的cookie 45 | * @throws LoginException 登陆失败 46 | */ 47 | public static String[] login(String username, String password) throws LoginException, IOException { 48 | double random = Math.random(); 49 | String url = "http://book.njulib.cn/smarty_lib/control/controller.php?control=control_log&action=user_login&user_id=" + username + "&user_pwd=" + password + "&rand=" + random; 50 | String returnInfo[] = NetworkUtils.myPostAndGetCookie("control=control_log&action=user_login&user_id=" + username + "&user_pwd=" + password + "&rand=" + random, url, 2000); 51 | if (returnInfo == null || returnInfo[0] == null || !returnInfo[0].equals("ok!")) { 52 | if (returnInfo != null && returnInfo[0] != null) 53 | throw new LoginException(returnInfo[0]); 54 | else 55 | throw new LoginException(); 56 | } else 57 | return returnInfo; 58 | } 59 | 60 | /** 61 | * 显示用户信息,包括姓名和性别的html文本 62 | * 63 | * @return 服务器返回的包括姓名和性别的html文本 64 | */ 65 | public String showReaderInfo() throws IOException { 66 | HashMap attr = new HashMap<>(); 67 | attr.put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"); 68 | attr.put("Accept-Encoding", "gzip, deflate, sdch"); 69 | attr.put("Referer", "http://book.njulib.cn/book_lst.php"); 70 | attr.put("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36"); 71 | attr.put("Upgrade-Insecure-Requests", "1"); 72 | attr.put("Accept-Language", "zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4,zh-TW;q=0.2"); 73 | return NetworkUtils.mygetWithCookie(null, "http://book.njulib.cn/reder_infor.php", cookie, 5000); 74 | } 75 | 76 | /** 77 | * 显示用户的性别,来源于{@linkplain #showReaderInfo()}中的信息提取 78 | * 79 | * @return 用户的性别,“男”或“女” 80 | */ 81 | public String showGender() { 82 | String returnData = null; 83 | try { 84 | returnData = showReaderInfo(); 85 | return getGender(returnData); 86 | } catch (IOException e) { 87 | e.printStackTrace(); 88 | return ""; 89 | } 90 | } 91 | 92 | /** 93 | * 从{@link #showReaderInfo()}中提取性别 94 | * 95 | * @param returnData{@link #showReaderInfo()}的返回值 96 | * @return 用户性别,"男"或"女" 97 | */ 98 | public static String getGender(String returnData) { 99 | if (returnData.contains("女")) 100 | return "女"; 101 | if (returnData.contains("男")) 102 | return "男"; 103 | return ""; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/icroom/ICRoom.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.icroom; 2 | 3 | import com.padeoe.icroom.util.NetworkUtils; 4 | import com.padeoe.utils.LoginException; 5 | 6 | import java.io.IOException; 7 | 8 | /** 9 | * 该类用于实现 南京大学IC空间管理系统 的接口 10 | * @author padeoe 11 | * Date: 2016/03/09 12 | */ 13 | 14 | public class ICRoom { 15 | private String cookie = null; 16 | 17 | /** 18 | * 通过用户名,密码构造,将会登陆后获取登录cookie 19 | * 20 | * @param username 用户名:学号/工号 21 | * @param password 南京大学IC空间管理系统的密码:初始值是用户名 22 | */ 23 | public ICRoom(String username, String password) throws LoginException, IOException { 24 | String[] returnData = login(username, password); 25 | cookie = returnData[1]; 26 | } 27 | 28 | /** 29 | * 直接通过已有cookie进行构造 30 | * 31 | * @param cookie 已获得的cookie 32 | */ 33 | public ICRoom(String cookie) { 34 | if (cookie != null) { 35 | this.cookie = cookie; 36 | } 37 | 38 | } 39 | 40 | /** 41 | * 用于登陆 42 | * 43 | * @param username 用户名:学号/工号 44 | * @param password 南京大学IC空间管理系统的密码:初始值是用户名 45 | * @return 数组长度为2,第一个元素是服务器返回的原始数据,第二个元素是cookie 46 | * @throws LoginException 登陆失败 47 | */ 48 | public static String[] login(String username, String password) throws LoginException, IOException { 49 | String returnInfo[] = NetworkUtils.myPostAndGetCookie("id=" + username + "&pwd=" + password + "&act=login", "http://114.212.7.24/ClientWeb/pro/ajax/login.aspx", 10000); 50 | if (returnInfo == null || returnInfo[0] == null || returnInfo[0].startsWith("{\"ret\":0")) { 51 | if (returnInfo != null &&returnInfo[0] != null) 52 | throw new LoginException(returnInfo[0]); 53 | else 54 | throw new LoginException(); 55 | } else 56 | return returnInfo; 57 | } 58 | 59 | /** 60 | * 预约研讨间页面具有的查找用户信息的功能,包括学生的姓名,院系,手机号(因为具有隐私泄露风险已向网站建设方报告并删除了手机号显示) 61 | * 62 | * @param ID 用户名:学号/工号 63 | * @return 服务器返回的用户信息字符串,非json格式,需要调用 {@link #parse(String)}方法处理成json格式 64 | */ 65 | public String queryStudentInfo(String ID) throws IOException { 66 | String time = String.valueOf(System.currentTimeMillis()); 67 | return NetworkUtils.mygetWithCookie("type=&&term=" + ID + "&_=" + time, "http://114.212.7.24/ClientWeb/pro/ajax/data/searchAccount.aspx?type=&&term=" + ID + "&_=" + time, 68 | cookie, 20000); 69 | } 70 | 71 | /** 72 | * 对服务器返回的数据进行处理,处理成json格式,并排除空数据,脏数据 73 | * @param result {@link #queryStudentInfo(String)}获得的数据,非json格式,且含有脏数据 74 | * @return 处理后的数据,是json格式,可以继续调用 {@link ICRoomUser#getFromJson(String)}对返回值进行处理获得对象 75 | */ 76 | public static String parse(String result){ 77 | int length=result.length(); 78 | if(length<4){ 79 | return null; 80 | } 81 | result=result.substring(1,length-1); 82 | if(result.equals("")){ 83 | return null; 84 | } 85 | if(result.indexOf("}")!=length-3){ 86 | return result.substring(0,result.indexOf("}")+1); 87 | } 88 | //排除脏数据 89 | /* if(result.indexOf("SKL3344")!=-1||result.indexOf("赵文胜")!=-1){ 90 | return null; 91 | }*/ 92 | return result; 93 | } 94 | 95 | /** 96 | * 预约研讨间页面具有的查找用户信息的功能,包括学生的姓名,院系,手机号(因为具有隐私泄露风险已向网站建设方报告并删除了手机号显示),该方法会对特定ID查询其信息 97 | * @param ID 用户名:学号/工号 98 | * @return 用户信息的对象格式 {@link ICRoomUser} 99 | */ 100 | public ICRoomUser queryStudentInfo_Object(String ID) throws IOException { 101 | String result = queryStudentInfo(ID); 102 | String newResult=parse(result); 103 | return ICRoomUser.getFromJson(newResult); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/icroom/ICRoomUser.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.icroom; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.alibaba.fastjson.annotation.JSONField; 5 | 6 | /** 7 | * 表示ICRoom系统{@link ICRoom}的用户,包含用户名,院系,邮箱等信息 8 | * Date: 2016/3/7. 9 | */ 10 | public class ICRoomUser { 11 | @JSONField(name = "id") 12 | private String id; 13 | @JSONField(name = "name") 14 | private String name; 15 | @JSONField(name = "label") 16 | private String label_major; 17 | @JSONField(name = "szLogonName") 18 | private String student_id; 19 | @JSONField(name = "szHandPhone") 20 | private String phone; 21 | @JSONField(name = "szTel") 22 | private String tel; 23 | @JSONField(name = "szEmail") 24 | private String email; 25 | 26 | /** 27 | * 默认构造函数,因为fastjson解析对象的需要,不可删除 28 | */ 29 | public ICRoomUser(){} 30 | 31 | public ICRoomUser(String id, String name, String label_major, String student_id, String phone, String tel, String email) { 32 | this.id = id; 33 | this.name = name; 34 | this.label_major = label_major; 35 | this.student_id = student_id; 36 | this.phone = phone; 37 | this.tel = tel; 38 | this.email = email; 39 | } 40 | 41 | public static ICRoomUser getFromJson(String json){ 42 | try { 43 | return JSON.parseObject(json, ICRoomUser.class); 44 | } catch (Exception e) { 45 | System.out.println(e.toString()); 46 | return null; 47 | } 48 | } 49 | 50 | public String getId() { 51 | return id; 52 | } 53 | 54 | public void setId(String id) { 55 | this.id = id; 56 | } 57 | 58 | public String getName() { 59 | return name; 60 | } 61 | 62 | public void setName(String name) { 63 | this.name = name; 64 | } 65 | 66 | public String getLabel_major() { 67 | return label_major; 68 | } 69 | 70 | public void setLabel_major(String label_major) { 71 | this.label_major = label_major; 72 | } 73 | 74 | public String getStudent_id() { 75 | return student_id; 76 | } 77 | 78 | public void setStudent_id(String student_id) { 79 | this.student_id = student_id; 80 | } 81 | 82 | public String getPhone() { 83 | return phone; 84 | } 85 | 86 | public void setPhone(String phone) { 87 | this.phone = phone; 88 | } 89 | 90 | public String getTel() { 91 | return tel; 92 | } 93 | 94 | public void setTel(String tel) { 95 | this.tel = tel; 96 | } 97 | 98 | public String getEmail() { 99 | return email; 100 | } 101 | 102 | public void setEmail(String email) { 103 | this.email = email; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/icroom/util/NetworkUtils.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.icroom.util; 2 | 3 | import com.padeoe.utils.network.MyHttpRequest; 4 | 5 | import java.io.IOException; 6 | import java.util.HashMap; 7 | 8 | /** 9 | * 该类用于负责{@link com.padeoe.icroom}内的网络通信,重新封装了{@link MyHttpRequest}内的方法,指定了特定http header 10 | * @author padeoe 11 | * Date: 2016/3/7 12 | */ 13 | public class NetworkUtils { 14 | public static String mygetWithCookie(String data,String URL,String cookie,int timeout) throws IOException { 15 | HashMap attr=new HashMap<>(); 16 | attr.put("Accept","application/json, text/javascript, */*; q=0.01"); 17 | attr.put("Referer", "http://114.212.7.24/ClientWeb/xcus/IC2/Default.aspx"); 18 | attr.put("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36"); 19 | attr.put("X-Requested-With", "XMLHttpRequest"); 20 | return MyHttpRequest.getWithCookie(data,URL,attr,cookie,"UTF-8", "UTF-8",timeout); 21 | } 22 | public static String[] myPostAndGetCookie(String data,String URL,int timeout) throws IOException { 23 | HashMap attr=new HashMap<>(); 24 | attr.put("Accept","application/json, text/javascript, */*; q=0.01"); 25 | attr.put("Referer", "http://114.212.7.24/ClientWeb/xcus/IC2/Default.aspx"); 26 | attr.put("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36"); 27 | attr.put("X-Requested-With", "XMLHttpRequest"); 28 | return MyHttpRequest.postAndGetCookie(data,URL,attr,"UTF-8", "UTF-8",timeout); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/nicservice/njuwlan/object/bras/Base.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.nicservice.njuwlan.object.bras; 2 | 3 | /** 4 | * Created by padeoe on 2015/9/23. 5 | */ 6 | 7 | /** 8 | * 基类 9 | */ 10 | public class Base { 11 | /** 12 | * 列表总行数 13 | */ 14 | protected String total; 15 | /** 16 | * (无用信息)查询时间,即当前时间 17 | */ 18 | protected String request_time; 19 | /** 20 | * 服务器返回信息,显示了查询是否成功 21 | */ 22 | protected String reply_msg; 23 | /** 24 | * 列表最大页数 25 | */ 26 | protected String max_page; 27 | /** 28 | * (无用信息)请求url 29 | */ 30 | protected String request_url; 31 | /** 32 | * 返回码,显示了查询是否成功 33 | */ 34 | protected String reply_code; 35 | 36 | public String getTotal() { 37 | return total; 38 | } 39 | 40 | public void setTotal(String total) { 41 | this.total = total; 42 | } 43 | 44 | public String getMax_page() { 45 | return max_page; 46 | } 47 | 48 | public void setMax_page(String max_page) { 49 | this.max_page = max_page; 50 | } 51 | 52 | 53 | public String getRequest_time() { 54 | return request_time; 55 | } 56 | 57 | public void setRequest_time(String request_time) { 58 | this.request_time = request_time; 59 | } 60 | 61 | public String getRequest_url() { 62 | return request_url; 63 | } 64 | 65 | public void setRequest_url(String request_url) { 66 | this.request_url = request_url; 67 | } 68 | 69 | public String getReply_code() { 70 | return reply_code; 71 | } 72 | 73 | public void setReply_code(String reply_code) { 74 | this.reply_code = reply_code; 75 | } 76 | 77 | public String getReply_msg() { 78 | return reply_msg; 79 | } 80 | 81 | public void setReply_msg(String reply_msg) { 82 | this.reply_msg = reply_msg; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/nicservice/njuwlan/object/bras/BrasIDInfo.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.nicservice.njuwlan.object.bras; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | 5 | /** 6 | * 该类表示南京大学网络认证计费系统自助平台中查询用户信息获得的用户信息列表,该列表包含了用户id,用户网络使用总时长,网费余额等信息 7 | * 具体包括一个包含用户信息列表的数组以及响应值,相应信息等信息 8 | * @author padeoe 9 | * Date: 2016/3/12 10 | */ 11 | public class BrasIDInfo 12 | { 13 | private BrasIDInfoRow[] results; 14 | 15 | private String reply_code; 16 | 17 | private String request_uri; 18 | 19 | private String request_time; 20 | 21 | private String reply_msg; 22 | 23 | 24 | public static BrasIDInfo getFromJson(String jsonobject){ 25 | try { 26 | return JSON.parseObject(jsonobject, BrasIDInfo.class); 27 | } catch (Exception e) { 28 | return null; 29 | } 30 | } 31 | 32 | public BrasIDInfoRow[] getResults () 33 | { 34 | return results; 35 | } 36 | 37 | public void setResults (BrasIDInfoRow[] results) 38 | { 39 | this.results = results; 40 | } 41 | 42 | public String getReply_code () 43 | { 44 | return reply_code; 45 | } 46 | 47 | public void setReply_code (String reply_code) 48 | { 49 | this.reply_code = reply_code; 50 | } 51 | 52 | public String getRequest_uri () 53 | { 54 | return request_uri; 55 | } 56 | 57 | public void setRequest_uri (String request_uri) 58 | { 59 | this.request_uri = request_uri; 60 | } 61 | 62 | public String getRequest_time () 63 | { 64 | return request_time; 65 | } 66 | 67 | public void setRequest_time (String request_time) 68 | { 69 | this.request_time = request_time; 70 | } 71 | 72 | public String getReply_msg () 73 | { 74 | return reply_msg; 75 | } 76 | 77 | public void setReply_msg (String reply_msg) 78 | { 79 | this.reply_msg = reply_msg; 80 | } 81 | 82 | @Override 83 | public String toString() 84 | { 85 | return "ClassPojo [results = "+results[0].toString()+", reply_code = "+reply_code+", request_uri = "+request_uri+", request_time = "+request_time+", reply_msg = "+reply_msg+"]"; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/nicservice/njuwlan/object/bras/UserAppend.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.nicservice.njuwlan.object.bras; 2 | 3 | /** 4 | * 该类表示的信息是用户在南京大学网络认证计费系统自助平台中查询当前用户信息获得的信息{@link BrasIDInfo}中的一部分 5 | * @author padeoe 6 | * Date: 2016/3/12 7 | */ 8 | public class UserAppend 9 | { 10 | private String userColName; 11 | 12 | private String userColValue; 13 | 14 | public String getUserColName () 15 | { 16 | return userColName; 17 | } 18 | 19 | public void setUserColName (String userColName) 20 | { 21 | this.userColName = userColName; 22 | } 23 | 24 | public String getUserColValue () 25 | { 26 | return userColValue; 27 | } 28 | 29 | public void setUserColValue (String userColValue) 30 | { 31 | this.userColValue = userColValue; 32 | } 33 | 34 | @Override 35 | public String toString() 36 | { 37 | return "ClassPojo [userColName = "+userColName+", userColValue = "+userColValue+"]"; 38 | } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/nicservice/njuwlan/object/bras/UserAppendDefine.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.nicservice.njuwlan.object.bras; 2 | 3 | /** 4 | * 该类表示的信息是用户在南京大学网络认证计费系统自助平台中查询当前用户信息获得的信息{@link BrasIDInfo}中的一部分 5 | * Created by padeoe on 2016/3/12. 6 | */ 7 | public class UserAppendDefine 8 | { 9 | private String colName; 10 | 11 | private String colValue; 12 | 13 | public String getColName () 14 | { 15 | return colName; 16 | } 17 | 18 | public void setColName (String colName) 19 | { 20 | this.colName = colName; 21 | } 22 | 23 | public String getColValue () 24 | { 25 | return colValue; 26 | } 27 | 28 | public void setColValue (String colValue) 29 | { 30 | this.colValue = colValue; 31 | } 32 | 33 | @Override 34 | public String toString() 35 | { 36 | return "ClassPojo [colName = "+colName+", colValue = "+colValue+"]"; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/nicservice/njuwlan/object/bras/list/AcctBras.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.nicservice.njuwlan.object.bras.list; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.alibaba.fastjson.annotation.JSONField; 5 | import com.padeoe.nicservice.njuwlan.object.bras.Base; 6 | import com.padeoe.nicservice.njuwlan.object.bras.row.AcctRowBras; 7 | 8 | /** 9 | * 10 | * 该类表示南京大学网络认证计费系统自助平台中查询详单信息获得的列表列表,该列表显示了每一次登陆至下线的详细信息, 11 | * 具体包含一个包含{@link AcctRowBras}对象的数组以及详单列表的总页数 12 | * @author padeoe 13 | * Date: 2015/9/23 14 | */ 15 | public class AcctBras extends Base { 16 | /** 17 | * 详单信息的列表,数组每一个元素包含了一个{@link AcctRowBras},记录了具体的单个详细信息 18 | */ 19 | @JSONField(name = "rows") 20 | private AcctRowBras[] acctRowBrases; 21 | /** 22 | * 详单信息列表的页号 23 | */ 24 | protected String pageNum; 25 | public AcctBras() { 26 | } 27 | 28 | /** 29 | * 30 | * @param jsonobject json格式的字符串 31 | * @return {@link AcctBras}对象 32 | */ 33 | public static AcctBras getFromJson(String jsonobject) { 34 | try { 35 | return JSON.parseObject(jsonobject, AcctBras.class); 36 | } catch (Exception e) { 37 | return null; 38 | } 39 | } 40 | 41 | public String getPageNum() { 42 | return pageNum; 43 | } 44 | 45 | public void setPageNum(String pageNum) { 46 | this.pageNum = pageNum; 47 | } 48 | 49 | public AcctRowBras[] getAcctRowBrases() { 50 | return acctRowBrases; 51 | } 52 | 53 | public void setAcctRowBrases(AcctRowBras[] acctRowBrases) { 54 | this.acctRowBrases = acctRowBrases; 55 | } 56 | 57 | @Override 58 | public String toString() 59 | { 60 | return "AcctBras:[\n" + 61 | "max_page = "+max_page+",\n" + 62 | "reply_code = "+reply_code+",\n" + 63 | "reply_msg = "+reply_msg+",\n"+ 64 | "pageNum = "+pageNum+",\n"+ 65 | "request_time = "+request_time+",\n"+ 66 | "request_url = "+request_url+",\n"+ 67 | acctRowBrases.toString()+",\n]\n"; 68 | } 69 | } 70 | 71 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/nicservice/njuwlan/object/bras/list/AuthLogBras.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.nicservice.njuwlan.object.bras.list; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.alibaba.fastjson.annotation.JSONField; 5 | import com.padeoe.nicservice.njuwlan.object.bras.Base; 6 | import com.padeoe.nicservice.njuwlan.object.bras.row.AuthLogRowBras; 7 | 8 | /** 9 | * 该类表示南京大学网络认证计费系统自助平台中查询认证信息获得的列表,该列表包含认证的每一次记录 10 | * 具体包含一个包含{@link AuthLogRowBras}对象的数组以及认证列表的总页数 11 | * @author padeoe 12 | * Date: 2015/9/24 13 | */ 14 | public class AuthLogBras extends Base { 15 | @JSONField(name = "rows") 16 | private AuthLogRowBras[] authLogRowBrases; 17 | @JSONField(name = "page") 18 | protected String pageNum; 19 | 20 | public AuthLogBras() { 21 | } 22 | 23 | public static AuthLogBras getFromJson(String jsonobject) { 24 | try { 25 | return JSON.parseObject(jsonobject, AuthLogBras.class); 26 | } catch (Exception e) { 27 | return null; 28 | } 29 | } 30 | 31 | public String getPageNum() { 32 | return pageNum; 33 | } 34 | 35 | public void setPageNum(String pageNum) { 36 | this.pageNum = pageNum; 37 | } 38 | public AuthLogRowBras[] getAuthLogRowBrases() { 39 | return authLogRowBrases; 40 | } 41 | 42 | public void setAuthLogRowBrases(AuthLogRowBras[] authLogRowBrases) { 43 | this.authLogRowBrases = authLogRowBrases; 44 | } 45 | 46 | @Override 47 | public String toString() 48 | { 49 | return "AuthLogBras:[\n" + 50 | "max_page = "+max_page+",\n" + 51 | "reply_code = "+reply_code+",\n" + 52 | "reply_msg = "+reply_msg+",\n"+ 53 | "pageNum = "+pageNum+",\n"+ 54 | "request_time = "+request_time+",\n"+ 55 | "request_url = "+request_url+",\n"+ 56 | authLogRowBrases.toString()+",\n]\n"; 57 | } 58 | } 59 | 60 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/nicservice/njuwlan/object/bras/list/BillsBras.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.nicservice.njuwlan.object.bras.list; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.alibaba.fastjson.annotation.JSONField; 5 | import com.padeoe.nicservice.njuwlan.object.bras.Base; 6 | import com.padeoe.nicservice.njuwlan.object.bras.row.BillsRowBras; 7 | 8 | /** 9 | * 该类表示南京大学网络认证计费系统自助平台中查询账单信息获得的列表 10 | * 具体包含一个包含{@link BillsRowBras}对象的数组以及账单列表的总页数 11 | * @author padeoe 12 | * Date: 2015/9/23 13 | */ 14 | public class BillsBras extends Base { 15 | @JSONField(name = "rows") 16 | private BillsRowBras[] billsRowBrases; 17 | @JSONField(name = "page") 18 | protected String pageNum; 19 | public BillsBras() { 20 | } 21 | 22 | public static BillsBras getFromJson(String jsonobject) { 23 | try { 24 | return JSON.parseObject(jsonobject, BillsBras.class); 25 | } catch (Exception e) { 26 | return null; 27 | } 28 | } 29 | 30 | public String getPageNum() { 31 | return pageNum; 32 | } 33 | 34 | public void setPageNum(String pageNum) { 35 | this.pageNum = pageNum; 36 | } 37 | 38 | public BillsRowBras[] getBillsRowBrases() { 39 | return billsRowBrases; 40 | } 41 | 42 | public void setBillsRowBrases(BillsRowBras[] billsRowBrases) { 43 | this.billsRowBrases = billsRowBrases; 44 | } 45 | 46 | @Override 47 | public String toString() 48 | { 49 | return "BillsBras:[\n" + 50 | "max_page = "+max_page+",\n" + 51 | "reply_code = "+reply_code+",\n" + 52 | "reply_msg = "+reply_msg+",\n"+ 53 | "pageNum = "+pageNum+",\n"+ 54 | "request_time = "+request_time+",\n"+ 55 | "request_url = "+request_url+",\n"+ 56 | billsRowBrases.toString()+",\n]\n"; 57 | } 58 | } 59 | 60 | 61 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/nicservice/njuwlan/object/bras/list/OnlineBras.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.nicservice.njuwlan.object.bras.list; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.alibaba.fastjson.annotation.JSONField; 5 | import com.padeoe.nicservice.njuwlan.object.bras.Base; 6 | import com.padeoe.nicservice.njuwlan.object.bras.row.OnlineRowBras; 7 | 8 | /** 9 | * 该类表示南京大学网络认证计费系统自助平台中查询当前在线设备获得的列表 10 | * 具体包含一个包含{@link OnlineRowBras}对象的数组以及在线设备列表的总页数 11 | * @author padeoe 12 | * Date: 2015/9/24 13 | */ 14 | public class OnlineBras extends Base 15 | { 16 | @JSONField(name = "rows") 17 | private OnlineRowBras[] onlineRowBrases; 18 | 19 | protected String pageNum; 20 | 21 | public OnlineBras(){} 22 | public static OnlineBras getFromJson(String jsonobject){ 23 | try { 24 | return JSON.parseObject(jsonobject, OnlineBras.class); 25 | } catch (Exception e) { 26 | return null; 27 | } 28 | } 29 | public String getPageNum() { 30 | return pageNum; 31 | } 32 | 33 | public void setPageNum(String pageNum) { 34 | this.pageNum = pageNum; 35 | } 36 | 37 | public OnlineRowBras[] getOnlineRowBrases() { 38 | return onlineRowBrases; 39 | } 40 | 41 | public void setOnlineRowBrases(OnlineRowBras[] onlineRowBrases) { 42 | this.onlineRowBrases = onlineRowBrases; 43 | } 44 | 45 | @Override 46 | public String toString() 47 | { 48 | return "OnlineBras:[\n" + 49 | "max_page = "+max_page+",\n" + 50 | "reply_code = "+reply_code+",\n" + 51 | "reply_msg = "+reply_msg+",\n"+ 52 | "pageNum = "+pageNum+",\n"+ 53 | "request_time = "+request_time+",\n"+ 54 | "request_url = "+request_url+",\n"+ 55 | onlineRowBrases.toString()+",\n]\n"; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/nicservice/njuwlan/object/bras/list/RechargeBras.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.nicservice.njuwlan.object.bras.list; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.alibaba.fastjson.annotation.JSONField; 5 | import com.padeoe.nicservice.njuwlan.object.bras.Base; 6 | import com.padeoe.nicservice.njuwlan.object.bras.row.RechargeRowBras; 7 | 8 | /** 9 | * 该类表示南京大学网络认证计费系统自助平台中查询充值信息获得的列表 10 | * 具体包含一个包含{@link RechargeRowBras}对象的数组以及充值列表的总页数 11 | * @author padeoe 12 | * Date: 2015/9/23 13 | */ 14 | public class RechargeBras extends Base { 15 | @JSONField(name = "rows") 16 | private RechargeRowBras[] rechargeRowBrases; 17 | protected String pageNum; 18 | 19 | public String getPageNum() { 20 | return pageNum; 21 | } 22 | 23 | public void setPageNum(String pageNum) { 24 | this.pageNum = pageNum; 25 | } 26 | 27 | public RechargeRowBras[] getRechargeRowBrases() { 28 | return rechargeRowBrases; 29 | } 30 | 31 | public void setRechargeRowBrases(RechargeRowBras[] rechargeRowBrases) { 32 | this.rechargeRowBrases = rechargeRowBrases; 33 | } 34 | 35 | public static RechargeBras getFromJson(String jsonobject){ 36 | try { 37 | RechargeBras rechargeBras = JSON.parseObject(jsonobject, RechargeBras.class); 38 | return rechargeBras; 39 | } catch (Exception e) { 40 | return null; 41 | } 42 | } 43 | 44 | @Override 45 | public String toString() 46 | { 47 | return "RechargeBras:[\n" + 48 | "max_page = "+max_page+",\n" + 49 | "reply_code = "+reply_code+",\n" + 50 | "reply_msg = "+reply_msg+",\n"+ 51 | "pageNum = "+pageNum+",\n"+ 52 | "request_time = "+request_time+",\n"+ 53 | "request_url = "+request_url+",\n"+ 54 | rechargeRowBrases.toString()+",\n]\n"; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/nicservice/njuwlan/object/bras/row/AuthLogRowBras.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.nicservice.njuwlan.object.bras.row; 2 | 3 | /** 4 | * 该类表示南京大学网络认证计费系统自助平台中查询登陆日志详单获得的详单信息列表中具体的一条(行)信息 5 | * 包括登陆区域,mac地址,登陆返回信息,用户名等大量信息 6 | * @author padeoe 7 | * Date: 2015/9/23 8 | */ 9 | public class AuthLogRowBras { 10 | protected String area_id; 11 | protected String subport; 12 | protected String mac; 13 | protected String ap_id; 14 | protected String reply_msg; 15 | protected String area_type; 16 | protected String svlan; 17 | protected String username; 18 | protected String area_name; 19 | protected String src_ip; 20 | protected String nas_ip; 21 | protected String datetime; 22 | 23 | protected AuthLogRowBras() { 24 | } 25 | 26 | 27 | public String getArea_id() { 28 | return area_id; 29 | } 30 | 31 | public void setArea_id(String area_id) { 32 | this.area_id = area_id; 33 | } 34 | 35 | public String getSubport() { 36 | return subport; 37 | } 38 | 39 | public void setSubport(String subport) { 40 | this.subport = subport; 41 | } 42 | 43 | public String getMac() { 44 | return mac; 45 | } 46 | 47 | public void setMac(String mac) { 48 | this.mac = mac; 49 | } 50 | 51 | public String getAp_id() { 52 | return ap_id; 53 | } 54 | 55 | public void setAp_id(String ap_id) { 56 | this.ap_id = ap_id; 57 | } 58 | 59 | public String getReply_msg() { 60 | return reply_msg; 61 | } 62 | 63 | public void setReply_msg(String reply_msg) { 64 | this.reply_msg = reply_msg; 65 | } 66 | 67 | 68 | public String getArea_type() { 69 | return area_type; 70 | } 71 | 72 | public void setArea_type(String area_type) { 73 | this.area_type = area_type; 74 | } 75 | 76 | public String getSvlan() { 77 | return svlan; 78 | } 79 | 80 | public void setSvlan(String svlan) { 81 | this.svlan = svlan; 82 | } 83 | 84 | public String getUsername() { 85 | return username; 86 | } 87 | 88 | public void setUsername(String username) { 89 | this.username = username; 90 | } 91 | 92 | public String getArea_name() { 93 | return area_name; 94 | } 95 | 96 | public void setArea_name(String area_name) { 97 | this.area_name = area_name; 98 | } 99 | 100 | public String getSrc_ip() { 101 | return src_ip; 102 | } 103 | 104 | public void setSrc_ip(String src_ip) { 105 | this.src_ip = src_ip; 106 | } 107 | 108 | public String getNas_ip() { 109 | return nas_ip; 110 | } 111 | 112 | public void setNas_ip(String nas_ip) { 113 | this.nas_ip = nas_ip; 114 | } 115 | 116 | public String getDatetime() { 117 | return datetime; 118 | } 119 | 120 | public void setDatetime(String datetime) { 121 | this.datetime = datetime; 122 | } 123 | 124 | @Override 125 | public String toString() { 126 | return "ClassPojo [area_id = " + area_id + ", subport = " + subport + 127 | ", mac = " + mac + ", ap_id = " + ap_id + ", reply_msg = " + reply_msg + 128 | ", area_type = " + area_type + ", svlan = " + svlan + ", username = " 129 | + username + ", area_name = " + area_name + ", src_ip = " + src_ip + ", nas_ip = " 130 | + nas_ip + ", datetime = " + datetime + "]"; 131 | } 132 | } 133 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/nicservice/njuwlan/object/bras/row/BillsRowBras.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.nicservice.njuwlan.object.bras.row; 2 | 3 | /** 4 | * 该类表示南京大学网络认证计费系统自助平台中查询账单信息获得的详单信息列表中具体的一条(行)信息 5 | * 具体包括起始时间,id,消费金额等信息 6 | * @author padeoe 7 | * Date: 2015/9/23 8 | */ 9 | public class BillsRowBras { 10 | protected String createtime; 11 | 12 | protected String id; 13 | 14 | protected String beginning_balance; 15 | 16 | protected String startdate; 17 | 18 | protected String recharge_amount; 19 | 20 | protected String ending_balance; 21 | 22 | protected String enddate; 23 | 24 | protected String costs_amount; 25 | 26 | protected String account_no; 27 | 28 | public String getCreatetime() { 29 | return createtime; 30 | } 31 | 32 | public void setCreatetime(String createtime) { 33 | this.createtime = createtime; 34 | } 35 | 36 | public String getId() { 37 | return id; 38 | } 39 | 40 | public void setId(String id) { 41 | this.id = id; 42 | } 43 | 44 | public String getBeginning_balance() { 45 | return beginning_balance; 46 | } 47 | 48 | public void setBeginning_balance(String beginning_balance) { 49 | this.beginning_balance = beginning_balance; 50 | } 51 | 52 | public String getStartdate() { 53 | return startdate; 54 | } 55 | 56 | public void setStartdate(String startdate) { 57 | this.startdate = startdate; 58 | } 59 | 60 | public String getRecharge_amount() { 61 | return recharge_amount; 62 | } 63 | 64 | public void setRecharge_amount(String recharge_amount) { 65 | this.recharge_amount = recharge_amount; 66 | } 67 | 68 | public String getEnding_balance() { 69 | return ending_balance; 70 | } 71 | 72 | public void setEnding_balance(String ending_balance) { 73 | this.ending_balance = ending_balance; 74 | } 75 | 76 | public String getEnddate() { 77 | return enddate; 78 | } 79 | 80 | public void setEnddate(String enddate) { 81 | this.enddate = enddate; 82 | } 83 | 84 | public String getCosts_amount() { 85 | return costs_amount; 86 | } 87 | 88 | public void setCosts_amount(String costs_amount) { 89 | this.costs_amount = costs_amount; 90 | } 91 | 92 | public String getAccount_no() { 93 | return account_no; 94 | } 95 | 96 | public void setAccount_no(String account_no) { 97 | this.account_no = account_no; 98 | } 99 | 100 | @Override 101 | public String toString() { 102 | return "ClassPojo [createtime = " + createtime + ", id = " + id + ", beginning_balance = " + beginning_balance + ", startdate = " + startdate + ", recharge_amount = " + recharge_amount + ", ending_balance = " + ending_balance + ", enddate = " + enddate + ", costs_amount = " + costs_amount + ", account_no = " + account_no + "]"; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/nicservice/njuwlan/object/bras/row/RechargeRowBras.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.nicservice.njuwlan.object.bras.row; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | 5 | /** 6 | * 该类表示南京大学网络认证计费系统自助平台中查询充值记录获得的充值记录列表中具体的一条(行)信息 7 | * 具体包括充值金额,充值时间等信息 8 | * @author padeoe 9 | * Date: 2015/9/23 10 | */ 11 | public class RechargeRowBras { 12 | 13 | protected String amount; 14 | 15 | protected String remark; 16 | 17 | protected String oper_time; 18 | 19 | protected String oper_id; 20 | 21 | protected String account_no; 22 | 23 | @JSONField(name = "oper_name") 24 | protected String oper_username; 25 | 26 | public String getAmount() { 27 | return amount; 28 | } 29 | 30 | public void setAmount(String amount) { 31 | this.amount = amount; 32 | } 33 | 34 | public String getRemark() { 35 | return remark; 36 | } 37 | 38 | public void setRemark(String remark) { 39 | this.remark = remark; 40 | } 41 | 42 | public String getOper_time() { 43 | return oper_time; 44 | } 45 | 46 | public void setOper_time(String oper_time) { 47 | this.oper_time = oper_time; 48 | } 49 | 50 | public String getOper_id() { 51 | return oper_id; 52 | } 53 | 54 | public void setOper_id(String oper_id) { 55 | this.oper_id = oper_id; 56 | } 57 | 58 | public String getAccount_no() { 59 | return account_no; 60 | } 61 | 62 | public void setAccount_no(String account_no) { 63 | this.account_no = account_no; 64 | } 65 | 66 | public String getOper_username() { 67 | return oper_username; 68 | } 69 | 70 | public void setOper_username(String oper_username) { 71 | this.oper_username = oper_username; 72 | } 73 | @Override 74 | public String toString() { 75 | return "ClassPojo " + ", amount = " + amount + ", remark = " + remark + ", oper_time = " + oper_time + ", oper_id = " + oper_id + ", account_no = " + account_no + "]"; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/nicservice/njuwlan/object/portal/Base.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.nicservice.njuwlan.object.portal; 2 | 3 | /** 4 | * Created by padeoe on 2015/9/23. 5 | */ 6 | 7 | /** 8 | * 基类 9 | */ 10 | public class Base { 11 | /** 12 | * 列表总行数 13 | */ 14 | protected String total; 15 | /** 16 | * 返回码,显示了查询是否成功 17 | */ 18 | protected String reply_code; 19 | /** 20 | * 返回信息,显示了查询是否成功 21 | */ 22 | protected String reply_msg; 23 | 24 | public String getTotal() { 25 | return total; 26 | } 27 | 28 | public void setTotal(String total) { 29 | this.total = total; 30 | } 31 | 32 | public String getReply_code() { 33 | return reply_code; 34 | } 35 | 36 | public void setReply_code(String reply_code) { 37 | this.reply_code = reply_code; 38 | } 39 | 40 | public String getReply_msg() { 41 | return reply_msg; 42 | } 43 | 44 | public void setReply_msg(String reply_msg) { 45 | this.reply_msg = reply_msg; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/nicservice/njuwlan/object/portal/BasicInfo.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.nicservice.njuwlan.object.portal; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.alibaba.fastjson.annotation.JSONField; 5 | import com.padeoe.nicservice.njuwlan.object.portal.row.BasicInfoRow; 6 | 7 | /** 8 | * 该类表示南京大学网络认证系统中查询当前登陆用户获得的用户信息列表 9 | * @author padeoe 10 | * Date: 2015/9/23 11 | */ 12 | public class BasicInfo extends Base { 13 | @JSONField(name = "rows") 14 | private BasicInfoRow[] basicInfoRows; 15 | 16 | public static BasicInfo getFromJson(String jsonobject) { 17 | try { 18 | return JSON.parseObject(jsonobject, BasicInfo.class); 19 | } catch (Exception e) { 20 | return null; 21 | } 22 | } 23 | 24 | public BasicInfoRow[] getBasicInfoRows() { 25 | return basicInfoRows; 26 | } 27 | 28 | public void setBasicInfoRows(BasicInfoRow[] basicInfoRows) { 29 | this.basicInfoRows = basicInfoRows; 30 | } 31 | 32 | 33 | @Override 34 | public String toString() { 35 | return "ClassPojo [total = " + total + ", reply_code = " + reply_code + ", rows = " + basicInfoRows + ", reply_msg = " + reply_msg + "]"; 36 | } 37 | } -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/nicservice/njuwlan/object/portal/ReturnData.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.nicservice.njuwlan.object.portal; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | import com.alibaba.fastjson.JSON; 7 | import com.alibaba.fastjson.annotation.JSONField; 8 | 9 | /** 10 | * 该类表示用户登陆南京大学网络认证系统时返回的数据, 11 | * 具体包括响应码,响应信息,以及用户信息对象{@link UserInfo} 12 | * @author padeoe 13 | * Date: 2015/4/24 14 | */ 15 | public class ReturnData implements Parcelable{ 16 | @JSONField(name = "reply_code") 17 | private String reply_code; 18 | @JSONField(name = "reply_msg") 19 | private String reply_message; 20 | @JSONField(name = "userinfo") 21 | private UserInfo UserInfo; 22 | 23 | public ReturnData() { 24 | } 25 | 26 | public ReturnData(String reply_code, String reply_message, UserInfo UserInfo) { 27 | this.reply_code = reply_code; 28 | this.reply_message = reply_message; 29 | this.UserInfo = UserInfo; 30 | } 31 | 32 | public static ReturnData getFromJson(String jsonobject) { 33 | try { 34 | return JSON.parseObject(jsonobject, ReturnData.class); 35 | } catch (Exception e) { 36 | System.out.println(e); 37 | return null; 38 | } 39 | } 40 | 41 | public void setReply_code(String reply_code) { 42 | this.reply_code = reply_code; 43 | } 44 | 45 | public String getReply_code() { 46 | return this.reply_code; 47 | } 48 | 49 | public void setReply_message(String reply_message) { 50 | this.reply_message = reply_message; 51 | } 52 | 53 | public String getReply_message() { 54 | return this.reply_message; 55 | } 56 | 57 | public void setUserInfo(UserInfo userInfo) { 58 | this.UserInfo = userInfo; 59 | } 60 | 61 | public UserInfo getUserInfo() { 62 | return this.UserInfo; 63 | } 64 | 65 | @Override 66 | public int describeContents() { 67 | return 0; 68 | } 69 | 70 | @Override 71 | public void writeToParcel(Parcel dest, int flags) { 72 | dest.writeString(this.reply_code); 73 | dest.writeString(this.reply_message); 74 | dest.writeParcelable(this.UserInfo, flags); 75 | } 76 | 77 | protected ReturnData(Parcel in) { 78 | this.reply_code = in.readString(); 79 | this.reply_message = in.readString(); 80 | this.UserInfo = in.readParcelable(com.padeoe.nicservice.njuwlan.object.portal.UserInfo.class.getClassLoader()); 81 | } 82 | 83 | public static final Creator CREATOR = new Creator() { 84 | @Override 85 | public ReturnData createFromParcel(Parcel source) { 86 | return new ReturnData(source); 87 | } 88 | 89 | @Override 90 | public ReturnData[] newArray(int size) { 91 | return new ReturnData[size]; 92 | } 93 | }; 94 | 95 | /** 96 | * 判断是否登录成功 97 | * @return 98 | */ 99 | public boolean isLoginSuccess(){ 100 | return reply_code.equals("1")||reply_code.equals("6"); 101 | } 102 | } -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/nicservice/njuwlan/object/portal/list/Acct.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.nicservice.njuwlan.object.portal.list; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.alibaba.fastjson.annotation.JSONField; 5 | import com.padeoe.nicservice.njuwlan.object.portal.Base; 6 | import com.padeoe.nicservice.njuwlan.object.portal.row.AcctRow; 7 | 8 | /** 9 | * 10 | * 该类表示南京大学网络认证系统中查询详单信息获得的列表列表,该列表显示了每一次登陆至下线的详细信息, 11 | * 具体包含一个包含{@link AcctRow}对象的数组以及详单列表的总页数 12 | * @author padeoe 13 | * Date: 2015/9/23 14 | */ 15 | public class Acct extends Base { 16 | @JSONField(name = "rows") 17 | private AcctRow[] acctRows; 18 | 19 | public Acct() { 20 | } 21 | 22 | public static Acct getFromJson(String jsonobject) { 23 | try { 24 | return JSON.parseObject(jsonobject, Acct.class); 25 | } catch (Exception e) { 26 | return null; 27 | } 28 | } 29 | 30 | public AcctRow[] getAcctRows() { 31 | return acctRows; 32 | } 33 | 34 | public void setAcctRows(AcctRow[] acctRows) { 35 | this.acctRows = acctRows; 36 | } 37 | 38 | @Override 39 | public String toString() 40 | { 41 | return "Acct:[\n" + 42 | "total = "+total+",\n" + 43 | "reply_code = "+reply_code+",\n" + 44 | "reply_msg = "+reply_msg+",\n"+ 45 | acctRows.toString()+",\n]\n"; 46 | } 47 | } 48 | 49 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/nicservice/njuwlan/object/portal/list/AuthLog.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.nicservice.njuwlan.object.portal.list; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.alibaba.fastjson.annotation.JSONField; 5 | import com.padeoe.nicservice.njuwlan.object.portal.Base; 6 | import com.padeoe.nicservice.njuwlan.object.portal.row.AuthLogRow; 7 | 8 | /** 9 | * 该类表示南京大学网络认证系统中查询认证信息获得的列表,该列表包含认证的每一次记录 10 | * 具体包含一个包含{@link AuthLogRow}对象的数组以及认证列表的总页数 11 | * @author padeoe 12 | * Date: 2015/9/23 13 | */ 14 | public class AuthLog extends Base { 15 | @JSONField(name = "rows") 16 | private AuthLogRow[] authLogRows; 17 | 18 | public AuthLog() { 19 | } 20 | 21 | public static AuthLog getFromJson(String jsonobject) { 22 | try { 23 | return JSON.parseObject(jsonobject, AuthLog.class); 24 | } catch (Exception e) { 25 | return null; 26 | } 27 | } 28 | 29 | public AuthLogRow[] getAuthLogRows() { 30 | return authLogRows; 31 | } 32 | 33 | public void setAuthLogRows(AuthLogRow[] authLogRows) { 34 | this.authLogRows = authLogRows; 35 | } 36 | 37 | @Override 38 | public String toString() 39 | { 40 | return "Authlog:[\n" + 41 | "total = "+total+",\n" + 42 | "reply_code = "+reply_code+",\n" + 43 | "reply_msg = "+reply_msg+",\n"+ 44 | authLogRows.toString()+",\n]\n"; 45 | } 46 | } 47 | 48 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/nicservice/njuwlan/object/portal/list/Bills.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.nicservice.njuwlan.object.portal.list; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.alibaba.fastjson.annotation.JSONField; 5 | import com.padeoe.nicservice.njuwlan.object.portal.Base; 6 | import com.padeoe.nicservice.njuwlan.object.portal.row.BillsRow; 7 | 8 | /** 9 | * 该类表示南京大学网络认证系统中查询账单信息获得的列表 10 | * 具体包含一个包含{@link BillsRow}对象的数组以及账单列表的总页数 11 | * @author padeoe 12 | * Date: 2015/9/23 13 | */ 14 | public class Bills extends Base { 15 | @JSONField(name = "rows") 16 | private BillsRow[] billsRows; 17 | 18 | public Bills() { 19 | } 20 | 21 | public static Bills getFromJson(String jsonobject) { 22 | try { 23 | return JSON.parseObject(jsonobject, Bills.class); 24 | } catch (Exception e) { 25 | return null; 26 | } 27 | } 28 | 29 | public BillsRow[] getBillsRows() { 30 | return billsRows; 31 | } 32 | 33 | public void setBillsRows(BillsRow[] billsRows) { 34 | this.billsRows = billsRows; 35 | } 36 | 37 | @Override 38 | public String toString() 39 | { 40 | return "Bills:[\n" + 41 | "total = "+total+",\n" + 42 | "reply_code = "+reply_code+",\n" + 43 | "reply_msg = "+reply_msg+",\n"+ 44 | billsRows.toString()+",\n]\n"; 45 | } 46 | } 47 | 48 | 49 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/nicservice/njuwlan/object/portal/list/Online.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.nicservice.njuwlan.object.portal.list; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.alibaba.fastjson.annotation.JSONField; 5 | import com.padeoe.nicservice.njuwlan.object.portal.Base; 6 | import com.padeoe.nicservice.njuwlan.object.portal.row.OnlineRow; 7 | 8 | /** 9 | * 该类表示南京大学网络认证系统中查询当前在线设备获得的列表 10 | * 具体包含一个包含{@link OnlineRow}对象的数组以及在线设备列表的总页数 11 | * @author padeoe 12 | * Date: 2015/9/24 13 | */ 14 | public class Online extends Base 15 | { 16 | @JSONField(name = "rows") 17 | private OnlineRow[] onlineRows; 18 | 19 | public Online(){} 20 | public static Online getFromJson(String jsonobject){ 21 | try { 22 | return JSON.parseObject(jsonobject, Online.class); 23 | } catch (Exception e) { 24 | return null; 25 | } 26 | } 27 | 28 | 29 | public OnlineRow[] getOnlineRows() { 30 | return onlineRows; 31 | } 32 | 33 | public void setOnlineRows(OnlineRow[] onlineRows) { 34 | this.onlineRows = onlineRows; 35 | } 36 | 37 | @Override 38 | public String toString() 39 | { 40 | return "Online:[\n" + 41 | "total = "+total+",\n" + 42 | "reply_code = "+reply_code+",\n" + 43 | "reply_msg = "+reply_msg+",\n"+ 44 | onlineRows.toString()+",\n]\n"; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/nicservice/njuwlan/object/portal/list/Recharge.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.nicservice.njuwlan.object.portal.list; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.alibaba.fastjson.annotation.JSONField; 5 | import com.padeoe.nicservice.njuwlan.object.portal.Base; 6 | import com.padeoe.nicservice.njuwlan.object.portal.row.RechargeRow; 7 | 8 | /** 9 | * 该类表示南京大学网络认证系统中查询充值信息获得的列表 10 | * 具体包含一个包含{@link RechargeRow}对象的数组以及充值列表的总页数 11 | * @author padeoe 12 | * Date: 2015/9/23 13 | */ 14 | public class Recharge extends Base { 15 | @JSONField(name = "rows") 16 | private RechargeRow[] rechargeRows; 17 | 18 | public RechargeRow[] getRechargeRows() { 19 | return rechargeRows; 20 | } 21 | 22 | public void setRechargeRows(RechargeRow[] rechargeRows) { 23 | this.rechargeRows = rechargeRows; 24 | } 25 | public static Recharge getFromJson(String jsonobject){ 26 | try { 27 | return JSON.parseObject(jsonobject, Recharge.class); 28 | } catch (Exception e) { 29 | return null; 30 | } 31 | } 32 | @Override 33 | public String toString() 34 | { 35 | return "Recharge:[\n" + 36 | "total = "+total+",\n" + 37 | "reply_code = "+reply_code+",\n" + 38 | "reply_msg = "+reply_msg+",\n"+ 39 | rechargeRows.toString()+",\n]\n"; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/nicservice/njuwlan/object/portal/row/AcctRow.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.nicservice.njuwlan.object.portal.row; 2 | 3 | import com.padeoe.nicservice.njuwlan.object.bras.row.AcctRowBras; 4 | 5 | /** 6 | * 该类表示南京大学网络认证系统中查询详单信息获得的详单信息列表中具体的一条(行)信息, 7 | * 包含用户所在区域,mac地址,id,用户名,使用时长等大量信息。 8 | */ 9 | public class AcctRow extends AcctRowBras{ 10 | } 11 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/nicservice/njuwlan/object/portal/row/AuthLogRow.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.nicservice.njuwlan.object.portal.row; 2 | 3 | import com.padeoe.nicservice.njuwlan.object.bras.row.AuthLogRowBras; 4 | 5 | /** 6 | * 该类表示南京大学网络认证系统中查询登陆日志详单获得的详单信息列表中具体的一条(行)信息 7 | * 包括登陆区域,mac地址,登陆返回信息,用户名等大量信息 8 | * @author padeoe 9 | * Date: 2015/9/23 10 | */ 11 | public class AuthLogRow extends AuthLogRowBras { 12 | protected String pvlan; 13 | protected String reply_code; 14 | protected String acctsessionid; 15 | protected String id; 16 | protected String area_type_name; 17 | 18 | public AuthLogRow() { 19 | } 20 | 21 | public String getPvlan() { 22 | return pvlan; 23 | } 24 | 25 | public void setPvlan(String pvlan) { 26 | this.pvlan = pvlan; 27 | } 28 | 29 | public String getReply_code() { 30 | return reply_code; 31 | } 32 | 33 | public void setReply_code(String reply_code) { 34 | this.reply_code = reply_code; 35 | } 36 | 37 | public String getAcctsessionid() { 38 | return acctsessionid; 39 | } 40 | 41 | public void setAcctsessionid(String acctsessionid) { 42 | this.acctsessionid = acctsessionid; 43 | } 44 | 45 | public String getId() { 46 | return id; 47 | } 48 | 49 | public void setId(String id) { 50 | this.id = id; 51 | } 52 | 53 | public String getArea_type_name() { 54 | return area_type_name; 55 | } 56 | 57 | public void setArea_type_name(String area_type_name) { 58 | this.area_type_name = area_type_name; 59 | } 60 | 61 | @Override 62 | public String toString() { 63 | return "ClassPojo [pvlan = " + pvlan + ", area_id = " + area_id + ", subport = " + subport + ", reply_code = " + reply_code + ", acctsessionid = " + acctsessionid + ", mac = " + mac + ", ap_id = " + ap_id + ", reply_msg = " + reply_msg + ", id = " + id + ", area_type = " + area_type + ", svlan = " + svlan + ", username = " + username + ", area_name = " + area_name + ", src_ip = " + src_ip + ", nas_ip = " + nas_ip + ", datetime = " + datetime + ", area_type_name = " + area_type_name + "]"; 64 | } 65 | } 66 | 67 | 68 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/nicservice/njuwlan/object/portal/row/BillsRow.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.nicservice.njuwlan.object.portal.row; 2 | 3 | import com.padeoe.nicservice.njuwlan.object.bras.row.BillsRowBras; 4 | 5 | /** 6 | * 该类表示南京大学网络认证系统中查询账单信息获得的详单信息列表中具体的一条(行)信息 7 | * 具体包括起始时间,id,消费金额等信息 8 | * @author padeoe 9 | * Date: 2015/9/23 10 | */ 11 | public class BillsRow extends BillsRowBras{ 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/nicservice/njuwlan/object/portal/row/OnlineRow.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.nicservice.njuwlan.object.portal.row; 2 | 3 | import com.padeoe.nicservice.njuwlan.object.bras.row.OnlineRowBras; 4 | 5 | /** 6 | * 该类表示南京大学网络认证系统中查询当前在线设备获得的在线设备列表中具体的一条(行)信息 7 | * 具体包括登陆区域,mac地址,登陆返回信息,用户名等大量信息 8 | * @author padeoe 9 | * Date: 2015/9/24 10 | */ 11 | public class OnlineRow extends OnlineRowBras 12 | { 13 | protected String user_id; 14 | 15 | public String getUser_id() { 16 | return user_id; 17 | } 18 | 19 | public void setUser_id(String user_id) { 20 | this.user_id = user_id; 21 | } 22 | @Override 23 | public String toString() 24 | { 25 | return "ClassPojo [pvlan = "+pvlan+", service_id = "+service_id+", area_id = "+area_id+", acctsessiontime = "+acctsessiontime+", mac = "+mac+", service_name = "+service_name+", ap_id = "+ap_id+", area_type = "+area_type+", id = "+id+", username = "+username+", acctstarttime = "+acctstarttime+", area_name = "+area_name+", acctoutputoctets_ipv4 = "+acctoutputoctets_ipv4+", user_ipv4 = "+user_ipv4+", fullname = "+fullname+", acctoutputoctets_ipv6 = "+acctoutputoctets_ipv6+", user_ipv6 = "+user_ipv6+", acctinputoctets_ipv6 = "+acctinputoctets_ipv6+", acctinputoctets_ipv4 = "+acctinputoctets_ipv4+", subport = "+subport+", acctsessionid = "+acctsessionid+", svlan = "+svlan+", src_ip = "+src_ip+", nas_ip = "+nas_ip+"]"; 26 | } 27 | } 28 | 29 | 30 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/nicservice/njuwlan/object/portal/row/RechargeRow.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.nicservice.njuwlan.object.portal.row; 2 | 3 | import com.padeoe.nicservice.njuwlan.object.bras.row.RechargeRowBras; 4 | 5 | /** 6 | * 该类表示南京大学网络认证系统中查询充值记录获得的充值记录列表中具体的一条(行)信息 7 | * 具体包括充值金额,充值时间等信息 8 | * @author padeoe 9 | * Date: 2015/9/23 10 | */ 11 | public class RechargeRow extends RechargeRowBras{ 12 | private String id; 13 | 14 | public String getId() { 15 | return id; 16 | } 17 | 18 | public void setId(String id) { 19 | this.id = id; 20 | } 21 | 22 | @Override 23 | public String toString() { 24 | return "ClassPojo [id = " + id + ", amount = " + amount + ", remark = " + remark + ", oper_time = " + oper_time + ", oper_username = " + oper_username + ", oper_id = " + oper_id + ", account_no = " + account_no + "]"; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/nicservice/njuwlan/service/AccountService.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.nicservice.njuwlan.service; 2 | 3 | import com.padeoe.nicservice.njuwlan.utils.NetworkUtils; 4 | 5 | import java.io.IOException; 6 | 7 | /** 8 | * 该类用于实现南京大学网络认证系统的账户管理功能,包括修改密码功能 9 | * Created by padeoe on 2015/9/26. 10 | */ 11 | public class AccountService { 12 | /** 13 | * 修改南京大学网络认证系统的密码,将会依次尝试 14 | * 1.通过南京大学网络认证系统的接口修改密码, 15 | * 2.通过南京大学网络认证计费系统自助平台的接口修改密码。 16 | * 17 | * @param username 南京大学网络认证系统的用户名 18 | * @param oldPassword 南京大学网络认证系统的旧密码 19 | * @param newPassword 南京大学网络认证系统的新密码 20 | * @return 南京大学网络认证系统的服务器返回消息,可以通过 {@link #isChangePasswSuccess(String)}来对返回值分析是否改密成功 21 | */ 22 | public static String changePassword(String username, String oldPassword, String newPassword) throws IOException { 23 | if (new OnlineQueryService().isPortalOnline()) { 24 | return NetworkUtils.connectAndPost("oldpassword=" + oldPassword + "&newpassword=" + newPassword + "&confirmpassword=" + newPassword, "http://"+NetworkUtils.getCurrentPortalIP()+"/portal_io/selfservice/modifypassword", 200); 25 | } else { 26 | //首先登陆bras.nju.edu.cn获取cookie 27 | String cookie; 28 | String[] loginResult = NetworkUtils.postAndGetCookie("username=" + username + "&password=" + oldPassword, "http://"+NetworkUtils.getCurrentBrasIP()+":8080/manage/self/auth/login", 200); 29 | if (OfflineQueryService.isLoginSuccess(loginResult[0])) { 30 | cookie = loginResult[1]; 31 | //登陆成功,修改密码 32 | return NetworkUtils.postWithCookie("oldPassword=" + oldPassword + "&newPassword=" + newPassword + "&confirmPassword=" + newPassword, cookie, "http://"+NetworkUtils.getCurrentBrasIP()+":8080/manage/self/userinfo/modifypassword", 200); 33 | } else { 34 | isChangePasswSuccess(""); 35 | return loginResult[0]; 36 | } 37 | } 38 | } 39 | 40 | /** 41 | * 判断{@link #changePassword(String, String, String)}是否改密成功 42 | * @param result {@link AccountService#changePassword(String username, String oldPassword, String newPassword)}返回值 43 | * @return 是否改密成功 44 | */ 45 | public static boolean isChangePasswSuccess(String result) { 46 | return result.equals("{\"reply_msg\":\"操作成功\",\"reply_code\":0}\n") || result.endsWith("\"reply_code\":0,\"request_uri\":\"/manage/self/userinfo/modifypassword\"}\n"); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/nicservice/njuwlan/service/DetailQuery.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.nicservice.njuwlan.service; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * 该接口用于描述南京大学网络认证系统的和南京大学网络认证计费系统自助平台都提供了的某些查询功能, 7 | * 包括获取当前在线设备,获取详单信息,获取认证信息,获取账单信息,获取充值信息 8 | * @author padeoe 9 | * Date: 2015/9/24 10 | */ 11 | public interface DetailQuery { 12 | String queryBy(int catalog, int page, int row, boolean order) throws IOException; 13 | String getOnline(int page, int row) throws IOException; 14 | String getAuthLog(int page, int row, boolean order) throws IOException; 15 | String getAcct(int page, int row, boolean order) throws IOException; 16 | String getBills(int page, int row, boolean order) throws IOException; 17 | String getRecharge(int page, int row, boolean order) throws IOException; 18 | } 19 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/nicservice/njuwlan/utils/ConversionUtils.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.nicservice.njuwlan.utils; 2 | 3 | /** 4 | * 该类集合了一些单位转换的静态方法,包括数据单位转换,ip转换 5 | * @author padeoe 6 | * Date: 2015/12/17 7 | */ 8 | public class ConversionUtils { 9 | /** 10 | * 将以B为单位的流量转化成合适的单位 11 | * 12 | * @param octetsSize long类型的数字,字节数,例如"2049" 13 | * @return 例如"1.01KB","2.34GB" 14 | */ 15 | public static String getShownDataSize(String octetsSize) { 16 | long size_b = Long.parseLong(octetsSize); 17 | boolean isMultiple = size_b % 1024 == 0; 18 | if (size_b < 1024) { 19 | return size_b + "B"; 20 | } 21 | if (size_b < 1048576) { 22 | return round(size_b / 1024.0, isMultiple) + "KB"; 23 | } 24 | if (size_b < 1073741824) { 25 | return round(size_b / 1048576.0, isMultiple) + "MB"; 26 | } 27 | if (size_b < 1099511627776L) { 28 | return round(size_b / 1073741824.0, isMultiple) + "GB"; 29 | } 30 | return round(size_b / 1099511627776.0, isMultiple) + "TB"; 31 | } 32 | 33 | private static String round(double number, boolean isMultiple) { 34 | if (isMultiple) { 35 | return String.valueOf((int) number); 36 | } 37 | return String.format("%.2f", number); 38 | } 39 | 40 | /** 41 | * 将十进制的IPv4地址转化成点段式IP地址 42 | * 43 | * @param ipv4 例如“1926545573” 44 | * @return 十进制点段式IP地址,例如“114.212.192.165” 45 | */ 46 | public static String getIPv4(String ipv4) { 47 | long ip = Long.parseLong(ipv4); 48 | long ip1 = (ip >>> 24) & 0x0ff; 49 | long ip2 = (ip >>> 16) & 0x0ff; 50 | long ip3 = (ip >>> 8) & 0x0ff; 51 | long ip4 = ip & 0x0ff; 52 | return String.format("%d.%d.%d.%d", ip1, ip2, ip3, ip4); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/njunet/App.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.njunet; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | import android.preference.PreferenceManager; 6 | 7 | import com.padeoe.nicservice.njuwlan.service.LoginService; 8 | import com.padeoe.nicservice.njuwlan.service.OfflineQueryService; 9 | import com.padeoe.njunet.util.PrefFileManager; 10 | 11 | import java.util.HashSet; 12 | import java.util.Set; 13 | 14 | /** 15 | * Created by padeoe on 2016/4/21. 16 | */ 17 | public class App extends Application { 18 | public static Context context; 19 | private static Boolean showNotification = null; 20 | private static Set portalWiFiSSIDSet = null; 21 | private static Set suspiciousWiFiSSIDSet = null; 22 | private static int maxTry = -1; 23 | 24 | @Override 25 | public void onCreate() { 26 | super.onCreate(); 27 | context = getApplicationContext(); 28 | LoginService loginService = LoginService.getInstance(); 29 | loginService.setTimeout(Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext()).getString("timeout_portal", "200"))); 30 | String portal_ip = PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext()).getString("portal_server", "").trim(); 31 | 32 | loginService.setSettingsPortalIP(portal_ip.equals("") ? null : portal_ip); 33 | 34 | String bras_ip = PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext()).getString("bras_server", "").trim(); 35 | OfflineQueryService.setSettingsBrasIP(bras_ip.equals("") ? null : bras_ip); 36 | } 37 | 38 | public static Context getAppContext() { 39 | return context; 40 | } 41 | 42 | public static Boolean getShowNotification() { 43 | return showNotification != null ? showNotification : (showNotification = PrefFileManager.getAccountPref().getBoolean("showNotification", true)); 44 | } 45 | 46 | public static void setShowNotification(Boolean showNotification) { 47 | PrefFileManager.getAccountPref().edit().putBoolean("showNotification", App.showNotification = showNotification).apply(); 48 | } 49 | 50 | private static Set getPortalWiFiSSIDSet() { 51 | return portalWiFiSSIDSet != null ? portalWiFiSSIDSet : (portalWiFiSSIDSet = PrefFileManager.getWiFiPref().getStringSet("portalWiFiSSIDSet", new HashSet())); 52 | } 53 | 54 | public static void addWiFiSSID(String SSID) { 55 | if (getPortalWiFiSSIDSet().add(SSID)) { 56 | PrefFileManager.getWiFiPref().edit().putStringSet("portalWiFiSSIDSet", portalWiFiSSIDSet).apply(); 57 | if (getSuspiciousWiFiSSIDSet().remove(SSID)) 58 | PrefFileManager.getWiFiPref().edit().putStringSet("suspiciousWiFiSSIDSet", suspiciousWiFiSSIDSet).apply(); 59 | } 60 | } 61 | 62 | public static void removeWiFiSSID(String SSID) { 63 | if (getPortalWiFiSSIDSet().remove(SSID)) { 64 | PrefFileManager.getWiFiPref().edit().putStringSet("portalWiFiSSIDSet", portalWiFiSSIDSet).apply(); 65 | if (getSuspiciousWiFiSSIDSet().add(SSID)) 66 | PrefFileManager.getWiFiPref().edit().putStringSet("suspiciousWiFiSSIDSet", suspiciousWiFiSSIDSet).apply(); 67 | } 68 | } 69 | 70 | private static Set getSuspiciousWiFiSSIDSet() { 71 | return suspiciousWiFiSSIDSet != null ? suspiciousWiFiSSIDSet : (suspiciousWiFiSSIDSet = PrefFileManager.getWiFiPref().getStringSet("suspiciousWiFiSSIDSet", new HashSet())); 72 | } 73 | 74 | public static boolean isInPortalWiFiSet(String SSID) { 75 | return getPortalWiFiSSIDSet().contains(SSID); 76 | } 77 | 78 | public static boolean isInSuspiciousWiFiSSIDSet(String SSID) { 79 | return getSuspiciousWiFiSSIDSet().contains(SSID); 80 | } 81 | 82 | public static int getMaxTry() { 83 | return maxTry == -1 ? Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(context).getString("times_relogin", "4")) : maxTry; 84 | } 85 | 86 | public static void setMaxTry(int maxTry) { 87 | App.maxTry = maxTry; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/njunet/connect/PermissionExplainFragment.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.njunet.connect; 2 | 3 | import android.app.Activity; 4 | import android.app.AlertDialog; 5 | import android.app.Dialog; 6 | import android.app.DialogFragment; 7 | import android.content.DialogInterface; 8 | import android.os.Bundle; 9 | import android.support.annotation.Nullable; 10 | import android.view.LayoutInflater; 11 | import android.view.View; 12 | import android.view.ViewGroup; 13 | 14 | import com.padeoe.njunet.R; 15 | 16 | /** 17 | * Created by padeoe on 2016/5/22. 18 | */ 19 | public class PermissionExplainFragment extends DialogFragment { 20 | PermissionHandler permissionHandler; 21 | 22 | public interface PermissionHandler { 23 | void onPermissionExplained(); 24 | } 25 | 26 | @Override 27 | public Dialog onCreateDialog(Bundle savedInstanceState) { 28 | AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 29 | LayoutInflater inflater = getActivity().getLayoutInflater(); 30 | View view = inflater.inflate(R.layout.permission_dialog, null); 31 | builder.setView(view) 32 | .setPositiveButton(R.string.next, new DialogInterface.OnClickListener() { 33 | @Override 34 | public void onClick(DialogInterface dialog, int id) { 35 | permissionHandler.onPermissionExplained(); 36 | } 37 | }) 38 | .setTitle(R.string.permission_request) 39 | .setMessage(R.string.permission_location_detail); 40 | return builder.create(); 41 | } 42 | 43 | @Nullable 44 | @Override 45 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 46 | getDialog().setCanceledOnTouchOutside(false); 47 | return super.onCreateView(inflater, container, savedInstanceState); 48 | } 49 | 50 | @Override 51 | public void onAttach(Activity activity) { 52 | super.onAttach(activity); 53 | try { 54 | // Instantiate the NoticeDialogListener so we can send events to the host 55 | permissionHandler = (PermissionHandler) activity; 56 | } catch (ClassCastException e) { 57 | // The activity doesn't implement the interface, throw exception 58 | throw new ClassCastException(activity.toString() 59 | + " must implement UpdateListener"); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/njunet/connect/controller/UpdateInfo.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.njunet.connect.controller; 2 | 3 | import android.util.Log; 4 | 5 | import com.padeoe.nicservice.njuwlan.object.portal.BasicInfo; 6 | import com.padeoe.nicservice.njuwlan.object.portal.ReturnData; 7 | import com.padeoe.nicservice.njuwlan.object.portal.row.BasicInfoRow; 8 | import com.padeoe.nicservice.njuwlan.service.OnlineQueryService; 9 | import com.padeoe.njunet.App; 10 | import com.padeoe.njunet.R; 11 | import com.padeoe.njunet.connect.uihandler.ConnectResultHandle; 12 | import com.padeoe.njunet.connect.uihandler.ErrorHandle; 13 | import com.padeoe.njunet.connect.uihandler.GetOnlineTimeFailHandle; 14 | import com.padeoe.njunet.connect.uihandler.OnlineTimeHandle; 15 | import com.padeoe.njunet.connect.uihandler.ReturnDataHandle; 16 | import com.padeoe.njunet.util.MyObservable; 17 | 18 | import java.io.IOException; 19 | 20 | /** 21 | * Created by padeoe on 2016/4/26. 22 | */ 23 | public class UpdateInfo extends MyObservable { 24 | public void updateInfo() { 25 | new Thread() { 26 | @Override 27 | public void run() { 28 | super.run(); 29 | OnlineQueryService onlineQueryService = new OnlineQueryService(); 30 | try { 31 | String result = onlineQueryService.getCurrentUserInfo(); 32 | ReturnData returnData = ReturnData.getFromJson(result); 33 | setChanged(); 34 | notifyObservers(returnData != null ? new ReturnDataHandle(returnData) : new ErrorHandle(result)); 35 | } catch (IOException e) { 36 | setChanged(); 37 | notifyObservers(new ErrorHandle(e.getMessage())); 38 | e.printStackTrace(); 39 | } 40 | 41 | } 42 | }.start(); 43 | } 44 | 45 | public void updateOnlineTime() { 46 | new Thread() { 47 | @Override 48 | public void run() { 49 | super.run(); 50 | OnlineQueryService onlineQueryService = new OnlineQueryService(); 51 | String result = null; 52 | try { 53 | result = onlineQueryService.getBasicInfo(); 54 | BasicInfo basicInfo = BasicInfo.getFromJson(result); 55 | int seconds; 56 | if (basicInfo != null && basicInfo.getBasicInfoRows() != null && basicInfo.getBasicInfoRows().length > 0) { 57 | BasicInfoRow basicInfoRow = basicInfo.getBasicInfoRows()[0]; 58 | try { 59 | seconds = Integer.parseInt(basicInfoRow.getTotal_ipv4_volume()); 60 | setChanged(); 61 | notifyObservers(new OnlineTimeHandle(seconds)); 62 | } catch (NumberFormatException e) { 63 | setChanged(); 64 | notifyObservers(new ErrorHandle(App.context.getString(R.string.illegal_result_from_server))); 65 | } 66 | } else { 67 | setChanged(); 68 | notifyObservers(new GetOnlineTimeFailHandle()); 69 | Log.e("获取时间失败", result); 70 | } 71 | } catch (IOException e) { 72 | setChanged(); 73 | notifyObservers(new ErrorHandle(e.getMessage())); 74 | e.printStackTrace(); 75 | } 76 | } 77 | }.start(); 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/njunet/connect/controller/WiFiScanner.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.njunet.connect.controller; 2 | 3 | import android.content.BroadcastReceiver; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.content.IntentFilter; 7 | import android.net.wifi.WifiManager; 8 | import android.support.v4.content.LocalBroadcastManager; 9 | 10 | import com.padeoe.njunet.App; 11 | import com.padeoe.njunet.connect.StatusNotificationManager; 12 | import com.padeoe.njunet.connect.monitor.ScanResultReceiver; 13 | import com.padeoe.njunet.connect.uihandler.ConnectResultHandle; 14 | import com.padeoe.njunet.util.MyObservable; 15 | import com.padeoe.njunet.util.MyObserver; 16 | 17 | /** 18 | * Created by padeoe on 2016/5/20. 19 | */ 20 | public class WiFiScanner implements MyObserver { 21 | static BroadcastReceiver receiver; 22 | 23 | public void startScan() { 24 | //如果wifi未连接,才进行扫描 25 | if (ConnectManager.getStatus() == ConnectManager.Status.WIFI_LOST) { 26 | StatusNotificationManager.showStatus("正在扫描WLAN"); 27 | //首先确保wifi开关已打开 28 | WifiManager wifiManager = (WifiManager) App.getAppContext().getApplicationContext().getSystemService(Context.WIFI_SERVICE); 29 | App.getAppContext().registerReceiver(receiver = new ScanResultReceiver(), new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)); 30 | if (wifiManager.isWifiEnabled() || wifiManager.setWifiEnabled(true)) { 31 | wifiManager.startScan(); 32 | } 33 | } 34 | //如果已连接,不进行扫描,做网络检测刷新或登录。 35 | else { 36 | System.out.println("无需扫描wifi,即将检查网络"); 37 | ConnectManager.setStatus(ConnectManager.Status.DETECTING); 38 | StatusNotificationManager.showStatus(); 39 | ConnectManager connectManager = new ConnectManager(); 40 | connectManager.addObserver(this); 41 | connectManager.login(); 42 | } 43 | } 44 | 45 | 46 | @Override 47 | public void update(MyObservable myObservable, ConnectResultHandle data) { 48 | //发送广播,可能别处的界面需要更新信息 49 | System.out.println("发送登陆结果广播"); 50 | Intent intent = new Intent(ConnectManager.BACKGROUND_LOGIN_ACTION); 51 | intent.putExtra("LOGIN_RESULT", data); 52 | LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(App.getAppContext()); 53 | broadcastManager.sendBroadcast(intent); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/njunet/connect/monitor/BootReceiver.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.njunet.connect.monitor; 2 | 3 | /** 4 | * Created by padeoe on 2016/6/1. 5 | */ 6 | 7 | import android.content.BroadcastReceiver; 8 | import android.content.Context; 9 | import android.content.Intent; 10 | import android.content.SharedPreferences; 11 | import android.preference.PreferenceManager; 12 | 13 | import com.padeoe.njunet.App; 14 | import com.padeoe.njunet.connect.controller.ConnectService; 15 | import com.padeoe.njunet.util.PrefFileManager; 16 | 17 | public class BootReceiver extends BroadcastReceiver { 18 | @Override 19 | public void onReceive(Context context, Intent intent) { 20 | SharedPreferences sharedPreferences = PrefFileManager.getAccountPref(); 21 | if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) { 22 | if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean("boot_launch", true) && 23 | PreferenceManager.getDefaultSharedPreferences(context).getBoolean("auto_connect",true)&& 24 | sharedPreferences.getString("username", null) != null && 25 | sharedPreferences.getString("password", null) != null) { 26 | context.startService(new Intent(context, ConnectService.class)); 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/njunet/connect/monitor/NetworkConnectChangedReceiver.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.njunet.connect.monitor; 2 | 3 | import android.content.BroadcastReceiver; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.net.NetworkInfo; 7 | import android.net.wifi.SupplicantState; 8 | import android.net.wifi.WifiInfo; 9 | import android.net.wifi.WifiManager; 10 | import android.support.v4.content.LocalBroadcastManager; 11 | import android.util.Log; 12 | 13 | import com.padeoe.nicservice.njuwlan.service.LoginService; 14 | import com.padeoe.njunet.App; 15 | import com.padeoe.njunet.R; 16 | import com.padeoe.njunet.connect.StatusNotificationManager; 17 | import com.padeoe.njunet.connect.controller.ConnectManager; 18 | import com.padeoe.njunet.connect.controller.ConnectService; 19 | import com.padeoe.njunet.connect.uihandler.ConnectResultHandle; 20 | import com.padeoe.njunet.connect.uihandler.ErrorHandle; 21 | import com.padeoe.njunet.connect.uihandler.WifiAvailableHandle; 22 | import com.padeoe.njunet.connect.uihandler.WifiLostHandle; 23 | import com.padeoe.njunet.util.MyObservable; 24 | import com.padeoe.njunet.util.MyObserver; 25 | 26 | /** 27 | * Created by padeoe on 4/20/15. 28 | */ 29 | public class NetworkConnectChangedReceiver extends BroadcastReceiver implements MyObserver { 30 | public void onReceive(final Context context, Intent intent) { 31 | NetworkInfo networkInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO); 32 | if (networkInfo != null) { 33 | NetworkInfo.DetailedState state = networkInfo.getDetailedState(); 34 | if (state == NetworkInfo.DetailedState.DISCONNECTED && ConnectManager.getStatus() != ConnectManager.Status.WIFI_LOST) { 35 | ConnectManager.stopAllConnect(); 36 | ConnectManager.setStatus(ConnectManager.Status.WIFI_LOST); 37 | StatusNotificationManager.showStatus(App.getAppContext().getResources().getString(R.string.no_wifi)); 38 | 39 | //发送离线广播,可能别处的界面需要更新信息 40 | Intent wifiLostIntent = new Intent(ConnectManager.WIFI_LOST_ACTION); 41 | wifiLostIntent.putExtra("WIFI_LOST", new WifiLostHandle()); 42 | LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(App.getAppContext()); 43 | broadcastManager.sendBroadcast(wifiLostIntent); 44 | } else { 45 | if (state == NetworkInfo.DetailedState.CONNECTED && ConnectManager.getStatus() == ConnectManager.Status.WIFI_LOST) { 46 | ConnectManager.setStatus(ConnectManager.Status.DETECTING); 47 | StatusNotificationManager.showStatus(); 48 | //绑定网络,开始监测portal的连通性 49 | ConnectManager.bindNetWork(); 50 | ConnectManager connectManager = new ConnectManager(); 51 | connectManager.addObserver(this); 52 | Log.d("登陆请求", "收到wifi连接广播"); 53 | connectManager.backgrConnect(); 54 | 55 | //发送广播,可能别处的界面需要更新信息 56 | WifiManager wifiManager = (WifiManager) App.getAppContext().getApplicationContext().getSystemService(Context.WIFI_SERVICE); 57 | Intent wifiConnectedIntent = new Intent(ConnectManager.WIFI_AVAILABLE_ACTION); 58 | wifiConnectedIntent.putExtra("NETINFO", new WifiAvailableHandle(wifiManager.getConnectionInfo().getSSID())); 59 | LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(App.getAppContext()); 60 | broadcastManager.sendBroadcast(wifiConnectedIntent); 61 | } 62 | } 63 | } 64 | } 65 | 66 | @Override 67 | public void update(MyObservable myObservable, ConnectResultHandle data) { 68 | //发送广播,可能别处的界面需要更新信息 69 | Intent intent = new Intent(ConnectManager.BACKGROUND_LOGIN_ACTION); 70 | intent.putExtra("LOGIN_RESULT", data); 71 | LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(App.getAppContext()); 72 | broadcastManager.sendBroadcast(intent); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/njunet/connect/monitor/ScanResultReceiver.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.njunet.connect.monitor; 2 | 3 | import android.content.BroadcastReceiver; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.net.wifi.ScanResult; 7 | import android.net.wifi.WifiConfiguration; 8 | import android.net.wifi.WifiManager; 9 | import android.os.Build; 10 | import android.util.Log; 11 | 12 | import com.padeoe.njunet.App; 13 | import com.padeoe.njunet.connect.StatusNotificationManager; 14 | 15 | import java.util.List; 16 | 17 | /** 18 | * Created by padeoe on 2016/5/21. 19 | */ 20 | public class ScanResultReceiver extends BroadcastReceiver { 21 | WifiManager wifiManager = (WifiManager) App.getAppContext().getApplicationContext().getSystemService(Context.WIFI_SERVICE); 22 | 23 | @Override 24 | public void onReceive(Context context, Intent intent) { 25 | List scanResults = wifiManager.getScanResults(); 26 | String myRequestWiFi = null; 27 | 28 | if (Build.VERSION.SDK_INT >= 17) { 29 | for (ScanResult s : scanResults) { 30 | if (App.isInPortalWiFiSet("\"" + s.SSID + "\"")) { 31 | myRequestWiFi = "\"" + s.SSID + "\""; 32 | break; 33 | } 34 | } 35 | 36 | if (myRequestWiFi == null) { 37 | for (ScanResult s : scanResults) { 38 | if (App.isInPortalWiFiSet("\"" + s.SSID + "\"")) { 39 | myRequestWiFi = "\"" + s.SSID + "\""; 40 | break; 41 | } 42 | } 43 | 44 | } 45 | } else { 46 | for (ScanResult s : scanResults) { 47 | if (App.isInPortalWiFiSet(s.SSID)) { 48 | myRequestWiFi = s.SSID; 49 | break; 50 | } 51 | } 52 | 53 | if (myRequestWiFi == null) { 54 | for (ScanResult s : scanResults) { 55 | if (App.isInPortalWiFiSet(s.SSID)) { 56 | myRequestWiFi = s.SSID; 57 | break; 58 | } 59 | } 60 | 61 | } 62 | } 63 | if (myRequestWiFi == null) { 64 | Log.e("未扫描到可用校园网", "扫描连接失败"); 65 | StatusNotificationManager.showStatus("未找到校园网Wifi"); 66 | } else { 67 | Log.e("扫描成功", myRequestWiFi); 68 | StatusNotificationManager.showStatus("正在连接" + myRequestWiFi); 69 | if (!App.isInPortalWiFiSet(wifiManager.getConnectionInfo().getSSID()) && !App.isInSuspiciousWiFiSSIDSet(wifiManager.getConnectionInfo().getSSID())) { 70 | List list = wifiManager.getConfiguredNetworks(); 71 | for (WifiConfiguration i : list) { 72 | if (i.SSID != null && i.SSID.equals(myRequestWiFi)) { 73 | wifiManager.enableNetwork(i.networkId, true); 74 | wifiManager.reassociate(); 75 | break; 76 | } 77 | } 78 | } 79 | } 80 | App.getAppContext().unregisterReceiver(this); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/njunet/connect/monitor/WifiNetWorkCallBack.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.njunet.connect.monitor; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.net.ConnectivityManager; 7 | import android.net.LinkProperties; 8 | import android.net.Network; 9 | import android.net.NetworkCapabilities; 10 | import android.net.wifi.WifiManager; 11 | import android.os.Build; 12 | import android.support.v4.content.LocalBroadcastManager; 13 | import android.util.Log; 14 | 15 | import com.padeoe.njunet.App; 16 | import com.padeoe.njunet.R; 17 | import com.padeoe.njunet.connect.StatusNotificationManager; 18 | import com.padeoe.njunet.connect.controller.ConnectManager; 19 | import com.padeoe.njunet.connect.uihandler.ConnectResultHandle; 20 | import com.padeoe.njunet.connect.uihandler.WifiAvailableHandle; 21 | import com.padeoe.njunet.connect.uihandler.WifiLostHandle; 22 | import com.padeoe.njunet.util.MyObservable; 23 | import com.padeoe.njunet.util.MyObserver; 24 | 25 | /** 26 | * Created by padeoe on 2016/5/11. 27 | */ 28 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 29 | public class WifiNetWorkCallBack extends ConnectivityManager.NetworkCallback implements MyObserver { 30 | public WifiNetWorkCallBack() { 31 | super(); 32 | } 33 | 34 | @Override 35 | public void onAvailable(final Network network) { 36 | super.onAvailable(network); 37 | ConnectManager.setStatus(ConnectManager.Status.DETECTING); 38 | StatusNotificationManager.showStatus(); 39 | //绑定网络,开始监测portal的连通性 40 | ConnectManager.bindNetWork(network); 41 | ConnectManager connectManager = new ConnectManager(); 42 | connectManager.addObserver(this); 43 | connectManager.backgrConnect(); 44 | 45 | //发送广播,可能别处的界面需要更新信息 46 | WifiManager wifiManager = (WifiManager) App.getAppContext().getApplicationContext().getSystemService(Context.WIFI_SERVICE); 47 | Intent intent = new Intent(ConnectManager.WIFI_AVAILABLE_ACTION); 48 | intent.putExtra("NETINFO", new WifiAvailableHandle(wifiManager.getConnectionInfo().getSSID())); 49 | LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(App.getAppContext()); 50 | broadcastManager.sendBroadcast(intent); 51 | } 52 | 53 | @Override 54 | public void onLost(Network network) { 55 | super.onLost(network); 56 | ConnectManager.stopAllConnect(); 57 | ConnectManager.setStatus(ConnectManager.Status.WIFI_LOST); 58 | StatusNotificationManager.showStatus(App.getAppContext().getResources().getString(R.string.no_wifi)); 59 | 60 | //发送离线广播,可能别处的界面需要更新信息 61 | Intent intent = new Intent(ConnectManager.WIFI_LOST_ACTION); 62 | intent.putExtra("WIFI_LOST", new WifiLostHandle()); 63 | LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(App.getAppContext()); 64 | broadcastManager.sendBroadcast(intent); 65 | } 66 | 67 | @Override 68 | public void update(MyObservable myObservable, ConnectResultHandle data) { 69 | //发送广播,可能别处的界面需要更新信息 70 | Intent intent = new Intent(ConnectManager.BACKGROUND_LOGIN_ACTION); 71 | intent.putExtra("LOGIN_RESULT", data); 72 | LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(App.getAppContext()); 73 | broadcastManager.sendBroadcast(intent); 74 | } 75 | } 76 | 77 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/njunet/connect/uihandler/AuthFailHandle.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.njunet.connect.uihandler; 2 | 3 | import android.content.Context; 4 | import android.net.wifi.WifiManager; 5 | import android.os.Parcel; 6 | 7 | import com.padeoe.nicservice.njuwlan.object.portal.ReturnData; 8 | import com.padeoe.njunet.App; 9 | import com.padeoe.njunet.connect.MainActivity; 10 | import com.padeoe.njunet.connect.StatusNotificationManager; 11 | import com.padeoe.njunet.connect.controller.ConnectManager; 12 | 13 | /** 14 | * Created by padeoe on 2016/5/19. 15 | */ 16 | public class AuthFailHandle implements ConnectResultHandle { 17 | ReturnData returnData; 18 | 19 | public AuthFailHandle(ReturnData returnData) { 20 | this.returnData = returnData; 21 | ConnectManager.setStatus(ConnectManager.Status.OFFLINE); 22 | StatusNotificationManager.showStatus("连接出错:" + returnData.getReply_message()); 23 | } 24 | 25 | @Override 26 | public void updateView(MainActivity activity) { 27 | activity.hideProgress(); 28 | WifiManager wifiManager = (WifiManager) App.getAppContext().getApplicationContext().getSystemService(Context.WIFI_SERVICE); 29 | activity.setNetInfo("认证失败",wifiManager.getConnectionInfo().getSSID()); 30 | // activity.user_detail.setVisibility(View.VISIBLE); 31 | activity.updateViewStatus(activity.status, ConnectManager.getStatus()); 32 | activity.showOnMainActivity(returnData.getReply_message()); 33 | } 34 | 35 | @Override 36 | public int describeContents() { 37 | return 0; 38 | } 39 | 40 | @Override 41 | public void writeToParcel(Parcel dest, int flags) { 42 | dest.writeParcelable(this.returnData, flags); 43 | } 44 | 45 | public AuthFailHandle() { 46 | } 47 | 48 | protected AuthFailHandle(Parcel in) { 49 | this.returnData = in.readParcelable(ReturnData.class.getClassLoader()); 50 | } 51 | 52 | public static final Creator CREATOR = new Creator() { 53 | @Override 54 | public AuthFailHandle createFromParcel(Parcel source) { 55 | return new AuthFailHandle(source); 56 | } 57 | 58 | @Override 59 | public AuthFailHandle[] newArray(int size) { 60 | return new AuthFailHandle[size]; 61 | } 62 | }; 63 | } 64 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/njunet/connect/uihandler/BackgrReturnDataHandle.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.njunet.connect.uihandler; 2 | 3 | import android.os.Parcel; 4 | 5 | import com.padeoe.nicservice.njuwlan.object.portal.ReturnData; 6 | import com.padeoe.njunet.connect.MainActivity; 7 | import com.padeoe.njunet.connect.StatusNotificationManager; 8 | import com.padeoe.njunet.connect.controller.ConnectManager; 9 | 10 | /** 11 | * Created by padeoe on 2016/5/16. 12 | * 该类表示后台自动登录成功后的处理,负责更新通知,发送广播更新主界面。该类的{@linkplain #updateView(MainActivity)}无法独立完成对界面的更新,而是生成其他的{@link ConnectResultHandle}对象 13 | */ 14 | public class BackgrReturnDataHandle implements ConnectResultHandle { 15 | String result; 16 | 17 | public BackgrReturnDataHandle(String result) { 18 | this.result = result; 19 | handleNotification(); 20 | } 21 | 22 | public void handleNotification() { 23 | ConnectManager.setStatus(ConnectManager.Status.ONLINE); 24 | StatusNotificationManager.showStatus(); 25 | } 26 | 27 | /** 28 | * MainActivity通过通知的形式接收到本类的实例,并将自己传进本实例的本方法进行更新界面 29 | * 30 | * @param activity 31 | */ 32 | @Override 33 | public void updateView(MainActivity activity) { 34 | getRealInfoHandle().updateView(activity); 35 | } 36 | 37 | @Override 38 | public int describeContents() { 39 | return 0; 40 | } 41 | 42 | @Override 43 | public void writeToParcel(Parcel dest, int flags) { 44 | dest.writeString(this.result); 45 | } 46 | 47 | public BackgrReturnDataHandle() { 48 | } 49 | 50 | protected BackgrReturnDataHandle(Parcel in) { 51 | this.result = in.readString(); 52 | } 53 | 54 | public static final Creator CREATOR = new Creator() { 55 | @Override 56 | public BackgrReturnDataHandle createFromParcel(Parcel source) { 57 | return new BackgrReturnDataHandle(source); 58 | } 59 | 60 | @Override 61 | public BackgrReturnDataHandle[] newArray(int size) { 62 | return new BackgrReturnDataHandle[size]; 63 | } 64 | }; 65 | 66 | /** 67 | * 用于获得具体状态的handle对象。 68 | * 69 | * @return 70 | */ 71 | private ConnectResultHandle getRealInfoHandle() { 72 | ReturnData returnData = ReturnData.getFromJson(result); 73 | return returnData == null ? new UnknownErrorHandle(result) : new ReturnDataHandle(returnData); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/njunet/connect/uihandler/ClientLimitHandle.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.njunet.connect.uihandler; 2 | 3 | import android.content.Context; 4 | import android.net.wifi.WifiManager; 5 | import android.os.Parcel; 6 | 7 | import com.padeoe.njunet.App; 8 | import com.padeoe.njunet.R; 9 | import com.padeoe.njunet.connect.MainActivity; 10 | import com.padeoe.njunet.connect.StatusNotificationManager; 11 | import com.padeoe.njunet.connect.controller.ConnectManager; 12 | 13 | /** 14 | * Created by padeoe on 2016/6/3. 15 | */ 16 | public class ClientLimitHandle implements ConnectResultHandle { 17 | @Override 18 | public void updateView(MainActivity activity) { 19 | WifiManager wifiManager = (WifiManager) App.getAppContext().getApplicationContext().getSystemService(Context.WIFI_SERVICE); 20 | activity.setNetInfo(App.getAppContext().getResources().getString(R.string.remote_online),wifiManager.getConnectionInfo().getSSID()); 21 | activity.hideProgress(); 22 | activity.updateViewStatus(activity.status, ConnectManager.getStatus()); 23 | activity.showOnMainActivity(App.getAppContext().getResources().getString(R.string.force_login_button)); 24 | } 25 | 26 | @Override 27 | public int describeContents() { 28 | return 0; 29 | } 30 | 31 | @Override 32 | public void writeToParcel(Parcel dest, int flags) { 33 | } 34 | 35 | public ClientLimitHandle() { 36 | ConnectManager.setStatus(ConnectManager.Status.REMOTE_ONLINE); 37 | StatusNotificationManager.showStatus(App.getAppContext().getResources().getString(R.string.remote_online)); 38 | } 39 | 40 | protected ClientLimitHandle(Parcel in) { 41 | } 42 | 43 | public static final Creator CREATOR = new Creator() { 44 | @Override 45 | public ClientLimitHandle createFromParcel(Parcel source) { 46 | return new ClientLimitHandle(source); 47 | } 48 | 49 | @Override 50 | public ClientLimitHandle[] newArray(int size) { 51 | return new ClientLimitHandle[size]; 52 | } 53 | }; 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/njunet/connect/uihandler/ConnectResultHandle.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.njunet.connect.uihandler; 2 | 3 | import android.os.Parcelable; 4 | 5 | import com.padeoe.njunet.connect.MainActivity; 6 | 7 | /** 8 | * Created by padeoe on 2016/5/17. 9 | */ 10 | public interface ConnectResultHandle extends Parcelable { 11 | void updateView(MainActivity activity); 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/njunet/connect/uihandler/ErrorHandle.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.njunet.connect.uihandler; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.Context; 5 | import android.net.wifi.WifiManager; 6 | import android.os.Build; 7 | import android.os.Parcel; 8 | 9 | import com.padeoe.njunet.App; 10 | import com.padeoe.njunet.R; 11 | import com.padeoe.njunet.connect.MainActivity; 12 | import com.padeoe.njunet.connect.controller.ConnectManager; 13 | 14 | /** 15 | * Created by padeoe on 2016/5/10. 16 | */ 17 | public class ErrorHandle implements ConnectResultHandle { 18 | String error; 19 | 20 | public ErrorHandle(String error) { 21 | this.error = error; 22 | ConnectManager.setStatus(ConnectManager.Status.OFFLINE); 23 | } 24 | 25 | 26 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 27 | @Override 28 | public void updateView(MainActivity mainActivity) { 29 | mainActivity.hideProgress(); 30 | mainActivity.showOnMainActivity(error); 31 | WifiManager wifiManager = (WifiManager) App.getAppContext().getApplicationContext().getSystemService(Context.WIFI_SERVICE); 32 | mainActivity.setNetInfo(App.getAppContext().getResources().getString(R.string.connect_error),wifiManager.getConnectionInfo().getSSID()); 33 | mainActivity.updateViewStatus(mainActivity.status,ConnectManager.getStatus()); 34 | } 35 | 36 | @Override 37 | public int describeContents() { 38 | return 0; 39 | } 40 | 41 | @Override 42 | public void writeToParcel(Parcel dest, int flags) { 43 | dest.writeString(this.error); 44 | } 45 | 46 | protected ErrorHandle(Parcel in) { 47 | this.error = in.readString(); 48 | } 49 | 50 | public static final Creator CREATOR = new Creator() { 51 | @Override 52 | public ErrorHandle createFromParcel(Parcel source) { 53 | return new ErrorHandle(source); 54 | } 55 | 56 | @Override 57 | public ErrorHandle[] newArray(int size) { 58 | return new ErrorHandle[size]; 59 | } 60 | }; 61 | } 62 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/njunet/connect/uihandler/GetOnlineTimeFailHandle.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.njunet.connect.uihandler; 2 | 3 | import android.os.Parcel; 4 | import android.util.Log; 5 | 6 | import com.padeoe.njunet.connect.MainActivity; 7 | import com.padeoe.njunet.connect.controller.UpdateInfo; 8 | import com.padeoe.njunet.util.MyObservable; 9 | 10 | /** 11 | * Created by padeoe on 2016/5/10. 12 | */ 13 | public class GetOnlineTimeFailHandle extends MyObservable implements ConnectResultHandle { 14 | private static int times; 15 | private static int maxTry = 10; 16 | 17 | public GetOnlineTimeFailHandle() { 18 | times++; 19 | } 20 | 21 | @Override 22 | public void updateView(MainActivity activity) { 23 | if (times < maxTry) { 24 | Log.d("尝试", "即将第" + times + "次获取时长"); 25 | UpdateInfo updateInfo = new UpdateInfo(); 26 | updateInfo.addObserver(activity); 27 | updateInfo.updateOnlineTime(); 28 | times++; 29 | } else { 30 | activity.hideProgress(); 31 | resetTimes(); 32 | notifyObservers(new ErrorHandle("获取时长失败")); 33 | Log.e("获取时长失败", "失败"); 34 | } 35 | } 36 | 37 | public static void resetTimes() { 38 | times = 0; 39 | } 40 | 41 | @Override 42 | public int describeContents() { 43 | return 0; 44 | } 45 | 46 | @Override 47 | public void writeToParcel(Parcel dest, int flags) { 48 | dest.writeInt(this.maxTry); 49 | } 50 | 51 | protected GetOnlineTimeFailHandle(Parcel in) { 52 | this.maxTry = in.readInt(); 53 | } 54 | 55 | public static final Creator CREATOR = new Creator() { 56 | @Override 57 | public GetOnlineTimeFailHandle createFromParcel(Parcel source) { 58 | return new GetOnlineTimeFailHandle(source); 59 | } 60 | 61 | @Override 62 | public GetOnlineTimeFailHandle[] newArray(int size) { 63 | return new GetOnlineTimeFailHandle[size]; 64 | } 65 | }; 66 | 67 | public static int getMaxTry() { 68 | return maxTry; 69 | } 70 | 71 | public static void setMaxTry(int maxTry) { 72 | GetOnlineTimeFailHandle.maxTry = maxTry; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/njunet/connect/uihandler/NoPasswordHandle.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.njunet.connect.uihandler; 2 | 3 | import android.content.Intent; 4 | import android.os.Parcel; 5 | 6 | import com.padeoe.njunet.connect.MainActivity; 7 | import com.padeoe.njunet.deploy.FirstSettingActivity; 8 | 9 | /** 10 | * Created by padeoe on 2016/5/30. 11 | */ 12 | public class NoPasswordHandle implements ConnectResultHandle { 13 | @Override 14 | public void updateView(MainActivity activity) { 15 | Intent intent = new Intent(); 16 | intent.setAction("com.padeoe.njunet.EDIT_ACCOUNT"); 17 | intent.setClass(activity, FirstSettingActivity.class); 18 | activity.startActivity(intent); 19 | } 20 | 21 | @Override 22 | public int describeContents() { 23 | return 0; 24 | } 25 | 26 | @Override 27 | public void writeToParcel(Parcel dest, int flags) { 28 | } 29 | 30 | public NoPasswordHandle() { 31 | } 32 | 33 | protected NoPasswordHandle(Parcel in) { 34 | } 35 | 36 | public static final Creator CREATOR = new Creator() { 37 | @Override 38 | public NoPasswordHandle createFromParcel(Parcel source) { 39 | return new NoPasswordHandle(source); 40 | } 41 | 42 | @Override 43 | public NoPasswordHandle[] newArray(int size) { 44 | return new NoPasswordHandle[size]; 45 | } 46 | }; 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/njunet/connect/uihandler/OfflineHandle.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.njunet.connect.uihandler; 2 | 3 | import android.content.Context; 4 | import android.net.wifi.WifiManager; 5 | import android.os.Parcel; 6 | import android.os.Parcelable; 7 | 8 | import com.padeoe.nicservice.njuwlan.object.portal.ReturnData; 9 | import com.padeoe.njunet.App; 10 | import com.padeoe.njunet.connect.MainActivity; 11 | import com.padeoe.njunet.connect.StatusNotificationManager; 12 | import com.padeoe.njunet.connect.controller.ConnectManager; 13 | import com.padeoe.njunet.util.MyAnimation; 14 | 15 | /** 16 | * Created by padeoe on 2016/5/10. 17 | */ 18 | public class OfflineHandle implements ConnectResultHandle { 19 | ReturnData returnData; 20 | 21 | public OfflineHandle(ReturnData returnData) { 22 | this.returnData = returnData; 23 | } 24 | 25 | @Override 26 | public void updateView(MainActivity mainActivity) { 27 | mainActivity.hideProgress(); 28 | mainActivity.setNetInfo("未登录",((WifiManager)App.getAppContext().getApplicationContext().getSystemService(Context.WIFI_SERVICE)).getConnectionInfo().getSSID()); 29 | MyAnimation.fadeInTextView(mainActivity.netinfo); 30 | ConnectManager.setStatus(ConnectManager.Status.OFFLINE); 31 | StatusNotificationManager.showStatus(); 32 | mainActivity.updateViewStatus(mainActivity.status, ConnectManager.getStatus()); 33 | mainActivity.showOnMainActivity(returnData.getReply_message()); 34 | } 35 | 36 | @Override 37 | public int describeContents() { 38 | return 0; 39 | } 40 | 41 | @Override 42 | public void writeToParcel(Parcel dest, int flags) { 43 | dest.writeParcelable(this.returnData, flags); 44 | } 45 | 46 | protected OfflineHandle(Parcel in) { 47 | this.returnData = in.readParcelable(ReturnData.class.getClassLoader()); 48 | } 49 | 50 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { 51 | @Override 52 | public OfflineHandle createFromParcel(Parcel source) { 53 | return new OfflineHandle(source); 54 | } 55 | 56 | @Override 57 | public OfflineHandle[] newArray(int size) { 58 | return new OfflineHandle[size]; 59 | } 60 | }; 61 | } 62 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/njunet/connect/uihandler/OnlineTimeHandle.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.njunet.connect.uihandler; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | import com.padeoe.njunet.connect.MainActivity; 7 | import com.padeoe.njunet.util.MyAnimation; 8 | 9 | /** 10 | * Created by padeoe on 2016/5/10. 11 | */ 12 | public class OnlineTimeHandle implements ConnectResultHandle { 13 | int second; 14 | 15 | public OnlineTimeHandle(int second) { 16 | this.second = second; 17 | } 18 | 19 | @Override 20 | public void updateView(MainActivity activity) { 21 | GetOnlineTimeFailHandle.resetTimes(); 22 | StringBuilder stringBuilder = new StringBuilder(); 23 | stringBuilder.append(second / 3600).append("小时").append(second % 3600 / 60).append("分钟"); 24 | activity.time.setText(stringBuilder.toString()); 25 | MyAnimation.fadeInTextView(activity.time); 26 | activity.hideProgress(); 27 | } 28 | 29 | @Override 30 | public int describeContents() { 31 | return 0; 32 | } 33 | 34 | @Override 35 | public void writeToParcel(Parcel dest, int flags) { 36 | dest.writeInt(this.second); 37 | } 38 | 39 | protected OnlineTimeHandle(Parcel in) { 40 | this.second = in.readInt(); 41 | } 42 | 43 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { 44 | @Override 45 | public OnlineTimeHandle createFromParcel(Parcel source) { 46 | return new OnlineTimeHandle(source); 47 | } 48 | 49 | @Override 50 | public OnlineTimeHandle[] newArray(int size) { 51 | return new OnlineTimeHandle[size]; 52 | } 53 | }; 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/njunet/connect/uihandler/Reachable.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.njunet.connect.uihandler; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | import com.padeoe.njunet.connect.MainActivity; 7 | 8 | /** 9 | * Created by padeoe on 2016/5/18. 10 | */ 11 | public class Reachable implements ConnectResultHandle { 12 | int code; 13 | 14 | public int getCode() { 15 | return code; 16 | } 17 | 18 | public Reachable(int code) { 19 | this.code = code; 20 | } 21 | 22 | @Override 23 | public void updateView(MainActivity activity) { 24 | activity.showOnMainActivity("code=" + code); 25 | } 26 | 27 | @Override 28 | public int describeContents() { 29 | return 0; 30 | } 31 | 32 | @Override 33 | public void writeToParcel(Parcel dest, int flags) { 34 | dest.writeInt(this.code); 35 | } 36 | 37 | protected Reachable(Parcel in) { 38 | this.code = in.readInt(); 39 | } 40 | 41 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { 42 | @Override 43 | public Reachable createFromParcel(Parcel source) { 44 | return new Reachable(source); 45 | } 46 | 47 | @Override 48 | public Reachable[] newArray(int size) { 49 | return new Reachable[size]; 50 | } 51 | }; 52 | 53 | public boolean isInternetAvailable() { 54 | return code == 204; 55 | } 56 | 57 | public boolean isCaptital() { 58 | return code != 204 && code >= 200 && code <= 399; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/njunet/connect/uihandler/ReturnDataHandle.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.njunet.connect.uihandler; 2 | 3 | import android.content.Context; 4 | import android.net.wifi.WifiManager; 5 | import android.os.Parcel; 6 | 7 | import com.padeoe.nicservice.njuwlan.object.portal.ReturnData; 8 | import com.padeoe.nicservice.njuwlan.object.portal.UserInfo; 9 | import com.padeoe.njunet.App; 10 | import com.padeoe.njunet.connect.MainActivity; 11 | import com.padeoe.njunet.connect.StatusNotificationManager; 12 | import com.padeoe.njunet.connect.controller.ConnectManager; 13 | import com.padeoe.njunet.connect.controller.UpdateInfo; 14 | import com.padeoe.njunet.util.MyAnimation; 15 | import com.padeoe.utils.ConvertionUtils; 16 | 17 | /** 18 | * Created by padeoe on 2016/5/10. 19 | */ 20 | public class ReturnDataHandle implements ConnectResultHandle { 21 | ReturnData returnData; 22 | 23 | public ReturnDataHandle(ReturnData returnData) { 24 | this.returnData = returnData; 25 | handleNotification(); 26 | } 27 | 28 | public void handleNotification() { 29 | ConnectManager.setStatus(ConnectManager.Status.ONLINE); 30 | StatusNotificationManager.showStatus(); 31 | } 32 | 33 | @Override 34 | public void updateView(MainActivity mainActivity) { 35 | if (returnData != null) { 36 | UserInfo userinfo = returnData.getUserInfo(); 37 | if (userinfo != null) { 38 | // mainActivity.username.setText(userinfo.getUsername() + "(" + userinfo.getFullname() + ")"); 39 | WifiManager wifiManager = (WifiManager) App.getAppContext().getApplicationContext().getSystemService(Context.WIFI_SERVICE); 40 | mainActivity.setNetInfo(userinfo,wifiManager.getConnectionInfo().getSSID()); 41 | MyAnimation.fadeInTextView(mainActivity.netinfo); 42 | // mainActivity.user_detail.setVisibility(View.VISIBLE); 43 | mainActivity.amount.setText(Double.valueOf(userinfo.getBalance()) / 100 + "元"); 44 | mainActivity.location.setText(userinfo.getArea_name()); 45 | mainActivity.ip.setText(ConvertionUtils.getIP(userinfo.getUseripv4())); 46 | MyAnimation.fadeInTextView(mainActivity.amount); 47 | MyAnimation.fadeInTextView(mainActivity.location); 48 | MyAnimation.fadeInTextView(mainActivity.ip); 49 | UpdateInfo updateInfo = new UpdateInfo(); 50 | updateInfo.addObserver(mainActivity); 51 | updateInfo.updateOnlineTime(); 52 | } else { 53 | //mainActivity.hideProgress(); 54 | //ConnectManager.setStatus(ConnectManager.Status.OFFLINE); 55 | new OfflineHandle(returnData).updateView(mainActivity); 56 | } 57 | mainActivity.updateViewStatus(mainActivity.status, ConnectManager.getStatus()); 58 | } 59 | } 60 | 61 | @Override 62 | public int describeContents() { 63 | return 0; 64 | } 65 | 66 | @Override 67 | public void writeToParcel(Parcel dest, int flags) { 68 | dest.writeParcelable(this.returnData, flags); 69 | } 70 | 71 | protected ReturnDataHandle(Parcel in) { 72 | this.returnData = in.readParcelable(ReturnData.class.getClassLoader()); 73 | } 74 | 75 | public static final Creator CREATOR = new Creator() { 76 | @Override 77 | public ReturnDataHandle createFromParcel(Parcel source) { 78 | return new ReturnDataHandle(source); 79 | } 80 | 81 | @Override 82 | public ReturnDataHandle[] newArray(int size) { 83 | return new ReturnDataHandle[size]; 84 | } 85 | }; 86 | } 87 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/njunet/connect/uihandler/UnknownErrorHandle.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.njunet.connect.uihandler; 2 | 3 | import android.os.Parcel; 4 | 5 | import com.padeoe.njunet.connect.MainActivity; 6 | 7 | /** 8 | * Created by padeoe on 2016/5/19. 9 | */ 10 | public class UnknownErrorHandle implements ConnectResultHandle { 11 | String error; 12 | 13 | public UnknownErrorHandle(String error) { 14 | this.error = error; 15 | } 16 | 17 | @Override 18 | public void updateView(MainActivity activity) { 19 | activity.hideProgress(); 20 | activity.showOnMainActivity(error); 21 | } 22 | 23 | @Override 24 | public int describeContents() { 25 | return 0; 26 | } 27 | 28 | @Override 29 | public void writeToParcel(Parcel dest, int flags) { 30 | dest.writeString(this.error); 31 | } 32 | 33 | public UnknownErrorHandle() { 34 | } 35 | 36 | protected UnknownErrorHandle(Parcel in) { 37 | this.error = in.readString(); 38 | } 39 | 40 | public static final Creator CREATOR = new Creator() { 41 | @Override 42 | public UnknownErrorHandle createFromParcel(Parcel source) { 43 | return new UnknownErrorHandle(source); 44 | } 45 | 46 | @Override 47 | public UnknownErrorHandle[] newArray(int size) { 48 | return new UnknownErrorHandle[size]; 49 | } 50 | }; 51 | } 52 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/njunet/connect/uihandler/UnknownNetHandle.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.njunet.connect.uihandler; 2 | 3 | import android.os.Parcel; 4 | 5 | import com.padeoe.njunet.App; 6 | import com.padeoe.njunet.R; 7 | import com.padeoe.njunet.connect.MainActivity; 8 | import com.padeoe.njunet.connect.controller.ConnectManager; 9 | import com.padeoe.njunet.util.MyAnimation; 10 | 11 | /** 12 | * Created by padeoe on 2016/5/19. 13 | */ 14 | public class UnknownNetHandle implements ConnectResultHandle { 15 | String SSID; 16 | 17 | public UnknownNetHandle(String SSID) { 18 | this.SSID = SSID; 19 | } 20 | 21 | @Override 22 | public void updateView(MainActivity activity) { 23 | activity.hideProgress(); 24 | // activity.user_detail.setVisibility(View.VISIBLE); 25 | activity.setNetInfo(App.isInPortalWiFiSet(SSID) || App.isInSuspiciousWiFiSSIDSet(SSID) ? 26 | App.getAppContext().getResources().getString(R.string.NJUWLAN) : App.getAppContext().getResources().getString(R.string.Unknown_WLAN), SSID); 27 | activity.updateViewStatus(activity.status, ConnectManager.getStatus()); 28 | MyAnimation.fadeInTextView(activity.status_internet); 29 | activity.showOnMainActivity(activity.getResources().getString(R.string.connect_fail)); 30 | } 31 | 32 | @Override 33 | public int describeContents() { 34 | return 0; 35 | } 36 | 37 | @Override 38 | public void writeToParcel(Parcel dest, int flags) { 39 | dest.writeString(this.SSID); 40 | } 41 | 42 | protected UnknownNetHandle(Parcel in) { 43 | this.SSID = in.readString(); 44 | } 45 | 46 | public static final Creator CREATOR = new Creator() { 47 | @Override 48 | public UnknownNetHandle createFromParcel(Parcel source) { 49 | return new UnknownNetHandle(source); 50 | } 51 | 52 | @Override 53 | public UnknownNetHandle[] newArray(int size) { 54 | return new UnknownNetHandle[size]; 55 | } 56 | }; 57 | } 58 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/njunet/connect/uihandler/WifiAvailableHandle.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.njunet.connect.uihandler; 2 | 3 | import android.os.Parcel; 4 | 5 | import com.padeoe.njunet.App; 6 | import com.padeoe.njunet.R; 7 | import com.padeoe.njunet.connect.MainActivity; 8 | 9 | /** 10 | * Created by padeoe on 2016/5/23. 11 | */ 12 | public class WifiAvailableHandle implements ConnectResultHandle { 13 | String ssid; 14 | 15 | @Override 16 | public void updateView(MainActivity activity) { 17 | activity.setNetInfo(App.isInPortalWiFiSet(ssid) || App.isInSuspiciousWiFiSSIDSet(ssid) ? 18 | App.getAppContext().getResources().getString(R.string.NJUWLAN) : App.getAppContext().getResources().getString(R.string.Unknown_WLAN), ssid); 19 | } 20 | 21 | @Override 22 | public int describeContents() { 23 | return 0; 24 | } 25 | 26 | @Override 27 | public void writeToParcel(Parcel dest, int flags) { 28 | dest.writeString(this.ssid); 29 | } 30 | 31 | public WifiAvailableHandle(String ssid) { 32 | this.ssid = ssid; 33 | } 34 | 35 | protected WifiAvailableHandle(Parcel in) { 36 | this.ssid = in.readString(); 37 | } 38 | 39 | public static final Creator CREATOR = new Creator() { 40 | @Override 41 | public WifiAvailableHandle createFromParcel(Parcel source) { 42 | return new WifiAvailableHandle(source); 43 | } 44 | 45 | @Override 46 | public WifiAvailableHandle[] newArray(int size) { 47 | return new WifiAvailableHandle[size]; 48 | } 49 | }; 50 | } 51 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/njunet/connect/uihandler/WifiLostHandle.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.njunet.connect.uihandler; 2 | 3 | import android.os.Parcel; 4 | 5 | import com.padeoe.njunet.connect.MainActivity; 6 | import com.padeoe.njunet.connect.controller.ConnectManager; 7 | 8 | /** 9 | * Created by padeoe on 2016/5/18. 10 | */ 11 | public class WifiLostHandle implements ConnectResultHandle { 12 | 13 | @Override 14 | public void updateView(MainActivity activity) { 15 | activity.hideProgress(); 16 | activity.setNetInfo("未连接WLAN",null); 17 | // activity.user_detail.setVisibility(View.INVISIBLE); 18 | ConnectManager.setStatus(ConnectManager.Status.WIFI_LOST); 19 | activity.updateViewStatus(activity.status, ConnectManager.getStatus()); 20 | activity.showOnMainActivity("未连接wifi"); 21 | } 22 | 23 | @Override 24 | public int describeContents() { 25 | return 0; 26 | } 27 | 28 | @Override 29 | public void writeToParcel(Parcel dest, int flags) { 30 | } 31 | 32 | public WifiLostHandle() { 33 | } 34 | 35 | protected WifiLostHandle(Parcel in) { 36 | } 37 | 38 | public static final Creator CREATOR = new Creator() { 39 | @Override 40 | public WifiLostHandle createFromParcel(Parcel source) { 41 | return new WifiLostHandle(source); 42 | } 43 | 44 | @Override 45 | public WifiLostHandle[] newArray(int size) { 46 | return new WifiLostHandle[size]; 47 | } 48 | }; 49 | } 50 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/njunet/deploy/AccountInputFragment.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.njunet.deploy; 2 | 3 | import android.content.Intent; 4 | import android.content.SharedPreferences; 5 | import android.net.Uri; 6 | import android.os.Bundle; 7 | import android.support.v4.app.Fragment; 8 | import android.support.v4.content.LocalBroadcastManager; 9 | import android.text.Editable; 10 | import android.text.TextWatcher; 11 | import android.view.KeyEvent; 12 | import android.view.LayoutInflater; 13 | import android.view.View; 14 | import android.view.ViewGroup; 15 | import android.view.inputmethod.EditorInfo; 16 | import android.widget.Button; 17 | import android.widget.EditText; 18 | import android.widget.TextView; 19 | 20 | import com.padeoe.njunet.R; 21 | import com.padeoe.njunet.connect.controller.ConnectService; 22 | import com.padeoe.njunet.util.PrefFileManager; 23 | 24 | public class AccountInputFragment extends DeployFragment { 25 | EditText usernameEdit; 26 | EditText passwordEdit; 27 | View view; 28 | 29 | public AccountInputFragment() { 30 | // Required empty public constructor 31 | } 32 | 33 | @Override 34 | public void onCreate(Bundle savedInstanceState) { 35 | super.onCreate(savedInstanceState); 36 | } 37 | 38 | @Override 39 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 40 | Bundle savedInstanceState) { 41 | Button button = (Button) (getActivity().findViewById(R.id.nextStepButton)); 42 | button.setText(getNextStepButtonText()); 43 | view = inflater.inflate(R.layout.fragment_account_input, container, false); 44 | usernameEdit = ((EditText) (view.findViewById(R.id.input_username))); 45 | passwordEdit = ((EditText) (view.findViewById(R.id.input_password))); 46 | usernameEdit.setText(PrefFileManager.getAccountPref().getString("username", "")); 47 | TextWatcher textWatcher = new TextWatcher() { 48 | 49 | @Override 50 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { 51 | 52 | } 53 | 54 | @Override 55 | public void onTextChanged(CharSequence s, int start, int before, int count) { 56 | 57 | } 58 | 59 | @Override 60 | public void afterTextChanged(Editable s) { 61 | getActivity().findViewById(R.id.nextStepButton).setEnabled(hasInput(usernameEdit) && hasInput(passwordEdit)); 62 | } 63 | }; 64 | usernameEdit.addTextChangedListener(textWatcher); 65 | passwordEdit.addTextChangedListener(textWatcher); 66 | 67 | passwordEdit.setOnEditorActionListener(new TextView.OnEditorActionListener() { 68 | @Override 69 | public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 70 | boolean handled = false; 71 | if (actionId == EditorInfo.IME_ACTION_NEXT) { 72 | if (hasInput(passwordEdit)) { 73 | ((FirstSettingActivity) getActivity()).onNextStepButtonClicked(getActivity().findViewById(R.id.nextStepButton)); 74 | } 75 | handled = true; 76 | } 77 | return handled; 78 | } 79 | }); 80 | return view; 81 | } 82 | 83 | 84 | @Override 85 | public void handle(View view) { 86 | ConnectService.setUsername(getUserName()); 87 | ConnectService.setPassword(getPassword()); 88 | view.setEnabled(true); 89 | } 90 | 91 | public String getUserName() { 92 | return ((TextView) (view.findViewById(R.id.input_username))).getText().toString(); 93 | } 94 | 95 | public String getPassword() { 96 | return ((TextView) (view.findViewById(R.id.input_password))).getText().toString(); 97 | } 98 | 99 | 100 | public boolean hasInput(EditText editText) { 101 | return editText.getText().toString().length() > 0; 102 | } 103 | 104 | public String getNextStepButtonText() { 105 | return getString(R.string.nextStep); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/njunet/deploy/AccountTypeFragment.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.njunet.deploy; 2 | 3 | import android.graphics.Color; 4 | import android.net.Uri; 5 | import android.os.Bundle; 6 | import android.support.v4.app.Fragment; 7 | import android.text.SpannableString; 8 | import android.text.Spanned; 9 | import android.text.style.ForegroundColorSpan; 10 | import android.util.Log; 11 | import android.view.LayoutInflater; 12 | import android.view.View; 13 | import android.view.ViewGroup; 14 | import android.widget.Button; 15 | import android.widget.RadioButton; 16 | import android.widget.RadioGroup; 17 | 18 | import com.padeoe.njunet.R; 19 | 20 | public class AccountTypeFragment extends DeployFragment { 21 | @Override 22 | public void onCreate(Bundle savedInstanceState) { 23 | super.onCreate(savedInstanceState); 24 | } 25 | 26 | @Override 27 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 28 | Bundle savedInstanceState) { 29 | Button button = (Button) (getActivity().findViewById(R.id.nextStepButton)); 30 | button.setText(getNextStepButtonText()); 31 | // Inflate the layout for this fragment 32 | View view = inflater.inflate(R.layout.fragment_account_type, container, false); 33 | RadioGroup accountKind = (RadioGroup) view.findViewById(R.id.AccountKindRadio); 34 | accountKind.setOnCheckedChangeListener( 35 | new RadioGroup.OnCheckedChangeListener() { 36 | @Override 37 | public void onCheckedChanged(RadioGroup group, int checkedId) { 38 | Log.d("被点击", "点击"); 39 | getActivity().findViewById(R.id.nextStepButton).setEnabled(true); 40 | /* NextStepEnable nextStepEnable=new NextStepEnable(); 41 | nextStepEnable.addObserver(); 42 | nextStepEnable.enableNextStep();*/ 43 | } 44 | } 45 | ); 46 | RadioButton portalradioButton = (RadioButton) view.findViewById(R.id.radio_pnju); 47 | RadioButton oaRadioButton = (RadioButton) view.findViewById(R.id.radio_oa); 48 | setRadioButtonTextColor(portalradioButton); 49 | setRadioButtonTextColor(oaRadioButton); 50 | return view; 51 | } 52 | 53 | @Override 54 | public void handle(View view) { 55 | view.setEnabled(false); 56 | } 57 | 58 | public String getNextStepButtonText() { 59 | return getString(R.string.nextStep); 60 | } 61 | 62 | private void setRadioButtonTextColor(RadioButton radioButton) { 63 | String pnjuRadioText = radioButton.getText().toString(); 64 | SpannableString spannableString = new SpannableString(pnjuRadioText); 65 | int index_newline = pnjuRadioText.indexOf("\n"); 66 | if (index_newline != -1) { 67 | spannableString.setSpan(new ForegroundColorSpan(Color.GRAY), index_newline, pnjuRadioText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); 68 | radioButton.setText(spannableString); 69 | } else { 70 | Log.e("内部错误", "first setting fragment中radio button文字不包含换行符"); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/njunet/deploy/DeployFragment.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.njunet.deploy; 2 | 3 | import android.support.v4.app.Fragment; 4 | import android.view.View; 5 | 6 | /** 7 | * Created by padeoe on 2016/5/27. 8 | */ 9 | public abstract class DeployFragment extends Fragment { 10 | public abstract void handle(View view); 11 | } 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/njunet/deploy/SettingFinishFragment.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.njunet.deploy; 2 | 3 | import android.net.Uri; 4 | import android.os.Bundle; 5 | import android.support.v4.app.Fragment; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.Button; 10 | 11 | import com.padeoe.njunet.R; 12 | import com.padeoe.njunet.util.PrefFileManager; 13 | 14 | 15 | public class SettingFinishFragment extends DeployFragment { 16 | 17 | @Override 18 | public void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | } 21 | 22 | @Override 23 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 24 | Bundle savedInstanceState) { 25 | Button button = (Button) (getActivity().findViewById(R.id.nextStepButton)); 26 | button.setText(getNextStepButtonText()); 27 | // Inflate the layout for this fragment 28 | return inflater.inflate(R.layout.fragment_setting_finish, container, false); 29 | } 30 | 31 | 32 | @Override 33 | public void handle(View view) { 34 | PrefFileManager.getAccountPref().edit().putBoolean("isFirstInstall",false).apply(); 35 | } 36 | 37 | /** 38 | * This interface must be implemented by activities that contain this 39 | * fragment to allow an interaction in this fragment to be communicated 40 | * to the activity and potentially other fragments contained in that 41 | * activity. 42 | *

43 | * See the Android Training lesson Communicating with Other Fragments for more information. 46 | */ 47 | public interface OnFragmentInteractionListener { 48 | // TODO: Update argument type and name 49 | void onFragmentInteraction(Uri uri); 50 | } 51 | 52 | public String getNextStepButtonText() { 53 | return getString(R.string.finish); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/njunet/settings/AboutDialogFragment.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.njunet.settings; 2 | 3 | import android.app.DialogFragment; 4 | 5 | import android.app.AlertDialog; 6 | import android.app.Dialog; 7 | import android.content.DialogInterface; 8 | import android.content.Intent; 9 | import android.content.pm.PackageManager; 10 | import android.os.Bundle; 11 | import android.view.LayoutInflater; 12 | import android.view.View; 13 | import android.widget.TextView; 14 | 15 | import com.padeoe.njunet.R; 16 | 17 | /** 18 | * Created by padeoe on 2016/6/1. 19 | */ 20 | public class AboutDialogFragment extends DialogFragment { 21 | @Override 22 | public Dialog onCreateDialog(Bundle savedInstanceState) { 23 | AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 24 | LayoutInflater inflater = getActivity().getLayoutInflater(); 25 | View view = inflater.inflate(R.layout.dialog_about, null); 26 | builder.setView(view) 27 | .setPositiveButton(R.string.feedback, new DialogInterface.OnClickListener() { 28 | @Override 29 | public void onClick(DialogInterface dialog, int id) { 30 | //打开用户邮件App 31 | final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 32 | emailIntent.setType("plain/text"); 33 | emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{(String) getResources().getText(R.string.author_email)}); 34 | emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, getResources().getText(R.string.app_name) + (String) getResources().getText(R.string.feedback)); 35 | getActivity().startActivity(Intent.createChooser(emailIntent, getResources().getText(R.string.send_email))); 36 | } 37 | }); 38 | TextView versionTextView = (TextView) view.findViewById(R.id.version); 39 | try { 40 | String versionName = this.getActivity().getPackageManager() 41 | .getPackageInfo(this.getActivity().getPackageName(), 0).versionName; 42 | versionTextView.setText(getResources().getText(R.string.version) + versionName); 43 | } catch (PackageManager.NameNotFoundException e) { 44 | 45 | } 46 | return builder.create(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/njunet/settings/AppCompatPreferenceActivity.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.njunet.settings; 2 | 3 | import android.content.res.Configuration; 4 | import android.os.Bundle; 5 | import android.preference.PreferenceActivity; 6 | import android.support.annotation.LayoutRes; 7 | import android.support.annotation.Nullable; 8 | import android.support.v7.app.ActionBar; 9 | import android.support.v7.app.AppCompatDelegate; 10 | import android.support.v7.widget.Toolbar; 11 | import android.view.MenuInflater; 12 | import android.view.View; 13 | import android.view.ViewGroup; 14 | 15 | /** 16 | * A {@link PreferenceActivity} which implements and proxies the necessary calls 17 | * to be used with AppCompat. 18 | */ 19 | public abstract class AppCompatPreferenceActivity extends PreferenceActivity { 20 | 21 | private AppCompatDelegate mDelegate; 22 | 23 | @Override 24 | protected void onCreate(Bundle savedInstanceState) { 25 | getDelegate().installViewFactory(); 26 | getDelegate().onCreate(savedInstanceState); 27 | super.onCreate(savedInstanceState); 28 | } 29 | 30 | @Override 31 | protected void onPostCreate(Bundle savedInstanceState) { 32 | super.onPostCreate(savedInstanceState); 33 | getDelegate().onPostCreate(savedInstanceState); 34 | } 35 | 36 | public ActionBar getSupportActionBar() { 37 | return getDelegate().getSupportActionBar(); 38 | } 39 | 40 | public void setSupportActionBar(@Nullable Toolbar toolbar) { 41 | getDelegate().setSupportActionBar(toolbar); 42 | } 43 | 44 | @Override 45 | public MenuInflater getMenuInflater() { 46 | return getDelegate().getMenuInflater(); 47 | } 48 | 49 | @Override 50 | public void setContentView(@LayoutRes int layoutResID) { 51 | getDelegate().setContentView(layoutResID); 52 | } 53 | 54 | @Override 55 | public void setContentView(View view) { 56 | getDelegate().setContentView(view); 57 | } 58 | 59 | @Override 60 | public void setContentView(View view, ViewGroup.LayoutParams params) { 61 | getDelegate().setContentView(view, params); 62 | } 63 | 64 | @Override 65 | public void addContentView(View view, ViewGroup.LayoutParams params) { 66 | getDelegate().addContentView(view, params); 67 | } 68 | 69 | @Override 70 | protected void onPostResume() { 71 | super.onPostResume(); 72 | getDelegate().onPostResume(); 73 | } 74 | 75 | @Override 76 | protected void onTitleChanged(CharSequence title, int color) { 77 | super.onTitleChanged(title, color); 78 | getDelegate().setTitle(title); 79 | } 80 | 81 | @Override 82 | public void onConfigurationChanged(Configuration newConfig) { 83 | super.onConfigurationChanged(newConfig); 84 | getDelegate().onConfigurationChanged(newConfig); 85 | } 86 | 87 | @Override 88 | protected void onStop() { 89 | super.onStop(); 90 | getDelegate().onStop(); 91 | } 92 | 93 | @Override 94 | protected void onDestroy() { 95 | super.onDestroy(); 96 | getDelegate().onDestroy(); 97 | } 98 | 99 | public void invalidateOptionsMenu() { 100 | getDelegate().invalidateOptionsMenu(); 101 | } 102 | 103 | private AppCompatDelegate getDelegate() { 104 | if (mDelegate == null) { 105 | mDelegate = AppCompatDelegate.create(this, null); 106 | } 107 | return mDelegate; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/njunet/util/MyAnimation.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.njunet.util; 2 | 3 | import android.animation.Animator; 4 | import android.animation.AnimatorListenerAdapter; 5 | import android.animation.AnimatorSet; 6 | import android.animation.ObjectAnimator; 7 | import android.graphics.drawable.ColorDrawable; 8 | import android.graphics.drawable.TransitionDrawable; 9 | import android.os.Build; 10 | import android.view.View; 11 | import android.view.animation.AlphaAnimation; 12 | import android.widget.TextView; 13 | 14 | /** 15 | * Created by padeoe on 2016/4/26. 16 | */ 17 | public class MyAnimation { 18 | public static void flip(final View front, final View back, final int duration) { 19 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { 20 | AnimatorSet set = new AnimatorSet(); 21 | set.playSequentially( 22 | ObjectAnimator.ofFloat(front, "rotationY", 90).setDuration(duration / 2), 23 | ObjectAnimator.ofInt(front, "visibility", View.GONE).setDuration(0), 24 | ObjectAnimator.ofFloat(back, "rotationY", -90).setDuration(0), 25 | ObjectAnimator.ofInt(back, "visibility", View.VISIBLE).setDuration(0), 26 | ObjectAnimator.ofFloat(back, "rotationY", 0).setDuration(duration / 2) 27 | ); 28 | set.start(); 29 | } else { 30 | front.animate().rotationY(90).setDuration(duration / 2).setListener(new AnimatorListenerAdapter() { 31 | @Override 32 | public void onAnimationEnd(Animator animation) { 33 | front.setVisibility(View.GONE); 34 | back.setRotationY(-90); 35 | back.setVisibility(View.VISIBLE); 36 | back.animate().rotationY(0).setDuration(duration / 2).setListener(null); 37 | } 38 | }); 39 | } 40 | } 41 | 42 | public static void fadeInTextView(TextView textView) { 43 | AlphaAnimation fadeIn = new AlphaAnimation(0.0f, 1.0f); 44 | textView.startAnimation(fadeIn); 45 | fadeIn.setDuration(1000); 46 | fadeIn.setFillAfter(true); 47 | } 48 | 49 | public static void updateBackground(View view, int initColor, int endColor, int duration) { 50 | ColorDrawable[] color = {new ColorDrawable(initColor), new ColorDrawable(endColor)}; 51 | TransitionDrawable trans = new TransitionDrawable(color); 52 | view.setBackgroundDrawable(trans); 53 | trans.startTransition(duration); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/njunet/util/MyObserver.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.njunet.util; 2 | 3 | /** 4 | * Created by padeoe on 2016/5/10. 5 | */ 6 | public interface MyObserver { 7 | void update(MyObservable myObservable, T data); 8 | } 9 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/njunet/util/NetworkTest.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.njunet.util; 2 | 3 | import java.net.HttpURLConnection; 4 | import java.net.URL; 5 | 6 | /** 7 | * Created by padeoe on 2016/5/18. 8 | */ 9 | 10 | public class NetworkTest { 11 | public static int testNetwork(String URL) { 12 | HttpURLConnection urlConnection = null; 13 | try { 14 | java.net.URL url = new URL(URL); 15 | urlConnection = (HttpURLConnection) url 16 | .openConnection(); 17 | urlConnection.setRequestMethod("GET"); 18 | urlConnection.setUseCaches(false); 19 | urlConnection.setDoOutput(false); 20 | urlConnection.setInstanceFollowRedirects(false); 21 | urlConnection.setUseCaches(false); 22 | urlConnection.getInputStream(); 23 | urlConnection.setConnectTimeout(2000); 24 | urlConnection.setReadTimeout(2000); 25 | int httpResponseCode = urlConnection.getResponseCode(); 26 | if (httpResponseCode == 200 && urlConnection.getContentLength() == 0) { 27 | httpResponseCode = 204; 28 | } 29 | return httpResponseCode; 30 | } catch (Exception e) { 31 | return -1; 32 | } finally { 33 | if (urlConnection != null) { 34 | urlConnection.disconnect(); 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/njunet/util/PrefFileManager.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.njunet.util; 2 | 3 | import android.content.SharedPreferences; 4 | import android.util.Log; 5 | 6 | import com.padeoe.njunet.App; 7 | 8 | /** 9 | * Created by padeoe on 2016/4/21. 10 | */ 11 | public class PrefFileManager { 12 | public static SharedPreferences getAccountPref() { 13 | return App.context.getSharedPreferences("DataFile", 0); 14 | } 15 | 16 | public static SharedPreferences getWiFiPref() { 17 | return App.context.getSharedPreferences("WiFiSSID", 0); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/njunet/util/ResultUtils.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.njunet.util; 2 | 3 | import com.padeoe.nicservice.njuwlan.object.portal.ReturnData; 4 | import com.padeoe.njunet.App; 5 | import com.padeoe.njunet.R; 6 | 7 | /** 8 | * Created by padeoe on 2015/9/17. 9 | */ 10 | public class ResultUtils { 11 | public static String getLoginResult(String connectResult, boolean isLogin) { 12 | if (connectResult == null) { 13 | return App.context.getResources().getString(R.string.unknownfault); 14 | } 15 | ReturnData returnData; 16 | try { 17 | returnData = ReturnData.getFromJson(connectResult); 18 | } catch (Exception e) { 19 | return connectResult; 20 | } 21 | if (returnData == null) { 22 | return connectResult; 23 | } 24 | if (isLogin & returnData.getUserInfo() != null) { 25 | return returnData.getUserInfo().getFullname() + returnData.getUserInfo().getUsername() + returnData.getReply_message(); 26 | } 27 | if (isLogin & returnData.getUserInfo() == null) { 28 | return returnData.getReply_message(); 29 | } 30 | if (!isLogin) { 31 | return returnData.getReply_message(); 32 | } 33 | return connectResult; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/oa/LoginService.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.oa; 2 | 3 | import java.io.IOException; 4 | import java.io.OutputStream; 5 | import java.io.UnsupportedEncodingException; 6 | import java.net.BindException; 7 | import java.net.HttpURLConnection; 8 | import java.net.MalformedURLException; 9 | import java.net.NoRouteToHostException; 10 | import java.net.ProtocolException; 11 | import java.net.URL; 12 | import java.net.UnknownHostException; 13 | import java.util.Map; 14 | 15 | /** 16 | * Created by padeoe on 2016/4/17. 17 | */ 18 | public class LoginService { 19 | public static boolean checkPassword(String username,String password){ 20 | String data0="encoded=false&goto=&gotoOnFail=&IDToken0=&loginLT=4dbd65e0-d0b5-4bbc-9e12-8f93132c7f3f&IDButton=Submit&username="+username+"&password="+password+"&gx_charset=UTF-8"; 21 | int returnCode=getRuturnCode("POST",data0,"http://mids.nju.edu.cn/_ids_mobile/webLogin20_2",null,"UTF-8",1000); 22 | return returnCode==200; 23 | } 24 | 25 | public static int getRuturnCode(String action,String postData,String URL,Map requestProperty,String inputEncoding,int timeout){ 26 | try { 27 | byte[] postAsBytes=new byte[]{}; 28 | if(postData!=null){ 29 | postAsBytes= postData.getBytes(inputEncoding); 30 | } 31 | java.net.URL url = new URL(URL); 32 | HttpURLConnection connection = (HttpURLConnection) url 33 | .openConnection(); 34 | connection.setConnectTimeout(timeout); 35 | connection.setDoOutput(true); 36 | connection.setRequestMethod(action); 37 | connection.setUseCaches(false); 38 | if(requestProperty!=null){ 39 | for(Map.Entry entry : requestProperty.entrySet()) { 40 | connection.setRequestProperty(entry.getKey(), entry.getValue()); 41 | } 42 | } 43 | connection.setRequestProperty("Content-Length", String.valueOf(postAsBytes.length)); 44 | 45 | OutputStream outputStream = null; 46 | try { 47 | outputStream = connection.getOutputStream(); 48 | outputStream.write(postAsBytes); 49 | } finally { 50 | if (outputStream != null) { 51 | outputStream.close(); 52 | } 53 | } 54 | connection.connect(); 55 | int code=connection.getResponseCode(); 56 | connection.disconnect(); 57 | return code; 58 | } catch (UnsupportedEncodingException e) { 59 | System.out.println(e); 60 | return -1; 61 | } catch (MalformedURLException malformedURLException) { 62 | System.out.println(malformedURLException); 63 | return -2; 64 | } catch (ProtocolException protocolException) { 65 | System.out.println(protocolException); 66 | return -3; 67 | }catch(NoRouteToHostException noroute){ 68 | return -7; 69 | } 70 | catch (BindException ss){ 71 | return -6; 72 | } 73 | catch (UnknownHostException sss){ 74 | return -5; 75 | } 76 | catch (IOException ioException) { 77 | System.out.println(ioException); 78 | return -4; 79 | } 80 | } 81 | 82 | 83 | 84 | } 85 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/service/DictService.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.service; 2 | 3 | import com.padeoe.utils.network.MyHttpRequest; 4 | 5 | import java.io.IOException; 6 | 7 | /** 8 | * Created by padeoe on 2015/12/13. 9 | */ 10 | public class DictService { 11 | /** 12 | * 查询英语单词释义 13 | * @param word 英语单词 14 | * @return 单词解释的html页面 15 | */ 16 | public static String lookUp(String word) throws IOException { 17 | return MyHttpRequest.post("word="+word,"http://bbs.nju.edu.cn/bbsdict?type=1",null,"UTF-8","GBK",500); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/utils/ConvertionUtils.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.utils; 2 | 3 | /** 4 | * Created by padeoe on 2016/4/22. 5 | */ 6 | public class ConvertionUtils { 7 | public static String getIP(String ip) { 8 | StringBuilder stringBuilder = new StringBuilder(); 9 | int intip=(int)Long.parseLong(ip); 10 | stringBuilder 11 | .append((intip >> 24) & 0xFF).append('.') 12 | .append((intip >> 16) & 0xFF).append('.') 13 | .append((intip >> 8) & 0xFF).append('.') 14 | .append(intip & 0xFF); 15 | return stringBuilder.toString(); 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/utils/LoginException.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.utils; 2 | 3 | /** 4 | * 该类用于表示各种网站登陆时的登陆失败 5 | * @author padeoe 6 | * Date: 2016/4/7 7 | */ 8 | public class LoginException extends Exception { 9 | /** 10 | * 11 | * @param message 服务器返回的失败信息 12 | */ 13 | public LoginException(String message) { 14 | super(message); 15 | } 16 | 17 | public LoginException() { 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/utils/MyDate.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.utils; 2 | 3 | public class MyDate { 4 | private int year; 5 | private int month; 6 | private int day; 7 | 8 | private MyDate(int y, int m, int d) throws Exception { 9 | if (y < 1 || m < 1 || m > 12 || d < 1) { 10 | throw new Exception(); 11 | } 12 | year = y; 13 | month = m; 14 | day = d; 15 | if (d > maxDay()) { 16 | throw new Exception(); 17 | } 18 | } 19 | 20 | public int maxDay() { 21 | int M[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; 22 | if (isLeapYear() && month == 2) 23 | return 29; 24 | else 25 | return M[month - 1]; 26 | } 27 | 28 | public boolean isLeapYear() { 29 | return (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)); 30 | } 31 | 32 | public int sub(MyDate myDate) { 33 | return this.day_t() - myDate.day_t(); 34 | } 35 | 36 | public int day_t() { 37 | int M[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; 38 | int sum = 0; 39 | for (int i = 0; i < month - 1; i++) 40 | sum = sum + M[i]; 41 | if (isLeapYear() && month > 2) 42 | sum++; 43 | return 365 * (year - 1) + (year - 1) / 4 - (year - 1) / 100 + (year - 1) / 400 + sum + day - 1; 44 | } 45 | 46 | public static void main(String[] args) { 47 | System.out.println("start"); 48 | long time1 = System.currentTimeMillis(); 49 | /* 50 | //我的算法,耗时约50ms 51 | for(int i=2015;i<1000000;i++){ 52 | MyDate myDate1; 53 | MyDate myDate2; 54 | try { 55 | myDate1 = new MyDate(i,7,9); 56 | new Date(0); 57 | myDate2=new MyDate(1995, 9, 11); 58 | myDate1.sub(myDate2); 59 | } catch (Exception e) { 60 | // TODO Auto-generated catch block 61 | e.printStackTrace(); 62 | } 63 | }*/ 64 | 65 | /* //jdk方法,耗时约500ms 66 | for(int i=2015;i<1000000;i++){ 67 | Date myDate1; 68 | Date myDate2; 69 | try { 70 | myDate1 = new Date(i,7,9); 71 | new Date(0); 72 | myDate2=new Date(1995, 9, 11); 73 | long a=(myDate1.getTime()-myDate2.getTime())/(1000*3600*24); 74 | } catch (Exception e) { 75 | // TODO Auto-generated catch block 76 | e.printStackTrace(); 77 | } 78 | }*/ 79 | 80 | long time2 = System.currentTimeMillis(); 81 | System.out.println(time2 - time1); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /app/src/main/java/com/padeoe/utils/network/MyByteArray.java: -------------------------------------------------------------------------------- 1 | package com.padeoe.utils.network; 2 | 3 | /** 4 | * @author Nifury 5 | * Date: 2015/12/17 6 | */ 7 | public class MyByteArray { 8 | private byte[] buffer = new byte[4096]; 9 | private int position = 0; 10 | 11 | public void ensureCapacity(int capacity) { 12 | if (buffer.length - position < capacity) { 13 | byte[] tmp = new byte[Math.max(buffer.length * 2, buffer.length + capacity)]; 14 | System.arraycopy(buffer, 0, tmp, 0, position); 15 | buffer = tmp; 16 | } 17 | } 18 | 19 | public void addOffset(int delta) { position += delta; } 20 | 21 | public byte[] getBuffer() { return buffer; } 22 | 23 | public int getOffset() { return position; } 24 | 25 | public int getSize() { return position; } 26 | 27 | public static void main(String[] args) { 28 | MyByteArray array = new MyByteArray(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/res/anim/fragment_slide_left_enter.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/anim/fragment_slide_left_exit.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/anim/fragment_slide_right_enter.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/anim/fragment_slide_right_exit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/connect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LilyStudio/AutoConnect-Android/f715462ffdfd0bc10e88c418889ce006b172b480/app/src/main/res/drawable-hdpi/connect.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/firstsetting.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LilyStudio/AutoConnect-Android/f715462ffdfd0bc10e88c418889ce006b172b480/app/src/main/res/drawable-hdpi/firstsetting.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/open_source_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LilyStudio/AutoConnect-Android/f715462ffdfd0bc10e88c418889ce006b172b480/app/src/main/res/drawable-hdpi/open_source_icon.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-ldpi/connect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LilyStudio/AutoConnect-Android/f715462ffdfd0bc10e88c418889ce006b172b480/app/src/main/res/drawable-ldpi/connect.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/connect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LilyStudio/AutoConnect-Android/f715462ffdfd0bc10e88c418889ce006b172b480/app/src/main/res/drawable-mdpi/connect.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-v21/ic_info_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v21/ic_notifications_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v21/ic_sync_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/connect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LilyStudio/AutoConnect-Android/f715462ffdfd0bc10e88c418889ce006b172b480/app/src/main/res/drawable-xhdpi/connect.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/connect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LilyStudio/AutoConnect-Android/f715462ffdfd0bc10e88c418889ce006b172b480/app/src/main/res/drawable-xxhdpi/connect.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/amount_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LilyStudio/AutoConnect-Android/f715462ffdfd0bc10e88c418889ce006b172b480/app/src/main/res/drawable/amount_icon.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/clock.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LilyStudio/AutoConnect-Android/f715462ffdfd0bc10e88c418889ce006b172b480/app/src/main/res/drawable/clock.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_settings.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_wifi_internet.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_wifi_off.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/icon_wifi_nointernet.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LilyStudio/AutoConnect-Android/f715462ffdfd0bc10e88c418889ce006b172b480/app/src/main/res/drawable/ip.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/left.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/location.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LilyStudio/AutoConnect-Android/f715462ffdfd0bc10e88c418889ce006b172b480/app/src/main/res/drawable/location.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/noconnect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LilyStudio/AutoConnect-Android/f715462ffdfd0bc10e88c418889ce006b172b480/app/src/main/res/drawable/noconnect.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/pc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LilyStudio/AutoConnect-Android/f715462ffdfd0bc10e88c418889ce006b172b480/app/src/main/res/drawable/pc.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/remote.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LilyStudio/AutoConnect-Android/f715462ffdfd0bc10e88c418889ce006b172b480/app/src/main/res/drawable/remote.png -------------------------------------------------------------------------------- /app/src/main/res/layout-land/permission_dialog.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /app/src/main/res/layout-large/activity_first_setting.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 11 | 12 | 13 | 20 | 21 | 22 | 23 | 28 | 29 | 33 | 34 |