From 6b434334d6180db2a607b047fe6d6d97edd531d8 Mon Sep 17 00:00:00 2001 From: else <517309507@qq.com> Date: Wed, 10 Jul 2019 17:31:47 +0800 Subject: [PATCH] feat. append color settings --- switchbutton/build.gradle | 6 +++--- .../main/java/ch/ielse/view/SwitchView.java | 19 +++++++++++++++++-- switchbutton/src/main/res/values/attrs.xml | 2 ++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/switchbutton/build.gradle b/switchbutton/build.gradle index 95351df..968b033 100644 --- a/switchbutton/build.gradle +++ b/switchbutton/build.gradle @@ -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 @@ -15,8 +15,8 @@ android { defaultConfig { minSdkVersion 10 targetSdkVersion 23 - versionCode 1 - versionName "1.0.1" + versionCode 2 + versionName "1.0.2" } buildTypes { release { diff --git a/switchbutton/src/main/java/ch/ielse/view/SwitchView.java b/switchbutton/src/main/java/ch/ielse/view/SwitchView.java index 5c0c05a..18504ba 100644 --- a/switchbutton/src/main/java/ch/ielse/view/SwitchView.java +++ b/switchbutton/src/main/java/ch/ielse/view/SwitchView.java @@ -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; @@ -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); @@ -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(); @@ -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 @@ -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); diff --git a/switchbutton/src/main/res/values/attrs.xml b/switchbutton/src/main/res/values/attrs.xml index 88da4c3..858b521 100644 --- a/switchbutton/src/main/res/values/attrs.xml +++ b/switchbutton/src/main/res/values/attrs.xml @@ -5,6 +5,8 @@ + +