Skip to content

Commit

Permalink
开发表情功能
Browse files Browse the repository at this point in the history
  • Loading branch information
CeuiLiSA committed Jun 23, 2020
1 parent 9b067c3 commit f1c6b59
Showing 1 changed file with 16 additions and 87 deletions.
103 changes: 16 additions & 87 deletions app/src/main/java/ceui/lisa/fragments/FragmentComing.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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,是否默认打开输入法
}
}

Expand All @@ -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) {
Expand All @@ -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<EmojiItem> current = new ArrayList<>();
private List<Content> 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() {
Expand Down

0 comments on commit f1c6b59

Please sign in to comment.