From f1c6b593ef369503127600f25f2f7b801e869c8a Mon Sep 17 00:00:00 2001 From: CeuiLiSA <32817377+CeuiLiSA@users.noreply.github.com> Date: Tue, 23 Jun 2020 15:07:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=8F=91=E8=A1=A8=E6=83=85=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ceui/lisa/fragments/FragmentComing.java | 103 +++--------------- 1 file changed, 16 insertions(+), 87 deletions(-) diff --git a/app/src/main/java/ceui/lisa/fragments/FragmentComing.java b/app/src/main/java/ceui/lisa/fragments/FragmentComing.java index cb0d86613..56090a69f 100644 --- a/app/src/main/java/ceui/lisa/fragments/FragmentComing.java +++ b/app/src/main/java/ceui/lisa/fragments/FragmentComing.java @@ -1,36 +1,16 @@ package ceui.lisa.fragments; -import android.os.Bundle; -import android.text.Editable; -import android.text.Html; -import android.text.SpannableString; -import android.text.Spanned; -import android.text.TextWatcher; -import android.text.method.LinkMovementMethod; -import android.view.KeyEvent; import android.view.View; -import android.widget.LinearLayout; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.RecyclerView; import com.effective.android.panel.PanelSwitchHelper; -import com.effective.android.panel.interfaces.listener.OnKeyboardStateListener; -import com.effective.android.panel.interfaces.listener.OnPanelChangeListener; -import com.effective.android.panel.view.panel.IPanelView; -import com.effective.android.panel.view.panel.PanelView; - -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.List; import ceui.lisa.R; import ceui.lisa.adapters.EmojiAdapter; -import ceui.lisa.core.ImgGetter; import ceui.lisa.databinding.FragmentComingBinding; import ceui.lisa.interfaces.OnItemClickListener; -import ceui.lisa.model.Content; import ceui.lisa.model.EmojiItem; import ceui.lisa.utils.Common; import ceui.lisa.utils.Emoji; @@ -51,7 +31,7 @@ public void onStart() { mHelper = new PanelSwitchHelper.Builder(this) .contentCanScrollOutside(true) //可选模式,默认true,当面板实现时内容区域是否往上滑动 .logTrack(true) //可选,默认false,是否开启log信息输出 - .build(false); //可选,默认false,是否默认打开输入法 + .build(false); //可选,默认false,是否默认打开输入法 } } @@ -65,58 +45,32 @@ public void initView(View view) { adapter.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(View v, int position, int viewType) { - final EmojiItem item = adapter.getItemAt(position); - if (selection < current.size()) { - current.add(selection, item); - - Content temp = new Content(); - temp.setEmoji(true); - content.add(selection, temp); - } else { - current.add(item); - - - Content temp = new Content(); - temp.setEmoji(true); - content.add(temp); - } + String name = item.getName(); + String show = baseBind.inputBox.getText().toString(); + if (selection < show.length()) { + String left = show.substring(0, selection); + String right = show.substring(selection); + commitString = left + name + right; - SpannableString spannableString = new SpannableString(Html.fromHtml(Emoji.transform(emojiToString()), - new ImgGetter(baseBind.inputBox), null)); - baseBind.inputBox.setText(spannableString); - - if (selection < current.size()) { - baseBind.inputBox.setSelection(selection + 1); + baseBind.inputBox.setText(left + name + right); + baseBind.inputBox.setSelection(selection + name.length()); } else { - current.add(adapter.getItemAt(position)); - baseBind.inputBox.setSelection(baseBind.inputBox.getText().toString().length()); - selection = baseBind.inputBox.getText().toString().length(); - } + String result = show + name; + commitString = result; + baseBind.inputBox.setText(result); + baseBind.inputBox.setSelection(result.length()); + } + Common.showLog(className + selection); } }); recyclerView.setAdapter(adapter); - baseBind.inputBox.setOnKeyListener(new View.OnKeyListener() { - @Override - public boolean onKey(View v, int keyCode, KeyEvent event) { - if(keyCode == KeyEvent.KEYCODE_DEL && event.getAction() != KeyEvent.ACTION_UP) { - if (selection > 0) { - final int index = selection - 1; - if (index < current.size()) { - current.remove(index); - selection = selection - 1; - } - } - } - return false; - } - }); baseBind.inputBox.setOnSelectionChange(new EditTextWithSelection.OnSelectionChange() { @Override public void onChange(int start, int end) { @@ -125,36 +79,11 @@ public void onChange(int start, int end) { } } }); - baseBind.inputBox.addTextChangedListener(new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - - } - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - Common.showLog(className + "afterTextChanged " + s + " " + "".equals(s.toString())); - - } - - @Override - public void afterTextChanged(Editable s) { - } - }); } private int selection = 0; - private List current = new ArrayList<>(); - private List content = new ArrayList<>(); - - private String emojiToString() { - String result = ""; - for (EmojiItem emojiItem : current) { - result = result + emojiItem.getName(); - } - return result; - } + private String commitString = ""; @Override public void initLayout() {