зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1417049 - [1.2] Don't show Add to Home Screen page action for incompatible launchers. r=nechen
This commit is contained in:
Родитель
964d3272c8
Коммит
546e2f6dbb
|
@ -163,6 +163,7 @@ import org.mozilla.gecko.util.HardwareUtils;
|
|||
import org.mozilla.gecko.util.IntentUtils;
|
||||
import org.mozilla.gecko.util.MenuUtils;
|
||||
import org.mozilla.gecko.util.PrefUtils;
|
||||
import org.mozilla.gecko.util.ShortcutUtils;
|
||||
import org.mozilla.gecko.util.StringUtils;
|
||||
import org.mozilla.gecko.util.ThreadUtils;
|
||||
import org.mozilla.gecko.util.WindowUtil;
|
||||
|
@ -3649,7 +3650,8 @@ public class BrowserApp extends GeckoApp
|
|||
MenuUtils.safeSetEnabled(aMenu, R.id.page, !isAboutHome(tab));
|
||||
MenuUtils.safeSetEnabled(aMenu, R.id.subscribe, tab.hasFeeds());
|
||||
MenuUtils.safeSetEnabled(aMenu, R.id.add_search_engine, tab.hasOpenSearch());
|
||||
MenuUtils.safeSetEnabled(aMenu, R.id.add_to_launcher, !isAboutHome(tab));
|
||||
MenuUtils.safeSetEnabled(aMenu, R.id.add_to_launcher,
|
||||
!isAboutHome(tab) && ShortcutUtils.isPinShortcutSupported());
|
||||
MenuUtils.safeSetEnabled(aMenu, R.id.set_as_homepage, !isAboutHome(tab));
|
||||
onPrepareOptionsMenuPinToTopSites(aMenu, tab);
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.mozilla.gecko.reader.ReadingListHelper;
|
|||
import org.mozilla.gecko.toolbar.BrowserToolbar.TabEditingState;
|
||||
import org.mozilla.gecko.toolbar.PageActionLayout;
|
||||
import org.mozilla.gecko.util.GeckoBundle;
|
||||
import org.mozilla.gecko.util.ShortcutUtils;
|
||||
import org.mozilla.gecko.util.ThreadUtils;
|
||||
import org.mozilla.gecko.webapps.WebAppManifest;
|
||||
import org.mozilla.gecko.widget.SiteLogins;
|
||||
|
@ -480,6 +481,10 @@ public class Tab {
|
|||
}
|
||||
|
||||
public void updatePageAction() {
|
||||
if (!ShortcutUtils.isPinShortcutSupported()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mManifestUrl != null) {
|
||||
showPwaPageAction();
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.mozilla.gecko.prompts.Prompt;
|
|||
import org.mozilla.gecko.prompts.PromptListItem;
|
||||
import org.mozilla.gecko.util.DrawableUtil;
|
||||
import org.mozilla.gecko.util.GeckoBundle;
|
||||
import org.mozilla.gecko.util.ShortcutUtils;
|
||||
import org.mozilla.gecko.util.ThreadUtils;
|
||||
|
||||
/**
|
||||
|
@ -192,9 +193,15 @@ public class BookmarkStateChangeDelegate extends BrowserAppDelegateWithReference
|
|||
}
|
||||
});
|
||||
|
||||
final PromptListItem[] items = new PromptListItem[2];
|
||||
items[0] = new PromptListItem(res.getString(R.string.contextmenu_edit_bookmark));
|
||||
items[1] = new PromptListItem(res.getString(R.string.contextmenu_add_page_shortcut));
|
||||
final PromptListItem[] items;
|
||||
if (ShortcutUtils.isPinShortcutSupported()) {
|
||||
items = new PromptListItem[2];
|
||||
items[0] = new PromptListItem(res.getString(R.string.contextmenu_edit_bookmark));
|
||||
items[1] = new PromptListItem(res.getString(R.string.contextmenu_add_page_shortcut));
|
||||
} else {
|
||||
items = new PromptListItem[1];
|
||||
items[0] = new PromptListItem(res.getString(R.string.contextmenu_edit_bookmark));
|
||||
}
|
||||
|
||||
ps.show("", "", items, ListView.CHOICE_MODE_NONE);
|
||||
}
|
||||
|
|
|
@ -11,11 +11,12 @@ import org.mozilla.gecko.R;
|
|||
import org.mozilla.gecko.Tab;
|
||||
import org.mozilla.gecko.Tabs;
|
||||
import org.mozilla.gecko.preferences.GeckoPreferences;
|
||||
import org.mozilla.gecko.util.DrawableUtil;
|
||||
import org.mozilla.gecko.util.ResourceDrawableUtils;
|
||||
import org.mozilla.gecko.util.BundleEventListener;
|
||||
import org.mozilla.gecko.util.DrawableUtil;
|
||||
import org.mozilla.gecko.util.EventCallback;
|
||||
import org.mozilla.gecko.util.GeckoBundle;
|
||||
import org.mozilla.gecko.util.ResourceDrawableUtils;
|
||||
import org.mozilla.gecko.util.ShortcutUtils;
|
||||
import org.mozilla.gecko.util.ThreadUtils;
|
||||
import org.mozilla.gecko.widget.GeckoPopupMenu;
|
||||
import org.mozilla.gecko.widget.themed.ThemedImageButton;
|
||||
|
@ -169,7 +170,7 @@ public class PageActionLayout extends ThemedLinearLayout implements BundleEventL
|
|||
if (UUID_PAGE_ACTION_PWA.equals(id)) {
|
||||
final SharedPreferences prefs = GeckoSharedPrefs.forApp(getContext());
|
||||
final boolean show = prefs.getBoolean(PREF_PWA_ONBOARDING, true);
|
||||
if (show) {
|
||||
if (show && ShortcutUtils.isPinShortcutSupported()) {
|
||||
PwaOnboarding.show(getContext());
|
||||
prefs.edit().putBoolean(PREF_PWA_ONBOARDING, false).apply();
|
||||
}
|
||||
|
|
|
@ -114,6 +114,29 @@ public class ShortcutUtils {
|
|||
// mgr.requestPinShortcut(info, null);
|
||||
}
|
||||
|
||||
public static boolean isPinShortcutSupported() {
|
||||
if (Versions.feature26Plus) {
|
||||
return isPinShortcutSupported26();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@TargetApi(26)
|
||||
private static boolean isPinShortcutSupported26() {
|
||||
final Context context = GeckoAppShell.getApplicationContext();
|
||||
try {
|
||||
final Class<?> mgrCls = Class.forName("android.content.pm.ShortcutManager");
|
||||
final Object mgr = context.getSystemService(mgrCls);
|
||||
|
||||
final boolean supported = (boolean)
|
||||
mgrCls.getDeclaredMethod("isRequestPinShortcutSupported")
|
||||
.invoke(mgr);
|
||||
return supported;
|
||||
} catch (final Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static Bitmap getLauncherIcon(Bitmap aSource, int size) {
|
||||
final float[] DEFAULT_LAUNCHER_ICON_HSV = { 32.0f, 1.0f, 1.0f };
|
||||
final int kOffset = 6;
|
||||
|
|
Загрузка…
Ссылка в новой задаче