Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

checkpoint: basically works.

  • Loading branch information...
commit 8bcf88cd9e5cf8dc8519115cf4ad1c674d21fc26 1 parent 90fbd3a
Robey Pointer authored
View
1  src/main/res/layout/main.xml
@@ -10,4 +10,3 @@
android:text="Hello World, HelloWorld"
/>
</LinearLayout>
-
View
60 src/main/res/xml/keyboard1.xml
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
+ android:keyWidth="10%p"
+ android:horizontalGap="0px"
+ android:verticalGap="0px"
+ android:keyHeight="@dimen/key_height">
+
+ <Row>
+ <Key android:codes="44,46" android:keyLabel=", ." android:keyWidth="15%p"
+ android:keyEdgeFlags="left" />
+ <Key android:codes="112" android:keyLabel="p" />
+ <Key android:codes="121" android:keyLabel="y" />
+ <Key android:codes="102" android:keyLabel="f" />
+ <Key android:codes="103" android:keyLabel="g" />
+ <Key android:codes="99" android:keyLabel="c" />
+ <Key android:codes="114" android:keyLabel="r" />
+ <Key android:codes="108" android:keyLabel="l" />
+ <Key android:codes="-5" android:keyIcon="@drawable/sym_keyboard_delete"
+ android:keyWidth="15%p" android:keyEdgeFlags="right" android:isRepeatable="true"/>
+ </Row>
+
+ <Row>
+ <Key android:codes="97" android:keyLabel="a" android:keyEdgeFlags="left" />
+ <Key android:codes="111" android:keyLabel="o" />
+ <Key android:codes="101" android:keyLabel="e" />
+ <Key android:codes="117" android:keyLabel="u" />
+ <Key android:codes="105" android:keyLabel="i" />
+ <Key android:codes="100" android:keyLabel="d" />
+ <Key android:codes="104" android:keyLabel="h" />
+ <Key android:codes="116" android:keyLabel="t" />
+ <Key android:codes="110" android:keyLabel="n" />
+ <Key android:codes="115" android:keyLabel="s" android:keyEdgeFlags="right" />
+ </Row>
+
+ <Row>
+ <Key android:codes="45" android:keyLabel="-" android:keyEdgeFlags="left" />
+ <Key android:codes="113" android:keyLabel="q" />
+ <Key android:codes="106" android:keyLabel="j" />
+ <Key android:codes="107" android:keyLabel="k" />
+ <Key android:codes="120" android:keyLabel="x" />
+ <Key android:codes="98" android:keyLabel="b" />
+ <Key android:codes="109" android:keyLabel="m" />
+ <Key android:codes="119" android:keyLabel="w" />
+ <Key android:codes="118" android:keyLabel="v" />
+ <Key android:codes="122" android:keyLabel="z" android:keyEdgeFlags="right" />
+ </Row>
+
+ <Row android:rowEdgeFlags="bottom">
+ <Key android:codes="-1" android:keyIcon="@drawable/sym_keyboard_shift"
+ android:keyWidth="15%p" android:isModifier="true"
+ android:isSticky="true" android:keyEdgeFlags="left" />
+ <Key android:codes="-3" android:keyIcon="@drawable/sym_keyboard_done" android:keyWidth="20%p" />
+ <Key android:codes="32" android:keyIcon="@drawable/sym_keyboard_space"
+ android:keyWidth="30%p" android:isRepeatable="true"/>
+ <Key android:codes="-2" android:keyLabel="123" android:keyWidth="15%p"/>
+ <Key android:codes="10" android:keyIcon="@drawable/sym_keyboard_return"
+ android:keyWidth="20%p" android:keyEdgeFlags="right" />
+ </Row>
+</Keyboard>
View
59 src/main/res/xml/keyboard2.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
+ android:keyWidth="10%p"
+ android:horizontalGap="0px"
+ android:verticalGap="0px"
+ android:keyHeight="@dimen/key_height">
+
+ <Row>
+ <Key android:codes="49" android:keyLabel="1" android:keyEdgeFlags="left" />
+ <Key android:codes="50" android:keyLabel="2" />
+ <Key android:codes="51" android:keyLabel="3" />
+ <Key android:codes="52" android:keyLabel="4" />
+ <Key android:codes="53" android:keyLabel="5" />
+ <Key android:codes="54" android:keyLabel="6" />
+ <Key android:codes="55" android:keyLabel="7" />
+ <Key android:codes="56" android:keyLabel="8" />
+ <Key android:codes="57" android:keyLabel="9" />
+ <Key android:codes="48" android:keyLabel="0" android:keyEdgeFlags="right" />
+ </Row>
+
+ <Row>
+ <Key android:codes="43" android:keyLabel="+" android:keyEdgeFlags="left" />
+ <Key android:codes="40" android:keyLabel="(" />
+ <Key android:codes="41" android:keyLabel=")" />
+ <Key android:codes="36" android:keyLabel="$" />
+ <Key android:codes="34" android:keyLabel="&quot;" />
+ <Key android:codes="37" android:keyLabel="%" />
+ <Key android:codes="38" android:keyLabel="&amp;" />
+ <Key android:codes="42" android:keyLabel="*" />
+ <Key android:codes="33" android:keyLabel="!" />
+ <Key android:codes="63" android:keyLabel="\?" android:keyEdgeFlags="right" />
+ </Row>
+
+ <Row>
+ <Key android:codes="45" android:keyLabel="-" android:keyEdgeFlags="left" />
+ <Key android:codes="47" android:keyLabel="/" />
+ <Key android:codes="58" android:keyLabel=":"/>
+ <Key android:codes="59" android:keyLabel=";"/>
+ <Key android:codes="61" android:keyLabel="="/>
+ <Key android:codes="60" android:keyLabel="&lt;" />
+ <Key android:codes="62" android:keyLabel="&gt;" />
+ <Key android:codes="39" android:keyLabel="\'"/>
+ <Key android:codes="35" android:keyLabel="\#"/>
+ <Key android:codes="64" android:keyLabel="\@" android:keyEdgeFlags="right" />
+ </Row>
+
+ <Row android:rowEdgeFlags="bottom">
+ <Key android:codes="-1" android:keyIcon="@drawable/sym_keyboard_shift"
+ android:keyWidth="15%p" android:isModifier="true"
+ android:isSticky="true" android:keyEdgeFlags="left" />
+ <Key android:codes="-3" android:keyIcon="@drawable/sym_keyboard_done" android:keyWidth="20%p" />
+ <Key android:codes="32" android:keyIcon="@drawable/sym_keyboard_space"
+ android:keyWidth="30%p" android:isRepeatable="true"/>
+ <Key android:codes="-2" android:keyLabel="123" android:keyWidth="15%p"/>
+ <Key android:codes="10" android:keyIcon="@drawable/sym_keyboard_return"
+ android:keyWidth="20%p" android:keyEdgeFlags="right" />
+ </Row>
+</Keyboard>
View
107 src/main/scala/net/lag/dvorky/Dvorky.scala
@@ -5,6 +5,13 @@ import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.content.Intent
+import android.text.InputType
+import android.content.Context
+import android.util.AttributeSet
+import android.inputmethodservice.{InputMethodService, Keyboard, KeyboardView}
+import android.view.KeyEvent
+import android.view.inputmethod.EditorInfo
+
class Dvorky extends Activity {
override def onCreate(savedInstanceState: Bundle) {
@@ -15,63 +22,103 @@ class Dvorky extends Activity {
}
}
-
-import android.inputmethodservice.{InputMethodService, Keyboard, KeyboardView}
-import android.view.inputmethod.EditorInfo
-
class DvorkyKeyboard extends InputMethodService with KeyboardView.OnKeyboardActionListener {
- var mainKeyboard: Keyboard = null
+ var keyboard1: Keyboard = null
+ var keyboard2: Keyboard = null
var view: KeyboardView = null
+ // capslock:
+ var lastShiftTime: Long = 0
+ var capsLock = false
+
override def onInitializeInterface() {
- mainKeyboard = new Keyboard(this, R.xml.main)
+ keyboard1 = new Keyboard(this, R.xml.keyboard1)
+ keyboard2 = new Keyboard(this, R.xml.keyboard2)
}
override def onCreateInputView() = {
view = getLayoutInflater().inflate(R.layout.input, null).asInstanceOf[KeyboardView]
- view.setKeyboard(mainKeyboard)
+ view.setKeyboard(keyboard1)
view.setOnKeyboardActionListener(this)
view
}
-
+
override def onStartInput(attribute: EditorInfo, restarting: Boolean) {
super.onStartInput(attribute, restarting)
- println("hello!")
}
override def onStartInputView(attribute: EditorInfo, restarting: Boolean) {
super.onStartInputView(attribute, restarting)
- view.setKeyboard(mainKeyboard)
+ view.setKeyboard(keyboard1)
view.closing()
- println("hello 2!")
}
-
-
+
+
// OnKeyboardActionListener
-
- def onKey(primaryCode: Int, keyCodes: Array[Int]) { }
+
+ def onKey(primaryCode: Int, keyCodes: Array[Int]) {
+ println("keycode:" + primaryCode + "/" + keyCodes.toList.toString)
+ primaryCode match {
+ case Keyboard.KEYCODE_DELETE =>
+ sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL)
+ case Keyboard.KEYCODE_SHIFT if view ne null =>
+ if (view.getKeyboard() == keyboard1) {
+ checkToggleCapsLock()
+ view.setShifted(capsLock || !view.isShifted())
+ }
+ case Keyboard.KEYCODE_CANCEL =>
+ requestHideSelf(0)
+ view.closing()
+ case Keyboard.KEYCODE_MODE_CHANGE if view ne null =>
+ if (view.getKeyboard() == keyboard1) {
+ view.setKeyboard(keyboard2)
+ } else {
+ view.setKeyboard(keyboard1)
+ }
+ keyboard1.setShifted(false)
+ keyboard2.setShifted(false)
+ case _ =>
+ handleKey(primaryCode, keyCodes)
+ updateShiftKeyState()
+ }
+ }
+
+ private def handleKey(primaryCode: Int, keyCodes: Array[Int]) {
+ val translatedCode = if (isInputViewShown() && view.isShifted()) {
+ Character.toUpperCase(primaryCode)
+ } else {
+ primaryCode
+ }
+ getCurrentInputConnection().commitText(String.valueOf(translatedCode.toChar), 1)
+ }
+
+ private def checkToggleCapsLock() {
+ val now = System.currentTimeMillis();
+ if (lastShiftTime + 800 > now || capsLock) {
+ capsLock = !capsLock
+ lastShiftTime = 0
+ } else {
+ lastShiftTime = now;
+ }
+ }
+
+ private def updateShiftKeyState() {
+ val ei = getCurrentInputEditorInfo()
+ if ((ei ne null) && (view ne null) && (view.getKeyboard() == keyboard1)) {
+ val caps = (ei.inputType != InputType.TYPE_NULL && getCurrentInputConnection().getCursorCapsMode(ei.inputType) != 0)
+ view.setShifted(capsLock || caps)
+ }
+ }
+
+ def onPress(primaryCode: Int) { }
+ def onRelease(primaryCode: Int) { }
def onText(text: CharSequence) { }
- def updateCandidates() { }
- def setSuggestions(suggestions: JList[String], completions: Boolean) { }
- def handleBackspace() { }
- def handleShift() { }
- def handleCharacter(primaryCode: Int, keyCodes: Array[Int]) { }
- def handleClose() { }
- def checkToggleCapsLock() { }
- def isWordSeparator(code: Int): Boolean = { code == 20 }
- def pickDefaultCandidate() { }
- def pickSuggestionManually(index: Int) { }
def swipeRight() { }
def swipeLeft() { }
def swipeDown() { }
def swipeUp() { }
- def onPress(primaryCode: Int) { }
- def onRelease(primaryCode: Int) { }
}
-import android.content.Context
-import android.util.AttributeSet
-
class DvorkyKeyboardView(context: Context, attrs: AttributeSet) extends KeyboardView(context, attrs) {
val KEYCODE_OPTIONS = -100;
Please sign in to comment.
Something went wrong with that request. Please try again.