Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy UI from AOSP's LatinIME #28

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ dependencies {
// implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation project(':lib')
// TODO not ready yet
implementation project(':keyboardview')
//implementation project(':dawg-android')
implementation "kentvu.dawgjava:dawg-android:$dawgjava_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.vutrankien.t9vietnamese.android

import android.inputmethodservice.KeyboardView
import com.android.inputmethod.keyboard.KeyboardActionListener
import com.android.inputmethod.latin.common.InputPointers
import com.vutrankien.t9vietnamese.lib.Event
import com.vutrankien.t9vietnamese.lib.EventWithData
import com.vutrankien.t9vietnamese.lib.Key
Expand All @@ -13,40 +14,25 @@ internal class KeyboardActionListener(
logFactory: LogFactory,
private val scope: CoroutineScope,
private val eventSource: Channel<EventWithData<Event, Key>>
) : KeyboardView.OnKeyboardActionListener {
) : KeyboardActionListener {
private val log: LogFactory.Log = logFactory.newLog("KeyboardActionListener")
override fun swipeRight() {
log.d("swipeRight")
}

override fun onPress(primaryCode: Int) {
log.d("onPress")
}

override fun onRelease(primaryCode: Int) {
log.d("onRelease")
override fun onPressKey(primaryCode: Int, repeatCount: Int, isSinglePointer: Boolean) {
log.d("onPressKey:$primaryCode")
}

override fun swipeLeft() {
log.d("swipeLeft")
override fun onReleaseKey(primaryCode: Int, withSliding: Boolean) {
log.d("onReleaseKey:$primaryCode")
}

override fun swipeUp() {
log.d("swipeUp")
override fun onCodeInput(primaryCode: Int, x: Int, y: Int, isKeyRepeat: Boolean) {
log.d("onCodeInput:$primaryCode")
}

override fun swipeDown() {
log.d("swipeDown")
}

override fun onKey(primaryCode: Int, keyCodes: IntArray?) {
log.d("onKey:$primaryCode,${keyCodes?.joinToString()}")
}

override fun onText(text: CharSequence?) {
log.d("onText:$text")
override fun onTextInput(text: String?) {
log.d("onTextInput:$text")
if(text == null) {
log.w("onText:text is null!!")
log.w("onTextInput:text is null!!")
return
}
scope.launch {
Expand All @@ -56,4 +42,33 @@ internal class KeyboardActionListener(
))
}
}

override fun onStartBatchInput() {
log.d("onStartBatchInput")
}

override fun onUpdateBatchInput(batchPointers: InputPointers?) {
log.d("onUpdateBatchInput:$batchPointers")
}

override fun onEndBatchInput(batchPointers: InputPointers?) {
log.d("onEndBatchInput:$batchPointers")
}

override fun onCancelBatchInput() {
log.d("onCancelBatchInput")
}

override fun onCancelInput() {
log.d("onCancelInput")
}

override fun onFinishSlidingInput() {
log.d("onFinishSlidingInput")
}

override fun onCustomRequest(requestCode: Int): Boolean {
log.d("onCustomRequest")
return false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,29 @@ package com.vutrankien.t9vietnamese.android
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.inputmethodservice.KeyboardView
import android.os.Bundle
import android.os.PowerManager
import android.provider.Settings
import android.text.InputType
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.inputmethod.EditorInfo
import android.view.inputmethod.InputMethodInfo
import android.view.inputmethod.InputMethodManager
import android.view.inputmethod.InputMethodSubtype
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.android.inputmethod.accessibility.AccessibilityUtils
import com.android.inputmethod.keyboard.KeyboardId
import com.android.inputmethod.keyboard.KeyboardLayoutSet
import com.android.inputmethod.keyboard.MainKeyboardView
import com.android.inputmethod.latin.InputView
import com.android.inputmethod.latin.RichInputMethodManager
import com.android.inputmethod.latin.RichInputMethodSubtype
import com.android.inputmethod.latin.utils.ResourceUtils
import com.vutrankien.t9vietnamese.lib.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand All @@ -36,6 +47,8 @@ class MainActivity : Activity(), MVPView {
companion object {
private const val WAKELOCK_TIMEOUT = 60000L
}
private lateinit var subtype: InputMethodSubtype

override val scope = CoroutineScope(Dispatchers.Main + Job())

override val eventSource: Channel<EventWithData<Event, Key>> =
Expand Down Expand Up @@ -71,9 +84,34 @@ class MainActivity : Activity(), MVPView {
(application as T9Application).appComponent.inject(this)
log = logFactory.newLog("MainActivity")
setContentView(R.layout.main)
val kbView = findViewById<KeyboardView>(R.id.dialpad)
kbView.keyboard = T9Keyboard(this, R.xml.t9)
kbView.setOnKeyboardActionListener(
AccessibilityUtils.init(this)
val inputView = findViewById<InputView>(R.id.dialpad)
val kbView =
inputView.findViewById(com.android.inputmethod.latin.R.id.keyboard_view) as MainKeyboardView
val editorInfo = EditorInfo()
editorInfo.inputType = InputType.TYPE_CLASS_TEXT
val builder = KeyboardLayoutSet.Builder(this, editorInfo)
val res = resources
val keyboardWidth = ResourceUtils.getDefaultKeyboardWidth(res)
val keyboardHeight = ResourceUtils.getDefaultKeyboardHeight(res)
builder.setKeyboardGeometry(keyboardWidth, keyboardHeight)
RichInputMethodManager.init(this)
val mRichImm = RichInputMethodManager.getInstance()
val imi: InputMethodInfo = mRichImm.getInputMethodInfoOfThisIme()
val subtypeCount = imi.subtypeCount
for (index in 0 until subtypeCount) {
//mAllSubtypesList.add(imi.getSubtypeAt(index))
if (imi.getSubtypeAt(index) != null) {
subtype = imi.getSubtypeAt(index)!!
break
}
}
builder.setSubtype(RichInputMethodSubtype.getRichInputMethodSubtype(subtype))
builder.setIsSpellChecker(true /* isSpellChecker */)
builder.disableTouchPositionCorrectionData()
val keyboardLayoutSet = builder.build()
kbView.setKeyboard(keyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_ALPHABET))
kbView.setKeyboardActionListener(
KeyboardActionListener(
logFactory,
scope,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import android.inputmethodservice.InputMethodService
import android.view.View
import android.widget.Button
import androidx.recyclerview.widget.RecyclerView
import com.android.inputmethod.keyboard.KeyboardId
import com.android.inputmethod.keyboard.KeyboardLayoutSet
import com.android.inputmethod.keyboard.MainKeyboardView
import com.android.inputmethod.keyboard.internal.KeyboardBuilder
import com.android.inputmethod.keyboard.internal.KeyboardParams
import com.android.inputmethod.latin.InputView
import com.vutrankien.t9vietnamese.lib.*
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
Expand Down Expand Up @@ -39,9 +45,14 @@ class T9Vietnamese : InputMethodService(), MVPView {

override fun onCreateInputView(): View {
val inputView = layoutInflater.inflate(
R.layout.input, null) as (T9KeyboardView)
inputView.keyboard = T9Keyboard(this, R.xml.t9)
inputView.setOnKeyboardActionListener(
R.layout.input, null) as (InputView)
val kbView =
inputView.findViewById(com.android.inputmethod.latin.R.id.keyboard_view) as MainKeyboardView
val builder = KeyboardBuilder(this, KeyboardParams())
builder.load(R.xml.t9, KeyboardId(KeyboardId.ELEMENT_PHONE, KeyboardLayoutSet.Params()/*.also { mKeyboardWith = .... }*/))
val keyboard = builder.build()
kbView.setKeyboard(keyboard)
kbView.setKeyboardActionListener(
KeyboardActionListener(
logFactory,
scope,
Expand Down
12 changes: 8 additions & 4 deletions app/src/main/res/layout/input.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<com.vutrankien.t9vietnamese.android.T9KeyboardView
xmlns:android="http://schemas.android.com/apk/res/android"
<com.android.inputmethod.latin.InputView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/keyboard"
android:layout_alignParentBottom="true"
style="?attr/inputViewStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
android:layout_alignParentBottom="true">

<include
android:id="@+id/main_keyboard_frame"
layout="@layout/main_keyboard_frame" />
</com.android.inputmethod.latin.InputView>

2 changes: 1 addition & 1 deletion app/src/main/res/layout/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:hint="@string/test_hint"
app:layout_constraintBottom_toTopOf="@+id/dialpad"
app:layout_constraintBottom_toTopOf="@id/dialpad"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
kotlin_version = '1.3.71'
kotlin_version = '1.3.72'
kotest_version = '4.0.1'
}
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.android.tools.build:gradle:3.6.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
1 change: 1 addition & 0 deletions keyboardview/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
63 changes: 63 additions & 0 deletions keyboardview/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Vietnamese-t9-ime: T9 input method for Vietnamese.
* Copyright (C) 2020 Vu Tran Kien.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

apply plugin: 'com.android.library'

android {
compileSdkVersion 29
buildToolsVersion "29.0.1"

defaultConfig {
minSdkVersion 15
targetSdkVersion 29
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
}
sourceSets {
main {
res.srcDirs += ['java/res']
java.srcDirs += ['common/src', 'java/src']
}

androidTest {
res.srcDirs = ['tests/res']
java.srcDirs = ['tests/src']
}
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.code.findbugs:jsr305:3.0.2'

implementation 'androidx.appcompat:appcompat:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.android.inputmethod.annotations;

/**
* Denotes that the class, method or field should not be eliminated by ProGuard,
* because it is externally referenced. (See proguard.flags)
*/
public @interface ExternallyReferenced {
}
Loading