From 67a68de1bd5db55947713e294f6be81e1f295d0e Mon Sep 17 00:00:00 2001 From: CaiFeng <2397707574@qq.com> Date: Sat, 3 Feb 2024 15:09:42 +0800 Subject: [PATCH 1/2] support native --- .../cloudphone/apiimpl/CloudPhoneImeMgr.java | 36 ++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/cloudphone/src/main/java/com/huawei/cloudphone/apiimpl/CloudPhoneImeMgr.java b/cloudphone/src/main/java/com/huawei/cloudphone/apiimpl/CloudPhoneImeMgr.java index ea7b8ee..fa1b24e 100644 --- a/cloudphone/src/main/java/com/huawei/cloudphone/apiimpl/CloudPhoneImeMgr.java +++ b/cloudphone/src/main/java/com/huawei/cloudphone/apiimpl/CloudPhoneImeMgr.java @@ -29,7 +29,7 @@ public class CloudPhoneImeMgr { private static final int TEXT_SIZE = 14; private static final int TEXT_MAX_LEN = 40; private static final int TEXT_MAX_LINES = 1; - private static final int BOX_INPUT_HEIGHT = 50; + private static final int BOX_INPUT_HEIGHT = 1; private static final int BUTTON_WIDTH = 65; private static final int BUTTON_HEIGHT = 40; private static final int IME_MSG_SHOW = 0; @@ -39,6 +39,7 @@ public class CloudPhoneImeMgr { private static final int IME_PASTE_FROM_CLOUD = 6; private static final int IME_PASTE_TO_CLOUD = 7; private static final int IME_MSG_HEADER_LEN = 3; + private static final String IME_CURSOR_SEPARATOR = "="; private ViewGroup mRootViewGroup; private ViewGroup mImeViewGroup; @@ -47,6 +48,8 @@ public class CloudPhoneImeMgr { private PopupWindow mPopWindow; private CloudPhoneTextWatchListener mTextWatchListener; private CloudPhoneClipboardListener mClipboardListener; + private int mCurrentCursor; + private boolean mCursorInEnd; @SuppressLint("Range") public CloudPhoneImeMgr(Context context, ViewGroup viewGroup) { @@ -94,8 +97,16 @@ public class CloudPhoneImeMgr { } @Override - public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { - byte[] data = charSequence.toString().getBytes(); + public void onTextChanged(CharSequence charSequence, int start, int before, int count) { + String text = ""; + int cursorPosition = mImeEditText.getSelectionStart(); + if (!mCursorInEnd|| (mCurrentCursor == before && mCurrentCursor == count)) { + text = charSequence.toString() + IME_CURSOR_SEPARATOR + mCurrentCursor; + mCursorInEnd = true; + } else { + text = charSequence.toString() + IME_CURSOR_SEPARATOR + cursorPosition; + } + byte[] data = text.getBytes(); byte[] msg = new byte[IME_MSG_HEADER_LEN + data.length]; msg[0] = IME_MSG_TEXT; msg[1] = (byte) ((data.length >> 8) & 0xFF); @@ -109,6 +120,7 @@ public class CloudPhoneImeMgr { @Override public void afterTextChanged(Editable editable) { + } }); @@ -124,7 +136,13 @@ public class CloudPhoneImeMgr { return 0; } if (text != null && text.length() > 0) { - mImeEditText.getText().replace(0, mImeEditText.length(), text); + int lastIndex = text.lastIndexOf(IME_CURSOR_SEPARATOR); + String content = text.substring(0 ,lastIndex); + int cursor = Integer.parseInt(text.substring(lastIndex + 1)); + mCurrentCursor = cursor; + mCursorInEnd = cursor == content.length() ? true : false; + mImeEditText.getText().replace(0, mImeEditText.length(), content); + mImeEditText.setSelection(cursor); } else { mImeEditText.getText().clear(); } @@ -167,11 +185,11 @@ public class CloudPhoneImeMgr { @Override public void run() { switch (type) { -// case IME_MSG_SHOW: -// showKeyBoard(true, finalText); -// break; -// case IME_MSG_HIDE: -// showKeyBoard(false, null); + case IME_MSG_SHOW: + showKeyBoard(true, finalText); + break; + case IME_MSG_HIDE: + showKeyBoard(false, null); case IME_PASTE_FROM_CLOUD: setClipBoard(finalText); default: -- Gitee From d5b444e7bae80f73d1640449a9293da2e29d2b8a Mon Sep 17 00:00:00 2001 From: CaiFeng <2397707574@qq.com> Date: Sat, 3 Feb 2024 15:45:11 +0800 Subject: [PATCH 2/2] support native --- .../cloudphone/apiimpl/CloudPhoneImeMgr.java | 20 +------------------ 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/cloudphone/src/main/java/com/huawei/cloudphone/apiimpl/CloudPhoneImeMgr.java b/cloudphone/src/main/java/com/huawei/cloudphone/apiimpl/CloudPhoneImeMgr.java index fa1b24e..23ea88c 100644 --- a/cloudphone/src/main/java/com/huawei/cloudphone/apiimpl/CloudPhoneImeMgr.java +++ b/cloudphone/src/main/java/com/huawei/cloudphone/apiimpl/CloudPhoneImeMgr.java @@ -60,7 +60,7 @@ public class CloudPhoneImeMgr { RelativeLayout.LayoutParams imeViewGroupLp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, dip2px(BOX_INPUT_HEIGHT)); imeViewGroupLp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); mImeViewGroup.setLayoutParams(imeViewGroupLp); - mImeViewGroup.setBackgroundColor(Color.WHITE); + mImeViewGroup.setBackgroundColor(Color.TRANSPARENT); mImeViewGroup.setAlpha(50); mImeEditText = new EditText(context); @@ -68,29 +68,11 @@ public class CloudPhoneImeMgr { mImeEditText.setLayoutParams(imeEditTextLp); mImeEditText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI); mImeEditText.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); - mImeEditText.setHint("请输入"); mImeEditText.setTextSize(TypedValue.COMPLEX_UNIT_PX, dip2px(TEXT_SIZE)); mImeEditText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(TEXT_MAX_LEN)}); mImeEditText.setMaxLines(TEXT_MAX_LINES); mImeViewGroup.addView(mImeEditText); - Button button = new Button(context); - RelativeLayout.LayoutParams marginLp = new RelativeLayout.LayoutParams(dip2px(BUTTON_WIDTH), dip2px(BUTTON_HEIGHT)); - marginLp.setMargins(0, dip2px(5), dip2px(10), 0); - RelativeLayout.LayoutParams buttonLp = new RelativeLayout.LayoutParams(marginLp); - buttonLp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); - button.setLayoutParams(buttonLp); - button.setText("下一步"); - button.setTextSize(TypedValue.COMPLEX_UNIT_PX, dip2px(12)); - mImeViewGroup.addView(button); - - button.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - hide(); - } - }); - mImeEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { -- Gitee