Java Code Examples for androidx.browser.customtabs.CustomTabsIntent#Builder

The following examples show how to use androidx.browser.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: MainActivity.java    From pandora with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    String url = "https://github.com/whataa/pandora";
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        Uri githubUrl = Uri.parse(url);
        intent.setData(githubUrl);
        if (intent.resolveActivity(getPackageManager()) != null) {
            startActivity(intent);
        }
    } else {
        CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
        builder.setToolbarColor(getResources().getColor(R.color.colorPrimary));
        CustomTabsIntent customTabsIntent = builder.build();
        customTabsIntent.launchUrl(this, Uri.parse(url));
    }
    return true;
}
 
Example 2
Source File: PostListAdapter.java    From indigenous-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onClick(View v) {
    PostListItem item = items.get(this.position);

    try {
        CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
        intentBuilder.setToolbarColor(ContextCompat.getColor(context, R.color.colorPrimary));
        intentBuilder.setSecondaryToolbarColor(ContextCompat.getColor(context, R.color.colorPrimaryDark));
        CustomTabsIntent customTabsIntent = intentBuilder.build();
        customTabsIntent.intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        customTabsIntent.launchUrl(context, Uri.parse(item.getUrl()));
    }
    catch (Exception ignored) { }

}
 
Example 3
Source File: TimelineDetailActivity.java    From indigenous-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Link clickable.
 *
 * @param strBuilder
 *   A string builder.
 * @param span
 *   The span with url.
 */
private void makeLinkClickable(SpannableStringBuilder strBuilder, final URLSpan span) {
    int start = strBuilder.getSpanStart(span);
    int end = strBuilder.getSpanEnd(span);
    int flags = strBuilder.getSpanFlags(span);
    ClickableSpan clickable = new ClickableSpan() {
        public void onClick(@NonNull View view) {
            try {
                CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
                intentBuilder.setToolbarColor(ContextCompat.getColor(TimelineDetailActivity.this, R.color.colorPrimary));
                intentBuilder.setSecondaryToolbarColor(ContextCompat.getColor(TimelineDetailActivity.this, R.color.colorPrimaryDark));
                CustomTabsIntent customTabsIntent = intentBuilder.build();
                customTabsIntent.intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                customTabsIntent.launchUrl(TimelineDetailActivity.this, Uri.parse(span.getURL()));
            }
            catch (Exception ignored) { }
        }
    };
    strBuilder.setSpan(clickable, start, end, flags);
    strBuilder.removeSpan(span);
}
 
Example 4
Source File: TimelineListAdapter.java    From indigenous-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Link clickable.
 *
 * @param strBuilder
 *   A string builder.
 * @param span
 *   The span with url.
 */
private void makeLinkClickable(SpannableStringBuilder strBuilder, final URLSpan span) {
    int start = strBuilder.getSpanStart(span);
    int end = strBuilder.getSpanEnd(span);
    int flags = strBuilder.getSpanFlags(span);
    ClickableSpan clickable = new ClickableSpan() {
        public void onClick(View view) {
            try {
                CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
                intentBuilder.setToolbarColor(ContextCompat.getColor(context, R.color.colorPrimary));
                intentBuilder.setSecondaryToolbarColor(ContextCompat.getColor(context, R.color.colorPrimaryDark));
                CustomTabsIntent customTabsIntent = intentBuilder.build();
                customTabsIntent.intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                customTabsIntent.launchUrl(context, Uri.parse(span.getURL()));
            }
            catch (Exception ignored) { }
        }
    };
    strBuilder.setSpan(clickable, start, end, flags);
    strBuilder.removeSpan(span);
}
 
Example 5
Source File: TimelineListAdapter.java    From indigenous-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onClick(View v) {
    TimelineItem item = items.get(this.position);

    try {
        CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
        intentBuilder.setToolbarColor(ContextCompat.getColor(context, R.color.colorPrimary));
        intentBuilder.setSecondaryToolbarColor(ContextCompat.getColor(context, R.color.colorPrimaryDark));
        CustomTabsIntent customTabsIntent = intentBuilder.build();
        customTabsIntent.intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        customTabsIntent.launchUrl(context, Uri.parse(item.getUrl()));
    }
    catch (Exception ignored) { }

}
 
Example 6
Source File: ChatAdapter.java    From Twire with GNU General Public License v3.0 6 votes vote down vote up
private void checkForLink(String message, SpannableStringBuilder spanbuilder) {
    Matcher linkMatcher = Patterns.WEB_URL.matcher(message);
    while (linkMatcher.find()) {
        String url = linkMatcher.group(0);

        if (!url.matches("^https?://.+"))
            url = "http://" + url;

        final String finalUrl = url;
        ClickableSpan clickableSpan = new ClickableSpan() {
            @Override
            public void onClick(View view) {
                CustomTabsIntent.Builder mTabs = new CustomTabsIntent.Builder();
                mTabs.setStartAnimations(context, R.anim.slide_in_bottom_anim, R.anim.fade_out_semi_anim);
                mTabs.setExitAnimations(context, R.anim.fade_in_semi_anim, R.anim.slide_out_bottom_anim);
                mTabs.build().launchUrl(context, Uri.parse(finalUrl));

                mRecyclerView.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
            }
        };

        spanbuilder.setSpan(clickableSpan, linkMatcher.start(), linkMatcher.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}
 
Example 7
Source File: AppUtils.java    From materialistic with Apache License 2.0 6 votes vote down vote up
@NonNull
private static Intent createViewIntent(Context context, @Nullable WebItem item,
                                       String url, @Nullable CustomTabsSession session) {
    if (Preferences.customTabsEnabled(context)) {
        CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(session)
                .setToolbarColor(ContextCompat.getColor(context,
                        AppUtils.getThemedResId(context, R.attr.colorPrimary)))
                .setShowTitle(true)
                .enableUrlBarHiding()
                .addDefaultShareMenuItem();
        if (item != null) {
            builder.addMenuItem(context.getString(R.string.comments),
                    PendingIntent.getActivity(context, 0,
                            new Intent(context, ItemActivity.class)
                                    .putExtra(ItemActivity.EXTRA_ITEM, item)
                                    .putExtra(ItemActivity.EXTRA_OPEN_COMMENTS, true),
                            PendingIntent.FLAG_ONE_SHOT));
        }
        return builder.build().intent.setData(Uri.parse(url));
    } else {
        return new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    }
}
 
Example 8
Source File: FileActivity.java    From lrkFM with MIT License 5 votes vote down vote up
/**
 * Opens the bug report page.
 */
private void launchBugReportTab() {
    CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
    builder.setToolbarColor(getColorByAttr(R.attr.colorPrimary));
    CustomTabsIntent build = builder.build();
    build.launchUrl(this, Uri.parse("https://github.com/lfuelling/lrkFM/issues/new"));
}
 
Example 9
Source File: ComicFragment.java    From Easy_xkcd with Apache License 2.0 5 votes vote down vote up
protected boolean explainComic(int number) {
    String url = "https://explainxkcd.com/" + String.valueOf(number);
    if (prefHelper.useCustomTabs()) {
        CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
        intentBuilder.setToolbarColor(themePrefs.getPrimaryColor(false));
        CustomTabActivityHelper.openCustomTab(getActivity(), intentBuilder.build(), Uri.parse(url), new BrowserFallback());
    } else {
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        startActivity(intent);
    }
    return true;
}
 
Example 10
Source File: AboutShortcuts.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
private static void openUrl(Context ctx, String url) {
    try {
        CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
        builder.setToolbarColor(ctx.getResources().getColor(R.color.colorPrimary));
        CustomTabsIntent customTabsIntent = builder.build();
        customTabsIntent.launchUrl(ctx, Uri.parse(url));
    } catch (ActivityNotFoundException e) {
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(url));
        ctx.startActivity(i);
    }
}
 
Example 11
Source File: CustomTabsHelper.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
@NonNull private CustomTabsIntent.Builder getBuilder(Context context, int color) {
  Intent openInNativeIntent =
      new Intent(context.getApplicationContext(), CustomTabNativeReceiver.class);
  PendingIntent pendingIntent =
      PendingIntent.getBroadcast(context.getApplicationContext(), 0, openInNativeIntent, 0);
  return new CustomTabsIntent.Builder().setToolbarColor(ContextCompat.getColor(context, color))
      .setShowTitle(true)
      .setCloseButtonIcon(
          BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_arrow_back))
      .addDefaultShareMenuItem()
      .addMenuItem(context.getString(R.string.customtabs_open_native_app), pendingIntent)
      .setStartAnimations(context, R.anim.slide_in_right, R.anim.slide_out_left)
      .setExitAnimations(context, R.anim.slide_in_left, R.anim.slide_out_right);
}
 
Example 12
Source File: NavigationUtils.java    From zephyr with MIT License 5 votes vote down vote up
public static void openUrl(@NonNull Context context, @NonNull String url) {
    try {
        CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
        builder.setToolbarColor(ContextCompat.getColor(context, R.color.primary));
        CustomTabsIntent customTabsIntent = builder.build();
        customTabsIntent.launchUrl(context, Uri.parse(url));
    } catch (ActivityNotFoundException e) {
        Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        context.startActivity(browserIntent);
    }
}
 
Example 13
Source File: AboutShortcuts.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
private static void openUrl(Context ctx, String url) {
    try {
        CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
        builder.setToolbarColor(ctx.getResources().getColor(R.color.colorPrimary));
        CustomTabsIntent customTabsIntent = builder.build();
        customTabsIntent.launchUrl(ctx, Uri.parse(url));
    } catch (ActivityNotFoundException e) {
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(url));
        ctx.startActivity(i);
    }
}
 
Example 14
Source File: DatabaseManager.java    From Easy_xkcd with Apache License 2.0 5 votes vote down vote up
@Override
protected void onPostExecute(String url) {
    progress.dismiss();
    if (url.equals(""))
        Toast.makeText(context, context.getResources().getString(R.string.thread_not_found), Toast.LENGTH_SHORT).show();
    else {
        CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
        intentBuilder.setToolbarColor(new ThemePrefs(context).getPrimaryColor(false));
        CustomTabActivityHelper.openCustomTab(((Activity) context), intentBuilder.build(), Uri.parse(url), new BrowserFallback());
    }

}
 
Example 15
Source File: LinkResolverActivity.java    From Infinity-For-Reddit with GNU Affero General Public License v3.0 5 votes vote down vote up
private void openInCustomTabs(Uri uri, PackageManager pm, boolean handleError) {
    ArrayList<ResolveInfo> resolveInfos = getCustomTabsPackages(pm);
    if (!resolveInfos.isEmpty()) {
        CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
        // add share action to menu list
        builder.addDefaultShareMenuItem();
        builder.setToolbarColor(mCustomThemeWrapper.getColorPrimary());
        CustomTabsIntent customTabsIntent = builder.build();
        customTabsIntent.intent.setPackage(resolveInfos.get(0).activityInfo.packageName);
        if (uri.getScheme() == null) {
            uri = Uri.parse("http://" + uri.toString());
        }
        try {
            customTabsIntent.launchUrl(this, uri);
        } catch (ActivityNotFoundException e) {
            if (handleError) {
                openInBrowser(uri, pm, false);
            } else {
                Toast.makeText(this, R.string.no_browser_found, Toast.LENGTH_SHORT).show();
            }
        }
    } else {
        if (handleError) {
            openInBrowser(uri, pm, false);
        } else {
            Toast.makeText(this, R.string.no_browser_found, Toast.LENGTH_SHORT).show();
        }
    }
}
 
Example 16
Source File: TimelineDetailActivity.java    From indigenous-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onClick(View v) {

    try {
        CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
        intentBuilder.setToolbarColor(ContextCompat.getColor(TimelineDetailActivity.this, R.color.colorPrimary));
        intentBuilder.setSecondaryToolbarColor(ContextCompat.getColor(TimelineDetailActivity.this, R.color.colorPrimaryDark));
        CustomTabsIntent customTabsIntent = intentBuilder.build();
        customTabsIntent.intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        customTabsIntent.launchUrl(TimelineDetailActivity.this, Uri.parse(item.getUrl()));
    }
    catch (Exception ignored) { }

}
 
Example 17
Source File: ExtraUtils.java    From Bop with Apache License 2.0 5 votes vote down vote up
public static void openCustomTabs(Context context, String url) {
    CustomTabsIntent.Builder builderq = new CustomTabsIntent.Builder();
    builderq.setToolbarColor(context.getResources().getColor(R.color.primaryColor));
    builderq.addDefaultShareMenuItem().enableUrlBarHiding();
    CustomTabsIntent customTabsIntent = builderq.build();
    customTabsIntent.launchUrl(context, Uri.parse(url));
}
 
Example 18
Source File: NavUtil.java    From EdXposedManager with GNU General Public License v3.0 5 votes vote down vote up
public static void startURL(Activity activity, Uri uri) {
    if (!XposedApp.getPreferences().getBoolean("chrome_tabs", true)) {
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        intent.putExtra(Browser.EXTRA_APPLICATION_ID, activity.getPackageName());
        activity.startActivity(intent);
        return;
    }

    CustomTabsIntent.Builder customTabsIntent = new CustomTabsIntent.Builder();
    customTabsIntent.setShowTitle(true);
    customTabsIntent.setToolbarColor(XposedApp.getColor(activity));
    customTabsIntent.build().launchUrl(activity, uri);
}
 
Example 19
Source File: CustomTabsHelper.java    From aptoide-client-v8 with GNU General Public License v3.0 3 votes vote down vote up
/**
 * <p>Launches specified url in a Chrome Custom Tab using no warm-up.</p>
 * <p>Referrers are injected into the intent before launching.</p>
 * <p>If the device/Android version doesn't support Chrome Custom Tabs,
 * it will launch the intent for the user to choose where he wants to open the url.</p>
 *
 * <p>The Custom Chrome tab is customized with an orange Action Bar,
 * a Share Url option (share intent),
 * an enter/exit slide animation and
 * a overflow menu item ("Open in App"), that allows user to open the url in a native application
 * that can handle those kind of urls (excluding browsers).</p>
 *
 * @param url Url to be launched in the Custom Chrome Tab
 * @param context Context
 */
public void openInChromeCustomTab(String url, Context context, int color) {
  CustomTabsIntent.Builder builder = getBuilder(context, color);
  CustomTabsIntent customTabsIntent = builder.build();
  addRefererHttpHeader(context, customTabsIntent);
  customTabsIntent.intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  customTabsIntent.launchUrl(context, Uri.parse(url));
}
 
Example 20
Source File: CustomTabManager.java    From AppAuth-Android with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a {@link androidx.browser.customtabs.CustomTabsIntent.Builder custom tab builder},
 * with an optional list of optional URIs that may be requested. The URI list
 * should be ordered such that the most likely URI to be requested is first. If the selected
 * browser does not support custom tabs, then the URI list has no effect.
 */
@WorkerThread
@NonNull
public CustomTabsIntent.Builder createTabBuilder(@Nullable Uri... possibleUris) {
    return new CustomTabsIntent.Builder(createSession(null, possibleUris));
}