Android Open Source - adamsonelearn Download Document Intent Service






From Project

Back to project page adamsonelearn.

License

The source code is released under:

MIT License

If you think the Android project adamsonelearn listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.jaselogic.adamsonelearn;
//from w  w  w . j av a 2s.c  o m
import java.io.IOException;
import java.net.SocketTimeoutException;

import org.jsoup.Connection.Response;
import org.jsoup.Jsoup;
import org.jsoup.Connection.Method;
import org.jsoup.nodes.Document;

import android.app.IntentService;
import android.content.Intent;
import android.util.Log;

public abstract class DownloadDocumentIntentService extends IntentService {
  protected final static String PAGE_LOGIN = "http://learn.adamson.edu.ph/V4/";
  protected final static String PAGE_BALINQ = "http://learn.adamson.edu.ph/V4/?page=balinq";
  protected final static String PAGE_UPDATES = "http://learn.adamson.edu.ph/V4/modules/newsfeed.php?sy=2013-2014&t=2";
  protected final static String PAGE_SUBJECTS = "http://learn.adamson.edu.ph/V4/modules/mysubjects.php?cat=0";
  protected final static String PAGE_CURRICULUM = "http://learn.adamson.edu.ph/V4/?page=curr";
  
  public DownloadDocumentIntentService(String name) {
    super(name);
  }

  @Override
  protected void onHandleIntent(Intent intent) {
    String cookie = getCookie(intent);
    
    Document result = null;
    Response loginres = null;
    
    performPriorDownload();
    
        try {
          if(cookie == null) {
              loginres = Jsoup.connect(PAGE_LOGIN)
                  .data("TXTusername", getStudno(intent), "TXTpassword", getPassword(intent), "BTNlogin", "Login")
                  .method(Method.POST)
                  .execute();
              cookie = loginres.cookie("PHPSESSID");
          }
            
          //TODO: Handle if cookie has expired.         
            result = Jsoup.connect(getPage())
                .cookie("PHPSESSID", cookie)
                .get();            
        } catch (IOException e) {                          
            e.printStackTrace();                           
        }
        
         performAfterDownload(result, cookie, intent);       

  }

  protected abstract void performPriorDownload();
  protected abstract void performAfterDownload(Document result, String cookie, Intent intent);
  protected abstract String getCookie(Intent intent);
  protected abstract String getPage();
  protected abstract String getStudno(Intent intent);
  protected abstract String getPassword(Intent intent);
}




Java Source Code List

com.jaselogic.adamsonelearn.AlertDialogBuilder.java
com.jaselogic.adamsonelearn.CurrDisplayAdapter.java
com.jaselogic.adamsonelearn.CurriculumFragment.java
com.jaselogic.adamsonelearn.CurriculumIntentService.java
com.jaselogic.adamsonelearn.CurriculumPageFragment.java
com.jaselogic.adamsonelearn.Dashboard.java
com.jaselogic.adamsonelearn.DownloadDocumentIntentService.java
com.jaselogic.adamsonelearn.DrawerListAdapter.java
com.jaselogic.adamsonelearn.HomeFragment.java
com.jaselogic.adamsonelearn.HomePageFragment.java
com.jaselogic.adamsonelearn.LoginIntentService.java
com.jaselogic.adamsonelearn.Main.java
com.jaselogic.adamsonelearn.NonSwipeViewPager.java
com.jaselogic.adamsonelearn.ScheduleHelper.java
com.jaselogic.adamsonelearn.SubjectIntentService.java
com.jaselogic.adamsonelearn.SubjectListAdapter.java
com.jaselogic.adamsonelearn.TodayListAdapter.java
com.jaselogic.adamsonelearn.UpdateIntentService.java
com.jaselogic.adamsonelearn.UpdatesListAdapter.java
com.jaselogic.adamsonelearn.YearSelectAdapter.java
com.viewpagerindicator.CirclePageIndicator.java
com.viewpagerindicator.IconPageIndicator.java
com.viewpagerindicator.IconPagerAdapter.java
com.viewpagerindicator.IcsLinearLayout.java
com.viewpagerindicator.LinePageIndicator.java
com.viewpagerindicator.PageIndicator.java
com.viewpagerindicator.TabPageIndicator.java
com.viewpagerindicator.TitlePageIndicator.java
com.viewpagerindicator.UnderlinePageIndicator.java