Commit 530ce747 authored by 王韦's avatar 王韦

[new] 增加 键盘库

parent d77725d0
/build
\ No newline at end of file
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: "com.whl.gradle-publish-plugin"
android {
compileSdkVersion 29
defaultConfig {
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
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'
implementation "androidx.core:core-ktx:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
repositories {
mavenCentral()
}
group 'com.qmai.android.widget'
version '1.1.2-SNAPSHOT'
gradlePublish {
sourceJarEnabled = true
javaDocEnabled = false
signEnabled = false
releaseRepository {
url = "https://hub.zmcms.cn/repository/maven-releases/"
userName = "wangwei"
password = "caihong520"
}
snapshotRepository {
url = "https://hub.zmcms.cn/repository/maven-snapshots/"
userName = "wangwei"
password = "caihong520"
}
}
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
\ No newline at end of file
package com.qmai.android.keyboardview;
import android.content.Context;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.qmai.android.keyboardview.test", appContext.getPackageName());
}
}
\ No newline at end of file
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.qmai.android.keyboardview">
</manifest>
\ No newline at end of file
package com.qmai.android.keyboard;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.Nullable;
import com.qmai.android.keyboardview.R;
/**
* created by wangwei ON 6/14/20 email:wangwei_5521@163.com
*
* @version 1.1.1
* @Description
**/
class MineView extends View {
public MineView(Context context) {
this(context, null);
}
public MineView(Context context, @Nullable AttributeSet attrs) {
this(context, attrs, R.attr.mineViewStyle);
}
public MineView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MineView,defStyleAttr,0);
for (int i = 0; i < a.getIndexCount(); i++) {
int attrIndex = a.getIndex(i);
if (attrIndex == R.styleable.MineView_title) {
String title = a.getString(attrIndex);
System.out.println("title = "+title);
}
}
a.recycle();
}
}
package com.qmai.android.keyboard;
import android.content.Context
import android.util.AttributeSet
import android.widget.EditText
import android.widget.TextView
import com.qmai.android.keyboardview.R
/**
* created by wangwei ON 6/12/20 email:wangwei_5521@163.com
* @version 1.1.1
**/
class NumberKeyBoard : QmKeyboardView {
private lateinit var editWidget: TextView
enum class Code constructor(var code: Int) {
ZERO(0), ONE(1), TWO(2), THREE(3), FOUR(4), FIVE(5),
SIX(6), SEVEN(7), EIGHT(8), NINE(9), DELETE(10), CLEAR(11)
}
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {
init(context)
}
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(
context,
attrs,
defStyleAttr
) {
init(context)
}
constructor(
context: Context?,
attrs: AttributeSet?,
defStyleAttr: Int,
defStyleRes: Int
) : super(context, attrs, defStyleAttr, defStyleRes) {
init(context)
}
fun bindEditText(editText: EditText) {
editWidget = editText
}
fun setKeyBoardLister(keyBoardListener: OnKeyboardActionListener) {
onKeyboardActionListener = keyBoardListener
}
private fun defaultKeyBoardListener() =
DefaultKeyBoardActionListener()
inner class DefaultKeyBoardActionListener : OnKeyboardActionListener {
override fun swipeRight() {
}
override fun onPress(primaryCode: Int) {
}
override fun onRelease(primaryCode: Int) {
}
override fun swipeLeft() {
}
override fun swipeUp() {
}
override fun swipeDown() {
}
override fun onKey(primaryCode: Int, keyCodes: IntArray?) {
val editable = editWidget.editableText
when (primaryCode) {
Code.CLEAR.code -> {
editable.clear()
}
Code.DELETE.code -> {
if (editable.isNotEmpty()) {
editable.delete(editable.length - 1, editable.length)
}
}
else -> {
editable.append(primaryCode.toString())
}
}
}
override fun onText(text: CharSequence?) {
}
}
private fun init(context: Context?) {
val keyBoard = QmKeyboard(context, R.xml.numkeyboard)
isEnabled = true
isPreviewEnabled = false
this.keyboard = keyBoard
onKeyboardActionListener = defaultKeyBoardListener()
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false"
android:drawable="@drawable/btn_close_normal" />
<item android:state_pressed="true"
android:drawable="@drawable/btn_close_pressed" />
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2008 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.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Toggle keys. Use checkable/checked state. -->
<item android:state_checkable="true" android:state_checked="true"
android:state_pressed="true"
android:drawable="@drawable/btn_keyboard_key_pressed" />
<item android:state_checkable="true" android:state_pressed="true"
android:drawable="@drawable/btn_keyboard_key_normal" />
<item android:state_checkable="true" android:state_checked="true"
android:drawable="@drawable/btn_keyboard_key_pressed" />
<item android:state_checkable="true"
android:drawable="@drawable/btn_keyboard_key_normal" />
<!-- Normal keys -->
<item android:state_pressed="true"
android:drawable="@drawable/btn_keyboard_key_pressed" />
<item
android:drawable="@drawable/btn_keyboard_key_normal" />
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_long_pressable="true"
android:drawable="@drawable/keyboard_key_feedback_more_background" />
<item android:drawable="@drawable/keyboard_key_feedback_background" />
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="80sp"
android:textSize="40sp"
android:textColor="#FFFFFF"
android:minWidth="32dip"
android:gravity="center"
android:background="@drawable/keyboard_key_feedback"
/>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:background="@drawable/keyboard_popup_panel_background"
android:layout_height="match_parent">
<com.qmai.android.keyboard.QmKeyboardView
android:id="@+id/keyboardView"
android:background="@android:color/transparent"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:keyPreviewLayout="@layout/keyboard_key_preview"
android:popupLayout="@layout/keyboard_popup_keyboard"
android:keyTextSize="22sp"
tools:ignore="ResourceCycle" />
<ImageButton
android:id="@+id/closeButton"
android:background="@android:color/transparent"
android:src="@drawable/btn_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="8dp"
android:clickable="true" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="QmKeyboardViewPreviewState">
<!-- State for {@link android.inputmethodservice.KeyboardView KeyboardView}
key preview background -->
<attr name="state_long_pressable" format="boolean" />
</declare-styleable>
<declare-styleable name="CKeyBoard">
<attr name="cKeyWidth" format="dimension|fraction"/>
<attr name="cKeyHeight" format="dimension|fraction" />
<attr name="CHorizontalGap" format="dimension|fraction" />
<attr name="CVerticalGap" format="dimension|fraction" />
</declare-styleable>
<declare-styleable name="MineView">
<attr name="title" format="string" />
</declare-styleable>
<declare-styleable name="test">
<attr name="keyWidth" format="dimension"/>
</declare-styleable>
<attr name="mineViewStyle" format="reference" />
<attr name="qmKeyboardViewStyle" format="reference" />
<declare-styleable name="QmKeyboardView">
<!-- Default KeyboardView style. -->
<!-- Image for the key. This image needs to be a StateListDrawable, with the following
possible states: normal, pressed, checkable, checkable+pressed, checkable+checked,
checkable+checked+pressed. -->
<attr name="key_Background" format="reference" />
<!-- Size of the text for character keys. -->
<attr name="keyTextSize" format="dimension" />
<!-- Size of the text for custom keys with some text and no icon. -->
<attr name="labelTextSize" format="dimension" />
<!-- Color to use for the label in a key -->
<attr name="keyTextColor" format="color" />
<!-- Layout resource for key press feedback.-->
<attr name="keyPreviewLayout" format="reference" />
<!-- Vertical offset of the key press feedback from the key. -->
<attr name="keyPreviewOffset" format="dimension" />
<!-- Height of the key press feedback popup. -->
<attr name="keyPreviewHeight" format="dimension" />
<!-- Amount to offset the touch Y coordinate by, for bias correction. -->
<attr name="verticalCorrection" format="dimension" />
<!-- Layout resource for popup keyboards -->
<attr name="popupLayout" format="reference" />
<attr name="shadowColor" format="color" />
<attr name="shadowRadius" format="float" />
</declare-styleable>
<declare-styleable name="QmKeyboard_Row">
<!-- Row edge flags-->
<attr name="rowEdgeFlags">
<!-- Row is anchored to the top of the keyboard -->
<flag name="top" value="4" />
<!-- Row is anchored to the bottom of the keyboard -->
<flag name="bottom" value="8" />
</attr>
<!-- Mode of the keyboard. If the mode doesn't match the
requested keyboard mode, the row will be skipped -->
<attr name="keyboardMode" format="reference" />
</declare-styleable>
<declare-styleable name="QmKeyboard_Key">
<!-- The unicode value or comma-separated values that this key outputs -->
<attr name="codes" format="integer|string" />
<!-- The XML keyboard layout of any popup keyboard -->
<attr name="popupKeyboard" format="reference" />
<!-- The characters to display in the popup keyboard -->
<attr name="popupCharacters" format="string" />
<!-- Key edge flags -->
<attr name="keyEdgeFlags">
<!-- Key is anchored to the left of the keyboard -->
<flag name="left" value="1" />
<!-- Key is anchored to the right of the keyboard -->
<flag name="right" value="2" />
</attr>
<!-- Whether this is a modifier key such as Alt or Shift -->
<attr name="isModifier" format="boolean" />
<!-- Whether this is a toggle key -->
<attr name="isSticky" format="boolean" />
<!-- Whether long-pressing on this key will make it repeat -->
<attr name="isRepeatable" format="boolean" />
<!-- The icon to show in the popup preview -->
<attr name="iconPreview" format="reference" />
<!-- The string of characters to output when this key is pressed -->
<attr name="keyOutputText" format="string" />
<!-- The label to display on the key -->
<attr name="keyLabel" format="string" />
<!-- The icon to display on the key instead of the label -->
<attr name="keyIcon" format="reference" />
<!-- Mode of the keyboard. If the mode doesn't match the
requested keyboard mode, the key will be skipped -->
<attr name="keyboardMode" />
</declare-styleable>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Widget.qmKeyboardViewStyleValue" parent="android:Widget">
<item name="background">@drawable/keyboard_background</item>
<item name="key_Background">@drawable/btn_keyboard_key</item>
<item name="keyTextSize">24sp</item>
<item name="keyTextColor">#333333</item>
<item name="keyPreviewLayout">@layout/keyboard_key_preview</item>
<item name="keyPreviewOffset">-12dp</item>
<item name="keyPreviewHeight">80dp</item>
<item name="labelTextSize">15sp</item>
<item name="popupLayout">@layout/keyboard_popup_keyboard</item>
<item name="verticalCorrection">-10dip</item>
<item name="shadowColor">#333333</item>
<item name="shadowRadius">0</item>
</style>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources></resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<KeyBoard
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cKeyHeight = "60dp"
app:CHorizontalGap= "48dp"
app:CVerticalGap = "13dp"
app:cKeyWidth="60dp">
<Row>
<Key
app:codes="1"
app:keyLabel="1" />
<Key
app:codes="2"
app:keyLabel="2" />
<Key
app:codes="3"
app:keyLabel="3" />
</Row>
<Row>
<Key
app:codes="4"
app:keyLabel="4" />
<Key
app:codes="5"
app:keyLabel="5" />
<Key
app:codes="6"
app:keyLabel="6" />
</Row>
<Row>
<Key
app:codes="7"
app:keyLabel="7" />
<Key
app:codes="8"
app:keyLabel="8" />
<Key
app:codes="9"
app:keyLabel="9" />
</Row>
<Row>
<Key
app:codes="11"
app:keyLabel="清空" />
<Key
app:codes="0"
app:keyLabel="0" />
<Key
app:codes="10"
app:isRepeatable="true"
app:keyIcon = "@drawable/keyboard_delete"
/>
</Row>
</KeyBoard>
package com.qmai.android.keyboardview;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment