android.support.v4.content.Loader Java Examples

The following examples show how to use android.support.v4.content.Loader. 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: OrderDetail.java    From Woodmin with Apache License 2.0 6 votes vote down vote up
@Override
public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
    switch (cursorLoader.getId()) {
        case ORDER_LOADER:
            mOrderSelected = null;
            if (cursor.moveToFirst()) {
                do {
                    String json = cursor.getString(COLUMN_ORDER_COLUMN_JSON);
                    if(json!=null){
                        mOrderSelected = mGson.fromJson(json, Order.class);
                    }
                } while (cursor.moveToNext());
                fillView();
            }
            break;
        default:
            break;
    }
}
 
Example #2
Source File: MainActivity.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
@Override
public void onLoadFinished(Loader<String> loader, String data) {

    /* When we finish loading, we want to hide the loading indicator from the user. */
    mLoadingIndicator.setVisibility(View.INVISIBLE);
    /*
     * If the results are null, we assume an error has occurred. There are much more robust
     * methods for checking errors, but we wanted to keep this particular example simple.
     */
    if (null == data) {
        showErrorMessage();
    } else {
        mSearchResultsTextView.setText(data);
        showJsonDataView();
    }
}
 
Example #3
Source File: WhatsNewViewBinder.java    From fdroidclient with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onLoadFinished(@NonNull Loader<Cursor> loader, Cursor cursor) {
    if (loader.getId() != LOADER_ID) {
        return;
    }

    whatsNewAdapter.setAppsCursor(cursor);

    if (whatsNewAdapter.getItemCount() == 0) {
        emptyState.setVisibility(View.VISIBLE);
        appList.setVisibility(View.GONE);
        explainEmptyStateToUser();
    } else {
        emptyState.setVisibility(View.GONE);
        appList.setVisibility(View.VISIBLE);
    }
}
 
Example #4
Source File: ClassifyFragment.java    From android-galaxyzoo with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onLoadFinished(final Loader<Cursor> cursorLoader, final Cursor cursor) {
    if (cursorLoader.getId() != ClassifyFragment.LOADER_ID_NEXT_ID) {
        return;
    }

    mCursor = cursor;
    mGetNextInProgress = false;

    updateFromCursor();

    // Avoid this being called twice, which seems to be an Android bug,
    // and which could cause us to get a different item ID if our virtual "next" item changes to
    // another item:
    // See http://stackoverflow.com/questions/14719814/onloadfinished-called-twice
    // and https://code.google.com/p/android/issues/detail?id=63179
    getLoaderManager().destroyLoader(ClassifyFragment.LOADER_ID_NEXT_ID);
}
 
Example #5
Source File: ManLocalArchiveFragment.java    From Man-Man with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onLoadFinished(Loader<List<File>> loader, List<File> manPageFiles) {
    if(mLocalPageList.getHeaderViewsCount() > 0) {
        mLocalPageList.removeHeaderView(mLocalPageList.getChildAt(0));
        mLocalPageList.removeHeaderView(mLocalPageList.getChildAt(1));
    }
    mLocalPageList.setAdapter(null); // for android < kitkat for header to work properly

    if(manPageFiles.isEmpty()) {
        mSearchLocalPage.setVisibility(View.GONE);
        View header1 = View.inflate(getActivity(), R.layout.add_folder_header, null);
        View header2 = View.inflate(getActivity(), R.layout.load_archive_header, null);
        mLocalPageList.addHeaderView(header1);
        mLocalPageList.addHeaderView(header2);
    } else {
        mSearchLocalPage.setVisibility(View.VISIBLE);
    }
    mLocalPageList.setAdapter(new LocalArchiveArrayAdapter(getActivity(), R.layout.chapter_command_list_item, R.id.command_name_label, manPageFiles));
}
 
Example #6
Source File: TopicsListFragment.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
private boolean isStreamLoading() {
    if (isAdded()) {
        final Loader loader = getLoaderManager().getLoader(TOPICS_LOADER_ID);
        if (loader != null) {
            return ((LatestTopicsLoader) loader).isLoading();
        }
    }
    return true;
}
 
Example #7
Source File: EventSelectionFragment.java    From attendee-checkin with Apache License 2.0 5 votes vote down vote up
@Override
public void onLoaderReset(Loader<Cursor> loader) {
    switch (loader.getId()) {
        case LOADER_EVENTS: {
            mAdapter.swapCursor(null);
            break;
        }
    }
}
 
Example #8
Source File: TopicsListFragment.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
private boolean streamHasMoreResults() {
    if (isAdded()) {
        final Loader loader = getLoaderManager().getLoader(TOPICS_LOADER_ID);
        if (loader != null) {
            return ((LatestTopicsLoader) loader).hasMoreResults();
        }
    }
    return false;
}
 
Example #9
Source File: ExplorerActivity.java    From PowerFileExplorer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void addConnection(OpenMode service) {

    try {
        if (cloudHandler.findEntry(service) != null) {
            // cloud entry already exists
            Toast.makeText(this, getResources().getString(R.string.connection_exists),
			   Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(ExplorerActivity.this, getResources().getString(R.string.please_wait), Toast.LENGTH_LONG).show();
            Bundle args = new Bundle();
            args.putInt(ARGS_KEY_LOADER, service.ordinal());

            // check if we already had done some work on the loader
            Loader loader = getSupportLoaderManager().getLoader(REQUEST_CODE_CLOUD_LIST_KEY);
            if (loader != null && loader.isStarted()) {
                // making sure that loader is not started
                getSupportLoaderManager().destroyLoader(REQUEST_CODE_CLOUD_LIST_KEY);
            }
            getSupportLoaderManager().initLoader(REQUEST_CODE_CLOUD_LIST_KEY, args, this);
        }
    } catch (CloudPluginException e) {
        e.printStackTrace();
        Toast.makeText(this, getResources().getString(R.string.cloud_error_plugin),
		   Toast.LENGTH_LONG).show();
    }
}
 
Example #10
Source File: CategoriesViewBinder.java    From fdroidclient with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onLoaderReset(Loader<Cursor> loader) {
    if (loader.getId() != LOADER_ID) {
        return;
    }

    categoryAdapter.setCategories(Collections.<String>emptyList());
}
 
Example #11
Source File: QuestRewardFragment.java    From MonsterHunter4UDatabase with MIT License 5 votes vote down vote up
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
	// Create an adapter to point at this cursor

	QuestRewardListCursorAdapter adapter = new QuestRewardListCursorAdapter(
			getActivity(), (QuestRewardCursor) cursor);
	setListAdapter(adapter);

}
 
Example #12
Source File: QuickQueueFragment.java    From mobile-manager-tool with MIT License 5 votes vote down vote up
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    // Check for database errors
    if (data == null) {
        return;
    }

    mMediaIdIndex = data.getColumnIndexOrThrow(BaseColumns._ID);
    mTitleIndex = data.getColumnIndexOrThrow(MediaColumns.TITLE);
    mArtistIndex = data.getColumnIndexOrThrow(AudioColumns.ARTIST);
    mAlbumIndex = data.getColumnIndexOrThrow(AudioColumns.ALBUM);
    mAlbumIdIndex = data.getColumnIndexOrThrow(AudioColumns.ALBUM_ID);
    mQuickQueueAdapter.changeCursor(data);
    mCursor = data;
}
 
Example #13
Source File: EssAlbumCollection.java    From FilePicker with MIT License 5 votes vote down vote up
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    Context context = mContext.get();
    if (context == null) {
        return;
    }

    mCallbacks.onAlbumMediaLoad(data);
}
 
Example #14
Source File: TVShowFragment.java    From android with Apache License 2.0 5 votes vote down vote up
@Override
public void onLoadFinished(Loader<List<TVShow>> loader, List<TVShow> tvShows) {

    mProgressBar.setVisibility(View.GONE);

    if (tvShows == null || tvShows.isEmpty()) {
        mListView.setEmptyView(mEmptyView);
        mRootView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getLoaderManager().restartLoader(2, null, TVShowFragment.this);
                mProgressBar.setVisibility(View.VISIBLE);
            }
        });
    } else {

        if (mListView != null && mListView.getFooterViewsCount() == 0 && tvShows.size() == 24) {
            mListView.addFooterView(mFooterView);
        }

        if (mStartPage == 1 || mAdapter.getCount() < 24) {
            mAdapter.clear();
        }

        mAdapter.buildData(tvShows);
        mStartPage++;
    }
}
 
Example #15
Source File: ItemMonsterFragment.java    From MonsterHunter4UDatabase with MIT License 5 votes vote down vote up
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
	// Create an adapter to point at this cursor
	ItemHuntingRewardListCursorAdapter adapter = new ItemHuntingRewardListCursorAdapter(
			getActivity(), (HuntingRewardCursor) cursor);
	setListAdapter(adapter);

}
 
Example #16
Source File: RecordsActivity.java    From android-auto-call-recorder with MIT License 5 votes vote down vote up
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    if (!mProgressBar.isShown()) {
        mProgressBar.setVisibility(View.VISIBLE);
    }
    String[] projection = args.getStringArray(RecordsActivity.args.projection.name());
    String selection = args.getString(RecordsActivity.args.selection.name());
    String[] selectionArgs = args.getStringArray(RecordsActivity.args.selectionArguments.name());
    String sort = mPreferenceHelper.getSortSelection()
            + mPreferenceHelper.getSortArrange();
    int limit = args.getInt(RecordsActivity.args.limit.name());
    int offset = args.getInt(RecordsActivity.args.offset.name());

    switch (id) {
        case 0:
            Uri uri = RecordDbContract.CONTENT_URL
                    .buildUpon()
                    .appendQueryParameter(RecordsContentProvider.QUERY_PARAMETER_LIMIT,
                            String.valueOf(limit))
                    .appendQueryParameter(RecordsContentProvider.QUERY_PARAMETER_OFFSET,
                            String.valueOf(offset))
                    .build();
            return new CursorLoader(this, uri, projection, selection, selectionArgs, sort);

        default:
            throw new IllegalArgumentException("no loader id handled!");
    }
}
 
Example #17
Source File: DetailActivity.java    From android-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    data.moveToFirst();

    TextView nameTv = (TextView) findViewById(R.id.name_tv);
    nameTv.setText(data.getString(data.getColumnIndex("name")));

    TextView idTv = (TextView) findViewById(R.id.id_tv);
    idTv.setText(data.getLong(data.getColumnIndex("_id")) + "");
}
 
Example #18
Source File: FragmentContainer2.java    From Contacts with MIT License 5 votes vote down vote up
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args)
{
	// Easy way to limit the query to contacts with phone numbers.
	String selection = SELECTION + getAdditionalFilters();
	
	return new CursorLoader(getActivity(),  // Context
			getUri(),       // URI representing the table/resource to be queried
			null,      // projection - the list of columns to return. Null means "all"
			selection, // selection - Which rows to return (condition rows must match)
			getSelectionArgs(),      // selection args - can be provided separately and subbed into selection.
			SORT_BY);   // string specifying sort order
}
 
Example #19
Source File: AccountsEditListFragment.java    From CSipSimple with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
	 return new CursorLoader(getActivity(), SipProfile.ACCOUNT_URI, new String[] {
		SipProfile.FIELD_ID + " AS " + BaseColumns._ID,
		SipProfile.FIELD_ID,
		SipProfile.FIELD_DISPLAY_NAME,
		SipProfile.FIELD_WIZARD,
		SipProfile.FIELD_ACTIVE
	 }, null, null, null);
	 
}
 
Example #20
Source File: MainActivity.java    From android-dev-challenge with Apache License 2.0 5 votes vote down vote up
/**
 * Called by the {@link android.support.v4.app.LoaderManagerImpl} when a new Loader needs to be
 * created. This Activity only uses one loader, so we don't necessarily NEED to check the
 * loaderId, but this is certainly best practice.
 *
 * @param loaderId The loader ID for which we need to create a loader
 * @param bundle   Any arguments supplied by the caller
 * @return A new Loader instance that is ready to start loading.
 */
@Override
public Loader<Cursor> onCreateLoader(int loaderId, Bundle bundle) {


    switch (loaderId) {

        case ID_FORECAST_LOADER:
            /* URI for all rows of weather data in our weather table */
            Uri forecastQueryUri = WeatherContract.WeatherEntry.CONTENT_URI;
            /* Sort order: Ascending by date */
            String sortOrder = WeatherContract.WeatherEntry.COLUMN_DATE + " ASC";
            /*
             * A SELECTION in SQL declares which rows you'd like to return. In our case, we
             * want all weather data from today onwards that is stored in our weather table.
             * We created a handy method to do that in our WeatherEntry class.
             */
            String selection = WeatherContract.WeatherEntry.getSqlSelectForTodayOnwards();

            return new CursorLoader(this,
                    forecastQueryUri,
                    MAIN_FORECAST_PROJECTION,
                    selection,
                    null,
                    sortOrder);

        default:
            throw new RuntimeException("Loader Not Implemented: " + loaderId);
    }
}
 
Example #21
Source File: DialogsListFragment.java    From q-municate-android with Apache License 2.0 5 votes vote down vote up
@Override
    public void onLoadFinished(Loader<List<DialogWrapper>> loader, List<DialogWrapper> dialogsList) {
        updateDialogsProcess = State.started;
        Log.d(TAG, "onLoadFinished!!! dialogsListLoader.isLoadCacheFinished() " + dialogsListLoader.isLoadCacheFinished());
        if (dialogsListLoader.isLoadCacheFinished()) {
            //clear queue after loading all dialogs from cache before updating all dialogs from REST
            loaderConsumerQueue.clear();
        } else {
            updateDialogsListFromQueue();
        }

        updateDialogsAdapter(dialogsList);

        checkEmptyList(dialogsListAdapter.getCount());

        if (!baseActivity.isDialogLoading()) {
            baseActivity.hideSnackBar(R.string.dialog_loading_dialogs);
        }

//        startForResult load dialogs from REST when finished loading from cache
        if (dialogsListLoader.isLoadCacheFinished()) {
            if (baseActivity.isChatInitializedAndUserLoggedIn()) {
                Log.v(TAG, " onLoadFinished --- !QBLoginChatCompositeCommand.isRunning()");
                QBLoadDialogsCommand.start(getContext(), true);
            }
        }
    }
 
Example #22
Source File: NGWLoginFragment.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onLoadFinished(
        @NonNull Loader<String> loader,
        String token)
{
    mSignInButton.setEnabled(true);
    if (null != mGuestButton) { // needed for overrides
        mGuestButton.setEnabled(true);
    }

    String accountName = "";
    try {
        String url = mUrlText;
        if (!url.startsWith("http")) {
            url = "http://" + url;
        }
        URI uri = new URI(url);
        if (uri.getHost() != null && uri.getHost().length() > 0) {
            accountName += uri.getHost();
        }
        if (uri.getPort() != 80 && uri.getPort() > 0) {
            accountName += ":" + uri.getPort();
        }
        if (uri.getPath() != null && uri.getPath().length() > 0) {
            accountName += uri.getPath();
        }
    } catch (URISyntaxException e) {
        accountName = mUrlText;
    }

    mUrlText = mUrlWithProtocol.get();
    if (loader.getId() == R.id.auth_token_loader) {
        if (token != null && token.length() > 0)
            onTokenReceived(accountName, token);
        else
            Toast.makeText(getActivity(), R.string.error_login, Toast.LENGTH_SHORT).show();
    } else if (loader.getId() == R.id.non_auth_token_loader)
        onTokenReceived(accountName, Constants.NGW_ACCOUNT_GUEST);
}
 
Example #23
Source File: MainActivity.java    From android-dev-challenge with Apache License 2.0 5 votes vote down vote up
/**
 * Called when a previously created loader is being reset, and thus making its data unavailable.
 * The application should at this point remove any references it has to the Loader's data.
 *
 * @param loader The Loader that is being reset.
 */
@Override
public void onLoaderReset(Loader<Cursor> loader) {
    /*
     * Since this Loader's data is now invalid, we need to clear the Adapter that is
     * displaying the data.
     */
    mForecastAdapter.swapCursor(null);
}
 
Example #24
Source File: ArenaQuestRewardFragment.java    From MonsterHunter4UDatabase with MIT License 5 votes vote down vote up
@SuppressLint("NewApi")
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
	// You only ever load the runs, so assume this is the case
	long arenaId = args.getLong(ARG_ARENA_QUEST_ID, -1);
	
	return new ArenaQuestRewardListCursorLoader(getActivity(), 
			ArenaQuestRewardListCursorLoader.FROM_ARENA_QUEST, arenaId);
}
 
Example #25
Source File: DataEntryActivity.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Loader<Form> onCreateLoader(int id, Bundle args) {
    DatasetInfoHolder info = getIntent().getExtras()
            .getParcelable(DatasetInfoHolder.TAG);

    if (id == LOADER_FORM_ID && info != null) {
        return new DataLoader(DataEntryActivity.this, info);
    }

    return null;
}
 
Example #26
Source File: Base.java    From COCOFramework with Apache License 2.0 5 votes vote down vote up
/**
 * Get exception from loader if it provides one by being a
 * {@link ThrowableLoader}
 *
 * @param loader
 * @return exception or null if none provided
 */
protected Exception getException(final Loader<T> loader) {
    if (loader instanceof ThrowableLoader) {
        return ((ThrowableLoader<T>) loader).clearException();
    } else {
        return null;
    }
}
 
Example #27
Source File: MonsterListFragment.java    From MonsterHunter4UDatabase with MIT License 5 votes vote down vote up
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
	// You only ever load the runs, so assume this is the case
	String mTab = null;
	if (args != null) {
		mTab = args.getString(ARG_TAB);
	}

	return new MonsterListCursorLoader(getActivity(), mTab);
}
 
Example #28
Source File: LoaderThrottleSupport.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    mAdapter.swapCursor(data);

    // The list should now be shown.
    if (isResumed()) {
        setListShown(true);
    } else {
        setListShownNoAnimation(true);
    }
}
 
Example #29
Source File: ASBActivity.java    From MonsterHunter4UDatabase with MIT License 5 votes vote down vote up
@Override
public void onLoadFinished(Loader<ASBSession> loader, ASBSession run) {
    session = run;

    // Initialization
    adapter = new ASBPagerAdapter(getSupportFragmentManager(), session);
    viewPager.setAdapter(adapter);
    mSlidingTabLayout.setViewPager(viewPager);

    updateASBSetChangedListeners();
}
 
Example #30
Source File: CitiesFragment.java    From sms-ticket with Apache License 2.0 5 votes vote down vote up
@Override
public void onLoadFinished(Loader<Object> loader, Object data) {
    if (!isAdded()) {
        return;
    }
    if (loader.getId() == Constants.LOADER_CITIES) {
        mAdapter = new CitiesAdapter(c, (List<CitiesAdapter.Item>)data);
        vList.setAdapter(mAdapter);
    }
}