判断搜索按键
This commit is contained in:
parent
c1abe2137f
commit
4a4e36184f
@ -15,10 +15,13 @@ public class KeyboardService extends InputMethodService implements KeyboardView.
|
||||
private int[] ViewXmls = new int[4];
|
||||
private MyKeyboard myKeyboard;
|
||||
|
||||
private int curImeAction;
|
||||
|
||||
public KeyboardService() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View onCreateInputView() {
|
||||
ViewXmls[0] = R.xml.view_1;
|
||||
@ -37,10 +40,16 @@ public class KeyboardService extends InputMethodService implements KeyboardView.
|
||||
@Override
|
||||
public void onWindowShown() {
|
||||
super.onWindowShown();
|
||||
myKeyboard.updateConfigView(this);
|
||||
curImeAction = getImeAction(getCurrentInputEditorInfo().imeOptions);
|
||||
myKeyboard.updateConfigView(this,curImeAction);
|
||||
myKeyboard.invalidate();
|
||||
}
|
||||
|
||||
public int getImeAction(int imeOptions) {
|
||||
int i = imeOptions & EditorInfo.IME_MASK_ACTION;
|
||||
return i ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPress(int primaryCode) {
|
||||
|
||||
@ -81,7 +90,7 @@ public class KeyboardService extends InputMethodService implements KeyboardView.
|
||||
getCurrentInputConnection().deleteSurroundingText(1, 0);
|
||||
break;
|
||||
case MyKeyboard.KeyBoard.KEYCODE_DONE:
|
||||
getCurrentInputConnection().performEditorAction(EditorInfo.IME_ACTION_DONE);
|
||||
getCurrentInputConnection().performEditorAction(curImeAction);
|
||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(myKeyboard.getWindowToken(), 0);
|
||||
break;
|
||||
|
||||
@ -7,6 +7,7 @@ import android.graphics.drawable.Drawable;
|
||||
import android.inputmethodservice.Keyboard;
|
||||
import android.inputmethodservice.KeyboardView;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
|
||||
|
||||
import com.key.coolkeyboard.tool.Mytool;
|
||||
@ -19,7 +20,7 @@ public class MyKeyboard extends KeyboardView {
|
||||
private int viewType = 0;
|
||||
private int shiftType = 0;
|
||||
private CustomViewConfig config;
|
||||
|
||||
private int curImeAction;
|
||||
public MyKeyboard(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
initView();
|
||||
@ -62,30 +63,36 @@ public class MyKeyboard extends KeyboardView {
|
||||
if (code == KeyBoard.KEYCODE_MODE_CHANGE) {
|
||||
|
||||
onDrawKeyBackground(key, config.getBgActionDraw(), canvas);
|
||||
onDrawLabel(key, canvas);
|
||||
onDrawLabel(key, canvas,"");
|
||||
|
||||
} else if (code == KeyBoard.KEYCODE_SHIFT) {
|
||||
onDrawKeyBackground(key, config.getBgActionDraw(), canvas);
|
||||
drawIcon.onDrawKeyIcon(key, getShiftDraw(), canvas, this);
|
||||
} else if (code == KeyBoard.KEYCODE_SHIFT_123) {
|
||||
onDrawKeyBackground(key, config.getBgActionDraw(), canvas);
|
||||
onDrawLabel(key, canvas);
|
||||
onDrawLabel(key, canvas,"");
|
||||
|
||||
} else if (code == KeyBoard.KEYCODE_SHIFT_MORE) {
|
||||
onDrawKeyBackground(key, config.getBgActionDraw(), canvas);
|
||||
onDrawLabel(key, canvas);
|
||||
onDrawLabel(key, canvas,"");
|
||||
|
||||
} else if (code == KeyBoard.KEYCODE_DONE) {
|
||||
onDrawKeyBackground(key, config.getBgActionDraw(), canvas);
|
||||
onDrawLabel(key, canvas);
|
||||
if(curImeAction == EditorInfo.IME_ACTION_SEARCH){
|
||||
onDrawLabel(key, canvas,"Search");
|
||||
}else {
|
||||
onDrawLabel(key, canvas,"");
|
||||
}
|
||||
|
||||
|
||||
} else if (code == KeyBoard.KEYCODE_DELETE) {
|
||||
onDrawKeyBackground(key, config.getBgActionDraw(), canvas);
|
||||
drawIcon.onDrawKeyIcon(key, config.getIconDel(), canvas, this);
|
||||
onDrawLabel(key, canvas);
|
||||
onDrawLabel(key, canvas,"");
|
||||
} else {
|
||||
mPaint.setColor(config.getKeyNoramlcolor());
|
||||
onDrawKeyBackground(key, config.getBgNormalDraw(), canvas);
|
||||
onDrawLabel(key, canvas);
|
||||
onDrawLabel(key, canvas,"");
|
||||
}
|
||||
}
|
||||
|
||||
@ -108,7 +115,8 @@ public class MyKeyboard extends KeyboardView {
|
||||
setPreviewEnabled(false);
|
||||
}
|
||||
|
||||
public void updateConfigView(Context con) {
|
||||
public void updateConfigView(Context con,int ime) {
|
||||
curImeAction = ime;
|
||||
config.updateConfig(con);
|
||||
setBackground(config.getBG());
|
||||
invalidateAllKeys();
|
||||
@ -132,13 +140,23 @@ public class MyKeyboard extends KeyboardView {
|
||||
|
||||
private void onDrawLabel(
|
||||
Keyboard.Key myKey,
|
||||
Canvas canvas) {
|
||||
Canvas canvas,String custLabel) {
|
||||
|
||||
boolean b = myKey.label == null || myKey.label == "";
|
||||
if (!b) {
|
||||
float y1 = myKey.y + myKey.height / 2f - (mPaint.descent() + mPaint.ascent()) / 2f;
|
||||
float x1 = myKey.x + getPaddingLeft() + ((myKey.width / 2f));
|
||||
x1 -= mPaint.measureText(myKey.label.toString()) / 2f;
|
||||
canvas.drawText(myKey.label.toString(), x1, y1, mPaint);
|
||||
if(!custLabel.isEmpty()){
|
||||
float texsize = Mytool.spToPpx(14f, this.getContext());
|
||||
mPaint.setTextSize(texsize);
|
||||
canvas.drawText(custLabel, x1, y1, mPaint);
|
||||
}else {
|
||||
float texsize = Mytool.spToPpx(18f, this.getContext());
|
||||
mPaint.setTextSize(texsize);
|
||||
canvas.drawText(myKey.label.toString(), x1, y1, mPaint);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user