Skip to content

Commit

Permalink
2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rtugeek committed Oct 8, 2021
1 parent 55e424b commit 0fa4adf
Show file tree
Hide file tree
Showing 32 changed files with 1,661 additions and 1,003 deletions.
169 changes: 94 additions & 75 deletions README.md
Expand Up @@ -2,34 +2,52 @@

### ScreenShot:

![](https://github.com/rtugeek/ColorSeekBar/blob/master/screenshot/screenshot.gif)

### Attrs
|attr|format|default|
|---|:---|:---:|
|colorSeeds|references||
|colorBarPosition|integer|0|
|alphaBarPosition|integer|0|
|maxPosition|integer|100|
|bgColor|color|TRANSPARENT|
|barHeight|dimension|2dp|
|barMargin|dimension|5dp|
|thumbHeight|dimension|30dp|
|showAlphaBar|boolean|false|
|showColorBar|boolean|true|
|isVertical|boolean|false|
|disabledColor|color|Color.GRAY|
|showThumb|boolean|true|
|barRadius|dimension|0px|
![](https://github.com/rtugeek/ColorSeekBar/blob/master/screenshot/color.jpg)
![](https://github.com/rtugeek/ColorSeekBar/blob/master/screenshot/alpha.jpg)

### ColorSeekbar Attrs

```xml

<declare-styleable name="ColorSeekBar">
<attr name="colorSeekBarColorSeeds" format="reference" />
<attr name="colorSeekBarBarHeight" format="dimension" />
<attr name="colorSeekBarProgress" format="integer" />
<attr name="colorSeekBarRadius" format="dimension" />
<attr name="colorSeekBarMaxProgress" format="integer" />
<attr name="colorSeekBarVertical" format="boolean" />
<attr name="colorSeekBarShowThumb" format="boolean" />
<attr name="colorSeekBarBorderColor" format="color" />
<attr name="colorSeekBarBorderSize" format="dimension" />
</declare-styleable>
```

### AlphaSeekbar Attrs

```xml

<declare-styleable name="AlphaSeekBar">
<attr name="alphaSeekBarHeight" format="dimension" />
<attr name="alphaSeekBarRadius" format="dimension" />
<attr name="alphaSeekBarShowGrid" format="boolean" />
<attr name="alphaSeekBarShowThumb" format="boolean" />
<attr name="alphaSeekBarSizeGrid" format="dimension" />
<attr name="alphaSeekBarProgress" format="integer" />
<attr name="alphaSeekBarVertical" format="boolean" />
<attr name="alphaSeekBarMaxProgress" format="integer" />
<attr name="alphaSeekBarBorderColor" format="color" />
<attr name="alphaSeekBarBorderSize" format="dimension" />
</declare-styleable>
```

### Gradle:

<a href="https://jitpack.io/#rtugeek/colorseekbar">![Release](https://jitpack.io/v/rtugeek/colorseekbar.svg)</a>
<a href="https://android-arsenal.com/api?level=14">![API](https://img.shields.io/badge/API-14%2B-brightgreen.svg?style=flat)</a>
<a href="https://android-arsenal.com/details/1/3118">![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-ColorSeekBar-green.svg?style=true)</a>

Step 1. Add the JitPack repository in your root build.gradle at the end of repositories:

```
allprojects {
repositories {
Expand All @@ -38,82 +56,83 @@ allprojects {
}
}
```

Step 2. Add the dependency

```
implementation 'com.github.rtugeek:colorseekbar:1.7.7'
implementation 'com.github.rtugeek:colorseekbar:2.0.0'
```

## Usage
## Usage

XML

```xml
<com.rtugeek.android.colorseekbar.ColorSeekBar
android:id="@+id/colorSlider"
android:layout_width="match_parent"
app:colorSeeds="@array/material_colors"
android:layout_height="wrap_content" />
<com.rtugeek.android.colorseekbar.ColorSeekBar
android:id="@+id/colorSeekBar"
android:layout_width="match_parent"
app:colorSeeds="@array/material_colors"
android:layout_height="wrap_content" />

<com.rtugeek.android.colorseekbar.AlphaSeekBar
android:id="@+id/alphaSeekBar"
android:layout_width="match_parent"
app:colorSeeds="@array/material_colors"
android:layout_height="wrap_content" />
```

JAVA
```java
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
colorSeekBar.setBarMargin(10); //set the margin between colorBar and alphaBar 10dpi
Kotlin

```kotlin
colorSeekBar.maxProgress = 1000
colorSeekBar.progress = 50
colorSeekBar.borderColor = Color.BLACK
colorSeekBar.borderRadius = 10
colorSeekBar.borderSize = 10
colorSeekBar.thumbDrawer = DefaultThumbDrawer(30,Color.WHITE,Color.BLUE)
colorSeekBar.isVertical = false
colorSeekBar.barHeight = 10

alphaSeekBar.maxProgress = 1000
alphaSeekBar.borderColor = Color.BLACK
alphaSeekBar.borderRadius = 10
alphaSeekBar.borderSize = 10
alphaSeekBar.thumbDrawer = DefaultThumbDrawer(30,Color.WHITE,Color.BLUE)
alphaSeekBar.isVertical = false
alphaSeekBar.barHeight = 10
```

Listener

```java
colorSeekBar.setOnColorChangeListener(new ColorSeekBar.OnColorChangeListener() {
@Override
public void onColorChangeListener(int colorBarPosition, int alphaBarPosition, int color) {
textView.setTextColor(color);
//colorSeekBar.getAlphaValue();
}
});
```
colorSeekBar.setOnColorChangeListener { progress, color ->
Log.i("TAG", "===progress:$progress-color:$color===")
}

## Vertical Bar
```xml
<com.rtugeek.android.colorseekbar.ColorSeekBar
android:id="@+id/colorSlider"
android:layout_width="match_parent"
app:colorSeeds="@array/material_colors"
app:isVertical="true"
android:layout_height="wrap_content" />
alphaSeekBar.setOnAlphaChangeListener { progress, alpha ->
Log.i("AlphaSeekBarFragment", "===progress:$progress-alpha:$alpha===")
}
```
![](https://github.com/rtugeek/ColorSeekBar/blob/master/screenshot/vertical.png)

Thumb Drawer
- com.rtugeek.android.colorseekbar.thumb.DefaultThumbDrawer
- com.rtugeek.android.colorseekbar.thumb.DrawableThumbDrawer - Load thumb from drawable resource
- com.rtugeek.android.colorseekbar.thumb.ThumbDrawer - Implement this interface if you want to customize thumb

## getColor() issue
Render flow:
1.Activity->onCreate();
2.Activity->onResume();
3.ColorSeekBar->onMeasure();
4.ColorSeekBar->onSizeChanged();
5.ColorSeekBar->init();
6.ColorSeekBar->onMeasure();
7.ColorSeekBar->onDraw();
## Vertical Bar

getColor()/getColors()/getColorIndexPosition() do not work correct until onDraw() method invoked.
So, If you want to get color or something else form ColorSeekBar on Activity.onCreate() function, just do:
```java
mColorSeekBar.setOnInitDoneListener(new ColorSeekBar.OnInitDoneListener() {
@Override` `
public void done() {
mColorSeekBar.getColorIndexPosition(mColor);
//mColorSeekBar.getColors();
//mColorSeekBar.getColor();
}
});
```xml

<com.rtugeek.android.colorseekbar.ColorSeekBar
android:id="@+id/colorSlider"
android:layout_width="match_parent"
app:colorSeeds="@array/material_colors"
app:colorSeekBarVertical="true"
android:layout_height="wrap_content" />
```

![](https://github.com/rtugeek/ColorSeekBar/blob/master/screenshot/vertical.png)

**Spread the word**

<a href="https://twitter.com/intent/tweet?text=Check%20out%20the%20ColorSeekBar%20library%20on%20Github:%20https://github.com/rtugeek/ColorSeekBar/" target="_blank" title="share to twitter" style="width:100%"><img src="https://github.com/PhilJay/MPAndroidChart/blob/master/design/twitter_icon.png" title="Share on Twitter" width="35" height=35 />
Expand Down
23 changes: 19 additions & 4 deletions app/build.gradle
@@ -1,11 +1,13 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
compileSdkVersion 30
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.rtugeek.android.colorseekbardemo"
minSdkVersion 14
targetSdkVersion 27
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
}
Expand All @@ -17,10 +19,23 @@ android {
}
productFlavors {
}
buildFeatures {
viewBinding true
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(':colorseekbar')
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation "androidx.core:core-ktx:1.5.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
}
repositories {
mavenCentral()
}
5 changes: 4 additions & 1 deletion app/src/main/AndroidManifest.xml
Expand Up @@ -8,7 +8,10 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity
android:name=".ColorSeekBarActivity"
android:label="@string/title_activity_color_seek_bar"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
@@ -0,0 +1,32 @@
package com.rtugeek.android.colorseekbardemo

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.tabs.TabLayoutMediator
import com.rtugeek.android.colorseekbardemo.databinding.ActivityMainBinding
import com.rtugeek.android.colorseekbardemo.fragment.SectionsPagerAdapter
import kotlinx.android.synthetic.main.activity_main.*

private val TAB_TITLES = arrayOf(
R.string.color,
R.string.alpha
)

class ColorSeekBarActivity : AppCompatActivity() {

private lateinit var binding: ActivityMainBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)

val sectionsPagerAdapter = SectionsPagerAdapter(this)
view_pager.adapter = sectionsPagerAdapter
view_pager.isUserInputEnabled = false
TabLayoutMediator(binding.tabs, view_pager) { tab, position ->
tab.text = getString(TAB_TITLES[position])
}.attach()
}
}

0 comments on commit 0fa4adf

Please sign in to comment.