use of com.devpaul.materiallibrary.utils.ShadowSelectorGenerator 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