mirror of
https://github.com/Julow/Unexpected-Keyboard.git
synced 2025-06-19 17:31:30 +02:00
Refactor: KeyValue: Simplify StringWithSymbol
This removes the Complex key kind and class by making StringWithSymbol a new kind of key.
This commit is contained in:
parent
3ea5c8d6b7
commit
e3f9341ed1
@ -100,7 +100,7 @@ public final class KeyEventHandler
|
||||
_recv.set_compose_pending(true);
|
||||
break;
|
||||
case Slider: handle_slider(key.getSlider(), key.getSliderRepeat()); break;
|
||||
case Complex: send_complex_key(key.getComplexKind(), key.getComplex()); break;
|
||||
case StringWithSymbol: send_text(key.getStringWithSymbol()); break;
|
||||
}
|
||||
update_meta_state(old_mods);
|
||||
}
|
||||
@ -219,16 +219,6 @@ public final class KeyEventHandler
|
||||
conn.performContextMenuAction(id);
|
||||
}
|
||||
|
||||
void send_complex_key(KeyValue.Complex.Kind kind, KeyValue.Complex val)
|
||||
{
|
||||
switch (kind)
|
||||
{
|
||||
case StringWithSymbol:
|
||||
send_text(((KeyValue.Complex.StringWithSymbol)val).str);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("InlinedApi")
|
||||
void handle_editing_key(KeyValue.Editing ev)
|
||||
{
|
||||
|
@ -90,10 +90,11 @@ public final class KeyValue implements Comparable<KeyValue>
|
||||
|
||||
public static enum Kind
|
||||
{
|
||||
Char, String, Keyevent, Event, Compose_pending, Hangul_initial,
|
||||
Hangul_medial, Modifier, Editing, Placeholder,
|
||||
Char, Keyevent, Event, Compose_pending, Hangul_initial, Hangul_medial,
|
||||
Modifier, Editing, Placeholder,
|
||||
String, // [_payload] is also the string to output, value is unused.
|
||||
Slider, // [_payload] is a [KeyValue.Slider], value is slider repeatition.
|
||||
Complex, // [_payload] is a [KeyValue.Complex], value is [Complex.Kind].
|
||||
StringWithSymbol, // [_payload] is a [KeyValue.StringWithSymbol], value is unused.
|
||||
}
|
||||
|
||||
private static final int FLAGS_OFFSET = 19;
|
||||
@ -131,10 +132,7 @@ public final class KeyValue implements Comparable<KeyValue>
|
||||
check((((Kind.values().length - 1) << KIND_OFFSET) & ~KIND_BITS) == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* [_payload.toString()] is the symbol that is rendered on the keyboard.
|
||||
* For keys of kind [String], this is also the string to output.
|
||||
*/
|
||||
/** [_payload.toString()] is the symbol that is rendered on the keyboard. */
|
||||
private final Comparable _payload;
|
||||
|
||||
/** This field encodes three things: Kind (KIND_BITS), flags (FLAGS_BITS) and
|
||||
@ -225,16 +223,10 @@ public final class KeyValue implements Comparable<KeyValue>
|
||||
return ((int)(short)(_code & VALUE_BITS));
|
||||
}
|
||||
|
||||
/** Defined only when [getKind() == Kind.Complex]. */
|
||||
public Complex getComplex()
|
||||
/** Defined only when [getKind() == Kind.StringWithSymbol]. */
|
||||
public String getStringWithSymbol()
|
||||
{
|
||||
return (Complex)_payload;
|
||||
}
|
||||
|
||||
/** Defined only when [getKind() == Kind.Complex]. */
|
||||
public Complex.Kind getComplexKind()
|
||||
{
|
||||
return Complex.Kind.values()[(_code & VALUE_BITS)];
|
||||
return ((StringWithSymbol)_payload).str;
|
||||
}
|
||||
|
||||
/* Update the char and the symbol. */
|
||||
@ -303,11 +295,6 @@ public final class KeyValue implements Comparable<KeyValue>
|
||||
_code = (kind & KIND_BITS) | (flags & FLAGS_BITS) | (value & VALUE_BITS);
|
||||
}
|
||||
|
||||
private KeyValue(Complex p, Complex.Kind value, int flags)
|
||||
{
|
||||
this(p, Kind.Complex, value.ordinal(), flags);
|
||||
}
|
||||
|
||||
public KeyValue(Comparable p, Kind k, int v, int f)
|
||||
{
|
||||
this(p, (k.ordinal() << KIND_OFFSET), v, f);
|
||||
@ -463,8 +450,8 @@ public final class KeyValue implements Comparable<KeyValue>
|
||||
|
||||
public static KeyValue makeStringKeyWithSymbol(String str, String symbol, int flags)
|
||||
{
|
||||
return new KeyValue(new Complex.StringWithSymbol(str, symbol),
|
||||
Complex.Kind.StringWithSymbol, flags);
|
||||
return new KeyValue(new StringWithSymbol(str, symbol),
|
||||
Kind.StringWithSymbol, 0, flags);
|
||||
}
|
||||
|
||||
/** Make a modifier key for passing to [KeyModifier]. */
|
||||
@ -753,32 +740,10 @@ public final class KeyValue implements Comparable<KeyValue>
|
||||
throw new RuntimeException("Assertion failure");
|
||||
}
|
||||
|
||||
public static abstract class Complex implements Comparable<Complex>
|
||||
{
|
||||
public abstract String getSymbol();
|
||||
|
||||
/** [compareTo] can assume that [snd] is an instance of the same class. */
|
||||
@Override
|
||||
public abstract int compareTo(Complex snd);
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return getSymbol();
|
||||
}
|
||||
|
||||
/** [hashCode] will be called on this class. */
|
||||
|
||||
/** The kind is stored in the [value] field of the key. */
|
||||
public static enum Kind
|
||||
{
|
||||
StringWithSymbol,
|
||||
}
|
||||
|
||||
public static final class StringWithSymbol extends Complex
|
||||
public static final class StringWithSymbol implements Comparable<StringWithSymbol>
|
||||
{
|
||||
public final String str;
|
||||
private final String _symbol;
|
||||
final String _symbol;
|
||||
|
||||
public StringWithSymbol(String _str, String _sym)
|
||||
{
|
||||
@ -787,17 +752,15 @@ public final class KeyValue implements Comparable<KeyValue>
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSymbol() { return _symbol; }
|
||||
public String toString() { return _symbol; }
|
||||
|
||||
@Override
|
||||
public int compareTo(Complex _snd)
|
||||
public int compareTo(StringWithSymbol snd)
|
||||
{
|
||||
StringWithSymbol snd = (StringWithSymbol)_snd;
|
||||
int d = str.compareTo(snd.str);
|
||||
if (d != 0) return d;
|
||||
return _symbol.compareTo(snd._symbol);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public static enum Slider
|
||||
|
Loading…
x
Reference in New Issue
Block a user