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.catnut.plugin.fantasy.Photo.java

@Override
public ContentValues convert(JSONObject data) {
    ContentValues photo = new ContentValues();
    photo.put(BaseColumns._ID, data.optLong(Constants.ID));
    photo.put(name, data.optString(name));
    photo.put(description, data.optString(description));
    photo.put(image_url, data.optString(image_url));
    photo.put(width, data.optInt(width));
    photo.put(height, data.optInt(height));
    return photo;
}

From source file:com.espian.ticktock.TickTockActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {

    case R.id.menu_new:
        startActivityForResult(new Intent(this, AddEditActivity.class), 1);
        break;/*from ww  w. j av  a 2  s .co m*/

    case R.id.menu_delete:
        if (mPagerAdapter.getCount() == 0)
            Toast.makeText(this, R.string.no_delete, Toast.LENGTH_SHORT).show();
        else {
            String idString = ((CountdownFragment) mPagerAdapter.getItem(mPager.getCurrentItem()))
                    .getCountdownId();
            int i = getContentResolver().delete(TickTockProvider.countdownUri, BaseColumns._ID + "=?",
                    new String[] { idString });
            if (i != 0)
                getLoaderManager().restartLoader(0, null, this);
            else
                Toast.makeText(this, R.string.failed_delete, Toast.LENGTH_SHORT).show();
            mPagerAdapter.notifyDataSetChanged();
        }
        return true;

    case R.id.menu_edit:
        if (mPagerAdapter.getCount() == 0)
            Toast.makeText(this, R.string.no_edit, Toast.LENGTH_SHORT).show();
        else {
            String idString2 = ((CountdownFragment) mPagerAdapter.getItem(mPager.getCurrentItem()))
                    .getCountdownId();
            startActivityForResult(new Intent(this, AddEditActivity.class).putExtra(BaseColumns._ID, idString2),
                    1);
        }
        return true;

    }
    return true;
}

From source file:fr.seeks.SuggestionProvider.java

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {

    String query = uri.getLastPathSegment();

    if (query == null || query.equals("") || query.equals("search_suggest_query"))
        return null;

    Log.v(TAG, "Request '" + query + "' for '" + uri + "'");

    MatrixCursor matrix = new MatrixCursor(
            new String[] { BaseColumns._ID, KEY_TITLE, KEY_DESCRIPTION, KEY_QUERY, KEY_ACTION, KEY_URL });

    Boolean instant_suggest = mPrefs.getBoolean("instant_suggest", false);
    if (instant_suggest) {
        setCursorOfQuery(uri, query, matrix);
    } else {//  ww  w.  jav a2s .  com
        perhapsSetCursorOfQuery(uri, query, matrix);
    }
    matrix.setNotificationUri(getContext().getContentResolver(), uri);

    return matrix;
}

From source file:org.catnut.plugin.zhihu.Zhihu.java

@Override
public ContentValues convert(JSONArray array) {
    long now = System.currentTimeMillis();

    ContentValues item = new ContentValues();

    // ??item???//from  ww w . j  ava2  s . co m
    item.put(BaseColumns._ID, now);

    // 
    item.put(STATUS, array.optString(1));
    item.put(ANSWER, array.optString(2));
    item.put(LAST_ALTER_DATE, array.optLong(4) * 1000);
    item.put(ANSWER_ID, array.optLong(5));

    // 
    JSONArray user = array.optJSONArray(6);
    if (user != null) {
        item.put(NICK, user.optString(0));
        item.put(UID, user.optString(1));
        item.put(AVATAR, user.optInt(2));
    }

    // 
    JSONArray question = array.optJSONArray(7);
    if (question != null) {
        item.put(TITLE, question.optString(1, null));
        item.put(DESCRIPTION, question.optString(2));
        item.put(QUESTION_ID, question.optLong(3));
    }

    return item;
}

From source file:com.binoy.vibhinna.VibhinnaFragment.java

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

    setHasOptionsMenu(true);// w  w  w.  ja v a2  s .  c om

    String[] from = { "name", "desc", "status", "path", "folder", BaseColumns._ID };
    int[] to = { R.id.name, R.id.desc, R.id.status, R.id.path };

    adapter = new VibhinnaAdapter(getActivity(), R.layout.main_row, null, from, to,
            SimpleCursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
    setListAdapter(adapter);
}

From source file:com.github.longkai.zhihu.util.Utils.java

public static void createTables(SQLiteDatabase db) {
    StringBuilder sql = new StringBuilder();
    // ?/*from   ww  w . j  a  va  2s  .c  om*/
    // _id ??id
    sql.append("CREATE TABLE ").append(ITEMS).append("(").append(BaseColumns._ID).append(" int,")
            .append(QUESTION_ID).append(" int NOT NULL,").append(TITLE).append(" text NOT NULL,")
            .append(DESCRIPTION).append(" text,").append(STARRED).append(" int,").append(ANSWERED)
            .append(" int,").append(VIEWED).append(" int,").append(TOPICS).append(" text,")

            .append(ANSWER_ID).append(" int NOT NULL,").append(ANSWER).append(" text,").append(VOTE)
            .append(" int PRIMARY KEY,").append(LAST_ALTER_DATE).append(" int,").append(VOTERS).append(" text,")

            .append(UID).append(" text,").append(NICK).append(" text,").append(STATUS).append(" text,")
            .append(AVATAR).append(" text").append(")");

    db.execSQL(sql.toString());

    // ?string builder
    sql.setLength(0);

    // ??
    sql.append("CREATE TABLE ").append(TOPICS).append("(").append(TOPIC_ID).append(" int PRIMARY KEY,")
            .append(TOPIC_NAME).append(" text,").append(TOPIC_DESCRIPTION).append(" text,").append(TOPIC_AVATAR)
            .append(" text").append(")");

    db.execSQL(sql.toString());
}

From source file:com.tojc.ormlite.android.framework.TableInfo.java

public TableInfo(Class<?> tableClassType) {
    // can't happen
    // keep a while, May 18th 2013
    // TODO remove after a while
    // if (!(tableClassType instanceof Class<?>)) {
    // throw new IllegalArgumentException("Parameter is not a Class<?>.");
    // }/*from w  w  w.  j  a v a 2s .c  o m*/

    this.classType = tableClassType;
    this.name = OrmLiteAnnotationAccessor.getAnnotationTableName(tableClassType);

    this.defaultContentUriInfo = new ContentUriInfo(tableClassType);
    this.defaultContentMimeTypeVndInfo = new ContentMimeTypeVndInfo(tableClassType);

    this.columns = new HashMap<String, ColumnInfo>();
    this.projectionMap = new HashMap<String, String>();

    SortedMap<Integer, String> defaultSortOrderMap = new TreeMap<Integer, String>();

    this.idColumnInfo = null;
    for (Field classfield : tableClassType.getDeclaredFields()) {
        if (classfield.isAnnotationPresent(DatabaseField.class)) {
            classfield.setAccessible(true); // private field accessible

            ColumnInfo columnInfo = new ColumnInfo(classfield);
            this.columns.put(columnInfo.getColumnName(), columnInfo);

            // check id
            if (columnInfo.getColumnName().equals(BaseColumns._ID)) {
                boolean generatedId = classfield.getAnnotation(DatabaseField.class).generatedId();
                if (generatedId) {
                    this.idColumnInfo = columnInfo;
                }
            }

            // DefaultSortOrder
            SortOrderInfo defaultSortOrderInfo = columnInfo.getDefaultSortOrderInfo();
            if (defaultSortOrderInfo.isValid()) {
                defaultSortOrderMap.put(defaultSortOrderInfo.getWeight(),
                        defaultSortOrderInfo.makeSqlOrderString(columnInfo.getColumnName()));
            }

            // ProjectionMap
            this.projectionMap.put(columnInfo.getProjectionColumnName(), columnInfo.getColumnName());

        }
    }

    if (this.idColumnInfo == null) {
        // @DatabaseField(columnName = _ID, generatedId = true)
        // private int _id;
        throw new IllegalArgumentException("Proper ID is not defined for field.");
    }

    // DefaultSortOrder
    if (defaultSortOrderMap.size() >= 1) {
        // make SQL OrderBy
        StringBuilder result = new StringBuilder();
        String comma = "";
        for (Map.Entry<Integer, String> entry : defaultSortOrderMap.entrySet()) {
            result.append(comma);
            result.append(entry.getValue());
            comma = ", ";
        }
        this.defaultSortOrder = result.toString();
    } else {
        this.defaultSortOrder = "";
    }
}

From source file:org.cnx.android.quizcards.activities.DeckListActivity.java

/**Extracts decks from the database, shows them in the ListView**/
private void getDecks() {
    String[] projection = { BaseColumns._ID, TITLE, AUTHOR, ABSTRACT };
    String order = "LOWER(" + TITLE + ")";
    titlesCursor = getContentResolver().query(DeckProvider.CONTENT_URI, projection, null, null, order);
    titlesCursor.moveToFirst();//w  w  w .j a va  2s .c o m

    int[] to = { R.id.title, R.id.authors, R.id.summary };
    String[] from = { TITLE, AUTHOR, ABSTRACT };
    SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(this, R.layout.deck_list_row, titlesCursor,
            from, to, CursorAdapter.NO_SELECTION);

    deckListView.setAdapter(cursorAdapter);
}

From source file:cz.maresmar.sfm.view.menu.CursorPagerAdapter.java

/**
 * Replaces old {@link Cursor} with new one.
 *
 * @param newCursor New cursor to replace
 * @return Old cursor//from   w w  w.  j a v  a2  s .c  om
 */
public Cursor swapCursor(@Nullable Cursor newCursor) {
    // Ignore same cursor
    if (newCursor == mCursor) {
        return null;
    }

    // Release old cursor
    final Cursor oldCursor = mCursor;
    if (oldCursor != null && mDataSetObserver != null) {
        oldCursor.unregisterDataSetObserver(mDataSetObserver);
    }

    // Prepare new cursor
    mCursor = newCursor;
    if (mCursor != null) {
        mCursor.registerDataSetObserver(mDataSetObserver);
        mIdColumnIndex = mCursor.getColumnIndexOrThrow(BaseColumns._ID);
    } else {
        mIdColumnIndex = -1;
    }

    // Update results in UI
    notifyDataSetChanged();
    return oldCursor;
}

From source file:es.jpv.android.examples.loadersexample.MainActivityFragment.java

/**
 * Initiates the Loader to perform the first load of data onto the RecyclerView
 *//*  ww  w  . java  2  s .  c o m*/
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    Bundle loaderArgs = new Bundle();
    loaderArgs.putString("Table", DataProviderContract.ITEMS_TABLE_NAME);
    loaderArgs.putStringArray("Projection", PROJECTION);
    loaderArgs.putString("Order", BaseColumns._ID);
    loaderArgs.putLong("Limit", lastLimitLoaded);
    getLoaderManager().initLoader(LOADER_ID, loaderArgs, new DBSelectLoader());
}