mirror of
https://github.com/Julow/Unexpected-Keyboard.git
synced 2025-08-18 14:52:25 +02:00
Compare commits
2 Commits
vertical-s
...
macro-sync
Author | SHA1 | Date | |
---|---|---|---|
|
3d1383adfa | ||
|
80bc21c4af |
@@ -1,7 +1,6 @@
|
|||||||
package juloo.keyboard2;
|
package juloo.keyboard2;
|
||||||
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
|
||||||
import android.text.InputType;
|
import android.text.InputType;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.inputmethod.EditorInfo;
|
import android.view.inputmethod.EditorInfo;
|
||||||
@@ -27,9 +26,9 @@ public final class Autocapitalisation
|
|||||||
InputType.TYPE_TEXT_FLAG_CAP_SENTENCES |
|
InputType.TYPE_TEXT_FLAG_CAP_SENTENCES |
|
||||||
InputType.TYPE_TEXT_FLAG_CAP_WORDS;
|
InputType.TYPE_TEXT_FLAG_CAP_WORDS;
|
||||||
|
|
||||||
public Autocapitalisation(Looper looper, Callback cb)
|
public Autocapitalisation(Handler h, Callback cb)
|
||||||
{
|
{
|
||||||
_handler = new Handler(looper);
|
_handler = h;
|
||||||
_callback = cb;
|
_callback = cb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2,6 +2,7 @@ package juloo.keyboard2;
|
|||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
import android.os.Handler;
|
||||||
import android.text.InputType;
|
import android.text.InputType;
|
||||||
import android.view.KeyCharacterMap;
|
import android.view.KeyCharacterMap;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
@@ -28,10 +29,10 @@ public final class KeyEventHandler
|
|||||||
[setSelection] could be used instead. */
|
[setSelection] could be used instead. */
|
||||||
boolean _move_cursor_force_fallback = false;
|
boolean _move_cursor_force_fallback = false;
|
||||||
|
|
||||||
public KeyEventHandler(Looper looper, IReceiver recv)
|
public KeyEventHandler(IReceiver recv)
|
||||||
{
|
{
|
||||||
_recv = recv;
|
_recv = recv;
|
||||||
_autocap = new Autocapitalisation(looper,
|
_autocap = new Autocapitalisation(recv.getHandler(),
|
||||||
this.new Autocapitalisation_callback());
|
this.new Autocapitalisation_callback());
|
||||||
_mods = Pointers.Modifiers.EMPTY;
|
_mods = Pointers.Modifiers.EMPTY;
|
||||||
}
|
}
|
||||||
@@ -324,32 +325,73 @@ public final class KeyEventHandler
|
|||||||
|
|
||||||
void evaluate_macro(KeyValue[] keys)
|
void evaluate_macro(KeyValue[] keys)
|
||||||
{
|
{
|
||||||
final Pointers.Modifiers empty = Pointers.Modifiers.EMPTY;
|
if (keys.length == 0)
|
||||||
|
return;
|
||||||
// Ignore modifiers that are activated at the time the macro is evaluated
|
// Ignore modifiers that are activated at the time the macro is evaluated
|
||||||
mods_changed(empty);
|
mods_changed(Pointers.Modifiers.EMPTY);
|
||||||
Pointers.Modifiers mods = empty;
|
evaluate_macro_loop(keys, 0, Pointers.Modifiers.EMPTY, _autocap.pause());
|
||||||
final boolean autocap_paused = _autocap.pause();
|
}
|
||||||
for (KeyValue kv : keys)
|
|
||||||
|
/** Evaluate the macro asynchronously to make sure event are processed in the
|
||||||
|
right order. */
|
||||||
|
void evaluate_macro_loop(final KeyValue[] keys, int i, Pointers.Modifiers mods, final boolean autocap_paused)
|
||||||
|
{
|
||||||
|
boolean should_delay = false;
|
||||||
|
KeyValue kv = KeyModifier.modify(keys[i], mods);
|
||||||
|
if (kv != null)
|
||||||
{
|
{
|
||||||
kv = KeyModifier.modify(kv, mods);
|
|
||||||
if (kv == null)
|
|
||||||
continue;
|
|
||||||
if (kv.hasFlagsAny(KeyValue.FLAG_LATCH))
|
if (kv.hasFlagsAny(KeyValue.FLAG_LATCH))
|
||||||
{
|
{
|
||||||
// Non-special latchable keys clear latched modifiers
|
// Non-special latchable keys clear latched modifiers
|
||||||
if (!kv.hasFlagsAny(KeyValue.FLAG_SPECIAL))
|
if (!kv.hasFlagsAny(KeyValue.FLAG_SPECIAL))
|
||||||
mods = empty;
|
mods = Pointers.Modifiers.EMPTY;
|
||||||
mods = mods.with_extra_mod(kv);
|
mods = mods.with_extra_mod(kv);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
key_down(kv, false);
|
key_down(kv, false);
|
||||||
key_up(kv, mods);
|
key_up(kv, mods);
|
||||||
mods = empty;
|
mods = Pointers.Modifiers.EMPTY;
|
||||||
}
|
}
|
||||||
|
should_delay = wait_after_macro_key(kv);
|
||||||
}
|
}
|
||||||
|
i++;
|
||||||
|
if (i >= keys.length) // Stop looping
|
||||||
|
{
|
||||||
_autocap.unpause(autocap_paused);
|
_autocap.unpause(autocap_paused);
|
||||||
}
|
}
|
||||||
|
else if (should_delay)
|
||||||
|
{
|
||||||
|
// Add a delay before sending the next key to avoid race conditions
|
||||||
|
// causing keys to be handled in the wrong order. Notably, KeyEvent keys
|
||||||
|
// handling is scheduled differently than the other edit functions.
|
||||||
|
final int i_ = i;
|
||||||
|
final Pointers.Modifiers mods_ = mods;
|
||||||
|
_recv.getHandler().postDelayed(new Runnable() {
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
evaluate_macro_loop(keys, i_, mods_, autocap_paused);
|
||||||
|
}
|
||||||
|
}, 1000/30);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
evaluate_macro_loop(keys, i, mods, autocap_paused);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean wait_after_macro_key(KeyValue kv)
|
||||||
|
{
|
||||||
|
switch (kv.getKind())
|
||||||
|
{
|
||||||
|
case Keyevent:
|
||||||
|
case Editing:
|
||||||
|
case Event:
|
||||||
|
return true;
|
||||||
|
case Slider:
|
||||||
|
return _move_cursor_force_fallback;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Repeat calls to [send_key_down_up]. */
|
/** Repeat calls to [send_key_down_up]. */
|
||||||
void send_key_down_up_repeat(int event_code, int repeat)
|
void send_key_down_up_repeat(int event_code, int repeat)
|
||||||
@@ -364,6 +406,7 @@ public final class KeyEventHandler
|
|||||||
public void set_shift_state(boolean state, boolean lock);
|
public void set_shift_state(boolean state, boolean lock);
|
||||||
public void set_compose_pending(boolean pending);
|
public void set_compose_pending(boolean pending);
|
||||||
public InputConnection getCurrentInputConnection();
|
public InputConnection getCurrentInputConnection();
|
||||||
|
public Handler getHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
class Autocapitalisation_callback implements Autocapitalisation.Callback
|
class Autocapitalisation_callback implements Autocapitalisation.Callback
|
||||||
|
@@ -6,6 +6,7 @@ import android.content.Intent;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.inputmethodservice.InputMethodService;
|
import android.inputmethodservice.InputMethodService;
|
||||||
import android.os.Build.VERSION;
|
import android.os.Build.VERSION;
|
||||||
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.text.InputType;
|
import android.text.InputType;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -38,6 +39,7 @@ public class Keyboard2 extends InputMethodService
|
|||||||
private ViewGroup _emojiPane = null;
|
private ViewGroup _emojiPane = null;
|
||||||
private ViewGroup _clipboard_pane = null;
|
private ViewGroup _clipboard_pane = null;
|
||||||
public int actionId; // Action performed by the Action key.
|
public int actionId; // Action performed by the Action key.
|
||||||
|
private Handler _handler;
|
||||||
|
|
||||||
private Config _config;
|
private Config _config;
|
||||||
|
|
||||||
@@ -107,7 +109,8 @@ public class Keyboard2 extends InputMethodService
|
|||||||
{
|
{
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
SharedPreferences prefs = DirectBootAwarePreferences.get_shared_preferences(this);
|
SharedPreferences prefs = DirectBootAwarePreferences.get_shared_preferences(this);
|
||||||
_keyeventhandler = new KeyEventHandler(getMainLooper(), this.new Receiver());
|
_handler = new Handler(getMainLooper());
|
||||||
|
_keyeventhandler = new KeyEventHandler(this.new Receiver());
|
||||||
Config.initGlobalConfig(prefs, getResources(), _keyeventhandler);
|
Config.initGlobalConfig(prefs, getResources(), _keyeventhandler);
|
||||||
prefs.registerOnSharedPreferenceChangeListener(this);
|
prefs.registerOnSharedPreferenceChangeListener(this);
|
||||||
_config = Config.globalConfig();
|
_config = Config.globalConfig();
|
||||||
@@ -481,6 +484,11 @@ public class Keyboard2 extends InputMethodService
|
|||||||
{
|
{
|
||||||
return Keyboard2.this.getCurrentInputConnection();
|
return Keyboard2.this.getCurrentInputConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Handler getHandler()
|
||||||
|
{
|
||||||
|
return _handler;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IBinder getConnectionToken()
|
private IBinder getConnectionToken()
|
||||||
|
Reference in New Issue
Block a user