mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-04-20 06:09:09 +00:00
Replace color picker by new one with editable hex values (#220)
This commit is contained in:
parent
87009e8921
commit
4baca025f9
2 changed files with 51 additions and 34 deletions
|
@ -81,7 +81,7 @@ dependencies {
|
|||
implementation 'androidx.preference:preference:1.2.1' // includes appcompat
|
||||
implementation 'androidx.recyclerview:recyclerview:1.3.1'
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||
implementation 'com.github.skydoves:colorpickerview:2.2.4'
|
||||
implementation 'com.github.martin-stone:hsv-alpha-color-picker-android:3.1.0'
|
||||
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
testImplementation 'org.mockito:mockito-core:3.12.4'
|
||||
|
@ -90,3 +90,7 @@ dependencies {
|
|||
testImplementation 'androidx.test:runner:1.5.2'
|
||||
testImplementation 'androidx.test:core:1.5.0'
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven { url "https://jitpack.io" }
|
||||
}
|
||||
|
|
|
@ -1,20 +1,18 @@
|
|||
package org.dslul.openboard.inputmethod.latin.settings
|
||||
|
||||
import android.app.Activity
|
||||
import android.graphics.Color
|
||||
import android.content.res.Configuration
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.view.WindowManager
|
||||
import android.widget.CompoundButton
|
||||
import android.widget.ImageView
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.content.edit
|
||||
import androidx.core.view.forEachIndexed
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.skydoves.colorpickerview.ColorPickerDialog
|
||||
import com.skydoves.colorpickerview.flag.BubbleFlag
|
||||
import com.skydoves.colorpickerview.flag.FlagMode
|
||||
import com.skydoves.colorpickerview.listeners.ColorEnvelopeListener
|
||||
import com.rarepebble.colorpicker.ColorPickerView
|
||||
import org.dslul.openboard.inputmethod.keyboard.KeyboardSwitcher
|
||||
import org.dslul.openboard.inputmethod.latin.R
|
||||
import org.dslul.openboard.inputmethod.latin.RichInputMethodManager
|
||||
|
@ -90,39 +88,54 @@ open class ColorsSettingsFragment : Fragment(R.layout.color_settings) {
|
|||
|
||||
val clickListener = View.OnClickListener {
|
||||
val hidden = RichInputMethodManager.getInstance().inputMethodManager.hideSoftInputFromWindow(binding.dummyText.windowToken, 0)
|
||||
val b = ColorPickerDialog.Builder(requireContext())
|
||||
val initialColor = Settings.readUserColor(prefs, requireContext(), colorPrefs[index], isNight)
|
||||
val picker = ColorPickerView(requireContext())
|
||||
// todo: later alpha bar should be activated, but currently setting alpha leads to glitches,
|
||||
// e.g. when setting alpha on key text it's not applied for key icons, but for emojis
|
||||
picker.showAlpha(false)
|
||||
picker.showHex(true)
|
||||
picker.showPreview(true)
|
||||
picker.color = initialColor
|
||||
picker.addColorObserver { observer ->
|
||||
prefs.edit { putInt(prefPrefix + colorPrefs[index], observer.color) }
|
||||
if (!csb.colorSwitch.isChecked) {
|
||||
prefs.edit { putBoolean(prefPrefix + colorPref + Settings.PREF_AUTO_USER_COLOR_SUFFIX, false) }
|
||||
csb.colorSwitch.setOnCheckedChangeListener(null)
|
||||
csb.colorSwitch.isChecked = true
|
||||
csb.colorSummary.text = ""
|
||||
csb.colorSwitch.setOnCheckedChangeListener(switchListener)
|
||||
updateColorPreviews()
|
||||
return@addColorObserver
|
||||
}
|
||||
updateColorPreviews()
|
||||
}
|
||||
val builder = AlertDialog.Builder(requireContext())
|
||||
builder
|
||||
.setTitle(colorPrefNames[index])
|
||||
// todo: later alphy bar should be activated, but currently setting alpha leads to glitches,
|
||||
// e.g. when setting alpha on key text it's not applied for key icons, but for emojis
|
||||
.attachAlphaSlideBar(false)
|
||||
.setPositiveButton(android.R.string.ok, ColorEnvelopeListener { envelope, _ ->
|
||||
prefs.edit { putInt(prefPrefix + colorPrefs[index], envelope.color) }
|
||||
.setView(picker)
|
||||
.setNegativeButton(android.R.string.cancel) { _, _ ->
|
||||
// If the slider is disabled, we simply want to close the dialog when no color is selected.
|
||||
if (csb.colorSwitch.isChecked)
|
||||
picker.color = initialColor
|
||||
}
|
||||
.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||
// When the slider is disabled, we want to define the default color as a custom color
|
||||
if (!csb.colorSwitch.isChecked) {
|
||||
prefs.edit { putBoolean(prefPrefix + colorPref + Settings.PREF_AUTO_USER_COLOR_SUFFIX, false) }
|
||||
csb.colorSwitch.setOnCheckedChangeListener(null)
|
||||
csb.colorSwitch.isChecked = true
|
||||
csb.colorSummary.text = ""
|
||||
csb.colorSwitch.setOnCheckedChangeListener(switchListener)
|
||||
reloadKeyboard(hidden)
|
||||
updateColorPreviews()
|
||||
return@ColorEnvelopeListener
|
||||
csb.colorSwitch.toggle()
|
||||
picker.color = initialColor
|
||||
}
|
||||
reloadKeyboard(hidden)
|
||||
updateColorPreviews()
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel) { _, _ ->
|
||||
if (hidden)
|
||||
RichInputMethodManager.getInstance().inputMethodManager.showSoftInput(binding.dummyText, 0)
|
||||
}
|
||||
val initialColor = if (prefs.contains(prefPrefix + colorPref))
|
||||
prefs.getInt(prefPrefix + colorPref, Color.GRAY)
|
||||
val dialog = builder.create()
|
||||
dialog.show()
|
||||
// Reduce the size of the dialog in portrait mode
|
||||
val wrapContent = WindowManager.LayoutParams.WRAP_CONTENT
|
||||
val widthPortrait = (resources.displayMetrics.widthPixels * 0.80f).toInt()
|
||||
val orientation = (resources.configuration.orientation)
|
||||
if (orientation == Configuration.ORIENTATION_LANDSCAPE)
|
||||
dialog.window?.setLayout(wrapContent, wrapContent)
|
||||
else
|
||||
Settings.readUserColor(prefs, requireContext(), colorPrefs[index], isNight)
|
||||
b.colorPickerView.setInitialColor(initialColor)
|
||||
// set better color drawable? neither the white circle nor the plus is nice
|
||||
b.colorPickerView.setSelectorDrawable(ContextCompat.getDrawable(requireContext(), R.drawable.ic_plus))
|
||||
b.colorPickerView.flagView = BubbleFlag(requireContext()).apply { flagMode = FlagMode.ALWAYS }
|
||||
b.show()
|
||||
dialog.window?.setLayout(widthPortrait, wrapContent)
|
||||
}
|
||||
csb.colorTextContainer.setOnClickListener(clickListener)
|
||||
csb.colorPreview.setOnClickListener(clickListener)
|
||||
|
|
Loading…
Add table
Reference in a new issue