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:com.csipsimple.ui.filters.AccountFiltersListFragment.java
@Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { return new CursorLoader(getActivity(), SipManager.FILTER_URI, new String[] { BaseColumns._ID, Filter.FIELD_ACCOUNT, Filter.FIELD_ACTION, Filter.FIELD_MATCHES, Filter.FIELD_PRIORITY, Filter.FIELD_REPLACE }, Filter.FIELD_ACCOUNT + "=?", new String[] { Long.toString(accountId) }, Filter.DEFAULT_ORDER); }
From source file:org.catnut.fragment.UserTimelineFragment.java
@Override protected void refresh() { // ???/*from ww w. ja v a 2 s.com*/ if (!isNetworkAvailable()) { Toast.makeText(getActivity(), getString(R.string.network_unavailable), Toast.LENGTH_SHORT).show(); initFromLocal(); return; } // refresh! final int size = getFetchSize(); (new Thread(new Runnable() { @Override public void run() { // ??????(?-)???Orz... String query = CatnutUtils.buildQuery(new String[] { BaseColumns._ID }, mSelection, Status.TABLE, null, BaseColumns._ID + " desc", size + ", 1" // limit x, y ); Cursor cursor = getActivity().getContentResolver().query(CatnutProvider.parse(Status.MULTIPLE), null, query, null, null); // the cursor never null? final long since_id; if (cursor.moveToNext()) { since_id = cursor.getLong(0); } else { since_id = 0; } cursor.close(); final CatnutAPI api = TweetAPI.userTimeline(mScreenName, since_id, 0, getFetchSize(), 0, 0, 0, 0); // refresh... mHandler.post(new Runnable() { @Override public void run() { mRequestQueue.add(new CatnutRequest(getActivity(), api, new StatusProcessor.TimelineProcessor(Status.OTHERS, true), new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { Log.d(TAG, "refresh done..."); mTotal = response.optInt(TOTAL_NUMBER); // ??? JSONArray jsonArray = response.optJSONArray(Status.MULTIPLE); int newSize = jsonArray.length(); // ... Bundle args = new Bundle(); args.putInt(TAG, newSize); getLoaderManager().restartLoader(0, args, UserTimelineFragment.this); } }, errorListener)).setTag(TAG); } }); } })).start(); }
From source file:net.sf.xfd.provider.PublicProvider.java
@Nullable @Override//from w ww .ja v a2s . co m public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { String path = uri.getPath(); if (TextUtils.isEmpty(uri.getPath())) { path = "/"; } try { assertAbsolute(path); } catch (FileNotFoundException e) { return null; } path = canonString(path); if (!path.equals(uri.getPath())) { uri = uri.buildUpon().path(path).build(); } if (!checkAccess(uri, "r")) { return null; } if (projection == null) { projection = COMMON_PROJECTION; } final OS os = base.getOS(); if (os == null) { return null; } try { final MatrixCursor cursor = new MatrixCursor(projection, 1); final Object[] row = new Object[projection.length]; final Stat stat = new Stat(); final String name = extractName(path); final String mime = base.getTypeFast(path, name, stat); for (int i = 0; i < projection.length; ++i) { String col = projection[i]; switch (col) { case BaseColumns._ID: row[i] = stat.st_ino; break; case COLUMN_DISPLAY_NAME: row[i] = name; break; case COLUMN_SIZE: row[i] = stat.st_size; break; case COLUMN_MIME_TYPE: row[i] = mime; break; default: row[i] = null; } } cursor.addRow(row); final Context context = getContext(); assert context != null; final String packageName = context.getPackageName(); cursor.setNotificationUri(context.getContentResolver(), DocumentsContract.buildDocumentUri(packageName + FileProvider.AUTHORITY_SUFFIX, path)); return cursor; } catch (IOException e) { e.printStackTrace(); return null; } }
From source file:com.google.android.apps.muzei.gallery.GalleryArtSource.java
private void ensureMetadataExists(@NonNull Uri imageUri) { Cursor existingMetadata = getContentResolver().query(GalleryContract.MetadataCache.CONTENT_URI, new String[] { BaseColumns._ID }, GalleryContract.MetadataCache.COLUMN_NAME_URI + "=?", new String[] { imageUri.toString() }, null); if (existingMetadata == null) { return;/*w ww . ja v a 2s.co m*/ } boolean metadataExists = existingMetadata.moveToFirst(); existingMetadata.close(); if (!metadataExists) { // No cached metadata or it's stale, need to pull it separately using Exif ContentValues values = new ContentValues(); values.put(GalleryContract.MetadataCache.COLUMN_NAME_URI, imageUri.toString()); InputStream in = null; try { ExifInterface exifInterface; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { in = getContentResolver().openInputStream(imageUri); exifInterface = new ExifInterface(in); } else { File imageFile = GalleryProvider.getLocalFileForUri(this, imageUri); if (imageFile == null) { return; } exifInterface = new ExifInterface(imageFile.getPath()); } String dateString = exifInterface.getAttribute(ExifInterface.TAG_DATETIME); if (!TextUtils.isEmpty(dateString)) { Date date = sExifDateFormat.parse(dateString); values.put(GalleryContract.MetadataCache.COLUMN_NAME_DATETIME, date.getTime()); } float[] latlong = new float[2]; if (exifInterface.getLatLong(latlong)) { // Reverse geocode List<Address> addresses = mGeocoder.getFromLocation(latlong[0], latlong[1], 1); if (addresses != null && addresses.size() > 0) { Address addr = addresses.get(0); String locality = addr.getLocality(); String adminArea = addr.getAdminArea(); String countryCode = addr.getCountryCode(); StringBuilder sb = new StringBuilder(); if (!TextUtils.isEmpty(locality)) { sb.append(locality); } if (!TextUtils.isEmpty(adminArea)) { if (sb.length() > 0) { sb.append(", "); } sb.append(adminArea); } if (!TextUtils.isEmpty(countryCode) && !sOmitCountryCodes.contains(countryCode)) { if (sb.length() > 0) { sb.append(", "); } sb.append(countryCode); } values.put(GalleryContract.MetadataCache.COLUMN_NAME_LOCATION, sb.toString()); } } getContentResolver().insert(GalleryContract.MetadataCache.CONTENT_URI, values); } catch (ParseException e) { Log.w(TAG, "Couldn't read image metadata.", e); } catch (IOException e) { Log.w(TAG, "Couldn't write temporary image file.", e); } finally { if (in != null) { try { in.close(); } catch (IOException ignored) { } } } } }
From source file:pl.selvin.android.listsyncsample.ui.EditItemActivity.java
@Override public Loader<Cursor> onCreateLoader(int lid, Bundle args) { switch (lid) { case PriorityLoaderId: return new CursorLoader(this, ListProvider.getHelper().getDirUri(Database.Priority.TABLE_NAME), new String[] { BaseColumns._ID, Database.Priority.C_NAME }, null, null, null); case StatusLoaderId: return new CursorLoader(this, ListProvider.getHelper().getDirUri(Database.Status.TABLE_NAME), new String[] { BaseColumns._ID, Database.Status.NAME }, null, null, null); case ItemLoaderId: return new CursorLoader(this, id, new String[] { Database.Item.NAME, Database.Item.DESCRIPTION, Database.Item.PRIORITY, Database.Item.STATUS, Database.Item.STARTDATE, Database.Item.ENDDATE }, null, null, null);/* w w w . j a va 2s . c om*/ default: return null; } }
From source file:fr.openbike.android.database.OpenBikeDBAdapter.java
public boolean syncStations(JSONArray jsonBikes) throws SQLiteException, JSONException { if ("".equals(jsonBikes)) return false; boolean needUpdate = false; final int size = jsonBikes.length(); JSONObject jsonStation;//from ww w . j a va 2 s .c om try { mDb.beginTransaction(); ContentValues contentValues = new ContentValues(); final int networkId = jsonBikes.getJSONObject(0).getInt(Station.NETWORK); HashSet<Integer> ids = new HashSet<Integer>(size); for (int i = 0; i < size; i++) { jsonStation = jsonBikes.getJSONObject(i); int id = jsonStation.getInt("id"); ids.add(id); contentValues.put(OpenBikeDBAdapter.KEY_BIKES, jsonStation.getInt(Station.BIKES)); contentValues.put(OpenBikeDBAdapter.KEY_SLOTS, jsonStation.getInt(Station.SLOTS)); contentValues.put(OpenBikeDBAdapter.KEY_OPEN, jsonStation.getBoolean(Station.OPEN)); if (mDb.update(STATIONS_TABLE, contentValues, BaseColumns._ID + " = " + id + " AND " + KEY_NETWORK + " = " + networkId, null) == 0) { needUpdate = true; break; } } if (!needUpdate) { Cursor cursorIds = mDb.query(STATIONS_TABLE, new String[] { BaseColumns._ID }, KEY_NETWORK + " = " + networkId, null, null, null, null); HashSet<Integer> oldIds = new HashSet<Integer>(cursorIds.getCount()); if (cursorIds.moveToFirst()) { do { oldIds.add(cursorIds.getInt(0)); } while (cursorIds.moveToNext()); } oldIds.removeAll(ids); for (Integer id : oldIds) { mDb.delete(STATIONS_TABLE, BaseColumns._ID + " = " + id + " AND " + KEY_NETWORK + " = " + networkId, null); } } } catch (SQLiteException e) { mDb.endTransaction(); throw e; } catch (JSONException e) { mDb.endTransaction(); throw e; } mDb.setTransactionSuccessful(); mDb.endTransaction(); return needUpdate; }
From source file:com.wheelly.fragments.LocationsMapFragment.java
@Subscribe public void onLoadFinished(LocationsLoadedEvent event) { googleMap.clear();/*from ww w .ja v a 2 s .c o m*/ if (null != event.cursor && event.cursor.moveToFirst()) { final int latIdx = event.cursor.getColumnIndex("latitude"); final int lonIdx = event.cursor.getColumnIndex("longitude"); final int nameIdx = event.cursor.getColumnIndex("name"); final int idIdx = event.cursor.getColumnIndex(BaseColumns._ID); final int colorIdx = event.cursor.getColumnIndex("color"); final Aggregate delegate = buildCameraUpdateDelegate(); do { final LatLng l = new LatLng(event.cursor.getDouble(latIdx), event.cursor.getDouble(lonIdx)); final long id = event.cursor.getLong(idIdx); final MarkerOptions markerOptions = new MarkerOptions().position(l) .title(event.cursor.getString(nameIdx)).snippet(Long.toString(id)).draggable(true); final String argb = event.cursor.getString(colorIdx); if (!Strings.isNullOrEmpty(argb)) { float[] hsv = new float[3]; Color.colorToHSV(Color.parseColor(argb), hsv); markerOptions.icon(BitmapDescriptorFactory.defaultMarker(hsv[0])); } // Adding marker on the Google Map googleMap.addMarker(markerOptions); delegate.seed(l, id); } while (event.cursor.moveToNext()); //googleMap.animateCamera(delegate.result()); googleMap.setOnCameraChangeListener(new OnCameraChangeListener() { @Override public void onCameraChange(CameraPosition paramCameraPosition) { googleMap.animateCamera(delegate.result()); googleMap.setOnCameraChangeListener(null); } }); } }
From source file:org.catnut.fragment.ProfileFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { // ??*_*?view? String query = CatnutUtils.buildQuery(PROJECTION, User.screen_name + "=" + CatnutUtils.quote(mScreenName), User.TABLE, null, null, null); new AsyncQueryHandler(getActivity().getContentResolver()) { @Override/*from w ww . ja v a2 s . c o m*/ protected void onQueryComplete(int token, Object cookie, Cursor cursor) { if (cursor.moveToNext()) { injectProfile(cursor); } else { // fall back to load from network... mApp.getRequestQueue().add(new CatnutRequest(getActivity(), UserAPI.profile(mScreenName), new UserProcessor.UserProfileProcessor(), new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { injectProfile(response); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Toast.makeText(getActivity(), getString(R.string.user_not_found), Toast.LENGTH_SHORT).show(); } })); } cursor.close(); } }.startQuery(0, null, CatnutProvider.parse(User.MULTIPLE), null, query, null, null); // ?? if (mApp.getPreferences().getBoolean(getString(R.string.pref_show_latest_tweet), true)) { String queryLatestTweet = CatnutUtils.buildQuery(new String[] { Status.columnText, // Status.thumbnail_pic, Status.bmiddle_pic, Status.comments_count, Status.reposts_count, Status.retweeted_status, Status.attitudes_count, Status.source, Status.created_at, }, new StringBuilder("uid=(select _id from ").append(User.TABLE).append(" where ") .append(User.screen_name).append("=").append(CatnutUtils.quote(mScreenName)).append(")") .append(" and ").append(Status.TYPE).append(" in(").append(Status.HOME).append(",") .append(Status.RETWEET).append(",").append(Status.OTHERS).append(")").toString(), Status.TABLE, null, BaseColumns._ID + " desc", "1"); new AsyncQueryHandler(getActivity().getContentResolver()) { @Override protected void onQueryComplete(int token, Object cookie, Cursor cursor) { if (cursor.moveToNext()) { mTweetLayout.setOnClickListener(tweetsOnclickListener); ViewStub viewStub = (ViewStub) mTweetLayout.findViewById(R.id.latest_tweet); View tweet = viewStub.inflate(); mRetweetLayout = tweet.findViewById(R.id.retweet); tweet.findViewById(R.id.timeline).setVisibility(View.GONE); tweet.findViewById(R.id.verified).setVisibility(View.GONE); tweet.findViewById(R.id.tweet_overflow).setVisibility(View.GONE); CatnutUtils.setText(tweet, R.id.nick, getString(R.string.latest_statues)) .setTextColor(getResources().getColor(R.color.actionbar_background)); String tweetText = cursor.getString(cursor.getColumnIndex(Status.columnText)); TweetImageSpan tweetImageSpan = new TweetImageSpan(getActivity()); TweetTextView text = (TweetTextView) CatnutUtils.setText(tweet, R.id.text, tweetImageSpan.getImageSpan(tweetText)); CatnutUtils.vividTweet(text, null); CatnutUtils.setTypeface(text, mTypeface); text.setLineSpacing(0, mLineSpacing); String thumbsUrl = cursor.getString(cursor.getColumnIndex(Status.bmiddle_pic)); if (!TextUtils.isEmpty(thumbsUrl)) { View thumbs = tweet.findViewById(R.id.thumbs); Picasso.with(getActivity()).load(thumbsUrl).placeholder(R.drawable.error) .error(R.drawable.error).into((ImageView) thumbs); thumbs.setVisibility(View.VISIBLE); } int replyCount = cursor.getInt(cursor.getColumnIndex(Status.comments_count)); CatnutUtils.setText(tweet, R.id.reply_count, CatnutUtils.approximate(replyCount)); int retweetCount = cursor.getInt(cursor.getColumnIndex(Status.reposts_count)); CatnutUtils.setText(tweet, R.id.reteet_count, CatnutUtils.approximate(retweetCount)); int favoriteCount = cursor.getInt(cursor.getColumnIndex(Status.attitudes_count)); CatnutUtils.setText(tweet, R.id.like_count, CatnutUtils.approximate(favoriteCount)); String source = cursor.getString(cursor.getColumnIndex(Status.source)); CatnutUtils.setText(tweet, R.id.source, Html.fromHtml(source).toString()); String create_at = cursor.getString(cursor.getColumnIndex(Status.created_at)); CatnutUtils .setText(tweet, R.id.create_at, DateUtils.getRelativeTimeSpanString(DateTime.getTimeMills(create_at))) .setVisibility(View.VISIBLE); // retweet final String jsonString = cursor.getString(cursor.getColumnIndex(Status.retweeted_status)); try { JSONObject jsonObject = new JSONObject(jsonString); TweetTextView retweet = (TweetTextView) mRetweetLayout.findViewById(R.id.retweet_text); retweet.setText(jsonObject.optString(Status.text)); CatnutUtils.vividTweet(retweet, tweetImageSpan); CatnutUtils.setTypeface(retweet, mTypeface); retweet.setLineSpacing(0, mLineSpacing); long mills = DateTime.getTimeMills(jsonObject.optString(Status.created_at)); TextView tv = (TextView) mRetweetLayout.findViewById(R.id.retweet_create_at); tv.setText(DateUtils.getRelativeTimeSpanString(mills)); TextView retweetUserScreenName = (TextView) mRetweetLayout .findViewById(R.id.retweet_nick); JSONObject user = jsonObject.optJSONObject(User.SINGLE); if (user == null) { retweetUserScreenName.setText(getString(R.string.unknown_user)); } else { retweetUserScreenName.setText(user.optString(User.screen_name)); mRetweetLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getActivity(), TweetActivity.class); intent.putExtra(Constants.JSON, jsonString); startActivity(intent); } }); } } catch (Exception e) { mRetweetLayout.setVisibility(View.GONE); } } cursor.close(); } }.startQuery(0, null, CatnutProvider.parse(Status.MULTIPLE), null, queryLatestTweet, null, null); } }
From source file:com.android.bluetooth.map.BluetoothMapContent.java
private void printSms(Cursor c) { String body = c.getString(c.getColumnIndex(Sms.BODY)); if (D)//from w w w . j ava2s . co m Log.d(TAG, "printSms " + BaseColumns._ID + ": " + c.getLong(c.getColumnIndex(BaseColumns._ID)) + " " + Sms.THREAD_ID + " : " + c.getLong(c.getColumnIndex(Sms.THREAD_ID)) + " " + Sms.ADDRESS + " : " + c.getString(c.getColumnIndex(Sms.ADDRESS)) + " " + Sms.BODY + " : " + body.substring(0, Math.min(body.length(), 8)) + " " + Sms.DATE + " : " + c.getLong(c.getColumnIndex(Sms.DATE)) + " " + Sms.TYPE + " : " + c.getInt(c.getColumnIndex(Sms.TYPE))); }
From source file:org.catnut.adapter.TweetAdapter.java
@Override public void bindView(View view, final Context context, Cursor cursor) { final ViewHolder holder = (ViewHolder) view.getTag(); final long id = cursor.getLong(cursor.getColumnIndex(BaseColumns._ID)); // ??/*from w w w. j a v a 2 s. c o m*/ if (mScreenName == null) { holder.avatar.setVisibility(View.VISIBLE); RequestCreator creator = Picasso.with(context).load(cursor.getString(holder.avatarIndex)) .placeholder(R.drawable.ic_social_person_light); if (mStayInLatest) { creator.error(R.drawable.error); } creator.into(holder.avatar); // final String nick = cursor.getString(holder.nickIndex); final long uid = cursor.getLong(cursor.getColumnIndex(Status.uid)); holder.avatar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { holder.avatar.getDrawable().clearColorFilter(); holder.avatar.invalidate(); Intent intent = new Intent(mContext, ProfileActivity.class); intent.putExtra(User.screen_name, nick); intent.putExtra(Constants.ID, uid); mContext.startActivity(intent); } }); holder.avatar.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return CatnutUtils.imageOverlay(v, event); } }); String remark = cursor.getString(holder.remarkIndex); holder.nick.setText(TextUtils.isEmpty(remark) ? cursor.getString(holder.nickIndex) : remark); if (CatnutUtils.getBoolean(cursor, User.verified)) { holder.verified.setVisibility(View.VISIBLE); } else { holder.verified.setVisibility(View.GONE); } } else { holder.nick.setText(mScreenName); } // ? CatnutUtils.setTypeface(holder.text, mCustomizedFont); holder.text.setLineSpacing(0, mCustomizedLineSpacing); holder.reply.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(context, TweetActivity.class); intent.putExtra(Constants.ID, id); context.startActivity(intent); } }); holder.retweet.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // just go to the tweet' s detail todo maybe will need forward? Intent intent = new Intent(context, TweetActivity.class); intent.putExtra(Constants.ID, id); context.startActivity(intent); } }); holder.text.setTextSize(mCustomizedFontSize); holder.text.setText(cursor.getString(holder.textIndex)); String create_at = cursor.getString(holder.create_atIndex); holder.time.setText(DateTime.getRelativeTimeString(create_at)); int replyCount = cursor.getInt(holder.replyCountIndex); holder.replyCount.setText(CatnutUtils.approximate(replyCount)); int retweetCount = cursor.getInt(holder.reteetCountIndex); holder.reteetCount.setText(CatnutUtils.approximate(retweetCount)); int favoriteCount = cursor.getInt(holder.likeCountIndex); holder.likeCount.setText(CatnutUtils.approximate(favoriteCount)); String source = cursor.getString(holder.sourceIndex); // remove html tags, maybe we should do this after we load the data from cloud... holder.source.setText(Html.fromHtml(source).toString()); // ? CatnutUtils.vividTweet(holder.text, mImageSpan); // ?? injectThumbs(context, cursor.getString(holder.originalPicIndex), cursor.getString(holder.mediumThumbIndex), cursor.getString(holder.smallThumbIndex), holder.thumbs); // ?? retweet(cursor.getString(holder.retweetIndex), holder); // others Bean bean = new Bean(); bean.id = id; bean.favorited = CatnutUtils.getBoolean(cursor, Status.favorited); bean.text = cursor.getString(holder.textIndex); holder.popup.setTag(bean); // inject data holder.popup.setOnClickListener(this); // got more pics ie. > 1 String picsJson = cursor.getString(holder.picsIndex); JSONArray jsonArray = CatnutUtils.optPics(picsJson); injectPicsOverflow(holder.picsOverflow, jsonArray); }