diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 0b842cf..19373ea 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -10,8 +10,10 @@ + diff --git a/.idea/misc.xml b/.idea/misc.xml index 5d19981..ba7052b 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,8 +1,5 @@ - - - - - - - - - - - - - - + diff --git a/.idea/modules.xml b/.idea/modules.xml index 1dab95f..f53e639 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,8 +2,9 @@ - + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 401bb48..94a25f7 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index b320158..b780b88 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,12 +1,12 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 24 - buildToolsVersion "25.0.0" + compileSdkVersion 26 + buildToolsVersion "26.0.2" defaultConfig { applicationId "com.example.keybord.keyborddemo" minSdkVersion 19 - targetSdkVersion 24 + targetSdkVersion 26 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -20,6 +20,9 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:appcompat-v7:24.2.1' + implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation 'com.android.support:appcompat-v7:26.1.0' + implementation 'com.android.support:recyclerview-v7:26.1.0' + implementation 'com.android.support.constraint:constraint-layout:1.0.2' + implementation project(':easykeyboard') } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 95193c6..7940f80 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,20 +1,23 @@ + package="com.example.keybord.keyborddemo"> - + android:theme="@style/AppTheme"> + + + + \ 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 b48f5d3..a2abf9d 100644 --- a/app/src/main/java/com/example/keybord/keyborddemo/MainActivity.java +++ b/app/src/main/java/com/example/keybord/keyborddemo/MainActivity.java @@ -1,13 +1,35 @@ package com.example.keybord.keyborddemo; -import android.support.v7.app.AppCompatActivity; +import android.app.ListActivity; +import android.content.Intent; import android.os.Bundle; +import android.view.View; +import android.widget.ArrayAdapter; +import android.widget.ListView; -public class MainActivity extends AppCompatActivity { - +public class MainActivity extends ListActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); + String type[] = new String[] {"SystemKeyboard","SystemKeyBoardEditText"}; + ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, type); + setListAdapter(adapter); + } + + @Override + protected void onListItemClick(ListView l, View v, int position, long id) { + super.onListItemClick(l, v, position, id); + switch (position){ + case 0: + startActivity(SystemKeyboardActivity.class); + break; + case 1: + startActivity(SystemKeyboardEidtTextActivity.class); + break; + } + } + + private void startActivity(Class c){ + startActivity(new Intent(this,c)); } } diff --git a/app/src/main/java/com/example/keybord/keyborddemo/MyKeyboard.java b/app/src/main/java/com/example/keybord/keyborddemo/MyKeyboard.java deleted file mode 100644 index 31c110d..0000000 --- a/app/src/main/java/com/example/keybord/keyborddemo/MyKeyboard.java +++ /dev/null @@ -1,690 +0,0 @@ -/** - * - */ -package com.example.keybord.keyborddemo; - -import android.annotation.TargetApi; -import android.app.Activity; -import android.content.Context; -import android.content.res.TypedArray; -import android.graphics.Rect; -import android.inputmethodservice.Keyboard; -import android.inputmethodservice.Keyboard.Key; -import android.inputmethodservice.KeyboardView; -import android.inputmethodservice.KeyboardView.OnKeyboardActionListener; -import android.os.Build; -import android.os.SystemClock; -import android.text.Editable; -import android.text.TextWatcher; -import android.util.AttributeSet; -import android.util.DisplayMetrics; -import android.view.ActionMode; -import android.view.Display; -import android.view.Gravity; -import android.view.KeyEvent; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuItem; -import android.view.MotionEvent; -import android.view.View; -import android.view.ViewGroup; -import android.view.Window; -import android.view.WindowManager; -import android.view.animation.Animation; -import android.view.animation.AnimationUtils; -import android.view.animation.TranslateAnimation; -import android.view.inputmethod.EditorInfo; -import android.view.inputmethod.InputMethodManager; -import android.widget.EditText; -import android.widget.PopupWindow; -import android.widget.PopupWindow.OnDismissListener; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.security.SecureRandom; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.Random; -import java.util.Timer; -import java.util.TimerTask; - -/** - * 自定义键盘,有按下效果 - * 现在只添加了身份证输入的键盘布局,想要其余的请自行添加 - */ -public class MyKeyboard extends EditText implements OnKeyboardActionListener { - - private KeyboardView mKeyboardView; - private Keyboard mKeyboard; - - private Window mWindow; - private View mDecorView; - private View mContentView; - - private PopupWindow mKeyboardWindow; - - private boolean needcustomkeyboard = true; //是否启用自定义键盘 - private boolean randomkeys = false; //数字按键是否随机 - - private int scrolldis = 0; //输入框在键盘被弹出时,要被推上去的距离 - - public static int screenw = -1;//未知宽高 - public static int screenh = -1; - public static int screenh_nonavbar = -1; //不包含导航栏的高度 - public static int real_scontenth = -1; //实际内容高度, 计算公式:屏幕高度-导航栏高度-电量栏高度 - - public static float density = 1.0f; - public static int densityDpi = 160; - public boolean isSpace = false; //是否开启输入自动空格 - - private boolean isHide = true; - /** - * 位数 - */ - private int unit = 4; - /** - * 标识符 - */ - private String tag = " "; - - /** - * @param context - * @param attrs - */ - public MyKeyboard(Context context, AttributeSet attrs) { - super(context, attrs); - initAttributes(context); - initKeyboard(context, attrs); - } - - /** - * @param context - * @param attrs - * @param defStyle - */ - public MyKeyboard(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - initAttributes(context); - initKeyboard(context, attrs); - } - - private void initKeyboard(Context context, AttributeSet attrs) { - - TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.keyboard); - - if (a.hasValue(R.styleable.keyboard_xml)) { - needcustomkeyboard = true; - - int xmlid = a.getResourceId(R.styleable.keyboard_xml, 0); - - mKeyboard = new Keyboard(context, xmlid); - mKeyboardView = (KeyboardView) LayoutInflater.from(context).inflate(R.layout.mykeyboardview, null); - if (a.hasValue(R.styleable.keyboard_randomkeys)) { - boolean random = a.getBoolean(R.styleable.keyboard_randomkeys, false); - randomkeys = random; - - if (random) { - randomdigkey(mKeyboard); - } - } - - if (a.hasValue(R.styleable.keyboard_space)) { - isSpace = a.getBoolean(R.styleable.keyboard_space, false); - } - if (isSpace) { - addTextChangedListener(new FormatTextWatcher()); - } - - setOnFocusChangeListener(new OnFocusChangeListener() { //这里是解决那个点别的Edittext弹出系统键盘此键盘不消失的bug - @Override - public void onFocusChange(View v, boolean hasFocus) { - if (!hasFocus){ - hideKeyboard(); - } - } - }); - mKeyboardView.setKeyboard(mKeyboard); - mKeyboardView.setEnabled(true); - mKeyboardView.setPreviewEnabled(false); - mKeyboardView.setOnKeyboardActionListener(this); - - mKeyboardWindow = new PopupWindow(mKeyboardView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); - mKeyboardWindow.setAnimationStyle(R.style.AnimationFade); - mKeyboardWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); - mKeyboardWindow.setOnDismissListener(new OnDismissListener() { - - @Override - public void onDismiss() { - // TODO Auto-generated method stub - if (scrolldis > 0) { - int temp = scrolldis; - scrolldis = 0; - if (null != mContentView) { - mContentView.scrollBy(0, -temp); - } - } - } - }); - } else { - needcustomkeyboard = false; - } - - a.recycle(); - - } - - private void showKeyboard() { - if (null != mKeyboardWindow) { - if (!mKeyboardWindow.isShowing()) { - if (randomkeys) { - randomdigkey(mKeyboard); - } - - mKeyboardView.setKeyboard(mKeyboard); - - mKeyboardWindow.showAtLocation(this.mDecorView, Gravity.BOTTOM, 0, 0); -// mKeyboardWindow.update(); - - - if (null != mDecorView && null != mContentView) { - int[] pos = new int[2]; - getLocationOnScreen(pos); - float height = dpToPx(getContext(), 240); - - Rect outRect = new Rect(); - mDecorView.getWindowVisibleDisplayFrame(outRect); - - int screen = real_scontenth; - scrolldis = (int) ((pos[1] + getMeasuredHeight() - outRect.top) - (screen - height)); - - if (scrolldis > 0) { - mContentView.scrollBy(0, scrolldis); - } - } - - } - } - } - - private void hideKeyboard() { - if (null != mKeyboardWindow) { - if (mKeyboardWindow.isShowing()) { - mKeyboardWindow.dismiss(); - } - } - } - - private void hideSysInput() { - if (this.getWindowToken() != null) { - InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); - imm.hideSoftInputFromWindow(this.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); - } - } - - - class FormatTextWatcher implements TextWatcher { - - int beforeTextLength = 0; - int afterTextLength = 0; - int location = 0;// 记录光标的位置 - boolean isChanging = false;// 是否更换中 - - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - beforeTextLength = s.length(); - } - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - - } - - @Override - public void afterTextChanged(Editable s) { - afterTextLength = s.length(); - - if (isChanging) - return; - - if (beforeTextLength < afterTextLength) {// 字符增加 - location = getSelectionEnd(); - setFormatText(s.toString()); - if (location % (unit + 1) == 0) { - setSelection(getLocation(location + 1)); - } else { - setSelection(getLocation(location)); - } - } else if (beforeTextLength > afterTextLength) {// 字符减少 - location = getSelectionEnd(); - setFormatText(s.toString()); - if (location % (unit + 1) == 0) { - setSelection(getLocation(location - 1)); - } else { - setSelection(getLocation(location)); - } - } - } - - private int getLocation(int location) { - if (location < 0) - return 0; - if (location > afterTextLength) { - return afterTextLength; - } - return location; - } - - private void setFormatText(String str) { - isChanging = true; - setText(addTag(str)); - isChanging = false; - } - - /** - * 加上标识符 - * - * @param str - * @return - */ - private String addTag(String str) { - str = replaceTag(str); - StringBuilder sb = new StringBuilder(); - int index = 0; - int strLength = str.length(); - while (index < strLength) { - int increment = index + unit; - sb.append(str.subSequence(index, index = (increment > strLength) ? strLength : increment)); - if (increment < strLength) { - sb.append(tag); - } - } - return sb.toString(); - } - } - - /** - * 清除标识符 - * - * @param str - * @return - */ - public String replaceTag(String str) { - if (str.indexOf(tag) != -1) { - str = str.replace(tag, ""); - } - return str; - } - - @Override - public String toString() { - return replaceTag(getText().toString()); - } - - - @Override - public boolean onTouchEvent(MotionEvent event) { - super.onTouchEvent(event); - if (isHide){ - requestFocus(); - requestFocusFromTouch(); - - if (needcustomkeyboard) { - hideSysInput(); - showKeyboard(); - } - }else{ - hideKeyboard(); - hideSysInput(); - } - - return true; - } - - - //设置是否获取焦点请用次方法,不然会有禁止获取焦点却能弹出键盘的bug - public void setKeyBordFocuable(boolean focuable){ - setFocusable(focuable); - setFocusableInTouchMode(focuable); - setCursorVisible(focuable); - isHide = focuable; - } - - - public boolean onKeyDown(int keyCode, KeyEvent event) { - if (keyCode == KeyEvent.KEYCODE_BACK) { - if (null != mKeyboardWindow) { - if (mKeyboardWindow.isShowing()) { - mKeyboardWindow.dismiss(); - return true; - } - } - } - - return super.onKeyDown(keyCode, event); - - } - - public void onAttachedToWindow() { - super.onAttachedToWindow(); - - this.mWindow = ((Activity) getContext()).getWindow(); - this.mDecorView = this.mWindow.getDecorView(); - this.mContentView = this.mWindow.findViewById(Window.ID_ANDROID_CONTENT); - - hideSysInput(); - } - - public void onDetachedFromWindow() { - super.onDetachedFromWindow(); - - hideKeyboard(); - - mKeyboardWindow = null; - mKeyboardView = null; - mKeyboard = null; - - mDecorView = null; - mContentView = null; - mWindow = null; - } - - @Override - public void onPress(int primaryCode) { - // TODO Auto-generated method stub - - } - - @Override - public void onRelease(int primaryCode) { - // TODO Auto-generated method stub - - } - - @Override - public void onKey(int primaryCode, int[] keyCodes) { - // TODO Auto-generated method stub - Editable editable = this.getText(); - int start = this.getSelectionStart(); - if (primaryCode == Keyboard.KEYCODE_CANCEL) {// 隐藏键盘 - hideKeyboard(); - } else if (primaryCode == Keyboard.KEYCODE_DELETE) {// 回退 - if (editable != null && editable.length() > 0) { - if (start > 0) { - editable.delete(start - 1, start); - } - } - } else if (primaryCode == 152) { - editable.clear(); - } else { - editable.insert(start, Character.toString((char) primaryCode)); - } - } - - //判断是否是字母 - private boolean isLetter(String str) { - String wordStr = "abcdefghijklmnopqrstuvwxyz"; - return wordStr.contains(str.toLowerCase()); - } - - @Override - public void onText(CharSequence text) { - // TODO Auto-generated method stub - - } - - @Override - public void swipeLeft() { - // TODO Auto-generated method stub - - } - - @Override - public void swipeRight() { - // TODO Auto-generated method stub - - } - - @Override - public void swipeDown() { - // TODO Auto-generated method stub - - } - - @Override - public void swipeUp() { - // TODO Auto-generated method stub - - } - - private Key getKeyByKeyCode(int keyCode) { - if (null != mKeyboard) { - List mKeys = mKeyboard.getKeys(); - for (int i = 0, size = mKeys.size(); i < size; i++) { - Key mKey = mKeys.get(i); - - int codes[] = mKey.codes; - - if (codes[0] == keyCode) { - return mKey; - } - } - } - - return null; - } - - private void initAttributes(Context context) { - initScreenParams(context); - this.setLongClickable(false); - this.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI); - removeCopyAbility(); - - if (this.getText() != null) { - this.setSelection(this.getText().length()); - } - - this.setOnFocusChangeListener(new OnFocusChangeListener() { - - @Override - public void onFocusChange(View v, boolean hasFocus) { - // TODO Auto-generated method stub - if (!hasFocus) { - hideKeyboard(); - } - } - }); - - - } - - @TargetApi(11) - private void removeCopyAbility() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { - this.setCustomSelectionActionModeCallback(new ActionMode.Callback() { - - @Override - public boolean onCreateActionMode(ActionMode mode, Menu menu) { - return false; - } - - @Override - public boolean onPrepareActionMode(ActionMode mode, Menu menu) { - return false; - } - - @Override - public void onDestroyActionMode(ActionMode mode) { - - } - - @Override - public boolean onActionItemClicked(ActionMode mode, MenuItem item) { - return false; - } - }); - } - } - - private boolean isNumber(String str) { - String wordstr = "0123456789"; - if (wordstr.indexOf(str) > -1) { - return true; - } - return false; - } - - private void randomdigkey(Keyboard mKeyboard) { - if (mKeyboard == null) { - return; - } - - List keyList = mKeyboard.getKeys(); - - // 查找出0-9的数字键 - List newkeyList = new ArrayList(); - for (int i = 0, size = keyList.size(); i < size; i++) { - Key key = keyList.get(i); - CharSequence label = key.label; - if (label != null && isNumber(label.toString())) { - newkeyList.add(key); - } - } - - - int count = newkeyList.size(); - - - List resultList = new ArrayList(); - - - LinkedList temp = new LinkedList(); - - - for (int i = 0; i < count; i++) { - temp.add(new KeyModel(48 + i, i + "")); - } - - - Random rand = new SecureRandom(); - rand.setSeed(SystemClock.currentThreadTimeMillis()); - - 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())); - temp.remove(num); - } - - for (int i = 0, size = newkeyList.size(); i < size; i++) { - Key newKey = newkeyList.get(i); - KeyModel resultmodle = resultList.get(i); - newKey.label = resultmodle.getLable(); - newKey.codes[0] = resultmodle.getCode(); - } - - - } - - - class KeyModel { - - private Integer code; - private String label; - - public KeyModel(Integer code, String lable) { - this.code = code; - this.label = lable; - } - - public Integer getCode() { - return code; - } - - public void setCode(Integer code) { - this.code = code; - } - - public String getLable() { - return label; - } - - public void setLabel(String lable) { - this.label = lable; - } - - - } - - /** - * 密度转换为像素值 - * - * @param dp - * @return - */ - public static int dpToPx(Context context, float dp) { - final float scale = context.getResources().getDisplayMetrics().density; - return (int) (dp * scale + 0.5f); - } - - - private void initScreenParams(Context context) { - DisplayMetrics dMetrics = new DisplayMetrics(); - WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); - Display display = windowManager.getDefaultDisplay(); - display.getMetrics(dMetrics); - - screenw = dMetrics.widthPixels; - screenh = dMetrics.heightPixels; - density = dMetrics.density; - densityDpi = dMetrics.densityDpi; - - screenh_nonavbar = screenh; - - int ver = Build.VERSION.SDK_INT; - - // 新版本的android 系统有导航栏,造成无法正确获取高度 - if (ver == 13) { - try { - Method mt = display.getClass().getMethod("getRealHeight"); - screenh_nonavbar = (Integer) mt.invoke(display); - } catch (Exception e) { - } - } else if (ver > 13) { - try { - Method mt = display.getClass().getMethod("getRawHeight"); - screenh_nonavbar = (Integer) mt.invoke(display); - } catch (Exception e) { - } - } - - real_scontenth = screenh_nonavbar - getStatusBarHeight(context); - - - } - - /** - * 电量栏高度 - * - * @return - */ - public static int getStatusBarHeight(Context context) { - Class c = null; - Object obj = null; - Field field = null; - int x = 0, - sbar = 0; - try { - c = Class.forName("com.android.internal.R$dimen"); - obj = c.newInstance(); - field = c.getField("status_bar_height"); - x = Integer.parseInt(field.get(obj).toString()); - sbar = context.getResources().getDimensionPixelSize(x); - } catch (Exception e1) { - e1.printStackTrace(); - } - - return sbar; - } - - -} diff --git a/app/src/main/java/com/example/keybord/keyborddemo/SystemKeyboardActivity.java b/app/src/main/java/com/example/keybord/keyborddemo/SystemKeyboardActivity.java new file mode 100644 index 0000000..0abdd58 --- /dev/null +++ b/app/src/main/java/com/example/keybord/keyborddemo/SystemKeyboardActivity.java @@ -0,0 +1,86 @@ +package com.example.keybord.keyborddemo; + +import android.graphics.Color; +import android.graphics.Paint; +import android.inputmethodservice.Keyboard; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +import com.jay.easykeyboard.SystemKeyboard; +import com.jay.easykeyboard.function.SystemOnKeyboardActionListener; + +/** + * Created by huangjie on 2018/2/6. + * 类名: + * 说明: + */ + +public class SystemKeyboardActivity extends AppCompatActivity implements View.OnFocusChangeListener { + + private SystemKeyboard mKeyboard; + private SystemOnKeyboardActionListener listener; + private EditText edit1; + private EditText edit2; + + @Override + 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); + edit1 = findViewById(R.id.edit); + edit2 = findViewById(R.id.edit2); + listener = new SystemOnKeyboardActionListener() { + @Override + public void onKey(int primaryCode, int[] keyCodes) { + //必须实现该方法,其余方法可选择实现,该方法的作用是将输入的值附到EditText上,同时进行键盘按键监听 + super.onKey(primaryCode, keyCodes); + if (primaryCode == Keyboard.KEYCODE_DONE) { + showShortToast("点击了完成按钮"); + } + } + }; + listener.setEditText(edit1); + mKeyboard.setOnKeyboardActionListener(listener); + + edit1.setOnFocusChangeListener(this); + edit2.setOnFocusChangeListener(this); + + btn_setkeyui.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + mKeyboard.setKeyboardUI(new SystemKeyboard.KeyUI() { + @Override + public Paint paintConfig(Paint mPaint) { + mPaint.setColor(Color.BLUE); + mPaint.setTextSize(100); + return mPaint; + } + }); + } + }); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + mKeyboard.recycle(); + } + + private void showShortToast(String str) { + Toast.makeText(this, str, Toast.LENGTH_SHORT).show(); + } + + @Override + public void onFocusChange(View v, boolean hasFocus) { + if (hasFocus) { + if (v instanceof EditText) + listener.setEditText((EditText) v); + } + } +} diff --git a/app/src/main/java/com/example/keybord/keyborddemo/SystemKeyboardEidtTextActivity.java b/app/src/main/java/com/example/keybord/keyborddemo/SystemKeyboardEidtTextActivity.java new file mode 100644 index 0000000..4839966 --- /dev/null +++ b/app/src/main/java/com/example/keybord/keyborddemo/SystemKeyboardEidtTextActivity.java @@ -0,0 +1,61 @@ +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.view.View; +import android.widget.EditText; +import android.widget.Toast; + +import com.jay.easykeyboard.SystemKeyBoardEditText; +import com.jay.easykeyboard.function.SystemOnKeyboardActionListener; + +/** + * Created by huangjie on 2018/2/6. + * 类名: + * 说明: + */ + +public class SystemKeyboardEidtTextActivity extends AppCompatActivity implements View.OnFocusChangeListener{ + + private SystemKeyBoardEditText skb_top; + private SystemKeyBoardEditText skb_bottom; + private SystemOnKeyboardActionListener listener; + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_systemkeyboardedittext); + skb_top = findViewById(R.id.skb_top); + skb_bottom = findViewById(R.id.skb_bottom); + listener = new SystemOnKeyboardActionListener(skb_top,skb_top.getKeyboardWindow()){ + @Override + public void onKey(int primaryCode, int[] keyCodes) { + super.onKey(primaryCode, keyCodes); + if (primaryCode== Keyboard.KEYCODE_DONE){ + showShortToast("点击了完成按钮"); + } + } + }; + skb_top.setOnKeyboardActionListener(listener); + skb_bottom.setOnKeyboardActionListener(listener); + skb_top.setOnFocusChangeListener(this); + skb_bottom.setOnFocusChangeListener(this); + } + + + private void showShortToast(String str){ + Toast.makeText(this, str, Toast.LENGTH_SHORT).show(); + } + + @Override + public void onFocusChange(View v, boolean hasFocus) { + if (hasFocus){ + if (v instanceof SystemKeyBoardEditText){ + listener.setEditText((EditText) v); + listener.setPopupWindow(((SystemKeyBoardEditText) v).getKeyboardWindow()); + } + } + } +} diff --git a/app/src/main/res/drawable/edit_bg.xml b/app/src/main/res/drawable/edit_bg.xml new file mode 100644 index 0000000..f0440f9 --- /dev/null +++ b/app/src/main/res/drawable/edit_bg.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml deleted file mode 100644 index de8cbc6..0000000 --- a/app/src/main/res/layout/activity_main.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - diff --git a/app/src/main/res/layout/activity_recycle_view.xml b/app/src/main/res/layout/activity_recycle_view.xml new file mode 100644 index 0000000..92cca80 --- /dev/null +++ b/app/src/main/res/layout/activity_recycle_view.xml @@ -0,0 +1,13 @@ + + + + diff --git a/app/src/main/res/layout/activity_systemkeyboard.xml b/app/src/main/res/layout/activity_systemkeyboard.xml new file mode 100644 index 0000000..767a2f2 --- /dev/null +++ b/app/src/main/res/layout/activity_systemkeyboard.xml @@ -0,0 +1,39 @@ + + + + + +