Skip to content

Commit ec624e3

Browse files
guangyaoguangyao
authored andcommitted
2 parents 723113a + 437cd9c commit ec624e3

File tree

19 files changed

+603
-482
lines changed

19 files changed

+603
-482
lines changed

android/chatinput/src/main/java/cn/jiguang/imui/chatinput/ChatInputView.java

100755100644
Lines changed: 193 additions & 262 deletions
Large diffs are not rendered by default.

android/chatinput/src/main/java/cn/jiguang/imui/chatinput/listener/OnMenuClickListener.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
package cn.jiguang.imui.chatinput.listener;
22

33

4-
import java.util.List;
5-
6-
import cn.jiguang.imui.chatinput.model.FileItem;
7-
84
/**
95
* Menu items' callbacks
106
*/
@@ -18,15 +14,6 @@ public interface OnMenuClickListener {
1814
*/
1915
boolean onSendTextMessage(CharSequence input);
2016

21-
/**
22-
* Files when send photos or videos.
23-
* When construct send message, you need to judge the type
24-
* of file item, according to
25-
*
26-
* @param list List of file item objects
27-
*/
28-
void onSendFiles(List<FileItem> list);
29-
3017
/**
3118
* Fires when voice button is on click.
3219
*/
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package cn.jiguang.imui.chatinput.record;
2+
3+
import android.content.Context;
4+
import android.support.annotation.AttrRes;
5+
import android.support.annotation.NonNull;
6+
import android.support.annotation.Nullable;
7+
import android.util.AttributeSet;
8+
import android.widget.FrameLayout;
9+
10+
/**
11+
* Created by dowin on 2017/8/26.
12+
*/
13+
14+
public class ActionLayout extends FrameLayout{
15+
public ActionLayout(@NonNull Context context) {
16+
super(context);
17+
}
18+
19+
public ActionLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
20+
super(context, attrs);
21+
}
22+
23+
public ActionLayout(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
24+
super(context, attrs, defStyleAttr);
25+
}
26+
27+
private final Runnable measureAndLayout = new Runnable() {
28+
29+
int width = 0;
30+
int height = 0;
31+
32+
@Override
33+
public void run() {
34+
35+
if (width == 0) {
36+
width = getWidth();
37+
}
38+
if (height == 0) {
39+
height = getHeight();
40+
}
41+
measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
42+
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
43+
layout(getLeft(), getTop(), getRight(), getBottom());
44+
}
45+
};
46+
@Override
47+
public void requestLayout() {
48+
super.requestLayout();
49+
post(measureAndLayout);
50+
}
51+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package cn.jiguang.imui.chatinput.record;
2+
3+
import android.content.Context;
4+
import android.view.MotionEvent;
5+
import android.view.View;
6+
import android.widget.Button;
7+
8+
import cn.jiguang.imui.chatinput.listener.RecordVoiceListener;
9+
10+
/**
11+
* Created by dowin on 2017/8/25.
12+
*/
13+
14+
public class OnChatVoiceTouch implements View.OnTouchListener {
15+
16+
enum UpdateStatus {
17+
Start, Canceled, Move, Continue, Complete
18+
}
19+
20+
final String[] text = new String[]{"按住 说话", "松开 结束", "松开 取消"};
21+
UpdateStatus updateStatus;
22+
private RecordHelper recordHelper;
23+
private Button button;
24+
25+
public OnChatVoiceTouch(Context context, Button button) {
26+
this.button = button;
27+
recordHelper = new RecordHelper(context);
28+
}
29+
30+
31+
void updateStatus(UpdateStatus status) {
32+
if (updateStatus == status) {
33+
return;
34+
}
35+
}
36+
37+
private void onStartAudioRecord() {
38+
button.setText(text[1]);
39+
button.setSelected(false);
40+
recordHelper.startRecording();
41+
}
42+
43+
private void onEndAudioRecord(boolean cancel) {
44+
button.setText(text[0]);
45+
button.setSelected(false);
46+
47+
48+
if (cancel) {
49+
recordHelper.cancelRecord();
50+
} else {
51+
recordHelper.finishRecord();
52+
}
53+
}
54+
55+
/**
56+
* 取消语音录制
57+
*
58+
* @param cancel
59+
*/
60+
private void cancelAudioRecord(boolean cancel) {
61+
button.setSelected(true);
62+
updateTimerTip(cancel);
63+
recordHelper.setCancelAble(cancel);
64+
}
65+
66+
private void updateTimerTip(boolean cancel) {
67+
button.setText(cancel ? text[2] : text[1]);
68+
}
69+
70+
private boolean isCancelled(View view, MotionEvent event) {
71+
int[] location = new int[2];
72+
view.getLocationOnScreen(location);
73+
74+
if (event.getRawX() < location[0] || event.getRawX() > location[0] + view.getWidth()
75+
|| event.getRawY() < location[1] - 40) {
76+
return true;
77+
}
78+
79+
return false;
80+
}
81+
82+
@Override
83+
public boolean onTouch(View v, MotionEvent event) {
84+
if (event.getAction() == MotionEvent.ACTION_DOWN) {
85+
onStartAudioRecord();
86+
updateStatus(UpdateStatus.Start);
87+
} else if (event.getAction() == MotionEvent.ACTION_CANCEL
88+
|| event.getAction() == MotionEvent.ACTION_UP) {
89+
onEndAudioRecord(isCancelled(v, event));
90+
updateStatus(isCancelled(v, event) ? UpdateStatus.Canceled : UpdateStatus.Complete);
91+
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
92+
// touched = true;
93+
cancelAudioRecord(isCancelled(v, event));
94+
updateStatus(isCancelled(v, event) ? UpdateStatus.Move : UpdateStatus.Continue);
95+
}
96+
return false;
97+
}
98+
99+
public void setListener(RecordVoiceListener listener) {
100+
recordHelper.setListener(listener);
101+
}
102+
}

android/chatinput/src/main/res/layout/view_chatinput.xml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
android:layout_height="match_parent" />
2020

2121
<FrameLayout
22-
android:id="@+id/aurora_framelayout_menuitem_voice"
22+
android:id="@+id/imui_layout_voice"
2323
android:layout_width="48dp"
2424
android:layout_height="48dp">
2525

2626
<ImageButton
27-
android:id="@+id/aurora_menuitem_ib_voice"
27+
android:id="@+id/imui_item_voice"
2828
style="@style/ChatInputIcon"
2929
android:scaleType="fitCenter"
3030
android:layout_gravity="center"
@@ -39,7 +39,7 @@
3939
android:layout_weight="1">
4040

4141
<EditText
42-
android:id="@+id/aurora_et_chat_input"
42+
android:id="@+id/imui_chat_input"
4343
android:layout_width="match_parent"
4444
android:layout_height="match_parent"
4545
android:background="@drawable/aurora_edittext_bg"
@@ -53,7 +53,7 @@
5353

5454
<Button
5555
android:background="@drawable/voice_bg"
56-
android:id="@+id/aurora_et_chat_voice"
56+
android:id="@+id/imui_chat_voice"
5757
android:layout_width="match_parent"
5858
android:layout_height="match_parent"
5959
android:text="按住 说话"
@@ -96,7 +96,7 @@
9696
android:scaleType="fitCenter" />
9797

9898
<TextView
99-
android:id="@+id/aurora_menuitem_tv_send_count"
99+
android:id="@+id/imui_receive_count"
100100
android:layout_width="16dp"
101101
android:layout_height="16dp"
102102
android:layout_gravity="bottom|right"
@@ -136,7 +136,7 @@
136136
android:layout_height="match_parent" />
137137
</LinearLayout>
138138

139-
<FrameLayout
139+
<cn.jiguang.imui.chatinput.record.ActionLayout
140140
android:id="@+id/aurora_fl_menu_container"
141141
android:layout_width="match_parent"
142142
android:layout_height="wrap_content"
@@ -152,9 +152,8 @@
152152
android:id="@+id/aurora_view_action_layout"
153153
android:layout_width="match_parent"
154154
android:layout_height="match_parent"
155-
android:orientation="vertical"
156-
android:visibility="gone">
155+
android:orientation="vertical">
157156

158157
</LinearLayout>
159-
</FrameLayout>
158+
</cn.jiguang.imui.chatinput.record.ActionLayout>
160159
</LinearLayout>

android/emoji/src/main/java/dowin/com/emoji/emoji/LinkClick.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dowin.com.emoji.emoji;
22

3+
import android.graphics.Color;
34
import android.text.TextPaint;
45
import android.text.style.ClickableSpan;
56
import android.view.View;
@@ -17,7 +18,7 @@ public interface OnLinkClickListener {
1718
OnLinkClickListener linkClickListener;
1819

1920
private final String url;
20-
private int color = 0xFF000000;
21+
private int color = Color.WHITE;
2122
public LinkClick(String url) {
2223
this.url = url;
2324
}
@@ -42,7 +43,8 @@ public void onClick(View widget) {
4243

4344
@Override
4445
public void updateDrawState(TextPaint ds) {
45-
ds.setColor(color);
46-
ds.setUnderlineText(true);
46+
// ds.setColor(color);
47+
// ds.linkColor = color;
48+
// ds.setUnderlineText(true);
4749
}
4850
}

android/emoji/src/main/java/dowin/com/emoji/emoji/MoonUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private static void viewSetText(View textView, SpannableString mSpannableString)
5959
public static void identifyFaceExpression(Context context,
6060
View textView, String value, int align, float scale, LinkClick.OnLinkClickListener listener) {
6161
SpannableString ss = replaceEmoticons(context, value, scale, align);
62-
Linkify.addLinks(ss, Linkify.WEB_URLS);
62+
Linkify.addLinks(ss, Linkify.WEB_URLS|Linkify.PHONE_NUMBERS|Linkify.EMAIL_ADDRESSES);
6363
URLSpan[] old = ss.getSpans(0, ss.length(), URLSpan.class);
6464
if (old != null && old.length > 0) {
6565
for (int i = old.length - 1; i >= 0; i--) {

android/messagelist/src/main/java/cn/jiguang/imui/commons/models/IMessage.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ enum MessageType {
8888
* Status of message, enum.
8989
*/
9090
enum MessageStatus {
91+
READED,
9192
CREATED,
9293
SEND_GOING,
9394
SEND_SUCCEED,

android/messagelist/src/main/java/cn/jiguang/imui/messages/MsgListAdapter.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import cn.jiguang.imui.messages.viewholder.VideoViewHolder;
4040
import cn.jiguang.imui.messages.viewholder.VoiceViewHolder;
4141

42+
4243
public class MsgListAdapter<MESSAGE extends IMessage> extends RecyclerView.Adapter<ViewHolder>
4344
implements ScrollMoreListener.OnLoadMoreListener {
4445

@@ -382,12 +383,19 @@ public void addToStart(List<MESSAGE> messages, boolean scrollToBottom) {
382383
}
383384
updateShowTimeItem(messages, first, true);
384385
notifyItemRangeInserted(0, messages.size());
385-
if (mLayoutManager != null && scrollToBottom) {
386+
if (mLayoutManager != null && isToBottom()) {
386387
mLayoutManager.scrollToPosition(0);
387388
mLayoutManager.requestLayout();
388389
}
389390
}
390391

392+
boolean isToBottom() {
393+
int firstVisibleItemPosition = mLayoutManager.findFirstVisibleItemPosition();
394+
Log.w(getClass().getName(), firstVisibleItemPosition + "");
395+
return firstVisibleItemPosition <= 0;
396+
397+
}
398+
391399
/**
392400
* Add messages chronologically, to load last page of messages from history, use this method.
393401
*

android/messagelist/src/main/java/cn/jiguang/imui/messages/viewholder/RedPacketOpenViewHolder.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package cn.jiguang.imui.messages.viewholder;
22

3-
import android.graphics.Bitmap;
4-
import android.graphics.BitmapFactory;
53
import android.graphics.Color;
64
import android.support.v7.widget.RecyclerView;
75
import android.text.SpannableString;
@@ -12,7 +10,6 @@
1210
import android.text.style.ImageSpan;
1311
import android.view.View;
1412
import android.widget.TextView;
15-
import android.widget.Toast;
1613

1714
import java.util.regex.Matcher;
1815
import java.util.regex.Pattern;
@@ -50,10 +47,10 @@ public void onBind(MESSAGE message) {
5047
String mText = "icon" + extend.getTipMsg();
5148
Matcher m = pattern.matcher(mText);
5249
SpannableString spann = new SpannableString(mText);
53-
if (imageSpan == null) {
54-
Bitmap b = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.icon_packet);
55-
imageSpan = new ImageSpan(mContext, b);
56-
}
50+
// if (imageSpan == null) {
51+
// Bitmap b = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.icon_packet);
52+
// imageSpan = new ImageSpan(mContext, b);
53+
// }
5754
// spann.setSpan(imageSpan, 0, 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
5855
while (m.find()) {
5956
int start = m.start();
@@ -82,7 +79,6 @@ public void onClick(View widget) {
8279
if (mMsgClickListener != null) {
8380
mMsgClickListener.onMessageClick(message);
8481
}
85-
Toast.makeText(mContext, "红包!!", Toast.LENGTH_SHORT).show();
8682
}
8783

8884
@Override

0 commit comments

Comments
 (0)