Refactoring
This commit is contained in:
+18
-25
@@ -1,17 +1,15 @@
|
||||
package cfpi_fpsi.eu.titanboard;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class TitanboardKeymap extends HashMap<Integer, String[]> {
|
||||
public TitanboardKeymap(XmlPullParser parser) {
|
||||
public class Keymap extends HashMap<Integer, String[]> {
|
||||
public Keymap(XmlPullParser parser) {
|
||||
int code = 0;
|
||||
String value = null, valueAlt = null;
|
||||
String value = null, valueAlt = null, valueSym = null;
|
||||
|
||||
try {
|
||||
while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
|
||||
@@ -29,11 +27,13 @@ public class TitanboardKeymap extends HashMap<Integer, String[]> {
|
||||
case "valueAlt":
|
||||
valueAlt = parser.getAttributeValue(i);
|
||||
break;
|
||||
case "valueSym":
|
||||
valueSym = parser.getAttributeValue(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (type == XmlPullParser.END_TAG && parser.getName().equals("key")) {
|
||||
Log.d("STATE", "Keymap key: " + code + " " + value + " " + valueAlt);
|
||||
put(code, new String[]{value, valueAlt});
|
||||
put(code, new String[]{value, valueAlt, valueSym});
|
||||
}
|
||||
|
||||
parser.next();
|
||||
@@ -44,29 +44,22 @@ public class TitanboardKeymap extends HashMap<Integer, String[]> {
|
||||
}
|
||||
|
||||
public String getValue(int keyCode) {
|
||||
String[] vals = get(keyCode);
|
||||
if (vals != null) {
|
||||
return vals[0];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
String[] values = get(keyCode);
|
||||
return values != null ? values[0] : null;
|
||||
}
|
||||
|
||||
public String getValueAlt(int keyCode) {
|
||||
String[] vals = get(keyCode);
|
||||
if (vals != null) {
|
||||
return vals[1];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
String[] values = get(keyCode);
|
||||
return values != null ? values[1] : null;
|
||||
}
|
||||
|
||||
public String getValueShift(int keyCode) {
|
||||
String[] vals = get(keyCode);
|
||||
if (vals != null) {
|
||||
return vals[0].toUpperCase();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
String[] values = get(keyCode);
|
||||
return values != null ? values[0].toUpperCase() : null;
|
||||
}
|
||||
|
||||
public String getValueSym(int keyCode) {
|
||||
String[] values = get(keyCode);
|
||||
return values != null ? values[2] : null;
|
||||
}
|
||||
}
|
||||
+10
-3
@@ -2,8 +2,8 @@ package cfpi_fpsi.eu.titanboard;
|
||||
|
||||
import android.view.KeyEvent;
|
||||
|
||||
public class TitanboardMetaKeyManager {
|
||||
private final int mRepeatCount = 5;
|
||||
public class MetaKeyManager {
|
||||
private static final int mRepeatCount = 5;
|
||||
private MetaKey mMetaKeyPressed = MetaKey.NONE;
|
||||
private MetaKey mMetaKeyLatched = MetaKey.NONE;
|
||||
private MetaKey mMetaKeyLocked = MetaKey.NONE;
|
||||
@@ -19,6 +19,9 @@ public class TitanboardMetaKeyManager {
|
||||
case KeyEvent.KEYCODE_SHIFT_RIGHT:
|
||||
updateMetaKeyDown(MetaKey.SHIFT, event.getRepeatCount());
|
||||
break;
|
||||
case KeyEvent.KEYCODE_SYM:
|
||||
updateMetaKeyDown(MetaKey.SYM, event.getRepeatCount());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -42,6 +45,9 @@ public class TitanboardMetaKeyManager {
|
||||
case KeyEvent.KEYCODE_SHIFT_RIGHT:
|
||||
updateMetaKeyUp(MetaKey.SHIFT);
|
||||
break;
|
||||
case KeyEvent.KEYCODE_SYM:
|
||||
updateMetaKeyUp(MetaKey.SYM);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -88,6 +94,7 @@ public class TitanboardMetaKeyManager {
|
||||
public enum MetaKey {
|
||||
ALT,
|
||||
NONE,
|
||||
SHIFT
|
||||
SHIFT,
|
||||
SYM
|
||||
}
|
||||
}
|
||||
@@ -11,17 +11,21 @@ import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class TitanboardIME extends InputMethodService {
|
||||
private TitanboardKeymap mKeymap;
|
||||
private final TitanboardMetaKeyManager mMetaKeyManager = new TitanboardMetaKeyManager();
|
||||
|
||||
private final MetaKeyManager mMetaKeyManager = new MetaKeyManager();
|
||||
private Keymap mKeymap;
|
||||
private LinearLayout mInputView;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
mKeymap = new TitanboardKeymap(getResources().getXml(R.xml.keymap_titan));
|
||||
// TODO, which already has been done anyways, is to support multiple phone models by using
|
||||
// the "ro.vendor.build.fingerprint" property. The goal is to support at least the other two
|
||||
// Unihertz phones: the Pocket and the Slim. However, as I don't have them, it'll be guesswork.
|
||||
// Sym key support is already implemented.
|
||||
mKeymap = new Keymap(getResources().getXml(R.xml.keymap_titan));
|
||||
}
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
@Override
|
||||
public void onInitializeInterface() {
|
||||
mInputView = (LinearLayout) getLayoutInflater().inflate(R.layout.input, null);
|
||||
@@ -95,40 +99,44 @@ public class TitanboardIME extends InputMethodService {
|
||||
}
|
||||
|
||||
private String getKey(int keyCode) {
|
||||
if (mMetaKeyManager.getMetaKeyPressed() == TitanboardMetaKeyManager.MetaKey.ALT
|
||||
|| mMetaKeyManager.getMetaKeyLatched() == TitanboardMetaKeyManager.MetaKey.ALT
|
||||
|| mMetaKeyManager.getMetaKeyLocked() == TitanboardMetaKeyManager.MetaKey.ALT) {
|
||||
if (metaKeyActive(MetaKeyManager.MetaKey.ALT)) {
|
||||
return mKeymap.getValueAlt(keyCode);
|
||||
} else if (mMetaKeyManager.getMetaKeyPressed() == TitanboardMetaKeyManager.MetaKey.SHIFT
|
||||
|| mMetaKeyManager.getMetaKeyLatched() == TitanboardMetaKeyManager.MetaKey.SHIFT
|
||||
|| mMetaKeyManager.getMetaKeyLocked() == TitanboardMetaKeyManager.MetaKey.SHIFT) {
|
||||
} else if (metaKeyActive(MetaKeyManager.MetaKey.SHIFT)) {
|
||||
return mKeymap.getValueShift(keyCode);
|
||||
} else if (metaKeyActive(MetaKeyManager.MetaKey.SYM)) {
|
||||
return mKeymap.getValueSym(keyCode);
|
||||
} else {
|
||||
return mKeymap.getValue(keyCode);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean metaKeyActive(MetaKeyManager.MetaKey key) {
|
||||
return mMetaKeyManager.getMetaKeyPressed() == key
|
||||
|| mMetaKeyManager.getMetaKeyLatched() == key
|
||||
|| mMetaKeyManager.getMetaKeyLocked() == key;
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
private void updateMetaStateTextView() {
|
||||
TextView stateView = mInputView.findViewById(R.id.state);
|
||||
|
||||
if (mMetaKeyManager.getMetaKeyLatched() == TitanboardMetaKeyManager.MetaKey.ALT) {
|
||||
if (mMetaKeyManager.getMetaKeyLatched() == MetaKeyManager.MetaKey.ALT) {
|
||||
stateView.setText("#?");
|
||||
} else if (mMetaKeyManager.getMetaKeyLatched() == TitanboardMetaKeyManager.MetaKey.SHIFT) {
|
||||
} else if (mMetaKeyManager.getMetaKeyLatched() == MetaKeyManager.MetaKey.SHIFT) {
|
||||
stateView.setText("Aa");
|
||||
} else {
|
||||
stateView.setText("aa");
|
||||
}
|
||||
|
||||
if (mMetaKeyManager.getMetaKeyPressed() == TitanboardMetaKeyManager.MetaKey.ALT
|
||||
|| mMetaKeyManager.getMetaKeyLocked() == TitanboardMetaKeyManager.MetaKey.ALT) {
|
||||
if (mMetaKeyManager.getMetaKeyPressed() == MetaKeyManager.MetaKey.ALT
|
||||
|| mMetaKeyManager.getMetaKeyLocked() == MetaKeyManager.MetaKey.ALT) {
|
||||
stateView.setText("#!");
|
||||
} else if (mMetaKeyManager.getMetaKeyPressed() == TitanboardMetaKeyManager.MetaKey.SHIFT
|
||||
|| mMetaKeyManager.getMetaKeyLocked() == TitanboardMetaKeyManager.MetaKey.SHIFT) {
|
||||
} else if (mMetaKeyManager.getMetaKeyPressed() == MetaKeyManager.MetaKey.SHIFT
|
||||
|| mMetaKeyManager.getMetaKeyLocked() == MetaKeyManager.MetaKey.SHIFT) {
|
||||
stateView.setText("AA");
|
||||
}
|
||||
|
||||
if (mMetaKeyManager.getMetaKeyLocked() != TitanboardMetaKeyManager.MetaKey.NONE
|
||||
if (mMetaKeyManager.getMetaKeyLocked() != MetaKeyManager.MetaKey.NONE
|
||||
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
stateView.setTextAppearance(R.style.KeyboardStateLocked);
|
||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
@@ -136,6 +144,7 @@ public class TitanboardIME extends InputMethodService {
|
||||
}
|
||||
}
|
||||
|
||||
/** @noinspection unused*/
|
||||
public void onInputViewExtraKeyClick(View v) {
|
||||
int visibility = mInputView.findViewById(R.id.extra_view).getVisibility();
|
||||
Button key = (Button) v;
|
||||
@@ -148,6 +157,7 @@ public class TitanboardIME extends InputMethodService {
|
||||
}
|
||||
}
|
||||
|
||||
/** @noinspection unused*/
|
||||
public void onInputViewKeyClick(View v) {
|
||||
Button key = (Button) v;
|
||||
InputConnection conn = getCurrentInputConnection();
|
||||
|
||||
@@ -42,7 +42,8 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="aa"
|
||||
android:typeface="normal" />
|
||||
android:typeface="normal"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -68,49 +69,56 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:text="–" />
|
||||
android:text="–"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<Button
|
||||
style="@style/KeyboardKey"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:text="—" />
|
||||
android:text="—"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<Button
|
||||
style="@style/KeyboardKey"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:text="`" />
|
||||
android:text="`"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<Button
|
||||
style="@style/KeyboardKey"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:text="~" />
|
||||
android:text="~"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<Button
|
||||
style="@style/KeyboardKey"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:text="{" />
|
||||
android:text="{"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<Button
|
||||
style="@style/KeyboardKey"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:text="}" />
|
||||
android:text="}"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<Button
|
||||
style="@style/KeyboardKey"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:text="\\" />
|
||||
android:text="\\"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<Button
|
||||
style="@style/KeyboardKey"
|
||||
@@ -130,49 +138,56 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:text="π" />
|
||||
android:text="π"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<Button
|
||||
style="@style/KeyboardKey"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:text="≤" />
|
||||
android:text="≤"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<Button
|
||||
style="@style/KeyboardKey"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:text="≥" />
|
||||
android:text="≥"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<Button
|
||||
style="@style/KeyboardKey"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:text="^" />
|
||||
android:text="^"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<Button
|
||||
style="@style/KeyboardKey"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:text="[" />
|
||||
android:text="["
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<Button
|
||||
style="@style/KeyboardKey"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:text="]" />
|
||||
android:text="]"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<Button
|
||||
style="@style/KeyboardKey"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:text="|" />
|
||||
android:text="|"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<Button
|
||||
style="@style/KeyboardKey"
|
||||
@@ -196,50 +211,58 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:text="<" />
|
||||
android:text="<"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<Button
|
||||
style="@style/KeyboardKey"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:text=">" />
|
||||
android:text=">"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<Button
|
||||
style="@style/KeyboardKey"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:text="=" />
|
||||
android:text="="
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<Button
|
||||
style="@style/KeyboardKey"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:text="$" />
|
||||
android:text="$"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<Button
|
||||
style="@style/KeyboardKey"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:text="%" />
|
||||
android:text="%"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<Button
|
||||
style="@style/KeyboardKey"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:text=";" />
|
||||
android:text=";"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<Button
|
||||
style="@style/KeyboardKey"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:text="&" />
|
||||
android:text="&"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<!--suppress AndroidMissingOnClickHandler -->
|
||||
<Button
|
||||
android:id="@+id/expand_button"
|
||||
style="@style/KeyboardKey"
|
||||
@@ -247,7 +270,8 @@
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:onClick="onInputViewExtraKeyClick"
|
||||
android:text="▲ " />
|
||||
android:text="▲ "
|
||||
tools:ignore="HardcodedText,OnClick" />
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
Reference in New Issue
Block a user