List of usage examples for android.net Uri withAppendedPath
public static Uri withAppendedPath(Uri baseUri, String pathSegment)
From source file:com.ultramegasoft.flavordex2.util.EntryFormHelper.java
/** * Set up the autocomplete for the maker field. */// www . ja v a 2 s . c om private void setupMakersAutoComplete() { final SimpleCursorAdapter adapter = new SimpleCursorAdapter(mFragment.getContext(), R.layout.simple_dropdown_item_2line, null, new String[] { Tables.Makers.NAME, Tables.Makers.LOCATION }, new int[] { android.R.id.text1, android.R.id.text2 }, 0); adapter.setFilterQueryProvider(new FilterQueryProvider() { @Override public Cursor runQuery(CharSequence constraint) { final Uri uri; if (TextUtils.isEmpty(constraint)) { uri = Tables.Makers.CONTENT_URI; } else { uri = Uri.withAppendedPath(Tables.Makers.CONTENT_FILTER_URI_BASE, Uri.encode(constraint.toString())); } final Bundle args = new Bundle(); args.putParcelable("uri", uri); mHandler.post(new Runnable() { @Override public void run() { mFragment.getLoaderManager().restartLoader(LOADER_MAKERS, args, EntryFormHelper.this); } }); return adapter.getCursor(); } }); mTxtMaker.setAdapter(adapter); // fill in maker and origin fields with a suggestion mTxtMaker.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { final Cursor cursor = (Cursor) parent.getItemAtPosition(position); cursor.moveToPosition(position); final String name = cursor.getString(cursor.getColumnIndex(Tables.Makers.NAME)); final String origin = cursor.getString(cursor.getColumnIndex(Tables.Makers.LOCATION)); mTxtMaker.setText(name); mTxtOrigin.setText(origin); // skip origin field mTxtOrigin.focusSearch(View.FOCUS_DOWN).requestFocus(); } }); }
From source file:com.example.edwin.car2charge.MainActivity.java
@Override protected void onListItemClick(ListView l, View v, int position, long id) { String[] projection = { CarDatabase.C_LAT, CarDatabase.C_LONG, CarDatabase.C_ADDRESS, CarDatabase.C_LICENSE, CarDatabase.C_BATTERY };//from ww w .j a v a 2 s . c om Cursor cursor = getContentResolver().query( Uri.withAppendedPath(CarDataProvider.CONTENT_URI, String.valueOf(id)), projection, null, null, null); cursor.moveToFirst(); double lat = cursor.getDouble(0); double lng = cursor.getDouble(1); Intent i = new Intent(getApplicationContext(), DetailActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); i.putExtra("lat", lat); i.putExtra("long", lng); i.putExtra("address", cursor.getString(2)); i.putExtra("license", cursor.getString(3)); i.putExtra("battery", cursor.getString(4)); startActivity(i); cursor.close(); }
From source file:com.android.messaging.mmslib.util.PduCache.java
/** * @param uri The Uri to be normalized./*from w ww . j a va 2 s. com*/ * @return Uri The normalized key of cached entry. */ private Uri normalizeKey(Uri uri) { int match = URI_MATCHER.match(uri); Uri normalizedKey = null; switch (match) { case MMS_ALL_ID: normalizedKey = uri; break; case MMS_INBOX_ID: case MMS_SENT_ID: case MMS_DRAFTS_ID: case MMS_OUTBOX_ID: String msgId = uri.getLastPathSegment(); normalizedKey = Uri.withAppendedPath(Mms.CONTENT_URI, msgId); break; default: return null; } if (LOCAL_LOGV) { Log.v(TAG, uri + " -> " + normalizedKey); } return normalizedKey; }
From source file:org.monospace.smsfilter.MainActivity.java
@Override public void onDialogPositiveClick(DbVars.FilterType type, DbVars.FilterState state, String rule, String desc) { ContentValues values = new ContentValues(4); values.put(DbVars.COL_FIL_TARGET, type.getTarget()); values.put(DbVars.COL_FIL_TYPE, type.getType()); values.put(DbVars.COL_FIL_RULE, type.applyContent(rule)); values.put(DbVars.COL_FIL_STATE, state.toString()); values.put(DbVars.COL_FIL_DESC, desc); getContentResolver().insert(Uri.withAppendedPath(DatabaseProvider.CONTENT_URI, DbVars.TABLE_FILTER), values);//from w w w. j a v a 2 s . c o m FilterListFragment fragment = (FilterListFragment) mTabs.getItem(TAB_FILTER); if (fragment != null) { fragment.getLoaderManager().restartLoader(0, null, fragment); } }
From source file:com.morphoss.jumble.models.Category.java
/** * /*from w w w . j av a2s. c o m*/ * @param context * required to work * @return the next word of the available ones */ public Word getNextWord(Context context) { ContentValues cv = new ContentValues(); ArrayList<String> tempsolved = CategoryWords.getSolvedWordsFromCategory(context, this); double ratioSolved = (double) tempsolved.size() / (double) words.size(); Log.d(TAG, "size of solved list : " + tempsolved.size()); Log.d(TAG, "size of words list : " + words.size()); Log.d(TAG, "ratio solved : " + ratioSolved); Log.d(TAG, "category selected : " + this.getLocalisedName()); int ratio = (int) (ratioSolved * 100); Log.d(TAG, "ratio :" + ratio); if (this.getLocalisedName() == null) { Log.e(TAG, "error localised name is null :"); } cv.put(JumbleCategoryTable.UNLOCK, "0"); cv.put(JumbleCategoryTable.CATEGORY, this.getLocalisedName()); cv.put(JumbleCategoryTable.RATIO, ratio); cv.put(JumbleCategoryTable.CC, SettingsActivity.getLanguageToLoad()); if (ratio == 0) { context.getContentResolver().insert(JumbleProvider.CONTENT_URI_CATEGORIES, cv); } else { cv = new ContentValues(); cv.put(JumbleCategoryTable.RATIO, ratio); String selection = JumbleCategoryTable.CATEGORY + "= ? AND " + JumbleCategoryTable.CC + "= ?"; String[] selectionArgs = { this.getLocalisedName(), SettingsActivity.getLanguageToLoad() }; context.getContentResolver().update( Uri.withAppendedPath(JumbleProvider.CONTENT_URI_CATEGORIES, "addratio"), cv, selection, selectionArgs); } Category nextCategory = CategoryGridAdapter.getCategory(getId()); Log.d(TAG, "next category name : " + nextCategory.getLocalisedName()); if (nextCategory.getLocalisedName() != null && ratio == 0) { cv = new ContentValues(); cv.put(JumbleCategoryTable.UNLOCK, "0"); cv.put(JumbleCategoryTable.CATEGORY, nextCategory.getLocalisedName()); cv.put(JumbleCategoryTable.RATIO, ratio); cv.put(JumbleCategoryTable.CC, SettingsActivity.getLanguageToLoad()); context.getContentResolver().insert(JumbleProvider.CONTENT_URI_CATEGORIES, cv); } if (!nextCategory.unlocked() && ratio > 20 && nextCategory.getLocalisedName() != null) { Log.d(TAG, "unlocking a new category"); unlockedCategories.add(nextCategory.getLocalisedName()); cv = new ContentValues(); //cv.put(JumbleCategoryTable.CATEGORY, nextCategory.getLocalisedName()); //cv.put(JumbleCategoryTable.CC, SettingsActivity.getLanguageToLoad()); cv.put(JumbleCategoryTable.UNLOCK, "1"); String selection = JumbleCategoryTable.CATEGORY + "= ? AND " + JumbleCategoryTable.CC + "= ?"; String[] selectionArgs = { nextCategory.getLocalisedName(), SettingsActivity.getLanguageToLoad() }; context.getContentResolver().update( Uri.withAppendedPath(JumbleProvider.CONTENT_URI_CATEGORIES, "unlockCategory"), cv, selection, selectionArgs); //context.getContentResolver().insert(JumbleProvider.CONTENT_URI_CATEGORIES,cv); nextCategory.setUnlocked(true); } int countEasyWords = wordsEasy.size(); Log.d(TAG, "count of easy words :" + countEasyWords); int countMediumWords = wordsMedium.size(); Log.d(TAG, "count of medium words :" + countMediumWords); int countAdvancedWords = wordsAdvanced.size(); Log.d(TAG, "count of advanced words :" + countAdvancedWords); ArrayList<Word> filteredwords = new ArrayList<Word>(); filteredwords.addAll(wordsEasy); if (filteredwords.size() < 3) filteredwords.addAll(wordsMedium); if (filteredwords.size() < 3) filteredwords.addAll(wordsAdvanced); if (filteredwords.size() == 0) return null; Word word = CategoryWords.getRandomItem(filteredwords); ArrayList<Word> wordList; Log.d(TAG, "the random word is : " + word.getLocalisedWord() + " with level :" + word.getLevel()); switch (word.getLevel()) { case EASY: wordList = wordsEasy; break; case MEDIUM: wordList = wordsMedium; break; case ADVANCED: wordList = wordsAdvanced; break; default: wordList = wordsAdvanced; break; } for (int i = 0; i < wordList.size(); i++) { if (wordList.get(i).equals(word)) { wordList.remove(i); break; } } return word; }
From source file:com.mutu.gpstracker.breadcrumbs.DownloadBreadcrumbsTrackTask.java
@Override protected void onPostExecute(Uri result) { super.onPostExecute(result); long ogtTrackId = Long.parseLong(result.getLastPathSegment()); Uri metadataUri = Uri.withAppendedPath(ContentUris.withAppendedId(Tracks.CONTENT_URI, ogtTrackId), "metadata"); BreadcrumbsTracks tracks = mAdapter.getBreadcrumbsTracks(); Integer bcTrackId = mTrack.second; Integer bcBundleId = tracks.getBundleIdForTrackId(bcTrackId); //TODO Integer bcActivityId = tracks.getActivityIdForBundleId(bcBundleId); String bcDifficulty = tracks.getValueForItem(mTrack, BreadcrumbsTracks.DIFFICULTY); String bcRating = tracks.getValueForItem(mTrack, BreadcrumbsTracks.RATING); String bcPublic = tracks.getValueForItem(mTrack, BreadcrumbsTracks.ISPUBLIC); String bcDescription = tracks.getValueForItem(mTrack, BreadcrumbsTracks.DESCRIPTION); ArrayList<ContentValues> metaValues = new ArrayList<ContentValues>(); if (bcTrackId != null) { metaValues.add(buildContentValues(BreadcrumbsTracks.TRACK_ID, Long.toString(bcTrackId))); }// w w w . j a va 2s . c om if (bcDescription != null) { metaValues.add(buildContentValues(BreadcrumbsTracks.DESCRIPTION, bcDescription)); } if (bcDifficulty != null) { metaValues.add(buildContentValues(BreadcrumbsTracks.DIFFICULTY, bcDifficulty)); } if (bcRating != null) { metaValues.add(buildContentValues(BreadcrumbsTracks.RATING, bcRating)); } if (bcPublic != null) { metaValues.add(buildContentValues(BreadcrumbsTracks.ISPUBLIC, bcPublic)); } if (bcBundleId != null) { metaValues.add(buildContentValues(BreadcrumbsTracks.BUNDLE_ID, Integer.toString(bcBundleId))); } // if (bcActivityId != null) // { // metaValues.add(buildContentValues(BreadcrumbsTracks.ACTIVITY_ID, Integer.toString(bcActivityId))); // } ContentResolver resolver = mContext.getContentResolver(); resolver.bulkInsert(metadataUri, metaValues.toArray(new ContentValues[1])); tracks.addSyncedTrack(ogtTrackId, mTrack.second); }
From source file:com.xorcode.andtweet.TweetListActivity.java
/** * Prepare query to the ContentProvider (to the database) and load List of Tweets with data * @param queryIntent/*from w ww . j a v a 2 s .c o m*/ * @param otherThread This method is being accessed from other thread * @param loadOneMorePage load one more page of tweets */ protected void queryListData(Intent queryIntent, boolean otherThread, boolean loadOneMorePage) { // The search query is provided as an "extra" string in the query intent // TODO maybe use mQueryString here... String queryString = queryIntent.getStringExtra(SearchManager.QUERY); Intent intent = getIntent(); if (MyLog.isLoggable(TAG, Log.VERBOSE)) { Log.v(TAG, "doSearchQuery; queryString=\"" + queryString + "\"; TimelineType=" + mTimelineType); } Uri contentUri = Tweets.CONTENT_URI; SelectionAndArgs sa = new SelectionAndArgs(); String sortOrder = Tweets.DEFAULT_SORT_ORDER; // Id of the last (oldest) tweet to retrieve long lastItemId = -1; if (queryString != null && queryString.length() > 0) { // Record the query string in the recent queries suggestions // provider SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, TimelineSearchSuggestionProvider.AUTHORITY, TimelineSearchSuggestionProvider.MODE); suggestions.saveRecentQuery(queryString, null); contentUri = Tweets.SEARCH_URI; contentUri = Uri.withAppendedPath(contentUri, Uri.encode(queryString)); } intent.putExtra(SearchManager.QUERY, queryString); if (!contentUri.equals(intent.getData())) { intent.setData(contentUri); } if (sa.nArgs == 0) { // In fact this is needed every time you want to load next page of // tweets. // So we have to duplicate here everything we set in // com.xorcode.andtweet.TimelineActivity.onOptionsItemSelected() sa.clear(); sa.addSelection(Tweets.TWEET_TYPE + " IN (?, ?)", new String[] { String.valueOf(Tweets.TIMELINE_TYPE_FRIENDS), String.valueOf(Tweets.TIMELINE_TYPE_MENTIONS) }); if (mTimelineType == Tweets.TIMELINE_TYPE_FAVORITES) { sa.addSelection(AndTweetDatabase.Tweets.FAVORITED + " = ?", new String[] { "1" }); } if (mTimelineType == Tweets.TIMELINE_TYPE_MENTIONS) { sa.addSelection(Tweets.MESSAGE + " LIKE ?", new String[] { "%@" + TwitterUser.getTwitterUser().getUsername() + "%" }); } } if (!positionRestored) { // We have to ensure that saved position will be // loaded from database into the list lastItemId = getSavedPosition(true); } int nTweets = 0; if (mCursor != null && !mCursor.isClosed()) { if (positionRestored) { // If position is NOT loaded - this cursor is from other // timeline/search // and we shouldn't care how much rows are there. nTweets = mCursor.getCount(); } if (!otherThread) { mCursor.close(); } } if (lastItemId > 0) { if (sa.nArgs == 0) { sa.addSelection("AndTweetDatabase.Tweets.TWEET_TYPE" + " IN (?, ?)" + ")", new String[] { String.valueOf(Tweets.TIMELINE_TYPE_FRIENDS), String.valueOf(Tweets.TIMELINE_TYPE_MENTIONS) }); } sa.addSelection(Tweets._ID + " >= ?", new String[] { String.valueOf(lastItemId) }); } else { if (loadOneMorePage) { nTweets += PAGE_SIZE; } else if (nTweets < PAGE_SIZE) { nTweets = PAGE_SIZE; } sortOrder += " LIMIT 0," + nTweets; } // This is for testing pruneOldRecords // try { // FriendTimeline fl = new FriendTimeline(TweetListActivity.this, // AndTweetDatabase.Tweets.TIMELINE_TYPE_FRIENDS); // fl.pruneOldRecords(); // // } catch (Exception e) { // e.printStackTrace(); // } mCursor = getContentResolver().query(contentUri, PROJECTION, sa.selection, sa.selectionArgs, sortOrder); if (!otherThread) { createAdapters(); } }
From source file:cc.softwarefactory.lokki.android.utilities.Utils.java
public static Bitmap openPhoto(Context context, long contactId) { Log.e(TAG, "openPhoto"); if (context == null) { return null; }//from ww w . j a va2s . c o m Uri contactUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactId); Uri photoUri = Uri.withAppendedPath(contactUri, ContactsContract.Contacts.Photo.CONTENT_DIRECTORY); Cursor cursor = context.getContentResolver().query(photoUri, new String[] { ContactsContract.Contacts.Photo.PHOTO }, null, null, null); if (cursor == null) { return null; } try { if (cursor.moveToFirst()) { byte[] data = cursor.getBlob(0); if (data != null) { return BitmapFactory.decodeStream(new ByteArrayInputStream(data)); } } } finally { cursor.close(); } return null; }
From source file:com.gsma.rcs.ri.utils.RcsContactUtil.java
/** * Gets the photo of a contact, or null if no photo is present * /*from w w w. j a v a 2s . c o m*/ * @param contact the contact ID * @return an Bitmap of the photo, or null if no photo is present */ public Bitmap getPhotoFromContactId(ContactId contact) { /* First try to get it from cache */ Bitmap photo = mPhotoContactCache.get(contact); if (photo != null) { return photo; } Uri contactUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_FILTER_URI, Uri.encode(contact.toString())); Cursor cursor = null; try { cursor = mResolver.query(contactUri, PROJ_CONTACT_ID, null, null, null); if (cursor == null) { throw new SQLException("Cannot query photo for contact=" + contact); } if (!cursor.moveToFirst()) { return null; } long contactId = cursor.getLong(cursor.getColumnIndexOrThrow(ContactsContract.PhoneLookup._ID)); InputStream photoInputStream = ContactsContract.Contacts.openContactPhotoInputStream(mResolver, ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactId)); if (photoInputStream != null) { photo = BitmapFactory.decodeStream(photoInputStream); /* Insert in cache */ mPhotoContactCache.put(contact, photo); return photo; } return null; } finally { if (cursor != null) { cursor.close(); } } }
From source file:com.visva.voicerecorder.utils.Utils.java
public static Uri getPhotoUriFromPhoneNumber(ContentResolver resolver, String phoneNo) { Uri result = null;//from w w w. ja v a 2 s . c o m if (phoneNo == "" || "null".equals(phoneNo)) { phoneNo = "111111111"; } String[] projection = null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { projection = new String[] { ContactsContract.Contacts._ID, ContactsContract.PhoneLookup.DISPLAY_NAME, ContactsContract.PhoneLookup.NUMBER, ContactsContract.Contacts.PHOTO_THUMBNAIL_URI, ContactsContract.PhoneLookup.PHOTO_URI, ContactsContract.PhoneLookup.LOOKUP_KEY }; } else { projection = new String[] { ContactsContract.Contacts._ID, ContactsContract.PhoneLookup.DISPLAY_NAME, ContactsContract.PhoneLookup.NUMBER, ContactsContract.PhoneLookup.PHOTO_URI, ContactsContract.PhoneLookup.LOOKUP_KEY }; } Uri lookupUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNo)); Cursor cursor = resolver.query(lookupUri, projection, null, null, null); if (cursor == null) return null; if (cursor.moveToFirst()) { if (cursor.getString(3) != null) result = Uri.parse(cursor.getString(3)); else if (cursor.getString(4) != null) result = Uri.parse(cursor.getString(4)); } if (cursor != null) { cursor.close(); cursor = null; } return result; }