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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/webapps/ChromeShortcutManager.java

Issue 2689993002: Refactor the INSTALL_SHORTCUT broadcast code into ChromeShortcutManager (Closed)
Patch Set: Sync and upload again Created 3 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.webapps;
6
7 import android.annotation.SuppressLint;
8 import android.content.Intent;
9 import android.content.pm.PackageManager;
10 import android.content.pm.ResolveInfo;
11 import android.graphics.Bitmap;
12
13 import org.chromium.base.ContextUtils;
14 import org.chromium.chrome.browser.ChromeApplication;
15
16 import java.util.List;
17
18 /**
19 * This class helps to add a shortcut to the Android Home Screen. It also tells if
20 * addShortcutToHomeScreen is supported or not.
gone 2017/02/15 19:40:19 1) Don't need to enumerate everything it does. Ju
Marti Wong 2017/02/17 05:10:49 It's really hard to think of a new name without co
gone 2017/02/17 19:41:43 Acknowledged.
21 */
22 public class ChromeShortcutManager {
23 private static ChromeShortcutManager sInstance;
gone 2017/02/15 19:40:19 nit: move private static below private static fina
Marti Wong 2017/02/17 05:10:49 Done.
24
25 // There is no public string defining this intent so if Home changes the val ue, we
26 // have to update this string.
27 private static final String INSTALL_SHORTCUT = "com.android.launcher.action. INSTALL_SHORTCUT";
28
29 /* Returns the singleton instance of ChromeShortcutManager, creating it if n eeded. */
30 public static ChromeShortcutManager getInstance() {
31 if (sInstance == null) {
32 sInstance = ((ChromeApplication) ContextUtils.getApplicationContext( )
33 .getApplicationContext())
34 .createChromeShortcutManager();
gone 2017/02/15 19:40:19 1) is this a git cl format thing? really struggli
Marti Wong 2017/02/17 05:10:49 Sorry about that. fixed.
35 }
36 return sInstance;
37 }
38
39 /**
40 * Creates an intent that will add a shortcut to the home screen.
41 * @param title Title of the shortcut.
gone 2017/02/15 19:40:19 nit: line up params?
Marti Wong 2017/02/17 05:10:49 Done.
42 * @param icon Image that represents the shortcut.
43 * @param shortcutIntent Intent to fire when the shortcut is activated.
44 * @return Intent for the shortcut.
45 */
46 public static Intent createAddToHomeIntent(String title, Bitmap icon, Intent shortcutIntent) {
47 Intent i = new Intent(INSTALL_SHORTCUT);
48 i.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
49 i.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
50 i.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
51 return i;
52 }
53
54 public void addShortcutToHomeScreen(String title, Bitmap icon, Intent shortc utIntent) {
gone 2017/02/15 19:40:19 public method -> add javadoc
Marti Wong 2017/02/17 05:10:49 Done.
55 Intent intent = createAddToHomeIntent(title, icon, shortcutIntent);
56 ContextUtils.getApplicationContext().sendBroadcast(intent);
57 }
58
59 // TODO(crbug.com/635567): Fix this properly.
60 @SuppressLint("WrongConstant")
61 public boolean canAddShortcutToHomescreen() {
62 PackageManager pm = ContextUtils.getApplicationContext().getPackageManag er();
63 Intent i = new Intent(INSTALL_SHORTCUT);
64 List<ResolveInfo> receivers =
65 pm.queryBroadcastReceivers(i, PackageManager.GET_INTENT_FILTERS) ;
66 return !receivers.isEmpty();
67 }
68
69 public boolean shouldShowToastWhenAddingShortcut() {
70 return true;
71 }
72 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698