Search in sources :

Example 1 with TouchEffectAnimator

use of com.cengalabs.flatui.TouchEffectAnimator in project FlatUI by eluleci.

the class RippleLinearLayout method init.

private void init() {
    // you should set a background to view for effect to be visible. in this sample, this
    // linear layout contains a transparent background which is set inside the XML
    // giving the view to animate on
    touchEffectAnimator = new TouchEffectAnimator(this);
    // enabling ripple effect. it only performs ease effect without enabling ripple effect
    touchEffectAnimator.setHasRippleEffect(true);
    // setting the effect color
    touchEffectAnimator.setEffectColor(Color.LTGRAY);
    // setting the duration
    touchEffectAnimator.setAnimDuration(1000);
    // setting radius to clip the effect. use it if you have a rounded background
    touchEffectAnimator.setClipRadius(20);
    // the view must contain an onClickListener to receive UP touch events. touchEffectAnimator
    // doesn't return any value in onTouchEvent for flexibility. so it is developers
    // responsibility to add a listener
    setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
        }
    });
}
Also used : TouchEffectAnimator(com.cengalabs.flatui.TouchEffectAnimator) View(android.view.View)

Example 2 with TouchEffectAnimator

use of com.cengalabs.flatui.TouchEffectAnimator in project FlatUI by eluleci.

the class FlatButton method init.

private void init(AttributeSet attrs) {
    // saving padding values for using them after setting background drawable
    final int paddingTop = getPaddingTop();
    final int paddingRight = getPaddingRight();
    final int paddingLeft = getPaddingLeft();
    final int paddingBottom = getPaddingBottom();
    if (attributes == null)
        attributes = new Attributes(this, getResources());
    if (attrs != null) {
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.fl_FlatButton);
        // getting common attributes
        int customTheme = a.getResourceId(R.styleable.fl_FlatButton_fl_theme, Attributes.DEFAULT_THEME);
        attributes.setThemeSilent(customTheme, getResources());
        attributes.setTouchEffect(a.getInt(R.styleable.fl_FlatButton_fl_touchEffect, Attributes.DEFAULT_TOUCH_EFFECT));
        attributes.setFontFamily(a.getString(R.styleable.fl_FlatButton_fl_fontFamily));
        attributes.setFontWeight(a.getString(R.styleable.fl_FlatButton_fl_fontWeight));
        attributes.setFontExtension(a.getString(R.styleable.fl_FlatButton_fl_fontExtension));
        attributes.setTextAppearance(a.getInt(R.styleable.fl_FlatButton_fl_textAppearance, Attributes.DEFAULT_TEXT_APPEARANCE));
        attributes.setRadius(a.getDimensionPixelSize(R.styleable.fl_FlatButton_fl_cornerRadius, Attributes.DEFAULT_RADIUS_PX));
        // getting view specific attributes
        bottom = a.getDimensionPixelSize(R.styleable.fl_FlatButton_fl_blockButtonEffectHeight, bottom);
        a.recycle();
    }
    if (attributes.hasTouchEffect()) {
        boolean hasRippleEffect = attributes.getTouchEffect() == Attributes.RIPPLE_TOUCH_EFFECT;
        touchEffectAnimator = new TouchEffectAnimator(this);
        touchEffectAnimator.setHasRippleEffect(hasRippleEffect);
        touchEffectAnimator.setEffectColor(attributes.getColor(1));
        touchEffectAnimator.setClipRadius(attributes.getRadius());
    }
    /*mPaint = new Paint();
        mPaint.setColor(attributes.getColor(1));
        mPaint.setAlpha(mAlpha);*/
    // creating normal state drawable
    ShapeDrawable normalFront = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
    normalFront.getPaint().setColor(attributes.getColor(2));
    ShapeDrawable normalBack = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
    normalBack.getPaint().setColor(attributes.getColor(1));
    normalBack.setPadding(0, 0, 0, bottom);
    Drawable[] d = { normalBack, normalFront };
    LayerDrawable normal = new LayerDrawable(d);
    // creating pressed state drawable
    ShapeDrawable pressedFront = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
    pressedFront.getPaint().setColor(attributes.getColor(1));
    ShapeDrawable pressedBack = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
    pressedBack.getPaint().setColor(attributes.getColor(0));
    if (bottom != 0)
        pressedBack.setPadding(0, 0, 0, bottom / 2);
    Drawable[] d2 = { pressedBack, pressedFront };
    LayerDrawable pressed = new LayerDrawable(d2);
    // creating disabled state drawable
    ShapeDrawable disabledFront = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
    disabledFront.getPaint().setColor(attributes.getColor(3));
    disabledFront.getPaint().setAlpha(0xA0);
    ShapeDrawable disabledBack = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
    disabledBack.getPaint().setColor(attributes.getColor(2));
    Drawable[] d3 = { disabledBack, disabledFront };
    LayerDrawable disabled = new LayerDrawable(d3);
    StateListDrawable states = new StateListDrawable();
    if (!attributes.hasTouchEffect())
        states.addState(new int[] { android.R.attr.state_pressed, android.R.attr.state_enabled }, pressed);
    states.addState(new int[] { android.R.attr.state_focused, android.R.attr.state_enabled }, pressed);
    states.addState(new int[] { android.R.attr.state_enabled }, normal);
    states.addState(new int[] { -android.R.attr.state_enabled }, disabled);
    setBackgroundDrawable(states);
    setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
    if (attributes.getTextAppearance() == 1)
        setTextColor(attributes.getColor(0));
    else if (attributes.getTextAppearance() == 2)
        setTextColor(attributes.getColor(3));
    else
        setTextColor(Color.WHITE);
    // check for IDE preview render
    if (!this.isInEditMode()) {
        Typeface typeface = FlatUI.getFont(getContext(), attributes);
        if (typeface != null)
            setTypeface(typeface);
    }
}
Also used : RoundRectShape(android.graphics.drawable.shapes.RoundRectShape) TouchEffectAnimator(com.cengalabs.flatui.TouchEffectAnimator) Typeface(android.graphics.Typeface) TypedArray(android.content.res.TypedArray) LayerDrawable(android.graphics.drawable.LayerDrawable) Attributes(com.cengalabs.flatui.Attributes) LayerDrawable(android.graphics.drawable.LayerDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable)

Aggregations

TouchEffectAnimator (com.cengalabs.flatui.TouchEffectAnimator)2 TypedArray (android.content.res.TypedArray)1 Typeface (android.graphics.Typeface)1 Drawable (android.graphics.drawable.Drawable)1 LayerDrawable (android.graphics.drawable.LayerDrawable)1 ShapeDrawable (android.graphics.drawable.ShapeDrawable)1 StateListDrawable (android.graphics.drawable.StateListDrawable)1 RoundRectShape (android.graphics.drawable.shapes.RoundRectShape)1 View (android.view.View)1 Attributes (com.cengalabs.flatui.Attributes)1