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:au.com.wallaceit.reddinator.MailCheckService.java

private void setNotification() {
    int message = global.mRedditData.getInboxCount();
    Intent notifyIntent = new Intent(this, WebViewActivity.class);
    notifyIntent.setAction(WebViewActivity.ACTION_CLEAR_INBOX_COUNT);
    notifyIntent.putExtra("url", "http://www.reddit.com/message/unread/.compact");
    Notification notification = new NotificationCompat.Builder(this).setContentTitle(message + " New Messages")
            .setContentText("Click to view reddit messages")
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.reddit_icon_small))
            .setSmallIcon(R.drawable.ic_notify)
            .setContentIntent(// w ww .  j  ava  2  s . com
                    PendingIntent.getActivity(this, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT))
            .build();

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(1, notification);
}

From source file:net.olejon.mdapp.NotificationsFromSlvIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    final Context mContext = this;

    final MyTools mTools = new MyTools(mContext);

    if (mTools.getDefaultSharedPreferencesBoolean("NOTIFICATIONS_FROM_SLV_NOTIFY")
            && mTools.isDeviceConnected()) {
        RequestQueue requestQueue = Volley.newRequestQueue(mContext);

        int projectVersionCode = mTools.getProjectVersionCode();

        String device = mTools.getDevice();

        JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(
                getString(R.string.project_website_uri) + "api/1/notifications-from-slv/?first&version_code="
                        + projectVersionCode + "&device=" + device,
                new Response.Listener<JSONArray>() {
                    @SuppressLint("InlinedApi")
                    @Override/*from  w ww  .  j av a 2 s .c om*/
                    public void onResponse(JSONArray response) {
                        try {
                            final JSONObject notifications = response.getJSONObject(0);

                            final String title = notifications.getString("title");
                            final String message = notifications.getString("message");

                            final String lastTitle = mTools
                                    .getSharedPreferencesString("NOTIFICATIONS_FROM_SLV_LAST_TITLE");

                            if (!title.equals(lastTitle)) {
                                if (!lastTitle.equals("")) {
                                    Intent launchIntent = new Intent(mContext,
                                            NotificationsFromSlvActivity.class);
                                    PendingIntent launchPendingIntent = PendingIntent.getActivity(mContext, 0,
                                            launchIntent, PendingIntent.FLAG_UPDATE_CURRENT);

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

                                    NotificationManagerCompat notificationManager = NotificationManagerCompat
                                            .from(mContext);
                                    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(
                                            mContext);

                                    notificationBuilder.setWhen(mTools.getCurrentTime())
                                            .setPriority(Notification.PRIORITY_HIGH)
                                            .setVisibility(Notification.VISIBILITY_PUBLIC)
                                            .setCategory(Notification.CATEGORY_MESSAGE).setLargeIcon(bitmap)
                                            .setSmallIcon(R.drawable.ic_local_hospital_white_24dp)
                                            .setSound(RingtoneManager
                                                    .getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                                            .setLights(Color.BLUE, 1000, 2000).setTicker(title)
                                            .setContentTitle(title).setContentText(message)
                                            .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
                                            .setContentIntent(launchPendingIntent)
                                            .addAction(R.drawable.ic_notifications_white_24dp,
                                                    getString(
                                                            R.string.service_notifications_from_slv_read_more),
                                                    launchPendingIntent);

                                    notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
                                }

                                mTools.setSharedPreferencesString("NOTIFICATIONS_FROM_SLV_LAST_TITLE", title);
                            }
                        } catch (Exception e) {
                            Log.e("NotificationsFromSlv", Log.getStackTraceString(e));
                        }
                    }
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Log.e("NotificationsFromSlv", error.toString());
                    }
                });

        jsonArrayRequest.setRetryPolicy(new DefaultRetryPolicy(10000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

        requestQueue.add(jsonArrayRequest);
    }
}

From source file:com.klinker.android.twitter.services.TrimDataService.java

public void notifyNewVersion(String version) {
    Intent goToStore = new Intent(this, RedirectToPlayStore.class);
    PendingIntent storePending = PendingIntent.getActivity(this, 0, goToStore, 0);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setContentTitle("Talon Version " + version);
    builder.setContentText("Click to update.");
    builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));
    builder.setSmallIcon(R.drawable.ic_stat_icon);
    builder.setContentIntent(storePending);

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

    notificationManager.notify(552, builder.build());
}

From source file:de.incoherent.suseconferenceclient.app.SocialWrapper.java

public static ArrayList<SocialItem> getGooglePlusItems(Context context, String tag, int maximum) {
    String twitterSearch = "https://www.googleapis.com/plus/v1/activities?orderBy=recent&query=" + tag + "&key="
            + Config.PLUS_KEY;/*  ww  w .  j  a  v  a 2 s .com*/
    Log.d("SUSEConferences", "Google search: " + twitterSearch);
    ArrayList<SocialItem> socialItems = new ArrayList<SocialItem>();
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'");
    formatter.setTimeZone(TimeZone.getTimeZone("UTC"));

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

    try {
        JSONObject result = HTTPWrapper.get(twitterSearch);
        JSONArray items = result.getJSONArray("items");
        int len = items.length();
        if ((len > 0) && (maximum > 0) && (len > maximum))
            len = maximum;

        for (int i = 0; i < len; i++) {
            JSONObject jsonItem = items.getJSONObject(i);
            JSONObject actorItem = jsonItem.getJSONObject("actor");
            JSONObject imageItem = actorItem.getJSONObject("image");
            JSONObject objectItem = jsonItem.getJSONObject("object");
            Bitmap image = HTTPWrapper.getImage(imageItem.getString("url"));
            String content = Html.fromHtml(objectItem.getString("content")).toString();
            Date formattedDate = new Date();
            try {
                formattedDate = formatter.parse(jsonItem.getString("published"));
            } catch (ParseException e) {
                e.printStackTrace();
            }

            SocialItem newItem = new SocialItem(SocialItem.GOOGLE, actorItem.getString("displayName"), content,
                    formattedDate,
                    DateUtils
                            .formatDateTime(context, formattedDate.getTime(),
                                    DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_NUMERIC_DATE
                                            | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE),
                    image, icon);
            newItem.setLink(jsonItem.getString("url"));
            socialItems.add(newItem);
        }
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (SocketException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return socialItems;
}

From source file:com.coderming.weatherwatch.gcm.MyGcmListenerService.java

/**
 *  Put the message into a notification and post it.
 *  This is just one simple example of what you might choose to do with a GCM message.
 *
 * @param message The alert message to be posted.
 *///  ww w  .j a va2s  .c  o m
private void sendNotification(String message) {
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);

    // Notifications using both a large and a small icon (which yours should!) need the large
    // icon as a bitmap. So we need to create that here from the resource ID, and pass the
    // object along in our notification builder. Generally, you want to use the app icon as the
    // small icon, so that users understand what app is triggering this notification.
    Bitmap largeIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.art_storm);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.art_clear).setLargeIcon(largeIcon).setContentTitle("Weather Alert!")
            .setStyle(new NotificationCompat.BigTextStyle().bigText(message)).setContentText(message)
            .setPriority(NotificationCompat.PRIORITY_HIGH);
    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}

From source file:com.lillicoder.newsblurry.feeds.FeedParser.java

/**
 * Gets the default {@link Favicon} for feeds.
 * @return Default feed {@link Favicon}.
 *///from  ww  w .j  a v  a2s.  co m
private Favicon getDefaultFeedFavicon() {
    Favicon defaultFavicon = null;

    Context context = this.getContext();
    Resources resources = context.getResources();
    Bitmap defaultFaviconImage = BitmapFactory.decodeResource(resources, DEFAULT_FEED_FAVICON_RESOURCE);

    if (defaultFaviconImage != null)
        defaultFavicon = new Favicon(defaultFaviconImage);

    return defaultFavicon;
}

From source file:br.ajmarques.cordova.plugin.localnotification.Receiver.java

/**
 * Erstellt die Notification./*from  w w w .java 2 s  .c  om*/
 */
private NotificationCompat.Builder buildNotification() {
    Bitmap icon = BitmapFactory.decodeResource(context.getResources(), options.getIcon());

    NotificationCompat.Builder notification = new NotificationCompat.Builder(context)
            .setContentTitle(options.getTitle()).setContentText(options.getMessage())
            .setNumber(options.getBadge()).setTicker(options.getTitle()).setSmallIcon(options.getSmallIcon())
            .setLargeIcon(icon).setSound(options.getSound()).setAutoCancel(options.getAutoCancel());

    /*
    Builder notification = new Notification.Builder(context)
    .setContentTitle(options.getTitle())
    .setContentText(options.getMessage())
    .setNumber(options.getBadge())
    .setTicker(options.getTitle())
    .setSmallIcon(options.getSmallIcon())
    .setLargeIcon(icon)
    .setSound(options.getSound())
    .setAutoCancel(options.getAutoCancel());
    */
    setClickEvent(notification);

    return notification;
}

From source file:com.example.vendrisample.HelloEffects.java

License:asdf

private void loadTextures() {
    // Generate textures
    GLES20.glGenTextures(2, mTextures, 0);

    // Load input bitmap
    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.vendri);
    mImageWidth = bitmap.getWidth();/* w  w w. j a  va  2  s.  c  o  m*/
    mImageHeight = bitmap.getHeight();
    mTexRenderer.updateTextureSize(mImageWidth, mImageHeight);

    // Upload to texture
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextures[0]);
    GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);

    // Set texture parameters
    GLToolbox.initTexParams();
}

From source file:de.dmxcontrol.device.Entity.java

public Bitmap getImage(Context context) {
    try {/* ww  w . j  a  v a2 s. c o m*/
        File imgFile = new File(ImageStorageName + File.separator + mImage);
        if (imgFile.isFile()) {
            if (imgFile.exists()) {
                Bitmap bmp = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
                if (bmp.getHeight() > 128 || bmp.getWidth() > 128) {
                    bmp = Bitmap.createScaledBitmap(bmp, 128, 128, false);
                }
                return bmp;
            }
        }
    } catch (Exception e) {
    }
    // Replace this icon with something else
    return BitmapFactory.decodeResource(context.getResources(), R.drawable.device_new);
}

From source file:com.portfolio.course.esguti.goubiquitous.mobile.gcm.MyGcmListenerService.java

/**
 *  Put the message into a notification and post it.
 *  This is just one simple example of what you might choose to do with a GCM message.
 *
 * @param message The alert message to be posted.
 *//*from   w w  w  .j  a  v  a 2  s .  c  o m*/
private void sendNotification(String message) {
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);

    // Notifications using both a large and a small icon (which yours should!) need the large
    // icon as a bitmap. So we need to create that here from the resource ID, and pass the
    // object along in our notification builder. Generally, you want to use the com.portfolio.course.esguti.goubiquitous.mobile icon as the
    // small icon, so that users understand what com.portfolio.course.esguti.goubiquitous.mobile is triggering this notification.
    Bitmap largeIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.art_storm);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.art_clear).setLargeIcon(largeIcon).setContentTitle("Weather Alert!")
            .setStyle(new NotificationCompat.BigTextStyle().bigText(message)).setContentText(message)
            .setPriority(NotificationCompat.PRIORITY_HIGH);
    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}