diff --git a/.gitignore b/.gitignore
index c6cbe56..3c117df 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,8 +1,65 @@
+# Built application files
+*.apk
+*.ap_
+
+# Files for the ART/Dalvik VM
+*.dex
+
+# Java class files
+*.class
+
+# Generated files
+bin/
+gen/
+out/
+
+# Gradle files
+.gradle/
+build/
+
+# Local configuration file (sdk path, etc)
+local.properties
+
+# Proguard folder generated by Eclipse
+proguard/
+
+# Log Files
+*.log
+
+# Android Studio Navigation editor temp files
+.navigation/
+
+# Android Studio captures folder
+captures/
+
+# IntelliJ
*.iml
-.gradle
-/local.properties
-/.idea/workspace.xml
-/.idea/libraries
-.DS_Store
-/build
-/captures
+.idea/workspace.xml
+.idea/tasks.xml
+.idea/gradle.xml
+.idea/assetWizardSettings.xml
+.idea/dictionaries
+.idea/libraries
+.idea/caches
+
+# Keystore files
+# Uncomment the following line if you do not want to check your keystore files in.
+#*.jks
+
+# External native build folder generated in Android Studio 2.2 and later
+.externalNativeBuild
+
+# Google Services (e.g. APIs or Firebase)
+google-services.json
+
+# Freeline
+freeline.py
+freeline/
+freeline_project_description.json
+
+# fastlane
+fastlane/report.xml
+fastlane/Preview.html
+fastlane/screenshots
+fastlane/test_output
+fastlane/readme.md
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 7940f80..dd59338 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -1,5 +1,6 @@
+ android:theme="@style/AppTheme"
+ tools:ignore="GoogleAppIndexingWarning">
@@ -15,9 +17,8 @@
-
-
-
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/example/keybord/keyborddemo/MainActivity.java b/app/src/main/java/com/example/keybord/keyborddemo/MainActivity.java
index a2abf9d..5c75d55 100644
--- a/app/src/main/java/com/example/keybord/keyborddemo/MainActivity.java
+++ b/app/src/main/java/com/example/keybord/keyborddemo/MainActivity.java
@@ -24,7 +24,7 @@ protected void onListItemClick(ListView l, View v, int position, long id) {
startActivity(SystemKeyboardActivity.class);
break;
case 1:
- startActivity(SystemKeyboardEidtTextActivity.class);
+ startActivity(SystemKeyboardEditTextActivity.class);
break;
}
}
diff --git a/app/src/main/java/com/example/keybord/keyborddemo/SystemKeyboardActivity.java b/app/src/main/java/com/example/keybord/keyborddemo/SystemKeyboardActivity.java
index 3938778..ac555e2 100644
--- a/app/src/main/java/com/example/keybord/keyborddemo/SystemKeyboardActivity.java
+++ b/app/src/main/java/com/example/keybord/keyborddemo/SystemKeyboardActivity.java
@@ -13,8 +13,8 @@
import android.widget.Toast;
import com.jay.easykeyboard.SystemKeyboard;
-import com.jay.easykeyboard.action.IKeyBoardUI;
-import com.jay.easykeyboard.action.KeyBoardActionListence;
+import com.jay.easykeyboard.action.IKeyBoardUIChange;
+import com.jay.easykeyboard.action.KeyBoardActionListener;
import com.jay.easykeyboard.util.Util;
/**
@@ -34,11 +34,11 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_systemkeyboard);
mKeyboard = findViewById(R.id.systemkeyboard);
- Button btn_setkeyui = findViewById(R.id.btn_setkeyui);
+ Button btnChangeUi = findViewById(R.id.btn_change_ui);
EditText edit1 = findViewById(R.id.edit);
EditText edit2 = findViewById(R.id.edit2);
mKeyboard.setEditText(edit1); //用于绑定EditText,如果切换了EditText,请务必设置此方法
- mKeyboard.setOnKeyboardActionListener(new KeyBoardActionListence() {
+ mKeyboard.setOnKeyboardActionListener(new KeyBoardActionListener() {
@Override
public void onComplete() {
showShortToast("完成");
@@ -63,11 +63,11 @@ public void onClearAll() {
edit1.setOnFocusChangeListener(this);
edit2.setOnFocusChangeListener(this);
- btn_setkeyui.setOnClickListener(new View.OnClickListener() {
+ btnChangeUi.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//改变ui
- mKeyboard.setKeyboardUI(new IKeyBoardUI() {
+ mKeyboard.setKeyboardUI(new IKeyBoardUIChange() {
@Override
public Paint setPaint(Paint paint) {
paint.setColor(Color.BLUE);
@@ -82,7 +82,7 @@ public Paint setPaint(Paint paint) {
@Override
public void onClick(View v) {
isRandom = !isRandom;
- mKeyboard.setRandomkeys(isRandom);
+ mKeyboard.setRandomKeys(isRandom);
}
});
}
diff --git a/app/src/main/java/com/example/keybord/keyborddemo/SystemKeyboardEidtTextActivity.java b/app/src/main/java/com/example/keybord/keyborddemo/SystemKeyboardEditTextActivity.java
similarity index 74%
rename from app/src/main/java/com/example/keybord/keyborddemo/SystemKeyboardEidtTextActivity.java
rename to app/src/main/java/com/example/keybord/keyborddemo/SystemKeyboardEditTextActivity.java
index 1aac851..a04e44b 100644
--- a/app/src/main/java/com/example/keybord/keyborddemo/SystemKeyboardEidtTextActivity.java
+++ b/app/src/main/java/com/example/keybord/keyborddemo/SystemKeyboardEditTextActivity.java
@@ -1,17 +1,12 @@
package com.example.keybord.keyborddemo;
-import android.inputmethodservice.Keyboard;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
-import android.view.View;
-import android.widget.EditText;
-import android.widget.Toast;
import com.jay.easykeyboard.SystemKeyBoardEditText;
-import com.jay.easykeyboard.action.KeyBoardActionListence;
-import com.jay.easykeyboard.impl.SystemOnKeyboardActionListener;
+import com.jay.easykeyboard.action.KeyBoardActionListener;
/**
* Created by huangjie on 2018/2/6.
@@ -19,7 +14,7 @@
* 说明:附带EditText的popwindow形式弹出的键盘
*/
-public class SystemKeyboardEidtTextActivity extends AppCompatActivity implements KeyBoardActionListence {
+public class SystemKeyboardEditTextActivity extends AppCompatActivity implements KeyBoardActionListener {
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
diff --git a/app/src/main/res/layout/activity_systemkeyboard.xml b/app/src/main/res/layout/activity_systemkeyboard.xml
index ea2b63c..06a8909 100644
--- a/app/src/main/res/layout/activity_systemkeyboard.xml
+++ b/app/src/main/res/layout/activity_systemkeyboard.xml
@@ -25,7 +25,7 @@
diff --git a/app/src/main/res/layout/activity_systemkeyboardedittext.xml b/app/src/main/res/layout/activity_systemkeyboardedittext.xml
index 5e9750f..a77351a 100644
--- a/app/src/main/res/layout/activity_systemkeyboardedittext.xml
+++ b/app/src/main/res/layout/activity_systemkeyboardedittext.xml
@@ -1,28 +1,34 @@
-
+ android:layout_height="match_parent">
+
+ android:background="@drawable/edit_bg"
+ android:hint="顶部EditText(附加属性:点击外部区域消失)"
+ android:padding="10dp"
+ keyboard:keyDrawable="@drawable/btn_keyboard_key"
+ keyboard:outSideCancel="true"
+ keyboard:xmlLayoutResId="@xml/keyboard_numbers" />
+
-
+
diff --git a/build.gradle b/build.gradle
index a9607a3..1a0ac0f 100644
--- a/build.gradle
+++ b/build.gradle
@@ -7,7 +7,7 @@ buildscript {
maven { url 'https://jitpack.io' }
}
dependencies {
- classpath 'com.android.tools.build:gradle:3.0.0'
+ classpath 'com.android.tools.build:gradle:3.4.2'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0' // Add this line
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
diff --git a/easykeyboard/src/main/java/com/jay/easykeyboard/SystemKeyBoardEditText.java b/easykeyboard/src/main/java/com/jay/easykeyboard/SystemKeyBoardEditText.java
index 4fcda18..6c5376b 100644
--- a/easykeyboard/src/main/java/com/jay/easykeyboard/SystemKeyBoardEditText.java
+++ b/easykeyboard/src/main/java/com/jay/easykeyboard/SystemKeyBoardEditText.java
@@ -6,16 +6,17 @@
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.util.AttributeSet;
+import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.widget.EditText;
-import com.jay.easykeyboard.action.KeyBoardActionListence;
-import com.jay.easykeyboard.action.OnEditFocusChangeListence;
-import com.jay.easykeyboard.widget.KeyBoardEditText;
-import com.jay.easykeyboard.util.Util;
+import com.jay.easykeyboard.action.KeyBoardActionListener;
+import com.jay.easykeyboard.action.OnEditFocusChangeListener;
import com.jay.easykeyboard.impl.FormatTextWatcher;
import com.jay.easykeyboard.impl.SystemOnKeyboardActionListener;
+import com.jay.easykeyboard.util.Util;
+import com.jay.easykeyboard.widget.KeyBoardEditText;
/**
* Created by huangjie on 2018/2/4.
@@ -25,13 +26,13 @@
public class SystemKeyBoardEditText extends KeyBoardEditText {
private boolean enable = true; //是否启用自定义键盘
- private boolean focuable = true; //默认获取焦点
- private boolean outSideable = false; //点击外部区域是否隐藏键盘
- private SystemKeyboard systemKeyboard;
- private FormatTextWatcher textWatcher;
- private SystemOnKeyboardActionListener listener;
- private OnEditFocusChangeListence focusChangeListence;
- private int FOCUSTAB;
+ private boolean focusEnable = true; //默认获取焦点
+ private boolean outSideEnable = false; //点击外部区域是否隐藏键盘
+ private SystemKeyboard mSystemKeyboard;
+ private FormatTextWatcher mTextWatcher;
+ private SystemOnKeyboardActionListener mActionListener;
+ private OnEditFocusChangeListener mFocusChangeListener;
+ private int focusMark;
private static final int READY = 0X110;
private static final int STAR = 0X111;
@@ -49,17 +50,17 @@ public SystemKeyBoardEditText(Context context, AttributeSet attrs) {
public SystemKeyBoardEditText(final Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
- initListence();
+ initListener();
}
- private void initListence() {
+ private void initListener() {
setOnTouchListener(new OnTouchListener() {
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouch(View v, MotionEvent event) {
if (!isShowing()) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
- if (focuable) {
+ if (focusEnable) {
requestFocus();
requestFocusFromTouch();
if (enable) {
@@ -83,24 +84,24 @@ public boolean onTouch(View v, MotionEvent event) {
@Override
public void onFocusChange(View v, final boolean hasFocus) {
//根据焦点变化判断外部点击区域
- FOCUSTAB++;
+ focusMark++;
if (STATUE == READY) {
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
if (STATUE == STAR) {
- if (FOCUSTAB == 1 && !hasFocus && outSideable) {
+ if (focusMark == 1 && !hasFocus && outSideEnable) {
dismissKeyboardWindow();
}
STATUE = READY;
- FOCUSTAB = 0;
+ focusMark = 0;
}
}
}, 200);
STATUE = STAR;
}
- if (focusChangeListence != null) {
- focusChangeListence.OnFocusChangeListener(v, hasFocus);
+ if (mFocusChangeListener != null) {
+ mFocusChangeListener.OnFocusChangeListener(v, hasFocus);
}
}
});
@@ -108,27 +109,27 @@ public void run() {
private void init(Context context, AttributeSet attrs) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SystemKeyBoardEditText);
- boolean randomkeys = a.getBoolean(R.styleable.SystemKeyboard_isRandom, false);
+ outSideEnable = a.getBoolean(R.styleable.SystemKeyBoardEditText_outSideCancel, false);
int xmlLayoutResId = a.getResourceId(R.styleable.SystemKeyBoardEditText_xmlLayoutResId, 0);
- boolean isSpace = a.getBoolean(R.styleable.SystemKeyBoardEditText_space, false);
- outSideable = a.getBoolean(R.styleable.SystemKeyBoardEditText_outSideCancel, false);
- systemKeyboard = new SystemKeyboard(context);
- systemKeyboard.setXmlLayoutResId(xmlLayoutResId);
- if (a.hasValue(R.styleable.SystemKeyBoardEditText_keyViewbg)) {
- Drawable keyViewbg = a.getDrawable(R.styleable.SystemKeyBoardEditText_keyViewbg);
- systemKeyboard.setKeybgDrawable(keyViewbg);
+ mSystemKeyboard = new SystemKeyboard(context);
+ mSystemKeyboard.setXmlLayoutResId(xmlLayoutResId);
+ if (a.hasValue(R.styleable.SystemKeyBoardEditText_keyDrawable)) {
+ Drawable keyDrawable = a.getDrawable(R.styleable.SystemKeyBoardEditText_keyDrawable);
+ mSystemKeyboard.setKeyDrawable(keyDrawable);
}
- initPopWindow(systemKeyboard);
- listener = new SystemOnKeyboardActionListener();
- listener.setEditText(this);
- listener.setPopupWindow(getKeyboardWindow());
- systemKeyboard.getKeyboardView().setOnKeyboardActionListener(listener);
+ initPopWindow(mSystemKeyboard);
+ mActionListener = new SystemOnKeyboardActionListener();
+ mActionListener.setEditText(this);
+ mActionListener.setPopupWindow(getKeyboardWindow());
+ mSystemKeyboard.getKeyboardView().setOnKeyboardActionListener(mActionListener);
+ boolean isSpace = a.getBoolean(R.styleable.SystemKeyBoardEditText_space, false);
if (isSpace) {
- textWatcher = new FormatTextWatcher(this);
- addTextChangedListener(textWatcher);
+ mTextWatcher = new FormatTextWatcher(this);
+ addTextChangedListener(mTextWatcher);
}
- if (randomkeys) {
- systemKeyboard.setRandomkeys(true);
+ boolean randomKeys = a.getBoolean(R.styleable.SystemKeyboard_isRandom, false);
+ if (randomKeys) {
+ mSystemKeyboard.setRandomKeys(true);
}
setCursorVisible(true);
a.recycle();
@@ -136,7 +137,7 @@ private void init(Context context, AttributeSet attrs) {
public SystemKeyboard getSystemKeyboard() {
- return systemKeyboard;
+ return mSystemKeyboard;
}
/**
@@ -146,47 +147,59 @@ public SystemKeyboard getSystemKeyboard() {
*/
public void setSpaceEnable(boolean isSpace) {
if (isSpace) {
- if (textWatcher == null) {
- textWatcher = new FormatTextWatcher(this);
+ if (mTextWatcher == null) {
+ mTextWatcher = new FormatTextWatcher(this);
}
- addTextChangedListener(textWatcher);
+ addTextChangedListener(mTextWatcher);
} else {
- if (null != textWatcher) {
- removeTextChangedListener(textWatcher);
+ if (null != mTextWatcher) {
+ removeTextChangedListener(mTextWatcher);
}
}
}
+ /**
+ * 重写onKeyDown 当键盘弹出按回退键关闭
+ */
+ @Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ if (event.getKeyCode() == KeyEvent.KEYCODE_BACK
+ && getKeyboardWindow().isShowing()) {
+ dismissKeyboardWindow();
+ return true;
+ }
+ return super.onKeyDown(keyCode, event);
+ }
/**
* 设置键盘输入监听
*
* @param listener listence
*/
- public void setOnKeyboardActionListener(KeyBoardActionListence listener) {
- this.listener.setKeyActionListence(listener);
+ public void setOnKeyboardActionListener(KeyBoardActionListener listener) {
+ this.mActionListener.setKeyActionListener(listener);
}
/**
* 设置焦点
*
- * @param focuable focuable
+ * @param focusEnable focuable
*/
- public void setFocuable(boolean focuable) {
- this.focuable = focuable;
- setFocusable(focuable);
- setFocusableInTouchMode(focuable);
- setCursorVisible(focuable);
+ public void setFocusEnable(boolean focusEnable) {
+ this.focusEnable = focusEnable;
+ setFocusable(focusEnable);
+ setFocusableInTouchMode(focusEnable);
+ setCursorVisible(focusEnable);
}
/**
* 焦点监听
*
- * @param focusChangeListence listence
+ * @param focusChangeListener listence
*/
- public void setFocusChangeListence(OnEditFocusChangeListence focusChangeListence) {
- this.focusChangeListence = focusChangeListence;
+ public void setFocusChangeListener(OnEditFocusChangeListener focusChangeListener) {
+ this.mFocusChangeListener = focusChangeListener;
}
/**
@@ -194,12 +207,12 @@ public void setFocusChangeListence(OnEditFocusChangeListence focusChangeListence
*
* @param drawable drawable
*/
- public void setKeyViewBgDrawable(Drawable drawable) {
- if (systemKeyboard != null) systemKeyboard.setKeybgDrawable(drawable);
+ public void setKeyViewDrawable(Drawable drawable) {
+ if (mSystemKeyboard != null) mSystemKeyboard.setKeyDrawable(drawable);
}
- public void setRandomkeys(boolean isRandomkeys) {
- if (systemKeyboard != null) systemKeyboard.setRandomkeys(isRandomkeys);
+ public void setRandomKeys(boolean isRandomKeys) {
+ if (mSystemKeyboard != null) mSystemKeyboard.setRandomKeys(isRandomKeys);
}
/**
@@ -208,9 +221,9 @@ public void setRandomkeys(boolean isRandomkeys) {
* @param editText editText
*/
public void setEditText(EditText editText) {
- listener.setEditText(editText);
+ mActionListener.setEditText(editText);
if (editText instanceof SystemKeyBoardEditText) {
- listener.setPopupWindow(((SystemKeyBoardEditText) editText).getKeyboardWindow());
+ mActionListener.setPopupWindow(((SystemKeyBoardEditText) editText).getKeyboardWindow());
}
}
diff --git a/easykeyboard/src/main/java/com/jay/easykeyboard/SystemKeyboard.java b/easykeyboard/src/main/java/com/jay/easykeyboard/SystemKeyboard.java
index fc17e2b..1f6d966 100644
--- a/easykeyboard/src/main/java/com/jay/easykeyboard/SystemKeyboard.java
+++ b/easykeyboard/src/main/java/com/jay/easykeyboard/SystemKeyboard.java
@@ -12,8 +12,8 @@
import android.widget.EditText;
import android.widget.FrameLayout;
-import com.jay.easykeyboard.action.IKeyBoardUI;
-import com.jay.easykeyboard.action.KeyBoardActionListence;
+import com.jay.easykeyboard.action.IKeyBoardUIChange;
+import com.jay.easykeyboard.action.KeyBoardActionListener;
import com.jay.easykeyboard.bean.KeyModel;
import com.jay.easykeyboard.impl.SystemOnKeyboardActionListener;
import com.jay.easykeyboard.keyboard.MyKeyboardView;
@@ -34,7 +34,7 @@
public class SystemKeyboard extends FrameLayout {
private static final String TAG = "SystemKeyboard";
private MyKeyboardView keyboardView;
- private Drawable keybgDrawable;
+ private Drawable keyDrawable;
private Keyboard mKeyboard;
private SystemOnKeyboardActionListener actionListener;
private int xmlLayoutResId;
@@ -54,17 +54,17 @@ public SystemKeyboard(Context context, @Nullable AttributeSet attrs, int defStyl
private void init(Context context, @Nullable AttributeSet attrs) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SystemKeyboard);
- if (a.hasValue(R.styleable.SystemKeyboard_keyViewbg)) {
- keybgDrawable = a.getDrawable(R.styleable.SystemKeyboard_keyViewbg);
+ if (a.hasValue(R.styleable.SystemKeyboard_keyDrawable)) {
+ keyDrawable = a.getDrawable(R.styleable.SystemKeyboard_keyDrawable);
}
if (a.hasValue(R.styleable.SystemKeyboard_xmlLayoutResId)) {
xmlLayoutResId = a.getResourceId(R.styleable.SystemKeyboard_xmlLayoutResId, 0);
initKeyBoard(context, xmlLayoutResId);
}
if (a.hasValue(R.styleable.SystemKeyboard_isRandom)){
- boolean isRandow = a.getBoolean(R.styleable.SystemKeyboard_isRandom,false);
- if (isRandow){
- randomkey();
+ boolean isRandom = a.getBoolean(R.styleable.SystemKeyboard_isRandom,false);
+ if (isRandom){
+ randomKey();
}
}
a.recycle();
@@ -76,8 +76,8 @@ private void initKeyBoard(Context context, int xmlLayoutResId) {
keyboardView.setKeyboard(mKeyboard);
keyboardView.setEnabled(true);
keyboardView.setPreviewEnabled(false);
- if (null != keybgDrawable) {
- keyboardView.setKeybgDrawable(keybgDrawable);
+ if (null != keyDrawable) {
+ keyboardView.setKeyDrawable(keyDrawable);
}
actionListener = new SystemOnKeyboardActionListener();
keyboardView.setOnKeyboardActionListener(actionListener);
@@ -86,17 +86,17 @@ private void initKeyBoard(Context context, int xmlLayoutResId) {
}
- private void randomkey() {
+ private void randomKey() {
List keyList = mKeyboard.getKeys();
- List newkeyList = new ArrayList();
+ List newKeyList = new ArrayList();
for (int i = 0, size = keyList.size(); i < size; i++) {
Keyboard.Key key = keyList.get(i);
CharSequence label = key.label;
if (label != null && Util.isNumeric(label.toString())) {
- newkeyList.add(key);
+ newKeyList.add(key);
}
}
- int count = newkeyList.size();
+ int count = newKeyList.size();
List resultList = new ArrayList();
LinkedList temp = new LinkedList();
for (int i = 0; i < count; i++) {
@@ -107,14 +107,14 @@ private void randomkey() {
for (int i = 0; i < count; i++) {
int num = rand.nextInt(count - i);
KeyModel model = temp.get(num);
- resultList.add(new KeyModel(model.getCode(), model.getLable()));
+ resultList.add(new KeyModel(model.getCode(), model.getLabel()));
temp.remove(num);
}
- for (int i = 0, size = newkeyList.size(); i < size; i++) {
- Keyboard.Key newKey = newkeyList.get(i);
- KeyModel resultmodle = resultList.get(i);
- newKey.label = resultmodle.getLable();
- newKey.codes[0] = resultmodle.getCode();
+ for (int i = 0; i < count; i++) {
+ Keyboard.Key newKey = newKeyList.get(i);
+ KeyModel resultModel = resultList.get(i);
+ newKey.label = resultModel.getLabel();
+ newKey.codes[0] = resultModel.getCode();
}
keyboardView.setKeyboard(mKeyboard);
}
@@ -140,11 +140,11 @@ public void setXmlLayoutResId(int xmlLayoutResId) {
/**
* 设置随机数字键盘
- * @param isRandomkeys 是否随机,再次设置为false则恢复正常
+ * @param isRandomKeys 是否随机,再次设置为false则恢复正常
*/
- public void setRandomkeys(boolean isRandomkeys) {
- if (isRandomkeys){
- randomkey();
+ public void setRandomKeys(boolean isRandomKeys) {
+ if (isRandomKeys){
+ randomKey();
}else {
mKeyboard = new Keyboard(getContext(), xmlLayoutResId);
keyboardView.setKeyboard(mKeyboard);
@@ -154,12 +154,12 @@ public void setRandomkeys(boolean isRandomkeys) {
/**
* 设置按压背景,线条粗细等
- * @param keybgDrawable d
+ * @param keyDrawable d
*/
- public void setKeybgDrawable(Drawable keybgDrawable) {
- this.keybgDrawable = keybgDrawable;
+ public void setKeyDrawable(Drawable keyDrawable) {
+ this.keyDrawable = keyDrawable;
if (null != keyboardView)
- keyboardView.setKeybgDrawable(keybgDrawable);
+ keyboardView.setKeyDrawable(keyDrawable);
}
@@ -180,6 +180,7 @@ public void setEditText(@NonNull EditText editText) {
* @param isOpenNativeKeyBoard 是否打开原生键盘
*/
public void setEditText(@NonNull EditText editText, boolean isOpenNativeKeyBoard) {
+ Util.checkNull(actionListener,"Please check if xmlLayoutResId is set");
actionListener.setEditText(editText);
if (isOpenNativeKeyBoard) {
Util.showKeyboard(editText);
@@ -196,15 +197,15 @@ public void setEditText(@NonNull EditText editText, boolean isOpenNativeKeyBoard
* 设置键盘输入监听
* @param listener l
*/
- public void setOnKeyboardActionListener(KeyBoardActionListence listener) {
- actionListener.setKeyActionListence(listener);
+ public void setOnKeyboardActionListener(KeyBoardActionListener listener) {
+ actionListener.setKeyActionListener(listener);
}
/**
* 设置ui监听
* @param ui u
*/
- public void setKeyboardUI(IKeyBoardUI ui) {
+ public void setKeyboardUI(IKeyBoardUIChange ui) {
if (null != ui) {
keyboardView.setPaint(ui.setPaint(keyboardView.getPaint()));
}
diff --git a/easykeyboard/src/main/java/com/jay/easykeyboard/action/IKeyBoardUI.java b/easykeyboard/src/main/java/com/jay/easykeyboard/action/IKeyBoardUIChange.java
similarity index 82%
rename from easykeyboard/src/main/java/com/jay/easykeyboard/action/IKeyBoardUI.java
rename to easykeyboard/src/main/java/com/jay/easykeyboard/action/IKeyBoardUIChange.java
index d30d3d6..016218f 100644
--- a/easykeyboard/src/main/java/com/jay/easykeyboard/action/IKeyBoardUI.java
+++ b/easykeyboard/src/main/java/com/jay/easykeyboard/action/IKeyBoardUIChange.java
@@ -6,6 +6,6 @@
* Created by hj on 2018/12/17.
* 说明:ui样式接口实现
*/
-public interface IKeyBoardUI {
+public interface IKeyBoardUIChange {
Paint setPaint(Paint paint);
}
diff --git a/easykeyboard/src/main/java/com/jay/easykeyboard/action/KeyBoardActionListence.java b/easykeyboard/src/main/java/com/jay/easykeyboard/action/KeyBoardActionListener.java
similarity index 88%
rename from easykeyboard/src/main/java/com/jay/easykeyboard/action/KeyBoardActionListence.java
rename to easykeyboard/src/main/java/com/jay/easykeyboard/action/KeyBoardActionListener.java
index 3887728..a861dbd 100644
--- a/easykeyboard/src/main/java/com/jay/easykeyboard/action/KeyBoardActionListence.java
+++ b/easykeyboard/src/main/java/com/jay/easykeyboard/action/KeyBoardActionListener.java
@@ -6,7 +6,7 @@
* Created by hj on 2018/12/17.
* 说明:键盘输入监听
*/
-public interface KeyBoardActionListence {
+public interface KeyBoardActionListener {
void onComplete(); //完成点击
void onTextChange(Editable editable); //文本改变
diff --git a/easykeyboard/src/main/java/com/jay/easykeyboard/action/OnEditFocusChangeListence.java b/easykeyboard/src/main/java/com/jay/easykeyboard/action/OnEditFocusChangeListener.java
similarity index 86%
rename from easykeyboard/src/main/java/com/jay/easykeyboard/action/OnEditFocusChangeListence.java
rename to easykeyboard/src/main/java/com/jay/easykeyboard/action/OnEditFocusChangeListener.java
index 21cdfd6..4ccbba1 100644
--- a/easykeyboard/src/main/java/com/jay/easykeyboard/action/OnEditFocusChangeListence.java
+++ b/easykeyboard/src/main/java/com/jay/easykeyboard/action/OnEditFocusChangeListener.java
@@ -6,6 +6,6 @@
* Created by hj on 2018/12/17.
* 说明:由于使用了OnFocusChangeListener接口,如果项目中需要使用到可以使用这个接口
*/
-public interface OnEditFocusChangeListence {
+public interface OnEditFocusChangeListener {
void OnFocusChangeListener(View v, boolean hasFocus);
}
diff --git a/easykeyboard/src/main/java/com/jay/easykeyboard/bean/KeyModel.java b/easykeyboard/src/main/java/com/jay/easykeyboard/bean/KeyModel.java
index c9ca659..fb6180a 100644
--- a/easykeyboard/src/main/java/com/jay/easykeyboard/bean/KeyModel.java
+++ b/easykeyboard/src/main/java/com/jay/easykeyboard/bean/KeyModel.java
@@ -5,16 +5,16 @@
*/
public class KeyModel {
- public KeyModel(int code,String lable){
+ public KeyModel(int code,String label){
this.code = code;
- this.lable = lable;
+ this.label = label;
}
- private String lable;
+ private String label;
private int code;
- public String getLable() {
- return lable;
+ public String getLabel() {
+ return label;
}
public int getCode() {
diff --git a/easykeyboard/src/main/java/com/jay/easykeyboard/impl/FormatTextWatcher.java b/easykeyboard/src/main/java/com/jay/easykeyboard/impl/FormatTextWatcher.java
index 939b763..852a4e4 100644
--- a/easykeyboard/src/main/java/com/jay/easykeyboard/impl/FormatTextWatcher.java
+++ b/easykeyboard/src/main/java/com/jay/easykeyboard/impl/FormatTextWatcher.java
@@ -24,7 +24,6 @@ public FormatTextWatcher(EditText editText){
private String tag = " ";
private int beforeTextLength = 0;
private int afterTextLength = 0;
- private int location = 0;//记录光标的位置
private boolean isChanging = false;// 是否更换中
@Override
@@ -39,6 +38,7 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
@Override
public void afterTextChanged(Editable s) {
+ int location;
afterTextLength = s.length();
if (isChanging)
return;
diff --git a/easykeyboard/src/main/java/com/jay/easykeyboard/impl/SystemOnKeyboardActionListener.java b/easykeyboard/src/main/java/com/jay/easykeyboard/impl/SystemOnKeyboardActionListener.java
index c52d66b..48e6471 100644
--- a/easykeyboard/src/main/java/com/jay/easykeyboard/impl/SystemOnKeyboardActionListener.java
+++ b/easykeyboard/src/main/java/com/jay/easykeyboard/impl/SystemOnKeyboardActionListener.java
@@ -3,13 +3,10 @@
import android.inputmethodservice.Keyboard;
import android.inputmethodservice.KeyboardView;
import android.text.Editable;
-import android.util.Log;
import android.widget.EditText;
import android.widget.PopupWindow;
-import com.jay.easykeyboard.action.KeyBoardActionListence;
-
-import static android.inputmethodservice.Keyboard.KEYCODE_DONE;
+import com.jay.easykeyboard.action.KeyBoardActionListener;
/**
* Created by huangjie on 2018/2/3.
@@ -21,7 +18,7 @@ public class SystemOnKeyboardActionListener implements KeyboardView.OnKeyboardAc
private EditText editText;
private PopupWindow popupWindow;
- private KeyBoardActionListence listence;
+ private KeyBoardActionListener mActionListener;
public void setEditText(EditText editText) {
this.editText = editText;
@@ -31,8 +28,8 @@ public void setPopupWindow(PopupWindow popupWindow) {
this.popupWindow = popupWindow;
}
- public void setKeyActionListence(KeyBoardActionListence listence){
- this.listence = listence;
+ public void setKeyActionListener(KeyBoardActionListener listener){
+ this.mActionListener = listener;
}
@Override
@@ -52,20 +49,20 @@ public void onKey(int primaryCode, int[] keyCodes) {
if (null != popupWindow && popupWindow.isShowing()) {
popupWindow.dismiss();
}
- listence.onComplete();
+ mActionListener.onComplete();
} else if (primaryCode == Keyboard.KEYCODE_DELETE) {// 回退
if (editable != null && editable.length() > 0) {
if (start > 0) {
editable.delete(start - 1, start);
}
}
- listence.onClear();
+ mActionListener.onClear();
} else if (primaryCode == 152) {
editable.clear();
- listence.onClearAll();
+ mActionListener.onClearAll();
}else {
editable.insert(start, Character.toString((char) primaryCode));
- listence.onTextChange(editable);
+ mActionListener.onTextChange(editable);
}
}
}
diff --git a/easykeyboard/src/main/java/com/jay/easykeyboard/keyboard/MyKeyboardView.java b/easykeyboard/src/main/java/com/jay/easykeyboard/keyboard/MyKeyboardView.java
index 5f42fbd..242338e 100644
--- a/easykeyboard/src/main/java/com/jay/easykeyboard/keyboard/MyKeyboardView.java
+++ b/easykeyboard/src/main/java/com/jay/easykeyboard/keyboard/MyKeyboardView.java
@@ -15,7 +15,7 @@
//核心类,承担绘制工作
public class MyKeyboardView extends KeyboardView {
- private Drawable mKeybgDrawable;
+ private Drawable mKeyDrawable;
private Rect rect;
private Paint paint;
@@ -39,8 +39,8 @@ private void initResources(Context context) {
paint.setColor(res.getColor(android.R.color.black));
}
- public void setKeybgDrawable(Drawable mKeybgDrawable){
- this.mKeybgDrawable = mKeybgDrawable;
+ public void setKeyDrawable(Drawable mKeyDrawable){
+ this.mKeyDrawable = mKeyDrawable;
invalidate();
}
@@ -61,40 +61,40 @@ public void onDraw(Canvas canvas) {
List keys = getKeyboard().getKeys();
for (Key key : keys) {
canvas.save();
- int offsety = 0;
+ int offsetY = 0;
if (key.y == 0) {
- offsety = 1;
+ offsetY = 1;
}
- int initdrawy = key.y + offsety;
- if (mKeybgDrawable!=null) {
+ int drawY = key.y + offsetY;
+ if (mKeyDrawable!=null) {
rect.left = key.x;
- rect.top = initdrawy;
+ rect.top = drawY;
rect.right = key.x + key.width;
rect.bottom = key.y + key.height;
canvas.clipRect(rect);
int[] state = key.getCurrentDrawableState();
//设置按压效果
- mKeybgDrawable.setState(state);
+ mKeyDrawable.setState(state);
//设置边距
- mKeybgDrawable.setBounds(rect);
- mKeybgDrawable.draw(canvas);
+ mKeyDrawable.setBounds(rect);
+ mKeyDrawable.draw(canvas);
}
if (key.label != null) {
canvas.drawText(
key.label.toString(),
key.x + (key.width / 2),
- initdrawy + (key.height + paint.getTextSize() - paint.descent()) / 2,
+ drawY + (key.height + paint.getTextSize() - paint.descent()) / 2,
paint);
} else if (key.icon != null) {
- int intriWidth = key.icon.getIntrinsicWidth();
- int intriHeight = key.icon.getIntrinsicHeight();
+ int intrinsicWidth = key.icon.getIntrinsicWidth();
+ int intrinsicHeight = key.icon.getIntrinsicHeight();
- final int drawableX = key.x + (key.width - intriWidth) / 2;
- final int drawableY = initdrawy + (key.height - intriHeight) / 2;
+ final int drawableX = key.x + (key.width - intrinsicWidth) / 2;
+ final int drawableY = drawY + (key.height - intrinsicHeight) / 2;
key.icon.setBounds(
- drawableX, drawableY, drawableX + intriWidth,
- drawableY + intriHeight);
+ drawableX, drawableY, drawableX + intrinsicWidth,
+ drawableY + intrinsicHeight);
key.icon.draw(canvas);
}
diff --git a/easykeyboard/src/main/java/com/jay/easykeyboard/util/Util.java b/easykeyboard/src/main/java/com/jay/easykeyboard/util/Util.java
index eda00ed..bb281e7 100644
--- a/easykeyboard/src/main/java/com/jay/easykeyboard/util/Util.java
+++ b/easykeyboard/src/main/java/com/jay/easykeyboard/util/Util.java
@@ -3,9 +3,6 @@
import android.app.Activity;
import android.content.Context;
import android.os.Build;
-import android.support.v7.widget.AppCompatEditText;
-import android.support.v7.widget.AppCompatImageView;
-import android.text.InputType;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.View;
@@ -15,8 +12,6 @@
import java.lang.reflect.Field;
import java.lang.reflect.Method;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
/**
* Created by huangjie on 2018/2/3.
@@ -155,4 +150,10 @@ public static int getStatusBarHeight(Context context) {
return sbar;
}
+
+ public static void checkNull(Object object, String info) {
+ if (object == null) {
+ throw new NullPointerException(info);
+ }
+ }
}
diff --git a/easykeyboard/src/main/java/com/jay/easykeyboard/widget/KeyBoardEditText.java b/easykeyboard/src/main/java/com/jay/easykeyboard/widget/KeyBoardEditText.java
index 9b9d4bc..437c034 100644
--- a/easykeyboard/src/main/java/com/jay/easykeyboard/widget/KeyBoardEditText.java
+++ b/easykeyboard/src/main/java/com/jay/easykeyboard/widget/KeyBoardEditText.java
@@ -29,7 +29,7 @@ public abstract class KeyBoardEditText extends AppCompatEditText {
private PopupWindow mKeyboardWindow;
private View mDecorView;
private View mContentView;
- private int scrolldis;
+ private int mDifference;
public KeyBoardEditText(Context context) {
@@ -66,10 +66,9 @@ protected void initPopWindow(View contentView) {
mKeyboardWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
- // TODO Auto-generated method stub
- if (scrolldis > 0) {
- int temp = scrolldis;
- scrolldis = 0;
+ if (mDifference > 0) {
+ int temp = mDifference;
+ mDifference = 0;
if (null != mContentView) {
mContentView.scrollBy(0, -temp);
}
@@ -109,9 +108,9 @@ public void run() {
Rect outRect = new Rect();
mDecorView.getWindowVisibleDisplayFrame(outRect);
int screen = realHeight;
- scrolldis = (int) ((pos[1] + getMeasuredHeight() - outRect.top) - (screen - height));
- if (scrolldis > 0) {
- mContentView.scrollBy(0, scrolldis);
+ mDifference = (int) ((pos[1] + getMeasuredHeight() - outRect.top) - (screen - height));
+ if (mDifference > 0) {
+ mContentView.scrollBy(0, mDifference);
}
}
});
diff --git a/easykeyboard/src/main/res/values/attrs.xml b/easykeyboard/src/main/res/values/attrs.xml
index 0fb84b8..3c366f4 100644
--- a/easykeyboard/src/main/res/values/attrs.xml
+++ b/easykeyboard/src/main/res/values/attrs.xml
@@ -2,15 +2,15 @@
-
+
-
+
-
+
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 0276e61..b125b84 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip