https://github.com/irontec/inkslider
https://github.com/irontec/inkslider
Last synced: 7 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/irontec/inkslider
- Owner: irontec
- License: gpl-3.0
- Created: 2019-08-26T13:13:58.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2021-09-09T10:34:48.000Z (almost 5 years ago)
- Last Synced: 2025-01-31T04:53:53.267Z (over 1 year ago)
- Language: Kotlin
- Size: 366 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# InkSliderLibraryProject
[](https://jitpack.io/#irontec/InkSlider)
Library to make fancy selector sliders. Indicators can be shown on both sides, one or none. Values and colors are not linked, so you can have a lot more values than colors.
# Parametrization
## By code
* *color*: Color resource id list.
* *values*: Values (**Item** below) list to select.
* *currentItem*: currently selected item.
* *onValueSet*: listener when a values is **selected**. When the user releases the touch.
* *onValueChange*: listener when a value is **displayed**. When the user moves the finger and the value changes.
* *hardSteps*: Defines if the marker can stop in any place when user press released, or only on some hard points (the center of the realm associated with a value)
* *enabled*: if view is enabled or disabled.
* *displayMode*. Values: LEFT, RIGHT, BOTH.
* *Item*
* *value*: **Any**. Put here what you want the user to be able to select.
* *display*: **Display** class (below)
* *selectable*: If this value is selectable. I use it to add some unselectable values on top or bottom if limits should not be selectable.
* *Display*
* *string*: indicator text value (optional)
* *textColor*: indicator text color (optional)
* *arrowTintColor*: indicator arrow tint color (optional)
* *iconTintColor*: indicator icon tint color (optional)
* *icon*: indicator icon (optional)
## By XML
### Dimension
```XML
17dp
18dp
33sp
60dp
60dp
10dp
20dp
50dp
1.5dp
24dp
48dp
72dp
72dp
64dp
64dp
64dp
64dp
64dp
64dp
64dp
64dp
16dp
16dp
16dp
```
### Colors
```XML
@color/colorprimary
@color/colorprimaryripple
#FFF
#FFF
```
# Examples
Temperature slider class:
```kt
import android.content.Context
import android.util.AttributeSet
import com.inlacou.inkslider.BaseInkSlider
import com.inlacou.inkslider.InkSliderMdl
import com.inlacou.inksliderlibraryproject.R
class BasicTemperatureSlider @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0)
: InkSlider(context, attrs, defStyleAttr){
var onValueSet: ((InkSliderMdl.Item, fromUser: Boolean) -> Unit)? = null
var onValueChange: ((InkSliderMdl.Item, fromUser: Boolean) -> Unit)? = null
val colors = context.resources?.getIntArray(R.array.temperature_slider)?.toList() ?: listOf()
val temperatures: List
init {
temperatures = (170 .. 270)
.filter { it.toString().last()=='0' || it.toString().last()=='5' }
.map { it.toDouble() }.reversed()
.mapIndexed { index, it -> InkSliderMdl.Item(value = it / 10, display = InkSliderMdl.Display("${it / 10}º", textColor = colors[(index + 1) / 2])) }
.toMutableList()
temperatures.add(0, InkSliderMdl.Item(value = 27, display = InkSliderMdl.Display(string = "27.0º", textColor = colors[0]), selectable = false))
model = InkSliderMdl(
colors = colors
, values = temperatures
, onValueSet = { item: InkSliderMdl.Item, b: Boolean ->
onValueSet?.invoke(item, b)
}, onValueChange = { item: InkSliderMdl.Item, b: Boolean ->
onValueChange?.invoke(item, b)
})
}
}
```
Sound slider class:
```kt
import android.content.Context
import android.util.AttributeSet
import com.inlacou.inkslider.BaseInkSlider
import com.inlacou.inkslider.InkSliderMdl
import com.inlacou.inksliderlibraryproject.R
class BasicSoundSlider @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0)
: InkSlider(context, attrs, defStyleAttr) {
var onValueSet: ((InkSliderMdl.Item, fromUser: Boolean) -> Unit)? = null
var onValueChange: ((InkSliderMdl.Item, fromUser: Boolean) -> Unit)? = null
val colors = context.resources?.getIntArray(R.array.sound_slider)?.toList() ?: listOf()
var icons: List = listOf()
init {
context.resources?.obtainTypedArray(R.array.sounds)?.let { array ->
icons = (0 until array.length())
.reversed()
.mapIndexed { index, it ->
InkSliderMdl.Item(value = it, selectable = index != 0, display = InkSliderMdl.Display(icon = array.getResourceId(index, -1)))
}
model = InkSliderMdl(
colors = colors
, values = icons
, onValueSet = { item: InkSliderMdl.Item, b: Boolean ->
onValueSet?.invoke(item, b)
}, onValueChange = { item: InkSliderMdl.Item, b: Boolean ->
onValueChange?.invoke(item, b)
})
array.recycle()
}
}
}
```