Skip to content

Commit 34069d4

Browse files
committed
update to 1.5.3
1 parent e564785 commit 34069d4

File tree

10 files changed

+67
-39
lines changed

10 files changed

+67
-39
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

BackgroundLibrary.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,4 +767,10 @@
767767
<option name="XML" value="true" />
768768
</context>
769769
</template>
770+
<template name="bl_stroke_position" value="app:bl_stroke_position=&quot;$value$&quot;" description="指定显示某个方向的边框" toReformat="true" toShortenFQNames="true">
771+
<variable name="value" expression="" defaultValue="" alwaysStopAt="true" />
772+
<context>
773+
<option name="XML" value="true" />
774+
</context>
775+
</template>
770776
</templateSet>

README-EN.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ A framework for directly generating shape through Tags, no need to write shape.x
77
Add this to your app's build.gradle:
88

99
implementation "com.android.support:appcompat-v7:$supportVersion"
10-
implementation 'com.noober.background:core:1.5.2'
10+
implementation 'com.noober.background:core:1.5.3'
1111

1212

1313
## Example effect
14+
show more in [wiki](https://github.com/JavaNoober/BackgroundLibrary/wiki)
1415

1516
![](https://user-gold-cdn.xitu.io/2018/9/12/165ce13d4c0a176f?w=286&h=606&f=gif&s=807047)
1617

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ A framework for directly generating shape through Tags, no need to write shape.x
1010
依赖方式:
1111

1212
implementation "com.android.support:appcompat-v7:$supportVersion"
13-
implementation 'com.noober.background:core:1.5.2'
13+
implementation 'com.noober.background:core:1.5.3'
1414

1515
## 使用文档
1616

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ dependencies {
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.5.2'
41-
// implementation project(':library')
40+
// implementation 'com.noober.background:core:1.5.2'
41+
implementation project(':library')
4242
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
4343
// implementation 'com.trello.rxlifecycle3:rxlifecycle:3.0.0'
4444
//

app/src/main/java/com/noober/backgroudlibrary/MainActivity.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,16 @@
1414
import android.widget.Button;
1515
import android.widget.TextView;
1616

17-
import com.noober.background.BackgroundLibrary;
1817
import com.noober.background.drawable.DrawableCreator;
19-
import com.noober.background.view.BLTextView;
2018

2119
public class MainActivity extends AppCompatActivity {
2220

23-
Button blTextView;
24-
2521
@Override
2622
protected void onCreate(@Nullable Bundle savedInstanceState) {
2723
super.onCreate(savedInstanceState);
2824
setContentView( R.layout.activity_main);
2925
getSupportFragmentManager().beginTransaction().add(R.id.fl_content, new BlankFragment()).commitAllowingStateLoss();
3026
Button button = findViewById(R.id.btn);
31-
blTextView = findViewById(R.id.ttt);
3227

3328
button.setOnClickListener(new View.OnClickListener() {
3429
@Override

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

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,26 @@
1414
tools:ignore="MissingPrefix">
1515

1616

17-
<Button
18-
android:layout_width="130dp"
19-
android:layout_height="36dp"
20-
android:layout_marginTop="5dp"
21-
android:gravity="center"
22-
android:text="TextView"
23-
android:textSize="20sp"
24-
android:background="@drawable/shape_login_button" />
25-
26-
<com.noober.background.view.BLButton
27-
android:layout_width="130dp"
17+
<com.noober.background.view.BLTextView
18+
android:layout_width="wrap_content"
2819
android:layout_height="36dp"
2920
android:layout_marginTop="5dp"
3021
android:background="@null"
3122
android:gravity="center"
32-
android:text="TextView"
23+
android:text="指定只显示左右下方的边框"
3324
android:textSize="20sp"
34-
app:bl_solid_color="#2fdcb5"
35-
app:bl_corners_radius="7dp" />
25+
app:bl_stroke_width="1dp"
26+
app:bl_stroke_color="@android:color/black"
27+
app:bl_solid_color="@android:color/white"
28+
app:bl_stroke_position="left|bottom|right"/>
3629

3730
<com.noober.background.view.BLTextView
3831
android:id="@+id/ttt"
39-
android:layout_width="130dp"
32+
android:layout_width="wrap_content"
4033
android:layout_height="36dp"
4134
android:layout_marginTop="5dp"
4235
android:gravity="center"
43-
android:text="TextView"
36+
android:text="虚线圆角边框以及填充"
4437
android:textColor="#8c6822"
4538
android:textSize="20sp"
4639
app:bl_corners_radius="4dp"
@@ -52,6 +45,7 @@
5245

5346
<com.noober.background.view.BLView
5447
android:id="@+id/v_anim"
48+
android:layout_marginTop="10dp"
5549
android:layout_width="wrap_content"
5650
android:layout_height="wrap_content"
5751
app:bl_anim_auto_start="true"
@@ -79,7 +73,7 @@
7973
android:layout_height="36dp"
8074
android:layout_marginTop="15dp"
8175
android:gravity="center"
82-
android:text="COBB ANGLE"
76+
android:text="点击填充变色"
8377
android:textColor="@android:color/black"
8478
android:textSize="18dp"
8579
android:textStyle="bold"

build.gradle

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

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

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
import android.content.Context;
44
import android.content.res.ColorStateList;
55
import android.content.res.TypedArray;
6+
import android.graphics.Outline;
67
import android.graphics.drawable.AnimationDrawable;
78
import android.graphics.drawable.Drawable;
89
import android.graphics.drawable.GradientDrawable;
10+
import android.graphics.drawable.LayerDrawable;
911
import android.graphics.drawable.RippleDrawable;
1012
import android.graphics.drawable.StateListDrawable;
1113
import android.os.Build;
@@ -17,6 +19,7 @@
1719
import android.view.InflateException;
1820
import android.view.LayoutInflater;
1921
import android.view.View;
22+
import android.view.ViewOutlineProvider;
2023
import android.widget.CompoundButton;
2124
import android.widget.TextView;
2225

@@ -148,21 +151,21 @@ private static View setViewBackground(String name, Context context, AttributeSet
148151
} else if (selectorTa.getIndexCount() > 0) {
149152
stateListDrawable = DrawableFactory.getSelectorDrawable(typedArray, selectorTa);
150153
view.setClickable(true);
151-
setDrawable(stateListDrawable, view, otherTa);
154+
setDrawable(stateListDrawable, view, otherTa, typedArray);
152155
} else if (pressTa.getIndexCount() > 0) {
153156
drawable = DrawableFactory.getDrawable(typedArray);
154157
stateListDrawable = DrawableFactory.getPressDrawable(drawable, typedArray, pressTa);
155158
view.setClickable(true);
156-
setDrawable(stateListDrawable, view, otherTa);
159+
setDrawable(stateListDrawable, view, otherTa, typedArray);
157160
} else if(multiSelTa.getIndexCount() > 0){
158161
stateListDrawable = DrawableFactory.getMultiSelectorDrawable(context, multiSelTa, typedArray);
159-
setBackground(stateListDrawable, view);
162+
setBackground(stateListDrawable, view, typedArray);
160163
} else if(typedArray.getIndexCount() > 0){
161164
drawable = DrawableFactory.getDrawable(typedArray);
162-
setDrawable(drawable, view, otherTa);
165+
setDrawable(drawable, view, otherTa, typedArray);
163166
} else if(animTa.getIndexCount() > 0){
164167
AnimationDrawable animationDrawable = DrawableFactory.getAnimationDrawable(animTa);
165-
setBackground(animationDrawable, view);
168+
setBackground(animationDrawable, view, typedArray);
166169
if(animTa.getBoolean(R.styleable.bl_anim_bl_anim_auto_start, false)){
167170
animationDrawable.start();
168171
}
@@ -181,17 +184,18 @@ private static View setViewBackground(String name, Context context, AttributeSet
181184
Drawable contentDrawable = (stateListDrawable == null ? drawable : stateListDrawable);
182185
RippleDrawable rippleDrawable = new RippleDrawable(ColorStateList.valueOf(color), contentDrawable, contentDrawable);
183186
view.setClickable(true);
184-
view.setBackground(rippleDrawable);
187+
setBackground(rippleDrawable, view, typedArray);
185188
} else if(stateListDrawable == null){
186189
StateListDrawable tmpDrawable = new StateListDrawable();
187190
GradientDrawable unPressDrawable = DrawableFactory.getDrawable(typedArray);
188191
unPressDrawable.setColor(color);
189192
tmpDrawable.addState(new int[]{-android.R.attr.state_pressed}, drawable);
190193
tmpDrawable.addState(new int[]{android.R.attr.state_pressed}, unPressDrawable);
191194
view.setClickable(true);
192-
setDrawable(tmpDrawable, view, otherTa);
195+
setDrawable(tmpDrawable, view, otherTa, typedArray);
193196
}
194197
}
198+
195199
return view;
196200
} catch (Exception e) {
197201
e.printStackTrace();
@@ -209,7 +213,7 @@ private static View setViewBackground(String name, Context context, AttributeSet
209213
}
210214
}
211215

212-
private static void setDrawable(Drawable drawable, View view, TypedArray otherTa){
216+
private static void setDrawable(Drawable drawable, View view, TypedArray otherTa, TypedArray typedArray){
213217

214218
if(view instanceof TextView){
215219
if(otherTa.hasValue(R.styleable.bl_other_bl_position)){
@@ -227,22 +231,43 @@ private static void setDrawable(Drawable drawable, View view, TypedArray otherTa
227231
((TextView)view).setCompoundDrawables(null, null, null, drawable);
228232
}
229233
}else {
230-
setBackground(drawable, view);
234+
setBackground(drawable, view, typedArray);
231235
}
232236
}else {
233-
setBackground(drawable, view);
237+
setBackground(drawable, view, typedArray);
234238
}
235239

236240
}
237241

238-
private static void setBackground(Drawable drawable, View view) {
242+
private static void setBackground(Drawable drawable, View view, TypedArray typedArray) {
243+
if(typedArray.hasValue(R.styleable.background_bl_stroke_width) && typedArray.hasValue(R.styleable.background_bl_stroke_position)){
244+
//bl_stroke_position flag默认值
245+
int left = 1 << 1;
246+
int top = 1 << 2;
247+
int right = 1 << 3;
248+
int bottom = 1 << 4;
249+
float width = typedArray.getDimension(R.styleable.background_bl_stroke_width, 0f);
250+
int position = typedArray.getInt(R.styleable.background_bl_stroke_position, 0);
251+
float leftValue = hasStatus(position, left) ? width : - width;
252+
float topValue = hasStatus(position, top) ? width : - width;
253+
float rightValue = hasStatus(position, right) ? width : - width;
254+
float bottomValue = hasStatus(position, bottom) ? width : - width;
255+
drawable = new LayerDrawable(new Drawable[]{drawable});
256+
((LayerDrawable)drawable).setLayerInset(0, (int)leftValue, (int)topValue, (int)rightValue, (int)bottomValue);
257+
}
258+
239259
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
240260
view.setBackground(drawable);
241261
} else {
242262
view.setBackgroundDrawable(drawable);
243263
}
244264
}
245265

266+
private static boolean hasStatus(int flag, int status) {
267+
return (flag & status) == status;
268+
}
269+
270+
246271
public void setInterceptFactory(LayoutInflater.Factory factory) {
247272
mViewCreateFactory = factory;
248273
}

library/src/main/res/values/attrs.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@
117117
<attr name="bl_unSelected_solid_color" format="color" />
118118
<attr name="bl_unPressed_solid_color" format="color" />
119119
<attr name="bl_unFocused_solid_color" format="color" />
120+
121+
<attr name="bl_stroke_position" format="flags">
122+
<flag name="left" value="2" />
123+
<flag name="top" value="4" />
124+
<flag name="right" value="8" />
125+
<flag name="bottom" value="16" />
126+
</attr>
120127
</declare-styleable>
121128

122129
<declare-styleable name="background_press">

0 commit comments

Comments
 (0)