use of android.content.pm.ShortcutManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class SettingsInitialize method refreshExistingShortcuts.
// Refresh settings shortcuts to have correct intent flags
@VisibleForTesting
void refreshExistingShortcuts(Context context) {
final ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
final List<ShortcutInfo> pinnedShortcuts = shortcutManager.getPinnedShortcuts();
final List<ShortcutInfo> updates = new ArrayList<>();
for (ShortcutInfo info : pinnedShortcuts) {
if (info.isImmutable()) {
continue;
}
final Intent shortcutIntent = info.getIntent();
shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
final ShortcutInfo updatedInfo = new ShortcutInfo.Builder(context, info.getId()).setIntent(shortcutIntent).build();
updates.add(updatedInfo);
}
shortcutManager.updateShortcuts(updates);
}
use of android.content.pm.ShortcutManager in project K6nele by Kaljurand.
the class Utils method publishShortcuts.
/**
* Constructs and publishes the list of app shortcuts, one for each combo that is selected for the
* search panel. The intent behind the shortcut sets AUTO_START=true and sets RESULTS_REWRITES
* to the list of default rewrites (at creation time), and PROMPT to the list of rewrite names.
* All other settings (e.g. MAX_RESULTS) depend on the settings at execution time.
*/
@TargetApi(Build.VERSION_CODES.N_MR1)
public static void publishShortcuts(Context context, List<Combo> selectedCombos, Set<String> rewriteTables) {
ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
List<ShortcutInfo> shortcuts = new ArrayList<>();
int maxShortcutCountPerActivity = shortcutManager.getMaxShortcutCountPerActivity();
int counter = 0;
// TODO: rewriteTables should be a list (not a set that needs to be sorted)
String[] names = rewriteTables.toArray(new String[rewriteTables.size()]);
Arrays.sort(names);
String rewritesId = TextUtils.join(", ", names);
String rewritesIdSuffix = "";
if (!rewritesId.isEmpty()) {
rewritesIdSuffix = "; " + rewritesId;
}
for (Combo combo : selectedCombos) {
Intent intent = new Intent(context, SpeechActionActivity.class);
intent.setAction(RecognizerIntent.ACTION_WEB_SEARCH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, combo.getLocaleAsStr());
intent.putExtra(Extras.EXTRA_SERVICE_COMPONENT, combo.getServiceComponent().flattenToShortString());
if (names.length > 0) {
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, rewritesId);
}
intent.putExtra(Extras.EXTRA_RESULT_REWRITES, names);
intent.putExtra(Extras.EXTRA_AUTO_START, true);
// Launch the activity so that the existing Kõnele activities are not in the background stack.
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
shortcuts.add(new ShortcutInfo.Builder(context, combo.getId() + rewritesId).setIntent(intent).setShortLabel(combo.getShortLabel() + rewritesIdSuffix).setLongLabel(combo.getLongLabel() + rewritesIdSuffix).setIcon(Icon.createWithBitmap(drawableToBitmap(combo.getIcon(context)))).build());
counter++;
// We are only allowed a certain number (5) of shortcuts
if (counter >= maxShortcutCountPerActivity) {
break;
}
}
shortcutManager.setDynamicShortcuts(shortcuts);
}
use of android.content.pm.ShortcutManager in project android_packages_apps_Settings by omnirom.
the class SettingsInitialize method refreshExistingShortcuts.
// Refresh settings shortcuts to have correct intent flags
@VisibleForTesting
void refreshExistingShortcuts(Context context) {
final ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
final List<ShortcutInfo> pinnedShortcuts = shortcutManager.getPinnedShortcuts();
final List<ShortcutInfo> updates = new ArrayList<>();
for (ShortcutInfo info : pinnedShortcuts) {
if (info.isImmutable()) {
continue;
}
final Intent shortcutIntent = info.getIntent();
shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
final ShortcutInfo updatedInfo = new ShortcutInfo.Builder(context, info.getId()).setIntent(shortcutIntent).build();
updates.add(updatedInfo);
}
shortcutManager.updateShortcuts(updates);
}
use of android.content.pm.ShortcutManager in project android_packages_apps_Settings by omnirom.
the class CreateShortcutPreferenceController method updateRestoredShortcuts.
public static void updateRestoredShortcuts(Context context) {
ShortcutManager sm = context.getSystemService(ShortcutManager.class);
List<ShortcutInfo> updatedShortcuts = new ArrayList<>();
for (ShortcutInfo si : sm.getPinnedShortcuts()) {
if (si.getId().startsWith(SHORTCUT_ID_PREFIX)) {
ResolveInfo ri = context.getPackageManager().resolveActivity(si.getIntent(), 0);
if (ri != null) {
updatedShortcuts.add(createShortcutInfo(context, buildShortcutIntent(ri), ri, si.getShortLabel()));
}
}
}
if (!updatedShortcuts.isEmpty()) {
sm.updateShortcuts(updatedShortcuts);
}
}
use of android.content.pm.ShortcutManager in project plaid by nickbutcher.
the class ShortcutHelper method enablePostShortcut.
@TargetApi(Build.VERSION_CODES.N_MR1)
public static void enablePostShortcut(@NonNull Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1)
return;
ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
Intent intent = new Intent(context, PostNewDesignerNewsStory.class);
intent.setAction(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
ShortcutInfo postShortcut = new ShortcutInfo.Builder(context, POST_SHORTCUT_ID).setShortLabel(context.getString(R.string.shortcut_post_short_label)).setLongLabel(context.getString(R.string.shortcut_post_long_label)).setDisabledMessage(context.getString(R.string.shortcut_post_disabled)).setIcon(Icon.createWithResource(context, R.drawable.ic_shortcut_post)).setIntent(intent).build();
shortcutManager.addDynamicShortcuts(Collections.singletonList(postShortcut));
}
Aggregations