use of android.graphics.drawable.GradientDrawable in project FlatUI by eluleci.
the class FlatRadioButton method init.
private void init(AttributeSet attrs) {
if (attributes == null)
attributes = new Attributes(this, getResources());
if (attrs != null) {
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.fl_FlatRadioButton);
// getting common attributes
int customTheme = a.getResourceId(R.styleable.fl_FlatRadioButton_fl_theme, Attributes.DEFAULT_THEME);
attributes.setThemeSilent(customTheme, getResources());
attributes.setFontFamily(a.getString(R.styleable.fl_FlatRadioButton_fl_fontFamily));
attributes.setFontWeight(a.getString(R.styleable.fl_FlatRadioButton_fl_fontWeight));
attributes.setFontExtension(a.getString(R.styleable.fl_FlatRadioButton_fl_fontExtension));
attributes.setSize(a.getDimensionPixelSize(R.styleable.fl_FlatRadioButton_fl_size, Attributes.DEFAULT_SIZE_PX));
attributes.setRadius(attributes.getSize() / 2);
attributes.setBorderWidth(a.getDimensionPixelSize(R.styleable.fl_FlatRadioButton_fl_borderWidth, Attributes.DEFAULT_BORDER_WIDTH_PX));
// getting view specific attributes
dotMargin = a.getDimensionPixelSize(R.styleable.fl_FlatRadioButton_fl_dotMargin, dotMargin);
a.recycle();
}
// creating unchecked-enabled state drawable
GradientDrawable uncheckedEnabled = new GradientDrawable();
uncheckedEnabled.setCornerRadius(attributes.getRadius());
uncheckedEnabled.setSize(attributes.getSize(), attributes.getSize());
uncheckedEnabled.setColor(Color.TRANSPARENT);
uncheckedEnabled.setStroke(attributes.getBorderWidth(), attributes.getColor(2));
// creating checked-enabled state drawable
GradientDrawable checkedOutside = new GradientDrawable();
checkedOutside.setCornerRadius(attributes.getSize());
checkedOutside.setSize(attributes.getSize(), attributes.getSize());
checkedOutside.setColor(Color.TRANSPARENT);
checkedOutside.setStroke(attributes.getBorderWidth(), attributes.getColor(2));
PaintDrawable checkedCore = new PaintDrawable(attributes.getColor(2));
checkedCore.setCornerRadius(attributes.getSize());
checkedCore.setIntrinsicHeight(attributes.getSize());
checkedCore.setIntrinsicWidth(attributes.getSize());
InsetDrawable checkedInside = new InsetDrawable(checkedCore, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin);
Drawable[] checkedEnabledDrawable = { checkedOutside, checkedInside };
LayerDrawable checkedEnabled = new LayerDrawable(checkedEnabledDrawable);
// creating unchecked-enabled state drawable
GradientDrawable uncheckedDisabled = new GradientDrawable();
uncheckedDisabled.setCornerRadius(attributes.getRadius());
uncheckedDisabled.setSize(attributes.getSize(), attributes.getSize());
uncheckedDisabled.setColor(Color.TRANSPARENT);
uncheckedDisabled.setStroke(attributes.getBorderWidth(), attributes.getColor(3));
// creating checked-disabled state drawable
GradientDrawable checkedOutsideDisabled = new GradientDrawable();
checkedOutsideDisabled.setCornerRadius(attributes.getRadius());
checkedOutsideDisabled.setSize(attributes.getSize(), attributes.getSize());
checkedOutsideDisabled.setColor(Color.TRANSPARENT);
checkedOutsideDisabled.setStroke(attributes.getBorderWidth(), attributes.getColor(3));
PaintDrawable checkedCoreDisabled = new PaintDrawable(attributes.getColor(3));
checkedCoreDisabled.setCornerRadius(attributes.getRadius());
checkedCoreDisabled.setIntrinsicHeight(attributes.getSize());
checkedCoreDisabled.setIntrinsicWidth(attributes.getSize());
InsetDrawable checkedInsideDisabled = new InsetDrawable(checkedCoreDisabled, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin);
Drawable[] checkedDisabledDrawable = { checkedOutsideDisabled, checkedInsideDisabled };
LayerDrawable checkedDisabled = new LayerDrawable(checkedDisabledDrawable);
StateListDrawable states = new StateListDrawable();
states.addState(new int[] { -android.R.attr.state_checked, android.R.attr.state_enabled }, uncheckedEnabled);
states.addState(new int[] { android.R.attr.state_checked, android.R.attr.state_enabled }, checkedEnabled);
states.addState(new int[] { -android.R.attr.state_checked, -android.R.attr.state_enabled }, uncheckedDisabled);
states.addState(new int[] { android.R.attr.state_checked, -android.R.attr.state_enabled }, checkedDisabled);
setButtonDrawable(states);
// setting padding for avoiding text to be appear on icon
setPadding(attributes.getSize() / 4 * 5, 0, 0, 0);
setTextColor(attributes.getColor(2));
// check for IDE preview render
if (!this.isInEditMode()) {
Typeface typeface = FlatUI.getFont(getContext(), attributes);
if (typeface != null)
setTypeface(typeface);
}
}
use of android.graphics.drawable.GradientDrawable in project FlatUI by eluleci.
the class FlatAutoCompleteTextView method init.
private void init(AttributeSet attrs) {
if (attributes == null)
attributes = new Attributes(this, getResources());
if (attrs != null) {
// getting android default tags for textColor and textColorHint
hasOwnTextColor = attrs.getAttributeValue(FlatUI.androidStyleNameSpace, "textColor") != null;
hasOwnHintColor = attrs.getAttributeValue(FlatUI.androidStyleNameSpace, "textColorHint") != null;
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.fl_FlatAutoCompleteTextView);
// getting common attributes
int customTheme = a.getResourceId(R.styleable.fl_FlatAutoCompleteTextView_fl_theme, Attributes.DEFAULT_THEME);
attributes.setThemeSilent(customTheme, getResources());
attributes.setFontFamily(a.getString(R.styleable.fl_FlatAutoCompleteTextView_fl_fontFamily));
attributes.setFontWeight(a.getString(R.styleable.fl_FlatAutoCompleteTextView_fl_fontWeight));
attributes.setFontExtension(a.getString(R.styleable.fl_FlatAutoCompleteTextView_fl_fontExtension));
attributes.setTextAppearance(a.getInt(R.styleable.fl_FlatAutoCompleteTextView_fl_textAppearance, Attributes.DEFAULT_TEXT_APPEARANCE));
attributes.setRadius(a.getDimensionPixelSize(R.styleable.fl_FlatAutoCompleteTextView_fl_cornerRadius, Attributes.DEFAULT_RADIUS_PX));
attributes.setBorderWidth(a.getDimensionPixelSize(R.styleable.fl_FlatAutoCompleteTextView_fl_borderWidth, Attributes.DEFAULT_BORDER_WIDTH_PX));
// getting view specific attributes
style = a.getInt(R.styleable.fl_FlatAutoCompleteTextView_fl_autoFieldStyle, 0);
a.recycle();
}
GradientDrawable backgroundDrawable = new GradientDrawable();
backgroundDrawable.setCornerRadius(attributes.getRadius());
if (style == 0) {
// flat
if (!hasOwnTextColor)
setTextColor(attributes.getColor(3));
backgroundDrawable.setColor(attributes.getColor(2));
backgroundDrawable.setStroke(0, attributes.getColor(2));
} else if (style == 1) {
// box
if (!hasOwnTextColor)
setTextColor(attributes.getColor(2));
backgroundDrawable.setColor(Color.WHITE);
backgroundDrawable.setStroke(attributes.getBorderWidth(), attributes.getColor(2));
} else if (style == 2) {
// transparent
if (!hasOwnTextColor)
setTextColor(attributes.getColor(1));
backgroundDrawable.setColor(Color.TRANSPARENT);
backgroundDrawable.setStroke(attributes.getBorderWidth(), attributes.getColor(2));
}
setBackgroundDrawable(backgroundDrawable);
if (!hasOwnHintColor)
setHintTextColor(attributes.getColor(3));
if (attributes.getTextAppearance() == 1)
setTextColor(attributes.getColor(0));
else if (attributes.getTextAppearance() == 2)
setTextColor(attributes.getColor(3));
// check for IDE preview render
if (!this.isInEditMode()) {
Typeface typeface = FlatUI.getFont(getContext(), attributes);
if (typeface != null)
setTypeface(typeface);
}
}
use of android.graphics.drawable.GradientDrawable in project MyDiary by erttyy8821.
the class PageEffectView method drawCurrentPageShadow.
/**
* Author : hmg25 Version: 1.0 Description : 绘制翻起页的阴影
*/
public void drawCurrentPageShadow(Canvas canvas) {
double degree;
if (mIsRTandLB) {
degree = Math.PI / 4 - Math.atan2(mBezierControl1.y - mTouch.y, mTouch.x - mBezierControl1.x);
} else {
degree = Math.PI / 4 - Math.atan2(mTouch.y - mBezierControl1.y, mTouch.x - mBezierControl1.x);
}
// 翻起页阴影顶点与touch点的距离
double d1 = (float) 25 * 1.414 * Math.cos(degree);
double d2 = (float) 25 * 1.414 * Math.sin(degree);
float x = (float) (mTouch.x + d1);
float y;
if (mIsRTandLB) {
y = (float) (mTouch.y + d2);
} else {
y = (float) (mTouch.y - d2);
}
mPath1.reset();
mPath1.moveTo(x, y);
mPath1.lineTo(mTouch.x, mTouch.y);
mPath1.lineTo(mBezierControl1.x, mBezierControl1.y);
mPath1.lineTo(mBezierStart1.x, mBezierStart1.y);
mPath1.close();
float rotateDegrees;
canvas.save();
canvas.clipPath(mPath0, Region.Op.XOR);
canvas.clipPath(mPath1, Region.Op.INTERSECT);
int leftx;
int rightx;
GradientDrawable mCurrentPageShadow;
if (mIsRTandLB) {
leftx = (int) (mBezierControl1.x);
rightx = (int) mBezierControl1.x + 25;
mCurrentPageShadow = mFrontShadowDrawableVLR;
} else {
leftx = (int) (mBezierControl1.x - 25);
rightx = (int) mBezierControl1.x + 1;
mCurrentPageShadow = mFrontShadowDrawableVRL;
}
rotateDegrees = (float) Math.toDegrees(Math.atan2(mTouch.x - mBezierControl1.x, mBezierControl1.y - mTouch.y));
canvas.rotate(rotateDegrees, mBezierControl1.x, mBezierControl1.y);
mCurrentPageShadow.setBounds(leftx, (int) (mBezierControl1.y - mMaxLength), rightx, (int) (mBezierControl1.y));
mCurrentPageShadow.draw(canvas);
canvas.restore();
mPath1.reset();
mPath1.moveTo(x, y);
mPath1.lineTo(mTouch.x, mTouch.y);
mPath1.lineTo(mBezierControl2.x, mBezierControl2.y);
mPath1.lineTo(mBezierStart2.x, mBezierStart2.y);
mPath1.close();
canvas.save();
canvas.clipPath(mPath0, Region.Op.XOR);
canvas.clipPath(mPath1, Region.Op.INTERSECT);
canvas.clipRect(calendarRect);
if (mIsRTandLB) {
leftx = (int) (mBezierControl2.y);
rightx = (int) (mBezierControl2.y + 25);
mCurrentPageShadow = mFrontShadowDrawableHTB;
} else {
leftx = (int) (mBezierControl2.y - 25);
rightx = (int) (mBezierControl2.y + 1);
mCurrentPageShadow = mFrontShadowDrawableHBT;
}
rotateDegrees = (float) Math.toDegrees(Math.atan2(mBezierControl2.y - mTouch.y, mBezierControl2.x - mTouch.x));
canvas.rotate(rotateDegrees, mBezierControl2.x, mBezierControl2.y);
float temp;
if (mBezierControl2.y < 0) {
temp = mBezierControl2.y - mHeight;
} else {
temp = mBezierControl2.y;
}
int hmg = (int) Math.hypot(mBezierControl2.x, temp);
if (hmg > mMaxLength) {
mCurrentPageShadow.setBounds((int) (mBezierControl2.x - 25) - hmg, leftx, (int) (mBezierControl2.x + mMaxLength) - hmg, rightx);
} else {
mCurrentPageShadow.setBounds((int) (mBezierControl2.x - mMaxLength), leftx, (int) (mBezierControl2.x), rightx);
}
// Log.i("TAG", "mBezierControl2.x " + mBezierControl2.x
// + " mBezierControl2.y " + mBezierControl2.y);
mCurrentPageShadow.draw(canvas);
canvas.restore();
}
use of android.graphics.drawable.GradientDrawable in project MyDiary by erttyy8821.
the class PageEffectView method createDrawable.
/**
* Author : hmg25 Version: 1.0 Description : 创建阴影的GradientDrawable
*/
private void createDrawable() {
int[] color = { 0x333333, 0xb0333333 };
mFolderShadowDrawableRL = new GradientDrawable(GradientDrawable.Orientation.RIGHT_LEFT, color);
mFolderShadowDrawableRL.setGradientType(GradientDrawable.LINEAR_GRADIENT);
mFolderShadowDrawableLR = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, color);
mFolderShadowDrawableLR.setGradientType(GradientDrawable.LINEAR_GRADIENT);
mBackShadowColors = new int[] { 0xff111111, 0x111111 };
mBackShadowDrawableRL = new GradientDrawable(GradientDrawable.Orientation.RIGHT_LEFT, mBackShadowColors);
mBackShadowDrawableRL.setGradientType(GradientDrawable.LINEAR_GRADIENT);
mBackShadowDrawableLR = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, mBackShadowColors);
mBackShadowDrawableLR.setGradientType(GradientDrawable.LINEAR_GRADIENT);
mFrontShadowColors = new int[] { 0x80111111, 0x111111 };
mFrontShadowDrawableVLR = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, mFrontShadowColors);
mFrontShadowDrawableVLR.setGradientType(GradientDrawable.LINEAR_GRADIENT);
mFrontShadowDrawableVRL = new GradientDrawable(GradientDrawable.Orientation.RIGHT_LEFT, mFrontShadowColors);
mFrontShadowDrawableVRL.setGradientType(GradientDrawable.LINEAR_GRADIENT);
mFrontShadowDrawableHTB = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, mFrontShadowColors);
mFrontShadowDrawableHTB.setGradientType(GradientDrawable.LINEAR_GRADIENT);
mFrontShadowDrawableHBT = new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, mFrontShadowColors);
mFrontShadowDrawableHBT.setGradientType(GradientDrawable.LINEAR_GRADIENT);
}
use of android.graphics.drawable.GradientDrawable in project android-menudrawer by SimonVT.
the class MenuDrawer method setDropShadowColor.
/**
* Sets the color of the drop shadow.
*
* @param color The color of the drop shadow.
*/
public void setDropShadowColor(int color) {
GradientDrawable.Orientation orientation = getDropShadowOrientation();
final int endColor = color & 0x00FFFFFF;
mDropShadowDrawable = new GradientDrawable(orientation, new int[] { color, endColor });
invalidate();
}
Aggregations