Example usage for android.graphics BitmapFactory decodeResource

List of usage examples for android.graphics BitmapFactory decodeResource

Introduction

In this page you can find the example usage for android.graphics BitmapFactory decodeResource.

Prototype

public static Bitmap decodeResource(Resources res, int id) 

Source Link

Document

Synonym for #decodeResource(Resources,int,android.graphics.BitmapFactory.Options) with null Options.

Usage

From source file:com.bccs.bsecure.MessageReceivedNotification.java

/**
 * Shows the notification, or updates a previously shown notification of
 * this type, with the given parameters.
 * <p>//  w  w  w . ja  v  a  2 s . c o m
 * Customize this method's arguments to present relevant content in
 * the notification.
 * <p>
 * Customize the contents of this method to tweak the behavior and
 * presentation of message received notifications. Make
 * sure to follow the
 * <a href="https://developer.android.com/design/patterns/notifications.html">
 * Notification design guidelines</a> when doing so.
 *
 * @see #cancel(Context)
 */
public static void notify(final Context context, final String title, final String body) {
    final Resources res = context.getResources();

    // This image is used as the notification's large icon (thumbnail).
    // Remove this if your notification has no relevant thumbnail.
    final Bitmap picture = BitmapFactory.decodeResource(res, R.drawable.ic_security_black_48dp);

    final String text = body;
    //Intent conversationIntent = new Intent("com.bccs.bsecure.recentconversation");
    Intent conversationIntent = new Intent(context, Conversation.class);

    final NotificationCompat.Builder builder = new NotificationCompat.Builder(context)

            // Set appropriate defaults for the notification light, sound,
            // and vibration.
            .setDefaults(Notification.DEFAULT_ALL)

            // Set required fields, including the small icon, the
            // notification title, and text.
            .setSmallIcon(R.drawable.ic_security_black_48dp).setContentTitle(title).setContentText(text)

            // All fields below this line are optional.

            // Use a default priority (recognized on devices running Android
            // 4.1 or later)
            .setPriority(NotificationCompat.PRIORITY_DEFAULT)

            // Provide a large icon, shown with the notification in the
            // notification drawer on devices running Android 3.0 or later.
            .setLargeIcon(picture)

            // If this notification relates to a past or upcoming event, you
            // should set the relevant time information using the setWhen
            // method below. If this call is omitted, the notification's
            // timestamp will by set to the time at which it was shown.
            // Call setWhen if this notification relates to a past or
            // upcoming event. The sole argument to this method should be
            // the notification timestamp in milliseconds.
            //.setWhen(...)

            // Set the pending intent to be initiated when the user touches
            // the notification.
            .setContentIntent(PendingIntent.getActivity(context, 0, conversationIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT))

            // Show expanded text content on devices running Android 4.1 or
            // later.
            .setStyle(new NotificationCompat.BigTextStyle().bigText(text).setBigContentTitle(title)
                    .setSummaryText(body))

            // Automatically dismiss the notification when it is touched.
            .setAutoCancel(true);

    notify(context, builder.build());
}

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);/*from  w  ww  .j a v  a  2s  .com*/
    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.androidzeitgeist.webcards.overlay.HandleView.java

public HandleView(Context context) {
    super(context);

    windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);

    final Resources resources = getResources();

    margin = resources.getDimensionPixelSize(R.dimen.overlay_button_margin);
    openOffsetX = resources.getDimensionPixelSize(R.dimen.overlay_width);

    paint = new Paint();
    paint.setColor(ContextCompat.getColor(context, R.color.overlayAccent));
    paint.setAntiAlias(true);//from www .j  a  v  a  2  s . com

    streamBitmap = BitmapFactory.decodeResource(resources, R.drawable.ic_action_stream);
    openAppBitmap = BitmapFactory.decodeResource(resources, R.drawable.ic_action_open_app);
    currentBitmap = openAppBitmap;

    setElevation(resources.getDimensionPixelSize(R.dimen.overlay_button_elevation));

    setOutlineProvider(new ViewOutlineProvider() {
        @Override
        public void getOutline(View view, Outline outline) {
            outline.setOval(0, 0, getWidth(), getHeight());
        }
    });
}

From source file:at.tugraz.ist.akm.webservice.requestprocessor.FaviconLoadRequestProcessor.java

@Override
synchronized public void handleRequest(RequestLine requestLine, String requestData, HttpResponse httpResponse,
        HttpContext httpContext) throws HttpException, IOException {
    try {/*from w w  w. j a  v a 2  s.  c o m*/

        Bitmap bmp = BitmapFactory.decodeResource(mContext.getResources(), R.raw.favicon);
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        bmp.compress(Bitmap.CompressFormat.PNG, 100, os);
        bmp = null;
        byte[] imageBytes = os.toByteArray();

        mResponseDataAppender.appendHttpResponseMediaType(httpResponse,
                WebServerConstants.HTTP.CONTENTY_TYPE_IMAGE_PNG, imageBytes);
    } catch (Exception ex) {
        mLog.error("what a terrible failure", ex);
    }
}

From source file:com.dev.pygmy.util.Utils.java

public static Bitmap getBitmapByType(Resources res, EntityType type, int scale) {
    int resId;// w w w  .j  av  a 2 s. com
    switch (type) {
    case BLACK_ROOK:
        resId = R.drawable.black_rook;
        break;
    case BLACK_KNIGHT:
        resId = R.drawable.black_knight;
        break;
    case BLACK_BISHOP:
        resId = R.drawable.black_bishop;
        break;
    case BLACK_QUEEN:
        resId = R.drawable.black_queen;
        break;
    case BLACK_KING:
        resId = R.drawable.black_king;
        break;
    case BLACK_PAWN:
        resId = R.drawable.black_pawn;
        break;

    case WHITE_ROOK:
        resId = R.drawable.white_rook;
        break;
    case WHITE_KNIGHT:
        resId = R.drawable.white_knight;
        break;
    case WHITE_BISHOP:
        resId = R.drawable.white_bishop;
        break;
    case WHITE_QUEEN:
        resId = R.drawable.white_queen;
        break;
    case WHITE_KING:
        resId = R.drawable.white_king;
        break;
    case WHITE_PAWN:
        resId = R.drawable.white_pawn;
        break;
    default:
        resId = -1;
        break;
    }

    Bitmap bitmap = null;
    if (resId != -1) {
        BitmapFactory.Options opts = new BitmapFactory.Options();
        opts.inJustDecodeBounds = true;
        bitmap = BitmapFactory.decodeResource(res, resId);
        bitmap = Bitmap.createScaledBitmap(bitmap, scale, scale, false);
    }

    return bitmap;
}

From source file:android.support.v17.leanback.supportleanbackshowcase.cards.TextCardView.java

public void updateUi(Card card) {
    TextView extraText = (TextView) findViewById(R.id.extra_text);
    TextView primaryText = (TextView) findViewById(R.id.primary_text);
    final ImageView imageView = (ImageView) findViewById(R.id.main_image);

    extraText.setText(card.getExtraText());
    primaryText.setText(card.getTitle());

    // Create a rounded drawable.
    int resourceId = card.getLocalImageResourceId(getContext());
    Bitmap bitmap = BitmapFactory.decodeResource(getContext().getResources(), resourceId);
    RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(getContext().getResources(), bitmap);
    drawable.setAntiAlias(true);/*from   ww  w.  j a v a  2  s .  c  om*/
    drawable.setCornerRadius(Math.max(bitmap.getWidth(), bitmap.getHeight()) / 2.0f);
    imageView.setImageDrawable(drawable);
}

From source file:com.adam.aslfms.service.ForegroundHide.java

@Override
public int onStartCommand(Intent i, int flags, int startId) {
    //Bundle extras = i.getExtras();

    Intent targetIntent = new Intent(mCtx, SettingsActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(mCtx, 0, targetIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(mCtx).setContentTitle("")
            .setSmallIcon(R.mipmap.ic_notify).setContentText("").setPriority(NotificationCompat.PRIORITY_MIN)
            .setContentIntent(contentIntent);

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB_MR2) {
        builder.setLargeIcon(BitmapFactory.decodeResource(mCtx.getResources(), R.mipmap.ic_launcher));
    }/*  w w w. j  a  va  2  s.  com*/

    this.startForeground(14619, builder.build());

    this.stopForeground(true);
    return Service.START_NOT_STICKY;
}

From source file:com.android.sandwichmaker.ui.NotifyService.java

private void issueNotification(Intent intent, String msg) {
    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    Bitmap bmp = BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.ic_launcher);

    // Constructs the Builder object.
    builder = new NotificationCompat.Builder(this).setLargeIcon(bmp).setSmallIcon(R.drawable.ic_launcher)
            .setTicker(getString(R.string.hint)).setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.notify_message)).setAutoCancel(true)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg));

    Intent resultIntent = new Intent(this, MainActivity.class);
    resultIntent.putExtra(CommonConstants.EXTRA_MESSAGE, msg);
    resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

    // Because clicking the notification opens a new ("special") activity, there's
    // no need to create an artificial back stack.
    PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, resultIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    builder.setContentIntent(resultPendingIntent);
    startTimer(mMillis);//from w w w  .j av a 2s  .co  m
}

From source file:com.benext.thibault.appsample.notification.builder.NotificationBuilder.java

public static NotificationCompat.Builder buildNotificationExtender(Context context) {

    Bitmap tableImg = BitmapFactory.decodeResource(context.getResources(), R.drawable.table_restaurant);

    NotificationCompat.Builder builder = buildNotificationSimpleNBackground(context);
    builder.setSmallIcon(R.drawable.resto_icn);

    // Create a WearableExtender to add functionality for wearables
    NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender()
            .setHintHideIcon(false).setBackground(tableImg);

    return (NotificationCompat.Builder) builder.extend(wearableExtender);
}

From source file:com.achep.acdisplay.ui.activities.MainActivity.java

private static void sendTestNotification(@NonNull Context context) {
    final int id = App.ID_NOTIFY_TEST;
    final Resources res = context.getResources();

    PendingIntent pendingIntent = PendingIntent.getActivity(context, id,
            new Intent(context, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.BigTextStyle bts = new NotificationCompat.BigTextStyle()
            .bigText(res.getString(R.string.notification_test_message_large));
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setContentTitle(res.getString(R.string.app_name))
            .setContentText(res.getString(R.string.notification_test_message)).setContentIntent(pendingIntent)
            .setLargeIcon(BitmapFactory.decodeResource(res, R.mipmap.ic_launcher))
            .setSmallIcon(R.drawable.stat_acdisplay).setAutoCancel(true).setStyle(bts)
            .setColor(App.ACCENT_COLOR)//from w ww. j a v  a  2  s. c  om
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));

    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(id, builder.build());
}