Flatten swatch, add background to picker

This commit is contained in:
Moez Bhatti
2018-03-24 03:59:25 -04:00
parent eda42267c0
commit 63070609bd
3 changed files with 44 additions and 17 deletions
@@ -26,6 +26,7 @@ import android.view.MotionEvent
import android.view.View
import com.moez.QKSMS.R
import common.util.extensions.setBackgroundTint
import common.util.extensions.setTint
import common.util.extensions.within
import kotlinx.android.synthetic.main.hsv_picker_view.view.*
@@ -64,7 +65,7 @@ class HSVPickerView @JvmOverloads constructor(context: Context, attrs: Attribute
val range = max - min
val hsv = floatArrayOf(hue, (x - min) / range, 1 - (y - min) / range)
swatchPreview.setBackgroundTint(Color.HSVToColor(hsv))
swatch.setTint(Color.HSVToColor(hsv))
}
else -> return@setOnTouchListener false
@@ -81,7 +82,7 @@ class HSVPickerView @JvmOverloads constructor(context: Context, attrs: Attribute
}
fun setColor(color: Int) {
swatchPreview.setBackgroundTint(color)
swatch.setTint(color)
// Convert the rgb color to HSV
val hsv = FloatArray(3).apply {
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
~
~ This file is part of QKSMS.
~
~ QKSMS is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ QKSMS is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@color/white" />
<corners android:radius="4dp" />
</shape>
</item>
</layer-list>
@@ -6,6 +6,17 @@
android:layout_height="wrap_content"
tools:parentTag="feature.themepicker.HSVPickerView">
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/rounded_rectangle_4dp"
android:backgroundTint="@color/white"
android:rotation="90"
app:layout_constraintBottom_toBottomOf="@id/saturation"
app:layout_constraintEnd_toEndOf="@id/saturation"
app:layout_constraintStart_toStartOf="@id/saturation"
app:layout_constraintTop_toTopOf="@id/saturation" />
<View
android:id="@+id/saturation"
android:layout_width="0dp"
@@ -30,25 +41,13 @@
app:layout_constraintStart_toStartOf="@id/saturation"
app:layout_constraintTop_toTopOf="@id/saturation" />
<FrameLayout
<ImageView
android:id="@+id/swatch"
android:layout_width="16dp"
android:layout_height="16dp"
android:background="@drawable/circle"
android:padding="2dp"
app:layout_constraintBottom_toBottomOf="@id/saturation"
app:layout_constraintEnd_toEndOf="@id/saturation"
app:layout_constraintStart_toStartOf="@id/saturation"
app:layout_constraintTop_toTopOf="@id/saturation">
<View
android:id="@+id/swatchPreview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="@drawable/circle"
android:backgroundTint="@color/tools_theme" />
</FrameLayout>
android:src="@drawable/circle"
tools:tint="@color/tools_theme" />
</merge>