Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Tabs Support Library

Recently was added this support library, but I couldn't find any example.

What the purpose of this library?

Could you post any example using this library?

like image 475
juanhl Avatar asked Aug 24 '15 11:08

juanhl


People also ask

What are Android custom Tabs?

Custom Tabs is a browser feature, introduced by Chrome, that is now supported by most major browsers on Android. It give apps more control over their web experience, and make transitions between native and web content more seamless without having to resort to a WebView.

What are custom Tabs in Salesforce?

Custom tabs let you display custom object data or other web content in Salesforce. When you add a custom tab to an app in Salesforce Classic, it appears as a tab. When you add a custom tab to an app in Lightning Experience, it appears as an item in the app's navigation bar and in the App Launcher.


2 Answers

CustomTabs is used to open links in a browser that supports CustomTabs. Most likely opening is done on Chrome, hence CustomTabs is part of chromium platform.

Purpose is to avoid implementing WebViews in your application and yet giving you option for styling actual chrome tabs, like toolbar color, title, various exit/enter transition, adding action buttons and menues. CustomTabs will allow your application bind to the chrome service and make chrome work as part of your application. Styling which will give you feel the opened web resource is part of your application.

Beside the styling, CustomTabs will give you full chrome web capabilities that probably couldn't be achieved with standard WebView.

Here are demos, which are straight forward.

Edit:

A snippet from my application which is "simplified" version of the Google's demo, lacking fallback mechanism, for now.

Usage of the helper is the following:

  1. Initialize it when your activity is alive

      @Override
      protected void onCreate(Bundle savedInstanceState) { 
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_preview);
         mCustomTabHelper = new SimpleCustomChromeTabsHelper(this);
}
2. When the instance is alive and we have an url ready to be opened we can call:

mCustomTabHelper.prepareUrl(mProduct.getRedirectUrl());

Which will bind to the Chrome service, if not previously bind, or will just notify Chrome service that we might be opening that link in the future. CustomTabSession can be used to open or prepare multiple url.

  1. Open the url

    mCustomTabHelper.openUrl(mProduct.getRedirectUrl());

The overloaded method of openUrl is using sort of ui options builder that is replica of the CustomTabIntent.Builder, but I have dropped the CustomTabsSession argument so the helper later will build CustomTabIntent internally.

I'm running Chrome Dev version along stable one. If I choose the stable one, I'm not able to use CustomTabsat all. As Google advices, CustomTabs will only work on Chrome 45 and beta versions of Chrome.

Demo from my application: https://youtu.be/fnIZwuJXjHI

Edit: Post

like image 130
Nikola Despotoski Avatar answered Oct 13 '22 07:10

Nikola Despotoski


Try this:

gradle dependency:

dependencies {
    ...
    compile 'com.android.support:customtabs:25.1.0'
}

Code :

Uri uri = Uri.parse("https://github.com/mzelzoghbi");

// create an intent builder
CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();

// Begin customizing
// set toolbar colors
intentBuilder.setToolbarColor(ContextCompat.getColor(this, R.color.colorPrimary));
intentBuilder.setSecondaryToolbarColor(ContextCompat.getColor(this, R.color.colorPrimaryDark));

// build custom tabs intent
CustomTabsIntent customTabsIntent = intentBuilder.build();

// launch the url
customTabsIntent.launchUrl(activity, uri);
like image 3
Mohamed Zakaria El-Zoghbi Avatar answered Oct 13 '22 07:10

Mohamed Zakaria El-Zoghbi