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();
}
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();
}
}
}
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();
}
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;
}
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;
}
Aggregations