Java Code Examples for android.support.customtabs.CustomTabsIntent#Builder
The following examples show how to use
android.support.customtabs.CustomTabsIntent#Builder .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DropboxConfig.java From rcloneExplorer with MIT License | 6 votes |
@Override protected Boolean doInBackground(Void... voids) { process = rclone.configCreate(options); String url = "http://127.0.0.1:53682/auth"; CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); CustomTabsIntent customTabsIntent = builder.build(); customTabsIntent.launchUrl(context, Uri.parse(url)); try { process.waitFor(); } catch (InterruptedException e) { e.printStackTrace(); } return process.exitValue() == 0; }
Example 2
Source File: LogoutActivity.java From KUAS-AP-Material with MIT License | 6 votes |
@Override public void onClick(View v) { if (v.getId() == R.id.button_openUrl) { mTracker.send(new HitBuilders.EventBuilder().setCategory("open url").setAction("click") .build()); String shareData = mTitle + "\n" + mURL + "\n\n" + getString(R.string.send_from); CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_share_white_24dp); builder.setActionButton(icon, getString(R.string.share), Utils.createSharePendingIntent(this, shareData)); builder.setToolbarColor(ContextCompat.getColor(this, R.color.main_theme)); CustomTabsIntent customTabsIntent = builder.build(); customTabsIntent.launchUrl(this, Uri.parse(mURL)); } else if (v.getId() == R.id.button_logout) { mTracker.send(new HitBuilders.EventBuilder().setCategory("logout").setAction("click") .build()); clearUserData(); startActivity(new Intent(this, LoginActivity.class)); finish(); } }
Example 3
Source File: DriveConfig.java From rcloneExplorer with MIT License | 6 votes |
@Override protected Boolean doInBackground(Void... voids) { process = rclone.configCreate(options); String url = "http://127.0.0.1:53682/auth"; CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); CustomTabsIntent customTabsIntent = builder.build(); customTabsIntent.launchUrl(context, Uri.parse(url)); try { process.waitFor(); } catch (InterruptedException e) { e.printStackTrace(); } return process.exitValue() == 0; }
Example 4
Source File: CustomTabActivityHelper.java From droidddle with Apache License 2.0 | 6 votes |
public static void openCustomTab(Activity activity, Uri uri, CustomTabFallback fallback) { String packageName = CustomTabsHelper.getPackageNameToUse(activity); //If we cant find a package name, it means theres no browser that supports //Chrome Custom Tabs installed. So, we fallback to the webview // 只有 16+版本可以用 custom tabs if (packageName == null || Build.VERSION.SDK_INT < 16) { if (fallback != null) { fallback.openUri(activity, uri); } } else { CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder(); int color = ThemeUtil.getThemeColor(activity, R.attr.colorPrimary); intentBuilder.setToolbarColor(color); intentBuilder.setShowTitle(true); intentBuilder.setStartAnimations(activity, R.anim.slide_in_right, R.anim.slide_out_left); intentBuilder.setExitAnimations(activity, android.R.anim.slide_in_left, android.R.anim.slide_out_right); CustomTabsIntent customTabsIntent = intentBuilder.build(); customTabsIntent.intent.setPackage(packageName); customTabsIntent.launchUrl(activity, uri); } }
Example 5
Source File: PortfolioActivity.java From EasyPortfolio with Apache License 2.0 | 5 votes |
private void openLink(String link) { CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); builder.setToolbarColor(ContextCompat.getColor(this, R.color.cardview_dark_background)); CustomTabsIntent customTabsIntent = builder.build(); customTabsIntent.launchUrl(this, Uri.parse(link)); }
Example 6
Source File: CustomTabsHelper.java From diycode with Apache License 2.0 | 5 votes |
public static void openUrl(Context context, String url) { CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); builder.setToolbarColor(Color.WHITE); builder.setShowTitle(true); builder.setCloseButtonIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable .ic_arrow_back_black_24dp)); builder.addDefaultShareMenuItem(); CustomTabsIntent customTabsIntent = builder.build(); customTabsIntent.launchUrl(context, Uri.parse(url)); }
Example 7
Source File: MainActivity.java From custom-tabs-client with Apache License 2.0 | 5 votes |
private void prepareActionButton(CustomTabsIntent.Builder builder) { // An example intent that sends an email. Intent actionIntent = new Intent(Intent.ACTION_SEND); actionIntent.setType("*/*"); actionIntent.putExtra(Intent.EXTRA_EMAIL, "[email protected]"); actionIntent.putExtra(Intent.EXTRA_SUBJECT, "example"); PendingIntent pi = PendingIntent.getActivity(this, 0, actionIntent, 0); Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_share); builder.setActionButton(icon, "send email", pi, true); }
Example 8
Source File: MainActivity.java From custom-tabs-client with Apache License 2.0 | 5 votes |
private void prepareMenuItems(CustomTabsIntent.Builder builder) { Intent menuIntent = new Intent(); menuIntent.setClass(getApplicationContext(), this.getClass()); // Optional animation configuration when the user clicks menu items. Bundle menuBundle = ActivityOptions.makeCustomAnimation(this, android.R.anim.slide_in_left, android.R.anim.slide_out_right).toBundle(); PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0, menuIntent, 0, menuBundle); builder.addMenuItem("Menu entry 1", pi); }
Example 9
Source File: SearchClinics.java From Crimson with Apache License 2.0 | 5 votes |
private void openCustomTab(String title) { CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); builder.setToolbarColor(ContextCompat.getColor(this, R.color.colorPrimary)); builder.addDefaultShareMenuItem(); CustomTabsIntent customTabsIntent = builder.build(); customTabsIntent.launchUrl(this, Uri.parse("http://www.google.com/search?q=" + title)); }
Example 10
Source File: NewsFragment.java From KUAS-AP-Material with MIT License | 5 votes |
@Override public void onClick(View view) { if (view.getId() == R.id.imageView) { String shareData = newsModel.title + "\n" + newsModel.url + "\n\n" + getString(R.string.send_from); CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_share_white_24dp); builder.setActionButton(icon, getString(R.string.share), Utils.createSharePendingIntent(activity, shareData)); builder.setToolbarColor(ContextCompat.getColor(activity, R.color.main_theme)); CustomTabsIntent customTabsIntent = builder.build(); customTabsIntent.launchUrl(activity, Uri.parse(newsModel.url)); } }
Example 11
Source File: ChromeCustomTabsManager.java From Anecdote with Apache License 2.0 | 5 votes |
/** * Open url */ public void openChrome(Context context, Anecdote anecdote) { String packageName = CustomTabsHelper.getPackageNameToUse(context); //If we cant find a package name, it means theres no browser that supports //Chrome Custom Tabs installed. So, we fallback to the webview if (packageName == null) { try { Toast.makeText(context, R.string.open_intent_browser, Toast.LENGTH_SHORT).show(); context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(anecdote.permalink))); } catch (ActivityNotFoundException exception) { Toast.makeText(context, R.string.open_intent_browser_error, Toast.LENGTH_SHORT).show(); } return; } Log.i(TAG, "openChrome"); CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(getSession()); setIntentAction(context, builder, anecdote); builder.setShowTitle(true); builder.enableUrlBarHiding(); builder.setToolbarColor(mToolbarBackgroundColor); builder.setSecondaryToolbarColor(Color.WHITE); builder.setStartAnimations(context, R.anim.slide_in_right, R.anim.hold); builder.setExitAnimations(context, R.anim.hold, R.anim.slide_out_left); builder.setCloseButtonIcon( Utils.getBitmapFromVectorDrawable(context, R.drawable.ic_arrow_back_white_24dp)); CustomTabsIntent customTabsIntent = builder.build(); customTabsIntent.intent.setPackage(packageName); customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); customTabsIntent.launchUrl(context, Uri.parse(anecdote.permalink)); }
Example 12
Source File: YTutils.java From YTPlayer with GNU General Public License v3.0 | 5 votes |
public static void StartURL(String url, Context context) { CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); builder.setToolbarColor(ContextCompat.getColor(context, R.color.colorPrimary)); CustomTabsIntent customTabsIntent = builder.build(); try { PackageInfo packageInfo = context.getPackageManager().getPackageInfo("com.android.chrome", 0); customTabsIntent.intent.setPackage("com.android.chrome"); customTabsIntent.launchUrl(context, Uri.parse(url)); } catch (Exception e) { Log.e("Chrome", "Chrome not installed: " + e.getMessage()); StartURLIntent(url, context); } }
Example 13
Source File: Browser.java From OsmGo with MIT License | 5 votes |
@PluginMethod() public void open(PluginCall call) { String url = call.getString("url"); String toolbarColor = call.getString("toolbarColor"); if (url == null) { call.error("Must provide a URL to open"); return; } if (url.isEmpty()) { call.error("URL must not be empty"); return; } CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(getCustomTabsSession()); builder.addDefaultShareMenuItem(); if (toolbarColor != null) { try { builder.setToolbarColor(Color.parseColor(toolbarColor)); } catch (IllegalArgumentException ex) { Log.e(getLogTag(), "Invalid color provided for toolbarColor. Using default"); } } CustomTabsIntent tabsIntent = builder.build(); tabsIntent.intent.putExtra(Intent.EXTRA_REFERRER, Uri.parse(Intent.URI_ANDROID_APP_SCHEME + "//" + getContext().getPackageName())); tabsIntent.launchUrl(getContext(), Uri.parse(url)); call.success(); }
Example 14
Source File: CustomTabsClientHelper.java From azure-mobile-apps-android-client with Apache License 2.0 | 5 votes |
CustomTabsIntent.Builder createCustomTabsIntentBuilder() { CustomTabsSession session = null; if (mCustomTabsClient != null) { session = mCustomTabsClient.newSession(null); } return new CustomTabsIntent.Builder(session); }
Example 15
Source File: ViewUtils.java From OmniList with GNU Affero General Public License v3.0 | 5 votes |
public static void launchUrl(Context context, String url) { int primaryColor = ColorUtils.primaryColor(); CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); CustomTabsIntent customTabsIntent = builder .setToolbarColor(primaryColor) .setSecondaryToolbarColor(ColorUtils.calStatusBarColor(primaryColor)) .build(); customTabsIntent.launchUrl(context, Uri.parse(url)); }
Example 16
Source File: ChromeTabActivity.java From More-For-GO with GNU General Public License v3.0 | 5 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.chrome_tabs); if (Globals.url != null) { CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); CustomTabsIntent customTabsIntent = builder.build(); customTabsIntent.launchUrl(ChromeTabActivity.this, Uri.parse(Globals.url)); } else { startActivity(getPackageManager().getLaunchIntentForPackage(Constants.GOPackageName)); finish(); } }
Example 17
Source File: StackOverflowUserAdapter.java From Learning-Resources with MIT License | 5 votes |
public void loadCustomTabs(String url) { CustomTabsIntent.Builder mBuilder = new CustomTabsIntent.Builder(getSession()); mBuilder.setToolbarColor(ContextCompat.getColor(mContext, R.color.colorPrimary)); mBuilder.setCloseButtonIcon(BitmapFactory.decodeResource(mContext.getResources(), R.mipmap.ic_arrow_back_white_24dp)); mBuilder.addMenuItem("Share", setMenuItem(url)); mBuilder.setActionButton(BitmapFactory.decodeResource(mContext.getResources(), R.mipmap.ic_file_download_white_24dp), "Engineering @Lets Nurture", addActionButton()); mBuilder.setStartAnimations(mContext, R.anim.slide_in_right, R.anim.slide_out_left); mBuilder.setExitAnimations(mContext, R.anim.slide_in_left, R.anim.slide_out_right); CustomTabsIntent mIntent = mBuilder.build(); mIntent.launchUrl((Activity) mContext, Uri.parse(url)); }
Example 18
Source File: ActivityHelper.java From FastAccess with GNU General Public License v3.0 | 4 votes |
public static void startCustomTab(@NonNull Activity context) { CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); builder.setToolbarColor(ViewHelper.getPrimaryColor(context)); CustomTabsIntent tabsIntent = builder.build(); tabsIntent.launchUrl(context, Uri.parse("https://github.com/k0shk0sh/FastAccess")); }
Example 19
Source File: DownloadUtils.java From AndroidChromium with Apache License 2.0 | 4 votes |
/** * Creates an Intent that allows viewing the given file in an internal media viewer. * @param fileUri URI pointing at the file, ideally in file:// form. * @param shareUri URI pointing at the file, ideally in content:// form. * @param mimeType MIME type of the file. * @return Intent that can be fired to open the file. */ public static Intent getMediaViewerIntentForDownloadItem( Uri fileUri, Uri shareUri, String mimeType) { Context context = ContextUtils.getApplicationContext(); Intent viewIntent = createViewIntentForDownloadItem(fileUri, mimeType); Bitmap closeIcon = BitmapFactory.decodeResource( context.getResources(), R.drawable.ic_arrow_back_white_24dp); Bitmap shareIcon = BitmapFactory.decodeResource( context.getResources(), R.drawable.ic_share_white_24dp); CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); builder.setToolbarColor(Color.BLACK); builder.setCloseButtonIcon(closeIcon); builder.setShowTitle(true); // Create a PendingIntent that can be used to view the file externally. // TODO(dfalcantara): Check if this is problematic in multi-window mode, where two // different viewers could be visible at the same time. Intent chooserIntent = Intent.createChooser(viewIntent, null); chooserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); String openWithStr = context.getString(R.string.download_manager_open_with); PendingIntent pendingViewIntent = PendingIntent.getActivity( context, 0, chooserIntent, PendingIntent.FLAG_CANCEL_CURRENT); builder.addMenuItem(openWithStr, pendingViewIntent); // Create a PendingIntent that shares the file with external apps. PendingIntent pendingShareIntent = PendingIntent.getActivity( context, 0, createShareIntent(shareUri, mimeType), 0); builder.setActionButton( shareIcon, context.getString(R.string.share), pendingShareIntent, true); // The color of the media viewer is dependent on the file type. int backgroundRes; if (DownloadFilter.fromMimeType(mimeType) == DownloadFilter.FILTER_IMAGE) { backgroundRes = R.color.image_viewer_bg; } else { backgroundRes = R.color.media_viewer_bg; } int mediaColor = ApiCompatibilityUtils.getColor(context.getResources(), backgroundRes); // Build up the Intent further. Intent intent = builder.build().intent; intent.setPackage(context.getPackageName()); intent.setData(fileUri); intent.putExtra(CustomTabIntentDataProvider.EXTRA_IS_MEDIA_VIEWER, true); intent.putExtra( CustomTabIntentDataProvider.EXTRA_INITIAL_BACKGROUND_COLOR, mediaColor); intent.putExtra( CustomTabsIntent.EXTRA_TOOLBAR_COLOR, mediaColor); intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName()); IntentHandler.addTrustedIntentExtras(intent, context); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setClass(context, CustomTabActivity.class); return intent; }
Example 20
Source File: MainActivity.java From explorer with Apache License 2.0 | 3 votes |
private void gotoFeedback() { CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); builder.setToolbarColor(ContextCompat.getColor(this, R.color.colorPrimary0)); builder.build().launchUrl(this, Uri.parse("https://github.com/calintat/Explorer/issues")); }