Java Code Examples for android.graphics.drawable.Drawable
The following examples show how to use
android.graphics.drawable.Drawable. These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: soas Source File: PhotoView.java License: Apache License 2.0 | 6 votes |
/** * Generate label background and foreground colors using Palette base on downloaded image colors. * * @param bitmap Download bitmap. */ @Override public void onBitmapChange(Bitmap bitmap) { if (bitmap == null) { return; } Palette.generateAsync(bitmap, new Palette.PaletteAsyncListener() { @SuppressWarnings("deprecation") public void onGenerated(Palette palette) { Resources res = getResources(); int photoNameColorBg = palette.getDarkMutedColor(res.getColor(R.color.list_item_photo_name_bg)); int photoNameColorFg = palette.getLightMutedColor(res.getColor(R.color.view_photo_name_fg)); ColorFilter photoNameColorFilter = new LightingColorFilter(photoNameColorBg, 1); Drawable photoNameDrawableBg = res.getDrawable(R.drawable.view_photo_name_bg); photoNameDrawableBg.setColorFilter(photoNameColorFilter); mPhotoName.setBackgroundDrawable(photoNameDrawableBg); mPhotoName.setTextColor(photoNameColorFg); } }); }
Example 2
Source Project: arcusandroid Source File: BaseFragment.java License: Apache License 2.0 | 6 votes |
/** * update background color based on the current device connectivity */ public void updateBackground(boolean isConnected) { try { ColorMatrix cm = new ColorMatrix(); cm.setSaturation(0f); final ColorFilter filter = new ColorMatrixColorFilter(cm); final ColorFilter filterOnline = getOnlineColorFilter(); final View bgView = ImageManager.getWallpaperView(); if (bgView != null) { final Drawable bgDrawable = bgView.getBackground(); if (bgDrawable != null) { bgDrawable.setColorFilter(isConnected ? filterOnline : filter); } } if(this instanceof ArcusProductFragment) { final ArcusProductFragment fragment = (ArcusProductFragment) this; fragment.setEnabled(isConnected); } if(callback != null) { callback.backgroundUpdated(); } }catch (Exception e){ logger.error("Can't change background color filter: {}", e); } }
Example 3
Source Project: litho Source File: ProgressSpec.java License: Apache License 2.0 | 6 votes |
@OnMount static void onMount( ComponentContext c, ProgressBar progressBar, @Prop(optional = true, resType = ResType.COLOR) int color, @FromPrepare Drawable resolvedIndeterminateDrawable) { if (resolvedIndeterminateDrawable != null) { progressBar.setIndeterminateDrawable(resolvedIndeterminateDrawable); } if (color != Color.TRANSPARENT && progressBar.getIndeterminateDrawable() != null) { progressBar .getIndeterminateDrawable() .mutate() .setColorFilter(color, PorterDuff.Mode.MULTIPLY); } }
Example 4
Source Project: QuickDevFramework Source File: CustomDrawableTextView.java License: Apache License 2.0 | 6 votes |
private void initAttrs(Context context, AttributeSet attr) { if (attr != null) { TypedArray typedArray = context.obtainStyledAttributes(attr, R.styleable.CustomDrawableTextView); drawableWidth = typedArray.getDimensionPixelOffset(R.styleable.CustomDrawableTextView_t_drawableWidth, 0); drawableHeight = typedArray.getDimensionPixelOffset(R.styleable.CustomDrawableTextView_t_drawableHeight, 0); drawableLeftWidth = typedArray.getDimensionPixelOffset(R.styleable.CustomDrawableTextView_t_drawableLeftWidth, 0); drawableLeftHeight = typedArray.getDimensionPixelOffset(R.styleable.CustomDrawableTextView_t_drawableLeftHeight, 0); drawableRightWidth = typedArray.getDimensionPixelOffset(R.styleable.CustomDrawableTextView_t_drawableRightWidth, 0); drawableRightHeight = typedArray.getDimensionPixelOffset(R.styleable.CustomDrawableTextView_t_drawableRightHeight, 0); drawableTopWidth = typedArray.getDimensionPixelOffset(R.styleable.CustomDrawableTextView_t_drawableTopWidth, 0); drawableTopHeight = typedArray.getDimensionPixelOffset(R.styleable.CustomDrawableTextView_t_drawableTopHeight, 0); drawableBottomWidth = typedArray.getDimensionPixelOffset(R.styleable.CustomDrawableTextView_t_drawableBottomWidth, 0); drawableBottomHeight = typedArray.getDimensionPixelOffset(R.styleable.CustomDrawableTextView_t_drawableBottomHeight, 0); typedArray.recycle(); } Drawable drawables[] = getCompoundDrawables(); Drawable left = drawables[0]; Drawable top = drawables[1]; Drawable right = drawables[2]; Drawable bottom = drawables[3]; setCompoundDrawables(left, top, right, bottom); }
Example 5
Source Project: fangzhuishushenqi Source File: DrawableCenterButton.java License: Apache License 2.0 | 6 votes |
@Override protected void onDraw(Canvas canvas) { Drawable[] drawables = getCompoundDrawables(); if (drawables != null) { Drawable drawableLeft = drawables[0]; if (drawableLeft != null) { float textWidth = getPaint().measureText(getText().toString()); int drawablePadding = getCompoundDrawablePadding(); int drawableWidth = 0; drawableWidth = drawableLeft.getIntrinsicWidth(); float bodyWidth = textWidth + drawableWidth + drawablePadding; canvas.translate((getWidth() - bodyWidth) / 11 * 5, 0); } } super.onDraw(canvas); }
Example 6
Source Project: QiQuYing Source File: RefreshImageView.java License: Apache License 2.0 | 6 votes |
private Bitmap getBitmapFromDrawable(Drawable drawable) { if (drawable == null) { return null; } if (drawable instanceof BitmapDrawable) { return ((BitmapDrawable) drawable).getBitmap(); } try { Bitmap bitmap; if (drawable instanceof ColorDrawable) { bitmap = Bitmap.createBitmap(COLORDRAWABLE_DIMENSION, COLORDRAWABLE_DIMENSION, BITMAP_CONFIG); } else { bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), BITMAP_CONFIG); } Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); return bitmap; } catch (OutOfMemoryError e) { return null; } }
Example 7
Source Project: BigApp_Discuz_Android Source File: AnimatedImageSpan.java License: Apache License 2.0 | 6 votes |
/** * 代码跟父类代码相似,就是getCachedDrawable()替换成getDrawable(),因为前者里面的图片是WeakReference, * 容易被gc回收,所以这里要避免这个问题 */ @Override public int getSize(Paint paint, CharSequence text, int start, int end, FontMetricsInt fm) { Drawable d = getDrawable(); if (lineHeight > 0) { return (int) (d.getIntrinsicWidth() * scale); } else { Rect rect = d.getBounds(); if (fm != null) { fm.ascent = -rect.bottom; fm.descent = 0; fm.top = fm.ascent; fm.bottom = 0; } return rect.right; } }
Example 8
Source Project: glide-support Source File: TestFragment.java License: The Unlicense | 6 votes |
@Override protected void load(Context context) throws Exception { int newIndex = (oldIndex + 1) % IMAGES.length; Glide .with(context) .load(IMAGES[newIndex]) .fitCenter() // can be implicit, but see thumbnail .thumbnail(Glide .with(context) .load(IMAGES[oldIndex]) .fitCenter() // have to be explicit here to match outer load exactly ) .listener(new LoggingListener<String, GlideDrawable>() { @Override public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { if (isFirstResource) { return false; // thumbnail was not shown, do as usual } return new DrawableCrossFadeFactory<Drawable>(/* customize timings here */) .build(false, false) // force crossFade() even if coming from memory cache .animate(resource, (ViewAdapter)target); } }) .into(imageView) ; oldIndex = newIndex; }
Example 9
Source Project: PhotoEditor Source File: ColorPickerAdapter.java License: MIT License | 6 votes |
private void buildColorPickerView(View view, int colorCode) { view.setVisibility(View.VISIBLE); ShapeDrawable biggerCircle = new ShapeDrawable(new OvalShape()); biggerCircle.setIntrinsicHeight(20); biggerCircle.setIntrinsicWidth(20); biggerCircle.setBounds(new Rect(0, 0, 20, 20)); biggerCircle.getPaint().setColor(colorCode); ShapeDrawable smallerCircle = new ShapeDrawable(new OvalShape()); smallerCircle.setIntrinsicHeight(5); smallerCircle.setIntrinsicWidth(5); smallerCircle.setBounds(new Rect(0, 0, 5, 5)); smallerCircle.getPaint().setColor(Color.WHITE); smallerCircle.setPadding(10, 10, 10, 10); Drawable[] drawables = {smallerCircle, biggerCircle}; LayerDrawable layerDrawable = new LayerDrawable(drawables); view.setBackgroundDrawable(layerDrawable); }
Example 10
Source Project: XERUNG Source File: MaterialEditText.java License: Apache License 2.0 | 5 votes |
private Bitmap[] generateIconBitmaps(Drawable drawable) { if (drawable == null) return null; Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); return generateIconBitmaps(Bitmap.createScaledBitmap(bitmap, iconSize, iconSize, false)); }
Example 11
Source Project: AlbumCameraRecorder Source File: GlideEngine.java License: MIT License | 5 votes |
@Override public void loadThumbnail(Context context, int resize, Drawable placeholder, ImageView imageView, Uri uri) { Glide.with(context) .load(uri) .asBitmap() // some .jpeg files are actually gif .placeholder(placeholder) .override(resize, resize) .centerCrop() .into(imageView); }
Example 12
Source Project: JianDan Source File: ShowMaxImageView.java License: Apache License 2.0 | 5 votes |
private Bitmap drawableToBitamp(Drawable drawable) { if (drawable != null) { BitmapDrawable bd = (BitmapDrawable) drawable; return bd.getBitmap(); } else { return null; } }
Example 13
Source Project: UltimateAndroid Source File: FloatingActionButton.java License: Apache License 2.0 | 5 votes |
Drawable getIconDrawable() { if (mIcon != 0) { return getResources().getDrawable(mIcon); } else { return new ColorDrawable(Color.TRANSPARENT); } }
Example 14
Source Project: fresco Source File: ArrayDrawable.java License: MIT License | 5 votes |
private DrawableParent createDrawableParentForIndex(final int index) { return new DrawableParent() { @Override public Drawable setDrawable(Drawable newDrawable) { return ArrayDrawable.this.setDrawable(index, newDrawable); } @Override public Drawable getDrawable() { return ArrayDrawable.this.getDrawable(index); } }; }
Example 15
Source Project: PainlessMusicPlayer Source File: BindingAdapters.java License: Apache License 2.0 | 5 votes |
@BindingAdapter({"src", "tintAttr"}) public static void setSrcTintedFromAttr( @NonNull final ImageView imageView, @Nullable Drawable src, @AttrRes final int tintAttr) { if (src != null) { src = DrawableUtils .getTintedDrawableFromAttrTint(imageView.getContext(), src, tintAttr); } imageView.setImageDrawable(src); }
Example 16
Source Project: SuntimesWidget Source File: SuntimesUtils.java License: GNU General Public License v3.0 | 5 votes |
public static ImageSpan createImageSpan(ImageSpan other) { Drawable drawable = null; if (other != null) drawable = other.getDrawable(); return new ImageSpan(drawable); }
Example 17
Source Project: ProjectX Source File: GradientTabStrip.java License: Apache License 2.0 | 5 votes |
private void setItemBackground(GradientTabStripItem item) { if (mItemBackgroundId != NO_ID) { item.setBackgroundResource(mItemBackgroundId); } else { if (mItemBackgroundDrawable != null) { final Drawable.ConstantState state = mItemBackgroundDrawable.getConstantState(); Drawable background; if (state != null) background = state.newDrawable(getResources()).mutate(); else background = mItemBackgroundDrawable; item.setBackgroundDrawable(background); } } }
Example 18
Source Project: zephyr Source File: ApplicationUtils.java License: MIT License | 5 votes |
@Nullable public Drawable getAppIcon(@NonNull PackageInfo packageInfo) { try { return mPackageManager.getApplicationIcon(packageInfo.applicationInfo); } catch (Exception e) { return mContext.getDrawable(R.drawable.ic_app_icon_unknown); } }
Example 19
Source Project: LaunchTime Source File: IconsHandler.java License: GNU General Public License v3.0 | 5 votes |
public static void applyIconTint(final Drawable app_icon, int mask_color) { if (Color.alpha(mask_color) > 10) { app_icon.mutate(); //int avg = (Color.red(mask_color) + Color.green(mask_color) + Color.blue(mask_color) ) / 3; if (Color.red(mask_color)>5 && Color.red(mask_color) == Color.green(mask_color) && Color.red(mask_color) == Color.blue(mask_color) ) { setSaturation(app_icon, (255f-Color.red(mask_color))/255f, Color.alpha(mask_color)/255f); } else { PorterDuff.Mode mode = PorterDuff.Mode.MULTIPLY; app_icon.setColorFilter(mask_color, mode); } } }
Example 20
Source Project: SimpleAdapterDemo Source File: BaseHeaderFooterAdapter.java License: Apache License 2.0 | 5 votes |
public BaseViewHolder setCompoundDrawables(@IdRes int id, @Nullable Drawable left, @Nullable Drawable top, @Nullable Drawable right, @Nullable Drawable bottom) { View view = findViewById(id); if (view instanceof TextView) ((TextView) view).setCompoundDrawables(left, top, right, bottom); return this; }
Example 21
Source Project: AndroidAnimationExercise Source File: Glide4Engine.java License: Apache License 2.0 | 5 votes |
@Override public void loadThumbnail(Context context, int resize, Drawable placeholder, ImageView imageView, Uri uri) { Glide.with(context) .asBitmap() // some .jpeg files are actually gif .load(uri) .apply(new RequestOptions() .override(resize, resize) .placeholder(placeholder) .centerCrop()) .into(imageView); }
Example 22
Source Project: LB-Launcher Source File: BubbleTextView.java License: Apache License 2.0 | 5 votes |
@Override protected void onAttachedToWindow() { super.onAttachedToWindow(); if (mBackground != null) mBackground.setCallback(this); Drawable top = getCompoundDrawables()[1]; if (top instanceof PreloadIconDrawable) { ((PreloadIconDrawable) top).applyTheme(getPreloaderTheme()); } mSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop(); }
Example 23
Source Project: FireFiles Source File: IconUtils.java License: Apache License 2.0 | 5 votes |
public static Drawable loadPackageIcon(Context context, String authority, int icon) { if (icon != 0) { if (authority != null) { final PackageManager pm = context.getPackageManager(); final ProviderInfo info = pm.resolveContentProvider(authority, 0); if (info != null) { return pm.getDrawable(info.packageName, icon, info.applicationInfo); } } else { return ContextCompat.getDrawable(context, icon); } } return null; }
Example 24
Source Project: Pix-Art-Messenger Source File: AvatarWorkerTask.java License: GNU General Public License v3.0 | 5 votes |
public static AvatarWorkerTask getBitmapWorkerTask(ImageView imageView) { if (imageView != null) { final Drawable drawable = imageView.getDrawable(); if (drawable instanceof AsyncDrawable) { final AsyncDrawable asyncDrawable = (AsyncDrawable) drawable; return asyncDrawable.getAvatarWorkerTask(); } } return null; }
Example 25
Source Project: px-android Source File: ViewUtils.java License: MIT License | 5 votes |
public static void resetDrawableBackgroundColor(@NonNull final View view) { final int transparentColor = ContextCompat.getColor(view.getContext(), R.color.px_transparent); final Drawable background = view.getBackground(); if (background != null) { background.setColorFilter(transparentColor, PorterDuff.Mode.SRC); } }
Example 26
Source Project: Noyze Source File: iOSVolumePanel.java License: Apache License 2.0 | 5 votes |
@Override public void setBackgroundColor(int backgroundColor) { super.setBackgroundColor(backgroundColor); Drawable background = makeBackground(getResources(), backgroundColor); background.setBounds(0, 0, root.getWidth(), root.getHeight()); root.setBackground(background); boolean dark = ColorPreference.isColorDark(backgroundColor); if (!has(BACKGROUND)) { setTextColor((dark) ? Color.WHITE : Color.BLACK); } }
Example 27
Source Project: UltimateAndroid Source File: CircularProgressButton.java License: Apache License 2.0 | 5 votes |
private void setIcon(int icon) { Drawable drawable = getResources().getDrawable(icon); if (drawable != null) { int padding = (getWidth() / 2) - (drawable.getIntrinsicWidth() / 2); setCompoundDrawablesWithIntrinsicBounds(icon, 0, 0, 0); setPadding(padding, 0, 0, 0); } }
Example 28
Source Project: styT Source File: IconHintView.java License: Apache License 2.0 | 5 votes |
private Drawable zoomDrawable(Drawable drawable, int w, int h) { int width = drawable.getIntrinsicWidth(); int height = drawable.getIntrinsicHeight(); Bitmap oldbmp = drawableToBitmap(drawable); Matrix matrix = new Matrix(); float scaleWidth = ((float) w / width); float scaleHeight = ((float) h / height); matrix.postScale(scaleWidth, scaleHeight); Bitmap newbmp = Bitmap.createBitmap(oldbmp, 0, 0, width, height, matrix, true); return new BitmapDrawable(null, newbmp); }
Example 29
Source Project: TurboLauncher Source File: HolographicLinearLayout.java License: Apache License 2.0 | 5 votes |
@Override protected void drawableStateChanged() { super.drawableStateChanged(); if (mImageView != null) { Drawable d = mImageView.getDrawable(); if (d instanceof StateListDrawable) { StateListDrawable sld = (StateListDrawable) d; sld.setState(getDrawableState()); sld.invalidateSelf(); } } }
Example 30
Source Project: SimpleChatView Source File: ActivityNewsHolder.java License: Apache License 2.0 | 5 votes |
@Override public void bindData(Object obj, int position) { MyChatMsg data = (MyChatMsg) obj; TextView textView = (TextView) getView(R.id.tv_activity_news); Drawable drawableLeft = ContextCompat.getDrawable(AppUtils.getContext(), R.drawable.ic_activity); Drawable drawableRight = ContextCompat.getDrawable(AppUtils.getContext(), R.drawable.ic_arrow); if (drawableLeft != null) { drawableLeft.setBounds(0, 0, DensityUtils.dp2px(AppUtils.getContext(), 18), DensityUtils.dp2px(AppUtils.getContext(), 18)); } if (drawableRight != null) { drawableRight.setBounds(0, 0, DensityUtils.dp2px(AppUtils.getContext(), 12), DensityUtils.dp2px(AppUtils.getContext(), 12)); } textView.setCompoundDrawables(drawableLeft, null, drawableRight, null); textView.setText(data.activityNews); }