Posted onEdited onInAndroidViews: Word count in article: 21kReading time ≈19 mins.
Introduction
Write an app to query the school's empty classrooms Pull information
from the school's registration website, classify and display it, and add
some miscellaneous things After all, it's my first time writing Android,
so I want to try everything Download here: BuptRoom repository address: A simple Beiyou self-study
room query system It took about 3 weekends to complete the first
version, and then I spent about 1 month updating miscellaneous things
After that, I spent about 1 month updating miscellaneous things Many
things written in an unstandardized manner, and I just looked up and
used them temporarily Summarize the experience of writing the App:
Learning content
Android basic architecture, components, lifecycle
Fragment
Java library and library calls
Github usage
Deploy app
Image processing methods
A stupid way to pull web content
Utilize GitHub third-party libraries
Color knowledge
Android Material Design
Simple optimization
Multithreading and Handler
Solved problems
Mainly solved the following problems:
Android 6.0 and above versions seem to require dynamic permission
verification, and the current version only supports 5.0 and below, used
permisson:
The webpage is a jsp dynamic webpage, which cannot be simply parsed,
so I finally used loadurl in webview to execute javascript commands, and
need to download the jsoup-1.9.2.jar package and add it to the library
file
Group contents=content.split(" |:"); String showcontent=""; count=0; int tsgflag=0; int cishu=0; j12.clear(); j34.clear(); j56.clear(); j78.clear(); j9.clear(); j1011.clear(); if (keyword.contains("图书馆")) tsgflag=1; for (String temp:contents){ if (temp.contains(keyword)){ cishu++; SaveBuidlingInfo(count,cishu,tsgflag); } count++; }
SaveBuildingInfo is to classify and store classrooms by building, and then classify and store them by time period in j12,j34..... while (1 == 1) { if (contents[k].contains("楼") || contents[k].contains("节") || contents[k].contains("图")) break; ; switch (c) { case1: j12.add(contents[k]); break; case2: j34.add(contents[k]); break; case3: j56.add(contents[k]); break; case4: j78.add(contents[k]); break; case5: j9.add(contents[k]); break; case6: j1011.add(contents[k]); break; default: break; } k++; }
The NavigationView is a simple one, with no special design,
because there are no multiple interfaces, just use the refresh TextView
to fake multiple interfaces
Tried the MaterialDesign components, added some things about
system time
if (mHour>=8&&mHour<10){ nowtime="现在是一二节课"; }else if (mHour>=10&&mHour<12){ nowtime="现在是三四节课"; }else if ((mHour==13&&mMinute>=30)||(mHour==14)||(mHour==15&&mMinute<30)){ nowtime="现在是五六节课"; }else if ((mHour==15&&mMinute>=30)||(mHour==16)||(mHour==17&&mMinute<30)){ nowtime="现在是七八节课"; }else if ((mHour==17&&mMinute>=30)||(mHour==18&&mMinute<30)){ nowtime="现在是第九节课"; }else if ((mHour==18&&mMinute>=30)||(mHour==19)||(mHour==20&&mMinute<30)){ nowtime="现在是十、十一节课"; }else nowtime="现在是休息时间";
In addition to trying to use other GitHub libraries, I learned a lot,
including color palettes, shake modules, fir update modules, sliding
card interfaces, etc. Some GitHub repository links are here
# Independent network pull and multi-threading - In the previous structure, network pull was integrated in the welcome activity, in order to add a refresh function in the main interface and call the network pull at any time, I wrote the network pull as a separate class, which can be called when needed - However, in the welcome activity, the welcome animation and network pull are in two separate threads (to prevent the animation from being blocked), so there may be a situation where the welcome animation is completed and the main interface is entered, but the network pull is not completed, and the content pulled cannot be passed to the main interface. The final solution is to set a 2s timeout for the network pull. If it is not pulled, an incorrect parameter is passed to the activity that starts the main interface, prompting a refresh ```Java webget = new Webget(); webget.init(webView); HaveNetFlag = webget.WebInit();
new Handler().postDelayed(new Runnable() { public void run() { //execute the task ImageView img = (ImageView) findViewById(R.id.welcomeimg); Animation animation = AnimationUtils.loadAnimation(WelcomeActivity.this, R.anim.enlarge); animation.setFillAfter(true); img.startAnimation(animation); } }, 50);
if (mHour>=8&&mHour<10){ nowtime="现在是一二节课"; }else if (mHour>=10&&mHour<12){ nowtime="现在是三四节课"; }else if ((mHour==13&&mMinute>=30)||(mHour==14)||(mHour==15&&mMinute<30)){ nowtime="现在是五六节课"; }else if ((mHour==15&&mMinute>=30)||(mHour==16)||(mHour==17&&mMinute<30)){ nowtime="现在是七八节课"; }else if ((mHour==17&&mMinute>=30)||(mHour==18&&mMinute<30)){ nowtime="现在是第九节课"; }else if ((mHour==18&&mMinute>=30)||(mHour==19)||(mHour==20&&mMinute<30)){ nowtime="现在是十、十一节课"; }else nowtime="现在是休息时间";