List of usage examples for android.content ContentUris withAppendedId
public static Uri withAppendedId(Uri contentUri, long id)
From source file:com.commonsware.android.arXiv.ArticleListFragment.java
@Override public void onLoadFinished(arXivLoader itemLoader, List<ArticleList.Item> list) { for (ArticleList.Item item : list) adapter.add(item);/*ww w.jav a 2 s .c o m*/ if (getListAdapter() != adapter) setListAdapter(adapter); firstResult = adapter.getCount() + 1; getListView().removeFooterView(footer); error = itemLoader.hasError(); if (error) { errorMsg.setText(itemLoader.getErrorMsg()); getListView().addFooterView(errorStrip); } else { totalCount = itemLoader.getTotalCount(); if (feedId != -1) { final ContentValues cv = new ContentValues(); cv.put(Feeds.UNREAD, 0); cv.put(Feeds.COUNT, totalCount); cv.put(Feeds.LAST_UPDATE, System.currentTimeMillis()); final Uri feedUri = ContentUris.withAppendedId(Feeds.CONTENT_URI, feedId); new Thread() { @Override public void run() { getActivity().getContentResolver().update(feedUri, cv, null, null); getActivity().getContentResolver().notifyChange(feedUri, null); } }.start(); } } }
From source file:at.bitfire.davdroid.resource.LocalCollection.java
/** * Finds new resources (resources which haven't been uploaded yet). * New resources are 1) dirty, and 2) don't have an ETag yet. * Only records matching sqlFilter will be returned. * //from www . jav a2 s.c o m * @return IDs of new resources * @throws LocalStorageException when the content provider couldn't be queried */ public long[] findNew() throws LocalStorageException { String where = entryColumnDirty() + "=1 AND " + entryColumnETag() + " IS NULL"; if (entryColumnParentID() != null) where += " AND " + entryColumnParentID() + "=" + String.valueOf(getId()); if (sqlFilter != null) where += " AND (" + sqlFilter + ")"; try { @Cleanup Cursor cursor = providerClient.query(entriesURI(), new String[] { entryColumnID() }, where, null, null); if (cursor == null) throw new LocalStorageException("Couldn't query new records"); long[] fresh = new long[cursor.getCount()]; for (int idx = 0; cursor.moveToNext(); idx++) { long id = cursor.getLong(0); // new record: we have to generate UID + remote file name for uploading T resource = findById(id, false); resource.initialize(); // write generated UID + remote file name into database ContentValues values = new ContentValues(2); values.put(entryColumnUID(), resource.getUid()); values.put(entryColumnRemoteName(), resource.getName()); providerClient.update(ContentUris.withAppendedId(entriesURI(), id), values, null, null); fresh[idx] = id; } return fresh; } catch (RemoteException ex) { throw new LocalStorageException(ex); } }
From source file:com.ksk.droidbatterybooster.provider.TimeSchedule.java
/** * Return an TimeSchedule object representing the schedule id in the database. * Returns null if no schedule exists./*from www .jav a 2 s. c o m*/ */ public static TimeSchedule getTimeSchedule(ContentResolver contentResolver, long scheduleId) { Cursor cursor = contentResolver.query(ContentUris.withAppendedId(CONTENT_URI, scheduleId), QUERY_COLUMNS, null, null, null); TimeSchedule schedule = null; if (cursor != null) { if (cursor.moveToFirst()) { schedule = new TimeSchedule(cursor); } cursor.close(); } return schedule; }
From source file:cn.code.notes.gtask.data.SqlData.java
public void commit(long noteId, boolean validateVersion, long version) { if (mIsCreate) { if (mDataId == INVALID_ID && mDiffDataValues.containsKey(DataColumns.ID)) { mDiffDataValues.remove(DataColumns.ID); }/*from w ww . j a va2 s .c o m*/ mDiffDataValues.put(DataColumns.NOTE_ID, noteId); Uri uri = mContentResolver.insert(Notes.CONTENT_DATA_URI, mDiffDataValues); try { mDataId = Long.valueOf(uri.getPathSegments().get(1)); } catch (NumberFormatException e) { Log.e(TAG, "Get note id error :" + e.toString()); throw new ActionFailureException("create note failed"); } } else { if (mDiffDataValues.size() > 0) { int result = 0; if (!validateVersion) { result = mContentResolver.update(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, mDataId), mDiffDataValues, null, null); } else { result = mContentResolver.update(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, mDataId), mDiffDataValues, " ? in (SELECT " + NoteColumns.ID + " FROM " + TABLE.NOTE + " WHERE " + NoteColumns.VERSION + "=?)", new String[] { String.valueOf(noteId), String.valueOf(version) }); } if (result == 0) { Log.w(TAG, "there is no update. maybe user updates note when syncing"); } } } mDiffDataValues.clear(); mIsCreate = false; }
From source file:edu.cens.loci.ui.VisitDetailActivity.java
private void updateData(Uri visitUri) { ContentResolver resolver = getContentResolver(); Cursor visitCursor = resolver.query(visitUri, VISIT_LOG_PROJECTION, null, null, null); try {/*from ww w . j a va 2 s.c o m*/ if (visitCursor != null && visitCursor.moveToFirst()) { long placeId = visitCursor.getLong(PLACE_ID_INDEX); long enter = visitCursor.getLong(ENTER_INDEX); long exit = visitCursor.getLong(EXIT_INDEX); int type = visitCursor.getInt(TYPE); String extra1 = visitCursor.getString(EXTRA1_INDEX); String extra2 = visitCursor.getString(EXTRA2_INDEX); MyLog.d(LociConfig.D.UI.DEBUG, TAG, String.format("[updateData] placeId=%d enter=%s exit=%s type=%d extra1=%s extra2=%s", placeId, MyDateUtils.getTimeFormatLong(enter), MyDateUtils.getTimeFormatLong(exit), type, extra1, extra2)); // Place name String place_name = ""; int place_state = 0; if (placeId > 0) { String placeSelection = Places._ID + "=" + placeId; Uri placeUri = ContentUris.withAppendedId(Places.CONTENT_URI, placeId); Cursor placeCursor = resolver.query(placeUri, PLACE_PROJECTION, placeSelection, null, null); if (placeCursor != null && placeCursor.moveToFirst()) { place_name = placeCursor.getString(PLACE_NAME_INDEX); place_state = placeCursor.getInt(PLACE_STATE_INDEX); placeCursor.close(); } else { place_name = "Unknown"; } } else { place_name = "Unknown"; } mPlaceName.setText(place_name); // Pull out string in format [relative], [date] CharSequence dateClause = DateUtils.formatDateRange(this, enter, enter, DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_SHOW_YEAR); mVisitTime.setText(dateClause); // Set the duration mVisitDuration.setText(formatDuration((exit - enter) / 1000)); switch (type) { case Visits.TYPE_GPS: mPlaceTypeIcon.setImageResource(R.drawable.icon_satellite); break; case Visits.TYPE_WIFI: mPlaceTypeIcon.setImageResource(R.drawable.icon_wifi); break; } List<ViewEntry> actions = new ArrayList<ViewEntry>(); // View place Intent viewPlaceIntent = new Intent(Intent.ACTION_VIEW, ContentUris.withAppendedId(Places.CONTENT_URI, placeId)); String placeViewLabel = ""; MyLog.d(LociConfig.D.UI.DEBUG, TAG, String.format("[updateData] placename=%s placestate=%d", place_name, place_state)); switch (place_state) { case Places.STATE_SUGGESTED: placeViewLabel = "Handle Suggested Place"; break; case Places.STATE_REGISTERED: placeViewLabel = "View " + place_name; break; default: placeViewLabel = null;//place_name + " state " + place_state; } if (placeViewLabel != null) { ViewEntry entry = new ViewEntry(LIST_ACTION_VIEW_PLACE, R.drawable.sym_action_map, placeViewLabel, null, null); entry.intent = viewPlaceIntent; actions.add(entry); } // View Wifi APs if (type == Visits.TYPE_WIFI && extra1 != null) { LociWifiFingerprint wifi; String apsAbstract = "Not available"; try { wifi = new LociWifiFingerprint(extra1); apsAbstract = wifi.getWifiInfoSubstring(5); ViewEntry wifiEntry = new ViewEntry(LIST_ACTION_VIEW_WIFIS, R.drawable.ic_settings_wireless, "View Wi-Fi APs", apsAbstract, null); wifiEntry.extra_string = extra1; actions.add(wifiEntry); } catch (JSONException e) { MyLog.e(LociConfig.D.JSON, TAG, "wifi json failed : " + extra1); e.printStackTrace(); } } // Additional Actions if (placeId > 0) { if (place_state == Places.STATE_REGISTERED || place_state == Places.STATE_BLOCKED) { if (type == Visits.TYPE_WIFI && extra1 != null) { ViewEntry entry = new ViewEntry(LIST_ACTION_CHANGE_PLACE, android.R.drawable.ic_menu_edit, "Change Place", null, null); entry.intent = new Intent(Intents.UI.ACTION_INSERT); entry.intent.putExtra(Intents.UI.LIST_ORDER_EXTRA_KEY, PlacesList.LIST_ORDER_TYPE_WIFI_SIMILARITY); entry.intent.putExtra(Intents.UI.LIST_ORDER_EXTRA_WIFI_KEY, extra1); entry.intent.putExtra(Intents.UI.LIST_ORDER_EXTRA_WIFI_TIME_KEY, String.valueOf(enter)); entry.intent.putExtra(Intents.UI.PLACE_ENTRY_TYPE_EXTRA_KEY, Places.ENTRY_WIFI_OVERWRITE_WRONG_RECOGNITION); actions.add(entry); } } } else { ViewEntry entry = new ViewEntry(LIST_ACTION_ADD_PLACE, R.drawable.sym_action_add, "Add Place", null, null); entry.intent = new Intent(Intents.UI.ACTION_INSERT); entry.intent.putExtra(Intents.UI.LIST_ORDER_EXTRA_KEY, PlacesList.LIST_ORDER_TYPE_WIFI_SIMILARITY); entry.intent.putExtra(Intents.UI.LIST_ORDER_EXTRA_WIFI_KEY, extra1); entry.intent.putExtra(Intents.UI.LIST_ORDER_EXTRA_WIFI_TIME_KEY, String.valueOf(enter)); entry.intent.putExtra(Intents.UI.PLACE_ENTRY_TYPE_EXTRA_KEY, Places.ENTRY_WIFI_USE_SHORT_VISIT); actions.add(entry); } // View Recognition Results //Log.d(TAG, "recog: " + extra2); if (extra2 != null && !TextUtils.isEmpty(extra2)) { ViewEntry recogEntry = new ViewEntry(LIST_ACTION_VIEW_RECOGNITION, R.drawable.ic_clock_strip_desk_clock, "View Recogntion Results", "", null); recogEntry.extra_string = extra2; actions.add(recogEntry); } ViewAdapter adapter = new ViewAdapter(this, actions); setListAdapter(adapter); //Log.d(TAG, String.format("placeId=%d enter=%s exit=%s", placeId, MyDateUtils.getDateFormatLong(enter), MyDateUtils.getDateFormatLong(exit))); //Log.d(TAG, String.format("extra1=%s", extra1)); //Log.d(TAG, String.format("extra2=%s", extra2)); } } finally { if (visitCursor != null) { visitCursor.close(); } } }
From source file:com.rukman.emde.smsgroups.platform.GMSContactOperations.java
public static int removeGroupFromContacts(ContentProviderClient provider, Account account, long rawContactId, SyncResult result) throws RemoteException { Uri uri = addCallerIsSyncAdapterParameter(ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId), true);//from ww w . ja v a 2s . c om return provider.delete(uri, null, null); }
From source file:com.xorcode.andtweet.FriendTimeline.java
/** * Insert a row from a JSONObject./*from w w w .ja va 2 s .c o m*/ * * @param jo * @return * @throws JSONException * @throws SQLiteConstraintException */ public Uri insertFromJSONObject(JSONObject jo) throws JSONException, SQLiteConstraintException { ContentValues values = new ContentValues(); // Construct the Uri to existing record Long lTweetId = Long.parseLong(jo.getString("id")); Uri aTweetUri = ContentUris.withAppendedId(mContentUri, lTweetId); String message = Html.fromHtml(jo.getString("text")).toString(); try { // TODO: Unify databases! switch (mTimelineType) { case AndTweetDatabase.Tweets.TIMELINE_TYPE_FRIENDS: case AndTweetDatabase.Tweets.TIMELINE_TYPE_MENTIONS: JSONObject user; user = jo.getJSONObject("user"); values.put(AndTweetDatabase.Tweets._ID, lTweetId.toString()); values.put(AndTweetDatabase.Tweets.AUTHOR_ID, user.getString("screen_name")); values.put(AndTweetDatabase.Tweets.MESSAGE, message); values.put(AndTweetDatabase.Tweets.SOURCE, jo.getString("source")); values.put(AndTweetDatabase.Tweets.TWEET_TYPE, mTimelineType); values.put(AndTweetDatabase.Tweets.IN_REPLY_TO_STATUS_ID, jo.getString("in_reply_to_status_id")); values.put(AndTweetDatabase.Tweets.IN_REPLY_TO_AUTHOR_ID, jo.getString("in_reply_to_screen_name")); values.put(AndTweetDatabase.Tweets.FAVORITED, jo.getBoolean("favorited") ? 1 : 0); break; case AndTweetDatabase.Tweets.TIMELINE_TYPE_MESSAGES: values.put(AndTweetDatabase.DirectMessages._ID, lTweetId.toString()); values.put(AndTweetDatabase.DirectMessages.AUTHOR_ID, jo.getString("sender_screen_name")); values.put(AndTweetDatabase.DirectMessages.MESSAGE, message); break; } Long created = Date.parse(jo.getString("created_at")); values.put(AndTweetDatabase.Tweets.SENT_DATE, created); } catch (Exception e) { Log.e(TAG, "insertFromJSONObject: " + e.toString()); } if ((mContentResolver.update(aTweetUri, values, null, null)) == 0) { // There was no such row so add new one mContentResolver.insert(mContentUri, values); mNewTweets++; switch (mTimelineType) { case AndTweetDatabase.Tweets.TIMELINE_TYPE_FRIENDS: case AndTweetDatabase.Tweets.TIMELINE_TYPE_MENTIONS: if (mTu.getUsername().equals(jo.getString("in_reply_to_screen_name")) || message.contains("@" + mTu.getUsername())) { mReplies++; } } } return aTweetUri; }
From source file:com.ternup.caddisfly.fragment.DetailsFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); getActivity().setTitle(R.string.details); mContext = getActivity();/* ww w . j a v a2 s. c om*/ ListView listView = getListView(); mFolderName = getArguments().getString(PreferencesHelper.FOLDER_NAME_KEY); View header = getActivity().getLayoutInflater().inflate(R.layout.fragment_result, null, false); mPpmText = (TextView) header.findViewById(R.id.ppmText); mDateView = (TextView) header.findViewById(R.id.testDate); mTitleView = (TextView) header.findViewById(R.id.titleView); mResultTextView = (TextView) header.findViewById(R.id.result); mAddressText = (TextView) header.findViewById(R.id.address1); mAddress2Text = (TextView) header.findViewById(R.id.address2); mAddress3Text = (TextView) header.findViewById(R.id.address3); mSourceText = (TextView) header.findViewById(R.id.sourceType); final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext); mFolderName = getArguments().getString(PreferencesHelper.FOLDER_NAME_KEY); mId = getArguments().getLong(getString(R.string.currentTestId)); mLocationId = sharedPreferences.getLong(getString(R.string.currentLocationId), -1); File directory = new File(FileUtils.getStoragePath(getActivity(), mLocationId, mFolderName, false)); long locationId = sharedPreferences.getLong(getString(R.string.currentLocationId), -1); final ArrayList<String> imagePaths = FileUtils.getFilePaths(getActivity(), mFolderName, "/small/", locationId); if (mId > -1) { if (!directory.exists()) { Uri uri = ContentUris.withAppendedId(TestContentProvider.CONTENT_URI, mId); mContext.getContentResolver().delete(uri, null, null); goBack(); } else if (imagePaths.size() > 0) { displayResult(); } else { FileUtils.deleteFolder(getActivity(), mLocationId, mFolderName); goBack(); } } ListView drawerList = (ListView) getActivity().findViewById(R.id.navigation_drawer); drawerList.setItemChecked(-1, true); drawerList.setSelection(-1); assert listView != null; listView.addHeaderView(header); // Gradient shading for title assert header != null; //Collections.sort(imagePaths); GalleryListAdapter adapter = new GalleryListAdapter(getActivity(), mTestTypeId, mId, imagePaths, true); setListAdapter(adapter); Shader textShader = new LinearGradient(0, 0, 0, mTitleView.getPaint().getTextSize(), new int[] { getResources().getColor(R.color.textGradientStart), getResources().getColor(R.color.textGradientEnd) }, new float[] { 0, 1 }, Shader.TileMode.CLAMP); mTitleView.getPaint().setShader(textShader); }
From source file:at.bitfire.davdroid.resource.LocalTaskList.java
@Override public void setCTag(String cTag) throws LocalStorageException { ContentValues values = new ContentValues(1); values.put(COLLECTION_COLUMN_CTAG, cTag); try {//from ww w .j ava 2 s . c o m providerClient.update(ContentUris.withAppendedId(taskListsURI(account), id), values, null, null); } catch (RemoteException e) { throw new LocalStorageException(e); } }
From source file:com.example.android.notepad.CMNotesProvider.java
@Override public Uri insert(Uri uri, ContentValues initialValues) { // Validate the requested uri if (sUriMatcher.match(uri) != NOTES) { throw new IllegalArgumentException("Unknown URI " + uri); }/* w ww . ja v a2 s. c om*/ ContentValues values; if (initialValues != null) { values = new ContentValues(initialValues); } else { values = new ContentValues(); } Long now = Long.valueOf(System.currentTimeMillis()); // Make sure that the fields are all set if (values.containsKey(NotePad.Notes.CREATED_DATE) == false) { values.put(NotePad.Notes.CREATED_DATE, now); } if (values.containsKey(NotePad.Notes.MODIFIED_DATE) == false) { values.put(NotePad.Notes.MODIFIED_DATE, now); } if (values.containsKey(NotePad.Notes.TITLE) == false) { Resources r = Resources.getSystem(); values.put(NotePad.Notes.TITLE, r.getString(android.R.string.untitled)); } if (values.containsKey(NotePad.Notes.NOTE) == false) { values.put(NotePad.Notes.NOTE, ""); } CMAdapter cmadapter = new CMAdapter(); // for the moment, use time for the key String key = System.currentTimeMillis() + ""; String new_key = cmadapter.updateValue(key, values); if (new_key != null) { System.out.println("Set key: " + key + ", got key: " + new_key); Uri noteUri = ContentUris.withAppendedId(NotePad.Notes.CONTENT_URI, Long.parseLong(new_key)); getContext().getContentResolver().notifyChange(noteUri, null); return noteUri; } // SQLiteDatabase db = mOpenHelper.getWritableDatabase(); // long rowId = db.insert(NOTES_TABLE_NAME, Notes.NOTE, values); // if (rowId > 0) { // Uri noteUri = ContentUris.withAppendedId(NotePad.Notes.CONTENT_URI, rowId); // getContext().getContentResolver().notifyChange(noteUri, null); // return noteUri; // } throw new SQLException("Failed to insert row into " + uri); }