├── keyboard
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── drawable
│ │ │ ├── keyboard_done.png
│ │ │ ├── keyboard_left.png
│ │ │ ├── keyboard_delete.png
│ │ │ ├── keyboard_right.png
│ │ │ ├── keyboard_search.png
│ │ │ ├── keyboard_shift.png
│ │ │ ├── keyboard_space.png
│ │ │ ├── keyboard_backspace.png
│ │ │ ├── keyboard_ic_dialog.png
│ │ │ ├── keyboard_word_del_layerlist2.xml
│ │ │ ├── keyboard_word_shift_layerlist.xml
│ │ │ ├── keyboard_word_shift_layerlist_da.xml
│ │ │ ├── keyboard_word_del_layerlist.xml
│ │ │ ├── keyboard_selector_bg.xml
│ │ │ ├── keyboard_selector_blue_bg.xml
│ │ │ └── keyboard_number_selector_bg.xml
│ │ ├── drawable-xxhdpi
│ │ │ ├── keyboard_enlarge.9.png
│ │ │ ├── icon_keyboard_capital_default.png
│ │ │ ├── icon_keyboard_capital_selected.png
│ │ │ ├── icon_shuzi_keyboard_del_default.png
│ │ │ └── icon_yingwen_fuhao_keyboard_del_default.png
│ │ ├── anim
│ │ │ ├── keyboard_anim_start.xml
│ │ │ └── keyboard_anim_dismiss.xml
│ │ ├── layout
│ │ │ ├── keyboard_key_preview_layout.xml
│ │ │ ├── keyboard_number_key_preview_layout.xml
│ │ │ └── keyboard_key_board_popu.xml
│ │ ├── values
│ │ │ ├── keyboard_strings.xml
│ │ │ ├── keyboard_dimens.xml
│ │ │ ├── keyboard_colors.xml
│ │ │ └── keyboard_styles.xml
│ │ └── xml
│ │ │ ├── keyboard_numbers.xml
│ │ │ ├── keyboard_symbol.xml
│ │ │ └── keyboard_word.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── kh
│ │ └── keyboard
│ │ ├── KeyBoardDialogUtils.java
│ │ ├── CustomKeyboardView.java
│ │ └── KhKeyboardView.java
└── build.gradle
├── settings.gradle
├── app
├── 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
│ │ └── safekeyboard
│ │ └── ly
│ │ └── com
│ │ └── safekeyboard
│ │ └── MainActivity.java
└── build.gradle
├── README.md
└── gradle.properties
/keyboard/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':keyboard'
2 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | SafeKeyBoard
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peiniwan/SafeKeyBoard/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peiniwan/SafeKeyBoard/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peiniwan/SafeKeyBoard/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peiniwan/SafeKeyBoard/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peiniwan/SafeKeyBoard/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/keyboard/src/main/res/drawable/keyboard_done.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peiniwan/SafeKeyBoard/HEAD/keyboard/src/main/res/drawable/keyboard_done.png
--------------------------------------------------------------------------------
/keyboard/src/main/res/drawable/keyboard_left.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peiniwan/SafeKeyBoard/HEAD/keyboard/src/main/res/drawable/keyboard_left.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peiniwan/SafeKeyBoard/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/peiniwan/SafeKeyBoard/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/keyboard/src/main/res/drawable/keyboard_delete.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peiniwan/SafeKeyBoard/HEAD/keyboard/src/main/res/drawable/keyboard_delete.png
--------------------------------------------------------------------------------
/keyboard/src/main/res/drawable/keyboard_right.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peiniwan/SafeKeyBoard/HEAD/keyboard/src/main/res/drawable/keyboard_right.png
--------------------------------------------------------------------------------
/keyboard/src/main/res/drawable/keyboard_search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peiniwan/SafeKeyBoard/HEAD/keyboard/src/main/res/drawable/keyboard_search.png
--------------------------------------------------------------------------------
/keyboard/src/main/res/drawable/keyboard_shift.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peiniwan/SafeKeyBoard/HEAD/keyboard/src/main/res/drawable/keyboard_shift.png
--------------------------------------------------------------------------------
/keyboard/src/main/res/drawable/keyboard_space.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peiniwan/SafeKeyBoard/HEAD/keyboard/src/main/res/drawable/keyboard_space.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peiniwan/SafeKeyBoard/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/peiniwan/SafeKeyBoard/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/peiniwan/SafeKeyBoard/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/keyboard/src/main/res/drawable/keyboard_backspace.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peiniwan/SafeKeyBoard/HEAD/keyboard/src/main/res/drawable/keyboard_backspace.png
--------------------------------------------------------------------------------
/keyboard/src/main/res/drawable/keyboard_ic_dialog.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peiniwan/SafeKeyBoard/HEAD/keyboard/src/main/res/drawable/keyboard_ic_dialog.png
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Android自定义安全键盘
2 | [文章链接](https://www.cnblogs.com/sixrain/p/7793610.html)
3 |
4 | 
5 |
--------------------------------------------------------------------------------
/keyboard/src/main/res/drawable-xxhdpi/keyboard_enlarge.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peiniwan/SafeKeyBoard/HEAD/keyboard/src/main/res/drawable-xxhdpi/keyboard_enlarge.9.png
--------------------------------------------------------------------------------
/keyboard/src/main/res/drawable-xxhdpi/icon_keyboard_capital_default.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peiniwan/SafeKeyBoard/HEAD/keyboard/src/main/res/drawable-xxhdpi/icon_keyboard_capital_default.png
--------------------------------------------------------------------------------
/keyboard/src/main/res/drawable-xxhdpi/icon_keyboard_capital_selected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peiniwan/SafeKeyBoard/HEAD/keyboard/src/main/res/drawable-xxhdpi/icon_keyboard_capital_selected.png
--------------------------------------------------------------------------------
/keyboard/src/main/res/drawable-xxhdpi/icon_shuzi_keyboard_del_default.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peiniwan/SafeKeyBoard/HEAD/keyboard/src/main/res/drawable-xxhdpi/icon_shuzi_keyboard_del_default.png
--------------------------------------------------------------------------------
/keyboard/src/main/res/drawable-xxhdpi/icon_yingwen_fuhao_keyboard_del_default.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peiniwan/SafeKeyBoard/HEAD/keyboard/src/main/res/drawable-xxhdpi/icon_yingwen_fuhao_keyboard_del_default.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/keyboard/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/keyboard/src/main/res/anim/keyboard_anim_start.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
9 |
10 |
--------------------------------------------------------------------------------
/keyboard/src/main/res/anim/keyboard_anim_dismiss.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/keyboard/src/main/res/layout/keyboard_key_preview_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
--------------------------------------------------------------------------------
/keyboard/src/main/res/values/keyboard_strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 软键盘
3 | 请输入用户名
4 | 请输入密码
5 | "@"
6 | "&"
7 | \"
8 | "<"
9 | ">"
10 |
11 |
--------------------------------------------------------------------------------
/keyboard/src/main/res/layout/keyboard_number_key_preview_layout.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/keyboard/src/main/res/values/keyboard_dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
7 | 45dp
8 | 10dp
9 | 10dp
10 | 120dp
11 |
12 |
--------------------------------------------------------------------------------
/keyboard/src/main/res/drawable/keyboard_word_del_layerlist2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 |
7 |
8 |
9 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/keyboard/src/main/res/drawable/keyboard_word_shift_layerlist.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 |
7 |
8 |
9 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/keyboard/src/main/res/drawable/keyboard_word_shift_layerlist_da.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 |
7 |
8 |
9 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/keyboard/src/main/res/drawable/keyboard_word_del_layerlist.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 |
7 |
8 |
9 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/keyboard/src/main/res/values/keyboard_colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #ffffff
7 | #bdbdbd
8 | #000000
9 | #424242
10 | #00ff00
11 | #ff0000
12 | #00000000
13 |
14 |
--------------------------------------------------------------------------------
/keyboard/src/main/res/drawable/keyboard_selector_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
7 |
8 |
9 |
10 |
11 | -
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/keyboard/src/main/res/drawable/keyboard_selector_blue_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
7 |
8 |
9 |
10 |
11 | -
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/keyboard/src/main/res/drawable/keyboard_number_selector_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
7 |
8 |
9 |
10 |
11 |
12 |
13 | -
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/main/java/safekeyboard/ly/com/safekeyboard/MainActivity.java:
--------------------------------------------------------------------------------
1 | package safekeyboard.ly.com.safekeyboard;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.view.View;
6 | import android.widget.EditText;
7 |
8 | import com.kh.keyboard.KeyBoardDialogUtils;
9 |
10 | public class MainActivity extends AppCompatActivity {
11 |
12 | private KeyBoardDialogUtils keyBoardDialogUtils;
13 | private EditText et;
14 |
15 | @Override
16 | protected void onCreate(Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | setContentView(R.layout.activity_main);
19 |
20 | et = (EditText) findViewById(R.id.et);
21 | keyBoardDialogUtils = new KeyBoardDialogUtils(this);
22 | et.setOnClickListener(new View.OnClickListener() {
23 | @Override
24 | public void onClick(View v) {
25 | keyBoardDialogUtils.show(et);
26 | }
27 | });
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "26.0.0"
6 | defaultConfig {
7 | applicationId "safekeyboard.ly.com.safekeyboard"
8 | minSdkVersion 14
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(include: ['*.jar'], dir: 'libs')
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.0-alpha7'
29 | testCompile 'junit:junit:4.12'
30 | compile project(':keyboard')
31 | }
32 |
--------------------------------------------------------------------------------
/keyboard/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | //键盘
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "26.0.0"
6 |
7 | defaultConfig {
8 | minSdkVersion 14
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 |
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | useLibrary 'org.apache.http.legacy'
23 | resourcePrefix "keyboard_"
24 |
25 | }
26 |
27 | repositories {
28 | flatDir {
29 | dirs 'libs'
30 | }
31 | maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
32 | }
33 | dependencies {
34 | compile fileTree(dir: 'libs', include: ['*.jar'])
35 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
36 | exclude group: 'com.android.support', module: 'support-annotations'
37 | })
38 |
39 | testCompile 'junit:junit:4.12'
40 | }
41 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
18 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/keyboard/src/main/res/values/keyboard_styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
20 |
21 |
--------------------------------------------------------------------------------
/keyboard/src/main/res/xml/keyboard_numbers.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/keyboard/src/main/res/layout/keyboard_key_board_popu.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
21 |
22 |
27 |
28 |
35 |
36 |
47 |
48 |
49 |
54 |
55 |
59 |
60 |
71 |
72 |
85 |
86 |
87 |
88 |
89 |
--------------------------------------------------------------------------------
/keyboard/src/main/res/xml/keyboard_symbol.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
51 |
52 |
53 |
54 |
56 |
57 |
58 |
59 |
60 | -->
61 |
62 |
63 |
64 |
65 |
67 |
68 |
--------------------------------------------------------------------------------
/keyboard/src/main/java/com/kh/keyboard/KeyBoardDialogUtils.java:
--------------------------------------------------------------------------------
1 | package com.kh.keyboard;
2 |
3 | import android.app.Activity;
4 | import android.app.Dialog;
5 | import android.content.Context;
6 | import android.content.DialogInterface;
7 | import android.os.Build;
8 | import android.text.InputType;
9 | import android.view.Gravity;
10 | import android.view.LayoutInflater;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 | import android.view.Window;
14 | import android.view.WindowManager;
15 | import android.view.inputmethod.InputMethodManager;
16 | import android.widget.EditText;
17 |
18 | import java.lang.reflect.Method;
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 |
23 | public class KeyBoardDialogUtils implements View.OnClickListener {
24 | protected View view;
25 | protected Dialog popWindow;
26 | protected Activity mContext;
27 | private EditText contentView;
28 | private List contentList;
29 | private KhKeyboardView keyboardUtil;
30 |
31 | public KeyBoardDialogUtils(Activity mContext) {
32 | try {
33 | this.mContext = mContext;
34 | if (contentList == null) {
35 | contentList = new ArrayList<>();
36 | }
37 |
38 | if (popWindow == null) {
39 | view = LayoutInflater.from(mContext).inflate(R.layout.keyboard_key_board_popu, null);
40 | // view.getBackground().setAlpha(68);
41 | popWindow = new Dialog(mContext, R.style.keyboard_popupAnimation);
42 | view.findViewById(R.id.keyboard_finish).setOnClickListener(this);
43 | view.findViewById(R.id.keyboard_back_hide).setOnClickListener(this);
44 | }
45 | popWindow.setContentView(view);
46 | popWindow.setCanceledOnTouchOutside(true);
47 | Window mWindow = popWindow.getWindow();
48 | mWindow.setWindowAnimations(R.style.keyboard_popupAnimation);
49 | mWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
50 | mWindow.setGravity(Gravity.BOTTOM | Gravity.FILL_HORIZONTAL);
51 | mWindow.setLayout(ViewGroup.LayoutParams.MATCH_PARENT,
52 | ViewGroup.LayoutParams.WRAP_CONTENT);
53 | popWindow.setOnDismissListener(new DialogInterface.OnDismissListener() {
54 |
55 | @Override
56 | public void onDismiss(DialogInterface dialog) {
57 | if (contentView != null && contentView.isFocused()) {
58 | contentView.clearFocus();
59 | }
60 | }
61 | });
62 | initView();
63 |
64 |
65 | } catch (Exception e) {
66 | e.printStackTrace();
67 | }
68 |
69 | }
70 |
71 | private void initView() {
72 | try {
73 | if (keyboardUtil == null)
74 | keyboardUtil = new KhKeyboardView(mContext, view);
75 |
76 | } catch (Exception e) {
77 | e.printStackTrace();
78 | }
79 |
80 | }
81 |
82 | /**
83 | * 隐藏系统键盘
84 | *
85 | * @param editText
86 | */
87 | public void hideSystemSofeKeyboard(EditText editText) {
88 | int sdkInt = Build.VERSION.SDK_INT;
89 | if (sdkInt >= 11) {
90 | try {
91 | Class cls = EditText.class;
92 | Method setShowSoftInputOnFocus;
93 | setShowSoftInputOnFocus = cls.getMethod("setShowSoftInputOnFocus", boolean.class);
94 | setShowSoftInputOnFocus.setAccessible(true);
95 | setShowSoftInputOnFocus.invoke(editText, false);
96 |
97 | } catch (SecurityException e) {
98 | e.printStackTrace();
99 | } catch (NoSuchMethodException e) {
100 | e.printStackTrace();
101 | } catch (Exception e) {
102 | e.printStackTrace();
103 | }
104 | } else {
105 | editText.setInputType(InputType.TYPE_NULL);
106 | }
107 | // 如果软键盘已经显示,则隐藏
108 | InputMethodManager imm = (InputMethodManager) mContext.getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
109 | imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
110 |
111 |
112 |
113 | }
114 |
115 |
116 |
117 | public void show(final EditText editText) {
118 | // popWindow.show(showParentView, Gravity.CENTER, 0, 0);
119 | editText.setFocusable(true);
120 | editText.setFocusableInTouchMode(true);
121 | editText.requestFocus();
122 | // hideSystemSofeKeyboard(editText);
123 | popWindow.show();
124 | keyboardUtil.showKeyboard(editText);
125 | }
126 |
127 | public void dismiss() {
128 | if (popWindow != null && popWindow.isShowing()) {
129 | popWindow.dismiss();
130 |
131 | }
132 |
133 | }
134 |
135 | @Override
136 | public void onClick(View v) {
137 | try {
138 | int i = v.getId();
139 | if (i == R.id.keyboard_finish) {
140 | keyboardUtil.hideKeyboard();
141 | dismiss();
142 |
143 | } else if (i == R.id.keyboard_back_hide) {
144 | keyboardUtil.hideKeyboard();
145 | dismiss();
146 |
147 | }
148 |
149 | } catch (Exception e) {
150 | e.printStackTrace();
151 | }
152 | }
153 |
154 |
155 | }
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
--------------------------------------------------------------------------------
/keyboard/src/main/java/com/kh/keyboard/CustomKeyboardView.java:
--------------------------------------------------------------------------------
1 | package com.kh.keyboard;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
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.util.AttributeSet;
13 |
14 | import java.lang.reflect.Field;
15 | import java.util.List;
16 |
17 | /**
18 | * Created by liuyu1 on 2017/8/2.
19 | */
20 |
21 | public class CustomKeyboardView extends KeyboardView {
22 | private Context context;
23 |
24 | public CustomKeyboardView(Context context, AttributeSet attrs) {
25 | super(context, attrs);
26 | this.context = context;
27 | }
28 |
29 | @Override
30 | public void onDraw(Canvas canvas) {
31 | super.onDraw(canvas);
32 | try {
33 | List keys = getKeyboard().getKeys();
34 | for (Keyboard.Key key : keys) {
35 | // Log.e("KEY", "Drawing key with code " + key.codes[0]);
36 | if (key.codes[0] == -5) {
37 | Drawable dr = (Drawable) context.getResources().getDrawable(R.drawable.keyboard_word_del_layerlist);
38 | dr.setBounds(key.x, key.y, key.x + key.width, key.y + key.height);
39 | dr.draw(canvas);
40 | } else if (key.codes[0] == -35) {
41 | Drawable dr = (Drawable) context.getResources().getDrawable(R.drawable.keyboard_word_del_layerlist2);
42 | dr.setBounds(key.x, key.y, key.x + key.width, key.y + key.height);
43 | dr.draw(canvas);
44 | } else if (key.codes[0] == -1) {
45 | Drawable dr = (Drawable) context.getResources().getDrawable(R.drawable.keyboard_word_shift_layerlist);
46 | Drawable dr_da = (Drawable) context.getResources().getDrawable(R.drawable.keyboard_word_shift_layerlist_da);
47 | dr.setBounds(key.x, key.y, key.x + key.width, key.y + key.height);
48 | dr_da.setBounds(key.x, key.y, key.x + key.width, key.y + key.height);
49 |
50 | if (KhKeyboardView.isUpper) {
51 | dr_da.draw(canvas);
52 | } else {
53 | dr.draw(canvas);
54 | }
55 |
56 | } else if (key.codes[0] == -2 || key.codes[0] == 90001) {
57 | Drawable dr = (Drawable) context.getResources().getDrawable(R.drawable.keyboard_selector_blue_bg);
58 | dr.setBounds(key.x, key.y, key.x + key.width, key.y + key.height);
59 | dr.draw(canvas);
60 | drawText(canvas, key);
61 | } else {
62 |
63 | }
64 | }
65 | } catch (Exception e) {
66 | e.printStackTrace();
67 | }
68 | }
69 |
70 |
71 | private void drawText(Canvas canvas, Keyboard.Key key) {
72 | try {
73 | Rect bounds = new Rect();
74 | Paint paint = new Paint();
75 | paint.setTextAlign(Paint.Align.CENTER);
76 |
77 |
78 | paint.setAntiAlias(true);
79 |
80 | paint.setColor(Color.WHITE);
81 |
82 | if (key.label != null) {
83 | String label = key.label.toString();
84 |
85 | Field field;
86 |
87 | if (label.length() > 1 && key.codes.length < 2) {
88 | int labelTextSize = 0;
89 | try {
90 | field = KeyboardView.class.getDeclaredField("mLabelTextSize");
91 | field.setAccessible(true);
92 | labelTextSize = (int) field.get(this);
93 | } catch (NoSuchFieldException e) {
94 | e.printStackTrace();
95 | } catch (IllegalAccessException e) {
96 | e.printStackTrace();
97 | }
98 | paint.setTextSize(labelTextSize);
99 | paint.setTypeface(Typeface.DEFAULT_BOLD);
100 | } else {
101 | int keyTextSize = 0;
102 | try {
103 | field = KeyboardView.class.getDeclaredField("mLabelTextSize");
104 | field.setAccessible(true);
105 | keyTextSize = (int) field.get(this);
106 | } catch (NoSuchFieldException e) {
107 | e.printStackTrace();
108 | } catch (IllegalAccessException e) {
109 | e.printStackTrace();
110 | }
111 | paint.setTextSize(keyTextSize);
112 | paint.setTypeface(Typeface.DEFAULT);
113 | }
114 |
115 | paint.getTextBounds(key.label.toString(), 0, key.label.toString()
116 | .length(), bounds);
117 | canvas.drawText(key.label.toString(), key.x + (key.width / 2),
118 | (key.y + key.height / 2) + bounds.height() / 2, paint);
119 | } else if (key.icon != null) {
120 | key.icon.setBounds(key.x + (key.width - key.icon.getIntrinsicWidth()) / 2, key.y + (key.height - key.icon.getIntrinsicHeight()) / 2,
121 | key.x + (key.width - key.icon.getIntrinsicWidth()) / 2 + key.icon.getIntrinsicWidth(), key.y + (key.height - key.icon.getIntrinsicHeight()) / 2 + key.icon.getIntrinsicHeight());
122 | key.icon.draw(canvas);
123 | }
124 |
125 | } catch (Exception e) {
126 | e.printStackTrace();
127 | }
128 |
129 |
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/keyboard/src/main/res/xml/keyboard_word.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
14 |
18 |
22 |
26 |
30 |
34 |
38 |
42 |
46 |
51 |
52 |
53 |
58 |
62 |
66 |
70 |
74 |
78 |
82 |
86 |
90 |
95 |
96 |
97 |
98 |
104 |
108 |
112 |
116 |
120 |
124 |
128 |
132 |
137 |
138 |
139 |
140 |
147 |
152 |
156 |
160 |
164 |
168 |
172 |
176 |
182 |
183 |
184 |
185 |
189 |
194 |
199 |
200 |
--------------------------------------------------------------------------------
/keyboard/src/main/java/com/kh/keyboard/KhKeyboardView.java:
--------------------------------------------------------------------------------
1 | package com.kh.keyboard;
2 |
3 | import android.app.Activity;
4 | import android.graphics.drawable.Drawable;
5 | import android.inputmethodservice.Keyboard;
6 | import android.inputmethodservice.KeyboardView;
7 | import android.text.Editable;
8 | import android.text.InputType;
9 | import android.util.Log;
10 | import android.view.View;
11 | import android.widget.EditText;
12 |
13 | import java.util.List;
14 |
15 |
16 | public class KhKeyboardView {
17 | private Activity mContext;
18 | private View parentView;
19 | private KeyboardView mLetterView; //字母键盘view
20 | private KeyboardView mNumberView; //数字键盘View
21 | private Keyboard mNumberKeyboard; // 数字键盘
22 | private Keyboard mLetterKeyboard; // 字母键盘
23 | private Keyboard mSymbolKeyboard; // 符号键盘
24 |
25 | private boolean isNumber = true; // 是否数字键盘
26 | public static boolean isUpper = false; // 是否大写
27 | private boolean isSymbol = false; // 是否是符号
28 | private EditText mEditText;
29 | private View headerView;
30 |
31 | public void setEditText(EditText text) {
32 | mEditText = text;
33 | }
34 |
35 | public KhKeyboardView(Activity context, View view) {
36 | mContext = context;
37 | parentView = view;
38 |
39 | mNumberKeyboard = new Keyboard(mContext, R.xml.keyboard_numbers);
40 | mLetterKeyboard = new Keyboard(mContext, R.xml.keyboard_word);
41 | mSymbolKeyboard = new Keyboard(mContext, R.xml.keyboard_symbol);
42 | mNumberView = (KeyboardView) parentView.findViewById(R.id.keyboard_view);
43 | mLetterView = (KeyboardView) parentView.findViewById(R.id.keyboard_view_2);
44 |
45 | mNumberView.setKeyboard(mNumberKeyboard);
46 | mNumberView.setEnabled(true);
47 | mNumberView.setPreviewEnabled(false);
48 | mNumberView.setOnKeyboardActionListener(listener);
49 | mLetterView.setKeyboard(mLetterKeyboard);
50 | mLetterView.setEnabled(true);
51 | mLetterView.setPreviewEnabled(true);
52 | mLetterView.setOnKeyboardActionListener(listener);
53 | headerView = parentView.findViewById(R.id.keyboard_header);
54 |
55 | }
56 |
57 | private KeyboardView.OnKeyboardActionListener listener = new KeyboardView.OnKeyboardActionListener() {
58 | @Override
59 | public void onPress(int primaryCode) {
60 | Log.d("primaryCode","onPress--"+primaryCode);
61 | if (primaryCode == Keyboard.KEYCODE_SHIFT) {
62 | List keyList = mLetterKeyboard.getKeys();
63 |
64 | mLetterView.setPreviewEnabled(false);
65 | } else if (primaryCode == Keyboard.KEYCODE_DELETE) {
66 | mLetterView.setPreviewEnabled(false);
67 | } else if (primaryCode == 32) {
68 | mLetterView.setPreviewEnabled(false);
69 | } else {
70 | mLetterView.setPreviewEnabled(true);
71 | }
72 |
73 | }
74 |
75 | @Override
76 | public void onRelease(int primaryCode) {
77 | Log.d("primaryCode","onRelease--"+primaryCode);
78 |
79 | // if(primaryCode== -1){
80 | // if(isUpper){
81 | // isUpper=false;
82 | // }else {
83 | // isUpper=true;
84 | // }
85 | // }
86 | }
87 |
88 | @Override
89 | public void onKey(int primaryCode, int[] keyCodes) {
90 | Log.d("primaryCode","onKey--"+primaryCode);
91 | try {
92 | if (mEditText == null)
93 | return;
94 | Editable editable = mEditText.getText();
95 | int start = mEditText.getSelectionStart();
96 | if (primaryCode == Keyboard.KEYCODE_CANCEL) {
97 | // 隐藏键盘
98 | hideKeyboard();
99 | } else if (primaryCode == Keyboard.KEYCODE_DELETE || primaryCode == -35) {
100 |
101 | // 回退键,删除字符
102 | if (editable != null && editable.length() > 0) {
103 | if (start > 0) {
104 | editable.delete(start - 1, start);
105 | }
106 | }
107 | } else if (primaryCode == Keyboard.KEYCODE_SHIFT) {
108 | // 大小写切换
109 | changeKeyboart();
110 | mLetterView.setKeyboard(mLetterKeyboard);
111 |
112 | } else if (primaryCode == Keyboard.KEYCODE_MODE_CHANGE) {
113 | // 数字与字母键盘互换
114 | if (isNumber) {
115 | showLetterView();
116 | showLetterView2();
117 | } else {
118 | showNumberView();
119 | }
120 |
121 | } else if (primaryCode == 90001) {
122 | // 字母与符号切换
123 | if (isSymbol) {
124 | showLetterView2();
125 | } else {
126 | showSymbolView();
127 | }
128 |
129 | } else {
130 | // 输入键盘值
131 | editable.insert(start, Character.toString((char) primaryCode));
132 | }
133 | } catch (Exception e) {
134 | e.printStackTrace();
135 | }
136 |
137 | }
138 |
139 | @Override
140 | public void onText(CharSequence text) {
141 |
142 | }
143 |
144 | @Override
145 | public void swipeLeft() {
146 |
147 | }
148 |
149 | @Override
150 | public void swipeRight() {
151 |
152 | }
153 |
154 | @Override
155 | public void swipeDown() {
156 |
157 | }
158 |
159 | @Override
160 | public void swipeUp() {
161 |
162 | }
163 | };
164 |
165 | // 字母-符号,显示字母
166 | private void showLetterView2() {
167 | if (mLetterView != null) {
168 | isSymbol = false;
169 | mLetterView.setKeyboard(mLetterKeyboard);
170 | }
171 | }
172 |
173 | // 字母-符号,显示符号
174 | private void showSymbolView() {
175 | try {
176 | if (mLetterKeyboard != null) {
177 | isSymbol = true;
178 | mLetterView.setKeyboard(mSymbolKeyboard);
179 | }
180 | } catch (Exception e) {
181 | }
182 | }
183 |
184 | // 数字-字母,显示字母键盘
185 | private void showLetterView() {
186 | try {
187 | if (mLetterView != null && mNumberView != null) {
188 | isNumber = false;
189 | mLetterView.setVisibility(View.VISIBLE);
190 | mNumberView.setVisibility(View.INVISIBLE);
191 | }
192 | } catch (Exception e) {
193 | e.printStackTrace();
194 | }
195 |
196 | }
197 |
198 | // 数字-字母, 显示数字键盘
199 | private void showNumberView() {
200 | try {
201 | if (mLetterView != null && mNumberView != null) {
202 | isNumber = true;
203 | mLetterView.setVisibility(View.INVISIBLE);
204 | mNumberView.setVisibility(View.VISIBLE);
205 | }
206 | } catch (Exception e) {
207 | e.printStackTrace();
208 | }
209 |
210 | }
211 |
212 | /**
213 | * 切换大小写
214 | */
215 | private void changeKeyboart() {
216 | List keyList = mLetterKeyboard.getKeys();
217 | if (isUpper) {
218 | // 大写切换小写
219 | isUpper = false;
220 | for (Keyboard.Key key : keyList) {
221 | Drawable icon = key.icon;
222 |
223 | if (key.label != null && isLetter(key.label.toString())) {
224 | key.label = key.label.toString().toLowerCase();
225 | key.codes[0] = key.codes[0] + 32;
226 | }
227 | }
228 | } else {
229 | // 小写切换成大写
230 | isUpper = true;
231 | for (Keyboard.Key key : keyList) {
232 | if (key.label != null && isLetter(key.label.toString())) {
233 | key.label = key.label.toString().toUpperCase();
234 | key.codes[0] = key.codes[0] - 32;
235 | }
236 | }
237 | }
238 | }
239 |
240 | /**
241 | * 判断是否是字母
242 | */
243 | private boolean isLetter(String str) {
244 | String wordStr = "abcdefghijklmnopqrstuvwxyz";
245 | return wordStr.contains(str.toLowerCase());
246 | }
247 |
248 | public void hideKeyboard() {
249 | try {
250 | int visibility = mLetterView.getVisibility();
251 | if (visibility == View.VISIBLE) {
252 | headerView.setVisibility(View.GONE);
253 | mLetterView.setVisibility(View.GONE);
254 | }
255 | visibility = mNumberView.getVisibility();
256 | if (visibility == View.VISIBLE) {
257 | headerView.setVisibility(View.GONE);
258 | mNumberView.setVisibility(View.GONE);
259 | }
260 | } catch (Exception e) {
261 | e.printStackTrace();
262 | }
263 |
264 | }
265 |
266 | /**
267 | * 显示键盘
268 | *
269 | * @param editText
270 | */
271 | public void showKeyboard(EditText editText) {
272 | try {
273 | this.mEditText = editText;
274 | int visibility = 0;
275 | int inputText = mEditText.getInputType();
276 | headerView.setVisibility(View.VISIBLE);
277 | switch (inputText) {
278 | case InputType.TYPE_CLASS_NUMBER:
279 | showNumberView();
280 | break;
281 | case InputType.TYPE_CLASS_PHONE:
282 | showNumberView();
283 | break;
284 | case InputType.TYPE_NUMBER_FLAG_DECIMAL:
285 | showNumberView();
286 | break;
287 | default:
288 | showLetterView();
289 | break;
290 | }
291 | } catch (Exception e) {
292 | e.printStackTrace();
293 | }
294 |
295 |
296 | }
297 |
298 |
299 | }
300 |
--------------------------------------------------------------------------------