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

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: Added action bar configuration item. 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..631e740a1d6ab42a8eec8597a466d84e2b6ac001 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()) {
@@ -106,6 +100,10 @@ public class CustomTabsHelper {
return sPackageNameToUse;
}
+ public static String getPackageNameToUse(Context context) {
Ian Wen 2016/02/09 00:14:16 javadoc. /** @see getPackageNameToUse(Context, Lis
BigBossZhiling 2016/02/09 01:03:12 Done.
+ return getPackageNameToUse(context, null);
+ }
+
/**
* Used to check whether there is a specialized handler for a given intent.
* @param intent The intent to check with.
@@ -139,4 +137,65 @@ public class CustomTabsHelper {
public static String[] getPackages() {
return new String[]{"", STABLE_PACKAGE, BETA_PACKAGE, DEV_PACKAGE, LOCAL_PACKAGE};
}
+
+ /**
+ * @return All possible colors.
+ */
+ public static String[] getColors() {
+ ArrayList<String> fieldList = new ArrayList<String>();
+ String colorName;
+ for (int i = 0; i < Color.class.getFields().length; i ++) {
+ colorName = Color.class.getFields()[i].getName();
+ // Make only the first character capitalized.
+ fieldList.add(i, colorName.charAt(0) + colorName.substring(1).toLowerCase());
+ }
+ return fieldList.toArray(new String[fieldList.size()]);
+ }
+
+ /**
+ * 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;
+ }
+
+ public static int stringToColor(String color) {
+ try {
+ return (int) Color.class.getField(color.toUpperCase()).get(new Color());
+ } catch (Exception e) {
+ return 0; // Transparent.
+ }
+ }
+
+ public static String chromeStable() {
+ return STABLE_PACKAGE;
+ }
+
+ public static String chromeBeta() {
+ return BETA_PACKAGE;
+ }
+
+ public static String chromeDev() {
+ return DEV_PACKAGE;
+ }
+
+ public static String chromeLocal() {
+ return LOCAL_PACKAGE;
+ }
}
« demos/src/main/res/values/dimens.xml ('K') | « demos/src/main/res/values/styles.xml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698