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


Java ShortcutManager.setDynamicShortcuts方法代碼示例

本文整理匯總了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);
}
 
開發者ID:AbyxBelgium,項目名稱:Loyalty,代碼行數:32,代碼來源:LauncherInfoManager.java

示例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));
    }
}
 
開發者ID:Omico,項目名稱:CurrentActivity,代碼行數:20,代碼來源:SplashActivity.java

示例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);
}
 
開發者ID:nicholasrout,項目名稱:shortstories,代碼行數:26,代碼來源:ChoiceActivity.java

示例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);
    }
}
 
開發者ID:RajneeshSingh007,項目名稱:MusicX-music-player,代碼行數:27,代碼來源:ShortcutsHandler.java

示例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à. */
    }
}
 
開發者ID:FranckRJ,項目名稱:RespawnIRC-Android,代碼行數:25,代碼來源:Utils.java

示例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);
}
 
開發者ID:8enet,項目名稱:AppOpsX,代碼行數:25,代碼來源:Helper.java

示例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);
    }
}
 
開發者ID:brarcher,項目名稱:loyalty-card-locker,代碼行數:27,代碼來源:ShortcutHelper.java

示例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));
}
 
開發者ID:out386,項目名稱:AndroidFileHost_Browser,代碼行數:22,代碼來源:MainActivity.java

示例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));
}
 
開發者ID:ZinoKader,項目名稱:SpotiQ,代碼行數:18,代碼來源:ShortcutUtil.java

示例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));
        }
    }
}
 
開發者ID:farmerbb,項目名稱:SecondScreen,代碼行數:20,代碼來源:MainActivity.java

示例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));
    }

}
 
開發者ID:TonnyL,項目名稱:Espresso,代碼行數:38,代碼來源:OnboardingActivity.java

示例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);
}
 
開發者ID:TheAndroidMaster,項目名稱:Metronome-Android,代碼行數:30,代碼來源:MainActivity.java

示例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();
        }
    });
}
 
開發者ID:nirhart,項目名稱:shortrain,代碼行數:28,代碼來源:MainActivity.java

示例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);

	}
}
 
開發者ID:arunrajora,項目名稱:Chit-Chat,代碼行數:35,代碼來源:FragmentChatList.java

示例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);
        }
    }
}
 
開發者ID:dasmikko,項目名稱:facepunchdroid,代碼行數:40,代碼來源:ShortcutsManager.java


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