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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabAppMenuPropertiesDelegate.java

Issue 2647593002: [Android] Add an option in CCT to disable star and download button (Closed)
Patch Set: nit Created 3 years, 11 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.customtabs; 5 package org.chromium.chrome.browser.customtabs;
6 6
7 import android.content.Intent; 7 import android.content.Intent;
8 import android.content.pm.PackageManager; 8 import android.content.pm.PackageManager;
9 import android.content.pm.ResolveInfo; 9 import android.content.pm.ResolveInfo;
10 import android.net.Uri; 10 import android.net.Uri;
(...skipping 17 matching lines...) Expand all
28 import java.util.concurrent.ExecutionException; 28 import java.util.concurrent.ExecutionException;
29 29
30 /** 30 /**
31 * App menu properties delegate for {@link CustomTabActivity}. 31 * App menu properties delegate for {@link CustomTabActivity}.
32 */ 32 */
33 public class CustomTabAppMenuPropertiesDelegate extends AppMenuPropertiesDelegat e { 33 public class CustomTabAppMenuPropertiesDelegate extends AppMenuPropertiesDelegat e {
34 private static final String SAMPLE_URL = "https://www.google.com"; 34 private static final String SAMPLE_URL = "https://www.google.com";
35 35
36 private final boolean mShowShare; 36 private final boolean mShowShare;
37 private final boolean mIsMediaViewer; 37 private final boolean mIsMediaViewer;
38 private final boolean mShowStar;
39 private final boolean mShowDownload;
38 40
39 private final List<String> mMenuEntries; 41 private final List<String> mMenuEntries;
40 private final Map<MenuItem, Integer> mItemToIndexMap = new HashMap<MenuItem, Integer>(); 42 private final Map<MenuItem, Integer> mItemToIndexMap = new HashMap<MenuItem, Integer>();
41 private final AsyncTask<Void, Void, String> mDefaultBrowserFetcher; 43 private final AsyncTask<Void, Void, String> mDefaultBrowserFetcher;
42 44
43 private boolean mIsCustomEntryAdded; 45 private boolean mIsCustomEntryAdded;
44 46
45 /** 47 /**
46 * Creates an {@link CustomTabAppMenuPropertiesDelegate} instance. 48 * Creates an {@link CustomTabAppMenuPropertiesDelegate} instance.
47 */ 49 */
48 public CustomTabAppMenuPropertiesDelegate(final ChromeActivity activity, 50 public CustomTabAppMenuPropertiesDelegate(final ChromeActivity activity,
49 List<String> menuEntries, boolean showShare, final boolean isOpenedB yChrome, 51 List<String> menuEntries, boolean showShare, final boolean isOpenedB yChrome,
50 final boolean isMediaViewer) { 52 final boolean isMediaViewer, boolean showStar, boolean showDownload) {
51 super(activity); 53 super(activity);
52 mMenuEntries = menuEntries; 54 mMenuEntries = menuEntries;
53 mShowShare = showShare; 55 mShowShare = showShare;
54 mIsMediaViewer = isMediaViewer; 56 mIsMediaViewer = isMediaViewer;
57 mShowStar = showStar;
58 mShowDownload = showDownload;
55 59
56 mDefaultBrowserFetcher = new AsyncTask<Void, Void, String>() { 60 mDefaultBrowserFetcher = new AsyncTask<Void, Void, String>() {
57 @Override 61 @Override
58 protected String doInBackground(Void... params) { 62 protected String doInBackground(Void... params) {
59 String packageLabel = null; 63 String packageLabel = null;
60 if (isOpenedByChrome) { 64 if (isOpenedByChrome) {
61 // If the Custom Tab was created by Chrome, Chrome should op en it. 65 // If the Custom Tab was created by Chrome, Chrome should op en it.
62 packageLabel = BuildInfo.getPackageLabel(activity); 66 packageLabel = BuildInfo.getPackageLabel(activity);
63 } else { 67 } else {
64 // Check if there is a default handler for the Intent. If s o, grab its label. 68 // Check if there is a default handler for the Intent. If s o, grab its label.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 addToHomeScreenItem.setVisible(false); 120 addToHomeScreenItem.setVisible(false);
117 } else { 121 } else {
118 try { 122 try {
119 openInChromeItem.setTitle(mDefaultBrowserFetcher.get()); 123 openInChromeItem.setTitle(mDefaultBrowserFetcher.get());
120 } catch (InterruptedException | ExecutionException e) { 124 } catch (InterruptedException | ExecutionException e) {
121 openInChromeItem.setTitle( 125 openInChromeItem.setTitle(
122 mActivity.getString(R.string.menu_open_in_product_de fault)); 126 mActivity.getString(R.string.menu_open_in_product_de fault));
123 } 127 }
124 updateBookmarkMenuItem(bookmarkItem, currentTab); 128 updateBookmarkMenuItem(bookmarkItem, currentTab);
125 } 129 }
126 130 bookmarkItem.setVisible(mShowStar);
131 downloadItem.setVisible(mShowDownload);
127 if (!FirstRunStatus.getFirstRunFlowComplete()) { 132 if (!FirstRunStatus.getFirstRunFlowComplete()) {
128 openInChromeItem.setVisible(false); 133 openInChromeItem.setVisible(false);
129 bookmarkItem.setVisible(false); 134 bookmarkItem.setVisible(false);
130 downloadItem.setVisible(false); 135 downloadItem.setVisible(false);
131 addToHomeScreenItem.setVisible(false); 136 addToHomeScreenItem.setVisible(false);
132 } 137 }
133 138
134 downloadItem.setEnabled(DownloadUtils.isAllowedToDownloadPage(curren tTab)); 139 downloadItem.setEnabled(DownloadUtils.isAllowedToDownloadPage(curren tTab));
135 140
136 // Add custom menu items. Make sure they are only added once. 141 // Add custom menu items. Make sure they are only added once.
(...skipping 28 matching lines...) Expand all
165 * the same title, a random one will be returned. This method is for testing purpose _only_. 170 * the same title, a random one will be returned. This method is for testing purpose _only_.
166 */ 171 */
167 @VisibleForTesting 172 @VisibleForTesting
168 MenuItem getMenuItemForTitle(String title) { 173 MenuItem getMenuItemForTitle(String title) {
169 for (MenuItem item : mItemToIndexMap.keySet()) { 174 for (MenuItem item : mItemToIndexMap.keySet()) {
170 if (item.getTitle().equals(title)) return item; 175 if (item.getTitle().equals(title)) return item;
171 } 176 }
172 return null; 177 return null;
173 } 178 }
174 } 179 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698