├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ └── layout
│ │ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── keyboard
│ │ │ └── xud
│ │ │ └── com
│ │ │ └── keyboardtest
│ │ │ └── MainActivity.java
│ ├── test
│ │ └── java
│ │ │ └── keyboard
│ │ │ └── xud
│ │ │ └── com
│ │ │ └── keyboardtest
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── keyboard
│ │ └── xud
│ │ └── com
│ │ └── keyboardtest
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── djkeyboard
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── keyboard_codes.xml
│ │ │ │ ├── ids.xml
│ │ │ │ └── colors.xml
│ │ │ ├── drawable-xhdpi
│ │ │ │ ├── ic_abc_del.png
│ │ │ │ ├── ic_num_del.png
│ │ │ │ ├── key_number_del.png
│ │ │ │ └── key_number_del_pressed.png
│ │ │ ├── drawable-xxhdpi
│ │ │ │ ├── ic_abc_del.png
│ │ │ │ ├── ic_num_del.png
│ │ │ │ ├── key_number_del.png
│ │ │ │ └── key_number_del_pressed.png
│ │ │ ├── drawable
│ │ │ │ ├── keyboard_number.xml
│ │ │ │ ├── keyboard_number_pressed.xml
│ │ │ │ ├── keyboard_abc.xml
│ │ │ │ ├── keyboard_abc_pressed.xml
│ │ │ │ ├── key_num_done_bg.xml
│ │ │ │ ├── key_abc_bg.xml
│ │ │ │ ├── key_abc_del_bg.xml
│ │ │ │ ├── key_num_del_bg.xml
│ │ │ │ ├── key_number_bg.xml
│ │ │ │ ├── key_abc_del_pressed.xml
│ │ │ │ └── key_abc_del.xml
│ │ │ ├── anim
│ │ │ │ ├── down_to_up.xml
│ │ │ │ └── up_to_hide.xml
│ │ │ ├── layout
│ │ │ │ ├── layout_keyboard_view.xml
│ │ │ │ └── layout_recycler_keyboard_view.xml
│ │ │ └── xml
│ │ │ │ ├── keyboard_number.xml
│ │ │ │ └── keyboard_abc.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── cn
│ │ │ └── baymax
│ │ │ └── android
│ │ │ └── keyboard
│ │ │ ├── Utils.java
│ │ │ ├── ABCKeyboard.java
│ │ │ ├── KeyboardSearchBaseAdapter.java
│ │ │ ├── NumberKeyboard.java
│ │ │ ├── ReflectionUtils.java
│ │ │ ├── SearchResultLinearLayoutManager.java
│ │ │ ├── KeyboardWithSearchView.java
│ │ │ ├── BaseKeyboard.java
│ │ │ ├── BaseKeyboardView.java
│ │ │ └── KeyboardManager.java
│ ├── test
│ │ └── java
│ │ │ └── cn
│ │ │ └── baymax
│ │ │ └── android
│ │ │ └── demo
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── cn
│ │ └── baymax
│ │ └── android
│ │ └── demo
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── README.md
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/djkeyboard/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':djkeyboard'
2 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xudjx/djkeyboard/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | KeyboardTest
3 |
4 |
--------------------------------------------------------------------------------
/djkeyboard/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | keyboard
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xudjx/djkeyboard/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xudjx/djkeyboard/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xudjx/djkeyboard/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xudjx/djkeyboard/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xudjx/djkeyboard/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xudjx/djkeyboard/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xudjx/djkeyboard/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xudjx/djkeyboard/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xudjx/djkeyboard/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xudjx/djkeyboard/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/djkeyboard/src/main/res/drawable-xhdpi/ic_abc_del.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xudjx/djkeyboard/HEAD/djkeyboard/src/main/res/drawable-xhdpi/ic_abc_del.png
--------------------------------------------------------------------------------
/djkeyboard/src/main/res/drawable-xhdpi/ic_num_del.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xudjx/djkeyboard/HEAD/djkeyboard/src/main/res/drawable-xhdpi/ic_num_del.png
--------------------------------------------------------------------------------
/djkeyboard/src/main/res/drawable-xxhdpi/ic_abc_del.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xudjx/djkeyboard/HEAD/djkeyboard/src/main/res/drawable-xxhdpi/ic_abc_del.png
--------------------------------------------------------------------------------
/djkeyboard/src/main/res/drawable-xxhdpi/ic_num_del.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xudjx/djkeyboard/HEAD/djkeyboard/src/main/res/drawable-xxhdpi/ic_num_del.png
--------------------------------------------------------------------------------
/djkeyboard/src/main/res/drawable-xhdpi/key_number_del.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xudjx/djkeyboard/HEAD/djkeyboard/src/main/res/drawable-xhdpi/key_number_del.png
--------------------------------------------------------------------------------
/djkeyboard/src/main/res/drawable-xxhdpi/key_number_del.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xudjx/djkeyboard/HEAD/djkeyboard/src/main/res/drawable-xxhdpi/key_number_del.png
--------------------------------------------------------------------------------
/djkeyboard/src/main/res/drawable-xhdpi/key_number_del_pressed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xudjx/djkeyboard/HEAD/djkeyboard/src/main/res/drawable-xhdpi/key_number_del_pressed.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 | .idea/
11 |
--------------------------------------------------------------------------------
/djkeyboard/src/main/res/drawable-xxhdpi/key_number_del_pressed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xudjx/djkeyboard/HEAD/djkeyboard/src/main/res/drawable-xxhdpi/key_number_del_pressed.png
--------------------------------------------------------------------------------
/djkeyboard/src/main/res/drawable/keyboard_number.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/djkeyboard/src/main/res/values/keyboard_codes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -2525
4 |
5 | -3525
6 |
--------------------------------------------------------------------------------
/djkeyboard/src/main/res/drawable/keyboard_number_pressed.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/djkeyboard/src/main/res/anim/down_to_up.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
--------------------------------------------------------------------------------
/djkeyboard/src/main/res/anim/up_to_hide.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/djkeyboard/src/main/res/drawable/keyboard_abc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/djkeyboard/src/main/res/drawable/keyboard_abc_pressed.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/djkeyboard/src/main/res/values/ids.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Jul 25 15:55:21 CST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/djkeyboard/src/main/res/drawable/key_num_done_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/djkeyboard/src/main/res/drawable/key_abc_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/djkeyboard/src/main/res/drawable/key_abc_del_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/djkeyboard/src/main/res/drawable/key_num_del_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/djkeyboard/src/main/res/drawable/key_number_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/djkeyboard/src/main/res/layout/layout_keyboard_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
--------------------------------------------------------------------------------
/djkeyboard/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/djkeyboard/src/main/res/drawable/key_abc_del_pressed.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/djkeyboard/src/main/res/drawable/key_abc_del.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | -
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/djkeyboard/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | #333333
6 |
7 | #d8d3cf
8 |
9 | #ffffff
10 |
11 | #a59a93
12 |
13 |
14 | #b9afa9
15 |
16 | #c35b3a
17 |
18 | #9d472c
19 |
20 |
--------------------------------------------------------------------------------
/djkeyboard/src/test/java/cn/baymax/android/demo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package cn.baymax.android.demo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/test/java/keyboard/xud/com/keyboardtest/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package keyboard.xud.com.keyboardtest;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/djkeyboard/src/main/java/cn/baymax/android/keyboard/Utils.java:
--------------------------------------------------------------------------------
1 | package cn.baymax.android.keyboard;
2 |
3 | import android.content.Context;
4 |
5 | /**
6 | * Created by xud on 2017/3/11.
7 | */
8 |
9 | public class Utils {
10 |
11 | public static int dipToPx(Context context, float dpValue) {
12 | final float scale = context.getResources().getDisplayMetrics().density;
13 | return (int) (dpValue * scale + 0.5f);
14 | }
15 |
16 | public static int pxToDip(Context context, float pxValue) {
17 | final float scale = context.getResources().getDisplayMetrics().density;
18 | return (int) (pxValue / scale + 0.5f);
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/djkeyboard/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/Max/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/djkeyboard/src/androidTest/java/cn/baymax/android/demo/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package cn.baymax.android.demo;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("cn.baymax.android.keyboard.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/keyboard/xud/com/keyboardtest/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package keyboard.xud.com.keyboardtest;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("keyboard.xud.com.keyboardtest", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/xud/Software/android-sdk-mac/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/djkeyboard/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.3"
6 |
7 | defaultConfig {
8 | minSdkVersion 23
9 | targetSdkVersion 25
10 |
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 |
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 | dependencies {
26 | compile fileTree(dir: 'libs', include: ['*.jar'])
27 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
28 | exclude group: 'com.android.support', module: 'support-annotations'
29 | })
30 | compile 'com.android.support:appcompat-v7:25.3.1'
31 | compile 'com.android.support.constraint:constraint-layout:1.0.1'
32 | testCompile 'junit:junit:4.12'
33 | compile 'com.android.support:recyclerview-v7:25.3.1'
34 | }
35 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.3"
6 | defaultConfig {
7 | applicationId "keyboard.xud.com.keyboardtest"
8 | minSdkVersion 23
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:25.3.1'
28 | compile 'com.android.support.constraint:constraint-layout:1.0.1'
29 | testCompile 'junit:junit:4.12'
30 |
31 | compile project(':djkeyboard')
32 | }
33 |
--------------------------------------------------------------------------------
/djkeyboard/src/main/java/cn/baymax/android/keyboard/ABCKeyboard.java:
--------------------------------------------------------------------------------
1 | package cn.baymax.android.keyboard;
2 |
3 | import android.content.Context;
4 |
5 | /**
6 | * Created by xud on 2017/3/2.
7 | */
8 |
9 | public class ABCKeyboard extends BaseKeyboard {
10 |
11 | public static final int DEFAULT_ABC_XML_LAYOUT = R.xml.keyboard_abc;
12 |
13 | public ABCKeyboard(Context context, int xmlLayoutResId) {
14 | super(context, xmlLayoutResId);
15 | }
16 |
17 | public ABCKeyboard(Context context, int xmlLayoutResId, int modeId, int width, int height) {
18 | super(context, xmlLayoutResId, modeId, width, height);
19 | }
20 |
21 | public ABCKeyboard(Context context, int xmlLayoutResId, int modeId) {
22 | super(context, xmlLayoutResId, modeId);
23 | }
24 |
25 | public ABCKeyboard(Context context, int layoutTemplateResId, CharSequence characters, int columns, int horizontalPadding) {
26 | super(context, layoutTemplateResId, characters, columns, horizontalPadding);
27 | }
28 |
29 | @Override
30 | public boolean handleSpecialKey(int primaryCode) {
31 | return false;
32 | }
33 |
34 | @Override
35 | public Padding getPadding() {
36 | return new Padding(10,0,10,0);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # djkeyboard
2 | Customize the keyboard, both number keyboard and alphabet keyboard.
3 |
4 | Please import the module.
5 |
6 | ### Number Keyboard
7 |
8 | You can use as follow:
9 |
10 | ```
11 | KeyboardManager keyboardManagerNumber = new KeyboardManager(this);
12 | NumberKeyboard numberKeyboard = new NumberKeyboard(context,NumberKeyboard.DEFAULT_NUMBER_XML_LAYOUT);
13 | keyboardManagerNumber.bindToEditor(editText2, numberKeyboard);
14 | ```
15 |
16 | 
17 |
18 |
19 |
20 |
21 | ### Alphabet Keyboard
22 |
23 | You can use as follow:
24 |
25 | ```
26 | KeyboardManager keyboardManagerAbc = new KeyboardManager(this);
27 | keyboardManagerAbc.bindToEditor(editText1, new ABCKeyboard(context, ABCKeyboard.DEFAULT_ABC_XML_LAYOUT));
28 | ```
29 |
30 | 
31 |
32 |
33 | By the way, the module also has some useful interface for customized requirements.
34 |
35 | ```
36 | public interface KeyStyle {
37 |
38 | public Drawable getKeyBackound(Key key);
39 |
40 | public Float getKeyTextSize(Key key);
41 |
42 | public Integer getKeyTextColor(Key key);
43 |
44 | public CharSequence getKeyLabel(Key key);
45 | }
46 |
47 | ```
48 |
49 | ```
50 | public interface ActionDoneClickListener {
51 | void onActionDone(CharSequence charSequence);
52 | }
53 | ```
54 |
55 |
--------------------------------------------------------------------------------
/djkeyboard/src/main/res/layout/layout_recycler_keyboard_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
17 |
18 |
19 |
24 |
25 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/djkeyboard/src/main/res/xml/keyboard_number.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
10 |
11 |
12 |
14 |
15 |
16 |
19 |
20 |
21 |
24 |
25 |
26 |
29 |
30 |
31 |
32 |
33 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/djkeyboard/src/main/java/cn/baymax/android/keyboard/KeyboardSearchBaseAdapter.java:
--------------------------------------------------------------------------------
1 | package cn.baymax.android.keyboard;
2 |
3 | import android.content.Context;
4 | import android.content.res.Resources;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.TextView;
10 |
11 | import java.util.List;
12 |
13 | /**
14 | * Created by xud 2017-03-09
15 | */
16 | public abstract class KeyboardSearchBaseAdapter extends RecyclerView.Adapter {
17 |
18 | public Context context;
19 | public Resources resources;
20 | public LayoutInflater mLayoutInflater;
21 | protected List listData;
22 | protected View.OnClickListener itemClickListener;
23 |
24 | public KeyboardSearchBaseAdapter(Context context, List listData) {
25 | this.context = context;
26 | this.listData = listData;
27 | this.resources = context.getResources();
28 | this.mLayoutInflater = LayoutInflater.from(context);
29 | }
30 |
31 | public List getAdapterData() {
32 | return listData;
33 | }
34 |
35 | protected void setAdapterData(List listData) {
36 | this.listData = listData;
37 | }
38 |
39 | public void setItemClickListener(View.OnClickListener itemClickListener) {
40 | this.itemClickListener = itemClickListener;
41 | }
42 |
43 | @Override
44 | public void onBindViewHolder(BaseViewHolder holder, int position) {
45 | holder.itemView.setTag(listData != null ? listData.get(position) : null);
46 | }
47 |
48 |
49 |
50 | @Override
51 | public int getItemCount() {
52 | return listData != null ? listData.size() : 0;
53 | }
54 |
55 | public abstract class BaseViewHolder extends RecyclerView.ViewHolder {
56 |
57 | public BaseViewHolder(View itemView) {
58 | super(itemView);
59 | if (itemClickListener != null)
60 | itemView.setOnClickListener(itemClickListener);
61 | }
62 |
63 | protected void injectView() {
64 | }
65 |
66 |
67 | }
68 |
69 | }
--------------------------------------------------------------------------------
/djkeyboard/src/main/res/xml/keyboard_abc.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
21 |
22 |
23 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
34 |
35 |
36 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/djkeyboard/src/main/java/cn/baymax/android/keyboard/NumberKeyboard.java:
--------------------------------------------------------------------------------
1 | package cn.baymax.android.keyboard;
2 |
3 | import android.content.Context;
4 | import android.text.Editable;
5 |
6 | /**
7 | * Created by xud on 2017/3/2.
8 | */
9 |
10 | public class NumberKeyboard extends BaseKeyboard {
11 |
12 | public static final int DEFAULT_NUMBER_XML_LAYOUT = R.xml.keyboard_number;
13 |
14 | private boolean enableDotInput = true;
15 |
16 | public ActionDoneClickListener mActionDoneClickListener;
17 |
18 | public NumberKeyboard(Context context, int xmlLayoutResId) {
19 | super(context, xmlLayoutResId);
20 | }
21 |
22 | public NumberKeyboard(Context context, int xmlLayoutResId, int modeId, int width, int height) {
23 | super(context, xmlLayoutResId, modeId, width, height);
24 | }
25 |
26 | public NumberKeyboard(Context context, int xmlLayoutResId, int modeId) {
27 | super(context, xmlLayoutResId, modeId);
28 | }
29 |
30 | public NumberKeyboard(Context context, int layoutTemplateResId, CharSequence characters, int columns, int horizontalPadding) {
31 | super(context, layoutTemplateResId, characters, columns, horizontalPadding);
32 | }
33 |
34 | public void setActionDoneClickListener(ActionDoneClickListener actionDoneClickListener) {
35 | mActionDoneClickListener = actionDoneClickListener;
36 | }
37 |
38 | public void setEnableDotInput(boolean enableDotInput) {
39 | this.enableDotInput = enableDotInput;
40 | }
41 |
42 | @Override
43 | public boolean handleSpecialKey(int primaryCode) {
44 | Editable editable = getEditText().getText();
45 | int start = getEditText().getSelectionStart();
46 | //小数点
47 | if(primaryCode == 46) {
48 | if (!enableDotInput) {
49 | return true;
50 | }
51 | if(!editable.toString().contains(".")){
52 | if(!editable.toString().startsWith(".")) {
53 | editable.insert(start, Character.toString((char) primaryCode));
54 | }else {
55 | editable.insert(start, "0"+Character.toString((char) primaryCode));
56 | }
57 | }
58 | return true;
59 | }
60 | if(primaryCode == getKeyCode(R.integer.action_done)) {
61 | if(mActionDoneClickListener != null) {
62 | mActionDoneClickListener.onActionDone(editable);
63 | }else {
64 | hideKeyboard();
65 | }
66 | return true;
67 | }
68 | return false;
69 | }
70 |
71 | public interface ActionDoneClickListener {
72 | void onActionDone(CharSequence charSequence);
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/java/keyboard/xud/com/keyboardtest/MainActivity.java:
--------------------------------------------------------------------------------
1 | package keyboard.xud.com.keyboardtest;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.graphics.drawable.Drawable;
6 | import android.inputmethodservice.Keyboard;
7 | import android.support.v4.content.ContextCompat;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.os.Bundle;
10 | import android.text.InputType;
11 | import android.text.TextUtils;
12 | import android.util.TypedValue;
13 | import android.widget.EditText;
14 | import android.widget.Toast;
15 |
16 | import cn.baymax.android.keyboard.ABCKeyboard;
17 | import cn.baymax.android.keyboard.BaseKeyboard;
18 | import cn.baymax.android.keyboard.KeyboardManager;
19 | import cn.baymax.android.keyboard.NumberKeyboard;
20 |
21 | public class MainActivity extends AppCompatActivity {
22 |
23 | EditText editText1;
24 | EditText editText2;
25 |
26 | private Context context;
27 | private KeyboardManager keyboardManagerNumber;
28 | private NumberKeyboard numberKeyboard;
29 |
30 | private KeyboardManager keyboardManagerAbc;
31 | private ABCKeyboard abcKeyboard;
32 |
33 | @Override
34 | protected void onCreate(Bundle savedInstanceState) {
35 | super.onCreate(savedInstanceState);
36 | setContentView(R.layout.activity_main);
37 | context = this;
38 | editText1 = (EditText) findViewById(R.id.edit1);
39 | editText2 = (EditText) findViewById(R.id.edit2);
40 | editText1.setInputType(InputType.TYPE_CLASS_TEXT);
41 | editText2.setInputType(InputType.TYPE_CLASS_NUMBER|InputType.TYPE_NUMBER_FLAG_DECIMAL);
42 |
43 | keyboardManagerNumber = new KeyboardManager(this);
44 | initNumberKeyboard();
45 | keyboardManagerNumber.bindToEditor(editText2, numberKeyboard);
46 |
47 | keyboardManagerAbc = new KeyboardManager(this);
48 | keyboardManagerAbc.bindToEditor(editText1, new ABCKeyboard(context, ABCKeyboard.DEFAULT_ABC_XML_LAYOUT));
49 | }
50 |
51 | private void initNumberKeyboard() {
52 | numberKeyboard = new NumberKeyboard(context,NumberKeyboard.DEFAULT_NUMBER_XML_LAYOUT);
53 | numberKeyboard.setEnableDotInput(true);
54 | numberKeyboard.setActionDoneClickListener(new NumberKeyboard.ActionDoneClickListener() {
55 | @Override
56 | public void onActionDone(CharSequence charSequence) {
57 | if(TextUtils.isEmpty(charSequence) || charSequence.toString().equals("0") || charSequence.toString().equals("0.0")) {
58 | Toast.makeText(context, "请输入内容", Toast.LENGTH_SHORT).show();
59 | }else {
60 | onNumberkeyActionDone();
61 | }
62 | }
63 | });
64 |
65 | numberKeyboard.setKeyStyle(new BaseKeyboard.KeyStyle() {
66 | @Override
67 | public Drawable getKeyBackound(Keyboard.Key key) {
68 | if(key.iconPreview != null) {
69 | return key.iconPreview;
70 | } else {
71 | return ContextCompat.getDrawable(context,R.drawable.key_number_bg);
72 | }
73 | }
74 |
75 | @Override
76 | public Float getKeyTextSize(Keyboard.Key key) {
77 | if(key.codes[0] == context.getResources().getInteger(R.integer.action_done)) {
78 | return convertSpToPixels(context, 20f);
79 | }
80 | return convertSpToPixels(context, 24f);
81 | }
82 |
83 | @Override
84 | public Integer getKeyTextColor(Keyboard.Key key) {
85 | if(key.codes[0] == context.getResources().getInteger(R.integer.action_done)) {
86 | return Color.WHITE;
87 | }
88 | return null;
89 | }
90 |
91 | @Override
92 | public CharSequence getKeyLabel(Keyboard.Key key) {
93 | return null;
94 | }
95 | });
96 | }
97 |
98 | public float convertSpToPixels(Context context, float sp) {
99 | float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, context.getResources().getDisplayMetrics());
100 | return px;
101 | }
102 |
103 | public void onNumberkeyActionDone() {
104 | editText1.requestFocus();
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/djkeyboard/src/main/java/cn/baymax/android/keyboard/ReflectionUtils.java:
--------------------------------------------------------------------------------
1 | package cn.baymax.android.keyboard;
2 |
3 | import android.text.TextUtils;
4 | import android.util.Log;
5 |
6 | import java.lang.reflect.Field;
7 | import java.lang.reflect.InvocationTargetException;
8 | import java.lang.reflect.Method;
9 |
10 | /**
11 | * Created by zhaopan on 2016/11/7.
12 | * e-mail: kangqiao610@gmail.com
13 | */
14 | public class ReflectionUtils {
15 |
16 | /**
17 | * 循环向上转型, 获取对象的 DeclaredMethod
18 | *
19 | * @param object : 子类对象
20 | * @param methodName : 父类中的方法名
21 | * @param parameterTypes : 父类中的方法参数类型
22 | * @return 父类中的方法对象
23 | */
24 |
25 | public static Method getDeclaredMethod(Object object, String methodName, Class>... parameterTypes) {
26 | Method method = null;
27 |
28 | for (Class> clazz = object.getClass(); clazz != Object.class; clazz = clazz.getSuperclass()) {
29 | try {
30 | method = clazz.getDeclaredMethod(methodName, parameterTypes);
31 | return method;
32 | } catch (Exception e) {
33 | //这里甚么都不要做!并且这里的异常必须这样写,不能抛出去。
34 | //如果这里的异常打印或者往外抛,则就不会执行clazz = clazz.getSuperclass(),最后就不会进入到父类中了
35 |
36 | }
37 | }
38 |
39 | return null;
40 | }
41 |
42 | /**
43 | * 直接调用对象方法, 而忽略修饰符(private, protected, default)
44 | *
45 | * @param object : 子类对象
46 | * @param methodName : 父类中的方法名
47 | * @param parameterTypes : 父类中的方法参数类型
48 | * @param parameters : 父类中的方法参数
49 | * @return 父类中方法的执行结果
50 | */
51 |
52 | public static Object invokeMethod(Object object, String methodName, Class>[] parameterTypes,
53 | Object[] parameters) {
54 | //根据 对象、方法名和对应的方法参数 通过反射 调用上面的方法获取 Method 对象
55 | Method method = getDeclaredMethod(object, methodName, parameterTypes);
56 |
57 | //抑制Java对方法进行检查,主要是针对私有方法而言
58 | method.setAccessible(true);
59 |
60 | try {
61 | if (null != method) {
62 |
63 | //调用object 的 method 所代表的方法,其方法的参数是 parameters
64 | return method.invoke(object, parameters);
65 | }
66 | } catch (IllegalArgumentException e) {
67 | e.printStackTrace();
68 | } catch (IllegalAccessException e) {
69 | e.printStackTrace();
70 | } catch (InvocationTargetException e) {
71 | e.printStackTrace();
72 | }
73 |
74 | return null;
75 | }
76 |
77 | /**
78 | * 循环向上转型, 获取对象的 DeclaredField
79 | *
80 | * @param object : 子类对象
81 | * @param fieldName : 父类中的属性名
82 | * @return 父类中的属性对象
83 | */
84 |
85 | public static Field getDeclaredField(Object object, String fieldName) {
86 | Field field = null;
87 |
88 | Class> clazz = object.getClass();
89 |
90 | for (; clazz != Object.class; clazz = clazz.getSuperclass()) {
91 | try {
92 | field = clazz.getDeclaredField(fieldName);
93 | return field;
94 | } catch (Exception e) {
95 | //这里甚么都不要做!并且这里的异常必须这样写,不能抛出去。
96 | //如果这里的异常打印或者往外抛,则就不会执行clazz = clazz.getSuperclass(),最后就不会进入到父类中了
97 |
98 | }
99 | }
100 |
101 | return null;
102 | }
103 |
104 | public static Object getFieldValue(Object obj, String fieldName) {
105 | if (obj == null || TextUtils.isEmpty(fieldName)) {
106 | return null;
107 | }
108 |
109 | Class> clazz = obj.getClass();
110 | while (clazz != Object.class) {
111 | try {
112 | Field field = clazz.getDeclaredField(fieldName);
113 | field.setAccessible(true);
114 | return field.get(obj);
115 | } catch (Exception e) {
116 | }
117 | clazz = clazz.getSuperclass();
118 | }
119 | Log.e("reflect", "get field " + fieldName + " not found in " + obj.getClass().getName());
120 | return null;
121 | }
122 |
123 | public static void setFieldValue(Object obj, String fieldName, Object value) {
124 | if (obj == null || TextUtils.isEmpty(fieldName)) {
125 | return;
126 | }
127 | Class> clazz = obj.getClass();
128 | while (clazz != Object.class) {
129 | try {
130 | Field field = clazz.getDeclaredField(fieldName);
131 | field.setAccessible(true);
132 | field.set(obj, value);
133 | return;
134 | } catch (Exception e) {
135 | }
136 | clazz = clazz.getSuperclass();
137 | }
138 | Log.e("reflect", "set field " + fieldName + " not found in " + obj.getClass().getName());
139 | }
140 | }
141 |
142 |
--------------------------------------------------------------------------------
/djkeyboard/src/main/java/cn/baymax/android/keyboard/SearchResultLinearLayoutManager.java:
--------------------------------------------------------------------------------
1 | package cn.baymax.android.keyboard;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.LinearLayoutManager;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.util.AttributeSet;
7 | import android.util.Log;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 |
11 | /**
12 | * Created by xud on 2017/3/9.
13 | */
14 |
15 | public class SearchResultLinearLayoutManager extends LinearLayoutManager {
16 |
17 | private static final String TAG = "srll";
18 |
19 | private Context mContext;
20 |
21 | private int maxVisibleItem = 3;
22 |
23 | private final int[] mMeasuredDimension = new int[2];
24 |
25 | public SearchResultLinearLayoutManager(Context context) {
26 | this(context,3);
27 | }
28 |
29 | public SearchResultLinearLayoutManager(Context context, int maxVisibleItem) {
30 | super(context);
31 | init(context,maxVisibleItem);
32 | }
33 |
34 | public SearchResultLinearLayoutManager(Context context, int orientation, boolean reverseLayout, int maxVisibleItem) {
35 | super(context, orientation, reverseLayout);
36 | init(context,maxVisibleItem);
37 | }
38 |
39 | public SearchResultLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes, int maxVisibleItem) {
40 | super(context, attrs, defStyleAttr, defStyleRes);
41 | init(context,maxVisibleItem);
42 | }
43 |
44 | private void init(Context context,int maxVisibleItem) {
45 | mContext = context;
46 | this.maxVisibleItem = Math.max(maxVisibleItem,0);
47 | }
48 |
49 | @Override
50 | public void onMeasure(final RecyclerView.Recycler recycler, final RecyclerView.State state,
51 | final int widthSpec, final int heightSpec) {
52 |
53 | final int widthMode = View.MeasureSpec.getMode(widthSpec);
54 | final int heightMode = View.MeasureSpec.getMode(heightSpec);
55 | final int widthSize = View.MeasureSpec.getSize(widthSpec);
56 | final int heightSize = View.MeasureSpec.getSize(heightSpec);
57 |
58 | int width = 0;
59 | int height = 0;
60 | int itemCount = Math.min(getItemCount(),maxVisibleItem);
61 | for (int i = 0; i < itemCount; i++) {
62 | measureScrapChild(recycler, View.MeasureSpec.makeMeasureSpec(i, View.MeasureSpec.
63 | UNSPECIFIED),
64 | View.MeasureSpec.makeMeasureSpec(i, View.MeasureSpec.UNSPECIFIED),
65 | mMeasuredDimension);
66 |
67 |
68 | if (getOrientation() == HORIZONTAL) {
69 | width = width + mMeasuredDimension[0];
70 | if (i == 0) {
71 | height = mMeasuredDimension[1];
72 | }
73 | } else {
74 | height = height + mMeasuredDimension[1];
75 | if (i == 0) {
76 | width = mMeasuredDimension[0];
77 | }
78 | }
79 | }
80 | switch (widthMode) {
81 | case View.MeasureSpec.EXACTLY:
82 | width = widthSize;
83 | case View.MeasureSpec.AT_MOST:
84 | case View.MeasureSpec.UNSPECIFIED:
85 | }
86 |
87 | switch (heightMode) {
88 | case View.MeasureSpec.EXACTLY:
89 | height = heightSize;
90 | case View.MeasureSpec.AT_MOST:
91 | case View.MeasureSpec.UNSPECIFIED:
92 | }
93 |
94 | setMeasuredDimension(width, height);
95 | }
96 |
97 | private void measureScrapChild(final RecyclerView.Recycler recycler, final int widthSpec,
98 | final int heightSpec, final int[] measuredDimension) {
99 | try {
100 | View view = recycler.getViewForPosition(0);
101 |
102 | if (view != null) {
103 | RecyclerView.LayoutParams p = (RecyclerView.LayoutParams) view.getLayoutParams();
104 |
105 | int childWidthSpec = ViewGroup.getChildMeasureSpec(widthSpec,
106 | getPaddingLeft() + getPaddingRight(), p.width);
107 |
108 | int childHeightSpec = ViewGroup.getChildMeasureSpec(heightSpec,
109 | getPaddingTop() + getPaddingBottom(), p.height);
110 |
111 | view.measure(childWidthSpec, childHeightSpec);
112 | measuredDimension[0] = view.getMeasuredWidth() + p.leftMargin + p.rightMargin;
113 | measuredDimension[1] = view.getMeasuredHeight() + p.bottomMargin + p.topMargin;
114 | recycler.recycleView(view);
115 | }
116 | } catch (Exception e) {
117 | Log.e(TAG, e.getMessage());
118 | }
119 | }
120 |
121 | /**
122 | * Disable scrolling.
123 | */
124 | @Override
125 | public boolean canScrollVertically() {
126 | return true;
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/djkeyboard/src/main/java/cn/baymax/android/keyboard/KeyboardWithSearchView.java:
--------------------------------------------------------------------------------
1 | package cn.baymax.android.keyboard;
2 |
3 | import android.annotation.TargetApi;
4 | import android.content.Context;
5 | import android.os.Build;
6 | import android.support.annotation.Nullable;
7 | import android.support.v7.widget.LinearLayoutCompat;
8 | import android.support.v7.widget.LinearLayoutManager;
9 | import android.support.v7.widget.RecyclerView;
10 | import android.support.v7.widget.ViewUtils;
11 | import android.util.AttributeSet;
12 | import android.view.LayoutInflater;
13 | import android.view.View;
14 | import android.view.ViewGroup;
15 | import android.widget.EditText;
16 | import android.widget.LinearLayout;
17 |
18 | import java.util.List;
19 |
20 | /**
21 | * Created by xud on 2017/3/9.
22 | */
23 |
24 | public class KeyboardWithSearchView extends LinearLayout {
25 |
26 | private static final int MAX_VISIBLE_SIZE = 3;
27 |
28 | private Context mContext;
29 |
30 | private RecyclerView mRecyclerView;
31 |
32 | private BaseKeyboardView mBaseKeyboardView;
33 |
34 | private LinearLayout mKeyboadViewContainer;
35 |
36 | //private OnSizeChangedListener mOnSizeChangedListener;
37 |
38 | private EditText mEditText;
39 |
40 | public KeyboardWithSearchView(Context context) {
41 | super(context);
42 | init(context);
43 | }
44 |
45 | public KeyboardWithSearchView(Context context, @Nullable AttributeSet attrs) {
46 | super(context, attrs);
47 | init(context);
48 | }
49 |
50 | public KeyboardWithSearchView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
51 | super(context, attrs, defStyleAttr);
52 | init(context);
53 | }
54 |
55 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
56 | public KeyboardWithSearchView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
57 | super(context, attrs, defStyleAttr, defStyleRes);
58 | init(context);
59 | }
60 |
61 | protected RecyclerView getRecyclerView() {
62 | return mRecyclerView;
63 | }
64 |
65 | protected BaseKeyboardView getBaseKeyboardView() {
66 | return mBaseKeyboardView;
67 | }
68 |
69 | protected EditText getEditText() {
70 | return mEditText;
71 | }
72 |
73 | // public void setOnSizeChangedListener(OnSizeChangedListener onSizeChangedListener) {
74 | // mOnSizeChangedListener = onSizeChangedListener;
75 | // }
76 |
77 | protected LinearLayout getKeyboadViewContainer() {
78 | return mKeyboadViewContainer;
79 | }
80 |
81 |
82 |
83 | private void init(Context context) {
84 | mContext = context;
85 | View view = LayoutInflater.from(context).inflate(R.layout.layout_recycler_keyboard_view,this,true);
86 | mEditText = (EditText) view.findViewById(R.id.hide_edittext);
87 | mRecyclerView = (RecyclerView) view.findViewById(R.id.search_recycler_view);
88 | mBaseKeyboardView = (BaseKeyboardView) view.findViewById(R.id.keyboard_view);
89 | mKeyboadViewContainer = (LinearLayout) view.findViewById(R.id.keyboard_container);
90 | }
91 |
92 | protected void initRecyclerView(KeyboardSearchBaseAdapter adapter, RecyclerView.LayoutManager manager, RecyclerView.ItemDecoration itemDecoration) {
93 | mRecyclerView.setAdapter(adapter);
94 | mRecyclerView.setLayoutManager(manager);
95 | mRecyclerView.addItemDecoration(itemDecoration);
96 | }
97 |
98 | protected void setSearchResult(List list,boolean hasFixedSize) {
99 | if(mRecyclerView.getAdapter() == null) {
100 | throw new RuntimeException("this view has not invoked init method");
101 | }
102 | mRecyclerView.getLayoutManager().scrollToPosition(0);
103 | if(list == null || list.size() ==0) {
104 | mRecyclerView.setVisibility(GONE);
105 | } else {
106 | int height = Utils.dipToPx(mContext,Math.min(3,list.size()) * 49) +
107 | Math.min(3,list.size());
108 | ViewGroup.LayoutParams params = mRecyclerView.getLayoutParams();
109 | if(params != null) {
110 | params.height = height;
111 | }else {
112 | LinearLayout.LayoutParams newParams =
113 | new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
114 | height);
115 | mRecyclerView.setLayoutParams(newParams);
116 | }
117 | mRecyclerView.setVisibility(VISIBLE);
118 | }
119 | mRecyclerView.setHasFixedSize(hasFixedSize);
120 |
121 | KeyboardSearchBaseAdapter adapter = (KeyboardSearchBaseAdapter) mRecyclerView.getAdapter();
122 | adapter.setAdapterData(list);
123 | adapter.notifyDataSetChanged();
124 | }
125 |
126 | // @Override
127 | // protected void onSizeChanged(int w, int h, int oldw, int oldh) {
128 | // super.onSizeChanged(w, h, oldw, oldh);
129 | // if(mOnSizeChangedListener != null) {
130 | // mOnSizeChangedListener.sizeChanged(w,h,oldw,oldh);
131 | // }
132 | // }
133 | //
134 | // protected interface OnSizeChangedListener {
135 | // void sizeChanged(int w, int h, int oldw, int oldh);
136 | // }
137 | }
138 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/djkeyboard/src/main/java/cn/baymax/android/keyboard/BaseKeyboard.java:
--------------------------------------------------------------------------------
1 | package cn.baymax.android.keyboard;
2 |
3 | import android.content.Context;
4 | import android.graphics.drawable.Drawable;
5 | import android.inputmethodservice.Keyboard;
6 | import android.inputmethodservice.KeyboardView;
7 | import android.support.annotation.IntegerRes;
8 | import android.text.Editable;
9 | import android.text.TextUtils;
10 | import android.util.TypedValue;
11 | import android.view.View;
12 | import android.widget.EditText;
13 |
14 | /**
15 | * Created by xud on 2017/3/2.
16 | */
17 |
18 | public abstract class BaseKeyboard extends Keyboard implements KeyboardView.OnKeyboardActionListener{
19 |
20 | private EditText mEditText;
21 |
22 | private View mNextFocusView;
23 |
24 | private KeyStyle mKeyStyle;
25 |
26 | protected Context mContext;
27 |
28 | public BaseKeyboard(Context context, int xmlLayoutResId) {
29 | super(context, xmlLayoutResId);
30 | mContext = context;
31 | }
32 |
33 | public BaseKeyboard(Context context, int xmlLayoutResId, int modeId, int width, int height) {
34 | super(context, xmlLayoutResId, modeId, width, height);
35 | mContext = context;
36 | }
37 |
38 | public BaseKeyboard(Context context, int xmlLayoutResId, int modeId) {
39 | super(context, xmlLayoutResId, modeId);
40 | mContext = context;
41 | }
42 |
43 | public BaseKeyboard(Context context, int layoutTemplateResId, CharSequence characters, int columns, int horizontalPadding) {
44 | super(context, layoutTemplateResId, characters, columns, horizontalPadding);
45 | mContext = context;
46 | }
47 |
48 | public void setEditText(EditText editText) {
49 | mEditText = editText;
50 | }
51 |
52 | public void setNextFocusView(View nextFocusView) {
53 | mNextFocusView = nextFocusView;
54 | }
55 |
56 | public void setKeyStyle(KeyStyle keyStyle) {
57 | mKeyStyle = keyStyle;
58 | }
59 |
60 | public EditText getEditText() {
61 | return mEditText;
62 | }
63 |
64 | public View getNextFocusView() {
65 | return mNextFocusView;
66 | }
67 |
68 | public KeyStyle getKeyStyle() {
69 | return mKeyStyle;
70 | }
71 |
72 | public int getKeyCode(@IntegerRes int redId) {
73 | return mContext.getResources().getInteger(redId);
74 | }
75 |
76 | @Override
77 | public void onPress(int primaryCode) {
78 |
79 | }
80 |
81 | @Override
82 | public void onRelease(int primaryCode) {
83 |
84 | }
85 |
86 | @Override
87 | public void onKey(int primaryCode, int[] keyCodes) {
88 | if(null != mEditText && mEditText.hasFocus() && !handleSpecialKey(primaryCode)) {
89 | Editable editable = mEditText.getText();
90 | int start = mEditText.getSelectionStart();
91 | int end = mEditText.getSelectionEnd();
92 | if (end > start){
93 | editable.delete(start,end);
94 | }
95 | if(primaryCode == KEYCODE_DELETE) {
96 | if(!TextUtils.isEmpty(editable)) {
97 | if(start > 0) {
98 | editable.delete(start-1,start);
99 | }
100 | }
101 | }else if(primaryCode == getKeyCode(R.integer.hide_keyboard)){
102 | hideKeyboard();
103 | }else {
104 | editable.insert(start,Character.toString((char) primaryCode));
105 | }
106 | }
107 | }
108 |
109 | @Override
110 | public void onText(CharSequence text) {
111 |
112 | }
113 |
114 | @Override
115 | public void swipeLeft() {
116 |
117 | }
118 |
119 | @Override
120 | public void swipeRight() {
121 |
122 | }
123 |
124 | @Override
125 | public void swipeDown() {
126 |
127 | }
128 |
129 | @Override
130 | public void swipeUp() {
131 |
132 | }
133 |
134 | public void hideKeyboard() {
135 | if(mNextFocusView != null) {
136 | mNextFocusView.requestFocus();
137 | }
138 | }
139 |
140 | /**
141 | *
142 | * @param primaryCode
143 | * @return true if handle the key
144 | * false no handle and dispatch
145 | */
146 | public abstract boolean handleSpecialKey(int primaryCode);
147 |
148 | public interface KeyStyle {
149 |
150 | public Drawable getKeyBackound(Key key);
151 |
152 | public Float getKeyTextSize(Key key);
153 |
154 | public Integer getKeyTextColor(Key key);
155 |
156 | public CharSequence getKeyLabel(Key key);
157 | }
158 |
159 | public Padding getPadding() {
160 | return new Padding(0,0,0,0);
161 | }
162 |
163 | public static class DefaultKeyStyle implements KeyStyle {
164 |
165 | @Override
166 | public Drawable getKeyBackound(Key key) {
167 | return key.iconPreview;
168 | }
169 |
170 | @Override
171 | public Float getKeyTextSize(Key key) {
172 | return null;
173 | }
174 |
175 | @Override
176 | public Integer getKeyTextColor(Key key) {
177 | return null;
178 | }
179 |
180 | @Override
181 | public CharSequence getKeyLabel(Key key) {
182 | return key.label;
183 | }
184 | }
185 |
186 | public static class Padding {
187 | int top;
188 | int left;
189 | int bottom;
190 | int right;
191 |
192 | /**
193 | * px
194 | * @param top
195 | * @param left
196 | * @param bottom
197 | * @param right
198 | */
199 | public Padding(int top, int left, int bottom, int right) {
200 | this.top = top;
201 | this.left = left;
202 | this.bottom = bottom;
203 | this.right = right;
204 | }
205 | }
206 |
207 | public float convertSpToPixels(Context context, float sp) {
208 | float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, context.getResources().getDisplayMetrics());
209 | return px;
210 | }
211 | }
212 |
--------------------------------------------------------------------------------
/djkeyboard/src/main/java/cn/baymax/android/keyboard/BaseKeyboardView.java:
--------------------------------------------------------------------------------
1 | package cn.baymax.android.keyboard;
2 |
3 | import android.annotation.TargetApi;
4 | import android.content.Context;
5 | import android.graphics.Canvas;
6 | import android.graphics.Paint;
7 | import android.graphics.Rect;
8 | import android.graphics.Typeface;
9 | import android.graphics.drawable.Drawable;
10 | import android.inputmethodservice.Keyboard;
11 | import android.inputmethodservice.KeyboardView;
12 | import android.os.Build;
13 | import android.util.AttributeSet;
14 | import android.util.Log;
15 | import android.widget.EditText;
16 |
17 | import java.util.List;
18 |
19 | /**
20 | * Created by xud on 2017/3/2.
21 | */
22 |
23 | public class BaseKeyboardView extends KeyboardView{
24 |
25 | private static final String TAG = "BaseKeyboardView";
26 | private Drawable rKeyBackground;
27 | private int rLabelTextSize;
28 | private int rKeyTextSize;
29 | private int rKeyTextColor;
30 | private float rShadowRadius;
31 | private int rShadowColor;
32 |
33 | private Rect rClipRegion;
34 | private Keyboard.Key rInvalidatedKey;
35 |
36 | public BaseKeyboardView(Context context, AttributeSet attrs) {
37 | super(context, attrs);
38 | init(context, attrs, 0, 0);
39 | }
40 |
41 | public BaseKeyboardView(Context context, AttributeSet attrs, int defStyleAttr) {
42 | super(context, attrs, defStyleAttr);
43 | init(context, attrs, defStyleAttr, 0);
44 | }
45 |
46 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
47 | public BaseKeyboardView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
48 | super(context, attrs, defStyleAttr, defStyleRes);
49 | init(context, attrs, defStyleAttr, defStyleRes);
50 | }
51 |
52 | private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
53 | rKeyBackground = (Drawable) ReflectionUtils.getFieldValue(this, "mKeyBackground");
54 | rLabelTextSize = (int) ReflectionUtils.getFieldValue(this, "mLabelTextSize");
55 | rKeyTextSize = (int) ReflectionUtils.getFieldValue(this, "mKeyTextSize");
56 | rKeyTextColor = (int) ReflectionUtils.getFieldValue(this, "mKeyTextColor");
57 | rShadowColor = (int) ReflectionUtils.getFieldValue(this, "mShadowColor");
58 | rShadowRadius = (float) ReflectionUtils.getFieldValue(this, "mShadowRadius");
59 | }
60 |
61 | @Override
62 | public void onDraw(Canvas canvas) {
63 | //说明CustomKeyboardView只针对CustomBaseKeyboard键盘进行重绘,
64 | // 且CustomBaseKeyboard必需有设置CustomKeyStyle的回调接口实现, 才进行重绘, 这才有意义
65 | if (null == getKeyboard() || !(getKeyboard() instanceof BaseKeyboard) || null == ((BaseKeyboard) getKeyboard()).getKeyStyle()) {
66 | Log.e(TAG, "");
67 | super.onDraw(canvas);
68 | return;
69 | }
70 | rClipRegion = (Rect) ReflectionUtils.getFieldValue(this, "mClipRegion");
71 | rInvalidatedKey = (Keyboard.Key) ReflectionUtils.getFieldValue(this, "mInvalidatedKey");
72 | super.onDraw(canvas);
73 | onRefreshKey(canvas);
74 | }
75 |
76 | /**
77 | * onRefreshKey是对父类的private void onBufferDraw()进行的重写. 只是在对key的绘制过程中进行了重新设置.
78 | *
79 | * @param canvas
80 | */
81 | private void onRefreshKey(Canvas canvas) {
82 | final Paint paint = (Paint) ReflectionUtils.getFieldValue(this, "mPaint");
83 | final Rect padding = (Rect) ReflectionUtils.getFieldValue(this, "mPadding");
84 |
85 | paint.setColor(rKeyTextColor);
86 | final int kbdPaddingLeft = getPaddingLeft();
87 | final int kbdPaddingTop = getPaddingTop();
88 | Drawable keyBackground = null;
89 |
90 | final Rect clipRegion = rClipRegion;
91 | final Keyboard.Key invalidKey = rInvalidatedKey;
92 | boolean drawSingleKey = false;
93 | if (invalidKey != null && canvas.getClipBounds(clipRegion)) {
94 | // Is clipRegion completely contained within the invalidated key?
95 | if (invalidKey.x + kbdPaddingLeft - 1 <= clipRegion.left &&
96 | invalidKey.y + kbdPaddingTop - 1 <= clipRegion.top &&
97 | invalidKey.x + invalidKey.width + kbdPaddingLeft + 1 >= clipRegion.right &&
98 | invalidKey.y + invalidKey.height + kbdPaddingTop + 1 >= clipRegion.bottom) {
99 | drawSingleKey = true;
100 | }
101 | }
102 |
103 | //拿到当前键盘被弹起的输入源 和 键盘为每个key的定制实现customKeyStyle
104 | EditText etCur = ((BaseKeyboard) getKeyboard()).getEditText();
105 | BaseKeyboard.KeyStyle customKeyStyle = ((BaseKeyboard) getKeyboard()).getKeyStyle();
106 |
107 | List keys = getKeyboard().getKeys();
108 | final int keyCount = keys.size();
109 | //canvas.drawColor(0x00000000, PorterDuff.Mode.CLEAR);
110 | for (int i = 0; i < keyCount; i++) {
111 | final Keyboard.Key key = keys.get(i);
112 | if (drawSingleKey && invalidKey != key) {
113 | continue;
114 | }
115 |
116 | //获取为Key自定义的背景, 若没有定制, 使用KeyboardView的默认属性keyBackground设置
117 | keyBackground = customKeyStyle.getKeyBackound(key);
118 | if (null == keyBackground) {
119 | keyBackground = rKeyBackground;
120 | }
121 |
122 | int[] drawableState = key.getCurrentDrawableState();
123 | keyBackground.setState(drawableState);
124 |
125 | //获取为Key自定义的Label, 若没有定制, 使用xml布局中指定的
126 | CharSequence keyLabel = customKeyStyle.getKeyLabel(key);
127 | if (null == keyLabel) {
128 | keyLabel = key.label;
129 | }
130 | // Switch the character to uppercase if shift is pressed
131 | String label = keyLabel == null ? null : adjustCase(keyLabel).toString();
132 |
133 | final Rect bounds = keyBackground.getBounds();
134 | if (key.width != bounds.right ||
135 | key.height != bounds.bottom) {
136 | keyBackground.setBounds(0, 0, key.width, key.height);
137 | }
138 | canvas.translate(key.x + kbdPaddingLeft, key.y + kbdPaddingTop);
139 | keyBackground.draw(canvas);
140 |
141 | if (label != null) {
142 | //获取为Key的Label的字体大小, 若没有定制, 使用KeyboardView的默认属性keyTextSize设置
143 | Float customKeyTextSize = customKeyStyle.getKeyTextSize(key);
144 | // For characters, use large font. For labels like "Done", use small font.
145 | if (null != customKeyTextSize) {
146 | paint.setTextSize(customKeyTextSize);
147 | paint.setTypeface(Typeface.DEFAULT);
148 | //paint.setTypeface(Typeface.DEFAULT_BOLD);
149 | } else {
150 | if (label.length() > 1 && key.codes.length < 2) {
151 | paint.setTextSize(rLabelTextSize);
152 | paint.setTypeface(Typeface.DEFAULT);
153 | //paint.setTypeface(Typeface.DEFAULT_BOLD);
154 | } else {
155 | paint.setTextSize(rKeyTextSize);
156 | paint.setTypeface(Typeface.DEFAULT);
157 | //paint.setTypeface(Typeface.DEFAULT);
158 | }
159 | }
160 |
161 | //获取为Key的Label的字体颜色, 若没有定制, 使用KeyboardView的默认属性keyTextColor设置
162 | Integer customKeyTextColor = customKeyStyle.getKeyTextColor(key);
163 | if (null != customKeyTextColor) {
164 | paint.setColor(customKeyTextColor);
165 | } else {
166 | paint.setColor(rKeyTextColor);
167 | }
168 | // Draw a drop shadow for the text
169 | paint.setShadowLayer(rShadowRadius, 0, 0, rShadowColor);
170 | // Draw the text
171 | canvas.drawText(label,
172 | (key.width - padding.left - padding.right) / 2
173 | + padding.left,
174 | (key.height - padding.top - padding.bottom) / 2
175 | + (paint.getTextSize() - paint.descent()) / 2 + padding.top,
176 | paint);
177 | // Turn off drop shadow
178 | paint.setShadowLayer(0, 0, 0, 0);
179 | } else if (key.icon != null) {
180 | final int drawableX = (key.width - padding.left - padding.right
181 | - key.icon.getIntrinsicWidth()) / 2 + padding.left;
182 | final int drawableY = (key.height - padding.top - padding.bottom
183 | - key.icon.getIntrinsicHeight()) / 2 + padding.top;
184 | canvas.translate(drawableX, drawableY);
185 | key.icon.setBounds(0, 0,
186 | key.icon.getIntrinsicWidth(), key.icon.getIntrinsicHeight());
187 | key.icon.draw(canvas);
188 | canvas.translate(-drawableX, -drawableY);
189 | }
190 | canvas.translate(-key.x - kbdPaddingLeft, -key.y - kbdPaddingTop);
191 | }
192 | rInvalidatedKey = null;
193 | }
194 |
195 | private CharSequence adjustCase(CharSequence label) {
196 | if (getKeyboard().isShifted() && label != null && label.length() < 3
197 | && Character.isLowerCase(label.charAt(0))) {
198 | label = label.toString().toUpperCase();
199 | }
200 | return label;
201 | }
202 | }
203 |
--------------------------------------------------------------------------------
/djkeyboard/src/main/java/cn/baymax/android/keyboard/KeyboardManager.java:
--------------------------------------------------------------------------------
1 | package cn.baymax.android.keyboard;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.graphics.Rect;
6 | import android.inputmethodservice.KeyboardView;
7 | import android.os.Build;
8 | import android.support.v7.widget.RecyclerView;
9 | import android.text.InputType;
10 | import android.util.Log;
11 | import android.view.Gravity;
12 | import android.view.LayoutInflater;
13 | import android.view.View;
14 | import android.view.ViewGroup;
15 | import android.view.ViewTreeObserver;
16 | import android.view.animation.AnimationUtils;
17 | import android.widget.EditText;
18 | import android.widget.FrameLayout;
19 |
20 | import java.lang.reflect.Method;
21 | import java.util.List;
22 |
23 | /**
24 | * Created by xud on 2017/3/2.
25 | */
26 |
27 | public class KeyboardManager {
28 |
29 | protected static final String TAG = "KeyboardManager";
30 |
31 | protected Context mContext;
32 |
33 | protected ViewGroup mRootView;
34 |
35 | protected KeyboardWithSearchView mKeyboardWithSearchView;
36 |
37 | protected FrameLayout.LayoutParams mKeyboardContainerLayoutParams;
38 |
39 | protected BaseKeyboard.DefaultKeyStyle mDefaultKeyStyle = new BaseKeyboard.DefaultKeyStyle();
40 |
41 | public KeyboardManager(Context context) {
42 | mContext = context;
43 | if (mContext instanceof Activity) {
44 | mRootView = (ViewGroup) ((Activity) context).getWindow().getDecorView().findViewById(android.R.id.content);
45 | mKeyboardWithSearchView = (KeyboardWithSearchView) LayoutInflater.from(mContext).inflate(R.layout
46 | .layout_keyboard_view, null);
47 | hideSystemSoftKeyboard(mKeyboardWithSearchView.getEditText());
48 | mKeyboardContainerLayoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup
49 | .LayoutParams.WRAP_CONTENT);
50 | mKeyboardContainerLayoutParams.gravity = Gravity.BOTTOM;
51 | } else {
52 | Log.e(TAG, "context must be activity");
53 | }
54 | }
55 |
56 | public void initRecyclerView(KeyboardSearchBaseAdapter adapter, RecyclerView.LayoutManager manager, RecyclerView
57 | .ItemDecoration itemDecoration) {
58 | mKeyboardWithSearchView.initRecyclerView(adapter, manager, itemDecoration);
59 | }
60 |
61 | public void setSearchResult(List data,boolean hasFixedSize) {
62 | mKeyboardWithSearchView.setSearchResult(data,hasFixedSize);
63 | }
64 |
65 | public void bindToEditor(EditText editText, BaseKeyboard keyboard) {
66 | hideSystemSoftKeyboard(editText);
67 | editText.setTag(R.id.bind_keyboard_2_editor, keyboard);
68 | if (keyboard.getKeyStyle() == null) {
69 | keyboard.setKeyStyle(mDefaultKeyStyle);
70 | }
71 | editText.setOnFocusChangeListener(editorFocusChangeListener);
72 | }
73 |
74 | private BaseKeyboard getBindKeyboard(EditText editText) {
75 | if (editText != null) {
76 | return (BaseKeyboard) editText.getTag(R.id.bind_keyboard_2_editor);
77 | }
78 | return null;
79 | }
80 |
81 | private void initKeyboard(BaseKeyboard keyboard) {
82 | mKeyboardWithSearchView.getBaseKeyboardView().setKeyboard(keyboard);
83 | mKeyboardWithSearchView.getBaseKeyboardView().setEnabled(true);
84 | mKeyboardWithSearchView.getBaseKeyboardView().setPreviewEnabled(false);
85 | mKeyboardWithSearchView.getBaseKeyboardView().setOnKeyboardActionListener(keyboard);
86 | }
87 |
88 | public void setShowAnchorView(View showAnchorView,EditText editText) {
89 | editText.setTag(R.id.anchor_view,showAnchorView);
90 | }
91 |
92 | public void showSoftKeyboard(EditText editText) {
93 | // mRootView.getViewTreeObserver().addOnGlobalLayoutListener(mOnGlobalLayoutListener);
94 | mRootView.addOnLayoutChangeListener(mOnLayoutChangeListener);
95 | BaseKeyboard keyboard = getBindKeyboard(editText);
96 | if (keyboard == null) {
97 | Log.e(TAG, "edit text not bind to keyboard");
98 | return;
99 | }
100 | keyboard.setEditText(editText);
101 | keyboard.setNextFocusView(mKeyboardWithSearchView.getEditText());
102 | initKeyboard(keyboard);
103 | mKeyboardWithSearchView.getKeyboadViewContainer().setPadding(Utils.dipToPx(mContext, keyboard.getPadding().left),
104 | Utils.dipToPx(mContext, keyboard.getPadding().top),
105 | Utils.dipToPx(mContext, keyboard.getPadding().right),
106 | Utils.dipToPx(mContext, keyboard.getPadding().bottom));
107 | if(mRootView.indexOfChild(mKeyboardWithSearchView) == -1) {
108 | mRootView.addView(mKeyboardWithSearchView, mKeyboardContainerLayoutParams);
109 | }else {
110 | mKeyboardWithSearchView.setVisibility(View.VISIBLE);
111 | }
112 | mKeyboardWithSearchView.setAnimation(AnimationUtils.loadAnimation(mContext, R.anim.down_to_up));
113 | }
114 |
115 | private void hideSoftKeyboard() {
116 | //mRootView.removeView(mKeyboardWithSearchView);
117 | mKeyboardWithSearchView.setVisibility(View.GONE);
118 | mKeyboardWithSearchView.setAnimation(AnimationUtils.loadAnimation(mContext, R.anim.up_to_hide));
119 | //mRootView.removeOnLayoutChangeListener(mOnLayoutChangeListener);
120 | }
121 |
122 | public void hideKeyboard() {
123 | if(mRootView != null) {
124 | mRootView.clearFocus();
125 | }
126 | }
127 |
128 | public static void hideSystemSoftKeyboard(EditText editText) {
129 | int sdkInt = Build.VERSION.SDK_INT;
130 | if (sdkInt >= 11) {
131 | try {
132 | Class cls = EditText.class;
133 | Method setShowSoftInputOnFocus;
134 | setShowSoftInputOnFocus = cls.getMethod("setShowSoftInputOnFocus", boolean.class);
135 | setShowSoftInputOnFocus.setAccessible(true);
136 | setShowSoftInputOnFocus.invoke(editText, false);
137 | } catch (SecurityException e) {
138 | e.printStackTrace();
139 | } catch (NoSuchMethodException e) {
140 | e.printStackTrace();
141 | } catch (Exception e) {
142 | e.printStackTrace();
143 | }
144 | } else {
145 | editText.setInputType(InputType.TYPE_NULL);
146 | }
147 | }
148 |
149 |
150 | private final View.OnFocusChangeListener editorFocusChangeListener = new View.OnFocusChangeListener() {
151 | @Override
152 | public void onFocusChange(final View v, boolean hasFocus) {
153 | if (v instanceof EditText) {
154 | if (hasFocus) {
155 | v.postDelayed(new Runnable() {
156 | @Override
157 | public void run() {
158 | showSoftKeyboard((EditText) v);
159 | }
160 | },300);
161 | } else {
162 | hideSoftKeyboard();
163 | }
164 | }
165 | }
166 | };
167 |
168 | private final ViewTreeObserver.OnGlobalLayoutListener mOnGlobalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
169 | @Override
170 | public void onGlobalLayout() {
171 | int hasMoved = 0;
172 | Object heightTag = mRootView.getTag(R.id.scroll_height_by_keyboard);
173 | if (heightTag != null) {
174 | hasMoved = (int) heightTag;
175 | }
176 | // if(mRootView.indexOfChild(mKeyboardWithSearchView) == -1) {
177 | // mRootView.removeOnLayoutChangeListener(mOnLayoutChangeListener);
178 | // if (hasMoved > 0) {
179 | // mRootView.getChildAt(0).scrollBy(0, -1 * hasMoved);
180 | // mRootView.setTag(R.id.scroll_height_by_keyboard, 0);
181 | // }
182 | // }
183 | if(mKeyboardWithSearchView.getVisibility() == View.GONE) {
184 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
185 | mRootView.getViewTreeObserver().removeOnGlobalLayoutListener(mOnGlobalLayoutListener);
186 | }else {
187 | mRootView.getViewTreeObserver().removeGlobalOnLayoutListener(mOnGlobalLayoutListener);
188 | }
189 | if (hasMoved > 0) {
190 | mRootView.getChildAt(0).scrollBy(0, -1 * hasMoved);
191 | mRootView.setTag(R.id.scroll_height_by_keyboard, 0);
192 | }
193 | } else {
194 | BaseKeyboard keyboard = (BaseKeyboard) mKeyboardWithSearchView.getBaseKeyboardView().getKeyboard();
195 | EditText editText = keyboard.getEditText();
196 |
197 |
198 | Rect rect = new Rect();
199 | mRootView.getWindowVisibleDisplayFrame(rect);
200 |
201 | int[] etLocation = new int[2];
202 | editText.getLocationOnScreen(etLocation);
203 | int keyboardTop = etLocation[1] + editText.getHeight() + editText.getPaddingTop() + editText.getPaddingBottom() + 1 ; //1px is a divider
204 | Object anchor = editText.getTag(R.id.anchor_view);
205 | View mShowAnchorView = null;
206 | if(anchor != null && anchor instanceof View) {
207 | mShowAnchorView = (View) anchor;
208 | }
209 | if (mShowAnchorView != null) {
210 | int[] saLocation = new int[2];
211 | mShowAnchorView.getLocationOnScreen(saLocation);
212 | keyboardTop = saLocation[1] + mShowAnchorView.getHeight() + mShowAnchorView.getPaddingTop() + mShowAnchorView //1px is a divider
213 | .getPaddingBottom() + 1;
214 | }
215 | int moveHeight = keyboardTop + mKeyboardWithSearchView.getHeight() - rect.bottom;
216 | //height > 0 rootview 需要继续上滑
217 | if(moveHeight > 0) {
218 | mRootView.getChildAt(0).scrollBy(0, moveHeight);
219 | mRootView.setTag(R.id.scroll_height_by_keyboard,hasMoved + moveHeight);
220 | }else {
221 | int moveBackHeight = Math.min(hasMoved,Math.abs(moveHeight));
222 | if(moveBackHeight >0) {
223 | mRootView.getChildAt(0).scrollBy(0, -1 * moveBackHeight);
224 | mRootView.setTag(R.id.scroll_height_by_keyboard,hasMoved - moveBackHeight);
225 | }
226 | }
227 |
228 | }
229 | }
230 | };
231 |
232 | private final View.OnLayoutChangeListener mOnLayoutChangeListener = new View.OnLayoutChangeListener() {
233 | @Override
234 | public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int
235 | oldRight, int oldBottom) {
236 | int hasMoved = 0;
237 | Object heightTag = mRootView.getTag(R.id.scroll_height_by_keyboard);
238 | if (heightTag != null) {
239 | hasMoved = (int) heightTag;
240 | }
241 | // if(mRootView.indexOfChild(mKeyboardWithSearchView) == -1) {
242 | // mRootView.removeOnLayoutChangeListener(mOnLayoutChangeListener);
243 | // if (hasMoved > 0) {
244 | // mRootView.getChildAt(0).scrollBy(0, -1 * hasMoved);
245 | // mRootView.setTag(R.id.scroll_height_by_keyboard, 0);
246 | // }
247 | // }
248 | if(mKeyboardWithSearchView.getVisibility() == View.GONE) {
249 | mRootView.removeOnLayoutChangeListener(mOnLayoutChangeListener);
250 | if (hasMoved > 0) {
251 | mRootView.getChildAt(0).scrollBy(0, -1 * hasMoved);
252 | mRootView.setTag(R.id.scroll_height_by_keyboard, 0);
253 | }
254 | } else {
255 | BaseKeyboard keyboard = (BaseKeyboard) mKeyboardWithSearchView.getBaseKeyboardView().getKeyboard();
256 | EditText editText = keyboard.getEditText();
257 |
258 | Rect rect = new Rect();
259 | mRootView.getWindowVisibleDisplayFrame(rect);
260 |
261 | int[] etLocation = new int[2];
262 | editText.getLocationOnScreen(etLocation);
263 | int keyboardTop = etLocation[1] + editText.getHeight() + editText.getPaddingTop() + editText.getPaddingBottom() + 1 ; //1px is a divider
264 | Object anchor = editText.getTag(R.id.anchor_view);
265 | View mShowAnchorView = null;
266 | if(anchor != null && anchor instanceof View) {
267 | mShowAnchorView = (View) anchor;
268 | }
269 | if (mShowAnchorView != null) {
270 | int[] saLocation = new int[2];
271 | mShowAnchorView.getLocationOnScreen(saLocation);
272 | keyboardTop = saLocation[1] + mShowAnchorView.getHeight() + mShowAnchorView.getPaddingTop() + mShowAnchorView //1px is a divider
273 | .getPaddingBottom() + 1;
274 | }
275 | int moveHeight = keyboardTop + mKeyboardWithSearchView.getHeight() - rect.bottom;
276 | //height > 0 rootview 需要继续上滑
277 | if(moveHeight > 0) {
278 | mRootView.getChildAt(0).scrollBy(0, moveHeight);
279 | mRootView.setTag(R.id.scroll_height_by_keyboard,hasMoved + moveHeight);
280 | }else {
281 | int moveBackHeight = Math.min(hasMoved,Math.abs(moveHeight));
282 | if(moveBackHeight >0) {
283 | mRootView.getChildAt(0).scrollBy(0, -1 * moveBackHeight);
284 | mRootView.setTag(R.id.scroll_height_by_keyboard,hasMoved - moveBackHeight);
285 | }
286 | }
287 |
288 | }
289 | }
290 | };
291 |
292 | }
293 |
--------------------------------------------------------------------------------