List of usage examples for android.graphics.drawable BitmapDrawable getBitmap
public final Bitmap getBitmap()
From source file:com.gtx.cooliris.imagecache.ImageCache.java
/** * Adds a bitmap to both memory and disk cache. * @param data Unique identifier for the bitmap to store * @param value The bitmap drawable to store */// w w w .j a v a 2s . co m public void addBitmapToCache(String data, BitmapDrawable value) { if (data == null || value == null) { return; } // Add to memory cache if (mMemoryCache != null) { if (RecyclingBitmapDrawable.class.isInstance(value)) { // The removed entry is a recycling drawable, so notify it // that it has been added into the memory cache ((RecyclingBitmapDrawable) value).setIsCached(true); } mMemoryCache.put(data, value); } synchronized (mDiskCacheLock) { // Add to disk cache if (mDiskLruCache != null) { final String key = hashKeyForDisk(data); OutputStream out = null; try { DiskLruCache.Snapshot snapshot = mDiskLruCache.get(key); if (snapshot == null) { final DiskLruCache.Editor editor = mDiskLruCache.edit(key); if (editor != null) { out = editor.newOutputStream(DISK_CACHE_INDEX); value.getBitmap().compress(mCacheParams.compressFormat, mCacheParams.compressQuality, out); editor.commit(); out.close(); } } else { snapshot.getInputStream(DISK_CACHE_INDEX).close(); } } catch (final IOException e) { LogUtil.e(TAG, "addBitmapToCache - " + e); } catch (Exception e) { LogUtil.e(TAG, "addBitmapToCache - " + e); } finally { try { if (out != null) { out.close(); } } catch (IOException e) { } } } } }
From source file:com.rsegismont.androlife.common.utils.ImageCacher.java
/** * Initialize the cache, providing all parameters. * // w w w . java 2 s .c o m * @param cacheParams * The cache parameters to initialize the cache */ @SuppressLint("UseSparseArrays") private void init(ImageCacheParams cacheParams) { mCacheParams = cacheParams; // Set up memory cache if (mCacheParams.memoryCacheEnabled) { if (BuildConfig.DEBUG) { Log.d(TAG, "Memory cache created (size = " + mCacheParams.memCacheSize + ")"); } // If we're running on Honeycomb or newer, then if (Utils.hasHoneycomb()) { mReusableBitmaps = new ConcurrentSkipListMap<Integer, SoftReference<Bitmap>>(); } mMemoryCacheSize = new HashMap<String, Point>(); mMemoryCacheData = new LruCache<String, BitmapDrawable>(mCacheParams.memCacheSize) { /** * Notify the removed entry that is no longer being cached */ @Override protected void entryRemoved(boolean evicted, String key, BitmapDrawable oldValue, BitmapDrawable newValue) { if (RecyclingBitmapDrawable.class.isInstance(oldValue)) { // The removed entry is a recycling drawable, so notify // it // that it has been removed from the memory cache ((RecyclingBitmapDrawable) oldValue).setIsCached(false); } else { // The removed entry is a standard BitmapDrawable if (Utils.hasHoneycomb()) { // We're running on Honeycomb or later, so add the // bitmap // to a SoftRefrence set for possible use with // inBitmap later synchronized (mMemCacheLock) { if (evicted == true) { mReusableBitmaps.put(getBitmapSize(oldValue), new SoftReference<Bitmap>(oldValue.getBitmap())); } } } } } /** * Measure item size in kilobytes rather than units which is * more practical for a bitmap cache */ @Override protected int sizeOf(String key, BitmapDrawable value) { final int bitmapSize = getBitmapSize(value) / 1024; return bitmapSize == 0 ? 1 : bitmapSize; } }; } // By default the disk cache is not initialized here as it should be // initialized // on a separate thread due to disk access. if (cacheParams.initDiskCacheOnCreate) { // Set up disk cache initDiskCache(); } }
From source file:com.corebase.android.bitmap.util.ImageCache.java
/** * Initialize the cache, providing all parameters. * /*from w w w . j av a 2 s .c o m*/ * @param cacheParams * The cache parameters to initialize the cache */ private void init(ImageCacheParams cacheParams) { mCacheParams = cacheParams; // Set up memory cache if (mCacheParams.memoryCacheEnabled) { // If we're running on Honeycomb or newer, then if (Utils.hasHoneycomb()) { // mReusableBitmaps = new HashSet<SoftReference<Bitmap>>(); // mReusableBitmaps = Collections.synchronizedSet(new // HashSet<SoftReference<Bitmap>>()); mReusableBitmaps = new ConcurrentHashMap<String, SoftReference<Bitmap>>(); } mMemoryCache = new LruCache<String, BitmapDrawable>(mCacheParams.memCacheSize) { /** * Notify the removed entry that is no longer being cached */ @Override protected void entryRemoved(boolean evicted, String key, BitmapDrawable oldValue, BitmapDrawable newValue) { if (RecyclingBitmapDrawable.class.isInstance(oldValue)) { // The removed entry is a recycling drawable, so notify // it // that it has been removed from the memory cache ((RecyclingBitmapDrawable) oldValue).setIsCached(false); } else { // The removed entry is a standard BitmapDrawable if (Utils.hasHoneycomb()) { // We're running on Honeycomb or later, so add the // bitmap // to a SoftRefrence set for possible use with // inBitmap later // mReusableBitmaps.add(new // SoftReference<Bitmap>(oldValue.getBitmap())); mReusableBitmaps.put(key, new SoftReference<Bitmap>(oldValue.getBitmap())); } } } /** * Measure item size in kilobytes rather than units which is * more practical for a bitmap cache */ @Override protected int sizeOf(String key, BitmapDrawable value) { final int bitmapSize = getBitmapSize(value) / 1024; return bitmapSize == 0 ? 1 : bitmapSize; } }; } // By default the disk cache is not initialized here as it should be // initialized // on a separate thread due to disk access. if (cacheParams.initDiskCacheOnCreate) { // Set up disk cache Logs.v(TAG, "init disk cache ..."); initDiskCache(); } }
From source file:com.ferdi2005.secondgram.voip.VoIPService.java
private void showNotification() { Intent intent = new Intent(this, VoIPActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP); Notification.Builder builder = new Notification.Builder(this) .setContentTitle(LocaleController.getString("VoipOutgoingCall", R.string.VoipOutgoingCall)) .setContentText(ContactsController.formatName(user.first_name, user.last_name)) .setSmallIcon(R.drawable.notification) .setContentIntent(PendingIntent.getActivity(this, 0, intent, 0)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { Intent endIntent = new Intent(); endIntent.setAction(getPackageName() + ".END_CALL"); endIntent.putExtra("end_hash", endHash = Utilities.random.nextInt()); builder.addAction(R.drawable.ic_call_end_white_24dp, LocaleController.getString("VoipEndCall", R.string.VoipEndCall), PendingIntent.getBroadcast(this, 0, endIntent, PendingIntent.FLAG_UPDATE_CURRENT)); builder.setPriority(Notification.PRIORITY_MAX); }//from w w w . j ava 2 s . c o m if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { builder.setShowWhen(false); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setColor(0xff2ca5e0); } if (user.photo != null) { TLRPC.FileLocation photoPath = user.photo.photo_small; if (photoPath != null) { BitmapDrawable img = ImageLoader.getInstance().getImageFromMemory(photoPath, null, "50_50"); if (img != null) { builder.setLargeIcon(img.getBitmap()); } else { try { float scaleFactor = 160.0f / AndroidUtilities.dp(50); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = scaleFactor < 1 ? 1 : (int) scaleFactor; Bitmap bitmap = BitmapFactory .decodeFile(FileLoader.getPathToAttach(photoPath, true).toString(), options); if (bitmap != null) { builder.setLargeIcon(bitmap); } } catch (Throwable e) { FileLog.e(e); } } } } ongoingCallNotification = builder.getNotification(); startForeground(ID_ONGOING_CALL_NOTIFICATION, ongoingCallNotification); }
From source file:com.ifeng.util.imagecache.ImageCache.java
/** * Initialize the cache, providing all parameters. * /*from w w w .java 2s.co m*/ * @param cacheParams * The cache parameters to initialize the cache */ private void init(ImageCacheParams cacheParams) { mCacheParams = cacheParams; // Set up memory cache if (mCacheParams.memoryCacheEnabled) { if (BuildConfig.DEBUG) { Log.d(TAG, "Memory cache created (size = " + mCacheParams.memCacheSize + ")"); } // If we're running on Honeycomb or newer, then if (Utils.hasHoneycomb()) { mReusableBitmaps = new HashSet<SoftReference<Bitmap>>(); } if (sMemoryCache == null) { sMemoryCache = new LruCache<String, BitmapDrawable>(mCacheParams.memCacheSize) { /** * Notify the removed entry that is no longer being cached */ @Override protected void entryRemoved(boolean evicted, String key, BitmapDrawable oldValue, BitmapDrawable newValue) { if (RecyclingBitmapDrawable.class.isInstance(oldValue)) { // The removed entry is a recycling drawable, so // notify // it // that it has been removed from the memory cache ((RecyclingBitmapDrawable) oldValue).setIsCached(false); } else { // The removed entry is a standard BitmapDrawable if (Utils.hasHoneycomb()) { // We're running on Honeycomb or later, so add // the // bitmap // to a SoftRefrence set for possible use with // inBitmap later mReusableBitmaps.add(new SoftReference<Bitmap>(oldValue.getBitmap())); } } } /** * Measure item size in kilobytes rather than units which is * more practical for a bitmap cache */ @Override protected int sizeOf(String key, BitmapDrawable value) { final int bitmapSize = getBitmapSize(value) / 1024; return bitmapSize == 0 ? 1 : bitmapSize; } }; } } // By default the disk cache is not initialized here as it should be // initialized // on a separate thread due to disk access. if (cacheParams.initDiskCacheOnCreate) { // Set up disk cache initDiskCache(); } }
From source file:com.jasper.image.imagemanager.imagehelper.imageEngine.ImageCache.java
public void addBitmapToCache(String data, BitmapDrawable value) { // BEGIN_INCLUDE(add_bitmap_to_cache) if (data == null || value == null) { return;//from w w w. j ava2 s. c o m } if (mMemoryCache != null) { if (RecyclingBitmapDrawable.class.isInstance(value)) { // The removed entry is a recycling drawable, so notify it // that it has been added into the memory cache ((RecyclingBitmapDrawable) value).setIsCached(true); } mMemoryCache.put(data, value); } synchronized (mDiskCacheLock) { // Add to disk cache if (mDiskLruCache != null) { final String key = hashKeyForDisk(data); OutputStream out = null; try { DiskLruCache.Snapshot snapshot = mDiskLruCache.get(key); if (snapshot == null) { final DiskLruCache.Editor editor = mDiskLruCache.edit(key); if (editor != null) { out = editor.newOutputStream(DISK_CACHE_INDEX); value.getBitmap().compress(mCacheParams.compressFormat, mCacheParams.compressQuality, out); editor.commit(); out.close(); } } else { snapshot.getInputStream(DISK_CACHE_INDEX).close(); } } catch (final IOException e) { Log.e(TAG, "addBitmapToCache - " + e); } catch (Exception e) { Log.e(TAG, "addBitmapToCache - " + e); } finally { try { if (out != null) { out.close(); } } catch (IOException e) { } } } } // END_INCLUDE(add_bitmap_to_cache) }
From source file:android.bitmap.util.ImageCache.java
/** * Adds a bitmap to both memory and disk cache. * @param data Unique identifier for the bitmap to store * @param value The bitmap drawable to store *//*from w w w.jav a2 s . co m*/ public void addBitmapToCache(String data, BitmapDrawable value) { if (data == null || value == null) { return; } // Add to memory cache if (mMemoryCache != null) { if (RecyclingBitmapDrawable.class.isInstance(value)) { // The removed entry is a recycling drawable, so notify it // that it has been added into the memory cache ((RecyclingBitmapDrawable) value).setIsCached(true); } mMemoryCache.put(data, value); } synchronized (mDiskCacheLock) { // Add to disk cache if (mDiskLruCache != null) { final String key = hashKeyForDisk(data); OutputStream out = null; try { DiskLruCache.Snapshot snapshot = mDiskLruCache.get(key); if (snapshot == null) { final DiskLruCache.Editor editor = mDiskLruCache.edit(key); if (editor != null) { out = editor.newOutputStream(DISK_CACHE_INDEX); value.getBitmap().compress(mCacheParams.compressFormat, mCacheParams.compressQuality, out); editor.commit(); out.close(); } } else { snapshot.getInputStream(DISK_CACHE_INDEX).close(); } } catch (final IOException e) { Log.e(TAG, "addBitmapToCache - " + e); } catch (Exception e) { Log.e(TAG, "addBitmapToCache - " + e); } finally { try { if (out != null) { out.close(); } } catch (IOException e) { } } } } }
From source file:com.hataskrau.utils.image.ImageCache.java
/** * Adds a bitmap to both memory and disk cache. * * @param data Unique identifier for the bitmap to store * @param value The bitmap drawable to store *//* www .ja va 2 s . c o m*/ public void addBitmapToCache(String data, BitmapDrawable value) { //BEGIN_INCLUDE(add_bitmap_to_cache) if (data == null || value == null) { return; } // Add to memory cache if (mMemoryCache != null) { if (RecyclingBitmapDrawable.class.isInstance(value)) { // The removed entry is a recycling drawable, so notify it // that it has been added into the memory cache ((RecyclingBitmapDrawable) value).setIsCached(true); } mMemoryCache.put(data, value); } synchronized (mDiskCacheLock) { // Add to disk cache if (mDiskLruCache != null) { final String key = hashKeyForDisk(data); OutputStream out = null; try { DiskLruCache.Snapshot snapshot = mDiskLruCache.get(key); if (snapshot == null) { final DiskLruCache.Editor editor = mDiskLruCache.edit(key); if (editor != null) { out = editor.newOutputStream(DISK_CACHE_INDEX); value.getBitmap().compress(mCacheParams.compressFormat, mCacheParams.compressQuality, out); editor.commit(); out.close(); } } else { snapshot.getInputStream(DISK_CACHE_INDEX).close(); } } catch (final IOException e) { } catch (Exception e) { } finally { try { if (out != null) { out.close(); } } catch (IOException e) { } } } } //END_INCLUDE(add_bitmap_to_cache) }
From source file:com.test.displaybitmaps.imagemanager.ImageCache.java
/** * Adds a bitmap to both memory and disk cache. * //from w ww . j a v a2 s . co m * @param data * Unique identifier for the bitmap to store * @param imageSize * @param value * The bitmap drawable to store */ public void addBitmapToCache(String data, ImageSize imageSize, BitmapDrawable value) { // BEGIN_INCLUDE(add_bitmap_to_cache) if (data == null || value == null) { return; } // concat data + imageSize data += imageSize.getSize(); // Add to memory cache if (mMemoryCache != null) { if (RecyclingBitmapDrawable.class.isInstance(value)) { // The removed entry is a recycling drawable, so notify it // that it has been added into the memory cache ((RecyclingBitmapDrawable) value).setIsCached(true); } mMemoryCache.put(data, value); } synchronized (mDiskCacheLock) { // Add to disk cache if (mDiskLruCache != null) { final String key = hashKeyForDisk(data); OutputStream out = null; try { DiskLruCache.Snapshot snapshot = mDiskLruCache.get(key); if (snapshot == null) { final DiskLruCache.Editor editor = mDiskLruCache.edit(key); if (editor != null) { out = editor.newOutputStream(DISK_CACHE_INDEX); value.getBitmap().compress(mCacheParams.compressFormat, mCacheParams.compressQuality, out); editor.commit(); out.close(); } } else { snapshot.getInputStream(DISK_CACHE_INDEX).close(); } } catch (final IOException e) { Log.e(TAG, "addBitmapToCache - " + e); } catch (Exception e) { Log.e(TAG, "addBitmapToCache - " + e); } finally { try { if (out != null) { out.close(); } } catch (IOException e) { } } } } // END_INCLUDE(add_bitmap_to_cache) }
From source file:com.android.simpleimageloader.image.ImageCache.java
/** * Adds a bitmap to both memory and disk cache. * /*from w ww . j a v a 2s. c om*/ * @param data Unique identifier for the bitmap to store * @param value The bitmap drawable to store */ public void addBitmapToCache(String data, BitmapDrawable value, DisplayOptions options) { // BEGIN_INCLUDE(add_bitmap_to_cache) if (data == null || value == null) { return; } // Add to memory cache if (mMemoryCache != null) { if (RecyclingBitmapDrawable.class.isInstance(value)) { // The removed entry is a recycling drawable, so notify it // that it has been added into the memory cache ((RecyclingBitmapDrawable) value).setIsCached(true); } mMemoryCache.put(data, value); } synchronized (mDiskCacheLock) { // Add to disk cache if (mDiskLruCache != null) { final String key = hashKeyForDisk(data); OutputStream out = null; try { DiskLruCache.Snapshot snapshot = mDiskLruCache.get(key); if (snapshot == null) { final DiskLruCache.Editor editor = mDiskLruCache.edit(key); if (editor != null) { out = editor.newOutputStream(DISK_CACHE_INDEX); value.getBitmap().compress(options.mCompressFormat, options.mCompressQuality, out); editor.commit(); out.close(); } } else { snapshot.getInputStream(DISK_CACHE_INDEX).close(); } } catch (final IOException e) { Log.e(TAG, "addBitmapToCache - " + e); } catch (Exception e) { Log.e(TAG, "addBitmapToCache - " + e); } finally { try { if (out != null) { out.close(); } } catch (IOException e) { } } } } // END_INCLUDE(add_bitmap_to_cache) }