Skip to content

Commit dcca6d6

Browse files
author
肖琪(融汇/产品技术中心)
committed
update to 1.6.6
1 parent b826993 commit dcca6d6

20 files changed

Lines changed: 3021 additions & 722 deletions

BackgroundLibrary.xml

Lines changed: 652 additions & 1 deletion
Large diffs are not rendered by default.

app/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ android {
3232
dependencies {
3333
implementation fileTree(include: ['*.jar'], dir: 'libs')
3434
implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
35-
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
35+
implementation 'com.android.support.constraint:constraint-layout:2.0.4'
3636
implementation 'com.android.support:support-v4:28.0.0-rc02'
3737
testImplementation 'junit:junit:4.12'
3838
androidTestImplementation 'com.android.support.test:runner:1.0.2'
3939
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
40-
implementation 'com.noober.background:core:1.6.5'
41-
// implementation project(':library')
40+
// implementation 'com.noober.background:core:1.6.5'
41+
implementation project(':library')
4242
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
4343
}

app/src/main/res/layout/activity_main.xml

Lines changed: 83 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,80 @@
1313
tools:context=".MainActivity"
1414
tools:ignore="MissingPrefix">
1515

16+
<com.noober.background.view.BLButton
17+
style="?android:attr/borderlessButtonStyle"
18+
android:layout_width="match_parent"
19+
android:layout_height="wrap_content"
20+
android:text="点击事件支持渐变"
21+
android:textColor="@android:color/white"
22+
app:bl_corners_radius="4dp"
23+
app:bl_pressed_gradient_centerColor="@android:color/holo_green_dark"
24+
app:bl_unPressed_gradient_centerColor="@android:color/darker_gray"
25+
app:bl_pressed_gradient_startColor="@android:color/black"
26+
app:bl_unPressed_gradient_startColor="@android:color/white"
27+
app:bl_pressed_gradient_endColor="@android:color/holo_red_dark"
28+
app:bl_unPressed_gradient_endColor="@android:color/holo_blue_light"/>
29+
30+
<android.support.constraint.ConstraintLayout
31+
android:layout_width="match_parent"
32+
android:layout_height="match_parent">
33+
34+
<com.noober.background.view.BLFlow
35+
android:layout_width="0dp"
36+
android:layout_height="wrap_content"
37+
android:padding="20.0dp"
38+
app:bl_corners_radius="4dp"
39+
app:bl_padding_bottom="5dp"
40+
app:bl_padding_left="15dp"
41+
app:bl_padding_right="5dp"
42+
app:bl_padding_top="15dp"
43+
app:bl_solid_color="#E3B666"
44+
app:bl_stroke_color="#8c6822"
45+
app:bl_stroke_dashGap="5dp"
46+
app:bl_stroke_dashWidth="10dp"
47+
app:bl_stroke_width="2dp"
48+
app:constraint_referenced_ids="tv1,tv2,tv3,tv4,tv5"
49+
app:flow_horizontalGap="20.0dp"
50+
app:flow_verticalGap="20.0dp"
51+
app:flow_wrapMode="aligned"
52+
app:layout_constraintEnd_toEndOf="parent"
53+
app:layout_constraintStart_toStartOf="parent"
54+
app:layout_constraintTop_toTopOf="parent" />
55+
56+
57+
<TextView
58+
android:id="@+id/tv1"
59+
android:layout_width="wrap_content"
60+
android:layout_height="wrap_content"
61+
android:text="Hello World!" />
62+
63+
<TextView
64+
android:id="@+id/tv4"
65+
android:layout_width="wrap_content"
66+
android:layout_height="wrap_content"
67+
android:text="Hello World!" />
68+
69+
<TextView
70+
android:id="@+id/tv2"
71+
android:layout_width="wrap_content"
72+
android:layout_height="wrap_content"
73+
android:text="Hello World!" />
74+
75+
<TextView
76+
android:id="@+id/tv3"
77+
android:layout_width="wrap_content"
78+
android:layout_height="wrap_content"
79+
android:text="Hello World!" />
80+
81+
<TextView
82+
android:id="@+id/tv5"
83+
android:layout_width="wrap_content"
84+
android:layout_height="wrap_content"
85+
android:text="Hello World!" />
86+
87+
88+
</android.support.constraint.ConstraintLayout>
89+
1690
<com.noober.background.view.BLButton
1791
android:id="@+id/btn_login"
1892
style="?android:attr/borderlessButtonStyle"
@@ -43,14 +117,14 @@
43117
android:layout_height="36dp"
44118
android:layout_marginTop="5dp"
45119
android:background="@null"
46-
android:gravity="center"
47120
android:clickable="true"
121+
android:gravity="center"
48122
android:text="指定只显示左右下方的边框22222"
49123
android:textSize="20sp"
50-
app:bl_unPressed_stroke_color="@android:color/black"
51124
app:bl_pressed_stroke_color="@android:color/holo_red_dark"
52125
app:bl_stroke_position="left|bottom|right"
53-
app:bl_stroke_width="1dp" />
126+
app:bl_stroke_width="1dp"
127+
app:bl_unPressed_stroke_color="@android:color/black" />
54128

55129

56130
<com.noober.background.view.BLTextView
@@ -494,16 +568,16 @@
494568
android:layout_width="130dp"
495569
android:layout_height="36dp"
496570
android:layout_marginTop="5dp"
497-
android:gravity="center"
498-
android:padding="0dp"
499571
android:clickable="true"
500572
android:focusable="true"
501-
app:bl_pressed_solid_color="@color/colorAccent"
502-
app:bl_unPressed_solid_color="@color/colorPrimaryDark"
503-
app:bl_corners_radius="5dp"
573+
android:gravity="center"
574+
android:padding="0dp"
504575
android:text="背景"
505576
android:textColor="#4F94CD"
506-
android:textSize="20sp" />
577+
android:textSize="20sp"
578+
app:bl_corners_radius="5dp"
579+
app:bl_pressed_solid_color="@color/colorAccent"
580+
app:bl_unPressed_solid_color="@color/colorPrimaryDark" />
507581

508582
<Button
509583
android:id="@+id/btnTest3"

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ ext {
3838
userOrg = 'noober'
3939
groupId = 'com.noober.background'
4040
uploadName = 'LibraryForBackground'
41-
publishVersion = '1.6.5'
41+
publishVersion = '1.6.6'
4242
desc = "A framework for directly generating shape through Tags, no need to write shape.xml again(通过标签直接生成shape,无需再写shape.xml)"
4343
website = 'https://github.com/JavaNoober/BackgroundLibrary'
4444
// gradlew clean build bintrayUpload -PbintrayUser=xiaoqiandroid -PbintrayKey=xxxxxxxxxxxxxxxx -PdryRun=false

library/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ dependencies {
3030
implementation fileTree(dir: 'libs', include: ['*.jar'])
3131

3232
compileOnly 'com.android.support:appcompat-v7:28.0.0-rc02'
33-
compileOnly 'com.android.support.constraint:constraint-layout:1.1.3'
33+
compileOnly 'com.android.support.constraint:constraint-layout:2.0.4'
3434
testImplementation 'junit:junit:4.12'
3535
androidTestImplementation 'com.android.support.test:runner:1.0.2'
3636
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

library/src/main/java/com/noober/background/BackgroundFactory.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,13 @@ private static View setViewBackground(String name, Context context, AttributeSet
131131
stateListDrawable = DrawableFactory.getSelectorPre21Drawable(typedArray);
132132
setDrawable(stateListDrawable, view, otherTa, typedArray);
133133
} else {
134-
drawable = DrawableFactory.getDrawable(typedArray);
135-
setDrawable(drawable, view, otherTa, typedArray);
134+
if (hasGradientState(typedArray)) {
135+
stateListDrawable = DrawableFactory.getStateGradientDrawable(typedArray);
136+
setDrawable(stateListDrawable, view, otherTa, typedArray);
137+
} else {
138+
drawable = DrawableFactory.getDrawable(typedArray);
139+
setDrawable(drawable, view, otherTa, typedArray);
140+
}
136141
}
137142
} else if (animTa.getIndexCount() > 0) {
138143
AnimationDrawable animationDrawable = DrawableFactory.getAnimationDrawable(animTa);
@@ -373,4 +378,15 @@ private static View createView(Context context, String name, String prefix) thro
373378
public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
374379
return onCreateView(name, context, attrs);
375380
}
381+
382+
private static boolean hasGradientState(TypedArray typedArray) {
383+
return typedArray.hasValue(R.styleable.background_bl_checkable_gradient_startColor) ||
384+
typedArray.hasValue(R.styleable.background_bl_checked_gradient_startColor) ||
385+
typedArray.hasValue(R.styleable.background_bl_enabled_gradient_startColor) ||
386+
typedArray.hasValue(R.styleable.background_bl_selected_gradient_startColor) ||
387+
typedArray.hasValue(R.styleable.background_bl_pressed_gradient_startColor) ||
388+
typedArray.hasValue(R.styleable.background_bl_focused_gradient_startColor);
389+
}
376390
}
391+
392+

library/src/main/java/com/noober/background/BackgroundLibrary.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private static void forceSetFactory2(LayoutInflater inflater) {
8080
try {
8181
Field sCheckedField = compatClass.getDeclaredField("sCheckedField");
8282
sCheckedField.setAccessible(true);
83-
sCheckedField.setBoolean(inflater, false);
83+
sCheckedField.setBoolean(compatClass, false);
8484
Field mFactory = inflaterClass.getDeclaredField("mFactory");
8585
mFactory.setAccessible(true);
8686
Field mFactory2 = inflaterClass.getDeclaredField("mFactory2");

library/src/main/java/com/noober/background/drawable/DrawableFactory.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.graphics.drawable.AnimationDrawable;
77
import android.graphics.drawable.GradientDrawable;
88
import android.graphics.drawable.StateListDrawable;
9+
import android.support.annotation.AttrRes;
910

1011
import org.xmlpull.v1.XmlPullParserException;
1112

@@ -16,12 +17,21 @@ public class DrawableFactory {
1617

1718
//获取shape属性的drawable
1819
public static GradientDrawable getDrawable(TypedArray typedArray) throws XmlPullParserException {
19-
return new GradientDrawableCreator(typedArray).create();
20+
return (GradientDrawable) new GradientDrawableCreator(typedArray).create();
2021
}
2122

23+
public static GradientDrawable getDrawable(TypedArray typedArray, @AttrRes int gradientState) throws XmlPullParserException {
24+
return (GradientDrawable) new GradientDrawableCreator(typedArray, gradientState).create();
25+
}
26+
27+
public static StateListDrawable getStateGradientDrawable(TypedArray typedArray) throws Exception {
28+
return (StateListDrawable) new GradientStateDrawableCreator(typedArray).create();
29+
}
30+
31+
2232
//获取selector属性的drawable
2333
public static StateListDrawable getSelectorDrawable(TypedArray typedArray, TypedArray selectorTa) throws Exception {
24-
return new SelectorDrawableCreator(typedArray, selectorTa).create();
34+
return (StateListDrawable) new SelectorDrawableCreator(typedArray, selectorTa).create();
2535
}
2636

2737
//针对sdk21以前获取selector属性的drawable
@@ -31,7 +41,7 @@ public static StateListDrawable getSelectorPre21Drawable(TypedArray typedArray)
3141

3242
//获取button 属性的drawable
3343
public static StateListDrawable getButtonDrawable(TypedArray typedArray, TypedArray buttonTa) throws Exception {
34-
return new ButtonDrawableCreator(typedArray, buttonTa).create();
44+
return (StateListDrawable) new ButtonDrawableCreator(typedArray, buttonTa).create();
3545
}
3646

3747
//获取text selector属性关于text的color
@@ -42,16 +52,16 @@ public static ColorStateList getTextSelectorColor(TypedArray textTa) {
4252
//适配早期版本的属性
4353
public static StateListDrawable getPressDrawable(GradientDrawable drawable, TypedArray typedArray, TypedArray pressTa)
4454
throws Exception {
45-
return new PressDrawableCreator(drawable, typedArray, pressTa).create();
55+
return (StateListDrawable) new PressDrawableCreator(drawable, typedArray, pressTa).create();
4656
}
4757

4858
//获取AnimationDrawable属性的drawable
49-
public static AnimationDrawable getAnimationDrawable(TypedArray animTa) {
50-
return new AnimationDrawableCreator(animTa).create();
59+
public static AnimationDrawable getAnimationDrawable(TypedArray animTa) throws Exception {
60+
return (AnimationDrawable) new AnimationDrawableCreator(animTa).create();
5161
}
5262

5363
public static StateListDrawable getMultiSelectorDrawable(Context context, TypedArray selectorTa, TypedArray typedArray) {
54-
return new MultiSelectorDrawableCreator(context, selectorTa, typedArray).create();
64+
return (StateListDrawable) new MultiSelectorDrawableCreator(context, selectorTa, typedArray).create();
5565
}
5666

5767
public static ColorStateList getMultiTextColorSelectorColorCreator(Context context, TypedArray selectorTa) {

0 commit comments

Comments
 (0)