├── .gitignore
├── .idea
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── gradle.xml
├── inspectionProfiles
│ ├── Project_Default.xml
│ └── profiles_settings.xml
├── markdown-navigator.xml
├── markdown-navigator
│ └── profiles_settings.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── zyl
│ │ └── customkeyboard
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── zyl
│ │ │ └── customkeyboard
│ │ │ ├── KeyboardEditTextActivity.java
│ │ │ ├── MainActivity.java
│ │ │ └── SimpleUsageActivity.java
│ └── res
│ │ ├── layout
│ │ ├── activity_keyboard_edittext.xml
│ │ ├── activity_main.xml
│ │ └── activity_simpleusage.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
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── zyl
│ └── customkeyboard
│ └── ExampleUnitTest.java
├── build.gradle
├── customkeyboard
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── zyl
│ │ └── customkeyboardview
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── zyl
│ │ │ └── customkeyboardview
│ │ │ └── CustomKeyboardEditText.java
│ └── res
│ │ ├── drawable
│ │ └── bg_keyboard_btn.xml
│ │ ├── layout
│ │ └── keyboard_view.xml
│ │ ├── mipmap-xxxhdpi
│ │ └── keyboard_del.png
│ │ ├── values
│ │ ├── attr.xml
│ │ └── strings.xml
│ │ └── xml
│ │ └── idcard_keyboard.xml
│ └── test
│ └── java
│ └── com
│ └── zyl
│ └── customkeyboardview
│ └── ExampleUnitTest.java
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.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/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/markdown-navigator.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
--------------------------------------------------------------------------------
/.idea/markdown-navigator/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # CustomKeyboardView
2 | android自定义键盘、自定义身份证键盘、支持拓展。
3 | android 系统键盘支持的点已经比较丰富了, 但是有时候某一些需求还不能满足我们的需求。最近公司应用到了实名认证相关的功能,这部分需要一个身份证的EditText, 自然也需要一个身份证的键盘,奈何系统没有这种键盘,只能自定义一个。
4 |
5 | 首先来看android SDK为我们提供**Keyboard**的这个类。
6 |
7 | 1、Keyboard xml描述文件
8 |
9 | 
10 |
11 | 上面已经描述的很清晰了, 它用来加载一个键盘和存储按键属性的一个描述XML。我们在res/xml 目录下新建一个idcard_keyboard.xml文件。
12 |
13 | ```
14 |
15 |
20 |
21 |
24 |
27 |
30 |
31 |
32 |
35 |
38 |
41 |
42 |
43 |
46 |
49 |
52 |
53 |
54 |
58 |
61 |
65 |
66 |
67 | ```
68 | 这里主要介绍一些常用的类属性,更多请参考[andorid官网](https://developer.android.google.cn/reference/android/inputmethodservice/Keyboard.html)。
69 | - Keyboard类:存储键盘以及按键相关信息。
70 | android:horizontalGap 按键之间默认的水平间距。
71 | android:verticalGap 按键之间默认的垂直间距。
72 | android:keyHeight 按键的默认高度,以像素或显示高度的百分比表示。
73 | android:keyWidth: 按键的默认宽度,以像素或显示宽度的百分比表示。
74 | - Row:为包含按键的容器。
75 | - Key: 用于描述键盘中单个键的位置和特性。
76 | android:codes 该键输出的unicode值。
77 | android:isRepeatable 这个属性如果设置为true,那么当长按该键时就会重复接受到该键上的动作,在 删除键键 和 空格键 上通常设为true。
78 | android:keyLabel 显示在按键上的文字。
79 | android:keyIcon 与keyLabel是二选一关系,它会代替文字以图标的形式显示在键上。
80 |
81 | 有了Keyboard来存储键盘相关信息了,那么键盘如何这些信息呢?这时候用到android SDK为我们提供的另外一个类***KeyboardView***。
82 |
83 | 2、KeyboardView
84 |
85 | 
86 |
87 | KeyboardView是一个渲染虚拟键盘的View。 它处理键的渲染和检测按键和触摸动作。显然我们需要KeyboardView来对Keyboard里的数据进行渲染并呈现给我们以及相关的点击事件做处理。
88 | 1)`//设置keyboard与KeyboardView相关联的方法。
89 | public void setKeyboard(Keyboard keyboard) `
90 | 2)`//设置虚拟键盘事件的监听,此方法必须设置,不然会报错。
91 | public void setOnKeyboardActionListener(OnKeyboardActionListener listener)`
92 | 步骤上呢,做完第一步的关联,并设置第二步的事件,调用`KeyboardView.setVisible(true);`键盘就可以显示出来了, 是不是很简单。不过到这里还没有结束哦,接下来我们为了使用上的便利要进行相应的封装。
93 | 封装
94 | 这里我们通过继承EditText来对Keyboard与KeyboardView进行封装。
95 | attr.xml文件,这里我们需要通过一个xml类型的自定义属性引入我们的键盘描述文件。
96 | ```
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 | ```
105 | 还需要一个keyboardView 布局文件
106 | ```
107 |
108 |
109 |
121 | ```
122 | 万事俱备、主角登场~~~
123 | ```
124 | /**
125 | * Description: 自定义键盘类KeyboardEditText
126 | * Created by zouyulong on 2017/7/26.
127 | */
128 |
129 | public class CustomKeyboardEditText extends EditText implements KeyboardView.OnKeyboardActionListener,
130 | View.OnClickListener {
131 | private Keyboard mKeyboard;
132 | private KeyboardView mKeyboardView;
133 | private PopupWindow mKeyboardWindow;
134 | private View mDecorView;
135 |
136 | public CustomKeyboardEditText(Context context) {
137 | this(context, null);
138 | }
139 |
140 | public CustomKeyboardEditText(Context context, AttributeSet attrs) {
141 | this(context, attrs, 0);
142 | }
143 |
144 | public CustomKeyboardEditText(Context context, AttributeSet attrs, int defStyleAttr) {
145 | super(context, attrs, defStyleAttr);
146 | initKeyboardView(context, attrs);
147 | }
148 |
149 | private void initKeyboardView(Context context, AttributeSet attrs) {
150 | TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.Keyboard);
151 | if (!array.hasValue(R.styleable.Keyboard_xml)) {
152 | throw new IllegalArgumentException("you need add keyboard_xml argument!");
153 | }
154 | int xmlId = array.getResourceId(R.styleable.Keyboard_xml, 0);
155 | mKeyboard = new Keyboard(context, xmlId);
156 | mKeyboardView = (KeyboardView) LayoutInflater.from(context).inflate(R.layout.keyboard_view, null);
157 | //键盘关联keyboard对象
158 | mKeyboardView.setKeyboard(mKeyboard);
159 | //关闭键盘按键预览效果,如果按键过小可能会比较适用。
160 | mKeyboardView.setPreviewEnabled(false);
161 | //设置键盘事件
162 | mKeyboardView.setOnKeyboardActionListener(this);
163 | //将keyboardview放入popupwindow方便显示以及位置调整。
164 | mKeyboardWindow = new PopupWindow(mKeyboardView,
165 | ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
166 | array.recycle();
167 | //设置点击事件,点击后键盘弹起,系统键盘收起。
168 | setOnClickListener(this);
169 | //屏蔽当前edittext的系统键盘
170 | notSystemSoftInput();
171 | }
172 |
173 | @Override
174 | public void onPress(int primaryCode) {
175 |
176 | }
177 |
178 | @Override
179 | public void onRelease(int primaryCode) {
180 |
181 | }
182 |
183 | @Override
184 | public void onKey(int primaryCode, int[] keyCodes) {
185 | Editable editable = this.getText();
186 | //获取光标偏移量下标
187 | int startIndex = this.getSelectionStart();
188 | switch (primaryCode) {
189 | case Keyboard.KEYCODE_CANCEL:// 隐藏键盘
190 | hideKeyboard();
191 | break;
192 | case Keyboard.KEYCODE_DELETE:// 回退
193 | if (editable != null && editable.length() > 0) {
194 | if (startIndex > 0) {
195 | editable.delete(startIndex - 1, startIndex);
196 | }
197 | }
198 | break;
199 | case 9994://左移
200 | setSelection(startIndex-1);
201 | break;
202 | case 9995://重输
203 | editable.clear();
204 | break;
205 | case 9996://右移
206 | if (startIndex < length()) {
207 | setSelection(startIndex + 1);
208 | }
209 | break;
210 | default:
211 | editable.insert(startIndex, Character.toString((char) primaryCode));
212 | break;
213 | }
214 | }
215 |
216 | @Override
217 | public void onText(CharSequence text) {
218 |
219 | }
220 |
221 | @Override
222 | public void swipeLeft() {
223 |
224 | }
225 |
226 | @Override
227 | public void swipeRight() {
228 |
229 | }
230 |
231 | @Override
232 | public void swipeDown() {
233 |
234 | }
235 |
236 | @Override
237 | public void swipeUp() {
238 |
239 | }
240 |
241 | /**
242 | * 根据key code 获取 Keyboard.Key 对象
243 | * @param primaryCode
244 | * @return
245 | */
246 | private Keyboard.Key getKeyByKeyCode(int primaryCode) {
247 | if(null != mKeyboard){
248 | List keyList = mKeyboard.getKeys();
249 | for (int i =0,size= keyList.size(); i < size; i++) {
250 | Keyboard.Key key = keyList.get(i);
251 |
252 | int codes[] = key.codes;
253 |
254 | if(codes[0] == primaryCode){
255 | return key;
256 | }
257 | }
258 | }
259 |
260 | return null;
261 | }
262 |
263 | @Override
264 | public boolean onKeyDown(int keyCode, KeyEvent event) {
265 | if (keyCode == KeyEvent.KEYCODE_BACK) {
266 | if (null != mKeyboardWindow) {
267 | if (mKeyboardWindow.isShowing()) {
268 | mKeyboardWindow.dismiss();
269 | return true;
270 | }
271 | }
272 | }
273 | return super.onKeyDown(keyCode, event);
274 | }
275 |
276 | @SuppressLint("MissingSuperCall")
277 | @Override
278 | protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
279 | if (!focused) {
280 | hideKeyboard();
281 | } else {
282 | hideSysInput();
283 | showKeyboard();
284 | }
285 | super.onFocusChanged(focused, direction, previouslyFocusedRect);
286 | }
287 |
288 | @Override
289 | public void onAttachedToWindow() {
290 | super.onAttachedToWindow();
291 | this.mDecorView = ((Activity) getContext()).getWindow().getDecorView();
292 | hideSysInput();
293 | }
294 |
295 | @Override
296 | public void onDetachedFromWindow() {
297 | super.onDetachedFromWindow();
298 | hideKeyboard();
299 | mKeyboardWindow = null;
300 | mKeyboardView = null;
301 | mKeyboard = null;
302 | mDecorView = null;
303 | }
304 |
305 | /**
306 | * 显示自定义键盘
307 | */
308 | private void showKeyboard() {
309 | if (null != mKeyboardWindow) {
310 | if (!mKeyboardWindow.isShowing()) {
311 | mKeyboardView.setKeyboard(mKeyboard);
312 | mKeyboardWindow.showAtLocation(this.mDecorView, Gravity.BOTTOM, 0, 0);
313 | }
314 | }
315 | }
316 |
317 | /**
318 | * 屏蔽系统输入法
319 | */
320 | private void notSystemSoftInput(){
321 | if (Build.VERSION.SDK_INT <= 10) {
322 | setInputType(InputType.TYPE_NULL);
323 | } else {
324 | ((Activity)getContext()).getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
325 | try {
326 | Class cls = EditText.class;
327 | Method setShowSoftInputOnFocus = cls.getMethod("setShowSoftInputOnFocus", boolean.class);
328 | setShowSoftInputOnFocus.setAccessible(true);
329 | setShowSoftInputOnFocus.invoke(this, false);
330 | } catch (Exception e) {
331 | e.printStackTrace();
332 | }
333 | }
334 | }
335 |
336 | /**
337 | * 隐藏自定义键盘
338 | */
339 | private void hideKeyboard() {
340 | if (null != mKeyboardWindow) {
341 | if (mKeyboardWindow.isShowing()) {
342 | mKeyboardWindow.dismiss();
343 | }
344 | }
345 | }
346 |
347 | /**
348 | * 隐藏系统键盘
349 | */
350 | private void hideSysInput() {
351 | if (this.getWindowToken() != null) {
352 | InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
353 | imm.hideSoftInputFromWindow(this.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
354 | }
355 | }
356 |
357 | @Override
358 | public void onClick(View v) {
359 | requestFocus();
360 | requestFocusFromTouch();
361 | hideSysInput();
362 | showKeyboard();
363 | }
364 | }
365 | ```
366 | 代码中注释写的已经很清晰了,就不做一一的讲解了。
367 |
368 | 结尾
369 | - 该自定义组件目前只是支持了身份证键盘,xml下只提供了身份证键盘的描述文件。如果需要其他键盘可以自己定义xml文件,如果有特殊点击事件,逻辑放入`public void onKey(int primaryCode, int[] keyCodes) ` case 相应的keycode逻辑下即可。
370 |
371 | - 代码已放入[github https://github.com/zyl409214686/CustomKeyboardView](https://github.com/zyl409214686/CustomKeyboardView),欢迎提 issues、star、Fork。
372 |
373 | - 效果图:
374 |
375 | 
376 |
377 |
378 | 参考:
379 | - [android开发者官网](https://developer.android.google.cn/reference/android/inputmethodservice/Keyboard.html)
380 | - [Android 总结:自定义键盘实现原理和三种实例详解](http://blog.csdn.net/u014136472/article/details/50257245)
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.2"
6 | defaultConfig {
7 | applicationId "com.zyl.customkeyboard"
8 | minSdkVersion 15
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.2'
29 | testCompile 'junit:junit:4.12'
30 | compile project(':customkeyboard')
31 | }
32 |
--------------------------------------------------------------------------------
/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 /Developer/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 |
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 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/zyl/customkeyboard/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.zyl.customkeyboard;
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("com.zyl.customkeyboard", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
22 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyl/customkeyboard/KeyboardEditTextActivity.java:
--------------------------------------------------------------------------------
1 | package com.zyl.customkeyboard;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 |
6 | /**
7 | * Description: 封装后的自定义KeyboardEditText
8 | * Created by zouyulong on 2017/7/26.
9 | * Email : zouyulong@syswin.com
10 | * Person in charge : zouyulong
11 | */
12 | public class KeyboardEditTextActivity extends AppCompatActivity {
13 | @Override
14 | protected void onCreate(Bundle savedInstanceState) {
15 | super.onCreate(savedInstanceState);
16 | setContentView(R.layout.activity_keyboard_edittext);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyl/customkeyboard/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.zyl.customkeyboard;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 |
8 | /**
9 | * Description: 主activity
10 | * Created by zouyulong on 2017/7/26.
11 | * Email : zouyulong@syswin.com
12 | * Person in charge : zouyulong
13 | */
14 | public class MainActivity extends AppCompatActivity {
15 |
16 | @Override
17 | protected void onCreate(Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | setContentView(R.layout.activity_main);
20 | findViewById(R.id.bt_unwrapper).setOnClickListener(new View.OnClickListener() {
21 | @Override
22 | public void onClick(View v) {
23 | Intent in = new Intent();
24 | in.setClass(MainActivity.this, SimpleUsageActivity.class);
25 | startActivity(in);
26 | }
27 | });
28 | findViewById(R.id.bt_wrappered).setOnClickListener(new View.OnClickListener() {
29 | @Override
30 | public void onClick(View v) {
31 | Intent in = new Intent();
32 | in.setClass(MainActivity.this, KeyboardEditTextActivity.class);
33 | startActivity(in);
34 | }
35 | });
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyl/customkeyboard/SimpleUsageActivity.java:
--------------------------------------------------------------------------------
1 | package com.zyl.customkeyboard;
2 |
3 | import android.inputmethodservice.Keyboard;
4 | import android.inputmethodservice.KeyboardView;
5 | import android.os.Bundle;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.view.View;
8 |
9 | /**
10 | * Description: 封装前,简单用法
11 | * Created by zouyulong on 2017/7/26.
12 | * Email : zouyulong@syswin.com
13 | * Person in charge : zouyulong
14 | */
15 | public class SimpleUsageActivity extends AppCompatActivity {
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_simpleusage);
21 | final KeyboardView keyboardView = (KeyboardView) findViewById(R.id.keyboard_idcard);
22 | Keyboard keyboard = new Keyboard(this, R.xml.idcard_keyboard);
23 | keyboardView.setKeyboard(keyboard);
24 | keyboardView.setOnKeyboardActionListener(new KeyboardView.OnKeyboardActionListener() {
25 | @Override
26 | public void onPress(int primaryCode) {
27 |
28 | }
29 |
30 | @Override
31 | public void onRelease(int primaryCode) {
32 |
33 | }
34 |
35 | @Override
36 | public void onKey(int primaryCode, int[] keyCodes) {
37 |
38 | }
39 |
40 | @Override
41 | public void onText(CharSequence text) {
42 |
43 | }
44 |
45 | @Override
46 | public void swipeLeft() {
47 |
48 | }
49 |
50 | @Override
51 | public void swipeRight() {
52 |
53 | }
54 |
55 | @Override
56 | public void swipeDown() {
57 |
58 | }
59 |
60 | @Override
61 | public void swipeUp() {
62 |
63 | }
64 | });
65 | findViewById(R.id.et_identity_card).setOnClickListener(new View.OnClickListener() {
66 | @Override
67 | public void onClick(View v) {
68 | keyboardView.setVisibility(View.VISIBLE);
69 | }
70 | });
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_keyboard_edittext.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
12 |
13 |
22 |
23 |
28 |
29 |
33 |
34 |
38 |
39 |
47 |
48 |
60 |
61 |
62 |
68 |
69 |
73 |
74 |
82 |
83 |
97 |
98 |
99 |
104 |
105 |
106 |
120 |
121 |
122 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
12 |
13 |
23 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_simpleusage.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
11 |
12 |
21 |
22 |
27 |
28 |
32 |
33 |
34 |
38 |
39 |
47 |
48 |
61 |
62 |
63 |
68 |
69 |
70 |
84 |
85 |
86 |
87 |
102 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyl409214686/CustomKeyboardView/cff6b2d660af2d1e49904d9a03b68136ac60c64a/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyl409214686/CustomKeyboardView/cff6b2d660af2d1e49904d9a03b68136ac60c64a/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyl409214686/CustomKeyboardView/cff6b2d660af2d1e49904d9a03b68136ac60c64a/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyl409214686/CustomKeyboardView/cff6b2d660af2d1e49904d9a03b68136ac60c64a/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyl409214686/CustomKeyboardView/cff6b2d660af2d1e49904d9a03b68136ac60c64a/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyl409214686/CustomKeyboardView/cff6b2d660af2d1e49904d9a03b68136ac60c64a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyl409214686/CustomKeyboardView/cff6b2d660af2d1e49904d9a03b68136ac60c64a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyl409214686/CustomKeyboardView/cff6b2d660af2d1e49904d9a03b68136ac60c64a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyl409214686/CustomKeyboardView/cff6b2d660af2d1e49904d9a03b68136ac60c64a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyl409214686/CustomKeyboardView/cff6b2d660af2d1e49904d9a03b68136ac60c64a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | CustomKeyBoard
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/zyl/customkeyboard/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.zyl.customkeyboard;
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 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.3.2'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/customkeyboard/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/customkeyboard/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.2"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
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 | }
23 |
24 | dependencies {
25 | compile fileTree(dir: 'libs', include: ['*.jar'])
26 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
27 | exclude group: 'com.android.support', module: 'support-annotations'
28 | })
29 | compile 'com.android.support:appcompat-v7:25.3.1'
30 | testCompile 'junit:junit:4.12'
31 | }
32 |
--------------------------------------------------------------------------------
/customkeyboard/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 /Developer/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 |
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 |
--------------------------------------------------------------------------------
/customkeyboard/src/androidTest/java/com/zyl/customkeyboardview/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.zyl.customkeyboardview;
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("com.zyl.customidcardkeyboard.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/customkeyboard/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/customkeyboard/src/main/java/com/zyl/customkeyboardview/CustomKeyboardEditText.java:
--------------------------------------------------------------------------------
1 | package com.zyl.customkeyboardview;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.app.Activity;
5 | import android.content.Context;
6 | import android.content.res.TypedArray;
7 | import android.graphics.Rect;
8 | import android.inputmethodservice.Keyboard;
9 | import android.inputmethodservice.KeyboardView;
10 | import android.os.Build;
11 | import android.text.Editable;
12 | import android.text.InputType;
13 | import android.util.AttributeSet;
14 | import android.view.Gravity;
15 | import android.view.KeyEvent;
16 | import android.view.LayoutInflater;
17 | import android.view.View;
18 | import android.view.ViewGroup;
19 | import android.view.WindowManager;
20 | import android.view.inputmethod.InputMethodManager;
21 | import android.widget.EditText;
22 | import android.widget.PopupWindow;
23 |
24 | import java.lang.reflect.Method;
25 | import java.util.List;
26 |
27 | /**
28 | * Description: 自定义KeyboardEditText
29 | * Created by zouyulong on 2017/7/26.
30 | * Email : zouyulong@syswin.com
31 | * Person in charge : zouyulong
32 | */
33 |
34 | public class CustomKeyboardEditText extends EditText implements KeyboardView.OnKeyboardActionListener,
35 | View.OnClickListener {
36 | private Keyboard mKeyboard;
37 | private KeyboardView mKeyboardView;
38 | private PopupWindow mKeyboardWindow;
39 | private View mDecorView;
40 |
41 | public CustomKeyboardEditText(Context context) {
42 | this(context, null);
43 | }
44 |
45 | public CustomKeyboardEditText(Context context, AttributeSet attrs) {
46 | this(context, attrs, 0);
47 | }
48 |
49 | public CustomKeyboardEditText(Context context, AttributeSet attrs, int defStyleAttr) {
50 | super(context, attrs, defStyleAttr);
51 | initKeyboardView(context, attrs);
52 | }
53 |
54 | private void initKeyboardView(Context context, AttributeSet attrs) {
55 | TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.Keyboard);
56 | if (!array.hasValue(R.styleable.Keyboard_xml)) {
57 | throw new IllegalArgumentException("you need add keyboard_xml argument!");
58 | }
59 | int xmlId = array.getResourceId(R.styleable.Keyboard_xml, 0);
60 | mKeyboard = new Keyboard(context, xmlId);
61 | mKeyboardView = (KeyboardView) LayoutInflater.from(context).inflate(R.layout.keyboard_view, null);
62 | //键盘关联keyboard对象
63 | mKeyboardView.setKeyboard(mKeyboard);
64 | //关闭键盘按键预览效果,如果按键过小可能会比较适用。
65 | mKeyboardView.setPreviewEnabled(false);
66 | //设置键盘事件
67 | mKeyboardView.setOnKeyboardActionListener(this);
68 | //将keyboardview放入popupwindow方便显示以及位置调整。
69 | mKeyboardWindow = new PopupWindow(mKeyboardView,
70 | ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
71 | array.recycle();
72 | //设置点击事件,点击后键盘弹起,系统键盘收起。
73 | setOnClickListener(this);
74 | //屏蔽当前edittext的系统键盘
75 | notSystemSoftInput();
76 | }
77 |
78 | @Override
79 | public void onPress(int primaryCode) {
80 |
81 | }
82 |
83 | @Override
84 | public void onRelease(int primaryCode) {
85 |
86 | }
87 |
88 | @Override
89 | public void onKey(int primaryCode, int[] keyCodes) {
90 | Editable editable = this.getText();
91 | //获取光标偏移量下标
92 | int startIndex = this.getSelectionStart();
93 | switch (primaryCode) {
94 | case Keyboard.KEYCODE_CANCEL:// 隐藏键盘
95 | hideKeyboard();
96 | break;
97 | case Keyboard.KEYCODE_DELETE:// 回退
98 | if (editable != null && editable.length() > 0) {
99 | if (startIndex > 0) {
100 | editable.delete(startIndex - 1, startIndex);
101 | }
102 | }
103 | break;
104 | case 9994://左移
105 | setSelection(startIndex-1);
106 | break;
107 | case 9995://重输
108 | editable.clear();
109 | break;
110 | case 9996://右移
111 | if (startIndex < length()) {
112 | setSelection(startIndex + 1);
113 | }
114 | break;
115 | default:
116 | editable.insert(startIndex, Character.toString((char) primaryCode));
117 | break;
118 | }
119 | }
120 |
121 | @Override
122 | public void onText(CharSequence text) {
123 |
124 | }
125 |
126 | @Override
127 | public void swipeLeft() {
128 |
129 | }
130 |
131 | @Override
132 | public void swipeRight() {
133 |
134 | }
135 |
136 | @Override
137 | public void swipeDown() {
138 |
139 | }
140 |
141 | @Override
142 | public void swipeUp() {
143 |
144 | }
145 |
146 | /**
147 | * 根据key code 获取 Keyboard.Key 对象
148 | * @param primaryCode
149 | * @return
150 | */
151 | private Keyboard.Key getKeyByKeyCode(int primaryCode) {
152 | if(null != mKeyboard){
153 | List keyList = mKeyboard.getKeys();
154 | for (int i =0,size= keyList.size(); i < size; i++) {
155 | Keyboard.Key key = keyList.get(i);
156 |
157 | int codes[] = key.codes;
158 |
159 | if(codes[0] == primaryCode){
160 | return key;
161 | }
162 | }
163 | }
164 |
165 | return null;
166 | }
167 |
168 | @Override
169 | public boolean onKeyDown(int keyCode, KeyEvent event) {
170 | if (keyCode == KeyEvent.KEYCODE_BACK) {
171 | if (null != mKeyboardWindow) {
172 | if (mKeyboardWindow.isShowing()) {
173 | mKeyboardWindow.dismiss();
174 | return true;
175 | }
176 | }
177 | }
178 | return super.onKeyDown(keyCode, event);
179 | }
180 |
181 | @SuppressLint("MissingSuperCall")
182 | @Override
183 | protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
184 | if (!focused) {
185 | hideKeyboard();
186 | } else {
187 | hideSysInput();
188 | showKeyboard();
189 | }
190 | super.onFocusChanged(focused, direction, previouslyFocusedRect);
191 | }
192 |
193 | @Override
194 | public void onAttachedToWindow() {
195 | super.onAttachedToWindow();
196 | this.mDecorView = ((Activity) getContext()).getWindow().getDecorView();
197 | hideSysInput();
198 | }
199 |
200 | @Override
201 | public void onDetachedFromWindow() {
202 | super.onDetachedFromWindow();
203 | hideKeyboard();
204 | mKeyboardWindow = null;
205 | mKeyboardView = null;
206 | mKeyboard = null;
207 | mDecorView = null;
208 | }
209 |
210 | /**
211 | * 显示自定义键盘
212 | */
213 | private void showKeyboard() {
214 | if (null != mKeyboardWindow) {
215 | if (!mKeyboardWindow.isShowing()) {
216 | mKeyboardView.setKeyboard(mKeyboard);
217 | mKeyboardWindow.showAtLocation(this.mDecorView, Gravity.BOTTOM, 0, 0);
218 | }
219 | }
220 | }
221 |
222 | /**
223 | * 屏蔽系统输入法
224 | */
225 | private void notSystemSoftInput(){
226 | if (Build.VERSION.SDK_INT <= 10) {
227 | setInputType(InputType.TYPE_NULL);
228 | } else {
229 | ((Activity)getContext()).getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
230 | try {
231 | Class cls = EditText.class;
232 | Method setShowSoftInputOnFocus = cls.getMethod("setShowSoftInputOnFocus", boolean.class);
233 | setShowSoftInputOnFocus.setAccessible(true);
234 | setShowSoftInputOnFocus.invoke(this, false);
235 | } catch (Exception e) {
236 | e.printStackTrace();
237 | }
238 | }
239 | }
240 |
241 | /**
242 | * 隐藏自定义键盘
243 | */
244 | private void hideKeyboard() {
245 | if (null != mKeyboardWindow) {
246 | if (mKeyboardWindow.isShowing()) {
247 | mKeyboardWindow.dismiss();
248 | }
249 | }
250 | }
251 |
252 | /**
253 | * 隐藏系统键盘
254 | */
255 | private void hideSysInput() {
256 | if (this.getWindowToken() != null) {
257 | InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
258 | imm.hideSoftInputFromWindow(this.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
259 | }
260 | }
261 |
262 | @Override
263 | public void onClick(View v) {
264 | requestFocus();
265 | requestFocusFromTouch();
266 | hideSysInput();
267 | showKeyboard();
268 | }
269 | }
270 |
--------------------------------------------------------------------------------
/customkeyboard/src/main/res/drawable/bg_keyboard_btn.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 | -
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/customkeyboard/src/main/res/layout/keyboard_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
--------------------------------------------------------------------------------
/customkeyboard/src/main/res/mipmap-xxxhdpi/keyboard_del.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyl409214686/CustomKeyboardView/cff6b2d660af2d1e49904d9a03b68136ac60c64a/customkeyboard/src/main/res/mipmap-xxxhdpi/keyboard_del.png
--------------------------------------------------------------------------------
/customkeyboard/src/main/res/values/attr.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/customkeyboard/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | CustomIdCardKeyboard
3 |
4 |
--------------------------------------------------------------------------------
/customkeyboard/src/main/res/xml/idcard_keyboard.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
14 |
17 |
18 |
19 |
22 |
25 |
28 |
29 |
30 |
33 |
36 |
39 |
40 |
41 |
45 |
48 |
52 |
53 |
--------------------------------------------------------------------------------
/customkeyboard/src/test/java/com/zyl/customkeyboardview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.zyl.customkeyboardview;
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 | }
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyl409214686/CustomKeyboardView/cff6b2d660af2d1e49904d9a03b68136ac60c64a/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Jul 26 15:57:50 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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':customkeyboard'
2 |
--------------------------------------------------------------------------------