diff options
author | Allan Wang <me@allanwang.ca> | 2018-12-24 01:17:31 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-24 01:17:31 -0500 |
commit | fb90c4a4ab23f2fd246c29c1dde4d6e155a2e38b (patch) | |
tree | cc6d67461b6caa256043b9482f7646831d528a08 /colorpicker | |
parent | a380adea1052d39f23c9c4d432a9380ce347d6c4 (diff) | |
download | kau-fb90c4a4ab23f2fd246c29c1dde4d6e155a2e38b.tar.gz kau-fb90c4a4ab23f2fd246c29c1dde4d6e155a2e38b.tar.bz2 kau-fb90c4a4ab23f2fd246c29c1dde4d6e155a2e38b.zip |
Enhancement/ktlint (#179)
* Add spotless dependency
* Apply ktlint
* Add license headers
Diffstat (limited to 'colorpicker')
4 files changed, 214 insertions, 106 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 bdd6eed..29257d8 100644 --- a/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/CircleView.kt +++ b/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/CircleView.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2018 Allan Wang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package ca.allanwang.kau.colorpicker import android.animation.ValueAnimator @@ -13,15 +28,15 @@ import android.graphics.drawable.ShapeDrawable import android.graphics.drawable.StateListDrawable import android.graphics.drawable.shapes.OvalShape import android.os.Build +import android.util.AttributeSet +import android.view.Gravity +import android.widget.FrameLayout +import android.widget.Toast import androidx.annotation.ColorInt import androidx.annotation.ColorRes import androidx.annotation.FloatRange import androidx.core.view.GravityCompat import androidx.core.view.ViewCompat -import android.util.AttributeSet -import android.view.Gravity -import android.widget.FrameLayout -import android.widget.Toast import ca.allanwang.kau.utils.getDip import ca.allanwang.kau.utils.setBackgroundColorRes import ca.allanwang.kau.utils.toColor @@ -33,7 +48,8 @@ import ca.allanwang.kau.utils.toHSV * An extension of MaterialDialog's CircleView with animation selection * [https://github.com/afollestad/material-dialogs/blob/master/commons/src/main/java/com/afollestad/materialdialogs/color/CircleView.java] */ -class CircleView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : FrameLayout(context, attrs, defStyleAttr) { +class CircleView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : + FrameLayout(context, attrs, defStyleAttr) { private val borderWidthMicro: Float = context.getDip(1f) private val borderWidthSmall: Float = context.getDip(3f) @@ -108,14 +124,14 @@ class CircleView @JvmOverloads constructor(context: Context, attrs: AttributeSet fun animateSelected(selected: Boolean) { if (this.selected == selected) return this.selected = selected // We need to draw the other bands - val range = if (selected) Pair(-borderWidthSmall, borderWidthLarge) else Pair(borderWidthLarge, -borderWidthSmall) + val range = + if (selected) Pair(-borderWidthSmall, borderWidthLarge) else Pair(borderWidthLarge, -borderWidthSmall) ValueAnimator.ofFloat(range.first, range.second).apply { reverse() duration = 150L addUpdateListener { animation -> whiteOuterBound = animation.animatedValue as Float invalidate() - } start() } @@ -137,12 +153,22 @@ class CircleView @JvmOverloads constructor(context: Context, attrs: AttributeSet if (whiteRadius >= centerWidth) { canvas.drawCircle(centerWidth, centerHeight, centerWidth, whitePaint) } else { - canvas.drawCircle(centerWidth, centerHeight, if (withBorder) centerWidth - borderWidthMicro else centerWidth, outerPaint) + canvas.drawCircle( + centerWidth, + centerHeight, + if (withBorder) centerWidth - borderWidthMicro else centerWidth, + outerPaint + ) canvas.drawCircle(centerWidth, centerHeight, whiteRadius, whitePaint) } canvas.drawCircle(centerWidth, centerHeight, innerRadius, innerPaint) } else { - canvas.drawCircle(centerWidth, centerHeight, if (withBorder) centerWidth - borderWidthMicro else centerWidth, innerPaint) + canvas.drawCircle( + centerWidth, + centerHeight, + if (withBorder) centerWidth - borderWidthMicro else centerWidth, + innerPaint + ) } } @@ -169,11 +195,13 @@ class CircleView @JvmOverloads constructor(context: Context, attrs: AttributeSet referenceX = screenWidth - referenceX // mirror } val cheatSheet = Toast - .makeText(context, String.format("#%06X", 0xFFFFFF and color), Toast.LENGTH_SHORT) + .makeText(context, String.format("#%06X", 0xFFFFFF and color), Toast.LENGTH_SHORT) if (midy < displayFrame.height()) { // Show along the top; follow action buttons - cheatSheet.setGravity(Gravity.TOP or GravityCompat.END, referenceX, - screenPos[1] + height - displayFrame.top) + cheatSheet.setGravity( + Gravity.TOP or GravityCompat.END, referenceX, + screenPos[1] + height - displayFrame.top + ) } else { // Show along the bottom center cheatSheet.setGravity(Gravity.BOTTOM or Gravity.CENTER_HORIZONTAL, 0, height) @@ -194,8 +222,10 @@ class CircleView @JvmOverloads constructor(context: Context, attrs: AttributeSet } @ColorInt - fun shiftColor(@ColorInt color: Int, - @FloatRange(from = 0.0, to = 2.0) by: Float): Int { + fun shiftColor( + @ColorInt color: Int, + @FloatRange(from = 0.0, to = 2.0) by: Float + ): Int { if (by == 1f) return color val hsv = color.toHSV() hsv[2] *= by // value component @@ -208,4 +238,4 @@ class CircleView @JvmOverloads constructor(context: Context, attrs: AttributeSet @ColorInt fun shiftColorUp(@ColorInt color: Int): Int = shiftColor(color, 1.1f) } -}
\ No newline at end of file +} 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 68e3461..d9db160 100644 --- a/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/ColorPalette.kt +++ b/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/ColorPalette.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2018 Allan Wang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package ca.allanwang.kau.colorpicker import android.graphics.Color @@ -9,29 +24,31 @@ internal object ColorPalette { val PRIMARY_COLORS: IntArray by lazy { colorArrayOf( - "#F44336", - "#E91E63", - "#9C27B0", - "#673AB7", - "#3F51B5", - "#2196F3", - "#03A9F4", - "#00BCD4", - "#009688", - "#4CAF50", - "#8BC34A", - "#CDDC39", - "#FFEB3B", - "#FFC107", - "#FF9800", - "#FF5722", - "#795548", - "#9E9E9E", - "#607D8B") + "#F44336", + "#E91E63", + "#9C27B0", + "#673AB7", + "#3F51B5", + "#2196F3", + "#03A9F4", + "#00BCD4", + "#009688", + "#4CAF50", + "#8BC34A", + "#CDDC39", + "#FFEB3B", + "#FFC107", + "#FF9800", + "#FF5722", + "#795548", + "#9E9E9E", + "#607D8B" + ) } val PRIMARY_COLORS_SUB: Array<IntArray> by lazy { - arrayOf(colorArrayOf( + arrayOf( + colorArrayOf( "#FFEBEE", "#FFCDD2", "#EF9A9A", @@ -42,7 +59,7 @@ internal object ColorPalette { "#D32F2F", "#C62828", "#B71C1C" - ), colorArrayOf( + ), colorArrayOf( "#FCE4EC", "#F8BBD0", "#F48FB1", @@ -53,7 +70,7 @@ internal object ColorPalette { "#C2185B", "#AD1457", "#880E4F" - ), colorArrayOf( + ), colorArrayOf( "#F3E5F5", "#E1BEE7", "#CE93D8", @@ -64,7 +81,7 @@ internal object ColorPalette { "#7B1FA2", "#6A1B9A", "#4A148C" - ), colorArrayOf( + ), colorArrayOf( "#EDE7F6", "#D1C4E9", "#B39DDB", @@ -75,7 +92,7 @@ internal object ColorPalette { "#512DA8", "#4527A0", "#311B92" - ), colorArrayOf( + ), colorArrayOf( "#E8EAF6", "#C5CAE9", "#9FA8DA", @@ -86,7 +103,7 @@ internal object ColorPalette { "#303F9F", "#283593", "#1A237E" - ), colorArrayOf( + ), colorArrayOf( "#E3F2FD", "#BBDEFB", "#90CAF9", @@ -97,7 +114,7 @@ internal object ColorPalette { "#1976D2", "#1565C0", "#0D47A1" - ), colorArrayOf( + ), colorArrayOf( "#E1F5FE", "#B3E5FC", "#81D4FA", @@ -108,7 +125,7 @@ internal object ColorPalette { "#0288D1", "#0277BD", "#01579B" - ), colorArrayOf( + ), colorArrayOf( "#E0F7FA", "#B2EBF2", "#80DEEA", @@ -119,7 +136,7 @@ internal object ColorPalette { "#0097A7", "#00838F", "#006064" - ), colorArrayOf( + ), colorArrayOf( "#E0F2F1", "#B2DFDB", "#80CBC4", @@ -130,7 +147,7 @@ internal object ColorPalette { "#00796B", "#00695C", "#004D40" - ), colorArrayOf( + ), colorArrayOf( "#E8F5E9", "#C8E6C9", "#A5D6A7", @@ -141,7 +158,7 @@ internal object ColorPalette { "#388E3C", "#2E7D32", "#1B5E20" - ), colorArrayOf( + ), colorArrayOf( "#F1F8E9", "#DCEDC8", "#C5E1A5", @@ -152,7 +169,7 @@ internal object ColorPalette { "#689F38", "#558B2F", "#33691E" - ), colorArrayOf( + ), colorArrayOf( "#F9FBE7", "#F0F4C3", "#E6EE9C", @@ -163,7 +180,7 @@ internal object ColorPalette { "#AFB42B", "#9E9D24", "#827717" - ), colorArrayOf( + ), colorArrayOf( "#FFFDE7", "#FFF9C4", "#FFF59D", @@ -174,7 +191,7 @@ internal object ColorPalette { "#FBC02D", "#F9A825", "#F57F17" - ), colorArrayOf( + ), colorArrayOf( "#FFF8E1", "#FFECB3", "#FFE082", @@ -185,7 +202,7 @@ internal object ColorPalette { "#FFA000", "#FF8F00", "#FF6F00" - ), colorArrayOf( + ), colorArrayOf( "#FFF3E0", "#FFE0B2", "#FFCC80", @@ -196,7 +213,7 @@ internal object ColorPalette { "#F57C00", "#EF6C00", "#E65100" - ), colorArrayOf( + ), colorArrayOf( "#FBE9E7", "#FFCCBC", "#FFAB91", @@ -207,7 +224,7 @@ internal object ColorPalette { "#E64A19", "#D84315", "#BF360C" - ), colorArrayOf( + ), colorArrayOf( "#EFEBE9", "#D7CCC8", "#BCAAA4", @@ -218,7 +235,7 @@ internal object ColorPalette { "#5D4037", "#4E342E", "#3E2723" - ), colorArrayOf( + ), colorArrayOf( "#FAFAFA", "#F5F5F5", "#EEEEEE", @@ -229,7 +246,7 @@ internal object ColorPalette { "#616161", "#424242", "#212121" - ), colorArrayOf( + ), colorArrayOf( "#ECEFF1", "#CFD8DC", "#B0BEC5", @@ -239,111 +256,117 @@ internal object ColorPalette { "#546E7A", "#455A64", "#37474F", - "#263238")) + "#263238" + ) + ) } val ACCENT_COLORS: IntArray by lazy { colorArrayOf( - "#FF1744", - "#F50057", - "#D500F9", - "#651FFF", - "#3D5AFE", - "#2979FF", - "#00B0FF", - "#00E5FF", - "#1DE9B6", - "#00E676", - "#76FF03", - "#C6FF00", - "#FFEA00", - "#FFC400", - "#FF9100", - "#FF3D00") + "#FF1744", + "#F50057", + "#D500F9", + "#651FFF", + "#3D5AFE", + "#2979FF", + "#00B0FF", + "#00E5FF", + "#1DE9B6", + "#00E676", + "#76FF03", + "#C6FF00", + "#FFEA00", + "#FFC400", + "#FF9100", + "#FF3D00" + ) } val ACCENT_COLORS_SUB: Array<IntArray> by lazy { - arrayOf(colorArrayOf("#FF8A80", + arrayOf( + colorArrayOf( + "#FF8A80", "#FF5252", "#FF1744", "#D50000" - ), colorArrayOf( + ), colorArrayOf( "#FF80AB", "#FF4081", "#F50057", "#C51162" - ), colorArrayOf( + ), colorArrayOf( "#EA80FC", "#E040FB", "#D500F9", "#AA00FF" - ), colorArrayOf( + ), colorArrayOf( "#B388FF", "#7C4DFF", "#651FFF", "#6200EA" - ), colorArrayOf( + ), colorArrayOf( "#8C9EFF", "#536DFE", "#3D5AFE", "#304FFE" - ), colorArrayOf( + ), colorArrayOf( "#82B1FF", "#448AFF", "#2979FF", "#2962FF" - ), colorArrayOf( + ), colorArrayOf( "#80D8FF", "#40C4FF", "#00B0FF", "#0091EA" - ), colorArrayOf( + ), colorArrayOf( "#84FFFF", "#18FFFF", "#00E5FF", "#00B8D4" - ), colorArrayOf( + ), colorArrayOf( "#A7FFEB", "#64FFDA", "#1DE9B6", "#00BFA5" - ), colorArrayOf( + ), colorArrayOf( "#B9F6CA", "#69F0AE", "#00E676", "#00C853" - ), colorArrayOf( + ), colorArrayOf( "#CCFF90", "#B2FF59", "#76FF03", "#64DD17" - ), colorArrayOf( + ), colorArrayOf( "#F4FF81", "#EEFF41", "#C6FF00", "#AEEA00" - ), colorArrayOf( + ), colorArrayOf( "#FFFF8D", "#FFFF00", "#FFEA00", "#FFD600" - ), colorArrayOf( + ), colorArrayOf( "#FFE57F", "#FFD740", "#FFC400", "#FFAB00" - ), colorArrayOf( + ), colorArrayOf( "#FFD180", "#FFAB40", "#FF9100", "#FF6D00" - ), colorArrayOf( + ), colorArrayOf( "#FF9E80", "#FF6E40", "#FF3D00", - "#DD2C00")) + "#DD2C00" + ) + ) } private fun colorArrayOf(vararg colors: String) = colors.map { Color.parseColor(it) }.toIntArray() } - diff --git a/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/ColorPickerDialog.kt b/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/ColorPickerDialog.kt index 6c4ad92..4202db1 100644 --- a/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/ColorPickerDialog.kt +++ b/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/ColorPickerDialog.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2018 Allan Wang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package ca.allanwang.kau.colorpicker import android.content.Context @@ -86,4 +101,4 @@ fun Context.colorPickerDialog(contract: ColorContract): MaterialDialog { } view.bind(contract, dialog) return dialog -}
\ No newline at end of file +} 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 5174089..ab0b149 100644 --- a/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/ColorPickerView.kt +++ b/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/ColorPickerView.kt @@ -1,22 +1,54 @@ +/* + * Copyright 2018 Allan Wang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package ca.allanwang.kau.colorpicker import android.annotation.SuppressLint import android.content.Context import android.graphics.Color -import androidx.annotation.ColorInt -import androidx.core.content.res.ResourcesCompat import android.text.Editable import android.text.InputFilter import android.text.TextWatcher import android.util.AttributeSet import android.view.View import android.view.ViewGroup -import android.widget.* -import ca.allanwang.kau.utils.* +import android.widget.AbsListView +import android.widget.BaseAdapter +import android.widget.EditText +import android.widget.LinearLayout +import android.widget.ScrollView +import android.widget.SeekBar +import android.widget.TextView +import androidx.annotation.ColorInt +import androidx.core.content.res.ResourcesCompat +import ca.allanwang.kau.utils.colorToForeground +import ca.allanwang.kau.utils.dimen +import ca.allanwang.kau.utils.fadeIn +import ca.allanwang.kau.utils.fadeOut +import ca.allanwang.kau.utils.gone +import ca.allanwang.kau.utils.isColorDark +import ca.allanwang.kau.utils.isColorVisibleOn +import ca.allanwang.kau.utils.isVisible +import ca.allanwang.kau.utils.resolveColor +import ca.allanwang.kau.utils.tint +import ca.allanwang.kau.utils.toHexString +import ca.allanwang.kau.utils.visible import com.afollestad.materialdialogs.DialogAction import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.color.FillGridView -import java.util.* +import java.util.Locale /** * Created by Allan Wang on 2017-06-08. @@ -24,7 +56,9 @@ import java.util.* * ColorPicker component of the ColorPickerDialog */ internal class ColorPickerView @JvmOverloads constructor( - context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0 ) : ScrollView(context, attrs, defStyleAttr) { val selectedColor: Int get() = _selectedColor @@ -33,8 +67,10 @@ internal class ColorPickerView @JvmOverloads constructor( private var isInCustom: Boolean = false private var circleSize: Int = context.dimen(R.dimen.kau_color_circle_size).toInt() @SuppressLint("PrivateResource") - private val backgroundColor = context.resolveColor(R.attr.md_background_color, - if (context.resolveColor(android.R.attr.textColorPrimary).isColorDark) Color.WHITE else 0xff424242.toInt()) + private val backgroundColor = context.resolveColor( + R.attr.md_background_color, + if (context.resolveColor(android.R.attr.textColorPrimary).isColorDark) Color.WHITE else 0xff424242.toInt() + ) private val backgroundColorTint = backgroundColor.colorToForeground() private lateinit var dialog: MaterialDialog private lateinit var builder: ColorContract @@ -175,13 +211,17 @@ internal class ColorPickerView @JvmOverloads constructor( override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { if (fromUser) { val color = if (builder.allowCustomAlpha) - Color.argb(alphaSeekbar.progress, - redSeekbar.progress, - greenSeekbar.progress, - blueSeekbar.progress) - else Color.rgb(redSeekbar.progress, + Color.argb( + alphaSeekbar.progress, + redSeekbar.progress, greenSeekbar.progress, - blueSeekbar.progress) + blueSeekbar.progress + ) + else Color.rgb( + redSeekbar.progress, + greenSeekbar.progress, + blueSeekbar.progress + ) hexInput.setText(color.toHexString(builder.allowCustomAlpha, false)) } @@ -279,8 +319,8 @@ internal class ColorPickerView @JvmOverloads constructor( } private fun circleAt(index: Int): CircleView? = - if (index == -1) null - else gridView.getChildAt(index) as? CircleView + if (index == -1) null + else gridView.getChildAt(index) as? CircleView private val View.tagData: Pair<Int, Int>? get() { @@ -316,4 +356,4 @@ internal class ColorPickerView @JvmOverloads constructor( } } } -}
\ No newline at end of file +} |