Android Open Source - mobile2-android E College Async Task






From Project

Back to project page mobile2-android.

License

The source code is released under:

Apache License

If you think the Android project mobile2-android 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.ecollege.android.tasks;
/*from   ww  w. j a  v  a  2s  .c  o  m*/
//Based on example from droid-fu

import roboguice.util.RoboAsyncTask;
import android.app.Activity;
import android.content.Context;

import com.ecollege.android.ECollegeApplication;
import com.ecollege.android.activities.ECollegeActivity;

/**
 * Works in a similar way to AsyncTask but provides extra functionality.
 *
 * 1) It keeps track of the active instance of each Context, ensuring that the
 * correct instance is reported to. This is very useful if your Activity is
 * forced into the background, or the user rotates his device.
 *
 * 2) A progress dialog is automatically shown. See useCustomDialog()
 * disableDialog()
 *
 * 3) If an Exception is thrown from inside doInBackground, this is now handled
 * by the handleError method.
 *
 * 4) You should now longer override onPreExecute(), doInBackground() and
 * onPostExecute(), instead you should use before(), doCheckedInBackground() and
 * after() respectively.
 *
 * These features require that the Application extends DroidFuApplication.
 *
 * @param <ParameterT>
 * @param <ProgressT>
 * @param <ReturnT>
 */
public abstract class ECollegeAsyncTask<ResultT> extends RoboAsyncTask<ResultT>  {

  protected ECollegeApplication app;
    @SuppressWarnings("unused")
  private boolean reportsProgress = false;
    private int progressDialogTitleId = -1;
    private int progressDialogMsgId = -1;
    private boolean showModalDialog = false;
  private boolean showTitlebarBusyIndicator = true;
    private String activityName;
  
    public ECollegeAsyncTask(ECollegeActivity activity) {
      super();
      this.app=activity.getApp();
      app.getInjector().injectMembers(this);
      activityName = activity.getClass().getCanonicalName();
      app.setActiveContext(activityName,(Context)activity);
    }
    
    @Override
  protected void onException(Exception e) throws RuntimeException {
    app.reportError(e);
  }

  public ECollegeAsyncTask<ResultT> makeModal() {
      this.showModalDialog = true;
    this.showTitlebarBusyIndicator = false;
      return this;
    }
    
    public ECollegeAsyncTask<ResultT> enableProgressHandling() {
      this.reportsProgress = true;
      return this;
    }

  public ECollegeAsyncTask<ResultT> setProgressDialogTitleId(int progressDialogTitleId) {
    this.progressDialogTitleId=progressDialogTitleId;
    return this;
  }

  public ECollegeAsyncTask<ResultT> setProgressDialogMsgId(int progressDialogMsgId) {
    this.progressDialogMsgId=progressDialogMsgId;
    return this;
  }
  
  public ECollegeAsyncTask<ResultT> disableTitlebarBusyIndicator() {
    this.showTitlebarBusyIndicator = false;
    return this;
  }
   
  protected ECollegeActivity getCurrentActivity() {
    return (ECollegeActivity)app.getActiveContext(activityName);
  }
  
    @Override
    protected void onPreExecute() throws Exception {
      super.onPreExecute();

      if (showTitlebarBusyIndicator) app.incrementPendingServiceCalls();
      
      ECollegeActivity currentActivity = getCurrentActivity();
      
        if (currentActivity != null && showModalDialog) {
          app.setNextProgressDialogTitleId(progressDialogTitleId);
          app.setNextProgressDialogMsgId(progressDialogMsgId);
          ((Activity)currentActivity).showDialog(0);
        }
    }


  @Override
  protected void onFinally() throws RuntimeException {
    super.onFinally();

    if (showTitlebarBusyIndicator) app.decrementPendingServiceCalls();

      ECollegeActivity currentActivity = getCurrentActivity();
      
        if (currentActivity != null && showModalDialog) {
            ((Activity)currentActivity).removeDialog(0);
        }
  }
}




Java Source Code List

com.ecollege.android.AnnouncementActivity.java
com.ecollege.android.CourseActivity.java
com.ecollege.android.CourseAnnouncementsActivity.java
com.ecollege.android.CourseDiscussionsActivity.java
com.ecollege.android.CourseGradebookActivity.java
com.ecollege.android.CoursePeopleActivity.java
com.ecollege.android.CourseThreadActivity.java
com.ecollege.android.CoursesActivity.java
com.ecollege.android.DiscussionsActivity.java
com.ecollege.android.DropboxMessageActivity.java
com.ecollege.android.ECollegeApplication.java
com.ecollege.android.GradeActivity.java
com.ecollege.android.HomeActivity.java
com.ecollege.android.HtmlContentActivity.java
com.ecollege.android.LoginActivity.java
com.ecollege.android.MainActivity.java
com.ecollege.android.PersonActivity.java
com.ecollege.android.ProfileActivity.java
com.ecollege.android.SingleSignonActivity.java
com.ecollege.android.SplashActivity.java
com.ecollege.android.UserDiscussionActivity.java
com.ecollege.android.UserResponseActivity.java
com.ecollege.android.UserTopicActivity.java
com.ecollege.android.activities.ECollegeActivityHelper.java
com.ecollege.android.activities.ECollegeActivity.java
com.ecollege.android.activities.ECollegeDefaultActivity.java
com.ecollege.android.activities.ECollegeListActivity.java
com.ecollege.android.activities.ECollegeTabActivity.java
com.ecollege.android.adapter.ActivityFeedAdapter.java
com.ecollege.android.adapter.GroupedAdapter.java
com.ecollege.android.adapter.LoadMoreAdapter.java
com.ecollege.android.adapter.ParentAdapterObserver.java
com.ecollege.android.adapter.ResponseAdapter.java
com.ecollege.android.adapter.TopicsAdapter.java
com.ecollege.android.adapter.UberAdapter.java
com.ecollege.android.adapter.UberItem.java
com.ecollege.android.adapter.UpcomingEventsAdapter.java
com.ecollege.android.adapter.WaitingForApiAdapter.java
com.ecollege.android.errors.ECollegeAlertException.java
com.ecollege.android.errors.ECollegeException.java
com.ecollege.android.errors.ECollegePromptException.java
com.ecollege.android.errors.ECollegePromptRetryException.java
com.ecollege.android.tasks.ECollegeAsyncTask.java
com.ecollege.android.tasks.ServiceCallTask.java
com.ecollege.android.tasks.TaskPostProcessor.java
com.ecollege.android.util.CacheConfiguration.java
com.ecollege.android.util.DateTimeUtil.java
com.ecollege.android.util.FileCacheManager.java
com.ecollege.android.util.VolatileCacheManager.java
com.ecollege.android.view.HeaderView.java
com.ecollege.android.view.helpers.ResponseCountViewHelper.java