Java Code Examples for android.content.pm.ShortcutManager#removeAllDynamicShortcuts()

The following examples show how to use android.content.pm.ShortcutManager#removeAllDynamicShortcuts() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AppShortcutsHelper.java    From rcloneExplorer with MIT License 6 votes vote down vote up
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();
}
 
Example 2
Source File: NavigationActivity.java    From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example 3
Source File: MainActivity.java    From shortrain with MIT License 5 votes vote down vote up
@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();
        }
    });
}
 
Example 4
Source File: NavigationActivity.java    From KernelAdiutor with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example 5
Source File: MainActivity.java    From android-wallet-app with GNU General Public License v3.0 4 votes vote down vote up
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();
            }
        }
    }
}
 
Example 6
Source File: MainActivity.java    From journaldev with MIT License 4 votes vote down vote up
private void removeShortcuts() {
    ShortcutManager manager = getSystemService(ShortcutManager.class);
    manager.removeAllDynamicShortcuts();

}
 
Example 7
Source File: ApiTwentyFivePlus.java    From linphone-android with GNU General Public License v3.0 4 votes vote down vote up
public static void removeChatShortcuts(Context context) {
    ShortcutManager shortcutManager =
            (ShortcutManager) context.getSystemService(Context.SHORTCUT_SERVICE);
    shortcutManager.removeAllDynamicShortcuts();
}