Chromium Code Reviews| OLD | NEW |
|---|---|
| (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.Context; | |
| 9 import android.content.Intent; | |
| 10 import android.content.pm.PackageManager; | |
| 11 import android.content.pm.ResolveInfo; | |
| 12 | |
| 13 import org.chromium.chrome.browser.ChromeApplication; | |
| 14 import org.chromium.chrome.browser.ShortcutHelper; | |
| 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. | |
| 21 */ | |
| 22 public class ChromeShortcutManager { | |
| 23 private static ChromeShortcutManager sInstance; | |
| 24 | |
| 25 /* Returns the singleton instance of ChromeShortcutManager, creating it if n eeded. */ | |
| 26 public static ChromeShortcutManager getInstance(Context context) { | |
| 27 if (sInstance == null) { | |
| 28 sInstance = ((ChromeApplication) context.getApplicationContext()) | |
| 29 .createChromeShortcutManager(); | |
| 30 } | |
| 31 return sInstance; | |
| 32 } | |
| 33 | |
| 34 public void addShortcutToHomeScreen(final Context context, final Intent inte nt) { | |
|
dominickn
2017/02/13 05:18:02
Instead of taking an Intent, can this take the id,
Marti Wong
2017/02/14 02:42:47
Done.
| |
| 35 context.sendBroadcast(intent); | |
| 36 } | |
| 37 | |
| 38 // TODO(crbug.com/635567): Fix this properly. | |
| 39 @SuppressLint("WrongConstant") | |
| 40 public boolean isAddShortcutToHomeScreenSupported(final Context context) { | |
|
dominickn
2017/02/13 05:18:02
Perhaps call this canAddShortcutToHomescreen()
Marti Wong
2017/02/14 02:42:47
Done.
| |
| 41 PackageManager pm = context.getPackageManager(); | |
| 42 Intent i = new Intent(ShortcutHelper.INSTALL_SHORTCUT); | |
| 43 List<ResolveInfo> receivers = | |
| 44 pm.queryBroadcastReceivers(i, PackageManager.GET_INTENT_FILTERS) ; | |
| 45 return !receivers.isEmpty(); | |
| 46 } | |
| 47 | |
| 48 public boolean canShowAddedToHomescreenToast(final Context context) { | |
|
dominickn
2017/02/13 05:18:02
Maybe call this shouldShowAddedToHomescreenToast()
Marti Wong
2017/02/14 02:42:47
Done.
| |
| 49 return true; | |
| 50 } | |
| 51 } | |
| OLD | NEW |