Skip to content

Commit

Permalink
update to 1.5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
JavaNoober committed Jul 30, 2019
1 parent e564785 commit 34069d4
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions BackgroundLibrary.xml
Original file line number Diff line number Diff line change
Expand Up @@ -767,4 +767,10 @@
<option name="XML" value="true" />
</context>
</template>
<template name="bl_stroke_position" value="app:bl_stroke_position=&quot;$value$&quot;" description="指定显示某个方向的边框" toReformat="true" toShortenFQNames="true">
<variable name="value" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="XML" value="true" />
</context>
</template>
</templateSet>
3 changes: 2 additions & 1 deletion README-EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ A framework for directly generating shape through Tags, no need to write shape.x
Add this to your app's build.gradle:

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


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

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

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ A framework for directly generating shape through Tags, no need to write shape.x
依赖方式:

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

## 使用文档

Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ 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.5.2'
// implementation project(':library')
// implementation 'com.noober.background:core:1.5.2'
implementation project(':library')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
// implementation 'com.trello.rxlifecycle3:rxlifecycle:3.0.0'
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,16 @@
import android.widget.Button;
import android.widget.TextView;

import com.noober.background.BackgroundLibrary;
import com.noober.background.drawable.DrawableCreator;
import com.noober.background.view.BLTextView;

public class MainActivity extends AppCompatActivity {

Button blTextView;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView( R.layout.activity_main);
getSupportFragmentManager().beginTransaction().add(R.id.fl_content, new BlankFragment()).commitAllowingStateLoss();
Button button = findViewById(R.id.btn);
blTextView = findViewById(R.id.ttt);

button.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down
28 changes: 11 additions & 17 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,26 @@
tools:ignore="MissingPrefix">


<Button
android:layout_width="130dp"
android:layout_height="36dp"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="TextView"
android:textSize="20sp"
android:background="@drawable/shape_login_button" />

<com.noober.background.view.BLButton
android:layout_width="130dp"
<com.noober.background.view.BLTextView
android:layout_width="wrap_content"
android:layout_height="36dp"
android:layout_marginTop="5dp"
android:background="@null"
android:gravity="center"
android:text="TextView"
android:text="指定只显示左右下方的边框"
android:textSize="20sp"
app:bl_solid_color="#2fdcb5"
app:bl_corners_radius="7dp" />
app:bl_stroke_width="1dp"
app:bl_stroke_color="@android:color/black"
app:bl_solid_color="@android:color/white"
app:bl_stroke_position="left|bottom|right"/>

<com.noober.background.view.BLTextView
android:id="@+id/ttt"
android:layout_width="130dp"
android:layout_width="wrap_content"
android:layout_height="36dp"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="TextView"
android:text="虚线圆角边框以及填充"
android:textColor="#8c6822"
android:textSize="20sp"
app:bl_corners_radius="4dp"
Expand All @@ -52,6 +45,7 @@

<com.noober.background.view.BLView
android:id="@+id/v_anim"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:bl_anim_auto_start="true"
Expand Down Expand Up @@ -79,7 +73,7 @@
android:layout_height="36dp"
android:layout_marginTop="15dp"
android:gravity="center"
android:text="COBB ANGLE"
android:text="点击填充变色"
android:textColor="@android:color/black"
android:textSize="18dp"
android:textStyle="bold"
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.5.2'
publishVersion = '1.5.3'
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
47 changes: 36 additions & 11 deletions library/src/main/java/com/noober/background/BackgroundFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Outline;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.RippleDrawable;
import android.graphics.drawable.StateListDrawable;
import android.os.Build;
Expand All @@ -17,6 +19,7 @@
import android.view.InflateException;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewOutlineProvider;
import android.widget.CompoundButton;
import android.widget.TextView;

Expand Down Expand Up @@ -148,21 +151,21 @@ private static View setViewBackground(String name, Context context, AttributeSet
} else if (selectorTa.getIndexCount() > 0) {
stateListDrawable = DrawableFactory.getSelectorDrawable(typedArray, selectorTa);
view.setClickable(true);
setDrawable(stateListDrawable, view, otherTa);
setDrawable(stateListDrawable, view, otherTa, typedArray);
} else if (pressTa.getIndexCount() > 0) {
drawable = DrawableFactory.getDrawable(typedArray);
stateListDrawable = DrawableFactory.getPressDrawable(drawable, typedArray, pressTa);
view.setClickable(true);
setDrawable(stateListDrawable, view, otherTa);
setDrawable(stateListDrawable, view, otherTa, typedArray);
} else if(multiSelTa.getIndexCount() > 0){
stateListDrawable = DrawableFactory.getMultiSelectorDrawable(context, multiSelTa, typedArray);
setBackground(stateListDrawable, view);
setBackground(stateListDrawable, view, typedArray);
} else if(typedArray.getIndexCount() > 0){
drawable = DrawableFactory.getDrawable(typedArray);
setDrawable(drawable, view, otherTa);
setDrawable(drawable, view, otherTa, typedArray);
} else if(animTa.getIndexCount() > 0){
AnimationDrawable animationDrawable = DrawableFactory.getAnimationDrawable(animTa);
setBackground(animationDrawable, view);
setBackground(animationDrawable, view, typedArray);
if(animTa.getBoolean(R.styleable.bl_anim_bl_anim_auto_start, false)){
animationDrawable.start();
}
Expand All @@ -181,17 +184,18 @@ private static View setViewBackground(String name, Context context, AttributeSet
Drawable contentDrawable = (stateListDrawable == null ? drawable : stateListDrawable);
RippleDrawable rippleDrawable = new RippleDrawable(ColorStateList.valueOf(color), contentDrawable, contentDrawable);
view.setClickable(true);
view.setBackground(rippleDrawable);
setBackground(rippleDrawable, view, typedArray);
} else if(stateListDrawable == null){
StateListDrawable tmpDrawable = new StateListDrawable();
GradientDrawable unPressDrawable = DrawableFactory.getDrawable(typedArray);
unPressDrawable.setColor(color);
tmpDrawable.addState(new int[]{-android.R.attr.state_pressed}, drawable);
tmpDrawable.addState(new int[]{android.R.attr.state_pressed}, unPressDrawable);
view.setClickable(true);
setDrawable(tmpDrawable, view, otherTa);
setDrawable(tmpDrawable, view, otherTa, typedArray);
}
}

return view;
} catch (Exception e) {
e.printStackTrace();
Expand All @@ -209,7 +213,7 @@ private static View setViewBackground(String name, Context context, AttributeSet
}
}

private static void setDrawable(Drawable drawable, View view, TypedArray otherTa){
private static void setDrawable(Drawable drawable, View view, TypedArray otherTa, TypedArray typedArray){

if(view instanceof TextView){
if(otherTa.hasValue(R.styleable.bl_other_bl_position)){
Expand All @@ -227,22 +231,43 @@ private static void setDrawable(Drawable drawable, View view, TypedArray otherTa
((TextView)view).setCompoundDrawables(null, null, null, drawable);
}
}else {
setBackground(drawable, view);
setBackground(drawable, view, typedArray);
}
}else {
setBackground(drawable, view);
setBackground(drawable, view, typedArray);
}

}

private static void setBackground(Drawable drawable, View view) {
private static void setBackground(Drawable drawable, View view, TypedArray typedArray) {
if(typedArray.hasValue(R.styleable.background_bl_stroke_width) && typedArray.hasValue(R.styleable.background_bl_stroke_position)){
//bl_stroke_position flag默认值
int left = 1 << 1;
int top = 1 << 2;
int right = 1 << 3;
int bottom = 1 << 4;
float width = typedArray.getDimension(R.styleable.background_bl_stroke_width, 0f);
int position = typedArray.getInt(R.styleable.background_bl_stroke_position, 0);
float leftValue = hasStatus(position, left) ? width : - width;
float topValue = hasStatus(position, top) ? width : - width;
float rightValue = hasStatus(position, right) ? width : - width;
float bottomValue = hasStatus(position, bottom) ? width : - width;
drawable = new LayerDrawable(new Drawable[]{drawable});
((LayerDrawable)drawable).setLayerInset(0, (int)leftValue, (int)topValue, (int)rightValue, (int)bottomValue);
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
view.setBackground(drawable);
} else {
view.setBackgroundDrawable(drawable);
}
}

private static boolean hasStatus(int flag, int status) {
return (flag & status) == status;
}


public void setInterceptFactory(LayoutInflater.Factory factory) {
mViewCreateFactory = factory;
}
Expand Down
7 changes: 7 additions & 0 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@
<attr name="bl_unSelected_solid_color" format="color" />
<attr name="bl_unPressed_solid_color" format="color" />
<attr name="bl_unFocused_solid_color" format="color" />

<attr name="bl_stroke_position" format="flags">
<flag name="left" value="2" />
<flag name="top" value="4" />
<flag name="right" value="8" />
<flag name="bottom" value="16" />
</attr>
</declare-styleable>

<declare-styleable name="background_press">
Expand Down

0 comments on commit 34069d4

Please sign in to comment.