Search in sources :

Example 1 with RippleDrawable

use of com.rey.material.drawable.RippleDrawable in project material by rey5137.

the class RippleManager method onClick.

@Override
public void onClick(View v) {
    Drawable background = v.getBackground();
    long delay = 0;
    if (background != null) {
        if (background instanceof RippleDrawable)
            delay = ((RippleDrawable) background).getClickDelayTime();
        else if (background instanceof ToolbarRippleDrawable)
            delay = ((ToolbarRippleDrawable) background).getClickDelayTime();
    }
    if (delay > 0 && v.getHandler() != null && !mClickScheduled) {
        mClickScheduled = true;
        v.getHandler().postDelayed(new ClickRunnable(v), delay);
    } else
        dispatchClickEvent(v);
}
Also used : ToolbarRippleDrawable(com.rey.material.drawable.ToolbarRippleDrawable) RippleDrawable(com.rey.material.drawable.RippleDrawable) ToolbarRippleDrawable(com.rey.material.drawable.ToolbarRippleDrawable) Drawable(android.graphics.drawable.Drawable) RippleDrawable(com.rey.material.drawable.RippleDrawable) ToolbarRippleDrawable(com.rey.material.drawable.ToolbarRippleDrawable)

Example 2 with RippleDrawable

use of com.rey.material.drawable.RippleDrawable in project material by rey5137.

the class FloatingActionButton method applyStyle.

protected void applyStyle(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FloatingActionButton, defStyleAttr, defStyleRes);
    int radius = -1;
    int elevation = -1;
    ColorStateList bgColor = null;
    int bgAnimDuration = -1;
    int iconSrc = 0;
    int iconLineMorphing = 0;
    for (int i = 0, count = a.getIndexCount(); i < count; i++) {
        int attr = a.getIndex(i);
        if (attr == R.styleable.FloatingActionButton_fab_radius)
            radius = a.getDimensionPixelSize(attr, 0);
        else if (attr == R.styleable.FloatingActionButton_fab_elevation)
            elevation = a.getDimensionPixelSize(attr, 0);
        else if (attr == R.styleable.FloatingActionButton_fab_backgroundColor)
            bgColor = a.getColorStateList(attr);
        else if (attr == R.styleable.FloatingActionButton_fab_backgroundAnimDuration)
            bgAnimDuration = a.getInteger(attr, 0);
        else if (attr == R.styleable.FloatingActionButton_fab_iconSrc)
            iconSrc = a.getResourceId(attr, 0);
        else if (attr == R.styleable.FloatingActionButton_fab_iconLineMorphing)
            iconLineMorphing = a.getResourceId(attr, 0);
        else if (attr == R.styleable.FloatingActionButton_fab_iconSize)
            mIconSize = a.getDimensionPixelSize(attr, 0);
        else if (attr == R.styleable.FloatingActionButton_fab_animDuration)
            mAnimDuration = a.getInteger(attr, 0);
        else if (attr == R.styleable.FloatingActionButton_fab_interpolator) {
            int resId = a.getResourceId(R.styleable.FloatingActionButton_fab_interpolator, 0);
            if (resId != 0)
                mInterpolator = AnimationUtils.loadInterpolator(context, resId);
        }
    }
    a.recycle();
    if (mIconSize < 0)
        mIconSize = ThemeUtil.dpToPx(context, 24);
    if (mAnimDuration < 0)
        mAnimDuration = context.getResources().getInteger(android.R.integer.config_mediumAnimTime);
    if (mInterpolator == null)
        mInterpolator = new DecelerateInterpolator();
    if (mBackground == null) {
        if (radius < 0)
            radius = ThemeUtil.dpToPx(context, 28);
        if (elevation < 0)
            elevation = ThemeUtil.dpToPx(context, 4);
        if (bgColor == null)
            bgColor = ColorStateList.valueOf(ThemeUtil.colorAccent(context, 0));
        if (bgAnimDuration < 0)
            bgAnimDuration = 0;
        mBackground = new OvalShadowDrawable(radius, bgColor, elevation, elevation, bgAnimDuration);
        mBackground.setInEditMode(isInEditMode());
        mBackground.setBounds(0, 0, getWidth(), getHeight());
        mBackground.setCallback(this);
    } else {
        if (radius >= 0)
            mBackground.setRadius(radius);
        if (bgColor != null)
            mBackground.setColor(bgColor);
        if (elevation >= 0)
            mBackground.setShadow(elevation, elevation);
        if (bgAnimDuration >= 0)
            mBackground.setAnimationDuration(bgAnimDuration);
    }
    if (iconLineMorphing != 0)
        setIcon(new LineMorphingDrawable.Builder(context, iconLineMorphing).build(), false);
    else if (iconSrc != 0)
        setIcon(context.getResources().getDrawable(iconSrc), false);
    getRippleManager().onCreate(this, context, attrs, defStyleAttr, defStyleRes);
    Drawable background = getBackground();
    if (background != null && background instanceof RippleDrawable) {
        RippleDrawable drawable = (RippleDrawable) background;
        drawable.setBackgroundDrawable(null);
        drawable.setMask(RippleDrawable.Mask.TYPE_OVAL, 0, 0, 0, 0, (int) mBackground.getPaddingLeft(), (int) mBackground.getPaddingTop(), (int) mBackground.getPaddingRight(), (int) mBackground.getPaddingBottom());
    }
}
Also used : DecelerateInterpolator(android.view.animation.DecelerateInterpolator) TypedArray(android.content.res.TypedArray) RippleDrawable(com.rey.material.drawable.RippleDrawable) Drawable(android.graphics.drawable.Drawable) LineMorphingDrawable(com.rey.material.drawable.LineMorphingDrawable) OvalShadowDrawable(com.rey.material.drawable.OvalShadowDrawable) ColorStateList(android.content.res.ColorStateList) LineMorphingDrawable(com.rey.material.drawable.LineMorphingDrawable) OvalShadowDrawable(com.rey.material.drawable.OvalShadowDrawable) RippleDrawable(com.rey.material.drawable.RippleDrawable)

Example 3 with RippleDrawable

use of com.rey.material.drawable.RippleDrawable in project material by rey5137.

the class RippleManager method onCreate.

/**
     * Should be called in the construction method of view to create a RippleDrawable.
     * @param v
     * @param context
     * @param attrs
     * @param defStyleAttr
     * @param defStyleRes
     */
public void onCreate(View v, Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    if (v.isInEditMode())
        return;
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RippleView, defStyleAttr, defStyleRes);
    int rippleStyle = a.getResourceId(R.styleable.RippleView_rd_style, 0);
    RippleDrawable drawable = null;
    if (rippleStyle != 0)
        drawable = new RippleDrawable.Builder(context, rippleStyle).backgroundDrawable(getBackground(v)).build();
    else {
        boolean rippleEnable = a.getBoolean(R.styleable.RippleView_rd_enable, false);
        if (rippleEnable)
            drawable = new RippleDrawable.Builder(context, attrs, defStyleAttr, defStyleRes).backgroundDrawable(getBackground(v)).build();
    }
    a.recycle();
    if (drawable != null)
        ViewUtil.setBackground(v, drawable);
}
Also used : TypedArray(android.content.res.TypedArray) RippleDrawable(com.rey.material.drawable.RippleDrawable) ToolbarRippleDrawable(com.rey.material.drawable.ToolbarRippleDrawable)

Aggregations

RippleDrawable (com.rey.material.drawable.RippleDrawable)3 TypedArray (android.content.res.TypedArray)2 Drawable (android.graphics.drawable.Drawable)2 ToolbarRippleDrawable (com.rey.material.drawable.ToolbarRippleDrawable)2 ColorStateList (android.content.res.ColorStateList)1 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)1 LineMorphingDrawable (com.rey.material.drawable.LineMorphingDrawable)1 OvalShadowDrawable (com.rey.material.drawable.OvalShadowDrawable)1