Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1736)

Unified Diff: shared/src/main/java/org/chromium/customtabsclient/shared/CustomTabsHelper.java

Issue 1603383003: color, package and action bar configuration. (Closed) Base URL: https://github.com/GoogleChrome/custom-tabs-client.git@master
Patch Set: address issues Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: shared/src/main/java/org/chromium/customtabsclient/shared/CustomTabsHelper.java
diff --git a/shared/src/main/java/org/chromium/customtabsclient/shared/CustomTabsHelper.java b/shared/src/main/java/org/chromium/customtabsclient/shared/CustomTabsHelper.java
index 00af1e2189019aeabbcfcc4d498e22d09a2a073c..30cb119e3cf5d90445c07ed863c9316bdea00aa8 100644
--- a/shared/src/main/java/org/chromium/customtabsclient/shared/CustomTabsHelper.java
+++ b/shared/src/main/java/org/chromium/customtabsclient/shared/CustomTabsHelper.java
@@ -19,6 +19,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
+import android.graphics.Color;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
@@ -60,9 +61,14 @@ public class CustomTabsHelper {
* @param context {@link Context} to use for accessing {@link PackageManager}.
* @return The package name recommended to use for connecting to custom tabs related components.
*/
- public static String getPackageNameToUse(Context context) {
+ public static String getPackageNameToUse(Context context,
+ List<String> packagesSupportingCustomTabs) {
if (sPackageNameToUse != null) return sPackageNameToUse;
+ if (packagesSupportingCustomTabs == null) {
+ packagesSupportingCustomTabs = getAllPackagesSupportingCustomTabs(context);
+ }
+
PackageManager pm = context.getPackageManager();
// Get default VIEW intent handler.
Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
@@ -72,18 +78,6 @@ public class CustomTabsHelper {
defaultViewHandlerPackageName = defaultViewHandlerInfo.activityInfo.packageName;
}
- // Get all apps that can handle VIEW intents.
- List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, 0);
- List<String> packagesSupportingCustomTabs = new ArrayList<>();
- for (ResolveInfo info : resolvedActivityList) {
- Intent serviceIntent = new Intent();
- serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION);
- serviceIntent.setPackage(info.activityInfo.packageName);
- if (pm.resolveService(serviceIntent, 0) != null) {
- packagesSupportingCustomTabs.add(info.activityInfo.packageName);
- }
- }
-
// Now packagesSupportingCustomTabs contains all apps that can handle both VIEW intents
// and service calls.
if (packagesSupportingCustomTabs.isEmpty()) {
@@ -107,6 +101,13 @@ public class CustomTabsHelper {
}
/**
+ * See getPackageNameToUse(Context, List<String).
+ */
+ public static String getPackageNameToUse(Context context) {
+ return getPackageNameToUse(context, null);
+ }
+
+ /**
* Used to check whether there is a specialized handler for a given intent.
* @param intent The intent to check with.
* @return Whether there is a specialized handler for the given intent.
@@ -139,4 +140,27 @@ public class CustomTabsHelper {
public static String[] getPackages() {
return new String[]{"", STABLE_PACKAGE, BETA_PACKAGE, DEV_PACKAGE, LOCAL_PACKAGE};
}
+
+ /**
+ * Get all apps that support custom tabs.
+ * @param context
+ * @return
+ */
+ public static ArrayList<String> getAllPackagesSupportingCustomTabs(Context context) {
+ PackageManager pm = context.getPackageManager();
+ // Get default VIEW intent handler.
+ Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
+ // Get all apps that can handle VIEW intents.
+ List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, 0);
+ ArrayList<String> packagesSupportingCustomTabs = new ArrayList<>();
+ for (ResolveInfo info : resolvedActivityList) {
+ Intent serviceIntent = new Intent();
+ serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION);
+ serviceIntent.setPackage(info.activityInfo.packageName);
+ if (pm.resolveService(serviceIntent, 0) != null) {
+ packagesSupportingCustomTabs.add(info.activityInfo.packageName);
+ }
+ }
+ return packagesSupportingCustomTabs;
+ }
}

Powered by Google App Engine
This is Rietveld 408576698