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:ar.com.martinrevert.argenteam.GcmIntentService.java

public Bitmap getRemoteImage(final String aURL, String tipo) {
    try {/* www.j av  a2 s  . c o  m*/
        if (aURL.isEmpty()) {
            if (tipo.equals("movie")) {
                return BitmapFactory.decodeResource(this.getResources(), R.drawable.stubportrait);
            } else {

                return BitmapFactory.decodeResource(this.getResources(), R.drawable.stublandscape);

            }
        }
        URL imagelink = new URL(aURL);
        final URLConnection conn = imagelink.openConnection();
        conn.connect();
        final BufferedInputStream bis = new BufferedInputStream(conn.getInputStream());
        BitmapFactory.Options options = new BitmapFactory.Options();
        final Bitmap scaledBitmap = BitmapFactory.decodeStream(bis, null, options);
        bis.close();
        return scaledBitmap;
    } catch (IOException e) {
        e.printStackTrace();

    }
    return null;
}

From source file:cl.chihau.holaauto.MessagingService.java

private void sendNotificationForConversation(int conversationId, String sender, String message,
        long timestamp) {
    // A pending Intent for reads
    PendingIntent readPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), conversationId,
            getMessageReadIntent(conversationId), PendingIntent.FLAG_UPDATE_CURRENT);

    /// Add the code to create the UnreadConversation
    // Build a RemoteInput for receiving voice input in a Car Notification
    RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).build();

    // Building a Pending Intent for the reply action to trigger
    PendingIntent replyIntent = PendingIntent.getBroadcast(getApplicationContext(), conversationId,
            getMessageReplyIntent(conversationId), PendingIntent.FLAG_UPDATE_CURRENT);

    // Create the UnreadConversation and populate it with the participant name,
    // read and reply intents.
    NotificationCompat.CarExtender.UnreadConversation.Builder unreadConversationBuilder = new NotificationCompat.CarExtender.UnreadConversation.Builder(
            sender).setLatestTimestamp(timestamp).setReadPendingIntent(readPendingIntent)
                    .setReplyAction(replyIntent, remoteInput);

    // Note: Add messages from oldest to newest to the UnreadConversation.Builder
    // Since we are sending a single message here we simply add the message.
    // In a real world application there could be multiple messages which should be ordered
    // and added from oldest to newest.
    unreadConversationBuilder.addMessage(message);

    /// End create UnreadConversation

    NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext())
            .setSmallIcon(R.drawable.notification_icon)
            .setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(),
                    R.drawable.android_contact))
            .setContentText(message).setWhen(timestamp).setContentTitle(sender)
            .setContentIntent(readPendingIntent).setContentIntent(readPendingIntent)
            /// Extend the notification with CarExtender.
            .extend(new NotificationCompat.CarExtender()
                    .setUnreadConversation(unreadConversationBuilder.build()))
    /// End//from  w  w w  .  j  a  v  a2s  .c o  m
    ;

    Log.d(TAG, "Sending notification " + conversationId + " conversation: " + message);

    NotificationManagerCompat.from(this).notify(conversationId, builder.build());
}

From source file:com.app.chasebank.contactslist.util.ImageLoader.java

/**
 * Set placeholder bitmap that shows when the the background thread is running.
 *
 * @param resId Resource ID of loading image.
 *//*from  ww  w  . jav a 2  s  . c o m*/
public void setLoadingImage(int resId) {
    //use the one we have already
    mLoadingBitmap = BitmapFactory.decodeResource(mResources, resId);
}

From source file:com.irccloud.android.activity.PreferencesActivity.java

@SuppressWarnings("deprecation")
@Override//  w ww  .  j a v  a2s.  c o m
public void onCreate(Bundle icicle) {
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    super.onCreate(icicle);
    getDelegate().installViewFactory();
    getDelegate().onCreate(icicle);
    if (Build.VERSION.SDK_INT >= 21) {
        Bitmap cloud = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
        setTaskDescription(new ActivityManager.TaskDescription(getResources().getString(R.string.app_name),
                cloud, 0xFFF2F7FC));
        cloud.recycle();
    }
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.actionbar_prefs);

    Toolbar toolbar = (Toolbar) findViewById(R.id.actionbar);
    toolbar.setTitle(getTitle());
    toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });

    toolbar.setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar));

    if (Build.VERSION.SDK_INT >= 21)
        toolbar.setElevation(0);

    conn = NetworkConnection.getInstance();
    addPreferencesFromResource(R.xml.preferences_account);
    addPreferencesFromResource(R.xml.preferences_display);
    addPreferencesFromResource(R.xml.preferences_device);
    addPreferencesFromResource(R.xml.preferences_photos);
    addPreferencesFromResource(R.xml.preferences_notifications);
    addPreferencesFromResource(R.xml.preferences_dashclock);
    findPreference("dashclock_showmsgs").setOnPreferenceChangeListener(dashclocktoggle);
    try {
        int pebbleVersion = getPackageManager().getPackageInfo("com.getpebble.android", 0).versionCode;
        if (pebbleVersion < 553)
            addPreferencesFromResource(R.xml.preferences_pebble);
    } catch (Exception e) {
    }
    boolean foundSony = false;
    try {
        getPackageManager().getPackageInfo("com.sonyericsson.extras.liveware", 0);
        addPreferencesFromResource(R.xml.preferences_sony);
        foundSony = true;
    } catch (Exception e) {
    }
    if (!foundSony) {
        try {
            getPackageManager().getPackageInfo("com.sonyericsson.extras.smartwatch", 0);
            addPreferencesFromResource(R.xml.preferences_sony);
            foundSony = true;
        } catch (Exception e) {
        }
    }
    if (!foundSony) {
        try {
            getPackageManager().getPackageInfo("com.sonyericsson.extras.liveview", 0);
            addPreferencesFromResource(R.xml.preferences_sony);
            foundSony = true;
        } catch (Exception e) {
        }
    }
    if (foundSony)
        findPreference("notify_sony").setOnPreferenceChangeListener(sonytoggle);
    if (BuildConfig.DEBUG)
        addPreferencesFromResource(R.xml.preferences_debug);
    addPreferencesFromResource(R.xml.preferences_about);
    findPreference("name").setOnPreferenceChangeListener(settingstoggle);

    findPreference("autoaway").setOnPreferenceChangeListener(settingstoggle);
    findPreference("time-24hr").setOnPreferenceChangeListener(prefstoggle);
    findPreference("time-seconds").setOnPreferenceChangeListener(prefstoggle);
    findPreference("mode-showsymbol").setOnPreferenceChangeListener(prefstoggle);
    findPreference("pastebin-disableprompt").setOnPreferenceChangeListener(prefstoggle);
    if (findPreference("emoji-disableconvert") != null) {
        findPreference("emoji-disableconvert").setOnPreferenceChangeListener(prefstoggle);
        findPreference("emoji-disableconvert").setSummary(":thumbsup:  \uD83D\uDC4D");
    }
    findPreference("nick-colors").setOnPreferenceChangeListener(prefstoggle);
    findPreference("faq").setOnPreferenceClickListener(urlClick);
    findPreference("feedback").setOnPreferenceClickListener(urlClick);
    findPreference("licenses").setOnPreferenceClickListener(licensesClick);
    findPreference("imageviewer").setOnPreferenceChangeListener(imageviewertoggle);
    findPreference("imgur_account_username").setOnPreferenceClickListener(imgurClick);
    //findPreference("subscriptions").setOnPreferenceClickListener(urlClick);
    //findPreference("changes").setOnPreferenceClickListener(urlClick);
    findPreference("notify_type").setOnPreferenceChangeListener(notificationstoggle);
    findPreference("notify_led_color").setOnPreferenceChangeListener(ledtoggle);
    findPreference("photo_size").setOnPreferenceChangeListener(photosizetoggle);

    imgurPreference = findPreference("imgur_account_username");
    if (NetworkConnection.getInstance().uploadsAvailable()) {
        if (!PreferenceManager.getDefaultSharedPreferences(this).getString("image_service", "IRCCloud")
                .equals("imgur")) {
            PreferenceCategory c = (PreferenceCategory) findPreference("photos");
            c.removePreference(imgurPreference);
        }
        findPreference("image_service").setOnPreferenceChangeListener(imageservicetoggle);
    } else {
        PreferenceCategory c = (PreferenceCategory) findPreference("photos");
        c.removePreference(findPreference("image_service"));
    }

    try {
        final String version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
        findPreference("version").setSummary(version);
        findPreference("version").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
                    android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(
                            CLIPBOARD_SERVICE);
                    clipboard.setText(version);
                } else {
                    @SuppressLint("ServiceCast")
                    android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(
                            CLIPBOARD_SERVICE);
                    android.content.ClipData clip = android.content.ClipData.newPlainText("IRCCloud Version",
                            version);
                    clipboard.setPrimaryClip(clip);
                }
                Toast.makeText(PreferencesActivity.this, "Version number copied to clipboard",
                        Toast.LENGTH_SHORT).show();
                return false;
            }
        });
    } catch (NameNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

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

@Override
public void onCreate() {
    settings = new AppSettings(this);
    mDb = new ScrobblesDatabase(this);
    mDb.open();//from  www.  j a  va  2 s .  com
    mNetManager = new NetworkerManager(this, mDb);

    int sdk = Build.VERSION.SDK_INT;
    if (sdk == Build.VERSION_CODES.GINGERBREAD || sdk == Build.VERSION_CODES.GINGERBREAD_MR1) {

        String ar = "";
        String tr = "";
        String api = "";
        if (mCurrentTrack != null) {
            ar = mCurrentTrack.getArtist();
            tr = mCurrentTrack.getTrack();
            api = mCurrentTrack.getMusicAPI().readAPIname();
        }

        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(ar)
                .setSmallIcon(R.mipmap.ic_notify).setContentText(tr + " : " + api)
                .setContentIntent(contentIntent);

        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB_MR2) {
            builder.setLargeIcon(BitmapFactory.decodeResource(mCtx.getResources(), R.mipmap.ic_launcher));
        }

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

        if (!settings.isNotifyEnabled(Util.checkPower(mCtx))) {
            Intent iNoti = new Intent(mCtx, ForegroundHide.class);
            this.startService(iNoti);
        }
    }
}

From source file:com.campusconnect.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *//*  www  . j a  v a 2 s.c o m*/
private void sendNotification(String title, String messageBody, String type, String id) {
    Intent intent = new Intent(this, HomeActivity2.class);
    Log.i("sw32notification", id + ":" + type + ":" + messageBody);

    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.setAction(Long.toString(System.currentTimeMillis()));
    intent.putExtra("pendingIntentAction", "Clear Notifications");
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    inboxStyle = new NotificationCompat.InboxStyle();
    int i = 0;
    for (CustomNotification customNotification : new ArrayList<>(
            CustomNotification.listAll(CustomNotification.class))) {
        Log.i("sw32", "here notification");
        i++;
        inboxStyle.addLine(customNotification.getTitle() + " - " + customNotification.getMessageBody());
    }
    inboxStyle.setSummaryText("Campus Connect");
    notificationBuilder.setSmallIcon(R.mipmap.ccnoti)
            .setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(), R.mipmap.ccnoti))
            .setContentTitle("Campus Connect").setContentText(i + " New notifications").setStyle(inboxStyle)
            .setGroup(CC).setGroupSummary(true).setSound(defaultSoundUri).setAutoCancel(true)
            .setContentIntent(pendingIntent);

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.notify(notifyId /*(int) System.currentTimeMillis()*/ /* ID of notification */,
            notificationBuilder.build());

}

From source file:alaindc.crowdroid.GeofenceTransitionsIntentService.java

/**
 * Posts a notification in the notification bar when a transition is detected.
 * If the user clicks the notification, control goes to the MainActivity.
 *///from w w w  . j a  v a 2s.  com
private void sendNotification(String nameofsensor) {
    // Create an explicit content Intent that starts the main Activity.
    Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class);

    // Construct a task stack.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    // Add the main Activity to the task stack as the parent.
    stackBuilder.addParentStack(MainActivity.class);

    // Push the content Intent onto the stack.
    stackBuilder.addNextIntent(notificationIntent);

    // Get a PendingIntent containing the entire back stack.
    PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Get a notification builder that's compatible with platform versions >= 4
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

    // Define the notification settings.
    builder.setSmallIcon(R.drawable.icon)
            // In a real app, you may want to use a library like Volley
            // to decode the Bitmap.
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.icon)).setColor(Color.RED)
            .setContentTitle("Geofence Crowdroid").setContentText("Geofence Trigger: " + nameofsensor)
            .setContentIntent(notificationPendingIntent);

    // Dismiss notification once the user touches it.
    builder.setAutoCancel(true);

    // Get an instance of the Notification manager
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    // Issue the notification
    mNotificationManager.notify(0, builder.build());
}

From source file:com.android.project.imagefetcher.ImageWorker.java

public void loadImage(Object data, ImageView imageView, int resId) {
    if (!loadingBitmaps.containsKey(resId)) {
        // Store loading bitmap in a hash table to prevent continual
        // decoding
        loadingBitmaps.put(resId, BitmapFactory.decodeResource(mResources, resId));
    }//from   w ww.ja  va2  s . c  o m
    setLoadingImage(loadingBitmaps.get(resId));
    loadImage(data, imageView);
}

From source file:com.mappn.gfan.ui.SplashActivity.java

private void initSplashBg() {

    File splashFile = new File(getApplicationContext().getCacheDir(), "splash.png");

    if (splashFile.exists()) {
        Bitmap bmp = BitmapFactory.decodeFile(splashFile.getAbsolutePath());
        if (bmp != null) {
            setSplashBitmap(bmp);/*w  w w  .  j a v a2  s . co  m*/
            return;
        }
    }
    // Splash
    setSplashBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.splash));
    mSession.setSplashTime(0);
}

From source file:ca.ualberta.trinkettrader.Inventory.Trinket.Pictures.Picture.java

/**
 * Creates a new picture from a file stored on the elasticsearch server.
 *
 * @param filename         filename of the picture stored on the server
 * @param directoryManager directory manager that can be used to store the picture
 * @param activity         android activity used to get the application's context
 *//*from  w w w .  java2  s  .c  o  m*/
public Picture(String filename, PictureDirectoryManager directoryManager, Activity activity)
        throws IOException, PackageManager.NameNotFoundException {
    this.directoryManager = directoryManager;
    this.filename = filename;
    // poitroae; http://stackoverflow.com/questions/8717333/converting-drawable-resource-image-into-bitmap; 2015-11-25
    Bitmap placeholder = BitmapFactory.decodeResource(activity.getResources(), R.drawable.placeholder);
    this.file = directoryManager.compressPicture(this.filename, placeholder);
    // \u00d3scar L\u00f3pez; http://stackoverflow.com/questions/8721262/how-to-get-file-size-in-java; 2015-11-04
    pictureByteArray = new byte[(int) this.file.length()];
    int result = 0;
    while (result == 0) {
        result = new FileInputStream(this.file).read(pictureByteArray);
    }
    this.observers = new HashSet<>();
}