Java Code Examples for android.graphics.drawable.LayerDrawable#findDrawableByLayerId()

The following examples show how to use android.graphics.drawable.LayerDrawable#findDrawableByLayerId() . 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: BaseActivity.java    From RetailStore with Apache License 2.0 6 votes vote down vote up
public void setBadgeCount(Context context, LayerDrawable icon, int count) {

        MenuCounterDrawable badge;

        // Reuse drawable if possible
        Drawable reuse = icon.findDrawableByLayerId(R.id.ic_badge);
        if (reuse != null && reuse instanceof MenuCounterDrawable) {
            badge = (MenuCounterDrawable) reuse;
        } else {
            badge = new MenuCounterDrawable(context);
        }

        badge.setCount(count);
        icon.mutate();
        icon.setDrawableByLayerId(R.id.ic_badge, badge);
    }
 
Example 2
Source File: Swipe_Button_View.java    From AGIKSwipeButton with MIT License 6 votes vote down vote up
void set_default(AttributeSet attrs, int defStyle) {
    inflate(getContext(), R.layout.sb_swipe_view, this);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        setBackground(ContextCompat.getDrawable(getContext(), R.drawable.sb_swipe_view_bg));
    } else {
        setBackgroundDrawable(ContextCompat.getDrawable(getContext(), R.drawable.sb_swipe_view_bg));
    }

    swipeTextView = findViewById(R.id.sb_text);
    swipe_button_controller = findViewById(R.id.sb_swipe);
    swipe_button_controller.setOnSeekBarChangeListener(this);
    swipe_bg_drawable = getBackground();
    swipeLayers = (LayerDrawable) swipe_button_controller.getThumb();
    thumb_bg_drawable = swipeLayers.findDrawableByLayerId(R.id.thumb_background);

    TypedArray attributes = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.SwipeButtonView,
            defStyle, defStyle);
    try {
        getAttributes(attributes);
    } finally {
        attributes.recycle();
    }
}
 
Example 3
Source File: CmBatteryBar.java    From Noyze with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the {@link ShapeDrawable} which displays the
 * color of the bar across the screen.
 */
public void setProgressDrawable(Drawable mDrawable, int mNewColor)
{
	if (mDrawable instanceof LayerDrawable &&
		getProgressDrawable() instanceof LayerDrawable)
	{
        final LayerDrawable mDraw = (LayerDrawable) getProgressDrawable();
        final ClipDrawable mShape = (ClipDrawable)
            mDraw.findDrawableByLayerId(android.R.id.progress);

        // Make sure we've got everything.
        if (mShape != null && mProgress != null &&
            mProgress.getPaint() != null)
        {
            mProgress.getPaint().setColor(mNewColor);
            final Rect mBounds = mDraw.getBounds();
            super.setProgressDrawable(mDraw);
            getProgressDrawable().setBounds(mBounds);
            return;
        }
	}
	
	super.setProgressDrawable(mDrawable);
}
 
Example 4
Source File: PlayActivity.java    From MeetMusic with Apache License 2.0 5 votes vote down vote up
private void setSeekBarBg(){
    try {
        int progressColor = CustomAttrValueUtil.getAttrColorValue(R.attr.colorPrimary,R.color.colorAccent,this);
        LayerDrawable layerDrawable = (LayerDrawable) seekBar.getProgressDrawable();
        ScaleDrawable scaleDrawable = (ScaleDrawable)layerDrawable.findDrawableByLayerId(android.R.id.progress);
        GradientDrawable drawable = (GradientDrawable) scaleDrawable.getDrawable();
        drawable.setColor(progressColor);
    }catch (Exception e){
        e.printStackTrace();
    }
}
 
Example 5
Source File: Switch.java    From MaterialDesignLibrary with Apache License 2.0 5 votes vote down vote up
public void changeBackground() {
	if (eventCheck) {
		setBackgroundResource(R.drawable.background_checkbox);
		LayerDrawable layer = (LayerDrawable) getBackground();
		GradientDrawable shape = (GradientDrawable) layer
				.findDrawableByLayerId(R.id.shape_bacground);
		shape.setColor(backgroundColor);
	} else {
		setBackgroundResource(R.drawable.background_switch_ball_uncheck);
	}
}
 
Example 6
Source File: Button.java    From atlas with Apache License 2.0 5 votes vote down vote up
public void setBackgroundColor(int color) {
	this.backgroundColor = color;
	if (isEnabled())
		beforeBackground = backgroundColor;
	try {
		LayerDrawable layer = (LayerDrawable) getBackground();
		GradientDrawable shape = (GradientDrawable) layer
				.findDrawableByLayerId(R.id.shape_bacground);
		shape.setColor(backgroundColor);
		rippleColor = makePressColor();
	} catch (Exception ex) {
		// Without bacground
	}
}
 
Example 7
Source File: ColorableProgressBar.java    From android-material-stepper with Apache License 2.0 5 votes vote down vote up
private void updateProgressDrawable() {
    LayerDrawable progressBarDrawable = (LayerDrawable) getProgressDrawable();
    Drawable backgroundDrawable = progressBarDrawable.findDrawableByLayerId(android.R.id.background);
    Drawable progressDrawable = progressBarDrawable.findDrawableByLayerId(android.R.id.progress);
    TintUtil.tintDrawable(backgroundDrawable, mProgressBackgroundColor);
    TintUtil.tintDrawable(progressDrawable, mProgressColor);
}
 
Example 8
Source File: ButtonFloat.java    From PhoneTutorial with Apache License 2.0 5 votes vote down vote up
public ButtonFloat(Context context, AttributeSet attrs) {
	super(context, attrs);
	setBackgroundResource(R.drawable.background_button_float);
	sizeRadius = 28;
	setDefaultProperties();
	icon = new ImageView(context);
	if(drawableIcon != null) {
		try {
			icon.setBackground(drawableIcon);
		} catch (NoSuchMethodError e) {
			icon.setBackgroundDrawable(drawableIcon);
		}
	}
	RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(Utils.dpToPx(sizeIcon, getResources()),Utils.dpToPx(sizeIcon, getResources()));
	params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
	icon.setLayoutParams(params);
	addView(icon);		
	
	LayerDrawable layer = (LayerDrawable) getBackground();
	GradientDrawable shape =  (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground);
	shape.setColor(backgroundColor);
	
	post(new Runnable() {
		
		@Override
		public void run() {
			showPosition = ViewHelper.getY(ButtonFloat.this) - Utils.dpToPx(24, getResources());
			hidePosition = ViewHelper.getY(ButtonFloat.this) + getHeight() * 3;
			ViewHelper.setY(ButtonFloat.this, hidePosition);
		}
	});
	
}
 
Example 9
Source File: Card.java    From MaterialDesignLibrary with Apache License 2.0 5 votes vote down vote up
public void setBackgroundColor(int color){
	this.backgroundColor = color;
	if(isEnabled())
		beforeBackground = backgroundColor;
	LayerDrawable layer = (LayerDrawable) getBackground();
	GradientDrawable shape =  (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground);
	shape.setColor(backgroundColor);
}
 
Example 10
Source File: ProgressBarDeterminate.java    From MoeGallery with GNU General Public License v3.0 5 votes vote down vote up
public void setBackgroundColor(int color){
	this.backgroundColor = color;
	if(isEnabled())
		beforeBackground = backgroundColor;
	LayerDrawable layer = (LayerDrawable) progressView.getBackground();
	GradientDrawable shape =  (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground);
	shape.setColor(color);
	super.setBackgroundColor(makePressColor());
}
 
Example 11
Source File: ReactSliderManager.java    From react-native-GPay with MIT License 5 votes vote down vote up
@ReactProp(name = "maximumTrackTintColor", customType = "Color")
public void setMaximumTrackTintColor(ReactSlider view, Integer color) {
  LayerDrawable drawable = (LayerDrawable) view.getProgressDrawable().getCurrent();
  Drawable background = drawable.findDrawableByLayerId(android.R.id.background);
  if (color == null) {
    background.clearColorFilter();
  } else {
    background.setColorFilter(color, PorterDuff.Mode.SRC_IN);
  }
}
 
Example 12
Source File: CheckBox.java    From MaterialDesignLibrary with Apache License 2.0 5 votes vote down vote up
public void changeBackground() {
	if (check) {
		setBackgroundResource(R.drawable.background_checkbox_check);
		LayerDrawable layer = (LayerDrawable) getBackground();
		GradientDrawable shape = (GradientDrawable) layer
				.findDrawableByLayerId(R.id.shape_bacground);
		shape.setColor(backgroundColor);
	} else {
		setBackgroundResource(R.drawable.background_checkbox_uncheck);
	}
}
 
Example 13
Source File: ProgressBarDeterminate.java    From meiShi with Apache License 2.0 5 votes vote down vote up
public void setBackgroundColor(int color){
	this.backgroundColor = color;
	if(isEnabled())
		beforeBackground = backgroundColor;
	LayerDrawable layer = (LayerDrawable) progressView.getBackground();
	GradientDrawable shape =  (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground);
	shape.setColor(color);
	super.setBackgroundColor(makePressColor());
}
 
Example 14
Source File: ColorFragment.java    From FlippableStackView with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_dummy, container, false);
    Bundle bdl = getArguments();

    mMainLayout = (FrameLayout) v.findViewById(R.id.main_layout);

    LayerDrawable bgDrawable = (LayerDrawable) mMainLayout.getBackground();
    GradientDrawable shape = (GradientDrawable) bgDrawable.findDrawableByLayerId(R.id.background_shape);
    shape.setColor(bdl.getInt(EXTRA_COLOR));

    return v;
}
 
Example 15
Source File: TutorialActivity.java    From PhoneTutorial with Apache License 2.0 4 votes vote down vote up
private void setSmallBackground(View v){
	v.setBackgroundResource(R.drawable.background_small_indicator);
	LayerDrawable layer = (LayerDrawable) v.getBackground();
	GradientDrawable shape =  (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground);
	shape.setColor(colorIndicator);
}
 
Example 16
Source File: FlatPlaybackControlsFragment.java    From RetroMusicPlayer with GNU General Public License v3.0 4 votes vote down vote up
private void setProgressBarColor(int dark) {
    LayerDrawable ld = (LayerDrawable) progressSlider.getProgressDrawable();
    ClipDrawable clipDrawable = (ClipDrawable) ld.findDrawableByLayerId(android.R.id.progress);
    clipDrawable.setColorFilter(dark, PorterDuff.Mode.SRC_IN);
}
 
Example 17
Source File: Slider.java    From DMAudioStreamer with Apache License 2.0 4 votes vote down vote up
public void changeBackground() {
    setBackgroundResource(R.drawable.background_checkbox);
    LayerDrawable layer = (LayerDrawable) getBackground();
    GradientDrawable shape = (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground);
    shape.setColor(backgroundColor);
}
 
Example 18
Source File: SlideView.java    From slideview with MIT License 4 votes vote down vote up
void init(AttributeSet attrs, int defStyle) {
    inflate(getContext(), R.layout.sv_slide_view, this);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        setBackground(ContextCompat.getDrawable(getContext(), R.drawable.sv_view_bg));
    } else {
        setBackgroundDrawable(ContextCompat.getDrawable(getContext(), R.drawable.sv_view_bg));
    }
    slideTextView = findViewById(R.id.sv_text);
    slider = findViewById(R.id.sv_slider);
    slider.setOnSeekBarChangeListener(this);
    slideBackground = getBackground();
    buttonLayers = (LayerDrawable) slider.getThumb();
    buttonBackground = buttonLayers.findDrawableByLayerId(R.id.buttonBackground);

    TypedArray a = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.SlideView,
            defStyle, defStyle);

    int strokeColor;
    float slideTextSize = spToPx(16, getContext());
    String slideText;
    boolean reverseSlide;
    ColorStateList sliderTextColor;
    try {
        animateSlideText = a.getBoolean(R.styleable.SlideView_sv_animateSlideText, true);
        reverseSlide = a.getBoolean(R.styleable.SlideView_sv_reverseSlide, false);
        strokeColor = a.getColor(R.styleable.SlideView_sv_strokeColor, ContextCompat.
                getColor(getContext(), R.color.sv_stroke_color_default));


        slideText = a.getString(R.styleable.SlideView_sv_slideText);
        sliderTextColor = a.getColorStateList(R.styleable.SlideView_sv_slideTextColor);

        slideTextSize = a.getDimension(R.styleable.SlideView_sv_slideTextSize, slideTextSize);
        slideTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, slideTextSize);

        setText(slideText);
        setTextColor(sliderTextColor == null ? slideTextView.getTextColors() : sliderTextColor);

        int buttonImageId = a.getResourceId(R.styleable.SlideView_sv_buttonImage, R.drawable.sv_ic_chevron_double_right);
        setButtonImage(ContextCompat.getDrawable(getContext(), buttonImageId));
        setButtonImageDisabled(ContextCompat.getDrawable(getContext(), a.getResourceId
                (R.styleable.SlideView_sv_buttonImageDisabled, buttonImageId)));

        setButtonBackgroundColor(a.getColorStateList(R.styleable.SlideView_sv_buttonBackgroundColor));
        setSlideBackgroundColor(a.getColorStateList(R.styleable.SlideView_sv_slideBackgroundColor));

        if (a.hasValue(R.styleable.SlideView_sv_strokeColor)) {
            Util.setDrawableStroke(slideBackground, strokeColor);
        }
        if (reverseSlide) {
            slider.setRotation(180);
            LayoutParams params = ((LayoutParams) slideTextView.getLayoutParams());
            params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, 0);
            params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                params.addRule(RelativeLayout.ALIGN_PARENT_END, 0);
                params.addRule(RelativeLayout.ALIGN_PARENT_START);
            }
            slideTextView.setLayoutParams(params);
        }
    } finally {
        a.recycle();
    }
}
 
Example 19
Source File: ButtonFloat.java    From PhoneTutorial with Apache License 2.0 4 votes vote down vote up
public void setBackgroundColor(int color){
	this.backgroundColor = color;
	LayerDrawable layer = (LayerDrawable) getBackground();
	GradientDrawable shape =  (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground);
	shape.setColor(backgroundColor);
}
 
Example 20
Source File: CheckBox.java    From MoeGallery with GNU General Public License v3.0 4 votes vote down vote up
private void changeBackgroundColor(int color) {
	LayerDrawable layer = (LayerDrawable) getBackground();
	GradientDrawable shape = (GradientDrawable) layer
			.findDrawableByLayerId(R.id.shape_bacground);
	shape.setColor(color);
}