Search in sources :

Example 16 with CacheableBitmapDrawable

use of uk.co.senab.bitmapcache.CacheableBitmapDrawable in project Talon-for-Twitter by klinker24.

the class NotificationUtils method getIcon.

public static Bitmap getIcon(Context context, int[] unreadCount, String screenname) {
    int homeTweets = unreadCount[0];
    int mentionsTweets = unreadCount[1];
    int dmTweets = unreadCount[2];
    boolean customPic = (mentionsTweets == 1 && homeTweets == 0 && dmTweets == 0) || (dmTweets == 1 && homeTweets == 0 && mentionsTweets == 0);
    if (screenname != null && customPic) {
        BitmapLruCache mCache = App.getInstance(context).getBitmapCache();
        Log.v("notifications_talon", "in screenname");
        String url;
        try {
            url = Utils.getTwitter(context, AppSettings.getInstance(context)).showUser(screenname).getBiggerProfileImageURL();
            CacheableBitmapDrawable wrapper = mCache.get(url + "_notification");
            Log.v("notifications_talon", "got wrapper");
            if (wrapper == null) {
                Log.v("notifications_talon", "wrapper null");
                URL mUrl = new URL(url);
                Bitmap image = BitmapFactory.decodeStream(mUrl.openConnection().getInputStream());
                image = ImageUtils.notificationResize(context, image);
                mCache.put(url + "_notification", image);
                return image;
            } else {
                return wrapper.getBitmap();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_stat_icon);
}
Also used : BitmapLruCache(uk.co.senab.bitmapcache.BitmapLruCache) Bitmap(android.graphics.Bitmap) CacheableBitmapDrawable(uk.co.senab.bitmapcache.CacheableBitmapDrawable) URL(java.net.URL)

Aggregations

CacheableBitmapDrawable (uk.co.senab.bitmapcache.CacheableBitmapDrawable)16 View (android.view.View)9 NetworkedCacheableImageView (com.klinker.android.twitter.views.NetworkedCacheableImageView)8 Intent (android.content.Intent)7 Bitmap (android.graphics.Bitmap)7 URL (java.net.URL)7 TweetPager (com.klinker.android.twitter.activities.tweet_viewer.TweetPager)5 BufferedInputStream (java.io.BufferedInputStream)5 InputStream (java.io.InputStream)5 HttpURLConnection (java.net.HttpURLConnection)5 Handler (android.os.Handler)3 Spannable (android.text.Spannable)3 ImageView (android.widget.ImageView)3 PhotoViewerActivity (com.klinker.android.twitter.activities.photo_viewer.PhotoViewerActivity)3 ProfilePager (com.klinker.android.twitter.activities.profile_viewer.ProfilePager)3 LayoutInflater (android.view.LayoutInflater)2 AbsListView (android.widget.AbsListView)2 LinearLayout (android.widget.LinearLayout)2 TextView (android.widget.TextView)2 PhotoPagerActivity (com.klinker.android.twitter.activities.photo_viewer.PhotoPagerActivity)2