Skip to content

Commit

Permalink
feat. append color settings
Browse files Browse the repository at this point in the history
  • Loading branch information
iielse committed Jul 10, 2019
1 parent c9255d1 commit 6b43433
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
6 changes: 3 additions & 3 deletions switchbutton/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

version = "1.0.1"
version = "1.0.2"
group = "ch.ielse" // Maven Group ID for the artifact,一般填你唯一的包名
def siteUrl = 'https://github.com/iielse/SwitchButton' // 项目的主页
def gitUrl = 'https://github.com/iielse/SwitchButton.git' // Git仓库的url
Expand All @@ -15,8 +15,8 @@ android {
defaultConfig {
minSdkVersion 10
targetSdkVersion 23
versionCode 1
versionName "1.0.1"
versionCode 2
versionName "1.0.2"
}
buildTypes {
release {
Expand Down
19 changes: 17 additions & 2 deletions switchbutton/src/main/java/ch/ielse/view/SwitchView.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class SwitchView extends View {
protected int colorOff;
protected int colorOffDark;
protected int colorShadow;
protected int colorBar;
protected int colorBackground;
protected boolean hasShadow;
protected boolean isOpened;

Expand Down Expand Up @@ -83,6 +85,8 @@ public SwitchView(Context context, AttributeSet attrs) {
colorOff = a.getColor(R.styleable.SwitchView_offColor, 0xFFE3E3E3);
colorOffDark = a.getColor(R.styleable.SwitchView_offColorDark, 0xFFBFBFBF);
colorShadow = a.getColor(R.styleable.SwitchView_shadowColor, 0xFF333333);
colorBar = a.getColor(R.styleable.SwitchView_barColor, 0xFFFFFFFF);
colorBackground = a.getColor(R.styleable.SwitchView_bgColor, 0xFFFFFFFF);
ratioAspect = a.getFloat(R.styleable.SwitchView_ratioAspect, 0.68f);
hasShadow = a.getBoolean(R.styleable.SwitchView_hasShadow, true);
isOpened = a.getBoolean(R.styleable.SwitchView_isOpened, false);
Expand Down Expand Up @@ -123,6 +127,17 @@ public void setColor(int newColorPrimary, int newColorPrimaryDark, int newColorO
invalidate();
}

public void setColor(int newColorPrimary, int newColorPrimaryDark, int newColorOff, int newColorOffDark, int newColorShadow, int newColorBar, int newColorBackground) {
colorPrimary = newColorPrimary;
colorPrimaryDark = newColorPrimaryDark;
colorOff = newColorOff;
colorOffDark = newColorOffDark;
colorShadow = newColorShadow;
colorBar = newColorBar;
colorBackgorund = newColorBackground;
invalidate();
}

public void setShadow(boolean shadow) {
hasShadow = shadow;
invalidate();
Expand Down Expand Up @@ -353,7 +368,7 @@ protected void onDraw(Canvas canvas) {
final float scaleOffset = (sRight - sCenterX - bRadius) * (isOn ? 1 - dsAnim : dsAnim);
canvas.save();
canvas.scale(scale, scale, sCenterX + scaleOffset, sCenterY);
paint.setColor(0xFFFFFFFF);
paint.setColor(colorBackground);
canvas.drawPath(sPath, paint);
canvas.restore();
// To prepare center bar path
Expand All @@ -372,7 +387,7 @@ protected void onDraw(Canvas canvas) {
// draw bar
canvas.scale(0.98f, 0.98f, bWidth / 2, bWidth / 2);
paint.setStyle(Paint.Style.FILL);
paint.setColor(0xffffffff);
paint.setColor(colorBar);
canvas.drawPath(bPath, paint);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(bStrokeWidth * 0.5f);
Expand Down
2 changes: 2 additions & 0 deletions switchbutton/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<attr name="primaryColorDark" format="color"/>
<attr name="offColor" format="color"/>
<attr name="offColorDark" format="color"/>
<attr name="barColor" format="color"/>
<attr name="bgColor" format="color"/>
<attr name="shadowColor" format="color"/>
<attr name="ratioAspect" format="float"/>
<attr name="isOpened" format="boolean"/>
Expand Down

0 comments on commit 6b43433

Please sign in to comment.