List of usage examples for android.provider BaseColumns _ID
String _ID
To view the source code for android.provider BaseColumns _ID.
Click Source Link
From source file:de.schildbach.wallet.ExchangeRatesProvider.java
@Override public Cursor query(final Uri uri, final String[] projection, final String selection, final String[] selectionArgs, final String sortOrder) { final long now = System.currentTimeMillis(); final boolean offline = uri.getQueryParameter(QUERY_PARAM_OFFLINE) != null; if (!offline && (lastUpdated == 0 || now - lastUpdated > UPDATE_FREQ_MS)) { Map<String, ExchangeRate> newExchangeRates = null; if (newExchangeRates == null) newExchangeRates = requestExchangeRates(BITCOINAVERAGE_URL, userAgent, BITCOINAVERAGE_SOURCE, BITCOINAVERAGE_FIELDS); if (newExchangeRates == null) newExchangeRates = requestExchangeRates(BLOCKCHAININFO_URL, userAgent, BLOCKCHAININFO_SOURCE, BLOCKCHAININFO_FIELDS); if (newExchangeRates != null) { exchangeRates = newExchangeRates; lastUpdated = now;/*www. j av a2 s . co m*/ final ExchangeRate exchangeRateToCache = bestExchangeRate(config.getExchangeCurrencyCode()); if (exchangeRateToCache != null) config.setCachedExchangeRate(exchangeRateToCache); } } if (exchangeRates == null) return null; final MatrixCursor cursor = new MatrixCursor( new String[] { BaseColumns._ID, KEY_CURRENCY_CODE, KEY_RATE_COIN, KEY_RATE_FIAT, KEY_SOURCE }); if (selection == null) { for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) { final ExchangeRate exchangeRate = entry.getValue(); final org.bitcoinj.utils.ExchangeRate rate = exchangeRate.rate; final String currencyCode = exchangeRate.getCurrencyCode(); cursor.newRow().add(currencyCode.hashCode()).add(currencyCode).add(rate.coin.value) .add(rate.fiat.value).add(exchangeRate.source); } } else if (selection.equals(QUERY_PARAM_Q)) { final String selectionArg = selectionArgs[0].toLowerCase(Locale.US); for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) { final ExchangeRate exchangeRate = entry.getValue(); final org.bitcoinj.utils.ExchangeRate rate = exchangeRate.rate; final String currencyCode = exchangeRate.getCurrencyCode(); final String currencySymbol = GenericUtils.currencySymbol(currencyCode); if (currencyCode.toLowerCase(Locale.US).contains(selectionArg) || currencySymbol.toLowerCase(Locale.US).contains(selectionArg)) cursor.newRow().add(currencyCode.hashCode()).add(currencyCode).add(rate.coin.value) .add(rate.fiat.value).add(exchangeRate.source); } } else if (selection.equals(KEY_CURRENCY_CODE)) { final String selectionArg = selectionArgs[0]; final ExchangeRate exchangeRate = bestExchangeRate(selectionArg); if (exchangeRate != null) { final org.bitcoinj.utils.ExchangeRate rate = exchangeRate.rate; final String currencyCode = exchangeRate.getCurrencyCode(); cursor.newRow().add(currencyCode.hashCode()).add(currencyCode).add(rate.coin.value) .add(rate.fiat.value).add(exchangeRate.source); } } return cursor; }
From source file:com.github.longkai.zhihu.ui.HotItemsFragment.java
@Override public void onClick(View v) { loading = true;//from w ww. j a v a2 s .c om page++; // ? new AsyncQueryHandler(getActivity().getContentResolver()) { @Override protected void onQueryComplete(int token, Object cookie, Cursor cursor) { mAdapter.changeCursor(cursor); loading = false; if (cursor.moveToLast()) { // todo bug // ?button? // ?id????= = long index = cursor.getLong(cursor.getColumnIndex(BaseColumns._ID)); if (index == MIN_ITEM_INDEX) { loadMore.setText(getString(R.string.no_more)); loadMore.setClickable(false); } } } }.startQuery(0, null, Utils.parseUri(ITEMS), ITEMS_PROJECTION, null, null, "_id desc limit " + (page * COUNT)); }
From source file:com.binoy.vibhinna.CustomIntentService.java
/** * You should not override this method for your IntentService. Instead, * override {@link #onHandleIntent}, which the system calls when the * IntentService receives a start request. * /*w ww . j a va 2s . c o m*/ * @see android.app.Service#onStartCommand */ @Override public int onStartCommand(Intent intent, int flags, int startId) { ContentValues values = new ContentValues(); if (intent.getIntExtra(VibhinnaService.TASK_TYPE, -1) == VibhinnaService.TASK_TYPE_NEW_VFS) values.put(DatabaseHelper.TASK_VS, VibhinnaUtils .avoidDuplicateFile(new File(intent.getStringExtra(VibhinnaService.FOLDER_PATH))).getName()); else values.put(DatabaseHelper.TASK_VS, new File(intent.getStringExtra(VibhinnaService.FOLDER_PATH)).getName()); values.put(DatabaseHelper.TASK_TYPE, intent.getIntExtra(VibhinnaService.TASK_TYPE, -1)); values.put(DatabaseHelper.TASK_STATUS, TasksAdapter.TASK_STATUS_WAITING); values.put(DatabaseHelper.TASK_MESSAGE, getString(R.string.task_message_waiting)); mLocalBroadcastManager = LocalBroadcastManager.getInstance(this); tasksUpdatedIntent = new Intent(); tasksUpdatedIntent.setAction(VibhinnaService.ACTION_TASK_QUEUE_UPDATED); mLocalBroadcastManager.sendBroadcast(tasksUpdatedIntent); vfsListUpdatedIntent = new Intent(VibhinnaService.ACTION_VFS_LIST_UPDATED); long id = Long .parseLong(getContentResolver().insert(TasksProvider.CONTENT_URI, values).getLastPathSegment()); intent.putExtra(BaseColumns._ID, id); onStart(intent, startId); return mRedelivery ? START_REDELIVER_INTENT : START_NOT_STICKY; }
From source file:org.codarama.haxsync.services.ContactsSyncAdapterService.java
private static void addSelfContact(Account account, int maxSize, boolean square, boolean faceDetect, boolean force, boolean root, int rootsize, File cacheDir, boolean google) { Uri rawContactUri = ContactsContract.Profile.CONTENT_RAW_CONTACTS_URI.buildUpon() .appendQueryParameter(RawContacts.ACCOUNT_NAME, account.name) .appendQueryParameter(RawContacts.ACCOUNT_TYPE, account.type).build(); long ID = -2; String username;//from w w w. ja v a2 s.co m String email; FacebookGraphFriend user = FacebookUtil.getSelfInfo(); if (user == null) return; Cursor cursor = mContentResolver.query(rawContactUri, new String[] { BaseColumns._ID, UsernameColumn }, null, null, null); if (cursor.getCount() > 0) { cursor.moveToFirst(); ID = cursor.getLong(cursor.getColumnIndex(BaseColumns._ID)); username = cursor.getString(cursor.getColumnIndex(UsernameColumn)); cursor.close(); } else { cursor.close(); username = user.getUserName(); email = user.getEmail(); ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>(); ContentProviderOperation.Builder builder = ContentProviderOperation .newInsert(ContactsContract.Profile.CONTENT_RAW_CONTACTS_URI); builder.withValue(RawContacts.ACCOUNT_NAME, account.name); builder.withValue(RawContacts.ACCOUNT_TYPE, account.type); builder.withValue(RawContacts.SYNC1, username); operationList.add(builder.build()); builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI); builder.withValueBackReference(ContactsContract.CommonDataKinds.StructuredName.RAW_CONTACT_ID, 0); builder.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE); builder.withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, account.name); operationList.add(builder.build()); builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI); builder.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0); builder.withValue(ContactsContract.Data.MIMETYPE, "vnd.android.cursor.item/vnd.org.codarama.haxsync.profile"); builder.withValue(ContactsContract.Data.DATA1, username); builder.withValue(ContactsContract.Data.DATA2, "Facebook Profile"); builder.withValue(ContactsContract.Data.DATA3, "View profile"); operationList.add(builder.build()); if (email != null) { builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI); builder.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0); builder.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE); builder.withValue(ContactsContract.CommonDataKinds.Email.ADDRESS, email); operationList.add(builder.build()); } try { mContentResolver.applyBatch(ContactsContract.AUTHORITY, operationList); } catch (Exception e) { // FIXME catching generic Exception class is not the best thing to do Log.e("Error", e.getLocalizedMessage()); return; } cursor = mContentResolver.query(rawContactUri, new String[] { BaseColumns._ID }, null, null, null); if (cursor.getCount() > 0) { cursor.moveToFirst(); ID = cursor.getLong(cursor.getColumnIndex(BaseColumns._ID)); cursor.close(); } else { Log.i(TAG, "NO SELF CONTACT FOUND"); return; } } Log.i("self contact", "id: " + ID + " uid: " + username); if (ID != -2 && username != null) { updateContactPhoto(ID, 0, maxSize, square, user.getPicURL(), faceDetect, true, root, rootsize, cacheDir, google, true); } }
From source file:org.sufficientlysecure.keychain.ui.ImportKeysSearchFragment.java
private void updateAdapter(String query) { mCurrentSuggestions.clear();//from w ww. j a v a 2s . c o m MatrixCursor c = new MatrixCursor(new String[] { BaseColumns._ID, CURSOR_SUGGESTION }); for (int i = 0; i < mNamesAndEmails.size(); i++) { String s = mNamesAndEmails.get(i); if (s.toLowerCase().startsWith(query.toLowerCase())) { mCurrentSuggestions.add(s); c.addRow(new Object[] { i, s }); } } mSearchAdapter.changeCursor(c); }
From source file:com.fututel.ui.favorites.FavAdapter.java
@Override public void bindView(View view, final Context context, Cursor cursor) { ContentValues cv = new ContentValues(); DatabaseUtils.cursorRowToContentValues(cursor, cv); int type = ContactsWrapper.TYPE_CONTACT; if (cv.containsKey(ContactsWrapper.FIELD_TYPE)) { type = cv.getAsInteger(ContactsWrapper.FIELD_TYPE); }/* w ww.ja va 2 s. c om*/ showViewForType(view, type); if (type == ContactsWrapper.TYPE_GROUP) { // Get views TextView tv = (TextView) view.findViewById(R.id.header_text); ImageView icon = (ImageView) view.findViewById(R.id.header_icon); PresenceStatusSpinner presSpinner = (PresenceStatusSpinner) view .findViewById(R.id.header_presence_spinner); // Get datas SipProfile acc = new SipProfile(cursor); final Long profileId = cv.getAsLong(BaseColumns._ID); final String groupName = acc.android_group; final String displayName = acc.display_name; final String wizard = acc.wizard; final boolean publishedEnabled = (acc.publish_enabled == 1); final String domain = acc.getDefaultDomain(); // Bind datas to view tv.setText(displayName); icon.setImageResource(WizardUtils.getWizardIconRes(wizard)); presSpinner.setProfileId(profileId); // Extra menu view if not already set ViewGroup menuViewWrapper = (ViewGroup) view.findViewById(R.id.header_cfg_spinner); MenuCallback newMcb = new MenuCallback(context, profileId, groupName, domain, publishedEnabled); MenuBuilder menuBuilder; if (menuViewWrapper.getTag() == null) { final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); ActionMenuPresenter mActionMenuPresenter = new ActionMenuPresenter(mContext); mActionMenuPresenter.setReserveOverflow(true); menuBuilder = new MenuBuilder(context); menuBuilder.setCallback(newMcb); MenuInflater inflater = new MenuInflater(context); inflater.inflate(R.menu.fav_menu, menuBuilder); menuBuilder.addMenuPresenter(mActionMenuPresenter); ActionMenuView menuView = (ActionMenuView) mActionMenuPresenter.getMenuView(menuViewWrapper); UtilityWrapper.getInstance().setBackgroundDrawable(menuView, null); menuViewWrapper.addView(menuView, layoutParams); menuViewWrapper.setTag(menuBuilder); } else { menuBuilder = (MenuBuilder) menuViewWrapper.getTag(); menuBuilder.setCallback(newMcb); } menuBuilder.findItem(R.id.share_presence).setTitle( publishedEnabled ? R.string.deactivate_presence_sharing : R.string.activate_presence_sharing); menuBuilder.findItem(R.id.set_sip_data).setVisible(!TextUtils.isEmpty(groupName)); } else if (type == ContactsWrapper.TYPE_CONTACT) { ContactInfo ci = ContactsWrapper.getInstance().getContactInfo(context, cursor); ci.userData = cursor.getPosition(); // Get views TextView tv = (TextView) view.findViewById(R.id.contact_name); QuickContactBadge badge = (QuickContactBadge) view.findViewById(R.id.quick_contact_photo); TextView statusText = (TextView) view.findViewById(R.id.status_text); ImageView statusImage = (ImageView) view.findViewById(R.id.status_icon); // Bind if (ci.contactId != null) { tv.setText(ci.displayName); badge.assignContactUri(ci.callerInfo.contactContentUri); ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(context, badge.getImageView(), ci.callerInfo, R.drawable.ic_contact_picture_holo_light); statusText.setVisibility(ci.hasPresence ? View.VISIBLE : View.GONE); statusText.setText(ci.status); statusImage.setVisibility(ci.hasPresence ? View.VISIBLE : View.GONE); statusImage.setImageResource(ContactsWrapper.getInstance().getPresenceIconResourceId(ci.presence)); } View v; v = view.findViewById(R.id.contact_view); v.setTag(ci); v.setOnClickListener(mPrimaryActionListener); v = view.findViewById(R.id.secondary_action_icon); v.setTag(ci); v.setOnClickListener(mSecondaryActionListener); } else if (type == ContactsWrapper.TYPE_CONFIGURE) { // We only bind if it's the correct type View v = view.findViewById(R.id.configure_view); v.setOnClickListener(this); ConfigureObj cfg = new ConfigureObj(); cfg.profileId = cv.getAsLong(BaseColumns._ID); v.setTag(cfg); } }
From source file:pl.selvin.android.listsyncsample.ui.ListFragment.java
@Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { switch (id) { case ListLoaderId: return new CursorLoader(getActivity(), ListProvider.getHelper().getItemUri(Database.List.TABLE_NAME, getShownId()), new String[] { BaseColumns._ID, Database.List.NAME, Database.List.DESCRIPTION, Database.List.CREATEDATE, Database.List.ID }, null, null, null);//from w w w . j a v a 2 s.c om case ListItemsLoaderId: setListShown(false); return new CursorLoader(getActivity(), ListProvider.getHelper().getDirUri(Database.Item.TABLE_NAME), new String[] { BaseColumns._ID, Database.Item.ID, Database.Item.NAME, Database.Item.DESCRIPTION }, Database.Item.LISTID + "=?", new String[] { listID }, Database.Item.NAME); } return null; }
From source file:com.csipsimple.ui.favorites.FavAdapter.java
@Override public void bindView(View view, final Context context, Cursor cursor) { ContentValues cv = new ContentValues(); DatabaseUtils.cursorRowToContentValues(cursor, cv); int type = ContactsWrapper.TYPE_CONTACT; if (cv.containsKey(ContactsWrapper.FIELD_TYPE)) { type = cv.getAsInteger(ContactsWrapper.FIELD_TYPE); }//from ww w .ja va 2 s . co m showViewForType(view, type); if (type == ContactsWrapper.TYPE_GROUP) { // Get views TextView tv = (TextView) view.findViewById(R.id.header_text); ImageView icon = (ImageView) view.findViewById(R.id.header_icon); PresenceStatusSpinner presSpinner = (PresenceStatusSpinner) view .findViewById(R.id.header_presence_spinner); // Get datas SipProfile acc = new SipProfile(cursor); final Long profileId = cv.getAsLong(BaseColumns._ID); final String groupName = acc.android_group; final String displayName = acc.display_name; final String wizard = acc.wizard; final boolean publishedEnabled = (acc.publish_enabled == 1); final String domain = acc.getDefaultDomain(); // Bind datas to view tv.setText(displayName); icon.setImageResource(WizardUtils.getWizardIconRes(wizard)); presSpinner.setProfileId(profileId); // Extra menu view if not already set ViewGroup menuViewWrapper = (ViewGroup) view.findViewById(R.id.header_cfg_spinner); MenuCallback newMcb = new MenuCallback(context, profileId, groupName, domain, publishedEnabled); MenuBuilder menuBuilder; if (menuViewWrapper.getTag() == null) { final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); ActionMenuPresenter mActionMenuPresenter = new ActionMenuPresenter(mContext); mActionMenuPresenter.setReserveOverflow(true); menuBuilder = new MenuBuilder(context); menuBuilder.setCallback(newMcb); MenuInflater inflater = new MenuInflater(context); inflater.inflate(R.menu.fav_menu, menuBuilder); menuBuilder.addMenuPresenter(mActionMenuPresenter); ActionMenuView menuView = (ActionMenuView) mActionMenuPresenter.getMenuView(menuViewWrapper); UtilityWrapper.getInstance().setBackgroundDrawable(menuView, null); menuViewWrapper.addView(menuView, layoutParams); menuViewWrapper.setTag(menuBuilder); } else { menuBuilder = (MenuBuilder) menuViewWrapper.getTag(); menuBuilder.setCallback(newMcb); } menuBuilder.findItem(R.id.share_presence).setTitle( publishedEnabled ? R.string.deactivate_presence_sharing : R.string.activate_presence_sharing); menuBuilder.findItem(R.id.set_sip_data).setVisible(!TextUtils.isEmpty(groupName)); } else if (type == ContactsWrapper.TYPE_CONTACT) { ContactInfo ci = ContactsWrapper.getInstance().getContactInfo(context, cursor); ci.userData = cursor.getPosition(); // Get views TextView tv = (TextView) view.findViewById(R.id.contact_name); QuickContactBadge badge = (QuickContactBadge) view.findViewById(R.id.quick_contact_photo); TextView statusText = (TextView) view.findViewById(R.id.status_text); ImageView statusImage = (ImageView) view.findViewById(R.id.status_icon); // Bind if (ci.contactId != null) { tv.setText(ci.displayName); badge.assignContactUri(ci.callerInfo.contactContentUri); ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(context, badge.getImageView(), ci.callerInfo, R.drawable.ic_contact_picture_holo_dark); statusText.setVisibility(ci.hasPresence ? View.VISIBLE : View.GONE); statusText.setText(ci.status); statusImage.setVisibility(ci.hasPresence ? View.VISIBLE : View.GONE); statusImage.setImageResource(ContactsWrapper.getInstance().getPresenceIconResourceId(ci.presence)); } View v; v = view.findViewById(R.id.contact_view); v.setTag(ci); v.setOnClickListener(mPrimaryActionListener); v = view.findViewById(R.id.secondary_action_icon); v.setTag(ci); v.setOnClickListener(mSecondaryActionListener); } else if (type == ContactsWrapper.TYPE_CONFIGURE) { // We only bind if it's the correct type View v = view.findViewById(R.id.configure_view); v.setOnClickListener(this); ConfigureObj cfg = new ConfigureObj(); cfg.profileId = cv.getAsLong(BaseColumns._ID); v.setTag(cfg); } }
From source file:com.nonninz.robomodel.RoboManager.java
public long[] getSelectedModelIds(String selection, String[] selectionArgs, String groupBy, String having, String orderBy) {/*from w w w . j av a2 s . com*/ final SQLiteDatabase db = mDatabaseManager.openOrCreateDatabase(getDatabaseName()); final String columns[] = new String[] { BaseColumns._ID }; Cursor query; /* * Try the query. If the Table doesn't exist, fix the DB and re-run the query. */ try { query = db.query(getTableName(), columns, selection, selectionArgs, groupBy, having, orderBy); } catch (final SQLiteException e) { prepareTable(db); query = db.query(getTableName(), columns, selection, selectionArgs, groupBy, having, orderBy); } final int columnIndex = query.getColumnIndex(BaseColumns._ID); final long result[] = new long[query.getCount()]; for (query.moveToFirst(); !query.isAfterLast(); query.moveToNext()) { result[query.getPosition()] = query.getLong(columnIndex); } return result; }
From source file:me.jreilly.JamesTweet.Adapters.TweetDataHelper.java
public Callback<List<Tweet>> callBackMaker(final int mMaxItems, final RecyclerView mRecyclerView, final Cursor mCursor, final SQLiteDatabase mTimelineDB, final TweetDataHelper mHelper, final SwipeRefreshLayout mSwipeRefreshLayout) { final int position = mCursor.getPosition(); return new Callback<List<Tweet>>() { @Override// w w w. j a va 2 s .co m public void success(Result<List<Tweet>> listResult) { long numEntries = DatabaseUtils.queryNumEntries(mTimelineDB, "home"); List<Tweet> list = listResult.data.subList(0, listResult.data.size()); for (Tweet t : list) { try { ContentValues tweetValues = mHelper.getValues(t); mTimelineDB.insertOrThrow("home", null, tweetValues); Log.v("NEW CONTEXT", "Added Tweet Tweets!"); } catch (Exception te) { Log.e("NEW CONTEXT", "Exception: " + te); } } int rowLimit = 50; if (DatabaseUtils.queryNumEntries(mTimelineDB, "home") > rowLimit) { String deleteQuery = "DELETE FROM home WHERE " + BaseColumns._ID + " NOT IN " + "(SELECT " + BaseColumns._ID + " FROM home ORDER BY " + "update_time DESC " + "limit " + rowLimit + ")"; mTimelineDB.execSQL(deleteQuery); Log.v("NEW CONTEXT", "Deleteing Tweets!"); } mRecyclerView.getAdapter().notifyDataSetChanged(); if (mSwipeRefreshLayout != null) { mSwipeRefreshLayout.setRefreshing(false); } else { mRecyclerView.smoothScrollToPosition(position); } Log.v("NEW CONTEXT", "All done!"); } @Override public void failure(TwitterException e) { Log.e("NEW CONTEXT", "Exception " + e); } }; }