Search in sources :

Example 1 with ExpandGridView

use of com.juns.wechat.chat.widght.ExpandGridView 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;
}
Also used : OnItemClickListener(android.widget.AdapterView.OnItemClickListener) ArrayList(java.util.ArrayList) ExpandGridView(com.juns.wechat.chat.widght.ExpandGridView) ImageView(android.widget.ImageView) ExpandGridView(com.juns.wechat.chat.widght.ExpandGridView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) EaseMobException(com.easemob.exceptions.EaseMobException) IOException(java.io.IOException) ExpressionAdapter(com.juns.wechat.chat.adpter.ExpressionAdapter) Field(java.lang.reflect.Field)

Aggregations

View (android.view.View)1 AbsListView (android.widget.AbsListView)1 AdapterView (android.widget.AdapterView)1 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 EaseMobException (com.easemob.exceptions.EaseMobException)1 ExpressionAdapter (com.juns.wechat.chat.adpter.ExpressionAdapter)1 ExpandGridView (com.juns.wechat.chat.widght.ExpandGridView)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1