@Override public void setTintList(ColorStateList tint) { mTint = tint; updateTintFilter(); }
public void setProgress(float progress) { if(mProgress != progress) { mProgress = progress; invalidateSelf(); } }
@Override public void draw(Canvas canvas) { final Rect bounds = getBounds(); final boolean isRtl = isLayoutRtl(); final float canvasRotate = lerp(isRtl ? -180 : 0, isRtl ? 0 : 180, mProgress); mPath.rewind(); for(int i = 0; i < mCurrent.size(); i++) { Bezier current = mCurrent.get(i); lerp(mStart.get(i), mEnd.get(i), mCurrent.get(i), mProgress); current.addTo(mPath); } canvas.save(); canvas.translate(bounds.centerX(), bounds.centerY()); if (mSpin) { canvas.rotate(canvasRotate * (isRtl ? -1 : 1)); } else if (isRtl) { canvas.rotate(180); } canvas.drawPath(mPath, mPaint); canvas.restore(); }
public SearchArrowDrawable(Context context, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) { super(context, defStyleAttr, defStyleRes); final TypedArray typedArray = context.getTheme() .obtainStyledAttributes(null, R.styleable.SearchArrowToggle, defStyleAttr, defStyleRes); float radius = round(typedArray.getDimension(R.styleable.SearchArrowToggle_td_searchRadius, 0)); float barLength = round(typedArray.getDimension(R.styleable.SearchArrowToggle_td_searchLength, 0)); float arrowHeadLength = round(typedArray.getDimension( R.styleable.SearchArrowToggle_td_arrowHeadLength, 0)); float arrowShaftLength = typedArray .getDimension(R.styleable.SearchArrowToggle_td_arrowShaftLength, 0); typedArray.recycle(); SearchModel search = new SearchModel(radius, barLength); ArrowModel arrow = new ArrowModel(arrowShaftLength, arrowHeadLength, getStrokeWidth()); add(search.handle, arrow.bottomHead); add(search.topRightQuadrant, arrow.topHead); add(search.bottomRightQuadrant, arrow.bottomHead); add(search.topLeftQuadrant, arrow.body); add(search.bottomLeftQuadrant, arrow.body); } }
public DrawerArrowDrawable(Context context, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) { super(context, defStyleAttr, defStyleRes); final TypedArray typedArray = context.getTheme() .obtainStyledAttributes(null, R.styleable.DrawerArrowToggle, defStyleAttr, defStyleRes); float gapSize = round(typedArray.getDimension(R.styleable.DrawerArrowToggle_td_gapSize, 0)); float barLength = round(typedArray.getDimension(R.styleable.DrawerArrowToggle_td_crossLength, 0)); float arrowHeadLength = round(typedArray.getDimension( R.styleable.DrawerArrowToggle_td_arrowHeadLength, 0)); float arrowShaftLength = typedArray .getDimension(R.styleable.DrawerArrowToggle_td_arrowShaftLength, 0); typedArray.recycle(); DrawerModel drawer = new DrawerModel(barLength, gapSize); ArrowModel arrow = new ArrowModel(arrowShaftLength, arrowHeadLength, getStrokeWidth()); add(drawer.topLine, arrow.topHead); add(drawer.middleLine, arrow.body); add(drawer.bottomLine, arrow.bottomHead); } }
public SearchCrossDrawable(Context context, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) { super(context, defStyleAttr, defStyleRes); final TypedArray typedArray = context.getTheme() .obtainStyledAttributes(null, R.styleable.SearchCrossToggle, defStyleAttr, defStyleRes); float radius = round(typedArray.getDimension(R.styleable.SearchCrossToggle_td_searchRadius, 0)); float searchLength = round(typedArray.getDimension(R.styleable.SearchCrossToggle_td_searchLength, 0)); float crossLength = round(typedArray.getDimension(R.styleable.SearchCrossToggle_td_crossLength, 0)); typedArray.recycle(); SearchModel search = new SearchModel(radius, searchLength); CrossModel cross = new CrossModel(crossLength); add(search.handle, cross.upLine); add(search.topRightQuadrant, cross.upLine); add(search.bottomRightQuadrant, cross.upLine); add(search.topLeftQuadrant, cross.downLine); add(search.bottomLeftQuadrant, cross.downLine); } }
add(new SearchArrowDrawable(this)); add(new SearchCrossDrawable(this)); add(new DrawerArrowDrawable(this)); add(new MyCustomToggleDrawable(this));
private void updateTintFilter() { if (mTint == null || mTintMode == null) { setColorFilter(null); return; } final int color = mTint.getColorForState(getState(), Color.TRANSPARENT); setColorFilter(new PorterDuffColorFilter(color, mTintMode)); }
@Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { for(ToggleDrawable drawable : mToggleDrawables) drawable.setProgress(progress / (float) seekBar.getMax()); }
public void setSpinEnabled(boolean spin) { if(mSpin != spin) { mSpin = spin; invalidateSelf(); } }
@Override protected boolean onStateChange(int[] state) { updateTintFilter(); return true; }
@Override public void setColorFilter(ColorFilter colorFilter) { mPaint.setColorFilter(colorFilter); invalidateSelf(); }
@Override public void setTintMode(@NonNull PorterDuff.Mode tintMode) { if(mTintMode != tintMode) { mTintMode = tintMode; updateTintFilter(); } }
public void setStrokeWidth(float strokeWidth) { if(mStrokeWidth != strokeWidth) { mStrokeWidth = strokeWidth; mPaint.setStrokeWidth(strokeWidth); invalidateSelf(); } }
public ToggleDrawable(Context context, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) { final TypedArray typedArray = context.getTheme() .obtainStyledAttributes(null, R.styleable.ToggleDrawable, defStyleAttr, defStyleRes); mPaint.setAntiAlias(true); mPaint.setColor(typedArray.getColor(R.styleable.ToggleDrawable_td_color, 0)); mSize = typedArray.getDimensionPixelSize(R.styleable.ToggleDrawable_td_drawableSize, 0); mStrokeWidth = typedArray.getDimension(R.styleable.ToggleDrawable_td_stroke, 0); mSpin = typedArray.getBoolean(R.styleable.ToggleDrawable_td_spin, true); typedArray.recycle(); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.MITER); mPaint.setStrokeCap(Paint.Cap.BUTT); mPaint.setStrokeWidth(mStrokeWidth); updateTintFilter(); }
@Override public void setAlpha(int alpha) { if (alpha != mPaint.getAlpha()) { mPaint.setAlpha(alpha); invalidateSelf(); } }