package com.mnnyang.gzuclassschedule.utils.spec;
import android.support.annotation.NonNull;
import com.mnnyang.gzuclassschedule.app.AppUtils;
import com.mnnyang.gzuclassschedule.app.Constant;
import com.mnnyang.gzuclassschedule.app.Url;
import com.mnnyang.gzuclassschedule.custom.course.CourseAncestor;
import com.mnnyang.gzuclassschedule.custom.util.Utils;
import com.mnnyang.gzuclassschedule.data.bean.Course;
import com.mnnyang.gzuclassschedule.data.bean.CourseTime;
import com.mnnyang.gzuclassschedule.data.beanv2.CourseV2;
import com.mnnyang.gzuclassschedule.utils.LogUtil;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
//import com.mnnyang.gzuclassschedule.data.bean.Course;
/**
* GZU课程解析
* Created by mnnyang on 17-10-19.
*/
public class ParseCourse {
private static final String pattern = "第.*节";
private static final String[] other = {"时间", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六",
"星期日", "早晨", "上午", "下午", "晚上"};
private static final Pattern pattern1 = Pattern.compile("第\\d{1,2}.*节");
private static final Pattern pattern2 = Pattern.compile("\\{第\\d{1,2}[-]*\\d*周");
public static String parseViewStateCode(String html) {
String code = "";
Document doc = org.jsoup.Jsoup.parse(html);
Elements inputs = doc.getElementsByAttributeValue("name", Url.__VIEWSTATE);
if (inputs.size() > 0) {
code = inputs.get(0).attr("value");
} else {
}
return code;
}
/**
* @param html
* @return 解析失敗返回空
*/
public static CourseTime parseTime(String html) {
String SELECTED = "selected";
String OPTION = "option";
Document doc = org.jsoup.Jsoup.parse(html);
CourseTime courseTime = new CourseTime();
Elements selects = doc.getElementsByTag("select");
if (selects == null || selects.size() < 2) {
LogUtil.e(ParseCourse.class, "select < 2 ");
return null;
}
Elements options = selects.get(0).getElementsByTag(OPTION);
for (Element o : options) {
String year = o.text().trim();
courseTime.years.add(year);
if (o.attr(SELECTED).equals(SELECTED)) {
courseTime.selectYear = year;
}
}
options = selects.get(1).getElementsByTag(OPTION);
for (Element o : options) {
String term = o.text().trim();
courseTime.terms.add(term);
if (o.attr(SELECTED).equals(SELECTED)) {
courseTime.selectTerm = term;
}
}
return courseTime;
}
/**
* @param html
* @return 解析失败返回空
*/
public static ArrayList<CourseV2> parse(String html) {
Document doc = org.jsoup.Jsoup.parse(html);
Element table1 = doc.getElementById("Table1");
Elements trs = table1.getElementsByTag("tr");
ArrayList<CourseV2> courses = new ArrayList<>();
int node = 0;
for (Element tr : trs) {
Elements tds = tr.getElementsByTag("td");
for (Element td : tds) {
String courseSource = td.text().trim();
if (courseSource.length() <= 6) {
//null data
continue;
}
if (Pattern.matches(pattern, courseSource)) {
//node number
try {
node = Integer.decode(courseSource.substring(1, courseSource.length() - 1));
} catch (Exception e) {
node = 0;
e.printStackTrace();
}
continue;
}
if (inArray(other, courseSource)) {
//other data
continue;
}
courses.addAll(ParseCourse.parseTextInfo(courseSource, node));
}
}
return mergeSameClass(courses);
}
/**
* 合并同一门课
*/
private static ArrayList<CourseV2> mergeSameClass(ArrayList<CourseV2> courses) throws NumberFormatException {
ArrayList<CourseV2> result = new ArrayList<>();
int i = 0;
for (CourseV2 cours : courses) {
boolean find = false;
for (CourseV2 courseV2 : result) {
//同一门课
if (cours.isSameClass(courseV2)) {
find = true;
String oneAllWeek = courseV2.getCouAllWeek();
String twoAllWeek = cours.getCouAllWeek();
if (oneAllWeek.length() > 0 && twoAllWeek.length() > 0) {
if (Integer.decode(oneAllWeek.substring(0, 1))
< Integer.decode(twoAllWeek.substring(0, 1))) {
courseV2.setCouAllWeek(oneAllWeek + "," + twoAllWeek);
} else {
courseV2.setCouAllWeek(twoAllWeek + "," + oneAllWeek);
}
} else if (twoAllWeek.length() > 0) {
courseV2.setCouAllWeek(twoAllWeek);
}
}
}
if (!find) {
result.add(cours);
}
}
for (int i1 = 0; i1 < result.size(); i1++) {
CourseV2 left = result.get(i1);
if (left.getCouColor() == null) {
int color = Utils.getRandomColor();
left.setCouColor(color);
for (CourseV2 courseV2 : result) {
if(courseV2.isSameClassWithoutLocation(left)){
courseV2.setCouColor(color);
}
}
}
}
return result;
}
public static void main(String[] args) {
//String s = readToString("/home/xxyangyoulin/Android/project/ClassSchedule/app/src/main/java/com/mnnyang/gzuclassschedule/impt/demo.html");
String s = "<table id=\"Table1\" class=\"blacktab\" bordercolor=\"Black\" border=\"0\" width=\"100%\">\n" +
" <tbody>\n" +
" <tr>\n" +
" <td colspan=\"2\" rowspan=\"1\" width=\"2%\">时间</td>\n" +
" <td align=\"Center\" width=\"14%\">星期一</td>\n" +
" <td align=\"Center\" width=\"14%\">星期二</td>\n" +
" <td align=\"Center\" width=\"14%\">星期三</td>\n" +
" <td align=\"Center\" width=\"14%\">星期四</td>\n" +
" <td align=\"Center\" width=\"14%\">星期五</td>\n" +
" <td class=\"noprint\" align=\"Center\" width=\"14%\">星期六</td>\n" +
" <td class=\"noprint\" align=\"Center\" width=\"14%\">星期日</td>\n" +
" </tr>\n" +
" <tr>\n" +
" <td colspan=\"2\">早晨</td>\n" +
" <td align=\"Center\"> </td>\n" +
" <td align=\"Center\"> </td>\n" +
" <td align=\"Center\"> </td>\n" +
" <td align=\"Center\"> </td>\n" +
" <td align=\"Center\"> </td>\n" +
" <td class=\"noprint\" align=\"Center\"> </td>\n" +
" <td class=\"noprint\" align=\"Center\"> </td>\n" +
" </tr>\n" +
" <tr>\n" +
" <td rowspan=\"5\" width=\"1%\">上�
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
本项目为“基于Java的掌上校园移动应用设计源码”,包含257个文件,其中包括116个XML配置文件、105个Java源文件、21个PNG图像文件、3个Gradle构建脚本、3个Properties配置文件、2个Markdown文档、1个Gitignore忽略配置文件、1个Pro项目文件、1个APK安装包以及1个JSON数据文件。该应用利用Java语言开发,旨在为校园用户提供便捷的一站式服务,包括课程查询、成绩查询、图书馆预约等功能,适用于高校学生和教职工。项目结构清晰,代码注释详尽,易于理解和集成。
资源推荐
资源详情
资源评论
收起资源包目录
基于Java的掌上校园移动应用设计源码 (256个子文件)
app-release.apk 4.3MB
gradlew.bat 2KB
.gitignore 7B
build.gradle 3KB
build.gradle 920B
settings.gradle 15B
gradlew 5KB
gradle-wrapper.jar 52KB
ParseCourse.java 24KB
HomePresenter.java 19KB
CourseActivity.java 18KB
HomeFragment.java 17KB
CourseView.java 16KB
CourseDbDao.java 15KB
WheelView.java 13KB
Html5Activity.java 12KB
CourseV2Dao.java 11KB
UpdateService.java 11KB
ImptPresenter.java 10KB
AddActivity.java 10KB
AppUtils.java 10KB
MgActivity.java 9KB
EduHttpUtils.java 8KB
PopupWindowDialog.java 8KB
Course.java 8KB
DialogHelper.java 8KB
ImptActivity.java 7KB
CourseV2.java 7KB
FileUtils.java 6KB
AboutActivity.java 6KB
MyHttpUtils.java 6KB
SignActivity.java 6KB
SchoolActivity.java 5KB
RecyclerBaseAdapter.java 5KB
RecyclerBaseAdapter.java 5KB
MyWidget.java 5KB
EditTextLayout.java 5KB
ShowDetailDialog.java 5KB
CourseGroupDao.java 5KB
SettingFragment.java 5KB
SettingItemNormal.java 4KB
ScreenUtils.java 4KB
CourseGroup.java 4KB
RequestPermission.java 4KB
CourseAncestor.java 4KB
SignPresenter.java 4KB
CoursePresenter.java 4KB
MgPresenter.java 3KB
SmoothProgress.java 3KB
DaoMaster.java 3KB
ImageResizer.java 3KB
RippleLayout.java 3KB
VersionUpdate.java 3KB
ShowTermDialog.java 3KB
Cache.java 3KB
Donate.java 3KB
CourseDbHelper.java 3KB
Preferences.java 3KB
DownCourseWrapper.java 3KB
Utils.java 3KB
BaseFragment.java 2KB
AboutPresenter.java 2KB
MgAdapter.java 2KB
ColorImageView.java 2KB
app.java 2KB
ActivityUtil.java 2KB
BaseActivity.java 2KB
Constant.java 2KB
Url.java 2KB
DaoSession.java 2KB
LogUtil.java 2KB
TimeUtils.java 2KB
SchoolPresenter.java 2KB
CoursesPsc.java 2KB
VersionWrapper.java 1KB
HomeActivity.java 1KB
SplashFragment.java 1KB
SettingActivity.java 1KB
HomeContract.java 1KB
SelectImageHelper.java 1KB
ToastUtils.java 1KB
UserWrapper.java 1023B
ImptContract.java 1018B
MgContract.java 957B
QRCode.java 862B
UpdateJobService.java 845B
CsName.java 842B
ButtonHandler.java 831B
JsonCallback.java 825B
ColorUtil.java 812B
ExampleInstrumentedTest.java 760B
CourseContract.java 751B
SelectWeekAdapter.java 746B
SignContact.java 728B
AddPresenter.java 723B
BaseBean.java 715B
MyOpenHelper.java 712B
AddContract.java 694B
CourseTime.java 626B
SchoolContract.java 568B
共 256 条
- 1
- 2
- 3
资源评论
csbysj2020
- 粉丝: 2540
- 资源: 5471
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功