mirror of
https://github.com/Julow/Unexpected-Keyboard.git
synced 2025-08-19 10:31:58 +02:00
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
fc68f2e07d | ||
|
8350efaa83 | ||
|
ef34303c7e | ||
|
f1ce6abe5a | ||
|
29fbb27a8a |
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="juloo.keyboard2" android:versionCode="27" android:versionName="1.19.0" android:hardwareAccelerated="false">
|
||||
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="30"/>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="juloo.keyboard2" android:versionCode="28" android:versionName="1.19.1" android:hardwareAccelerated="false">
|
||||
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="31"/>
|
||||
<application android:label="@string/app_name" android:allowBackup="true" android:icon="@drawable/ic_launcher" android:hardwareAccelerated="false">
|
||||
<service android:name="juloo.keyboard2.Keyboard2" android:label="@string/app_name" android:permission="android.permission.BIND_INPUT_METHOD" android:exported="true" android:directBootAware="true">
|
||||
<intent-filter>
|
||||
@@ -8,7 +8,7 @@
|
||||
</intent-filter>
|
||||
<meta-data android:name="android.view.im" android:resource="@xml/method"/>
|
||||
</service>
|
||||
<activity android:name="juloo.keyboard2.SettingsActivity" android:icon="@drawable/ic_launcher" android:label="@string/settings_activity_label" android:theme="@style/android:Theme.DeviceDefault">
|
||||
<activity android:name="juloo.keyboard2.SettingsActivity" android:icon="@drawable/ic_launcher" android:label="@string/settings_activity_label" android:theme="@style/android:Theme.DeviceDefault" android:exported="true" android:directBootAware="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
</intent-filter>
|
||||
|
6
metadata/android/en-US/changelogs/28.txt
Normal file
6
metadata/android/en-US/changelogs/28.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
Updated translations: Latvian
|
||||
|
||||
Fix crash when typing device password
|
||||
Increase target SDK version to 31
|
||||
|
||||
Thanks to the contributors: @eandersons
|
@@ -10,6 +10,10 @@
|
||||
<string name="pref_accents_e_all_installed">Rādīt uzsvara zīmes visām uzstādītajām valodām</string>
|
||||
<string name="pref_accents_e_selected">Rādīt uzsvara zīmes tikai atlasītajām valodām</string>
|
||||
<string name="pref_accents_e_none">Paslēpt uzsvara zīmes</string>
|
||||
<string name="pref_show_numpad_title">Rādīt ciparnīcu</string>
|
||||
<string name="pref_show_numpad_never">Nekad</string>
|
||||
<string name="pref_show_numpad_landscape">Tikai guleniskajā skatā</string>
|
||||
<string name="pref_show_numpad_always">Vienmēr</string>
|
||||
<string name="pref_autocapitalisation_title">Automātiski lielie burti</string>
|
||||
<string name="pref_autocapitalisation_summary">Piespiest Shift teikuma sākumā</string>
|
||||
<string name="pref_extra_keys_title">Pievienot tastatūrai taustiņus</string>
|
||||
@@ -38,6 +42,7 @@
|
||||
<string name="pref_theme_e_dark">Tumšs</string>
|
||||
<string name="pref_theme_e_light">Gaišs</string>
|
||||
<string name="pref_theme_e_black">Melns</string>
|
||||
<string name="pref_theme_e_white">Balts</string>
|
||||
<string name="pref_swipe_dist_e_very_short">Ļoti tuvs</string>
|
||||
<string name="pref_swipe_dist_e_short">Tuvs</string>
|
||||
<string name="pref_swipe_dist_e_default">Vidējs</string>
|
||||
|
@@ -5,7 +5,6 @@ import android.content.res.Resources;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.TypedValue;
|
||||
import android.view.KeyEvent;
|
||||
@@ -15,6 +14,8 @@ import java.util.HashSet;
|
||||
|
||||
final class Config
|
||||
{
|
||||
private final SharedPreferences _prefs;
|
||||
|
||||
// From resources
|
||||
public final float marginTop;
|
||||
public final float keyPadding;
|
||||
@@ -53,9 +54,9 @@ final class Config
|
||||
|
||||
public final IKeyEventHandler handler;
|
||||
|
||||
private Config(Context context, IKeyEventHandler h)
|
||||
private Config(SharedPreferences prefs, Resources res, IKeyEventHandler h)
|
||||
{
|
||||
Resources res = context.getResources();
|
||||
_prefs = prefs;
|
||||
// static values
|
||||
marginTop = res.getDimension(R.dimen.margin_top);
|
||||
keyPadding = res.getDimension(R.dimen.key_padding);
|
||||
@@ -76,7 +77,7 @@ final class Config
|
||||
characterSize = 1.f;
|
||||
accents = 1;
|
||||
// from prefs
|
||||
refresh(context);
|
||||
refresh(res);
|
||||
// initialized later
|
||||
shouldOfferSwitchingToNextInputMethod = false;
|
||||
shouldOfferSwitchingToProgramming = false;
|
||||
@@ -90,10 +91,8 @@ final class Config
|
||||
/*
|
||||
** Reload prefs
|
||||
*/
|
||||
public void refresh(Context context)
|
||||
public void refresh(Resources res)
|
||||
{
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
Resources res = context.getResources();
|
||||
DisplayMetrics dm = res.getDisplayMetrics();
|
||||
// The height of the keyboard is relative to the height of the screen.
|
||||
// This is the height of the keyboard if it have 4 rows.
|
||||
@@ -101,52 +100,52 @@ final class Config
|
||||
// Scale some dimensions depending on orientation
|
||||
float horizontalIntervalScale = 1.f;
|
||||
float characterSizeScale = 1.f;
|
||||
String show_numpad_s = prefs.getString("show_numpad", "never");
|
||||
String show_numpad_s = _prefs.getString("show_numpad", "never");
|
||||
show_numpad = "always".equals(show_numpad_s);
|
||||
if (res.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) // Landscape mode
|
||||
{
|
||||
if ("landscape".equals(show_numpad_s))
|
||||
show_numpad = true;
|
||||
keyboardHeightPercent = prefs.getInt("keyboard_height_landscape", 50);
|
||||
keyboardHeightPercent = _prefs.getInt("keyboard_height_landscape", 50);
|
||||
horizontalIntervalScale = 2.f;
|
||||
characterSizeScale = 1.25f;
|
||||
}
|
||||
else
|
||||
{
|
||||
keyboardHeightPercent = prefs.getInt("keyboard_height", 35);
|
||||
keyboardHeightPercent = _prefs.getInt("keyboard_height", 35);
|
||||
}
|
||||
String layout_s = prefs.getString("layout", "system");
|
||||
String layout_s = _prefs.getString("layout", "system");
|
||||
layout = layout_s.equals("system") ? -1 : layoutId_of_string(layout_s);
|
||||
String prog_layout_s = prefs.getString("programming_layout", "none");
|
||||
String prog_layout_s = _prefs.getString("programming_layout", "none");
|
||||
programming_layout = prog_layout_s.equals("none") ? -1 : layoutId_of_string(prog_layout_s);
|
||||
// The swipe distance is defined relatively to the "exact physical pixels
|
||||
// per inch of the screen", which isn't affected by the scaling settings.
|
||||
// Take the mean of both dimensions as an approximation of the diagonal.
|
||||
float physical_scaling = (dm.widthPixels + dm.heightPixels) / (dm.xdpi + dm.ydpi);
|
||||
swipe_dist_px = Float.valueOf(prefs.getString("swipe_dist", "15")) * physical_scaling;;
|
||||
vibrateEnabled = prefs.getBoolean("vibrate_enabled", vibrateEnabled);
|
||||
longPressTimeout = prefs.getInt("longpress_timeout", (int)longPressTimeout);
|
||||
longPressInterval = prefs.getInt("longpress_interval", (int)longPressInterval);
|
||||
marginBottom = getDipPref(dm, prefs, "margin_bottom", marginBottom);
|
||||
keyVerticalInterval = getDipPref(dm, prefs, "key_vertical_space", keyVerticalInterval);
|
||||
swipe_dist_px = Float.valueOf(_prefs.getString("swipe_dist", "15")) * physical_scaling;;
|
||||
vibrateEnabled = _prefs.getBoolean("vibrate_enabled", vibrateEnabled);
|
||||
longPressTimeout = _prefs.getInt("longpress_timeout", (int)longPressTimeout);
|
||||
longPressInterval = _prefs.getInt("longpress_interval", (int)longPressInterval);
|
||||
marginBottom = getDipPref(dm, _prefs, "margin_bottom", marginBottom);
|
||||
keyVerticalInterval = getDipPref(dm, _prefs, "key_vertical_space", keyVerticalInterval);
|
||||
keyHorizontalInterval =
|
||||
getDipPref(dm, prefs, "key_horizontal_space", keyHorizontalInterval)
|
||||
getDipPref(dm, _prefs, "key_horizontal_space", keyHorizontalInterval)
|
||||
* horizontalIntervalScale;
|
||||
// Do not substract keyVerticalInterval from keyHeight because this is done
|
||||
// during rendered.
|
||||
keyHeight = dm.heightPixels * keyboardHeightPercent / 100 / 4;
|
||||
horizontalMargin =
|
||||
getDipPref(dm, prefs, "horizontal_margin", horizontalMargin)
|
||||
getDipPref(dm, _prefs, "horizontal_margin", horizontalMargin)
|
||||
+ res.getDimension(R.dimen.extra_horizontal_margin);
|
||||
preciseRepeat = prefs.getBoolean("precise_repeat", preciseRepeat);
|
||||
double_tap_lock_shift = prefs.getBoolean("lock_double_tap", false);
|
||||
preciseRepeat = _prefs.getBoolean("precise_repeat", preciseRepeat);
|
||||
double_tap_lock_shift = _prefs.getBoolean("lock_double_tap", false);
|
||||
characterSize =
|
||||
prefs.getFloat("character_size", characterSize)
|
||||
_prefs.getFloat("character_size", characterSize)
|
||||
* characterSizeScale;
|
||||
accents = Integer.valueOf(prefs.getString("accents", "1"));
|
||||
theme = getThemeId(res, prefs.getString("theme", ""));
|
||||
autocapitalisation = prefs.getBoolean("autocapitalisation", true);
|
||||
extra_keys_param = ExtraKeyCheckBoxPreference.get_extra_keys(prefs);
|
||||
accents = Integer.valueOf(_prefs.getString("accents", "1"));
|
||||
theme = getThemeId(res, _prefs.getString("theme", ""));
|
||||
autocapitalisation = _prefs.getBoolean("autocapitalisation", true);
|
||||
extra_keys_param = ExtraKeyCheckBoxPreference.get_extra_keys(_prefs);
|
||||
}
|
||||
|
||||
/** Update the layout according to the configuration.
|
||||
@@ -277,9 +276,10 @@ final class Config
|
||||
|
||||
private static Config _globalConfig = null;
|
||||
|
||||
public static void initGlobalConfig(Context context, IKeyEventHandler handler)
|
||||
public static void initGlobalConfig(SharedPreferences prefs, Resources res,
|
||||
IKeyEventHandler handler)
|
||||
{
|
||||
_globalConfig = new Config(context, handler);
|
||||
_globalConfig = new Config(prefs, res, handler);
|
||||
}
|
||||
|
||||
public static Config globalConfig()
|
||||
|
86
srcs/juloo.keyboard2/DirectBootAwarePreferences.java
Normal file
86
srcs/juloo.keyboard2/DirectBootAwarePreferences.java
Normal file
@@ -0,0 +1,86 @@
|
||||
package juloo.keyboard2;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build.VERSION;
|
||||
import android.preference.PreferenceManager;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public final class DirectBootAwarePreferences
|
||||
{
|
||||
/* On API >= 24, preferences are read from the device protected storage. This
|
||||
* storage is less protected than the default, no personnal or sensitive
|
||||
* information is stored there (only the keyboard settings). This storage is
|
||||
* accessible during boot and allow the keyboard to read its settings and
|
||||
* allow typing the storage password. */
|
||||
public static SharedPreferences get_shared_preferences(Context context)
|
||||
{
|
||||
if (VERSION.SDK_INT < 24)
|
||||
return PreferenceManager.getDefaultSharedPreferences(context);
|
||||
SharedPreferences prefs = get_protected_prefs(context);
|
||||
check_need_migration(context, prefs);
|
||||
return prefs;
|
||||
}
|
||||
|
||||
/* Copy shared preferences to device protected storage. Not using
|
||||
* [Context.moveSharedPreferencesFrom] because the settings activity still
|
||||
* use [PreferenceActivity], which can't work on a non-default shared
|
||||
* preference file. */
|
||||
public static void copy_preferences_to_protected_storage(Context context,
|
||||
SharedPreferences src)
|
||||
{
|
||||
if (VERSION.SDK_INT >= 24)
|
||||
copy_shared_preferences(src, get_protected_prefs(context));
|
||||
}
|
||||
|
||||
static SharedPreferences get_protected_prefs(Context context)
|
||||
{
|
||||
String pref_name =
|
||||
PreferenceManager.getDefaultSharedPreferencesName(context);
|
||||
return context.createDeviceProtectedStorageContext()
|
||||
.getSharedPreferences(pref_name, Context.MODE_PRIVATE);
|
||||
}
|
||||
|
||||
static void check_need_migration(Context app_context,
|
||||
SharedPreferences protected_prefs)
|
||||
{
|
||||
if (!protected_prefs.getBoolean("need_migration", true))
|
||||
return;
|
||||
SharedPreferences prefs;
|
||||
try
|
||||
{
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(app_context);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Device is locked, migrate later.
|
||||
return;
|
||||
}
|
||||
prefs.edit().putBoolean("need_migration", false).commit();
|
||||
copy_shared_preferences(prefs, protected_prefs);
|
||||
}
|
||||
|
||||
static void copy_shared_preferences(SharedPreferences src, SharedPreferences dst)
|
||||
{
|
||||
SharedPreferences.Editor e = dst.edit();
|
||||
Map<String, ?> entries = src.getAll();
|
||||
for (String k : entries.keySet())
|
||||
{
|
||||
Object v = entries.get(k);
|
||||
if (v instanceof Boolean)
|
||||
e.putBoolean(k, (Boolean)v);
|
||||
else if (v instanceof Float)
|
||||
e.putFloat(k, (Float)v);
|
||||
else if (v instanceof Integer)
|
||||
e.putInt(k, (Integer)v);
|
||||
else if (v instanceof Long)
|
||||
e.putLong(k, (Long)v);
|
||||
else if (v instanceof String)
|
||||
e.putString(k, (String)v);
|
||||
else if (v instanceof Set)
|
||||
e.putStringSet(k, (Set<String>)v);
|
||||
}
|
||||
e.commit();
|
||||
}
|
||||
}
|
@@ -3,7 +3,6 @@ package juloo.keyboard2;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Typeface;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
@@ -84,9 +83,10 @@ public class EmojiGridView extends GridView
|
||||
|
||||
private void saveLastUsed()
|
||||
{
|
||||
SharedPreferences.Editor edit = PreferenceManager.getDefaultSharedPreferences(getContext()).edit();
|
||||
SharedPreferences.Editor edit;
|
||||
try { edit = emojiSharedPreferences().edit(); }
|
||||
catch (Exception _e) { return; }
|
||||
HashSet<String> set = new HashSet<String>();
|
||||
|
||||
for (Emoji emoji : _lastUsed.keySet())
|
||||
set.add(String.valueOf(_lastUsed.get(emoji)) + "-" + emoji.name());
|
||||
edit.putStringSet(LAST_USE_PREF, set);
|
||||
@@ -95,16 +95,18 @@ public class EmojiGridView extends GridView
|
||||
|
||||
private void loadLastUsed()
|
||||
{
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
Set<String> lastUseSet = prefs.getStringSet(LAST_USE_PREF, null);
|
||||
|
||||
_lastUsed = new HashMap<Emoji, Integer>();
|
||||
SharedPreferences prefs;
|
||||
// Storage might not be available (eg. the device is locked), avoid
|
||||
// crashing.
|
||||
try { prefs = emojiSharedPreferences(); }
|
||||
catch (Exception _e) { return; }
|
||||
Set<String> lastUseSet = prefs.getStringSet(LAST_USE_PREF, null);
|
||||
if (lastUseSet != null)
|
||||
for (String emojiData : lastUseSet)
|
||||
{
|
||||
String[] data = emojiData.split("-", 2);
|
||||
Emoji emoji;
|
||||
|
||||
if (data.length != 2)
|
||||
continue ;
|
||||
emoji = Emoji.getEmojiByName(data[1]);
|
||||
@@ -114,6 +116,11 @@ public class EmojiGridView extends GridView
|
||||
}
|
||||
}
|
||||
|
||||
SharedPreferences emojiSharedPreferences()
|
||||
{
|
||||
return getContext().getSharedPreferences("emoji_last_use", Context.MODE_PRIVATE);
|
||||
}
|
||||
|
||||
private static class EmojiView extends TextView
|
||||
{
|
||||
public EmojiView(Context context)
|
||||
|
@@ -6,23 +6,22 @@ import android.content.SharedPreferences;
|
||||
import android.inputmethodservice.InputMethodService;
|
||||
import android.os.Build.VERSION;
|
||||
import android.os.IBinder;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.text.InputType;
|
||||
import android.util.Log;
|
||||
import android.util.LogPrinter;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewParent;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputConnection;
|
||||
import android.view.inputmethod.InputMethodInfo;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.view.inputmethod.InputMethodSubtype;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewParent;
|
||||
import android.util.Log;
|
||||
import android.util.LogPrinter;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class Keyboard2 extends InputMethodService
|
||||
@@ -49,11 +48,10 @@ public class Keyboard2 extends InputMethodService
|
||||
public void onCreate()
|
||||
{
|
||||
super.onCreate();
|
||||
PreferenceManager.setDefaultValues(this, R.xml.settings, false);
|
||||
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
|
||||
Config.initGlobalConfig(this, new KeyEventHandler(this.new Receiver()));
|
||||
SharedPreferences prefs = DirectBootAwarePreferences.get_shared_preferences(this);
|
||||
prefs.registerOnSharedPreferenceChangeListener(this);
|
||||
Config.initGlobalConfig(prefs, getResources(), new KeyEventHandler(this.new Receiver()));
|
||||
_config = Config.globalConfig();
|
||||
_config.refresh(this);
|
||||
_keyboardView = (Keyboard2View)inflate_view(R.layout.keyboard);
|
||||
_keyboardView.reset();
|
||||
_debug_logs = getResources().getBoolean(R.bool.debug_logs);
|
||||
@@ -205,7 +203,7 @@ public class Keyboard2 extends InputMethodService
|
||||
private void refreshConfig()
|
||||
{
|
||||
int prev_theme = _config.theme;
|
||||
_config.refresh(this);
|
||||
_config.refresh(getResources());
|
||||
refreshSubtypeImm();
|
||||
// Refreshing the theme config requires re-creating the views
|
||||
if (prev_theme != _config.theme)
|
||||
|
@@ -1,9 +1,11 @@
|
||||
package juloo.keyboard2;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
public class SettingsActivity extends PreferenceActivity
|
||||
{
|
||||
@@ -12,7 +14,13 @@ public class SettingsActivity extends PreferenceActivity
|
||||
{
|
||||
detectSystemTheme();
|
||||
super.onCreate(savedInstanceState);
|
||||
SharedPreferences prefs;
|
||||
// The preferences can't be read when in direct-boot mode. Avoid crashing
|
||||
// and don't allow changing the settings.
|
||||
try { prefs = PreferenceManager.getDefaultSharedPreferences(this); }
|
||||
catch (Exception _e) { fallbackEncrypted(); return; }
|
||||
addPreferencesFromResource(R.xml.settings);
|
||||
prefs.registerOnSharedPreferenceChangeListener(this.new OnPreferencesChange());
|
||||
}
|
||||
|
||||
/** The default theme is [Theme.DeviceDefault], which is dark. Detect if the
|
||||
@@ -26,4 +34,21 @@ public class SettingsActivity extends PreferenceActivity
|
||||
setTheme(android.R.style.Theme_DeviceDefault_Light);
|
||||
}
|
||||
}
|
||||
|
||||
void fallbackEncrypted()
|
||||
{
|
||||
// Can't communicate with the user here.
|
||||
finish();
|
||||
}
|
||||
|
||||
/** See DirectBootAwarePreferences. */
|
||||
class OnPreferencesChange implements SharedPreferences.OnSharedPreferenceChangeListener
|
||||
{
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences prefs, String _key)
|
||||
{
|
||||
DirectBootAwarePreferences
|
||||
.copy_preferences_to_protected_storage(SettingsActivity.this, prefs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user