Example usage for android.database Cursor getColumnIndexOrThrow

List of usage examples for android.database Cursor getColumnIndexOrThrow

Introduction

In this page you can find the example usage for android.database Cursor getColumnIndexOrThrow.

Prototype

int getColumnIndexOrThrow(String columnName) throws IllegalArgumentException;

Source Link

Document

Returns the zero-based index for the given column name, or throws IllegalArgumentException if the column doesn't exist.

Usage

From source file:com.android.providers.contacts.ContactsSyncAdapter.java

private static void addPhonesToContactEntry(ContentResolver cr, long personId, ContactEntry entry)
        throws ParseException {
    Cursor c = cr.query(Phones.CONTENT_URI, null, "person=" + personId, null, null);
    int numberIndex = c.getColumnIndexOrThrow(People.Phones.NUMBER);
    try {/*from ww w .  j a  v a2 s  . co m*/
        while (c.moveToNext()) {
            PhoneNumber phoneNumber = new PhoneNumber();
            cursorToContactsElement(phoneNumber, c, PROVIDER_TYPE_TO_ENTRY_PHONE);
            phoneNumber.setPhoneNumber(c.getString(numberIndex));
            entry.addPhoneNumber(phoneNumber);
        }
    } finally {
        if (c != null)
            c.close();
    }
}

From source file:com.samuelcastro.cordova.InstagramSharePlugin.java

public String getRealImagePathFromURI(Uri contentUri) {
    String res = null;//  www .j av  a 2 s.co m
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = cordova.getActivity().getContentResolver().query(contentUri, proj, null, null, null);
    if (cursor.moveToFirst()) {
        ;
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        res = cursor.getString(column_index);
    }
    cursor.close();
    return res;
}

From source file:de.golov.zeitgeistreich.ZeitGeistReichActivity.java

protected void submitImage(String tags) {
    Intent intent = getIntent();/*from  ww  w.  j a va 2 s.c o m*/
    Bundle extras = intent.getExtras();
    Uri mImageUri = null;
    File mFilename = null;
    if (Intent.ACTION_SEND.equals(intent.getAction()) && extras != null) {
        if (extras.containsKey(Intent.EXTRA_STREAM)) {
            mImageUri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
            if (mImageUri != null) {
                Cursor cursor = getContentResolver().query(mImageUri, null, null, null, null);
                if (cursor.moveToFirst()) {
                    mFilename = new File(cursor.getString(cursor.getColumnIndexOrThrow(ImageColumns.DATA)));
                }
                cursor.close();
                if (mFilename != null) {
                    ZeitGeistReichUploaderTask task = new ZeitGeistReichUploaderTask();
                    ZeitGeistObject o = new ZeitGeistObject(mFilename, tags);
                    task.execute(o);
                }
            }
        }
    }
}

From source file:com.google.android.apps.gutenberg.EditNoteFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    switch (loader.getId()) {
    case LOADER_ATTENDEE:
        if (cursor.getCount() > 0) {
            cursor.moveToFirst();/*w w w .  j  ava 2 s.co  m*/
            String note = cursor.getString(cursor.getColumnIndexOrThrow(Table.Attendee.NOTE));
            if (mEditNote != null) {
                mEditNote.setText(note);
            }
            String name = cursor.getString(cursor.getColumnIndexOrThrow(Table.Attendee.NAME));
            Dialog dialog = getDialog();
            if (dialog != null) {
                dialog.setTitle(name);
            }
        } else {
            Toast.makeText(getActivity(), "Error", Toast.LENGTH_SHORT).show();
            dismissAllowingStateLoss();
        }
        break;
    }
}

From source file:com.devgmail.mitroshin.totutu.util.StationCursorAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {

    mTextCountry = (TextView) view.findViewById(R.id.item_text_country);
    mTextStation = (TextView) view.findViewById(R.id.item_text_station);
    mTextCity = (TextView) view.findViewById(R.id.item_text_city);

    mStringCountry = cursor.getString(cursor.getColumnIndexOrThrow(mDatabaseHelper.COUNTRY_TITLE));
    mStringStation = cursor.getString(cursor.getColumnIndexOrThrow(mDatabaseHelper.STATION_TITLE));
    mStringCity = cursor.getString(cursor.getColumnIndexOrThrow(mDatabaseHelper.CITY_TITLE));

    mTextCountry.setText(mStringCountry);
    mTextStation.setText(mStringStation);
    mTextCity.setText(mStringCity);/*from w w w  .  j  av  a2  s  .co m*/
}

From source file:com.amaze.carbonfilemanager.utils.files.Futils.java

private static Uri fileToContentUri(Context context, String path, String volume) {
    String[] projection = null;//from  w w w  . jav a  2 s  .  c  o m
    final String where = MediaStore.MediaColumns.DATA + " = ?";
    Uri baseUri = MediaStore.Files.getContentUri(volume);
    boolean isMimeTypeImage = false, isMimeTypeVideo = false, isMimeTypeAudio = false;
    isMimeTypeImage = Icons.isPicture(path);
    if (!isMimeTypeImage) {
        isMimeTypeVideo = Icons.isVideo(path);
        if (!isMimeTypeVideo) {
            isMimeTypeAudio = Icons.isVideo(path);
        }
    }
    if (isMimeTypeImage || isMimeTypeVideo || isMimeTypeAudio) {
        projection = new String[] { BaseColumns._ID };
        if (isMimeTypeImage) {
            baseUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
        } else if (isMimeTypeVideo) {
            baseUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
        } else if (isMimeTypeAudio) {
            baseUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
        }
    } else {
        projection = new String[] { BaseColumns._ID, MediaStore.Files.FileColumns.MEDIA_TYPE };
    }
    ContentResolver cr = context.getContentResolver();
    Cursor c = cr.query(baseUri, projection, where, new String[] { path }, null);
    try {
        if (c != null && c.moveToNext()) {
            boolean isValid = false;
            if (isMimeTypeImage || isMimeTypeVideo || isMimeTypeAudio) {
                isValid = true;
            } else {
                int type = c.getInt(c.getColumnIndexOrThrow(MediaStore.Files.FileColumns.MEDIA_TYPE));
                isValid = type != 0;
            }

            if (isValid) {
                // Do not force to use content uri for no media files
                long id = c.getLong(c.getColumnIndexOrThrow(BaseColumns._ID));
                return Uri.withAppendedPath(baseUri, String.valueOf(id));
            }
        }
    } finally {
        if (c != null) {
            c.close();
        }
    }
    return null;
}

From source file:com.gelecekonline.android.uploadornek.MainActivity.java

/**
 * Content resolverdan data cekmek icin query
 * @param uri/*www.ja v  a2  s.c o m*/
 * @return
 */
public String getPath(Uri uri) {
    String[] projection = { MediaStore.Images.Media.DATA };
    Cursor cursor = managedQuery(uri, projection, null, null, null);
    if (cursor != null) {
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        return cursor.getString(column_index);
    } else
        return null;
}

From source file:ac.robinson.mediaphone.provider.NarrativeAdapter.java

public void bindView(View view, Context context, Cursor cursor) {
    NarrativeViewHolder holder = (NarrativeViewHolder) view.getTag();

    // only load column indices once
    if (mInternalIdIndex < 0) {
        mInternalIdIndex = cursor.getColumnIndexOrThrow(NarrativeItem.INTERNAL_ID);
        mCreationDateIndex = cursor.getColumnIndexOrThrow(NarrativeItem.DATE_CREATED);
        mSequenceIdIndex = cursor.getColumnIndexOrThrow(NarrativeItem.SEQUENCE_ID);
    }/*  w ww  .  ja v a 2s . co  m*/

    holder.narrativeInternalId = cursor.getString(mInternalIdIndex);
    holder.narrativeDateCreated = cursor.getLong(mCreationDateIndex);
    holder.narrativeSequenceId = cursor.getInt(mSequenceIdIndex);

    final BrowserActivity activity = mActivity;
    if (activity.getScrollState() == AbsListView.OnScrollListener.SCROLL_STATE_FLING
            || activity.isPendingIconsUpdate()) {
        holder.queryIcons = true;
        holder.frameList.setAdapter(mEmptyAdapter);
    } else {
        attachAdapter(holder);
        holder.queryIcons = false;
    }

    // alternating row colours
    int cursorPosition = cursor.getPosition();
    if ((cursor.getCount() - cursorPosition) % 2 == 0) { // so the colour stays the same when adding a new narrative
        holder.frameList.setBackgroundResource(
                mIsTemplateView ? R.color.template_list_dark : R.color.narrative_list_dark);
    } else {
        holder.frameList.setBackgroundResource(
                mIsTemplateView ? R.color.template_list_light : R.color.narrative_list_light);
    }
}

From source file:com.android.providers.contacts.ContactsSyncAdapter.java

private static void addOrganizationsToContactEntry(ContentResolver cr, long personId, ContactEntry entry)
        throws ParseException {
    Cursor c = cr.query(Organizations.CONTENT_URI, null, "person=" + personId, null, null);
    try {// w  w w  . j av a 2s. co  m
        int companyIndex = c.getColumnIndexOrThrow(Organizations.COMPANY);
        int titleIndex = c.getColumnIndexOrThrow(Organizations.TITLE);
        while (c.moveToNext()) {
            Organization organization = new Organization();
            cursorToContactsElement(organization, c, PROVIDER_TYPE_TO_ENTRY_ORGANIZATION);
            organization.setName(c.getString(companyIndex));
            organization.setTitle(c.getString(titleIndex));
            entry.addOrganization(organization);
        }
    } finally {
        if (c != null)
            c.close();
    }
}

From source file:com.dwdesign.tweetings.adapter.UserAutoCompleteAdapter.java

@Override
public void changeCursor(final Cursor cursor) {
    if (mCursorClosed)
        return;/* ww  w . ja v a 2s  .co m*/
    if (cursor != null) {
        if (mLookupText != null) {
            mStatusText = cursor.getColumnIndexOrThrow(Statuses.TEXT_PLAIN);
        } else {
            mProfileImageUrlIdx = cursor.getColumnIndexOrThrow(Statuses.PROFILE_IMAGE_URL);
            mScreenNameIdx = cursor.getColumnIndexOrThrow(CachedUsers.SCREEN_NAME);
        }
    }
    mCursor = cursor;
    super.changeCursor(mCursor);
}