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:com.espian.ticktock.AddEditActivity.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    return new CursorLoader(this, TickTockProvider.countdownUri, null, BaseColumns._ID + "=?",
            new String[] { editId }, null);
}

From source file:com.wheelly.activity.FilterDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View v = layoutInflater.inflate(R.layout.blotter_filter, null);
    final Activity ctx = this.getActivity();

    locationCursor = new LocationRepository(db = new DatabaseHelper(ctx).getReadableDatabase())
            .list(filter.containsKey(F.LOCATION_CONSTRAINT) ? filter.getAsString(F.LOCATION_CONSTRAINT) : "");

    //ctx.startManagingCursor(locationCursor);

    final ListAdapter adapter = new SimpleCursorAdapter(ctx, android.R.layout.simple_spinner_dropdown_item,
            null, new String[] { "name" }, new int[] { android.R.id.text1 }, 0);

    x = new ActivityLayout(new NodeInflater(layoutInflater), new ActivityLayoutListener() {
        @Override/*from w ww.  j ava2 s .c o  m*/
        public void onClick(View v) {
            switch (v.getId()) {
            case R.id.period:
                Intent intent = new Intent(ctx, DateFilterActivity.class);
                FilterUtils.filterToIntent(filter, intent);
                startActivityForResult(intent, PERIOD_REQUEST);
                break;
            case R.id.period_clear:
                filter.remove(F.PERIOD);
                c.period.setText(R.string.no_filter);
                break;
            case R.id.location: {
                long locationId = filter.containsKey(F.LOCATION) ? filter.getAsLong(F.LOCATION) : -1;
                long selectedId = c != null ? locationId : -1;

                x.select(ctx, R.id.location, R.string.location, locationCursor, adapter, BaseColumns._ID,
                        selectedId);
            }
                break;
            case R.id.location_clear:
                filter.remove(F.LOCATION);
                c.location.setText(R.string.no_filter);
                break;
            }
        }

        @Override
        public void onSelectedId(int id, long selectedId) {
            switch (id) {
            case R.id.location:
                filter.put(F.LOCATION, selectedId);
                updateLocationFromFilter(filter, locationCursor);
                break;
            }
        }

        @Override
        public void onSelected(int arg0, List<? extends MultiChoiceItem> arg1) {
            // TODO Auto-generated method stub
        }

        @Override
        public void onSelectedPos(int arg0, int arg1) {
            // TODO Auto-generated method stub
        }
    });

    c = new Controls(x, v);

    df = DateUtils.getShortDateFormat(ctx);
    filterValueNotFound = getString(R.string.filter_value_not_found);

    final Dialog d = new AlertDialog.Builder(getActivity()).setView(v).setCancelable(true).create();

    c.bOk.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            dismiss();
            listener.onFilterChanged(filter);
        }
    });

    c.bCancel.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            d.cancel();
        }
    });

    c.bNoFilter.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            dismiss();
            listener.onFilterChanged(null);
        }
    });

    if (null != filter) {
        updatePeriodFromFilter(filter);
        updateLocationFromFilter(filter, locationCursor);
    }

    return d;
}

From source file:com.boardgamegeek.util.SelectionBuilder.java

public SelectionBuilder mapToTable(String column, String table) {
    if (column.equals(BaseColumns._ID)) {
        mapToTable(column, table, column);
    } else {//from ww  w  . j a  va2 s. co  m
        mProjectionMap.put(column, table + "." + column);
    }
    return this;
}

From source file:com.andrew.apolloMod.activities.QueryBrowserActivity.java

@Override
public void onServiceConnected(ComponentName name, IBinder service) {
    if (mAdapter != null) {
        getQueryCursor(mAdapter.getQueryHandler(), null);
    }/*  w w w . j  a  v  a 2s.  co  m*/

    Intent intent = getIntent();
    String action = intent != null ? intent.getAction() : null;

    if (Intent.ACTION_VIEW.equals(action)) {
        // this is something we got from the search bar
        Uri uri = intent.getData();
        String path = uri.toString();
        if (path.startsWith("content://media/external/audio/media/")) {
            // This is a specific file
            String id = uri.getLastPathSegment();
            long[] list = new long[] { Long.valueOf(id) };
            MusicUtils.playAll(this, list, 0);
            finish();
            return;
        } else if (path.startsWith("content://media/external/audio/albums/")) {
            // This is an album, show the songs on it
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
            i.putExtra("album", uri.getLastPathSegment());
            startActivity(i);
            finish();
            return;
        } else if (path.startsWith("content://media/external/audio/artists/")) {
            intent = new Intent(Intent.ACTION_VIEW);

            Bundle bundle = new Bundle();
            bundle.putString(MIME_TYPE, Audio.Artists.CONTENT_TYPE);
            bundle.putString(ARTIST_KEY, uri.getLastPathSegment());
            bundle.putLong(BaseColumns._ID, ApolloUtils.getArtistId(uri.getLastPathSegment(), ARTIST_ID, this));

            intent.setClass(this, TracksBrowser.class);
            intent.putExtras(bundle);
            startActivity(intent);
            return;
        }
    }

    mFilterString = intent.getStringExtra(SearchManager.QUERY);
    if (MediaStore.INTENT_ACTION_MEDIA_SEARCH.equals(action)) {
        String focus = intent.getStringExtra(MediaStore.EXTRA_MEDIA_FOCUS);
        String artist = intent.getStringExtra(MediaStore.EXTRA_MEDIA_ARTIST);
        String album = intent.getStringExtra(MediaStore.EXTRA_MEDIA_ALBUM);
        String title = intent.getStringExtra(MediaStore.EXTRA_MEDIA_TITLE);
        if (focus != null) {
            if (focus.startsWith("audio/") && title != null) {
                mFilterString = title;
            } else if (focus.equals(Audio.Albums.ENTRY_CONTENT_TYPE)) {
                if (album != null) {
                    mFilterString = album;
                    if (artist != null) {
                        mFilterString = mFilterString + " " + artist;
                    }
                }
            } else if (focus.equals(Audio.Artists.ENTRY_CONTENT_TYPE)) {
                if (artist != null) {
                    mFilterString = artist;
                }
            }
        }
    }

    setContentView(R.layout.listview);
    mTrackList = getListView();
    mTrackList.setTextFilterEnabled(true);
    if (mAdapter == null) {
        mAdapter = new QueryListAdapter(getApplication(), this, R.layout.listview_items, null, // cursor
                new String[] {}, new int[] {}, 0);
        setListAdapter(mAdapter);
        if (TextUtils.isEmpty(mFilterString)) {
            getQueryCursor(mAdapter.getQueryHandler(), null);
        } else {
            mTrackList.setFilterText(mFilterString);
            mFilterString = null;
        }
    } else {
        mAdapter.setActivity(this);
        setListAdapter(mAdapter);
        mQueryCursor = mAdapter.getCursor();
        if (mQueryCursor != null) {
            init(mQueryCursor);
        } else {
            getQueryCursor(mAdapter.getQueryHandler(), mFilterString);
        }
    }

    LinearLayout emptyness = (LinearLayout) findViewById(R.id.empty_view);
    emptyness.setVisibility(View.GONE);
}

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

/**
 * Android`_id`??
 * @param id
 * @return _id=xx
 */
public static String queryById(String id) {
    return queryByKey(BaseColumns._ID, id);
}

From source file:io.github.carlorodriguez.alarmon.MediaListView.java

protected void query(Uri contentUri, String nameColumn, String selection, int rowResId, String[] displayColumns,
        int[] resIDs) {
    this.nameColumn = nameColumn;
    final ArrayList<String> queryColumns = new ArrayList<>(displayColumns.length + 1);
    queryColumns.addAll(Arrays.asList(displayColumns));
    // The ID column is required for the SimpleCursorAdapter.  Make sure to
    // add it if it's not already there.
    if (!queryColumns.contains(BaseColumns._ID)) {
        queryColumns.add(BaseColumns._ID);
    }//from  www.  ja  va 2s  . c o  m

    Cursor dbCursor;

    if (ContextCompat.checkSelfPermission(getContext(),
            Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
        dbCursor = getContext().getContentResolver().query(contentUri,
                queryColumns.toArray(new String[queryColumns.size()]), selection, null, sortOrder);
    } else {
        dbCursor = new MatrixCursor(queryColumns.toArray(new String[queryColumns.size()]));
    }

    if (staticCursor != null) {
        Cursor[] cursors = new Cursor[] { staticCursor, dbCursor };
        cursor = new MergeCursor(cursors);
    } else {
        cursor = dbCursor;
    }
    manageCursor(cursor);

    this.contentUri = contentUri;

    final SimpleCursorAdapter adapter = new SimpleCursorAdapter(getContext(), rowResId, cursor, displayColumns,
            resIDs, 1);
    // Use a custom binder to highlight the selected element.
    adapter.setViewBinder(new ViewBinder() {
        @Override
        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
            if (view.getVisibility() == View.VISIBLE && view instanceof TextView) {
                TextView text = (TextView) view;
                if (isItemChecked(cursor.getPosition())) {
                    text.setTypeface(Typeface.DEFAULT_BOLD);
                } else {
                    text.setTypeface(Typeface.DEFAULT);
                }
            }
            // Let the default binder do the real work.
            return false;
        }
    });
    setAdapter(adapter);
    setOnItemClickListener(this);
}

From source file:com.tct.email.provider.EmailMessageCursor.java

public EmailMessageCursor(final Context c, final Cursor cursor, final String htmlColumn,
        final String textColumn) {
    super(cursor);
    mHtmlColumnIndex = cursor.getColumnIndex(htmlColumn);
    mTextColumnIndex = cursor.getColumnIndex(textColumn);
    final int cursorSize = cursor.getCount();
    mHtmlParts = new SparseArray<String>(cursorSize);
    mTextParts = new SparseArray<String>(cursorSize);
    //TS: jian.xu 2015-11-03 EMAIL BUGFIX-845079 ADD_S
    mHtmlLinkifyColumnIndex = cursor.getColumnIndex(UIProvider.MessageColumns.BODY_HTML_LINKIFY);
    mHtmlLinkifyParts = new SparseArray<String>(cursorSize);
    mTextLinkifyColumnIndex = cursor.getColumnIndex(UIProvider.MessageColumns.BODY_TEXT_LINKIFY);
    mTextLinkifyParts = new SparseArray<String>(cursorSize);
    //TS: jian.xu 2015-11-03 EMAIL BUGFIX-845079 ADD_E

    final ContentResolver cr = c.getContentResolver();

    while (cursor.moveToNext()) {
        final int position = cursor.getPosition();
        final long messageId = cursor.getLong(cursor.getColumnIndex(BaseColumns._ID));
        // TS: chao.zhang 2015-09-14 EMAIL BUGFIX-1039046  MOD_S
        InputStream htmlIn = null;
        InputStream textIn = null;
        try {/* w  ww  .j av  a2 s.c om*/
            if (mHtmlColumnIndex != -1) {
                final Uri htmlUri = Body.getBodyHtmlUriForMessageWithId(messageId);
                //WARNING: Actually openInput will used 2 PIPE(FD) to connect,but if some exception happen during connect,
                //such as fileNotFoundException,maybe the connection will not be closed. just a try!!!
                htmlIn = cr.openInputStream(htmlUri);
                final String underlyingHtmlString;
                try {
                    underlyingHtmlString = IOUtils.toString(htmlIn);
                } finally {
                    htmlIn.close();
                    htmlIn = null;
                }
                //TS: zhaotianyong 2015-04-05 EMAIL BUGFIX_964325 MOD_S
                final String sanitizedHtml = HtmlSanitizer.sanitizeHtml(underlyingHtmlString);
                mHtmlParts.put(position, sanitizedHtml);
                //TS: zhaotianyong 2015-04-05 EMAIL BUGFIX_964325 MOD_E
                //TS: jian.xu 2015-11-03 EMAIL BUGFIX-845079 ADD_S
                //NOTE: add links for sanitized html
                if (!TextUtils.isEmpty(sanitizedHtml)) {
                    final String linkifyHtml = com.tct.mail.utils.Linkify.addLinks(sanitizedHtml);
                    mHtmlLinkifyParts.put(position, linkifyHtml);
                } else {
                    mHtmlLinkifyParts.put(position, "");
                }
                //TS: jian.xu 2015-11-03 EMAIL BUGFIX-845079 ADD_E
            }
        } catch (final IOException e) {
            LogUtils.v(LogUtils.TAG, e, "Did not find html body for message %d", messageId);
        } catch (final OutOfMemoryError oom) {
            LogUtils.v(LogUtils.TAG, oom,
                    "Terrible,OOM happen durning query EmailMessageCursor in bodyHtml,current message %d",
                    messageId);
            mHtmlLinkifyParts.put(position, "");
        }
        try {
            if (mTextColumnIndex != -1) {
                final Uri textUri = Body.getBodyTextUriForMessageWithId(messageId);
                textIn = cr.openInputStream(textUri);
                final String underlyingTextString;
                try {
                    underlyingTextString = IOUtils.toString(textIn);
                } finally {
                    textIn.close();
                    textIn = null;
                }
                mTextParts.put(position, underlyingTextString);
                //TS: jian.xu 2015-11-03 EMAIL BUGFIX-845079 ADD_S
                //NOTE: add links for underlying text string
                if (!TextUtils.isEmpty(underlyingTextString)) {
                    final SpannableString spannable = new SpannableString(underlyingTextString);
                    Linkify.addLinks(spannable,
                            Linkify.EMAIL_ADDRESSES | Linkify.WEB_URLS | Linkify.PHONE_NUMBERS);
                    final String linkifyText = Html.toHtml(spannable);
                    mTextLinkifyParts.put(position, linkifyText);
                } else {
                    mTextLinkifyParts.put(position, "");
                }
                //TS: jian.xu 2015-11-03 EMAIL BUGFIX-845079 ADD_E
            }
        } catch (final IOException e) {
            LogUtils.v(LogUtils.TAG, e, "Did not find text body for message %d", messageId);
        } catch (final OutOfMemoryError oom) {
            LogUtils.v(LogUtils.TAG, oom,
                    "Terrible,OOM happen durning query EmailMessageCursor in bodyText,current message %d",
                    messageId);
            mTextLinkifyParts.put(position, "");
        }
        //NOTE:Remember that this just a protective code,for better release Not used Resources.
        if (htmlIn != null) {
            try {
                htmlIn.close();
            } catch (IOException e1) {
                LogUtils.v(LogUtils.TAG, e1, "IOException happen while close the htmlInput connection ");
            }
        }
        if (textIn != null) {
            try {
                textIn.close();
            } catch (IOException e2) {
                LogUtils.v(LogUtils.TAG, e2, "IOException happen while close the textInput connection ");
            }
        } // TS: chao.zhang 2015-09-14 EMAIL BUGFIX-1039046  MOD_E
    }
    cursor.moveToPosition(-1);
}

From source file:org.catnut.metadata.User.java

@Override
public String ddl() {
    Log.i(TAG, "create table [users]...");

    StringBuilder ddl = new StringBuilder("CREATE TABLE ");
    ddl.append(TABLE).append("(").append(BaseColumns._ID).append(" int primary key,").append(screen_name)
            .append(" text,").append(name).append(" text,").append(province).append(" int,").append(city)
            .append(" int,").append(location).append(" text,").append(description).append(" text,").append(url)
            .append(" text,").append(profile_image_url).append(" text,").append(cover_image).append(" text,")
            .append(cover_image_phone).append(" text,").append(profile_url).append(" text,").append(domain)
            .append(" text,").append(weihao).append(" text,").append(gender).append(" text,")
            .append(followers_count).append(" int,").append(friends_count).append(" int,")
            .append(statuses_count).append(" int,").append(favourites_count).append(" int,").append(created_at)
            .append(" text,").append(following).append(" int,").append(allow_all_act_msg).append(" int,")
            .append(geo_enabled).append(" int,").append(verified).append(" int,").append(verified_type)
            .append(" int,").append(remark).append(" int,")
            //            .append(ptype).append(" int,")
            .append(allow_all_comment).append(" int,").append(avatar_large).append(" text,").append(avatar_hd)
            .append(" text,").append(verified_reason).append(" text,").append(follow_me).append(" int,")
            .append(online_status).append(" int,").append(bi_followers_count).append(" int,").append(lang)
            .append(" text"); // ???
    //            .append(star).append(" int,")
    //            .append(mbtype).append(" int,")
    //            .append(mbrank).append(" int,")
    //            .append(block_word).append(" int");
    return ddl.append(")").toString();
}

From source file:org.catnut.fragment.UserTimelineFragment.java

@Override
public void onConfirm(Bundle args) {
    final long id = args.getLong(TAG);
    mRequestQueue.add(new CatnutRequest(getActivity(), TweetAPI.destroy(id), new CatnutProcessor<JSONObject>() {
        @Override/*from w  w w .ja v a2 s  . co  m*/
        public void asyncProcess(Context context, JSONObject data) throws Exception {
            context.getContentResolver().delete(CatnutProvider.parse(Status.MULTIPLE),
                    BaseColumns._ID + "=" + id, null);
            // ? -1
            String update = CatnutUtils.increment(false, User.TABLE, User.statuses_count, mUid);
            context.getContentResolver().update(CatnutProvider.parse(User.MULTIPLE), null, update, null);
        }
    }, null, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e(TAG, "error deleting tweet id[" + id + "]", error);
            WeiboAPIError weiboAPIError = WeiboAPIError.fromVolleyError(error);
            Toast.makeText(getActivity(), weiboAPIError.error, Toast.LENGTH_LONG).show();
        }
    })).setTag(TAG);
}

From source file:org.andstatus.app.timeline.TimelineSelector.java

private MySimpleAdapter newListAdapter(List<TimelineListViewItem> listData) {
    List<Map<String, String>> list = new ArrayList<>();
    final String syncText = getText(R.string.synced_abbreviated).toString();
    for (TimelineListViewItem viewItem : listData) {
        Map<String, String> map = new HashMap<>();
        map.put(KEY_VISIBLE_NAME, viewItem.timelineTitle.toString());
        map.put(KEY_SYNC_AUTO, viewItem.timeline.isSyncedAutomatically() ? syncText : "");
        map.put(BaseColumns._ID, Long.toString(viewItem.timeline.getId()));
        list.add(map);//from  www. j a v  a  2  s  .  c o  m
    }

    return new MySimpleAdapter(getActivity(), list, R.layout.accountlist_item,
            new String[] { KEY_VISIBLE_NAME, KEY_SYNC_AUTO, BaseColumns._ID },
            new int[] { R.id.visible_name, R.id.sync_auto, R.id.id }, true);
}