當前位置: 首頁>>代碼示例>>Java>>正文


Java ShortcutManager.getDynamicShortcuts方法代碼示例

本文整理匯總了Java中android.content.pm.ShortcutManager.getDynamicShortcuts方法的典型用法代碼示例。如果您正苦於以下問題:Java ShortcutManager.getDynamicShortcuts方法的具體用法?Java ShortcutManager.getDynamicShortcuts怎麽用?Java ShortcutManager.getDynamicShortcuts使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.content.pm.ShortcutManager的用法示例。


在下文中一共展示了ShortcutManager.getDynamicShortcuts方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createShortcut

import android.content.pm.ShortcutManager; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.N_MR1)
private void createShortcut(String label, String packageName, Bitmap icon, Intent intent) {
    ShortcutManager shortcutManager;
    shortcutManager = getSystemService(ShortcutManager.class);

    ShortcutInfo shortcut = new ShortcutInfo.Builder(this, packageName)
            .setShortLabel(label)
            .setLongLabel(label)
            .setIcon(Icon.createWithBitmap(icon))
            .setIntent(intent)
            .setRank(0)
            .build();

    List<ShortcutInfo> shortcutList = shortcutManager.getDynamicShortcuts();
    int shortcutSize = shortcutList.size();

    if (shortcutSize >= 5) {
        for (int i = 0; i < shortcutSize - 4; i++) {
            shortcutManager.removeDynamicShortcuts(Collections.singletonList(shortcutList.get(0).getId()));
        }
    }
    shortcutManager.addDynamicShortcuts(Collections.singletonList(shortcut));
}
 
開發者ID:frowhy,項目名稱:Wake,代碼行數:24,代碼來源:WakeActivity.java

示例2: removeShortcut

import android.content.pm.ShortcutManager; //導入方法依賴的package包/類
/**
 * Remove the given card id from the app shortcuts, if such a
 * shortcut exists.
 */
@TargetApi(25)
static void removeShortcut(Context context, int cardId)
{
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N_MR1)
    {
        ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
        List<ShortcutInfo> list = shortcutManager.getDynamicShortcuts();

        String shortcutId = Integer.toString(cardId);

        for(int index = 0; index < list.size(); index++)
        {
            if(list.get(index).getId().equals(shortcutId))
            {
                list.remove(index);
                break;
            }
        }

        shortcutManager.setDynamicShortcuts(list);
    }
}
 
開發者ID:brarcher,項目名稱:loyalty-card-locker,代碼行數:27,代碼來源:ShortcutHelper.java

示例3: addDynamicShortcut

import android.content.pm.ShortcutManager; //導入方法依賴的package包/類
private void addDynamicShortcut(Place place) {
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
            ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
            String name = HTTextUtils.isEmpty(place.getName()) ? place.getAddress() : place.getName();
            int count = 0;
            if (shortcutManager.getDynamicShortcuts() != null) {
                count = shortcutManager.getDynamicShortcuts().size();
            }
            if (count > 2) {
                String id = shortcutManager.getDynamicShortcuts().get(0).getId();
                List<String> shortcutIds = new ArrayList<>();
                shortcutIds.add(id);
                shortcutManager.removeDynamicShortcuts(shortcutIds);
            }

            List<ShortcutInfo> shortcut = new ArrayList<>();

            shortcut.add(0, new ShortcutInfo.Builder(this, place.getLocation().getLatLng().toString())
                    .setShortLabel(name)
                    .setIcon(Icon.createWithResource(this, R.drawable.ic_marker_gray))
                    .setIntent(new Intent(Intent.ACTION_VIEW,
                            Uri.parse("share.location://hypertrack")))
                    .build());
            shortcutManager.addDynamicShortcuts(shortcut);
        }
    } catch (Exception e) {
        Crashlytics.logException(e);
    }
}
 
開發者ID:hypertrack,項目名稱:hypertrack-live-android,代碼行數:31,代碼來源:Home.java

示例4: disableExistingShortcuts

import android.content.pm.ShortcutManager; //導入方法依賴的package包/類
private void disableExistingShortcuts() {
    ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
    List<String> shortcutIds = new ArrayList<>();
    for (ShortcutInfo shortcutInfo: shortcutManager.getDynamicShortcuts()) {
        shortcutIds.add(shortcutInfo.getId());
    }
    shortcutManager.disableShortcuts(shortcutIds);
}
 
開發者ID:nicholasrout,項目名稱:shortstories,代碼行數:9,代碼來源:ChoiceActivity.java

示例5: doCreateView

import android.content.pm.ShortcutManager; //導入方法依賴的package包/類
@Override
protected void doCreateView(View view) {
    setHasOptionsMenu(true);
    mAppListActivity = ((AppListActivity) getActivity());
    new AppsPresenter(mAppListActivity, this);
    RecyclerView mRecyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
    mRecyclerView.setHasFixedSize(true);
    LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
    mRecyclerView.setLayoutManager(layoutManager);
    mRecyclerView.addItemDecoration(new DividerItemDecoration(mAppListActivity, layoutManager.getOrientation()));

    mAppInfoDBController = new AppInfoDBController(mAppListActivity);
    Set<String> appPackageSet = new HashSet<>();
    if (mAppListActivity.getIntent().getBooleanExtra(EXTRA_MANUAL_SHORTCUT, false)) {
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
            ShortcutManager manager = mAppListActivity.getSystemService(ShortcutManager.class);
            for (ShortcutInfo shortcutInfo : manager.getDynamicShortcuts()) {
                appPackageSet.add(shortcutInfo.getId());
            }
        }
    } else {
        List<AppInfo> appInfoSet = mAppInfoDBController.getDisableApps(AppInfoDBOpenHelper.TABLE_NAME_APP_INFO);
        for (AppInfo appInfo : appInfoSet) {
            appPackageSet.add(appInfo.getAppPackageName());
        }
    }
    mAppListAdapter = new AppListAdapter(mAppListActivity, mRecyclerView, appPackageSet);
    mRecyclerView.setAdapter(mAppListAdapter);

    int tabCategory = getArguments().getInt(TAB_CATEGORY);
    mPresenter.getApps(tabCategory == 0 ? AppsRepository.APPS_FLAG_USER : AppsRepository.APPS_FLAG_SYSTEM);
    initListener();
}
 
開發者ID:XYScience,項目名稱:StopApp,代碼行數:34,代碼來源:AppListFragment.java

示例6: getChannelIdsOfShortcuts

import android.content.pm.ShortcutManager; //導入方法依賴的package包/類
@TargetApi(25)
public static List<String> getChannelIdsOfShortcuts(Context context) {
	ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
	if (shortcutManager == null) {
		return Collections.emptyList();
	}

	List<ShortcutInfo> shortcuts = shortcutManager.getDynamicShortcuts();
	List<String> ids = new ArrayList<>(shortcuts.size());
	for (ShortcutInfo shortcut : shortcuts) {
		ids.add(shortcut.getId());
	}
	return ids;
}
 
開發者ID:cemrich,項目名稱:zapp,代碼行數:15,代碼來源:ShortcutHelper.java

示例7: updateShortcuts

import android.content.pm.ShortcutManager; //導入方法依賴的package包/類
static void updateShortcuts(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
        ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);

        List<ShortcutInfo> existingShortcuts = shortcutManager.getDynamicShortcuts();

        // create and set dynamic shortcuts
        ShortcutInfo debugShortcut = createShortcut(context,
                AppShortcutActivity.EXTRA_TOGGLE_DEBUG_AWAKE,
                PrefUtils.isAwakeDebugEnabled(context),
                DEBUG_SHORTCUT_ID,
                context.getString(R.string.awake_debug_toggle_short),
                context.getString(R.string.awake_debug_toggle_long),
                1);

        ShortcutInfo acShortcut = createShortcut(context,
                AppShortcutActivity.EXTRA_TOGGLE_AC_AWAKE,
                PrefUtils.isAwakeAcEnabled(context),
                AC_POWER_SHORTCUT_ID,
                context.getString(R.string.awake_ac_toggle_short),
                context.getString(R.string.awake_ac_toggle_long),
                0);

        List<ShortcutInfo> shortcuts = Arrays.asList(debugShortcut, acShortcut);

        if (existingShortcuts.isEmpty()) {
            shortcutManager.setDynamicShortcuts(shortcuts);
        } else {
            shortcutManager.updateShortcuts(shortcuts);
        }
    }
}
 
開發者ID:AfzalivE,項目名稱:AwakeDebug,代碼行數:33,代碼來源:ShortcutUtils.java


注:本文中的android.content.pm.ShortcutManager.getDynamicShortcuts方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。