From 4a4e36184f4bd49be9fb8bd476a44dc1e26c4996 Mon Sep 17 00:00:00 2001 From: litingting Date: Mon, 26 Aug 2024 18:23:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A4=E6=96=AD=E6=90=9C=E7=B4=A2=E6=8C=89?= =?UTF-8?q?=E9=94=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../keyboard/KeyboardService.java | 13 ++++++- .../key/coolkeyboard/keyboard/MyKeyboard.java | 38 ++++++++++++++----- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/key/coolkeyboard/keyboard/KeyboardService.java b/app/src/main/java/com/key/coolkeyboard/keyboard/KeyboardService.java index b6fd70c..2f81146 100644 --- a/app/src/main/java/com/key/coolkeyboard/keyboard/KeyboardService.java +++ b/app/src/main/java/com/key/coolkeyboard/keyboard/KeyboardService.java @@ -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; diff --git a/app/src/main/java/com/key/coolkeyboard/keyboard/MyKeyboard.java b/app/src/main/java/com/key/coolkeyboard/keyboard/MyKeyboard.java index 3e7faeb..825a408 100644 --- a/app/src/main/java/com/key/coolkeyboard/keyboard/MyKeyboard.java +++ b/app/src/main/java/com/key/coolkeyboard/keyboard/MyKeyboard.java @@ -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); + } + } }