use of com.devpaul.materiallibrary.utils.ShadowRippleGenerator in project MaterialLibrary by DeveloperPaul123.
the class MaterialFlatButton method init.
@Override
public void init(Context context, AttributeSet attrs) {
String text = "Button";
TypedArray a = null;
if (attrs != null) {
try {
a = context.obtainStyledAttributes(attrs, R.styleable.MaterialFlatButton);
String temp = a.getString(R.styleable.MaterialFlatButton_mat_flat_button_text);
isFlat = a.getBoolean(R.styleable.MaterialFlatButton_mat_flat_button_is_flat, false);
color = a.getColor(R.styleable.MaterialFlatButton_mat_flat_button_color, getColor(R.color.material_deep_teal_500));
if (temp != null)
text = temp;
} finally {
if (a != null) {
a.recycle();
}
}
} else {
isFlat = false;
color = getColor(R.color.material_deep_teal_500);
}
padding = getDimension(R.dimen.material_flat_button_padding);
buttonHeight = getDimension(R.dimen.material_flat_button_draw_height);
viewHeight = getDimension(R.dimen.material_flat_button_height) + padding;
minWidth = getDimension(R.dimen.material_flat_button_min_width);
//2dp
clipRadius = getDimension(R.dimen.material_flat_button_clip_radius);
drawRect = new RectF(padding, padding / 2, minWidth + padding, buttonHeight + padding / 2);
mainPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mainPaint.setColor(color);
mainPaint.setStyle(Paint.Style.FILL);
shadowRippleGenerator = new ShadowRippleGenerator(this, mainPaint);
shadowRippleGenerator.setAnimationDuration(200);
shadowRippleGenerator.setBoundingRect(drawRect);
shadowRippleGenerator.setClipRadius(clipRadius);
shadowRippleGenerator.setRippleColor(ColorUtils.getDarkerColor(color));
shadowRippleGenerator.setMaxRippleRadius(minWidth / 2);
shadowRippleGenerator.setMaxShadowOffset(clipRadius / 2);
shadowRippleGenerator.setMaxShadowSize(clipRadius * 2);
createMainTextView(context, text);
setWillNotDraw(false);
}
use of com.devpaul.materiallibrary.utils.ShadowRippleGenerator in project MaterialLibrary by DeveloperPaul123.
the class MaterialFloatingActionButton method init.
/**
* Initialize various things for this view.
* @param context the context passed from the constructor.
* @param attributeSet attributeSet passed from the constructor.
*/
private void init(Context context, AttributeSet attributeSet) {
int size = 0;
//try to first deduce the accent color.
int accentColor = -1;
TypedArray a = null;
try {
TypedValue typedValue = new TypedValue();
a = context.obtainStyledAttributes(typedValue.data, new int[] { R.attr.colorAccent });
accentColor = a.getColor(0, -1);
} catch (Resources.NotFoundException e) {
e.printStackTrace();
} finally {
if (a != null) {
a.recycle();
}
}
//read the attributes.
TypedArray attr = context.obtainStyledAttributes(attributeSet, R.styleable.MaterialFloatingActionButton, 0, 0);
mButtonColor = attr.getColor(R.styleable.MaterialFloatingActionButton_mat_fab_colorNormal, accentColor == -1 ? getColor(android.R.color.holo_blue_dark) : accentColor);
mButtonPressedColor = attr.getColor(R.styleable.MaterialFloatingActionButton_mat_fab_colorPressed, ColorUtils.getDarkerColor(mButtonColor));
mIcon = attr.getResourceId(R.styleable.MaterialFloatingActionButton_mat_fab_icon, 0);
useSelector = attr.getBoolean(R.styleable.MaterialFloatingActionButton_mat_fab_use_selector, false);
size = attr.getInt(R.styleable.MaterialFloatingActionButton_mat_fab_size, 0);
attr.recycle();
iconSize = getDimension(R.dimen.mat_fab_icon_size);
if (mIcon != 0) {
iconBitmap = BitmapFactory.decodeResource(getResources(), mIcon);
drawable = new BitmapDrawable(getResources(), iconBitmap);
drawable.setAntiAlias(true);
bitmapRect = new Rect(0, 0, iconBitmap.getWidth(), iconBitmap.getHeight());
bitmapDrawRect = new RectF(0.0f, 0.0f, iconSize, iconSize);
} else {
iconBitmap = getDefaulBitmap();
bitmapRect = new Rect(0, 0, iconBitmap.getWidth(), iconBitmap.getHeight());
bitmapDrawRect = new RectF(0.0f, 0.0f, iconSize, iconSize);
}
float maxShadowOffset = getDimension(R.dimen.mat_fab_shadow_offset) * 1.5f;
float minShadowOffset = maxShadowOffset / 1.5f;
float maxShadowSize = getDimension(R.dimen.mat_fab_shadow_max_radius);
float minShawdowSize = getDimension(R.dimen.mat_fab_shadow_min_radius) / 2;
buttonSize = size == 0 ? getDimension(R.dimen.mat_fab_normal_size) : getDimension(R.dimen.mat_fab_mini_size);
mSize = buttonSize + maxShadowSize * 4 + maxShadowOffset * 3;
cx = mSize / 2;
cy = mSize / 2;
rotation = 0;
rotationAnimator = ObjectAnimator.ofFloat(this, "rotation", MAX_ROTATION);
rotationAnimator.setDuration(200);
rotationAnimator.setInterpolator(new OvershootInterpolator());
float halfsize = buttonSize / 2;
float halfBitmapSize = iconSize / 2;
bitmapDrawRect.set(cx - halfBitmapSize, cy - halfBitmapSize, cx + halfBitmapSize, cy + halfBitmapSize);
mButtonPaint.setStyle(Paint.Style.FILL);
mButtonPaint.setColor(mButtonColor);
bitmapPaint = new Paint();
bitmapPaint.setAntiAlias(true);
bitmapPaint.setFilterBitmap(true);
bitmapPaint.setDither(true);
shadowRippleGenerator = new ShadowRippleGenerator(this, mButtonPaint);
shadowRippleGenerator.setRippleColor(ColorUtils.getDarkerColor(mButtonColor));
shadowRippleGenerator.setClipRadius((int) buttonSize / 2);
shadowRippleGenerator.setAnimationDuration(200);
shadowRippleGenerator.setMaxRippleRadius((int) (0.75f * buttonSize / 2));
shadowRippleGenerator.setBoundingRect(new RectF(cx - halfsize, cy - halfsize, cx + halfsize, cy + halfsize));
shadowSelectorGenerator = new ShadowSelectorGenerator(this, mButtonPaint);
shadowSelectorGenerator.setNormalColor(mButtonColor);
shadowSelectorGenerator.setPressedColor(mButtonPressedColor);
shadowSelectorGenerator.setAnimationDuration(200);
shadowSelectorGenerator.setShadowLimits(minShadowOffset, maxShadowOffset, minShawdowSize, maxShadowSize);
invalidate();
}
Aggregations