use of sj.keyboard.widget.EmoticonPageView in project XhsEmoticonsKeyboard by w446108264.
the class QqUtils method addQqPageSetEntity.
public static void addQqPageSetEntity(PageSetAdapter pageSetAdapter, Context context, final EmoticonClickListener emoticonClickListener) {
EmoticonPageSetEntity kaomojiPageSetEntity = new EmoticonPageSetEntity.Builder().setLine(3).setRow(7).setEmoticonList(ParseDataUtils.ParseQqData(DefQqEmoticons.sQqEmoticonHashMap)).setIPageViewInstantiateItem(new PageViewInstantiateListener<EmoticonPageEntity>() {
@Override
public View instantiateItem(ViewGroup container, int position, EmoticonPageEntity pageEntity) {
if (pageEntity.getRootView() == null) {
EmoticonPageView pageView = new EmoticonPageView(container.getContext());
pageView.setNumColumns(pageEntity.getRow());
pageEntity.setRootView(pageView);
try {
EmoticonsAdapter adapter = new EmoticonsAdapter(container.getContext(), pageEntity, emoticonClickListener);
adapter.setItemHeightMaxRatio(1.8);
adapter.setOnDisPlayListener(getEmoticonDisplayListener(emoticonClickListener));
pageView.getEmoticonsGridView().setAdapter(adapter);
} catch (Exception e) {
e.printStackTrace();
}
}
return pageEntity.getRootView();
}
}).setShowDelBtn(EmoticonPageEntity.DelBtnStatus.LAST).setIconUri(ImageBase.Scheme.DRAWABLE.toUri("kys")).build();
pageSetAdapter.add(kaomojiPageSetEntity);
}
use of sj.keyboard.widget.EmoticonPageView in project XhsEmoticonsKeyboard by w446108264.
the class EmoticonPageEntity method instantiateItem.
@Override
public View instantiateItem(final ViewGroup container, int position, EmoticonPageEntity pageEntity) {
if (mPageViewInstantiateListener != null) {
return mPageViewInstantiateListener.instantiateItem(container, position, this);
}
if (getRootView() == null) {
EmoticonPageView pageView = new EmoticonPageView(container.getContext());
pageView.setNumColumns(mRow);
setRootView(pageView);
}
return getRootView();
}
use of sj.keyboard.widget.EmoticonPageView in project XhsEmoticonsKeyboard by w446108264.
the class SimpleCommonUtils method getEmoticonPageViewInstantiateItem.
public static PageViewInstantiateListener<EmoticonPageEntity> getEmoticonPageViewInstantiateItem(final Class _class, final EmoticonClickListener onEmoticonClickListener, final EmoticonDisplayListener<Object> emoticonDisplayListener) {
return new PageViewInstantiateListener<EmoticonPageEntity>() {
@Override
public View instantiateItem(ViewGroup container, int position, EmoticonPageEntity pageEntity) {
if (pageEntity.getRootView() == null) {
EmoticonPageView pageView = new EmoticonPageView(container.getContext());
pageView.setNumColumns(pageEntity.getRow());
pageEntity.setRootView(pageView);
try {
EmoticonsAdapter adapter = (EmoticonsAdapter) newInstance(_class, container.getContext(), pageEntity, onEmoticonClickListener);
if (emoticonDisplayListener != null) {
adapter.setOnDisPlayListener(emoticonDisplayListener);
}
pageView.getEmoticonsGridView().setAdapter(adapter);
} catch (Exception e) {
e.printStackTrace();
}
}
return pageEntity.getRootView();
}
};
}
use of sj.keyboard.widget.EmoticonPageView in project XhsEmoticonsKeyboard by w446108264.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final XhsEmoticonsKeyBoard ek_bar = (XhsEmoticonsKeyBoard) findViewById(R.id.ek_bar);
// source data
ArrayList<EmojiBean> emojiArray = new ArrayList<>();
Collections.addAll(emojiArray, DefEmoticons.getDefEmojiArray());
// emoticon click
final EmoticonClickListener emoticonClickListener = new EmoticonClickListener() {
@Override
public void onEmoticonClick(Object o, int actionType, boolean isDelBtn) {
if (isDelBtn) {
int action = KeyEvent.ACTION_DOWN;
int code = KeyEvent.KEYCODE_DEL;
KeyEvent event = new KeyEvent(action, code);
ek_bar.getEtChat().onKeyDown(KeyEvent.KEYCODE_DEL, event);
} else {
if (o == null) {
return;
}
String content = null;
if (o instanceof EmojiBean) {
content = ((EmojiBean) o).emoji;
}
int index = ek_bar.getEtChat().getSelectionStart();
Editable editable = ek_bar.getEtChat().getText();
editable.insert(index, content);
}
}
};
// emoticon instantiate
final EmoticonDisplayListener emoticonDisplayListener = new EmoticonDisplayListener() {
@Override
public void onBindView(int i, ViewGroup viewGroup, EmoticonsAdapter.ViewHolder viewHolder, Object object, final boolean isDelBtn) {
final EmojiBean emojiBean = (EmojiBean) object;
if (emojiBean == null && !isDelBtn) {
return;
}
viewHolder.ly_root.setBackgroundResource(com.keyboard.view.R.drawable.bg_emoticon);
if (isDelBtn) {
viewHolder.iv_emoticon.setImageResource(R.mipmap.icon_del);
} else {
viewHolder.iv_emoticon.setImageResource(emojiBean.icon);
}
viewHolder.rootView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
emoticonClickListener.onEmoticonClick(emojiBean, 0, isDelBtn);
}
});
}
};
// page instantiate
PageViewInstantiateListener pageViewInstantiateListener = new PageViewInstantiateListener<EmoticonPageEntity>() {
@Override
public View instantiateItem(ViewGroup viewGroup, int i, EmoticonPageEntity pageEntity) {
if (pageEntity.getRootView() == null) {
EmoticonPageView pageView = new EmoticonPageView(viewGroup.getContext());
pageView.setNumColumns(pageEntity.getRow());
pageEntity.setRootView(pageView);
try {
EmoticonsAdapter adapter = new EmoticonsAdapter(viewGroup.getContext(), pageEntity, null);
// emoticon instantiate
adapter.setOnDisPlayListener(emoticonDisplayListener);
pageView.getEmoticonsGridView().setAdapter(adapter);
} catch (Exception e) {
e.printStackTrace();
}
}
return pageEntity.getRootView();
}
};
// build
EmoticonPageSetEntity xhsPageSetEntity = new EmoticonPageSetEntity.Builder().setLine(3).setRow(7).setEmoticonList(emojiArray).setIPageViewInstantiateItem(pageViewInstantiateListener).setShowDelBtn(EmoticonPageEntity.DelBtnStatus.LAST).setIconUri(R.mipmap.ic_launcher).build();
PageSetAdapter pageSetAdapter = new PageSetAdapter();
pageSetAdapter.add(xhsPageSetEntity);
ek_bar.setAdapter(pageSetAdapter);
class EmojiFilter extends EmoticonFilter {
private int emojiSize = -1;
@Override
public void filter(EditText editText, CharSequence text, int start, int lengthBefore, int lengthAfter) {
emojiSize = emojiSize == -1 ? EmoticonsKeyboardUtils.getFontHeight(editText) : emojiSize;
clearSpan(editText.getText(), start, text.toString().length());
Matcher m = EmojiDisplay.getMatcher(text.toString().substring(start, text.toString().length()));
if (m != null) {
while (m.find()) {
String emojiHex = Integer.toHexString(Character.codePointAt(m.group(), 0));
Drawable drawable = getDrawable(editText.getContext(), EmojiDisplay.HEAD_NAME + emojiHex);
if (drawable != null) {
int itemHeight;
int itemWidth;
if (emojiSize == EmojiDisplay.WRAP_DRAWABLE) {
itemHeight = drawable.getIntrinsicHeight();
itemWidth = drawable.getIntrinsicWidth();
} else {
itemHeight = emojiSize;
itemWidth = emojiSize;
}
drawable.setBounds(0, 0, itemHeight, itemWidth);
EmojiSpan imageSpan = new EmojiSpan(drawable);
editText.getText().setSpan(imageSpan, start + m.start(), start + m.end(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
}
}
}
}
private void clearSpan(Spannable spannable, int start, int end) {
if (start == end) {
return;
}
EmojiSpan[] oldSpans = spannable.getSpans(start, end, EmojiSpan.class);
for (int i = 0; i < oldSpans.length; i++) {
spannable.removeSpan(oldSpans[i]);
}
}
}
// add a filter
ek_bar.getEtChat().addEmoticonFilter(new EmojiFilter());
}
Aggregations