Example usage for android.graphics Bitmap createScaledBitmap

List of usage examples for android.graphics Bitmap createScaledBitmap

Introduction

In this page you can find the example usage for android.graphics Bitmap createScaledBitmap.

Prototype

public static Bitmap createScaledBitmap(@NonNull Bitmap src, int dstWidth, int dstHeight, boolean filter) 

Source Link

Document

Creates a new bitmap, scaled from an existing bitmap, when possible.

Usage

From source file:com.irateam.vkplayer.notifications.PlayerNotificationFactory.java

public static Bitmap scaleNotification(Context context, Bitmap bitmap) {
    return Bitmap.createScaledBitmap(bitmap,
            (int) context.getResources().getDimension(android.R.dimen.notification_large_icon_height),
            (int) context.getResources().getDimension(android.R.dimen.notification_large_icon_width), false);
}

From source file:com.dm.material.dashboard.candybar.helpers.DrawableHelper.java

@Nullable
public static Drawable getResizedDrawable(@NonNull Context context, @DrawableRes int drawableRes,
        @DimenRes int dimenRes) {
    try {//from  w  w  w .jav  a  2 s  .c  o  m
        Drawable drawable = getDrawable(context, drawableRes);
        if (drawable == null)
            return null;

        int size = context.getResources().getDimensionPixelSize(dimenRes);

        Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
                Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);

        return new BitmapDrawable(context.getResources(), Bitmap.createScaledBitmap(bitmap, size, size, true));
    } catch (Exception | OutOfMemoryError e) {
        LogUtil.d(Log.getStackTraceString(e));
        return null;
    }
}

From source file:ca.hoogit.powerhour.Notifications.Foreground.java

public static Notification build(Context context, GameModel game) {
    // Intent for the notification
    Intent intentMain = new Intent(context, MainActivity.class);
    intentMain.setAction(Constants.ACTION.MAIN);
    intentMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    PendingIntent pendingMain = PendingIntent.getActivity(context, 0, intentMain, 0);

    // Pending intent action to pause the game
    Intent intentPause = new Intent(context, Engine.class);
    intentPause.setAction(Constants.ACTION.PAUSE_GAME);
    PendingIntent pendingPause = PendingIntent.getService(context, 0, intentPause, 0);

    // Pending intent action to pause the game
    Intent intentResume = new Intent(context, Engine.class);
    intentResume.setAction(Constants.ACTION.RESUME_GAME);
    PendingIntent pendingResume = PendingIntent.getService(context, 0, intentResume, 0);

    Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher);

    String contentText = game.minutesRemaining();
    NotificationCompat.Action action = new NotificationCompat.Action(R.drawable.ic_stat_av_pause, "Pause",
            pendingPause);//w  ww . j a  v a  2  s.c o m
    if (game.is(State.ACTIVE)) {
        contentText = "Active with " + contentText;
    } else if (game.is(State.PAUSED)) {
        contentText = "Paused with " + contentText;
        action = new NotificationCompat.Action(R.drawable.ic_stat_av_play_arrow, "Resume", pendingResume);
    }

    Notification notification = new NotificationCompat.Builder(context)
            .setContentTitle(game.options().getTitle() + " - Round " + game.currentRound())
            .setTicker(game.options().getTitle() + " - Round " + game.currentRound())
            .setContentText(contentText).setSmallIcon(R.drawable.ic_stat_beer)
            .setLargeIcon(Bitmap.createScaledBitmap(icon, 128, 128, false)).setContentIntent(pendingMain)
            .setOngoing(true).addAction(action).build();

    if (game.is(State.ACTIVE) && !game.canPause()) {
        notification.actions[0] = new Notification.Action(R.drawable.ic_stat_action_flip_to_front, "Open",
                pendingMain);
    }
    return notification;
}

From source file:com.rp.podemu.DockingLogoView.java

public void activateBitmap() {
    if (mBitmap == null)
        return;/*w  w  w.ja v  a 2s.com*/

    ImageView podemuLogo = (ImageView) ((Activity) context).findViewById(R.id.DOCK_status_icon);
    if (podemuLogo != null) {
        podemuLogo.setImageDrawable(ContextCompat.getDrawable(context, (R.drawable.border)));
    }

    DockingLogoView dockingLogo = (DockingLogoView) findViewById(R.id.dockStationLogo);
    dockingLogo.setVisibility(ImageView.VISIBLE);

    resizedBitmap = Bitmap.createScaledBitmap(mBitmap, IMAGE_SCALED_RES_X, IMAGE_SCALED_RES_Y, true);
    invalidate();
}

From source file:net.idlesoft.android.apps.github.utils.GravatarCache.java

/**
 * Returns a Bitmap of the Gravatar associated with the provided ID. This
 * image will be scaled according to the provided size.
 * //  ww  w. jav  a 2 s. co m
 * @param id
 * @param size
 * @return a scaled Bitmap
 */
public static Bitmap getGravatar(final String id, final int size) {
    Bitmap bm = null;
    try {
        final File gravatars = ensure_directory(ROOT_DIR);
        /* Prevents the gravatars from showing up in the Gallery app */
        hideMediaFromGallery(gravatars);

        final File image = new File(gravatars, id + ".png");
        bm = BitmapFactory.decodeFile(image.getPath());
        if (bm == null) {
            bm = downloadGravatar(id);
            /* Compress to a 100x100px PNG */
            bm.compress(Bitmap.CompressFormat.PNG, 100, new FileOutputStream(image));
        }
        bm = Bitmap.createScaledBitmap(bm, size, size, true);
    } catch (final IOException e) {
        Log.e("debug", "Error saving bitmap", e);
        e.printStackTrace();
    }
    return bm;
}

From source file:com.example.android.recipeassistant.RecipeService.java

private void createNotification(Intent intent) {
    mRecipe = Recipe.fromBundle(intent.getBundleExtra(Constants.EXTRA_RECIPE));
    ArrayList<Notification> notificationPages = new ArrayList<Notification>();

    int stepCount = mRecipe.recipeSteps.size();

    for (int i = 0; i < stepCount; ++i) {
        Recipe.RecipeStep recipeStep = mRecipe.recipeSteps.get(i);
        NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle();
        style.bigText(recipeStep.stepText);
        style.setBigContentTitle(//from ww  w.j ava2s.  co  m
                String.format(getResources().getString(R.string.step_count), i + 1, stepCount));
        style.setSummaryText("");
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
        builder.setStyle(style);
        notificationPages.add(builder.build());
    }

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

    if (mRecipe.recipeImage != null) {
        Bitmap recipeImage = Bitmap.createScaledBitmap(AssetUtils.loadBitmapAsset(this, mRecipe.recipeImage),
                Constants.NOTIFICATION_IMAGE_WIDTH, Constants.NOTIFICATION_IMAGE_HEIGHT, false);
        builder.setLargeIcon(recipeImage);
    }
    builder.setContentTitle(mRecipe.titleText);
    builder.setContentText(mRecipe.summaryText);
    builder.setSmallIcon(R.mipmap.ic_notification_recipe);

    Notification notification = builder
            .extend(new NotificationCompat.WearableExtender().addPages(notificationPages)).build();
    mNotificationManager.notify(Constants.NOTIFICATION_ID, notification);
}

From source file:com.icecream.snorlax.module.feature.encounter.EncounterNotification.java

@SuppressWarnings("deprecation")
void show(int pokemonNumber, String pokemonName, double iv, int attack, int defense, int stamina, int cp,
        double level, int hp, String move1, String move1Type, int move1Power, String move2, String move2Type,
        int move2Power, double pokeRate, double greatRate, double ultraRate, String type1, String type2,
        String pokemonClass) {/* ww  w  . j  av a 2 s.  c o m*/
    new Handler(Looper.getMainLooper()).post(() -> {

        Notification notification = new NotificationCompat.Builder(mContext)
                .setSmallIcon(R.drawable.ic_pokeball)
                .setLargeIcon(Bitmap.createScaledBitmap(
                        BitmapFactory.decodeResource(mResources, getPokemonResourceId(pokemonNumber)),
                        getLargeIconWidth(), getLargeIconHeight(), false))
                .setContentTitle(mContext.getString(R.string.notification_title, pokemonName, cp, level))
                .setContentText(mContext.getString(R.string.notification_content, iv, attack, defense, stamina))
                .setStyle(new NotificationCompat.InboxStyle()
                        .addLine(mContext.getString(R.string.notification_categoty_stats_content_iv, iv, attack,
                                defense, stamina))
                        .addLine(mContext.getString(R.string.notification_categoty_stats_content_hp, hp))
                        .addLine(getBoldSpannable(
                                mContext.getString(R.string.notification_categoty_moves_title)))
                        .addLine(mContext.getString(R.string.notification_categoty_moves_fast, move1, move1Type,
                                move1Power))
                        .addLine(mContext.getString(R.string.notification_categoty_moves_charge, move2,
                                move2Type, move2Power))
                        .addLine(getBoldSpannable(
                                mContext.getString(R.string.notification_categoty_catch_title)))
                        .addLine(mContext.getString(R.string.notification_categoty_catch_content, pokeRate,
                                greatRate, ultraRate))
                        .setSummaryText(getFooter(type1, type2, pokemonClass)))
                .setColor(ContextCompat.getColor(mContext, R.color.red_700)).setAutoCancel(true)
                .setVibrate(new long[] { 0 }).setPriority(Notification.PRIORITY_MAX)
                .setCategory(NotificationCompat.CATEGORY_ALARM).build();

        hideIcon(notification);

        mNotificationManager.notify(NOTIFICATION_ID, notification);
    });
}

From source file:com.truiton.foregroundservice.ForegroundService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent.getAction().equals(Constants.ACTION.STARTFOREGROUND_ACTION)) {
        Log.i(LOG_TAG, "Received Start Foreground Intent ");
        Intent notificationIntent = new Intent(this, MainActivity.class);
        notificationIntent.setAction(Constants.ACTION.MAIN_ACTION);
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

        Intent previousIntent = new Intent(this, ForegroundService.class);
        previousIntent.setAction(Constants.ACTION.PREV_ACTION);
        PendingIntent ppreviousIntent = PendingIntent.getService(this, 0, previousIntent, 0);

        Intent playIntent = new Intent(this, ForegroundService.class);
        playIntent.setAction(Constants.ACTION.PLAY_ACTION);
        PendingIntent pplayIntent = PendingIntent.getService(this, 0, playIntent, 0);

        Intent nextIntent = new Intent(this, ForegroundService.class);
        nextIntent.setAction(Constants.ACTION.NEXT_ACTION);
        PendingIntent pnextIntent = PendingIntent.getService(this, 0, nextIntent, 0);

        Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.truiton_short);

        Notification notification = new NotificationCompat.Builder(this).setContentTitle("Truiton Music Player")
                .setTicker("Truiton Music Player").setContentText("My Music")
                .setSmallIcon(R.drawable.ic_launcher)
                .setLargeIcon(Bitmap.createScaledBitmap(icon, 128, 128, false)).setContentIntent(pendingIntent)
                .setOngoing(true).addAction(android.R.drawable.ic_media_previous, "Previous", ppreviousIntent)
                .addAction(android.R.drawable.ic_media_play, "Play", pplayIntent)
                .addAction(android.R.drawable.ic_media_next, "Next", pnextIntent).build();
        startForeground(Constants.NOTIFICATION_ID.FOREGROUND_SERVICE, notification);
    } else if (intent.getAction().equals(Constants.ACTION.PREV_ACTION)) {
        Log.i(LOG_TAG, "Clicked Previous");
    } else if (intent.getAction().equals(Constants.ACTION.PLAY_ACTION)) {
        Log.i(LOG_TAG, "Clicked Play");
    } else if (intent.getAction().equals(Constants.ACTION.NEXT_ACTION)) {
        Log.i(LOG_TAG, "Clicked Next");
    } else if (intent.getAction().equals(Constants.ACTION.STOPFOREGROUND_ACTION)) {
        Log.i(LOG_TAG, "Received Stop Foreground Intent");
        stopForeground(true);//from w  ww  . j  a v  a2  s. co m
        stopSelf();
    }
    return START_STICKY;
}

From source file:helix.profitkey.hotelapp.ImagePagerFragment.java

/** Constructor */
ImagePagerFragment(Context context, String[] img_url_array) {
    contex = context;/* w ww.ja  v a  2s. co m*/
    inflater = LayoutInflater.from(context);
    image_url = img_url_array;
    /** Initialize and setting configuration for image loader*/
    ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(context));

    options = new DisplayImageOptions.Builder().showImageForEmptyUri(R.drawable.lock)
            .showImageOnFail(R.drawable.lock).resetViewBeforeLoading(true).cacheOnDisk(true)
            .imageScaleType(ImageScaleType.EXACTLY).bitmapConfig(Bitmap.Config.RGB_565).considerExifParams(true)
            .displayer(new FadeInBitmapDisplayer(300)).postProcessor(new BitmapProcessor() {
                @Override
                public Bitmap process(Bitmap bmp) {
                    return Bitmap.createScaledBitmap(bmp, 600, 410, false);
                }
            }).build();
}

From source file:com.f2prateek.dfg.core.GenerateFrameService.java

@Override
public void startingImage(Bitmap screenshot) {
    // Create the large notification icon
    int imageWidth = screenshot.getWidth();
    int imageHeight = screenshot.getHeight();
    int iconSize = resources.getDimensionPixelSize(android.R.dimen.notification_large_icon_height);
    final int shortSide = imageWidth < imageHeight ? imageWidth : imageHeight;

    // Check for if config is null, http://crashes.to/s/dd0857c8648
    Bitmap preview = Bitmap.createBitmap(shortSide, shortSide,
            screenshot.getConfig() == null ? Bitmap.Config.ARGB_8888 : screenshot.getConfig());
    Canvas c = new Canvas(preview);
    Paint paint = new Paint();
    ColorMatrix desat = new ColorMatrix();
    desat.setSaturation(0.25f);/*from  www  .ja  v a2  s . co  m*/
    paint.setColorFilter(new ColorMatrixColorFilter(desat));
    Matrix matrix = new Matrix();
    matrix.postTranslate((shortSide - imageWidth) / 2, (shortSide - imageHeight) / 2);
    c.drawBitmap(screenshot, matrix, paint);
    c.drawColor(0x40FFFFFF);

    Bitmap croppedIcon = Bitmap.createScaledBitmap(preview, iconSize, iconSize, true);

    Intent nullIntent = new Intent(this, MainActivity.class);
    nullIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationBuilder = new NotificationCompat.Builder(this)
            .setTicker(resources.getString(R.string.screenshot_saving_ticker))
            .setContentTitle(resources.getString(R.string.screenshot_saving_title))
            .setSmallIcon(R.drawable.ic_stat_app_notification)
            .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(preview))
            .setContentIntent(PendingIntent.getActivity(this, 0, nullIntent, 0))
            .setWhen(System.currentTimeMillis()).setProgress(0, 0, true).setLargeIcon(croppedIcon);

    Notification n = notificationBuilder.build();
    n.flags |= Notification.FLAG_NO_CLEAR;
    notificationManager.notify(DFG_NOTIFICATION_ID, n);
}