项目:RoundButton
文件:RoundButton.java
private void update() {
StateListDrawable background = new StateListDrawable();
background.addState(new int[]{android.R.attr.state_pressed},createDrawable(backgroundColorpressed,cornerColorpressed,cornerWidth,cornerRadius));
background.addState(new int[]{-android.R.attr.state_enabled},createDrawable(backgroundColordisabled,cornerColordisabled,cornerRadius));
background.addState(StateSet.WILD_CARD,createDrawable(backgroundColor,cornerColor,cornerRadius));
setBackground(background);
setTextColor(new ColorStateList(
new int[][]{
new int[]{android.R.attr.state_pressed},new int[]{-android.R.attr.state_enabled},new int[]{}
},new int[]{
textColorpressed,textColordisabled,textColor
}
));
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private Drawable createFillDrawable() {
StateListDrawable drawable = new StateListDrawable();
drawable.addState(new int[]{android.R.attr.state_pressed},createRectDrawable(mColorpressed));
drawable.addState(new int[]{},createRectDrawable(mColornormal));
if (Util.hasLollipop()) {
rippledrawable ripple = new rippledrawable(new ColorStateList(new int[][]{{}},new int[]{mColorRipple}),drawable,null);
setoutlineProvider(new ViewOutlineProvider() {
@Override
public void getoutline(View view,Outline outline) {
outline.setoval(0,view.getWidth(),view.getHeight());
}
});
setClipToOutline(true);
mBackgroundDrawable = ripple;
return ripple;
}
mBackgroundDrawable = drawable;
return drawable;
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public void setBackgroundColor(int colorpressed,int colornormal){
StateListDrawable sd = new StateListDrawable();
int[] state_pressed = new int[]{android.R.attr.state_pressed};
int[] state_normal = new int[]{android.R.attr.state_enabled};
GradientDrawable pressed = new GradientDrawable();
pressed.setColor(colorpressed);
pressed.setCornerRadius(10);
GradientDrawable enable = new GradientDrawable();
enable.setColor(colornormal);
enable.setCornerRadius(10);
sd.addState(state_pressed,pressed);
sd.addState(state_normal,enable);
bg.setBackground(sd);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
void onActionDown() {
if (mUsingStyle) {
mBackgroundDrawable = getBackground();
}
if (mBackgroundDrawable instanceof StateListDrawable) {
StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
drawable.setState(new int[]{android.R.attr.state_pressed});
} else if (Util.hasLollipop() && mBackgroundDrawable instanceof rippledrawable) {
rippledrawable ripple = (rippledrawable) mBackgroundDrawable;
ripple.setState(new int[]{android.R.attr.state_enabled,android.R.attr.state_pressed});
ripple.setHotspot(getMeasuredWidth() / 2,getMeasuredHeight() / 2);
ripple.setVisible(true,true);
}
// setpressed(true);
}
/**
* create state list drawable
*
* @param context
* @param idnormal
* @param idpressed
* @param idFocused
* @param idUnable
* @return
*/
public static StateListDrawable createStateListDrawable(Context context,int idnormal,int idpressed,int idFocused,int idUnable) {
StateListDrawable bg = new StateListDrawable();
Drawable normal = idnormal == -1 ? null : context.getResources().getDrawable(idnormal);
Drawable pressed = idpressed == -1 ? null : context.getResources().getDrawable(idpressed);
Drawable focused = idFocused == -1 ? null : context.getResources().getDrawable(idFocused);
Drawable unable = idUnable == -1 ? null : context.getResources().getDrawable(idUnable);
// View.pressed_ENABLED_STATE_SET
bg.addState(new int[]{android.R.attr.state_pressed,android.R.attr.state_enabled},pressed);
// View.ENABLED_FOCUSED_STATE_SET
bg.addState(new int[]{android.R.attr.state_enabled,android.R.attr.state_focused},focused);
// View.ENABLED_STATE_SET
bg.addState(new int[]{android.R.attr.state_enabled},normal);
// View.FOCUSED_STATE_SET
bg.addState(new int[]{android.R.attr.state_focused},focused);
// View.WINDOW_FOCUSED_STATE_SET
bg.addState(new int[]{android.R.attr.state_window_focused},unable);
// View.EMPTY_STATE_SET
bg.addState(new int[]{},normal);
return bg;
}
项目:OpenEyesReading-android
文件:Util.java
public void setCircleButtonStateListDrawable(View circleButton,int radius,int color) {
WeakReference<Bitmap> imagenormal = new WeakReference<>(Bitmap.createBitmap(2 * radius,2 * radius,Bitmap.Config.ARGB_8888));
Canvas canvasnormal = new Canvas(imagenormal.get());
Paint paintnormal = new Paint();
paintnormal.setAntiAlias(true);
paintnormal.setColor(color);
canvasnormal.drawCircle(radius,radius,paintnormal);
StateListDrawable stateListDrawable = new StateListDrawable();
stateListDrawable.addState(StateSet.WILD_CARD,new BitmapDrawable(circleButton.getContext().getResources(),imagenormal.get()));
if (android.os.Build.VERSION.SDK_INT >= 16) {
circleButton.setBackground(stateListDrawable);
} else {
circleButton.setBackgroundDrawable(stateListDrawable);
}
}
项目:RLibrary
文件:ResUtil.java
/**
* Generate bg drawable drawable.
*
* @param radii the radii
* @param pressColor the press color
* @param defaultColor the default color
* @return the drawable
*/
public static Drawable generateRoundDrawable(Resources res,float radii,int pressColor,int defaultColor) {
radii = dpToPx(res,radii);
//外环的圆角矩形
float[] ouTradii = new float[]{radii,radii,radii};//四个角的 圆角幅度,8个可以设置的值,每个角都有2个边 2*4=8个
//按下状态
Shape roundRectShape = new RoundRectShape(ouTradii,null,null);//圆角背景
ShapeDrawable shopDrawablePress = new ShapeDrawable(roundRectShape);//圆角shape
shopDrawablePress.getPaint().setColor(pressColor);//设置颜色
//正常状态
Shape roundRectShapenormal = new RoundRectShape(ouTradii,null);
ShapeDrawable shopDrawablenormal = new ShapeDrawable(roundRectShapenormal);
shopDrawablenormal.getPaint().setColor(defaultColor);
StateListDrawable bgStateDrawable = new StateListDrawable();//状态shape
bgStateDrawable.addState(new int[]{android.R.attr.state_pressed},shopDrawablePress);//按下状态
bgStateDrawable.addState(new int[]{},shopDrawablenormal);//其他状态
return bgStateDrawable;
}
项目:RLibrary
文件:ResUtil.java
/**
* 正常 圆角边框;
* 按下 圆角色块
*/
public static Drawable generateBorderDrawable(float radii,float borderWidth,int defaultColor) {
//外环的圆角矩形
float[] ouTradii = new float[]{radii,每个角都有2个边 2*4=8个
RectF inset = new RectF(borderWidth,borderWidth,borderWidth);
//按下状态
Shape roundRectShape = new RoundRectShape(ouTradii,inset,ouTradii);
ShapeDrawable shopDrawablenormal = new ShapeDrawable(roundRectShapenormal);
shopDrawablenormal.getPaint().setColor(defaultColor);
StateListDrawable bgStateDrawable = new StateListDrawable();//状态shape
bgStateDrawable.addState(new int[]{android.R.attr.state_pressed},shopDrawablenormal);//其他状态
return bgStateDrawable;
}
public YearPickerView(Context context,DatePickerController controller) {
super(context);
this.mController = controller;
this.mController.registerOnDateChangedListener(this);
setLayoutParams(new LayoutParams(-1,-2));
Resources res = context.getResources();
this.mViewSize = res.getDimensionPixelOffset(R.dimen.mdtp_date_picker_view_animator_height);
this.mChildSize = res.getDimensionPixelOffset(R.dimen.mdtp_year_label_height);
setVerticalFadingEdgeEnabled(true);
setFadingEdgeLength(this.mChildSize / 3);
init(context);
setonItemClickListener(this);
setSelector(new StateListDrawable());
setDividerHeight(0);
onDateChanged();
}
项目:AppCommonFrame
文件:BitmapUtil.java
/**
* 通过代码配置一个selector XML对象 . <br>
* @author liulongzhenhai 2012-7-4 上午10:45:03 <br>
* @param normal 没有状态
* @param pressed 按下状态
* @param focused 获取焦点状态
* @param unable 无状态
* @return 返回selector 的对象布局
*/
public static StateListDrawable getNewSelector(final Drawable normal,final Drawable pressed,final Drawable focused,final Drawable unable) {
final StateListDrawable bg = new StateListDrawable();
// View.pressed_ENABLED_STATE_SET
bg.addState(new int[] { android.R.attr.state_pressed,android.R.attr.state_enabled },pressed);
// View.ENABLED_FOCUSED_STATE_SET
bg.addState(new int[] { android.R.attr.state_enabled,android.R.attr.state_focused },focused);
// View.ENABLED_STATE_SET
bg.addState(new int[] { android.R.attr.state_enabled },normal);
// View.FOCUSED_STATE_SET
bg.addState(new int[] { android.R.attr.state_focused },focused);
// View.WINDOW_FOCUSED_STATE_SET
bg.addState(new int[] { android.R.attr.state_window_focused },unable);
// View.EMPTY_STATE_SET
bg.addState(new int[] {},normal);
return bg;
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private Drawable createFillDrawable() {
StateListDrawable drawable = new StateListDrawable();
drawable.addState(new int[]{-android.R.attr.state_enabled},createCircleDrawable(mColordisabled));
drawable.addState(new int[]{android.R.attr.state_pressed},createCircleDrawable(mColorpressed));
drawable.addState(new int[]{},createCircleDrawable(mColornormal));
if (Util.hasLollipop()) {
rippledrawable ripple = new rippledrawable(new ColorStateList(new int[][]{{}},view.getHeight());
}
});
setClipToOutline(true);
mBackgroundDrawable = ripple;
return ripple;
}
mBackgroundDrawable = drawable;
return drawable;
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private Drawable createFillDrawable() {
StateListDrawable drawable = new StateListDrawable();
drawable.addState(new int[]{android.R.attr.state_pressed},view.getHeight());
}
});
setClipToOutline(true);
mBackgroundDrawable = ripple;
return ripple;
}
mBackgroundDrawable = drawable;
return drawable;
}
private void initIdleStateDrawable() {
int colornormal = getnormalColor(mIdleColorState);
int colorpressed = getpressedColor(mIdleColorState);
int colorFocused = getFocusedColor(mIdleColorState);
int colordisabled = getdisabledColor(mIdleColorState);
if (background == null) {
background = createDrawable(colornormal);
}
strokeGradientDrawable drawabledisabled = createDrawable(colordisabled);
strokeGradientDrawable drawableFocused = createDrawable(colorFocused);
strokeGradientDrawable drawablepressed = createDrawable(colorpressed);
mIdleStateDrawable = new StateListDrawable();
mIdleStateDrawable.addState(new int[]{android.R.attr.state_pressed},drawablepressed.getGradientDrawable());
mIdleStateDrawable.addState(new int[]{android.R.attr.state_focused},drawableFocused.getGradientDrawable());
mIdleStateDrawable.addState(new int[]{-android.R.attr.state_enabled},drawabledisabled.getGradientDrawable());
mIdleStateDrawable.addState(StateSet.WILD_CARD,background.getGradientDrawable());
}
项目:MDWechat
文件:Label.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private Drawable createFillDrawable() {
StateListDrawable drawable = new StateListDrawable();
drawable.addState(new int[]{android.R.attr.state_pressed},view.getHeight());
}
});
setClipToOutline(true);
mBackgroundDrawable = ripple;
return ripple;
}
mBackgroundDrawable = drawable;
return drawable;
}
项目:MDWechat
文件:Label.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
void onActionDown() {
if (mUsingStyle) {
mBackgroundDrawable = getBackground();
}
if (mBackgroundDrawable instanceof StateListDrawable) {
StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
drawable.setState(new int[]{android.R.attr.state_pressed});
} else if (Util.hasLollipop() && mBackgroundDrawable instanceof rippledrawable) {
rippledrawable ripple = (rippledrawable) mBackgroundDrawable;
ripple.setState(new int[]{android.R.attr.state_enabled,true);
}
// setpressed(true);
}
项目:MDWechat
文件:Label.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
void onActionUp() {
if (mUsingStyle) {
mBackgroundDrawable = getBackground();
}
if (mBackgroundDrawable instanceof StateListDrawable) {
StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
drawable.setState(new int[]{});
} else if (Util.hasLollipop() && mBackgroundDrawable instanceof rippledrawable) {
rippledrawable ripple = (rippledrawable) mBackgroundDrawable;
ripple.setState(new int[]{});
ripple.setHotspot(getMeasuredWidth() / 2,true);
}
// setpressed(false);
}
项目:silly-android
文件:ColoringTest.java
/**
* Tests the {@link Coloring#createMultiStateDrawable(Drawable,Drawable,boolean)} method.
* <p>
* Unfortunately some Drawable properties are not shadowed by Robolectric yet,so we can test only the basic stuff here.
*/
@Test
public final void testCreateMultiStateDrawable() {
// noinspection deprecation - can't enforce Lollipop here
final BitmapDrawable normal = (BitmapDrawable) mActivityContext.getResources().getDrawable(android.R.drawable.btn_star_big_on);
assertNotNull("normal drawable is null",normal);
// noinspection deprecation - can't enforce Lollipop here
final BitmapDrawable clicked = (BitmapDrawable) mActivityContext.getResources().getDrawable(android.R.drawable.btn_star_big_off);
assertNotNull("Clicked drawable is null",clicked);
// noinspection deprecation - can't enforce Lollipop here
final BitmapDrawable checked = (BitmapDrawable) mActivityContext.getResources().getDrawable(android.R.drawable.star_off);
assertNotNull("Checked drawable is null",checked);
final StateListDrawable stateList = Coloring.createMultiStateDrawable(normal,clicked,checked,true);
assertNotNull("Contrast state drawable is null",stateList);
assertTrue("Contrast state drawable is not stateful",stateList.isstateful());
final Drawable.ConstantState constantState = stateList.getConstantState();
assertNotNull("Constant state is null",constantState);
}
项目:android-paypal-example
文件:BadgeDrawableBuilder.java
public StateListDrawable build(Context ctx) {
StateListDrawable stateListDrawable = new StateListDrawable();
GradientDrawable normal = (GradientDrawable) ContextCompat.getDrawable(ctx,R.drawable.action_item_badge);
GradientDrawable selected = (GradientDrawable) normal.getConstantState().newDrawable().mutate();
normal.setColor(mColor);
selected.setColor(mColorpressed);
if (mstroke > -1) {
normal.setstroke(mstroke,mstrokeColor);
selected.setstroke(mstroke,mstrokeColor);
}
if (mCorners > -1) {
normal.setCornerRadius(mCorners);
selected.setCornerRadius(mCorners);
}
stateListDrawable.addState(new int[]{android.R.attr.state_pressed},selected);
stateListDrawable.addState(StateSet.WILD_CARD,normal);
return stateListDrawable;
}
项目:Mix
文件:ThemeUtils.java
public static boolean containsNinePatch(Drawable drawable) {
drawable = getWrapperDrawable(drawable);
if (drawable instanceof NinePatchDrawable
|| drawable instanceof InsetDrawable
|| drawable instanceof LayerDrawable) {
return true;
} else if (drawable instanceof StateListDrawable) {
final DrawableContainer.DrawableContainerState containerState = ((DrawableContainer.DrawableContainerState) drawable.getConstantState());
//can't getBaseApplication containState from drawable which is containing DrawableWrapperDonut
//https://code.google.com/p/android/issues/detail?id=169920
if (containerState == null) {
return true;
}
for (Drawable dr : containerState.getChildren()) {
dr = getWrapperDrawable(dr);
if (dr instanceof NinePatchDrawable
|| dr instanceof InsetDrawable
|| dr instanceof LayerDrawable) {
return true;
}
}
}
return false;
}
public Drawable getCheckStatusDrawable(String origin,String checked,String pressed,String checkpressed,boolean is9Png) {
int originId = this.mResources.getIdentifier(origin,"drawable",this.packageName);
int selectId = this.mResources.getIdentifier(checked,this.packageName);
int pressedId = this.mResources.getIdentifier(pressed,this.packageName);
int selectpressId = this.mResources.getIdentifier(checkpressed,this.packageName);
if (originId == 0 && selectId == 0 && pressedId == 0 && selectpressId == 0) {
String suffix = (is9Png ? ".9" : "") + ".png";
return new StateListDrawableBuilder(this.mContext,"drawable/" + origin + suffix).setPressDrawable("drawable/" + pressed + suffix).setCheckedDrawable("drawable/" + checked + suffix).setPressCheckedDrawable("drawable/" + checkpressed + suffix).create();
}
Drawable mStateListDrawable = new StateListDrawable();
mStateListDrawable.addState(new int[]{16842912},this.mResources.getDrawable(selectId));
mStateListDrawable.addState(new int[]{16842919},this.mResources.getDrawable(pressedId));
mStateListDrawable.addState(new int[]{16842919,16842912},this.mResources.getDrawable(selectpressId));
mStateListDrawable.addState(new int[0],this.mResources.getDrawable(originId));
return mStateListDrawable;
}
项目:RLibrary
文件:EmojiTabLayout.java
public void addItem(@DrawableRes int ico) {
EmojiTabItemView itemView = new EmojiTabItemView(getContext());
itemView.setimageResource(ico);
if (mItemBackgroundRes == 0) {
StateListDrawable stateListDrawable = new StateListDrawable();
stateListDrawable.addState(new int[]{android.R.attr.state_checked},new ColorDrawable(getResources().getColor(R.color.default_base_bg_press)));
stateListDrawable.addState(new int[]{android.R.attr.state_pressed},new ColorDrawable(getResources().getColor(R.color.default_base_bg_press)));
stateListDrawable.addState(new int[]{},new ColorDrawable(Color.TRANSPARENT));
itemView.setBackground(stateListDrawable);
} else {
itemView.setBackgroundResource(mItemBackgroundRes);
}
addView(itemView,-1,-1);
itemView.setonClickListener(this);
}
项目:ChatExchange-old
文件:Label.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private Drawable createFillDrawable() {
StateListDrawable drawable = new StateListDrawable();
drawable.addState(new int[]{android.R.attr.state_pressed},view.getHeight());
}
});
setClipToOutline(true);
mBackgroundDrawable = ripple;
return ripple;
}
mBackgroundDrawable = drawable;
return drawable;
}
项目:RLibrary
文件:ResUtil.java
/**
* Generate bg drawable drawable.
*
* @param pressColor the press color
* @param defaultColor the default color
* @return the drawable
*/
public static Drawable generateRoundDrawable(float radii,int defaultColor) {
//圆角
Shape roundRectShape = new RoundRectShape(new float[]{radii,radii},null);//圆角背景
//按下状态
ShapeDrawable shopDrawablePress = new ShapeDrawable(roundRectShape);//圆角shape
shopDrawablePress.getPaint().setColor(pressColor);//设置颜色
//正常状态
ShapeDrawable shopDrawablenormal = new ShapeDrawable(roundRectShape);
shopDrawablenormal.getPaint().setColor(defaultColor);
StateListDrawable bgStateDrawable = new StateListDrawable();//状态shape
bgStateDrawable.addState(new int[]{android.R.attr.state_pressed},shopDrawablePress);//按下状态
bgStateDrawable.addState(new int[]{-android.R.attr.state_enabled},shopDrawablePress);
bgStateDrawable.addState(new int[]{},shopDrawablenormal);//其他状态
return bgStateDrawable;
}
项目:ChatExchange-old
文件:Label.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
void onActionUp() {
if (mUsingStyle) {
mBackgroundDrawable = getBackground();
}
if (mBackgroundDrawable instanceof StateListDrawable) {
StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
drawable.setState(new int[]{});
} else if (Util.hasLollipop() && mBackgroundDrawable instanceof rippledrawable) {
rippledrawable ripple = (rippledrawable) mBackgroundDrawable;
ripple.setState(new int[]{});
ripple.setHotspot(getMeasuredWidth() / 2,true);
}
// setpressed(false);
}
项目:Watermark
文件:MediaActivity.java
private StateListDrawable createDefaultOverButtonBgDrawable() {
int dp12 = (int) ThemeUtils.applyDimensionDp(this,12.f);
int dp8 = (int) ThemeUtils.applyDimensionDp(this,8.f);
float dp4 = ThemeUtils.applyDimensionDp(this,4.f);
float[] round = new float[]{dp4,dp4,dp4};
ShapeDrawable pressedDrawable = new ShapeDrawable(new RoundRectShape(round,null));
pressedDrawable.setPadding(dp12,dp8,dp12,dp8);
int pressedColor = ThemeUtils.resolveColor(this,R.attr.gallery_toolbar_over_button_pressed_color,R.color.gallery_default_toolbar_over_button_pressed_color);
pressedDrawable.getPaint().setColor(pressedColor);
int normalColor = ThemeUtils.resolveColor(this,R.attr.gallery_toolbar_over_button_normal_color,R.color.gallery_default_toolbar_over_button_normal_color);
ShapeDrawable normalDrawable = new ShapeDrawable(new RoundRectShape(round,null));
normalDrawable.setPadding(dp12,dp8);
normalDrawable.getPaint().setColor(normalColor);
StateListDrawable stateListDrawable = new StateListDrawable();
stateListDrawable.addState(new int[]{android.R.attr.state_pressed},pressedDrawable);
stateListDrawable.addState(new int[]{},normalDrawable);
return stateListDrawable;
}
项目:PWEditText-SafeKeyboard
文件:SafetyKeyboard.java
private StateListDrawable getDrawableSeletor(Drawable normal,Drawable press) {
StateListDrawable bg = new StateListDrawable();
if (null != normal) {
bg.addState(new int[] { android.R.attr.state_pressed },press);
}
if (null != press) {
bg.addState(new int[] { android.R.attr.state_enabled },normal);
}
return bg;
}
项目:MeetMusic
文件:ScanActivity.java
private void setScanBtnBg(){
int defColor = CustomAttrValueUtil.getAttrColorValue(R.attr.colorAccent,R.color.colorAccent,this);
int pressColor = CustomAttrValueUtil.getAttrColorValue(R.attr.press_color,this);
Drawable backgroundDrawable = scanBtn.getBackground();
StateListDrawable sld = (StateListDrawable) backgroundDrawable;// 通过向下转型,转回原型,selector对应的java类为:StateListDrawable
SelectorUtil.changeViewColor(sld,new int[]{pressColor,defColor});
}
private static StateListDrawable getStateListDrawable(@ColorInt int normalColor,@ColorInt int pressedColor) {
StateListDrawable states = new StateListDrawable();
states.addState(new int[]{android.R.attr.state_activated},getColorDrawable(pressedColor));
states.addState(new int[]{},getColorDrawable(normalColor));
// Animating across states.
// It seems item background is lost on scrolling out of the screen,21 <= API <= 23
if (!Utils.hasLollipop() || Utils.hasNougat()) {
int duration = 200; //android.R.integer.config_shortAnimTime
states.setEnterFadeDuration(duration);
states.setExitFadeDuration(duration);
}
return states;
}
项目:SingleSelectBar
文件:ResHelper.java
private Drawable getpressedEffectBeforeLollipop(CORNER_POSITION cornerPosition,int color) {
ShapeDrawable colorDrawablepressed = getCornerStateDrawable(cornerPosition);
colorDrawablepressed.getPaint().setColor(color);
colorDrawablepressed.getPaint().setStyle(Paint.Style.FILL);
colorDrawablepressed.getPaint().setAlpha(pressed_ALPHA_VALUE);
colorDrawablepressed.mutate();
StateListDrawable textBgDrawable = new StateListDrawable();
textBgDrawable.addState(new int[]{android.R.attr.state_enabled,android.R.attr.state_pressed},colorDrawablepressed);
return textBgDrawable;
}
项目:GitHub
文件:FastAdapterUIUtils.java
/**
* helper to create an StateListDrawable for the given normal and pressed color
*
* @param normalColor the normal color
* @param pressedColor the pressed color
* @return the StateListDrawable
*/
private static StateListDrawable getStateListDrawable(
int normalColor,int pressedColor) {
StateListDrawable states = new StateListDrawable();
states.addState(new int[]{android.R.attr.state_pressed},new ColorDrawable(pressedColor));
states.addState(new int[]{android.R.attr.state_focused},new ColorDrawable(pressedColor));
states.addState(new int[]{android.R.attr.state_activated},new ColorDrawable(pressedColor));
states.addState(new int[]{},new ColorDrawable(normalColor));
return states;
}
项目:GitHub
文件:JellyBeanFloatingActionButton.java
/**
* more advanced usage for fillable in alpha
*
* @param circleRect the defined rectangle
* @return StateListDrawable item
*/
protected StateListDrawable createFillDrawable(RectF circleRect) {
StateListDrawable drawable = new StateListDrawable();
drawable.addState(new int[]{android.R.attr.state_pressed},createalphaDrawble(circleRect,mColorpressed,mAlpha_press));
drawable.addState(new int[]{},mColornormal,mAlpha_normal));
return drawable;
}
项目:GitHub
文件:FloatingActionButton.java
/**
* @param circleRect the defined rectangle
* @param alpha between 0 - 1
* @return StateListDrawable
*/
protected StateListDrawable createFillDrawable(RectF circleRect,float alpha) {
StateListDrawable drawable = new StateListDrawable();
drawable.addState(new int[]{android.R.attr.state_pressed},alpha));
drawable.addState(new int[]{},alpha));
return drawable;
}
项目:GitHub
文件:FloatingActionButton.java
/**
* @param circleRect the defined rectangle
* @return StateListDrawable
*/
protected StateListDrawable createFillDrawable(RectF circleRect) {
StateListDrawable drawable = new StateListDrawable();
drawable.addState(new int[]{android.R.attr.state_pressed},createCircleDrawable(circleRect,mColorpressed));
drawable.addState(new int[]{},mColornormal));
return drawable;
}
private static Drawable generateBackground(int color,int fadeTime) {
StateListDrawable drawable = new StateListDrawable();
drawable.setExitFadeDuration(fadeTime);
drawable.addState(new int[]{16842912},generateCircleDrawable(color));
if (VERSION.SDK_INT >= 21) {
drawable.addState(new int[]{16842919},generaterippledrawable(color));
} else {
drawable.addState(new int[]{16842919},generateCircleDrawable(color));
}
drawable.addState(new int[0],generateCircleDrawable(0));
return drawable;
}
项目:GitHub
文件:MsgView.java
public void setBgSelector() {
StateListDrawable bg = new StateListDrawable();
setDrawable(gd_background,backgroundColor,strokeColor);
bg.addState(new int[]{-android.R.attr.state_pressed},gd_background);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {//16
setBackground(bg);
} else {
//noinspection deprecation
setBackgroundDrawable(bg);
}
}
项目:GitHub
文件:WoWoStateListColorAnimation.java
private void setColors(View view,int[] colors) {
Drawable drawable = view.getBackground();
if (drawable instanceof StateListDrawable) {
StateListDrawable stateListDrawable = (StateListDrawable) drawable;
DrawableContainerState drawableContainerState = (DrawableContainerState) stateListDrawable.getConstantState();
if (drawableContainerState != null) {
Drawable[] drawables = drawableContainerState.getChildren();
for (int i = 0; i < colors.length; i++) if (drawables[i] instanceof GradientDrawable) ((GradientDrawable) drawables[i]).setColor(colors[i]);
}
} else Log.w(TAG,"Drawable of view must be StateListDrawable in WoWoStateListColorAnimation");
}
private StateListDrawable createDefaultBackground() {
TypedValue value = new TypedValue();
if (!getContext().getTheme().resolveAttribute(R.attr.colorControlHighlight,value,true)) {
return null;
}
StateListDrawable drawable = new StateListDrawable();
drawable.addState(CHECKED_STATE_SET,new ColorDrawable(value.data));
drawable.addState(EMPTY_STATE_SET,new ColorDrawable(0));
return drawable;
}
项目:GitHub
文件:DayView.java
private static Drawable generateBackground(int color,int fadeTime,Rect bounds) {
StateListDrawable drawable = new StateListDrawable();
drawable.setExitFadeDuration(fadeTime);
drawable.addState(new int[]{android.R.attr.state_checked},generateCircleDrawable(color));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
drawable.addState(new int[]{android.R.attr.state_pressed},generaterippledrawable(color,bounds));
} else {
drawable.addState(new int[]{android.R.attr.state_pressed},generateCircleDrawable(color));
}
drawable.addState(new int[]{},generateCircleDrawable(Color.TRANSPARENT));
return drawable;
}
项目:HeadlineNews
文件:SelectorFactory.java
public StateListDrawable create() {
StateListDrawable selector = new StateListDrawable();
//enabled = false
if (hasSetdisabledBgColor || hasSetdisabledstrokeColor) {
GradientDrawable disabledShape = getItemShape(mShape,mCornerRadius,mdisabledBgColor,mstrokeWidth,mdisabledstrokeColor);
selector.addState(new int[]{-android.R.attr.state_enabled},disabledShape);
}
//pressed = true
if (hasSetpressedBgColor || hasSetpressedstrokeColor) {
GradientDrawable pressedShape = getItemShape(mShape,mpressedBgColor,mpressedstrokeColor);
selector.addState(new int[]{android.R.attr.state_pressed},pressedShape);
}
//selected = true
if (hasSetSelectedBgColor || hasSetSelectedstrokeColor) {
GradientDrawable selectedShape = getItemShape(mShape,mSelectedBgColor,mSelectedstrokeColor);
selector.addState(new int[]{android.R.attr.state_selected},selectedShape);
}
//focused = true
if (hasSetFocusedBgColor || hasSetFocusedstrokeColor) {
GradientDrawable focusedShape = getItemShape(mShape,mFocusedBgColor,mFocusedstrokeColor);
selector.addState(new int[]{android.R.attr.state_focused},focusedShape);
}
//default
GradientDrawable defaultShape = getItemShape(mShape,mDefaultBgColor,mDefaultstrokeColor);
selector.addState(new int[]{},defaultShape);
return selector;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。