Java 类android.graphics.drawable.Icon 实例源码

项目:Loyalty    文件:LauncherInfoManager.java   
/**
 * 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);
}
项目:Wake    文件:WakeActivity.java   
@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));
}
项目:CurrentActivity    文件:SplashActivity.java   
@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));
    }
}
项目:easyfilemanager    文件:ServerService.java   
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();
    }
}
项目:Phony-Android    文件:PhonyUtil.java   
/**
 * 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));
}
项目:shortcut-helper    文件:ShortcutHelper.java   
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;
}
项目:shortbread    文件:ResourcesShortcutActivityGenerated.java   
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);
}
项目:shortbread    文件:TwoShortcutActivitiesGenerated.java   
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);
}
项目:shortbread    文件:AdvancedShortcutActivityGenerated.java   
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);
}
项目:Auto.js    文件:ShortcutCreateActivity.java   
@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));
}
项目:shortstories    文件:ChoiceActivity.java   
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);
}
项目:ScreenShotAnywhere    文件:MainActivity.java   
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);
}
项目:revolution-irc    文件:IRCChooserTargetService.java   
@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;
}
项目:FireFiles    文件:ServerService.java   
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();
    }
}
项目:StopApp    文件:ShortcutsManager.java   
/**
     * 构造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;
        }
    }
项目:simple-share-android    文件:ServerService.java   
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();
    }
}
项目:GravityBox    文件:ModStatusbarColor.java   
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;
}
项目:GravityBox    文件:ModStatusbarColor.java   
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);
    }
}
项目:MusicX-music-player    文件:ShortcutsHandler.java   
/**
 * 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);
    }
}
项目:container    文件:NotificationFixer.java   
@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    文件:Daedalus.java   
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));
    }
}
项目:Magisk-Quick-Toggle    文件:RootTileService.java   
@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();
    }
}
项目:RespawnIRC-Android    文件:Utils.java   
@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à. */
    }
}
项目:Android7_Shortcuts_Demo    文件:MainActivity.java   
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);
    }
项目:zapp    文件:ShortcutHelper.java   
/**
 * 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;
    }
}
项目:AppOpsX    文件:Helper.java   
@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);
}
项目:Taskbar    文件:QuickSettingsTileService.java   
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();
    }
}
项目:GeometricWeather    文件:TileHelper.java   
/** <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();
        }
    }
项目:TrebleShot    文件:CommunicationToggleTile.java   
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();
    }
}
项目:AndroidFileHost_Browser    文件:MainActivity.java   
@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));
}
项目:Demo-Mode-tile    文件:DemoModeTile.java   
@Override
public void onClick() {
    super.onClick();

    if (!Utils.isDumpPermissionGranted() || !Utils.isWriteSecureSettingsPermissionGranted()) {
        Intent mainActivity = new Intent(getApplicationContext(), MainActivity.class);
        mainActivity.setAction(Utils.MISSING_PERMISSION);
        mainActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        startActivity(mainActivity);
    } else {
        if (getQsTile().getState() == Tile.STATE_ACTIVE) {
            getQsTile().setState(Tile.STATE_INACTIVE);
            getQsTile().setIcon(Icon.createWithResource(getApplicationContext(), R.drawable.ic_off));
            getQsTile().updateTile();

            Utils.disableDemoMode();
        } else {
            getQsTile().setState(Tile.STATE_ACTIVE);
            getQsTile().setIcon(Icon.createWithResource(getApplicationContext(), R.drawable.ic_on));
            getQsTile().updateTile();

            Utils.enableDemoMode();
        }
    }
}
项目:AndroidStudyDemo    文件:DirectShareService.java   
@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName, IntentFilter matchedFilter) {
    ComponentName componentName = new ComponentName(getPackageName(),
            ShareActivity.class.getCanonicalName());
    ArrayList<ChooserTarget> targets = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        Bundle extras = new Bundle();
        extras.putInt("directsharekey", i);
        targets.add(new ChooserTarget(
                "name_" + i,
                Icon.createWithResource(this, R.mipmap.ic_logo),
                0.5f,
                componentName,
                extras));
    }
    return targets;
}
项目:android-proguards    文件:ShortcutHelper.java   
@TargetApi(Build.VERSION_CODES.N_MR1)
public static void enablePostShortcut(@NonNull Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) return;
    ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);

    Intent intent = new Intent(context, PostNewDesignerNewsStory.class);
    intent.setAction(Intent.ACTION_VIEW);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    ShortcutInfo postShortcut
            = new ShortcutInfo.Builder(context, POST_SHORTCUT_ID)
            .setShortLabel(context.getString(R.string.shortcut_post_short_label))
            .setLongLabel(context.getString(R.string.shortcut_post_long_label))
            .setDisabledMessage(context.getString(R.string.shortcut_post_disabled))
            .setIcon(Icon.createWithResource(context, R.drawable.ic_shortcut_post))
            .setIntent(intent)
            .build();
    shortcutManager.addDynamicShortcuts(Collections.singletonList(postShortcut));
}
项目:SpotiQ    文件:ShortcutUtil.java   
@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));
}
项目:NyanpasuTile    文件:NetworkAdbTile.java   
@Override
public void onClick() {
    if (!Settings.getHelper(this, "root").get("root_tip", false)) {
        Intent intent = new Intent(this, RootCheckActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivityAndCollapse(intent);
    } else {
        if (CmdUtils.isNetworkAdbEnabled()) {
            CmdUtils.execRootCmd(CmdUtils.STOP_NET_ADB);
            getQsTile().setIcon(Icon.createWithResource(this, R.drawable.ic_phonelink_off_white_24dp));
            getQsTile().setLabel(getString(R.string.network_adb_tile_label));
            getQsTile().updateTile();
        } else {
            CmdUtils.execRootCmd(CmdUtils.START_NET_ADB);
            getQsTile().setIcon(Icon.createWithResource(this, R.drawable.ic_phonelink_white_24dp));
            getQsTile().setLabel(NetworkUtils.getHostIP() + ":" + "5555");
            getQsTile().updateTile();
        }
    }
}
项目:wear-exchangerates    文件:ComplicationService.java   
static void updateComplication(float quote, boolean invert, String symbol, int complicationId, int type,
                               ComplicationManager manager, PendingIntent pi, Context ctx) {
    if (invert) {
        quote = 1.0f / quote;
    }
    DecimalFormat df = new DecimalFormat("#.###");
    df.setRoundingMode(RoundingMode.HALF_UP);
    String displayQuote = quote > 0.0f ? df.format(quote) : "-";
    String displayLabel = invert ? "$:" + symbol : symbol + ":$";
    ComplicationData.Builder builder = new ComplicationData.Builder(type);
    builder.setTapAction(pi);

    if (type == ComplicationData.TYPE_SHORT_TEXT) {
        builder.setShortText(ComplicationText.plainText(displayQuote));
        builder.setShortTitle(ComplicationText.plainText(displayLabel));
    } else if (type == ComplicationData.TYPE_LONG_TEXT) {
        builder.setLongText(ComplicationText.plainText(displayQuote));
        builder.setLongTitle(ComplicationText.plainText(displayLabel));
        builder.setIcon(Icon.createWithResource(ctx, R.mipmap.ic_provider_icon));
    }
    manager.updateComplicationData(complicationId, builder.build());

}
项目:365browser    文件:LauncherShortcutActivity.java   
/**
 * Adds a "New incognito tab" dynamic launcher shortcut.
 * @param context The context used to retrieve the system {@link ShortcutManager}.
 * @return True if addint the shortcut has succeeded. False if the call fails due to rate
 *         limiting. See {@link ShortcutManager#addDynamicShortcuts}.
 */
@TargetApi(Build.VERSION_CODES.N_MR1)
private static boolean addIncognitoLauncherShortcut(Context context) {
    Intent intent = new Intent(LauncherShortcutActivity.ACTION_OPEN_NEW_INCOGNITO_TAB);
    intent.setPackage(context.getPackageName());
    intent.setClass(context, LauncherShortcutActivity.class);

    ShortcutInfo shortcut =
            new ShortcutInfo.Builder(context, DYNAMIC_OPEN_NEW_INCOGNITO_TAB_ID)
                    .setShortLabel(context.getResources().getString(
                            R.string.accessibility_tabstrip_incognito_identifier))
                    .setLongLabel(
                            context.getResources().getString(R.string.menu_new_incognito_tab))
                    .setIcon(Icon.createWithResource(context, R.drawable.shortcut_incognito))
                    .setIntent(intent)
                    .build();

    ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
    return shortcutManager.addDynamicShortcuts(Arrays.asList(shortcut));
}
项目:plaid    文件:ShortcutHelper.java   
@TargetApi(Build.VERSION_CODES.N_MR1)
public static void enablePostShortcut(@NonNull Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) return;
    ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);

    Intent intent = new Intent(context, PostNewDesignerNewsStory.class);
    intent.setAction(Intent.ACTION_VIEW);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    ShortcutInfo postShortcut
            = new ShortcutInfo.Builder(context, POST_SHORTCUT_ID)
            .setShortLabel(context.getString(R.string.shortcut_post_short_label))
            .setLongLabel(context.getString(R.string.shortcut_post_long_label))
            .setDisabledMessage(context.getString(R.string.shortcut_post_disabled))
            .setIcon(Icon.createWithResource(context, R.drawable.ic_shortcut_post))
            .setIntent(intent)
            .build();
    shortcutManager.addDynamicShortcuts(Collections.singletonList(postShortcut));
}
项目:Slide    文件:MainActivity.java   
private Icon getIcon(String subreddit, @DrawableRes int overlay) {
    Bitmap color = Bitmap.createBitmap(toDp(this, 148), toDp(this, 148), Bitmap.Config.RGB_565);
    color.eraseColor(Palette.getColor(subreddit));
    color = clipToCircle(color);

    Bitmap over = drawableToBitmap(ResourcesCompat.getDrawable(getResources(), overlay, null));

    Canvas canvas = new Canvas(color);
    canvas.drawBitmap(over, color.getWidth() / 2 - (over.getWidth() / 2),
            color.getHeight() / 2 - (over.getHeight() / 2), null);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        return Icon.createWithBitmap(color);
    }
    return null;
}
项目:WearNetworkNotifications    文件:NetworkComplicationProviderService.java   
@Override
public void onComplicationActivated(int complicationId, int type, ComplicationManager complicationManager) {
    super.onComplicationActivated(complicationId, type, complicationManager);
    NetworkComplicationProviderService.serviceInstance = this;
    NetworkComplicationProviderService.complicationManager = complicationManager;
    NetworkComplicationProviderService.complicationId = complicationId;
    Log.d(LOGTAG, "onCompilationActivated: compilationId=" + complicationId);

    // invoke the NetworkNotification service:
    Intent intent = new Intent(this, NetworkNotificationService.class);
    intent.setAction(NetworkNotificationService.ACTION_SHOW_COMPILATION);
    startService(intent);

    // Intent for tap event (invoke the NetworkNotification service)
    Intent tapIntent = new Intent(serviceInstance, StartActivity.class);
    tapIntent.setAction(NetworkNotificationService.ACTION_SHOW_NOTIFICATION);

    ComplicationData complicationData = new ComplicationData.Builder(ComplicationData.TYPE_SHORT_TEXT)
            .setShortText(ComplicationText.plainText(getString(R.string.loading)))
            .setIcon(Icon.createWithResource(serviceInstance, R.drawable.ic_launcher))
            .setTapAction(PendingIntent.getActivity(serviceInstance, 0, tapIntent, 0))
            .build();

    complicationManager.updateComplicationData(complicationId, complicationData);
}