Example usage for android.support.v4.app LoaderManager getLoader

List of usage examples for android.support.v4.app LoaderManager getLoader

Introduction

In this page you can find the example usage for android.support.v4.app LoaderManager getLoader.

Prototype

public abstract <D> Loader<D> getLoader(int id);

Source Link

Document

Return the Loader with the given id or null if no matching Loader is found.

Usage

From source file:com.gh4a.activities.IssueListActivity.java

@Override
public void onRefresh() {
    mAssignees = null;/*from w  w  w  . jav  a 2  s . c om*/
    mMilestones = null;
    mLabels = null;
    mIsCollaborator = null;
    updateRightNavigationDrawer();

    LoaderManager lm = getSupportLoaderManager();
    for (int i = 0; i < 4; i++) {
        Loader loader = lm.getLoader(i);
        if (loader != null) {
            loader.onContentChanged();
        }
    }
    super.onRefresh();
}

From source file:com.wit.android.support.fragment.BaseFragment.java

/**
 * Starts a loader with the specified <var>id</var>. If there was already started loader with the
 * same id before, such a loader will be <b>re-started</b>, otherwise new loader will be <b>initialized</b>.
 * <p>// www  .  j  a  va 2s  . c o m
 * See {@link android.support.v4.app.LoaderManager#restartLoader(int, Bundle, android.support.v4.app.LoaderManager.LoaderCallbacks)} and
 * {@link android.support.v4.app.LoaderManager#initLoader(int, Bundle, android.support.v4.app.LoaderManager.LoaderCallbacks)} for more info.
 *
 * @param id        Id of the desired loader to start.
 * @param params    Params for loader.
 * @param callbacks Callbacks for loader.
 * @return {@code True} if loader with the specified id was <b>initialized</b> or <b>re-started</b>,
 * {@code false} if the current activity is already invalid or {@link android.support.v4.app.LoaderManager} is not available.
 */
protected boolean startLoader(int id, @Nullable Bundle params,
        @NonNull LoaderManager.LoaderCallbacks callbacks) {
    if (mActivity != null) {
        final LoaderManager loaderManager = ((FragmentActivity) mActivity).getSupportLoaderManager();
        if (loaderManager != null) {
            if (loaderManager.getLoader(id) != null) {
                loaderManager.restartLoader(id, params, callbacks);
            } else {
                loaderManager.initLoader(id, params, callbacks);
            }
            return true;
        }
    }
    return false;
}

From source file:org.bwgz.quotation.activity.QuotationActivity.java

private <T> void initLoader(LoaderManager loaderManager, int loaderId, Bundle args,
        LoaderCallbacks<T> callbacks) {
    final Loader<T> loader = loaderManager.getLoader(loaderId);
    if (loader == null || loader.isReset()) {
        Log.d(TAG, String.format("initLoader - initLoader: %d", loaderId));
        loaderManager.initLoader(loaderId, args, callbacks);
    } else {/* www .j  ava 2  s  . c o  m*/
        Log.d(TAG, String.format("initLoader - restartLoader: %d", loaderId));
        loaderManager.restartLoader(loaderId, args, callbacks);
    }
}

From source file:com.tct.fw.ex.photo.fragments.PhotoViewFragment.java

@Override
public void onCursorChanged(Cursor cursor) {
    if (mAdapter == null) {
        // The adapter is set in onAttach(), and is guaranteed to be non-null. We have magically
        // received an onCursorChanged without attaching to an activity. Ignore this cursor
        // change.
        return;//from   w  w  w  .j a  v  a  2  s  .  c o m
    }
    // FLAG: There is a problem here:
    // If the cursor changes, and new items are added at an earlier position than
    // the current item, we will switch photos here. Really we should probably
    // try to find a photo with the same url and move the cursor to that position.
    if (cursor.moveToPosition(mPosition) && !isPhotoBound()) {
        mCallback.onCursorChanged(this, cursor);

        final LoaderManager manager = getLoaderManager();

        final Loader<BitmapResult> fakePhotoLoader = manager.getLoader(PhotoViewCallbacks.BITMAP_LOADER_PHOTO);
        if (fakePhotoLoader != null) {
            final PhotoBitmapLoaderInterface loader = (PhotoBitmapLoaderInterface) fakePhotoLoader;
            mResolvedPhotoUri = mAdapter.getPhotoUri(cursor);
            loader.setPhotoUri(mResolvedPhotoUri);
            loader.forceLoad();
        }

        if (!mThumbnailShown) {
            final Loader<BitmapResult> fakeThumbnailLoader = manager
                    .getLoader(PhotoViewCallbacks.BITMAP_LOADER_THUMBNAIL);
            if (fakeThumbnailLoader != null) {
                final PhotoBitmapLoaderInterface loader = (PhotoBitmapLoaderInterface) fakeThumbnailLoader;
                mThumbnailUri = mAdapter.getThumbnailUri(cursor);
                loader.setPhotoUri(mThumbnailUri);
                loader.forceLoad();
            }
        }
    }
}

From source file:org.dmfs.webcal.fragments.CalendarItemFragment.java

public void loadCalendar() {
    // the the adapter has no cursor yet
    LoaderManager loaderManager = getLoaderManager();
    if (loaderManager != null) {
        if (loaderManager.getLoader(LOADER_PREVIEW) == null) {
            Loader<Cursor> initLoader = loaderManager.initLoader(LOADER_PREVIEW, null,
                    CalendarItemFragment.this);
            if (initLoader != null) {
                initLoader.forceLoad();/*from  w ww.  j  a  v a2s .co m*/
            } else {
                Log.e(TAG, "Newly created Loader is null");
            }
        } else {
            loaderManager.restartLoader(LOADER_PREVIEW, null, CalendarItemFragment.this);
        }
    } else {
        Log.e(TAG, "Loader Manager is null");
    }
}

From source file:de.ub0r.android.callmeter.ui.PlansFragment.java

/**
 * {@inheritDoc}/*from w ww .  j a  v a2s  .c  om*/
 */
@Override
public void onActivityCreated(final Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    PlansAdapter adapter = new PlansAdapter(getActivity(), now);
    setListAdapter(adapter);
    getListView().setOnItemLongClickListener(this);

    LoaderManager lm = getLoaderManager();
    if (lm.getLoader(uid) != null) {
        getLoaderManager().initLoader(uid, null, this);
    } else if (doDummy && now < 0L) {
        doDummy = false;
        getLoaderManager().initLoader(UID_DUMMY, null, this);
    }
}

From source file:com.stockbrowser.BookmarksPageCallbacks.java

/**
 * @param uri//from  w w  w  . jav a 2s. com
 */
private void loadFolder(int groupPosition, Uri uri) {
    LoaderManager manager = getLoaderManager();
    // This assumes groups are ordered the same as loaders
    BookmarksLoader loader = (BookmarksLoader) ((Loader<?>) manager
            .getLoader(LOADER_BOOKMARKS + groupPosition));
    loader.setUri(uri);
    loader.forceLoad();
}

From source file:de.ub0r.android.callmeter.ui.PlansFragment.java

/**
 * Re-query database.//from w  w  w  .ja  v  a  2  s  .c  om
 *
 * @param forceUpdate force update
 */
public void requery(final boolean forceUpdate) {
    Log.d(TAG, "requery(", forceUpdate, ")");
    if (!this.ignoreQuery) {
        LoaderManager lm = getLoaderManager();
        if (forceUpdate && lm.getLoader(uid) != null) {
            lm.restartLoader(uid, null, this);
        } else {
            lm.initLoader(uid, null, this);
        }
    } else {
        Log.d(TAG, "requery(", forceUpdate, "): ignore");
    }
}

From source file:hku.fyp14017.blencode.ui.fragment.LookFragment.java

public void initOrRestartLoader(Bundle arguments) {
    LoaderManager loaderManager = getLoaderManager();

    if (loaderManager.getLoader(LookController.ID_LOADER_MEDIA_IMAGE) == null) {
        loaderManager.initLoader(LookController.ID_LOADER_MEDIA_IMAGE, arguments, this);
    } else {/*from   ww  w.j av a  2  s .c o  m*/
        loaderManager.restartLoader(LookController.ID_LOADER_MEDIA_IMAGE, arguments, this);
    }
}

From source file:it.geosolutions.geocollect.android.core.mission.PendingMissionListFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);

    Log.v("MISSION_LIST_FRAGMENT", "onAttach()");
    // Activities containing this fragment must implement its callbacks.
    if (!(activity instanceof Callbacks)) {
        throw new IllegalStateException("Activity must implement fragment's callbacks.");
    }/*from w w w.  j  av a  2  s  .com*/

    // If a previous instance of the database was attached, the loader must be restarted
    boolean needReload = false;
    if (db != null && db.dbversion().equals("unknown")) {
        needReload = true;
    }

    // Check for a database
    if (getSherlockActivity() instanceof PendingMissionListActivity) {
        Log.v(TAG, "Loader: Connecting to Activity database");
        db = ((PendingMissionListActivity) getSherlockActivity()).spatialiteDatabase;
        // restart the loader if needed
        if (needReload) {
            LoaderManager lm = getSherlockActivity().getSupportLoaderManager();
            if (lm.getLoader(CURRENT_LOADER_INDEX) != null) {
                lm.restartLoader(CURRENT_LOADER_INDEX, null, this);
            }
        }
    } else {
        Log.w(TAG, "Loader: Could not connect to Activity database");
    }

    listSelectionCallbacks = (Callbacks) activity;

}