-
-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add dynamic colors #277
Add dynamic colors #277
Conversation
app/src/main/java/org/dslul/openboard/inputmethod/keyboard/MainKeyboardView.java
Outdated
Show resolved
Hide resolved
What's with all the logic around |
I'm not sure I understand your question... Dynamic colors don't behave the same way as other colors light, dark, etc. when the keys are pressed. |
Authored-by: Helium314 <helium314@mailbox.org>
Having the colors doing different things depeding on the colors is highly unexpected. If the user sets excactly the same colors as the ones given to |
I don't understand your example because if (themeColors == THEME_DYNAMIC_LIGHT || themeColors == THEME_DYNAMIC_DARK ) colorFilter(doubleDarken(accent)) In this example, if I apply a double darkening for dynamic colors, it's to better highlight the selected emoji category compared to the background of the emoji category strip. It was mainly the Dynamic Light theme that was affected, but it's not disturbing to apply it to the Dynamic dark theme. |
Sticking to the "Principle of Least Surprise" is quite useful in advoiding hard-to-find bugs. This app violates that principle in too many places, and it's often a pain to deal with it. |
I totally agree with you. 😬
I hope this person will do what we do, i.e. understand what is already written... I'm a total beginner and yet I manage to understand (not often, it's true) what's coded...
Thank you so much for telling me about this principle; I didn't know about it and tonight I read some interesting articles about it. In relation to colors, when you said: " I think I tried too hard to match Gboard's colors... ☹ |
It often depends on what kind of code you read... In some places the code is very much enclosed, and you only need check one or two files. Though there is InputLogic, where most of the stuff is happening in one file, but still it's quite convoluted and difficult to grasp, e.g. the different outcomes on backspace. But an important point is also how simple it is to understand the code. If you stare long enough, you'll understand eventually. And simple understanding is very much coupled to clear function names (so you don't need to look up what it actually does) and straightforward code with few branches and special cases (which is usually hard due to necessary complexity).
I don't know how exactly you want the colors to look like, but what I want is to get rid of the It would be ok for example to add some |
As I don't know how to modify |
Sorry for my long non-reply. I didn't (and still don't) have enough time, and was rather occupied with working on the layout parser. I had some thoughts on how the interface Colors {
@ColorInt fun get(color: Color): Int
fun setBackground(view: View, Color)
fun setColor(drawable: Drawable, Color)
}
enum class Color { KEY_TEXT, KEYBOARD_BACKGROUND, SUGGESTION_BACKGROUND, MORE_KEYS_BACKGROUND, MORE_SUGGESTIONS_BACKGROUND, NAV_BAR, ... } The Then instead of e.g. Does that sound good for you? |
Don't apologize, there's no problem! I can see that the layout parser is very complex and requires a lot of work, so once again, no worries! The concepts you are talking about are new to me so I will do some tests this week and I will keep you informed. |
The interface can be pretty simple, here an extended example: interface Colors {
@ColorInt fun get(color: ColorType): Int
fun setBackground(view: View, color: ColorType)
fun setColor(drawable: Drawable, color: ColorType)
}
@RequiresApi(Build.VERSION_CODES.S)
class DynamicColors(context: Context) : Colors {
private val keyText = ContextCompat.getColor(context, android.R.color.system_neutral1_200)
private val background = ContextCompat.getColor(context, android.R.color.system_neutral2_700)
private val nav = ContextCompat.getColor(context, android.R.color.system_accent1_400)
override fun get(color: ColorType): Int = when (color) {
ColorType.KEY_TEXT -> keyText
ColorType.KEYBOARD_BACKGROUND, ColorType.SUGGESTION_BACKGROUND,
ColorType.MORE_KEYS_BACKGROUND, ColorType.MORE_SUGGESTIONS_BACKGROUND -> background
ColorType.NAV_BAR -> nav
}
override fun setColor(drawable: Drawable, color: ColorType) {
drawable.setTint(get(color)) // could be simliar to setBackgroundColor
}
override fun setBackground(view: View, color: ColorType) {
setColor(view.background, color) // could be similar to setKeyboardBackground
}
}
enum class ColorType { KEY_TEXT, KEYBOARD_BACKGROUND, SUGGESTION_BACKGROUND, MORE_KEYS_BACKGROUND, MORE_SUGGESTIONS_BACKGROUND, NAV_BAR }
class OldColors ( // renamed because of conflict
private val themeStyle: String,
private val hasKeyBorders: Boolean,
private val accent: Int,
private val gesture: Int,
private val background: Int,
private val keyBackground: Int,
private val functionalKey: Int,
private val spaceBar: Int,
private val keyText: Int,
private val keyHintText: Int,
private val spaceBarText: Int
) : Colors {
// ... the old code, but using the interface functions to set color (all other funs and all vals private) In |
Co-authored-by: Helium314 <helium314@mailbox.org>
I was finally able to work on this PR. I was inspired by the code you gave me and, indeed, dynamic colors no longer influence other colors without the need to add I hope you'll find this commit e92d177 better than what I suggested. 😅 |
It's not fully what I had in mind, as the idea was to have a more generic interface (allowing more flexibility), but the current state in the PR is somewhere on the way there. Definitely good enough, thanks!.
Can you check whether |
Without your help, I wouldn't have achieved this result (even if it isn't perfect 😬), so it's my turn to thank you.
Does the attached stacktrace answer your question? |
There is no logging in the functions I mentioned. My idea was to just add a log line, and check in Android Studio logcat viewer. E.g. add What's interesting is that there are some log lines regarding |
Cool, you've taught me something again! I can confirm that the 2 functions are called up without opening the keyboard and just after changing the color in the palette color. |
Ok, then you could use the fact that in both cases For checking you can add another function to the |
I don't understand your sentence: "Use the changed branch of the I've made dozens of attempts and now I'm still lost... 😭 |
In the branch that triggers when anything changed:
Add the color change to the conditions in the |
if the colors in the color palette are changed Co-authored-by: Helium314 <helium314@mailbox.org>
So in I understood right, the plan was to make a PR based on another branch, probably There are some minor things, but still looks good. |
great! I'll take care of making the changes to the TodoColor branch here. |
instead of the internal color names
only dynamic colours is affected
Done 👍 |
ColorType.SPACEBAR_TEXT -> spaceBarText | ||
ColorType.NAV_BAR -> navBar | ||
ColorType.MORE_SUGGESTIONS_HINT, ColorType.SUGGESTED_WORD, ColorType.TYPED_WORD, ColorType.VALID_WORD -> adjustedKeyText | ||
else -> Color.WHITE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all ColorType
s should return a chosen color. This is essentially a / the main reason to use enum and not some int
assigned to each color.
When explicitly assigning a color to all values, it's impossible to forget setting a color (especially considering that new values might get added).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I didn't know I had to list everything.
Done with commit a5af535.
app/src/main/java/org/dslul/openboard/inputmethod/latin/common/Colors.kt
Show resolved
Hide resolved
I did some adjustments so the names and the interface are closer to what I had in mind. |
I can confirm that the colors are identical. |
I notice that you didn't co-author... you helped me enormously on this PR so please, can you not forget this little detail again? |
I don't understand... the commit says it's co-authored by me: 0edbf9c |
You have to enter the commit in the GitHub mobile application to see it. In the commits list, you don't see the avatars side by side like on the internet. Very glad you did and thanks again for helping me on this PR. |
This PR adds Dynamic colors and fixes partially #29 (Openboard settings will be made later in another PR, even if already done locally).
To know:
This theme only appears in the list of colors for Android versions above 12+.
The colors are based on those of Gboard (Google is the creator of dynamic colors, so it makes sense to use theirs).
If you change the color in your device's color palette, the keyboard theme is not updated; you must perform a forced close.Fixed with commit 01c3eea thanks to Helium's help.This is not due to the addition of this new theme, as this "bug" is currently occurring.
I think this is due to
KeyboardSwitcher.updateKeyboardThemeAndContextThemeWrapper
.I didn't modify this part of the code because I didn't know how to change it without influencing the existing themes.
However, if you toggle the display on your device from light to dark, the keyboard colors update correctly.
A new image forSolved with commit b2e2c9ekeyboard_popup_panel_background_rounded_base
is provided because on my phone a 1 pixel white band was appearing under the popup selector. This was noticeable when the device was on the light theme.Maybe it's the same on other screens with different resolutions, but unfortunately I can't really tell because I don't have enough devices in my possession.
Maybe in another PR we'll have to think about using xml drawables instead of 9-patch files to display popups.
Finally, the dividers in the suggestion strip are green on my Samsung tablet with Android 13. It's impossible to know where this is coming from and only this device is affected.Solved thanks to Helium - commit c2f4b61See screenshots
The screenshots are from my tablet, as it's the only device I have that has the Color Palette option.
If you don't have the Color Palette option in your device (like on my Huawei phone with Android 12), here's what it looks like: