mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-04-27 18:17:38 +00:00
parent
99075977ff
commit
ae1a2ca183
7 changed files with 88 additions and 11 deletions
|
@ -25,10 +25,12 @@ Changes:
|
|||
* based on wordmage's work https://github.com/openboard-team/openboard/tree/57d33791d7674e3fe0600eddb72f6b4317b5df00
|
||||
* tested with Google libraries and [others](https://github.com/openboard-team/openboard/issues/3#issuecomment-1200456262) (when building with the [rename](https://github.com/openboard-team/openboard/tree/57d33791d7674e3fe0600eddb72f6b4317b5df00))
|
||||
* Allow adjusting keyboard colors, https://github.com/openboard-team/openboard/issues/124
|
||||
* Optionally make the navigation bar follow current theme, https://github.com/Helium314/openboard/issues/4
|
||||
* Remove suggestions by long pressing on suggestion strip while the more suggestions popup is open, https://github.com/openboard-team/openboard/issues/106
|
||||
* suggestions get re-added if they are entered again
|
||||
* Optionally add typed words to system personal dictionary
|
||||
* Allow using contacts for suggestions (enable in spell checker settings), https://github.com/openboard-team/openboard/issues/374
|
||||
* Re-arranged comma-long-press-menu, https://github.com/Helium314/openboard/pull/7
|
||||
|
||||
Plan / to do:
|
||||
* ~upgrade dependencies~
|
||||
|
|
|
@ -138,6 +138,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
private static final String SCHEME_PACKAGE = "package";
|
||||
|
||||
final Settings mSettings;
|
||||
private int mOriginalNavBarColor = 0;
|
||||
private int mOriginalNavBarFlags = 0;
|
||||
private final DictionaryFacilitator mDictionaryFacilitator =
|
||||
DictionaryFacilitatorProvider.getDictionaryFacilitator(
|
||||
false /* isNeededForSpellChecking */);
|
||||
|
@ -1067,7 +1069,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
@Override
|
||||
public void onWindowShown() {
|
||||
super.onWindowShown();
|
||||
setNavigationBarVisibility(isInputViewShown());
|
||||
if (isInputViewShown())
|
||||
setNavigationBarColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1077,7 +1080,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
if (mainKeyboardView != null) {
|
||||
mainKeyboardView.closing();
|
||||
}
|
||||
setNavigationBarVisibility(false);
|
||||
clearNavigationBarColor();
|
||||
}
|
||||
|
||||
void onFinishInputInternal() {
|
||||
|
@ -2014,12 +2017,62 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
return mSettings.getCurrent().isLanguageSwitchKeyEnabled();
|
||||
}
|
||||
|
||||
private void setNavigationBarVisibility(final boolean visible) {
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
|
||||
// For N and later, IMEs can specify Color.TRANSPARENT to make the navigation bar
|
||||
// transparent. For other colors the system uses the default color.
|
||||
getWindow().getWindow().setNavigationBarColor(
|
||||
visible ? Color.BLACK : Color.TRANSPARENT);
|
||||
// slightly modified from Simple Keyboard: https://github.com/rkkr/simple-keyboard/blob/master/app/src/main/java/rkr/simplekeyboard/inputmethod/latin/LatinIME.java
|
||||
private void setNavigationBarColor() {
|
||||
final SettingsValues settingsValues = mSettings.getCurrent();
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP || !settingsValues.mNavBarColor)
|
||||
return;
|
||||
final int color;
|
||||
if (settingsValues.mUserTheme) {
|
||||
final int c = settingsValues.mBackgroundColor;
|
||||
// slightly adjust so color is same as keyboard background
|
||||
color = Color.rgb((int) (Color.red(c) * 0.925), (int) (Color.green(c) * 0.9379), (int) (Color.blue(c) * 0.945));
|
||||
} else
|
||||
color = settingsValues.mBackgroundColor;
|
||||
final Window window = getWindow().getWindow();
|
||||
if (window == null)
|
||||
return;
|
||||
mOriginalNavBarColor = window.getNavigationBarColor();
|
||||
window.setNavigationBarColor(color);
|
||||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
|
||||
return;
|
||||
final View view = window.getDecorView();
|
||||
mOriginalNavBarFlags = view.getSystemUiVisibility();
|
||||
if (isBrightColor(color)) {
|
||||
view.setSystemUiVisibility(mOriginalNavBarFlags | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
|
||||
} else {
|
||||
view.setSystemUiVisibility(mOriginalNavBarFlags & ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
|
||||
}
|
||||
}
|
||||
|
||||
private void clearNavigationBarColor() {
|
||||
final SettingsValues settingsValues = mSettings.getCurrent();
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP || !settingsValues.mNavBarColor)
|
||||
return;
|
||||
final Window window = getWindow().getWindow();
|
||||
if (window == null) {
|
||||
return;
|
||||
}
|
||||
window.setNavigationBarColor(mOriginalNavBarColor);
|
||||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
|
||||
return;
|
||||
final View view = window.getDecorView();
|
||||
view.setSystemUiVisibility(mOriginalNavBarFlags);
|
||||
}
|
||||
|
||||
private static boolean isBrightColor(int color) {
|
||||
if (android.R.color.transparent == color) {
|
||||
return true;
|
||||
}
|
||||
// See http://www.nbdtech.com/Blog/archive/2008/04/27/Calculating-the-Perceived-Brightness-of-a-Color.aspx
|
||||
boolean bright = false;
|
||||
int[] rgb = {Color.red(color), Color.green(color), Color.blue(color)};
|
||||
int brightness = (int) Math.sqrt(rgb[0] * rgb[0] * .241 + rgb[1] * rgb[1] * .691 + rgb[2] * rgb[2] * .068);
|
||||
if (brightness >= 210) {
|
||||
bright = true;
|
||||
}
|
||||
return bright;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,6 +51,9 @@ class AppearanceSettingsFragment : SubScreenFragment(), Preference.OnPreferenceC
|
|||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
|
||||
removePreference(Settings.PREF_THEME_DAY_NIGHT)
|
||||
}
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
||||
removePreference(Settings.PREF_NAVBAR_COLOR)
|
||||
}
|
||||
setupTheme()
|
||||
|
||||
if (!ProductionFlags.IS_SPLIT_KEYBOARD_SUPPORTED ||
|
||||
|
|
|
@ -137,6 +137,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
|
|||
|
||||
public static final String PREF_SECONDARY_LOCALES = "pref_secondary_locales";
|
||||
public static final String PREF_ADD_TO_PERSONAL_DICTIONARY = "add_to_personal_dictionary";
|
||||
public static final String PREF_NAVBAR_COLOR = "navbar_color";
|
||||
|
||||
// This preference key is deprecated. Use {@link #PREF_SHOW_LANGUAGE_SWITCH_KEY} instead.
|
||||
// This is being used only for the backward compatibility.
|
||||
|
|
|
@ -111,6 +111,7 @@ public class SettingsValues {
|
|||
public final int mScreenMetrics;
|
||||
public final boolean mAddToPersonalDictionary;
|
||||
public final boolean mUseContactsDictionary;
|
||||
public final boolean mNavBarColor;
|
||||
|
||||
// From the input box
|
||||
@Nonnull
|
||||
|
@ -263,13 +264,14 @@ public class SettingsValues {
|
|||
mOneHandedModeGravity = Settings.readOneHandedModeGravity(prefs);
|
||||
mSecondaryLocale = Settings.getSecondaryLocale(prefs, RichInputMethodManager.getInstance().getCurrentSubtypeLocale().toString());
|
||||
|
||||
mUserTheme = KeyboardTheme.getIsUser(KeyboardTheme.getThemeForParameters(
|
||||
final int keyboardThemeId = KeyboardTheme.getThemeForParameters(
|
||||
prefs.getString(Settings.PREF_THEME_FAMILY, ""),
|
||||
prefs.getString(Settings.PREF_THEME_VARIANT, ""),
|
||||
prefs.getBoolean(Settings.PREF_THEME_KEY_BORDERS, false),
|
||||
prefs.getBoolean(Settings.PREF_THEME_DAY_NIGHT, false),
|
||||
prefs.getBoolean(Settings.PREF_THEME_AMOLED_MODE, false)
|
||||
));
|
||||
);
|
||||
mUserTheme = KeyboardTheme.getIsUser(keyboardThemeId);
|
||||
mUserThemeColorAccent = prefs.getInt(Settings.PREF_THEME_USER_COLOR_ACCENT, Color.BLUE);
|
||||
final int keyBgColor;
|
||||
if (prefs.getBoolean(Settings.PREF_THEME_KEY_BORDERS, false))
|
||||
|
@ -280,11 +282,21 @@ public class SettingsValues {
|
|||
mHintTextColorFilter = BlendModeColorFilterCompat.createBlendModeColorFilterCompat(prefs.getInt(Settings.PREF_THEME_USER_COLOR_HINT_TEXT, Color.WHITE), BlendModeCompat.SRC_ATOP);
|
||||
mKeyTextColor = prefs.getInt(Settings.PREF_THEME_USER_COLOR_TEXT, Color.WHITE);
|
||||
mKeyTextColorFilter = BlendModeColorFilterCompat.createBlendModeColorFilterCompat(mKeyTextColor, BlendModeCompat.SRC_ATOP);
|
||||
mBackgroundColor = prefs.getInt(Settings.PREF_THEME_USER_COLOR_BACKGROUND, Color.DKGRAY);
|
||||
if (mUserTheme) {
|
||||
mBackgroundColor = prefs.getInt(Settings.PREF_THEME_USER_COLOR_BACKGROUND, Color.DKGRAY);
|
||||
} else if (KeyboardTheme.THEME_VARIANT_LIGHT.equals(KeyboardTheme.getThemeVariant(keyboardThemeId))) {
|
||||
mBackgroundColor = Color.rgb(236, 239, 241);
|
||||
} else if (keyboardThemeId == KeyboardTheme.THEME_ID_LXX_DARK) {
|
||||
mBackgroundColor = Color.rgb(38, 50, 56);
|
||||
} else {
|
||||
// dark border is 13/13/13, but that's ok
|
||||
mBackgroundColor = Color.BLACK;
|
||||
}
|
||||
mBackgroundColorFilter = BlendModeColorFilterCompat.createBlendModeColorFilterCompat(mBackgroundColor, BlendModeCompat.MODULATE);
|
||||
|
||||
mAddToPersonalDictionary = prefs.getBoolean(Settings.PREF_ADD_TO_PERSONAL_DICTIONARY, false);
|
||||
mUseContactsDictionary = prefs.getBoolean(AndroidSpellCheckerService.PREF_USE_CONTACTS_KEY, false);
|
||||
mNavBarColor = prefs.getBoolean(Settings.PREF_NAVBAR_COLOR, false);
|
||||
}
|
||||
|
||||
public boolean isMetricsLoggingEnabled() {
|
||||
|
|
|
@ -644,6 +644,8 @@ disposition rather than other common dispositions for Latin languages. [CHAR LIM
|
|||
<string name="amoled_mode">Deep black backgrounds</string>
|
||||
<!-- Description indicating amoled mode can lower power usage depending on the screen of the device. -->
|
||||
<string name="amoled_mode_summary">Can reduce power usage depending on the device’s screen technology</string>
|
||||
<!-- Option for setting navbar to follow keyboard color -->
|
||||
<string name="theme_navbar">Color navigation bar</string>
|
||||
<!-- Option for selecting custom theme colors -->
|
||||
<string name="select_user_colors">Adjust theme colors</string>
|
||||
<!-- Description for selection of user-defined colors. -->
|
||||
|
|
|
@ -45,6 +45,10 @@
|
|||
android:title="@string/amoled_mode"
|
||||
android:summary="@string/amoled_mode_summary"/>
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="theme_key_borders"
|
||||
android:title="@string/theme_navbar"/>
|
||||
|
||||
<Preference
|
||||
android:key="theme_select_colors"
|
||||
android:title="@string/select_user_colors"
|
||||
|
|
Loading…
Add table
Reference in a new issue