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.totschnig.myexpenses.fragment.PlanList.java

@SuppressLint("NewApi")
@Override/*from   w  w  w  . j  av  a 2  s. c  o m*/
public void onLoadFinished(Loader<Cursor> loader, Cursor c) {
    int id = loader.getId();
    long expandedId = ((ManageTemplates) getActivity()).calledFromCalendarWithId;
    switch (id) {
    case TEMPLATES_CURSOR:
        mTemplatesCursor = c;
        if (!indexesCalculated) {
            columnIndexRowId = c.getColumnIndex(KEY_ROWID);
            columnIndexPlanId = c.getColumnIndex(KEY_PLANID);
            columnIndexAmount = c.getColumnIndex(KEY_AMOUNT);
            columnIndexLabelSub = c.getColumnIndex(KEY_LABEL_SUB);
            columnIndexComment = c.getColumnIndex(KEY_COMMENT);
            columnIndexPayee = c.getColumnIndex(KEY_PAYEE_NAME);
            columnIndexTitle = c.getColumnIndex(KEY_TITLE);
            columnIndexColor = c.getColumnIndex(KEY_COLOR);
            columnIndexTransferPeer = c.getColumnIndex(KEY_TRANSFER_PEER);
            columnIndexCurrency = c.getColumnIndex(KEY_CURRENCY);
            indexesCalculated = true;
        }
        int planCount = mTemplatesCursor.getCount();
        newPlanEnabled = planCount < 3;
        if (planCount > 0) {
            mTemplatesCursor.moveToFirst();
            ArrayList<Long> plans = new ArrayList<Long>();
            long templateId, planId;
            Bundle planBundle = new Bundle();
            while (mTemplatesCursor.isAfterLast() == false) {
                templateId = mTemplatesCursor.getLong(columnIndexRowId);
                if (expandedId == templateId) {
                    mExpandedPosition = mTemplatesCursor.getPosition();
                }
                Bundle instanceBundle = new Bundle();
                instanceBundle.putLong("template_id", templateId);
                //loader for instance2transactionmap
                int loaderId = mTemplatesCursor.getPosition() * 2 + 1;
                if (mManager.getLoader(loaderId) != null && !mManager.getLoader(loaderId).isReset()) {
                    mManager.restartLoader(loaderId, instanceBundle, this);
                } else {
                    mManager.initLoader(loaderId, instanceBundle, this);
                }
                if ((planId = mTemplatesCursor.getLong(columnIndexPlanId)) != 0L) {
                    plans.add(planId);
                }
                mTemplatesCursor.moveToNext();
            }
            planBundle.putSerializable("plans", plans);
            if (mManager.getLoader(PLANS_CURSOR) != null && !mManager.getLoader(PLANS_CURSOR).isReset()) {
                mManager.restartLoader(PLANS_CURSOR, planBundle, this);
            } else {
                mManager.initLoader(PLANS_CURSOR, planBundle, this);
            }
        } else {
            mPlanTimeInfo = new HashMap<Long, String>();
            mAdapter.setGroupCursor(mTemplatesCursor);
        }
        break;
    case PLANS_CURSOR:
        mPlanTimeInfo = new HashMap<Long, String>();
        c.moveToFirst();
        while (c.isAfterLast() == false) {
            mPlanTimeInfo.put(c.getLong(c.getColumnIndex(Events._ID)), Plan.prettyTimeInfo(getActivity(),
                    c.getString(c.getColumnIndex(Events.RRULE)), c.getLong(c.getColumnIndex(Events.DTSTART))));
            c.moveToNext();
        }
        mAdapter.setGroupCursor(mTemplatesCursor);
        if (mExpandedPosition != -1) {
            mListView.expandGroup(mExpandedPosition);
        }
        break;
    default:
        int groupPosition = id / 2;
        if (id % 2 == 0) {
            //check if group still exists
            if (mAdapter.getGroupId(groupPosition) != 0) {
                mAdapter.setChildrenCursor(groupPosition, c);
                if (mExpandedPosition != -1) {
                    mListView.setSelectionFromTop(mExpandedPosition, 0);
                }
            }
        } else {
            c.moveToFirst();
            while (c.isAfterLast() == false) {
                mInstance2TransactionMap.put(c.getLong(c.getColumnIndex(KEY_INSTANCEID)),
                        c.getLong(c.getColumnIndex(KEY_TRANSACTIONID)));
                c.moveToNext();
            }
        }
    }
}

From source file:org.xbmc.kore.ui.ArtistOverviewFragment.java

/** {@inheritDoc} */
@Override//from  w  w w  .ja va  2 s .c  om
public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
    if (cursor != null && cursor.getCount() > 0) {
        switch (cursorLoader.getId()) {
        case LOADER_ARTIST:
            displayArtistDetails(cursor);
            break;
        case LOADER_ALBUMS:
            createAlbumList(cursor);
            getLoaderManager().initLoader(LOADER_SONGS, null, this);
            break;
        case LOADER_SONGS:
            downloadSongs(cursor);
        }
    }
}

From source file:net.reichholf.dreamdroid.fragment.abs.BaseHttpFragment.java

@Override
public void onLoadFinished(Loader<LoaderResult<ExtendedHashMap>> loader, LoaderResult<ExtendedHashMap> result) {
    mHttpHelper.onLoadFinished();/*from w  ww .j  a  va2 s  .  c  o  m*/
    setCurrentTitle(getLoadFinishedTitle());
    getAppCompatActivity().setTitle(getCurrentTitle());
    if (result.isError()) {
        showToast(result.getErrorText());
        return;
    }
    applyData(loader.getId(), result.getResult());
}

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

public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    // Swap the new cursor in. (The framework will take care of closing the
    // old cursor once we return.)
    switch (loader.getId()) {
    case LOADER_ID_KEYRING:
        if (data.moveToFirst()) {
            // get name, email, and comment from USER_ID
            String[] mainUserId = PgpKeyHelper.splitUserId(data.getString(KEYRING_INDEX_USER_ID));
            if (mainUserId[0] != null) {
                getActivity().setTitle(mainUserId[0]);
                mName.setText(mainUserId[0]);
            } else {
                getActivity().setTitle(R.string.user_id_no_name);
                mName.setText(R.string.user_id_no_name);
            }//  w  w w.j  a va 2s .c om
            mEmail.setText(mainUserId[1]);
            mComment.setText(mainUserId[2]);
        }

        break;
    case LOADER_ID_USER_IDS:
        mUserIdsAdapter.swapCursor(data);
        break;
    case LOADER_ID_KEYS:
        // the first key here is our master key
        if (data.moveToFirst()) {
            // get key id from MASTER_KEY_ID
            long keyId = data.getLong(KEYS_INDEX_KEY_ID);
            String keyIdStr = PgpKeyHelper.convertKeyIdToHex(keyId);
            mKeyId.setText(keyIdStr);

            // get creation date from CREATION
            if (data.isNull(KEYS_INDEX_CREATION)) {
                mCreation.setText(R.string.none);
            } else {
                Date creationDate = new Date(data.getLong(KEYS_INDEX_CREATION) * 1000);

                mCreation.setText(
                        DateFormat.getDateFormat(getActivity().getApplicationContext()).format(creationDate));
            }

            // get expiry date from EXPIRY
            if (data.isNull(KEYS_INDEX_EXPIRY)) {
                mExpiry.setText(R.string.none);
            } else {
                Date expiryDate = new Date(data.getLong(KEYS_INDEX_EXPIRY) * 1000);

                mExpiry.setText(
                        DateFormat.getDateFormat(getActivity().getApplicationContext()).format(expiryDate));
            }

            String algorithmStr = PgpKeyHelper.getAlgorithmInfo(data.getInt(KEYS_INDEX_ALGORITHM),
                    data.getInt(KEYS_INDEX_KEY_SIZE));
            mAlgorithm.setText(algorithmStr);

            byte[] fingerprintBlob = data.getBlob(KEYS_INDEX_FINGERPRINT);
            if (fingerprintBlob == null) {
                // FALLBACK for old database entries
                fingerprintBlob = ProviderHelper.getFingerprint(getActivity(), mDataUri);
            }
            String fingerprint = PgpKeyHelper.convertFingerprintToHex(fingerprintBlob);

            mFingerprint.setText(PgpKeyHelper.colorizeFingerprint(fingerprint));
        }

        mKeysAdapter.swapCursor(data);
        break;

    default:
        break;
    }
}

From source file:com.jbirdvegas.mgerrit.PatchSetViewerFragment.java

@Override
public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
    CommitDetailsAdapter.Cards cardType = null;

    switch (cursorLoader.getId()) {
    case LOADER_PROPERTIES:
        cardType = CommitDetailsAdapter.Cards.PROPERTIES;
        break;// w  w w . j a  v a 2  s  .  com
    case LOADER_MESSAGE:
        cardType = CommitDetailsAdapter.Cards.COMMIT_MSG;
        break;
    case LOADER_FILES:
        cardType = CommitDetailsAdapter.Cards.CHANGED_FILES;
        break;
    case LOADER_REVIEWERS:
        cardType = CommitDetailsAdapter.Cards.REVIEWERS;
        break;
    case LOADER_COMMENTS:
        cardType = CommitDetailsAdapter.Cards.COMMENTS;
        break;
    }
    if (cardType != null)
        mAdapter.setCursor(cardType, cursor);
}

From source file:net.reichholf.dreamdroid.fragment.abs.AbstractHttpFragment.java

@Override
public void onLoadFinished(Loader<LoaderResult<ExtendedHashMap>> loader, LoaderResult<ExtendedHashMap> result) {
    mHttpHelper.onLoadFinished();/*from   w  w w.  j  ava  2 s . c  om*/
    setCurrentTitle(getLoadFinishedTitle());
    getActionBarActivity().setTitle(getCurrentTitle());
    if (result.isError()) {
        showToast(result.getErrorText());
        return;
    }
    applyData(loader.getId(), result.getResult());
}

From source file:nl.sogeti.android.gpstracker.actions.NameTrack.java

@Override
public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
    if (cursorLoader.getId() == STARTSTATIONCURSOR_LOADER) {
        mStartStationSimpleCursorAdapter.swapCursor(cursor);
    } else {/*from w ww . j ava2  s .c o m*/
        mEndStationSimpleCursorAdapter.swapCursor(cursor);
    }
}

From source file:de.elanev.studip.android.app.frontend.courses.CourseOverviewFragment.java

public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {

    if (getActivity() == null) {
        return;//from  w  w w  . ja  va 2s  . c  o m
    }
    cursor.moveToFirst();

    int loaderId = loader.getId();
    switch (loaderId) {
    case COURSE_LOADER:

        if (!cursor.isAfterLast()) {
            String courseTitle = cursor
                    .getString(cursor.getColumnIndex(CoursesContract.Columns.Courses.COURSE_TITLE));
            String courseDescription = cursor
                    .getString(cursor.getColumnIndex(CoursesContract.Columns.Courses.COURSE_DESCIPTION));
            int courseTyp = cursor.getInt(cursor.getColumnIndex(CoursesContract.Columns.Courses.COURSE_TYPE));

            mTitleTextView.setText(courseTitle);
            getActivity().setTitle(courseTitle);
            String courseTypeString = Settings
                    .fromJson(Prefs.getInstance(getActivity()).getApiSettings()).semTypes.get(courseTyp).name;
            mCourseTypeTextView.setText(courseTypeString);
            if (!TextUtils.isEmpty(courseDescription)) {
                mDescriptionTextView.setText(courseDescription);
                mDescriptionTextView.setMovementMethod(new ScrollingMovementMethod());
            }

        }
        break;
    case COURSE_EVENTS_LOADER:
        if (cursor.getCount() >= 1) {

            String room = cursor.getString(cursor.getColumnIndex(EventsContract.Columns.EVENT_ROOM));
            String title = cursor.getString(cursor.getColumnIndex(EventsContract.Columns.EVENT_TITLE));
            mNextAppointmentTextView.setText(String.format("%s\n%s", title, room));
        }

        break;
    case COURSE_NEWS_LOADER:
        if (cursor.getCount() >= 1) {

            final String newsTopic = cursor.getString(cursor.getColumnIndex(NewsContract.Columns.NEWS_TOPIC));
            final Long newsDate = cursor.getLong(cursor.getColumnIndex(NewsContract.Columns.NEWS_MKDATE));
            final String newsBody = cursor.getString(cursor.getColumnIndex(NewsContract.Columns.NEWS_BODY));
            final String userForename = cursor
                    .getString(cursor.getColumnIndex(UsersContract.Columns.USER_FORENAME));
            final String userLastname = cursor
                    .getString(cursor.getColumnIndex(UsersContract.Columns.USER_LASTNAME));

            mNewsTitleTextView.setText(newsTopic);
            mNewsAuthorTextView.setText(TextTools.getLocalizedAuthorAndDateString(
                    String.format("%s %s", userForename, userLastname), newsDate, getActivity()));
            mNewsAuthorTextView.setVisibility(View.VISIBLE);
            mNewsShowMoreTextView.setVisibility(View.VISIBLE);
            mNewsTextTextView.setText(Html.fromHtml(newsBody));

        }
        break;
    case COURSE_TEACHERS_LOADER:
        String teachersString;
        if (!cursor.isAfterLast()) {
            String teacherAvatarUrl = cursor
                    .getString(cursor.getColumnIndex(UsersContract.Columns.USER_AVATAR_NORMAL));
            teachersString = TextTools.createNameSting(
                    cursor.getString(cursor.getColumnIndex(UsersContract.Columns.USER_TITLE_PRE)),
                    cursor.getString(cursor.getColumnIndex(UsersContract.Columns.USER_FORENAME)),
                    cursor.getString(cursor.getColumnIndex(UsersContract.Columns.USER_LASTNAME)),
                    cursor.getString(cursor.getColumnIndex(UsersContract.Columns.USER_TITLE_POST)));
            mTeacherNameTextView.setText(teachersString);

            int teacherCount = cursor.getCount();
            if (teacherCount > 1) {
                teacherCount -= 1;
                mTeacherCountTextView
                        .setText(String.format(getString(R.string.and_more_teachers), teacherCount));
                mTeacherCountTextView.setVisibility(View.VISIBLE);
            }

            Picasso.with(mContext).load(teacherAvatarUrl)
                    .resizeDimen(R.dimen.user_image_icon_size, R.dimen.user_image_icon_size).centerCrop()
                    .placeholder(R.drawable.nobody_normal).into(mUserImageView);
        }
        break;
    }

}

From source file:cz.maresmar.sfm.view.user.UserDetailFragment.java

@Override
public void onLoaderReset(@NonNull Loader<Cursor> loader) {
    switch (loader.getId()) {
    case USER_LOADER_ID:
        Timber.e("User data %s is no longer valid", mUserUri);
        // Let's tread current user data as new entry
        reset(null);// w  w  w  . j a  v  a 2s.  c o  m
        break;
    default:
        throw new UnsupportedOperationException("Unknown loader id: " + loader.getId());
    }
}

From source file:com.money.manager.ex.reports.IncomeVsExpensesListFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    switch (loader.getId()) {
    case ID_LOADER_REPORT:
        //                ((IncomeVsExpensesAdapter) getListAdapter()).swapCursor(data);
        ((IncomeVsExpensesAdapter) getListAdapter()).changeCursor(data);

        if (isResumed()) {
            setListShown(true);/*w w  w.  java 2  s. com*/
        } else {
            setListShownNoAnimation(true);
        }
        // calculate income, expenses
        double income = 0, expenses = 0;
        if (data == null)
            return;

        while (data.moveToNext()) {
            if (data.getInt(data.getColumnIndex(
                    IncomeVsExpenseReportEntity.Month)) != IncomeVsExpensesActivity.SUBTOTAL_MONTH) {
                income += data.getDouble(data.getColumnIndex(IncomeVsExpenseReportEntity.Income));
                expenses += data.getDouble(data.getColumnIndex(IncomeVsExpenseReportEntity.Expenses));
            }
        }
        updateListViewFooter(mFooterListView, income, expenses);
        if (data.getCount() > 0) {
            getListView().removeFooterView(mFooterListView);
            getListView().addFooterView(mFooterListView);
        }

        if (((IncomeVsExpensesActivity) getActivity()).mIsDualPanel) {
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    showChart();
                }
            }, 1 * 1000);
        }
        break;

    case ID_LOADER_YEARS:
        if (data != null && data.moveToFirst()) {
            while (!data.isAfterLast()) {
                int year = data.getInt(data.getColumnIndex("Year"));
                if (mYearsSelected.get(year, false) == false) {
                    mYearsSelected.put(year, false);
                }
                data.moveToNext();
            }
            startLoader();
        }
    }
}