remove some unnecessary stuff

This commit is contained in:
Helium314 2023-12-29 12:08:32 +01:00
parent fcff8c9098
commit dc898cd3ca
7 changed files with 16 additions and 112 deletions

View file

@ -7,7 +7,6 @@ package org.dslul.openboard.inputmethod.keyboard.internal
import android.content.Context import android.content.Context
import android.content.res.Resources import android.content.res.Resources
import org.dslul.openboard.inputmethod.latin.utils.Log
import android.util.Xml import android.util.Xml
import androidx.annotation.XmlRes import androidx.annotation.XmlRes
import org.dslul.openboard.inputmethod.annotations.UsedForTesting import org.dslul.openboard.inputmethod.annotations.UsedForTesting
@ -22,6 +21,7 @@ import org.dslul.openboard.inputmethod.latin.R
import org.dslul.openboard.inputmethod.latin.common.Constants import org.dslul.openboard.inputmethod.latin.common.Constants
import org.dslul.openboard.inputmethod.latin.define.DebugFlags import org.dslul.openboard.inputmethod.latin.define.DebugFlags
import org.dslul.openboard.inputmethod.latin.settings.Settings import org.dslul.openboard.inputmethod.latin.settings.Settings
import org.dslul.openboard.inputmethod.latin.utils.Log
import org.dslul.openboard.inputmethod.latin.utils.sumOf import org.dslul.openboard.inputmethod.latin.utils.sumOf
import org.xmlpull.v1.XmlPullParser import org.xmlpull.v1.XmlPullParser
@ -165,9 +165,6 @@ open class KeyboardBuilder<KP : KeyboardParams>(protected val mContext: Context,
} }
// determine key size and positions using relative width and height // determine key size and positions using relative width and height
// ideally this should not change anything
// but it does a little, depending on how float -> int is done (cast or round, and when to sum up gaps and width)
// still should not be more than a pixel difference
private fun determineAbsoluteValues() { private fun determineAbsoluteValues() {
var currentY = mParams.mTopPadding.toFloat() var currentY = mParams.mTopPadding.toFloat()
for (row in keysInRows) { for (row in keysInRows) {
@ -187,6 +184,7 @@ open class KeyboardBuilder<KP : KeyboardParams>(protected val mContext: Context,
// necessary for adjusting widths and positions properly // necessary for adjusting widths and positions properly
// without adding spacers whose width can then be adjusted, we would have to deal with keyXPos, // without adding spacers whose width can then be adjusted, we would have to deal with keyXPos,
// which is more complicated than expected // which is more complicated than expected
// todo: remove? maybe was only necessary with old parser
private fun fillGapsWithSpacers(row: MutableList<KeyParams>) { private fun fillGapsWithSpacers(row: MutableList<KeyParams>) {
if (mParams.mId.mElementId !in KeyboardId.ELEMENT_ALPHABET..KeyboardId.ELEMENT_SYMBOLS_SHIFTED) return if (mParams.mId.mElementId !in KeyboardId.ELEMENT_ALPHABET..KeyboardId.ELEMENT_SYMBOLS_SHIFTED) return
if (row.isEmpty()) return if (row.isEmpty()) return

View file

@ -73,7 +73,7 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co
} else { } else {
throw(UnsupportedOperationException("creating KeyboardId ${params.mId.mElementId} not supported")) throw(UnsupportedOperationException("creating KeyboardId ${params.mId.mElementId} not supported"))
} }
// rescale height if we have more than 4 rows (todo: there is some default row count in params that could be used) // rescale height if we have more than 4 rows
val heightRescale = if (keysInRows.size > 4) 4f / keysInRows.size else 1f val heightRescale = if (keysInRows.size > 4) 4f / keysInRows.size else 1f
if (heightRescale != 1f) { if (heightRescale != 1f) {
keysInRows.forEach { row -> row.forEach { it.mRelativeHeight *= heightRescale } } keysInRows.forEach { row -> row.forEach { it.mRelativeHeight *= heightRescale } }
@ -138,7 +138,8 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co
// keyboard parsed bottom-up because the number of rows is not fixed, but the functional keys // keyboard parsed bottom-up because the number of rows is not fixed, but the functional keys
// are always added to the rows near the bottom // are always added to the rows near the bottom
keysInRows.add(getBottomRowAndAdjustBaseKeys(baseKeys)) keysInRows.add(getBottomRowAndAdjustBaseKeys(baseKeys)) // not really fast, but irrelevant compared to below
// todo: this loop could use some performance improvements
baseKeys.reversed().forEachIndexed { i, it -> baseKeys.reversed().forEachIndexed { i, it ->
val row: List<KeyData> = if (i == 0 && isTablet()) { val row: List<KeyData> = if (i == 0 && isTablet()) {
// add bottom row extra keys // add bottom row extra keys

View file

@ -1,47 +0,0 @@
/*
* Copyright (C) 2008 The Android Open Source Project
* modified
* SPDX-License-Identifier: Apache-2.0 AND GPL-3.0-only
*/
package org.dslul.openboard.inputmethod.latin;
import android.app.backup.BackupAgentHelper;
import android.app.backup.BackupDataInput;
import android.app.backup.SharedPreferencesBackupHelper;
import android.content.SharedPreferences;
import android.os.ParcelFileDescriptor;
import org.dslul.openboard.inputmethod.latin.settings.LocalSettingsConstants;
import java.io.IOException;
/**
* Backup/restore agent for LatinIME.
* Currently it backs up the default shared preferences.
*/
public final class BackupAgent extends BackupAgentHelper {
private static final String PREF_SUFFIX = "_preferences";
@Override
public void onCreate() {
addHelper("shared_pref", new SharedPreferencesBackupHelper(this,
getPackageName() + PREF_SUFFIX));
}
@Override
public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
throws IOException {
// Let the restore operation go through
super.onRestore(data, appVersionCode, newState);
// Remove the preferences that we don't want restored.
final SharedPreferences.Editor prefEditor = getSharedPreferences(
getPackageName() + PREF_SUFFIX, MODE_PRIVATE).edit();
for (final String key : LocalSettingsConstants.PREFS_TO_SKIP_RESTORING) {
prefEditor.remove(key);
}
// Flush the changes to disk.
prefEditor.commit();
}
}

View file

@ -1,42 +0,0 @@
/*
* Copyright (C) 2014 The Android Open Source Project
* modified
* SPDX-License-Identifier: Apache-2.0 AND GPL-3.0-only
*/
package org.dslul.openboard.inputmethod.latin.settings;
/**
* Collection of device specific preference constants.
*/
public class LocalSettingsConstants {
// Preference file for storing preferences that are tied to a device
// and are not backed up.
public static final String PREFS_FILE = "local_prefs";
// Preference key for the current account.
// Do not restore.
public static final String PREF_ACCOUNT_NAME = "pref_account_name";
// Preference key for enabling cloud sync feature.
// Do not restore.
public static final String PREF_ENABLE_CLOUD_SYNC = "pref_enable_cloud_sync";
// List of preference keys to skip from being restored by backup agent.
// These preferences are tied to a device and hence should not be restored.
// e.g. account name.
// Ideally they could have been kept in a separate file that wasn't backed up
// however the preference UI currently only deals with the default
// shared preferences which makes it non-trivial to move these out to
// a different shared preferences file.
public static final String[] PREFS_TO_SKIP_RESTORING = new String[] {
PREF_ACCOUNT_NAME,
PREF_ENABLE_CLOUD_SYNC,
// The debug settings are not restored on a new device.
// If a feature relies on these, it should ensure that the defaults are
// correctly set for it to work on a new device.
DebugSettings.PREF_DEBUG_MODE,
DebugSettings.PREF_FORCE_NON_DISTINCT_MULTITOUCH,
DebugSettings.PREF_SHOULD_SHOW_LXX_SUGGESTION_UI,
DebugSettings.PREF_SLIDING_KEY_INPUT_PREVIEW
};
}

View file

@ -166,6 +166,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
add(PREF_EMOJI_RECENT_KEYS); add(PREF_EMOJI_RECENT_KEYS);
add(PREF_DONT_SHOW_MISSING_DICTIONARY_DIALOG); add(PREF_DONT_SHOW_MISSING_DICTIONARY_DIALOG);
add(PREF_SHOW_ALL_COLORS); add(PREF_SHOW_ALL_COLORS);
add(PREF_SELECTED_INPUT_STYLE);
}}; }};
public static Settings getInstance() { public static Settings getInstance() {
@ -251,9 +252,8 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static boolean readVibrationEnabled(final SharedPreferences prefs, public static boolean readVibrationEnabled(final SharedPreferences prefs,
final Resources res) { final Resources res) {
final boolean hasVibrator = AudioAndHapticFeedbackManager.getInstance().hasVibrator(); return prefs.getBoolean(PREF_VIBRATE_ON, res.getBoolean(R.bool.config_default_vibration_enabled))
return hasVibrator && prefs.getBoolean(PREF_VIBRATE_ON, && AudioAndHapticFeedbackManager.getInstance().hasVibrator();
res.getBoolean(R.bool.config_default_vibration_enabled));
} }
public static boolean readAutoCorrectEnabled(final SharedPreferences prefs) { public static boolean readAutoCorrectEnabled(final SharedPreferences prefs) {

View file

@ -46,7 +46,6 @@ public class SettingsValues {
// Float.NEGATIVE_INFINITE and Float.MAX_VALUE. Currently used for auto-correction settings. // Float.NEGATIVE_INFINITE and Float.MAX_VALUE. Currently used for auto-correction settings.
private static final String FLOAT_MAX_VALUE_MARKER_STRING = "floatMaxValue"; private static final String FLOAT_MAX_VALUE_MARKER_STRING = "floatMaxValue";
private static final String FLOAT_NEGATIVE_INFINITY_MARKER_STRING = "floatNegativeInfinity"; private static final String FLOAT_NEGATIVE_INFINITY_MARKER_STRING = "floatNegativeInfinity";
private static final int TIMEOUT_TO_GET_TARGET_PACKAGE = 5; // seconds
public static final float DEFAULT_SIZE_SCALE = 1.0f; // 100% public static final float DEFAULT_SIZE_SCALE = 1.0f; // 100%
public static final float AUTO_CORRECTION_DISABLED_THRESHOLD = Float.MAX_VALUE; public static final float AUTO_CORRECTION_DISABLED_THRESHOLD = Float.MAX_VALUE;
@ -96,9 +95,7 @@ public class SettingsValues {
public final boolean mSlidingKeyInputPreviewEnabled; public final boolean mSlidingKeyInputPreviewEnabled;
public final int mKeyLongpressTimeout; public final int mKeyLongpressTimeout;
public final boolean mEnableEmojiAltPhysicalKey; public final boolean mEnableEmojiAltPhysicalKey;
public final boolean mShowAppIcon;
public final boolean mIsShowAppIconSettingInPreferences; public final boolean mIsShowAppIconSettingInPreferences;
public final boolean mCloudSyncEnabled;
public final boolean mShouldShowLxxSuggestionUi; public final boolean mShouldShowLxxSuggestionUi;
// Use split layout for keyboard. // Use split layout for keyboard.
public final boolean mIsSplitKeyboardEnabled; public final boolean mIsSplitKeyboardEnabled;
@ -109,7 +106,6 @@ public class SettingsValues {
public final boolean mCustomNavBarColor; public final boolean mCustomNavBarColor;
public final float mKeyboardHeightScale; public final float mKeyboardHeightScale;
public final boolean mUrlDetectionEnabled; public final boolean mUrlDetectionEnabled;
public final List<ToolbarKey> mPinnedKeys;
public final float mBottomPaddingScale; public final float mBottomPaddingScale;
// From the input box // From the input box
@ -134,6 +130,7 @@ public class SettingsValues {
@Nullable @Nullable
public final String mAccount; public final String mAccount;
// creation of Colors and SpacingAndPunctuations are the slowest parts in here, but still ok
public SettingsValues(final Context context, final SharedPreferences prefs, final Resources res, public SettingsValues(final Context context, final SharedPreferences prefs, final Resources res,
@NonNull final InputAttributes inputAttributes) { @NonNull final InputAttributes inputAttributes) {
mLocale = res.getConfiguration().locale; mLocale = res.getConfiguration().locale;
@ -186,15 +183,11 @@ public class SettingsValues {
mKeyLongpressTimeout = Settings.readKeyLongpressTimeout(prefs, res); mKeyLongpressTimeout = Settings.readKeyLongpressTimeout(prefs, res);
mKeypressVibrationDuration = Settings.readKeypressVibrationDuration(prefs, res); mKeypressVibrationDuration = Settings.readKeypressVibrationDuration(prefs, res);
mKeypressSoundVolume = Settings.readKeypressSoundVolume(prefs, res); mKeypressSoundVolume = Settings.readKeypressSoundVolume(prefs, res);
mEnableEmojiAltPhysicalKey = prefs.getBoolean( mEnableEmojiAltPhysicalKey = prefs.getBoolean(Settings.PREF_ENABLE_EMOJI_ALT_PHYSICAL_KEY, true);
Settings.PREF_ENABLE_EMOJI_ALT_PHYSICAL_KEY, true);
mShowAppIcon = Settings.readShowSetupWizardIcon(prefs, context);
mIsShowAppIconSettingInPreferences = prefs.contains(Settings.PREF_SHOW_SETUP_WIZARD_ICON); mIsShowAppIconSettingInPreferences = prefs.contains(Settings.PREF_SHOW_SETUP_WIZARD_ICON);
mGestureInputEnabled = Settings.readGestureInputEnabled(prefs); mGestureInputEnabled = Settings.readGestureInputEnabled(prefs);
mGestureTrailEnabled = prefs.getBoolean(Settings.PREF_GESTURE_PREVIEW_TRAIL, true); mGestureTrailEnabled = prefs.getBoolean(Settings.PREF_GESTURE_PREVIEW_TRAIL, true);
mCloudSyncEnabled = prefs.getBoolean(LocalSettingsConstants.PREF_ENABLE_CLOUD_SYNC, false); mAccount = null; // remove? or can it be useful somewhere?
mAccount = prefs.getString(LocalSettingsConstants.PREF_ACCOUNT_NAME,
null /* default */);
mGestureFloatingPreviewTextEnabled = !mInputAttributes.mDisableGestureFloatingPreviewText mGestureFloatingPreviewTextEnabled = !mInputAttributes.mDisableGestureFloatingPreviewText
&& prefs.getBoolean(Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT, true); && prefs.getBoolean(Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT, true);
mAutoCorrectionEnabledPerUserSettings = mAutoCorrectEnabled; mAutoCorrectionEnabledPerUserSettings = mAutoCorrectEnabled;
@ -250,7 +243,6 @@ public class SettingsValues {
prefs.getBoolean(Settings.PREF_GESTURE_SPACE_AWARE, false) prefs.getBoolean(Settings.PREF_GESTURE_SPACE_AWARE, false)
); );
mUrlDetectionEnabled = prefs.getBoolean(Settings.PREF_URL_DETECTION, false); mUrlDetectionEnabled = prefs.getBoolean(Settings.PREF_URL_DETECTION, false);
mPinnedKeys = Settings.readPinnedKeys(prefs);
mSpacingAndPunctuations = new SpacingAndPunctuations(res, mUrlDetectionEnabled); mSpacingAndPunctuations = new SpacingAndPunctuations(res, mUrlDetectionEnabled);
mBottomPaddingScale = prefs.getFloat(Settings.PREF_BOTTOM_PADDING_SCALE, DEFAULT_SIZE_SCALE); mBottomPaddingScale = prefs.getFloat(Settings.PREF_BOTTOM_PADDING_SCALE, DEFAULT_SIZE_SCALE);
} }

View file

@ -13,6 +13,7 @@ import android.app.KeyguardManager;
import android.content.ClipData; import android.content.ClipData;
import android.content.ClipboardManager; import android.content.ClipboardManager;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources; import android.content.res.Resources;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.Color; import android.graphics.Color;
@ -141,7 +142,8 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
public SuggestionStripView(final Context context, final AttributeSet attrs, final int defStyle) { public SuggestionStripView(final Context context, final AttributeSet attrs, final int defStyle) {
super(context, attrs, defStyle); super(context, attrs, defStyle);
final Colors colors = Settings.getInstance().getCurrent().mColors; final Colors colors = Settings.getInstance().getCurrent().mColors;
DEBUG_SUGGESTIONS = DeviceProtectedUtils.getSharedPreferences(context).getBoolean(DebugSettings.PREF_SHOW_SUGGESTION_INFOS, false); final SharedPreferences prefs = DeviceProtectedUtils.getSharedPreferences(context);
DEBUG_SUGGESTIONS = prefs.getBoolean(DebugSettings.PREF_SHOW_SUGGESTION_INFOS, false);
final LayoutInflater inflater = LayoutInflater.from(context); final LayoutInflater inflater = LayoutInflater.from(context);
inflater.inflate(R.layout.suggestions_strip, this); inflater.inflate(R.layout.suggestions_strip, this);
@ -188,7 +190,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
getResources().getDimensionPixelSize(R.dimen.config_suggestions_strip_edge_key_width), getResources().getDimensionPixelSize(R.dimen.config_suggestions_strip_edge_key_width),
LinearLayout.LayoutParams.MATCH_PARENT LinearLayout.LayoutParams.MATCH_PARENT
); );
for (final ToolbarKey key : ToolbarUtilsKt.getEnabledToolbarKeys(DeviceProtectedUtils.getSharedPreferences(context))) { for (final ToolbarKey key : ToolbarUtilsKt.getEnabledToolbarKeys(prefs)) {
final ImageButton button = createToolbarKey(context, keyboardAttr, key); final ImageButton button = createToolbarKey(context, keyboardAttr, key);
button.setLayoutParams(toolbarKeyLayoutParams); button.setLayoutParams(toolbarKeyLayoutParams);
setupKey(button, colors); setupKey(button, colors);
@ -213,7 +215,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
mToolbarExpandKey.getLayoutParams().height *= 0.82; // shrink the whole key a little (drawable not affected) mToolbarExpandKey.getLayoutParams().height *= 0.82; // shrink the whole key a little (drawable not affected)
mToolbarExpandKey.getLayoutParams().width *= 0.82; mToolbarExpandKey.getLayoutParams().width *= 0.82;
for (final ToolbarKey pinnedKey : Settings.getInstance().getCurrent().mPinnedKeys) { for (final ToolbarKey pinnedKey : Settings.readPinnedKeys(prefs)) {
final View pinnedKeyInToolbar = mToolbar.findViewWithTag(pinnedKey); final View pinnedKeyInToolbar = mToolbar.findViewWithTag(pinnedKey);
if (pinnedKeyInToolbar == null) continue; if (pinnedKeyInToolbar == null) continue;
pinnedKeyInToolbar.setBackground(mEnabledToolKeyBackground); pinnedKeyInToolbar.setBackground(mEnabledToolKeyBackground);