mirror of
https://github.com/SimpleMobileTools/Simple-Keyboard.git
synced 2025-02-19 21:30:47 +01:00
adding some coloring related improvements
This commit is contained in:
parent
356b56fe71
commit
bdb1c1f18a
@ -14,6 +14,7 @@ import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
|||||||
import com.simplemobiletools.keyboard.R
|
import com.simplemobiletools.keyboard.R
|
||||||
import com.simplemobiletools.keyboard.extensions.config
|
import com.simplemobiletools.keyboard.extensions.config
|
||||||
import com.simplemobiletools.keyboard.extensions.getCurrentClip
|
import com.simplemobiletools.keyboard.extensions.getCurrentClip
|
||||||
|
import com.simplemobiletools.keyboard.extensions.getStrokeColor
|
||||||
import com.simplemobiletools.keyboard.helpers.ClipsHelper
|
import com.simplemobiletools.keyboard.helpers.ClipsHelper
|
||||||
import com.simplemobiletools.keyboard.helpers.ITEM_CLIP
|
import com.simplemobiletools.keyboard.helpers.ITEM_CLIP
|
||||||
import com.simplemobiletools.keyboard.helpers.ITEM_SECTION_LABEL
|
import com.simplemobiletools.keyboard.helpers.ITEM_SECTION_LABEL
|
||||||
@ -30,7 +31,6 @@ class ClipsKeyboardAdapter(
|
|||||||
) : RecyclerView.Adapter<ClipsKeyboardAdapter.ViewHolder>() {
|
) : RecyclerView.Adapter<ClipsKeyboardAdapter.ViewHolder>() {
|
||||||
|
|
||||||
private val layoutInflater = LayoutInflater.from(context)
|
private val layoutInflater = LayoutInflater.from(context)
|
||||||
private val baseConfig = context.config
|
|
||||||
private var textColor = context.getProperTextColor()
|
private var textColor = context.getProperTextColor()
|
||||||
private var backgroundColor = context.getProperBackgroundColor()
|
private var backgroundColor = context.getProperBackgroundColor()
|
||||||
|
|
||||||
@ -67,6 +67,7 @@ class ClipsKeyboardAdapter(
|
|||||||
view.apply {
|
view.apply {
|
||||||
val rippleBg = clip_holder.background as RippleDrawable
|
val rippleBg = clip_holder.background as RippleDrawable
|
||||||
val layerDrawable = rippleBg.findDrawableByLayerId(R.id.clipboard_background_holder) as LayerDrawable
|
val layerDrawable = rippleBg.findDrawableByLayerId(R.id.clipboard_background_holder) as LayerDrawable
|
||||||
|
layerDrawable.findDrawableByLayerId(R.id.clipboard_background_stroke).applyColorFilter(context.getStrokeColor())
|
||||||
layerDrawable.findDrawableByLayerId(R.id.clipboard_background_shape).applyColorFilter(backgroundColor)
|
layerDrawable.findDrawableByLayerId(R.id.clipboard_background_shape).applyColorFilter(backgroundColor)
|
||||||
|
|
||||||
clip_value.apply {
|
clip_value.apply {
|
||||||
|
@ -2,6 +2,11 @@ package com.simplemobiletools.keyboard.extensions
|
|||||||
|
|
||||||
import android.content.ClipboardManager
|
import android.content.ClipboardManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.graphics.Color
|
||||||
|
import com.simplemobiletools.commons.extensions.getProperBackgroundColor
|
||||||
|
import com.simplemobiletools.commons.extensions.isUsingSystemDarkTheme
|
||||||
|
import com.simplemobiletools.commons.extensions.lightenColor
|
||||||
|
import com.simplemobiletools.keyboard.R
|
||||||
import com.simplemobiletools.keyboard.databases.ClipsDatabase
|
import com.simplemobiletools.keyboard.databases.ClipsDatabase
|
||||||
import com.simplemobiletools.keyboard.helpers.Config
|
import com.simplemobiletools.keyboard.helpers.Config
|
||||||
import com.simplemobiletools.keyboard.interfaces.ClipsDao
|
import com.simplemobiletools.keyboard.interfaces.ClipsDao
|
||||||
@ -14,3 +19,20 @@ fun Context.getCurrentClip(): String? {
|
|||||||
val clipboardManager = (getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager)
|
val clipboardManager = (getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager)
|
||||||
return clipboardManager.primaryClip?.getItemAt(0)?.text?.trim()?.toString()
|
return clipboardManager.primaryClip?.getItemAt(0)?.text?.trim()?.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Context.getStrokeColor(): Int {
|
||||||
|
return if (config.isUsingSystemTheme) {
|
||||||
|
if (isUsingSystemDarkTheme()) {
|
||||||
|
resources.getColor(R.color.md_grey_800, theme)
|
||||||
|
} else {
|
||||||
|
resources.getColor(R.color.md_grey_400, theme)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
val lighterColor = getProperBackgroundColor().lightenColor()
|
||||||
|
if (lighterColor == Color.WHITE || lighterColor == Color.BLACK) {
|
||||||
|
resources.getColor(R.color.divider_grey, theme)
|
||||||
|
} else {
|
||||||
|
lighterColor
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -36,6 +36,7 @@ import com.simplemobiletools.keyboard.adapters.ClipsKeyboardAdapter
|
|||||||
import com.simplemobiletools.keyboard.extensions.clipsDB
|
import com.simplemobiletools.keyboard.extensions.clipsDB
|
||||||
import com.simplemobiletools.keyboard.extensions.config
|
import com.simplemobiletools.keyboard.extensions.config
|
||||||
import com.simplemobiletools.keyboard.extensions.getCurrentClip
|
import com.simplemobiletools.keyboard.extensions.getCurrentClip
|
||||||
|
import com.simplemobiletools.keyboard.extensions.getStrokeColor
|
||||||
import com.simplemobiletools.keyboard.helpers.*
|
import com.simplemobiletools.keyboard.helpers.*
|
||||||
import com.simplemobiletools.keyboard.helpers.MyKeyboard.Companion.KEYCODE_DELETE
|
import com.simplemobiletools.keyboard.helpers.MyKeyboard.Companion.KEYCODE_DELETE
|
||||||
import com.simplemobiletools.keyboard.helpers.MyKeyboard.Companion.KEYCODE_ENTER
|
import com.simplemobiletools.keyboard.helpers.MyKeyboard.Companion.KEYCODE_ENTER
|
||||||
@ -266,25 +267,46 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
|||||||
mTextColor = context.getProperTextColor()
|
mTextColor = context.getProperTextColor()
|
||||||
mBackgroundColor = context.getProperBackgroundColor()
|
mBackgroundColor = context.getProperBackgroundColor()
|
||||||
mPrimaryColor = context.getProperPrimaryColor()
|
mPrimaryColor = context.getProperPrimaryColor()
|
||||||
|
val strokeColor = context.getStrokeColor()
|
||||||
|
|
||||||
|
val toolbarColor = if (context.config.isUsingSystemTheme) {
|
||||||
|
resources.getColor(R.color.you_keyboard_toolbar_color, context.theme)
|
||||||
|
} else {
|
||||||
|
mBackgroundColor.darkenColor()
|
||||||
|
}
|
||||||
|
|
||||||
|
val darkerColor = if (context.config.isUsingSystemTheme) {
|
||||||
|
resources.getColor(R.color.you_keyboard_background_color, context.theme)
|
||||||
|
} else {
|
||||||
|
mBackgroundColor.darkenColor(2)
|
||||||
|
}
|
||||||
|
|
||||||
|
val miniKeyboardBackgroundColor = if (context.config.isUsingSystemTheme) {
|
||||||
|
resources.getColor(R.color.you_keyboard_toolbar_color, context.theme)
|
||||||
|
} else {
|
||||||
|
mBackgroundColor.darkenColor(4)
|
||||||
|
}
|
||||||
|
|
||||||
if (changedView == mini_keyboard_view) {
|
if (changedView == mini_keyboard_view) {
|
||||||
val previewBackground = background as LayerDrawable
|
val previewBackground = background as LayerDrawable
|
||||||
previewBackground.findDrawableByLayerId(R.id.button_background_shape).applyColorFilter(mBackgroundColor.darkenColor(4))
|
previewBackground.findDrawableByLayerId(R.id.button_background_shape).applyColorFilter(miniKeyboardBackgroundColor)
|
||||||
previewBackground.findDrawableByLayerId(R.id.button_background_stroke).applyColorFilter(getPreviewStrokeColor())
|
previewBackground.findDrawableByLayerId(R.id.button_background_stroke).applyColorFilter(strokeColor)
|
||||||
background = previewBackground
|
background = previewBackground
|
||||||
} else {
|
} else {
|
||||||
background.applyColorFilter(mBackgroundColor.darkenColor(2))
|
background.applyColorFilter(darkerColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
val rippleBg = resources.getDrawable(R.drawable.clipboard_background, context.theme) as RippleDrawable
|
val rippleBg = resources.getDrawable(R.drawable.clipboard_background, context.theme) as RippleDrawable
|
||||||
val layerDrawable = rippleBg.findDrawableByLayerId(R.id.clipboard_background_holder) as LayerDrawable
|
val layerDrawable = rippleBg.findDrawableByLayerId(R.id.clipboard_background_holder) as LayerDrawable
|
||||||
|
layerDrawable.findDrawableByLayerId(R.id.clipboard_background_stroke).applyColorFilter(strokeColor)
|
||||||
layerDrawable.findDrawableByLayerId(R.id.clipboard_background_shape).applyColorFilter(mBackgroundColor)
|
layerDrawable.findDrawableByLayerId(R.id.clipboard_background_shape).applyColorFilter(mBackgroundColor)
|
||||||
|
|
||||||
val wasDarkened = mBackgroundColor != mBackgroundColor.darkenColor()
|
val wasDarkened = mBackgroundColor != mBackgroundColor.darkenColor()
|
||||||
mToolbarHolder?.apply {
|
mToolbarHolder?.apply {
|
||||||
top_keyboard_divider.beGoneIf(wasDarkened)
|
top_keyboard_divider.beGoneIf(wasDarkened)
|
||||||
|
top_keyboard_divider.background = ColorDrawable(strokeColor)
|
||||||
|
|
||||||
background = ColorDrawable(mBackgroundColor.darkenColor())
|
background = ColorDrawable(toolbarColor)
|
||||||
clipboard_value.apply {
|
clipboard_value.apply {
|
||||||
background = rippleBg
|
background = rippleBg
|
||||||
setTextColor(mTextColor)
|
setTextColor(mTextColor)
|
||||||
@ -298,7 +320,8 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
|||||||
|
|
||||||
mClipboardManagerHolder?.apply {
|
mClipboardManagerHolder?.apply {
|
||||||
top_clipboard_divider.beGoneIf(wasDarkened)
|
top_clipboard_divider.beGoneIf(wasDarkened)
|
||||||
clipboard_manager_holder.background = ColorDrawable(mBackgroundColor.darkenColor())
|
top_clipboard_divider.background = ColorDrawable(strokeColor)
|
||||||
|
clipboard_manager_holder.background = ColorDrawable(toolbarColor)
|
||||||
|
|
||||||
clipboard_manager_close.applyColorFilter(mTextColor)
|
clipboard_manager_close.applyColorFilter(mTextColor)
|
||||||
clipboard_manager_manage.applyColorFilter(mTextColor)
|
clipboard_manager_manage.applyColorFilter(mTextColor)
|
||||||
@ -518,7 +541,11 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
|||||||
val code = key.code
|
val code = key.code
|
||||||
var keyBackground = mKeyBackground
|
var keyBackground = mKeyBackground
|
||||||
if (code == KEYCODE_SPACE) {
|
if (code == KEYCODE_SPACE) {
|
||||||
keyBackground = resources.getDrawable(R.drawable.keyboard_space_background, context.theme)
|
keyBackground = if (context.config.isUsingSystemTheme) {
|
||||||
|
resources.getDrawable(R.drawable.keyboard_space_background_material, context.theme)
|
||||||
|
} else {
|
||||||
|
resources.getDrawable(R.drawable.keyboard_space_background, context.theme)
|
||||||
|
}
|
||||||
} else if (code == KEYCODE_ENTER) {
|
} else if (code == KEYCODE_ENTER) {
|
||||||
keyBackground = resources.getDrawable(R.drawable.keyboard_enter_background, context.theme)
|
keyBackground = resources.getDrawable(R.drawable.keyboard_enter_background, context.theme)
|
||||||
}
|
}
|
||||||
@ -768,9 +795,15 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val previewBackgroundColor = if (context.config.isUsingSystemTheme) {
|
||||||
|
resources.getColor(R.color.you_keyboard_toolbar_color, context.theme)
|
||||||
|
} else {
|
||||||
|
mBackgroundColor.darkenColor(4)
|
||||||
|
}
|
||||||
|
|
||||||
val previewBackground = mPreviewText!!.background as LayerDrawable
|
val previewBackground = mPreviewText!!.background as LayerDrawable
|
||||||
previewBackground.findDrawableByLayerId(R.id.button_background_shape).applyColorFilter(mBackgroundColor.darkenColor(4))
|
previewBackground.findDrawableByLayerId(R.id.button_background_shape).applyColorFilter(previewBackgroundColor)
|
||||||
previewBackground.findDrawableByLayerId(R.id.button_background_stroke).applyColorFilter(getPreviewStrokeColor())
|
previewBackground.findDrawableByLayerId(R.id.button_background_stroke).applyColorFilter(context.getStrokeColor())
|
||||||
mPreviewText!!.background = previewBackground
|
mPreviewText!!.background = previewBackground
|
||||||
|
|
||||||
mPreviewText!!.setTextColor(mTextColor)
|
mPreviewText!!.setTextColor(mTextColor)
|
||||||
@ -1339,15 +1372,6 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
|||||||
mClipboardManagerHolder?.clips_list?.adapter = adapter
|
mClipboardManagerHolder?.clips_list?.adapter = adapter
|
||||||
}
|
}
|
||||||
|
|
||||||
// stroke is usually the lighter version of the background color, but if it becomes white or black, it might be invisible. So use light grey there.
|
|
||||||
private fun getPreviewStrokeColor(): Int {
|
|
||||||
var strokeColor = mBackgroundColor.lightenColor()
|
|
||||||
if (strokeColor == Color.WHITE || strokeColor == Color.BLACK) {
|
|
||||||
strokeColor = resources.getColor(R.color.divider_grey)
|
|
||||||
}
|
|
||||||
return strokeColor
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun closing() {
|
private fun closing() {
|
||||||
if (mPreviewPopup.isShowing) {
|
if (mPreviewPopup.isShowing) {
|
||||||
mPreviewPopup.dismiss()
|
mPreviewPopup.dismiss()
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item android:state_pressed="true">
|
||||||
|
<layer-list>
|
||||||
|
<item android:id="@+id/space_pressed" android:bottom="@dimen/normal_margin" android:left="@dimen/normal_margin" android:right="@dimen/normal_margin" android:state_pressed="true" android:top="@dimen/normal_margin">
|
||||||
|
<shape android:shape="rectangle">
|
||||||
|
<solid android:color="@android:color/system_accent2_600" />
|
||||||
|
<corners android:radius="@dimen/medium_margin" />
|
||||||
|
</shape>
|
||||||
|
</item>
|
||||||
|
</layer-list>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layer-list>
|
||||||
|
<item android:id="@+id/space_normal" android:bottom="@dimen/normal_margin" android:left="@dimen/normal_margin" android:right="@dimen/normal_margin" android:state_pressed="true" android:top="@dimen/normal_margin">
|
||||||
|
<shape android:shape="rectangle">
|
||||||
|
<solid android:color="@android:color/system_accent2_700" />
|
||||||
|
<corners android:radius="@dimen/medium_margin" />
|
||||||
|
</shape>
|
||||||
|
</item>
|
||||||
|
</layer-list>
|
||||||
|
</item>
|
||||||
|
</selector>
|
@ -11,6 +11,7 @@
|
|||||||
</item>
|
</item>
|
||||||
<item android:id="@+id/clipboard_background_stroke">
|
<item android:id="@+id/clipboard_background_stroke">
|
||||||
<shape android:shape="rectangle">
|
<shape android:shape="rectangle">
|
||||||
|
<solid android:color="@android:color/transparent" />
|
||||||
<stroke
|
<stroke
|
||||||
android:width="1dp"
|
android:width="1dp"
|
||||||
android:color="@color/md_grey_600" />
|
android:color="@color/md_grey_600" />
|
||||||
|
5
app/src/main/res/values-night-v31/colors.xml
Normal file
5
app/src/main/res/values-night-v31/colors.xml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<color name="you_keyboard_background_color">@android:color/system_neutral1_900</color>
|
||||||
|
<color name="you_keyboard_toolbar_color">#111111</color>
|
||||||
|
</resources>
|
5
app/src/main/res/values-v31/colors.xml
Normal file
5
app/src/main/res/values-v31/colors.xml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<color name="you_keyboard_background_color">@android:color/system_neutral1_10</color>
|
||||||
|
<color name="you_keyboard_toolbar_color">@android:color/system_neutral1_50</color>
|
||||||
|
</resources>
|
Loading…
x
Reference in New Issue
Block a user