Skip to content

Commit

Permalink
update to 1.6.4 增加selector属性使用的时候默认颜色设置
Browse files Browse the repository at this point in the history
  • Loading branch information
JavaNoober committed May 18, 2020
1 parent bc4fddb commit 9849d83
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 44 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.noober.background:core:1.6.2'
implementation 'com.noober.background:core:1.6.4'
// implementation project(':library')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
// AnimationDrawable animationDrawable = (AnimationDrawable) vAnim.getBackground();
// animationDrawable.start();


// findViewById(R.id.tv111).setSelected(true);

// findViewById(R.id.select_view).setSelected(true);

Drawable drawable = new DrawableCreator.Builder().setCornersRadius(30)
.setSolidColor(Color.parseColor("#FFFFFF"))
.setStrokeColor(Color.parseColor("#FFFFFF"))
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/test_sel3.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/black" android:state_pressed="true" />
<item android:drawable="@android:color/holo_red_dark" android:state_selected="true" />
<item android:drawable="@android:color/darker_gray" />
</selector>
41 changes: 41 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,47 @@
tools:context=".MainActivity"
tools:ignore="MissingPrefix">


<TextView
android:id="@+id/tv111"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="今日持仓"
android:textSize="12sp"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:background="@drawable/test_sel3" />


<com.noober.background.view.BLFrameLayout
android:id="@+id/select_view"
android:layout_width="match_parent"
android:layout_height="30dp"
app:bl_corners_radius="15dp"
app:bl_solid_color="@android:color/darker_gray"
app:bl_selected_solid_color="@android:color/holo_red_dark"
app:bl_pressed_solid_color="@android:color/black">

</com.noober.background.view.BLFrameLayout>

<com.noober.background.view.BLRadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="今日持仓"
android:textSize="12sp"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:paddingTop="2dp"
android:paddingBottom="2dp"
app:bl_checked_solid_color="@color/colorPrimaryDark"
app:bl_unCheckable_solid_color="#F4F4F4"
app:bl_checked_textColor="@android:color/white"
app:bl_unChecked_textColor="@color/colorPrimaryDark"
app:bl_corners_radius="10dp" />


<com.noober.background.view.BLButton
android:id="@+id/btn_login"
style="?android:attr/borderlessButtonStyle"
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ext {
userOrg = 'noober'
groupId = 'com.noober.background'
uploadName = 'LibraryForBackground'
publishVersion = '1.6.3'
publishVersion = '1.6.4'
desc = "A framework for directly generating shape through Tags, no need to write shape.xml again(通过标签直接生成shape,无需再写shape.xml)"
website = 'https://github.com/JavaNoober/BackgroundLibrary'
// gradlew clean build bintrayUpload -PbintrayUser=xiaoqiandroid -PbintrayKey=xxxxxxxxxxxxxxxx -PdryRun=false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,57 +116,73 @@ public GradientDrawable create() throws XmlPullParserException {
int start = 0;
ArrayList<Integer> stateList = new ArrayList<>();
ArrayList<Integer> colorList = new ArrayList<>();
if (typedArray.hasValue(R.styleable.background_bl_pressed_solid_color) &&
typedArray.hasValue(R.styleable.background_bl_unPressed_solid_color)) {
if (typedArray.hasValue(R.styleable.background_bl_pressed_solid_color)) {
stateList.add(android.R.attr.state_pressed);
stateList.add(-android.R.attr.state_pressed);
colorList.add(typedArray.getColor(R.styleable.background_bl_pressed_solid_color, 0));
}
if (typedArray.hasValue(R.styleable.background_bl_unPressed_solid_color)) {
stateList.add(-android.R.attr.state_pressed);
colorList.add(typedArray.getColor(R.styleable.background_bl_unPressed_solid_color, 0));
}
if (typedArray.hasValue(R.styleable.background_bl_checkable_solid_color) &&
typedArray.hasValue(R.styleable.background_bl_unCheckable_solid_color)) {
if (typedArray.hasValue(R.styleable.background_bl_checkable_solid_color)) {
stateList.add(android.R.attr.state_checkable);
stateList.add(-android.R.attr.state_checkable);
colorList.add(typedArray.getColor(R.styleable.background_bl_checkable_solid_color, 0));
}
if (typedArray.hasValue(R.styleable.background_bl_unCheckable_solid_color)) {
stateList.add(-android.R.attr.state_checkable);
colorList.add(typedArray.getColor(R.styleable.background_bl_unCheckable_solid_color, 0));
}
if (typedArray.hasValue(R.styleable.background_bl_checked_solid_color) &&
typedArray.hasValue(R.styleable.background_bl_unChecked_solid_color)) {
if (typedArray.hasValue(R.styleable.background_bl_checked_solid_color)) {
stateList.add(android.R.attr.state_checked);
stateList.add(-android.R.attr.state_checked);
colorList.add(typedArray.getColor(R.styleable.background_bl_checked_solid_color, 0));
}
if (typedArray.hasValue(R.styleable.background_bl_unChecked_solid_color)) {
stateList.add(-android.R.attr.state_checked);
colorList.add(typedArray.getColor(R.styleable.background_bl_unChecked_solid_color, 0));
}
if (typedArray.hasValue(R.styleable.background_bl_enabled_solid_color) &&
typedArray.hasValue(R.styleable.background_bl_unEnabled_solid_color)) {
if (typedArray.hasValue(R.styleable.background_bl_enabled_solid_color)) {
stateList.add(android.R.attr.state_enabled);
stateList.add(-android.R.attr.state_enabled);
colorList.add(typedArray.getColor(R.styleable.background_bl_enabled_solid_color, 0));
}
if (typedArray.hasValue(R.styleable.background_bl_unEnabled_solid_color)) {
stateList.add(-android.R.attr.state_enabled);
colorList.add(typedArray.getColor(R.styleable.background_bl_unEnabled_solid_color, 0));
}
if (typedArray.hasValue(R.styleable.background_bl_selected_solid_color) &&
typedArray.hasValue(R.styleable.background_bl_unSelected_solid_color)) {
if (typedArray.hasValue(R.styleable.background_bl_selected_solid_color)) {
stateList.add(android.R.attr.state_selected);
stateList.add(-android.R.attr.state_selected);
colorList.add(typedArray.getColor(R.styleable.background_bl_selected_solid_color, 0));
}
if (typedArray.hasValue(R.styleable.background_bl_unSelected_solid_color)) {
stateList.add(-android.R.attr.state_selected);
colorList.add(typedArray.getColor(R.styleable.background_bl_unSelected_solid_color, 0));
}
if (typedArray.hasValue(R.styleable.background_bl_focused_solid_color) &&
typedArray.hasValue(R.styleable.background_bl_unFocused_solid_color)) {
if (typedArray.hasValue(R.styleable.background_bl_focused_solid_color)) {
stateList.add(android.R.attr.state_focused);
stateList.add(-android.R.attr.state_focused);
colorList.add(typedArray.getColor(R.styleable.background_bl_focused_solid_color, 0));
}
if (typedArray.hasValue(R.styleable.background_bl_unFocused_solid_color)) {
stateList.add(-android.R.attr.state_focused);
colorList.add(typedArray.getColor(R.styleable.background_bl_unFocused_solid_color, 0));
}

if (stateList.size() > 0) {
int[][] state = new int[stateList.size()][];
int[] color = new int[stateList.size()];
int size = stateList.size();
if (typedArray.hasValue(R.styleable.background_bl_solid_color)) {
size ++;
}
int[][] state = new int[size][];
int[] color = new int[size];
for (int iState : stateList) {
state[start] = new int[]{iState};
color[start] = colorList.get(start);
start++;
}

if (typedArray.hasValue(R.styleable.background_bl_solid_color)) {
state[start] = new int[]{};
color[start] = solidColor;
}

ColorStateList colorStateList = new ColorStateList(state, color);
drawable.setColor(colorStateList);
} else if (typedArray.hasValue(R.styleable.background_bl_solid_color)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class GradientDrawableCreator implements ICreateDrawable {
}

@Override
public Drawable create() throws XmlPullParserException {
public GradientDrawable create() throws XmlPullParserException {
GradientDrawable drawable = new GradientDrawable();
float[] cornerRadius = new float[8];
float sizeWidth = 0;
Expand Down Expand Up @@ -116,57 +116,73 @@ public Drawable create() throws XmlPullParserException {
int start = 0;
ArrayList<Integer> stateList = new ArrayList<>();
ArrayList<Integer> colorList = new ArrayList<>();
if (typedArray.hasValue(R.styleable.background_bl_pressed_solid_color) &&
typedArray.hasValue(R.styleable.background_bl_unPressed_solid_color)) {
if (typedArray.hasValue(R.styleable.background_bl_pressed_solid_color)) {
stateList.add(android.R.attr.state_pressed);
stateList.add(-android.R.attr.state_pressed);
colorList.add(typedArray.getColor(R.styleable.background_bl_pressed_solid_color, 0));
}
if (typedArray.hasValue(R.styleable.background_bl_unPressed_solid_color)) {
stateList.add(-android.R.attr.state_pressed);
colorList.add(typedArray.getColor(R.styleable.background_bl_unPressed_solid_color, 0));
}
if (typedArray.hasValue(R.styleable.background_bl_checkable_solid_color) &&
typedArray.hasValue(R.styleable.background_bl_unCheckable_solid_color)) {
if (typedArray.hasValue(R.styleable.background_bl_checkable_solid_color)) {
stateList.add(android.R.attr.state_checkable);
stateList.add(-android.R.attr.state_checkable);
colorList.add(typedArray.getColor(R.styleable.background_bl_checkable_solid_color, 0));
}
if (typedArray.hasValue(R.styleable.background_bl_unCheckable_solid_color)) {
stateList.add(-android.R.attr.state_checkable);
colorList.add(typedArray.getColor(R.styleable.background_bl_unCheckable_solid_color, 0));
}
if (typedArray.hasValue(R.styleable.background_bl_checked_solid_color) &&
typedArray.hasValue(R.styleable.background_bl_unChecked_solid_color)) {
if (typedArray.hasValue(R.styleable.background_bl_checked_solid_color)) {
stateList.add(android.R.attr.state_checked);
stateList.add(-android.R.attr.state_checked);
colorList.add(typedArray.getColor(R.styleable.background_bl_checked_solid_color, 0));
}
if (typedArray.hasValue(R.styleable.background_bl_unChecked_solid_color)) {
stateList.add(-android.R.attr.state_checked);
colorList.add(typedArray.getColor(R.styleable.background_bl_unChecked_solid_color, 0));
}
if (typedArray.hasValue(R.styleable.background_bl_enabled_solid_color) &&
typedArray.hasValue(R.styleable.background_bl_unEnabled_solid_color)) {
if (typedArray.hasValue(R.styleable.background_bl_enabled_solid_color)) {
stateList.add(android.R.attr.state_enabled);
stateList.add(-android.R.attr.state_enabled);
colorList.add(typedArray.getColor(R.styleable.background_bl_enabled_solid_color, 0));
}
if (typedArray.hasValue(R.styleable.background_bl_unEnabled_solid_color)) {
stateList.add(-android.R.attr.state_enabled);
colorList.add(typedArray.getColor(R.styleable.background_bl_unEnabled_solid_color, 0));
}
if (typedArray.hasValue(R.styleable.background_bl_selected_solid_color) &&
typedArray.hasValue(R.styleable.background_bl_unSelected_solid_color)) {
if (typedArray.hasValue(R.styleable.background_bl_selected_solid_color)) {
stateList.add(android.R.attr.state_selected);
stateList.add(-android.R.attr.state_selected);
colorList.add(typedArray.getColor(R.styleable.background_bl_selected_solid_color, 0));
}
if (typedArray.hasValue(R.styleable.background_bl_unSelected_solid_color)) {
stateList.add(-android.R.attr.state_selected);
colorList.add(typedArray.getColor(R.styleable.background_bl_unSelected_solid_color, 0));
}
if (typedArray.hasValue(R.styleable.background_bl_focused_solid_color) &&
typedArray.hasValue(R.styleable.background_bl_unFocused_solid_color)) {
if (typedArray.hasValue(R.styleable.background_bl_focused_solid_color)) {
stateList.add(android.R.attr.state_focused);
stateList.add(-android.R.attr.state_focused);
colorList.add(typedArray.getColor(R.styleable.background_bl_focused_solid_color, 0));
}
if (typedArray.hasValue(R.styleable.background_bl_unFocused_solid_color)) {
stateList.add(-android.R.attr.state_focused);
colorList.add(typedArray.getColor(R.styleable.background_bl_unFocused_solid_color, 0));
}

if (stateList.size() > 0) {
int[][] state = new int[stateList.size()][];
int[] color = new int[stateList.size()];
int size = stateList.size();
if (typedArray.hasValue(R.styleable.background_bl_solid_color)) {
size ++;
}
int[][] state = new int[size][];
int[] color = new int[size];
for (int iState : stateList) {
state[start] = new int[]{iState};
color[start] = colorList.get(start);
start++;
}

if (typedArray.hasValue(R.styleable.background_bl_solid_color)) {
state[start] = new int[]{};
color[start] = solidColor;
}

ColorStateList colorStateList = new ColorStateList(state, color);
drawable.setColor(colorStateList);
} else if (typedArray.hasValue(R.styleable.background_bl_solid_color)) {
Expand Down Expand Up @@ -325,7 +341,6 @@ public Drawable create() throws XmlPullParserException {
e.printStackTrace();
}
}

}
return drawable;
}
Expand Down

0 comments on commit 9849d83

Please sign in to comment.