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);
|
_recv.set_compose_pending(true);
|
||||||
break;
|
break;
|
||||||
case Slider: handle_slider(key.getSlider(), key.getSliderRepeat()); 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);
|
update_meta_state(old_mods);
|
||||||
}
|
}
|
||||||
@ -219,16 +219,6 @@ public final class KeyEventHandler
|
|||||||
conn.performContextMenuAction(id);
|
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")
|
@SuppressLint("InlinedApi")
|
||||||
void handle_editing_key(KeyValue.Editing ev)
|
void handle_editing_key(KeyValue.Editing ev)
|
||||||
{
|
{
|
||||||
|
@ -90,10 +90,11 @@ public final class KeyValue implements Comparable<KeyValue>
|
|||||||
|
|
||||||
public static enum Kind
|
public static enum Kind
|
||||||
{
|
{
|
||||||
Char, String, Keyevent, Event, Compose_pending, Hangul_initial,
|
Char, Keyevent, Event, Compose_pending, Hangul_initial, Hangul_medial,
|
||||||
Hangul_medial, Modifier, Editing, Placeholder,
|
Modifier, Editing, Placeholder,
|
||||||
|
String, // [_payload] is also the string to output, value is unused.
|
||||||
Slider, // [_payload] is a [KeyValue.Slider], value is slider repeatition.
|
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;
|
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);
|
check((((Kind.values().length - 1) << KIND_OFFSET) & ~KIND_BITS) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** [_payload.toString()] is the symbol that is rendered on the keyboard. */
|
||||||
* [_payload.toString()] is the symbol that is rendered on the keyboard.
|
|
||||||
* For keys of kind [String], this is also the string to output.
|
|
||||||
*/
|
|
||||||
private final Comparable _payload;
|
private final Comparable _payload;
|
||||||
|
|
||||||
/** This field encodes three things: Kind (KIND_BITS), flags (FLAGS_BITS) and
|
/** 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));
|
return ((int)(short)(_code & VALUE_BITS));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Defined only when [getKind() == Kind.Complex]. */
|
/** Defined only when [getKind() == Kind.StringWithSymbol]. */
|
||||||
public Complex getComplex()
|
public String getStringWithSymbol()
|
||||||
{
|
{
|
||||||
return (Complex)_payload;
|
return ((StringWithSymbol)_payload).str;
|
||||||
}
|
|
||||||
|
|
||||||
/** Defined only when [getKind() == Kind.Complex]. */
|
|
||||||
public Complex.Kind getComplexKind()
|
|
||||||
{
|
|
||||||
return Complex.Kind.values()[(_code & VALUE_BITS)];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update the char and the symbol. */
|
/* 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);
|
_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)
|
public KeyValue(Comparable p, Kind k, int v, int f)
|
||||||
{
|
{
|
||||||
this(p, (k.ordinal() << KIND_OFFSET), v, 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)
|
public static KeyValue makeStringKeyWithSymbol(String str, String symbol, int flags)
|
||||||
{
|
{
|
||||||
return new KeyValue(new Complex.StringWithSymbol(str, symbol),
|
return new KeyValue(new StringWithSymbol(str, symbol),
|
||||||
Complex.Kind.StringWithSymbol, flags);
|
Kind.StringWithSymbol, 0, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Make a modifier key for passing to [KeyModifier]. */
|
/** Make a modifier key for passing to [KeyModifier]. */
|
||||||
@ -753,50 +740,26 @@ public final class KeyValue implements Comparable<KeyValue>
|
|||||||
throw new RuntimeException("Assertion failure");
|
throw new RuntimeException("Assertion failure");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static abstract class Complex implements Comparable<Complex>
|
public static final class StringWithSymbol implements Comparable<StringWithSymbol>
|
||||||
{
|
{
|
||||||
public abstract String getSymbol();
|
public final String str;
|
||||||
|
final String _symbol;
|
||||||
|
|
||||||
/** [compareTo] can assume that [snd] is an instance of the same class. */
|
public StringWithSymbol(String _str, String _sym)
|
||||||
@Override
|
|
||||||
public abstract int compareTo(Complex snd);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString()
|
|
||||||
{
|
{
|
||||||
return getSymbol();
|
str = _str;
|
||||||
|
_symbol = _sym;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** [hashCode] will be called on this class. */
|
@Override
|
||||||
|
public String toString() { return _symbol; }
|
||||||
|
|
||||||
/** The kind is stored in the [value] field of the key. */
|
@Override
|
||||||
public static enum Kind
|
public int compareTo(StringWithSymbol snd)
|
||||||
{
|
{
|
||||||
StringWithSymbol,
|
int d = str.compareTo(snd.str);
|
||||||
}
|
if (d != 0) return d;
|
||||||
|
return _symbol.compareTo(snd._symbol);
|
||||||
public static final class StringWithSymbol extends Complex
|
|
||||||
{
|
|
||||||
public final String str;
|
|
||||||
private final String _symbol;
|
|
||||||
|
|
||||||
public StringWithSymbol(String _str, String _sym)
|
|
||||||
{
|
|
||||||
str = _str;
|
|
||||||
_symbol = _sym;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSymbol() { return _symbol; }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(Complex _snd)
|
|
||||||
{
|
|
||||||
StringWithSymbol snd = (StringWithSymbol)_snd;
|
|
||||||
int d = str.compareTo(snd.str);
|
|
||||||
if (d != 0) return d;
|
|
||||||
return _symbol.compareTo(snd._symbol);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user