List of usage examples for android.graphics.drawable BitmapDrawable BitmapDrawable
private BitmapDrawable(BitmapState state, Resources res)
From source file:com.mods.grx.settings.utils.Utils.java
public static Drawable get_drawable_from_path(Context contex, String path) { Drawable tmp = null;/*from w w w . java2 s.co m*/ try { File f_i = new File(path); if (f_i.exists() && f_i.canRead()) { FileInputStream i_s = new FileInputStream(f_i); tmp = new BitmapDrawable(contex.getResources(), BitmapFactory.decodeStream(i_s)); i_s.close(); } } catch (Exception e) { Toast.makeText(contex, e.getMessage(), Toast.LENGTH_SHORT).show(); } return tmp; }
From source file:com.android.contacts.common.list.ShortcutIntentBuilder.java
private Drawable getPhotoDrawable(byte[] bitmapData, String displayName, String lookupKey) { if (bitmapData != null) { Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapData, 0, bitmapData.length, null); return new BitmapDrawable(mContext.getResources(), bitmap); } else {/*w ww. j a v a2s. co m*/ return ContactPhotoManager.getDefaultAvatarDrawableForContact(mContext.getResources(), false, new DefaultImageRequest(displayName, lookupKey, false)); } }
From source file:com.native5.plugins.ActionBarPlugin.java
private Drawable getDrawableForURI(String uri_string) { Uri uri = Uri.parse(uri_string);/*from w ww . j av a 2 s. c o m*/ Activity ctx = (Activity) cordova; // Special case - TrueType fonts if (uri_string.endsWith(".ttf")) { /*for(String base: bases) { String path = base + uri; // TODO: Font load / glyph rendering ("/blah/fontawesome.ttf:\f1234") }*/ } // General bitmap else { if (uri.isAbsolute()) { if (uri.getScheme().startsWith("http")) { try { URL url = new URL(uri_string); InputStream stream = url.openConnection().getInputStream(); return new BitmapDrawable(ctx.getResources(), stream); } catch (MalformedURLException e) { return null; } catch (IOException e) { return null; } catch (Exception e) { return null; } } else { try { InputStream stream = ctx.getContentResolver().openInputStream(uri); return new BitmapDrawable(ctx.getResources(), stream); } catch (FileNotFoundException e) { return null; } } } else { for (String base : bases) { String path = base + uri; // Asset if (base.startsWith("file:///android_asset/")) { path = path.substring(22); try { InputStream stream = ctx.getAssets().open(path); return new BitmapDrawable(ctx.getResources(), stream); } catch (IOException e) { continue; } } // General URI else { try { InputStream stream = ctx.getContentResolver().openInputStream(Uri.parse(path)); return new BitmapDrawable(ctx.getResources(), stream); } catch (FileNotFoundException e) { continue; } } } } } return null; }
From source file:cn.edu.nju.dapenti.activity.MainActivity.java
private void selectDrawerItem(int position) { mCurrentDrawerPos = position;/*from w ww . j a va 2 s .c o m*/ mIcon = null; Uri newUri; boolean showFeedInfo = true; switch (position) { case 0: newUri = FeedData.EntryColumns.CONTENT_URI; break; case 1: newUri = FeedData.EntryColumns.FAVORITES_CONTENT_URI; break; default: long feedOrGroupId = mDrawerAdapter.getItemId(position); if (mDrawerAdapter.isItemAGroup(position)) { newUri = FeedData.EntryColumns.ENTRIES_FOR_GROUP_CONTENT_URI(feedOrGroupId); } else { byte[] iconBytes = mDrawerAdapter.getItemIcon(position); if (iconBytes != null && iconBytes.length > 0) { int bitmapSizeInDip = UiUtils.dpToPixel(24); Bitmap bitmap = BitmapFactory.decodeByteArray(iconBytes, 0, iconBytes.length); if (bitmap != null) { if (bitmap.getHeight() != bitmapSizeInDip) { bitmap = Bitmap.createScaledBitmap(bitmap, bitmapSizeInDip, bitmapSizeInDip, false); } mIcon = new BitmapDrawable(getResources(), bitmap); } } newUri = FeedData.EntryColumns.ENTRIES_FOR_FEED_CONTENT_URI(feedOrGroupId); showFeedInfo = false; } mTitle = mDrawerAdapter.getItemName(position); break; } if (!newUri.equals(mEntriesFragment.getUri())) { mEntriesFragment.setData(newUri, showFeedInfo); } mDrawerList.setItemChecked(position, true); // First open => we open the drawer for you if (PrefUtils.getBoolean(PrefUtils.FIRST_OPEN, true)) { PrefUtils.putBoolean(PrefUtils.FIRST_OPEN, false); mDrawerLayout.postDelayed(new Runnable() { @Override public void run() { mDrawerLayout.openDrawer(mDrawerList); } }, 500); } }
From source file:com.hunch.ImageManager.java
protected Drawable getDrawableFromMemoryCache(final Context context, final URL url) { SoftReference<Bitmap> drawableRef = drawableMap.get(url); if (drawableRef != null) { // the key exists Bitmap image = drawableRef.get(); if (image != null) { Log.v(Const.TAG, "found image in memory cache (" + fileNameFromURL(url) + ")"); // the image hasn't been gc'd yet. return new BitmapDrawable(context.getResources(), image); } else {//w ww .j a v a 2 s. co m // the drawable has been gc'd, remove the key drawableMap.remove(url); } } return null; }
From source file:com.dunrite.xpaper.utility.Utils.java
/** * Creates drawable for the wallpaper/*from w w w . j a v a2 s . co m*/ * @param context current app context * @param foreground foreground drawable * @param bgColor color of background * @param fgColor color of foreground * @param isPreview if this is for the preview or not * @return the final, constructed wallpaper */ public static Drawable constructWallpaper(Context context, Drawable foreground, int bgColor, int fgColor, boolean isPreview) { final int WIDTH = 2560; final int HEIGHT = 1440; Canvas comboImage; Bitmap cs, fg; Paint fgPaint = new Paint(); //create bitmap from foreground drawable fg = ((BitmapDrawable) foreground).getBitmap(); if (isPreview) cs = Bitmap.createBitmap(WIDTH / 2, HEIGHT / 2, Bitmap.Config.ARGB_8888); else cs = Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.ARGB_8888); comboImage = new Canvas(cs); fgPaint.setFilterBitmap(false); fgPaint.setColorFilter(new PorterDuffColorFilter(fgColor, PorterDuff.Mode.SRC_ATOP)); comboImage.drawRGB(Color.red(bgColor), Color.green(bgColor), Color.blue(bgColor)); if (isPreview) comboImage.drawBitmap(Bitmap.createScaledBitmap(fg, WIDTH / 2, HEIGHT / 2, true), 0, 0, fgPaint); else comboImage.drawBitmap(fg, 0, 0, fgPaint); return new BitmapDrawable(context.getResources(), cs); }
From source file:com.android.contacts.ShortcutIntentBuilder.java
private Drawable getPhotoDrawable(byte[] bitmapData, String displayName, String lookupKey) { if (bitmapData != null) { Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapData, 0, bitmapData.length, null); return new BitmapDrawable(mContext.getResources(), bitmap); } else {/*from ww w . j a v a 2 s . c o m*/ final DefaultImageRequest request = new DefaultImageRequest(displayName, lookupKey, false); if (BuildCompat.isAtLeastO()) { // On O, scale the image down to add the padding needed by AdaptiveIcons. request.scale = LetterTileDrawable.getAdaptiveIconScale(); } return ContactPhotoManager.getDefaultAvatarDrawableForContact(mContext.getResources(), false, request); } }
From source file:com.fatelon.partyphotobooth.setup.fragments.EventInfoSetupFragment.java
/** * Loads the event logo from cache and updates ui when the operation completes. If the logo is unavailable, * an attempt will be made to create a new logo based on the source image uri. * * @param srcUri the {@link Uri} to the source image. *///w w w. j av a 2s . co m private void loadLogo(final String srcUri) { mBitmapCache.asyncGet(BaseTitleHeader.EVENT_LOGO_CACHE_KEY, new PersistedBitmapCache.IAsyncGetCallbacks() { @Override public void onSuccess(String key, Bitmap bitmap) { if (isActivityAlive()) { mLogoUri.setText(srcUri); // Set thumb as compound drawable, fitted to the text height. final BitmapDrawable thumb = new BitmapDrawable(getResources(), bitmap); int thumbSize = (int) getResources().getDimension(R.dimen.text_size_normal); Point drawableSize = ImageHelper.getAspectFitSize(thumbSize, thumbSize, bitmap.getWidth(), bitmap.getHeight()); thumb.setBounds(0, 0, drawableSize.x, drawableSize.y); mLogoUri.setCompoundDrawables(null, null, thumb, null); mLogoClear.setVisibility(View.VISIBLE); } } @Override public void onFailure(String key) { if (isActivityAlive()) { newLogo(Uri.parse(srcUri)); } } }); }
From source file:com.ifeng.util.imagecache.ImageWorker.java
/** * /* w w w.j a v a 2s .co m*/ * * @param imageView * @param drawable */ public static void setFadeInDrawable(ImageView imageView, Drawable drawable) { // Bug fix by XuWei 2013-09-09 // Drawable?bug?ViewDrawable??Drawable Drawable copyDrawable = new BitmapDrawable(imageView.getContext().getResources(), ((BitmapDrawable) drawable).getBitmap()); // Transition drawable with a transparent drawable and the final // drawable final TransitionDrawable td = new TransitionDrawable( new Drawable[] { new ColorDrawable(android.R.color.transparent), copyDrawable }); imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); }
From source file:com.androidpi.bricks.gallery.lru.cache.ImageWorker.java
/** * Called when the processing is complete and the final drawable should be set on the ImageView. * * @param imageView/*from w ww.j av a 2 s . c o m*/ * @param drawable */ private void setImageDrawable(ImageView imageView, Drawable drawable) { if (mFadeInBitmap) { // Transition drawable with a transparent drawable and the final // drawable final TransitionDrawable td = new TransitionDrawable(new Drawable[] { new ColorDrawable(imageView.getResources().getColor(android.R.color.transparent)), drawable }); // Set background to loading bitmap imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap)); imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); } else { imageView.setImageDrawable(drawable); } }