use of cn.hadcn.keyboard.emoticon.EmoticonBean in project ChatKeyboard by CPPAlien.
the class EmoticonLayout method init.
private void init(Context context) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.keyboard_bottom_emoticons, this);
ivIndicator = (IndicatorView) findViewById(R.id.emoticon_indicator_view);
epvContent = (EmoticonsPageView) findViewById(R.id.emoticon_page_view);
etvToolBar = (EmoticonsToolBarView) findViewById(R.id.emoticon_page_toolbar);
epvContent.setOnIndicatorListener(this);
epvContent.setIViewListener(new IView() {
@Override
public void onItemClick(EmoticonBean bean) {
mListener.onEmoticonItemClicked(bean);
}
@Override
public void onPageChangeTo(int position) {
etvToolBar.setToolBtnSelect(position);
}
});
etvToolBar.setOnToolBarItemClickListener(new EmoticonsToolBarView.OnToolBarItemClickListener() {
@Override
public void onToolBarItemClick(int position) {
epvContent.setPageSelect(position);
}
});
}
use of cn.hadcn.keyboard.emoticon.EmoticonBean in project ChatKeyboard by CPPAlien.
the class ChatKeyboardLayout method showEmoticons.
public void showEmoticons() {
btnEmoticon.setVisibility(VISIBLE);
EmoticonsKeyboardBuilder builder = getBuilder(mContext);
EmoticonLayout layout = new EmoticonLayout(mContext);
layout.setContents(builder, new EmoticonLayout.OnEmoticonListener() {
@Override
public void onEmoticonItemClicked(EmoticonBean bean) {
if (etInputArea != null) {
setEditableState(true);
if (bean.getEventType() == EmoticonBean.FACE_TYPE_DEL) {
int action = KeyEvent.ACTION_DOWN;
int code = KeyEvent.KEYCODE_DEL;
KeyEvent event = new KeyEvent(action, code);
etInputArea.onKeyDown(KeyEvent.KEYCODE_DEL, event);
return;
} else if (bean.getEventType() == EmoticonBean.FACE_TYPE_STICKER) {
if (mOnChatKeyBoardListener != null) {
mOnChatKeyBoardListener.onUserDefEmoticonClicked(bean.getTag(), bean.getIconUri());
}
return;
}
int index = etInputArea.getSelectionStart();
Editable editable = etInputArea.getEditableText();
if (index < 0) {
editable.append(bean.getTag());
} else {
editable.insert(index, bean.getTag());
}
}
}
});
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
lyBottomLayout.addView(layout, params);
FUNC_EMOTICON_POS = FUNC_ORDER_COUNT;
++FUNC_ORDER_COUNT;
}
use of cn.hadcn.keyboard.emoticon.EmoticonBean in project ChatKeyboard by CPPAlien.
the class EmoticonHandler method setTextFace.
public void setTextFace(String content, Spannable spannable, int start, int size) {
if (mEmoticonBeans == null) {
mEmoticonBeans = emoticonDbHelper.queryAllEmoticonBeans();
emoticonDbHelper.cleanup();
}
if (content.length() <= 0) {
return;
}
int keyIndex = start;
for (EmoticonBean bean : mEmoticonBeans) {
String key = bean.getTag();
int keyLength = key.length();
while (keyIndex >= 0) {
//when do not find, get -1
keyIndex = content.indexOf(key, keyIndex);
if (keyIndex < 0) {
break;
}
Drawable drawable = EmoticonLoader.getInstance(mContext).getDrawable(bean.getIconUri());
drawable.setBounds(0, 0, size, size);
VerticalImageSpan imageSpan = new VerticalImageSpan(drawable);
spannable.setSpan(imageSpan, keyIndex, keyIndex + keyLength, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
keyIndex += keyLength;
}
keyIndex = start;
}
}
use of cn.hadcn.keyboard.emoticon.EmoticonBean in project ChatKeyboard by CPPAlien.
the class EmoticonsAdapter method getView.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if (convertView == null) {
convertView = LayoutInflater.from(mContext).inflate(R.layout.emoticons_item, parent, false);
convertView.setLayoutParams(new AbsListView.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, mItemHeight));
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(mImgHeight, mImgHeight);
//params.addRule(RelativeLayout.CENTER_HORIZONTAL);
viewHolder = new ViewHolder(convertView);
viewHolder.ivEmoticon.setLayoutParams(params);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
final EmoticonBean emoticonBean = getItem(position);
if (emoticonBean != null) {
// exists some empty block
viewHolder.ivEmoticon.setBackgroundResource(R.drawable.emoticon_bg);
if (isDisplayName) {
viewHolder.tvName.setVisibility(View.VISIBLE);
viewHolder.tvName.setText(getItem(position).getName());
} else {
viewHolder.tvName.setVisibility(View.GONE);
}
viewHolder.ivEmoticon.setImageDrawable(EmoticonLoader.getInstance(mContext).getDrawable(emoticonBean.getIconUri()));
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mOnItemListener != null) {
mOnItemListener.onItemClick(emoticonBean);
}
}
});
}
return convertView;
}
use of cn.hadcn.keyboard.emoticon.EmoticonBean in project ChatKeyboard by CPPAlien.
the class EmoticonsPageView method updateView.
private void updateView() {
if (mEmoticonSetBeanList == null)
return;
if (mEmoticonsViewPagerAdapter == null) {
mEmoticonsViewPagerAdapter = new EmoticonsViewPagerAdapter();
setAdapter(mEmoticonsViewPagerAdapter);
setOnPageChangeListener(new PageChangeListener());
}
int screenWidth = Utils.getDisplayWidthPixels(mContext);
int maxPagerHeight = mHeight;
mEmoticonPageViews.clear();
mEmoticonsViewPagerAdapter.notifyDataSetChanged();
for (EmoticonSetBean bean : mEmoticonSetBeanList) {
List<EmoticonBean> emoticonList = bean.getEmoticonList();
if (emoticonList != null) {
int emoticonSetSum = emoticonList.size();
int row = bean.getRow();
int line = bean.getLine();
int del = bean.isShowDelBtn() ? 1 : 0;
int everyPageMaxSum = row * line - del;
int pageCount = getPageCount(bean);
mMaxEmoticonSetPageCount = Math.max(mMaxEmoticonSetPageCount, pageCount);
int start = 0;
int end = everyPageMaxSum > emoticonSetSum ? emoticonSetSum : everyPageMaxSum;
RelativeLayout.LayoutParams gridParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
gridParams.addRule(SoftListenLayout.CENTER_VERTICAL);
int itemHeight = Math.min((screenWidth - (bean.getRow() - 1) * Utils.dip2px(mContext, bean.getHorizontalSpacing())) / bean.getRow(), (maxPagerHeight - (bean.getLine() - 1) * Utils.dip2px(mContext, bean.getVerticalSpacing())) / bean.getLine());
for (int i = 0; i < pageCount; i++) {
RelativeLayout rl = new RelativeLayout(mContext);
GridView gridView = new GridView(mContext);
gridView.setNumColumns(bean.getRow());
gridView.setBackgroundColor(Color.TRANSPARENT);
gridView.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
gridView.setCacheColorHint(0);
gridView.setHorizontalSpacing(Utils.dip2px(mContext, bean.getHorizontalSpacing()));
gridView.setVerticalSpacing(Utils.dip2px(mContext, bean.getVerticalSpacing()));
gridView.setSelector(new ColorDrawable(Color.TRANSPARENT));
gridView.setGravity(Gravity.CENTER);
gridView.setVerticalScrollBarEnabled(false);
List<EmoticonBean> list = new ArrayList<>();
for (int j = start; j < end; j++) {
list.add(emoticonList.get(j));
}
if (bean.isShowDelBtn()) {
int count = bean.getLine() * bean.getRow();
while (list.size() < count - 1) {
list.add(null);
}
list.add(new EmoticonBean(EmoticonBean.FACE_TYPE_DEL, "drawable://icon_del", null, null));
} else {
int count = bean.getLine() * bean.getRow();
while (list.size() < count) {
list.add(null);
}
}
EmoticonsAdapter adapter = new EmoticonsAdapter(mContext, list, bean.isShownName());
adapter.setHeight(itemHeight, Utils.dip2px(mContext, bean.getItemPadding()));
gridView.setAdapter(adapter);
rl.addView(gridView, gridParams);
mEmoticonPageViews.add(rl);
adapter.setOnItemListener(this);
start = everyPageMaxSum + i * everyPageMaxSum;
end = everyPageMaxSum + (i + 1) * everyPageMaxSum;
if (end >= emoticonSetSum) {
end = emoticonSetSum;
}
}
}
}
mEmoticonsViewPagerAdapter.notifyDataSetChanged();
}
Aggregations