Search in sources :

Example 1 with ShortcutManager

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

the class ShortcutHelper method reportPostUsed.

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

Example 2 with ShortcutManager

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

the class ShortcutHelper method disablePostShortcut.

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

Example 3 with ShortcutManager

use of android.content.pm.ShortcutManager in project AndroidDevelop by 7449.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
        return;
    }
    List<ShortcutInfo> shortcutInfoList = new ArrayList<>();
    final ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
    ShortcutInfo blogShortcut = new ShortcutInfo.Builder(this, "blog").setShortLabel("my blog").setLongLabel("我的博客").setDisabledMessage("被删除了").setIcon(Icon.createWithResource(getApplicationContext(), R.mipmap.ic_launcher)).setIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("https://7449.github.io/"))).build();
    ShortcutInfo githubShortcut = new ShortcutInfo.Builder(this, "github").setShortLabel("my github").setLongLabel("我的github").setDisabledMessage("被删除了").setIcon(Icon.createWithResource(getApplicationContext(), R.mipmap.ic_launcher)).setIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/7449"))).build();
    Intent intent = new Intent(this, TestActivity.class);
    intent.setAction(Intent.ACTION_VIEW);
    ShortcutInfo newActivityShortcut = new ShortcutInfo.Builder(this, "Activity").setShortLabel("newActivity").setLongLabel("newActivity").setDisabledMessage("被删除了").setIcon(Icon.createWithResource(getApplicationContext(), R.mipmap.ic_launcher)).setIntent(intent).build();
    shortcutInfoList.add(blogShortcut);
    shortcutInfoList.add(githubShortcut);
    shortcutInfoList.add(newActivityShortcut);
    shortcutManager.setDynamicShortcuts(shortcutInfoList);
    findViewById(R.id.delete).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
                List<ShortcutInfo> dynamicShortcuts = shortcutManager.getDynamicShortcuts();
                for (int i = 0; i < dynamicShortcuts.size(); i++) {
                    ShortcutInfo shortcutInfo = dynamicShortcuts.get(i);
                    if (TextUtils.equals("github", shortcutInfo.getId())) {
                        //桌面的图标这个时候就变灰了
                        shortcutManager.disableShortcuts(Collections.singletonList(shortcutInfo.getId()));
                        shortcutManager.removeDynamicShortcuts(Collections.singletonList(shortcutInfo.getId()));
                    }
                }
            }
        }
    });
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) ShortcutManager(android.content.pm.ShortcutManager) ArrayList(java.util.ArrayList) Intent(android.content.Intent) ArrayList(java.util.ArrayList) List(java.util.List) View(android.view.View)

Example 4 with ShortcutManager

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

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 5 with ShortcutManager

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

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)

Aggregations

ShortcutManager (android.content.pm.ShortcutManager)52 ShortcutInfo (android.content.pm.ShortcutInfo)37 Intent (android.content.Intent)30 ArrayList (java.util.ArrayList)17 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)4 ActivityNotFoundException (android.content.ActivityNotFoundException)3 Uri (android.net.Uri)3 WorkerThread (android.support.annotation.WorkerThread)3 SuppressLint (android.annotation.SuppressLint)2 PackageManager (android.content.pm.PackageManager)2 ResolveInfo (android.content.pm.ResolveInfo)2 Cursor (android.database.Cursor)2 Bitmap (android.graphics.Bitmap)2 RequiresApi (android.support.annotation.RequiresApi)2 File (java.io.File)2