List of usage examples for android.support.v4.graphics.drawable RoundedBitmapDrawableFactory create
public static RoundedBitmapDrawable create(Resources resources, InputStream inputStream)
From source file:io.nuclei.cyto.ui.view.GlideImageView.java
@Override public void setImageDrawable(Drawable drawable) { if (mCircle && drawable instanceof BitmapDrawable) { Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap(); RoundedBitmapDrawable d = RoundedBitmapDrawableFactory.create(getResources(), bitmap); d.setCornerRadius(d.getIntrinsicWidth() / 2); d.setAntiAlias(true);//ww w . j av a 2 s .c om drawable = d; } super.setImageDrawable(drawable); if (mListener != null) mListener.onDrawable(drawable); }
From source file:com.fjoglar.etsitnoticias.utils.UiUtils.java
/** * Create a circular drawable from a resource drawable id. * * @param context Need to get the resources * @param resId Drawable's id.// ww w. ja v a 2 s. c o m * * @return RoundedBitmapDrawable */ public static RoundedBitmapDrawable getCircleBitmapDrawable(Context context, int resId) { Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resId); RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(context.getResources(), bitmap); drawable.setCornerRadius(Math.max(bitmap.getWidth() / 2, bitmap.getHeight() / 2)); drawable.setAntiAlias(true); return drawable; }
From source file:bruce.kk.imglibcompare.picasso.PicassoActivity.java
@OnClick({ R.id.btn_load_local, R.id.btn_load_url, R.id.btn_load_cancel }) public void onClick(View view) { switch (view.getId()) { case R.id.btn_load_local: Picasso.with(PicassoActivity.this).load(R.mipmap.ic_loading).into(ivImg); break;//from ww w.j a v a 2 s. c om case R.id.btn_load_url: // // Picasso.with(PicassoActivity.this) // .load(ImgConstant.IMG_URL) // .resize(80, 80) // .error(R.mipmap.ic_failed) // .into(ivImg); // Picasso.Builder builder = new Picasso.Builder(PicassoActivity.this); builder.listener(new Picasso.Listener() { @Override public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception) { LogDetails.d(" exception: " + exception); } }); builder.build().load(ImgConstant.IMG_URL) // .load("http://dd.com/ssss.jpg") .placeholder(R.mipmap.ic_loading2).error(R.mipmap.ic_failed) // tansform .transform(new Transformation() { @Override public Bitmap transform(Bitmap source) { RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(getResources(), source); drawable.setCornerRadius(50); // drawable.setCircular(true); // ? // ? int width = drawable.getIntrinsicWidth(); int height = drawable.getIntrinsicHeight(); // ?? Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565; // bitmap Bitmap bitmap = Bitmap.createBitmap(width, height, config); if (bitmap != source) { source.recycle(); } Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, width, height); drawable.draw(canvas); return bitmap; } @Override public String key() { return "rounded"; } }).into(ivImg); break; case R.id.btn_load_cancel: Picasso.with(PicassoActivity.this).cancelRequest(ivImg); break; } }
From source file:org.chromium.chrome.browser.enhancedbookmarks.EnhancedBookmarkBookmarkRow.java
@Override public void onLargeIconAvailable(Bitmap icon, int fallbackColor) { if (icon == null) { mIconGenerator.setBackgroundColor(fallbackColor); icon = mIconGenerator.generateIconForUrl(mUrl); mIconImageView.setImageDrawable(new BitmapDrawable(getResources(), icon)); } else {/*from w ww . j av a 2s.c om*/ RoundedBitmapDrawable roundedIcon = RoundedBitmapDrawableFactory.create(getResources(), Bitmap.createScaledBitmap(icon, mDisplayedIconSize, mDisplayedIconSize, false)); roundedIcon.setCornerRadius(mCornerRadius); mIconImageView.setImageDrawable(roundedIcon); } }
From source file:ua.com.spacetv.mycookbook.tools.ListAdapter.java
/** * Set image into image viev/*from w w w. ja v a 2 s . co m*/ * Usage Glide library * * @param path */ private void setImage(String path, final ImageView img) { Glide.with(mContext).load(path).asBitmap().centerCrop().into(new BitmapImageViewTarget(img) { @Override protected void setResource(Bitmap resource) { RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory .create(mContext.getResources(), resource); circularBitmapDrawable.setCircular(true); img.setImageDrawable(circularBitmapDrawable); } }); }
From source file:io.github.protino.codewatch.ui.adapter.LeadersAdapter.java
private void setCircularAvatar(final ImageView avatar, String photoUrl) { Glide.with(context).load(photoUrl).asBitmap().placeholder(R.drawable.ic_account_circle_white_24dp) .into(new BitmapImageViewTarget(avatar) { @Override//from w w w .j a va2 s . co m protected void setResource(Bitmap resource) { RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(context.getResources(), resource); drawable.setCircular(true); avatar.setImageDrawable(drawable); } }); }
From source file:nuclei.ui.view.GlideImageView.java
private BitmapImageViewTarget newTarget() { return new BitmapImageViewTarget(this) { Drawable newDrawable(Drawable drawable) { if (drawable instanceof BitmapDrawable) return newDrawable(((BitmapDrawable) drawable).getBitmap()); return drawable; }/* w w w .j a va 2 s .c om*/ Drawable newDrawable(Bitmap bitmap) { if (bitmap == null) return null; RoundedBitmapDrawable d = RoundedBitmapDrawableFactory.create(view.getResources(), bitmap); if (mCircle) d.setCircular(true); else d.setCornerRadius(mRadius); return d; } @Override public void onLoadStarted(Drawable placeholder) { view.setImageDrawable(newDrawable(placeholder)); } @Override public void onLoadCleared(Drawable placeholder) { view.setImageDrawable(newDrawable(placeholder)); } @Override public void onLoadFailed(Exception e, Drawable errorDrawable) { view.setImageDrawable(newDrawable(errorDrawable)); } @Override protected void setResource(Bitmap resource) { view.setImageDrawable(newDrawable(resource)); } }; }
From source file:net.fred.feedex.adapter.EntriesCursorAdapter.java
@Override public void bindView(View view, final Context context, Cursor cursor) { if (view.getTag(R.id.holder) == null) { ViewHolder holder = new ViewHolder(); holder.titleTextView = (TextView) view.findViewById(android.R.id.text1); holder.dateTextView = (TextView) view.findViewById(android.R.id.text2); holder.mainImgView = (ImageView) view.findViewById(R.id.main_icon); holder.starImgView = (ImageView) view.findViewById(R.id.favorite_icon); view.setTag(R.id.holder, holder); }//w ww .j ava 2 s . c om final ViewHolder holder = (ViewHolder) view.getTag(R.id.holder); String titleText = cursor.getString(mTitlePos); holder.titleTextView.setText(titleText); final long feedId = cursor.getLong(mFeedIdPos); String feedName = cursor.getString(mFeedNamePos); String mainImgUrl = cursor.getString(mMainImgPos); mainImgUrl = TextUtils.isEmpty(mainImgUrl) ? null : NetworkUtils.getDownloadedOrDistantImageUrl(cursor.getLong(mIdPos), mainImgUrl); ColorGenerator generator = ColorGenerator.DEFAULT; int color = generator.getColor(feedId); // The color is specific to the feedId (which shouldn't change) String lettersForName = feedName != null ? (feedName.length() < 2 ? feedName.toUpperCase() : feedName.substring(0, 2).toUpperCase()) : ""; TextDrawable letterDrawable = TextDrawable.builder().buildRound(lettersForName, color); if (mainImgUrl != null) { Glide.with(context).load(mainImgUrl).asBitmap().centerCrop().placeholder(letterDrawable) .error(letterDrawable).into(new BitmapImageViewTarget(holder.mainImgView) { @Override protected void setResource(Bitmap resource) { RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory .create(context.getResources(), resource); circularBitmapDrawable.setCircular(true); getView().setImageDrawable(circularBitmapDrawable); } }); } else { Glide.clear(holder.mainImgView); holder.mainImgView.setImageDrawable(letterDrawable); } holder.isFavorite = cursor.getInt(mFavoritePos) == 1; holder.starImgView.setVisibility(holder.isFavorite ? View.VISIBLE : View.INVISIBLE); if (mShowFeedInfo && mFeedNamePos > -1) { if (feedName != null) { holder.dateTextView.setText(Html.fromHtml("<font color='#247ab0'>" + feedName + "</font>" + Constants.COMMA_SPACE + StringUtils.getDateTimeString(cursor.getLong(mDatePos)))); } else { holder.dateTextView.setText(StringUtils.getDateTimeString(cursor.getLong(mDatePos))); } } else { holder.dateTextView.setText(StringUtils.getDateTimeString(cursor.getLong(mDatePos))); } if (cursor.isNull(mIsReadPos)) { holder.titleTextView.setEnabled(true); holder.dateTextView.setEnabled(true); holder.isRead = false; } else { holder.titleTextView.setEnabled(false); holder.dateTextView.setEnabled(false); holder.isRead = true; } }
From source file:org.appspot.apprtc.util.ThumbnailsCacheManager.java
public static void LoadImage(final String url, ImageView image, final String displayname, final boolean rounded, boolean fromCache) { final WeakReference<ImageView> imageView = new WeakReference<ImageView>(image); final Handler uiHandler = new Handler(); final int FG_COLOR = 0xFFFAFAFA; final String name = displayname; if (fromCache) { Bitmap bitmap = ThumbnailsCacheManager.getBitmapFromDiskCache(url); if (bitmap != null) { if (rounded) { RoundedBitmapDrawable roundedBitmap = RoundedBitmapDrawableFactory .create(imageView.get().getResources(), bitmap); roundedBitmap.setCircular(true); imageView.get().setImageDrawable(roundedBitmap); } else { imageView.get().setImageBitmap(bitmap); }// ww w . j av a 2 s . c om imageView.get().setContentDescription(displayname); return; } } AsyncHttpURLConnection httpConnection = new AsyncHttpURLConnection("GET", url, "", new AsyncHttpURLConnection.AsyncHttpEvents() { @Override public void onHttpError(String errorMessage) { Log.d("LoadImage", errorMessage); } @Override public void onHttpComplete(String response) { int size = 96; Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); final String trimmedName = name == null ? "" : name.trim(); drawTile(canvas, trimmedName, 0, 0, size, size); ThumbnailsCacheManager.addBitmapToCache(url, bitmap); onHttpComplete(bitmap); } @Override public void onHttpComplete(final Bitmap response) { if (imageView != null && imageView.get() != null) { uiHandler.post(new Runnable() { @Override public void run() { if (imageView.get() != null) { if (rounded) { RoundedBitmapDrawable roundedBitmap = RoundedBitmapDrawableFactory .create(imageView.get().getResources(), response); roundedBitmap.setCircular(true); imageView.get().setImageDrawable(roundedBitmap); } else { imageView.get().setImageBitmap(response); } imageView.get().setContentDescription(displayname); } } }); } } private boolean drawTile(Canvas canvas, String letter, int tileColor, int left, int top, int right, int bottom) { letter = letter.toUpperCase(Locale.getDefault()); Paint tilePaint = new Paint(), textPaint = new Paint(); tilePaint.setColor(tileColor); textPaint.setFlags(Paint.ANTI_ALIAS_FLAG); textPaint.setColor(FG_COLOR); textPaint.setTypeface(Typeface.create("sans-serif-light", Typeface.NORMAL)); textPaint.setTextSize((float) ((right - left) * 0.8)); Rect rect = new Rect(); canvas.drawRect(new Rect(left, top, right, bottom), tilePaint); textPaint.getTextBounds(letter, 0, 1, rect); float width = textPaint.measureText(letter); canvas.drawText(letter, (right + left) / 2 - width / 2, (top + bottom) / 2 + rect.height() / 2, textPaint); return true; } private boolean drawTile(Canvas canvas, String name, int left, int top, int right, int bottom) { if (name != null) { final String letter = getFirstLetter(name); final int color = ThumbnailsCacheManager.getColorForName(name); drawTile(canvas, letter, color, left, top, right, bottom); return true; } return false; } }); httpConnection.setBitmap(); httpConnection.send(); }
From source file:us.theparamountgroup.android.inventory.ShellCursorAdapter.java
/** * This method binds the shell data (in the current row pointed to by cursor) to the given * list item layout. For example, the name for the current shell can be set on the name TextView * in the list item layout.//from w w w . j a v a2 s. c o m * * @param view Existing view, returned earlier by newView() method * @param context app context * @param cursor The cursor from which to get the data. The cursor is already moved to the * correct row. */ @Override public void bindView(View view, final Context context, Cursor cursor) { // Find individual views that we want to modify in the list item layout TextView nameTextView = (TextView) view.findViewById(R.id.name); TextView colorTextView = (TextView) view.findViewById(R.id.color); final TextView quantityTextView = (TextView) view.findViewById(R.id.quantity); TextView priceTextView = (TextView) view.findViewById(R.id.price); ImageView photoImageView = (ImageView) view.findViewById(R.id.thumbnail); Button saleButton = (Button) view.findViewById(R.id.sale_button); final String idColumn = cursor.getString(cursor.getColumnIndexOrThrow(ShellContract.ShellEntry._ID)); final String nameColumn = cursor .getString(cursor.getColumnIndexOrThrow(ShellContract.ShellEntry.COLUMN_SHELL_NAME)); final Uri currentProductUri = ContentUris.withAppendedId(ShellContract.ShellEntry.CONTENT_URI, Long.parseLong(idColumn)); // Find the columns of shell attributes that we're interested in int nameColumnIndex = cursor.getColumnIndex(ShellContract.ShellEntry.COLUMN_SHELL_NAME); int colorColumnIndex = cursor.getColumnIndex(ShellContract.ShellEntry.COLUMN_SHELL_COLOR); int photoColumnIndex = cursor.getColumnIndex(ShellContract.ShellEntry.COLUMN_SHELL_PHOTO); int quantityColumnIndex = cursor.getColumnIndex(ShellContract.ShellEntry.COLUMN_SHELL_QUANTITY); int priceColumnIndex = cursor.getColumnIndex(ShellContract.ShellEntry.COLUMN_SHELL_PRICE); int thumbnailColumnIndex = cursor.getColumnIndex(ShellContract.ShellEntry.COLUMN_SHELL_THUMBNAIL); // Read the shell attributes from the Cursor for the current shell final String shellName = cursor.getString(nameColumnIndex); String shellColor = cursor.getString(colorColumnIndex); String shellQuantity = cursor.getString(quantityColumnIndex); String shellPrice = cursor.getString(priceColumnIndex); String photo = cursor.getString(photoColumnIndex); // check if there is photo saved for item and assign the saved thumbnail to photoImageView if (!photo.isEmpty()) { try { byte[] thumbnail = cursor.getBlob(thumbnailColumnIndex); Bitmap thumbImage = getImage(thumbnail); photoImageView.setBackground(null); int cornerRadius = 10; RoundedBitmapDrawable dr = RoundedBitmapDrawableFactory.create(context.getResources(), thumbImage); dr.setCornerRadius(cornerRadius); photoImageView.setImageDrawable(dr); } catch (Exception e) { Log.e("ThumbnailUtils", "Problem extracting thumbnail", e); e.printStackTrace(); } } // If the shell color is empty string or null, then use some default text // that says "Unknown color", so the TextView isn't blank. if (TextUtils.isEmpty(shellColor)) { shellColor = context.getString(R.string.unknown_color); } ; saleButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int quantity; if (quantityTextView.getText().toString().isEmpty()) { quantity = 0; } else { quantity = Integer.parseInt(quantityTextView.getText().toString()); } if (quantity > 0) { quantity = quantity - 1; quantityTextView.setText(String.valueOf(quantity)); ContentValues values = new ContentValues(); // values.put(ShellContract.ShellEntry.COLUMN_SHELL_NAME, shellName); values.put(ShellContract.ShellEntry.COLUMN_SHELL_QUANTITY, quantity); //values.put(ProductEntry.COLUMN_PRODUCT_PRICE, priceColumn); //values.put(ProductEntry.COLUMN_PRODUCT_PHOTO, photoColumn); int rowsAffected = context.getContentResolver().update(currentProductUri, values, null, null); if (rowsAffected == 0) { // Toast.makeText(v.getContext(), v.getContext().getString("error updating"), Toast.LENGTH_LONG).show(); } else { Toast.makeText(v.getContext(), "Sale Product " + nameColumn, Toast.LENGTH_LONG).show(); } } else { Toast.makeText(v.getContext(), "Order Product", Toast.LENGTH_SHORT).show(); } } }); // Update the TextViews with the attributes for the current shell nameTextView.setText(shellName); colorTextView.setText(shellColor); quantityTextView.setText(shellQuantity); priceTextView.setText("$" + shellPrice); }