use of com.juns.wechat.chat.adpter.ExpressionAdapter in project wechat by motianhuo.
the class ChatActivity method getGridChildView.
/**
* 获取表情的gridview的子view
*
* @param i
* @return
*/
private View getGridChildView(int i) {
View view = View.inflate(this, R.layout.expression_gridview, null);
ExpandGridView gv = (ExpandGridView) view.findViewById(R.id.gridview);
List<String> list = new ArrayList<String>();
if (i == 1) {
List<String> list1 = reslist.subList(0, 21);
list.addAll(list1);
} else if (i == 2) {
list.addAll(reslist.subList(21, reslist.size()));
} else if (i == 3) {
list.addAll(reslist.subList(42, reslist.size()));
}
list.add("delete_expression");
final ExpressionAdapter expressionAdapter = new ExpressionAdapter(this, 1, list);
gv.setAdapter(expressionAdapter);
gv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String filename = expressionAdapter.getItem(position);
try {
// 按住说话可见,不让输入表情
if (buttonSetModeKeyboard.getVisibility() != View.VISIBLE) {
if (filename != "delete_expression") {
// 不是删除键,显示表情
// 这里用的反射,所以混淆的时候不要混淆SmileUtils这个类
Class clz = Class.forName("com.juns.wechat.chat.utils.SmileUtils");
Field field = clz.getField(filename);
mEditTextContent.append(SmileUtils.getSmiledText(ChatActivity.this, (String) field.get(null)));
} else {
// 删除文字或者表情
if (!TextUtils.isEmpty(mEditTextContent.getText())) {
int selectionStart = mEditTextContent.getSelectionStart();
if (selectionStart > 0) {
String body = mEditTextContent.getText().toString();
String tempStr = body.substring(0, selectionStart);
// 获取最后一个表情的位置
int i = tempStr.lastIndexOf("[");
if (i != -1) {
CharSequence cs = tempStr.substring(i, selectionStart);
if (SmileUtils.containsKey(cs.toString()))
mEditTextContent.getEditableText().delete(i, selectionStart);
else
mEditTextContent.getEditableText().delete(selectionStart - 1, selectionStart);
} else {
mEditTextContent.getEditableText().delete(selectionStart - 1, selectionStart);
}
}
}
}
}
} catch (Exception e) {
}
}
});
return view;
}
Aggregations