Java Code Examples for android.support.v4.app.LoaderManager#getLoader()

The following examples show how to use android.support.v4.app.LoaderManager#getLoader() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SMSConversationsListFragment.java    From BlackList with Apache License 2.0 6 votes vote down vote up
private void loadListViewItems(int listPosition, boolean markSeen, boolean showProgress) {
    if (!isAdded()) {
        return;
    }
    int loaderId = 0;
    ConversationsLoaderCallbacks callbacks =
            new ConversationsLoaderCallbacks(getContext(), listView,
                    listPosition, cursorAdapter, markSeen, showProgress);

    LoaderManager manager = getLoaderManager();
    Loader<?> loader = manager.getLoader(loaderId);
    if (loader == null) {
        // init and run the items loader
        manager.initLoader(loaderId, null, callbacks);
    } else {
        // restart loader
        manager.restartLoader(loaderId, null, callbacks);
    }
}
 
Example 2
Source File: JournalFragment.java    From BlackList with Apache License 2.0 6 votes vote down vote up
private void loadListViewItems(String itemsFilter, boolean deleteItems, int listPosition) {
    if (!isAdded()) {
        return;
    }
    int loaderId = 0;
    JournalItemsLoaderCallbacks callbacks =
            new JournalItemsLoaderCallbacks(getContext(), cursorAdapter,
                    itemsFilter, deleteItems, listView, listPosition);
    LoaderManager manager = getLoaderManager();
    if (manager.getLoader(loaderId) == null) {
        // init and run the items loader
        manager.initLoader(loaderId, null, callbacks);
    } else {
        // restart loader
        manager.restartLoader(loaderId, null, callbacks);
    }
}
 
Example 3
Source File: SMSConversationFragment.java    From BlackList with Apache License 2.0 6 votes vote down vote up
private void loadListViewItems(int threadId, int unreadCount, int listPosition) {
    if (!isAdded()) {
        return;
    }
    int loaderId = 0;
    ConversationLoaderCallbacks callbacks =
            new ConversationLoaderCallbacks(getContext(),
                    threadId, unreadCount, listView, listPosition, cursorAdapter);

    LoaderManager manager = getLoaderManager();
    if (manager.getLoader(loaderId) == null) {
        // init and run the items loader
        manager.initLoader(loaderId, null, callbacks);
    } else {
        // restart loader
        manager.restartLoader(loaderId, null, callbacks);
    }
}
 
Example 4
Source File: ContactsFragment.java    From BlackList with Apache License 2.0 6 votes vote down vote up
private void loadListViewItems(String itemsFilter, boolean deleteItems, int listPosition) {
    if (!isAdded()) {
        return;
    }
    int loaderId = 0;
    ContactsLoaderCallbacks callbacks =
            new ContactsLoaderCallbacks(getContext(), contactType, cursorAdapter,
                    itemsFilter, deleteItems, listView, listPosition);
    LoaderManager manager = getLoaderManager();
    if (manager.getLoader(loaderId) == null) {
        // init and run the items loader
        manager.initLoader(loaderId, null, callbacks);
    } else {
        // restart loader
        manager.restartLoader(loaderId, null, callbacks);
    }
}
 
Example 5
Source File: PlansFragment.java    From callmeter with GNU General Public License v3.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@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);
    }
}
 
Example 6
Source File: PlansFragment.java    From callmeter with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Re-query database.
 *
 * @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");
    }
}
 
Example 7
Source File: MainActivity.java    From android-dev-challenge with Apache License 2.0 4 votes vote down vote up
/**
 * This method retrieves the search text from the EditText, constructs the
 * URL (using {@link NetworkUtils}) for the github repository you'd like to find, displays
 * that URL in a TextView, and finally request that an AsyncTaskLoader performs the GET request.
 */
private void makeGithubSearchQuery() {
    String githubQuery = mSearchBoxEditText.getText().toString();

    /*
     * If the user didn't enter anything, there's nothing to search for. In the case where no
     * search text was entered but the search button was clicked, we will display a message
     * stating that there is nothing to search for and we will not attempt to load anything.
     *
     * If there is text entered in the search box when the search button was clicked, we will
     * create the URL that will return our Github search results, display that URL, and then
     * pass that URL to the Loader. The reason we pass the URL as a String is simply a matter
     * of convenience. There are other ways of achieving this same result, but we felt this
     * was the simplest.
     */
    if (TextUtils.isEmpty(githubQuery)) {
        mUrlDisplayTextView.setText("No query entered, nothing to search for.");
        return;
    }

    URL githubSearchUrl = NetworkUtils.buildUrl(githubQuery);
    mUrlDisplayTextView.setText(githubSearchUrl.toString());

    Bundle queryBundle = new Bundle();
    queryBundle.putString(SEARCH_QUERY_URL_EXTRA, githubSearchUrl.toString());

    /*
     * Now that we've created our bundle that we will pass to our Loader, we need to decide
     * if we should restart the loader (if the loader already existed) or if we need to
     * initialize the loader (if the loader did NOT already exist).
     *
     * We do this by first store the support loader manager in the variable loaderManager.
     * All things related to the Loader go through through the LoaderManager. Once we have a
     * hold on the support loader manager, (loaderManager) we can attempt to access our
     * githubSearchLoader. To do this, we use LoaderManager's method, "getLoader", and pass in
     * the ID we assigned in its creation. You can think of this process similar to finding a
     * View by ID. We give the LoaderManager an ID and it returns a loader (if one exists). If
     * one doesn't exist, we tell the LoaderManager to create one. If one does exist, we tell
     * the LoaderManager to restart it.
     */
    LoaderManager loaderManager = getSupportLoaderManager();
    Loader<String> githubSearchLoader = loaderManager.getLoader(GITHUB_SEARCH_LOADER);
    if (githubSearchLoader == null) {
        loaderManager.initLoader(GITHUB_SEARCH_LOADER, queryBundle, this);
    } else {
        loaderManager.restartLoader(GITHUB_SEARCH_LOADER, queryBundle, this);
    }
}
 
Example 8
Source File: LogsFragment.java    From callmeter with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Set Adapter.
 *
 * @param forceUpdate force update
 */
public void setAdapter(final boolean forceUpdate) {
    LogAdapter adapter = (LogAdapter) getListAdapter();
    if (!forceUpdate && adapter != null && !adapter.isEmpty()) {
        return;
    }

    String where = DataProvider.Logs.TABLE + "." + DataProvider.Logs.TYPE + " in (-1";
    if (tbCall != null && tbCall.isChecked()) {
        where += "," + DataProvider.TYPE_CALL;
    }
    if (tbSMS != null && tbSMS.isChecked()) {
        where += "," + DataProvider.TYPE_SMS;
    }
    if (tbMMS != null && tbMMS.isChecked()) {
        where += "," + DataProvider.TYPE_MMS;
    }
    if (tbData != null && tbData.isChecked()) {
        where += "," + DataProvider.TYPE_DATA;
    }
    where += ") and " + DataProvider.Logs.TABLE + "." + DataProvider.Logs.DIRECTION + " in (-1";
    if (tbIn != null && tbIn.isChecked()) {
        where += "," + DataProvider.DIRECTION_IN;
    }
    if (tbOut != null && tbOut.isChecked()) {
        where += "," + DataProvider.DIRECTION_OUT;
    }
    where += ")";

    if (planId > 0L && tbPlan != null && tbPlan.isChecked()) {
        String plans = DataProvider.Plans.parseMergerWhere(getActivity()
                .getContentResolver(), planId);
        where = DbUtils.sqlAnd(plans, where);
        Log.d(TAG, "where: ", where);
    }
    Bundle args = new Bundle(1);
    args.putString("where", where);

    LoaderManager lm = getLoaderManager();
    if (lm.getLoader(LOADER_UID) == null) {
        lm.initLoader(LOADER_UID, args, this);
    } else {
        lm.restartLoader(LOADER_UID, args, this);
    }
}