| OLD | NEW |
| 1 // Copyright 2015 Google Inc. All Rights Reserved. | 1 // Copyright 2015 Google Inc. All Rights Reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 * | 45 * |
| 46 * @param activity The host activity. | 46 * @param activity The host activity. |
| 47 * @param customTabsIntent a CustomTabsIntent to be used if Custom Tabs is a
vailable. | 47 * @param customTabsIntent a CustomTabsIntent to be used if Custom Tabs is a
vailable. |
| 48 * @param uri the Uri to be opened. | 48 * @param uri the Uri to be opened. |
| 49 * @param fallback a CustomTabFallback to be used if Custom Tabs is not avai
lable. | 49 * @param fallback a CustomTabFallback to be used if Custom Tabs is not avai
lable. |
| 50 */ | 50 */ |
| 51 public static void openCustomTab(Activity activity, | 51 public static void openCustomTab(Activity activity, |
| 52 CustomTabsIntent customTabsIntent, | 52 CustomTabsIntent customTabsIntent, |
| 53 Uri uri, | 53 Uri uri, |
| 54 CustomTabFallback fallback) { | 54 CustomTabFallback fallback) { |
| 55 String packageName = CustomTabsHelper.getPackageNameToUse(activity); | 55 openCustomTab(activity, customTabsIntent, uri, fallback, null); |
| 56 } |
| 56 | 57 |
| 57 //If we cant find a package name, it means theres no browser that suppor
ts | 58 /** |
| 58 //Chrome Custom Tabs installed. So, we fallback to the webview | 59 * @see #openCustomTab(Activity, CustomTabsIntent, Uri, CustomTabFallback) |
| 60 * Same as the previous method, but is able to specify which package the use
r wants to use. |
| 61 */ |
| 62 public static void openCustomTab(Activity activity, |
| 63 CustomTabsIntent customTabsIntent, |
| 64 Uri uri, |
| 65 CustomTabFallback fallback, |
| 66 String packageName) { |
| 59 if (packageName == null) { | 67 if (packageName == null) { |
| 60 if (fallback != null) { | 68 packageName = CustomTabsHelper.getPackageNameToUse(activity); |
| 61 fallback.openUri(activity, uri); | 69 //If we cant find a package name, it means theres no browser that su
pports |
| 70 //Chrome Custom Tabs installed. So, we fallback to the webview |
| 71 if (packageName == null) { |
| 72 if (fallback != null) { |
| 73 fallback.openUri(activity, uri); |
| 74 } |
| 62 } | 75 } |
| 63 } else { | 76 } else { |
| 64 customTabsIntent.intent.setPackage(packageName); | 77 customTabsIntent.intent.setPackage(packageName); |
| 65 customTabsIntent.launchUrl(activity, uri); | 78 customTabsIntent.launchUrl(activity, uri); |
| 66 } | 79 } |
| 67 } | 80 } |
| 68 | 81 |
| 69 /** | 82 /** |
| 70 * Unbinds the Activity from the Custom Tabs Service. | 83 * Unbinds the Activity from the Custom Tabs Service. |
| 71 * @param activity the activity that is connected to the service. | 84 * @param activity the activity that is connected to the service. |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 public interface CustomTabFallback { | 176 public interface CustomTabFallback { |
| 164 /** | 177 /** |
| 165 * | 178 * |
| 166 * @param activity The Activity that wants to open the Uri. | 179 * @param activity The Activity that wants to open the Uri. |
| 167 * @param uri The uri to be opened by the fallback. | 180 * @param uri The uri to be opened by the fallback. |
| 168 */ | 181 */ |
| 169 void openUri(Activity activity, Uri uri); | 182 void openUri(Activity activity, Uri uri); |
| 170 } | 183 } |
| 171 | 184 |
| 172 } | 185 } |
| OLD | NEW |