abouttreesummaryrefslogcommitdiff
path: root/srcs/juloo.keyboard2
diff options
context:
space:
mode:
authorJules Aguillon2024-01-13 20:59:05 +0100
committerJules Aguillon2024-01-13 20:59:05 +0100
commiteddf9c6c117449012e2aece5776694467e3483f0 (patch)
tree0f503419b7beffc15f6f0903d95e68d1c4bdddd1 /srcs/juloo.keyboard2
parent148f3dfc052bc6a4161073e59505bd547ab347c3 (diff)
downloadunexpected-keyboard-eddf9c6c117449012e2aece5776694467e3483f0.tar.gz
unexpected-keyboard-eddf9c6c117449012e2aece5776694467e3483f0.zip
Refactor: New namespace for preference classes
Diffstat (limited to 'srcs/juloo.keyboard2')
-rw-r--r--srcs/juloo.keyboard2/Autocapitalisation.java2
-rw-r--r--srcs/juloo.keyboard2/Config.java5
-rw-r--r--srcs/juloo.keyboard2/ExtraKeys.java2
-rw-r--r--srcs/juloo.keyboard2/KeyEventHandler.java2
-rw-r--r--srcs/juloo.keyboard2/KeyModifier.java2
-rw-r--r--srcs/juloo.keyboard2/KeyValue.java2
-rw-r--r--srcs/juloo.keyboard2/Keyboard2.java1
-rw-r--r--srcs/juloo.keyboard2/KeyboardData.java2
-rw-r--r--srcs/juloo.keyboard2/Utils.java2
-rw-r--r--srcs/juloo.keyboard2/prefs/CustomExtraKeysPreference.java (renamed from srcs/juloo.keyboard2/CustomExtraKeysPreference.java)3
-rw-r--r--srcs/juloo.keyboard2/prefs/ExtraKeysPreference.java (renamed from srcs/juloo.keyboard2/ExtraKeysPreference.java)3
-rw-r--r--srcs/juloo.keyboard2/prefs/IntSlideBarPreference.java120
-rw-r--r--srcs/juloo.keyboard2/prefs/LayoutsPreference.java (renamed from srcs/juloo.keyboard2/LayoutsPreference.java)13
-rw-r--r--srcs/juloo.keyboard2/prefs/ListGroupPreference.java (renamed from srcs/juloo.keyboard2/ListGroupPreference.java)3
-rw-r--r--srcs/juloo.keyboard2/prefs/SlideBarPreference.java131
15 files changed, 276 insertions, 17 deletions
diff --git a/srcs/juloo.keyboard2/Autocapitalisation.java b/srcs/juloo.keyboard2/Autocapitalisation.java
index b73f2e3..3baff48 100644
--- a/srcs/juloo.keyboard2/Autocapitalisation.java
+++ b/srcs/juloo.keyboard2/Autocapitalisation.java
@@ -8,7 +8,7 @@ import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.KeyEvent;
-final class Autocapitalisation
+public final class Autocapitalisation
{
boolean _enabled = false;
boolean _should_enable_shift = false;
diff --git a/srcs/juloo.keyboard2/Config.java b/srcs/juloo.keyboard2/Config.java
index cb68e80..f59bce3 100644
--- a/srcs/juloo.keyboard2/Config.java
+++ b/srcs/juloo.keyboard2/Config.java
@@ -14,8 +14,11 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import juloo.keyboard2.prefs.CustomExtraKeysPreference;
+import juloo.keyboard2.prefs.ExtraKeysPreference;
+import juloo.keyboard2.prefs.LayoutsPreference;
-final class Config
+public final class Config
{
private final SharedPreferences _prefs;
diff --git a/srcs/juloo.keyboard2/ExtraKeys.java b/srcs/juloo.keyboard2/ExtraKeys.java
index ca9e46a..416e507 100644
--- a/srcs/juloo.keyboard2/ExtraKeys.java
+++ b/srcs/juloo.keyboard2/ExtraKeys.java
@@ -9,7 +9,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-class ExtraKeys
+public final class ExtraKeys
{
public static final ExtraKeys EMPTY = new ExtraKeys(Collections.EMPTY_LIST);
diff --git a/srcs/juloo.keyboard2/KeyEventHandler.java b/srcs/juloo.keyboard2/KeyEventHandler.java
index e903bdb..c79d002 100644
--- a/srcs/juloo.keyboard2/KeyEventHandler.java
+++ b/srcs/juloo.keyboard2/KeyEventHandler.java
@@ -7,7 +7,7 @@ import android.view.inputmethod.ExtractedText;
import android.view.inputmethod.ExtractedTextRequest;
import android.view.inputmethod.InputConnection;
-class KeyEventHandler implements Config.IKeyEventHandler
+public final class KeyEventHandler implements Config.IKeyEventHandler
{
IReceiver _recv;
Autocapitalisation _autocap;
diff --git a/srcs/juloo.keyboard2/KeyModifier.java b/srcs/juloo.keyboard2/KeyModifier.java
index 984db2e..c0f5beb 100644
--- a/srcs/juloo.keyboard2/KeyModifier.java
+++ b/srcs/juloo.keyboard2/KeyModifier.java
@@ -4,7 +4,7 @@ import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import java.util.HashMap;
-class KeyModifier
+public final class KeyModifier
{
/** Cache key is KeyValue's name */
private static HashMap<KeyValue, HashMap<Pointers.Modifiers, KeyValue>> _cache =
diff --git a/srcs/juloo.keyboard2/KeyValue.java b/srcs/juloo.keyboard2/KeyValue.java
index fdb1f25..24eab0b 100644
--- a/srcs/juloo.keyboard2/KeyValue.java
+++ b/srcs/juloo.keyboard2/KeyValue.java
@@ -3,7 +3,7 @@ package juloo.keyboard2;
import android.view.KeyEvent;
import java.util.HashMap;
-final class KeyValue
+public final class KeyValue
{
public static enum Event
{
diff --git a/srcs/juloo.keyboard2/Keyboard2.java b/srcs/juloo.keyboard2/Keyboard2.java
index 66380e4..daa9ea0 100644
--- a/srcs/juloo.keyboard2/Keyboard2.java
+++ b/srcs/juloo.keyboard2/Keyboard2.java
@@ -23,6 +23,7 @@ import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import juloo.keyboard2.prefs.LayoutsPreference;
public class Keyboard2 extends InputMethodService
implements SharedPreferences.OnSharedPreferenceChangeListener
diff --git a/srcs/juloo.keyboard2/KeyboardData.java b/srcs/juloo.keyboard2/KeyboardData.java
index 557e42f..3cbd4aa 100644
--- a/srcs/juloo.keyboard2/KeyboardData.java
+++ b/srcs/juloo.keyboard2/KeyboardData.java
@@ -14,7 +14,7 @@ import java.util.Set;
import java.util.function.Function;
import org.xmlpull.v1.XmlPullParser;
-class KeyboardData
+public final class KeyboardData
{
public final List<Row> rows;
/** Total width of the keyboard. */
diff --git a/srcs/juloo.keyboard2/Utils.java b/srcs/juloo.keyboard2/Utils.java
index 0eee945..712c83d 100644
--- a/srcs/juloo.keyboard2/Utils.java
+++ b/srcs/juloo.keyboard2/Utils.java
@@ -7,7 +7,7 @@ import android.view.WindowManager;
import java.io.InputStream;
import java.io.InputStreamReader;
-class Utils
+public final class Utils
{
/** Turn the first letter of a string uppercase. */
public static String capitalize_string(String s)
diff --git a/srcs/juloo.keyboard2/CustomExtraKeysPreference.java b/srcs/juloo.keyboard2/prefs/CustomExtraKeysPreference.java
index d007bf7..9d8395f 100644
--- a/srcs/juloo.keyboard2/CustomExtraKeysPreference.java
+++ b/srcs/juloo.keyboard2/prefs/CustomExtraKeysPreference.java
@@ -1,4 +1,4 @@
-package juloo.keyboard2;
+package juloo.keyboard2.prefs;
import android.app.AlertDialog;
import android.content.Context;
@@ -13,6 +13,7 @@ import android.widget.EditText;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import juloo.keyboard2.*;
import org.json.JSONArray;
import org.json.JSONException;
diff --git a/srcs/juloo.keyboard2/ExtraKeysPreference.java b/srcs/juloo.keyboard2/prefs/ExtraKeysPreference.java
index 3e8b74b..47ca535 100644
--- a/srcs/juloo.keyboard2/ExtraKeysPreference.java
+++ b/srcs/juloo.keyboard2/prefs/ExtraKeysPreference.java
@@ -1,4 +1,4 @@
-package juloo.keyboard2;
+package juloo.keyboard2.prefs;
import android.content.Context;
import android.content.SharedPreferences;
@@ -11,6 +11,7 @@ import android.widget.TextView;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
+import juloo.keyboard2.*;
/** This class implements the "extra keys" preference but also defines the
possible extra keys. */
diff --git a/srcs/juloo.keyboard2/prefs/IntSlideBarPreference.java b/srcs/juloo.keyboard2/prefs/IntSlideBarPreference.java
new file mode 100644
index 0000000..bb6bf7d
--- /dev/null
+++ b/srcs/juloo.keyboard2/prefs/IntSlideBarPreference.java
@@ -0,0 +1,120 @@
+package juloo.keyboard2.prefs;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.preference.DialogPreference;
+import android.util.AttributeSet;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+import android.widget.SeekBar;
+
+/*
+ ** IntSlideBarPreference
+ ** -
+ ** Open a dialog showing a seekbar
+ ** -
+ ** xml attrs:
+ ** android:defaultValue Default value (int)
+ ** min min value (int)
+ ** max max value (int)
+ ** -
+ ** Summary field allow to show the current value using %s flag
+ */
+public class IntSlideBarPreference extends DialogPreference
+ implements SeekBar.OnSeekBarChangeListener
+{
+ private LinearLayout _layout;
+ private TextView _textView;
+ private SeekBar _seekBar;
+
+ private int _min;
+
+ private String _initialSummary;
+
+ public IntSlideBarPreference(Context context, AttributeSet attrs)
+ {
+ super(context, attrs);
+ _initialSummary = getSummary().toString();
+ _textView = new TextView(context);
+ _textView.setPadding(48, 40, 48, 40);
+ _seekBar = new SeekBar(context);
+ _seekBar.setOnSeekBarChangeListener(this);
+ _min = attrs.getAttributeIntValue(null, "min", 0);
+ int max = attrs.getAttributeIntValue(null, "max", 0);
+ _seekBar.setMax(max - _min);
+ _layout = new LinearLayout(getContext());
+ _layout.setOrientation(LinearLayout.VERTICAL);
+ _layout.addView(_textView);
+ _layout.addView(_seekBar);
+ }
+
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
+ {
+ updateText();
+ }
+
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar)
+ {
+ }
+
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar)
+ {
+ }
+
+ @Override
+ protected void onSetInitialValue(boolean restorePersistedValue, Object defaultValue)
+ {
+ int value;
+
+ if (restorePersistedValue)
+ {
+ value = getPersistedInt(_min);
+ }
+ else
+ {
+ value = (Integer)defaultValue;
+ persistInt(value);
+ }
+ _seekBar.setProgress(value - _min);
+ updateText();
+ }
+
+ @Override
+ protected Object onGetDefaultValue(TypedArray a, int index)
+ {
+ return (a.getInt(index, _min));
+ }
+
+ @Override
+ protected void onDialogClosed(boolean positiveResult)
+ {
+ if (positiveResult)
+ persistInt(_seekBar.getProgress() + _min);
+ else
+ _seekBar.setProgress(getPersistedInt(_min) - _min);
+
+ updateText();
+ }
+
+ protected View onCreateDialogView()
+ {
+ ViewGroup parent = (ViewGroup)_layout.getParent();
+
+ if (parent != null)
+ parent.removeView(_layout);
+ return (_layout);
+ }
+
+ private void updateText()
+ {
+ String f = String.format(_initialSummary, _seekBar.getProgress() + _min);
+
+ _textView.setText(f);
+ setSummary(f);
+ }
+}
diff --git a/srcs/juloo.keyboard2/LayoutsPreference.java b/srcs/juloo.keyboard2/prefs/LayoutsPreference.java
index d1cffcf..787800c 100644
--- a/srcs/juloo.keyboard2/LayoutsPreference.java
+++ b/srcs/juloo.keyboard2/prefs/LayoutsPreference.java
@@ -1,4 +1,4 @@
-package juloo.keyboard2;
+package juloo.keyboard2.prefs;
import android.app.AlertDialog;
import android.content.Context;
@@ -12,6 +12,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import juloo.keyboard2.*;
import org.json.JSONException;
import org.json.JSONObject;
@@ -237,22 +238,22 @@ public class LayoutsPreference extends ListGroupPreference<LayoutsPreference.Lay
/** A layout selected by the user. The only implementations are
[NamedLayout], [SystemLayout] and [CustomLayout]. */
- interface Layout {}
+ public interface Layout {}
- static final class SystemLayout implements Layout
+ public static final class SystemLayout implements Layout
{
public SystemLayout() {}
}
/** The name of a layout defined in [res/xml]. */
- static final class NamedLayout implements Layout
+ public static final class NamedLayout implements Layout
{
public final String name;
public NamedLayout(String n) { name = n; }
}
/** The XML description of a custom layout. */
- static final class CustomLayout implements Layout
+ public static final class CustomLayout implements Layout
{
public final String xml;
/** Might be null. */
@@ -269,7 +270,7 @@ public class LayoutsPreference extends ListGroupPreference<LayoutsPreference.Lay
/** Named layouts are serialized to strings and custom layouts to JSON
objects with a [kind] field. */
- static class Serializer implements ListGroupPreference.Serializer<Layout>
+ public static class Serializer implements ListGroupPreference.Serializer<Layout>
{
public Layout load_item(Object obj) throws JSONException
{
diff --git a/srcs/juloo.keyboard2/ListGroupPreference.java b/srcs/juloo.keyboard2/prefs/ListGroupPreference.java
index 075b38c..e332764 100644
--- a/srcs/juloo.keyboard2/ListGroupPreference.java
+++ b/srcs/juloo.keyboard2/prefs/ListGroupPreference.java
@@ -1,4 +1,4 @@
-package juloo.keyboard2;
+package juloo.keyboard2.prefs;
import android.content.Context;
import android.content.SharedPreferences;
@@ -9,6 +9,7 @@ import android.view.View;
import android.view.ViewGroup;
import java.util.ArrayList;
import java.util.List;
+import juloo.keyboard2.*;
import org.json.JSONArray;
import org.json.JSONException;
diff --git a/srcs/juloo.keyboard2/prefs/SlideBarPreference.java b/srcs/juloo.keyboard2/prefs/SlideBarPreference.java
new file mode 100644
index 0000000..cacf37e
--- /dev/null
+++ b/srcs/juloo.keyboard2/prefs/SlideBarPreference.java
@@ -0,0 +1,131 @@
+package juloo.keyboard2.prefs;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.preference.DialogPreference;
+import android.util.AttributeSet;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+import android.widget.SeekBar;
+
+/*
+ ** SideBarPreference
+ ** -
+ ** Open a dialog showing a seekbar
+ ** -
+ ** xml attrs:
+ ** android:defaultValue Default value (float)
+ ** min min value (float)
+ ** max max value (float)
+ ** -
+ ** Summary field allow to show the current value using %f or %s flag
+ */
+public class SlideBarPreference extends DialogPreference
+ implements SeekBar.OnSeekBarChangeListener
+{
+ private static final int STEPS = 100;
+
+ private LinearLayout _layout;
+ private TextView _textView;
+ private SeekBar _seekBar;
+
+ private float _min;
+ private float _max;
+ private float _value;
+
+ private String _initialSummary;
+
+ public SlideBarPreference(Context context, AttributeSet attrs)
+ {
+ super(context, attrs);
+ _initialSummary = getSummary().toString();
+ _textView = new TextView(context);
+ _textView.setPadding(48, 40, 48, 40);
+ _seekBar = new SeekBar(context);
+ _seekBar.setOnSeekBarChangeListener(this);
+ _seekBar.setMax(STEPS);
+ _min = float_of_string(attrs.getAttributeValue(null, "min"));
+ _value = _min;
+ _max = Math.max(1f, float_of_string(attrs.getAttributeValue(null, "max")));
+ _layout = new LinearLayout(getContext());
+ _layout.setOrientation(LinearLayout.VERTICAL);
+ _layout.addView(_textView);
+ _layout.addView(_seekBar);
+ }
+
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
+ {
+ _value = Math.round(progress * (_max - _min)) / (float)STEPS + _min;
+ updateText();
+ }
+
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar)
+ {
+ }
+
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar)
+ {
+ }
+
+ @Override
+ protected void onSetInitialValue(boolean restorePersistedValue, Object defaultValue)
+ {
+ if (restorePersistedValue)
+ {
+ _value = getPersistedFloat(_min);
+ }
+ else
+ {
+ _value = (Float)defaultValue;
+ persistFloat(_value);
+ }
+ _seekBar.setProgress((int)((_value - _min) * STEPS / (_max - _min)));
+ updateText();
+ }
+
+ @Override
+ protected Object onGetDefaultValue(TypedArray a, int index)
+ {
+ return (a.getFloat(index, _min));
+ }
+
+ @Override
+ protected void onDialogClosed(boolean positiveResult)
+ {
+ if (positiveResult)
+ persistFloat(_value);
+ else
+ _seekBar.setProgress((int)((getPersistedFloat(_min) - _min) * STEPS / (_max - _min)));
+
+ updateText();
+ }
+
+ protected View onCreateDialogView()
+ {
+ ViewGroup parent = (ViewGroup)_layout.getParent();
+
+ if (parent != null)
+ parent.removeView(_layout);
+ return (_layout);
+ }
+
+ private void updateText()
+ {
+ String f = String.format(_initialSummary, _value);
+
+ _textView.setText(f);
+ setSummary(f);
+ }
+
+ private static float float_of_string(String str)
+ {
+ if (str == null)
+ return (0f);
+ return (Float.parseFloat(str));
+ }
+}