use of net.qiujuer.genius.ui.drawable.shape.BorderShape in project Genius-Android by qiujuer.
the class EditText method initBackground.
private void initBackground() {
final int lineSize = getLineSize();
Drawable background;
if (lineSize == 0) {
background = null;
} else {
int increment = getResources().getDimensionPixelSize(R.dimen.g_editText_lineSize_active_increment);
int lineActive = lineSize + increment;
int lineHalf = lineSize >> 1;
// Creating normal state drawable
ShapeDrawable normal = new ShapeDrawable(new BorderShape(new RectF(0, 0, 0, lineSize)));
normal.getPaint().setColor(getLineColor(new int[] { android.R.attr.state_enabled }));
// Creating pressed state drawable
ShapeDrawable pressed = new ShapeDrawable(new BorderShape(new RectF(0, 0, 0, lineActive)));
pressed.getPaint().setColor(getLineColor(new int[] { android.R.attr.state_pressed, android.R.attr.state_enabled }));
// Creating focused state drawable
ShapeDrawable focused = new ShapeDrawable(new BorderShape(new RectF(0, 0, 0, lineActive)));
focused.getPaint().setColor(getLineColor(new int[] { android.R.attr.state_focused, android.R.attr.state_enabled }));
// Creating disabled state drawable
ShapeDrawable disabled = new ShapeDrawable(new BorderShape(new RectF(0, 0, 0, lineHalf), lineHalf, lineSize));
disabled.getPaint().setColor(getLineColor(new int[] { -android.R.attr.state_enabled }));
// disabled.getPaint().setAlpha(0xA0);
Drawable[] drawable = new Drawable[] { pressed, focused, normal, disabled };
background = createStateListDrawable(drawable);
}
// Set Background
UiCompat.setBackground(this, background);
}
use of net.qiujuer.genius.ui.drawable.shape.BorderShape in project Genius-Android by qiujuer.
the class TextView method setBorder.
/**
* Set the border, You can init border size, color and decision that direction contains border
*
* @param flag use {@link #BORDER_ALL } if you need All border,
* or {@link #BORDER_LEFT} the view will have Left border
* of case you can use eg: {@link #BORDER_LEFT}|{@link #BORDER_BOTTOM}
* the view will left and bottom border
* <p>
* if you not use border you need set the flag to 0
* @param size set all border size, unit is px, if you use dp, plx see {@link Ui#dipToPx(Resources, float)} )}
* @param color set all border color
*/
public void setBorder(int flag, int size, int color) {
if (mBorder != flag || mBorderSize != size || mBorderColor != color) {
mBorder = flag;
mBorderSize = size;
mBorderColor = color;
if (flag <= 0) {
mBorderDrawable = null;
} else {
RectF borderRect;
if ((flag & BORDER_ALL) == BORDER_ALL)
borderRect = new RectF(size, size, size, size);
else {
int l = 0, t = 0, r = 0, b = 0;
if ((flag & BORDER_LEFT) == BORDER_LEFT)
l = size;
if ((flag & BORDER_RIGHT) == BORDER_RIGHT)
r = size;
if ((flag & BORDER_TOP) == BORDER_TOP)
t = size;
if ((flag & BORDER_BOTTOM) == BORDER_BOTTOM)
b = size;
borderRect = new RectF(l, t, r, b);
}
if (mBorderDrawable == null) {
ShapeDrawable drawable = new ShapeDrawable(new BorderShape(borderRect));
Paint paint = drawable.getPaint();
paint.setColor(color);
drawable.setCallback(this);
mBorderDrawable = drawable;
} else {
ShapeDrawable drawable = (ShapeDrawable) mBorderDrawable;
Paint paint = drawable.getPaint();
paint.setColor(color);
BorderShape shape = (BorderShape) drawable.getShape();
shape.setBorder(borderRect);
}
}
invalidate();
}
}
Aggregations