java类android.graphics.drawable.Icon的实例源码

LauncherInfoManager.java 文件源码 项目:Loyalty 阅读 23 收藏 0 点赞 0 评论 0
/**
 * 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);
}
WakeActivity.java 文件源码 项目:Wake 阅读 26 收藏 0 点赞 0 评论 0
@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));
}
SplashActivity.java 文件源码 项目:CurrentActivity 阅读 26 收藏 0 点赞 0 评论 0
@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));
    }
}
ServerService.java 文件源码 项目:easyfilemanager 阅读 28 收藏 0 点赞 0 评论 0
private void updateTileState(int state) {
    Tile tile = getQsTile();
    if (tile != null) {
        tile.setState(state);
        Icon icon = tile.getIcon();
        switch (state) {
            case Tile.STATE_ACTIVE:
                icon.setTint(Color.WHITE);
                break;
            case Tile.STATE_INACTIVE:
            case Tile.STATE_UNAVAILABLE:
            default:
                icon.setTint(Color.GRAY);
                break;
        }
        tile.updateTile();
    }
}
PhonyUtil.java 文件源码 项目:Phony-Android 阅读 75 收藏 0 点赞 0 评论 0
/**
 * Create a new {@link PhoneAccount} and register it with the system.
 *
 * @param context     The context to use for finding the services and resources.
 * @param accountName The name of the account to add - must be an international phonenumber.
 */
public static void registerNewPhoneAccount(Context context, String accountName) {
    PhoneAccountHandle accountHandle = createPhoneAccountHandle(context, accountName);

    PhoneAccount phone = PhoneAccount.builder(accountHandle, context.getResources().getString(R.string.app_name))
            .setIcon(Icon.createWithResource(context, R.mipmap.ic_launcher_round))
            .setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER)
            .addSupportedUriScheme(PhoneAccount.SCHEME_SIP)
            .setAddress(Uri.parse("sip:" + accountName))
            .build();

    TelecomManager telecomManager = (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);

    telecomManager.registerPhoneAccount(phone);

    // Let the user enable our phone account
    // TODO Show toast so the user knows what is happening
    context.startActivity(new Intent(TelecomManager.ACTION_CHANGE_PHONE_ACCOUNTS));
}
ShortcutHelper.java 文件源码 项目:shortcut-helper 阅读 38 收藏 0 点赞 0 评论 0
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;
}
ResourcesShortcutActivityGenerated.java 文件源码 项目:shortbread 阅读 23 收藏 0 点赞 0 评论 0
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);
}
TwoShortcutActivitiesGenerated.java 文件源码 项目:shortbread 阅读 26 收藏 0 点赞 0 评论 0
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);
}
AdvancedShortcutActivityGenerated.java 文件源码 项目:shortbread 阅读 30 收藏 0 点赞 0 评论 0
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);
}
ShortcutCreateActivity.java 文件源码 项目:Auto.js 阅读 25 收藏 0 点赞 0 评论 0
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
private void createShortcutForAndroidN() {
    Icon icon;
    if (mIsDefaultIcon) {
        icon = Icon.createWithResource(this, R.drawable.ic_node_js_black);
    } else {
        Bitmap bitmap = BitmapTool.drawableToBitmap(mIcon.getDrawable());
        icon = Icon.createWithBitmap(bitmap);
    }
    PersistableBundle extras = new PersistableBundle(1);
    extras.putString(ScriptIntents.EXTRA_KEY_PATH, mScriptFile.getPath());
    ShortcutManager.getInstance(this).addDynamicShortcut(mName.getText(), mScriptFile.getPath(), icon,
            new Intent(this, ShortcutActivity.class)
                    .putExtra(ScriptIntents.EXTRA_KEY_PATH, mScriptFile.getPath())
                    .setAction(Intent.ACTION_MAIN));
}
ChoiceActivity.java 文件源码 项目:shortstories 阅读 26 收藏 0 点赞 0 评论 0
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);
}
MainActivity.java 文件源码 项目:ScreenShotAnywhere 阅读 25 收藏 0 点赞 0 评论 0
private void createNotify(){
    Intent resultIntent = new Intent(this, MainActivity.class);
    resultIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

    PendingIntent piShot = PendingIntent.getService(this, 0, shotIntent, PendingIntent.FLAG_CANCEL_CURRENT);
    Icon icon = Icon.createWithResource(this, R.drawable.ic_camera);
    Notification.Action shotAction = new Notification.Action.Builder(icon, getString(R.string.notify_title_shot), piShot).build();

    NotifyUtil.notifyShot(this, resultIntent, 1, shotAction);
}
IRCChooserTargetService.java 文件源码 项目:revolution-irc 阅读 22 收藏 0 点赞 0 评论 0
@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName targetComponentName,
                                               IntentFilter intentFilter) {
    if (sServer != null && sChannel != null) {
        if (System.currentTimeMillis() - sSetTime >= SET_TIMEOUT) {
            sServer = null;
            sChannel = null;
            return null;
        }
        ComponentName componentName = new ComponentName(getPackageName(),
                MainActivity.class.getCanonicalName());

        List<ChooserTarget> targets = new ArrayList<>();
        Bundle extras = new Bundle();
        extras.putString(MainActivity.ARG_SERVER_UUID, sServer.toString());
        extras.putString(MainActivity.ARG_CHANNEL_NAME, sChannel);
        targets.add(new ChooserTarget(sChannel,
                Icon.createWithResource(this, R.drawable.ic_direct_share),
                1.f, componentName, extras));
        return targets;
    }
    return null;
}
ServerService.java 文件源码 项目:FireFiles 阅读 22 收藏 0 点赞 0 评论 0
private void updateTileState(int state) {
    Tile tile = getQsTile();
    if (tile != null) {
        tile.setState(state);
        Icon icon = tile.getIcon();
        switch (state) {
            case Tile.STATE_ACTIVE:
                icon.setTint(Color.WHITE);
                break;
            case Tile.STATE_INACTIVE:
            case Tile.STATE_UNAVAILABLE:
            default:
                icon.setTint(Color.GRAY);
                break;
        }
        tile.updateTile();
    }
}
ShortcutsManager.java 文件源码 项目:StopApp 阅读 27 收藏 0 点赞 0 评论 0
/**
     * 构造App Shortcut Intent
     *
     * @param appInfo
     * @return
     */
    private ShortcutInfo getShortcut(AppInfo appInfo) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
            ShortcutInfo shortcut = new ShortcutInfo.Builder(mContext, appInfo.getAppPackageName())
                    .setShortLabel(appInfo.getAppName())
                    .setIcon(Icon.createWithBitmap(appInfo.getAppIcon()))
                    .setIntent(
                            new Intent(ShortcutActivity.OPEN_APP_SHORTCUT)
                                    .putExtra(ShortcutActivity.EXTRA_PACKAGE_NAME, appInfo.getAppPackageName())
                            // this dynamic shortcut set up a back stack using Intents, when pressing back, will go to MainActivity
                            // the last Intent is what the shortcut really opened
//                            new Intent[]{
//                                    new Intent(Intent.ACTION_MAIN, Uri.EMPTY, mContext, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK),
//                                    new Intent(AppListActivity.ACTION_OPEN_DYNAMIC)
//                                    // intent's action must be set
//                            }
                    )
                    .build();

            return shortcut;
        } else {
            return null;
        }
    }
ServerService.java 文件源码 项目:simple-share-android 阅读 24 收藏 0 点赞 0 评论 0
private void updateTileState(int state) {
    Tile tile = getQsTile();
    if (tile != null) {
        tile.setState(state);
        Icon icon = tile.getIcon();
        switch (state) {
            case Tile.STATE_ACTIVE:
                icon.setTint(Color.WHITE);
                break;
            case Tile.STATE_INACTIVE:
            case Tile.STATE_UNAVAILABLE:
            default:
                icon.setTint(Color.GRAY);
                break;
        }
        tile.updateTile();
    }
}
ModStatusbarColor.java 文件源码 项目:GravityBox 阅读 22 收藏 0 点赞 0 评论 0
private static Drawable getColoredDrawable(Context ctx, String pkg, Icon icon) {
    if (icon == null) return null;

    Drawable d = null;
    if (pkg == null || PACKAGE_NAME.equals(pkg)) {
        final int iconId = (int) XposedHelpers.callMethod(icon, "getResId");
        d = SysUiManagers.IconManager.getBasicIcon(iconId);
        if (d != null) {
            return d;
        }
    }
    d = icon.loadDrawable(ctx);
    if (d != null) {
        if (SysUiManagers.IconManager.isColoringEnabled()) {
            d = SysUiManagers.IconManager.applyColorFilter(d.mutate(),
                    PorterDuff.Mode.SRC_IN);
        } else {
            d.clearColorFilter();
        }
    }
    return d;
}
ModStatusbarColor.java 文件源码 项目:GravityBox 阅读 19 收藏 0 点赞 0 评论 0
private static void updateStatusIcons(String statusIcons) {
    if (mPhoneStatusBar == null) return;
    try {
        Object icCtrl = XposedHelpers.getObjectField(mPhoneStatusBar, "mIconController");
        ViewGroup vg = (ViewGroup) XposedHelpers.getObjectField(icCtrl, statusIcons);
        final int childCount = vg.getChildCount();
        for (int i = 0; i < childCount; i++) {
            if (!vg.getChildAt(i).getClass().getName().equals(CLASS_STATUSBAR_ICON_VIEW)) {
                continue;
            }
            ImageView v = (ImageView) vg.getChildAt(i);
            final Object sbIcon = XposedHelpers.getObjectField(v, "mIcon");
            if (sbIcon != null) {
                final String iconPackage =
                        (String) XposedHelpers.getObjectField(sbIcon, "pkg");
                Drawable d = getColoredDrawable(v.getContext(), iconPackage,
                        (Icon) XposedHelpers.getObjectField(sbIcon, "icon"));
                if (d != null) {
                    v.setImageDrawable(d);
                }
            }
        }
    } catch (Throwable t) {
        XposedBridge.log(t);
    }
}
ShortcutsHandler.java 文件源码 项目:MusicX-music-player 阅读 24 收藏 0 点赞 0 评论 0
/**
 * 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);
    }
}
NotificationFixer.java 文件源码 项目:container 阅读 38 收藏 0 点赞 0 评论 0
@TargetApi(Build.VERSION_CODES.M)
    void fixIcon(Icon icon, Context pluginContext, boolean isInstall) {
        if (icon == null) return;
        int type = Reflect.on(icon).get("mType");
//        Log.i(TAG, "smallIcon type=" + type);
        if (type == 2) {
            if (isInstall) {
                Reflect.on(icon).set("mObj1", pluginContext.getResources());
                Reflect.on(icon).set("mString1", pluginContext.getPackageName());
            } else {
                Drawable drawable = icon.loadDrawable(pluginContext);
                Bitmap bitmap = drawableToBitMap(drawable);
                Reflect.on(icon).set("mObj1", bitmap);
                Reflect.on(icon).set("mString1", null);
                Reflect.on(icon).set("mType", 1);
            }
        }
    }
Daedalus.java 文件源码 项目:Daedalus 阅读 31 收藏 0 点赞 0 评论 0
public static void updateShortcut(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
        Log.d("Daedalus", "Updating shortcut");
        //shortcut!
        String notice = context.getString(R.string.button_text_activate);
        boolean activate = true;
        ActivityManager manager = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE);
        for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
            if (DaedalusVpnService.class.getName().equals(service.service.getClassName())) {
                notice = context.getString(R.string.button_text_deactivate);
                activate = false;
            }
        }
        ShortcutInfo info = new ShortcutInfo.Builder(context, Daedalus.SHORTCUT_ID_ACTIVATE)
                .setLongLabel(notice)
                .setShortLabel(notice)
                .setIcon(Icon.createWithResource(context, R.mipmap.ic_launcher))
                .setIntent(new Intent(context, MainActivity.class).setAction(Intent.ACTION_VIEW)
                        .putExtra(MainActivity.LAUNCH_ACTION, activate ? MainActivity.LAUNCH_ACTION_ACTIVATE : MainActivity.LAUNCH_ACTION_DEACTIVATE))
                .build();

        ShortcutManager shortcutManager = (ShortcutManager) context.getSystemService(SHORTCUT_SERVICE);
        shortcutManager.addDynamicShortcuts(Collections.singletonList(info));
    }
}
RootTileService.java 文件源码 项目:Magisk-Quick-Toggle 阅读 19 收藏 0 点赞 0 评论 0
@Override
public void onClick() {
    super.onClick();
    Icon icon;

    if (toggleState == 1) {
        toggleState = 0;
        // Hide/unmount Magisk root
        Shell.su("setprop magisk.root 0");
        icon =  Icon.createWithResource(getApplicationContext(), R.drawable.ic_root_off);
        getQsTile().setIcon(icon);
        getQsTile().setState(Tile.STATE_INACTIVE);
        getQsTile().updateTile();
    } else {
        toggleState = 1;
        // Mount Magisk root
        Shell.su("setprop magisk.root 1");
        icon = Icon.createWithResource(getApplicationContext(), R.drawable.ic_root);
        getQsTile().setIcon(icon);
        getQsTile().setState(Tile.STATE_ACTIVE);
        getQsTile().updateTile();
    }
}
Utils.java 文件源码 项目:RespawnIRC-Android 阅读 24 收藏 0 点赞 0 评论 0
@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à. */
    }
}
MainActivity.java 文件源码 项目:Android7_Shortcuts_Demo 阅读 23 收藏 0 点赞 0 评论 0
private void setupShortcuts() {
        mShortcutManager = getSystemService(ShortcutManager.class);

        List<ShortcutInfo> infos = new ArrayList<>();
        for (int i = 0; i < mShortcutManager.getMaxShortcutCountPerActivity(); i++) {
            Intent intent = new Intent(this, MessageActivity.class);
            intent.setAction(Intent.ACTION_VIEW);
            intent.putExtra("msg", "我和" + mAdapter.getItem(i) + "的对话");

            ShortcutInfo info = new ShortcutInfo.Builder(this, "id" + i)
                    .setShortLabel(mAdapter.getItem(i))
                    .setLongLabel("联系人:" + mAdapter.getItem(i))
                    .setIcon(Icon.createWithResource(this, R.drawable.icon))
                    .setIntent(intent)
                    .build();
            infos.add(info);
//            manager.addDynamicShortcuts(Arrays.asList(info));
        }

        mShortcutManager.setDynamicShortcuts(infos);
    }
ShortcutHelper.java 文件源码 项目:zapp 阅读 28 收藏 0 点赞 0 评论 0
/**
 * Adds the given channel as shortcut to the launcher icon.
 * Only call on api level >= 25.
 *
 * @param context to access system services
 * @param channel channel to create a shortcut for
 * @return true if the channel could be added
 */
@TargetApi(25)
public static boolean addShortcutForChannel(Context context, ChannelModel channel) {
    ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);

    if (shortcutManager == null || shortcutManager.getDynamicShortcuts().size() >= 4) {
        return false;
    }

    ShortcutInfo shortcut = new ShortcutInfo.Builder(context, channel.getId())
        .setShortLabel(channel.getName())
        .setLongLabel(channel.getName())
        .setIcon(Icon.createWithResource(context, channel.getDrawableId()))
        .setIntent(ChannelDetailActivity.getStartIntent(context, channel.getId()))
        .build();

    try {
        return shortcutManager.addDynamicShortcuts(Collections.singletonList(shortcut));
    } catch (IllegalArgumentException e) {
        // too many shortcuts
        return false;
    }
}
Helper.java 文件源码 项目:AppOpsX 阅读 39 收藏 0 点赞 0 评论 0
@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);
}
QuickSettingsTileService.java 文件源码 项目:Taskbar 阅读 23 收藏 0 点赞 0 评论 0
private void updateState() {
    Tile tile = getQsTile();
    if(tile != null) {
        SharedPreferences pref = U.getSharedPreferences(this);
        tile.setIcon(Icon.createWithResource(this, pref.getBoolean("app_drawer_icon", false)
                ? R.drawable.ic_system
                : R.drawable.ic_allapps));

        if(U.canDrawOverlays(this))
            tile.setState(U.isServiceRunning(this, NotificationService.class)
                    ? Tile.STATE_ACTIVE
                    : Tile.STATE_INACTIVE);
        else
            tile.setState(Tile.STATE_UNAVAILABLE);

        tile.updateTile();
    }
}
TileHelper.java 文件源码 项目:GeometricWeather 阅读 19 收藏 0 点赞 0 评论 0
/** <br> UI. */

    @RequiresApi(api = Build.VERSION_CODES.N)
    public static void refreshTile(Context context, Tile tile) {
        if (tile == null) {
            return;
        }
        Location location = DatabaseHelper.getInstance(context).readLocationList().get(0);
        location.weather = DatabaseHelper.getInstance(context).readWeather(location);
        if (location.weather != null) {
            boolean f = PreferenceManager.getDefaultSharedPreferences(context)
                    .getBoolean(context.getString(R.string.key_fahrenheit), false);
            tile.setIcon(
                    Icon.createWithResource(
                            context,
                            WeatherHelper.getNotificationWeatherIcon(
                                    location.weather.realTime.weatherKind,
                                    TimeManager.getInstance(context).isDayTime())));
            tile.setLabel(
                    ValueUtils.buildCurrentTemp(
                            location.weather.realTime.temp,
                            false,
                            f));
            tile.updateTile();
        }
    }
CommunicationToggleTile.java 文件源码 项目:TrebleShot 阅读 20 收藏 0 点赞 0 评论 0
private void updateTileState(int state)
{
    Tile tile = getQsTile();

    if (tile != null) {
        tile.setState(state);
        Icon icon = tile.getIcon();

        switch (state) {
            case Tile.STATE_ACTIVE:
                icon.setTint(Color.WHITE);
                break;
            case Tile.STATE_INACTIVE:
            case Tile.STATE_UNAVAILABLE:
            default:
                icon.setTint(Color.GRAY);
                break;
        }

        tile.updateTile();
    }
}
MainActivity.java 文件源码 项目:AndroidFileHost_Browser 阅读 19 收藏 0 点赞 0 评论 0
@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));
}


问题


面经


文章

微信
公众号

扫码关注公众号