Inline autofill theming support (#360)

This commit is contained in:
arcarum 2023-12-29 15:27:47 +04:00 committed by GitHub
parent a323baca5f
commit 98fb94de8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 8 deletions

View file

@ -244,7 +244,7 @@ class DynamicColors(context: Context, override val themeStyle: String, override
override fun get(color: ColorType): Int = when (color) {
TOOL_BAR_KEY_ENABLED_BACKGROUND, EMOJI_CATEGORY_SELECTED, ACTION_KEY_BACKGROUND,
CLIPBOARD_PIN, SHIFT_KEY_ICON -> accent
EMOJI_CATEGORY_BACKGROUND, GESTURE_PREVIEW, MORE_KEYS_BACKGROUND, MORE_SUGGESTIONS_BACKGROUND, KEY_PREVIEW -> adjustedBackground
CHIP, EMOJI_CATEGORY_BACKGROUND, GESTURE_PREVIEW, MORE_KEYS_BACKGROUND, MORE_SUGGESTIONS_BACKGROUND, KEY_PREVIEW -> adjustedBackground
TOOL_BAR_EXPAND_KEY_BACKGROUND -> if (!isNight) accent else doubleAdjustedBackground
GESTURE_TRAIL -> gesture
KEY_TEXT, SUGGESTION_AUTO_CORRECT, REMOVE_SUGGESTION_ICON, CLEAR_CLIPBOARD_HISTORY_KEY,
@ -442,7 +442,7 @@ class DefaultColors (
override fun get(color: ColorType): Int = when (color) {
TOOL_BAR_KEY_ENABLED_BACKGROUND, EMOJI_CATEGORY_SELECTED, ACTION_KEY_BACKGROUND,
CLIPBOARD_PIN, SHIFT_KEY_ICON -> accent
EMOJI_CATEGORY_BACKGROUND, GESTURE_PREVIEW, MORE_KEYS_BACKGROUND, MORE_SUGGESTIONS_BACKGROUND, KEY_PREVIEW -> adjustedBackground
CHIP, EMOJI_CATEGORY_BACKGROUND, GESTURE_PREVIEW, MORE_KEYS_BACKGROUND, MORE_SUGGESTIONS_BACKGROUND, KEY_PREVIEW -> adjustedBackground
TOOL_BAR_EXPAND_KEY_BACKGROUND -> doubleAdjustedBackground
GESTURE_TRAIL -> gesture
KEY_TEXT, SUGGESTION_AUTO_CORRECT, REMOVE_SUGGESTION_ICON, CLEAR_CLIPBOARD_HISTORY_KEY, FUNCTIONAL_KEY_TEXT,
@ -551,6 +551,7 @@ enum class ColorType {
ACTION_KEY_BACKGROUND,
ACTION_KEY_MORE_KEYS_BACKGROUND,
BACKGROUND,
CHIP,
CLEAR_CLIPBOARD_HISTORY_KEY,
CLIPBOARD_PIN,
CLIPBOARD_BACKGROUND,

View file

@ -10,11 +10,9 @@ import static android.util.TypedValue.COMPLEX_UNIT_DIP;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Icon;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.util.Size;
import android.util.TypedValue;
import android.view.ViewGroup;
@ -32,6 +30,9 @@ import androidx.autofill.inline.common.ViewStyle;
import androidx.autofill.inline.v1.InlineSuggestionUi;
import org.dslul.openboard.inputmethod.latin.R;
import org.dslul.openboard.inputmethod.latin.common.ColorType;
import org.dslul.openboard.inputmethod.latin.common.Colors;
import org.dslul.openboard.inputmethod.latin.settings.Settings;
import java.util.ArrayList;
import java.util.List;
@ -51,32 +52,36 @@ public class InlineAutofillUtils {
public static InlineSuggestionsRequest createInlineSuggestionRequest(Context context) {
final Colors colors = Settings.getInstance().getCurrent().mColors;
UiVersions.StylesBuilder stylesBuilder = UiVersions.newStylesBuilder();
@SuppressLint("RestrictedApi") InlineSuggestionUi.Style style = InlineSuggestionUi.newStyleBuilder()
.setSingleIconChipStyle(
new ViewStyle.Builder()
.setBackground(
Icon.createWithResource(context,
androidx.autofill.R.drawable.autofill_inline_suggestion_chip_background))
androidx.autofill.R.drawable.autofill_inline_suggestion_chip_background)
.setTint(colors.get(ColorType.CHIP)))
.setPadding(0, 0, 0, 0)
.build())
.setChipStyle(
new ViewStyle.Builder()
.setBackground(
Icon.createWithResource(context,
androidx.autofill.R.drawable.autofill_inline_suggestion_chip_background))
androidx.autofill.R.drawable.autofill_inline_suggestion_chip_background)
.setTint(colors.get(ColorType.CHIP)))
.build())
.setStartIconStyle(new ImageViewStyle.Builder().setLayoutMargin(0, 0, 0, 0).build())
.setTitleStyle(
new TextViewStyle.Builder()
.setLayoutMargin(toPixel(4, context), 0, toPixel(4, context), 0)
.setTextColor(Color.parseColor("#FF202124"))
.setTextColor(colors.get(ColorType.KEY_TEXT))
.setTextSize(12)
.build())
.setSubtitleStyle(
new TextViewStyle.Builder()
.setLayoutMargin(0, 0, toPixel(4, context), 0)
.setTextColor(Color.parseColor("#99202124"))
.setTextColor(colors.get(ColorType.KEY_HINT_TEXT))
.setTextSize(10)
.build())
.setEndIconStyle(new ImageViewStyle.Builder().setLayoutMargin(0, 0, 0, 0).build())