android.graphics.drawable.Icon Java Examples

The following examples show how to use android.graphics.drawable.Icon. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ModStatusbarColor.java    From GravityBox with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #2
Source File: ServerService.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #3
Source File: DirectShareService.java    From AndroidStudyDemo with GNU General Public License v2.0 6 votes vote down vote up
@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;
}
 
Example #4
Source File: TextClassification.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Nullable
private static Drawable maybeLoadDrawable(Icon icon) {
    if (icon == null) {
        return null;
    }
    switch (icon.getType()) {
        case Icon.TYPE_BITMAP:
            return new BitmapDrawable(Resources.getSystem(), icon.getBitmap());
        case Icon.TYPE_ADAPTIVE_BITMAP:
            return new AdaptiveIconDrawable(null,
                    new BitmapDrawable(Resources.getSystem(), icon.getBitmap()));
        case Icon.TYPE_DATA:
            return new BitmapDrawable(
                    Resources.getSystem(),
                    BitmapFactory.decodeByteArray(
                            icon.getDataBytes(), icon.getDataOffset(), icon.getDataLength()));
    }
    return null;
}
 
Example #5
Source File: IRCChooserTargetService.java    From revolution-irc with GNU General Public License v3.0 6 votes vote down vote up
@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;
}
 
Example #6
Source File: ShadowsocksTileService.java    From Maying with Apache License 2.0 6 votes vote down vote up
@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);

    iconIdle = Icon.createWithResource(this, R.drawable.ic_start_idle).setTint(0x80ffffff);
    iconBusy = Icon.createWithResource(this, R.drawable.ic_start_busy);
    iconConnected = Icon.createWithResource(this, R.drawable.ic_start_connected);

    mServiceBoundContext = new ServiceBoundContext(base) {
        @Override
        protected void onServiceConnected() {
            try {
                callback.stateChanged(bgService.getState(), bgService.getProfileName(), null);
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        }
    };
}
 
Example #7
Source File: ServerService.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #8
Source File: MainActivity.java    From SecondScreen with Apache License 2.0 6 votes vote down vote up
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));
        }
    }
}
 
Example #9
Source File: AppShortcutsHelper.java    From rcloneExplorer with MIT License 6 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
public static void addRemoteToAppShortcuts(Context context, RemoteItem remoteItem, String id) {
    ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
    if (shortcutManager == null) {
        return;
    }

    Intent intent = new Intent(Intent.ACTION_MAIN, Uri.EMPTY, context, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    intent.putExtra(APP_SHORTCUT_REMOTE_NAME, remoteItem.getName());

    ShortcutInfo shortcut = new ShortcutInfo.Builder(context, id)
            .setShortLabel(remoteItem.getName())
            .setIcon(Icon.createWithResource(context, AppShortcutsHelper.getRemoteIcon(remoteItem.getType(), remoteItem.isCrypt())))
            .setIntent(intent)
            .build();

    shortcutManager.addDynamicShortcuts(Collections.singletonList(shortcut));
}
 
Example #10
Source File: NotificationFixer.java    From container with GNU General Public License v3.0 6 votes vote down vote up
@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);
			}
		}
	}
 
Example #11
Source File: Suggestion.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private Suggestion(Parcel in) {
    mId = in.readString();
    mTitle = in.readCharSequence();
    mSummary = in.readCharSequence();
    mIcon = in.readParcelable(Icon.class.getClassLoader());
    mFlags = in.readInt();
    mPendingIntent = in.readParcelable(PendingIntent.class.getClassLoader());
}
 
Example #12
Source File: NumberGraphic.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static void testNotification(String text) {
    {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

            final Notification.Builder mBuilder = new Notification.Builder(xdrip.getAppContext());

            mBuilder.setSmallIcon(Icon.createWithBitmap(getSmallIconBitmap(text)));

            mBuilder.setContentTitle("Test Number Graphic");
            mBuilder.setContentText("Check the number is visible");
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                mBuilder.setTimeoutAfter(Constants.SECOND_IN_MS * 30);
            } else {
                JoH.runOnUiThreadDelayed(new Runnable() {
                    @Override
                    public void run() {
                        JoH.cancelNotification(Constants.NUMBER_TEXT_TEST_ID);
                    }
                }, Constants.SECOND_IN_MS * 30);
            }
            mBuilder.setOngoing(false);
            mBuilder.setVibrate(vibratePattern);

            int mNotificationId = Constants.NUMBER_TEXT_TEST_ID;
            final NotificationManager mNotifyMgr = (NotificationManager) xdrip.getAppContext().getSystemService(NOTIFICATION_SERVICE);
            mNotifyMgr.notify(mNotificationId, mBuilder.build());
            JoH.runOnUiThreadDelayed(new Runnable() {
                @Override
                public void run() {
                    mNotifyMgr.notify(mNotificationId, mBuilder.build());
                }
            }, 1000);
        } else {
            JoH.static_toast_long("Not supported below Android 6");
        }
    }
}
 
Example #13
Source File: NotificationBuilderBase.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Adds an action to {@code builder} using a {@code Bitmap} if a bitmap is provided and the API
 * level is high enough, otherwise a resource id is used.
 */
@SuppressWarnings("deprecation") // For addAction(int, CharSequence, PendingIntent)
@TargetApi(Build.VERSION_CODES.M) // For the Icon class.
protected static void addActionToBuilder(Notification.Builder builder, Action action) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && action.iconBitmap != null) {
        Icon icon = Icon.createWithBitmap(action.iconBitmap);
        builder.addAction(
                new Notification.Action.Builder(icon, action.title, action.intent).build());
    } else {
        builder.addAction(action.iconId, action.title, action.intent);
    }
}
 
Example #14
Source File: TgChooserTargetService.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private Icon createSavedMessagesIcon() {
    try {
        final Bitmap bitmap = Bitmap.createBitmap(AndroidUtilities.dp(56f), AndroidUtilities.dp(56f), Bitmap.Config.ARGB_8888);
        final AvatarDrawable avatarDrawable = new AvatarDrawable();
        avatarDrawable.setAvatarType(AvatarDrawable.AVATAR_TYPE_SAVED);
        avatarDrawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
        avatarDrawable.draw(new Canvas(bitmap));
        return Icon.createWithBitmap(bitmap);
    } catch (Throwable e) {
        FileLog.e(e);
    }
    return null;
}
 
Example #15
Source File: ServiceTileMain.java    From tracker-control-android with GNU General Public License v3.0 5 votes vote down vote up
private void update() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    boolean enabled = prefs.getBoolean("enabled", false);
    Tile tile = getQsTile();
    if (tile != null) {
        tile.setState(enabled ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE);
        tile.setIcon(Icon.createWithResource(this, enabled ? R.drawable.ic_rocket_white : R.drawable.ic_rocket_white_60));
        tile.updateTile();
    }
}
 
Example #16
Source File: ShortcutsManager.java    From GeometricWeather with GNU Lesser General Public License v3.0 5 votes vote down vote up
@NonNull
private static Icon getIcon(ResourceProvider provider, WeatherCode code, boolean daytime) {
    return Icon.createWithBitmap(
            drawableToBitmap(
                    ResourceHelper.getShortcutsIcon(provider, code, daytime)
            )
    );
}
 
Example #17
Source File: ShortcutUtils.java    From Shortcut with Apache License 2.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
private ShortcutInfo returnShortcutInfo(Shortcut shortcut) {
    return new ShortcutInfo.Builder(context, shortcut.getShortcutId())
            .setShortLabel(shortcut.getShortcutShortLabel())
            .setLongLabel(shortcut.getShortcutLongLabel())
            .setIcon(Icon.createWithResource(context, shortcut.getShortcutIcon()))
            .setIntent(returnIntent(shortcut))
            .build();
}
 
Example #18
Source File: ShortcutHelper.java    From android-AppShortcuts with Apache License 2.0 5 votes vote down vote up
private ShortcutInfo.Builder setSiteInformation(ShortcutInfo.Builder b, Uri uri) {
    // TODO Get the actual site <title> and use it.
    // TODO Set the current locale to accept-language to get localized title.
    b.setShortLabel(uri.getHost());
    b.setLongLabel(uri.toString());

    Bitmap bmp = fetchFavicon(uri);
    if (bmp != null) {
        b.setIcon(Icon.createWithBitmap(bmp));
    } else {
        b.setIcon(Icon.createWithResource(mContext, R.drawable.link));
    }

    return b;
}
 
Example #19
Source File: RemoteViews.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private Class<?> getParameterType() {
    switch (this.type) {
        case BOOLEAN:
            return boolean.class;
        case BYTE:
            return byte.class;
        case SHORT:
            return short.class;
        case INT:
            return int.class;
        case LONG:
            return long.class;
        case FLOAT:
            return float.class;
        case DOUBLE:
            return double.class;
        case CHAR:
            return char.class;
        case STRING:
            return String.class;
        case CHAR_SEQUENCE:
            return CharSequence.class;
        case URI:
            return Uri.class;
        case BITMAP:
            return Bitmap.class;
        case BUNDLE:
            return Bundle.class;
        case INTENT:
            return Intent.class;
        case COLOR_STATE_LIST:
            return ColorStateList.class;
        case ICON:
            return Icon.class;
        default:
            return null;
    }
}
 
Example #20
Source File: MainActivity.java    From Android7_Shortcuts_Demo with Apache License 2.0 5 votes vote down vote up
private void updItem(int index) {
    Intent intent = new Intent(this, MessageActivity.class);
    intent.setAction(Intent.ACTION_VIEW);
    intent.putExtra("msg", "我和" + mAdapter.getItem(index) + "的对话");

    ShortcutInfo info = new ShortcutInfo.Builder(this, "id" + index)
            .setShortLabel(mAdapter.getItem(index))
            .setLongLabel("联系人:" + mAdapter.getItem(index))
            .setIcon(Icon.createWithResource(this, R.drawable.icon))
            .setIntent(intent)
            .build();

    mShortcutManager.updateShortcuts(Arrays.asList(info));
}
 
Example #21
Source File: IconCache.java    From MiPushFramework with GNU General Public License v3.0 5 votes vote down vote up
public Icon getIconCache(final Context ctx, final String pkg, Converter<Bitmap, Icon> callback) {
    return new AbstractCacheAspect<Icon>(mIconMemoryCaches) {
        @Override
        Icon gen() {
            Bitmap rawIconBitmap = getRawIconBitmap(ctx, pkg);
            Bitmap whiteIconBitmap = new WhiteIconProcess().convert(ctx, rawIconBitmap);
            return callback.convert(ctx, whiteIconBitmap);
        }
    }.get("white_" + pkg);
}
 
Example #22
Source File: TgChooserTargetService.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private Icon createSavedMessagesIcon() {
    try {
        final Bitmap bitmap = Bitmap.createBitmap(AndroidUtilities.dp(56f), AndroidUtilities.dp(56f), Bitmap.Config.ARGB_8888);
        final AvatarDrawable avatarDrawable = new AvatarDrawable();
        avatarDrawable.setAvatarType(AvatarDrawable.AVATAR_TYPE_SAVED);
        avatarDrawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
        avatarDrawable.draw(new Canvas(bitmap));
        return Icon.createWithBitmap(bitmap);
    } catch (Throwable e) {
        FileLog.e(e);
    }
    return null;
}
 
Example #23
Source File: FtpTileService.java    From ProjectX with Apache License 2.0 5 votes vote down vote up
private void updateTile() {
    final Tile tile = getQsTile();
    if (FtpServiceHelper.getInstance().isStarted()) {
        tile.setIcon(Icon.createWithResource(this, R.drawable.ic_tile_ftp));
        tile.setLabel(getString(R.string.ftp_tile_label_active));
        tile.setState(Tile.STATE_ACTIVE);
    } else {
        tile.setIcon(Icon.createWithResource(this, R.drawable.ic_tile_ftp));
        tile.setLabel(getString(R.string.ftp_tile_label_inactive));
        tile.setState(Tile.STATE_INACTIVE);
    }
    tile.updateTile();
}
 
Example #24
Source File: ExfriendManager.java    From QNotified with GNU General Public License v3.0 5 votes vote down vote up
public Notification createNotiComp(NotificationManager nm, String ticker, String title, String content, long[] vibration, PendingIntent pi) {
    Application app = getApplication();
    Notification.Builder builder;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        NotificationChannel channel = new NotificationChannel("qn_del_notify", "删好友通知", NotificationManager.IMPORTANCE_DEFAULT);
        channel.setSound(null, null);
        channel.setVibrationPattern(vibration);
        nm.createNotificationChannel(channel);
        builder = new Notification.Builder(app, channel.getId());
    } else {
        builder = new Notification.Builder(app);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        MainHook.injectModuleResources(app.getResources());
        //we have to createWithBitmap rather than with a ResId, otherwise RemoteServiceException
        builder.setSmallIcon(Icon.createWithBitmap(BitmapFactory.decodeResource(app.getResources(), R.drawable.ic_del_friend_top)));
    } else {
        //2020 now, still using <23?
        builder.setSmallIcon(android.R.drawable.ic_delete);
    }
    builder.setTicker(ticker);
    builder.setContentTitle(title);
    builder.setContentText(content);
    builder.setContentIntent(pi);
    builder.setVibrate(vibration);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        return builder.build();
    } else {
        return builder.getNotification();
    }
}
 
Example #25
Source File: Tile.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void readFromParcel(Parcel source) {
    if (source.readByte() != 0) {
        mIcon = Icon.CREATOR.createFromParcel(source);
    } else {
        mIcon = null;
    }
    mState = source.readInt();
    mLabel = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
    mContentDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
}
 
Example #26
Source File: LauncherIconCreator.java    From ActivityLauncher with ISC License 5 votes vote down vote up
@TargetApi(26)
private static void doCreateShortcut(Context context, String appName, Drawable draw, Intent intent) {
    ShortcutManager shortcutManager = Objects.requireNonNull(context.getSystemService(ShortcutManager.class));

    if (shortcutManager.isRequestPinShortcutSupported()) {
        Bitmap bitmap = getBitmapFromDrawable(draw);
        intent.setAction(Intent.ACTION_CREATE_SHORTCUT);


        ShortcutInfo shortcutInfo = new ShortcutInfo.Builder(context, appName)
                .setShortLabel(appName)
                .setLongLabel(appName)
                .setIcon(Icon.createWithBitmap(bitmap))
                .setIntent(intent)
                .build();

        shortcutManager.requestPinShortcut(shortcutInfo, null);
    } else {
        new AlertDialog.Builder(context)
                .setTitle(context.getText(R.string.error_creating_shortcut))
                .setMessage(context.getText(R.string.error_verbose_pin_shortcut))
                .setPositiveButton(context.getText(android.R.string.ok), new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // Just close dialog don't do anything
                        dialog.cancel();
                    }
                })
                .show();
    }
}
 
Example #27
Source File: NotificationBuilderBase.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a public version of the notification to be displayed in sensitive contexts, such as
 * on the lockscreen, displaying just the site origin and badge or generated icon.
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected Notification createPublicNotification(Context context) {
    // Use Android's Notification.Builder because we want the default small icon behaviour.
    Notification.Builder builder =
            new Notification.Builder(context)
                    .setContentText(context.getString(
                            org.chromium.chrome.R.string.notification_hidden_text))
                    .setSmallIcon(org.chromium.chrome.R.drawable.ic_chrome);

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
        // On N, 'subtext' displays at the top of the notification and this looks better.
        builder.setSubText(mOrigin);
    } else {
        // Set origin as title on L & M, because they look odd without one.
        builder.setContentTitle(mOrigin);
        // Hide the timestamp to match Android's default public notifications on L and M.
        builder.setShowWhen(false);
    }

    // Use the badge if provided and SDK supports it, else use a generated icon.
    if (mSmallIconBitmap != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        // The Icon class was added in Android M.
        Bitmap publicIcon = mSmallIconBitmap.copy(mSmallIconBitmap.getConfig(), true);
        builder.setSmallIcon(Icon.createWithBitmap(publicIcon));
    } else if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M && mOrigin != null) {
        // Only set the large icon for L & M because on N(+?) it would add an extra icon on
        // the right hand side, which looks odd without a notification title.
        builder.setLargeIcon(mIconGenerator.generateIconForUrl(mOrigin.toString(), true));
    }
    return builder.build();
}
 
Example #28
Source File: NotificationBuilderBase.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a public version of the notification to be displayed in sensitive contexts, such as
 * on the lockscreen, displaying just the site origin and badge or generated icon.
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected Notification createPublicNotification(Context context) {
    // Use a non-compat builder because we want the default small icon behaviour.
    ChromeNotificationBuilder builder =
            NotificationBuilderFactory
                    .createChromeNotificationBuilder(
                            false /* preferCompat */, ChannelDefinitions.CHANNEL_ID_SITES)
                    .setContentText(context.getString(
                            org.chromium.chrome.R.string.notification_hidden_text))
                    .setSmallIcon(org.chromium.chrome.R.drawable.ic_chrome);

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
        // On N, 'subtext' displays at the top of the notification and this looks better.
        builder.setSubText(mOrigin);
    } else {
        // Set origin as title on L & M, because they look odd without one.
        builder.setContentTitle(mOrigin);
        // Hide the timestamp to match Android's default public notifications on L and M.
        builder.setShowWhen(false);
    }

    // Use the badge if provided and SDK supports it, else use a generated icon.
    if (mSmallIconBitmap != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        // The Icon class was added in Android M.
        Bitmap publicIcon = mSmallIconBitmap.copy(mSmallIconBitmap.getConfig(), true);
        builder.setSmallIcon(Icon.createWithBitmap(publicIcon));
    } else if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M && mOrigin != null) {
        // Only set the large icon for L & M because on N(+?) it would add an extra icon on
        // the right hand side, which looks odd without a notification title.
        builder.setLargeIcon(mIconGenerator.generateIconForUrl(mOrigin.toString(), true));
    }
    return builder.build();
}
 
Example #29
Source File: AppShortcutIconGenerator.java    From Music-Player with GNU General Public License v3.0 5 votes vote down vote up
public static Icon generateThemedIcon(Context context, int iconId) {
    if (PreferenceUtil.getInstance(context).coloredAppShortcuts()) {
        return generateUserThemedIcon(context, iconId).toIcon();
    } else {
        return generateDefaultThemedIcon(context, iconId).toIcon();
    }
}
 
Example #30
Source File: Utility.java    From Shelter with Do What The F*ck You Want To Public License 5 votes vote down vote up
public static void createLauncherShortcut(Context context, Intent launchIntent, Icon icon, String id, String label) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);

        if (shortcutManager.isRequestPinShortcutSupported()) {
            ShortcutInfo info = new ShortcutInfo.Builder(context, id)
                    .setIntent(launchIntent)
                    .setIcon(icon)
                    .setShortLabel(label)
                    .setLongLabel(label)
                    .build();
            Intent addIntent = shortcutManager.createShortcutResultIntent(info);
            shortcutManager.requestPinShortcut(info,
                    PendingIntent.getBroadcast(context, 0, addIntent, 0).getIntentSender());
        } else {
            // TODO: Maybe implement this for launchers without pin shortcut support?
            // TODO: Should be the same with the fallback for Android < O
            // for now just show unsupported
            Toast.makeText(context, context.getString(R.string.unsupported_launcher), Toast.LENGTH_LONG).show();
        }
    } else {
        Intent shortcutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
        shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchIntent);
        shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, label);
        shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, drawableToBitmap(icon.loadDrawable(context)));
        context.sendBroadcast(shortcutIntent);
        Toast.makeText(context, R.string.shortcut_create_success, Toast.LENGTH_SHORT).show();
    }
}