Java Examples for android.R.attr
The following java examples will help you to understand the usage of android.R.attr. These source code samples are taken from different open source projects.
Example 1
| Project: pixate-freestyle-android-master File: PXDrawableUtil.java View source code |
/**
* Creates a new {@link StateListDrawable} by looking into the contexts and
* generating one according to their states.
*
* @param adapter
* @param ruleSets
* @param contexts
* @return A new {@link StateListDrawable}. <code>null</code> in case the
* contexts is <code>null</code> or empty.
*/
public static StateListDrawable createNewStateListDrawable(PXStyleAdapter adapter, List<PXRuleSet> ruleSets, List<PXStylerContext> contexts) {
if (contexts != null && !contexts.isEmpty()) {
// No state-lists here, so simply loop and set the backgrounds
StateListDrawable stateListDrawable = adapter.shouldAdjustDrawableBounds() ? (new StateListDrawableWithBoundsChange()) : (new StateListDrawable());
int[][] deferredDefaultStates = null;
Drawable defaultDrawable = null;
int rulesetSize = ruleSets.size();
for (int i = 0; i < rulesetSize; i++) {
PXStylerContext context = contexts.get(i);
String activeStateName = context.getActiveStateName();
if (activeStateName == null) {
activeStateName = PXStyleInfo.DEFAULT_STYLE;
}
Drawable drawable = (context.usesImage() || context.usesColorOnly()) ? context.getBackgroundImage() : null;
// Artificially add states to the one we got. For example, add a
// 'pressed' state to a 'checked' state.
int stateValue = PXDrawableUtil.getStateValue(activeStateName);
if (stateValue == android.R.attr.drawable) {
deferredDefaultStates = adapter.createAdditionalDrawableStates(stateValue);
defaultDrawable = drawable;
} else {
int[][] activeStates = adapter.createAdditionalDrawableStates(stateValue);
for (int[] activeState : activeStates) {
stateListDrawable.addState(activeState, drawable);
}
}
}
if (deferredDefaultStates != null && defaultDrawable != null) {
// add the defaults at the end of the state list.
for (int[] activeState : deferredDefaultStates) {
stateListDrawable.addState(activeState, defaultDrawable);
}
}
return stateListDrawable;
}
return null;
}Example 2
| Project: litho-master File: ComponentsRule.java View source code |
/**
* TODO natthu: this is just a hack around a BUCK issue whereby BUCK only generates random array
* values. Component tests require the correct values for the ComponentLayout styleable array in
* order to bind props to the layout. The array that we define here needs to be kept up-to-date
* with the array defined in //android_res/com/facebook/components/res/values/attrs.xml.
*/
static void setComponentStyleableAttributes() {
System.arraycopy(new int[] { R.attr.flex_direction, R.attr.flex_layoutDirection, R.attr.flex_justifyContent, R.attr.flex_alignItems, R.attr.flex_alignSelf, R.attr.flex_positionType, R.attr.flex_wrap, R.attr.flex_left, R.attr.flex_top, R.attr.flex_right, R.attr.flex_bottom, R.attr.flex, android.R.attr.layout_width, android.R.attr.layout_height, android.R.attr.padding, android.R.attr.paddingLeft, android.R.attr.paddingTop, android.R.attr.paddingRight, android.R.attr.paddingBottom, android.R.attr.paddingStart, android.R.attr.paddingEnd, android.R.attr.layout_margin, android.R.attr.layout_marginLeft, android.R.attr.layout_marginTop, android.R.attr.layout_marginRight, android.R.attr.layout_marginBottom, android.R.attr.layout_marginStart, android.R.attr.layout_marginEnd, android.R.attr.contentDescription, android.R.attr.background, android.R.attr.foreground, android.R.attr.importantForAccessibility, android.R.attr.duplicateParentState }, /* srcPos */
0, R.styleable.ComponentLayout, /* destPos */
0, R.styleable.ComponentLayout.length);
System.arraycopy(new int[] { android.R.attr.minLines, android.R.attr.maxLines, android.R.attr.textColor, android.R.attr.textColorLink, android.R.attr.textColorHighlight, android.R.attr.textSize, android.R.attr.lineSpacingMultiplier, android.R.attr.ellipsize, android.R.attr.textAlignment, android.R.attr.textStyle, android.R.attr.text, android.R.attr.textDirection, android.R.attr.includeFontPadding, android.R.attr.singleLine, android.R.attr.shadowColor, android.R.attr.shadowDx, android.R.attr.shadowDy, android.R.attr.shadowRadius, android.R.attr.gravity, android.R.attr.minEms, android.R.attr.minWidth, android.R.attr.maxEms, android.R.attr.maxWidth }, /* srcPos */
0, R.styleable.Text, /* destPos */
0, R.styleable.Text.length);
System.arraycopy(new int[] { android.R.attr.src, android.R.attr.scaleType }, /* srcPos */
0, R.styleable.Image, /* destPos */
0, R.styleable.Image.length);
}Example 3
| Project: turquoise-master File: StateListDrawableUtils.java View source code |
/**
* 生成按下/点击/选中效果的Selector
* @param normal 正常状态
* @param pressed 按下/点击/选中状态
*/
public static StateListDrawable createPressSelector(Drawable normal, Drawable pressed) {
StateListDrawable drawable = new StateListDrawable();
drawable.addState(new int[] { -android.R.attr.state_focused, -android.R.attr.state_selected, -android.R.attr.state_pressed }, normal);
drawable.addState(new int[] { -android.R.attr.state_focused, android.R.attr.state_selected, -android.R.attr.state_pressed }, pressed);
drawable.addState(new int[] { android.R.attr.state_focused, -android.R.attr.state_selected, -android.R.attr.state_pressed }, pressed);
drawable.addState(new int[] { android.R.attr.state_focused, android.R.attr.state_selected, -android.R.attr.state_pressed }, pressed);
drawable.addState(new int[] { android.R.attr.state_selected, android.R.attr.state_pressed }, pressed);
drawable.addState(new int[] { android.R.attr.state_pressed }, pressed);
return drawable;
}Example 4
| Project: boilerplate-master File: TintHelper.java View source code |
public static ColorStateList getTintColorStateList(Context context, int activeColor, int defaultColor) {
return new ColorStateList(new int[][] { new int[] { android.R.attr.state_pressed }, new int[] { android.R.attr.state_focused }, new int[] { android.R.attr.state_selected }, new int[] { android.R.attr.state_checked }, new int[] { android.R.attr.state_active }, new int[] { android.R.attr.state_activated }, new int[] {} }, new int[] { activeColor, activeColor, activeColor, activeColor, activeColor, activeColor, defaultColor });
}Example 5
| Project: AndroidPicker-master File: StateBaseDrawable.java View source code |
protected void addState(Drawable normal, Drawable pressed) {
addState(new int[] { android.R.attr.state_pressed, android.R.attr.state_enabled }, pressed);
addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_focused }, pressed);
addState(new int[] { android.R.attr.state_enabled }, normal);
addState(new int[] { android.R.attr.state_focused }, pressed);
addState(new int[] { android.R.attr.state_window_focused }, normal);
addState(new int[] {}, normal);
}Example 6
| Project: itsnat_droid-master File: ClassDescView_widget_GridLayout.java View source code |
public static void getGridLayoutLayoutParamsFromStyleId(int styleId, List<DOMAttr> styleLayoutParamsAttribs, ContextThemeWrapper ctx) {
if (styleId == 0)
throw MiscUtil.internalError();
Configuration configuration = ctx.getResources().getConfiguration();
TypedArray a = ctx.obtainStyledAttributes(styleId, layoutParamsAttrs);
for (int i = 0; i < layoutParamsAttrs.length; i++) {
if (!a.hasValue(i))
continue;
String name = layoutParamsNames[i];
String value;
if ("layout_gravity".equals(name)) {
int valueInt = a.getInt(i, 0);
value = GravityUtil.getNameFromValue(valueInt);
} else {
// Los demás atributos son enteros normales
value = a.getString(i);
}
DOMAttr attr = DOMAttr.createDOMAttr(NamespaceUtil.XMLNS_ANDROID, name, value);
styleLayoutParamsAttribs.add(attr);
}
a.recycle();
// Llamamos a la clase base
ClassDescView_view_ViewGroup.getViewGroupMarginLayoutParamsFromStyleId(styleId, styleLayoutParamsAttribs, ctx);
}Example 7
| Project: Android_Skin_2.0-master File: EnvCheckedTextViewChanger.java View source code |
@Override
protected void onApplyStyle(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes, boolean allowSysRes) {
super.onApplyStyle(context, attrs, defStyleAttr, defStyleRes, allowSysRes);
EnvTypedArray array = EnvTypedArray.obtainStyledAttributes(context, attrs, ATTRS, defStyleAttr, defStyleRes);
mCheckMarkEnvRes = array.getEnvRes(Arrays.binarySearch(ATTRS, android.R.attr.checkMark), allowSysRes);
array.recycle();
}Example 8
| Project: ijoomer-adv-sdk-master File: SmartTabItem.java View source code |
@SuppressWarnings("deprecation")
private void initComponent(AttributeSet attr) {
try {
nameSpace = "http://schemas.android.com/apk/res/" + SmartApplication.REF_SMART_APPLICATION.getPackageName();
OnDrawable = attr.getAttributeResourceValue(nameSpace, "OnDrawable", 0);
OffDrawable = attr.getAttributeResourceValue(nameSpace, "OffDrawable", 0);
OffPressedDrawable = attr.getAttributeResourceValue(nameSpace, "OffPressedDrawable", 0);
StateListDrawable mStateContainer = new StateListDrawable();
StateListDrawable mStateContainer1 = new StateListDrawable();
this.setButtonDrawable(mStateContainer1);
Drawable checkedDrawable = getResources().getDrawable(OnDrawable);
Drawable defaultDrawable = getResources().getDrawable(OffDrawable);
Drawable defaultPressedDrawable = getResources().getDrawable(OffPressedDrawable);
mStateContainer.addState(CHECKED_STATE_SET, checkedDrawable);
mStateContainer.addState(CHECKED_PRESSED_STATE_SET, defaultPressedDrawable);
mStateContainer.addState(StateSet.WILD_CARD, defaultDrawable);
this.setBackgroundDrawable(mStateContainer);
setChecked(false);
} catch (Throwable e) {
e.printStackTrace();
}
}Example 9
| Project: material-design-toolkit-master File: StateChanger.java View source code |
@Override
public boolean onStateChange(int[] prev_states, int[] next_states) {
if (mEnabled) {
boolean prev_pressed = contains(prev_states, android.R.attr.state_pressed);
boolean next_pressed = contains(next_states, android.R.attr.state_pressed);
if (prev_pressed != next_pressed) {
// pressed status changed
if (next_pressed) {
onPressed();
} else {
onReleased();
}
return true;
}
boolean prev_focused = contains(prev_states, android.R.attr.state_focused);
boolean next_focused = contains(next_states, android.R.attr.state_focused);
if (prev_focused != next_focused) {
// focused status changed
if (next_focused) {
onFocused();
} else {
onReleased();
}
return true;
}
}
return false;
}Example 10
| Project: robolectric-master File: ShadowResourcesTest.java View source code |
@Test
public void obtainTypedArray() throws Exception {
final Display display = Shadow.newInstanceOf(Display.class);
final ShadowDisplay shadowDisplay = shadowOf(display);
// Standard xxhdpi screen
shadowDisplay.setDensityDpi(480);
final DisplayMetrics displayMetrics = new DisplayMetrics();
display.getMetrics(displayMetrics);
final TypedArray valuesTypedArray = resources.obtainTypedArray(R.array.typed_array_values);
assertThat(valuesTypedArray.getString(0)).isEqualTo("abcdefg");
assertThat(valuesTypedArray.getInt(1, 0)).isEqualTo(3875);
assertThat(valuesTypedArray.getInteger(1, 0)).isEqualTo(3875);
assertThat(valuesTypedArray.getFloat(2, 0.0f)).isEqualTo(2.0f);
assertThat(valuesTypedArray.getColor(3, Color.BLACK)).isEqualTo(Color.MAGENTA);
assertThat(valuesTypedArray.getColor(4, Color.BLACK)).isEqualTo(Color.parseColor("#00ffff"));
assertThat(valuesTypedArray.getDimension(5, 0.0f)).isEqualTo(8.0f);
assertThat(valuesTypedArray.getDimension(6, 0.0f)).isEqualTo(12.0f);
assertThat(valuesTypedArray.getDimension(7, 0.0f)).isEqualTo(6.0f);
assertThat(valuesTypedArray.getDimension(8, 0.0f)).isEqualTo(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, 3.0f, displayMetrics));
assertThat(valuesTypedArray.getDimension(9, 0.0f)).isEqualTo(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_IN, 4.0f, displayMetrics));
assertThat(valuesTypedArray.getDimension(10, 0.0f)).isEqualTo(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 36.0f, displayMetrics));
assertThat(valuesTypedArray.getDimension(11, 0.0f)).isEqualTo(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PT, 18.0f, displayMetrics));
final TypedArray refsTypedArray = resources.obtainTypedArray(R.array.typed_array_references);
assertThat(refsTypedArray.getString(0)).isEqualTo("apple");
assertThat(refsTypedArray.getString(1)).isEqualTo("banana");
assertThat(refsTypedArray.getInt(2, 0)).isEqualTo(5);
assertThat(refsTypedArray.getBoolean(3, false)).isTrue();
if (RuntimeEnvironment.getApiLevel() >= LOLLIPOP) {
assertThat(refsTypedArray.getType(4)).isEqualTo(TypedValue.TYPE_NULL);
}
assertThat(shadowOf(refsTypedArray.getDrawable(5)).getCreatedFromResId()).isEqualTo(R.drawable.an_image);
assertThat(refsTypedArray.getColor(6, Color.BLACK)).isEqualTo(Color.parseColor("#ff5c00"));
if (RuntimeEnvironment.getApiLevel() >= LOLLIPOP) {
assertThat(refsTypedArray.getThemeAttributeId(7, -1)).isEqualTo(R.attr.animalStyle);
}
assertThat(refsTypedArray.getResourceId(8, 0)).isEqualTo(R.array.typed_array_values);
assertThat(refsTypedArray.getTextArray(8)).containsExactly("abcdefg", "3875", "2.0", "#ffff00ff", "#00ffff", "8px", "12dp", "6dip", "3mm", "4in", "36sp", "18pt");
assertThat(refsTypedArray.getResourceId(9, 0)).isEqualTo(R.style.Theme_Robolectric);
}Example 11
| Project: CameraColorPicker-master File: BackgroundUtilsImplPreLollipop.java View source code |
private static Drawable getPressedColorDrawable(int normalColor, int pressedColor) {
StateListDrawable drawable = new StateListDrawable();
drawable.addState(new int[] { android.R.attr.state_pressed, android.R.attr.state_enabled }, getColorDrawableFromColor(pressedColor));
drawable.addState(new int[] { android.R.attr.state_focused }, getColorDrawableFromColor(pressedColor));
drawable.addState(new int[] { android.R.attr.state_activated }, getColorDrawableFromColor(pressedColor));
drawable.addState(new int[] {}, getColorDrawableFromColor(normalColor));
return drawable;
}Example 12
| Project: react-native-navigation-master File: TopTabsIconColorHelper.java View source code |
private ColorStateList createColorStateList(int selectedColor, int unselectedIconColor) {
int[][] states = new int[][] { new int[] { android.R.attr.state_pressed }, new int[] { android.R.attr.state_selected }, new int[] { android.R.attr.state_enabled }, new int[] { android.R.attr.state_focused, android.R.attr.state_pressed }, new int[] { -android.R.attr.state_enabled }, new int[] {} };
int[] colors = new int[] { selectedColor, selectedColor, unselectedIconColor, unselectedIconColor, unselectedIconColor, unselectedIconColor };
return new ColorStateList(states, colors);
}Example 13
| Project: remusic-master File: LayerDrawableUtils.java View source code |
@Override
protected Drawable inflateDrawable(Context context, XmlPullParser parser, AttributeSet attrs) throws IOException, XmlPullParserException {
final int innerDepth = parser.getDepth() + 1;
int type;
int depth;
int layerAttrUseCount = 0;
int drawableUseCount = 0;
int space = STEP << 1;
//L,T,R,B,S,E,id
int[][] childLayersAttrs = new int[space][ATTRS.length];
Drawable[] drawables = new Drawable[space];
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) {
if (type != XmlPullParser.START_TAG) {
continue;
}
if (depth > innerDepth || !parser.getName().equals("item")) {
continue;
}
if (layerAttrUseCount >= childLayersAttrs.length) {
int[][] dstInt = new int[drawables.length + STEP][ATTRS.length];
System.arraycopy(childLayersAttrs, 0, dstInt, 0, childLayersAttrs.length);
childLayersAttrs = dstInt;
}
updateLayerAttrs(context, attrs, childLayersAttrs[layerAttrUseCount]);
layerAttrUseCount++;
Drawable drawable = getAttrDrawable(context, attrs, android.R.attr.drawable);
// element.
if (drawable == null) {
while ((type = parser.next()) == XmlPullParser.TEXT) {
}
if (type != XmlPullParser.START_TAG) {
throw new XmlPullParserException(parser.getPositionDescription() + ": <item> tag requires a 'drawable' attribute or " + "child tag defining a drawable");
}
drawable = createFromXmlInner(context, parser, attrs);
} else {
final ColorStateList cls = getTintColorList(context, attrs, R.attr.drawableTint);
if (cls != null) {
drawable = ThemeUtils.tintDrawable(drawable, cls, getTintMode(context, attrs, R.attr.drawableTintMode));
}
}
if (drawable != null) {
if (drawableUseCount >= drawables.length) {
Drawable[] dst = new Drawable[drawables.length + STEP];
System.arraycopy(drawables, 0, dst, 0, drawables.length);
drawables = dst;
}
drawables[drawableUseCount] = drawable;
drawableUseCount++;
}
}
if (drawables[0] == null || drawableUseCount != layerAttrUseCount) {
return null;
} else {
LayerDrawable layerDrawable = new LayerDrawable(drawables);
for (int i = 0; i < drawables.length; i++) {
int[] childLayersAttr = childLayersAttrs[i];
if (childLayersAttr[0] != 0 || childLayersAttr[1] != 0 || childLayersAttr[2] != 0 || childLayersAttr[3] != 0) {
layerDrawable.setLayerInset(i, childLayersAttr[0], childLayersAttr[1], childLayersAttr[2], childLayersAttr[3]);
}
if (childLayersAttr[4] != 0) {
layerDrawable.setId(i, childLayersAttr[4]);
}
}
return layerDrawable;
}
}Example 14
| Project: MagicaSakura-master File: LayerDrawableInflateImpl.java View source code |
@Override
public Drawable inflateDrawable(Context context, XmlPullParser parser, AttributeSet attrs) throws IOException, XmlPullParserException {
final int innerDepth = parser.getDepth() + 1;
int type;
int depth;
int layerAttrUseCount = 0;
int drawableUseCount = 0;
int space = STEP << 1;
//L,T,R,B,S,E,id
int[][] childLayersAttrs = new int[space][ATTRS.length];
Drawable[] drawables = new Drawable[space];
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) {
if (type != XmlPullParser.START_TAG) {
continue;
}
if (depth > innerDepth || !parser.getName().equals("item")) {
continue;
}
if (layerAttrUseCount >= childLayersAttrs.length) {
int[][] dstInt = new int[drawables.length + STEP][ATTRS.length];
System.arraycopy(childLayersAttrs, 0, dstInt, 0, childLayersAttrs.length);
childLayersAttrs = dstInt;
}
updateLayerAttrs(context, attrs, childLayersAttrs[layerAttrUseCount]);
layerAttrUseCount++;
Drawable drawable = DrawableUtils.getAttrDrawable(context, attrs, android.R.attr.drawable);
// element.
if (drawable == null) {
while ((type = parser.next()) == XmlPullParser.TEXT) {
}
if (type != XmlPullParser.START_TAG) {
throw new XmlPullParserException(parser.getPositionDescription() + ": <item> tag requires a 'drawable' attribute or " + "child tag defining a drawable");
}
drawable = DrawableUtils.createFromXmlInner(context, parser, attrs);
} else {
final ColorStateList cls = DrawableUtils.getTintColorList(context, attrs, R.attr.drawableTint);
if (cls != null) {
drawable = ThemeUtils.tintDrawable(drawable, cls, DrawableUtils.getTintMode(context, attrs, R.attr.drawableTintMode));
}
}
if (drawable != null) {
if (drawableUseCount >= drawables.length) {
Drawable[] dst = new Drawable[drawables.length + STEP];
System.arraycopy(drawables, 0, dst, 0, drawables.length);
drawables = dst;
}
drawables[drawableUseCount] = drawable;
drawableUseCount++;
}
}
if (drawables[0] == null || drawableUseCount != layerAttrUseCount) {
return null;
} else {
LayerDrawable layerDrawable = new LayerDrawable(drawables);
for (int i = 0; i < drawables.length; i++) {
int[] childLayersAttr = childLayersAttrs[i];
if (childLayersAttr[0] != 0 || childLayersAttr[1] != 0 || childLayersAttr[2] != 0 || childLayersAttr[3] != 0) {
layerDrawable.setLayerInset(i, childLayersAttr[0], childLayersAttr[1], childLayersAttr[2], childLayersAttr[3]);
}
if (childLayersAttr[4] != 0) {
layerDrawable.setId(i, childLayersAttr[4]);
}
}
return layerDrawable;
}
}Example 15
| Project: life-master File: ResourcesUtils.java View source code |
/**
* 创建一个ColorStateList
* create a StateListDrawable instance
*
* @param context context
* @param normalRes normalRes
* @param pressedRes pressedRes
* @param focusedRes focusedRes
* @param unableRes unableRes
* @return StateListDrawable
*/
public static StateListDrawable createStateListDrawable(Context context, @DrawableRes int normalRes, @DrawableRes int pressedRes, @DrawableRes int focusedRes, @DrawableRes int unableRes) {
StateListDrawable stateListDrawable = new StateListDrawable();
stateListDrawable.addState(new int[] { android.R.attr.state_pressed, android.R.attr.state_enabled }, getDrawable(context, pressedRes));
stateListDrawable.addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_focused }, getDrawable(context, focusedRes));
stateListDrawable.addState(new int[] { android.R.attr.state_enabled }, getDrawable(context, normalRes));
stateListDrawable.addState(new int[] { android.R.attr.state_focused }, getDrawable(context, focusedRes));
stateListDrawable.addState(new int[] { android.R.attr.state_window_focused }, getDrawable(context, unableRes));
stateListDrawable.addState(new int[] {}, getDrawable(context, normalRes));
return stateListDrawable;
}Example 16
| Project: ulti-master File: AlmostRippleDrawable.java View source code |
@Override
public boolean setState(int[] stateSet) {
int[] oldState = getState();
boolean oldPressed = false;
for (int i : oldState) {
if (i == android.R.attr.state_pressed) {
oldPressed = true;
}
}
super.setState(stateSet);
boolean focused = false;
boolean pressed = false;
boolean disabled = true;
for (int i : stateSet) {
if (i == android.R.attr.state_focused) {
focused = true;
} else if (i == android.R.attr.state_pressed) {
pressed = true;
} else if (i == android.R.attr.state_enabled) {
disabled = false;
}
}
if (disabled) {
unscheduleSelf(mUpdater);
mRippleColor = mDisabledColor;
mRippleBgColor = 0;
mCurrentScale = ACTIVE_SCALE / 2;
invalidateSelf();
} else {
if (pressed) {
animateToPressed();
mRippleColor = mRippleBgColor = mPressedColor;
} else if (oldPressed) {
mRippleColor = mRippleBgColor = mPressedColor;
animateToNormal();
} else if (focused) {
mRippleColor = mFocusedColor;
mRippleBgColor = 0;
mCurrentScale = ACTIVE_SCALE;
invalidateSelf();
} else {
mRippleColor = 0;
mRippleBgColor = 0;
mCurrentScale = INACTIVE_SCALE;
invalidateSelf();
}
}
return true;
}Example 17
| Project: Klyph-master File: ProfileImageView.java View source code |
private void initDrawables(Context context) {
final int themeColor = AttrUtil.getColor(context, R.attr.themeColor);
final int borderWidth = context.getResources().getDimensionPixelSize(R.dimen.profile_image_border_size);
setBorderDrawable(new BorderDrawable(KlyphPreferences.isRoundedPictureEnabled() ? BorderDrawable.OVAL : BorderDrawable.RECT, themeColor, borderWidth));
}Example 18
| Project: gscript-master File: CheckableListItem.java View source code |
void updateCheckedState() {
Drawable drawable = this.getBackground();
if (drawable instanceof StateListDrawable) {
StateListDrawable list = (StateListDrawable) drawable;
list.setState(new int[] { this.isChecked() ? android.R.attr.state_checked : 0, this.isSelected() ? android.R.attr.state_selected : 0, this.isPressed() ? android.R.attr.state_pressed : 0, this.isFocused() ? android.R.attr.state_focused : 0, this.isEnabled() ? android.R.attr.state_enabled : 0 });
}
}Example 19
| Project: androids-master File: STextView.java View source code |
private ColorStateList createColorStateList(int pressed, int selected, int unable, int normal) {
ColorStateList colorStateList = new ColorStateList(new int[][] { // 遍历到满足的状态则停止遍历
{ android.R.attr.state_enabled, android.R.attr.state_pressed }, { android.R.attr.state_enabled, android.R.attr.state_selected }, { -android.R.attr.state_enabled }, {} }, new int[] { pressed, selected, unable, normal });
return colorStateList;
}Example 20
| Project: material-dialogs-master File: MDTintHelper.java View source code |
public static void setTint(@NonNull RadioButton radioButton, @ColorInt int color) {
final int disabledColor = DialogUtils.getDisabledColor(radioButton.getContext());
ColorStateList sl = new ColorStateList(new int[][] { new int[] { android.R.attr.state_enabled, -android.R.attr.state_checked }, new int[] { android.R.attr.state_enabled, android.R.attr.state_checked }, new int[] { -android.R.attr.state_enabled, -android.R.attr.state_checked }, new int[] { -android.R.attr.state_enabled, android.R.attr.state_checked } }, new int[] { DialogUtils.resolveColor(radioButton.getContext(), R.attr.colorControlNormal), color, disabledColor, disabledColor });
setTint(radioButton, sl);
}Example 21
| Project: ride-master File: RideRequestButton.java View source code |
private void setBackgroundAttributes(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
int attrsResources[] = { android.R.attr.background };
TypedArray backgroundAttributes = context.getTheme().obtainStyledAttributes(attrs, attrsResources, defStyleAttr, defStyleRes);
try {
applyBackgroundResource(backgroundAttributes);
} finally {
backgroundAttributes.recycle();
}
}Example 22
| Project: memo-master File: CheckBoxPreference.java View source code |
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
TypedArray typedArray = context.obtainStyledAttributes(attrs, new int[] { android.R.attr.summaryOn, android.R.attr.summaryOff, android.R.attr.disableDependentsState }, defStyleAttr, defStyleRes);
setSummaryOn(typedArray.getString(0));
setSummaryOff(typedArray.getString(1));
setDisableDependentsState(typedArray.getBoolean(2, false));
typedArray.recycle();
setWidgetLayoutResource(R.layout.mp_checkbox_preference);
}Example 23
| Project: AmazeFileManager-master File: EditTextColorStateUtil.java View source code |
private static ColorStateList createEditTextColorStateList(int color) {
int[][] states = new int[3][];
int[] colors = new int[3];
int i = 0;
states[i] = new int[] { -android.R.attr.state_enabled };
colors[i] = Color.parseColor("#f6f6f6");
i++;
states[i] = new int[] { -android.R.attr.state_pressed, -android.R.attr.state_focused };
colors[i] = Color.parseColor("#666666");
i++;
states[i] = new int[] {};
colors[i] = color;
return new ColorStateList(states, colors);
}Example 24
| Project: MultipleTheme-master File: ViewAttributeUtil.java View source code |
public static int getAttributeValue(AttributeSet attr, int paramInt) { int value = -1; int count = attr.getAttributeCount(); for (int i = 0; i < count; i++) { if (attr.getAttributeNameResource(i) == paramInt) { String str = attr.getAttributeValue(i); if (null != str && str.startsWith("?")) { value = Integer.valueOf(str.substring(1, str.length())).intValue(); return value; } } } return value; }
Example 25
| Project: PictureSelector-master File: SelectedStateListDrawable.java View source code |
@Override
protected boolean onStateChange(int[] states) {
boolean isStatePressedInArray = false;
for (int state : states) {
if (state == android.R.attr.state_selected) {
isStatePressedInArray = true;
}
}
if (isStatePressedInArray) {
super.setColorFilter(mSelectionColor, PorterDuff.Mode.SRC_ATOP);
} else {
super.clearColorFilter();
}
return super.onStateChange(states);
}Example 26
| Project: digits-android-master File: ButtonThemer.java View source code |
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
void setBackgroundAccentColorInverse(View view, int accentColor) {
final StateListDrawable background = new StateListDrawable();
final float radius = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, resources.getDisplayMetrics());
final float strokeWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, resources.getDisplayMetrics());
// pressed or in focus
GradientDrawable tmp = new GradientDrawable();
tmp.setCornerRadius(radius);
tmp.setStroke((int) strokeWidth, getPressedColor(accentColor));
for (int[] state : focussedOrPressedButEnabled) {
background.addState(state, tmp);
}
// disabled
tmp = new GradientDrawable();
tmp.setCornerRadius(radius);
tmp.setStroke((int) strokeWidth, getDisabledColor(accentColor));
background.addState(new int[] { -android.R.attr.state_enabled }, tmp);
// default
tmp = new GradientDrawable();
tmp.setCornerRadius(radius);
tmp.setStroke((int) strokeWidth, accentColor);
background.addState(StateSet.WILD_CARD, tmp);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
view.setBackground(background);
} else {
view.setBackgroundDrawable(background);
}
}Example 27
| Project: Heyzap-ANE-master File: Drawables.java View source code |
public static Drawable getPrimaryButtonBackground(Context context) {
StateListDrawable states = new StateListDrawable();
Drawable pressed = getDrawable(null, "dialog_grn_btn_sel.png");
states.addState(new int[] { android.R.attr.state_pressed }, pressed);
states.addState(new int[] { android.R.attr.state_focused }, pressed);
states.addState(new int[] { android.R.attr.state_enabled }, getDrawable(null, "dialog_grn_btn.png"));
return states;
}Example 28
| Project: RippleViews-master File: RippleButton.java View source code |
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void setRippleColor(final int color) {
rippleColor = color;
if (rippleColor == 0) {
return;
}
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Drawable drawable = getBackground();
if (drawable instanceof RippleDrawable) {
RippleDrawable rippleDrawable = (RippleDrawable) drawable;
ColorStateList colorStateList = new ColorStateList(new int[][] { new int[] { android.R.attr.state_pressed }, new int[] { android.R.attr.state_focused }, new int[] { android.R.attr.state_activated }, new int[] { 0 } }, new int[] { rippleColor, rippleColor, rippleColor, buttonColor });
rippleDrawable.setColor(colorStateList);
} else {
Log.w("RippleButton", "The Background must be a RippleDrawable instance.");
}
}
}Example 29
| Project: LuaViewSDK-master File: DrawableUtil.java View source code |
/**
* 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;
}Example 30
| Project: AppCompat-Extension-Library-master File: PickerThemeUtils.java View source code |
public static ColorStateList getHeaderTextColorStateList(Context context) {
return new ColorStateList(new int[][] { // states
new int[] { android.R.attr.state_selected }, // state_default
new int[] {} }, new int[] { // colors
ContextCompat.getColor(context, R.color.abc_primary_text_material_dark), ContextCompat.getColor(context, R.color.abc_secondary_text_material_dark) });
}Example 31
| Project: Facebook-master File: FacebookButtonBase.java View source code |
private void parseBackgroundAttributes(final Context context, final AttributeSet attrs, final int defStyleAttr, final int defStyleRes) {
final int attrsResources[] = { android.R.attr.background };
final TypedArray a = context.getTheme().obtainStyledAttributes(attrs, attrsResources, defStyleAttr, defStyleRes);
try {
if (a.hasValue(0)) {
int backgroundResource = a.getResourceId(0, 0);
if (backgroundResource != 0) {
setBackgroundResource(backgroundResource);
} else {
setBackgroundColor(a.getColor(0, 0));
}
} else {
// fallback, if no background specified, fill with Facebook blue
setBackgroundColor(a.getColor(0, R.color.com_facebook_blue));
}
} finally {
a.recycle();
}
}Example 32
| Project: MaterialDesignDemo-master File: NavigationViewAttr.java View source code |
private ColorStateList createSelector(int color) {
int statePressed = android.R.attr.state_checked;
int stateChecked = android.R.attr.state_checked;
int[][] state = { { statePressed }, { -statePressed }, { stateChecked }, { -stateChecked } };
int color1 = color;
int color2 = Color.parseColor("#6E6E6E");
int color3 = color;
int color4 = Color.parseColor("#6E6E6E");
int[] colors = { color1, color2, color3, color4 };
ColorStateList colorStateList = new ColorStateList(state, colors);
return colorStateList;
}Example 33
| Project: HTWDD-master File: CareerServiceBeratung.java View source code |
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Button ButtonTermin, ButtonJobboerse, ButtonMentoring;
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= 14) {
ButtonTermin = new Button(getActivity(), null, android.R.attr.borderlessButtonStyle);
ButtonTermin.setTextColor(Color.parseColor("#33B5E5"));
ButtonJobboerse = new Button(getActivity(), null, android.R.attr.borderlessButtonStyle);
ButtonJobboerse.setTextColor(Color.parseColor("#33B5E5"));
ButtonMentoring = new Button(getActivity(), null, android.R.attr.borderlessButtonStyle);
ButtonMentoring.setTextColor(Color.parseColor("#33B5E5"));
} else {
ButtonTermin = new Button(getActivity(), null, android.R.attr.buttonStyleSmall);
ButtonJobboerse = new Button(getActivity(), null, android.R.attr.buttonStyleSmall);
ButtonMentoring = new Button(getActivity(), null, android.R.attr.buttonStyleSmall);
}
ButtonTermin.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
ButtonTermin.setText("Termin anfragen");
ButtonJobboerse.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
ButtonJobboerse.setText("Jobbörse im Browser öffnen");
ButtonMentoring.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
ButtonMentoring.setText("Mentoring im Browser öffnen");
LinearLayout layoutBeratung = (LinearLayout) getActivity().findViewById(R.id.CareerBeratung);
LinearLayout layoutJobboerse = (LinearLayout) getActivity().findViewById(R.id.CareerJobboerse);
LinearLayout layoutMentoring = (LinearLayout) getActivity().findViewById(R.id.CareerMentoring);
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
layoutBeratung.addView(ButtonTermin, lp);
layoutJobboerse.addView(ButtonJobboerse, lp);
layoutMentoring.addView(ButtonMentoring, lp);
ButtonTermin.setOnClickListener(new TerminOnClickListener());
ButtonJobboerse.setOnClickListener(new JobboerseOnClickListener());
ButtonMentoring.setOnClickListener(new MentoringOnClickListener());
}Example 34
| Project: QMBForm-master File: FormDetailTextInlineFieldCell.java View source code |
@Override
protected void init() {
super.init();
mDetailTextView = (TextView) findViewById(R.id.detailTextView);
if (setStyleId(mDetailTextView, CellDescriptor.APPEARANCE_TEXT_VALUE, CellDescriptor.COLOR_VALUE) == false) {
// If no specific style is defined for APPEARANCE_TEXT_VALUE,
// set inline text size to the default EditText size.
// Get the android:textAppearance item from R.style.Widget_AppCompat_EditText (default EditText style)
int editTextAppearanceId = getStyleItemResourceId(mDetailTextView.getContext(), R.style.Widget_AppCompat_EditText, android.R.attr.textAppearance, android.R.attr.textAppearanceMediumInverse);
// Get the android:textSize item from retrieved textAppearance style
DisplayMetrics displayMetrics = mDetailTextView.getContext().getResources().getDisplayMetrics();
float editSize = getStyleItemDimension(mDetailTextView.getContext(), editTextAppearanceId, android.R.attr.textSize, 18f * (displayMetrics.densityDpi / 160f));
// Set inline text size
mDetailTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, editSize);
}
}Example 35
| Project: HaoCommon-master File: CornerUtils.java View source code |
/**
* set btn selector with corner drawable for special position
*/
public static StateListDrawable btnSelector(float radius, int normalColor, int pressColor, int postion) {
StateListDrawable bg = new StateListDrawable();
Drawable normal = null;
Drawable pressed = null;
if (postion == 0) {
// left btn
normal = cornerDrawable(normalColor, new float[] { 0, 0, 0, 0, 0, 0, radius, radius });
pressed = cornerDrawable(pressColor, new float[] { 0, 0, 0, 0, 0, 0, radius, radius });
} else if (postion == 1) {
// right btn
normal = cornerDrawable(normalColor, new float[] { 0, 0, 0, 0, radius, radius, 0, 0 });
pressed = cornerDrawable(pressColor, new float[] { 0, 0, 0, 0, radius, radius, 0, 0 });
} else if (postion == -1) {
// only one btn
normal = cornerDrawable(normalColor, new float[] { 0, 0, 0, 0, radius, radius, radius, radius });
pressed = cornerDrawable(pressColor, new float[] { 0, 0, 0, 0, radius, radius, radius, radius });
}
bg.addState(new int[] { -android.R.attr.state_pressed }, normal);
bg.addState(new int[] { android.R.attr.state_pressed }, pressed);
return bg;
}Example 36
| Project: ant-master File: SupportButton.java View source code |
protected ColorStateList createButtonColorStateList() {
int[][] states = new int[][] { // disabled
new int[] { -android.R.attr.state_enabled }, // pressed
new int[] { android.R.attr.state_pressed }, // focused
new int[] { android.R.attr.state_focused }, // enabled
new int[] { android.R.attr.state_enabled } };
int[] colors = new int[] { mDisabledColor, mPressedColor, mPressedColor, mNormalColor };
return new ColorStateList(states, colors);
}Example 37
| Project: React-Native-Remote-Update-master File: ReactProgressBarViewManager.java View source code |
/* package */
static int getStyleFromString(@Nullable String styleStr) {
if (styleStr == null) {
throw new JSApplicationIllegalArgumentException("ProgressBar needs to have a style, null received");
} else if (styleStr.equals("Horizontal")) {
return android.R.attr.progressBarStyleHorizontal;
} else if (styleStr.equals("Small")) {
return android.R.attr.progressBarStyleSmall;
} else if (styleStr.equals("Large")) {
return android.R.attr.progressBarStyleLarge;
} else if (styleStr.equals("Inverse")) {
return android.R.attr.progressBarStyleInverse;
} else if (styleStr.equals("SmallInverse")) {
return android.R.attr.progressBarStyleSmallInverse;
} else if (styleStr.equals("LargeInverse")) {
return android.R.attr.progressBarStyleLargeInverse;
} else {
throw new JSApplicationIllegalArgumentException("Unknown ProgressBar style: " + styleStr);
}
}Example 38
| Project: Android-Bootstrap-master File: BootstrapDrawableFactory.java View source code |
/**
* Generates a Drawable for a Bootstrap Edit Text background
*
* @param context the current context
* @param bootstrapBrand the BootstrapBrand theming whose colors should be used
* @param rounded whether the corners should be rounded or not
* @return the Bootstrap Edit Text background
*/
static Drawable bootstrapEditText(Context context, BootstrapBrand bootstrapBrand, float strokeWidth, float cornerRadius, boolean rounded) {
StateListDrawable drawable = new StateListDrawable();
GradientDrawable activeDrawable = new GradientDrawable();
GradientDrawable disabledDrawable = new GradientDrawable();
GradientDrawable defaultDrawable = new GradientDrawable();
activeDrawable.setColor(ColorUtils.resolveColor(android.R.color.white, context));
disabledDrawable.setColor(ColorUtils.resolveColor(android.R.color.white, context));
defaultDrawable.setColor(ColorUtils.resolveColor(android.R.color.white, context));
if (rounded) {
activeDrawable.setCornerRadius(cornerRadius);
disabledDrawable.setCornerRadius(cornerRadius);
defaultDrawable.setCornerRadius(cornerRadius);
}
// stroke is larger when focused
int defaultBorder = ColorUtils.resolveColor(R.color.bootstrap_brand_secondary_border, context);
int disabledBorder = ColorUtils.resolveColor(R.color.bootstrap_edittext_disabled, context);
activeDrawable.setStroke((int) strokeWidth, bootstrapBrand.defaultEdge(context));
disabledDrawable.setStroke((int) strokeWidth, disabledBorder);
defaultDrawable.setStroke((int) strokeWidth, defaultBorder);
drawable.addState(new int[] { android.R.attr.state_focused }, activeDrawable);
drawable.addState(new int[] { -android.R.attr.state_enabled }, disabledDrawable);
drawable.addState(new int[] {}, defaultDrawable);
return drawable;
}Example 39
| Project: qksms-master File: QKSwitch.java View source code |
private ColorStateList getSwitchThumbColorStateList() {
final int[][] states = new int[3][];
final int[] colors = new int[3];
// Disabled state
states[0] = new int[] { -android.R.attr.state_enabled };
colors[0] = mRes.getColor(ThemeManager.isNightMode() ? R.color.switch_thumb_disabled_dark : R.color.switch_thumb_disabled_light);
// Checked state
states[1] = new int[] { android.R.attr.state_checked };
colors[1] = ThemeManager.getColor();
// Unchecked enabled state state
states[2] = new int[0];
colors[2] = mRes.getColor(ThemeManager.isNightMode() ? R.color.switch_thumb_enabled_dark : R.color.switch_thumb_enabled_light);
return new ColorStateList(states, colors);
}Example 40
| Project: NyaungUConverter-master File: FlatButton.java View source code |
private void init(AttributeSet attrs) {
// saving padding values for using them after setting background drawable
final int paddingTop = getPaddingTop();
final int paddingRight = getPaddingRight();
final int paddingLeft = getPaddingLeft();
final int paddingBottom = getPaddingBottom();
if (attributes == null)
attributes = new Attributes(this, getResources());
if (attrs != null) {
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.fl_FlatButton);
// getting common attributes
int customTheme = a.getResourceId(R.styleable.fl_FlatButton_fl_theme, Attributes.DEFAULT_THEME);
attributes.setThemeSilent(customTheme, getResources());
attributes.setTouchEffect(a.getInt(R.styleable.fl_FlatButton_fl_touchEffect, Attributes.DEFAULT_TOUCH_EFFECT));
attributes.setFontFamily(a.getString(R.styleable.fl_FlatButton_fl_fontFamily));
attributes.setFontWeight(a.getString(R.styleable.fl_FlatButton_fl_fontWeight));
attributes.setFontExtension(a.getString(R.styleable.fl_FlatButton_fl_fontExtension));
attributes.setTextAppearance(a.getInt(R.styleable.fl_FlatButton_fl_textAppearance, Attributes.DEFAULT_TEXT_APPEARANCE));
attributes.setRadius(a.getDimensionPixelSize(R.styleable.fl_FlatButton_fl_cornerRadius, Attributes.DEFAULT_RADIUS_PX));
// getting view specific attributes
bottom = a.getDimensionPixelSize(R.styleable.fl_FlatButton_fl_blockButtonEffectHeight, bottom);
a.recycle();
}
if (attributes.hasTouchEffect()) {
boolean hasRippleEffect = attributes.getTouchEffect() == Attributes.RIPPLE_TOUCH_EFFECT;
touchEffectAnimator = new TouchEffectAnimator(this);
touchEffectAnimator.setHasRippleEffect(hasRippleEffect);
touchEffectAnimator.setEffectColor(attributes.getColor(1));
touchEffectAnimator.setClipRadius(attributes.getRadius());
}
/*mPaint = new Paint();
mPaint.setColor(attributes.getColor(1));
mPaint.setAlpha(mAlpha);*/
// creating normal state drawable
ShapeDrawable normalFront = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
normalFront.getPaint().setColor(attributes.getColor(2));
ShapeDrawable normalBack = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
normalBack.getPaint().setColor(attributes.getColor(1));
normalBack.setPadding(0, 0, 0, bottom);
Drawable[] d = { normalBack, normalFront };
LayerDrawable normal = new LayerDrawable(d);
// creating pressed state drawable
ShapeDrawable pressedFront = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
pressedFront.getPaint().setColor(attributes.getColor(1));
ShapeDrawable pressedBack = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
pressedBack.getPaint().setColor(attributes.getColor(0));
if (bottom != 0)
pressedBack.setPadding(0, 0, 0, bottom / 2);
Drawable[] d2 = { pressedBack, pressedFront };
LayerDrawable pressed = new LayerDrawable(d2);
// creating disabled state drawable
ShapeDrawable disabledFront = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
disabledFront.getPaint().setColor(attributes.getColor(3));
disabledFront.getPaint().setAlpha(0xA0);
ShapeDrawable disabledBack = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
disabledBack.getPaint().setColor(attributes.getColor(2));
Drawable[] d3 = { disabledBack, disabledFront };
LayerDrawable disabled = new LayerDrawable(d3);
StateListDrawable states = new StateListDrawable();
if (!attributes.hasTouchEffect())
states.addState(new int[] { android.R.attr.state_pressed, android.R.attr.state_enabled }, pressed);
states.addState(new int[] { android.R.attr.state_focused, android.R.attr.state_enabled }, pressed);
states.addState(new int[] { android.R.attr.state_enabled }, normal);
states.addState(new int[] { -android.R.attr.state_enabled }, disabled);
setBackgroundDrawable(states);
setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
if (attributes.getTextAppearance() == 1)
setTextColor(attributes.getColor(0));
else if (attributes.getTextAppearance() == 2)
setTextColor(attributes.getColor(3));
else
setTextColor(Color.WHITE);
// check for IDE preview render
if (!this.isInEditMode()) {
Typeface typeface = FlatUI.getFont(getContext(), attributes);
if (typeface != null)
setTypeface(typeface);
}
}Example 41
| Project: MaterialDrawer-master File: BadgeDrawableBuilder.java View source code |
public StateListDrawable build(Context ctx) {
StateListDrawable stateListDrawable = new StateListDrawable();
GradientDrawable normal = (GradientDrawable) AppCompatResources.getDrawable(ctx, mStyle.getGradientDrawable());
GradientDrawable selected = (GradientDrawable) normal.getConstantState().newDrawable().mutate();
ColorHolder.applyToOrTransparent(mStyle.getColor(), ctx, normal);
if (mStyle.getColorPressed() == null) {
ColorHolder.applyToOrTransparent(mStyle.getColor(), ctx, selected);
} else {
ColorHolder.applyToOrTransparent(mStyle.getColorPressed(), ctx, selected);
}
if (mStyle.getCorners() != null) {
normal.setCornerRadius(mStyle.getCorners().asPixel(ctx));
selected.setCornerRadius(mStyle.getCorners().asPixel(ctx));
}
stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, selected);
stateListDrawable.addState(StateSet.WILD_CARD, normal);
return stateListDrawable;
}Example 42
| Project: wire-android-master File: CursorIconButton.java View source code |
private void setBackgroundColor(int defaultColor, int pressedColor) {
if (ThemeUtils.isDarkTheme(getContext())) {
alphaPressed = PRESSED_ALPHA__DARK;
} else {
alphaPressed = PRESSED_ALPHA__LIGHT;
}
float avg = (Color.red(pressedColor) + Color.blue(pressedColor) + Color.green(pressedColor)) / (3 * 255.0f);
if (avg > TRESHOLD) {
float darken = 1.0f - DARKEN_FACTOR;
pressedColor = Color.rgb((int) (Color.red(pressedColor) * darken), (int) (Color.green(pressedColor) * darken), (int) (Color.blue(pressedColor) * darken));
}
int pressed = ColorUtils.injectAlpha(alphaPressed, pressedColor);
GradientDrawable pressedBgColor = new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, new int[] { pressed, pressed });
pressedBgColor.setShape(GradientDrawable.OVAL);
GradientDrawable defaultBgColor = new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, new int[] { defaultColor, defaultColor });
defaultBgColor.setShape(GradientDrawable.OVAL);
StateListDrawable states = new StateListDrawable();
states.addState(new int[] { android.R.attr.state_pressed }, pressedBgColor);
states.addState(new int[] { android.R.attr.state_focused }, pressedBgColor);
states.addState(new int[] { -android.R.attr.state_enabled }, pressedBgColor);
states.addState(new int[] {}, defaultBgColor);
setBackground(states);
invalidate();
}Example 43
| Project: hkm-progress-button-master File: SAutoBgButtonBackgroundDrawable.java View source code |
@Override
protected boolean onStateChange(int[] states) {
boolean enabled = false;
boolean pressed = false;
for (int state : states) {
if (state == android.R.attr.state_enabled)
enabled = true;
else if (state == android.R.attr.state_pressed)
pressed = true;
}
mutate();
if (enabled && pressed) {
setColorFilter(_pressedFilter);
} else if (!enabled) {
setColorFilter(null);
setAlpha(_disabledAlpha);
} else {
setColorFilter(null);
}
invalidateSelf();
return super.onStateChange(states);
}Example 44
| Project: Genius-Android-master File: CheckStateDrawable.java View source code |
@Override
public boolean setState(int[] stateSet) {
if (stateSet == null)
return false;
// Call super
boolean status = super.setState(stateSet);
boolean oldChecked = mChecked;
boolean oldEnabled = mEnabled;
mChecked = false;
mEnabled = true;
for (int i : stateSet) {
if (i == android.R.attr.state_checked) {
mChecked = true;
} else if (i == -android.R.attr.state_enabled) {
mEnabled = false;
}
}
if (status || oldChecked != mChecked || oldEnabled != mEnabled) {
//We've changed states
onStateChange(getColor(), oldChecked, mChecked);
invalidateSelf();
}
return status;
}Example 45
| Project: material-calendarview-master File: DirectionButton.java View source code |
private static int getThemeSelectableBackgroundId(Context context) {
//Get selectableItemBackgroundBorderless defined for AppCompat
int colorAttr = context.getResources().getIdentifier("selectableItemBackgroundBorderless", "attr", context.getPackageName());
if (colorAttr == 0) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
colorAttr = android.R.attr.selectableItemBackgroundBorderless;
} else {
colorAttr = android.R.attr.selectableItemBackground;
}
}
TypedValue outValue = new TypedValue();
context.getTheme().resolveAttribute(colorAttr, outValue, true);
return outValue.resourceId;
}Example 46
| Project: astrid-master File: CustomBorderDrawable.java View source code |
public static StateListDrawable customButton(int tl, int tr, int br, int bl, int onColor, int offColor, int borderColor, int strokeWidth) {
Shape shape = new RoundRectShape(new float[] { tl, tl, tr, tr, br, br, bl, bl }, null, null);
ShapeDrawable sdOn = new CustomBorderDrawable(shape, onColor, borderColor, strokeWidth);
ShapeDrawable sdOff = new CustomBorderDrawable(shape, offColor, borderColor, strokeWidth);
StateListDrawable stld = new StateListDrawable();
stld.addState(new int[] { android.R.attr.state_pressed }, sdOn);
stld.addState(new int[] { android.R.attr.state_checked }, sdOn);
stld.addState(new int[] { android.R.attr.state_enabled }, sdOff);
return stld;
}Example 47
| Project: TelegramGallery-master File: Theme.java View source code |
public static Drawable createBarSelectorDrawable(int color, boolean masked) {
if (Build.VERSION.SDK_INT >= 21) {
Drawable maskDrawable = null;
if (masked) {
maskPaint.setColor(0xffffffff);
maskDrawable = new Drawable() {
@Override
public void draw(Canvas canvas) {
android.graphics.Rect bounds = getBounds();
canvas.drawCircle(bounds.centerX(), bounds.centerY(), AndroidUtilities.dp(18), maskPaint);
}
@Override
public void setAlpha(int alpha) {
}
@Override
public void setColorFilter(ColorFilter colorFilter) {
}
@Override
public int getOpacity() {
return 0;
}
};
}
ColorStateList colorStateList = new ColorStateList(new int[][] { new int[] {} }, new int[] { color });
return new RippleDrawable(colorStateList, null, maskDrawable);
} else {
StateListDrawable stateListDrawable = new StateListDrawable();
stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, new ColorDrawable(color));
stateListDrawable.addState(new int[] { android.R.attr.state_focused }, new ColorDrawable(color));
stateListDrawable.addState(new int[] { android.R.attr.state_selected }, new ColorDrawable(color));
stateListDrawable.addState(new int[] { android.R.attr.state_activated }, new ColorDrawable(color));
stateListDrawable.addState(new int[] {}, new ColorDrawable(0x00000000));
return stateListDrawable;
}
}Example 48
| Project: enjoymovie-master File: TabBarButton.java View source code |
private void setStateImageDrawables(Drawable onDrawable, Drawable offDrawable) {
StateListDrawable drawables = new StateListDrawable();
int stateChecked = android.R.attr.state_checked;
int stateFocused = android.R.attr.state_focused;
int statePressed = android.R.attr.state_pressed;
int stateWindowFocused = android.R.attr.state_window_focused;
Resources resource = this.getResources();
Drawable xDrawable = resource.getDrawable(R.drawable.bottom_bar_highlight);
drawables.addState(new int[] { stateChecked, -stateWindowFocused }, offDrawable);
drawables.addState(new int[] { -stateChecked, -stateWindowFocused }, offDrawable);
drawables.addState(new int[] { stateChecked, statePressed }, onDrawable);
drawables.addState(new int[] { -stateChecked, statePressed }, onDrawable);
drawables.addState(new int[] { stateChecked, stateFocused }, onDrawable);
drawables.addState(new int[] { -stateChecked, stateFocused }, offDrawable);
drawables.addState(new int[] { stateChecked }, onDrawable);
drawables.addState(new int[] { -stateChecked }, offDrawable);
drawables.addState(new int[] {}, xDrawable);
this.setButtonDrawable(drawables);
}Example 49
| Project: androGister-master File: ProductUiHelper.java View source code |
public Drawable getStateGradientDrawable(int color) {
StateListDrawable state = new StateListDrawable();
// int darkerColor = getColorDarker(color);
// Drawable selected =
// context.getResources().getDrawable(android.R.drawable.a);
Drawable normal = getCacheBackgroundGradientColor(color);
Drawable selected = getCacheBackgroundGradientColor(getColorDarker(color));
// State
state.addState(new int[] { android.R.attr.state_pressed }, selected);
state.addState(new int[] { android.R.attr.state_checked }, selected);
state.addState(new int[] { android.R.attr.state_activated }, selected);
state.addState(StateSet.NOTHING, normal);
return state;
}Example 50
| Project: FastHub-master File: ViewHelper.java View source code |
@NonNull
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[] { android.R.attr.state_selected }, new ColorDrawable(pressedColor));
states.addState(new int[] {}, new ColorDrawable(normalColor));
return states;
}Example 51
| Project: aesthetic-master File: ViewUtil.java View source code |
@Nullable
static Observable<Integer> getObservableForResId(@NonNull Context context, @IdRes int resId, @Nullable Observable<Integer> fallback) {
if (resId == 0) {
return fallback;
} else if (resId == resolveResId(context, R.attr.colorPrimary, 0)) {
return Aesthetic.get().colorPrimary();
} else if (resId == resolveResId(context, R.attr.colorPrimaryDark, 0)) {
return Aesthetic.get().colorStatusBar();
} else if (resId == resolveResId(context, R.attr.colorAccent, 0)) {
return Aesthetic.get().colorAccent();
} else if (resId == resolveResId(context, android.R.attr.windowBackground, 0)) {
return Aesthetic.get().colorWindowBackground();
} else if (resId == resolveResId(context, android.R.attr.textColorPrimary, 0)) {
return Aesthetic.get().textColorPrimary();
} else if (resId == resolveResId(context, android.R.attr.textColorPrimaryInverse, 0)) {
return Aesthetic.get().textColorPrimaryInverse();
} else if (resId == resolveResId(context, android.R.attr.textColorSecondary, 0)) {
return Aesthetic.get().textColorSecondary();
} else if (resId == resolveResId(context, android.R.attr.textColorSecondaryInverse, 0)) {
return Aesthetic.get().textColorSecondaryInverse();
}
return fallback;
}Example 52
| Project: android-periodic-table-master File: ExpandableIndicatorView.java View source code |
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void initExpandableIndicatorView(Context context) {
Resources.Theme theme = context.getTheme();
TypedValue typedValue = new TypedValue();
theme.resolveAttribute(android.R.attr.expandableListViewStyle, typedValue, true);
TypedArray typedArray = theme.obtainStyledAttributes(typedValue.resourceId, new int[] { android.R.attr.groupIndicator, R.attr.colorControlHighlight });
mGroupIndicator = (StateListDrawable) typedArray.getDrawable(0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
final int tintColor = typedArray.getColor(1, 0);
if (tintColor != 0) {
mGroupIndicator.setTint(tintColor);
}
}
typedArray.recycle();
setStateExpanded(false);
}Example 53
| Project: container-master File: FinishActivity.java View source code |
@Override
public Object afterCall(Object who, Method method, Object[] args, Object result) throws Throwable {
IBinder token = (IBinder) args[0];
ActivityClientRecord r = VActivityManager.get().getActivityRecord(token);
boolean taskRemoved = VActivityManager.get().onActivityDestroy(token);
if (!taskRemoved && r != null && r.activity != null && r.info.getThemeResource() != 0) {
try {
TypedValue out = new TypedValue();
Resources.Theme theme = r.activity.getResources().newTheme();
theme.applyStyle(r.info.getThemeResource(), true);
if (theme.resolveAttribute(android.R.attr.windowAnimationStyle, out, true)) {
TypedArray array = theme.obtainStyledAttributes(out.data, new int[] { android.R.attr.activityCloseEnterAnimation, android.R.attr.activityCloseExitAnimation });
r.activity.overridePendingTransition(array.getResourceId(0, 0), array.getResourceId(1, 0));
array.recycle();
}
} catch (Throwable e) {
e.printStackTrace();
}
}
return super.afterCall(who, method, args, result);
}Example 54
| Project: droid-bootstrap-master File: MaterialEditText.java View source code |
public MaterialEditText setBackgroundColor(final int normal, final int focused) {
final Resources resources = getResources();
final Drawable normalDrawable = new TintedNinePatchDrawable(resources, R.drawable.input_line, normal);
final Drawable focusedDrawable = new TintedNinePatchDrawable(resources, R.drawable.input_line_focused, focused);
final StateListDrawable bgDrawable = new StateListDrawable();
bgDrawable.addState(new int[] { android.R.attr.state_focused }, focusedDrawable);
bgDrawable.addState(new int[] { android.R.attr.state_enabled }, normalDrawable);
setBackgroundDrawable(bgDrawable);
return this;
}Example 55
| Project: SublimePicker-master File: SUtils.java View source code |
public static void initializeResources(Context context) {
TypedArray a = context.obtainStyledAttributes(new int[] { R.attr.colorAccent, R.attr.colorControlHighlight, R.attr.colorControlActivated, R.attr.colorButtonNormal, android.R.attr.textColorPrimary, android.R.attr.textColorPrimaryInverse, R.attr.colorPrimary, R.attr.colorPrimaryDark, android.R.attr.textColorSecondary, android.R.attr.colorBackground, android.R.attr.textColorSecondaryInverse });
if (a.hasValue(0))
COLOR_ACCENT = a.getColor(0, Color.TRANSPARENT);
if (a.hasValue(1))
COLOR_CONTROL_HIGHLIGHT = a.getColor(1, Color.TRANSPARENT);
if (a.hasValue(2))
COLOR_CONTROL_ACTIVATED = a.getColor(2, Color.TRANSPARENT);
if (a.hasValue(3))
COLOR_BUTTON_NORMAL = a.getColor(3, Color.TRANSPARENT);
if (a.hasValue(4))
COLOR_TEXT_PRIMARY = a.getColor(4, Color.TRANSPARENT);
if (a.hasValue(5))
COLOR_TEXT_PRIMARY_INVERSE = a.getColor(5, Color.TRANSPARENT);
if (a.hasValue(6))
COLOR_PRIMARY = a.getColor(6, Color.TRANSPARENT);
if (a.hasValue(7))
COLOR_PRIMARY_DARK = a.getColor(7, Color.TRANSPARENT);
if (a.hasValue(8))
COLOR_TEXT_SECONDARY = a.getColor(8, Color.TRANSPARENT);
if (a.hasValue(9))
COLOR_BACKGROUND = a.getColor(9, Color.TRANSPARENT);
if (a.hasValue(10))
COLOR_TEXT_SECONDARY_INVERSE = a.getColor(10, Color.TRANSPARENT);
a.recycle();
CORNER_RADIUS = context.getResources().getDimensionPixelSize(R.dimen.control_corner_material);
if (Config.DEBUG) {
Log.i(TAG, "COLOR_ACCENT: " + Integer.toHexString(COLOR_ACCENT));
Log.i(TAG, "COLOR_CONTROL_HIGHLIGHT: " + Integer.toHexString(COLOR_CONTROL_HIGHLIGHT));
Log.i(TAG, "COLOR_CONTROL_ACTIVATED: " + Integer.toHexString(COLOR_CONTROL_ACTIVATED));
Log.i(TAG, "COLOR_BUTTON_NORMAL: " + Integer.toHexString(COLOR_BUTTON_NORMAL));
Log.i(TAG, "COLOR_TEXT_PRIMARY: " + Integer.toHexString(COLOR_TEXT_PRIMARY));
Log.i(TAG, "COLOR_TEXT_PRIMARY_INVERSE: " + Integer.toHexString(COLOR_TEXT_PRIMARY_INVERSE));
Log.i(TAG, "COLOR_PRIMARY: " + Integer.toHexString(COLOR_PRIMARY));
Log.i(TAG, "COLOR_PRIMARY_DARK: " + Integer.toHexString(COLOR_PRIMARY_DARK));
Log.i(TAG, "COLOR_TEXT_SECONDARY: " + Integer.toHexString(COLOR_TEXT_SECONDARY));
Log.i(TAG, "COLOR_BACKGROUND: " + Integer.toHexString(COLOR_BACKGROUND));
Log.i(TAG, "COLOR_TEXT_SECONDARY_INVERSE: " + Integer.toHexString(COLOR_TEXT_SECONDARY_INVERSE));
}
}Example 56
| Project: RTL-Toolbar-Android-AppCompat-master File: TintManager.java View source code |
void tintDrawable(final int resId, final Drawable drawable) {
PorterDuff.Mode tintMode = null;
boolean colorAttrSet = false;
int colorAttr = 0;
int alpha = -1;
if (arrayContains(TINT_COLOR_CONTROL_NORMAL, resId)) {
colorAttr = R.attr.colorControlNormal;
colorAttrSet = true;
} else if (arrayContains(TINT_COLOR_CONTROL_ACTIVATED, resId)) {
colorAttr = R.attr.colorControlActivated;
colorAttrSet = true;
} else if (arrayContains(TINT_COLOR_BACKGROUND_MULTIPLY, resId)) {
colorAttr = android.R.attr.colorBackground;
colorAttrSet = true;
tintMode = PorterDuff.Mode.MULTIPLY;
} else if (resId == R.drawable.abc_list_divider_mtrl_alpha) {
colorAttr = android.R.attr.colorForeground;
colorAttrSet = true;
alpha = Math.round(0.16f * 255);
}
if (colorAttrSet) {
if (tintMode == null) {
tintMode = DEFAULT_MODE;
}
final int color = getThemeAttrColor(mContext, colorAttr);
tintDrawableUsingColorFilter(drawable, color, tintMode);
if (alpha != -1) {
drawable.setAlpha(alpha);
}
if (DEBUG) {
Log.d(TAG, "Tinted Drawable ID: " + mResources.getResourceName(resId) + " with color: #" + Integer.toHexString(color));
}
}
}Example 57
| Project: frameworks_base_disabled-master File: TargetDrawable.java View source code |
/**
* Returns true if the drawable is a StateListDrawable and is in the focused state.
*
* @return
*/
public boolean isActive() {
if (mDrawable instanceof StateListDrawable) {
StateListDrawable d = (StateListDrawable) mDrawable;
int[] states = d.getState();
for (int i = 0; i < states.length; i++) {
if (states[i] == android.R.attr.state_focused) {
return true;
}
}
}
return false;
}Example 58
| Project: OttoFit-master File: RippleView.java View source code |
public void init() {
mPaint = new Paint();
mPaint.setAlpha(100);
setRippleColor(Color.BLACK, 0.2f);
ShapeDrawable normal = new ShapeDrawable(new RectShape());
normal.getPaint().setColor(Color.parseColor("#00FFFFFF"));
StateListDrawable states = new StateListDrawable();
states.addState(new int[] { android.R.attr.state_pressed, android.R.attr.state_enabled }, normal);
states.addState(new int[] { android.R.attr.state_focused, android.R.attr.state_enabled }, normal);
states.addState(new int[] { android.R.attr.state_enabled }, normal);
states.addState(new int[] { -android.R.attr.state_enabled }, normal);
setBackgroundDrawable(states);
}Example 59
| Project: JD-Test-master File: BottomNavigationTab.java View source code |
public void initialise(boolean setActiveColor) {
iconView.setSelected(false);
if (isInActiveIconSet) {
StateListDrawable states = new StateListDrawable();
states.addState(new int[] { android.R.attr.state_selected }, mCompactIcon);
states.addState(new int[] { -android.R.attr.state_selected }, mCompactInActiveIcon);
states.addState(new int[] {}, mCompactInActiveIcon);
iconView.setImageDrawable(states);
} else {
if (setActiveColor) {
DrawableCompat.setTintList(mCompactIcon, new ColorStateList(new int[][] { //1
new int[] { android.R.attr.state_selected }, //2
new int[] { -android.R.attr.state_selected }, new int[] {} }, new int[] { //1
mActiveColor, //2
mInActiveColor, //3
mInActiveColor }));
} else {
DrawableCompat.setTintList(mCompactIcon, new ColorStateList(new int[][] { //1
new int[] { android.R.attr.state_selected }, //2
new int[] { -android.R.attr.state_selected }, new int[] {} }, new int[] { //1
mBackgroundColor, //2
mInActiveColor, //3
mInActiveColor }));
}
iconView.setImageDrawable(mCompactIcon);
}
}Example 60
| Project: AisenForAndroid-master File: MDButton.java View source code |
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
final Drawable d = MDHelper.resolveDrawable(context, R.attr.MDbuttonSelector);
setDefaultSelector(d);
int themeColor = MDHelper.resolveColor(context, R.attr.colorPrimary);
final ColorStateList colorStateList = getMDTextStateList(context, themeColor);
setTextColor(colorStateList);
}Example 61
| Project: platform_frameworks_support-master File: ViewUtilsLollipop.java View source code |
/**
* Creates and sets a {@link StateListAnimator} with a custom elevation value
*/
static void setDefaultAppBarLayoutStateListAnimator(final View view, final float elevation) {
final int dur = view.getResources().getInteger(R.integer.app_bar_elevation_anim_duration);
final StateListAnimator sla = new StateListAnimator();
// Enabled and collapsible, but not collapsed means not elevated
sla.addState(new int[] { android.R.attr.enabled, R.attr.state_collapsible, -R.attr.state_collapsed }, ObjectAnimator.ofFloat(view, "elevation", 0f).setDuration(dur));
// Default enabled state
sla.addState(new int[] { android.R.attr.enabled }, ObjectAnimator.ofFloat(view, "elevation", elevation).setDuration(dur));
// Disabled state
sla.addState(new int[0], ObjectAnimator.ofFloat(view, "elevation", 0).setDuration(0));
view.setStateListAnimator(sla);
}Example 62
| Project: cnBetaReader-master File: UIKit.java View source code |
/** 对TextView设置不同状态时其文字颜色。 */
public static ColorStateList createColorStateList(int normal, int actived, boolean passed) {
if (!passed) {
return createColorStateList(normal, actived);
}
int[] colors = new int[] { actived, actived, normal };
int[][] states = new int[3][];
states[0] = new int[] { android.R.attr.state_pressed };
states[1] = new int[] { android.R.attr.state_focused };
states[2] = new int[] {};
return new ColorStateList(states, colors);
}Example 63
| Project: FriendCircle-master File: ForceClickImageView.java View source code |
/**
* 初始化
*/
private void init(Context context, AttributeSet attrs, boolean needDefaultForceGroundColor) {
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ForceClickImageView);
mForegroundDrawable = a.getDrawable(R.styleable.ForceClickImageView_foregroundColor);
if (mForegroundDrawable instanceof ColorDrawable || (attrs == null && needDefaultForceGroundColor)) {
int foreGroundColor = a.getColor(R.styleable.ForceClickImageView_foregroundColor, 0x882b2b2b);
mForegroundDrawable = new StateListDrawable();
ColorDrawable forceDrawable = new ColorDrawable(foreGroundColor);
ColorDrawable normalDrawable = new ColorDrawable(Color.TRANSPARENT);
((StateListDrawable) mForegroundDrawable).addState(new int[] { android.R.attr.state_pressed }, forceDrawable);
((StateListDrawable) mForegroundDrawable).addState(new int[] { android.R.attr.state_focused }, forceDrawable);
((StateListDrawable) mForegroundDrawable).addState(new int[] { android.R.attr.state_enabled }, normalDrawable);
((StateListDrawable) mForegroundDrawable).addState(new int[] {}, normalDrawable);
}
if (mForegroundDrawable != null) {
mForegroundDrawable.setCallback(this);
}
a.recycle();
}Example 64
| Project: MaterialAbout-master File: RippleUtil.java View source code |
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));
states.addState(StateSet.WILD_CARD, new ColorDrawable(normalColor));
return states;
}Example 65
| Project: MarkdownEditors-master File: BaseDrawerLayoutActivity.java View source code |
private void initDrawer() {
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, mDrawerLayout, getToolbar(), R.string.navigation_drawer_open, R.string.navigation_drawer_close);
mDrawerLayout.setDrawerListener(toggle);
toggle.syncState();
mNavigationView.setNavigationItemSelectedListener(this);
ColorStateList colorStateList = new ColorStateList(new int[][] { { android.R.attr.state_checked, android.R.attr.state_enabled }, { android.R.attr.state_enabled }, {} }, new int[] { BaseApplication.color(R.color.colorPrimary), BaseApplication.color(R.color.colorSecondaryText), 0xffDCDDDD });
//设置图标的颜色变化
mNavigationView.setItemIconTintList(colorStateList);
//设置item的颜色变化
mNavigationView.setItemTextColor(colorStateList);
if (getDefaultMenuItemId() > 0)
//设置默认选择
mNavigationView.setCheckedItem(getDefaultMenuItemId());
}Example 66
| Project: PhotoNoter-master File: ColorChooserDialog.java View source code |
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
View v = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_color_chooser, null);
AlertDialog dialog = new AlertDialog.Builder(getActivity(), R.style.note_dialog).setTitle(R.string.color_chooser).setCancelable(true).setView(v).create();
final TypedArray ta = getActivity().getResources().obtainTypedArray(R.array.colors);
mColors = new int[ta.length()];
for (int i = 0; i < ta.length(); i++) {
mColors[i] = ta.getColor(i, 0);
}
ta.recycle();
final GridLayout list = (GridLayout) v.findViewById(R.id.grid);
final int preselect = getArguments().getInt("preselect", -1);
for (int i = 0; i < mColors.length; i++) {
FrameLayout child = (FrameLayout) list.getChildAt(i);
child.setTag(i);
child.setOnClickListener(this);
child.getChildAt(0).setVisibility(preselect == i ? View.VISIBLE : View.GONE);
Drawable selector = createSelector(mColors[i]);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
int[][] states = new int[][] { new int[] { -android.R.attr.state_pressed }, new int[] { android.R.attr.state_pressed } };
int[] colors = new int[] { shiftColor(mColors[i]), mColors[i] };
ColorStateList rippleColors = new ColorStateList(states, colors);
setBackgroundCompat(child, new RippleDrawable(rippleColors, selector, null));
} else {
setBackgroundCompat(child, selector);
}
}
return dialog;
}Example 67
| Project: Android-skin-support-master File: SkinMaterialNavigationView.java View source code |
private void applyItemTextColorResource() {
mTextColorResId = SkinCompatHelper.checkResourceId(mTextColorResId);
if (mTextColorResId != INVALID_ID) {
setItemTextColor(SkinCompatResources.getInstance().getColorStateList(mTextColorResId));
} else {
mDefaultTintResId = SkinCompatHelper.checkResourceId(mDefaultTintResId);
if (mDefaultTintResId != INVALID_ID) {
setItemTextColor(createDefaultColorStateList(android.R.attr.textColorPrimary));
}
}
}Example 68
| Project: actor-platform-master File: ComposeFabFragment.java View source code |
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View res = inflater.inflate(R.layout.fragment_fab, container, false);
FloatingActionButton fabRoot = (FloatingActionButton) res.findViewById(R.id.fab);
fabRoot.setImageResource(R.drawable.ic_edit_white_24dp);
fabRoot.setBackgroundTintList(new ColorStateList(new int[][] { new int[] { android.R.attr.state_pressed }, StateSet.WILD_CARD }, new int[] { ActorSDK.sharedActor().style.getFabPressedColor(), ActorSDK.sharedActor().style.getFabColor() }));
fabRoot.setRippleColor(ActorSDK.sharedActor().style.getFabPressedColor());
fabRoot.setOnClickListener( v -> startActivity(new Intent(getActivity(), ComposeActivity.class)));
return res;
}Example 69
| Project: materialistic-master File: ReleaseNotesActivity.java View source code |
@SuppressWarnings("ConstantConditions")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_release);
findViewById(R.id.button_ok).setOnClickListener( v -> finish());
findViewById(R.id.button_rate).setOnClickListener( v -> {
AppUtils.openPlayStore(this);
finish();
});
WebView webView = (WebView) findViewById(R.id.web_view);
webView.setWebViewClient(new WebViewClient());
webView.setWebChromeClient(new WebChromeClient());
webView.setBackgroundColor(Color.TRANSPARENT);
webView.loadDataWithBaseURL(null, getString(R.string.release_notes, AppUtils.toHtmlColor(this, android.R.attr.textColorPrimary), AppUtils.toHtmlColor(this, android.R.attr.textColorLink)), "text/html", "UTF-8", null);
Preferences.setReleaseNotesSeen(this);
}Example 70
| Project: adp-delightful-details-master File: TrimClipActivity.java View source code |
@OnClick(R.id.rootview)
void onClick() {
isChecked = !isChecked;
final int[] stateSet = { android.R.attr.state_checked * (isChecked ? 1 : -1) };
airplaneView.setImageState(stateSet, true);
eyeView.setImageState(stateSet, true);
flashlightView.setImageState(stateSet, true);
searchbackView.setImageState(stateSet, true);
heartView.setImageState(stateSet, true);
}Example 71
| Project: vograbulary-master File: AndroidLetterDisplayFactory.java View source code |
@Override
public LetterDisplay create(String letter) {
TextView textView = new TextView(layout.getContext());
textView.setText(letter);
textView.setTextAppearance(layout.getContext(), android.R.attr.textAppearanceLarge);
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 45);
textView.setTypeface(Typeface.MONOSPACE);
layout.addView(textView);
final AndroidLetterDisplay display = new AndroidLetterDisplay(textView);
textView.setClickable(true);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
display.click();
}
});
return display;
}Example 72
| Project: budget-envelopes-master File: EnvelopesAdapter.java View source code |
public static Drawable getColorStateDrawable(int color) {
StateListDrawable retVal = new StateListDrawable();
Drawable normal = new ColorDrawable(color);
Drawable superS = new ColorDrawable(0xFF99CC00);
Drawable select = new ColorDrawable(0x8899CC00);
retVal.addState(new int[] { android.R.attr.state_pressed }, select);
retVal.addState(new int[] { android.R.attr.state_focused }, select);
retVal.addState(new int[] { android.R.attr.state_checked }, superS);
retVal.addState(new int[] { android.R.attr.state_selected }, select);
retVal.addState(new int[0], normal);
return retVal;
}Example 73
| Project: bonfire-firebase-sample-master File: AutofitRecyclerView.java View source code |
private void init(Context context, AttributeSet attrs) {
if (attrs != null) {
int[] attrsArray = { android.R.attr.columnWidth };
TypedArray array = context.obtainStyledAttributes(attrs, attrsArray);
columnWidth = array.getDimensionPixelSize(0, -1);
array.recycle();
}
manager = new GridLayoutManager(context, 1);
setLayoutManager(manager);
}Example 74
| Project: otm-android-master File: SegmentedButton.java View source code |
private List<int[]> buildOnStates() {
List<int[]> res = new ArrayList<>();
res.add(new int[] { android.R.attr.state_focused, android.R.attr.state_enabled });
res.add(new int[] { android.R.attr.state_focused, android.R.attr.state_selected, android.R.attr.state_enabled });
res.add(new int[] { android.R.attr.state_pressed });
return res;
}Example 75
| Project: Qinder-master File: ImageViewLoader.java View source code |
private void initView(Context context, AttributeSet attrs, int defStyle) {
RelativeLayout mBloc = new RelativeLayout(context, attrs, defStyle);
mImage = new ImageView(context);
mProgressbar = new ProgressBar(context);
int sizePx = (int) (SIDE_PIXEL * this.getContext().getResources().getDisplayMetrics().density);
int marginPx = (int) (MARGIN_PIXEL * this.getContext().getResources().getDisplayMetrics().density);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(sizePx, sizePx);
lp.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
lp.setMargins(marginPx, marginPx, marginPx, marginPx);
mProgressbar.setLayoutParams(lp);
mProgressbar.setVisibility(View.INVISIBLE);
mImage.setAdjustViewBounds(true);
mBloc.addView(mImage);
mBloc.addView(mProgressbar);
if (attrs != null) {
int[] attrsArray = new int[] { android.R.attr.layout_width, android.R.attr.layout_height, android.R.attr.maxWidth, android.R.attr.maxHeight };
TypedArray ta = context.obtainStyledAttributes(attrs, attrsArray);
int width = getDimensionValue(ta, 0, -2);
int height = getDimensionValue(ta, 1, -2);
int maxWidth = getDimensionValue(ta, 2, -1);
int maxHeight = getDimensionValue(ta, 3, -1);
int scaleType = attrs.getAttributeIntValue("http://schemas.android.com/apk/res/android", "scaleType", -1);
mBloc.setLayoutParams(new RelativeLayout.LayoutParams(width, height));
mImage.setLayoutParams(new RelativeLayout.LayoutParams(width, height));
if (scaleType != -1) {
mImage.setScaleType(ImageView.ScaleType.values()[scaleType]);
}
if (maxWidth != -1) {
mImage.setMaxWidth(maxWidth);
}
if (maxHeight != -1) {
mImage.setMaxHeight(maxHeight);
}
ta.recycle();
}
addView(mBloc);
}Example 76
| Project: Calligraphy-master File: CalligraphyConfig.java View source code |
/**
* AppCompat will inflate special versions of views for Material tinting etc,
* this adds those classes to the style lookup map
*/
private static void addAppCompatViews() {
DEFAULT_STYLES.put(android.support.v7.widget.AppCompatTextView.class, android.R.attr.textViewStyle);
DEFAULT_STYLES.put(android.support.v7.widget.AppCompatButton.class, android.R.attr.buttonStyle);
DEFAULT_STYLES.put(android.support.v7.widget.AppCompatEditText.class, android.R.attr.editTextStyle);
DEFAULT_STYLES.put(android.support.v7.widget.AppCompatAutoCompleteTextView.class, android.R.attr.autoCompleteTextViewStyle);
DEFAULT_STYLES.put(android.support.v7.widget.AppCompatMultiAutoCompleteTextView.class, android.R.attr.autoCompleteTextViewStyle);
DEFAULT_STYLES.put(android.support.v7.widget.AppCompatCheckBox.class, android.R.attr.checkboxStyle);
DEFAULT_STYLES.put(android.support.v7.widget.AppCompatRadioButton.class, android.R.attr.radioButtonStyle);
DEFAULT_STYLES.put(android.support.v7.widget.AppCompatCheckedTextView.class, android.R.attr.checkedTextViewStyle);
}Example 77
| Project: android-about-page-master File: AboutPageUtils.java View source code |
static int getThemeAccentColor(Context context) {
int colorAttr;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
colorAttr = android.R.attr.colorAccent;
} else {
//Get colorAccent defined for AppCompat
colorAttr = context.getResources().getIdentifier("colorAccent", "attr", context.getPackageName());
}
TypedValue outValue = new TypedValue();
context.getTheme().resolveAttribute(colorAttr, outValue, true);
return outValue.data;
}Example 78
| Project: MaterialDesignColorPalette-master File: DrawerAdapter.java View source code |
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
convertView = mLayoutInflater.inflate(LAYOUT_RESOURCE, parent, false);
holder = new ViewHolder((TextView) convertView);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
final PaletteColorSection paletteColorSection = mColorList.get(position);
final String colorName = paletteColorSection.getColorSectionName();
holder.textView.setText(colorName);
final StateListDrawable sld = new StateListDrawable();
final Drawable d = new ColorDrawable(paletteColorSection.getColorSectionValue());
sld.addState(new int[] { android.R.attr.state_pressed }, d);
sld.addState(new int[] { android.R.attr.state_checked }, d);
holder.textView.setBackground(sld);
return convertView;
}Example 79
| Project: MVPAndroidBootstrap-master File: AutoBackgroundButton.java View source code |
@Override
protected boolean onStateChange(int[] states) {
boolean enabled = false;
boolean pressed = false;
for (int state : states) {
if (state == android.R.attr.state_enabled)
enabled = true;
else if (state == android.R.attr.state_pressed)
pressed = true;
}
mutate();
if (enabled && pressed) {
setColorFilter(_pressedFilter);
} else if (!enabled) {
setColorFilter(null);
setAlpha(_disabledAlpha);
} else {
setColorFilter(null);
setAlpha(_fullAlpha);
}
invalidateSelf();
return super.onStateChange(states);
}Example 80
| Project: LoopSeries-Mobile-master File: AutoFitRecyclerView.java View source code |
private void init(Context context, AttributeSet attrs) {
if (attrs != null) {
int[] attrsArray = { android.R.attr.columnWidth, android.R.attr.columnCount };
TypedArray array = context.obtainStyledAttributes(attrs, attrsArray);
columnWidth = array.getDimensionPixelSize(0, -1);
maxColumnCount = array.getInt(1, 999);
array.recycle();
}
manager = new GridLayoutManager(getContext(), 1);
setLayoutManager(manager);
this.gridLayoutManager = new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
if (position == 0) {
return mSpanCount;
}
return 1;
}
};
}Example 81
| Project: AlertDialogPro-master File: DialogTitle.java View source code |
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
final Layout layout = getLayout();
if (layout != null) {
final int lineCount = layout.getLineCount();
if (lineCount > 0) {
final int ellipsisCount = layout.getEllipsisCount(lineCount - 1);
if (ellipsisCount > 0) {
setSingleLine(false);
setMaxLines(2);
final TypedArray a = getContext().obtainStyledAttributes(null, TEXT_APPEARANCE_ATTRS, android.R.attr.textAppearanceMedium, android.R.style.TextAppearance_Medium);
final int textSize = a.getDimensionPixelSize(0, 0);
if (textSize != 0) {
// textSize is already expressed in pixels
setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
}
a.recycle();
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
}
}Example 82
| Project: FlycoRoundView-master File: RoundViewDelegate.java View source code |
public void setBgSelector() {
StateListDrawable bg = new StateListDrawable();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && isRippleEnable) {
setDrawable(gd_background, backgroundColor, strokeColor);
RippleDrawable rippleDrawable = new RippleDrawable(getPressedColorSelector(backgroundColor, backgroundPressColor), gd_background, null);
view.setBackground(rippleDrawable);
} else {
setDrawable(gd_background, backgroundColor, strokeColor);
bg.addState(new int[] { -android.R.attr.state_pressed }, gd_background);
if (backgroundPressColor != Integer.MAX_VALUE || strokePressColor != Integer.MAX_VALUE) {
setDrawable(gd_background_press, backgroundPressColor == Integer.MAX_VALUE ? backgroundColor : backgroundPressColor, strokePressColor == Integer.MAX_VALUE ? strokeColor : strokePressColor);
bg.addState(new int[] { android.R.attr.state_pressed }, gd_background_press);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
//16
view.setBackground(bg);
} else {
//noinspection deprecation
view.setBackgroundDrawable(bg);
}
}
if (view instanceof TextView) {
if (textPressColor != Integer.MAX_VALUE) {
ColorStateList textColors = ((TextView) view).getTextColors();
// Log.d("AAA", textColors.getColorForState(new int[]{-android.R.attr.state_pressed}, -1) + "");
ColorStateList colorStateList = new ColorStateList(new int[][] { new int[] { -android.R.attr.state_pressed }, new int[] { android.R.attr.state_pressed } }, new int[] { textColors.getDefaultColor(), textPressColor });
((TextView) view).setTextColor(colorStateList);
}
}
}Example 83
| Project: iShowUp-master File: SAutoBgButton.java View source code |
@Override
protected boolean onStateChange(int[] states) {
boolean enabled = false;
boolean pressed = false;
for (int state : states) {
if (state == android.R.attr.state_enabled)
enabled = true;
else if (state == android.R.attr.state_pressed)
pressed = true;
}
mutate();
if (enabled && pressed) {
setColorFilter(_pressedFilter);
} else if (!enabled) {
setColorFilter(null);
setAlpha(_disabledAlpha);
} else {
setColorFilter(null);
setAlpha(_fullAlpha);
}
invalidateSelf();
return super.onStateChange(states);
}Example 84
| Project: TwsPluginFramework-master File: CheckedTextView.java View source code |
public void twsSetCheckStyle(int checkStyle, Drawable d) {
if (checkStyle == STYLE_SYSTEM) {
mIsAnimationButton = false;
setCheckMarkDrawable(d);
return;
}
final boolean isSupportTintDrawable = ThemeUtils.isSupportTintDrawable(getContext());
int colorControlNormal = ThemeUtils.getThemeAttrColor(getContext(), R.attr.colorControlNormal);
int colorControlActivated = ThemeUtils.getThemeAttrColor(getContext(), R.attr.colorControlActivated);
int colorControlDisabled = ThemeUtils.getDisabledThemeAttrColor(getContext(), R.attr.colorControlNormal);
int colorControlActivateDisabled = ThemeUtils.getDisabledThemeAttrColor(getContext(), R.attr.colorControlActivated);
final PorterDuff.Mode DEFAULT_MODE = PorterDuff.Mode.SRC_IN;
if (colorControlNormal == 0) {
colorControlNormal = getContext().getResources().getColor(R.color.control_normal_color);
}
if (colorControlActivated == 0) {
colorControlActivated = getContext().getResources().getColor(R.color.control_activated_color);
}
if (colorControlDisabled == 0) {
colorControlDisabled = getContext().getResources().getColor(R.color.control_disabled_color);
}
if (colorControlActivateDisabled == 0) {
colorControlActivateDisabled = getContext().getResources().getColor(R.color.control_activate_disabled_color);
}
if (checkStyle == STYLE_SINGLE) {
mIsAnimationButton = true;
TwsAnimatedStateListDrawable drawable = new TwsAnimatedStateListDrawable();
Drawable radioOffDisableDrawable = getResources().getDrawable(radioOffDisableResId);
Drawable radioOnDisableDrawable = getResources().getDrawable(radioOnDisableResId);
Drawable radioOffDrawable = getResources().getDrawable(radioOffResId);
Drawable radioOnDrawable = getResources().getDrawable(radioOnResId);
if (isSupportTintDrawable) {
radioOffDisableDrawable.setColorFilter(colorControlDisabled, DEFAULT_MODE);
radioOnDisableDrawable.setColorFilter(colorControlActivateDisabled, DEFAULT_MODE);
radioOffDrawable.setColorFilter(colorControlNormal, DEFAULT_MODE);
radioOnDrawable.setColorFilter(colorControlActivated, DEFAULT_MODE);
}
drawable.addState(radioOffDisableState, radioOffDisableDrawable, 0);
drawable.addState(radioOnDisableState, radioOnDisableDrawable, 0);
drawable.addState(radioOffState, radioOffDrawable, radioOffKeyframeId);
drawable.addState(radioOnState, radioOnDrawable, radioOnkeyframeId);
AnimationDrawable toOnDrawable = (AnimationDrawable) getResources().getDrawable(radioToOnResId);
AnimationDrawable toOffDrawable = (AnimationDrawable) getResources().getDrawable(radioToOffResId);
if (isSupportTintDrawable) {
toOnDrawable.setColorFilter(colorControlActivated, DEFAULT_MODE);
toOffDrawable.setColorFilter(colorControlNormal, DEFAULT_MODE);
}
drawable.addTransition(radioOffKeyframeId, radioOnkeyframeId, toOnDrawable, false);
drawable.addTransition(radioOnkeyframeId, radioOffKeyframeId, toOffDrawable, false);
setCheckMarkDrawable(drawable);
mIsSupportTintDrawable = isSupportTintDrawable;
mColorControlActivated = colorControlActivated;
mAnimationButtonDrawable = drawable;
} else if (checkStyle == STYLE_MULTI) {
mIsAnimationButton = true;
TwsAnimatedStateListDrawable drawable = new TwsAnimatedStateListDrawable();
Drawable checkOffDisableDrawable = getResources().getDrawable(checkOffDisableResId);
Drawable checkOnDisableDrawable = getResources().getDrawable(checkOnDisableResId);
Drawable checkOffDrawable = getResources().getDrawable(checkOffResId);
Drawable checkOnDrawable = getResources().getDrawable(checkOnResId);
if (isSupportTintDrawable) {
checkOffDisableDrawable.setColorFilter(colorControlDisabled, DEFAULT_MODE);
checkOnDisableDrawable.setColorFilter(colorControlActivateDisabled, DEFAULT_MODE);
checkOffDrawable.setColorFilter(colorControlNormal, DEFAULT_MODE);
checkOnDrawable.setColorFilter(colorControlActivated, DEFAULT_MODE);
}
drawable.addState(checkOffDisableState, checkOffDisableDrawable, 0);
drawable.addState(checkOnDisableState, checkOnDisableDrawable, 0);
drawable.addState(checkOffState, checkOffDrawable, checkOffKeyframeId);
drawable.addState(checkOnState, checkOnDrawable, checkOnkeyframeId);
AnimationDrawable toOnDrawable = (AnimationDrawable) getResources().getDrawable(checkToOnResId);
AnimationDrawable toOffDrawable = (AnimationDrawable) getResources().getDrawable(checkToOffResId);
if (isSupportTintDrawable) {
toOnDrawable.setColorFilter(colorControlActivated, DEFAULT_MODE);
toOffDrawable.setColorFilter(colorControlNormal, DEFAULT_MODE);
}
drawable.addTransition(checkOffKeyframeId, checkOnkeyframeId, toOnDrawable, false);
drawable.addTransition(checkOnkeyframeId, checkOffKeyframeId, toOffDrawable, false);
setCheckMarkDrawable(drawable);
mIsSupportTintDrawable = isSupportTintDrawable;
mColorControlActivated = colorControlActivated;
mAnimationButtonDrawable = drawable;
}
}Example 85
| Project: edx-app-android-master File: CheckboxDrawableUtil.java View source code |
@NonNull
public static Drawable createStateListDrawable(@NonNull Context context, @DimenRes int sizeRes, @ColorRes int checkedColorRes, @ColorRes int uncheckedColorRes) {
final StateListDrawable drawable = new StateListDrawable();
drawable.addState(new int[] { android.R.attr.state_checked }, createCheckedDrawable(context, sizeRes, checkedColorRes));
drawable.addState(new int[] { -android.R.attr.state_checked }, createUncheckedDrawable(context, sizeRes, uncheckedColorRes));
return drawable;
}Example 86
| Project: Campus-master File: ThemeImageView.java View source code |
@Override
protected boolean onStateChange(int[] states) {
boolean enabled = false;
boolean pressed = false;
for (int state : states) {
if (state == android.R.attr.state_enabled)
enabled = true;
else if (state == android.R.attr.state_pressed)
pressed = true;
}
mutate();
if (enabled && pressed) {
setColorFilter(_pressedFilter);
} else if (!enabled) {
setColorFilter(null);
setAlpha(_disabledAlpha);
} else {
setColorFilter(null);
}
invalidateSelf();
return super.onStateChange(states);
}Example 87
| Project: simple_weather-master File: FButton.java View source code |
private void parseAttrs(Context context, AttributeSet attrs) {
//Load from custom attributes
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.FButton);
if (typedArray == null)
return;
for (int i = 0; i < typedArray.getIndexCount(); i++) {
int attr = typedArray.getIndex(i);
if (attr == R.styleable.FButton_shadowEnabled) {
//Default is true
isShadowEnabled = typedArray.getBoolean(attr, true);
} else if (attr == R.styleable.FButton_buttonColor) {
mButtonColor = typedArray.getColor(attr, R.color.fbutton_default_color);
} else if (attr == R.styleable.FButton_shadowColor) {
mShadowColor = typedArray.getColor(attr, R.color.fbutton_default_shadow_color);
isShadowColorDefined = true;
} else if (attr == R.styleable.FButton_shadowHeight) {
mShadowHeight = typedArray.getDimensionPixelSize(attr, R.dimen.fbutton_default_shadow_height);
} else if (attr == R.styleable.FButton_cornerRadius) {
mCornerRadius = typedArray.getDimensionPixelSize(attr, R.dimen.fbutton_default_conner_radius);
}
}
typedArray.recycle();
//Get paddingLeft, paddingRight
int[] attrsArray = new int[] { // 0
android.R.attr.paddingLeft, // 1
android.R.attr.paddingRight };
TypedArray ta = context.obtainStyledAttributes(attrs, attrsArray);
if (ta == null)
return;
mPaddingLeft = ta.getDimensionPixelSize(0, 0);
mPaddingRight = ta.getDimensionPixelSize(1, 0);
ta.recycle();
//Get paddingTop, paddingBottom
int[] attrsArray2 = new int[] { // 0
android.R.attr.paddingTop, // 1
android.R.attr.paddingBottom };
TypedArray ta1 = context.obtainStyledAttributes(attrs, attrsArray2);
if (ta1 == null)
return;
mPaddingTop = ta.getDimensionPixelSize(0, 0);
mPaddingBottom = ta.getDimensionPixelSize(1, 0);
ta1.recycle();
}Example 88
| Project: Bingo-master File: Selector.java View source code |
public static Drawable createSelector(int color, Shape shape) {
ShapeDrawable shapeDrawable = new ShapeDrawable(shape);
shapeDrawable.getPaint().setColor(color);
ShapeDrawable darkerShapeDrawablee = new ShapeDrawable(shape);
darkerShapeDrawablee.getPaint().setColor(shiftColor(color));
StateListDrawable stateListDrawable = new StateListDrawable();
stateListDrawable.addState(new int[] { -android.R.attr.state_pressed }, shapeDrawable);
stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, darkerShapeDrawablee);
return stateListDrawable;
}Example 89
| Project: FASTA-master File: FastAdapterUIUtils.java View source code |
/**
* helper to get the system default selectable background inclusive an active state
*
* @param ctx the context
* @param selected_color the selected color
* @param animate true if you want to fade over the states (only animates if API newer than Build.VERSION_CODES.HONEYCOMB)
* @return the StateListDrawable
*/
public static StateListDrawable getSelectableBackground(Context ctx, @ColorInt int selected_color, boolean animate) {
StateListDrawable states = new StateListDrawable();
ColorDrawable clrActive = new ColorDrawable(selected_color);
states.addState(new int[] { android.R.attr.state_selected }, clrActive);
states.addState(new int[] {}, ContextCompat.getDrawable(ctx, getSelectableBackground(ctx)));
//if possible we enable animating across states
if (animate) {
int duration = ctx.getResources().getInteger(android.R.integer.config_shortAnimTime);
states.setEnterFadeDuration(duration);
states.setExitFadeDuration(duration);
}
return states;
}Example 90
| Project: material-navigation-drawer-master File: SimpleNavigationItemDescriptor.java View source code |
@Override
public void bindView(View view, boolean selected) {
super.bindView(view, selected);
Context context = view.getContext();
TextView badge = ViewHolder.get(view, R.id.badge);
int badgeColor = getBadgeColor(context);
String badgeString = getBadge(context);
if (badgeString != null) {
badge.setText(badgeString);
if (badgeColor == 0) {
badge.setBackgroundColor(0);
badge.setTextAppearance(context, R.style.TextAppearance_MaterialNavigationDrawer_Badge_NoBackground);
// int textColorPrimary = Utils.getColor(context, android.R.attr.textColorPrimary, 0xde000000);
// int textColorSecondary = Utils.getColor(context, android.R.attr.textColorSecondary, 0x89000000);
// ColorStateList badgeTextColor = Utils.createActivatedColor(textColorSecondary, textColorPrimary);
// badge.setTextColor(badgeTextColor);
int textColor;
if (selected) {
textColor = Utils.getColor(context, android.R.attr.textColorPrimary, 0xde000000);
} else {
textColor = Utils.getColor(context, android.R.attr.textColorSecondary, 0x89000000);
}
badge.setTextColor(textColor);
} else {
Utils.setBackground(badge, Utils.createRoundRect(context, badgeColor, 1));
badge.setTextAppearance(context, R.style.TextAppearance_MaterialNavigationDrawer_Badge);
badge.setTextColor(Utils.computeTextColor(context, badgeColor));
}
badge.setVisibility(View.VISIBLE);
} else {
badge.setVisibility(View.GONE);
}
}Example 91
| Project: OMzen-master File: SystemUI_BaseStatusBar.java View source code |
private static StateListDrawable getTranslucentNotificationsBackground() {
// cria o StateListDrawable baseado no notification_bg.xml
// do framework-res.apk, mas com os drawables do m�dulo !!
StateListDrawable bg = new StateListDrawable();
bg.setExitFadeDuration(android.R.integer.config_mediumAnimTime);
// normal
bg.addState(new int[] { -android.R.attr.state_pressed }, new ColorDrawable(Color.TRANSPARENT));
// pressionado
bg.addState(new int[] { android.R.attr.state_pressed }, new ColorDrawable(Color.argb(50, 255, 255, 255)));
// focado
bg.addState(new int[] { android.R.attr.state_focused, -android.R.attr.state_pressed }, mTranslucentNotificationsFocusDrawable);
return bg;
}Example 92
| Project: material-master File: CompoundButton.java View source code |
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void applyPadding(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
TypedArray a = context.obtainStyledAttributes(attrs, new int[] { android.R.attr.padding, android.R.attr.paddingLeft, android.R.attr.paddingTop, android.R.attr.paddingRight, android.R.attr.paddingBottom, android.R.attr.paddingStart, android.R.attr.paddingEnd }, defStyleAttr, defStyleRes);
int padding = -1;
int leftPadding = -1;
int topPadding = -1;
int rightPadding = -1;
int bottomPadding = -1;
int startPadding = Integer.MIN_VALUE;
int endPadding = Integer.MIN_VALUE;
boolean startPaddingDefined = false;
boolean endPaddingDefined = false;
boolean leftPaddingDefined = false;
boolean rightPaddingDefined = false;
for (int i = 0, count = a.getIndexCount(); i < count; i++) {
int attr = a.getIndex(i);
if (attr == 0) {
padding = a.getDimensionPixelSize(attr, -1);
leftPaddingDefined = true;
rightPaddingDefined = true;
} else if (attr == 1) {
leftPadding = a.getDimensionPixelSize(attr, -1);
leftPaddingDefined = true;
} else if (attr == 2)
topPadding = a.getDimensionPixelSize(attr, -1);
else if (attr == 3) {
rightPadding = a.getDimensionPixelSize(attr, -1);
rightPaddingDefined = true;
} else if (attr == 4)
bottomPadding = a.getDimensionPixelSize(attr, -1);
else if (attr == 5) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
startPadding = a.getDimensionPixelSize(attr, Integer.MIN_VALUE);
startPaddingDefined = (startPadding != Integer.MIN_VALUE);
}
} else if (attr == 6) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
endPadding = a.getDimensionPixelSize(attr, Integer.MIN_VALUE);
endPaddingDefined = (endPadding != Integer.MIN_VALUE);
}
}
}
a.recycle();
if (padding >= 0)
setPadding(padding, padding, padding, padding);
else {
if (leftPaddingDefined || rightPaddingDefined)
setPadding(leftPaddingDefined ? leftPadding : getPaddingLeft(), topPadding >= 0 ? topPadding : getPaddingTop(), rightPaddingDefined ? rightPadding : getPaddingRight(), bottomPadding >= 0 ? bottomPadding : getPaddingBottom());
if (startPaddingDefined || endPaddingDefined)
setPaddingRelative(startPaddingDefined ? startPadding : getPaddingStart(), topPadding >= 0 ? topPadding : getPaddingTop(), endPaddingDefined ? endPadding : getPaddingEnd(), bottomPadding >= 0 ? bottomPadding : getPaddingBottom());
}
}Example 93
| Project: Android-BaseLib-master File: CommonUtils.java View source code |
@Override
public void onLoadCompleted(View container, String uri, Bitmap bitmap, BitmapDisplayConfig config, BitmapLoadFrom from) {
Drawable normalDrawable = new BitmapDrawable(bitmap);
stateListDrawable.addState(new int[] { android.R.attr.state_active }, normalDrawable);
stateListDrawable.addState(new int[] { android.R.attr.state_focused, android.R.attr.state_enabled }, normalDrawable);
stateListDrawable.addState(new int[] { android.R.attr.state_enabled }, normalDrawable);
utils.display(container, pressedImageUrl, new BitmapLoadCallBack<View>() {
@Override
public void onLoadCompleted(View container, String uri, Bitmap bitmap, BitmapDisplayConfig config, BitmapLoadFrom from) {
stateListDrawable.addState(new int[] { android.R.attr.state_pressed, android.R.attr.state_enabled }, new BitmapDrawable(bitmap));
view.setBackgroundDrawable(stateListDrawable);
}
@Override
public void onLoadFailed(View container, String uri, Drawable drawable) {
// TODO Auto-generated method stub
}
});
}Example 94
| Project: LemonLancher-master File: IconHighlights.java View source code |
private static Drawable newSelector(Context context) {
GradientDrawable mDrawPressed;
GradientDrawable mDrawSelected;
StateListDrawable drawable = new StateListDrawable();
int selectedColor = AlmostNexusSettingsHelper.getHighlightsColorFocus(context);
int pressedColor = AlmostNexusSettingsHelper.getHighlightsColor(context);
int stateFocused = android.R.attr.state_focused;
int statePressed = android.R.attr.state_pressed;
int stateWindowFocused = android.R.attr.state_window_focused;
mDrawSelected = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[] { 0x77FFFFFF, selectedColor, selectedColor, selectedColor, selectedColor, 0x77000000 });
mDrawSelected.setShape(GradientDrawable.RECTANGLE);
mDrawSelected.setGradientRadius((float) (Math.sqrt(2) * 60));
mDrawSelected.setCornerRadius(8);
mDrawPressed = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[] { 0x77FFFFFF, pressedColor, pressedColor, pressedColor, pressedColor, 0x77000000 });
mDrawPressed.setShape(GradientDrawable.RECTANGLE);
mDrawPressed.setGradientRadius((float) (Math.sqrt(2) * 60));
mDrawPressed.setCornerRadius(8);
drawable.addState(new int[] { statePressed }, mDrawPressed);
drawable.addState(new int[] { stateFocused, stateWindowFocused }, mDrawSelected);
drawable.addState(new int[] { stateFocused, -stateWindowFocused }, null);
drawable.addState(new int[] { -stateFocused, stateWindowFocused }, null);
drawable.addState(new int[] { -stateFocused, -stateWindowFocused }, null);
return drawable;
}Example 95
| Project: AndroidTrainingCode-master File: TouchHighlightImageButton.java View source code |
/**
* General view initialization used common to all constructors of the view.
*/
private void init() {
// Reset default ImageButton background and padding.
setBackgroundColor(0);
setPadding(0, 0, 0, 0);
// Retrieve the drawable resource assigned to the android.R.attr.selectableItemBackground
// theme attribute from the current theme.
TypedArray a = getContext().obtainStyledAttributes(new int[] { android.R.attr.selectableItemBackground });
mForegroundDrawable = a.getDrawable(0);
mForegroundDrawable.setCallback(this);
a.recycle();
}Example 96
| Project: android-color-button-master File: ColorButton.java View source code |
private StateListDrawable getStateListDrawable() {
LayerDrawable tap = getDrawable(true);
LayerDrawable normal = getDrawable(false);
StateListDrawable stateListDrawable = new StateListDrawable();
stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, tap);
stateListDrawable.addState(new int[] { android.R.attr.state_focused }, tap);
stateListDrawable.addState(new int[] { android.R.attr.state_enabled }, normal);
return stateListDrawable;
}Example 97
| Project: HoloEverywhere-master File: AmPmCirclesView.java View source code |
private int getCircleBackgroundColor(int amOrPm) {
final boolean pressed = mAmOrPmPressed == amOrPm;
final boolean selected = mAmOrPm == amOrPm;
final int[] state = { pressed ? android.R.attr.state_pressed : -android.R.attr.state_pressed, selected ? android.R.attr.state_selected : -android.R.attr.state_selected };
return mCircleBackground.getColorForState(state, mCircleBackgroundDefault);
}Example 98
| Project: termux-app-master File: ExtraKeysView.java View source code |
void reload() {
altButton = controlButton = null;
removeAllViews();
String[][] buttons = { { "ESC", "CTRL", "ALT", "TAB", "―", "/", "|" } };
final int rows = buttons.length;
final int cols = buttons[0].length;
setRowCount(rows);
setColumnCount(cols);
for (int row = 0; row < rows; row++) {
for (int col = 0; col < cols; col++) {
final String buttonText = buttons[row][col];
Button button;
switch(buttonText) {
case "CTRL":
button = controlButton = new ToggleButton(getContext(), null, android.R.attr.buttonBarButtonStyle);
button.setClickable(true);
break;
case "ALT":
button = altButton = new ToggleButton(getContext(), null, android.R.attr.buttonBarButtonStyle);
button.setClickable(true);
break;
case "FN":
button = fnButton = new ToggleButton(getContext(), null, android.R.attr.buttonBarButtonStyle);
button.setClickable(true);
break;
default:
button = new Button(getContext(), null, android.R.attr.buttonBarButtonStyle);
break;
}
button.setText(buttonText);
button.setTextColor(TEXT_COLOR);
final Button finalButton = button;
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finalButton.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
View root = getRootView();
switch(buttonText) {
case "CTRL":
case "ALT":
case "FN":
ToggleButton self = (ToggleButton) finalButton;
self.setChecked(self.isChecked());
self.setTextColor(self.isChecked() ? 0xFF80DEEA : TEXT_COLOR);
break;
default:
sendKey(root, buttonText);
break;
}
}
});
GridLayout.LayoutParams param = new GridLayout.LayoutParams();
param.height = param.width = 0;
param.rightMargin = param.topMargin = 0;
param.setGravity(Gravity.LEFT);
float weight = "▲▼◀▶".contains(buttonText) ? 0.7f : 1.f;
param.columnSpec = GridLayout.spec(col, GridLayout.FILL, weight);
param.rowSpec = GridLayout.spec(row, GridLayout.FILL, 1.f);
button.setLayoutParams(param);
addView(button);
}
}
}Example 99
| Project: MaterialDrawer-Xamarin-master File: DrawerUIUtils.java View source code |
/**
* helper to get the system default selectable background
*
* @param ctx
* @return
*/
public static int getSelectableBackground(Context ctx) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
// If we're running on Honeycomb or newer, then we can use the Theme's
// selectableItemBackground to ensure that the View has a pressed state
TypedValue outValue = new TypedValue();
ctx.getTheme().resolveAttribute(R.attr.selectableItemBackground, outValue, true);
return outValue.resourceId;
} else {
TypedValue outValue = new TypedValue();
ctx.getTheme().resolveAttribute(android.R.attr.itemBackground, outValue, true);
return outValue.resourceId;
}
}Example 100
| Project: ViewPump-master File: TextUpdatingInterceptor.java View source code |
@Override
public InflateResult intercept(Chain chain) {
InflateResult result = chain.proceed(chain.request());
if (result.view() instanceof CustomTextView) {
CustomTextView textView = (CustomTextView) result.view();
TypedArray a = result.context().obtainStyledAttributes(result.attrs(), new int[] { android.R.attr.text });
try {
CharSequence text = a.getText(0);
if (text != null && text.length() > 0) {
if (text.toString().startsWith("\n")) {
text = text.toString().substring(1);
}
textView.setText(textView.getContext().getString(R.string.custom_textview_prefixed_text, text));
}
} finally {
if (a != null) {
a.recycle();
}
}
}
return result;
}Example 101
| Project: android-gif-drawable-master File: GifSelectorDrawable.java View source code |
@Override
public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Resources.Theme theme) throws XmlPullParserException, IOException {
final XmlResourceParser resourceParser = (XmlResourceParser) parser;
resourceParser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
int eventType = resourceParser.getEventType();
do {
if (eventType == XmlPullParser.START_TAG && "item".equals(resourceParser.getName())) {
@DrawableRes final int resourceId = resourceParser.getAttributeResourceValue(NAMESPACE, "drawable", 0);
final boolean state_pressed = resourceParser.getAttributeBooleanValue(NAMESPACE, "state_pressed", false);
final int[] stateSet = state_pressed ? new int[] { android.R.attr.state_pressed } : new int[0];
addState(stateSet, GifDrawable.createFromResource(r, resourceId));
}
eventType = resourceParser.next();
} while (eventType != XmlPullParser.END_DOCUMENT);
}