Place the school on the desktop-update the on-campus data Android desktop components in real time, on-campus android

Source: Internet
Author: User

Place the school on the desktop-update the on-campus data Android desktop components in real time, on-campus android

Project address: https://github.com/hwding/AeolosXDUWidget

Seek for support ( ̄ 3 ̄)♡

Although Ben Xiaobai's school is XX Electronic Science and Technology University, the network infrastructure is really... each page used for query is not a set of systems at all... that is to say, if you want to easily obtain your lab score, the number of physical connections, the current situation and balance of the on-campus card, usage of utilities, and library borrowing information, you have to log on to many different webpages and use multiple different systems to enter different accounts and passwords... (I don't want to worry about some systems being outsourced to another E-Science University ...)

So can we use a convenient way to present and refresh important information in a timely manner?

According to this requirement, I made a small part for myself on the mobile phone desktop, which is really convenient! It's really convenient! It's really convenient!

Two previews are shown below.

<Uses-permission android: name = "android. permission. WRITE_EXTERNAL_STORAGE"/> this permission

 

Cache method:

 1 public void getCaptcha(File file) throws IOException { 2         URL url = new URL(HOST + CAPTCHA_SUFFIX); 3         URLConnection urlConnection = url.openConnection(); 4         urlConnection.setRequestProperty("Cookie", "JSESSIONID="+JSESSIONID); 5         urlConnection.connect(); 6         InputStream inputStream = urlConnection.getInputStream(); 7         byte[] bytes = new byte[1024]; 8         FileOutputStream fileOutputStream = new FileOutputStream(file); 9         int LENGTH;10         while ((LENGTH = inputStream.read(bytes)) != -1){11             fileOutputStream.write(bytes, 0, LENGTH);12         }13         inputStream.close();14         fileOutputStream.close();15     }

 

Set the thread for the page to Download the verification code:

 1 package xdu.hwding.aeolosxdu; 2  3 import android.os.Handler; 4 import android.os.Message; 5 import java.io.File; 6 import java.io.IOException; 7 import FooPackage.ECard; 8  9 public class CaptchaLoaderThread extends Thread{10     File file;11     ECard eCard;12     Handler handler;13 14     CaptchaLoaderThread(File file, Handler handler) throws IOException {15         this.file = file;16         this.handler = handler;17     }18 19     public void run() {20         try {21             eCard = new ECard();22             eCard.getCaptcha(file);23             Message message = new Message();24             message.obj = eCard;25             handler.sendMessage(message);26         } catch (IOException e) {27             e.printStackTrace();28         }29     }30 }

 

After the cache is successful, the main thread is notified to display it in BitMap mode:

 1     Handler generateHandler(final ImageView imageView, final File file) { 2         return new Handler() { 3             @Override 4             public void handleMessage(Message msg) { 5                 Bitmap bitmap = BitmapFactory.decodeFile(String.valueOf(file)); 6                 imageView.setImageBitmap(bitmap); 7                 findViewById(R.id.add_button).setEnabled(true); 8                 findViewById(R.id.add_button).setOnClickListener(generateOnClickListener((ECard) msg.obj)); 9             }10         };11 }

 

About HTML parsing:

Extracting valid information from the analysis result page is the most important part. The program is ultimately a crawler.

JSoup is undoubtedly the first choice. For details, see parse HTML data in Java (using a third-party library Jsoup)

I will not repeat it here

 

Update cycle of widgets:

When you create a desktop part, AndroidStudio automatically generates an XML configuration file that defines some attributes of the part.

 1 <?xml version="1.0" encoding="utf-8"?> 2 <appwidget-provider 3     xmlns:android="http://schemas.android.com/apk/res/android" 4     android:configure="xdu.hwding.aeolosxdu.NewAppWidgetConfigureActivity" 5     android:initialKeyguardLayout="@layout/new_app_widget" 6     android:initialLayout="@layout/new_app_widget" 7     android:minHeight="215dp" 8     android:minWidth="250dp" 9     android:previewImage="@drawable/preview"10     android:resizeMode="vertical"11     android:updatePeriodMillis="1800000"12     android:widgetCategory="home_screen">13 </appwidget-provider>

The minHeight and minWidth attributes define the minimum part size.

ResizeMode defines the zooming direction

Note that this is the most pitfall !!!

I have not read this document. I really think that updatePeriodMillis can be refreshed every minute as low as 60000 milliseconds during the day...

However, the fact is thatMinimum update cycleIt also takes half an hour (1800000 ms)... if you want to be shorter, you can only run one more thread and then broadcast the notification.

For this long time I know the truth, tears have fallen...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.