OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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; | 5 package org.chromium.chrome.browser; |
6 | 6 |
7 import android.annotation.SuppressLint; | |
8 import android.app.ActivityManager; | 7 import android.app.ActivityManager; |
9 import android.content.Context; | 8 import android.content.Context; |
10 import android.content.Intent; | 9 import android.content.Intent; |
11 import android.content.pm.ApplicationInfo; | 10 import android.content.pm.ApplicationInfo; |
12 import android.content.pm.PackageInfo; | 11 import android.content.pm.PackageInfo; |
13 import android.content.pm.PackageManager; | 12 import android.content.pm.PackageManager; |
14 import android.content.pm.PackageManager.NameNotFoundException; | 13 import android.content.pm.PackageManager.NameNotFoundException; |
15 import android.content.pm.ResolveInfo; | |
16 import android.graphics.Bitmap; | 14 import android.graphics.Bitmap; |
17 import android.graphics.BitmapFactory; | 15 import android.graphics.BitmapFactory; |
18 import android.graphics.Canvas; | 16 import android.graphics.Canvas; |
19 import android.graphics.Color; | 17 import android.graphics.Color; |
20 import android.graphics.Paint; | 18 import android.graphics.Paint; |
21 import android.graphics.Rect; | 19 import android.graphics.Rect; |
22 import android.graphics.drawable.BitmapDrawable; | 20 import android.graphics.drawable.BitmapDrawable; |
23 import android.graphics.drawable.Drawable; | 21 import android.graphics.drawable.Drawable; |
24 import android.net.Uri; | 22 import android.net.Uri; |
25 import android.os.AsyncTask; | 23 import android.os.AsyncTask; |
26 import android.support.annotation.NonNull; | 24 import android.support.annotation.NonNull; |
27 import android.text.TextUtils; | 25 import android.text.TextUtils; |
28 import android.util.Base64; | 26 import android.util.Base64; |
29 | 27 |
30 import org.chromium.base.ApiCompatibilityUtils; | 28 import org.chromium.base.ApiCompatibilityUtils; |
31 import org.chromium.base.ContextUtils; | 29 import org.chromium.base.ContextUtils; |
32 import org.chromium.base.Log; | 30 import org.chromium.base.Log; |
33 import org.chromium.base.ThreadUtils; | 31 import org.chromium.base.ThreadUtils; |
34 import org.chromium.base.VisibleForTesting; | 32 import org.chromium.base.VisibleForTesting; |
35 import org.chromium.base.annotations.CalledByNative; | 33 import org.chromium.base.annotations.CalledByNative; |
36 import org.chromium.blink_public.platform.WebDisplayMode; | 34 import org.chromium.blink_public.platform.WebDisplayMode; |
37 import org.chromium.chrome.R; | 35 import org.chromium.chrome.R; |
| 36 import org.chromium.chrome.browser.util.IntentUtils; |
| 37 import org.chromium.chrome.browser.webapps.ChromeShortcutManager; |
38 import org.chromium.chrome.browser.webapps.ChromeWebApkHost; | 38 import org.chromium.chrome.browser.webapps.ChromeWebApkHost; |
39 import org.chromium.chrome.browser.webapps.WebApkInfo; | 39 import org.chromium.chrome.browser.webapps.WebApkInfo; |
40 import org.chromium.chrome.browser.webapps.WebappActivity; | 40 import org.chromium.chrome.browser.webapps.WebappActivity; |
41 import org.chromium.chrome.browser.webapps.WebappAuthenticator; | 41 import org.chromium.chrome.browser.webapps.WebappAuthenticator; |
42 import org.chromium.chrome.browser.webapps.WebappDataStorage; | 42 import org.chromium.chrome.browser.webapps.WebappDataStorage; |
43 import org.chromium.chrome.browser.webapps.WebappLauncherActivity; | 43 import org.chromium.chrome.browser.webapps.WebappLauncherActivity; |
44 import org.chromium.chrome.browser.webapps.WebappRegistry; | 44 import org.chromium.chrome.browser.webapps.WebappRegistry; |
45 import org.chromium.chrome.browser.widget.RoundedIconGenerator; | 45 import org.chromium.chrome.browser.widget.RoundedIconGenerator; |
46 import org.chromium.content_public.common.ScreenOrientationConstants; | 46 import org.chromium.content_public.common.ScreenOrientationConstants; |
47 import org.chromium.ui.widget.Toast; | 47 import org.chromium.ui.widget.Toast; |
48 import org.chromium.webapk.lib.client.WebApkValidator; | 48 import org.chromium.webapk.lib.client.WebApkValidator; |
49 | 49 |
50 import java.io.ByteArrayOutputStream; | 50 import java.io.ByteArrayOutputStream; |
51 import java.util.ArrayList; | 51 import java.util.ArrayList; |
52 import java.util.List; | 52 import java.util.List; |
53 | 53 |
54 /** | 54 /** |
55 * This class contains functions related to adding shortcuts to the Android Home | 55 * This class contains functions related to adding shortcuts to the Android Home |
56 * screen. These shortcuts are used to either open a page in the main browser | 56 * screen. These shortcuts are used to either open a page in the main browser |
57 * or open a web app. | 57 * or open a web app. |
58 */ | 58 */ |
59 public class ShortcutHelper { | 59 public class ShortcutHelper { |
60 public static final String EXTRA_ICON = "org.chromium.chrome.browser.webapp_
icon"; | 60 public static final String EXTRA_ICON = "org.chromium.chrome.browser.webapp_
icon"; |
61 public static final String EXTRA_ID = "org.chromium.chrome.browser.webapp_id
"; | 61 public static final String EXTRA_ID = "org.chromium.chrome.browser.webapp_id
"; |
62 public static final String EXTRA_MAC = "org.chromium.chrome.browser.webapp_m
ac"; | 62 public static final String EXTRA_MAC = "org.chromium.chrome.browser.webapp_m
ac"; |
63 // EXTRA_TITLE is present for backward compatibility reasons | 63 // EXTRA_TITLE is present for backward compatibility reasons. |
64 public static final String EXTRA_TITLE = "org.chromium.chrome.browser.webapp
_title"; | 64 public static final String EXTRA_TITLE = "org.chromium.chrome.browser.webapp
_title"; |
65 public static final String EXTRA_NAME = "org.chromium.chrome.browser.webapp_
name"; | 65 public static final String EXTRA_NAME = "org.chromium.chrome.browser.webapp_
name"; |
66 public static final String EXTRA_SHORT_NAME = "org.chromium.chrome.browser.w
ebapp_short_name"; | 66 public static final String EXTRA_SHORT_NAME = "org.chromium.chrome.browser.w
ebapp_short_name"; |
67 public static final String EXTRA_URL = "org.chromium.chrome.browser.webapp_u
rl"; | 67 public static final String EXTRA_URL = "org.chromium.chrome.browser.webapp_u
rl"; |
68 public static final String EXTRA_SCOPE = "org.chromium.chrome.browser.webapp
_scope"; | 68 public static final String EXTRA_SCOPE = "org.chromium.chrome.browser.webapp
_scope"; |
69 public static final String EXTRA_DISPLAY_MODE = | 69 public static final String EXTRA_DISPLAY_MODE = |
70 "org.chromium.chrome.browser.webapp_display_mode"; | 70 "org.chromium.chrome.browser.webapp_display_mode"; |
71 public static final String EXTRA_ORIENTATION = ScreenOrientationConstants.EX
TRA_ORIENTATION; | 71 public static final String EXTRA_ORIENTATION = ScreenOrientationConstants.EX
TRA_ORIENTATION; |
72 public static final String EXTRA_SOURCE = "org.chromium.chrome.browser.webap
p_source"; | 72 public static final String EXTRA_SOURCE = "org.chromium.chrome.browser.webap
p_source"; |
73 public static final String EXTRA_THEME_COLOR = "org.chromium.chrome.browser.
theme_color"; | 73 public static final String EXTRA_THEME_COLOR = "org.chromium.chrome.browser.
theme_color"; |
74 public static final String EXTRA_BACKGROUND_COLOR = | 74 public static final String EXTRA_BACKGROUND_COLOR = |
75 "org.chromium.chrome.browser.background_color"; | 75 "org.chromium.chrome.browser.background_color"; |
76 public static final String EXTRA_IS_ICON_GENERATED = | 76 public static final String EXTRA_IS_ICON_GENERATED = |
77 "org.chromium.chrome.browser.is_icon_generated"; | 77 "org.chromium.chrome.browser.is_icon_generated"; |
78 public static final String EXTRA_VERSION = | 78 public static final String EXTRA_VERSION = |
79 "org.chromium.chrome.browser.webapp_shortcut_version"; | 79 "org.chromium.chrome.browser.webapp_shortcut_version"; |
80 public static final String REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB = | 80 public static final String REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB = |
81 "REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB"; | 81 "REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB"; |
82 public static final String EXTRA_WEBAPK_PACKAGE_NAME = | 82 public static final String EXTRA_WEBAPK_PACKAGE_NAME = |
83 "org.chromium.chrome.browser.webapk_package_name"; | 83 "org.chromium.chrome.browser.webapk_package_name"; |
84 | 84 |
| 85 /** Used for the callback intent when using the new shortcut API. */ |
| 86 public static final String SHORTCUT_TOAST_CATEGORY = |
| 87 "com.google.intent.category.SHORTCUT_TOAST"; |
| 88 |
85 // When a new field is added to the intent, this version should be increment
ed so that it will | 89 // When a new field is added to the intent, this version should be increment
ed so that it will |
86 // be correctly populated into the WebappRegistry/WebappDataStorage. | 90 // be correctly populated into the WebappRegistry/WebappDataStorage. |
87 public static final int WEBAPP_SHORTCUT_VERSION = 2; | 91 public static final int WEBAPP_SHORTCUT_VERSION = 2; |
88 | 92 |
89 // This value is equal to kInvalidOrMissingColor in the C++ content::Manifes
t struct. | 93 // This value is equal to kInvalidOrMissingColor in the C++ content::Manifes
t struct. |
90 public static final long MANIFEST_COLOR_INVALID_OR_MISSING = ((long) Integer
.MAX_VALUE) + 1; | 94 public static final long MANIFEST_COLOR_INVALID_OR_MISSING = ((long) Integer
.MAX_VALUE) + 1; |
91 | 95 |
92 private static final String TAG = "ShortcutHelper"; | 96 private static final String TAG = "ShortcutHelper"; |
93 | 97 |
94 // There is no public string defining this intent so if Home changes the val
ue, we | |
95 // have to update this string. | |
96 private static final String INSTALL_SHORTCUT = "com.android.launcher.action.
INSTALL_SHORTCUT"; | |
97 | |
98 // The activity class used for launching a WebApk. | 98 // The activity class used for launching a WebApk. |
99 private static final String WEBAPK_MAIN_ACTIVITY = "org.chromium.webapk.shel
l_apk.MainActivity"; | 99 private static final String WEBAPK_MAIN_ACTIVITY = "org.chromium.webapk.shel
l_apk.MainActivity"; |
100 | 100 |
101 // These sizes are from the Material spec for icons: | 101 // These sizes are from the Material spec for icons: |
102 // https://www.google.com/design/spec/style/icons.html#icons-product-icons | 102 // https://www.google.com/design/spec/style/icons.html#icons-product-icons |
103 private static final float MAX_INNER_SIZE_RATIO = 1.25f; | 103 private static final float MAX_INNER_SIZE_RATIO = 1.25f; |
104 private static final float ICON_PADDING_RATIO = 2.0f / 44.0f; | 104 private static final float ICON_PADDING_RATIO = 2.0f / 44.0f; |
105 private static final float ICON_CORNER_RADIUS_RATIO = 1.0f / 16.0f; | 105 private static final float ICON_CORNER_RADIUS_RATIO = 1.0f / 16.0f; |
106 private static final float GENERATED_ICON_PADDING_RATIO = 1.0f / 12.0f; | 106 private static final float GENERATED_ICON_PADDING_RATIO = 1.0f / 12.0f; |
107 private static final float GENERATED_ICON_FONT_SIZE_RATIO = 1.0f / 3.0f; | 107 private static final float GENERATED_ICON_FONT_SIZE_RATIO = 1.0f / 3.0f; |
108 | 108 |
109 /** Broadcasts Intents out Android for adding the shortcut. */ | 109 /** Helper for generating home screen shortcuts. */ |
110 public static class Delegate { | 110 public static class Delegate { |
111 /** | 111 /** |
112 * Broadcasts an intent to all interested BroadcastReceivers. | 112 * Request Android to add a shortcut to the home screen. |
113 * @param context The Context to use. | 113 * @param title Title of the shortcut. |
114 * @param intent The intent to broadcast. | 114 * @param icon Image that represents the shortcut. |
| 115 * @param intent Intent to fire when the shortcut is activated. |
115 */ | 116 */ |
116 public void sendBroadcast(Context context, Intent intent) { | 117 public void addShortcutToHomescreen(String title, Bitmap icon, Intent sh
ortcutIntent) { |
117 context.sendBroadcast(intent); | 118 ChromeShortcutManager.getInstance().addShortcutToHomeScreen( |
| 119 title, icon, shortcutIntent); |
118 } | 120 } |
119 | 121 |
120 /** | 122 /** |
121 * Returns the name of the fullscreen Activity to use when launching sho
rtcuts. | 123 * Returns the name of the fullscreen Activity to use when launching sho
rtcuts. |
122 */ | 124 */ |
123 public String getFullscreenAction() { | 125 public String getFullscreenAction() { |
124 return WebappLauncherActivity.ACTION_START_WEBAPP; | 126 return WebappLauncherActivity.ACTION_START_WEBAPP; |
125 } | 127 } |
126 } | 128 } |
127 | 129 |
(...skipping 30 matching lines...) Expand all Loading... |
158 sDelegate.getFullscreenAction(), url, nonEmptyScopeUrl,
name, shortName, | 160 sDelegate.getFullscreenAction(), url, nonEmptyScopeUrl,
name, shortName, |
159 icon, WEBAPP_SHORTCUT_VERSION, displayMode, orientation,
themeColor, | 161 icon, WEBAPP_SHORTCUT_VERSION, displayMode, orientation,
themeColor, |
160 backgroundColor, iconUrl.isEmpty()); | 162 backgroundColor, iconUrl.isEmpty()); |
161 shortcutIntent.putExtra(EXTRA_MAC, getEncodedMac(context, url)); | 163 shortcutIntent.putExtra(EXTRA_MAC, getEncodedMac(context, url)); |
162 shortcutIntent.putExtra(EXTRA_SOURCE, source); | 164 shortcutIntent.putExtra(EXTRA_SOURCE, source); |
163 shortcutIntent.setPackage(context.getPackageName()); | 165 shortcutIntent.setPackage(context.getPackageName()); |
164 return shortcutIntent; | 166 return shortcutIntent; |
165 } | 167 } |
166 @Override | 168 @Override |
167 protected void onPostExecute(final Intent resultIntent) { | 169 protected void onPostExecute(final Intent resultIntent) { |
168 Context context = ContextUtils.getApplicationContext(); | 170 sDelegate.addShortcutToHomescreen(userTitle, icon, resultIntent)
; |
169 sDelegate.sendBroadcast( | |
170 context, createAddToHomeIntent(userTitle, icon, resultIn
tent)); | |
171 | 171 |
172 // Store the webapp data so that it is accessible without the in
tent. Once this | 172 // Store the webapp data so that it is accessible without the in
tent. Once this |
173 // process is complete, call back to native code to start the sp
lash image | 173 // process is complete, call back to native code to start the sp
lash image |
174 // download. | 174 // download. |
175 WebappRegistry.getInstance().register( | 175 WebappRegistry.getInstance().register( |
176 id, new WebappRegistry.FetchWebappDataStorageCallback()
{ | 176 id, new WebappRegistry.FetchWebappDataStorageCallback()
{ |
177 @Override | 177 @Override |
178 public void onWebappDataStorageRetrieved(WebappDataS
torage storage) { | 178 public void onWebappDataStorageRetrieved(WebappDataS
torage storage) { |
179 storage.updateFromShortcutIntent(resultIntent); | 179 storage.updateFromShortcutIntent(resultIntent); |
180 nativeOnWebappDataStored(callbackPointer); | 180 nativeOnWebappDataStored(callbackPointer); |
181 } | 181 } |
182 }); | 182 }); |
183 | 183 if (ChromeShortcutManager.getInstance().shouldShowToastWhenAddin
gShortcut()) { |
184 showAddedToHomescreenToast(userTitle); | 184 showAddedToHomescreenToast(userTitle); |
| 185 } |
185 } | 186 } |
186 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); | 187 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
187 } | 188 } |
188 | 189 |
189 public static void addWebApkShortcut(Context context, String packageName) { | 190 public static void addWebApkShortcut(Context context, String packageName) { |
190 PackageManager pm = context.getPackageManager(); | 191 PackageManager pm = context.getPackageManager(); |
191 try { | 192 try { |
192 ApplicationInfo appInfo = pm.getApplicationInfo( | 193 ApplicationInfo appInfo = pm.getApplicationInfo( |
193 packageName, PackageManager.GET_META_DATA); | 194 packageName, PackageManager.GET_META_DATA); |
194 String shortcutTitle = pm.getApplicationLabel(appInfo).toString(); | 195 String shortcutTitle = pm.getApplicationLabel(appInfo).toString(); |
195 Bitmap shortcutIcon = ((BitmapDrawable) pm.getApplicationIcon(packag
eName)).getBitmap(); | 196 Bitmap shortcutIcon = ((BitmapDrawable) pm.getApplicationIcon(packag
eName)).getBitmap(); |
196 | 197 |
197 Bitmap bitmap = createHomeScreenIconFromWebIcon(shortcutIcon); | 198 Bitmap bitmap = createHomeScreenIconFromWebIcon(shortcutIcon); |
198 Intent i = new Intent(); | 199 Intent i = new Intent(); |
199 i.setClassName(packageName, WEBAPK_MAIN_ACTIVITY); | 200 i.setClassName(packageName, WEBAPK_MAIN_ACTIVITY); |
200 i.addCategory(Intent.CATEGORY_LAUNCHER); | 201 i.addCategory(Intent.CATEGORY_LAUNCHER); |
201 context.sendBroadcast(createAddToHomeIntent(shortcutTitle, bitmap, i
)); | 202 context.sendBroadcast( |
| 203 ChromeShortcutManager.createAddToHomeIntent(shortcutTitle, b
itmap, i)); |
202 } catch (NameNotFoundException e) { | 204 } catch (NameNotFoundException e) { |
203 e.printStackTrace(); | 205 e.printStackTrace(); |
204 } | 206 } |
205 } | 207 } |
206 | 208 |
207 /** | 209 /** |
208 * Adds home screen shortcut which opens in the browser Activity. | 210 * Adds home screen shortcut which opens in the browser Activity. |
209 */ | 211 */ |
210 @SuppressWarnings("unused") | 212 @SuppressWarnings("unused") |
211 @CalledByNative | 213 @CalledByNative |
212 private static void addShortcut(String url, String userTitle, Bitmap icon, i
nt source) { | 214 private static void addShortcut( |
| 215 String id, String url, String userTitle, Bitmap icon, int source) { |
213 Context context = ContextUtils.getApplicationContext(); | 216 Context context = ContextUtils.getApplicationContext(); |
214 final Intent shortcutIntent = createShortcutIntent(url); | 217 final Intent shortcutIntent = createShortcutIntent(url); |
| 218 shortcutIntent.putExtra(EXTRA_ID, id); |
215 shortcutIntent.putExtra(EXTRA_SOURCE, source); | 219 shortcutIntent.putExtra(EXTRA_SOURCE, source); |
216 shortcutIntent.setPackage(context.getPackageName()); | 220 shortcutIntent.setPackage(context.getPackageName()); |
217 sDelegate.sendBroadcast( | 221 sDelegate.addShortcutToHomescreen(userTitle, icon, shortcutIntent); |
218 context, createAddToHomeIntent(userTitle, icon, shortcutIntent))
; | 222 if (ChromeShortcutManager.getInstance().shouldShowToastWhenAddingShortcu
t()) { |
219 showAddedToHomescreenToast(userTitle); | 223 showAddedToHomescreenToast(userTitle); |
| 224 } |
220 } | 225 } |
221 | 226 |
222 /** | 227 /** |
223 * Show toast to alert user that the shortcut was added to the home screen. | 228 * Show toast to alert user that the shortcut was added to the home screen. |
224 */ | 229 */ |
225 private static void showAddedToHomescreenToast(final String title) { | 230 private static void showAddedToHomescreenToast(final String title) { |
226 Context applicationContext = ContextUtils.getApplicationContext(); | 231 Context applicationContext = ContextUtils.getApplicationContext(); |
227 String toastText = applicationContext.getString(R.string.added_to_homesc
reen, title); | 232 String toastText = applicationContext.getString(R.string.added_to_homesc
reen, title); |
228 showToast(toastText); | 233 showToast(toastText); |
229 } | 234 } |
230 | 235 |
231 /** | 236 /** |
| 237 * Show toast when getting the callback intent by the launcher after adding
shortcut by using |
| 238 * the new shortcut API. |
| 239 */ |
| 240 public static void showAddedToHomescreenToastFromIntent(Intent intent) { |
| 241 String title = IntentUtils.safeGetStringExtra(intent, Intent.EXTRA_SHORT
CUT_NAME); |
| 242 showAddedToHomescreenToast(title); |
| 243 } |
| 244 |
| 245 /** |
| 246 * Determine if it is a callback intent (which requests for a show-toast), u
sed in the new |
| 247 * shortcut API. |
| 248 */ |
| 249 public static boolean isShowToastIntent(Intent intent) { |
| 250 if (intent == null || intent.getCategories() == null) return false; |
| 251 return intent.getCategories().contains(SHORTCUT_TOAST_CATEGORY); |
| 252 } |
| 253 |
| 254 /** |
232 * Shows toast notifying user that a WebAPK install is already in progress w
hen user tries to | 255 * Shows toast notifying user that a WebAPK install is already in progress w
hen user tries to |
233 * queue a new install for the same WebAPK. | 256 * queue a new install for the same WebAPK. |
234 */ | 257 */ |
235 @SuppressWarnings("unused") | 258 @SuppressWarnings("unused") |
236 @CalledByNative | 259 @CalledByNative |
237 private static void showWebApkInstallInProgressToast() { | 260 private static void showWebApkInstallInProgressToast() { |
238 Context applicationContext = ContextUtils.getApplicationContext(); | 261 Context applicationContext = ContextUtils.getApplicationContext(); |
239 String toastText = applicationContext.getString(R.string.webapk_install_
in_progress); | 262 String toastText = applicationContext.getString(R.string.webapk_install_
in_progress); |
240 showToast(toastText); | 263 showToast(toastText); |
241 } | 264 } |
(...skipping 24 matching lines...) Expand all Loading... |
266 | 289 |
267 @Override | 290 @Override |
268 protected void onPostExecute(String encodedImage) { | 291 protected void onPostExecute(String encodedImage) { |
269 storage.updateSplashScreenImage(encodedImage); | 292 storage.updateSplashScreenImage(encodedImage); |
270 } | 293 } |
271 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); | 294 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
272 } | 295 } |
273 } | 296 } |
274 | 297 |
275 /** | 298 /** |
276 * Creates an intent that will add a shortcut to the home screen. | |
277 * @param title Title of the shortcut. | |
278 * @param icon Image that represents the shortcut. | |
279 * @param shortcutIntent Intent to fire when the shortcut is activated. | |
280 * @return Intent for the shortcut. | |
281 */ | |
282 public static Intent createAddToHomeIntent(String title, Bitmap icon, | |
283 Intent shortcutIntent) { | |
284 Intent i = new Intent(INSTALL_SHORTCUT); | |
285 i.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); | |
286 i.putExtra(Intent.EXTRA_SHORTCUT_NAME, title); | |
287 i.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon); | |
288 return i; | |
289 } | |
290 | |
291 /** | |
292 * Creates a shortcut to launch a web app on the home screen. | 299 * Creates a shortcut to launch a web app on the home screen. |
293 * @param id Id of the web app. | 300 * @param id Id of the web app. |
294 * @param action Intent action to open a full screen activity. | 301 * @param action Intent action to open a full screen activity. |
295 * @param url Url of the web app. | 302 * @param url Url of the web app. |
296 * @param scope Url scope of the web app. | 303 * @param scope Url scope of the web app. |
297 * @param name Name of the web app. | 304 * @param name Name of the web app. |
298 * @param shortName Short name of the web app. | 305 * @param shortName Short name of the web app. |
299 * @param icon Icon of the web app. | 306 * @param icon Icon of the web app. |
300 * @param version Version number of the shortcut. | 307 * @param version Version number of the shortcut. |
301 * @param displayMode Display mode of the web app. | 308 * @param displayMode Display mode of the web app. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 * @return Intent for onclick action of the shortcut. | 358 * @return Intent for onclick action of the shortcut. |
352 */ | 359 */ |
353 public static Intent createShortcutIntent(String url) { | 360 public static Intent createShortcutIntent(String url) { |
354 Intent shortcutIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); | 361 Intent shortcutIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); |
355 shortcutIntent.putExtra(REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB, true); | 362 shortcutIntent.putExtra(REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB, true); |
356 return shortcutIntent; | 363 return shortcutIntent; |
357 } | 364 } |
358 | 365 |
359 /** | 366 /** |
360 * Utility method to check if a shortcut can be added to the home screen. | 367 * Utility method to check if a shortcut can be added to the home screen. |
361 * @param context Context used to get the package manager. | |
362 * @return if a shortcut can be added to the home screen under the current p
rofile. | 368 * @return if a shortcut can be added to the home screen under the current p
rofile. |
363 */ | 369 */ |
364 // TODO(crbug.com/635567): Fix this properly. | 370 public static boolean isAddToHomeIntentSupported() { |
365 @SuppressLint("WrongConstant") | 371 return ChromeShortcutManager.getInstance().canAddShortcutToHomescreen(); |
366 public static boolean isAddToHomeIntentSupported(Context context) { | |
367 PackageManager pm = context.getPackageManager(); | |
368 Intent i = new Intent(INSTALL_SHORTCUT); | |
369 List<ResolveInfo> receivers = pm.queryBroadcastReceivers( | |
370 i, PackageManager.GET_INTENT_FILTERS); | |
371 return !receivers.isEmpty(); | |
372 } | 372 } |
373 | 373 |
374 /** | 374 /** |
375 * Returns whether the given icon matches the size requirements to be used o
n the home screen. | 375 * Returns whether the given icon matches the size requirements to be used o
n the home screen. |
376 * @param width Icon width, in pixels. | 376 * @param width Icon width, in pixels. |
377 * @param height Icon height, in pixels. | 377 * @param height Icon height, in pixels. |
378 * @return whether the given icon matches the size requirements to be used o
n the home screen. | 378 * @return whether the given icon matches the size requirements to be used o
n the home screen. |
379 */ | 379 */ |
380 @CalledByNative | 380 @CalledByNative |
381 public static boolean isIconLargeEnoughForLauncher(int width, int height) { | 381 public static boolean isIconLargeEnoughForLauncher(int width, int height) { |
382 Context context = ContextUtils.getApplicationContext(); | 382 Context context = ContextUtils.getApplicationContext(); |
383 ActivityManager am = (ActivityManager) context.getSystemService(Context.
ACTIVITY_SERVICE); | 383 ActivityManager am = (ActivityManager) context.getSystemService(Context.
ACTIVITY_SERVICE); |
384 final int minimalSize = am.getLauncherLargeIconSize() / 2; | 384 final int minimalSize = am.getLauncherLargeIconSize() / 2; |
385 return width >= minimalSize && height >= minimalSize; | 385 return width >= minimalSize && height >= minimalSize; |
386 } | 386 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 paint.setFilterBitmap(true); | 429 paint.setFilterBitmap(true); |
430 canvas.drawBitmap(webIcon, null, innerBounds, paint); | 430 canvas.drawBitmap(webIcon, null, innerBounds, paint); |
431 | 431 |
432 return bitmap; | 432 return bitmap; |
433 } | 433 } |
434 | 434 |
435 /** | 435 /** |
436 * Generates a generic icon to be used in the launcher. This is just a round
ed rectangle with | 436 * Generates a generic icon to be used in the launcher. This is just a round
ed rectangle with |
437 * a letter in the middle taken from the website's domain name. | 437 * a letter in the middle taken from the website's domain name. |
438 * | 438 * |
439 * @param url URL of the shortcut. | 439 * @param url URL of the shortcut. |
440 * @param red Red component of the dominant icon color. | 440 * @param red Red component of the dominant icon color. |
441 * @param green Green component of the dominant icon color. | 441 * @param green Green component of the dominant icon color. |
442 * @param blue Blue component of the dominant icon color. | 442 * @param blue Blue component of the dominant icon color. |
443 * @return Bitmap Either the touch-icon or the newly created favicon. | 443 * @return Bitmap Either the touch-icon or the newly created favicon. |
444 */ | 444 */ |
445 @CalledByNative | 445 @CalledByNative |
446 public static Bitmap generateHomeScreenIcon(String url, int red, int green,
int blue) { | 446 public static Bitmap generateHomeScreenIcon(String url, int red, int green,
int blue) { |
447 Context context = ContextUtils.getApplicationContext(); | 447 Context context = ContextUtils.getApplicationContext(); |
448 ActivityManager am = (ActivityManager) context.getSystemService(Context.
ACTIVITY_SERVICE); | 448 ActivityManager am = (ActivityManager) context.getSystemService(Context.
ACTIVITY_SERVICE); |
449 final int outerSize = am.getLauncherLargeIconSize(); | 449 final int outerSize = am.getLauncherLargeIconSize(); |
450 final int iconDensity = am.getLauncherLargeIconDensity(); | 450 final int iconDensity = am.getLauncherLargeIconDensity(); |
451 | 451 |
452 Bitmap bitmap = null; | 452 Bitmap bitmap = null; |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 for (int i = 0; i < list.size(); i++) { | 700 for (int i = 0; i < list.size(); i++) { |
701 array[i] = list.get(i); | 701 array[i] = list.get(i); |
702 } | 702 } |
703 return array; | 703 return array; |
704 } | 704 } |
705 | 705 |
706 private static native void nativeOnWebappDataStored(long callbackPointer); | 706 private static native void nativeOnWebappDataStored(long callbackPointer); |
707 private static native void nativeOnWebApksRetrieved(long callbackPointer, St
ring[] shortNames, | 707 private static native void nativeOnWebApksRetrieved(long callbackPointer, St
ring[] shortNames, |
708 String[] packageName, int[] shellApkVersions, int[] versionCodes); | 708 String[] packageName, int[] shellApkVersions, int[] versionCodes); |
709 } | 709 } |
OLD | NEW |