Android Open Source - AerisAndroidLibrary Simple Cursor Loader






From Project

Back to project page AerisAndroidLibrary.

License

The source code is released under:

Apache License

If you think the Android project AerisAndroidLibrary 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.example.db;
// w  w w  . j  av  a 2s . co m
import android.content.AsyncTaskLoader;
import android.content.Context;
import android.database.Cursor;

/**
 * Used to write apps that run on platforms prior to Android 3.0. When running
 * on Android 3.0 or above, this implementation is still used; it does not try
 * to switch to the framework's implementation. See the framework SDK
 * documentation for a class overview.
 * 
 * This was based on the CursorLoader class
 */
public abstract class SimpleCursorLoader extends AsyncTaskLoader<Cursor> {
  private Cursor mCursor;

  public SimpleCursorLoader(Context context) {
    super(context);
  }

  /* Runs on a worker thread */
  @Override
  public abstract Cursor loadInBackground();

  /* Runs on the UI thread */
  @Override
  public void deliverResult(Cursor cursor) {
    if (isReset()) {
      // An async query came in while the loader is stopped
      if (cursor != null) {
        cursor.close();
      }
      return;
    }
    Cursor oldCursor = mCursor;
    mCursor = cursor;

    if (isStarted()) {
      super.deliverResult(cursor);
    }

    if (oldCursor != null && oldCursor != cursor && !oldCursor.isClosed()) {
      oldCursor.close();
    }
  }

  /**
   * Starts an asynchronous load of the contacts list data. When the result is
   * ready the callbacks will be called on the UI thread. If a previous load
   * has been completed and is still valid the result may be passed to the
   * callbacks immediately.
   * <p/>
   * Must be called from the UI thread
   */
  @Override
  protected void onStartLoading() {
    if (mCursor != null) {
      deliverResult(mCursor);
    }
    if (takeContentChanged() || mCursor == null) {
      forceLoad();
    }
  }

  /**
   * Must be called from the UI thread
   */
  @Override
  protected void onStopLoading() {
    // Attempt to cancel the current load task if possible.
    cancelLoad();
  }

  @Override
  public void onCanceled(Cursor cursor) {
    if (cursor != null && !cursor.isClosed()) {
      cursor.close();
    }
  }

  @Override
  protected void onReset() {
    super.onReset();

    // Ensure the loader is stopped
    onStopLoading();

    if (mCursor != null && !mCursor.isClosed()) {
      mCursor.close();
    }
    mCursor = null;
  }
}




Java Source Code List

aeris.AerisUnusedStub.java
com.example.customendpoint.CustomEndpointAdapter.java
com.example.customendpoint.CustomMoonModel.java
com.example.customendpoint.CustomSunModel.java
com.example.customendpoint.CustomSunmoonFragment.java
com.example.customendpoint.CustomSunmoonHolder.java
com.example.customendpoint.CustomSunmoonModel.java
com.example.customendpoint.CustomSunmoonResponse.java
com.example.db.MyLocLoader.java
com.example.db.MyPlace.java
com.example.db.MyPlacesDb.java
com.example.db.MyPlacesSubject.java
com.example.db.SimpleCursorLoader.java
com.example.demoaerisproject.AerisDialog.java
com.example.demoaerisproject.AerisNotification.java
com.example.demoaerisproject.BaseApplication.java
com.example.demoaerisproject.DrawerActivity.java
com.example.demoaerisproject.LocationSearchActivity.java
com.example.demoaerisproject.MyLocsActivity.java
com.example.demoaerisproject.SettingsActivity.java
com.example.edithelp.EditTextEnterListener.java
com.example.edithelp.EnterPressedDelegate.java
com.example.fragment.AerisFragment.java
com.example.fragment.AerisPrefFragment.java
com.example.fragment.ExtForecastFragment.java
com.example.fragment.HeadlessFragment.java
com.example.fragment.MapFragment.java
com.example.fragment.NearbyObsFragment.java
com.example.fragment.ObservationFragment.java
com.example.fragment.OverviewFragment.java
com.example.fragment.RecentObsFragment.java
com.example.fragment.RefreshInterface.java
com.example.fragment.SplashFragment.java
com.example.fragment.WeekendFragment.java
com.example.listview.AdapterHolder.java
com.example.listview.DayNightPeriod.java
com.example.listview.ForecastAdapter.java
com.example.listview.ForecastItemHolder.java
com.example.listview.IndexMonitorAdapter.java
com.example.listview.ListAdapter.java
com.example.listview.ObservationAdapter.java
com.example.listview.ObservationItemHolder.java
com.example.listview.ObservationPeriodAdapter.java
com.example.listview.PlacesAdapter.java
com.example.listview.PlacesItemHolder.java
com.example.listview.RecentObsHolder.java
com.example.listview.WeekendAdapter.java
com.example.listview.WeekendItemHolder.java
com.example.menudrawer.HomeFragment.java
com.example.menudrawer.NavDrawerItem.java
com.example.menudrawer.NavDrawerListAdapter.java
com.example.preference.PrefManager.java
com.example.service.NotificationService.java
com.example.service.ScreenOnReceiver.java
com.example.service.ScreenOnService.java
com.example.util.FormatUtil.java
com.example.view.DayNightView.java
com.example.view.SmallForecastView.java
com.example.view.TemperatureInfoData.java
com.example.view.TemperatureWindowAdapter.java
com.example.view.TwoPartView.java