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: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;// w ww . j a v a2s.  c o  m
    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.example.levelup.core.app.RegisterFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    LoaderManager loaderManager = getLoaderManager();

    if (mAccessTokenLoaderCallbacks != null) {
        mAccessTokenLoaderCallbacks.reconnectOrDismiss();
    }//from w w w.  j  a v  a 2  s .  c  om

    // Reconnect the loader callbacks.
    if (loaderManager.getLoader(LOADER_LOGIN) != null) {
        loaderManager.initLoader(LOADER_LOGIN, null, mAccessTokenLoaderCallbacks);
    }

    if (loaderManager.getLoader(LOADER_REGISTER) != null) {
        loaderManager.initLoader(LOADER_REGISTER, null, mRegisterLoaderCallbacks);
    }
}

From source file:com.kaliturin.blacklist.fragments.JournalFragment.java

private void loadListViewItems(String itemsFilter, boolean deleteItems, int listPosition) {
    if (!isAdded()) {
        return;//from www.  jav  a  2 s . c o  m
    }
    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);
    }
}

From source file:org.mozilla.search.autocomplete.SuggestionsFragment.java

public void loadSuggestions(String query) {
    final Bundle args = new Bundle();
    args.putString(KEY_SEARCH_TERM, query);
    final LoaderManager loaderManager = getLoaderManager();

    // Ensure that we don't try to restart a loader that doesn't exist. This becomes
    // an issue because SuggestionLoaderCallbacks.onCreateLoader can return null
    // as a loader if we don't have a suggestClient available yet.
    if (loaderManager.getLoader(LOADER_ID_SUGGESTION) == null) {
        loaderManager.initLoader(LOADER_ID_SUGGESTION, args, suggestionLoaderCallbacks);
    } else {/*from w ww.ja v  a  2  s  .  c o m*/
        loaderManager.restartLoader(LOADER_ID_SUGGESTION, args, suggestionLoaderCallbacks);
    }
}

From source file:com.kaliturin.blacklist.fragments.ContactsFragment.java

private void loadListViewItems(String itemsFilter, boolean deleteItems, int listPosition) {
    if (!isAdded()) {
        return;//from   w  ww.  j  a v  a 2s.c om
    }
    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);
    }
}

From source file:org.totschnig.myexpenses.util.Utils.java

public static void requireLoader(LoaderManager manager, int loaderId, Bundle args,
        LoaderManager.LoaderCallbacks callback) {
    if (manager.getLoader(loaderId) != null && !manager.getLoader(loaderId).isReset()) {
        manager.restartLoader(loaderId, args, callback);
    } else {//ww  w.j a va  2s.  co m
        manager.initLoader(loaderId, args, callback);
    }
}

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

/**
 * Set Adapter./*  w  w w .  j av  a2  s  . c  o  m*/
 *
 * @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);
    }
}

From source file:com.kafilicious.popularmovies.ui.activity.MainActivity.java

public void loadMovies(String sort, int page) {
    setSubtitle(sort);//from  ww w  .j a v  a2  s.  co m
    if (sort.equalsIgnoreCase(SORT_BY_FAVORITES))
        new FetchFavorites().execute();
    else {
        URL movieRequestUrl = NetworkUtils.buildUrl(sort, page);
        Log.i(TAG, "Formed URL: " + movieRequestUrl);
        Bundle queryBundle = new Bundle();
        queryBundle.putString(SEARCH_QUERY_URL_EXTRA, movieRequestUrl.toString());

        LoaderManager loaderManager = getSupportLoaderManager();

        Loader<MovieList> movieSearchLoader = loaderManager.getLoader(THEMOVIEDB_SEARCH_LOADER);

        if (movieSearchLoader == null) {
            loaderManager.initLoader(THEMOVIEDB_SEARCH_LOADER, queryBundle, this);
            Log.i(TAG, "Loader initialized");
        } else {
            loaderManager.restartLoader(THEMOVIEDB_SEARCH_LOADER, queryBundle, this);
            Log.i(TAG, "Loader restarted");
        }
    }
}

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

@Override
public void onRefresh() {
    mIssue = null;//from ww  w .  j a va2  s. com
    mEventsLoaded = false;
    mIsCollaborator = false;
    setContentShown(false);
    transitionHeaderToColor(R.attr.colorPrimary, R.attr.colorPrimaryDark);
    mHeader.setVisibility(View.GONE);

    // onRefresh() can be triggered in the draw loop, and CoordinatorLayout doesn't
    // like its child list being changed while drawing
    mHandler.post(new Runnable() {
        @Override
        public void run() {
            updateFabVisibility();
            updateCommentLockState();
        }
    });

    LoaderManager lm = getSupportLoaderManager();
    for (int i = 0; i < 3; i++) {
        lm.getLoader(i).onContentChanged();
    }
    super.onRefresh();
}

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

@Override
public void onRefresh() {
    mAllAssignee = null;/*from w  w w . ja v a  2  s.c o  m*/
    mAllMilestone = null;
    mAllLabels = null;
    mIsCollaborator = false;
    updateLabels();
    updateLabelStates();

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