当前位置: 首页>>代码示例>>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;未经允许,请勿转载。