Add dynamic colors when installing Openboard (#447)

This commit is contained in:
BlackyHawky 2024-01-26 18:13:05 +01:00 committed by GitHub
parent 9d8a22880c
commit 2353cf491a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 116 additions and 52 deletions

View file

@ -6,31 +6,41 @@
package org.dslul.openboard.inputmethod.latin.setup;
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 org.dslul.openboard.inputmethod.latin.utils.Log;
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.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.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;
@ -52,7 +62,7 @@ public final class SetupWizardActivity extends Activity implements View.OnClickL
private VideoView mWelcomeVideoView;
private ImageView mWelcomeImageView;
private View mActionStart;
private View mActionNext;
private TextView mActionNext;
private TextView mStep1Bullet;
private TextView mActionFinish;
private SetupStepGroup mSetupStepGroup;
@ -109,12 +119,12 @@ public final class SetupWizardActivity extends Activity implements View.OnClickL
@Override
protected void onCreate(final Bundle savedInstanceState) {
setTheme(android.R.style.Theme_Translucent_NoTitleBar);
super.onCreate(savedInstanceState);
final Context context = getApplicationContext();
final boolean isNight = ResourceUtils.isNight(context.getResources());
mImm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
mHandler = new SettingsPoolingHandler(this, mImm);
setContentView(R.layout.setup_wizard);
mSetupWizard = findViewById(R.id.setup_wizard);
@ -137,8 +147,7 @@ public final class SetupWizardActivity extends Activity implements View.OnClickL
final TextView stepsTitle = findViewById(R.id.setup_title);
stepsTitle.setText(getString(R.string.setup_steps_title, applicationName));
final SetupStepIndicatorView indicatorView =
findViewById(R.id.setup_step_indicator);
final SetupStepIndicatorView indicatorView = findViewById(R.id.setup_step_indicator);
mSetupStepGroup = new SetupStepGroup(indicatorView);
mStep1Bullet = findViewById(R.id.setup_step1_bullet);
@ -198,15 +207,39 @@ public final class SetupWizardActivity extends Activity implements View.OnClickL
mActionStart = findViewById(R.id.setup_start_label);
mActionStart.setOnClickListener(this);
mActionNext = findViewById(R.id.setup_next);
mActionNext.setOnClickListener(this);
mActionFinish = findViewById(R.id.setup_finish);
final Drawable finishDrawable = ContextCompat.getDrawable(this, R.drawable.ic_setup_check);
assert finishDrawable != null;
DrawableCompat.setTintList(finishDrawable, new ColorStateList(new int[][]{{android.R.attr.state_focused}, {android.R.attr.state_pressed}, {}},
new int[]{Color.WHITE, Color.WHITE, step1.mActivatedColor}));
if (finishDrawable == null) {
return;
}
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
@ -402,8 +435,7 @@ public final class SetupWizardActivity extends Activity implements View.OnClickL
public final int mStepNo;
private final View mStepView;
private final TextView mBulletView;
private final int mActivatedColor;
private final int mDeactivatedColor;
private final ColorStateList mTextColorStateList;
private final String mInstruction;
private final String mFinishedInstruction;
private final TextView mActionLabel;
@ -416,26 +448,26 @@ public final class SetupWizardActivity extends Activity implements View.OnClickL
mStepView = stepView;
mBulletView = bulletView;
final Resources res = stepView.getResources();
mActivatedColor = res.getColor(R.color.setup_text_action);
mDeactivatedColor = res.getColor(R.color.setup_text_dark);
mTextColorStateList = AppCompatResources.getColorStateList(mStepView.getContext(), R.color.setup_step_action_text);
final TextView titleView = mStepView.findViewById(R.id.setup_step_title);
titleView.setText(res.getString(title, applicationName));
mInstruction = (instruction == 0) ? null
: res.getString(instruction, applicationName);
mFinishedInstruction = (finishedInstruction == 0) ? null
: res.getString(finishedInstruction, applicationName);
mInstruction = (instruction == 0) ? null : res.getString(instruction, applicationName);
mFinishedInstruction = (finishedInstruction == 0) ? null : res.getString(finishedInstruction, applicationName);
mActionLabel = mStepView.findViewById(R.id.setup_step_action_label);
mActionLabel.setText(res.getString(actionLabel));
final Drawable actionIconDrawable = res.getDrawable(actionIcon);
DrawableCompat.setTintList(actionIconDrawable, new ColorStateList(new int[][]{{android.R.attr.state_focused}, {android.R.attr.state_pressed}, {}},
new int[]{Color.WHITE, Color.WHITE, this.mActivatedColor}));
final Drawable actionIconDrawable = ResourcesCompat.getDrawable(res, actionIcon, null);
if (actionIconDrawable == null) {
return;
}
DrawableCompat.setTintList(actionIconDrawable, mTextColorStateList);
if (actionIcon == 0) {
final int paddingEnd = mActionLabel.getPaddingEnd();
mActionLabel.setPaddingRelative(paddingEnd, 0, paddingEnd, 0);
} else {
int size = (int) (24 * res.getDisplayMetrics().density); // width and height of drawables is 24dp
final int size = (int) TypedValue.applyDimension(COMPLEX_UNIT_DIP, 24f, res.getDisplayMetrics());
actionIconDrawable.setBounds(0,0, size, size);
mActionLabel.setCompoundDrawablesRelative(actionIconDrawable, null, null, null);
}
@ -443,9 +475,10 @@ public final class SetupWizardActivity extends Activity implements View.OnClickL
public void setEnabled(final boolean enabled, final boolean isStepActionAlreadyDone) {
mStepView.setVisibility(enabled ? View.VISIBLE : View.GONE);
mBulletView.setTextColor(enabled ? mActivatedColor : mDeactivatedColor);
final TextView instructionView = mStepView.findViewById(
R.id.setup_step_instruction);
mBulletView.setTextColor(enabled
? mBulletView.getContext().getResources().getColor(R.color.setup_step_action_text_pressed)
: mBulletView.getContext().getResources().getColor(R.color.setup_text_action));
final TextView instructionView = mStepView.findViewById(R.id.setup_step_instruction);
instructionView.setText(isStepActionAlreadyDone ? mFinishedInstruction : mInstruction);
mActionLabel.setVisibility(isStepActionAlreadyDone ? View.GONE : View.VISIBLE);
}

View file

@ -7,10 +7,10 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_focused="true"
android:color="@color/setup_text_action" />
android:color="@color/setup_step_action_pressed" />
<item
android:state_pressed="true"
android:color="@color/setup_text_action" />
android:color="@color/setup_step_action_pressed" />
<item
android:color="@color/setup_step_background" />
</selector>

View file

@ -1,16 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2013 The Android Open Source Project
SPDX-License-Identifier: Apache-2.0
SPDX-License-Identifier: GPL-3.0-only
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_focused="true"
android:color="@color/setup_step_background" />
android:color="@color/setup_step_action_text_pressed" />
<item
android:state_pressed="true"
android:color="@color/setup_step_background" />
android:color="@color/setup_step_action_text_pressed" />
<item
android:color="@color/setup_text_action" />
</selector>

View file

@ -7,10 +7,10 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_focused="true"
android:drawable="@color/setup_text_action" />
android:drawable="@color/setup_step_action_pressed" />
<item
android:state_pressed="true"
android:drawable="@color/setup_text_action" />
android:drawable="@color/setup_step_action_pressed" />
<item
android:drawable="@color/setup_step_background" />
</selector>

View file

@ -30,7 +30,7 @@
android:id="@+id/setup_step_indicator"
style="@style/setupStepIndicatorStyle" />
<FrameLayout
android:id="@+id/setup_steps_pane"
android:id="@+id/setup_steps_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include

View file

@ -15,5 +15,5 @@
android:text="@string/setup_welcome_additional_description"
android:layout_marginTop="@dimen/setup_welcome_description_top_margin"
android:gravity="center"
style="@style/setupWelcomeDescritpionStyle" />
style="@style/setupWelcomeDescriptionStyle" />
</merge>

View file

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
SPDX-License-Identifier: GPL-3.0-only
-->
<resources>
<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>
</resources>

View file

@ -9,4 +9,13 @@
<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 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>
</resources>

View file

@ -1,10 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2012 The Android Open Source Project
modified
SPDX-License-Identifier: Apache-2.0
SPDX-License-Identifier: GPL-3.0-only
-->
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!-- System theming colors for LXX_Light theme, overriding some colors in main colors.xml -->
<color name="highlight_color_lxx_light">@android:color/system_accent1_500</color>
@ -17,4 +14,12 @@
<!-- colors used when user sets keyboard background color to be determined automatically -->
<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 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>
</resources>

View file

@ -53,10 +53,12 @@
<color name="emoji_tab_page_indicator_background_lxx_base_border">@android:color/white</color>
<!-- Color resources for setup wizard and tutorial -->
<color name="setup_background">#FFEBEBEB</color>
<color name="setup_text_dark">#FF707070</color>
<color name="setup_text_action">@android:color/holo_blue_light</color>
<color name="setup_step_background">@android:color/background_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>
<!-- Colors that are different for night theme -->

View file

@ -1,16 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2013 The Android Open Source Project
modified
SPDX-License-Identifier: Apache-2.0
-->
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="setupTitleStyleCommon">
<item name="android:textColor">@color/setup_text_dark</item>
<item name="android:textColor">@color/setup_text_title</item>
<item name="android:textSize">@dimen/setup_title_text_size</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
</style>
<style name="setupWelcomeDescritpionStyle" parent="setupTitleStyle">
<style name="setupWelcomeDescriptionStyle" parent="setupTitleStyle">
<item name="android:textSize">@dimen/setup_welcome_description_text_size</item>
</style>
<style name="setupStepIndicatorStyle">
@ -18,7 +19,6 @@
<item name="android:layout_height">@dimen/setup_step_triangle_indicator_height</item>
</style>
<style name="setupStepBulletStyle">
<item name="android:textColor">@color/setup_text_dark</item>
<item name="android:textSize">@dimen/setup_step_bullet_text_size</item>
<item name="android:layout_width">0dp</item>
<item name="android:layout_weight">1.0</item>
@ -26,7 +26,6 @@
<item name="android:gravity">center_horizontal</item>
</style>
<style name="setupStepBaseStyle">
<item name="android:textColor">@color/setup_text_dark</item>
<item name="android:background">@color/setup_step_background</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
@ -34,9 +33,11 @@
<item name="android:paddingRight">@dimen/setup_step_horizontal_padding</item>
</style>
<style name="setupStepTitleStyle" parent="setupStepBaseStyle">
<item name="android:textColor">@color/setup_text_action</item>
<item name="android:textSize">@dimen/setup_step_title_text_size</item>
</style>
<style name="setupStepInstructionStyle" parent="setupStepBaseStyle">
<item name="android:textColor">@color/setup_step_action_text</item>
<item name="android:textSize">@dimen/setup_step_instruction_text_size</item>
</style>
<style name="setupStepStartIndicatorStyle">
@ -45,7 +46,7 @@
<item name="android:layout_height">@dimen/setup_step_action_height</item>
</style>
<style name="setupStepActionLabelStyleCommon" parent="setupStepBaseStyle">
<item name="android:textColor">@color/setup_step_action_color</item>
<item name="android:textColor">@color/setup_step_action_text</item>
<item name="android:background">@drawable/setup_step_action_background</item>
<item name="android:layout_height">@dimen/setup_step_action_height</item>
<item name="android:paddingLeft">@dimen/setup_step_horizontal_padding_half</item>
@ -55,8 +56,9 @@
<item name="android:clickable">true</item>
<item name="android:focusable">true</item>
</style>
<!-- todo: remove? <style name="setupStepStartActionLabelStyleCommon" parent="setupStepActionLabelStyleCommon">
<item name="android:paddingLeft">@dimen/setup_step_horizontal_padding</item>
<item name="android:paddingRight">@dimen/setup_step_horizontal_padding</item>
</style> -->
<!-- todo: remove? -->
<!-- <style name="setupStepStartActionLabelStyleCommon" parent="setupStepActionLabelStyleCommon">
<item name="android:paddingLeft">@dimen/setup_step_horizontal_padding</item>
<item name="android:paddingRight">@dimen/setup_step_horizontal_padding</item>
</style> -->
</resources>