removeAllDynamicShortcuts()源码实例Demo

android.content.pm.ShortcutManager#removeAllDynamicShortcuts()源码实例Demo

下面列出了android.content.pm.ShortcutManager#removeAllDynamicShortcuts() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: rcloneExplorer   文件: AppShortcutsHelper.java
public static void removeAllAppShortcuts(Context context) {
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.N_MR1) {
        return;
    }

    ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
    if (shortcutManager == null) {
        return;
    }

    shortcutManager.removeAllDynamicShortcuts();

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.remove(context.getString(R.string.shared_preferences_app_shortcuts));
    editor.apply();
}
 
private void setShortcuts() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) return;

    PriorityQueue<Class<? extends Fragment>> queue = new PriorityQueue<>(
            (o1, o2) -> {
                int opened1 = AppSettings.getFragmentOpened(o1, this);
                int opened2 = AppSettings.getFragmentOpened(o2, this);
                return opened2 - opened1;
            });

    for (Map.Entry<Integer, Class<? extends Fragment>> entry : mActualFragments.entrySet()) {
        Class<? extends Fragment> fragmentClass = entry.getValue();
        if (fragmentClass == null || fragmentClass == SettingsFragment.class) continue;

        queue.offer(fragmentClass);
    }

    List<ShortcutInfo> shortcutInfos = new ArrayList<>();
    ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
    shortcutManager.removeAllDynamicShortcuts();
    for (int i = 0; i < 4; i++) {
        NavigationFragment fragment = findNavigationFragmentByClass(queue.poll());
        if (fragment == null || fragment.mFragmentClass == null) continue;
        Intent intent = new Intent(this, MainActivity.class);
        intent.setAction(Intent.ACTION_VIEW);
        intent.putExtra(INTENT_SECTION, fragment.mFragmentClass.getCanonicalName());
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);

        ShortcutInfo shortcut = new ShortcutInfo.Builder(this,
                fragment.mFragmentClass.getSimpleName())
                .setShortLabel(getString(fragment.mId))
                .setLongLabel(Utils.strFormat(getString(R.string.open), getString(fragment.mId)))
                .setIcon(Icon.createWithResource(this, fragment.mDrawable == 0 ?
                        R.drawable.ic_blank : fragment.mDrawable))
                .setIntent(intent)
                .build();
        shortcutInfos.add(shortcut);
    }
    shortcutManager.setDynamicShortcuts(shortcutInfos);
}
 
源代码3 项目: shortrain   文件: MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

    ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);

    shortcutManager.removeAllDynamicShortcuts();
    int newWallId = ShortcutsUtils.getNextRailNumber(shortcutManager);
    ShortcutInfo ballShortcut = ShortcutsUtils.createTrainShortcut(this);
    ShortcutInfo wallShortcut = ShortcutsUtils.createRailShortcut(this, newWallId);
    shortcutManager.setDynamicShortcuts(Arrays.asList(ballShortcut, wallShortcut));

    setContentView(R.layout.activity_main);

    rootView = findViewById(R.id.activity_main_root);

    viewPager = (ViewPager) findViewById(R.id.activity_main_view_pager);
    pagerAdapter = new TutorialViewPagerAdapter(getFragmentManager());
    viewPager.setAdapter(pagerAdapter);
    rootView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finishActivity();
        }
    });
}
 
源代码4 项目: KernelAdiutor   文件: NavigationActivity.java
private void setShortcuts() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) return;

    PriorityQueue<Class<? extends Fragment>> queue = new PriorityQueue<>(
            (o1, o2) -> {
                int opened1 = AppSettings.getFragmentOpened(o1, this);
                int opened2 = AppSettings.getFragmentOpened(o2, this);
                return opened2 - opened1;
            });

    for (Map.Entry<Integer, Class<? extends Fragment>> entry : mActualFragments.entrySet()) {
        Class<? extends Fragment> fragmentClass = entry.getValue();
        if (fragmentClass == null || fragmentClass == SettingsFragment.class) continue;

        queue.offer(fragmentClass);
    }

    List<ShortcutInfo> shortcutInfos = new ArrayList<>();
    ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
    shortcutManager.removeAllDynamicShortcuts();
    for (int i = 0; i < 4; i++) {
        NavigationFragment fragment = findNavigationFragmentByClass(queue.poll());
        if (fragment == null || fragment.mFragmentClass == null) continue;
        Intent intent = new Intent(this, MainActivity.class);
        intent.setAction(Intent.ACTION_VIEW);
        intent.putExtra(INTENT_SECTION, fragment.mFragmentClass.getCanonicalName());
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);

        ShortcutInfo shortcut = new ShortcutInfo.Builder(this,
                fragment.mFragmentClass.getSimpleName())
                .setShortLabel(getString(fragment.mId))
                .setLongLabel(Utils.strFormat(getString(R.string.open), getString(fragment.mId)))
                .setIcon(Icon.createWithResource(this, fragment.mDrawable == 0 ?
                        R.drawable.ic_blank : fragment.mDrawable))
                .setIntent(intent)
                .build();
        shortcutInfos.add(shortcut);
    }
    shortcutManager.setDynamicShortcuts(shortcutInfos);
}
 
源代码5 项目: android-wallet-app   文件: MainActivity.java
private void updateDynamicShortcuts() {
    ShortcutManager shortcutManager;

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N_MR1) {

        Intent intentGenerateQrCode = new Intent(this, MainActivity.class);
        intentGenerateQrCode.setFlags((Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK));
        intentGenerateQrCode.setAction(Constants.ACTION_GENERATE_QR_CODE);

        ShortcutInfo shortcutGenerateQrCode = new ShortcutInfo.Builder(this, SHORTCUT_ID_GENERATE_QR_CODE)
                .setShortLabel(getString(R.string.shortcut_generate_qr_code))
                .setLongLabel(getString(R.string.shortcut_generate_qr_code))
                .setIcon(Icon.createWithResource(this, R.drawable.ic_shortcut_qr))
                .setIntent(intentGenerateQrCode)
                .build();

        Intent intentTransferIotas = new Intent(this, MainActivity.class);
        intentTransferIotas.setFlags((Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK));
        intentTransferIotas.setAction(Constants.ACTION_SEND_TRANSFER);

        ShortcutInfo shortcutTransferIotas = new ShortcutInfo.Builder(this, SHORTCUT_ID_SEND_TRANSFER)
                .setShortLabel(getString(R.string.shortcut_send_transfer))
                .setLongLabel(getString(R.string.shortcut_send_transfer))
                .setIcon(Icon.createWithResource(this, R.drawable.ic_shortcut_transaction))
                .setIntent(intentTransferIotas)
                .build();

        shortcutManager = getSystemService(ShortcutManager.class);

        if (shortcutManager != null) {
            if (IOTA.seed != null) {
                shortcutManager.setDynamicShortcuts(Arrays.asList(shortcutGenerateQrCode, shortcutTransferIotas));
                shortcutManager.enableShortcuts(Arrays.asList(SHORTCUT_ID_GENERATE_QR_CODE, SHORTCUT_ID_SEND_TRANSFER));
            } else {
                // remove shortcuts if Iota.seed.isEmpty()
                shortcutManager.disableShortcuts(Arrays.asList(SHORTCUT_ID_GENERATE_QR_CODE, SHORTCUT_ID_SEND_TRANSFER));
                shortcutManager.removeAllDynamicShortcuts();
            }
        }
    }
}
 
源代码6 项目: journaldev   文件: MainActivity.java
private void removeShortcuts() {
    ShortcutManager manager = getSystemService(ShortcutManager.class);
    manager.removeAllDynamicShortcuts();

}
 
源代码7 项目: linphone-android   文件: ApiTwentyFivePlus.java
public static void removeChatShortcuts(Context context) {
    ShortcutManager shortcutManager =
            (ShortcutManager) context.getSystemService(Context.SHORTCUT_SERVICE);
    shortcutManager.removeAllDynamicShortcuts();
}