aboutsummaryrefslogtreecommitdiff
path: root/colorpicker/src/main
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2018-02-13 16:51:56 -0500
committerGitHub <noreply@github.com>2018-02-13 16:51:56 -0500
commitcdb1bd6eec2c90abc9d3d982814552443c7fc3b2 (patch)
tree2d21dfcce61fec76384d862b410ee61579169bc2 /colorpicker/src/main
parentf5d6ddb72a3dc369b95631a607471f9a6ea5e70f (diff)
downloadkau-cdb1bd6eec2c90abc9d3d982814552443c7fc3b2.tar.gz
kau-cdb1bd6eec2c90abc9d3d982814552443c7fc3b2.tar.bz2
kau-cdb1bd6eec2c90abc9d3d982814552443c7fc3b2.zip
Update docs (#135)
* Update docs * Update format * Update dependencies
Diffstat (limited to 'colorpicker/src/main')
-rw-r--r--colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/CircleView.kt20
-rw-r--r--colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/ColorPalette.kt2
-rw-r--r--colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/ColorPickerView.kt28
3 files changed, 22 insertions, 28 deletions
diff --git a/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/CircleView.kt b/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/CircleView.kt
index 713b800..c74cba1 100644
--- a/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/CircleView.kt
+++ b/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/CircleView.kt
@@ -47,7 +47,6 @@ class CircleView @JvmOverloads constructor(context: Context, attrs: AttributeSet
private val innerPaint: Paint = Paint().apply { isAntiAlias = true }
private var selected: Boolean = false
var withBorder: Boolean = false
- get() = field
set(value) {
if (field != value) {
field = value
@@ -65,13 +64,13 @@ class CircleView @JvmOverloads constructor(context: Context, attrs: AttributeSet
outerPaint.color = shiftColorDown(color)
val selector = createSelector(color)
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ foreground = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
val states = arrayOf(intArrayOf(android.R.attr.state_pressed))
val colors = intArrayOf(shiftColorUp(color))
val rippleColors = ColorStateList(states, colors)
- foreground = RippleDrawable(rippleColors, selector, null)
+ RippleDrawable(rippleColors, selector, null)
} else {
- foreground = selector
+ selector
}
}
@@ -85,20 +84,17 @@ class CircleView @JvmOverloads constructor(context: Context, attrs: AttributeSet
setBackgroundColorRes(color)
}
-
- @Deprecated("")
+ @Deprecated("Cannot use setBackground() on CircleView", level = DeprecationLevel.ERROR)
override fun setBackground(background: Drawable) {
throw IllegalStateException("Cannot use setBackground() on CircleView.")
}
-
- @Deprecated("")
+ @Deprecated("Cannot use setBackgroundDrawable() on CircleView", level = DeprecationLevel.ERROR)
override fun setBackgroundDrawable(background: Drawable) {
throw IllegalStateException("Cannot use setBackgroundDrawable() on CircleView.")
}
-
- @Deprecated("")
+ @Deprecated("Cannot use setActivated() on CircleView", level = DeprecationLevel.ERROR)
override fun setActivated(activated: Boolean) {
throw IllegalStateException("Cannot use setActivated() on CircleView.")
}
@@ -194,10 +190,10 @@ class CircleView @JvmOverloads constructor(context: Context, attrs: AttributeSet
cheatSheet.show()
}
- companion object {
+ private companion object {
@ColorInt
- private fun translucentColor(color: Int): Int {
+ fun translucentColor(color: Int): Int {
val factor = 0.7f
val alpha = Math.round(Color.alpha(color) * factor)
val red = Color.red(color)
diff --git a/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/ColorPalette.kt b/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/ColorPalette.kt
index b08767c..68e3461 100644
--- a/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/ColorPalette.kt
+++ b/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/ColorPalette.kt
@@ -344,6 +344,6 @@ internal object ColorPalette {
"#DD2C00"))
}
- fun colorArrayOf(vararg colors: String) = colors.map { Color.parseColor(it) }.toIntArray()
+ private fun colorArrayOf(vararg colors: String) = colors.map { Color.parseColor(it) }.toIntArray()
}
diff --git a/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/ColorPickerView.kt b/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/ColorPickerView.kt
index e9da763..778b775 100644
--- a/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/ColorPickerView.kt
+++ b/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/ColorPickerView.kt
@@ -1,5 +1,6 @@
package ca.allanwang.kau.colorpicker
+import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Color
import android.support.annotation.ColorInt
@@ -29,6 +30,7 @@ internal class ColorPickerView @JvmOverloads constructor(
var isInSub: Boolean = false
var isInCustom: Boolean = false
var circleSize: Int = context.dimen(R.dimen.kau_color_circle_size).toInt()
+ @SuppressLint("PrivateResource")
val backgroundColor = context.resolveColor(R.attr.md_background_color,
if (context.resolveColor(android.R.attr.textColorPrimary).isColorDark) Color.WHITE else 0xff424242.toInt())
val backgroundColorTint = backgroundColor.colorToForeground()
@@ -52,7 +54,6 @@ internal class ColorPickerView @JvmOverloads constructor(
}
}
-
val gridView: FillGridView by bindView(R.id.md_grid)
val customFrame: LinearLayout by bindView(R.id.md_colorChooserCustomFrame)
val customColorIndicator: View by bindView(R.id.md_colorIndicator)
@@ -126,10 +127,10 @@ internal class ColorPickerView @JvmOverloads constructor(
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
- try {
- selectedColor = Color.parseColor("#" + s.toString())
+ selectedColor = try {
+ Color.parseColor("#$s")
} catch (e: IllegalArgumentException) {
- selectedColor = Color.BLACK
+ Color.BLACK
}
customColorIndicator.setBackgroundColor(selectedColor)
@@ -171,9 +172,9 @@ internal class ColorPickerView @JvmOverloads constructor(
blueValue.text = blueSeekbar.progress.toString()
}
- override fun onStartTrackingTouch(seekBar: SeekBar) {}
+ override fun onStartTrackingTouch(seekBar: SeekBar) = Unit
- override fun onStopTrackingTouch(seekBar: SeekBar) {}
+ override fun onStopTrackingTouch(seekBar: SeekBar) = Unit
}
redSeekbar.setOnSeekBarChangeListener(customRgbListener)
greenSeekbar.setOnSeekBarChangeListener(customRgbListener)
@@ -187,7 +188,7 @@ internal class ColorPickerView @JvmOverloads constructor(
findColor(selectedColor)
if (builder.allowCustom) dialog.setActionButton(DialogAction.NEUTRAL, builder.customText)
dialog.setActionButton(DialogAction.NEGATIVE, if (isInSub) builder.backText else builder.cancelText)
- gridView.fadeIn(onStart = { invalidateGrid() })
+ gridView.fadeIn(onStart = this::invalidateGrid)
customFrame.fadeOut(onFinish = { customFrame.gone() })
hexInput.removeTextChangedListener(customHexTextWatcher)
customHexTextWatcher = null
@@ -217,11 +218,10 @@ internal class ColorPickerView @JvmOverloads constructor(
hexInput.tint(visibleColor)
}
- fun findColor(@ColorInt color: Int): Boolean {
+ private fun findColor(@ColorInt color: Int): Boolean {
topIndex = -1
subIndex = -1
- colorsTop.forEachIndexed {
- index, topColor ->
+ colorsTop.forEachIndexed { index, topColor ->
if (findSubColor(color, index)) {
topIndex = index
return true
@@ -234,10 +234,9 @@ internal class ColorPickerView @JvmOverloads constructor(
return false
}
- fun findSubColor(@ColorInt color: Int, topIndex: Int): Boolean {
+ private fun findSubColor(@ColorInt color: Int, topIndex: Int): Boolean {
if (colorsSub == null || colorsSub!!.size <= topIndex) return false
- colorsSub!![topIndex].forEachIndexed {
- index, subColor ->
+ colorsSub!![topIndex].forEachIndexed { index, subColor ->
if (subColor == color) {
subIndex = index
return true
@@ -246,7 +245,7 @@ internal class ColorPickerView @JvmOverloads constructor(
return false
}
- fun invalidateGrid() {
+ private fun invalidateGrid() {
if (gridView.adapter == null) {
gridView.adapter = ColorGridAdapter()
gridView.selector = ResourcesCompat.getDrawable(resources, R.drawable.kau_transparent, null)
@@ -303,6 +302,5 @@ internal class ColorPickerView @JvmOverloads constructor(
setOnLongClickListener(this@ColorGridAdapter)
}
}
-
}
} \ No newline at end of file