Chromium Code Reviews| Index: customtabs/src/android/support/customtabs/browseraction/BrowserActionCreator.java |
| diff --git a/customtabs/src/android/support/customtabs/browseraction/BrowserActionCreator.java b/customtabs/src/android/support/customtabs/browseraction/BrowserActionCreator.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e1a972efd73357a08c3d59d15ab928e74ef6abb2 |
| --- /dev/null |
| +++ b/customtabs/src/android/support/customtabs/browseraction/BrowserActionCreator.java |
| @@ -0,0 +1,77 @@ |
| +/* |
| + * Copyright (C) 2017 The Android Open Source Project |
| + * |
| + * Licensed under the Apache License, Version 2.0 (the "License"); |
| + * you may not use this file except in compliance with the License. |
| + * You may obtain a copy of the License at |
| + * |
| + * http://www.apache.org/licenses/LICENSE-2.0 |
| + * |
| + * Unless required by applicable law or agreed to in writing, software |
| + * distributed under the License is distributed on an "AS IS" BASIS, |
| + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| + * See the License for the specific language governing permissions and |
| + * limitations under the License. |
| + */ |
| +package android.support.customtabs.browseraction; |
|
Yusuf
2017/04/03 18:00:48
browseractions
ltian
2017/04/05 01:44:28
Done.
|
| + |
| +import android.content.Context; |
| +import android.content.Intent; |
| +import android.content.pm.PackageManager; |
| +import android.content.pm.ResolveInfo; |
| +import android.net.Uri; |
| + |
| +import java.util.ArrayList; |
| +import java.util.List; |
| + |
| +/** |
| + * A delegate class to open a browser action menu. |
| + */ |
| +public class BrowserActionCreator { |
|
Yusuf
2017/04/03 18:00:48
I think we should combine this into BrowserActions
ltian
2017/04/05 01:44:28
Done.
|
| + /** |
| + * Open a browser action menu with custom items. |
| + * It first checks if Chrome is available to create a browser action menu. |
|
Yusuf
2017/04/03 18:00:48
no mention of Chrome here. "any BrowserActions pro
ltian
2017/04/05 01:44:28
Done.
|
| + * If not, open a browser action locally from support library. |
| + * @param context The context requests for browser action menu. |
| + * @param url The url for browser action menu. |
| + * @param type The type of the url for context menu to be opened. |
| + * @param items List of custom items to be added to browser action menu. |
| + */ |
| + public static void create( |
| + Context context, String url, int type, ArrayList<BrowserActionItem> items) { |
| + if (hasBrowserActionIntentHandler(context)) { |
| + BrowserActionIntent.Builder builder = new BrowserActionIntent.Builder(); |
| + builder.setUrlType(type); |
| + builder.setCustomItems(items); |
| + BrowserActionIntent intent = builder.build(); |
| + intent.openBrowserAction(context, Uri.parse(url)); |
| + } else { |
| + openLocalBrowserAction(context, url, type, items); |
| + } |
| + } |
| + |
| + /** |
| + * Check whether Chrome is available to handle the intent to open a browser action context menu. |
| + * @param context The context requests the browser action menu. |
| + * @return true If Chrome could handle the intent. |
| + */ |
| + private static boolean hasBrowserActionIntentHandler(Context context) { |
| + Intent intent = BrowserActionIntent.getLightWeightBrowserActionIntent(); |
| + PackageManager pm = context.getPackageManager(); |
| + List<ResolveInfo> resolveInfoList = |
| + pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); |
|
Yusuf
2017/04/03 18:00:48
if we say MATCH_DEFAULT_ONLY, we will always fail
ltian
2017/04/05 01:44:28
Done.
|
| + return resolveInfoList.size() > 0 ? true : false; |
| + } |
| + |
| + /** |
| + * Open a browser action menu from support library. |
| + * @param context The context requests the browser action menu. |
| + * @param url The url for browser action menu. |
| + * @param type The type of the url for context menu to be opened. |
| + * @param items List of custom items to add to browser action menu. |
| + */ |
| + private static void openLocalBrowserAction( |
| + Context context, String url, int type, ArrayList<BrowserActionItem> items) { |
| + return; |
| + } |
| +} |