List of usage examples for android.net Uri buildUpon
public abstract Builder buildUpon();
From source file:org.mobisocial.corral.ContentCorral.java
/** * Makes a webapp available offline via the Corral. *//*from w w w. j av a 2 s . co m*/ public static Uri cacheWebApp(Uri appUri, String name) { File localAppDir = new File( new File(Environment.getExternalStorageDirectory(), ContentCorral.APPS_SUBFOLDER), name); try { FileUtils.deleteDirectory(localAppDir); } catch (IOException e) { } localAppDir.mkdirs(); String indexPath = getIndexPath(appUri); try { downloadFile(localAppDir, appUri, indexPath); scrapePage(localAppDir, appUri.buildUpon().path("").build(), indexPath); } catch (IOException e) { Log.e(TAG, "Failed to cache webapp", e); } return getWebappCacheUrl(appUri, localAppDir.getName()); }
From source file:com.mobilesolutionworks.android.httpcache.HttpCacheLoaderImpl.java
public HttpCache onForceLoad(ContentObserver observer) { HttpCache tag = new HttpCache(); tag.local = mBuilder.localUri();/* ww w. ja v a 2 s . co m*/ Uri authority = HttpCacheConfiguration.configure(mContext).authority; ContentResolver cr = mContext.getContentResolver(); tag.cursor = cr.query(authority, PROJECTION, "local = ?", new String[] { tag.local }, null); if (tag.cursor == null) { // cursor only null if provider is not set throw new IllegalStateException("is tag provider set properly?"); } tag.cursor.getCount(); tag.cursor.registerContentObserver(observer); tag.cursor.setNotificationUri(mContext.getContentResolver(), authority.buildUpon().appendEncodedPath(tag.local).build()); if (tag.cursor.moveToFirst()) { // cache stored in database tag.loaded = true; tag.remote = tag.cursor.getString(0); tag.content = tag.cursor.getString(1); tag.expiry = tag.cursor.getLong(2); tag.error = tag.cursor.getInt(3); byte[] trace = tag.cursor.getBlob(4); if (trace != null) { tag.trace = SerializationUtils.deserialize(trace); } tag.status = tag.cursor.getInt(5); } return tag; }
From source file:com.android.music.AlbumBrowserActivity.java
private Cursor getAlbumCursor(AsyncQueryHandler async, String filter) { String[] cols = new String[] { MediaStore.Audio.Albums._ID, MediaStore.Audio.Albums.ARTIST, MediaStore.Audio.Albums.ALBUM, MediaStore.Audio.Albums.ALBUM_ART }; Cursor ret = null;//from w w w. j a v a2 s . c o m if (mArtistId != null) { Uri uri = MediaStore.Audio.Artists.Albums.getContentUri("external", Long.valueOf(mArtistId)); if (!TextUtils.isEmpty(filter)) { uri = uri.buildUpon().appendQueryParameter("filter", Uri.encode(filter)).build(); } if (async != null) { async.startQuery(0, null, uri, cols, null, null, MediaStore.Audio.Albums.DEFAULT_SORT_ORDER); } else { ret = MusicUtils.query(this, uri, cols, null, null, MediaStore.Audio.Albums.DEFAULT_SORT_ORDER); } } else { Uri uri = MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI; if (!TextUtils.isEmpty(filter)) { uri = uri.buildUpon().appendQueryParameter("filter", Uri.encode(filter)).build(); } if (async != null) { async.startQuery(0, null, uri, cols, null, null, MediaStore.Audio.Albums.DEFAULT_SORT_ORDER); } else { ret = MusicUtils.query(this, uri, cols, null, null, MediaStore.Audio.Albums.DEFAULT_SORT_ORDER); } } return ret; }
From source file:com.android.contacts.common.ContactPhotoManager.java
/** * Removes the contact type information stored in the photo URI encoded fragment. * * @param photoUri The photo URI to remove the contact type from. * @return The photo URI with contact type removed. *///from www . j av a2s . c om public static Uri removeContactType(Uri photoUri) { String encodedFragment = photoUri.getEncodedFragment(); if (!TextUtils.isEmpty(encodedFragment)) { Builder builder = photoUri.buildUpon(); builder.encodedFragment(null); return builder.build(); } return photoUri; }
From source file:moose.com.ac.ArticleViewActivity.java
private void filterImg(String str) { Document mDocument = Jsoup.parse(str); Elements imgs = mDocument.select("img"); for (int imgIndex = 0; imgIndex < imgs.size(); imgIndex++) { Element img = imgs.get(imgIndex); String src = img.attr("src").trim(); if (TextUtils.isEmpty(src)) continue; Uri parsedUri = Uri.parse(src); if ("file".equals(parsedUri.getScheme())) continue; if (parsedUri.getPath() == null) continue; if (!"http".equals(parsedUri.getScheme())) { parsedUri = parsedUri.buildUpon().scheme("http").authority("www.acfun.tv").build(); }/*from w ww . ja va 2 s.co m*/ // url may have encoded path parsedUri = parsedUri.buildUpon().path(parsedUri.getPath()).build(); src = parsedUri.toString(); Log.i(TAG, "image src:" + src); img.attr("org", src); if (CommonUtil.getMode() == 1 && !CommonUtil.isWifiConnected(mContext)) {// Log.i(TAG, "[?]"); img.after("<div style=\"width: 100%;text-align: center;\"><br><p>[]</p></div>"); } else { Log.i(TAG, "[?]"); StringBuilder builder = new StringBuilder(); builder.append("<div style='text-align: center;'><br>") .append("<img src='file:///android_asset/loading.gif'").append("name = '").append(src) .append("'\n;onclick = window.JsBridge.showImage('").append(src).append("')") .append(" alt=' '/>\n").append("</div>"); img.after(builder.toString()); Log.i(TAG, "image:table:-" + builder.toString()); } /*if (CommonUtil.getMode() == 1 && !CommonUtil.isWifiConnected(mContext)) { img.after("<p >[]</p>"); } else if (!src.contains(Config.AC_EMOTION)) { StringBuilder builder = new StringBuilder(); builder.append("<div style=\"width: 100%;text-align: center;\"><br><img src=\"") .append(src) .append("\" width=: 100%;height:auto\"") .append(" alt=\" \"/>\n") .append("</div>"); Log.i(TAG, "index image:" + builder.toString()); img.after(builder.toString()); } else { img.after("<img src=\"" + src + "\" alt=\" \"/>\n"); }*/ img.remove(); //img.removeAttr("style"); HtmlBody = mDocument.toString(); Log.i(TAG, "??html:" + HtmlBody); } }
From source file:com.silentcircle.contacts.list.ScContactEntryListAdapter.java
protected Uri getContactUri(int partitionIndex, Cursor cursor, int contactIdColumn) { long contactId = cursor.getLong(contactIdColumn); Uri uri = RawContacts.getLookupUri(contactId); long directoryId = ((DirectoryPartition) getPartition(partitionIndex)).getDirectoryId(); if (directoryId != Directory.DEFAULT) { uri = uri.buildUpon() .appendQueryParameter(ScContactsContract.DIRECTORY_PARAM_KEY, String.valueOf(directoryId)) .build();// w w w. j a va2s. c om } return uri; }
From source file:com.android.contacts.list.ContactEntryListAdapter.java
protected Uri getContactUri(int partitionIndex, Cursor cursor, int contactIdColumn, int lookUpKeyColumn) { long contactId = cursor.getLong(contactIdColumn); String lookupKey = cursor.getString(lookUpKeyColumn); Uri uri = Contacts.getLookupUri(contactId, lookupKey); long directoryId = ((DirectoryPartition) getPartition(partitionIndex)).getDirectoryId(); if (directoryId != Directory.DEFAULT) { uri = uri.buildUpon() .appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY, String.valueOf(directoryId)) .build();// w w w . j a va 2s . c o m } return uri; }
From source file:com.silentcircle.contacts.list.ScDefaultContactListAdapter.java
protected void configureUri(CursorLoader loader, long directoryId, ContactListFilter filter) { Uri uri = RawContacts.CONTENT_URI; if (filter != null && filter.filterType == ContactListFilter.FILTER_TYPE_SINGLE_CONTACT) { uri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, getSelectedContactId()); }//from w w w. java 2 s . c o m if (directoryId == Directory.DEFAULT && isSectionHeaderDisplayEnabled()) { uri = buildSectionIndexerUri(uri); } // The "All accounts" filter is the same as the entire contents of Directory.DEFAULT if (filter != null && filter.filterType != ContactListFilter.FILTER_TYPE_CUSTOM && filter.filterType != ContactListFilter.FILTER_TYPE_SINGLE_CONTACT) { final Uri.Builder builder = uri.buildUpon(); builder.appendQueryParameter(ScContactsContract.DIRECTORY_PARAM_KEY, String.valueOf(Directory.DEFAULT)); if (filter.filterType == ContactListFilter.FILTER_TYPE_ACCOUNT) { filter.addAccountQueryParameterToUrl(builder); } uri = builder.build(); } loader.setUri(uri); }
From source file:com.android.messaging.datamodel.BugleNotifications.java
/** * Returns the displayPhotoUri from the avatar URI, or null if avatar URI * does not have a displayPhotoUri./* w ww . j a va 2 s . c om*/ */ private static Uri getDisplayPhotoUri(final Uri avatarUri) { final Uri thumbnailUri = getThumbnailUri(avatarUri); if (thumbnailUri == null) { return null; } final List<String> originalPaths = thumbnailUri.getPathSegments(); final int originalPathsSize = originalPaths.size(); final StringBuilder newPathBuilder = new StringBuilder(); // Change content://com.android.contacts/contacts("_corp")/123/photo to // content://com.android.contacts/contacts("_corp")/123/display_photo for (int i = 0; i < originalPathsSize; i++) { newPathBuilder.append('/'); if (i == 2) { newPathBuilder.append(ContactsContract.Contacts.Photo.DISPLAY_PHOTO); } else { newPathBuilder.append(originalPaths.get(i)); } } return thumbnailUri.buildUpon().path(newPathBuilder.toString()).build(); }
From source file:bolts.AppLinkNavigation.java
/** * Performs the navigation.//ww w. ja va 2 s . com * * @param context the Context from which the navigation should be performed. * @return the {@link NavigationResult} performed by navigating. */ public NavigationResult navigate(Context context) { PackageManager pm = context.getPackageManager(); Bundle finalAppLinkData = buildAppLinkDataForNavigation(context); Intent eligibleTargetIntent = null; for (AppLink.Target target : getAppLink().getTargets()) { Intent targetIntent = new Intent(Intent.ACTION_VIEW); if (target.getUrl() != null) { targetIntent.setData(target.getUrl()); } else { targetIntent.setData(appLink.getSourceUrl()); } targetIntent.setPackage(target.getPackageName()); if (target.getClassName() != null) { targetIntent.setClassName(target.getPackageName(), target.getClassName()); } targetIntent.putExtra(AppLinks.KEY_NAME_APPLINK_DATA, finalAppLinkData); ResolveInfo resolved = pm.resolveActivity(targetIntent, PackageManager.MATCH_DEFAULT_ONLY); if (resolved != null) { eligibleTargetIntent = targetIntent; break; } } Intent outIntent = null; NavigationResult result = NavigationResult.FAILED; if (eligibleTargetIntent != null) { outIntent = eligibleTargetIntent; result = NavigationResult.APP; } else { // Fall back to the web if it's available Uri webUrl = getAppLink().getWebUrl(); if (webUrl != null) { JSONObject appLinkDataJson; try { appLinkDataJson = getJSONForBundle(finalAppLinkData); } catch (JSONException e) { sendAppLinkNavigateEventBroadcast(context, eligibleTargetIntent, NavigationResult.FAILED, e); throw new RuntimeException(e); } webUrl = webUrl.buildUpon() .appendQueryParameter(AppLinks.KEY_NAME_APPLINK_DATA, appLinkDataJson.toString()).build(); outIntent = new Intent(Intent.ACTION_VIEW, webUrl); result = NavigationResult.WEB; } } sendAppLinkNavigateEventBroadcast(context, outIntent, result, null); if (outIntent != null) { context.startActivity(outIntent); } return result; }