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

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

Introduction

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

Prototype

public abstract <D> Loader<D> restartLoader(int id, Bundle args, LoaderManager.LoaderCallbacks<D> callback);

Source Link

Document

Starts a new or restarts an existing android.content.Loader in this manager, registers the callbacks to it, and (if the activity/fragment is currently started) starts loading it.

Usage

From source file:nu.firetech.android.pactrack.frontend.ParcelDetailsFragment.java

public void doRefresh() {
    LoaderManager lm = getLoaderManager();
    if (lm.getLoader(REFRESH_LOADER_ID) == null) {
        lm.initLoader(REFRESH_LOADER_ID, null, this);
    } else {/*from w w  w .ja  v  a2 s .  com*/
        lm.restartLoader(REFRESH_LOADER_ID, null, this);
    }
}

From source file:com.example.android.asynctaskloader.MainActivity.java

/**
 * 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.
 *//*from w  w w . ja  v  a2s.  c o  m*/
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);
    }
}

From source file:com.zns.comicdroid.activity.Comics.java

private void loadData() {
    final LoaderManager lm = getSupportLoaderManager();
    if (lm.getLoader(LOADER_ID) == null) {
        lm.initLoader(LOADER_ID, null, this);
    } else {/*from w ww. j a  v  a 2 s .  c  o  m*/
        lm.restartLoader(LOADER_ID, null, this);
    }
}

From source file:org.sufficientlysecure.keychain.ui.keyview.presenter.SystemContactPresenter.java

public void startLoader(LoaderManager loaderManager) {
    if (ContextCompat.checkSelfPermission(context,
            Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_DENIED) {
        Log.w(Constants.TAG, "loading linked system contact not possible READ_CONTACTS permission denied!");
        view.hideLinkedSystemContact();/*ww w.  j  a v a 2s  .  com*/
        return;
    }

    Bundle linkedContactData = new Bundle();

    // initialises loader for contact query so we can listen to any updates
    loaderManager.restartLoader(loaderId, linkedContactData, this);
}

From source file:org.dodgybits.shuffle.android.core.listener.CursorLoader.java

private void restartListLoading(Location location) {
    ViewMode viewMode = location.getViewMode();
    int listId = listId();
    Log.d(TAG, "Refreshing list cursor " + viewMode + " listId " + listId);
    final LoaderManager lm = mActivity.getSupportLoaderManager();
    switch (viewMode) {
    case TASK:/*from   ww w.j av a2  s  .  c o m*/
    case TASK_LIST:
    case SEARCH_RESULTS_LIST:
    case SEARCH_RESULTS_TASK:
        lm.restartLoader(listId, null, TASK_LIST_LOADER_CALLBACKS);
        break;
    case CONTEXT_LIST:
        lm.restartLoader(listId, null, CONTEXT_LIST_LOADER_CALLBACKS);
        break;
    case PROJECT_LIST:
        lm.restartLoader(listId, null, PROJECT_LIST_LOADER_CALLBACKS);
        break;
    case DELETED_LIST:
        lm.restartLoader(("task" + listId).hashCode(), null, TASK_LIST_LOADER_CALLBACKS);
        lm.restartLoader(("context" + listId).hashCode(), null, CONTEXT_LIST_LOADER_CALLBACKS);
        lm.restartLoader(("project" + listId).hashCode(), null, PROJECT_LIST_LOADER_CALLBACKS);
        break;
    default:
        // nothing to do
    }
}

From source file:net.niyonkuru.koodroid.ui.UsageFragment.java

@Override
public boolean onMenuItemClick(MenuItem item) {
    int id = item.getItemId();

    switch (id) {
    case R.id.edit_billing_cycle:
        Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
        cal.setTime((Date) mPeriodFrom.getTag());

        DatePickerDialog dialog = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() {
            @Override//  w w w. j a  v  a2s  .  co  m
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                ContentValues values = new ContentValues(1);
                values.put(Settings.BILLING_CYCLE, dayOfMonth);
                mContext.getContentResolver().insert(Settings.CONTENT_URI, values);
            }
        }, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE));

        dialog.setMessage(getResources().getString(R.string.billing_cycle_dialog));

        //                DatePicker datePicker = dialog.getDatePicker();
        //                datePicker.setMaxDate(System.currentTimeMillis());

        dialog.show();

        return true;
    case R.id.enable_airtime: {
        getLoaderManager().restartLoader(AIRTIME_TOKEN, null, this);
    }
    case R.id.disable_airtime:
        View airtimeContent = getView().findViewById(R.id.airtime_content);
        AnimUtils.show(airtimeContent);

        toggleService(Settings.AIRTIME_SERVICE, id == R.id.enable_airtime);

        /* refresh the widget to show or hide data */
        IntentUtils.updateWidget(mContext);

        return true;
    case R.id.refresh_airtime:
        sync(SyncService.AIRTIME);
        return true;
    case R.id.enable_data: {
        LoaderManager loaderManager = getLoaderManager();

        loaderManager.restartLoader(DATA_TOKEN, null, this);
        loaderManager.restartLoader(TEXT_TOKEN, null, this);
    }
    case R.id.disable_data:
        View dataContent = getView().findViewById(R.id.data_content);
        AnimUtils.show(dataContent);

        View textContent = getView().findViewById(R.id.text_content);
        AnimUtils.show(textContent);

        toggleService(Settings.USAGE_SERVICE, id == R.id.enable_data);

        /* refresh the widget to show or hide data */
        IntentUtils.updateWidget(mContext);

        return true;
    case R.id.refresh_data:
        sync(SyncService.USAGE);
        return true;
    case R.id.detail_data:
        mCallBack.onShowDataTransactions(getSubscriber());
        return true;
    }

    return false;
}

From source file:nu.firetech.android.pactrack.frontend.ParcelDetailsFragment.java

@Override
public void refreshDone() {
    int[] loaders = { PARCEL_LOADER_ID, EVENTS_LOADER_ID };

    LoaderManager lm = getLoaderManager();
    for (int loader_id : loaders) {
        if (lm.getLoader(loader_id) == null) {
            lm.initLoader(loader_id, null, this);
        } else {//from www  .ja va 2 s  .  c o m
            lm.restartLoader(loader_id, null, this);
        }
    }
}

From source file:org.totschnig.myexpenses.dialog.TransactionDetailFragment.java

public void fillData(Transaction o) {
    final FragmentActivity ctx = getActivity();
    mLayout.findViewById(R.id.progress).setVisibility(View.GONE);
    mTransaction = o;//from www. j  ava 2s  .  c om
    if (mTransaction == null) {
        TextView error = (TextView) mLayout.findViewById(R.id.error);
        error.setVisibility(View.VISIBLE);
        error.setText(R.string.transaction_deleted);
        return;
    }
    boolean doShowPicture = false;
    if (mTransaction.getPictureUri() != null) {
        doShowPicture = true;
        if (mTransaction.getPictureUri().getScheme().equals("file")) {
            if (!new File(mTransaction.getPictureUri().getPath()).exists()) {
                Toast.makeText(getActivity(), R.string.image_deleted, Toast.LENGTH_SHORT).show();
                doShowPicture = false;
            }
        }
    }
    AlertDialog dlg = (AlertDialog) getDialog();
    if (dlg != null) {
        Button btn = dlg.getButton(AlertDialog.BUTTON_POSITIVE);
        if (btn != null) {
            if (mTransaction.crStatus != Transaction.CrStatus.VOID) {
                btn.setEnabled(true);
            } else {
                btn.setVisibility(View.GONE);
            }
        }
        btn = dlg.getButton(AlertDialog.BUTTON_NEUTRAL);
        if (btn != null) {
            btn.setVisibility(doShowPicture ? View.VISIBLE : View.GONE);
        }
    }
    mLayout.findViewById(R.id.Table).setVisibility(View.VISIBLE);
    int title;
    boolean type = mTransaction.getAmount().getAmountMinor() > 0 ? ExpenseEdit.INCOME : ExpenseEdit.EXPENSE;

    if (mTransaction instanceof SplitTransaction) {
        mLayout.findViewById(R.id.SplitContainer).setVisibility(View.VISIBLE);
        //TODO: refactor duplicated code with SplitPartList
        title = R.string.split_transaction;
        View emptyView = mLayout.findViewById(R.id.empty);

        ListView lv = (ListView) mLayout.findViewById(R.id.list);
        // Create an array to specify the fields we want to display in the list
        String[] from = new String[] { KEY_LABEL_MAIN, KEY_AMOUNT };

        // and an array of the fields we want to bind those fields to 
        int[] to = new int[] { R.id.category, R.id.amount };

        // Now create a simple cursor adapter and set it to display
        mAdapter = new SplitPartAdapter(ctx, R.layout.split_part_row, null, from, to, 0,
                mTransaction.getAmount().getCurrency());
        lv.setAdapter(mAdapter);
        lv.setEmptyView(emptyView);

        LoaderManager manager = getLoaderManager();
        if (manager.getLoader(SPLIT_PART_CURSOR) != null && !manager.getLoader(SPLIT_PART_CURSOR).isReset()) {
            manager.restartLoader(SPLIT_PART_CURSOR, null, this);
        } else {
            manager.initLoader(SPLIT_PART_CURSOR, null, this);
        }

    } else {
        if (mTransaction instanceof Transfer) {
            title = R.string.transfer;
            ((TextView) mLayout.findViewById(R.id.AccountLabel)).setText(R.string.transfer_from_account);
            ((TextView) mLayout.findViewById(R.id.CategoryLabel)).setText(R.string.transfer_to_account);
        } else {
            title = type ? R.string.income : R.string.expense;
        }
    }

    String amountText;
    String accountLabel = Account.getInstanceFromDb(mTransaction.accountId).label;
    if (mTransaction instanceof Transfer) {
        ((TextView) mLayout.findViewById(R.id.Account)).setText(type ? mTransaction.label : accountLabel);
        ((TextView) mLayout.findViewById(R.id.Category)).setText(type ? accountLabel : mTransaction.label);
        if (((Transfer) mTransaction).isSameCurrency()) {
            amountText = formatCurrencyAbs(mTransaction.getAmount());
        } else {
            String self = formatCurrencyAbs(mTransaction.getAmount());
            String other = formatCurrencyAbs(mTransaction.getTransferAmount());
            amountText = type == ExpenseEdit.EXPENSE ? (self + " => " + other) : (other + " => " + self);
        }
    } else {
        ((TextView) mLayout.findViewById(R.id.Account)).setText(accountLabel);
        if ((mTransaction.getCatId() != null && mTransaction.getCatId() > 0)) {
            ((TextView) mLayout.findViewById(R.id.Category)).setText(mTransaction.label);
        } else {
            mLayout.findViewById(R.id.CategoryRow).setVisibility(View.GONE);
        }
        amountText = formatCurrencyAbs(mTransaction.getAmount());
    }

    //noinspection SetTextI18n
    ((TextView) mLayout.findViewById(R.id.Date))
            .setText(DateFormat.getDateInstance(DateFormat.FULL).format(mTransaction.getDate()) + " "
                    + DateFormat.getTimeInstance(DateFormat.SHORT).format(mTransaction.getDate()));

    ((TextView) mLayout.findViewById(R.id.Amount)).setText(amountText);

    if (!mTransaction.comment.equals("")) {
        ((TextView) mLayout.findViewById(R.id.Comment)).setText(mTransaction.comment);
    } else {
        mLayout.findViewById(R.id.CommentRow).setVisibility(View.GONE);
    }

    if (!mTransaction.referenceNumber.equals("")) {
        ((TextView) mLayout.findViewById(R.id.Number)).setText(mTransaction.referenceNumber);
    } else {
        mLayout.findViewById(R.id.NumberRow).setVisibility(View.GONE);
    }

    if (!mTransaction.payee.equals("")) {
        ((TextView) mLayout.findViewById(R.id.Payee)).setText(mTransaction.payee);
        ((TextView) mLayout.findViewById(R.id.PayeeLabel)).setText(type ? R.string.payer : R.string.payee);
    } else {
        mLayout.findViewById(R.id.PayeeRow).setVisibility(View.GONE);
    }

    if (mTransaction.methodId != null) {
        ((TextView) mLayout.findViewById(R.id.Method))
                .setText(PaymentMethod.getInstanceFromDb(mTransaction.methodId).getLabel());
    } else {
        mLayout.findViewById(R.id.MethodRow).setVisibility(View.GONE);
    }

    if (Account.getInstanceFromDb(mTransaction.accountId).type.equals(AccountType.CASH)) {
        mLayout.findViewById(R.id.StatusRow).setVisibility(View.GONE);
    } else {
        TextView tv = (TextView) mLayout.findViewById(R.id.Status);
        tv.setBackgroundColor(mTransaction.crStatus.color);
        tv.setText(mTransaction.crStatus.toString());
    }

    if (mTransaction.originTemplate == null) {
        mLayout.findViewById(R.id.PlannerRow).setVisibility(View.GONE);
    } else {
        ((TextView) mLayout.findViewById(R.id.Plan))
                .setText(mTransaction.originTemplate.getPlan() == null ? getString(R.string.plan_event_deleted)
                        : Plan.prettyTimeInfo(getActivity(), mTransaction.originTemplate.getPlan().rrule,
                                mTransaction.originTemplate.getPlan().dtstart));
    }

    dlg.setTitle(title);
    if (doShowPicture) {
        ImageView image = ((ImageView) dlg.getWindow().findViewById(android.R.id.icon));
        image.setVisibility(View.VISIBLE);
        image.setScaleType(ImageView.ScaleType.CENTER_CROP);
        Picasso.with(ctx).load(mTransaction.getPictureUri()).fit().into(image);
    }
}

From source file:com.rowland.moviesquire.ui.fragments.DetailFragment.java

public void onResume() {
    super.onResume();
    LoaderManager manager = getActivity().getSupportLoaderManager();

    manager.restartLoader(REVIEWS_LOADER_ID, null, mReviewLoaderCallBack);
    manager.restartLoader(TRAILERS_LOADER_ID, null, mTrailerLoaderCallBack);
}

From source file:com.github.jobs.ui.fragment.JobListFragment.java

private void queryList() {
    try {/*from w w w . j a  v  a 2  s.c o  m*/
        FragmentActivity activity = getActivity();
        if (activity == null || !isAdded()) {
            return;
        }
        LoaderManager loaderManager = activity.getSupportLoaderManager();
        Loader<Object> loader = loaderManager.getLoader(mCurrentSearch.hashCode());
        if (loader == null) {
            loaderManager.initLoader(mCurrentSearch.hashCode(), null, this);
        } else {
            loaderManager.restartLoader(mCurrentSearch.hashCode(), null, this);
        }
    } catch (IllegalStateException e) {
        // happens when activity is closed. We can't use isResumed since it will be false when the activity is
        // not being shown, thus it will cause problems if user loads another screen while this is still loading
    }
}