├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── libraries │ ├── appcompat_v7_23_0_1.xml │ ├── customtabs_23_0_0.xml │ ├── support_annotations_23_0_1.xml │ └── support_v4_23_0_1.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml ├── vcs.xml └── workspace.xml ├── ChromeCustomTabs.iml ├── LICENSE ├── README.md ├── app ├── .gitignore ├── app.iml ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── anjithsasindran │ │ └── chromecustomtabs │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── anjithsasindran │ │ │ └── chromecustomtabs │ │ │ ├── CustomWebView.java │ │ │ └── MainActivity.java │ └── res │ │ ├── anim │ │ ├── slide_in_left.xml │ │ ├── slide_in_right.xml │ │ ├── slide_out_left.xml │ │ └── slide_out_right.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ └── webview.xml │ │ ├── mipmap-hdpi │ │ ├── ic_arrow_back_white_24dp.png │ │ ├── ic_file_download_white_24dp.png │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ ├── ic_arrow_back_white_24dp.png │ │ ├── ic_file_download_white_24dp.png │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ ├── ic_arrow_back_white_24dp.png │ │ ├── ic_file_download_white_24dp.png │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_arrow_back_white_24dp.png │ │ ├── ic_file_download_white_24dp.png │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_arrow_back_white_24dp.png │ │ └── ic_file_download_white_24dp.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── anjithsasindran │ └── chromecustomtabs │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── screenshot └── preview.png └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | 15 | # Gradle files 16 | .gradle/ 17 | build/ 18 | /*/build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | ChromeCustomTabs -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/libraries/appcompat_v7_23_0_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /.idea/libraries/customtabs_23_0_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/libraries/support_annotations_23_0_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/support_v4_23_0_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | 1.8 51 | 52 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | 12 | 13 | 14 | 15 | 22 | 23 | 24 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 62 | 63 | 64 | 88 | 1181 | 1186 | 1496 | 1499 | 1500 | 1501 | 1519 | 1520 | 1521 | 1526 | 1527 | 1528 | 1529 | 1530 | 1531 | 1536 | 1537 | 1538 | 1539 | 1540 | 1541 | 1542 | 1543 | 1544 | 1545 | 1546 | 1547 | 1548 | 1549 | 1550 | 1551 | 1552 | 1553 | 1554 | 1555 | 1556 | 1557 | 1558 | 1559 | 1560 | 1561 | 1562 | 1563 | 1566 | 1567 | 1568 | 1569 | 1570 | 1571 | 1572 | 1573 | 1574 | 1575 | 1576 | 1577 | 1578 | 1579 | 1580 | 1581 | 1582 | 1583 | 1584 | 1585 | 1586 | 1587 | 1588 | 1589 | 1590 | 1591 | 1592 | 1593 | 1594 | 1595 | 1596 | 1597 | 1598 | 1599 | 1600 | 1601 | 1602 | 1603 | 1604 | 1605 | 1606 | 1607 | 1608 | 1636 | 1637 | 1638 | 1666 | 1667 | 1668 | 1681 | 1682 | 1683 | 1684 | 1698 | 1699 | 1700 | 1701 | 1702 | 1703 | 1704 | 1705 | 1706 | 1707 | 1708 | 1715 | 1716 | 1717 | 1718 | 1736 | 1743 | 1744 | 1745 | 1773 | 1774 | 1775 | 1776 | 1777 | 1785 | 1786 | 1788 | 1789 | localhost 1790 | 5050 1791 | 1792 | 1793 | 1794 | 1795 | 1796 | 1797 | 1442422780271 1798 | 1801 | 1802 | 1803 | 1804 | 1805 | 1806 | 1807 | 1808 | 1809 | 1810 | 1811 | 1812 | 1813 | 1814 | 1815 | 1816 | 1817 | 1818 | 1819 | 1820 | 1821 | 1822 | 1823 | 1824 | 1825 | 1826 | 1827 | 1828 | 1829 | 1830 | 1831 | 1832 | 1833 | 1834 | 1835 | 1836 | 1837 | 1838 | 1841 | 1844 | 1845 | 1846 | 1848 | 1849 | 1850 | 1851 | 1852 | 1853 | 1854 | 1855 | 1856 | 1857 | 1858 | 1859 | 1860 | 1861 | 1862 | 1863 | 1864 | 1865 | 1866 | 1867 | 1868 | 1869 | 1870 | 1871 | 1872 | 1873 | 1874 | 1875 | 1876 | 1877 | 1878 | 1879 | 1880 | 1881 | 1882 | 1883 | 1884 | 1885 | 1886 | 1887 | 1888 | 1889 | 1890 | 1891 | 1892 | 1893 | 1894 | 1895 | 1896 | 1897 | 1898 | 1899 | 1900 | 1901 | 1902 | 1903 | 1904 | 1905 | 1906 | 1907 | 1908 | 1909 | 1910 | 1911 | 1912 | 1913 | 1914 | 1915 | 1916 | 1917 | 1918 | 1919 | 1920 | 1921 | 1922 | 1923 | 1924 | 1925 | 1926 | 1927 | 1928 | 1929 | 1930 | 1931 | 1932 | 1933 | 1934 | 1935 | 1936 | 1937 | 1938 | 1939 | 1940 | 1941 | 1942 | 1943 | 1944 | 1945 | 1946 | 1947 | 1948 | 1949 | 1950 | 1951 | 1952 | 1953 | 1954 | 1955 | 1956 | 1957 | 1958 | 1959 | 1960 | -------------------------------------------------------------------------------- /ChromeCustomTabs.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Anjith Sasindran 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Chrome Custom Tabs 2 | 3 | **[Tutorial on my blog](http://anjithsasindran.in/blog/2015/09/28/chrome-custom-tabs/)** 4 | 5 | Sample code, which demonstrates the usage of Chrome Custom Tabs with action buttons, 6 | menu items and compares it with opening a webpage in Chrome Browser and WebView. 7 | 8 | ### What is Chrome Custom Tabs 9 | 10 | Chrome Custom Tabs is a new way to show third party content in android, which 11 | allows you to change how chrome looks and feels making the transition from app 12 | to web seemless. 13 | 14 | With Chrome Custom Tabs, you can have 15 | 16 | - Toolbar color 17 | - Start/Exit animation 18 | - Up button 19 | - Action buttons 20 | - Menu items 21 | 22 | ![Sample preview of Chrome Custom Tabs](/screenshot/preview.png) 23 | 24 | ### Usage 25 | 26 | 1. Include the gradle dependency 27 | 2. Connecting to browser service 28 | 3. Chrome warmup 29 | 4. Prefetch the webpage 30 | 5. Load the webpage in Chrome Custom Tabs 31 | 32 | ### Keep In Mind 33 | 34 | Chrome Custom Tabs is only supported in Chrome browsers which are version 45 & above. 35 | 36 | Also google has forgot to add dependency name in their [sample codes on GitHub] 37 | (https://github.com/GoogleChrome/custom-tabs-client). 38 | The gradle dependency for Chrome Custom Tabs is 39 | ``` 40 | compile 'com.android.support:customtabs:23.0.0' 41 | ``` 42 | 43 | #### Author 44 | **Anjith Sasindran** 45 | - https://twitter.com/anjithsasindran 46 | - https://instagram.com/anjithsasindran/ 47 | - https://github.com/4k3R 48 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.0" 6 | 7 | defaultConfig { 8 | applicationId "anjithsasindran.chromecustomtabs" 9 | minSdkVersion 16 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:23.0.1' 26 | compile 'com.android.support:customtabs:23.0.0' 27 | } 28 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\Users\Anjith Sasindran\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/anjithsasindran/chromecustomtabs/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package anjithsasindran.chromecustomtabs; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/java/anjithsasindran/chromecustomtabs/CustomWebView.java: -------------------------------------------------------------------------------- 1 | package anjithsasindran.chromecustomtabs; 2 | 3 | import android.net.Uri; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.webkit.WebView; 7 | import android.webkit.WebViewClient; 8 | 9 | /** 10 | * Created by Anjith Sasindran 11 | * on 16-Sep-15. 12 | */ 13 | public class CustomWebView extends AppCompatActivity { 14 | 15 | @Override 16 | protected void onCreate(Bundle savedInstanceState) { 17 | super.onCreate(savedInstanceState); 18 | setContentView(R.layout.webview); 19 | 20 | class MyWebViewClient extends WebViewClient { 21 | @Override 22 | public boolean shouldOverrideUrlLoading(WebView view, String url) { 23 | if (Uri.parse(url).getHost().equals(getIntent().getStringExtra("url"))) 24 | return false; 25 | else 26 | return super.shouldOverrideUrlLoading(view, url); 27 | } 28 | } 29 | 30 | WebView webView = (WebView) findViewById(R.id.webview); 31 | webView.getSettings().setJavaScriptEnabled(true); 32 | webView.loadUrl(getIntent().getStringExtra("url")); 33 | webView.setWebViewClient(new MyWebViewClient()); 34 | } 35 | } -------------------------------------------------------------------------------- /app/src/main/java/anjithsasindran/chromecustomtabs/MainActivity.java: -------------------------------------------------------------------------------- 1 | package anjithsasindran.chromecustomtabs; 2 | 3 | import android.app.PendingIntent; 4 | import android.content.ComponentName; 5 | import android.content.Intent; 6 | import android.graphics.BitmapFactory; 7 | import android.net.Uri; 8 | import android.os.Bundle; 9 | import android.support.customtabs.CustomTabsCallback; 10 | import android.support.customtabs.CustomTabsClient; 11 | import android.support.customtabs.CustomTabsIntent; 12 | import android.support.customtabs.CustomTabsServiceConnection; 13 | import android.support.customtabs.CustomTabsSession; 14 | import android.support.v4.content.ContextCompat; 15 | import android.support.v7.app.AppCompatActivity; 16 | import android.view.View; 17 | 18 | public class MainActivity extends AppCompatActivity { 19 | 20 | private final String url = "http://www.anjithsasindran.in"; 21 | 22 | private CustomTabsClient mClient; 23 | 24 | @Override 25 | protected void onCreate(Bundle savedInstanceState) { 26 | super.onCreate(savedInstanceState); 27 | setContentView(R.layout.activity_main); 28 | 29 | CustomTabsServiceConnection mConnection = new CustomTabsServiceConnection() { 30 | @Override 31 | public void onCustomTabsServiceConnected(ComponentName componentName, CustomTabsClient customTabsClient) { 32 | mClient = customTabsClient; 33 | } 34 | 35 | @Override 36 | public void onServiceDisconnected(ComponentName componentName) { 37 | mClient = null; 38 | } 39 | }; 40 | 41 | String packageName = "com.android.chrome"; 42 | CustomTabsClient.bindCustomTabsService(this, packageName, mConnection); 43 | } 44 | 45 | public void prefetchContent(View view) { 46 | 47 | if (mClient != null) { 48 | mClient.warmup(0); 49 | CustomTabsSession customTabsSession = getSession(); 50 | customTabsSession.mayLaunchUrl(Uri.parse(url), null, null); 51 | } 52 | 53 | } 54 | 55 | public void loadCustomTabs(View view) { 56 | CustomTabsIntent.Builder mBuilder = new CustomTabsIntent.Builder(getSession()); 57 | mBuilder.setToolbarColor(ContextCompat.getColor(this, R.color.indigo_500)); 58 | mBuilder.setCloseButtonIcon(BitmapFactory.decodeResource(getResources(), 59 | R.mipmap.ic_arrow_back_white_24dp)); 60 | mBuilder.addMenuItem("Share", setMenuItem()); 61 | mBuilder.setActionButton(BitmapFactory.decodeResource(getResources(), 62 | R.mipmap.ic_file_download_white_24dp), "Material Color Picker", addActionButton()); 63 | mBuilder.setStartAnimations(this, R.anim.slide_in_right, R.anim.slide_out_left); 64 | mBuilder.setExitAnimations(this, R.anim.slide_in_left, R.anim.slide_out_right); 65 | CustomTabsIntent mIntent = mBuilder.build(); 66 | mIntent.launchUrl(this, Uri.parse(url)); 67 | } 68 | 69 | private CustomTabsSession getSession() { 70 | return mClient.newSession(new CustomTabsCallback() { 71 | @Override 72 | public void onNavigationEvent(int navigationEvent, Bundle extras) { 73 | super.onNavigationEvent(navigationEvent, extras); 74 | } 75 | }); 76 | } 77 | 78 | private PendingIntent setMenuItem() { 79 | Intent shareIntent = new Intent(Intent.ACTION_SEND); 80 | shareIntent.setType("text/plain"); 81 | shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Official website of Anjith Sasindran"); 82 | shareIntent.putExtra(Intent.EXTRA_TEXT, url); 83 | return PendingIntent.getActivity(this, 0, shareIntent, 0); 84 | } 85 | 86 | private PendingIntent addActionButton() { 87 | Intent playStoreIntent = new Intent(Intent.ACTION_VIEW, 88 | Uri.parse("market://details?id=com.anjithsasindran.materialcolorpicker")); 89 | return PendingIntent.getActivity(this, 0, playStoreIntent, 0); 90 | } 91 | 92 | public void loadInChrome(View view) { 93 | Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); 94 | startActivity(browserIntent); 95 | } 96 | 97 | public void loadInWebView(View view) { 98 | Intent webViewIntent= new Intent(this, CustomWebView.class); 99 | webViewIntent.putExtra("url", url); 100 | startActivity(webViewIntent); 101 | } 102 | } -------------------------------------------------------------------------------- /app/src/main/res/anim/slide_in_left.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/anim/slide_in_right.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/anim/slide_out_left.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/anim/slide_out_right.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 |