Search in sources :

Example 61 with Bitmap

use of android.graphics.Bitmap in project Talon-for-Twitter by klinker24.

the class WidgetViewsFactory method getCachedPic.

public Bitmap getCachedPic(String url) {
    CacheableBitmapDrawable wrapper = mCache.get(url);
    if (wrapper == null) {
        try {
            URL mUrl = new URL(url);
            Bitmap image = BitmapFactory.decodeStream(mUrl.openConnection().getInputStream());
            if (settings.roundContactImages) {
                image = ImageUtils.getCircle(image, mContext);
            }
            wrapper = mCache.put(url, image);
        } catch (Exception e) {
        }
    }
    return wrapper.getBitmap();
}
Also used : Bitmap(android.graphics.Bitmap) CacheableBitmapDrawable(uk.co.senab.bitmapcache.CacheableBitmapDrawable) URL(java.net.URL)

Example 62 with Bitmap

use of android.graphics.Bitmap in project Talon-for-Twitter by klinker24.

the class WearTransactionActivity method onMessageReceived.

@Override
public void onMessageReceived(MessageEvent messageEvent) {
    if (messageEvent.getPath().equals(KeyProperties.PATH)) {
        final DataMap map = DataMap.fromByteArray(messageEvent.getData());
        if (map.containsKey(KeyProperties.KEY_USER_NAME)) {
            names = map.getStringArrayList(KeyProperties.KEY_USER_NAME);
            screennames = map.getStringArrayList(KeyProperties.KEY_USER_SCREENNAME);
            bodies = map.getStringArrayList(KeyProperties.KEY_TWEET);
            ids = map.getStringArrayList(KeyProperties.KEY_ID);
            sharedPreferences.edit().putInt(KeyProperties.KEY_PRIMARY_COLOR, map.getInt(KeyProperties.KEY_PRIMARY_COLOR)).putInt(KeyProperties.KEY_ACCENT_COLOR, map.getInt(KeyProperties.KEY_ACCENT_COLOR)).commit();
            Log.v(TAG, "found " + names.size() + " tweets");
            handler.post(new Runnable() {

                @Override
                public void run() {
                    updateDisplay();
                }
            });
        } else {
            new Thread(new Runnable() {

                @Override
                public void run() {
                    byte[] imageData = map.getByteArray(KeyProperties.KEY_IMAGE_DATA);
                    String imageName = map.getString(KeyProperties.KEY_IMAGE_NAME);
                    Bitmap bitmap = BitmapFactory.decodeByteArray(imageData, 0, imageData.length);
                    File file = new File(getCacheDir(), imageName);
                    IoUtils utils = new IoUtils();
                    try {
                        utils.cacheBitmap(bitmap, file);
                    } catch (Exception e) {
                        Log.v(TAG, "error caching bitmap", e);
                    }
                }
            }).start();
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) File(java.io.File) IoUtils(com.klinker.android.twitter.util.IoUtils)

Example 63 with Bitmap

use of android.graphics.Bitmap in project android-gif-drawable by koral--.

the class TexturePlaceholderFragment method onDrawPlaceholder.

@Override
public void onDrawPlaceholder(Canvas canvas) {
    final Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
    canvas.drawBitmap(bitmap, 0, 0, null);
    bitmap.recycle();
}
Also used : Bitmap(android.graphics.Bitmap)

Example 64 with Bitmap

use of android.graphics.Bitmap in project ion by koush.

the class FileLoader method loadBitmap.

@Override
public Future<BitmapInfo> loadBitmap(final Context context, final Ion ion, final String key, final String uri, final int resizeWidth, final int resizeHeight, final boolean animateGif) {
    if (uri == null || !uri.startsWith("file:/"))
        return null;
    final SimpleFuture<BitmapInfo> ret = new SimpleFuture<BitmapInfo>();
    //        Log.d("FileLoader", "Loading file bitmap " + uri + " " + resizeWidth + "," + resizeHeight);
    Ion.getBitmapLoadExecutorService().execute(new Runnable() {

        @Override
        public void run() {
            if (ret.isCancelled()) {
                //                    Log.d("FileLoader", "Bitmap load cancelled (no longer needed)");
                return;
            }
            try {
                File file = new File(URI.create(uri));
                BitmapFactory.Options options = ion.getBitmapCache().prepareBitmapOptions(file, resizeWidth, resizeHeight);
                Point size = new Point(options.outWidth, options.outHeight);
                BitmapInfo info;
                if (animateGif && TextUtils.equals("image/gif", options.outMimeType)) {
                    FileInputStream fin = new FileInputStream(file);
                    try {
                        info = loadGif(key, size, fin, options);
                    } finally {
                        StreamUtility.closeQuietly(fin);
                    }
                } else {
                    Bitmap bitmap = IonBitmapCache.loadBitmap(file, options);
                    if (bitmap == null)
                        throw new Exception("Bitmap failed to load");
                    info = new BitmapInfo(key, options.outMimeType, bitmap, size);
                }
                info.servedFrom = ResponseServedFrom.LOADED_FROM_CACHE;
                ret.setComplete(info);
            } catch (OutOfMemoryError e) {
                ret.setComplete(new Exception(e), null);
            } catch (Exception e) {
                ret.setComplete(e);
            }
        }
    });
    return ret;
}
Also used : Bitmap(android.graphics.Bitmap) Point(android.graphics.Point) File(java.io.File) BitmapInfo(com.koushikdutta.ion.bitmap.BitmapInfo) FileInputStream(java.io.FileInputStream) SimpleFuture(com.koushikdutta.async.future.SimpleFuture)

Example 65 with Bitmap

use of android.graphics.Bitmap in project ion by koush.

the class PackageIconLoader method loadBitmap.

@Override
public Future<BitmapInfo> loadBitmap(Context context, final Ion ion, final String key, final String uri, int resizeWidth, int resizeHeight, boolean animateGif) {
    if (uri == null || !uri.startsWith("package:"))
        return null;
    final SimpleFuture<BitmapInfo> ret = new SimpleFuture<BitmapInfo>();
    Ion.getBitmapLoadExecutorService().execute(new Runnable() {

        @Override
        public void run() {
            try {
                final URI request = URI.create(uri);
                String pkg = request.getHost();
                PackageManager pm = ion.getContext().getPackageManager();
                Bitmap bmp = ((BitmapDrawable) pm.getPackageInfo(pkg, 0).applicationInfo.loadIcon(pm)).getBitmap();
                if (bmp == null)
                    throw new Exception("package icon failed to load");
                BitmapInfo info = new BitmapInfo(key, null, bmp, new Point(bmp.getWidth(), bmp.getHeight()));
                info.servedFrom = ResponseServedFrom.LOADED_FROM_CACHE;
                ret.setComplete(info);
            } catch (Exception e) {
                ret.setComplete(e);
            }
        }
    });
    return ret;
}
Also used : Bitmap(android.graphics.Bitmap) PackageManager(android.content.pm.PackageManager) Point(android.graphics.Point) URI(java.net.URI) BitmapInfo(com.koushikdutta.ion.bitmap.BitmapInfo) SimpleFuture(com.koushikdutta.async.future.SimpleFuture)

Aggregations

Bitmap (android.graphics.Bitmap)3746 Canvas (android.graphics.Canvas)889 Paint (android.graphics.Paint)709 BitmapDrawable (android.graphics.drawable.BitmapDrawable)461 IOException (java.io.IOException)394 Rect (android.graphics.Rect)341 File (java.io.File)262 Test (org.junit.Test)255 Matrix (android.graphics.Matrix)254 Drawable (android.graphics.drawable.Drawable)243 BitmapFactory (android.graphics.BitmapFactory)240 View (android.view.View)225 ImageView (android.widget.ImageView)210 Intent (android.content.Intent)187 FileOutputStream (java.io.FileOutputStream)186 InputStream (java.io.InputStream)171 RectF (android.graphics.RectF)150 FileNotFoundException (java.io.FileNotFoundException)150 Point (android.graphics.Point)148 Uri (android.net.Uri)128