android.support.customtabs.CustomTabsIntent Java Examples

The following examples show how to use android.support.customtabs.CustomTabsIntent. 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: CustomTabAuthHandler.java    From blade-player with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean start(final Activity contextActivity, final AuthenticationRequest request) {

    final String packageName = getChromePackageName(contextActivity);
    if (packageName == null) {
        return false;
    }

    if (!hasCustomTabRedirectActivity(contextActivity, request.getRedirectUri())) {
        return false;
    }

    CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
    builder.setToolbarColor(SPOTIFY_GREEN);
    final CustomTabsIntent customTabsIntent = builder.build();
    customTabsIntent.intent.setPackage(packageName);
    customTabsIntent.launchUrl(contextActivity, request.toUri());

    return true;
}
 
Example #2
Source File: DropboxConfig.java    From rcloneExplorer with MIT License 6 votes vote down vote up
@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 #3
Source File: BoxConfig.java    From rcloneExplorer with MIT License 6 votes vote down vote up
@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: PcloudConfig.java    From rcloneExplorer with MIT License 6 votes vote down vote up
@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 #5
Source File: CustomTabsControllerTest.java    From Auth0.Android with MIT License 6 votes vote down vote up
@Test
public void shouldBindAndLaunchUri() throws Exception {
    bindService(true);
    controller.launchUri(uri);
    connectBoundService();

    verify(context, timeout(MAX_TEST_WAIT_TIME_MS)).startActivity(launchIntentCaptor.capture());
    Intent intent = launchIntentCaptor.getValue();
    assertThat(intent.getAction(), is(Intent.ACTION_VIEW));
    assertThat(intent.getPackage(), is(DEFAULT_BROWSER_PACKAGE));
    assertThat(intent.hasExtra(CustomTabsIntent.EXTRA_SESSION), is(true));
    assertThat(intent.hasExtra(CustomTabsIntent.EXTRA_TOOLBAR_COLOR), is(false));
    assertThat(intent.hasExtra(CustomTabsIntent.EXTRA_TITLE_VISIBILITY_STATE), is(true));
    assertThat(intent.getIntExtra(CustomTabsIntent.EXTRA_TITLE_VISIBILITY_STATE, CustomTabsIntent.NO_TITLE), is(CustomTabsIntent.NO_TITLE));
    assertThat(intent.getData(), is(uri));
    assertThat(intent, not(hasFlag(Intent.FLAG_ACTIVITY_NO_HISTORY)));
}
 
Example #6
Source File: DesignerNewsStory.java    From android-proguards with Apache License 2.0 6 votes vote down vote up
public static CustomTabsIntent.Builder getCustomTabIntent(@NonNull Context context,
                                                          @NonNull Story story,
                                                          @Nullable CustomTabsSession session) {
    Intent upvoteStory = new Intent(context, UpvoteStoryService.class);
    upvoteStory.setAction(UpvoteStoryService.ACTION_UPVOTE);
    upvoteStory.putExtra(UpvoteStoryService.EXTRA_STORY_ID, story.id);
    PendingIntent pendingIntent = PendingIntent.getService(context, 0, upvoteStory, 0);
    return new CustomTabsIntent.Builder(session)
            .setToolbarColor(ContextCompat.getColor(context, R.color.designer_news))
            .setActionButton(ImageUtils.vectorToBitmap(context,
                            R.drawable.ic_upvote_filled_24dp_white),
                    context.getString(R.string.upvote_story),
                    pendingIntent,
                    false)
            .setShowTitle(true)
            .enableUrlBarHiding()
            .addDefaultShareMenuItem();
}
 
Example #7
Source File: DriveConfig.java    From rcloneExplorer with MIT License 6 votes vote down vote up
@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 #8
Source File: HubicConfig.java    From rcloneExplorer with MIT License 6 votes vote down vote up
@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 #9
Source File: CustomTabsControllerTest.java    From Auth0.Android with MIT License 6 votes vote down vote up
@Test
public void shouldLaunchUriWithFallbackIfCustomTabIntentFails() {
    doThrow(ActivityNotFoundException.class)
            .doNothing()
            .when(context).startActivity(any(Intent.class));
    controller.launchUri(uri);

    verify(context, timeout(MAX_TEST_WAIT_TIME_MS)).startActivity(launchIntentCaptor.capture());
    List<Intent> intents = launchIntentCaptor.getAllValues();

    Intent customTabIntent = intents.get(0);
    assertThat(customTabIntent.getAction(), is(Intent.ACTION_VIEW));
    //A null package name would make the OS decide the best app to resolve the intent
    assertThat(customTabIntent.getPackage(), is(nullValue()));
    assertThat(customTabIntent.getData(), is(uri));
    assertThat(customTabIntent, not(hasFlag(Intent.FLAG_ACTIVITY_NO_HISTORY)));
    assertThat(customTabIntent.hasExtra(CustomTabsIntent.EXTRA_SESSION), is(true));
    assertThat(customTabIntent.hasExtra(CustomTabsIntent.EXTRA_TITLE_VISIBILITY_STATE), is(true));
    assertThat(customTabIntent.hasExtra(CustomTabsIntent.EXTRA_TOOLBAR_COLOR), is(false));
    assertThat(customTabIntent.getIntExtra(CustomTabsIntent.EXTRA_TITLE_VISIBILITY_STATE, CustomTabsIntent.NO_TITLE), is(CustomTabsIntent.NO_TITLE));
}
 
Example #10
Source File: MainActivity.java    From homeassist with Apache License 2.0 6 votes vote down vote up
private void showWebUI() {
        CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
        //builder.setStartAnimations(mActivity, R.anim.right_in, R.anim.left_out);

        builder.setStartAnimations(this, R.anim.activity_open_translate, R.anim.activity_close_scale);
        builder.setExitAnimations(this, R.anim.activity_open_scale, R.anim.activity_close_translate);
        builder.setToolbarColor(ResourcesCompat.getColor(getResources(), R.color.md_blue_500, null));
//        builder.setSecondaryToolbarColor(ResourcesCompat.getColor(getResources(), R.color.md_white_1000, null));
        CustomTabsIntent customTabsIntent = builder.build();

        try {
            customTabsIntent.launchUrl(this, mCurrentServer.getBaseUri());
        } catch (ActivityNotFoundException e) {
            showToast(getString(R.string.exception_no_chrome));
        }
    }
 
Example #11
Source File: PassphraseDialogFragment.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private SpannableString getResetText() {
    final Context context = getActivity();
    return SpanApplier.applySpans(
            context.getString(R.string.sync_passphrase_reset_instructions),
            new SpanInfo("<resetlink>", "</resetlink>", new ClickableSpan() {
                @Override
                public void onClick(View view) {
                    recordPassphraseDialogDismissal(PASSPHRASE_DIALOG_RESET_LINK);
                    Uri syncDashboardUrl = Uri.parse(
                            context.getText(R.string.sync_dashboard_url).toString());
                    Intent intent = new Intent(Intent.ACTION_VIEW, syncDashboardUrl);
                    intent.setPackage(BuildInfo.getPackageName(context));
                    IntentUtils.safePutBinderExtra(
                            intent, CustomTabsIntent.EXTRA_SESSION, null);
                    context.startActivity(intent);
                }
            }));
}
 
Example #12
Source File: PassphraseTypeDialogFragment.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private SpannableString getResetText() {
    final Context context = getActivity();
    return SpanApplier.applySpans(
            context.getString(R.string.sync_passphrase_encryption_reset_instructions),
            new SpanInfo("<resetlink>", "</resetlink>", new ClickableSpan() {
                @Override
                public void onClick(View view) {
                    Uri syncDashboardUrl = Uri.parse(
                            context.getText(R.string.sync_dashboard_url).toString());
                    Intent intent = new Intent(Intent.ACTION_VIEW, syncDashboardUrl);
                    intent.setPackage(BuildInfo.getPackageName(context));
                    IntentUtils.safePutBinderExtra(
                            intent, CustomTabsIntent.EXTRA_SESSION, null);
                    context.startActivity(intent);
                }
            }));
}
 
Example #13
Source File: CustomTabsControllerTest.java    From Auth0.Android with MIT License 6 votes vote down vote up
@Test
public void shouldBindAndLaunchUriWithCustomization() throws Exception {
    CustomTabsOptions options = CustomTabsOptions.newBuilder()
            .showTitle(true)
            .withToolbarColor(android.R.color.black)
            .build();

    bindService(true);
    controller.setCustomizationOptions(options);
    controller.launchUri(uri);
    connectBoundService();

    verify(context, timeout(MAX_TEST_WAIT_TIME_MS)).startActivity(launchIntentCaptor.capture());
    Intent intent = launchIntentCaptor.getValue();
    assertThat(intent.getAction(), is(Intent.ACTION_VIEW));
    assertThat(intent.getPackage(), is(DEFAULT_BROWSER_PACKAGE));
    assertThat(intent.hasExtra(CustomTabsIntent.EXTRA_SESSION), is(true));
    assertThat(intent.hasExtra(CustomTabsIntent.EXTRA_TITLE_VISIBILITY_STATE), is(true));
    assertThat(intent.hasExtra(CustomTabsIntent.EXTRA_TOOLBAR_COLOR), is(true));
    assertThat(intent.getIntExtra(CustomTabsIntent.EXTRA_TITLE_VISIBILITY_STATE, CustomTabsIntent.NO_TITLE), is(CustomTabsIntent.SHOW_PAGE_TITLE));
    assertThat(intent.getIntExtra(CustomTabsIntent.EXTRA_TOOLBAR_COLOR, 0), is(Color.BLACK));
    assertThat(intent.getData(), is(uri));
    assertThat(intent, not(hasFlag(Intent.FLAG_ACTIVITY_NO_HISTORY)));
}
 
Example #14
Source File: SystemBarColorPredictor.java    From custom-tabs-client with Apache License 2.0 6 votes vote down vote up
/**
 * Makes a best-effort guess about which navigation bar color will be used when the Trusted Web
 * Activity is launched. Returns null if not possible to predict.
 */
@Nullable
Integer getExpectedNavbarColor(Context context, String providerPackage,
        TrustedWebActivityIntentBuilder builder) {
    Intent intent = builder.buildCustomTabsIntent().intent;
    if (providerSupportsNavBarColorCustomization(context, providerPackage)) {
        if (providerSupportsColorSchemeParams(context, providerPackage)) {
            int colorScheme = getExpectedColorScheme(context, builder);
            CustomTabColorSchemeParams params = CustomTabsIntent.getColorSchemeParams(intent,
                    colorScheme);
            return params.navigationBarColor;
        }
        Bundle extras = intent.getExtras();
        return extras == null ? null :
                (Integer) extras.get(CustomTabsIntent.EXTRA_NAVIGATION_BAR_COLOR);
    }
    if (TrustedWebUtils.SUPPORTED_CHROME_PACKAGES.contains(providerPackage)) {
        // Prior to adding support for nav bar color customization, Chrome had always set
        // the white color.
        return Color.WHITE;
    }
    return null;
}
 
Example #15
Source File: BottomBarManager.java    From custom-tabs-client with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    int clickedId = intent.getIntExtra(CustomTabsIntent.EXTRA_REMOTEVIEWS_CLICKED_ID, -1);
    Toast.makeText(context, "Current URL " + intent.getDataString() + "\nClicked id "
            + clickedId, Toast.LENGTH_SHORT).show();

    CustomTabsSession session = SessionHelper.getCurrentSession();
    if (session == null) return;

    if (clickedId == R.id.play_pause) {
        MediaPlayer player = sMediaPlayerWeakRef.get();
        if (player != null) {
            boolean isPlaying = player.isPlaying();
            if (isPlaying) player.pause();
            else player.start();
            // Update the play/stop icon to respect the current state.
            session.setSecondaryToolbarViews(createRemoteViews(context, isPlaying), getClickableIDs(),
                    getOnClickPendingIntent(context));
        }
    } else if (clickedId == R.id.cover) {
        // Clicking on the cover image will dismiss the bottom bar.
        session.setSecondaryToolbarViews(null, null, null);
    }
}
 
Example #16
Source File: AboutActivity.java    From android-proguards with Apache License 2.0 6 votes vote down vote up
private @NonNull LibraryHolder createLibraryHolder(ViewGroup parent) {
    final LibraryHolder holder = new LibraryHolder(LayoutInflater.from(parent.getContext())
            .inflate(R.layout.library, parent, false));
    View.OnClickListener clickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int position = holder.getAdapterPosition();
            if (position == RecyclerView.NO_POSITION) return;
            CustomTabActivityHelper.openCustomTab(
                    host,
                    new CustomTabsIntent.Builder()
                            .setToolbarColor(ContextCompat.getColor(host, R.color.primary))
                            .addDefaultShareMenuItem()
                            .build(), Uri.parse(libs[position - 1].link));

        }
    };
    holder.itemView.setOnClickListener(clickListener);
    holder.link.setOnClickListener(clickListener);
    return holder;
}
 
Example #17
Source File: OktaAppAuth.java    From okta-sdk-appauth-android with Apache License 2.0 6 votes vote down vote up
@WorkerThread
private void doEndSession(PendingIntent completionIntent, PendingIntent cancelIntent) {
    Log.d(TAG, "Starting end session flow");

    EndSessionRequest request = new EndSessionRequest(
            mAuthStateManager.getCurrent().getAuthorizationServiceConfiguration(),
            mAuthStateManager.getCurrent().getIdToken(),
            mConfiguration.getEndSessionRedirectUri());

    warmUpBrowser(request.toUri());

    CustomTabsIntent.Builder intentBuilder =
            createAuthorizationServiceIfNeeded()
                    .createCustomTabsIntentBuilder(request.toUri());
    intentBuilder.setToolbarColor(mCustomTabColor);
    CustomTabsIntent endSessionIntent = intentBuilder.build();

    createAuthorizationServiceIfNeeded()
            .performEndOfSessionRequest(request, completionIntent,
            cancelIntent, endSessionIntent);
}
 
Example #18
Source File: BaseUrlSpan.java    From actor-platform with GNU Affero General Public License v3.0 6 votes vote down vote up
public static CustomTabsIntent buildChromeIntent() {
        CustomTabsIntent.Builder customTabsIntent = new CustomTabsIntent.Builder();

//        Intent sendIntent = new Intent(Intent.ACTION_SEND);
//        sendIntent.setType("*/*");
//        PendingIntent pi = PendingIntent.getActivity(AndroidContext.getContext()    , 0, sendIntent, 0);

        Intent actionIntent = new Intent(
                AndroidContext.getContext(), ChromeCustomTabReceiver.class);
        PendingIntent pi =
                PendingIntent.getBroadcast(AndroidContext.getContext(), 0, actionIntent, 0);

        customTabsIntent.setToolbarColor(ActorSDK.sharedActor().style.getMainColor())
                .setActionButton(BitmapFactory.decodeResource(AndroidContext.getContext().getResources(), R.drawable.ic_share_white_24dp), "Share", pi)
                .setCloseButtonIcon(BitmapFactory.decodeResource(AndroidContext.getContext().getResources(), R.drawable.ic_arrow_back_white_24dp));

        return customTabsIntent.build();
    }
 
Example #19
Source File: ChromeCustomTabPlugin.java    From cordova-plugin-safariviewcontroller with MIT License 6 votes vote down vote up
private void show(String url, @ColorInt int toolbarColor, boolean showDefaultShareMenuItem, String transition) {
    CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(getSession())
            .setToolbarColor(toolbarColor);
    if(showDefaultShareMenuItem)
        builder.addDefaultShareMenuItem();
    if(!TextUtils.isEmpty(transition))
        addTransition(builder, transition);


    CustomTabsIntent customTabsIntent = builder.build();

    String packageName = CustomTabsHelper.getPackageNameToUse(cordova.getActivity());
    if ( packageName != null ) {
       customTabsIntent.intent.setPackage(packageName);
    }

    startCustomTabActivity(url, customTabsIntent.intent);
}
 
Example #20
Source File: WebViewActivity.java    From CryptoBuddy with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.internet_button:
            CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
            CustomTabsIntent customTabsIntent = builder.build();
            customTabsIntent.launchUrl(this, Uri.parse(url));
            return true;
        case R.id.share_button:
            Intent sharingIntent = new Intent(Intent.ACTION_SEND);
            sharingIntent.setType("text/plain");
            String shareBody = "Check out this article I found on CryptoBuddy: " + this.url;
            sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "Cryptocurrency Article");
            sharingIntent.putExtra(Intent.EXTRA_TEXT, shareBody);
            startActivity(Intent.createChooser(sharingIntent, "Share via"));
            return true;
    }
    finish();
    return true;
}
 
Example #21
Source File: Demo.java    From snowplow-android-tracker with Apache License 2.0 5 votes vote down vote up
/**
 * Setups listener for tabs.
 */
private void setupTabListener() {
    _tabButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Tracker.instance().suspendSessionChecking(true);
            String url = "https://snowplowanalytics.com/";
            CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
            CustomTabsIntent customTabsIntent = builder.build();
            customTabsIntent.launchUrl(Demo.this, Uri.parse(url));
        }
    });
}
 
Example #22
Source File: Intents.java    From droidconat-2016 with Apache License 2.0 5 votes vote down vote up
public static void startExternalUrl(@NonNull Activity activity, @NonNull String url) {
    CustomTabsIntent intent = new CustomTabsIntent.Builder()
            .setShowTitle(true)
            .setToolbarColor(ContextCompat.getColor(activity, R.color.primary))
            .build();
    intent.launchUrl(activity, Uri.parse(url));
}
 
Example #23
Source File: CustomButtonParams.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * @return The content description contained in the given {@link Bundle}. Will return null if
 *         input is invalid.
 */
static String parseDescriptionFromBundle(Bundle bundle) {
    if (bundle == null) return null;
    String description = IntentUtils.safeGetString(bundle, CustomTabsIntent.KEY_DESCRIPTION);
    if (TextUtils.isEmpty(description)) return null;
    return description;
}
 
Example #24
Source File: LoginFragment.java    From incubator-taverna-mobile with Apache License 2.0 5 votes vote down vote up
@OnClick(R.id.bRegister)
public void register(View v) {
    if (Build.VERSION.SDK_INT < 15) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setData(Uri.parse(myExperimentURL));
        startActivity(intent);
    } else {
        CustomTabsIntent.Builder customTabsIntentBuilder = new CustomTabsIntent.Builder();
        CustomTabsIntent customTabsIntent = customTabsIntentBuilder.build();
        customTabsIntent.launchUrl(getActivity(), Uri.parse(myExperimentURL));
    }
}
 
Example #25
Source File: ChromeCustomTabsManager.java    From Anecdote with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #26
Source File: LauncherActivityTest.java    From custom-tabs-client with Apache License 2.0 5 votes vote down vote up
private void checkColor(TestBrowser browser) {
    int requestedColor = browser.getIntent()
            .getIntExtra(CustomTabsIntent.EXTRA_TOOLBAR_COLOR, 0);
    int expectedColor = InstrumentationRegistry.getTargetContext().getResources()
            .getColor(STATUS_BAR_COLOR_ID);

    assertEquals(expectedColor, requestedColor);
}
 
Example #27
Source File: ChromeTabsDelegate.java    From SteamGifts with MIT License 5 votes vote down vote up
@Override
public void start(@NonNull Activity activity) {
    @ColorInt
    int color = activity.obtainStyledAttributes(new int[]{R.attr.colorPrimary}).getColor(0, 0);

    CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder()
            .setToolbarColor(color)
            .setShowTitle(true)
            .build();
    customTabsIntent.launchUrl(activity, uri);
}
 
Example #28
Source File: SimpleCustomTabActivity.java    From AndroidProjects with MIT License 5 votes vote down vote up
@Override
public void onClick(View v) {
    int viewId = v.getId();

    switch (viewId) {
        case R.id.start_custom_tab:
            String url = mUrlEditText.getText().toString();
            CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder().build();
            CustomTabActivityHelper.openCustomTab(this, customTabsIntent, Uri.parse(url), new WebviewFallback());
            break;
        default:
            //Unknown View Clicked
    }
}
 
Example #29
Source File: ActivityUtils.java    From CumulusTV with MIT License 5 votes vote down vote up
public static void launchWebsite(Activity activity) {
    String url = activity.getString(R.string.website_url);
    CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
    CustomTabsIntent customTabsIntent = builder.build();
    try {
        customTabsIntent.launchUrl(activity, Uri.parse(url));
    } catch (Exception e) {
        // There is no way to view the website.
        activity.startActivity(new Intent(activity,
                HomepageWebViewActivity.class));
    }
}
 
Example #30
Source File: PostActivity.java    From materialup with Apache License 2.0 5 votes vote down vote up
private void openLink(String url) {
    CustomTabActivityHelper.openCustomTab(
            PostActivity.this,
            new CustomTabsIntent.Builder()
                    .setToolbarColor(ContextCompat.getColor(PostActivity.this, R.color.dribbble))
                    .build(),
            Uri.parse(url));
}