Search in sources :

Example 31 with ShortcutManager

use of android.content.pm.ShortcutManager in project plaid by nickbutcher.

the class ShortcutHelper method reportSearchUsed.

@TargetApi(Build.VERSION_CODES.N_MR1)
public static void reportSearchUsed(@NonNull Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1)
        return;
    ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
    shortcutManager.reportShortcutUsed(SEARCH_SHORTCUT_ID);
}
Also used : ShortcutManager(android.content.pm.ShortcutManager) TargetApi(android.annotation.TargetApi)

Example 32 with ShortcutManager

use of android.content.pm.ShortcutManager in project platform_frameworks_base by android.

the class RemoteInputView method sendRemoteInput.

private void sendRemoteInput() {
    Bundle results = new Bundle();
    results.putString(mRemoteInput.getResultKey(), mEditText.getText().toString());
    Intent fillInIntent = new Intent().addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    RemoteInput.addResultsToIntent(mRemoteInputs, fillInIntent, results);
    mEditText.setEnabled(false);
    mSendButton.setVisibility(INVISIBLE);
    mProgressBar.setVisibility(VISIBLE);
    mEntry.remoteInputText = mEditText.getText();
    mController.addSpinning(mEntry.key, mToken);
    mController.removeRemoteInput(mEntry, mToken);
    mEditText.mShowImeOnInputConnection = false;
    mController.remoteInputSent(mEntry);
    // Tell ShortcutManager that this package has been "activated".  ShortcutManager
    // will reset the throttling for this package.
    // Strictly speaking, the intent receiver may be different from the notification publisher,
    // but that's an edge case, and also because we can't always know which package will receive
    // an intent, so we just reset for the publisher.
    getContext().getSystemService(ShortcutManager.class).onApplicationActive(mEntry.notification.getPackageName(), mEntry.notification.getUser().getIdentifier());
    MetricsLogger.action(mContext, MetricsProto.MetricsEvent.ACTION_REMOTE_INPUT_SEND, mEntry.notification.getPackageName());
    try {
        mPendingIntent.send(mContext, 0, fillInIntent);
    } catch (PendingIntent.CanceledException e) {
        Log.i(TAG, "Unable to send remote input result", e);
        MetricsLogger.action(mContext, MetricsProto.MetricsEvent.ACTION_REMOTE_INPUT_FAIL, mEntry.notification.getPackageName());
    }
}
Also used : Bundle(android.os.Bundle) ShortcutManager(android.content.pm.ShortcutManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 33 with ShortcutManager

use of android.content.pm.ShortcutManager in project android_frameworks_base by ResurrectionRemix.

the class RemoteInputView method sendRemoteInput.

private void sendRemoteInput() {
    Bundle results = new Bundle();
    results.putString(mRemoteInput.getResultKey(), mEditText.getText().toString());
    Intent fillInIntent = new Intent().addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    RemoteInput.addResultsToIntent(mRemoteInputs, fillInIntent, results);
    mEditText.setEnabled(false);
    mSendButton.setVisibility(INVISIBLE);
    mProgressBar.setVisibility(VISIBLE);
    mEntry.remoteInputText = mEditText.getText();
    mController.addSpinning(mEntry.key, mToken);
    mController.removeRemoteInput(mEntry, mToken);
    mEditText.mShowImeOnInputConnection = false;
    mController.remoteInputSent(mEntry);
    // Tell ShortcutManager that this package has been "activated".  ShortcutManager
    // will reset the throttling for this package.
    // Strictly speaking, the intent receiver may be different from the notification publisher,
    // but that's an edge case, and also because we can't always know which package will receive
    // an intent, so we just reset for the publisher.
    getContext().getSystemService(ShortcutManager.class).onApplicationActive(mEntry.notification.getPackageName(), mEntry.notification.getUser().getIdentifier());
    MetricsLogger.action(mContext, MetricsProto.MetricsEvent.ACTION_REMOTE_INPUT_SEND, mEntry.notification.getPackageName());
    try {
        mPendingIntent.send(mContext, 0, fillInIntent);
    } catch (PendingIntent.CanceledException e) {
        Log.i(TAG, "Unable to send remote input result", e);
        MetricsLogger.action(mContext, MetricsProto.MetricsEvent.ACTION_REMOTE_INPUT_FAIL, mEntry.notification.getPackageName());
    }
}
Also used : Bundle(android.os.Bundle) ShortcutManager(android.content.pm.ShortcutManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 34 with ShortcutManager

use of android.content.pm.ShortcutManager in project android_packages_apps_Settings by LineageOS.

the class CreateShortcut method createResultIntent.

protected Intent createResultIntent(Intent shortcutIntent, ResolveInfo resolveInfo, CharSequence label) {
    shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    ShortcutManager sm = getSystemService(ShortcutManager.class);
    ActivityInfo activityInfo = resolveInfo.activityInfo;
    Icon maskableIcon = activityInfo.icon != 0 ? Icon.createWithAdaptiveBitmap(createIcon(activityInfo.icon, R.layout.shortcut_badge_maskable, getResources().getDimensionPixelSize(R.dimen.shortcut_size_maskable))) : Icon.createWithResource(this, R.mipmap.ic_launcher);
    String shortcutId = SHORTCUT_ID_PREFIX + shortcutIntent.getComponent().flattenToShortString();
    ShortcutInfo info = new ShortcutInfo.Builder(this, shortcutId).setShortLabel(label).setIntent(shortcutIntent).setIcon(maskableIcon).build();
    Intent intent = sm.createShortcutResultIntent(info);
    if (intent == null) {
        intent = new Intent();
    }
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher));
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, label);
    if (activityInfo.icon != 0) {
        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, createIcon(activityInfo.icon, R.layout.shortcut_badge, getResources().getDimensionPixelSize(R.dimen.shortcut_size)));
    }
    return intent;
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) ShortcutInfo(android.content.pm.ShortcutInfo) ShortcutManager(android.content.pm.ShortcutManager) Intent(android.content.Intent) Icon(android.graphics.drawable.Icon)

Example 35 with ShortcutManager

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

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