use of android.content.pm.ShortcutManager in project android_packages_apps_Settings by omnirom.
the class ShortcutsUpdateTask method doInBackground.
@Override
public Void doInBackground(Void... params) {
ShortcutManager sm = mContext.getSystemService(ShortcutManager.class);
PackageManager pm = mContext.getPackageManager();
List<ShortcutInfo> updates = new ArrayList<>();
for (ShortcutInfo info : sm.getPinnedShortcuts()) {
if (!info.getId().startsWith(SHORTCUT_ID_PREFIX)) {
continue;
}
ComponentName cn = ComponentName.unflattenFromString(info.getId().substring(SHORTCUT_ID_PREFIX.length()));
ResolveInfo ri = pm.resolveActivity(new Intent(SHORTCUT_PROBE).setComponent(cn), 0);
if (ri == null) {
continue;
}
updates.add(new ShortcutInfo.Builder(mContext, info.getId()).setShortLabel(ri.loadLabel(pm)).build());
}
if (!updates.isEmpty()) {
sm.updateShortcuts(updates);
}
return null;
}
use of android.content.pm.ShortcutManager in project Taskbar by farmerbb.
the class MainActivity method proceedWithAppLaunch.
@SuppressWarnings("ResultOfMethodCallIgnored")
private void proceedWithAppLaunch(Bundle savedInstanceState) {
try {
setContentView(R.layout.tb_main);
} catch (IllegalStateException e) {
setTheme(R.style.Theme_AppCompat_Light);
setContentView(R.layout.tb_main);
}
if (!U.isLibrary(this)) {
setSupportActionBar(findViewById(R.id.toolbar));
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE);
}
}
theSwitch = findViewById(R.id.the_switch);
helpButton = findViewById(R.id.help_button);
if (theSwitch != null) {
final SharedPreferences pref = U.getSharedPreferences(this);
theSwitch.setChecked(pref.getBoolean(PREF_TASKBAR_ACTIVE, false));
theSwitch.setOnCheckedChangeListener((compoundButton, b) -> {
if (b) {
if (U.canDrawOverlays(this)) {
boolean firstRun = pref.getBoolean(PREF_FIRST_RUN, true);
startTaskbarService();
if (firstRun)
U.showRecentAppsDialog(this);
} else {
U.showPermissionDialog(this);
compoundButton.setChecked(false);
}
} else
stopTaskbarService();
});
}
if (savedInstanceState == null) {
U.initPrefs(this);
File restoreInProgress = new File(getFilesDir(), "restore_in_progress");
File restoreSuccessful = new File(getFilesDir(), "restore_successful");
if (restoreInProgress.exists() || restoreSuccessful.exists()) {
if (restoreInProgress.exists()) {
U.showToastLong(this, R.string.tb_restore_failed);
restoreInProgress.delete();
}
if (restoreSuccessful.exists()) {
U.showToastLong(this, R.string.tb_restore_successful);
restoreSuccessful.delete();
}
navigateTo(new ManageAppDataFragment());
} else if (!getIntent().hasExtra("theme_change"))
navigateTo(new AboutFragment());
else
navigateTo(new AppearanceFragment());
} else
try {
Fragment oldFragment = getFragmentManager().findFragmentById(R.id.fragmentContainer);
navigateTo(oldFragment.getClass().newInstance());
} catch (IllegalAccessException | InstantiationException ignored) {
}
SharedPreferences pref = U.getSharedPreferences(this);
if (!getPackageName().equals(BuildConfig.BASE_APPLICATION_ID) && freeVersionInstalled()) {
if (!pref.getBoolean(PREF_DONT_SHOW_UNINSTALL_DIALOG, false)) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.tb_settings_imported_successfully).setMessage(R.string.tb_import_dialog_message).setPositiveButton(R.string.tb_action_uninstall, (dialog, which) -> {
pref.edit().putBoolean(PREF_UNINSTALL_DIALOG_SHOWN, true).apply();
try {
startActivity(new Intent(Intent.ACTION_DELETE, Uri.parse("package:" + BuildConfig.BASE_APPLICATION_ID)));
} catch (ActivityNotFoundException ignored) {
}
});
if (pref.getBoolean(PREF_UNINSTALL_DIALOG_SHOWN, false))
builder.setNegativeButton(R.string.tb_action_dont_show_again, (dialogInterface, i) -> pref.edit().putBoolean(PREF_DONT_SHOW_UNINSTALL_DIALOG, true).apply());
AlertDialog dialog = builder.create();
dialog.show();
dialog.setCancelable(false);
}
if (!pref.getBoolean(PREF_UNINSTALL_DIALOG_SHOWN, false)) {
if (theSwitch != null)
theSwitch.setChecked(false);
SharedPreferences.Editor editor = pref.edit();
String iconPack = pref.getString(PREF_ICON_PACK, BuildConfig.BASE_APPLICATION_ID);
if (iconPack.contains(BuildConfig.BASE_APPLICATION_ID)) {
editor.putString(PREF_ICON_PACK, getPackageName());
} else {
U.refreshPinnedIcons(this);
}
editor.putBoolean(PREF_FIRST_RUN, true);
editor.apply();
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1 && !U.isLibrary(this)) {
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
if (shortcutManager.getDynamicShortcuts().size() == 0) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClass(this, StartTaskbarActivity.class);
intent.putExtra(EXTRA_IS_LAUNCHING_SHORTCUT, true);
ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "start_taskbar").setShortLabel(getString(R.string.tb_start_taskbar)).setIcon(Icon.createWithResource(this, R.drawable.tb_shortcut_icon_start)).setIntent(intent).build();
if (U.enableFreeformModeShortcut(this)) {
Intent intent2 = new Intent(Intent.ACTION_MAIN);
intent2.setClass(this, ShortcutActivity.class);
intent2.putExtra(EXTRA_IS_LAUNCHING_SHORTCUT, true);
ShortcutInfo shortcut2 = new ShortcutInfo.Builder(this, "freeform_mode").setShortLabel(getString(R.string.tb_pref_header_freeform)).setIcon(Icon.createWithResource(this, R.drawable.tb_shortcut_icon_freeform)).setIntent(intent2).build();
shortcutManager.setDynamicShortcuts(Arrays.asList(shortcut, shortcut2));
} else
shortcutManager.setDynamicShortcuts(Collections.singletonList(shortcut));
}
}
if (pref.getInt("show_changelog", 0) < latestChangelogVersion && U.isConsumerBuild(this)) {
Snackbar snackbar = Snackbar.make(findViewById(R.id.main_activity_layout), R.string.tb_see_whats_new, Snackbar.LENGTH_INDEFINITE);
snackbar.setAction(R.string.tb_action_view, v -> {
pref.edit().putInt("show_changelog", latestChangelogVersion).apply();
Uri uri = Uri.parse("https://github.com/farmerbb/Taskbar/blob/" + BuildConfig.VERSION_CODE + "/CHANGELOG.md");
try {
DependencyUtils.openChromeCustomTab(this, uri);
} catch (ActivityNotFoundException | IllegalArgumentException ignored) {
}
});
snackbar.show();
}
}
use of android.content.pm.ShortcutManager in project Rocket by mozilla-tw.
the class ShortcutUtils method updateShortcut26.
// Add this to make lint happy
@TargetApi(26)
private static void updateShortcut26(@NonNull Context context, ShortcutInfoCompat shortcut) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
final ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
if (shortcutManager != null) {
final List<ShortcutInfo> list = new ArrayList<>();
list.add(shortcut.toShortcutInfo());
shortcutManager.updateShortcuts(list);
}
}
}
use of android.content.pm.ShortcutManager in project MiMangaNu by raulhaag.
the class Shortcuts method addShortCuts.
public static void addShortCuts(Manga m, Context ctx) {
if (m.getVault().isEmpty() && m.getImages() != null && !m.getImages().isEmpty()) {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
ShortcutManager sm = ctx.getSystemService(ShortcutManager.class);
List<ShortcutInfo> sl = sm.getDynamicShortcuts();
String icdir = prefs.getString("directorio", Environment.getExternalStorageDirectory().getAbsolutePath()) + "/MiMangaNu/";
icdir = icdir + "cache/";
Bitmap bm = decodeFile(new File(icdir + m.getImages().hashCode()));
Icon icon = null;
if (bm == null) {
icon = Icon.createWithResource(ctx, R.drawable.noimage);
} else {
icon = Icon.createWithBitmap(bm);
}
Intent i = new Intent(ctx, MainActivity.class);
i.putExtra("manga_id", m.getId());
i.setAction(Intent.ACTION_VIEW);
ShortcutInfo s = new ShortcutInfo.Builder(ctx, m.getTitle() + m.getServerId()).setShortLabel(m.getTitle()).setIcon(icon).setIntent(i).build();
if (!sl.contains(s)) {
sl.add(s);
sm.addDynamicShortcuts(Arrays.asList(s));
}
if (sl.size() > 4) {
sm.removeDynamicShortcuts(Arrays.asList(sl.get(0).getId()));
}
}
}
}
use of android.content.pm.ShortcutManager in project packages_apps_AicpExtras by AICP.
the class LauncherActivity method initShortcutManager.
private void initShortcutManager() {
final ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
if (Util.isPackageEnabled(Constants.AICP_OTA_PACKAGE, this.getPackageManager())) {
// Intent for launching AICP OTA
final Intent INTENT_OTA = new Intent().setComponent(new ComponentName(Constants.AICP_OTA_PACKAGE, Constants.AICP_OTA_ACTIVITY));
INTENT_OTA.setAction(Intent.ACTION_VIEW);
ShortcutInfo aicpotaShortcut = new ShortcutInfo.Builder(this, "aicpota").setShortLabel(getString(R.string.aicp_ota_title)).setLongLabel(getString(R.string.aicp_ota_title)).setIcon(Icon.createWithResource(this, R.drawable.ic_launcher_shortcut_ota)).setIntent(INTENT_OTA).setRank(0).build();
shortcutManager.setDynamicShortcuts(Arrays.asList(aicpotaShortcut));
} else {
ShortcutInfo downloadsShortcut = new ShortcutInfo.Builder(this, "downloads").setShortLabel(getString(R.string.aicp_downloads_title)).setLongLabel(getString(R.string.aicp_downloads_title)).setIcon(Icon.createWithResource(this, R.drawable.ic_launcher_shortcut_downloads)).setIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(Util.getDownloadLinkForDevice(this)))).setRank(0).build();
shortcutManager.setDynamicShortcuts(Arrays.asList(downloadsShortcut));
}
}
Aggregations