Skip to content

Commit

Permalink
Add dynamic colors to settings (Helium314#454)
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackyHawky authored Jan 29, 2024
1 parent 2beb949 commit 9fb59ed
Show file tree
Hide file tree
Showing 15 changed files with 129 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.os.Bundle;

import org.dslul.openboard.inputmethod.latin.permissions.PermissionsManager;
import org.dslul.openboard.inputmethod.latin.utils.ActivityThemeUtils;
import org.dslul.openboard.inputmethod.latin.utils.NewDictionaryAdder;

import androidx.annotation.NonNull;
Expand Down Expand Up @@ -44,6 +45,8 @@ protected void onCreate(final Bundle savedState) {
getSupportFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();

ActivityThemeUtils.setActivityTheme(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,42 @@

import static android.util.TypedValue.COMPLEX_UNIT_DIP;

import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Message;
import android.provider.Settings;
import android.util.TypedValue;
import android.view.View;
import android.view.WindowInsetsController;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.VideoView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.core.content.ContextCompat;
import androidx.core.content.res.ResourcesCompat;
import androidx.core.graphics.ColorUtils;
import androidx.core.graphics.drawable.DrawableCompat;

import org.dslul.openboard.inputmethod.latin.R;
import org.dslul.openboard.inputmethod.latin.settings.SettingsActivity;
import org.dslul.openboard.inputmethod.latin.utils.ActivityThemeUtils;
import org.dslul.openboard.inputmethod.latin.utils.JniUtils;
import org.dslul.openboard.inputmethod.latin.utils.LeakGuardHandlerWrapper;
import org.dslul.openboard.inputmethod.latin.utils.Log;
import org.dslul.openboard.inputmethod.latin.utils.ResourceUtils;
import org.dslul.openboard.inputmethod.latin.utils.UncachedInputMethodManagerUtils;

import java.util.ArrayList;

// TODO: Use Fragment to implement welcome screen and setup steps.
public final class SetupWizardActivity extends Activity implements View.OnClickListener {
public final class SetupWizardActivity extends AppCompatActivity implements View.OnClickListener {
static final String TAG = SetupWizardActivity.class.getSimpleName();

// For debugging purpose.
Expand Down Expand Up @@ -121,8 +117,13 @@ public void cancelPollingImeSettings() {
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Context context = getApplicationContext();
final boolean isNight = ResourceUtils.isNight(context.getResources());
final ActionBar actionBar = getSupportActionBar();
if (actionBar == null) {
return;
}
actionBar.hide();
getWindow().setStatusBarColor(getResources().getColor(R.color.setup_background));
ActivityThemeUtils.setActivityTheme(this);

mImm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
mHandler = new SettingsPoolingHandler(this, mImm);
Expand Down Expand Up @@ -220,27 +221,6 @@ mStep1Bullet, findViewById(R.id.setup_step1),
DrawableCompat.setTintList(finishDrawable, step1.mTextColorStateList);
mActionFinish.setCompoundDrawablesRelativeWithIntrinsicBounds(finishDrawable, null, null, null);
mActionFinish.setOnClickListener(this);

// Set the status bar color
getWindow().setStatusBarColor(getResources().getColor(R.color.setup_background));
// Navigation bar color
if (!isNight && !(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)) {
getWindow().setNavigationBarColor(ColorUtils.setAlphaComponent(Color.GRAY, 180));
} else {
getWindow().setNavigationBarColor(getResources().getColor(R.color.setup_background));
}
// Set the icons of the status bar and the navigation bar light or dark
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
final WindowInsetsController controller = getWindow().getInsetsController();
if (controller == null) return;
if (!isNight) {
controller.setSystemBarsAppearance(WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS, WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS);
controller.setSystemBarsAppearance(WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS, WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS);
}
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
final View view = getWindow().getDecorView();
view.setSystemUiVisibility(!isNight ? View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR : 0);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
public final class SpellCheckerSettingsActivity extends AppCompatActivity
implements ActivityCompat.OnRequestPermissionsResultCallback {
private static final String DEFAULT_FRAGMENT = SpellCheckerSettingsFragment.class.getName();

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.dslul.openboard.inputmethod.latin.permissions.PermissionsManager;
import org.dslul.openboard.inputmethod.latin.permissions.PermissionsUtil;
import org.dslul.openboard.inputmethod.latin.settings.SubScreenFragment;
import org.dslul.openboard.inputmethod.latin.utils.ActivityThemeUtils;

import androidx.preference.SwitchPreferenceCompat;

Expand All @@ -31,8 +32,10 @@ public final class SpellCheckerSettingsFragment extends SubScreenFragment
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.spell_checker_settings);
mLookupContactsPreference = (SwitchPreferenceCompat) findPreference(AndroidSpellCheckerService.PREF_USE_CONTACTS_KEY);
mLookupContactsPreference = findPreference(AndroidSpellCheckerService.PREF_USE_CONTACTS_KEY);
turnOffLookupContactsIfNoPermission();

ActivityThemeUtils.setActivityTheme(requireActivity());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: GPL-3.0-only
package org.dslul.openboard.inputmethod.latin.utils;

import android.app.Activity;
import android.os.Build;
import android.view.View;
import android.view.WindowInsetsController;

public class ActivityThemeUtils {

public static void setActivityTheme(final Activity activity) {
final boolean isNight = ResourceUtils.isNight(activity.getResources());

// Set the icons of the status bar and the navigation bar light or dark
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
final WindowInsetsController controller = activity.getWindow().getInsetsController();
if (controller != null && !isNight) {
controller.setSystemBarsAppearance(WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS, WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS);
controller.setSystemBarsAppearance(WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS, WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS);
}
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
final View view = activity.getWindow().getDecorView();
view.setSystemUiVisibility(!isNight ? View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR : 0);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ fun reorderMoreKeysDialog(context: Context, key: String, defaultSetting: String,
override fun areItemsTheSame(p0: Pair<String, Boolean>, p1: Pair<String, Boolean>) = p0 == p1
override fun areContentsTheSame(p0: Pair<String, Boolean>, p1: Pair<String, Boolean>) = p0 == p1
}
val bgColor = if (ResourceUtils.isNight(context.resources))
ContextCompat.getColor(context, androidx.appcompat.R.color.background_floating_material_dark)
else ContextCompat.getColor(context, androidx.appcompat.R.color.background_floating_material_light)
val bgColor = ContextCompat.getColor(context, R.color.sliding_items_background)
val adapter = object : ListAdapter<Pair<String, Boolean>, RecyclerView.ViewHolder>(callback) {
override fun onCreateViewHolder(p0: ViewGroup, p1: Int): RecyclerView.ViewHolder {
val b = LayoutInflater.from(context).inflate(R.layout.morekeys_list_item, rv, false)
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/seek_bar_dialog.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2012 The Android Open Source Project
modified
SPDX-License-Identifier: Apache-2.0
-->

Expand All @@ -19,7 +20,7 @@
<TextView android:id="@+id/seek_bar_dialog_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"/>
android:textSize="18sp"/>
</LinearLayout>
<SeekBar
android:id="@+id/seek_bar_dialog_bar"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@
android:baselineAligned="false">

<Button
style="@style/Widget.AppCompat.Button.Colored"
android:id="@+id/user_dictionary_delete_button"
android:backgroundTint="@color/accent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
Expand All @@ -124,8 +124,8 @@
</Button>

<Button
style="@style/Widget.AppCompat.Button.Colored"
android:id="@+id/user_dictionary_save_button"
android:backgroundTint="@color/accent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
android:gravity="bottom|end"
android:background="@android:color/transparent">
<Button
style="@style/Widget.AppCompat.Button.Colored"
android:id="@+id/user_dictionary_add_word_button"
android:backgroundTint="@color/accent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/user_dict_add_word_button"
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/res/values-night-v31/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
SPDX-License-Identifier: GPL-3.0-only
-->
<resources>
<!-- Color resources for setup wizard, tutorial and settings -->
<color name="accent">@android:color/system_accent1_500</color>

<!-- Color resources for setup wizard and tutorial -->
<color name="setup_background">@android:color/system_neutral1_900</color>
<color name="setup_step_background">@android:color/system_accent1_500</color>
<color name="setup_step_action_pressed">@android:color/system_accent1_700</color>
<color name="setup_text_title">@android:color/system_accent1_300</color>
<color name="setup_text_action">#FFFFFFFF</color>
<color name="setup_step_action_text_pressed">@android:color/system_accent1_500</color>
<color name="action_bar_color">@android:color/system_neutral2_800</color>
<color name="sliding_items_background">@android:color/system_neutral2_800</color>
<color name="dialog_background">@android:color/system_neutral2_800</color>
<color name="drop_down_menu_background">@android:color/system_neutral2_700</color>
</resources>
7 changes: 5 additions & 2 deletions app/src/main/res/values-night/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@
<color name="foreground_weak">#BBB</color>
<color name="almost_background">#666</color>

<color name="accent">@color/highlight_color_lxx_dark</color>
<color name="keyboard_background">@color/keyboard_background_dark</color>

<!-- Color resources for setup wizard and tutorial -->
<!-- Color resources for setup wizard, tutorial and settings -->
<color name="accent">@color/highlight_color_lxx_dark</color>
<color name="setup_background">#FF303030</color>
<color name="setup_step_background">#FF2D4260</color>
<color name="setup_step_action_pressed">#FF314868</color>
<color name="setup_text_title">#FF5C94F1</color>
<color name="setup_text_action">#FFFFFFFF</color>
<color name="setup_step_action_text_pressed">#FF5E9CED</color>
<color name="setup_welcome_video_margin_color">#FFCCCCCC</color>
<color name="action_bar_color">#FF212121</color>
<color name="navigation_bar_color">#FF303030</color>
<color name="sliding_items_background">#FF424242</color>
</resources>
7 changes: 6 additions & 1 deletion app/src/main/res/values-v31/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@
<color name="keyboard_background_light">@android:color/system_neutral1_100</color>
<color name="keyboard_background_dark">@android:color/system_neutral1_800</color>

<!-- Color resources for setup wizard and tutorial -->
<!-- Color resources for setup wizard, tutorial and settings -->
<color name="accent">@android:color/system_accent1_600</color>
<color name="setup_background">@android:color/system_neutral1_10</color>
<color name="setup_step_background">@android:color/system_accent1_50</color>
<color name="setup_step_action_pressed">@android:color/system_accent1_100</color>
<color name="setup_text_title">@android:color/system_accent1_700</color>
<color name="setup_text_action">@android:color/system_accent1_700</color>
<color name="setup_step_action_text_pressed">@android:color/system_accent1_500</color>
<color name="action_bar_color">@android:color/system_accent1_50</color>
<color name="sliding_items_background">@android:color/system_accent1_50</color>
<color name="dialog_background">@android:color/system_accent1_50</color>
<color name="drop_down_menu_background">@android:color/system_accent1_10</color>
</resources>
54 changes: 54 additions & 0 deletions app/src/main/res/values-v31/platform-theme.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
SPDX-License-Identifier: GPL-3.0-only
-->

<resources xmlns:android="http://schemas.android.com/apk/res/android">

<style name="platformActivityTheme" parent="Theme.AppCompat.DayNight">
<!-- Some items are duplicated from the original platform-theme file to ensure that the
"android/system_accent_*" or "android/system_neutral_*" colors are used. -->

<item name="android:colorAccent">@color/accent</item>
<item name="colorAccent">@color/accent</item>

<item name="android:statusBarColor">@color/action_bar_color</item>
<item name="android:navigationBarColor">@color/setup_background</item>

<item name="actionBarStyle">@style/ActionBarStyle</item>
<item name="android:actionBarSize">80dp</item>
<item name="actionBarSize">80dp</item>

<!-- Preference list background color -->
<item name="android:windowBackground">@color/setup_background</item>

<item name="android:alertDialogTheme">@style/AlertDialogTheme</item>
<item name="alertDialogTheme">@style/AlertDialogTheme</item>

<item name="android:buttonCornerRadius">50dp</item>

<item name="android:spinnerDropDownItemStyle">@style/DropDownMenuTheme</item>
<item name="spinnerDropDownItemStyle">@style/DropDownMenuTheme</item>

<!-- Menu background -->
<item name="android:itemBackground">@color/drop_down_menu_background</item>
</style>

<style name="ActionBarStyle" parent="Widget.AppCompat.ActionBar">
<item name="android:background">@color/action_bar_color</item>*
<item name="background">@color/action_bar_color</item>
</style>

<style name="AlertDialogTheme" parent="ThemeOverlay.AppCompat.Dialog.Alert">
<item name="android:colorBackgroundFloating">@color/dialog_background</item>
<item name="colorBackgroundFloating">@color/dialog_background</item>
<item name="android:dialogCornerRadius">28dp</item>
<item name="dialogCornerRadius">28dp</item>
</style>

<style name="DropDownMenuTheme" parent="Widget.AppCompat.DropDownItem.Spinner">
<item name="android:background">@color/drop_down_menu_background</item>
<item name="background">@color/drop_down_menu_background</item>
</style>

</resources>
7 changes: 5 additions & 2 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,24 @@
<color name="key_bottom_bevel_lxx_base">#A9ABAD</color>
<color name="emoji_tab_page_indicator_background_lxx_base_border">@android:color/white</color>

<!-- Color resources for setup wizard and tutorial -->
<!-- Color resources for setup wizard, tutorial and settings -->
<color name="accent">@color/highlight_color_lxx_light</color>
<color name="setup_background">#FFFAFAFA</color>
<color name="setup_step_background">#FFD1E3FA</color>
<color name="setup_step_action_pressed">#FFE8F1FC</color>
<color name="setup_text_title">#FF1767CF</color>
<color name="setup_text_action">#FF1767CF</color>
<color name="setup_step_action_text_pressed">#FF5E9CED</color>
<color name="setup_welcome_video_margin_color">#FFCCCCCC</color>
<color name="action_bar_color">#FFF5F5F5</color>
<color name="navigation_bar_color">#B3888888</color>
<color name="sliding_items_background">#FFFFFFFF</color>

<!-- Colors that are different for night theme -->
<color name="foreground">#000</color>
<color name="foreground_weak">#555</color>
<color name="almost_background">#AAA</color>
<color name="highlight_color_lxx_light">#1A73E8</color> <!-- todo: remove / replace with accent? -->
<color name="accent">@color/highlight_color_lxx_light</color>
<color name="keyboard_background">@color/keyboard_background_light</color>

<!-- Actually used keyboard default background colors -->
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/platform-theme.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@
<style name="platformActivityTheme" parent="Theme.AppCompat.DayNight">
<item name="android:colorAccent">@color/accent</item>
<item name="colorAccent">@color/accent</item>

<item name="android:statusBarColor">@color/action_bar_color</item>
<item name="android:navigationBarColor">@color/navigation_bar_color</item>
</style>
</resources>

0 comments on commit 9fb59ed

Please sign in to comment.