Skip to content

Commit

Permalink
项目重构v1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay-huangjie committed Dec 17, 2018
1 parent 3675cdf commit 2de114d
Show file tree
Hide file tree
Showing 29 changed files with 379 additions and 329 deletions.
22 changes: 0 additions & 22 deletions .idea/compiler.xml

This file was deleted.

3 changes: 0 additions & 3 deletions .idea/copyright/profiles_settings.xml

This file was deleted.

3 changes: 1 addition & 2 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
buildToolsVersion "26.0.3"
defaultConfig {
applicationId "com.example.keybord.keyborddemo"
minSdkVersion 19
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
Expand All @@ -23,6 +23,5 @@ dependencies {
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')
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,85 +2,97 @@

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.text.Editable;
import android.util.Log;
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;
import com.jay.easykeyboard.action.IKeyBoardUI;
import com.jay.easykeyboard.action.KeyBoardActionListence;
import com.jay.easykeyboard.util.Util;

/**
* Created by huangjie on 2018/2/6.
* 类名:
* 说明:
* 说明:此Activity实现了键盘固定的情况下的使用
*/

public class SystemKeyboardActivity extends AppCompatActivity implements View.OnFocusChangeListener {

private static final String TAG = "SystemKeyboardActivity";
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() {
EditText edit1 = findViewById(R.id.edit);
EditText edit2 = findViewById(R.id.edit2);
mKeyboard.setEditText(edit1); //用于绑定EditText,如果切换了EditText,请务必设置此方法
mKeyboard.setOnKeyboardActionListener(new KeyBoardActionListence() {
@Override
public void onKey(int primaryCode, int[] keyCodes) {
//必须实现该方法,其余方法可选择实现,该方法的作用是将输入的值附到EditText上,同时进行键盘按键监听
super.onKey(primaryCode, keyCodes);
if (primaryCode == Keyboard.KEYCODE_DONE) {
showShortToast("点击了完成按钮");
}
public void onComplete() {
showShortToast("完成");
}
};
listener.setEditText(edit1); //用于绑定EditText,如果切换了EditText,请务必设置此方法
mKeyboard.setOnKeyboardActionListener(listener);

@Override
public void onTextChange(Editable editable) {
Log.i(TAG,"onTextChange:"+editable.toString());
}

@Override
public void onClear() {
showShortToast("onClear");
}

@Override
public void onClearAll() {
showShortToast("onClearAll");
}
});

edit1.setOnFocusChangeListener(this);
edit2.setOnFocusChangeListener(this);

btn_setkeyui.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mKeyboard.setKeyboardUI(new SystemKeyboard.KeyUI() {
//改变ui
mKeyboard.setKeyboardUI(new IKeyBoardUI() {
@Override
public Paint paintConfig(Paint mPaint) { //更新Ui,可用画笔设置字体大小,颜色等参数
mPaint.setColor(Color.BLUE);
mPaint.setTextSize(100);
return mPaint;
public Paint setPaint(Paint paint) {
paint.setColor(Color.BLUE);
paint.setTextSize(Util.dpToPx(getApplicationContext(),16));
return paint;
}
});
}
});
}

@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);
switch (v.getId()){
case R.id.edit: //绑定EditText并显示自定义键盘
mKeyboard.setEditText((EditText) v);
break;
case R.id.edit2: //绑定EditText并显示原生键盘
mKeyboard.setEditText((EditText) v,true);
break;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,69 @@
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.function.SystemOnKeyboardActionListener;
import com.jay.easykeyboard.action.KeyBoardActionListence;
import com.jay.easykeyboard.impl.SystemOnKeyboardActionListener;

/**
* Created by huangjie on 2018/2/6.
* 类名:
* 说明:
*/

public class SystemKeyboardEidtTextActivity extends AppCompatActivity implements View.OnFocusChangeListener{
public class SystemKeyboardEidtTextActivity extends AppCompatActivity implements KeyBoardActionListence {

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);
skb_top.setOnKeyboardActionListener(this);
skb_bottom.setOnKeyboardActionListener(this);
// 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){
// ()v.setEditText((EditText) v);
// }
// }
// }

@Override
public void onComplete() {

}

@Override
public void onTextChange(Editable editable) {

}

@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus){
if (v instanceof SystemKeyBoardEditText){
listener.setEditText((EditText) v);
listener.setPopupWindow(((SystemKeyBoardEditText) v).getKeyboardWindow());
}
}
public void onClear() {

}

@Override
public void onClearAll() {

}
}
6 changes: 2 additions & 4 deletions app/src/main/res/drawable/edit_bg.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<stroke android:color="@color/black" android:width="0.5dp"/>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="1dp" android:color="#399cff"/>
</shape>
File renamed without changes.
File renamed without changes.
6 changes: 2 additions & 4 deletions app/src/main/res/layout/activity_recycle_view.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.keybord.keyborddemo.RecyclerViewActivity">
>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/mRecyclerView"
></android.support.v7.widget.RecyclerView>
/>
</FrameLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_systemkeyboard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
keyboard:keyViewbg="@drawable/edit_bg"
keyboard:keyViewbg="@drawable/btn_keyboard_key"
keyboard:xmlLayoutResId="@xml/keyboard_numbers" />
</RelativeLayout>
5 changes: 3 additions & 2 deletions app/src/main/res/layout/activity_systemkeyboardedittext.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
android:layout_width="match_parent"
android:layout_height="50dp"
keyboard:xmlLayoutResId="@xml/keyboard_numbers"
keyboard:outSideCancel="true"
android:id="@+id/skb_top"
android:hint="顶部EditText"
android:layout_margin="10dp"
android:background="@drawable/edit_bg"
android:background="@drawable/btn_keyboard_key"
/>
<com.jay.easykeyboard.SystemKeyBoardEditText
android:layout_width="match_parent"
Expand All @@ -22,6 +23,6 @@
android:id="@+id/skb_bottom"
keyboard:space="true"
keyboard:xmlLayoutResId="@xml/keyboard_numbers"
android:background="@drawable/edit_bg"
android:background="@drawable/btn_keyboard_key"
/>
</RelativeLayout>
Loading

0 comments on commit 2de114d

Please sign in to comment.