From 43579fe635fcfb5e689beba51b00576cde369288 Mon Sep 17 00:00:00 2001
From: "rtugeek@gmail.com" <47328663>
Date: Tue, 31 Mar 2020 19:43:56 +0800
Subject: [PATCH] Add method setPosition() , setShowColorBar() ,
getIsShowColorBar()
---
README.md | 5 +-
app/build.gradle | 4 +-
.../colorseekbardemo/MainActivity.java | 17 ++-
app/src/main/res/layout/activity_main.xml | 12 +++
build.gradle | 5 +-
colorseekbar/build.gradle | 8 +-
.../android/colorseekbar/ColorSeekBar.java | 100 +++++++++++-------
colorseekbar/src/main/res/values/attrs.xml | 1 +
gradle.properties | 4 +-
9 files changed, 106 insertions(+), 50 deletions(-)
diff --git a/README.md b/README.md
index b5c2f60..8f22e5c 100644
--- a/README.md
+++ b/README.md
@@ -16,6 +16,7 @@
|barMargin|dimension|5dp|
|thumbHeight|dimension|30dp|
|showAlphaBar|boolean|false|
+|showColorBar|boolean|true|
|isVertical|boolean|false|
|disabledColor|color|Color.GRAY|
|showThumb|boolean|true|
@@ -39,7 +40,7 @@ allprojects {
```
Step 2. Add the dependency
```
-implementation 'com.github.rtugeek:colorseekbar:1.7.5'
+implementation 'com.github.rtugeek:colorseekbar:1.7.6'
```
## Usage
@@ -59,6 +60,8 @@ colorSeekBar.setMaxPosition(100);
colorSeekBar.setColorSeeds(R.array.material_colors); // material_colors is defalut included in res/color,just use it.
colorSeekBar.setColorBarPosition(10); //0 - maxValue
colorSeekBar.setAlphaBarPosition(10); //0 - 255
+colorSeekBar.setPosition(10,10); // An easier way to set ColorBar and AlphaBar
+
colorSeekBar.setShowAlphaBar(true);
colorSeekBar.setBarHeight(5); //5dpi
colorSeekBar.setThumbHeight(30); //30dpi
diff --git a/app/build.gradle b/app/build.gradle
index 187f949..2105387 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,6 +1,6 @@
apply plugin: 'com.android.application'
android {
- compileSdkVersion 27
+ compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.rtugeek.android.colorseekbardemo"
@@ -22,5 +22,5 @@ android {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(':colorseekbar')
- implementation 'com.android.support:appcompat-v7:27.1.1'
+ implementation 'androidx.appcompat:appcompat:1.1.0'
}
diff --git a/app/src/main/java/com/rtugeek/android/colorseekbardemo/MainActivity.java b/app/src/main/java/com/rtugeek/android/colorseekbardemo/MainActivity.java
index fb2fb09..613862c 100644
--- a/app/src/main/java/com/rtugeek/android/colorseekbardemo/MainActivity.java
+++ b/app/src/main/java/com/rtugeek/android/colorseekbardemo/MainActivity.java
@@ -3,7 +3,7 @@
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
-import android.support.v7.app.AppCompatActivity;
+import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
import android.widget.CheckBox;
import android.widget.CompoundButton;
@@ -44,6 +44,10 @@ protected void onCreate(Bundle savedInstanceState) {
mColorSeekBar.setThumbHeight(30);
mColorSeekBar.setDisabledColor(Color.GRAY);
+ int colorBarPosition = sp.getInt("colorBarPosition",0);
+ int alphaBarPosition = sp.getInt("alphaBarPosition",0);
+ mColorSeekBar.setPosition(colorBarPosition,alphaBarPosition);
+
mColorSeekBar.setOnInitDoneListener(new ColorSeekBar.OnInitDoneListener() {
@Override
public void done() {
@@ -129,6 +133,13 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
}
});
+ ((CheckBox)findViewById(R.id.chk_show_color_bar)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ mColorSeekBar.setShowColorBar(isChecked);
+ }
+ });
+
((SeekBar)findViewById(R.id.seek_radius)).setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
@@ -146,6 +157,7 @@ public void onStopTrackingTouch(SeekBar seekBar) {
}
});
+
}
@@ -153,6 +165,9 @@ public void onStopTrackingTouch(SeekBar seekBar) {
protected void onStop() {
super.onStop();
spe.putInt("color", mColorSeekBar.getColor());
+ spe.putInt("colorBarPosition", mColorSeekBar.getColorBarPosition());
+ spe.putInt("alphaBarPosition", mColorSeekBar.getAlphaBarPosition());
+ spe.putInt("color", mColorSeekBar.getColor());
spe.putBoolean("showAlpha", mColorSeekBar.isShowAlphaBar());
spe.commit();
}
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 0ef7e88..d0bb940 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -63,6 +63,18 @@
+
+
+
mMaxPosition ? mMaxPosition : mColorBarPosition;
mColorBarPosition = mColorBarPosition < 0 ? 0 : mColorBarPosition;
+ this.mAlphaBarPosition = alphaBarPosition;
+ setAlphaValue();
invalidate();
if (mOnColorChangeLister != null) {
mOnColorChangeLister.onColorChangeListener(mColorBarPosition, mAlphaBarPosition, getColor());
}
}
-
public void setOnInitDoneListener(OnInitDoneListener listener) {
this.mOnInitDoneListener = listener;
}
@@ -760,6 +774,7 @@ public int getBarRadius() {
/**
* Set bar radius with px unit
+ *
* @param barRadiusInPx
*/
public void setBarRadius(int barRadiusInPx) {
@@ -767,4 +782,13 @@ public void setBarRadius(int barRadiusInPx) {
invalidate();
}
+ public boolean isIsShowColorBar() {
+ return mIsShowColorBar;
+ }
+
+ public void setShowColorBar(boolean isShowColorBar) {
+ this.mIsShowColorBar = isShowColorBar;
+ refreshLayoutParams();
+ invalidate();
+ }
}
diff --git a/colorseekbar/src/main/res/values/attrs.xml b/colorseekbar/src/main/res/values/attrs.xml
index 163751e..a7e3930 100644
--- a/colorseekbar/src/main/res/values/attrs.xml
+++ b/colorseekbar/src/main/res/values/attrs.xml
@@ -5,6 +5,7 @@
+
diff --git a/gradle.properties b/gradle.properties
index 1d3591c..915f0e6 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -15,4 +15,6 @@
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
-# org.gradle.parallel=true
\ No newline at end of file
+# org.gradle.parallel=true
+android.enableJetifier=true
+android.useAndroidX=true
\ No newline at end of file