Skip to content

Commit

Permalink
update to 1.6.3
Browse files Browse the repository at this point in the history
  • Loading branch information
JavaNoober committed Jan 8, 2020
1 parent 3bee275 commit c97b677
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README-EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ 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.6.2'
implementation 'com.noober.background:core:1.6.3'

if use androidx:

implementation "androidx.appcompat:appcompat:$supportVersion"
implementation 'com.noober.background:core:1.6.2'
implementation 'com.noober.background:core:1.6.3'


## Example effect
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ 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.6.2'
implementation 'com.noober.background:core:1.6.3'

如果项目使用了androidx:

implementation "androidx.appcompat:appcompat:$supportVersion"
implementation 'com.noober.background:core:1.6.2'
implementation 'com.noober.background:core:1.6.3'


## 使用文档
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.2'
publishVersion = '1.6.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
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@

import android.annotation.TargetApi;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.RippleDrawable;
import android.graphics.drawable.StateListDrawable;
import android.os.Build;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.TextView;

import com.noober.background.R;

import java.lang.reflect.Field;
import java.util.ArrayList;
Expand Down Expand Up @@ -41,6 +46,12 @@ public enum Gradient {
}
}

public enum DrawablePosition {

Left, Right, Top, Bottom

}

public static class Builder {
private Shape shape = Shape.Rectangle;
private Integer solidColor;
Expand Down Expand Up @@ -899,6 +910,38 @@ StateListDrawable getStateListDrawable(StateListDrawable stateListDrawable) {
}
return stateListDrawable;
}
}

// 设置drawable的位置
public static void setDrawable(Drawable drawable, View view, DrawablePosition drawablePosition) {

if (view instanceof TextView) {
if (drawablePosition == DrawablePosition.Left) {
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
((TextView) view).setCompoundDrawables(drawable, null, null, null);
} else if (drawablePosition == DrawablePosition.Top) {
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
((TextView) view).setCompoundDrawables(null, drawable, null, null);
} else if (drawablePosition == DrawablePosition.Right) {
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
((TextView) view).setCompoundDrawables(null, null, drawable, null);
} else if (drawablePosition == DrawablePosition.Bottom) {
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
((TextView) view).setCompoundDrawables(null, null, null, drawable);
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
view.setBackground(drawable);
} else {
view.setBackgroundDrawable(drawable);
}
}
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
view.setBackground(drawable);
} else {
view.setBackgroundDrawable(drawable);
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import android.graphics.drawable.RippleDrawable;
import android.graphics.drawable.StateListDrawable;
import android.os.Build;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

Expand Down Expand Up @@ -42,6 +44,12 @@ public enum Gradient {
}
}

public enum DrawablePosition {

Left, Right, Top, Bottom

}

public static class Builder {
private Shape shape = Shape.Rectangle;
private Integer solidColor;
Expand Down Expand Up @@ -902,4 +910,38 @@ StateListDrawable getStateListDrawable(StateListDrawable stateListDrawable) {
}

}


// 设置drawable的位置
public static void setDrawable(Drawable drawable, View view, DrawablePosition drawablePosition) {

if (view instanceof TextView) {
if (drawablePosition == DrawablePosition.Left) {
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
((TextView) view).setCompoundDrawables(drawable, null, null, null);
} else if (drawablePosition == DrawablePosition.Top) {
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
((TextView) view).setCompoundDrawables(null, drawable, null, null);
} else if (drawablePosition == DrawablePosition.Right) {
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
((TextView) view).setCompoundDrawables(null, null, drawable, null);
} else if (drawablePosition == DrawablePosition.Bottom) {
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
((TextView) view).setCompoundDrawables(null, null, null, drawable);
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
view.setBackground(drawable);
} else {
view.setBackgroundDrawable(drawable);
}
}
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
view.setBackground(drawable);
} else {
view.setBackgroundDrawable(drawable);
}
}

}
}

0 comments on commit c97b677

Please sign in to comment.