本文整理汇总了Java中android.content.pm.ShortcutManager.setDynamicShortcuts方法的典型用法代码示例。如果您正苦于以下问题:Java ShortcutManager.setDynamicShortcuts方法的具体用法?Java ShortcutManager.setDynamicShortcuts怎么用?Java ShortcutManager.setDynamicShortcuts使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.pm.ShortcutManager
的用法示例。
在下文中一共展示了ShortcutManager.setDynamicShortcuts方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateDynamicShortcuts
import android.content.pm.ShortcutManager; //导入方法依赖的package包/类
/**
* Update the dynamic shortcuts that are associated with this app. The given list of cards must
* be sorted by popularity. The amount parameter indicates how much shortcuts should be made.
*
* @param cards A list of cards that's sorted by popularity.
* @param amount Amount indicates the number n of cards for which a shortcut should be made from
* the list.
*/
public void updateDynamicShortcuts(List<Card> cards, int amount) {
if (cards.size() < amount) {
amount = cards.size();
}
this.cards = cards;
List<ShortcutInfo> shortcuts = new ArrayList<>();
ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
for (int i = 0; i < amount; i++) {
ShortcutInfo shortcut = new ShortcutInfo.Builder(context, cards.get(i).getName() + "-shortcut")
.setShortLabel(cards.get(i).getName())
.setIcon(Icon.createWithResource(context, R.drawable.shortcut_store))
.setIntent(createCardShortcutIntent(cards.get(i)))
.build();
shortcuts.add(shortcut);
}
shortcutManager.setDynamicShortcuts(shortcuts);
}
示例2: createShortcut
import android.content.pm.ShortcutManager; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.N_MR1)
private void createShortcut() {
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
Intent intent = new Intent(this, SplashActivity.class);
intent.setAction(ACTION_QUICK_START_OR_QUICK_STOP);
intent.putExtra(EXTRA_COME_FROM_SHORTCUT, true);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "shortcut_quick_switch")
.setShortLabel(getString(R.string.shortcut_quick_switch))
.setIcon(Icon.createWithResource(this, R.mipmap.ic_launcher))
.setIntent(intent)
.build();
if (shortcutManager != null) {
shortcutManager.setDynamicShortcuts(Collections.singletonList(shortcut));
}
}
示例3: addChoiceShortcuts
import android.content.pm.ShortcutManager; //导入方法依赖的package包/类
private void addChoiceShortcuts() {
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
if (mChoice.isFinish()) {
shortcutManager.removeAllDynamicShortcuts();
return;
}
if (mChoice.choices == null || mChoice.choices.size() == 0) {
return;
}
List<ShortcutInfo> choiceShortcuts = new ArrayList<>();
int rank = 1;
for (Choice choice : mChoice.choices) {
ShortcutInfo choiceShortcut = new ShortcutInfo.Builder(this, IdUtil.getRandomUniqueShortcutId())
.setShortLabel(choice.action)
.setLongLabel(choice.action)
.setDisabledMessage(getString(R.string.shortcut_disabled_message))
.setIcon(Icon.createWithBitmap(choice.getActionEmoji(this)))
.setIntent(IntentUtil.choice(this, choice))
.setRank(rank)
.build();
choiceShortcuts.add(choiceShortcut);
rank++;
}
shortcutManager.setDynamicShortcuts(choiceShortcuts);
}
示例4: create
import android.content.pm.ShortcutManager; //导入方法依赖的package包/类
/**
* Shortucts features on android N
* @param context
*/
public static void create(Context context) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N_MR1) {
ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
Icon pause = Icon.createWithResource(context, R.drawable.ic_shortcut_aw_ic_pause);
ShortcutInfo pauses = new ShortcutInfo.Builder(context, Constants.PAUSE_SHORTCUTS)
.setShortLabel("Pause")
.setIcon(pause)
.setIntent(shortcut(context,2))
.build();
Icon play = Icon.createWithResource(context, R.drawable.ic_shortcut_aw_ic_play);
ShortcutInfo plays = new ShortcutInfo.Builder(context, Constants.PLAY_SHORTCUTS)
.setShortLabel("Play")
.setIcon(play)
.setIntent(shortcut(context, 1))
.build();
ArrayList<ShortcutInfo> shortcuts = new ArrayList<>();
shortcuts.add(plays);
shortcuts.add(pauses);
shortcutManager.setDynamicShortcuts(shortcuts);
}
}
示例5: updateShortcuts
import android.content.pm.ShortcutManager; //导入方法依赖的package包/类
@TargetApi(25)
public static void updateShortcuts(Activity parentActivity, ShortcutManager shortcutManager, int sizeOfForumFavArray) {
ArrayList<ShortcutInfo> listOfShortcuts = new ArrayList<>();
int sizeOfShortcutArray = (sizeOfForumFavArray > 4 ? 4 : sizeOfForumFavArray);
for (int i = 0; i < sizeOfShortcutArray; ++i) {
String currentShortcutLink = PrefsManager.getStringWithSufix(PrefsManager.StringPref.Names.FORUM_FAV_LINK, String.valueOf(i));
String currentShortcutName = PrefsManager.getStringWithSufix(PrefsManager.StringPref.Names.FORUM_FAV_NAME, String.valueOf(i));
ShortcutInfo newShortcut = new ShortcutInfo.Builder(parentActivity, String.valueOf(i) + "_" + currentShortcutLink)
.setShortLabel(currentShortcutName)
.setLongLabel(currentShortcutName)
.setIcon(Icon.createWithResource(parentActivity, R.mipmap.ic_shortcut_forum))
.setIntent(new Intent(MainActivity.ACTION_OPEN_LINK, Uri.parse(currentShortcutLink))).build();
listOfShortcuts.add(newShortcut);
}
try {
shortcutManager.setDynamicShortcuts(listOfShortcuts);
} catch (Exception e) {
/* À ce qu'il parait ça peut crash "when the user is locked", je sais pas ce que ça
* veut dire donc dans le doute je mets ça là. */
}
}
示例6: updataShortcuts
import android.content.pm.ShortcutManager; //导入方法依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
private static void updataShortcuts(Context context, List<AppInfo> items) {
ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
List<ShortcutInfo> shortcutInfoList = new ArrayList<>();
int max = shortcutManager.getMaxShortcutCountPerActivity();
for (int i = 0; i < max && i < items.size(); i++) {
AppInfo appInfo = items.get(i);
ShortcutInfo.Builder shortcut = new ShortcutInfo.Builder(context, appInfo.packageName);
shortcut.setShortLabel(appInfo.appName);
shortcut.setLongLabel(appInfo.appName);
shortcut.setIcon(
Icon.createWithBitmap(drawableToBitmap(LocalImageLoader.getDrawable(context, appInfo))));
Intent intent = new Intent(context, AppPermissionActivity.class);
intent.putExtra(AppPermissionActivity.EXTRA_APP_PKGNAME, appInfo.packageName);
intent.putExtra(AppPermissionActivity.EXTRA_APP_NAME, appInfo.appName);
intent.setAction(Intent.ACTION_DEFAULT);
shortcut.setIntent(intent);
shortcutInfoList.add(shortcut.build());
}
shortcutManager.setDynamicShortcuts(shortcutInfoList);
}
示例7: 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);
}
}
示例8: setShortcut
import android.content.pm.ShortcutManager; //导入方法依赖的package包/类
@Override
public void setShortcut(String did, String manufacturer, String deviceName) {
//Home screen shortcut for favourite device
if (Build.VERSION.SDK_INT < 25)
return;
ShortcutManager sM = getSystemService(ShortcutManager.class);
sM.removeAllDynamicShortcuts();
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.setAction(Intent.ACTION_VIEW);
intent.putExtra(Constants.EXTRA_DEVICE_ID, did);
ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "shortcut1")
.setIntent(intent)
.setLongLabel(manufacturer + " " + deviceName)
.setShortLabel(deviceName)
.setIcon(Icon.createWithResource(this, R.drawable.ic_device_placeholder))
.build();
sM.setDynamicShortcuts(Collections.singletonList(shortcut));
}
示例9: addSearchShortcut
import android.content.pm.ShortcutManager; //导入方法依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
public static void addSearchShortcut(Context context, String searchWithPartyTitle) {
ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
Intent openSearch = new Intent(context.getApplicationContext(), SearchActivity.class);
openSearch.putExtra(ApplicationConstants.PARTY_NAME_EXTRA, searchWithPartyTitle);
openSearch.setAction(Intent.ACTION_VIEW);
ShortcutInfo shortcut = new ShortcutInfo.Builder(context, ApplicationConstants.SEARCH_SHORTCUT_ID)
.setShortLabel("Search songs")
.setLongLabel("Search for songs to add to the queue")
.setIcon(Icon.createWithResource(context, R.drawable.ic_shortcut_search))
.setIntent(openSearch)
.build();
shortcutManager.setDynamicShortcuts(Arrays.asList(shortcut));
}
示例10: setLauncherShortcuts
import android.content.pm.ShortcutManager; //导入方法依赖的package包/类
private void setLauncherShortcuts() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
if(shortcutManager.getDynamicShortcuts().size() == 0) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName(BuildConfig.APPLICATION_ID, TaskerQuickActionsActivity.class.getName());
intent.putExtra("launched-from-app", true);
ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "quick_actions")
.setShortLabel(getString(R.string.label_quick_actions))
.setIcon(Icon.createWithResource(this, R.drawable.shortcut_icon))
.setIntent(intent)
.build();
shortcutManager.setDynamicShortcuts(Collections.singletonList(shortcut));
}
}
}
示例11: enableShortcuts
import android.content.pm.ShortcutManager; //导入方法依赖的package包/类
private void enableShortcuts() {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
ShortcutManager manager = getSystemService(ShortcutManager.class);
ShortcutInfo addPkg = new ShortcutInfo.Builder(this, "shortcut_add_package")
.setLongLabel(getString(R.string.shortcut_label_add_package))
.setShortLabel(getString(R.string.shortcut_label_add_package))
.setIcon(Icon.createWithResource(this, R.drawable.ic_shortcut_add))
.setIntent(
new Intent(OnboardingActivity.this, AddPackageActivity.class)
.setAction(Intent.ACTION_VIEW)
.addCategory(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION)
)
.build();
ShortcutInfo scanCode = new ShortcutInfo.Builder(this, "shortcut_scan_code")
.setIcon(Icon.createWithResource(this, R.drawable.ic_shortcut_filter_center_focus))
.setLongLabel(getString(R.string.shortcut_label_scan_code))
.setShortLabel(getString(R.string.shortcut_label_scan_code))
.setIntent(
new Intent(OnboardingActivity.this, AddPackageActivity.class)
.setAction("io.github.marktony.espresso.mvp.addpackage.AddPackageActivity")
.addCategory(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION)
)
.build();
ShortcutInfo search = new ShortcutInfo.Builder(this, "shortcut_search")
.setIcon(Icon.createWithResource(this, R.drawable.ic_shortcut_search))
.setLongLabel(getString(R.string.shortcut_label_search))
.setShortLabel(getString(R.string.shortcut_label_search))
.setIntent(
new Intent(OnboardingActivity.this, SearchActivity.class)
.setAction(Intent.ACTION_VIEW)
.addCategory(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION)
)
.build();
manager.setDynamicShortcuts(Arrays.asList(addPkg, scanCode, search));
}
}
示例12: saveBookmarks
import android.content.pm.ShortcutManager; //导入方法依赖的package包/类
private void saveBookmarks() {
SharedPreferences.Editor editor = prefs.edit();
for (int i = 0; i < bookmarks.size(); i++) {
editor.putInt(PREF_BOOKMARK + i, bookmarks.get(i));
}
editor.putInt(PREF_BOOKMARKS_LENGTH, bookmarks.size());
editor.apply();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
Collections.sort(bookmarks);
ShortcutManager manager = (ShortcutManager) getSystemService(Context.SHORTCUT_SERVICE);
if (manager != null) {
List<ShortcutInfo> shortcuts = new ArrayList<>();
for (int bpm : bookmarks) {
shortcuts.add(
new ShortcutInfo.Builder(this, String.valueOf(bpm))
.setShortLabel(getString(R.string.bpm, String.valueOf(bpm)))
.setIcon(Icon.createWithResource(this, R.drawable.ic_note))
.setIntent(getBookmarkIntent(bpm))
.build()
);
}
manager.setDynamicShortcuts(shortcuts);
}
}
updateBookmarks(true);
}
示例13: onCreate
import android.content.pm.ShortcutManager; //导入方法依赖的package包/类
@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();
}
});
}
示例14: onLoadFinished
import android.content.pm.ShortcutManager; //导入方法依赖的package包/类
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
mAdapter.swapCursor(data);
if (data != null && data.getCount() > 0) {
mEmptyView.setVisibility(View.GONE);
} else {
mEmptyView.setVisibility(View.VISIBLE);
}
if (VERSION.SDK_INT >= VERSION_CODES.N_MR1 && data != null) {
data.moveToFirst();
List<ShortcutInfo> shortcuts = new ArrayList<>();
for (int i = 1; i < 5 && !data.isAfterLast(); ) {
ChatListDataModel item = new ChatListDataModel(data);
if (item.name != null && !item.name.isEmpty()) {
Intent intent = new Intent(getContext(), ChatActivity.class);
intent.putExtra("type", "contact_data_model");
intent.putExtra("data", item.getContactItemDataModel());
ShortcutInfo shortcutInfo =
new ShortcutInfo.Builder(getContext(), "id" + i)
.setShortLabel(item.name)
.setLongLabel(String.format("%s%s", getString(item.is_bot ? R.string.Bot_label : R.string.Contact_label), item.name))
.setIntent(intent)
.setIcon(Icon.createWithResource(getContext(), R.drawable.empty_profile_pic))
.build();
shortcuts.add(shortcutInfo);
i++;
}
data.moveToNext();
}
ShortcutManager shortcutManager = getContext().getSystemService(ShortcutManager.class);
shortcutManager.setDynamicShortcuts(shortcuts);
}
}
示例15: updateShortcuts
import android.content.pm.ShortcutManager; //导入方法依赖的package包/类
public static void updateShortcuts(Realm realm, Activity activity) {
/**
* Shortcuts!
*/
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
ShortcutManager shortcutManager = activity.getSystemService(ShortcutManager.class);
ArrayList<ShortcutInfo> shortcutlist = new ArrayList<>();
// Get Pinned items
RealmResults<PinnedItem> pinnedItems = realm.where(PinnedItem.class).findAll();
if (pinnedItems.size() > 0) {
int count = 0;
for (PinnedItem pitem : pinnedItems) {
Intent linkIntent = new Intent(
Intent.ACTION_VIEW,
Uri.parse(pitem.getUrl()),
activity,
activity.getClass());
linkIntent.putExtra("shortcut", pitem.getUrl());
ShortcutInfo shortcut = new ShortcutInfo.Builder(activity, "shortcut" + count)
.setShortLabel(pitem.getTitle())
.setLongLabel(pitem.getTitle())
.setIcon(Icon.createWithResource(activity, R.drawable.ic_link_black_24dp))
.setIntent(linkIntent)
.build();
shortcutlist.add(shortcut);
count++;
}
shortcutManager.setDynamicShortcuts(shortcutlist);
}
}
}