Java Code Examples for android.graphics.drawable.LayerDrawable#getDrawable()
The following examples show how to use
android.graphics.drawable.LayerDrawable#getDrawable() .
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 File: RoundedDrawable.java From Common with Apache License 2.0 | 6 votes |
public static Drawable fromDrawable(Drawable drawable) { if (drawable != null) { if (drawable instanceof RoundedDrawable) { // just return if it's already a RoundedDrawable return drawable; } else if (drawable instanceof LayerDrawable) { LayerDrawable ld = (LayerDrawable) drawable; int num = ld.getNumberOfLayers(); // loop through layers to and change to RoundedDrawables if possible for (int i = 0; i < num; i++) { Drawable d = ld.getDrawable(i); ld.setDrawableByLayerId(ld.getId(i), fromDrawable(d)); } return ld; } // try to get a bitmap from the drawable and Bitmap bm = drawableToBitmap(drawable); if (bm != null) { return new RoundedDrawable(bm); } } return drawable; }
Example 2
Source File: RoundedDrawable.java From BigApp_Discuz_Android with Apache License 2.0 | 6 votes |
public static Drawable fromDrawable(Drawable drawable) { if (drawable != null) { if (drawable instanceof RoundedDrawable) { // just return if it's already a RoundedDrawable return drawable; } else if (drawable instanceof LayerDrawable) { LayerDrawable ld = (LayerDrawable) drawable; int num = ld.getNumberOfLayers(); // loop through layers to and change to RoundedDrawables if possible for (int i = 0; i < num; i++) { Drawable d = ld.getDrawable(i); ld.setDrawableByLayerId(ld.getId(i), fromDrawable(d)); } return ld; } // try to get a bitmap from the drawable and Bitmap bm = drawableToBitmap(drawable); if (bm != null) { return new RoundedDrawable(bm); } } return drawable; }
Example 3
Source File: RoundedDrawable.java From android-common-utils with Apache License 2.0 | 6 votes |
public static Drawable fromDrawable(Drawable drawable) { if (drawable != null) { if (drawable instanceof RoundedDrawable) { // just return if it's already a RoundedDrawable return drawable; } else if (drawable instanceof LayerDrawable) { LayerDrawable ld = (LayerDrawable) drawable; int num = ld.getNumberOfLayers(); // loop through layers to and change to RoundedDrawables if // possible for (int i = 0; i < num; i++) { Drawable d = ld.getDrawable(i); ld.setDrawableByLayerId(ld.getId(i), fromDrawable(d)); } return ld; } // try to get a bitmap from the drawable and Bitmap bm = drawableToBitmap(drawable); if (bm != null) { return new RoundedDrawable(bm); } } return drawable; }
Example 4
Source File: SelectableRoundedImageView.java From Expert-Android-Programming with MIT License | 6 votes |
public static Drawable fromDrawable(Drawable drawable, Resources r) { if (drawable != null) { if (drawable instanceof SelectableRoundedCornerDrawable) { return drawable; } else if (drawable instanceof LayerDrawable) { LayerDrawable ld = (LayerDrawable) drawable; final int num = ld.getNumberOfLayers(); for (int i = 0; i < num; i++) { Drawable d = ld.getDrawable(i); ld.setDrawableByLayerId(ld.getId(i), fromDrawable(d, r)); } return ld; } Bitmap bm = drawableToBitmap1(drawable); if (bm != null) { return new SelectableRoundedCornerDrawable(bm, r); } else { MyLg.w(TAG, "Failed to create bitmap from drawable!"); } } return drawable; }
Example 5
Source File: RoundedDrawable.java From DMusic with Apache License 2.0 | 6 votes |
public static Drawable fromDrawable(Drawable drawable) { if (drawable != null) { if (drawable instanceof RoundedDrawable) { // just return if it's already a RoundedDrawable return drawable; } else if (drawable instanceof LayerDrawable) { LayerDrawable ld = (LayerDrawable) drawable; int num = ld.getNumberOfLayers(); // loop through layers to and change to RoundedDrawables if possible for (int i = 0; i < num; i++) { Drawable d = ld.getDrawable(i); ld.setDrawableByLayerId(ld.getId(i), fromDrawable(d)); } return ld; } // try to get a bitmap from the drawable and Bitmap bm = drawableToBitmap(drawable); if (bm != null) { return new RoundedDrawable(bm); } } return drawable; }
Example 6
Source File: WorkoutActivity.java From privacy-friendly-interval-timer with GNU General Public License v3.0 | 6 votes |
/** * Switches between colors for rest timer and workout timer * according to the boolean flag provided/ * * @param guiFlip True for workout phase colors, false for rest phase colors */ private void setWorkoutGuiColors(boolean guiFlip) { int textColor = guiFlip ? R.color.white : R.color.black; int backgroundColor = guiFlip ? R.color.lightblue : R.color.white; int progressBackgroundColor = guiFlip ? R.color.white : R.color.lightblue; int buttonColor = guiFlip ? R.color.white : R.color.darkblue; currentSetsInfo.setTextColor(getResources().getColor(textColor)); workoutTitle.setTextColor(getResources().getColor(textColor)); workoutTimer.setTextColor(getResources().getColor(textColor)); prevTimer.setColorFilter(getResources().getColor(buttonColor)); nextTimer.setColorFilter(getResources().getColor(buttonColor)); View view = findViewById(R.id.workout_content); view.setBackgroundColor(getResources().getColor(backgroundColor)); LayerDrawable progressBarDrawable = (LayerDrawable) progressBar.getProgressDrawable(); Drawable backgroundDrawable = progressBarDrawable.getDrawable(0); Drawable progressDrawable = progressBarDrawable.getDrawable(1); progressDrawable.setColorFilter(ContextCompat.getColor(this, R.color.colorPrimary), PorterDuff.Mode.SRC_IN); backgroundDrawable.setColorFilter(ContextCompat.getColor(this, progressBackgroundColor), PorterDuff.Mode.SRC_IN); //progressBar.setProgressBackgroundTintList(ColorStateList.valueOf(getResources().getColor(progressBackgroundColor))); }
Example 7
Source File: RoundedDrawable.java From Loop with Apache License 2.0 | 6 votes |
public static Drawable fromDrawable(Drawable drawable) { if (drawable != null) { if (drawable instanceof RoundedDrawable) { // just return if it's already a RoundedDrawable return drawable; } else if (drawable instanceof LayerDrawable) { LayerDrawable ld = (LayerDrawable) drawable; int num = ld.getNumberOfLayers(); // loop through layers to and change to RoundedDrawables if possible for (int i = 0; i < num; i++) { Drawable d = ld.getDrawable(i); ld.setDrawableByLayerId(ld.getId(i), fromDrawable(d)); } return ld; } // try to get a bitmap from the drawable and Bitmap bm = drawableToBitmap(drawable); if (bm != null) { return new RoundedDrawable(bm); } } return drawable; }
Example 8
Source File: BottomBar.java From Camera2 with Apache License 2.0 | 6 votes |
private void setCancelBackgroundColor(int alpha, int color) { LayerDrawable layerDrawable = (LayerDrawable) mCancelButton.getBackground(); Drawable d = layerDrawable.getDrawable(0); if (d instanceof AnimatedCircleDrawable) { AnimatedCircleDrawable animatedCircleDrawable = (AnimatedCircleDrawable) d; animatedCircleDrawable.setColor(color); animatedCircleDrawable.setAlpha(alpha); } else if (d instanceof ColorDrawable) { ColorDrawable colorDrawable = (ColorDrawable) d; if (!ApiHelper.isLOrHigher()) { colorDrawable.setColor(color); } colorDrawable.setAlpha(alpha); } }
Example 9
Source File: SuntimesUtils.java From SuntimesWidget with GNU General Public License v3.0 | 6 votes |
/** * @param context context used to get resources * @param resourceID drawable resourceID to a LayerDrawable * @param fillColor fill color to apply to drawable * @param strokeColor stroke color to apply to drawable * @param strokePx width of stroke (pixels) * @return a Bitmap of the drawable */ public static Bitmap layerDrawableToBitmap(Context context, int resourceID, int fillColor, int strokeColor, int strokePx) { Drawable drawable = ResourcesCompat.getDrawable(context.getResources(), resourceID, null); LayerDrawable layers = (LayerDrawable)drawable; int w = 1, h = 1; if (layers != null) { Drawable layer0 = layers.getDrawable(0); w = layers.getIntrinsicWidth(); h = (layer0 != null ? layer0.getIntrinsicHeight() : layers.getIntrinsicHeight()); } Drawable tinted = tintDrawable(layers, fillColor, strokeColor, strokePx); return drawableToBitmap(context, tinted, w, h, true); }
Example 10
Source File: MaterialButtonHelper.java From material-components-android with Apache License 2.0 | 6 votes |
@Nullable private MaterialShapeDrawable getMaterialShapeDrawable(boolean getSurfaceColorStrokeDrawable) { if (rippleDrawable != null && rippleDrawable.getNumberOfLayers() > 0) { if (IS_LOLLIPOP) { InsetDrawable insetDrawable = (InsetDrawable) rippleDrawable.getDrawable(0); LayerDrawable layerDrawable = (LayerDrawable) insetDrawable.getDrawable(); return (MaterialShapeDrawable) layerDrawable.getDrawable(getSurfaceColorStrokeDrawable ? 0 : 1); } else { return (MaterialShapeDrawable) rippleDrawable.getDrawable(getSurfaceColorStrokeDrawable ? 0 : 1); } } return null; }
Example 11
Source File: RoundedImageView.java From AndroidMaterialDesign with Apache License 2.0 | 6 votes |
public static Drawable fromDrawable(Drawable drawable, Resources r) { if (drawable != null) { if (drawable instanceof SelectableRoundedCornerDrawable) { return drawable; } else if (drawable instanceof LayerDrawable) { LayerDrawable ld = (LayerDrawable) drawable; final int num = ld.getNumberOfLayers(); for (int i = 0; i < num; i++) { Drawable d = ld.getDrawable(i); ld.setDrawableByLayerId(ld.getId(i), fromDrawable(d, r)); } return ld; } Bitmap bm = drawableToBitmap(drawable); if (bm != null) { return new SelectableRoundedCornerDrawable(bm, r); } else { Log.w(TAG, "Failed to create bitmap from drawable!"); } } return drawable; }
Example 12
Source File: MonthAdapter.java From RackMonthPicker with Apache License 2.0 | 5 votes |
private void setMonthBackgroundSelected(int color) { LayerDrawable layerDrawable = (LayerDrawable) ContextCompat.getDrawable(context, R.drawable.month_selected); GradientDrawable gradientDrawable = (GradientDrawable) layerDrawable.getDrawable(1); gradientDrawable.setColor(color); layerDrawable.setDrawableByLayerId(1, gradientDrawable); StateListDrawable states = new StateListDrawable(); states.addState(new int[]{android.R.attr.state_selected}, gradientDrawable); states.addState(new int[]{android.R.attr.state_pressed}, gradientDrawable); states.addState(new int[]{}, ContextCompat.getDrawable(context, R.drawable.month_default)); layoutMain.setBackground(states); }
Example 13
Source File: RoundedDrawable.java From UltimateAndroid with Apache License 2.0 | 5 votes |
public static Drawable fromDrawable(Drawable drawable) { if (drawable != null) { if (drawable instanceof RoundedDrawable) { // just return if it's already a RoundedDrawable return drawable; } else if (drawable instanceof LayerDrawable) { LayerDrawable ld = (LayerDrawable) drawable; int num = ld.getNumberOfLayers(); // loop through layers to and change to RoundedDrawables if possible for (int i = 0; i < num; i++) { Drawable d = ld.getDrawable(i); ld.setDrawableByLayerId(ld.getId(i), fromDrawable(d)); } return ld; } // try to get a bitmap from the drawable and Bitmap bm = drawableToBitmap(drawable); if (bm != null) { return new RoundedDrawable(bm); } else { Log.w(TAG, "Failed to create bitmap from drawable!"); } } return drawable; }
Example 14
Source File: RoundedDrawable.java From android-project-wo2b with Apache License 2.0 | 5 votes |
public static Drawable fromDrawable(Drawable drawable) { if (drawable != null) { if (drawable instanceof RoundedDrawable) { // just return if it's already a RoundedDrawable return drawable; } else if (drawable instanceof LayerDrawable) { LayerDrawable ld = (LayerDrawable) drawable; int num = ld.getNumberOfLayers(); // loop through layers to and change to RoundedDrawables if possible for (int i = 0; i < num; i++) { Drawable d = ld.getDrawable(i); ld.setDrawableByLayerId(ld.getId(i), fromDrawable(d)); } return ld; } // try to get a bitmap from the drawable and Bitmap bm = drawableToBitmap(drawable); if (bm != null) { return new RoundedDrawable(bm); } else { Log.w(TAG, "Failed to create bitmap from drawable!"); } } return drawable; }
Example 15
Source File: RoundedDrawable.java From MousePaint with MIT License | 5 votes |
public static Drawable fromDrawable(Drawable drawable) { if (drawable != null) { if (drawable instanceof RoundedDrawable) { // just return if it's already a RoundedDrawable return drawable; } else if (drawable instanceof LayerDrawable) { LayerDrawable ld = (LayerDrawable) drawable; int num = ld.getNumberOfLayers(); // loop through layers to and change to RoundedDrawables if possible for (int i = 0; i < num; i++) { Drawable d = ld.getDrawable(i); ld.setDrawableByLayerId(ld.getId(i), fromDrawable(d)); } return ld; } // try to get a bitmap from the drawable and Bitmap bm = drawableToBitmap(drawable); if (bm != null) { return new RoundedDrawable(bm); } else { Log.w(TAG, "Failed to create bitmap from drawable!"); } } return drawable; }
Example 16
Source File: RoundedDrawable.java From q-municate-android with Apache License 2.0 | 5 votes |
public static Drawable fromDrawable(Drawable drawable) { if (drawable != null) { if (drawable instanceof RoundedDrawable) { // just return if it's already a RoundedDrawable return drawable; } else if (drawable instanceof LayerDrawable) { LayerDrawable ld = (LayerDrawable) drawable; int num = ld.getNumberOfLayers(); // loop through layers to and change to RoundedDrawables if possible for (int i = 0; i < num; i++) { Drawable d = ld.getDrawable(i); ld.setDrawableByLayerId(ld.getId(i), fromDrawable(d)); } return ld; } // try to get a bitmap from the drawable and Bitmap bm = drawableToBitmap(drawable); if (bm != null) { return new RoundedDrawable(bm); } else { Log.w(TAG, "Failed to create bitmap from drawable!"); } } return drawable; }
Example 17
Source File: MonthAdapter.java From RackMonthPicker with Apache License 2.0 | 5 votes |
private void setMonthBackgroundSelected(int color) { LayerDrawable layerDrawable = (LayerDrawable) ContextCompat.getDrawable(context, R.drawable.month_selected); GradientDrawable gradientDrawable = (GradientDrawable) layerDrawable.getDrawable(1); gradientDrawable.setColor(color); layerDrawable.setDrawableByLayerId(1, gradientDrawable); StateListDrawable states = new StateListDrawable(); states.addState(new int[]{android.R.attr.state_selected}, gradientDrawable); states.addState(new int[]{android.R.attr.state_pressed}, gradientDrawable); states.addState(new int[]{}, ContextCompat.getDrawable(context, R.drawable.month_default)); layoutMain.setBackground(states); }
Example 18
Source File: ChartProgressBar.java From ChartProgressBar-Android with Apache License 2.0 | 4 votes |
private void clickBarOn(FrameLayout frameLayout) { pins.get((int) frameLayout.getTag()).setVisibility(View.VISIBLE); isOldBarClicked = true; int childCount = frameLayout.getChildCount(); for (int i = 0; i < childCount; i++) { View childView = frameLayout.getChildAt(i); if (childView instanceof LinearLayout) { LinearLayout linearLayout = (LinearLayout) childView; Bar bar = (Bar) linearLayout.getChildAt(0); TextView titleTxtView = (TextView) linearLayout.getChildAt(1); LayerDrawable layerDrawable = (LayerDrawable) bar.getProgressDrawable(); layerDrawable.mutate(); ScaleDrawable scaleDrawable = (ScaleDrawable) layerDrawable.getDrawable(1); GradientDrawable progressLayer = (GradientDrawable) scaleDrawable.getDrawable(); if (mPinBackgroundColor != 0) { if (progressLayer != null) { progressLayer.setColor(ContextCompat.getColor(mContext, mProgressClickColor)); } } else { if (progressLayer != null) { progressLayer.setColor(ContextCompat.getColor(mContext, android.R.color.holo_green_dark)); } } if (mBarTitleSelectedColor > 0) { titleTxtView.setTextColor(ContextCompat.getColor(mContext, mBarTitleSelectedColor)); } else { titleTxtView.setTextColor(ContextCompat.getColor(mContext, android.R.color.holo_green_dark)); } } } }
Example 19
Source File: SettingPopup.java From eBook with Apache License 2.0 | 4 votes |
private void setCurSeekBarStyle() { for (SeekBar seekBar : mSeekBars) { //获取seekBar的layer-list drawable对象 LayerDrawable layerDrawable = (LayerDrawable) seekBar.getProgressDrawable(); //层次包括背景图和进度,所以进度直接设为1,获取并设置进度条背景 Drawable drawable = layerDrawable.getDrawable(1); drawable.setColorFilter(mStrokeColors[mTheme], PorterDuff.Mode.SRC); //获取thumb背景 Drawable thumb = seekBar.getThumb(); thumb.setColorFilter(mStrokeColors[mTheme], PorterDuff.Mode.SRC); } }
Example 20
Source File: ChartProgressBar.java From ChartProgressBar-Android with Apache License 2.0 | 4 votes |
public void enableBar(int index) { final int barsCount = ((LinearLayout) this.getChildAt(0)).getChildCount(); for (int i = 0; i < barsCount; i++) { FrameLayout rootFrame = (FrameLayout) ((LinearLayout) this.getChildAt(0)).getChildAt(i); int rootChildCount = rootFrame.getChildCount(); for (int j = 0; j < rootChildCount; j++) { if ((int) rootFrame.getTag() != index) continue; rootFrame.setEnabled(true); rootFrame.setClickable(true); View childView = rootFrame.getChildAt(j); if (childView instanceof LinearLayout) { //bar LinearLayout barContainerLinear = ((LinearLayout) childView); int barContainerCount = barContainerLinear.getChildCount(); for (int k = 0; k < barContainerCount; k++) { View view = barContainerLinear.getChildAt(k); if (view instanceof Bar) { Bar bar = (Bar) view; LayerDrawable layerDrawable = (LayerDrawable) bar.getProgressDrawable(); layerDrawable.mutate(); ScaleDrawable scaleDrawable = (ScaleDrawable) layerDrawable.getDrawable(1); GradientDrawable progressLayer = (GradientDrawable) scaleDrawable.getDrawable(); if (progressLayer != null) { if (mProgressColor > 0) progressLayer.setColor(ContextCompat.getColor(mContext, mProgressColor)); else progressLayer.setColor(ContextCompat.getColor(mContext, android.R.color.darker_gray)); } } else { TextView titleTxtView = (TextView) view; if (mProgressDisableColor > 0) titleTxtView.setTextColor(ContextCompat.getColor(mContext, mBarTitleColor)); else titleTxtView.setTextColor(ContextCompat.getColor(mContext, android.R.color.darker_gray)); } } } } } }