// Path: app/src/main/java/com/vlath/keyboard/latin/settings/SettingsValues.java
// public class SettingsValues {
//     public static final float DEFAULT_SIZE_SCALE = 1.0f; // 100%
// 
//     // From resources:
//     public final SpacingAndPunctuations mSpacingAndPunctuations;
//     // From configuration:
//     public final Locale mLocale;
//     public final boolean mHasHardwareKeyboard;
//     public final int mDisplayOrientation;
//     // From preferences, in the same order as xml/prefs.xml:
//     public final boolean mAutoCap;
//     public final boolean mVibrateOn;
//     public final boolean mSoundOn;
//     public final boolean mKeyPreviewPopupOn;
//     public final boolean mShowsLanguageSwitchKey;
//     public final int mKeyLongpressTimeout;
//     //public final boolean mShouldShowLxxSuggestionUi;
//     public final boolean mHideSpecialChars;
//     public final boolean mShowNumberRow;
//     public final boolean mSpaceSwipeEnabled;
// 
//     // From the input box
//     @NonNull
//     public final InputAttributes mInputAttributes;
// 
//     // Deduced settings
//     public final int mKeypressVibrationDuration;
//     public final float mKeypressSoundVolume;
//     public final int mKeyPreviewPopupDismissDelay;
// 
//     // Debug settings
//     public final boolean mHasKeyboardResize;
//     public final float mKeyboardHeightScale;
//     public final int mKeyPreviewShowUpDuration;
//     public final int mKeyPreviewDismissDuration;
//     public final float mKeyPreviewShowUpStartXScale;
//     public final float mKeyPreviewShowUpStartYScale;
//     public final float mKeyPreviewDismissEndXScale;
//     public final float mKeyPreviewDismissEndYScale;
// 
//     public SettingsValues(final SharedPreferences prefs, final Resources res,
//             @NonNull final InputAttributes inputAttributes) {
//         mLocale = res.getConfiguration().locale;
//         // Get the resources
//         mSpacingAndPunctuations = new SpacingAndPunctuations(res);
// 
//         // Store the input attributes
//         mInputAttributes = inputAttributes;
// 
//         // Get the settings preferences
//         mAutoCap = prefs.getBoolean(Settings.PREF_AUTO_CAP, true);
//         mVibrateOn = false;
//         mSoundOn = Settings.readKeypressSoundEnabled(prefs, res);
//         mKeyPreviewPopupOn = Settings.readKeyPreviewPopupEnabled(prefs, res);
//         mShowsLanguageSwitchKey = false;
//         mHasHardwareKeyboard = Settings.readHasHardwareKeyboard(res.getConfiguration());
// 
//         // Compute other readable settings
//         mKeyLongpressTimeout = Settings.readKeyLongpressTimeout(prefs, res);
//         mKeypressVibrationDuration = Settings.readKeypressVibrationDuration(prefs, res);
//         mKeypressSoundVolume = Settings.readKeypressSoundVolume(prefs, res);
//         mKeyPreviewPopupDismissDelay = Settings.readKeyPreviewPopupDismissDelay(prefs, res);
//         mHasKeyboardResize = true;
//         mKeyboardHeightScale = Settings.readKeyboardHeight(prefs, DEFAULT_SIZE_SCALE);
//         mKeyPreviewShowUpDuration = res.getInteger(R.integer.config_key_preview_show_up_duration);
//         mKeyPreviewDismissDuration = res.getInteger(R.integer.config_key_preview_dismiss_duration);
//         final float defaultKeyPreviewShowUpStartScale = ResourceUtils.getFloatFromFraction(
//                 res, R.fraction.config_key_preview_show_up_start_scale);
//         final float defaultKeyPreviewDismissEndScale = ResourceUtils.getFloatFromFraction(
//                 res, R.fraction.config_key_preview_dismiss_end_scale);
//         mKeyPreviewShowUpStartXScale = defaultKeyPreviewShowUpStartScale;
//         mKeyPreviewShowUpStartYScale = defaultKeyPreviewShowUpStartScale;
//         mKeyPreviewDismissEndXScale = defaultKeyPreviewDismissEndScale;
//         mKeyPreviewDismissEndYScale = defaultKeyPreviewDismissEndScale;
//         mDisplayOrientation = res.getConfiguration().orientation;
//         mHideSpecialChars = Settings.readHideSpecialChars(prefs);
//         mShowNumberRow = Settings.readShowNumberRow(prefs);
//         mSpaceSwipeEnabled = Settings.readSpaceSwipeEnabled(prefs);
//     }
// 
//     public boolean isWordSeparator(final int code) {
//         return mSpacingAndPunctuations.isWordSeparator(code);
//     }
// 
//     public boolean isLanguageSwitchKeyEnabled() {
//         if (!mShowsLanguageSwitchKey) {
//             return false;
//         }
//         final RichInputMethodManager imm = RichInputMethodManager.getInstance();
//         return imm.hasMultipleEnabledIMEsOrSubtypes(false /* include aux subtypes */);
//     }
// 
//     public boolean isSameInputType(final EditorInfo editorInfo) {
//         return mInputAttributes.isSameInputType(editorInfo);
//     }
// 
//     public boolean hasSameOrientation(final Configuration configuration) {
//         return mDisplayOrientation == configuration.orientation;
//     }
// }


import com.vlath.keyboard.latin.settings.SettingsValues;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.os.Build;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.regex.PatternSyntaxException;
import com.vlath.keyboard.R;
import com.vlath.keyboard.annotations.UsedForTesting;
        // Check all patterns in a condition are true
        boolean matchedAll = true;
        for (final String pattern : patterns) {
            final int posEqual = pattern.indexOf('=');
            if (posEqual < 0) {
                throw new DeviceOverridePatternSyntaxError("Pattern has no '='", condition);
            }
            final String key = pattern.substring(0, posEqual);
            final String value = keyValuePairs.get(key);
            if (value == null) {
                throw new DeviceOverridePatternSyntaxError("Unknown key", condition);
            }
            final String patternRegexpValue = pattern.substring(posEqual + 1);
            try {
                if (!value.matches(patternRegexpValue)) {
                    matchedAll = false;
                    // And continue walking through all patterns.
                }
            } catch (final PatternSyntaxException e) {
                throw new DeviceOverridePatternSyntaxError("Syntax error", condition, e);
            }
        }
        return matchedAll;
    }

    public static int getDefaultKeyboardWidth(final Resources res) {
        final DisplayMetrics dm = res.getDisplayMetrics();
        return dm.widthPixels;
    }

// Path: app/src/main/java/com/vlath/keyboard/latin/settings/SettingsValues.java
// public class SettingsValues {
//     public static final float DEFAULT_SIZE_SCALE = 1.0f; // 100%
// 
//     // From resources:
//     public final SpacingAndPunctuations mSpacingAndPunctuations;
//     // From configuration:
//     public final Locale mLocale;
//     public final boolean mHasHardwareKeyboard;
//     public final int mDisplayOrientation;
//     // From preferences, in the same order as xml/prefs.xml:
//     public final boolean mAutoCap;
//     public final boolean mVibrateOn;
//     public final boolean mSoundOn;
//     public final boolean mKeyPreviewPopupOn;
//     public final boolean mShowsLanguageSwitchKey;
//     public final int mKeyLongpressTimeout;
//     //public final boolean mShouldShowLxxSuggestionUi;
//     public final boolean mHideSpecialChars;
//     public final boolean mShowNumberRow;
//     public final boolean mSpaceSwipeEnabled;
// 
//     // From the input box
//     @NonNull
//     public final InputAttributes mInputAttributes;
// 
//     // Deduced settings
//     public final int mKeypressVibrationDuration;
//     public final float mKeypressSoundVolume;
//     public final int mKeyPreviewPopupDismissDelay;
// 
//     // Debug settings
//     public final boolean mHasKeyboardResize;
//     public final float mKeyboardHeightScale;
//     public final int mKeyPreviewShowUpDuration;
//     public final int mKeyPreviewDismissDuration;
//     public final float mKeyPreviewShowUpStartXScale;
//     public final float mKeyPreviewShowUpStartYScale;
//     public final float mKeyPreviewDismissEndXScale;
//     public final float mKeyPreviewDismissEndYScale;
// 
//     public SettingsValues(final SharedPreferences prefs, final Resources res,
//             @NonNull final InputAttributes inputAttributes) {
//         mLocale = res.getConfiguration().locale;
//         // Get the resources
//         mSpacingAndPunctuations = new SpacingAndPunctuations(res);
// 
//         // Store the input attributes
//         mInputAttributes = inputAttributes;
// 
//         // Get the settings preferences
//         mAutoCap = prefs.getBoolean(Settings.PREF_AUTO_CAP, true);
//         mVibrateOn = false;
//         mSoundOn = Settings.readKeypressSoundEnabled(prefs, res);
//         mKeyPreviewPopupOn = Settings.readKeyPreviewPopupEnabled(prefs, res);
//         mShowsLanguageSwitchKey = false;
//         mHasHardwareKeyboard = Settings.readHasHardwareKeyboard(res.getConfiguration());
// 
//         // Compute other readable settings
//         mKeyLongpressTimeout = Settings.readKeyLongpressTimeout(prefs, res);
//         mKeypressVibrationDuration = Settings.readKeypressVibrationDuration(prefs, res);
//         mKeypressSoundVolume = Settings.readKeypressSoundVolume(prefs, res);
//         mKeyPreviewPopupDismissDelay = Settings.readKeyPreviewPopupDismissDelay(prefs, res);
//         mHasKeyboardResize = true;
//         mKeyboardHeightScale = Settings.readKeyboardHeight(prefs, DEFAULT_SIZE_SCALE);
//         mKeyPreviewShowUpDuration = res.getInteger(R.integer.config_key_preview_show_up_duration);
//         mKeyPreviewDismissDuration = res.getInteger(R.integer.config_key_preview_dismiss_duration);
//         final float defaultKeyPreviewShowUpStartScale = ResourceUtils.getFloatFromFraction(
//                 res, R.fraction.config_key_preview_show_up_start_scale);
//         final float defaultKeyPreviewDismissEndScale = ResourceUtils.getFloatFromFraction(
//                 res, R.fraction.config_key_preview_dismiss_end_scale);
//         mKeyPreviewShowUpStartXScale = defaultKeyPreviewShowUpStartScale;
//         mKeyPreviewShowUpStartYScale = defaultKeyPreviewShowUpStartScale;
//         mKeyPreviewDismissEndXScale = defaultKeyPreviewDismissEndScale;
//         mKeyPreviewDismissEndYScale = defaultKeyPreviewDismissEndScale;
//         mDisplayOrientation = res.getConfiguration().orientation;
//         mHideSpecialChars = Settings.readHideSpecialChars(prefs);
//         mShowNumberRow = Settings.readShowNumberRow(prefs);
//         mSpaceSwipeEnabled = Settings.readSpaceSwipeEnabled(prefs);
//     }
// 
//     public boolean isWordSeparator(final int code) {
//         return mSpacingAndPunctuations.isWordSeparator(code);
//     }
// 
//     public boolean isLanguageSwitchKeyEnabled() {
//         if (!mShowsLanguageSwitchKey) {
//             return false;
//         }
//         final RichInputMethodManager imm = RichInputMethodManager.getInstance();
//         return imm.hasMultipleEnabledIMEsOrSubtypes(false /* include aux subtypes */);
//     }
// 
//     public boolean isSameInputType(final EditorInfo editorInfo) {
//         return mInputAttributes.isSameInputType(editorInfo);
//     }
// 
//     public boolean hasSameOrientation(final Configuration configuration) {
//         return mDisplayOrientation == configuration.orientation;
//     }
// }


// Path: app/src/main/java/com/vlath/keyboard/latin/utils/ResourceUtils.java
import com.vlath.keyboard.latin.settings.SettingsValues;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.os.Build;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.regex.PatternSyntaxException;
import com.vlath.keyboard.R;
import com.vlath.keyboard.annotations.UsedForTesting;

        // Check all patterns in a condition are true
        boolean matchedAll = true;
        for (final String pattern : patterns) {
            final int posEqual = pattern.indexOf('=');
            if (posEqual < 0) {
                throw new DeviceOverridePatternSyntaxError("Pattern has no '='", condition);
            }
            final String key = pattern.substring(0, posEqual);
            final String value = keyValuePairs.get(key);
            if (value == null) {
                throw new DeviceOverridePatternSyntaxError("Unknown key", condition);
            }
            final String patternRegexpValue = pattern.substring(posEqual + 1);
            try {
                if (!value.matches(patternRegexpValue)) {
                    matchedAll = false;
                    // And continue walking through all patterns.
                }
            } catch (final PatternSyntaxException e) {
                throw new DeviceOverridePatternSyntaxError("Syntax error", condition, e);
            }
        }
        return matchedAll;
    }

    public static int getDefaultKeyboardWidth(final Resources res) {
        final DisplayMetrics dm = res.getDisplayMetrics();
        return dm.widthPixels;
    }

    public static int getKeyboardHeight(final Resources res, final SettingsValues settingsValues) {