当前位置: 首页>>代码示例>>Java>>正文


Java ShortcutInfo类代码示例

本文整理汇总了Java中android.content.pm.ShortcutInfo的典型用法代码示例。如果您正苦于以下问题:Java ShortcutInfo类的具体用法?Java ShortcutInfo怎么用?Java ShortcutInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ShortcutInfo类属于android.content.pm包,在下文中一共展示了ShortcutInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: pinShortcutToHomeScreen

import android.content.pm.ShortcutInfo; //导入依赖的package包/类
private void pinShortcutToHomeScreen(Context context) {
    ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
    if (shortcutManager.isRequestPinShortcutSupported()) {
        ShortcutInfo pinShortcutInfo = createShortcutInfo(this);
        Intent resultIntent = shortcutManager.createShortcutResultIntent(pinShortcutInfo);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, resultIntent, 0);
        shortcutManager.requestPinShortcut(pinShortcutInfo, pendingIntent.getIntentSender());
    } else {
        Toast.makeText(context, R.string.device_does_not_support_shortcut_pinning, Toast.LENGTH_SHORT).show();
    }
}
 
开发者ID:akexorcist,项目名称:Android-O-Feature,代码行数:12,代码来源:PinningActivity.java

示例2: updateDynamicShortcuts

import android.content.pm.ShortcutInfo; //导入依赖的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

示例3: createShortcut

import android.content.pm.ShortcutInfo; //导入依赖的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

示例4: createShortcut

import android.content.pm.ShortcutInfo; //导入依赖的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

示例5: createShortcutList

import android.content.pm.ShortcutInfo; //导入依赖的package包/类
public ShortcutHelper createShortcutList(@NonNull List<Shortcut> shortcuts) {
    if (Build.VERSION.SDK_INT < 25) {
        return this;
    }
    mShortcutManager = mActivity.getSystemService(ShortcutManager.class);
    for (int i=0; i<shortcuts.size(); i++) {
        if (i < mShortcutManager.getMaxShortcutCountPerActivity()) {
            String shortcutId = shortcuts.get(i).getShortLabel().replaceAll("\\s+","").toLowerCase() + "_shortcut";
            ShortcutInfo shortcut = new ShortcutInfo.Builder(mActivity, shortcutId)
                    .setShortLabel(shortcuts.get(i).getShortLabel())
                    .setLongLabel(shortcuts.get(i).getLongLabel())
                    .setIcon(Icon.createWithResource(mActivity, shortcuts.get(i).getIconResource()))
                    .setIntent(shortcuts.get(i).getIntent())
                    .build();
            mShortcutInfos.add(shortcut);
        }
    }
    return this;
}
 
开发者ID:marcoscgdev,项目名称:shortcut-helper,代码行数:20,代码来源:ShortcutHelper.java

示例6: createShortcuts

import android.content.pm.ShortcutInfo; //导入依赖的package包/类
public static List<List<ShortcutInfo>> createShortcuts(Context context) {
    if (shortcuts == null) {
        List<ShortcutInfo> enabledShortcuts = new ArrayList<>();
        List<ShortcutInfo> disabledShortcuts = new ArrayList<>();
        enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID")
                .setShortLabel("Short label")
                .setIntents(TaskStackBuilder.create(context)
                        .addNextIntent(new Intent(Intent.ACTION_VIEW))
                        .getIntents())
                .setRank(0)
                .build());

        shortcuts = Arrays.asList(enabledShortcuts, disabledShortcuts);
    }

    return shortcuts;
}
 
开发者ID:MatthiasRobbers,项目名称:shortbread,代码行数:18,代码来源:ShortbreadGenerated.java

示例7: createShortcuts

import android.content.pm.ShortcutInfo; //导入依赖的package包/类
public static List<List<ShortcutInfo>> createShortcuts(Context context) {
    List<ShortcutInfo> enabledShortcuts = new ArrayList<>();
    List<ShortcutInfo> disabledShortcuts = new ArrayList<>();
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID")
            .setShortLabel(context.getString(34))
            .setLongLabel(context.getString(56))
            .setIcon(Icon.createWithResource(context, 12))
            .setDisabledMessage(context.getString(78))
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(ResourcesShortcutActivity.class)
                    .addNextIntent(new Intent(context, ResourcesShortcutActivity.class)
                            .setAction(Intent.ACTION_VIEW))
                    .getIntents())
            .setRank(0)
            .build());
    return Arrays.asList(enabledShortcuts, disabledShortcuts);
}
 
开发者ID:MatthiasRobbers,项目名称:shortbread,代码行数:18,代码来源:ResourcesShortcutActivityGenerated.java

示例8: createShortcuts

import android.content.pm.ShortcutInfo; //导入依赖的package包/类
public static List<List<ShortcutInfo>> createShortcuts(Context context) {
    List<ShortcutInfo> enabledShortcuts = new ArrayList<>();
    List<ShortcutInfo> disabledShortcuts = new ArrayList<>();
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID")
            .setShortLabel("SHORT_LABEL")
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(BackStackShortcutActivity.class)
                    .addNextIntent(new Intent(Intent.ACTION_VIEW).setClass(context, EmptyActivity1.class))
                    .addNextIntent(new Intent(Intent.ACTION_VIEW).setClass(context, EmptyActivity2.class))
                    .addNextIntent(new Intent(context, BackStackShortcutActivity.class)
                            .setAction(Intent.ACTION_VIEW))
                    .getIntents())
            .setRank(0)
            .build());
    return Arrays.asList(enabledShortcuts, disabledShortcuts);
}
 
开发者ID:MatthiasRobbers,项目名称:shortbread,代码行数:17,代码来源:BackStackShortcutActivityGenerated.java

示例9: createShortcuts

import android.content.pm.ShortcutInfo; //导入依赖的package包/类
public static List<List<ShortcutInfo>> createShortcuts(Context context) {
    List<ShortcutInfo> enabledShortcuts = new ArrayList<>();
    List<ShortcutInfo> disabledShortcuts = new ArrayList<>();
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID")
            .setShortLabel(ShortcutUtils.getActivityLabel(context, SimpleShortcutActivity.class))
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(SimpleShortcutActivity.class)
                    .addNextIntent(new Intent(context, SimpleShortcutActivity.class)
                            .setAction(Intent.ACTION_VIEW))
                    .getIntents())
            .setRank(0)
            .build());
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID_2")
            .setShortLabel("SHORT_LABEL")
            .setLongLabel("LONG_LABEL")
            .setIcon(Icon.createWithResource(context, 123))
            .setDisabledMessage("DISABLED_MESSAGE")
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(AdvancedShortcutActivity.class)
                    .addNextIntent(new Intent(context, AdvancedShortcutActivity.class)
                            .setAction("ACTION"))
                    .getIntents())
            .setRank(1)
            .build());
    return Arrays.asList(enabledShortcuts, disabledShortcuts);
}
 
开发者ID:MatthiasRobbers,项目名称:shortbread,代码行数:27,代码来源:TwoShortcutActivitiesGenerated.java

示例10: createShortcuts

import android.content.pm.ShortcutInfo; //导入依赖的package包/类
public static List<List<ShortcutInfo>> createShortcuts(Context context) {
    List<ShortcutInfo> enabledShortcuts = new ArrayList<>();
    List<ShortcutInfo> disabledShortcuts = new ArrayList<>();
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID_2")
            .setShortLabel("SHORT_LABEL")
            .setLongLabel("LONG_LABEL")
            .setIcon(Icon.createWithResource(context, 123))
            .setDisabledMessage("DISABLED_MESSAGE")
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(AdvancedShortcutActivity.class)
                    .addNextIntent(new Intent(context, AdvancedShortcutActivity.class)
                            .setAction("ACTION"))
                    .getIntents())
            .setRank(1)
            .build());
    return Arrays.asList(enabledShortcuts, disabledShortcuts);
}
 
开发者ID:MatthiasRobbers,项目名称:shortbread,代码行数:18,代码来源:AdvancedShortcutActivityGenerated.java

示例11: createShortcuts

import android.content.pm.ShortcutInfo; //导入依赖的package包/类
public static List<List<ShortcutInfo>> createShortcuts(Context context) {
    List<ShortcutInfo> enabledShortcuts = new ArrayList<>();
    List<ShortcutInfo> disabledShortcuts = new ArrayList<>();
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID")
            .setShortLabel(ShortcutUtils.getActivityLabel(context, MethodShortcutActivity.class))
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(MethodShortcutActivity.class)
                    .addNextIntent(new Intent(context, MethodShortcutActivity.class)
                            .setAction(Intent.ACTION_VIEW)
                            .putExtra("shortbread_method", "shortcutMethod"))
                    .getIntents())
            .setRank(0)
            .build());
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID")
            .setShortLabel(ShortcutUtils.getActivityLabel(context, MethodShortcutActivity2.class))
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(MethodShortcutActivity2.class)
                    .addNextIntent(new Intent(context, MethodShortcutActivity2.class)
                            .setAction(Intent.ACTION_VIEW)
                            .putExtra("shortbread_method", "shortcutMethod"))
                    .getIntents())
            .setRank(0)
            .build());
    return Arrays.asList(enabledShortcuts, disabledShortcuts);
}
 
开发者ID:MatthiasRobbers,项目名称:shortbread,代码行数:26,代码来源:TwoMethodShortcutActivitiesGenerated.java

示例12: createShortcuts

import android.content.pm.ShortcutInfo; //导入依赖的package包/类
public static List<List<ShortcutInfo>> createShortcuts(Context context) {
    List<ShortcutInfo> enabledShortcuts = new ArrayList<>();
    List<ShortcutInfo> disabledShortcuts = new ArrayList<>();
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID")
            .setShortLabel(ShortcutUtils.getActivityLabel(context, TwoMethodShortcutsActivity.class))
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(TwoMethodShortcutsActivity.class)
                    .addNextIntent(new Intent(context, TwoMethodShortcutsActivity.class)
                            .setAction(Intent.ACTION_VIEW)
                            .putExtra("shortbread_method", "shortcutMethod1"))
                    .getIntents())
            .setRank(0)
            .build());
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID_2")
            .setShortLabel(ShortcutUtils.getActivityLabel(context, TwoMethodShortcutsActivity.class))
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(TwoMethodShortcutsActivity.class)
                    .addNextIntent(new Intent(context, TwoMethodShortcutsActivity.class)
                            .setAction(Intent.ACTION_VIEW)
                            .putExtra("shortbread_method", "shortcutMethod2"))
                    .getIntents())
            .setRank(0)
            .build());
    return Arrays.asList(enabledShortcuts, disabledShortcuts);
}
 
开发者ID:MatthiasRobbers,项目名称:shortbread,代码行数:26,代码来源:TwoMethodShortcutsActivityGenerated.java

示例13: addChoiceShortcuts

import android.content.pm.ShortcutInfo; //导入依赖的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

示例14: getNextRailNumber

import android.content.pm.ShortcutInfo; //导入依赖的package包/类
public static int getNextRailNumber(ShortcutManager shortcutManager) {
    List<ShortcutInfo> shortcuts = shortcutManager.getPinnedShortcuts();

    int newRailId = -1;

    for (ShortcutInfo shortcutInfo : shortcuts) {
        String id = shortcutInfo.getId();
        if (isRailShortcut(id)) {
            int railId = getRailNumber(id);
            if (railId > newRailId) {
                newRailId = railId;
            }
        }
    }

    newRailId++;

    return newRailId;
}
 
开发者ID:nirhart,项目名称:shortrain,代码行数:20,代码来源:ShortcutsUtils.java

示例15: addAppShortcut

import android.content.pm.ShortcutInfo; //导入依赖的package包/类
/**
 * 添加App Shortcut
 */
public void addAppShortcut(List<AppInfo> appList) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
        List<AppInfo> appInfoDB = new ArrayList<>(
                mDBController.getDisableApps(AppInfoDBOpenHelper.TABLE_NAME_SHORTCUT_APP_INFO));

        for (AppInfo appInfo : appList) {
            if (!mDBController.searchApp(AppInfoDBOpenHelper.TABLE_NAME_SHORTCUT_APP_INFO, appInfo.getAppPackageName())) {
                appInfoDB.add(appInfo);
            }
        }

        mDBController.clearDisableApp(AppInfoDBOpenHelper.TABLE_NAME_SHORTCUT_APP_INFO);
        List<ShortcutInfo> shortcutList = new ArrayList<>();
        for (int i = appInfoDB.size() - 1; i >= 0; i--) {
            if (shortcutList.size() < 4) {
                shortcutList.add(getShortcut(appInfoDB.get(i)));
                mDBController.addDisableApp(appInfoDB.get(i), AppInfoDBOpenHelper.TABLE_NAME_SHORTCUT_APP_INFO);
            } else {
                removeShortcut(appInfoDB.get(i).getAppPackageName(), mContext.getString(R.string.shortcut_num_limit));
            }
        }
        mShortcutManager.setDynamicShortcuts(shortcutList);
    }
}
 
开发者ID:XYScience,项目名称:StopApp,代码行数:28,代码来源:ShortcutsManager.java


注:本文中的android.content.pm.ShortcutInfo类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。