use of android.graphics.BitmapShader in project remusic by aa112901.
the class RoundImageView method make.
private void make(Bitmap bitmap) {
mBitmap = getCroppedRoundBitmap(bitmap, 255, 15);
mBitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
mBitmapPaint.setAntiAlias(true);
mBitmapPaint.setShader(mBitmapShader);
mDrawableRect.set(0, 0, getWidth(), getHeight());
mDrawableRadius = Math.min(mDrawableRect.height() / 2, mDrawableRect.width() / 2);
mBitmapHeight = mBitmap.getHeight();
mBitmapWidth = mBitmap.getWidth();
updateShaderMatrix();
invalidate();
}
use of android.graphics.BitmapShader in project Carbon by ZieIony.
the class EditText method initEditText.
private void initEditText(AttributeSet attrs, int defStyleAttr) {
if (isInEditMode())
return;
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.EditText, defStyleAttr, R.style.carbon_EditText);
int ap = a.getResourceId(R.styleable.EditText_android_textAppearance, -1);
if (ap != -1)
setTextAppearanceInternal(ap);
for (int i = 0; i < a.getIndexCount(); i++) {
int attr = a.getIndex(i);
if (attr == R.styleable.EditText_carbon_textAllCaps) {
setAllCaps(a.getBoolean(attr, false));
} else if (!isInEditMode() && attr == R.styleable.EditText_carbon_fontPath) {
String path = a.getString(attr);
Typeface typeface = TypefaceUtils.getTypeface(getContext(), path);
setTypeface(typeface);
} else if (attr == R.styleable.EditText_carbon_fontFamily) {
int textStyle = a.getInt(R.styleable.EditText_android_textStyle, 0);
Typeface typeface = TypefaceUtils.getTypeface(getContext(), a.getString(attr), textStyle);
setTypeface(typeface);
}
}
setCursorColor(a.getColor(R.styleable.EditText_carbon_cursorColor, 0));
setPattern(a.getString(R.styleable.EditText_carbon_pattern));
DIVIDER_PADDING = (int) getResources().getDimension(R.dimen.carbon_paddingHalf);
setMatchingView(a.getResourceId(R.styleable.EditText_carbon_matchingView, 0));
setUnderline(a.getBoolean(R.styleable.EditText_carbon_underline, true));
Carbon.initRippleDrawable(this, a, rippleIds);
Carbon.initTint(this, a, tintIds);
Carbon.initElevation(this, a, elevationIds);
Carbon.initAnimations(this, a, animationIds);
Carbon.initTouchMargin(this, a, touchMarginIds);
setCornerRadius(a.getDimension(R.styleable.EditText_carbon_cornerRadius, 0));
Carbon.initHtmlText(this, a, R.styleable.EditText_carbon_htmlText);
a.recycle();
try {
Field mHighlightPaintField = android.widget.TextView.class.getDeclaredField("mHighlightPaint");
mHighlightPaintField.setAccessible(true);
mHighlightPaintField.set(this, new Paint() {
@Override
public void setColor(int color) {
if (getSelectionStart() == getSelectionEnd()) {
super.setColor(cursorColor);
} else {
super.setColor(color);
}
}
});
} catch (Exception e) {
}
int underlineWidth = getResources().getDimensionPixelSize(R.dimen.carbon_1dip);
Bitmap dashPathBitmap = Bitmap.createBitmap(underlineWidth * 4, underlineWidth, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(dashPathBitmap);
paint.setColor(0xffffffff);
paint.setAlpha(255);
c.drawCircle(dashPathBitmap.getHeight() / 2.0f, dashPathBitmap.getHeight() / 2.0f, dashPathBitmap.getHeight() / 2.0f, paint);
dashPathShader = new BitmapShader(dashPathBitmap, Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
initSelectionHandle();
addTextChangedListener(new SimpleTextWatcher() {
@Override
public void afterTextChanged(Editable editable) {
validateInternalEvent();
}
});
validateInternalEvent();
if (getElevation() > 0)
AnimUtils.setupElevationAnimator(stateAnimator, this);
}
use of android.graphics.BitmapShader in project JamsMusicPlayer by psaravan.
the class PicassoCircularTransformer method transform.
@Override
public Bitmap transform(Bitmap source) {
int size = Math.min(source.getWidth(), source.getHeight());
int x = (source.getWidth() - size) / 2;
int y = (source.getHeight() - size) / 2;
Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size);
if (squaredBitmap != source) {
source.recycle();
}
Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig());
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
paint.setShader(shader);
paint.setAntiAlias(true);
float r = size / 2f;
canvas.drawCircle(r, r, r, paint);
squaredBitmap.recycle();
return bitmap;
}
use of android.graphics.BitmapShader in project JamsMusicPlayer by psaravan.
the class PicassoRoundedRectTransformer method transform.
@Override
public Bitmap transform(final Bitmap source) {
final Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
Bitmap output = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
canvas.drawRoundRect(new RectF(margin, margin, source.getWidth() - margin, source.getHeight() - margin), radius, radius, paint);
if (source != output) {
source.recycle();
}
return output;
}
use of android.graphics.BitmapShader in project plaid by nickbutcher.
the class CircleTransform method circleCrop.
private static Bitmap circleCrop(BitmapPool pool, Bitmap source) {
if (source == null)
return null;
int size = Math.min(source.getWidth(), source.getHeight());
int x = (source.getWidth() - size) / 2;
int y = (source.getHeight() - size) / 2;
// TODO this could be acquired from the pool too
Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);
Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
if (result == null) {
result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
}
Canvas canvas = new Canvas(result);
Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG | Paint.ANTI_ALIAS_FLAG);
paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
float r = size / 2f;
canvas.drawCircle(r, r, r, paint);
return result;
}
Aggregations