-
Notifications
You must be signed in to change notification settings - Fork 598
/
Copy pathSimpleTranslucentChatActivity.java
204 lines (181 loc) · 6.94 KB
/
SimpleTranslucentChatActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
package com.xhsemoticonskeyboard.activity;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.AbsListView;
import android.widget.ListView;
import android.widget.Toast;
import com.sj.emoji.EmojiBean;
import com.xhsemoticonskeyboard.R;
import com.xhsemoticonskeyboard.common.Constants;
import com.xhsemoticonskeyboard.common.SimpleCommonUtils;
import com.xhsemoticonskeyboard.common.adapter.ChattingListAdapter;
import com.xhsemoticonskeyboard.common.data.ImMsgBean;
import com.xhsemoticonskeyboard.common.widget.SimpleAppsGridView;
import java.util.ArrayList;
import java.util.List;
import butterknife.Bind;
import butterknife.ButterKnife;
import sj.keyboard.XhsEmoticonsKeyBoard;
import sj.keyboard.data.EmoticonEntity;
import sj.keyboard.interfaces.EmoticonClickListener;
import sj.keyboard.utils.EmoticonsKeyboardUtils;
import sj.keyboard.widget.EmoticonsEditText;
import sj.keyboard.widget.FuncLayout;
public class SimpleTranslucentChatActivity extends AppCompatActivity implements FuncLayout.OnFuncKeyBoardListener {
@Bind(R.id.toolbar) Toolbar toolbar;
@Bind(R.id.lv_chat) ListView lvChat;
@Bind(R.id.ek_bar) XhsEmoticonsKeyBoard ekBar;
private ChattingListAdapter chattingListAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
setContentView(R.layout.activity_simple_chat_translucent);
ButterKnife.bind(this);
toolbar.setTitle("Simple Chat Keyboard");
initView();
}
private void initView() {
initEmoticonsKeyBoardBar();
initListView();
}
private void initEmoticonsKeyBoardBar() {
SimpleCommonUtils.initEmoticonsEditText(ekBar.getEtChat());
ekBar.setAdapter(SimpleCommonUtils.getCommonAdapter(this, emoticonClickListener));
ekBar.addOnFuncKeyBoardListener(this);
ekBar.addFuncView(new SimpleAppsGridView(this));
ekBar.getEtChat().setOnSizeChangedListener(new EmoticonsEditText.OnSizeChangedListener() {
@Override
public void onSizeChanged(int w, int h, int oldw, int oldh) {
scrollToBottom();
}
});
ekBar.getBtnSend().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
OnSendBtnClick(ekBar.getEtChat().getText().toString());
ekBar.getEtChat().setText("");
}
});
ekBar.getEmoticonsToolBarView().addFixedToolItemView(false, R.mipmap.icon_add, null, new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(SimpleTranslucentChatActivity.this, "ADD", Toast.LENGTH_SHORT).show();
}
});
ekBar.getEmoticonsToolBarView().addToolItemView(R.mipmap.icon_setting, new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(SimpleTranslucentChatActivity.this, "SETTING", Toast.LENGTH_SHORT).show();
}
});
}
EmoticonClickListener emoticonClickListener = new EmoticonClickListener() {
@Override
public void onEmoticonClick(Object o, int actionType, boolean isDelBtn) {
if (isDelBtn) {
SimpleCommonUtils.delClick(ekBar.getEtChat());
} else {
if(o == null){
return;
}
if(actionType == Constants.EMOTICON_CLICK_BIGIMAGE){
if(o instanceof EmoticonEntity){
OnSendImage(((EmoticonEntity)o).getIconUri());
}
} else {
String content = null;
if(o instanceof EmojiBean){
content = ((EmojiBean)o).emoji;
} else if(o instanceof EmoticonEntity){
content = ((EmoticonEntity)o).getContent();
}
if(TextUtils.isEmpty(content)){
return;
}
int index = ekBar.getEtChat().getSelectionStart();
Editable editable = ekBar.getEtChat().getText();
editable.insert(index, content);
}
}
}
};
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if(EmoticonsKeyboardUtils.isFullScreen(this)){
boolean isConsum = ekBar.dispatchKeyEventInFullScreen(event);
return isConsum ? isConsum : super.dispatchKeyEvent(event);
}
return super.dispatchKeyEvent(event);
}
private void initListView() {
chattingListAdapter = new ChattingListAdapter(this);
List<ImMsgBean> beanList = new ArrayList<>();
for (int i = 0; i < 20; i++) {
ImMsgBean bean = new ImMsgBean();
bean.setContent("Test:" + i);
beanList.add(bean);
}
chattingListAdapter.addData(beanList);
lvChat.setAdapter(chattingListAdapter);
lvChat.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
switch (scrollState) {
case SCROLL_STATE_FLING:
break;
case SCROLL_STATE_IDLE:
break;
case SCROLL_STATE_TOUCH_SCROLL:
ekBar.reset();
break;
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
}
});
}
private void OnSendBtnClick(String msg) {
if (!TextUtils.isEmpty(msg)) {
ImMsgBean bean = new ImMsgBean();
bean.setContent(msg);
chattingListAdapter.addData(bean, true, false);
scrollToBottom();
}
}
private void OnSendImage(String image) {
if (!TextUtils.isEmpty(image)) {
OnSendBtnClick("[img]" + image);
}
}
private void scrollToBottom() {
lvChat.requestLayout();
lvChat.post(new Runnable() {
@Override
public void run() {
lvChat.setSelection(lvChat.getBottom());
}
});
}
@Override
public void OnFuncPop(int height) {
scrollToBottom();
}
@Override
public void OnFuncClose() { }
@Override
protected void onPause() {
super.onPause();
ekBar.reset();
}
}