下面列出了android.content.res.TypedArray#getColor() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public ViewfinderView(Context context, AttributeSet attrs) {
super(context, attrs);
// Initialize these once for performance rather than calling them every time in onDraw().
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
/*Resources resources = getResources();
maskColor = resources.getColor(R.color.viewfinder_mask);
resultColor = resources.getColor(R.color.result_view);
laserColor = resources.getColor(R.color.viewfinder_laser);
resultPointColor = resources.getColor(R.color.possible_result_points); // */
TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.ViewfinderView);
laserColor = array.getColor(R.styleable.ViewfinderView_laser_color, 0x00FF00);
cornerColor = array.getColor(R.styleable.ViewfinderView_corner_color, 0x00FF00);
frameColor = array.getColor(R.styleable.ViewfinderView_frame_color, 0xFFFFFF);
resultPointColor = array.getColor(R.styleable.ViewfinderView_result_point_color, 0xC0FFFF00);
maskColor = array.getColor(R.styleable.ViewfinderView_mask_color, 0x60000000);
resultColor = array.getColor(R.styleable.ViewfinderView_result_color, 0xB0000000);
labelTextColor = array.getColor(R.styleable.ViewfinderView_label_text_color, 0x90FFFFFF);
labelText = array.getString(R.styleable.ViewfinderView_label_text);
labelTextSize = array.getFloat(R.styleable.ViewfinderView_label_text_size, 36f);
possibleResultPoints = new ArrayList<>(5);
lastPossibleResultPoints = null;
}
private XanderPanel(Context context, int theme) {
super(context, theme);
TypedArray typedArray = context.obtainStyledAttributes(new int[]{
STATUS_BAR_COLOR,
NAVIGATION_BAR_COLOR
});
statusBarColor = typedArray.getColor(0,0x30000000);
navigationBarColor = typedArray.getColor(1,0x30000000);
typedArray.recycle();
if (null == tintManager) {
// tintManager = new SystemBarTintManager(context,getWindow());
// tintManager.setStatusBarTintEnabled(true);
// tintManager.setStatusBarTintColor(0x0000ff00);
// tintManager.setNavigationBarTintEnabled(true);
// tintManager.setNavigationBarTintColor(0x00ff0000);
// tintManager.setTintAlpha(0.f);
}
// 设置背景透明度
setDimAmount(DEFAULT_DIM_AMOUNT);
panelController = new PanelController(getContext(), this);
}
void init(Context context, AttributeSet attributeSet) {
TypedArray attr = context.obtainStyledAttributes(attributeSet, R.styleable.FloatingActionButton, 0, 0);
mColorNormal = attr.getColor(R.styleable.FloatingActionButton_fab_colorNormal, getColor(android.R.color.holo_blue_dark));
mColorPressed = attr.getColor(R.styleable.FloatingActionButton_fab_colorPressed, getColor(android.R.color.holo_blue_light));
mColorDisabled = attr.getColor(R.styleable.FloatingActionButton_fab_colorDisabled, getColor(android.R.color.darker_gray));
mSize = attr.getInt(R.styleable.FloatingActionButton_fab_size, SIZE_NORMAL);
mIcon = attr.getResourceId(R.styleable.FloatingActionButton_fab_icon, 0);
mTitle = attr.getString(R.styleable.FloatingActionButton_fab_title);
mStrokeVisible = attr.getBoolean(R.styleable.FloatingActionButton_fab_stroke_visible, true);
attr.recycle();
updateCircleSize();
mShadowRadius = getDimension(R.dimen.fab_shadow_radius);
mShadowOffset = getDimension(R.dimen.fab_shadow_offset);
updateDrawableSize();
updateBackground();
}
/**
* 动态获取当前主题中的自定义颜色属性值
*
* @param attr
* e.g R.attr.colorAccent
* @param defaultColor
* 默认颜色值
*/
public static int getAttrColorValue(int attr, int defaultColor, Context context) {
int[] attrsArray = {attr};
TypedArray typedArray = context.obtainStyledAttributes(attrsArray);
int value = typedArray.getColor(0, defaultColor);
typedArray.recycle();
return value;
}
public LikerTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.LikerTextView);
clickBgColor = typedArray.getColor(R.styleable.LikerTextView_liker_click_bg_color, getResources().getColor(R.color.liker_click_default_bg_color));
defaultBgColor = typedArray.getColor(R.styleable.LikerTextView_liker_default_bg_color, getResources().getColor(R.color.liker_default_bg_color));
typedArray.recycle();
}
private void initAttrs(Context context, AttributeSet attrs) {
TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.Curve, 0, 0);
try {
mUnitWidth = a.getDimensionPixelSize(R.styleable.Curve_unitWidth, 120);
mFillColor = a.getColor(R.styleable.Curve_backgroundColor, Color.TRANSPARENT);
mContentColor = a.getColor(R.styleable.Curve_contentColor, Color.BLACK);
mStrokeWidth = a.getDimensionPixelSize(R.styleable.Curve_strokeWidth, 10);
mContentPaddingTop = a.getDimensionPixelSize(R.styleable.Curve_contentPaddingTop, 0);
mContentPaddingBottom = a.getDimensionPixelSize(R.styleable.Curve_contentPaddingBottom, 0);
mDotTextSize = a.getDimensionPixelSize(R.styleable.Curve_dotTextSize, 60);
mDotTextColor = a.getColor(R.styleable.Curve_dotTextColor, Color.BLACK);
mAxisTextSize = a.getDimensionPixelSize(R.styleable.Curve_axisTextSize, 40);
mAxisTextColor = a.getColor(R.styleable.Curve_axisTextColor, Color.BLACK);
mCorner = a.getDimensionPixelSize(R.styleable.Curve_corner, 0);
mContentPaddingStart = a.getDimensionPixelSize(R.styleable.Curve_contentPaddingStart, 0);
mContentPaddingEnd = a.getDimensionPixelSize(R.styleable.Curve_contentPaddingEnd, 0);
mShowXLine = a.getBoolean(R.styleable.Curve_showXLine, false);
mShowXText = a.getBoolean(R.styleable.Curve_showXText, false);
mShowY = a.getBoolean(R.styleable.Curve_showY, false);
mGravity = a.getInteger(R.styleable.Curve_dotTextGravity, 0);
mShowAll = a.getBoolean(R.styleable.Curve_showAll, false);
mAxisTextToLineGapHeight = a.getDimensionPixelSize(R.styleable.Curve_axisTextToLineGapHeight, 0);
mAxisLineToCurveAreaGapHeight = a.getDimensionPixelSize(R.styleable.Curve_axisLineToCurveAreaGapHeight, 0);
} finally {
a.recycle();
}
}
private void init(Context context, AttributeSet attributeSet) {
try {
TypedArray typedArray = context.obtainStyledAttributes(attributeSet, R.styleable.RoundTextView);
mBgColor = typedArray.getColor(R.styleable.RoundTextView_backgroundColor,
getResources().getColor(R.color.aurora_event_msg_bg_color));
mCornerRadius = typedArray.getDimensionPixelSize(R.styleable.RoundTextView_cornerRadius,
getResources().getDimensionPixelSize(R.dimen.aurora_event_bg_corner_radius));
mPaint = new Paint(Paint.FILTER_BITMAP_FLAG);
} catch (Exception e) {
e.printStackTrace();
}
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public LeafView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TreeView);
mColor = typedArray.getColor(R.styleable.TreeView_android_color, getResources().getColor(R.color
.mountain_1));
typedArray.recycle();
init();
}
public RandomShowTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
//load styled attributes.
final TypedArray attributes = context.getTheme().obtainStyledAttributes(attrs, R.styleable.RandomShowTextView,
defStyleAttr, 0);
text = attributes.getString(R.styleable.RandomShowTextView_text);
duration = attributes.getInt(R.styleable.RandomShowTextView_duration, default_duration_time);
color = attributes.getColor(R.styleable.RandomShowTextView_textColor, default_text_color);
init();
fireWork();
}
private void initThis (Context context, AttributeSet attrs) {
mPaint = new Paint();
mPaint.setStyle(Paint.Style.FILL);
if (attrs != null) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProgressBar);
try {
final int color = a.getColor(R.styleable.ProgressBar_progressColor, Color.BLACK);
mPaint.setColor(color);
Log.v(TAG, "color=" + Integer.toHexString(color));
} finally {
a.recycle();
}
}
}
public CircleImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircleImageView, defStyle, 0);
mBorderWidth = a.getDimensionPixelSize(R.styleable.CircleImageView_civ_border_width, DEFAULT_BORDER_WIDTH);
mBorderColor = a.getColor(R.styleable.CircleImageView_civ_border_color, DEFAULT_BORDER_COLOR);
mBorderOverlay = a.getBoolean(R.styleable.CircleImageView_civ_border_overlay, DEFAULT_BORDER_OVERLAY);
mFillColor = a.getColor(R.styleable.CircleImageView_civ_fill_color, DEFAULT_FILL_COLOR);
a.recycle();
init();
}
private void setProgramColor(String color) {
int programTheme = ColorUtils.getThemeFromColor(color);
int programColor = ColorUtils.getColorFrom(color, ColorUtils.getPrimaryColor(this, ColorUtils.ColorType.PRIMARY));
if (programTheme != -1) {
presenter.saveProgramTheme(programTheme);
binding.toolbar.setBackgroundColor(programColor);
binding.tabLayout.setBackgroundColor(programColor);
if (OrientationUtilsKt.isLandscape())
if (binding.dotsIndicator.getVisibility() == View.VISIBLE) {
binding.dotsIndicator.setDotIndicatorColor(programColor);
binding.dotsIndicator.setStrokeDotsIndicatorColor(programColor);
}
} else {
presenter.removeProgramTheme();
int colorPrimary;
switch (presenter.getProgramTheme(R.style.AppTheme)) {
case R.style.RedTheme:
colorPrimary = R.color.colorPrimaryRed;
break;
case R.style.OrangeTheme:
colorPrimary = R.color.colorPrimaryOrange;
break;
case R.style.GreenTheme:
colorPrimary = R.color.colorPrimaryGreen;
break;
case R.style.AppTheme:
default:
colorPrimary = R.color.colorPrimary;
break;
}
binding.toolbar.setBackgroundColor(ContextCompat.getColor(this, colorPrimary));
binding.tabLayout.setBackgroundColor(ContextCompat.getColor(this, colorPrimary));
if (OrientationUtilsKt.isLandscape())
if (binding.dotsIndicator.getVisibility() == View.VISIBLE) {
binding.dotsIndicator.setDotIndicatorColor(ContextCompat.getColor(this, colorPrimary));
binding.dotsIndicator.setStrokeDotsIndicatorColor(ContextCompat.getColor(this, colorPrimary));
}
}
binding.executePendingBindings();
setTheme(presenter.getProgramTheme(R.style.AppTheme));
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
TypedValue typedValue = new TypedValue();
TypedArray a = obtainStyledAttributes(typedValue.data, new int[]{R.attr.colorPrimaryDark});
int colorToReturn = a.getColor(0, 0);
a.recycle();
window.setStatusBarColor(colorToReturn);
}
}
void initialize() {
Context context = getContext();
final Resources res = getResources();
final TypedArray a = context.obtainStyledAttributes(R.styleable.ButtonLayout);
if (SUtils.isApi_17_OrHigher()) {
setLayoutDirection(LAYOUT_DIRECTION_LOCALE);
}
setOrientation(HORIZONTAL);
setGravity(Gravity.BOTTOM);
setPadding(res.getDimensionPixelSize(R.dimen.sp_button_bar_padding_start),
res.getDimensionPixelSize(R.dimen.sp_button_bar_padding_top),
res.getDimensionPixelSize(R.dimen.sp_button_bar_padding_end),
res.getDimensionPixelSize(R.dimen.sp_button_bar_padding_bottom));
final LayoutInflater inflater = (LayoutInflater) context.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.sublime_button_panel_layout, this, true);
mSwitcherButton = (Button) findViewById(R.id.buttonSwitcher);
Button bPositive = (Button) findViewById(R.id.buttonPositive);
Button bNegative = (Button) findViewById(R.id.buttonNegative);
ImageView ivPositive = (ImageView) findViewById(R.id.imageViewPositive);
ImageView ivNegative = (ImageView) findViewById(R.id.imageViewNegative);
try {
// obtain float value held by android.R.attr.disabledAlpha
TypedValue typedValueDisabledAlpha = new TypedValue();
getContext().getTheme().resolveAttribute(android.R.attr.disabledAlpha,
typedValueDisabledAlpha, true);
// defaults to 0.5 ~ 122/255
mDisabledAlpha = typedValueDisabledAlpha.type == TypedValue.TYPE_FLOAT ?
(int) (typedValueDisabledAlpha.getFloat() * 255)
: 122;
// buttons or icons?
int presentation = a.getInt(R.styleable.ButtonLayout_spPresentation, 0);
int bgColor = a.getColor(R.styleable.ButtonLayout_spButtonBgColor,
SUtils.COLOR_BUTTON_NORMAL);
int pressedBgColor = a.getColor(R.styleable.ButtonLayout_spButtonPressedBgColor,
SUtils.COLOR_CONTROL_HIGHLIGHT);
mButtonBarBgColor = a.getColor(R.styleable.ButtonLayout_spButtonBarBgColor,
Color.TRANSPARENT);
SUtils.setViewBackground(mSwitcherButton,
SUtils.createButtonBg(context, bgColor,
pressedBgColor));
setBackgroundColor(mButtonBarBgColor);
if (presentation == 0 /* mode: Button */) {
bPositive.setVisibility(View.VISIBLE);
bNegative.setVisibility(View.VISIBLE);
bPositive.setText(res.getString(R.string.ok));
bNegative.setText(res.getString(R.string.cancel));
SUtils.setViewBackground(bPositive,
SUtils.createButtonBg(context, bgColor,
pressedBgColor));
SUtils.setViewBackground(bNegative,
SUtils.createButtonBg(context, bgColor,
pressedBgColor));
mPositiveButton = bPositive;
mNegativeButton = bNegative;
} else /* mode: ImageView */ {
ivPositive.setVisibility(View.VISIBLE);
ivNegative.setVisibility(View.VISIBLE);
mIconOverlayColor = a.getColor(R.styleable.ButtonLayout_spIconColor,
SUtils.COLOR_ACCENT);
ivPositive.setColorFilter(mIconOverlayColor, PorterDuff.Mode.MULTIPLY);
ivNegative.setColorFilter(mIconOverlayColor, PorterDuff.Mode.MULTIPLY);
SUtils.setViewBackground(ivPositive,
SUtils.createImageViewBg(bgColor,
pressedBgColor));
SUtils.setViewBackground(ivNegative,
SUtils.createImageViewBg(bgColor,
pressedBgColor));
mPositiveButton = ivPositive;
mNegativeButton = ivNegative;
}
} finally {
a.recycle();
}
// set OnClickListeners
mPositiveButton.setOnClickListener(this);
mNegativeButton.setOnClickListener(this);
mSwitcherButton.setOnClickListener(this);
}
private void initByAttributes(Context context, AttributeSet attrs) {
TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.MaskedEditText, 0, 0);
if (TextUtils.isEmpty(mask) && TextUtils.isEmpty(notMaskedSymbol)) {
notMaskedSymbol = a.getString(R.styleable.MaskedEditText_notMaskedSymbol);
mask = a.getString(R.styleable.MaskedEditText_mask);
Drawable drawableIcon = a.getDrawable(R.styleable.MaskedEditText_maskIcon);
if (drawableIcon != null) {
final Drawable wrappedDrawable = DrawableCompat.wrap(drawableIcon);
int drawableIconColor = a.getColor(R.styleable.MaskedEditText_maskIconColor, getCurrentHintTextColor());
DrawableCompat.setTint(wrappedDrawable, drawableIconColor);
maskIcon = wrappedDrawable;
}
}
if (!TextUtils.isEmpty(mask) && !TextUtils.isEmpty(notMaskedSymbol)) {
deleteChar = a.getString(R.styleable.MaskedEditText_deleteChar);
if (deleteChar == null) deleteChar = " ";
replacementChar = a.getString(R.styleable.MaskedEditText_replacementChar);
if (replacementChar == null) replacementChar = " ";
format = a.getString(R.styleable.MaskedEditText_format);
if (format == null) format = "";
initListValidCursorPositions(mask, notMaskedSymbol);
filteredMask = this.mask.replace(this.notMaskedSymbol, replacementChar);
this.setText(filteredMask, BufferType.NORMAL);
maskedInputFilter = new MaskedInputFilter();
this.setFilters(new InputFilter[]{maskedInputFilter});
} else {
System.err.println("Mask not correct initialised ");
}
int inputType = a.getInteger(R.styleable.MaskedEditText_android_inputType, -1);
this.setInputType(inputType);
}
private void initAttrs(Context context, AttributeSet attrs) {
if (attrs != null) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.VectorCompatTextView);
Drawable ds = null;
Drawable dt = null;
Drawable de = null;
Drawable db = null;
Drawable dl = null;
Drawable dr = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
ds = a.getDrawable(R.styleable.VectorCompatTextView_drawableStartCompat);
dt = a.getDrawable(R.styleable.VectorCompatTextView_drawableTopCompat);
de = a.getDrawable(R.styleable.VectorCompatTextView_drawableEndCompat);
db = a.getDrawable(R.styleable.VectorCompatTextView_drawableBottomCompat);
dl = a.getDrawable(R.styleable.VectorCompatTextView_drawableLeftCompat);
dr = a.getDrawable(R.styleable.VectorCompatTextView_drawableRightCompat);
} else {
int dsId = a.getResourceId(R.styleable.VectorCompatTextView_drawableStartCompat, -1);
int dtId = a.getResourceId(R.styleable.VectorCompatTextView_drawableTopCompat, -1);
int deId = a.getResourceId(R.styleable.VectorCompatTextView_drawableEndCompat, -1);
int dbId = a.getResourceId(R.styleable.VectorCompatTextView_drawableBottomCompat, -1);
int dlId = a.getResourceId(R.styleable.VectorCompatTextView_drawableLeftCompat, -1);
int drId = a.getResourceId(R.styleable.VectorCompatTextView_drawableRightCompat, -1);
if (dsId != -1) ds = AppCompatResources.getDrawable(context, dsId);
if (dtId != -1) dt = AppCompatResources.getDrawable(context, dtId);
if (deId != -1) de = AppCompatResources.getDrawable(context, deId);
if (dbId != -1) db = AppCompatResources.getDrawable(context, dbId);
if (dlId != -1) dl = AppCompatResources.getDrawable(context, dlId);
if (drId != -1) dr = AppCompatResources.getDrawable(context, drId);
}
isTintDrawableInTextColor = a.getBoolean(R.styleable.VectorCompatTextView_tintDrawableInTextColor, false);
mDrawableCompatColor = a.getColor(R.styleable.VectorCompatTextView_drawableCompatColor, 0);
isDrawableAdjustTextWidth = a.getBoolean(R.styleable.VectorCompatTextView_drawableAdjustTextWidth, false);
isDrawableAdjustTextHeight = a.getBoolean(R.styleable.VectorCompatTextView_drawableAdjustTextHeight, false);
isDrawableAdjustViewWidth = a.getBoolean(R.styleable.VectorCompatTextView_drawableAdjustViewWidth, false);
isDrawableAdjustViewHeight = a.getBoolean(R.styleable.VectorCompatTextView_drawableAdjustViewHeight, false);
mDrawableWidth = a.getDimensionPixelSize(R.styleable.VectorCompatTextView_drawableWidth, 0);
mDrawableHeight = a.getDimensionPixelSize(R.styleable.VectorCompatTextView_drawableHeight, 0);
hideDrawable = a.getBoolean(R.styleable.VectorCompatTextView_hideDrawable, false);
a.recycle();
if (mDrawableWidth < 0)
mDrawableWidth = 0;
if (mDrawableHeight < 0)
mDrawableHeight = 0;
if (isDrawableAdjustTextWidth)
isDrawableAdjustViewWidth = false;
if (isDrawableAdjustTextHeight)
isDrawableAdjustViewHeight = false;
mDrawableStart = ds;
mDrawableTop = dt;
mDrawableEnd = de;
mDrawableBottom = db;
if (ds == null)
mDrawableStart = dl;
if (de == null)
mDrawableEnd = dr;
boolean initHidden = hideDrawable;
if (initHidden) {
hideDrawable = false;
}
behaveDrawables();
if (initHidden) {
hideDrawable = true;
behaveDrawables();
}
}
}
private void initialize(Context context, AttributeSet attrs) {
//Progress background drawable
mDrawableProgressBackground = new GradientDrawable();
//Progress drawable
mDrawableProgress = new GradientDrawable();
//Normal drawable
mDrawableButton = new GradientDrawable();
//Get default normal color
int defaultButtonColor = getResources().getColor(R.color.colorGray, null);
//Get default progress color
int defaultProgressColor = getResources().getColor(R.color.colorGreen, null);
//Get default progress background color
int defaultBackColor = getResources().getColor(R.color.colorGray, null);
TypedArray attr = context.obtainStyledAttributes(attrs, R.styleable.ProgressButton);
try {
mProgressMargin = attr.getDimension(R.styleable.ProgressButton_progressMargin, mProgressMargin);
mCornerRadius = attr.getDimension(R.styleable.ProgressButton_cornerRadius, mCornerRadius);
//Get custom normal color
int buttonColor = attr.getColor(R.styleable.ProgressButton_buttonColor, defaultButtonColor);
//Set normal color
mDrawableButton.setColor(buttonColor);
//Get custom progress background color
int progressBackColor = attr.getColor(R.styleable.ProgressButton_progressBackColor, defaultBackColor);
//Set progress background drawable color
mDrawableProgressBackground.setColor(progressBackColor);
//Get custom progress color
int progressColor = attr.getColor(R.styleable.ProgressButton_progressColor, defaultProgressColor);
//Set progress drawable color
mDrawableProgress.setColor(progressColor);
//Get default progress
mProgress = attr.getInteger(R.styleable.ProgressButton_progress, mProgress);
//Get minimum progress
mMinProgress = attr.getInteger(R.styleable.ProgressButton_minProgress, mMinProgress);
//Get maximize progress
mMaxProgress = attr.getInteger(R.styleable.ProgressButton_maxProgress, mMaxProgress);
} finally {
attr.recycle();
}
//Set corner radius
mDrawableButton.setCornerRadius(mCornerRadius);
mDrawableProgressBackground.setCornerRadius(mCornerRadius);
mDrawableProgress.setCornerRadius(mCornerRadius - mProgressMargin);
setBackgroundDrawable(mDrawableButton);
mFinish = false;
}
/**
* @param attrs are the attributes containing the values given by user
* @param context context of the activity to use this view class
*/
private void init(AttributeSet attrs, Context context) {
paintInnerCircle = new Paint();
paintArc = new Paint();
paintLines = new Paint();
paintText = new Paint();
paintArc.setStyle(Paint.Style.STROKE);
paintArc.setPathEffect(new DashPathEffect(new float[]{5, 10}, 0));
paintLines.setAntiAlias(true);
paintText.setTextAlign(Paint.Align.RIGHT);
if (attrs != null) {
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.DialView);
lineInterval = typedArray.getInt(R.styleable.DialView_lineInterval, 0);
maxValue = typedArray.getInt(R.styleable.DialView_maxValue, 0);
minValue = typedArray.getInt(R.styleable.DialView_minValue, 0);
leastCount = typedArray.getInt(R.styleable.DialView_leastCount, 0);
centerPadding = typedArray.getInt(R.styleable.DialView_centerPadding, 0);
textSize = typedArray.getInt(R.styleable.DialView_textSize, 0);
dialDirection = typedArray.getInt(R.styleable.DialView_dialDirection, 0);
tickGapAngle = ((double) typedArray.getInt(R.styleable.DialView_tickGapAngle, 0)
/ (double) 180) * PI;
startColor = typedArray.getColor(R.styleable.DialView_startColor, 0);
endColor = typedArray.getColor(R.styleable.DialView_endColor, 0);
paintLineColor = typedArray.getColor(R.styleable.DialView_paintLineColor, 0);
paintTextColor = typedArray.getColor(R.styleable.DialView_paintTextColor, 0);
paintArcColor = typedArray.getColor(R.styleable.DialView_paintArcColor, 0);
typedArray.recycle();
}
if (minValue >= maxValue) {
maxValue = minValue;
minValue = 0;
}
paintInnerCircle.setStyle(Paint.Style.FILL);
paintInnerCircle.setFilterBitmap(true);
paintInnerCircle.setShader(new LinearGradient(0, 0, 0, getHeight(), endColor, startColor, Shader.TileMode.CLAMP));
paintLines.setColor(paintLineColor);
paintText.setColor(paintTextColor);
paintArc.setColor(paintArcColor);
switch (dialDirection) {
//for left
case 1:
currentTheta = 0;
initTheta = 0;
angleToCompare = 0;
break;
//for top
case 2:
currentTheta = PI / 2;
initTheta = PI / 2;
angleToCompare = 90;
break;
//for right
case 3:
currentTheta = PI;
initTheta = PI;
angleToCompare = 180;
break;
//for bottom
case 4:
currentTheta = PI * 3 / 2;
initTheta = PI * 3 / 2;
angleToCompare = 270;
break;
default:
// // TODO: 4/5/17 nothing
break;
}
paintText.setTextSize(textSize);
}
@SuppressWarnings("ConstantConditions")
private void layout(Context context, AttributeSet attrs, Size size) {
inflate(context, R.layout.fast_scroller, this);
setClipChildren(false);
setOrientation(HORIZONTAL);
bubbleView = findViewById(R.id.fastscroll_bubble);
handleView = findViewById(R.id.fastscroll_handle);
trackView = findViewById(R.id.fastscroll_track);
scrollbar = findViewById(R.id.fastscroll_scrollbar);
bubbleSize = size;
@ColorInt int bubbleColor = Color.GRAY;
@ColorInt int handleColor = Color.DKGRAY;
@ColorInt int trackColor = Color.LTGRAY;
@ColorInt int textColor = Color.WHITE;
boolean hideScrollbar = true;
boolean showBubble = true;
boolean showTrack = false;
float textSize = getResources().getDimension(size.textSizeId);
if (attrs != null) {
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.FastScroller, 0, 0);
if (typedArray != null) {
try {
bubbleColor = typedArray.getColor(R.styleable.FastScroller_bubbleColor, bubbleColor);
handleColor = typedArray.getColor(R.styleable.FastScroller_handleColor, handleColor);
trackColor = typedArray.getColor(R.styleable.FastScroller_trackColor, trackColor);
textColor = typedArray.getColor(R.styleable.FastScroller_bubbleTextColor, textColor);
hideScrollbar = typedArray.getBoolean(R.styleable.FastScroller_hideScrollbar, hideScrollbar);
showBubble = typedArray.getBoolean(R.styleable.FastScroller_showBubble, showBubble);
showTrack = typedArray.getBoolean(R.styleable.FastScroller_showTrack, showTrack);
int sizeOrdinal = typedArray.getInt(R.styleable.FastScroller_bubbleSize, size.ordinal());
bubbleSize = Size.fromOrdinal(sizeOrdinal);
textSize = typedArray.getDimension(R.styleable.FastScroller_bubbleTextSize,
getResources().getDimension(bubbleSize.textSizeId));
} finally {
typedArray.recycle();
}
}
}
setTrackColor(trackColor);
setHandleColor(handleColor);
setBubbleColor(bubbleColor);
setBubbleTextColor(textColor);
setHideScrollbar(hideScrollbar);
setBubbleVisible(showBubble);
setTrackVisible(showTrack);
bubbleView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
}
/**
* Does all the initial setup of the button such as retrieving all the attributes that were
* set in xml and inflating the like button's view and initial state.
*
* @param context
* @param attrs
* @param defStyle
*/
private void init(Context context, AttributeSet attrs, int defStyle) {
LayoutInflater.from(getContext()).inflate(R.layout.likeview, this, true);
icon = (ImageView) findViewById(R.id.icon);
dotsView = (DotsView) findViewById(R.id.dots);
circleView = (CircleView) findViewById(R.id.circle);
final TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.LikeButton, defStyle, 0);
iconSize = array.getDimensionPixelSize(R.styleable.LikeButton_icon_size, -1);
if (iconSize == -1)
iconSize = 40;
String iconType = array.getString(R.styleable.LikeButton_icon_type);
likeDrawable = getDrawableFromResource(array, R.styleable.LikeButton_like_drawable);
if (likeDrawable != null)
setLikeDrawable(likeDrawable);
unLikeDrawable = getDrawableFromResource(array, R.styleable.LikeButton_unlike_drawable);
if (unLikeDrawable != null)
setUnlikeDrawable(unLikeDrawable);
if (iconType != null)
if (!iconType.isEmpty())
currentIcon = parseIconType(iconType);
circleStartColor = array.getColor(R.styleable.LikeButton_circle_start_color, 0);
if (circleStartColor != 0)
circleView.setStartColor(circleStartColor);
circleEndColor = array.getColor(R.styleable.LikeButton_circle_end_color, 0);
if (circleEndColor != 0)
circleView.setEndColor(circleEndColor);
dotPrimaryColor = array.getColor(R.styleable.LikeButton_dots_primary_color, 0);
dotSecondaryColor = array.getColor(R.styleable.LikeButton_dots_secondary_color, 0);
if (dotPrimaryColor != 0 && dotSecondaryColor != 0) {
dotsView.setColors(dotPrimaryColor, dotSecondaryColor);
}
if (likeDrawable == null && unLikeDrawable == null) {
if (currentIcon != null) {
setIcon();
} else {
setIcon(IconType.Heart);
}
}
setEnabled(array.getBoolean(R.styleable.LikeButton_is_enabled, true));
Boolean status = array.getBoolean(R.styleable.LikeButton_liked, false);
setAnimationScaleFactor(array.getFloat(R.styleable.LikeButton_anim_scale_factor, 3));
setLiked(status);
setOnClickListener(this);
array.recycle();
}
private void init(Context context, AttributeSet attrs) {
TypedArray attr = context.obtainStyledAttributes(attrs, R.styleable.FloatingActionMenu, 0, 0);
mButtonSpacing = attr.getDimensionPixelSize(R.styleable.FloatingActionMenu_menu_buttonSpacing, mButtonSpacing);
mLabelsMargin = attr.getDimensionPixelSize(R.styleable.FloatingActionMenu_menu_labels_margin, mLabelsMargin);
mLabelsPosition = attr.getInt(R.styleable.FloatingActionMenu_menu_labels_position, LABELS_POSITION_LEFT);
mLabelsShowAnimation = attr.getResourceId(R.styleable.FloatingActionMenu_menu_labels_showAnimation,
mLabelsPosition == LABELS_POSITION_LEFT ? R.anim.fab_slide_in_from_right : R.anim.fab_slide_in_from_left);
mLabelsHideAnimation = attr.getResourceId(R.styleable.FloatingActionMenu_menu_labels_hideAnimation,
mLabelsPosition == LABELS_POSITION_LEFT ? R.anim.fab_slide_out_to_right : R.anim.fab_slide_out_to_left);
mLabelsPaddingTop = attr.getDimensionPixelSize(R.styleable.FloatingActionMenu_menu_labels_paddingTop, mLabelsPaddingTop);
mLabelsPaddingRight = attr.getDimensionPixelSize(R.styleable.FloatingActionMenu_menu_labels_paddingRight, mLabelsPaddingRight);
mLabelsPaddingBottom = attr.getDimensionPixelSize(R.styleable.FloatingActionMenu_menu_labels_paddingBottom, mLabelsPaddingBottom);
mLabelsPaddingLeft = attr.getDimensionPixelSize(R.styleable.FloatingActionMenu_menu_labels_paddingLeft, mLabelsPaddingLeft);
mLabelsTextColor = attr.getColorStateList(R.styleable.FloatingActionMenu_menu_labels_textColor);
// set default value if null same as for textview
if (mLabelsTextColor == null) {
mLabelsTextColor = ColorStateList.valueOf(Color.WHITE);
}
mLabelsTextSize = attr.getDimension(R.styleable.FloatingActionMenu_menu_labels_textSize, getResources().getDimension(R.dimen.labels_text_size));
mLabelsCornerRadius = attr.getDimensionPixelSize(R.styleable.FloatingActionMenu_menu_labels_cornerRadius, mLabelsCornerRadius);
mLabelsShowShadow = attr.getBoolean(R.styleable.FloatingActionMenu_menu_labels_showShadow, true);
mLabelsColorNormal = attr.getColor(R.styleable.FloatingActionMenu_menu_labels_colorNormal, 0xFF333333);
mLabelsColorPressed = attr.getColor(R.styleable.FloatingActionMenu_menu_labels_colorPressed, 0xFF444444);
mLabelsColorRipple = attr.getColor(R.styleable.FloatingActionMenu_menu_labels_colorRipple, 0x66FFFFFF);
mMenuShowShadow = attr.getBoolean(R.styleable.FloatingActionMenu_menu_showShadow, true);
mMenuShadowColor = attr.getColor(R.styleable.FloatingActionMenu_menu_shadowColor, 0x66000000);
mMenuShadowRadius = attr.getDimension(R.styleable.FloatingActionMenu_menu_shadowRadius, mMenuShadowRadius);
mMenuShadowXOffset = attr.getDimension(R.styleable.FloatingActionMenu_menu_shadowXOffset, mMenuShadowXOffset);
mMenuShadowYOffset = attr.getDimension(R.styleable.FloatingActionMenu_menu_shadowYOffset, mMenuShadowYOffset);
mMenuColorNormal = attr.getColor(R.styleable.FloatingActionMenu_menu_colorNormal, 0xFFDA4336);
mMenuColorPressed = attr.getColor(R.styleable.FloatingActionMenu_menu_colorPressed, 0xFFE75043);
mMenuColorRipple = attr.getColor(R.styleable.FloatingActionMenu_menu_colorRipple, 0x99FFFFFF);
mAnimationDelayPerItem = attr.getInt(R.styleable.FloatingActionMenu_menu_animationDelayPerItem, 50);
mIcon = attr.getDrawable(R.styleable.FloatingActionMenu_menu_icon);
if (mIcon == null) {
mIcon = getResources().getDrawable(R.drawable.fab_add);
}
mLabelsSingleLine = attr.getBoolean(R.styleable.FloatingActionMenu_menu_labels_singleLine, false);
mLabelsEllipsize = attr.getInt(R.styleable.FloatingActionMenu_menu_labels_ellipsize, 0);
mLabelsMaxLines = attr.getInt(R.styleable.FloatingActionMenu_menu_labels_maxLines, -1);
mMenuFabSize = attr.getInt(R.styleable.FloatingActionMenu_menu_fab_size, FloatingActionButton.SIZE_NORMAL);
mLabelsStyle = attr.getResourceId(R.styleable.FloatingActionMenu_menu_labels_style, 0);
mOpenDirection = attr.getInt(R.styleable.FloatingActionMenu_menu_openDirection, OPEN_UP);
mBackgroundColor = attr.getColor(R.styleable.FloatingActionMenu_menu_backgroundColor, Color.TRANSPARENT);
if (attr.hasValue(R.styleable.FloatingActionMenu_menu_fab_label)) {
mUsingMenuLabel = true;
mMenuLabelText = attr.getString(R.styleable.FloatingActionMenu_menu_fab_label);
}
if (attr.hasValue(R.styleable.FloatingActionMenu_menu_labels_padding)) {
int padding = attr.getDimensionPixelSize(R.styleable.FloatingActionMenu_menu_labels_padding, 0);
initPadding(padding);
}
mOpenInterpolator = new OvershootInterpolator();
mCloseInterpolator = new AnticipateInterpolator();
mLabelsContext = new ContextThemeWrapper(getContext(), mLabelsStyle);
initBackgroundDimAnimation();
createMenuButton();
initMenuButtonAnimations(attr);
attr.recycle();
}