Example usage for android.provider BaseColumns _ID

List of usage examples for android.provider BaseColumns _ID

Introduction

In this page you can find the example usage for android.provider BaseColumns _ID.

Prototype

String _ID

To view the source code for android.provider BaseColumns _ID.

Click Source Link

Document

The unique ID for a row.

Usage

From source file:org.odk.collect.android.tasks.InstanceSyncTask.java

private void encryptInstance(Cursor instanceCursor, String candidateInstance, ContentValues values,
        InstancesDao instancesDao) throws EncryptionException, IOException {

    File instanceXml = new File(candidateInstance);
    if (!new File(instanceXml.getParentFile(), "submission.xml.enc").exists()) {
        Uri uri = Uri.parse(InstanceColumns.CONTENT_URI + "/"
                + instanceCursor.getInt(instanceCursor.getColumnIndex(BaseColumns._ID)));
        FormController.InstanceMetadata instanceMetadata = new FormController.InstanceMetadata(
                getInstanceIdFromInstance(candidateInstance), null, null);
        EncryptionUtils.EncryptedFormInformation formInfo = EncryptionUtils.getEncryptedFormInformation(uri,
                instanceMetadata);/* w  w w .  j a v  a2  s .  co m*/

        if (formInfo != null) {
            File submissionXml = new File(instanceXml.getParentFile(), "submission.xml");
            FileUtils.copyFile(instanceXml, submissionXml);

            EncryptionUtils.generateEncryptedSubmission(instanceXml, submissionXml, formInfo);

            values.put(InstanceColumns.CAN_EDIT_WHEN_COMPLETE, Boolean.toString(false));
            instancesDao.updateInstance(values, InstanceColumns.INSTANCE_FILE_PATH + "=?",
                    new String[] { candidateInstance });

            SaveToDiskTask.manageFilesAfterSavingEncryptedForm(instanceXml, submissionXml);
            if (!EncryptionUtils.deletePlaintextFiles(instanceXml)) {
                Timber.e("Error deleting plaintext files for %s", instanceXml.getAbsolutePath());
            }
        }
    }
}

From source file:com.rks.musicx.misc.utils.Helper.java

/**
 * Edit Song Tags//from www. ja v  a 2  s .  c o  m
 *
 * @param context
 * @param song
 * @return
 */
public static boolean editSongTags(Context context, Song song) {
    File f = new File(song.getmSongPath());
    if (f.exists()) {
        try {
            AudioFile audioFile = AudioFileIO.read(f);
            if (audioFile == null) {
                return false;
            }
            TagOptionSingleton.getInstance().setAndroid(true);
            Tag tag = audioFile.getTag();
            if (tag == null) {
                return false;
            }
            String year = song.getYear();
            String title = song.getTitle();
            String album = song.getAlbum();
            String artist = song.getArtist();
            String lyrics = song.getLyrics();
            tag.deleteField(FieldKey.LYRICS);
            tag.setField(FieldKey.LYRICS, Html.fromHtml(lyrics).toString());
            ContentValues values = new ContentValues();
            if (title != null) {
                tag.setField(FieldKey.TITLE, title);
                values.put(MediaStore.Audio.Media.TITLE, title);
            }
            if (artist != null) {
                tag.setField(FieldKey.ARTIST, artist);
                values.put(MediaStore.Audio.Media.ARTIST, artist);
            }
            if (album != null) {
                tag.setField(FieldKey.ALBUM, album);
                Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
                        new String[] { BaseColumns._ID, MediaStore.Audio.AlbumColumns.ALBUM,
                                MediaStore.Audio.AlbumColumns.ALBUM_KEY, MediaStore.Audio.AlbumColumns.ARTIST },
                        MediaStore.Audio.AlbumColumns.ALBUM + " = ?", new String[] { album },
                        MediaStore.Audio.Albums.DEFAULT_SORT_ORDER);

                if (cursor != null && cursor.moveToFirst()) {
                    long id = cursor.getLong(cursor.getColumnIndex(BaseColumns._ID));
                    values.put(MediaStore.Audio.Media.ALBUM_ID, id);
                    cursor.close();
                } else {
                    values.put(MediaStore.Audio.Media.ALBUM, album);
                }
            }
            if (song.getTrackNumber() != -1) {
                tag.setField(FieldKey.TRACK, String.valueOf(song.getTrackNumber()));
                values.put(MediaStore.Audio.Media.TRACK, song.getTrackNumber());
            }
            if (year != null && year.length() > 0) {
                tag.setField(FieldKey.YEAR, "" + year);
                values.put(MediaStore.Audio.Media.YEAR, year);
            }
            if (values.size() > 0) {
                context.getContentResolver().update(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, values,
                        android.provider.MediaStore.Audio.Media._ID + "=?",
                        new String[] { String.valueOf(song.getId()) });
            } else {
                return false;
            }
            audioFile.setTag(tag);
            AudioFileIO.write(audioFile);
        } catch (CannotReadException | CannotWriteException | InvalidAudioFrameException | TagException
                | IOException | ReadOnlyFileException e) {
            e.printStackTrace();
        }
        return true;
    } else {
        return false;
    }
}

From source file:ca.mudar.mtlaucasou.BaseMapFragment.java

/**
 * Get the list of Placemarks from the database and return them as array to
 * be added as OverlayItems in the map.//from ww  w. jav  a  2s .  c om
 * 
 * @return ArrayList of MarpMarkers
 */
protected ArrayList<MapMarker> fetchMapMarkers() {
    MapMarker mMapMarker;
    ArrayList<MapMarker> alLocations = new ArrayList<MapMarker>();

    Cursor cur = getActivity().getApplicationContext().getContentResolver()
            .query(mActivityHelper.getContentUri(indexSection), MAP_MARKER_PROJECTION, null, null, null);
    if (cur.moveToFirst()) {
        final int columnId = cur.getColumnIndexOrThrow(BaseColumns._ID);
        final int columnName = cur.getColumnIndexOrThrow(PlacemarkColumns.PLACEMARK_NAME);
        final int columnAddress = cur.getColumnIndexOrThrow(PlacemarkColumns.PLACEMARK_ADDRESS);
        final int columnGeoLat = cur.getColumnIndexOrThrow(PlacemarkColumns.PLACEMARK_GEO_LAT);
        final int columnGeoLng = cur.getColumnIndexOrThrow(PlacemarkColumns.PLACEMARK_GEO_LNG);

        do {
            mMapMarker = new MapMarker(cur.getInt(columnId), cur.getString(columnName),
                    cur.getString(columnAddress), cur.getDouble(columnGeoLat), cur.getDouble(columnGeoLng));
            alLocations.add(mMapMarker);

        } while (cur.moveToNext());
    }
    /**
     * Note: using startManagingCursor() crashed the application when
     * running on Honeycomb! So we don't manage the cursor and close it
     * manually here.
     */
    cur.close();

    return alLocations;
}

From source file:fr.openbike.android.database.OpenBikeDBAdapter.java

public void cleanAndInsertStations(long version, JSONArray jsonBikes) throws JSONException {
    if ("".equals(jsonBikes))
        return;//from w w  w . j a va 2s  .c  o m
    Cursor favorites = getFilteredStationsCursor(new String[] { BaseColumns._ID }, KEY_FAVORITE + " = 1", null);
    // Get count : hack for forcing cursor query
    favorites.getCount();
    int network = jsonBikes.getJSONObject(0).getInt(Station.NETWORK);
    mDb.delete(STATIONS_TABLE, KEY_NETWORK + " = ?", new String[] { String.valueOf(network) });
    mDb.delete(STATIONS_VIRTUAL_TABLE, KEY_NETWORK + " = ?", new String[] { String.valueOf(network) });
    insertStations(jsonBikes);
    while (favorites.moveToNext()) {
        updateFavorite(favorites.getInt(0), true);
    }
    favorites.close();
    mPreferences.edit().putLong(AbstractPreferencesActivity.STATIONS_VERSION, version).commit();
}

From source file:com.android.bluetooth.map.BluetoothMapContent.java

private void printMms(Cursor c) {
    if (D)/*from  www .j a va2 s.co m*/
        Log.d(TAG,
                "printMms " + BaseColumns._ID + ": " + c.getLong(c.getColumnIndex(BaseColumns._ID)) + "\n   "
                        + Mms.THREAD_ID + " : " + c.getLong(c.getColumnIndex(Mms.THREAD_ID)) + "\n   "
                        + Mms.MESSAGE_ID + " : " + c.getString(c.getColumnIndex(Mms.MESSAGE_ID)) + "\n   "
                        + Mms.SUBJECT + " : " + c.getString(c.getColumnIndex(Mms.SUBJECT)) + "\n   "
                        + Mms.CONTENT_TYPE + " : " + c.getString(c.getColumnIndex(Mms.CONTENT_TYPE)) + "\n   "
                        + Mms.TEXT_ONLY + " : " + c.getInt(c.getColumnIndex(Mms.TEXT_ONLY)) + "\n   " + Mms.DATE
                        + " : " + c.getLong(c.getColumnIndex(Mms.DATE)) + "\n   " + Mms.DATE_SENT + " : "
                        + c.getLong(c.getColumnIndex(Mms.DATE_SENT)) + "\n   " + Mms.READ + " : "
                        + c.getInt(c.getColumnIndex(Mms.READ)) + "\n   " + Mms.MESSAGE_BOX + " : "
                        + c.getInt(c.getColumnIndex(Mms.MESSAGE_BOX)) + "\n   " + Mms.STATUS + " : "
                        + c.getInt(c.getColumnIndex(Mms.STATUS)) + "\n   " + Mms.MESSAGE_TYPE + " : "
                        + c.getInt(c.getColumnIndex(Mms.MESSAGE_TYPE)));
}

From source file:com.pawnua.android.app.gpstrips.activities.TripDetailActivity.java

public void openThumbGallery() {
    Intent intent = new Intent(this, TripGalleryActivity.class);
    intent.putExtra(BaseColumns._ID, trip.getId());

    startActivity(intent);/*from  w w w  .  j  a va  2  s .com*/
}

From source file:com.pawnua.android.app.gpstrips.activities.TripDetailActivity.java

public void openMap() {
    Intent intent = new Intent(this, MapActivity.class);
    intent.putExtra(BaseColumns._ID, trip.getId());

    startActivity(intent);//from  w  w w.  j  a  v  a 2 s.  c  o m
}

From source file:fr.openbike.android.database.OpenBikeDBAdapter.java

public void setUpdateVersion(long version, int networkId) {
    ContentValues newValues = new ContentValues();
    newValues.put(KEY_VERSION, version);
    mDb.update(NETWORKS_TABLE, newValues, BaseColumns._ID + " = ?;",
            new String[] { String.valueOf(networkId) });
}

From source file:fr.openbike.android.database.OpenBikeDBAdapter.java

public boolean updateFavorite(int id, boolean isFavorite) {
    ContentValues newValues = new ContentValues();
    newValues.put(KEY_FAVORITE, isFavorite ? 1 : 0);
    return mDb.update(STATIONS_TABLE, newValues, BaseColumns._ID + " = ? AND " + KEY_NETWORK + " = ?;",
            new String[] { String.valueOf(id),
                    String.valueOf(mPreferences.getInt(AbstractPreferencesActivity.NETWORK_PREFERENCE,
                            AbstractPreferencesActivity.NO_NETWORK)) }) > 0;
}

From source file:pl.selvin.android.listsyncsample.ui.EditItemActivity.java

void SetupSpinner(final int sid, final Spinner spinner) {
    for (int i = 0; i < spinner.getCount(); i++) {
        Cursor value = (Cursor) spinner.getItemAtPosition(i);
        int id = value.getInt(value.getColumnIndex(BaseColumns._ID));
        if (id == sid) {
            spinner.setSelection(i);// www.  ja  va 2  s. c  om
            break;
        }
    }
}