Example usage for android.support.v4.content Loader getId

List of usage examples for android.support.v4.content Loader getId

Introduction

In this page you can find the example usage for android.support.v4.content Loader getId.

Prototype

public int getId() 

Source Link

Usage

From source file:org.sufficientlysecure.keychain.ui.ViewKeyFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    /* TODO better error handling? May cause problems when a key is deleted,
     * because the notification triggers faster than the activity closes.
     */// w w  w. j av a 2 s . c  om
    if (data == null) {
        return;
    }
    // Swap the new cursor in. (The framework will take care of closing the
    // old cursor once we return.)
    switch (loader.getId()) {
    case LOADER_ID_UNIFIED: {
        if (data.getCount() == 1 && data.moveToFirst()) {

            mIsSecret = data.getInt(INDEX_HAS_ANY_SECRET) != 0;
            mFingerprint = data.getBlob(INDEX_FINGERPRINT);
            long masterKeyId = data.getLong(INDEX_MASTER_KEY_ID);

            // init other things after we know if it's a secret key
            initUserIds(mIsSecret);
            initLinkedIds(mIsSecret);
            initLinkedContactLoader(masterKeyId, mIsSecret);
            initCardButtonsVisibility(mIsSecret);
        }
        break;
    }

    case LOADER_ID_USER_IDS: {
        setContentShown(true, false);
        mUserIdsAdapter.swapCursor(data);

        break;
    }

    case LOADER_ID_LINKED_IDS: {
        mLinkedIdsAdapter.swapCursor(data);

        if (mIsSecret) {
            mLinkedIdsCard.setVisibility(View.VISIBLE);
            mLinkedIdsEmpty.setVisibility(mLinkedIdsAdapter.getCount() > 0 ? View.GONE : View.VISIBLE);
        } else {
            mLinkedIdsCard.setVisibility(mLinkedIdsAdapter.getCount() > 0 ? View.VISIBLE : View.GONE);
            mLinkedIdsEmpty.setVisibility(View.GONE);
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && mPostponeType == PostponeType.LINKED) {
            mLinkedIdsCard.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
                @TargetApi(VERSION_CODES.LOLLIPOP)
                @Override
                public boolean onPreDraw() {
                    mLinkedIdsCard.getViewTreeObserver().removeOnPreDrawListener(this);
                    getActivity().startPostponedEnterTransition();
                    return true;
                }
            });
        }
        break;
    }

    case LOADER_ID_LINKED_CONTACT: {
        if (data.moveToFirst()) { // if we have a linked contact
            long contactId = data.getLong(INDEX_CONTACT_ID);
            loadLinkedSystemContact(contactId);
        }
        break;
    }
    }
}

From source file:com.money.manager.ex.account.AccountTransactionListFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    switch (loader.getId()) {
    case ID_LOADER_SUMMARY:
        if (data != null && data.moveToFirst()) {
            String balance = Double.toString(data.getDouble(data.getColumnIndex(QueryAccountBills.TOTAL)));
            mAccountBalance = MoneyFactory.fromString(balance);
            String reconciled = Double
                    .toString(data.getDouble(data.getColumnIndex(QueryAccountBills.RECONCILED)));
            mAccountReconciled = MoneyFactory.fromString(reconciled);
        } else {//ww  w  .ja v a2 s  .  com
            mAccountBalance = MoneyFactory.fromString("0");
            mAccountReconciled = MoneyFactory.fromString("0");
        }
        // show balance values
        setTextViewBalance();
        break;

    case AllDataListFragment.ID_LOADER_ALL_DATA_DETAIL:
        // Notification received from AllDataListFragment.
        // Once the transactions are loaded, load the summary data.
        getLoaderManager().restartLoader(ID_LOADER_SUMMARY, null, this);
        // load/reset running balance
        populateRunningBalance();

        break;
    }
}

From source file:com.gsma.rcs.ri.messaging.OneToOneTalkView.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    if (LOADER_ID == loader.getId()) {
        /*//from  w ww. j  av  a  2 s  .c o m
         * The asynchronous load is complete and the data is now available for use. Only now can
         * we associate the queried Cursor with the CursorAdapter.
         */
        mAdapter.swapCursor(data);
        /**
         * Registering content observer for XMS message content URI. When this content URI will
         * change, this will notify the loader to reload its data.
         */
        if (mObserver != null && !mObserver.getLoader().equals(loader)) {
            ContentResolver resolver = getContentResolver();
            resolver.unregisterContentObserver(mObserver);
            mObserver = null;
        }
        if (mObserver == null) {
            if (LogUtils.isActive) {
                Log.d(LOGTAG, "onLoadFinished: register content observer");
            }
            mObserver = new ChatCursorObserver(new Handler(), loader);
            ContentResolver resolver = getContentResolver();
            resolver.registerContentObserver(ChatLog.Message.CONTENT_URI, true, mObserver);
            resolver.registerContentObserver(FileTransferLog.CONTENT_URI, true, mObserver);
        }
    }
}

From source file:android.com.example.contactslist.ui.ContactsListFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    // This swaps the new cursor into the adapter.
    if (loader.getId() == ContactsQuery.QUERY_ID) {
        mAdapter.swapCursor(data);//from w w w .  j a  v a 2 s.c  o  m

        // If this is a two-pane layout and there is a search query then
        // there is some additional work to do around default selected
        // search item.
        if (mIsTwoPaneLayout && !TextUtils.isEmpty(mSearchTerm) && mSearchQueryChanged) {
            // Selects the first item in results, unless this fragment has
            // been restored from a saved state (like orientation change)
            // in which case it selects the previously selected search item.
            if (data != null && data.moveToPosition(mPreviouslySelectedSearchItem)) {
                // Creates the content Uri for the previously selected contact by appending the
                // contact's ID to the Contacts table content Uri
                final Uri uri = Uri.withAppendedPath(Contacts.CONTENT_URI,
                        String.valueOf(data.getLong(ContactsQuery.ID)));
                mOnContactSelectedListener.onContactSelected(uri);
                getListView().setItemChecked(mPreviouslySelectedSearchItem, true);
            } else {
                // No results, clear selection.
                onSelectionCleared();
            }
            // Only restore from saved state one time. Next time fall back
            // to selecting first item. If the fragment state is saved again
            // then the currently selected item will once again be saved.
            mPreviouslySelectedSearchItem = 0;
            mSearchQueryChanged = false;
        }
    }
}

From source file:com.onegravity.contactpicker.core.ContactPickerActivity.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    switch (loader.getId()) {
    case CONTACTS_LOADER_ID:
        readContacts(cursor);/*from   www.  j  a  va  2s . c  om*/
        // contacts loaded --> load the contact details
        getSupportLoaderManager().initLoader(CONTACT_DETAILS_LOADER_ID, null, this);
        break;

    case CONTACT_DETAILS_LOADER_ID:
        readContactDetails(cursor);
        break;

    case GROUPS_LOADER_ID: {
        readGroups(cursor);
        break;
    }
    }
}

From source file:com.money.manager.ex.home.HomeFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    switch (loader.getId()) {
    case LOADER_ACCOUNT_BILLS:
        try {//from w  w w. j a va2s .c  o m
            renderAccountsList(data);
        } catch (Exception e) {
            Timber.e(e, "rendering account list");
        }

        // set total for accounts in the main Drawer.
        EventBus.getDefault().post(new AccountsTotalLoadedEvent(txtTotalAccounts.getText().toString()));
        break;

    case LOADER_INCOME_EXPENSES:
        double income = 0, expenses = 0;
        if (data != null) {
            while (data.moveToNext()) {
                expenses = data.getDouble(data.getColumnIndex(IncomeVsExpenseReportEntity.Expenses));
                income = data.getDouble(data.getColumnIndex(IncomeVsExpenseReportEntity.Income));
            }
        }
        TextView txtIncome = (TextView) getActivity().findViewById(R.id.textViewIncome);
        TextView txtExpenses = (TextView) getActivity().findViewById(R.id.textViewExpenses);
        TextView txtDifference = (TextView) getActivity().findViewById(R.id.textViewDifference);
        // set value
        if (txtIncome != null)
            txtIncome.setText(mCurrencyService.getCurrencyFormatted(mCurrencyService.getBaseCurrencyId(),
                    MoneyFactory.fromDouble(income)));
        if (txtExpenses != null)
            txtExpenses.setText(mCurrencyService.getCurrencyFormatted(mCurrencyService.getBaseCurrencyId(),
                    MoneyFactory.fromDouble(Math.abs(expenses))));
        if (txtDifference != null)
            txtDifference.setText(mCurrencyService.getCurrencyFormatted(mCurrencyService.getBaseCurrencyId(),
                    MoneyFactory.fromDouble(income - Math.abs(expenses))));
        // manage progressbar
        final ProgressBar barIncome = (ProgressBar) getActivity().findViewById(R.id.progressBarIncome);
        final ProgressBar barExpenses = (ProgressBar) getActivity().findViewById(R.id.progressBarExpenses);

        if (barIncome != null && barExpenses != null) {
            barIncome.setMax((int) (Math.abs(income) + Math.abs(expenses)));
            barExpenses.setMax((int) (Math.abs(income) + Math.abs(expenses)));

            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
                ObjectAnimator animationIncome = ObjectAnimator.ofInt(barIncome, "progress",
                        (int) Math.abs(income));
                animationIncome.setDuration(1000); // 0.5 second
                animationIncome.setInterpolator(new DecelerateInterpolator());
                animationIncome.start();

                ObjectAnimator animationExpenses = ObjectAnimator.ofInt(barExpenses, "progress",
                        (int) Math.abs(expenses));
                animationExpenses.setDuration(1000); // 0.5 second
                animationExpenses.setInterpolator(new DecelerateInterpolator());
                animationExpenses.start();
            } else {
                barIncome.setProgress((int) Math.abs(income));
                barExpenses.setProgress((int) Math.abs(expenses));
            }
        }
        break;
    }

    // Close the cursor.
    MmxDatabaseUtils.closeCursor(data);
}

From source file:com.example.android.contactslist.ui.groupsEditor.GroupsEditorFragment.java

@Override
public void onLoaderReset(Loader<Cursor> loader) {
    if (loader.getId() == GroupsListStatsQuery.QUERY_ID) {
        // When the loader is being reset, clear the cursor from the adapter. This allows the
        // cursor resources to be freed.
        mAdapter.swapCursor(null);//from   w w  w.  j a va2 s .c  o m
    }
}

From source file:org.thialfihar.android.apg.ui.ImportKeysListFragment.java

@Override
public void onLoadFinished(Loader<AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>> loader,
        AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>> data) {
    // Swap the new cursor in. (The framework will take care of closing the
    // old cursor once we return.)

    Log.d(Constants.TAG, "data: " + data.getResult());

    // swap in the real data!
    mAdapter.setData(data.getResult());/*w w w. j av a  2s  .  co  m*/
    mAdapter.notifyDataSetChanged();

    setListAdapter(mAdapter);

    // The list should now be shown.
    if (isResumed()) {
        setListShown(true);
    } else {
        setListShownNoAnimation(true);
    }

    Exception error = data.getError();

    switch (loader.getId()) {
    case LOADER_ID_BYTES:

        if (error == null) {
            // No error
        } else if (error instanceof ImportKeysListLoader.FileHasNoContent) {
            AppMsg.makeText(getActivity(), R.string.error_import_file_no_content, AppMsg.STYLE_ALERT).show();
        } else if (error instanceof ImportKeysListLoader.NonPgpPartException) {
            AppMsg.makeText(getActivity(),
                    ((ImportKeysListLoader.NonPgpPartException) error).getCount() + " "
                            + getResources().getQuantityString(R.plurals.error_import_non_pgp_part,
                                    ((ImportKeysListLoader.NonPgpPartException) error).getCount()),
                    new AppMsg.Style(AppMsg.LENGTH_LONG, R.color.confirm)).show();
        } else {
            AppMsg.makeText(getActivity(), R.string.error_generic_report_bug,
                    new AppMsg.Style(AppMsg.LENGTH_LONG, R.color.alert)).show();
        }
        break;

    case LOADER_ID_SERVER_QUERY:
        if (error == null) {
            AppMsg.makeText(getActivity(), getResources().getQuantityString(R.plurals.keys_found,
                    mAdapter.getCount(), mAdapter.getCount()), AppMsg.STYLE_INFO).show();
        } else if (error instanceof KeyServer.InsufficientQuery) {
            AppMsg.makeText(getActivity(), R.string.error_keyserver_insufficient_query, AppMsg.STYLE_ALERT)
                    .show();
        } else if (error instanceof KeyServer.QueryException) {
            AppMsg.makeText(getActivity(), R.string.error_keyserver_query, AppMsg.STYLE_ALERT).show();
        } else if (error instanceof KeyServer.TooManyResponses) {
            AppMsg.makeText(getActivity(), R.string.error_keyserver_too_many_responses, AppMsg.STYLE_ALERT)
                    .show();
        }
        break;

    default:
        break;
    }
}

From source file:org.totschnig.myexpenses.fragment.TransactionList.java

@Override
public void onLoaderReset(Loader<Cursor> arg0) {
    switch (arg0.getId()) {
    case TRANSACTION_CURSOR:
        mTransactionsCursor = null;/*  w  ww .ja  va 2s .c o  m*/
        ((SimpleCursorAdapter) mAdapter).swapCursor(null);
        hasItems = false;
        break;
    case SUM_CURSOR:
        mappedCategories = false;
        mappedPayees = false;
        mappedMethods = false;
        break;
    case GROUPING_CURSOR:
        mGroupingCursor = null;
    }
}

From source file:com.silentcircle.contacts.list.ScContactEntryListFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    if (!mEnabled) {
        return;/*from w  w w  .ja  va 2s .c  om*/
    }

    int loaderId = loader.getId();
    if (loaderId == DIRECTORY_LOADER_ID) {
        mDirectoryListStatus = STATUS_LOADED;
        mAdapter.changeDirectories(data);
        startLoading();
    } else {
        onPartitionLoaded(loaderId, data);
        if (isSearchMode()) {
            int directorySearchMode = getDirectorySearchMode();
            if (directorySearchMode != DirectoryListLoader.SEARCH_MODE_NONE) {
                if (mDirectoryListStatus == STATUS_NOT_LOADED) {
                    mDirectoryListStatus = STATUS_LOADING;
                    getLoaderManager().initLoader(DIRECTORY_LOADER_ID, null, this);
                } else {
                    startLoading();
                }
            }
        } else {
            mDirectoryListStatus = STATUS_NOT_LOADED;
            getLoaderManager().destroyLoader(DIRECTORY_LOADER_ID);
        }
    }
}