Skip to content

Commit bdb1c1f

Browse files
committed
adding some coloring related improvements
1 parent 356b56f commit bdb1c1f

File tree

7 files changed

+99
-18
lines changed

7 files changed

+99
-18
lines changed

app/src/main/kotlin/com/simplemobiletools/keyboard/adapters/ClipsKeyboardAdapter.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import com.simplemobiletools.commons.helpers.ensureBackgroundThread
1414
import com.simplemobiletools.keyboard.R
1515
import com.simplemobiletools.keyboard.extensions.config
1616
import com.simplemobiletools.keyboard.extensions.getCurrentClip
17+
import com.simplemobiletools.keyboard.extensions.getStrokeColor
1718
import com.simplemobiletools.keyboard.helpers.ClipsHelper
1819
import com.simplemobiletools.keyboard.helpers.ITEM_CLIP
1920
import com.simplemobiletools.keyboard.helpers.ITEM_SECTION_LABEL
@@ -30,7 +31,6 @@ class ClipsKeyboardAdapter(
3031
) : RecyclerView.Adapter<ClipsKeyboardAdapter.ViewHolder>() {
3132

3233
private val layoutInflater = LayoutInflater.from(context)
33-
private val baseConfig = context.config
3434
private var textColor = context.getProperTextColor()
3535
private var backgroundColor = context.getProperBackgroundColor()
3636

@@ -67,6 +67,7 @@ class ClipsKeyboardAdapter(
6767
view.apply {
6868
val rippleBg = clip_holder.background as RippleDrawable
6969
val layerDrawable = rippleBg.findDrawableByLayerId(R.id.clipboard_background_holder) as LayerDrawable
70+
layerDrawable.findDrawableByLayerId(R.id.clipboard_background_stroke).applyColorFilter(context.getStrokeColor())
7071
layerDrawable.findDrawableByLayerId(R.id.clipboard_background_shape).applyColorFilter(backgroundColor)
7172

7273
clip_value.apply {

app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ package com.simplemobiletools.keyboard.extensions
22

33
import android.content.ClipboardManager
44
import android.content.Context
5+
import android.graphics.Color
6+
import com.simplemobiletools.commons.extensions.getProperBackgroundColor
7+
import com.simplemobiletools.commons.extensions.isUsingSystemDarkTheme
8+
import com.simplemobiletools.commons.extensions.lightenColor
9+
import com.simplemobiletools.keyboard.R
510
import com.simplemobiletools.keyboard.databases.ClipsDatabase
611
import com.simplemobiletools.keyboard.helpers.Config
712
import com.simplemobiletools.keyboard.interfaces.ClipsDao
@@ -14,3 +19,20 @@ fun Context.getCurrentClip(): String? {
1419
val clipboardManager = (getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager)
1520
return clipboardManager.primaryClip?.getItemAt(0)?.text?.trim()?.toString()
1621
}
22+
23+
fun Context.getStrokeColor(): Int {
24+
return if (config.isUsingSystemTheme) {
25+
if (isUsingSystemDarkTheme()) {
26+
resources.getColor(R.color.md_grey_800, theme)
27+
} else {
28+
resources.getColor(R.color.md_grey_400, theme)
29+
}
30+
} else {
31+
val lighterColor = getProperBackgroundColor().lightenColor()
32+
if (lighterColor == Color.WHITE || lighterColor == Color.BLACK) {
33+
resources.getColor(R.color.divider_grey, theme)
34+
} else {
35+
lighterColor
36+
}
37+
}
38+
}

app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import com.simplemobiletools.keyboard.adapters.ClipsKeyboardAdapter
3636
import com.simplemobiletools.keyboard.extensions.clipsDB
3737
import com.simplemobiletools.keyboard.extensions.config
3838
import com.simplemobiletools.keyboard.extensions.getCurrentClip
39+
import com.simplemobiletools.keyboard.extensions.getStrokeColor
3940
import com.simplemobiletools.keyboard.helpers.*
4041
import com.simplemobiletools.keyboard.helpers.MyKeyboard.Companion.KEYCODE_DELETE
4142
import com.simplemobiletools.keyboard.helpers.MyKeyboard.Companion.KEYCODE_ENTER
@@ -266,25 +267,46 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
266267
mTextColor = context.getProperTextColor()
267268
mBackgroundColor = context.getProperBackgroundColor()
268269
mPrimaryColor = context.getProperPrimaryColor()
270+
val strokeColor = context.getStrokeColor()
271+
272+
val toolbarColor = if (context.config.isUsingSystemTheme) {
273+
resources.getColor(R.color.you_keyboard_toolbar_color, context.theme)
274+
} else {
275+
mBackgroundColor.darkenColor()
276+
}
277+
278+
val darkerColor = if (context.config.isUsingSystemTheme) {
279+
resources.getColor(R.color.you_keyboard_background_color, context.theme)
280+
} else {
281+
mBackgroundColor.darkenColor(2)
282+
}
283+
284+
val miniKeyboardBackgroundColor = if (context.config.isUsingSystemTheme) {
285+
resources.getColor(R.color.you_keyboard_toolbar_color, context.theme)
286+
} else {
287+
mBackgroundColor.darkenColor(4)
288+
}
269289

270290
if (changedView == mini_keyboard_view) {
271291
val previewBackground = background as LayerDrawable
272-
previewBackground.findDrawableByLayerId(R.id.button_background_shape).applyColorFilter(mBackgroundColor.darkenColor(4))
273-
previewBackground.findDrawableByLayerId(R.id.button_background_stroke).applyColorFilter(getPreviewStrokeColor())
292+
previewBackground.findDrawableByLayerId(R.id.button_background_shape).applyColorFilter(miniKeyboardBackgroundColor)
293+
previewBackground.findDrawableByLayerId(R.id.button_background_stroke).applyColorFilter(strokeColor)
274294
background = previewBackground
275295
} else {
276-
background.applyColorFilter(mBackgroundColor.darkenColor(2))
296+
background.applyColorFilter(darkerColor)
277297
}
278298

279299
val rippleBg = resources.getDrawable(R.drawable.clipboard_background, context.theme) as RippleDrawable
280300
val layerDrawable = rippleBg.findDrawableByLayerId(R.id.clipboard_background_holder) as LayerDrawable
301+
layerDrawable.findDrawableByLayerId(R.id.clipboard_background_stroke).applyColorFilter(strokeColor)
281302
layerDrawable.findDrawableByLayerId(R.id.clipboard_background_shape).applyColorFilter(mBackgroundColor)
282303

283304
val wasDarkened = mBackgroundColor != mBackgroundColor.darkenColor()
284305
mToolbarHolder?.apply {
285306
top_keyboard_divider.beGoneIf(wasDarkened)
307+
top_keyboard_divider.background = ColorDrawable(strokeColor)
286308

287-
background = ColorDrawable(mBackgroundColor.darkenColor())
309+
background = ColorDrawable(toolbarColor)
288310
clipboard_value.apply {
289311
background = rippleBg
290312
setTextColor(mTextColor)
@@ -298,7 +320,8 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
298320

299321
mClipboardManagerHolder?.apply {
300322
top_clipboard_divider.beGoneIf(wasDarkened)
301-
clipboard_manager_holder.background = ColorDrawable(mBackgroundColor.darkenColor())
323+
top_clipboard_divider.background = ColorDrawable(strokeColor)
324+
clipboard_manager_holder.background = ColorDrawable(toolbarColor)
302325

303326
clipboard_manager_close.applyColorFilter(mTextColor)
304327
clipboard_manager_manage.applyColorFilter(mTextColor)
@@ -518,7 +541,11 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
518541
val code = key.code
519542
var keyBackground = mKeyBackground
520543
if (code == KEYCODE_SPACE) {
521-
keyBackground = resources.getDrawable(R.drawable.keyboard_space_background, context.theme)
544+
keyBackground = if (context.config.isUsingSystemTheme) {
545+
resources.getDrawable(R.drawable.keyboard_space_background_material, context.theme)
546+
} else {
547+
resources.getDrawable(R.drawable.keyboard_space_background, context.theme)
548+
}
522549
} else if (code == KEYCODE_ENTER) {
523550
keyBackground = resources.getDrawable(R.drawable.keyboard_enter_background, context.theme)
524551
}
@@ -768,9 +795,15 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
768795
}
769796
}
770797

798+
val previewBackgroundColor = if (context.config.isUsingSystemTheme) {
799+
resources.getColor(R.color.you_keyboard_toolbar_color, context.theme)
800+
} else {
801+
mBackgroundColor.darkenColor(4)
802+
}
803+
771804
val previewBackground = mPreviewText!!.background as LayerDrawable
772-
previewBackground.findDrawableByLayerId(R.id.button_background_shape).applyColorFilter(mBackgroundColor.darkenColor(4))
773-
previewBackground.findDrawableByLayerId(R.id.button_background_stroke).applyColorFilter(getPreviewStrokeColor())
805+
previewBackground.findDrawableByLayerId(R.id.button_background_shape).applyColorFilter(previewBackgroundColor)
806+
previewBackground.findDrawableByLayerId(R.id.button_background_stroke).applyColorFilter(context.getStrokeColor())
774807
mPreviewText!!.background = previewBackground
775808

776809
mPreviewText!!.setTextColor(mTextColor)
@@ -1339,15 +1372,6 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
13391372
mClipboardManagerHolder?.clips_list?.adapter = adapter
13401373
}
13411374

1342-
// 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.
1343-
private fun getPreviewStrokeColor(): Int {
1344-
var strokeColor = mBackgroundColor.lightenColor()
1345-
if (strokeColor == Color.WHITE || strokeColor == Color.BLACK) {
1346-
strokeColor = resources.getColor(R.color.divider_grey)
1347-
}
1348-
return strokeColor
1349-
}
1350-
13511375
private fun closing() {
13521376
if (mPreviewPopup.isShowing) {
13531377
mPreviewPopup.dismiss()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item android:state_pressed="true">
4+
<layer-list>
5+
<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">
6+
<shape android:shape="rectangle">
7+
<solid android:color="@android:color/system_accent2_600" />
8+
<corners android:radius="@dimen/medium_margin" />
9+
</shape>
10+
</item>
11+
</layer-list>
12+
</item>
13+
<item>
14+
<layer-list>
15+
<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">
16+
<shape android:shape="rectangle">
17+
<solid android:color="@android:color/system_accent2_700" />
18+
<corners android:radius="@dimen/medium_margin" />
19+
</shape>
20+
</item>
21+
</layer-list>
22+
</item>
23+
</selector>

app/src/main/res/drawable/clipboard_background.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
</item>
1212
<item android:id="@+id/clipboard_background_stroke">
1313
<shape android:shape="rectangle">
14+
<solid android:color="@android:color/transparent" />
1415
<stroke
1516
android:width="1dp"
1617
android:color="@color/md_grey_600" />
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<color name="you_keyboard_background_color">@android:color/system_neutral1_900</color>
4+
<color name="you_keyboard_toolbar_color">#111111</color>
5+
</resources>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<color name="you_keyboard_background_color">@android:color/system_neutral1_10</color>
4+
<color name="you_keyboard_toolbar_color">@android:color/system_neutral1_50</color>
5+
</resources>

0 commit comments

Comments
 (0)