List of usage examples for android.graphics.drawable BitmapDrawable getBitmap
public final Bitmap getBitmap()
From source file:com.android.example.notificationshowcase.NotificationService.java
@Override protected void onHandleIntent(Intent intent) { ArrayList<Notification> mNotifications = new ArrayList<Notification>(); NotificationManager noMa = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); int bigtextId = mNotifications.size(); mNotifications.add(makeBigTextNotification(this, 0, bigtextId, System.currentTimeMillis())); int uploadId = mNotifications.size(); long uploadWhen = System.currentTimeMillis(); mNotifications.add(makeUploadNotification(this, 10, uploadWhen)); Notification phoneCall = new NotificationCompat.Builder(this).setContentTitle("Incoming call") .setContentText("Matias Duarte").setLargeIcon(getBitmap(this, R.drawable.matias_hed)) .setSmallIcon(R.drawable.stat_sys_phone_call).setDefaults(Notification.DEFAULT_SOUND) .setPriority(NotificationCompat.PRIORITY_MAX) .setContentIntent(ToastService.getPendingIntent(this, "Clicked on Matias")) .addAction(R.drawable.ic_dial_action_call, "Answer", ToastService.getPendingIntent(this, "call answered")) .addAction(R.drawable.ic_end_call, "Ignore", ToastService.getPendingIntent(this, "call ignored")) .setAutoCancel(true).build(); phoneCall.flags |= Notification.FLAG_INSISTENT; mNotifications.add(phoneCall);/*from w w w. j a v a 2 s. c om*/ mNotifications.add( new NotificationCompat.Builder(this).setContentTitle("Stopwatch PRO").setContentText("Counting up") .setContentIntent(ToastService.getPendingIntent(this, "Clicked on Stopwatch")) .setSmallIcon(R.drawable.stat_notify_alarm).setUsesChronometer(true).build()); mNotifications.add( new NotificationCompat.Builder(this).setContentTitle("J Planning").setContentText("The Botcave") .setWhen(System.currentTimeMillis()).setSmallIcon(R.drawable.stat_notify_calendar) .setContentIntent(ToastService.getPendingIntent(this, "Clicked on calendar event")) .setContentInfo("7PM") .addAction(R.drawable.stat_notify_snooze, "+10 min", ToastService.getPendingIntent(this, "snoozed 10 min")) .addAction(R.drawable.stat_notify_snooze_longer, "+1 hour", ToastService.getPendingIntent(this, "snoozed 1 hr")) .addAction(R.drawable.stat_notify_email, "Email", makeEmailIntent(this, "gabec@example.com,mcleron@example.com,dsandler@example.com")) .build()); BitmapDrawable d = (BitmapDrawable) getResources().getDrawable(R.drawable.romainguy_rockaway); mNotifications.add(new NotificationCompat.BigPictureStyle(new NotificationCompat.Builder(this) .setContentTitle("Romain Guy") .setContentText("I was lucky to find a Canon 5D Mk III at a local Bay Area " + "store last week but I had not been able to try it in the field " + "until tonight. After a few days of rain the sky finally cleared " + "up. Rockaway Beach did not disappoint and I was finally able to " + "see what my new camera feels like when shooting landscapes.") .setSmallIcon(R.drawable.ic_stat_gplus) .setContentIntent(ToastService.getPendingIntent(this, "Clicked on bigPicture")) .setLargeIcon(getBitmap(this, R.drawable.romainguy_hed)) .addAction(R.drawable.add, "Add to Gallery", ToastService.getPendingIntent(this, "added! (just kidding)")) .setSubText("talk rocks!")).bigPicture(d.getBitmap()).build()); // Note: this may conflict with real email notifications StyleSpan bold = new StyleSpan(Typeface.BOLD); SpannableString line1 = new SpannableString("Alice: hey there!"); line1.setSpan(bold, 0, 5, 0); SpannableString line2 = new SpannableString("Bob: hi there!"); line2.setSpan(bold, 0, 3, 0); SpannableString line3 = new SpannableString("Charlie: Iz IN UR EMAILZ!!"); line3.setSpan(bold, 0, 7, 0); mNotifications.add(new NotificationCompat.InboxStyle( new NotificationCompat.Builder(this).setContentTitle("24 new messages") .setContentText("You have mail!").setSubText("test.hugo2@gmail.com") .setContentIntent(ToastService.getPendingIntent(this, "Clicked on Email")) .setSmallIcon(R.drawable.stat_notify_email)).setSummaryText("+21 more").addLine(line1) .addLine(line2).addLine(line3).build()); mNotifications .add(new NotificationCompat.Builder(this).setContentTitle("Twitter").setContentText("New mentions") .setContentIntent(ToastService.getPendingIntent(this, "Clicked on Twitter")) .setSmallIcon(R.drawable.twitter_icon).setNumber(15) .setPriority(NotificationCompat.PRIORITY_LOW).build()); for (int i = 0; i < mNotifications.size(); i++) { noMa.notify(NOTIFICATION_ID + i, mNotifications.get(i)); } ProgressService.startProgressUpdater(this, uploadId, uploadWhen, 0); }
From source file:com.alfd.app.utils.ImageCache.java
/** * Initialize the cache, providing all parameters. * * @param cacheParams The cache parameters to initialize the cache *//*ww w .ja va2 s . c o m*/ private void init(ImageCacheParams cacheParams) { mCacheParams = cacheParams; //BEGIN_INCLUDE(init_memory_cache) // 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, create a set of reusable bitmaps that can be // populated into the inBitmap field of BitmapFactory.Options. Note that the set is // of SoftReferences which will actually not be very effective due to the garbage // collector being aggressive clearing Soft/WeakReferences. A better approach // would be to use a strongly references bitmaps, however this would require some // balancing of memory usage between this set and the bitmap LruCache. It would also // require knowledge of the expected size of the bitmaps. From Honeycomb to JellyBean // the size would need to be precise, from KitKat onward the size would just need to // be the upper bound (due to changes in how inBitmap can re-use bitmaps). if (Utils.hasHoneycomb()) { mReusableBitmaps = Collections.synchronizedSet(new HashSet<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 SoftReference 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; } }; } //END_INCLUDE(init_memory_cache) }
From source file:com.allwinner.theatreplayer.launcher.activity.LaunchActivity.java
@SuppressWarnings("unchecked") private void setCellDate() { if (mCellInfoList == null || mCellViews == null) { return;//w w w. ja v a2 s . c o m } int listCount = mCellInfoList.size(); if (Constants.CELL_COUNT >= listCount) { CellInfo cellInfo = null; CellViews cellViews = null; ArrayList<CellInfo> cloneList = (ArrayList<CellInfo>) mCellInfoList.clone(); // Log.i("jim", "cloneList.size() = "+cloneList.size()); for (int i = 0; i < listCount; i++) { cellInfo = cloneList.get(i); cellViews = mCellViews.get(i); if (cellInfo != null) { if (cellViews != null && cellViews.iLayout != null) { if (cellInfo.type == 4) { cellViews.iLayout.setVisibility(View.INVISIBLE); } else if (cellInfo.type == 3) { cellViews.iLayout.setVisibility(View.GONE); } } if (cellInfo.type == 4 && !LoadApplicationInfo.isInstalled(this, cellInfo.packageName)) { mCellInfoList.remove(cellInfo); } } } cloneList.clear(); cloneList = null; listCount = mCellInfoList.size(); } for (int i = 0; i < listCount; i++) { CellInfo cellInfo = mCellInfoList.get(i); CellViews cellViews = mCellViews.get(i); if (cellViews != null && cellViews.iLayout != null) { cellViews.iLayout.setTag(cellInfo); cellViews.iLayout.setVisibility(View.VISIBLE); if (!mIsFiveLayout && cellInfo.type == 3 && !LoadApplicationInfo.isInstalled(this, cellInfo.packageName)) { cellViews.iLayout.setVisibility(View.GONE); } if (cellInfo.backgroundPic != null && !cellInfo.backgroundPic.equals("")) { BitmapDrawable bitmapDrawable = (BitmapDrawable) ImageUtils.getShortcutIconFromSys(this, cellInfo.backgroundPic); if (bitmapDrawable != null) { Bitmap bitmap = bitmapDrawable.getBitmap(); cellViews.iLayout.setImageBitmap(bitmap); } } else if (cellInfo.backgroundColour != null && !cellInfo.backgroundColour.equals("")) { cellViews.iLayout.setBackgroundColor(Color.parseColor(cellInfo.backgroundColour)); } // if (i != 0) { // if(cellInfo.packageName.equals("com.vst.live.allwinner")){ // Log.i("jim", "55555555555======"+cellInfo.packageName); // // } Drawable iconDrawable = null; if (cellInfo.icon != null && !cellInfo.icon.equals("")) { iconDrawable = ImageUtils.getShortcutIconFromSys(this, cellInfo.icon); } if (iconDrawable == null && cellInfo.type == 4) { iconDrawable = ImageUtils.getAppIcon(cellInfo.packageName, this); } if (iconDrawable != null && cellViews.iconView != null) { cellViews.iconView.setImageDrawable(iconDrawable); } if (cellViews.textView != null) { cellViews.textView.setText(cellInfo.title); } // } if (cellViews.imgView != null) { Bitmap bitmap = ImageUtils.loadImageFromLocat(this, cellInfo.className); if (bitmap == null) { bitmap = ImageUtils.getBitmapByPicName(this, "img_" + cellInfo.className); } if (bitmap != null) { cellViews.imgView.setImageBitmap(bitmap); } } } } }
From source file:com.geecko.QuickLyric.fragment.LyricsViewFragment.java
private void showFirstStart() { stopRefreshAnimation();/* w ww .j a v a 2 s . c om*/ LayoutInflater inflater = LayoutInflater.from(getActivity()); ViewGroup parent = (ViewGroup) ((ViewGroup) getActivity().findViewById(R.id.scrollview)).getChildAt(0); if (parent.findViewById(R.id.tracks_msg) == null) inflater.inflate(R.layout.no_tracks, parent); TypedValue typedValue = new TypedValue(); getActivity().getTheme().resolveAttribute(R.attr.firstLaunchCoverDrawable, typedValue, true); int firstLaunchBGid = typedValue.resourceId; @SuppressWarnings("deprecation") BitmapDrawable bd = ((BitmapDrawable) getResources().getDrawable(firstLaunchBGid)); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity()); setCoverArt(bd != null ? bd.getBitmap() : null, null); ((TextSwitcher) getActivity().findViewById(R.id.switcher)).setText(""); int themeNum = Integer.valueOf(sharedPref.getString("pref_theme", "0")); if (themeNum > 0 && themeNum != 7) { TypedValue darkColorValue = new TypedValue(); getActivity().getTheme().resolveAttribute(R.attr.colorPrimaryDark, darkColorValue, true); ((FadeInNetworkImageView) getActivity().findViewById(R.id.cover)).setColorFilter(darkColorValue.data, PorterDuff.Mode.OVERLAY); } getActivity().findViewById(R.id.error_msg).setVisibility(View.INVISIBLE); ((TextView) getActivity().findViewById(R.id.artist)).setText(""); ((TextView) getActivity().findViewById(R.id.song)).setText(""); getActivity().findViewById(R.id.top_gradient).setVisibility(View.INVISIBLE); getActivity().findViewById(R.id.bottom_gradient).setVisibility(View.INVISIBLE); getActivity().findViewById(R.id.edit_tags_btn).setVisibility(View.INVISIBLE); }
From source file:org.telepatch.android.NotificationsController.java
/** * Qui lui crea le notifiche//from ww w .j a v a 2 s. co m */ private void showOrUpdateNotification(boolean notifyAboutLast) { if (!UserConfig.isClientActivated() || pushMessages.isEmpty()) { dismissNotification(); return; } try { ConnectionsManager.getInstance().resumeNetworkMaybe(); MessageObject lastMessageObject = pushMessages.get(0); long dialog_id = lastMessageObject.getDialogId(); int mid = lastMessageObject.messageOwner.id; int chat_id = lastMessageObject.messageOwner.to_id.chat_id; int user_id = lastMessageObject.messageOwner.to_id.user_id; if (user_id == 0) { user_id = lastMessageObject.messageOwner.from_id; } else if (user_id == UserConfig.getClientUserId()) { user_id = lastMessageObject.messageOwner.from_id; } TLRPC.User user = MessagesController.getInstance().getUser(user_id); TLRPC.Chat chat = null; if (chat_id != 0) { chat = MessagesController.getInstance().getChat(chat_id); } TLRPC.FileLocation photoPath = null; boolean notifyDisabled = false; int needVibrate = 0; String choosenSoundPath = null; int ledColor = 0xff00ff00; boolean inAppSounds = false; boolean inAppVibrate = false; boolean inAppPreview = false; int vibrate_override = 0; int notify_override = preferences.getInt("notify2_" + dialog_id, 0); if (!notifyAboutLast || notify_override == 2 || (!preferences.getBoolean("EnableAll", true) || chat_id != 0 && !preferences.getBoolean("EnableGroup", true)) && notify_override == 0) { notifyDisabled = true; } String defaultPath = Settings.System.DEFAULT_NOTIFICATION_URI.getPath(); if (!notifyDisabled) { inAppSounds = preferences.getBoolean("EnableInAppSounds", true); inAppVibrate = preferences.getBoolean("EnableInAppVibrate", true); inAppPreview = preferences.getBoolean("EnableInAppPreview", true); vibrate_override = preferences.getInt("vibrate_" + dialog_id, 0); choosenSoundPath = preferences.getString("sound_path_" + dialog_id, null); if (chat_id != 0) { if (choosenSoundPath != null && choosenSoundPath.equals(defaultPath)) { choosenSoundPath = null; } else if (choosenSoundPath == null) { choosenSoundPath = preferences.getString("GroupSoundPath", defaultPath); } needVibrate = preferences.getInt("vibrate_group", 0); ledColor = preferences.getInt("GroupLed", 0xff00ff00); } else if (user_id != 0) { if (choosenSoundPath != null && choosenSoundPath.equals(defaultPath)) { choosenSoundPath = null; } else if (choosenSoundPath == null) { choosenSoundPath = preferences.getString("GlobalSoundPath", defaultPath); } needVibrate = preferences.getInt("vibrate_messages", 0); ledColor = preferences.getInt("MessagesLed", 0xff00ff00); } if (preferences.contains("color_" + dialog_id)) { ledColor = preferences.getInt("color_" + dialog_id, 0); } if (needVibrate == 2 && (vibrate_override == 1 || vibrate_override == 3 || vibrate_override == 5) || needVibrate != 2 && vibrate_override == 2 || vibrate_override != 0) { needVibrate = vibrate_override; } if (!ApplicationLoader.mainInterfacePaused) { if (!inAppSounds) { choosenSoundPath = null; } if (!inAppVibrate) { needVibrate = 2; } } } Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class); intent.setAction("com.tmessages.openchat" + Math.random() + Integer.MAX_VALUE); intent.setFlags(32768); if ((int) dialog_id != 0) { if (pushDialogs.size() == 1) { if (chat_id != 0) { intent.putExtra("chatId", chat_id); } else if (user_id != 0) { intent.putExtra("userId", user_id); } } if (pushDialogs.size() == 1) { if (chat != null) { if (chat.photo != null && chat.photo.photo_small != null && chat.photo.photo_small.volume_id != 0 && chat.photo.photo_small.local_id != 0) { photoPath = chat.photo.photo_small; } } else { if (user.photo != null && user.photo.photo_small != null && user.photo.photo_small.volume_id != 0 && user.photo.photo_small.local_id != 0) { photoPath = user.photo.photo_small; } } } } else { if (pushDialogs.size() == 1) { intent.putExtra("encId", (int) (dialog_id >> 32)); } } PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent, PendingIntent.FLAG_ONE_SHOT); String name = null; boolean replace = true; if ((int) dialog_id == 0 || pushDialogs.size() > 1) { name = LocaleController.getString("AppName", R.string.AppName); replace = false; } else { if (chat != null) { name = chat.title; } else { name = ContactsController.formatName(user.first_name, user.last_name); } } String detailText = null; if (pushDialogs.size() == 1) { detailText = LocaleController.formatPluralString("NewMessages", total_unread_count); } else { detailText = LocaleController.formatString("NotificationMessagesPeopleDisplayOrder", R.string.NotificationMessagesPeopleDisplayOrder, LocaleController.formatPluralString("NewMessages", total_unread_count), LocaleController.formatPluralString("FromContacts", pushDialogs.size())); } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder( ApplicationLoader.applicationContext).setContentTitle(name) .setSmallIcon(R.drawable.notification).setAutoCancel(true).setNumber(total_unread_count) .setContentIntent(contentIntent).setGroup("messages") .setGroupSummary(true); String lastMessage = null; String lastMessageFull = null; if (pushMessages.size() == 1) { String message = lastMessageFull = getStringForMessage(pushMessages.get(0), false); //lastMessage = getStringForMessage(pushMessages.get(0), true); lastMessage = lastMessageFull; if (message == null) { return; } if (replace) { if (chat != null) { message = message.replace(" @ " + name, ""); } else { message = message.replace(name + ": ", "").replace(name + " ", ""); } } mBuilder.setContentText(message); mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(message)); } else { mBuilder.setContentText(detailText); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle(name); int count = Math.min(10, pushMessages.size()); for (int i = 0; i < count; i++) { String message = getStringForMessage(pushMessages.get(i), false); if (message == null) { continue; } if (i == 0) { lastMessageFull = message; //lastMessage = getStringForMessage(pushMessages.get(i), true); lastMessage = lastMessageFull; } if (pushDialogs.size() == 1) { if (replace) { if (chat != null) { message = message.replace(" @ " + name, ""); } else { message = message.replace(name + ": ", "").replace(name + " ", ""); } } } inboxStyle.addLine(message); } inboxStyle.setSummaryText(detailText); mBuilder.setStyle(inboxStyle); } if (photoPath != null) { BitmapDrawable img = ImageLoader.getInstance().getImageFromMemory(photoPath, null, "50_50", null); if (img != null) { mBuilder.setLargeIcon(img.getBitmap()); } } if (!notifyDisabled) { if (ApplicationLoader.mainInterfacePaused || inAppPreview) { if (lastMessage.length() > 100) { lastMessage = lastMessage.substring(0, 100).replace("\n", " ").trim() + "..."; } mBuilder.setTicker(lastMessage); } if (choosenSoundPath != null && !choosenSoundPath.equals("NoSound")) { if (choosenSoundPath.equals(defaultPath)) { /*MediaPlayer mediaPlayer = new MediaPlayer(); mediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM); mediaPlayer.setDataSource(ApplicationLoader.applicationContext, Settings.System.DEFAULT_NOTIFICATION_URI); mediaPlayer.prepare(); mediaPlayer.start();*/ mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI, AudioManager.STREAM_NOTIFICATION); } else { mBuilder.setSound(Uri.parse(choosenSoundPath), AudioManager.STREAM_NOTIFICATION); } } if (ledColor != 0) { mBuilder.setLights(ledColor, 1000, 1000); } if (needVibrate == 2) { mBuilder.setVibrate(new long[] { 0, 0 }); } else if (needVibrate == 1) { mBuilder.setVibrate(new long[] { 0, 100, 0, 100 }); } else if (needVibrate == 0 || needVibrate == 4) { mBuilder.setDefaults(NotificationCompat.DEFAULT_VIBRATE); } else if (needVibrate == 3) { mBuilder.setVibrate(new long[] { 0, 1000 }); } } else { mBuilder.setVibrate(new long[] { 0, 0 }); } notificationManager.notify(1, mBuilder.build()); if (preferences.getBoolean("EnablePebbleNotifications", false)) { sendAlertToPebble(lastMessageFull); } showWearNotifications(notifyAboutLast); scheduleNotificationRepeat(); } catch (Exception e) { FileLog.e("tmessages", e); } }
From source file:com.android.simpleimageloader.image.ImageCache.java
/** * Initialize the cache, providing all parameters. * /*from w ww .j a va 2 s . co m*/ * @param cacheParams The cache parameters to initialize the cache */ private void init(ImageCacheParams cacheParams) { mCacheParams = cacheParams; // BEGIN_INCLUDE(init_memory_cache) // Set up memory cache if (BuildConfig.DEBUG) { Log.d(TAG, "Memory cache created (size = " + mCacheParams.memCacheSize + ")"); } // If we're running on Honeycomb or newer, create a set of reusable bitmaps that can be // populated into the inBitmap field of BitmapFactory.Options. Note that the set is // of SoftReferences which will actually not be very effective due to the garbage // collector being aggressive clearing Soft/WeakReferences. A better approach // would be to use a strongly references bitmaps, however this would require some // balancing of memory usage between this set and the bitmap LruCache. It would also // require knowledge of the expected size of the bitmaps. From Honeycomb to JellyBean // the size would need to be precise, from KitKat onward the size would just need to // be the upper bound (due to changes in how inBitmap can re-use bitmaps). if (Utils.hasHoneycomb()) { mReusableBitmaps = Collections.synchronizedSet(new HashSet<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 SoftReference 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; } }; // END_INCLUDE(init_memory_cache) initDiskCache(); }
From source file:com.lovebridge.chat.view.ImageCache.java
/** * Initialize the cache, providing all parameters. * * @param cacheParams The cache parameters to initialize the cache *///from w w w . j ava 2 s. co m private void init(ImageCacheParams cacheParams) { mCacheParams = cacheParams; // BEGIN_INCLUDE(init_memory_cache) // 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, create a set of reusable // bitmaps that can be // populated into the inBitmap field of BitmapFactory.Options. Note // that the set is // of SoftReferences which will actually not be very effective due // to the garbage // collector being aggressive clearing Soft/WeakReferences. A better // approach // would be to use a strongly references bitmaps, however this would // require some // balancing of memory usage between this set and the bitmap // LruCache. It would also // require knowledge of the expected size of the bitmaps. From // Honeycomb to JellyBean // the size would need to be precise, from KitKat onward the size // would just need to // be the upper bound (due to changes in how inBitmap can re-use // bitmaps). if (com.lovebridge.chat.utils.Utils.hasHoneycomb()) { mReusableBitmaps = Collections.synchronizedSet(new HashSet<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 (com.lovebridge.chat.utils.Utils.hasHoneycomb()) { // We're running on Honeycomb or later, so add the // bitmap // to a SoftReference 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; } }; } }
From source file:com.hataskrau.utils.image.ImageCache.java
/** * Initialize the cache, providing all parameters. * * @param cacheParams The cache parameters to initialize the cache *///from ww w .j av a2 s .c om private void init(ImageCacheParams cacheParams) { mCacheParams = cacheParams; //BEGIN_INCLUDE(init_memory_cache) // Set up memory cache if (mCacheParams.memoryCacheEnabled) { // If we're running on Honeycomb or newer, create a set of reusable bitmaps that can be // populated into the inBitmap field of BitmapFactory.Options. Note that the set is // of SoftReferences which will actually not be very effective due to the garbage // collector being aggressive clearing Soft/WeakReferences. A better approach // would be to use a strongly references bitmaps, however this would require some // balancing of memory usage between this set and the bitmap LruCache. It would also // require knowledge of the expected size of the bitmaps. From Honeycomb to JellyBean // the size would need to be precise, from KitKat onward the size would just need to // be the upper bound (due to changes in how inBitmap can re-use bitmaps). mReusableBitmaps = Collections.synchronizedSet(new HashSet<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 // We're running on Honeycomb or later, so add the bitmap // to a SoftReference 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; } }; } //END_INCLUDE(init_memory_cache) // 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.xuwakao.mixture.framework.image.ImageCache.java
/** * Initialize the cache, providing all parameters. * * @param cacheParams The cache parameters to initialize the cache *//* www.j a va2s.c om*/ private void init(ImageCacheParams cacheParams) { mCacheParams = cacheParams; // Set up memory cache if (mCacheParams.memoryCacheEnabled) { MLog.debug(TAG, "Memory cache created (size = " + mCacheParams.memCacheSize + ")"); // If we're running on Honeycomb or newer, then if (Utils.hasHoneycomb()) { mReusableBitmaps = new HashSet<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())); } } } /** * 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.yuedu.image.ImageCache.java
/** * Initialize the cache, providing all parameters. * * @param cacheParams The cache parameters to initialize the cache *///www . ja v a2 s. co m 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>>(); } 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())); } } } /** * 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(); } }