Search in sources :

Example 26 with ShortcutManager

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);
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) ShortcutManager(android.content.pm.ShortcutManager) ArrayList(java.util.ArrayList) Intent(android.content.Intent) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 27 with ShortcutManager

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);
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) ShortcutManager(android.content.pm.ShortcutManager) ArrayList(java.util.ArrayList) Combo(ee.ioc.phon.android.speak.model.Combo) Intent(android.content.Intent) RecognizerIntent(android.speech.RecognizerIntent) ExecutableString(ee.ioc.phon.android.speak.ExecutableString) SpannableString(android.text.SpannableString) TargetApi(android.annotation.TargetApi)

Example 28 with ShortcutManager

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);
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) ShortcutManager(android.content.pm.ShortcutManager) ArrayList(java.util.ArrayList) Intent(android.content.Intent) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 29 with ShortcutManager

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);
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ShortcutInfo(android.content.pm.ShortcutInfo) ShortcutManager(android.content.pm.ShortcutManager) ArrayList(java.util.ArrayList)

Example 30 with ShortcutManager

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));
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) ShortcutManager(android.content.pm.ShortcutManager) Intent(android.content.Intent) TargetApi(android.annotation.TargetApi)

Aggregations

ShortcutManager (android.content.pm.ShortcutManager)55 ShortcutInfo (android.content.pm.ShortcutInfo)39 Intent (android.content.Intent)31 ArrayList (java.util.ArrayList)19 TargetApi (android.annotation.TargetApi)15 PendingIntent (android.app.PendingIntent)7 Icon (android.graphics.drawable.Icon)7 ActivityInfo (android.content.pm.ActivityInfo)6 Bundle (android.os.Bundle)6 ComponentName (android.content.ComponentName)5 ResolveInfo (android.content.pm.ResolveInfo)4 PackageManager (android.content.pm.PackageManager)3 WorkerThread (android.support.annotation.WorkerThread)3 SuppressLint (android.annotation.SuppressLint)2 ActivityNotFoundException (android.content.ActivityNotFoundException)2 Cursor (android.database.Cursor)2 Bitmap (android.graphics.Bitmap)2 Uri (android.net.Uri)2 RequiresApi (android.support.annotation.RequiresApi)2 VisibleForTesting (androidx.annotation.VisibleForTesting)2