List of usage examples for android.graphics.drawable BitmapDrawable BitmapDrawable
private BitmapDrawable(BitmapState state, Resources res)
From source file:com.me.harris.listviewitemanimations._01_activityAnim.ActivityAnimations.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_animations); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/*from ww w . j a v a 2 s . c om*/ getSupportActionBar().setTitle(""); handleStatusBar(); // Grayscale filter used on all thumbnails ColorMatrix grayMatrix = new ColorMatrix(); grayMatrix.setSaturation(0); ColorMatrixColorFilter grayscaleFilter = new ColorMatrixColorFilter(grayMatrix); mGridLayout = (GridLayout) findViewById(R.id.gridLayout); mGridLayout.setColumnCount(3); mGridLayout.setUseDefaultMargins(true); // add all photo thumbnails to layout Resources resources = getResources(); ArrayList<PictureData> pictures = mBitmapUtils.loadPhotos(resources); for (int i = 0; i < pictures.size(); ++i) { PictureData pictureData = pictures.get(i); BitmapDrawable thumbnailDrawable = new BitmapDrawable(resources, pictureData.thumbnail); thumbnailDrawable.setColorFilter(grayscaleFilter); ImageView imageView = new ImageView(this); imageView.setOnClickListener(thumbnailClickListener); imageView.setImageDrawable(thumbnailDrawable); mPicturesData.put(imageView, pictureData); mGridLayout.addView(imageView); } }
From source file:me.piebridge.prevent.ui.UserGuideActivity.java
private Drawable cropDrawable(Drawable icon) { int width = getPixel(0x20); if (icon.getMinimumWidth() > width && icon instanceof BitmapDrawable) { Bitmap bitmap = Bitmap.createScaledBitmap(((BitmapDrawable) icon).getBitmap(), width, width, false); return new BitmapDrawable(getResources(), bitmap); }//ww w. j av a 2s .c o m return icon; }
From source file:com.gmail.altakey.lucene.AsyncImageLoader.java
protected BitmapDrawable doInBackground(Void... args) { final Context context = this.view.getContext(); final Resources res = context.getResources(); try {//ww w. j a v a 2 s.co m InputStream in = this.read(new ProgressReportingInputStream.ProgressListener() { public void onAdvance(long at, long size) { publishProgress(at, size); } }); BitmapFactory.Options bfo = new BitmapFactory.Options(); bfo.inDither = true; bfo.inPreferredConfig = Bitmap.Config.RGB_565; try { bfo.inPreferQualityOverSpeed = true; } catch (NoSuchFieldError e) { } Bitmap bitmap = BitmapFactory.decodeStream(in, new Rect(-1, -1, -1, -1), bfo); return new BitmapDrawable(res, this.scale(bitmap)); } catch (FileNotFoundException e) { return null; } catch (OutOfMemoryError e) { this.oomMessage.show(); return null; } }
From source file:com.android.displayingbitmaps.util.ImageWorker.java
public Bitmap loadImage(String data) { if (data == null) { return null; }/*from w w w . ja v a 2 s.com*/ BitmapDrawable value = null; if (mImageCache != null) { value = mImageCache.getBitmapFromMemCache(String.valueOf(data)); if (value != null) { return value.getBitmap(); } } Bitmap bitmap = processBitmap(data); if (bitmap != null) { if (Utils.hasHoneycomb()) { // Running on Honeycomb or newer, so wrap in a standard // BitmapDrawable value = new BitmapDrawable(mResources, bitmap); } else { // Running on Gingerbread or older, so wrap in a // RecyclingBitmapDrawable // which will recycle automagically value = new RecyclingBitmapDrawable(mResources, bitmap); } if (mImageCache != null) { mImageCache.addBitmapToCache(data, value); } } return bitmap; }
From source file:com.hellofyc.base.util.ViewUtils.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) static void blur(Context context, View view) { view.buildDrawingCache();/* w w w . j a v a2 s . c om*/ Bitmap srcBitmap = view.getDrawingCache(); float radius = 20f; Bitmap overlay = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(overlay); canvas.translate(-view.getLeft(), -view.getTop()); canvas.drawBitmap(srcBitmap, 0, 0, null); RenderScript script = RenderScript.create(context); Allocation allocation = Allocation.createFromBitmap(script, overlay); ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(script, allocation.getElement()); blur.setInput(allocation); blur.setRadius(radius); blur.forEach(allocation); allocation.copyTo(overlay); view.setBackground(new BitmapDrawable(context.getResources(), overlay)); script.destroy(); }
From source file:com.c4mprod.utils.ImageManager.java
private ImageManager(final Context ctx) { instance = this; mDowloadLooper = new LooperThread(); mDowloadLooper.start();/*from w w w . java 2 s. c o m*/ mUiHandler = new Handler() { @Override public void handleMessage(Message msg) { if (mStopped) { return; } ImageDownloadMessageData messageData = (ImageDownloadMessageData) msg.obj; View v = messageData.viewRef.get(); if (v != null && messageData.bitmap != null && messageData == getImageDownloadData(v, messageData.flags)) { if (messageData.listerner != null) { messageData.listerner.onImageDownloaded(v, messageData.bitmap); } else { if (v instanceof ImageView) { if ((messageData.flags & FLAG_IN_BACKGROUND) != 0) { BitmapDrawable bd = new BitmapDrawable(ctx.getResources(), messageData.bitmap); v.setBackgroundDrawable(bd); } else { ((ImageView) v).setImageBitmap(messageData.bitmap); } } else if (v instanceof ImageButton) { if ((messageData.flags & FLAG_IN_BACKGROUND) != 0) { BitmapDrawable bd = new BitmapDrawable(ctx.getResources(), messageData.bitmap); v.setBackgroundDrawable(bd); } else { ((ImageButton) v).setImageBitmap(messageData.bitmap); } } else { // no src BitmapDrawable bd = new BitmapDrawable(ctx.getResources(), messageData.bitmap); v.setBackgroundDrawable(bd); } } } }; }; // create cache dir if needed new File(ctx.getExternalCacheDir() + THUMB_FOLDER).mkdirs(); }
From source file:com.nextgis.maplibui.fragment.ReorderedLayerView.java
/** * Creates the hover cell with the appropriate bitmap and of appropriate size. The hover cell's * BitmapDrawable is drawn on top of the bitmap every single time an invalidate call is made. */// ww w.j a v a 2s. c om protected BitmapDrawable getAndAddHoverView(View v) { int w = v.getWidth(); int h = v.getHeight(); int top = v.getTop(); int left = v.getLeft(); Bitmap b = getBitmapWithBorder(v); BitmapDrawable drawable = new BitmapDrawable(getResources(), b); mHoverCellOriginalBounds = new Rect(left, top, left + w, top + h); mHoverCellCurrentBounds = new Rect(mHoverCellOriginalBounds); drawable.setBounds(mHoverCellCurrentBounds); return drawable; }
From source file:android.support.v17.leanback.media.MediaControllerGlue.java
@Override public Drawable getMediaArt() { Bitmap bitmap = mMediaController.getMetadata().getDescription().getIconBitmap(); return bitmap == null ? null : new BitmapDrawable(getContext().getResources(), bitmap); }
From source file:com.nextgis.maplibui.util.ControlHelper.java
public static Drawable getIconByVectorType(Context context, int geometryType, int color, int defaultIcon, boolean syncable) { int drawableId; switch (geometryType) { case GTPoint: drawableId = R.drawable.ic_type_point; break;//ww w. j a va 2s. com case GTMultiPoint: drawableId = R.drawable.ic_type_multipoint; break; case GTLineString: drawableId = R.drawable.ic_type_line; break; case GTMultiLineString: drawableId = R.drawable.ic_type_multiline; break; case GTPolygon: drawableId = R.drawable.ic_type_polygon; break; case GTMultiPolygon: drawableId = R.drawable.ic_type_multipolygon; break; default: return ContextCompat.getDrawable(context, defaultIcon); } BitmapDrawable icon = (BitmapDrawable) ContextCompat.getDrawable(context, drawableId); if (icon != null) { Bitmap src = icon.getBitmap(); Bitmap bitmap = Bitmap.createBitmap(src.getWidth(), src.getHeight(), src.getConfig()); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); ColorFilter filter = new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP); paint.setColorFilter(filter); canvas.drawBitmap(src, 0, 0, paint); if (syncable) { int syncIconId = isDarkTheme(context) ? R.drawable.ic_action_refresh_dark : R.drawable.ic_action_refresh_light; ; src = BitmapFactory.decodeResource(context.getResources(), syncIconId); src = Bitmap.createScaledBitmap(src, bitmap.getWidth() / 2, bitmap.getWidth() / 2, true); canvas.drawBitmap(src, bitmap.getWidth() - bitmap.getWidth() / 2, bitmap.getWidth() - bitmap.getWidth() / 2, new Paint()); } icon = new BitmapDrawable(context.getResources(), bitmap); } return icon; }
From source file:com.hitkoDev.chemApp.fragment.SectionsFragment.java
public void loadSections(final int level) { if (!started) { return;/*w ww .j a v a 2s. co m*/ } if (level > 0) { if (level != loadedLevel) { if (getContext() != null) { new LoadDataTask(getContext(), new OnJSONResponseListener() { @Override public void onSuccess(JSONObject response) { try { JSONArray l = response.getJSONObject("object").getJSONArray("sections"); SectionsFragment.this.level = new Level(response.getJSONObject("object")); sections.clear(); for (int i = 0; i < l.length(); i++) { try { Section s = new Section(l.getJSONObject(i), getContext(), new Section.OnIconLoaded() { @Override public void notifyLoaded(Section s) { s.setTile( new BitmapDrawable(getContext().getResources(), tileProvider.makeCircle( s.isChild() ? subTileDimensions : tileDimensions, s.getIcon()))); } }); if (!s.hasIcon()) { s.setTile(new BitmapDrawable(getContext().getResources(), tileProvider .getLetterTile(tileDimensions, s.getName(), s.getId() + ""))); } sections.add(s); if (s.hasChildren()) { for (Section sub : s.getChildren()) { sub.setTile(new BitmapDrawable(getContext().getResources(), s.loadedIcon() ? tileProvider.makeCircle(subTileDimensions, s.getIcon()) : tileProvider.getLetterTile(subTileDimensions, sub.getName(), sub.getId() + ""))); } sections.addAll(s.getChildren()); } } catch (Exception ex) { } } } catch (Exception ex) { } loadedLevel = level; recyclerView.setAdapter(adapter); setHeader(); } @Override public void onFail(String response) { System.out.println(response); } }).execute("level", level + ""); } } else { if (recyclerView.getAdapter() != adapter) { recyclerView.setAdapter(adapter); } setHeader(); } } }