Commit 1d77a571893007ffde073e557eca2af9a2431351

Authored by 陈硕
1 parent bf007192

添加语音 图片

Showing 27 changed files with 1056 additions and 333 deletions
app/src/main/AndroidManifest.xml
... ... @@ -34,26 +34,20 @@
34 34  
35 35 <activity
36 36 android:name="com.cnlive.im.ui.ChatRoomActivity"
37   - android:windowSoftInputMode="adjustResize"
38 37 android:theme="@style/Theme.AppCompat.Light.NoActionBar"
39   - >
40   - </activity>
  38 + android:windowSoftInputMode="adjustResize"></activity>
41 39  
42 40 <activity
43 41 android:name="com.cnlive.im.ui.LoGinActivity"
44   - />
  42 + android:screenOrientation="portrait" />
45 43  
46 44 <activity
47 45 android:name=".ui.UserLoginActivity"
48   - />
49   - <activity
50   - android:name="com.cnlive.im.ui.PrivateChatActivity"
51   - />
  46 + android:screenOrientation="portrait" />
52 47  
53 48 <activity
54 49 android:name="com.cnlive.im.ui.CommentActivity"
55   - />
56   -
  50 + android:screenOrientation="portrait" />
57 51  
58 52  
59 53 <service
... ... @@ -61,11 +55,13 @@
61 55 android:exported="true"
62 56 android:process=":ipc" />
63 57  
64   - <service android:name="io.rong.imlib.ReConnectService"
65   - android:exported="true"/>
  58 + <service
  59 + android:name="io.rong.imlib.ReConnectService"
  60 + android:exported="true" />
66 61  
67   - <receiver android:name="io.rong.imlib.ConnectChangeReceiver"
68   - android:exported="true"/>
  62 + <receiver
  63 + android:name="io.rong.imlib.ConnectChangeReceiver"
  64 + android:exported="true" />
69 65  
70 66 <receiver
71 67 android:name="io.rong.imlib.HeartbeatReceiver"
... ...
app/src/main/java/com/cnlive/im/adapter/ChatListAdapter.java
1 1 package com.cnlive.im.adapter;
2 2  
3   -import android.annotation.TargetApi;
4   -import android.content.Context;
5   -import android.graphics.Color;
6   -import android.os.Build;
7   -import android.view.LayoutInflater;
8   -import android.view.View;
9   -import android.view.ViewGroup;
10   -import android.widget.BaseAdapter;
11   -import android.widget.RelativeLayout;
12   -import android.widget.TextView;
13   -
14   -import com.cnlive.im.R;
15   -import com.cnlive.im.ui.ChatRoomActivity;
16   -
17   -import org.json.JSONException;
18   -import org.json.JSONObject;
19   -
20   -import java.util.ArrayList;
21   -import java.util.List;
22   -
23 3 /**
24 4 * Created by Lynn on 2/13/2017.
25 5 */
26 6  
27   -public class ChatListAdapter extends BaseAdapter {
  7 +public class ChatListAdapter {
28 8  
29   - private List<ChatRoomActivity.CNMessageInfo> msgList;
  9 + /* private List<Object> msgList;
30 10 private LayoutInflater mInflater = null;
31 11 private final RelativeLayout.LayoutParams layoutParams;
  12 + Context mContext;
32 13  
33 14 public ChatListAdapter(Context context) {
  15 + this.mContext = context;
34 16 msgList = new ArrayList<>();
35 17 mInflater = LayoutInflater.from(context);
36 18 layoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
... ... @@ -54,52 +36,92 @@ public class ChatListAdapter extends BaseAdapter {
54 36 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
55 37 @Override
56 38 public View getView(int position, View convertView, ViewGroup parent) {
57   - ViewHolder viewHolder;
58   - if (convertView == null) {
59   - viewHolder = new ViewHolder();
60   - convertView = mInflater.inflate(R.layout.msg_text_view, null);
61   - viewHolder.mRelativeLayout = (RelativeLayout) convertView.findViewById(R.id.re_chat_room);
62   - viewHolder.userName = (TextView) convertView.findViewById(R.id.user_name);
63   - viewHolder.msgContent = (TextView) convertView.findViewById(R.id.msg_text);
64   - convertView.setTag(viewHolder);
65   - } else {
66   - viewHolder = (ViewHolder) convertView.getTag();
67   - }
68 39  
69   - if (msgList.get(position).isSendMesageInfo()) {
70   - viewHolder.msgContent.setText(msgList.get(position).getCnMessage().getUserInfo().getUserName() == null ? "" : " : " + msgList.get(position).getCnMessage().getUserInfo().getUserName());
71   - try {
72   - viewHolder.userName.setText(msgList.get(position).getCnMessage().getContent() == null ? "" : (String) new JSONObject(msgList.get(position).getCnMessage().getContent()).get("message"));
73   - } catch (JSONException e) {
74   - e.printStackTrace();
75   - }
76   - layoutParams.removeRule(RelativeLayout.ALIGN_PARENT_START);
77   - layoutParams.addRule(RelativeLayout.ALIGN_PARENT_END);
78   - viewHolder.mRelativeLayout.setLayoutParams(layoutParams);
79   - viewHolder.msgContent.setTextColor(Color.parseColor("#d61d0c"));
80   - viewHolder.userName.setTextColor(Color.BLACK);
81   - } else {
82   - viewHolder.userName.setText(msgList.get(position).getCnMessage().getUserInfo().getUserName() == null ? "" : msgList.get(position).getCnMessage().getUserInfo().getUserName() + " : ");
83   - try {
84   - viewHolder.msgContent.setText(msgList.get(position).getCnMessage().getContent() == null ? "" : msgList.get(position).getCnMessage().getContent() == null ? "" : (String) new JSONObject(msgList.get(position).getCnMessage().getContent()).get("message"));
85   - } catch (JSONException e) {
86   - e.printStackTrace();
  40 + cnStringMessage(position, convertView, parent);
  41 + cnImaMessage(position, convertView,parent);
  42 +
  43 +
  44 + return convertView;
  45 +
  46 + }
  47 +
  48 + private void cnImaMessage(int position, View convertView,ViewGroup parent) {
  49 + ImaViewHolder viewHolder;
  50 + Object cnImagMessage = msgList.get(position);
  51 + if (cnImagMessage instanceof ImagMessage) {
  52 + if (convertView == null) {
  53 + viewHolder = new ImaViewHolder();
  54 + if (((ImagMessage) cnImagMessage).isUserSend()) {
  55 + convertView = mInflater.inflate(R.layout.imag_layout_item_user, parent,false);
  56 + viewHolder.userName = (TextView) convertView.findViewById(R.id.img_user_name);
  57 + viewHolder.userImaView = (ImageView) convertView.findViewById(R.id.img_content);
  58 + convertView.setTag(viewHolder);
  59 + }
  60 +
  61 + } else {
  62 + viewHolder = (ImaViewHolder) convertView.getTag();
87 63 }
88   - viewHolder.mRelativeLayout.setLayoutParams(layoutParams);
89   - layoutParams.removeRule(RelativeLayout.ALIGN_PARENT_END);
90   - layoutParams.addRule(RelativeLayout.ALIGN_PARENT_START);
91   - viewHolder.userName.setTextColor(Color.parseColor("#d61d0c"));
92   - viewHolder.msgContent.setTextColor(Color.BLACK);
  64 + ImagMessage cnImagMessage1 = (ImagMessage) cnImagMessage;
  65 + viewHolder.userName.setText(cnImagMessage1.getCnImgMessage().getUserInfo().getUserName());
  66 + Glide.with(mContext).load(cnImagMessage1.getCnImgMessage().getThumUri()).into(viewHolder.userImaView);
  67 +
  68 +
93 69 }
94 70  
95 71  
96   - return convertView;
97 72  
98 73 }
99 74  
  75 + @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
  76 + private void cnStringMessage(int position, View convertView, ViewGroup parent) {
  77 + ViewHolder viewHolder;
  78 + Object o = msgList.get(position);
  79 + if (o instanceof ChatRoomActivity.CNMessageInfo) {
  80 + if (convertView == null) {
  81 + viewHolder = new ViewHolder();
  82 + convertView = mInflater.inflate(R.layout.msg_text_view, parent,false);
  83 + viewHolder.mRelativeLayout = (RelativeLayout) convertView.findViewById(R.id.re_chat_room);
  84 + viewHolder.userName = (TextView) convertView.findViewById(R.id.user_name);
  85 + viewHolder.msgContent = (TextView) convertView.findViewById(R.id.msg_text);
  86 + convertView.setTag(viewHolder);
  87 + } else {
  88 + viewHolder = (ViewHolder) convertView.getTag();
  89 + }
  90 + ChatRoomActivity.CNMessageInfo cnMessageInfo = (ChatRoomActivity.CNMessageInfo) msgList.get(position);
  91 + if (cnMessageInfo.isSendMesageInfo()) {
  92 + viewHolder.msgContent.setText(cnMessageInfo.getCnMessage().getUserInfo().getUserName() == null ? "" : " : " + cnMessageInfo.getCnMessage().getUserInfo().getUserName());
  93 + try {
  94 + viewHolder.userName.setText(cnMessageInfo.getCnMessage().getContent() == null ? "" : (String) new JSONObject(cnMessageInfo.getCnMessage().getContent()).get("message"));
  95 + } catch (JSONException e) {
  96 + e.printStackTrace();
  97 + }
  98 + layoutParams.removeRule(RelativeLayout.ALIGN_PARENT_START);
  99 + layoutParams.addRule(RelativeLayout.ALIGN_PARENT_END);
  100 + viewHolder.mRelativeLayout.setLayoutParams(layoutParams);
  101 + viewHolder.msgContent.setTextColor(Color.parseColor("#d61d0c"));
  102 + viewHolder.userName.setTextColor(Color.BLACK);
  103 + } else {
  104 + viewHolder.userName.setText(cnMessageInfo.getCnMessage().getUserInfo().getUserName() == null ? "" : cnMessageInfo.getCnMessage().getUserInfo().getUserName() + " : ");
  105 + try {
  106 + viewHolder.msgContent.setText(cnMessageInfo.getCnMessage().getContent() == null ? "" : cnMessageInfo.getCnMessage().getContent() == null ? "" : (String) new JSONObject(cnMessageInfo.getCnMessage().getContent()).get("message"));
  107 + } catch (JSONException e) {
  108 + e.printStackTrace();
  109 + }
  110 + viewHolder.mRelativeLayout.setLayoutParams(layoutParams);
  111 + layoutParams.removeRule(RelativeLayout.ALIGN_PARENT_END);
  112 + layoutParams.addRule(RelativeLayout.ALIGN_PARENT_START);
  113 + viewHolder.userName.setTextColor(Color.parseColor("#d61d0c"));
  114 + viewHolder.msgContent.setTextColor(Color.BLACK);
  115 + }
100 116  
101 117  
102   - public void updateItems(List<ChatRoomActivity.CNMessageInfo> items) {
  118 + }
  119 +
  120 +
  121 + }
  122 +
  123 +
  124 + public void updateItems(List<Object> items) {
103 125 if (items == null) return;
104 126 msgList.clear();
105 127 msgList.addAll(items);
... ... @@ -112,4 +134,11 @@ public class ChatListAdapter extends BaseAdapter {
112 134 RelativeLayout mRelativeLayout;
113 135  
114 136 }
  137 +
  138 +
  139 + private class ImaViewHolder {
  140 + TextView userName;
  141 + ImageView userImaView;
  142 +
  143 + }*/
115 144 }
... ...
app/src/main/java/com/cnlive/im/adapter/ChatRoomAdpter.java 0 → 100644
  1 +package com.cnlive.im.adapter;
  2 +
  3 +import android.content.Context;
  4 +import android.graphics.Color;
  5 +import android.net.Uri;
  6 +import android.support.v7.widget.RecyclerView;
  7 +import android.view.LayoutInflater;
  8 +import android.view.View;
  9 +import android.view.ViewGroup;
  10 +import android.widget.ImageView;
  11 +import android.widget.TextView;
  12 +
  13 +import com.bumptech.glide.Glide;
  14 +import com.cnlive.im.R;
  15 +import com.cnlive.im.adapter.base.BaseRecyclerAdapter;
  16 +import com.cnlive.im.adapter.base.VoiceItemClickListener;
  17 +import com.cnlive.im.mode.ImagMessage;
  18 +import com.cnlive.im.mode.StringMessage;
  19 +import com.cnlive.im.mode.VoiceMessage;
  20 +
  21 +/**
  22 + * @author 陈硕
  23 + * @time 2017/7/14 14:35
  24 + * @desc ${TODD}
  25 + */
  26 +public class ChatRoomAdpter extends BaseRecyclerAdapter {
  27 +
  28 + private int stringUser = 1;
  29 + private int stringOppsite = 2;
  30 + private int imaUser = 3;
  31 + private int imaOppsite = 4;
  32 + private int voiceUser = 5;
  33 + private int voiceOppsite = 6;
  34 + private Context mContext;
  35 + private VoiceItemClickListener mVoiceItemClickListener;
  36 +
  37 + public ChatRoomAdpter(Context context) {
  38 + super(context);
  39 + this.mContext = context;
  40 +
  41 + }
  42 +
  43 +
  44 + public void setonVoiceItemClickListener(VoiceItemClickListener voiveItemClickListener) {
  45 + this.mVoiceItemClickListener = voiveItemClickListener;
  46 + }
  47 +
  48 + @Override
  49 + public int getItemViewType(int position) {
  50 + Object o = mItems.get(position);
  51 + if (o instanceof StringMessage) {
  52 + StringMessage o1 = (StringMessage) o;
  53 + boolean userSend = o1.isUserSend();
  54 + if (userSend) return stringUser;
  55 + else return stringOppsite;
  56 + } else if (o instanceof ImagMessage) {
  57 + ImagMessage o1 = (ImagMessage) o;
  58 + if (o1.isUserSend()) return imaUser;
  59 + else return imaOppsite;
  60 + } else if (o instanceof VoiceMessage) {
  61 + VoiceMessage o1 = (VoiceMessage) o;
  62 + if (o1.isUserSend())
  63 + return voiceUser;
  64 + else return voiceOppsite;
  65 +
  66 + }
  67 + return 0;
  68 + }
  69 +
  70 + @Override
  71 + public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
  72 + if (viewType == imaUser) {
  73 + return new ImaMessageHolder(LayoutInflater.from(mContext).inflate(R.layout.imag_layout_item_user, null));
  74 + } else if (viewType == imaOppsite) {
  75 + return new ImaMessageHolder(LayoutInflater.from(mContext).inflate(R.layout.imag_layout_item_oppsite, null));
  76 + } else if (viewType == stringUser) {
  77 + return new StringMessageHolder(LayoutInflater.from(mContext).inflate(R.layout.string_layout_item_user, null));
  78 + } else if (viewType == stringOppsite) {
  79 + return new StringMessageHolder(LayoutInflater.from(mContext).inflate(R.layout.string_layout_item_oppsite, null));
  80 + } else if (viewType == voiceUser) {
  81 + return new VoiceMessageHolder(LayoutInflater.from(mContext).inflate(R.layout.voice_layout_item_user, null));
  82 + } else if (viewType == voiceOppsite) {
  83 + return new VoiceMessageHolder(LayoutInflater.from(mContext).inflate(R.layout.voice_layout_item_oppsite, null));
  84 + }
  85 + return null;
  86 + }
  87 +
  88 + @Override
  89 + public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
  90 + if (holder instanceof StringMessageHolder) {
  91 + StringMessageHolder holder1 = (StringMessageHolder) holder;
  92 + Object o = mItems.get(position);
  93 + StringMessage o1 = (StringMessage) o;
  94 + holder1.msg_text.setText(o1.getCnMessage().getContent());
  95 + holder1.user_name.setText(o1.getCnMessage().getUserInfo().getUserName());
  96 + holder1.user_name.setTextColor(Color.parseColor("#d61d0c"));
  97 + holder1.msg_text.setTextColor(Color.BLACK);
  98 + } else if (holder instanceof ImaMessageHolder) {
  99 + ImaMessageHolder holder1 = (ImaMessageHolder) holder;
  100 + Object o = mItems.get(position);
  101 + ImagMessage o1 = (ImagMessage) o;
  102 + holder1.ima_user_name.setTextColor(Color.parseColor("#d61d0c"));
  103 + Glide.with(mContext).load(o1.getCnImgMessage().getRemoteUri()).into(holder1.img_content);
  104 + holder1.ima_user_name.setText(o1.getCnImgMessage().getUserInfo().getUserName());
  105 + } else if (holder instanceof VoiceMessageHolder) {
  106 + VoiceMessageHolder holder1 = (VoiceMessageHolder) holder;
  107 + Object o = mItems.get(position);
  108 + VoiceMessage o1 = (VoiceMessage) o;
  109 + holder1.voice_user_name.setText(o1.getCnVoiceMessage().getUserInfo().getUserName());
  110 + final Uri voiceUri = o1.getCnVoiceMessage().getVoiceUri();
  111 + holder1.itemView.setOnClickListener(new View.OnClickListener() {
  112 + @Override
  113 + public void onClick(View v) {
  114 + mVoiceItemClickListener.onItemClick(voiceUri);
  115 + }
  116 + });
  117 + }
  118 +
  119 + }
  120 +
  121 + public class StringMessageHolder extends RecyclerView.ViewHolder {
  122 + private TextView user_name;
  123 + private TextView msg_text;
  124 +
  125 + public StringMessageHolder(View itemView) {
  126 + super(itemView);
  127 + user_name = (TextView) itemView.findViewById(R.id.user_name);
  128 + msg_text = (TextView) itemView.findViewById(R.id.msg_text);
  129 +
  130 + }
  131 + }
  132 +
  133 + public class ImaMessageHolder extends RecyclerView.ViewHolder {
  134 +
  135 + private TextView ima_user_name;
  136 + private ImageView img_content;
  137 +
  138 + public ImaMessageHolder(View itemView) {
  139 + super(itemView);
  140 + ima_user_name = (TextView) itemView.findViewById(R.id.img_user_name);
  141 + img_content = (ImageView) itemView.findViewById(R.id.img_content);
  142 + }
  143 + }
  144 +
  145 + public class VoiceMessageHolder extends RecyclerView.ViewHolder {
  146 +
  147 +
  148 + private TextView voice_user_name;
  149 + private ImageView voice_content;
  150 +
  151 + public VoiceMessageHolder(View itemView) {
  152 + super(itemView);
  153 + voice_user_name = (TextView) itemView.findViewById(R.id.voice_user_name);
  154 + voice_content = (ImageView) itemView.findViewById(R.id.voice_content);
  155 + }
  156 + }
  157 +
  158 +
  159 +
  160 +}
... ...
app/src/main/java/com/cnlive/im/adapter/base/BaseRecyclerAdapter.java 0 → 100644
  1 +package com.cnlive.im.adapter.base;
  2 +
  3 +import android.content.Context;
  4 +import android.support.annotation.NonNull;
  5 +import android.support.annotation.Nullable;
  6 +import android.support.v7.widget.RecyclerView;
  7 +import android.util.Log;
  8 +import android.view.LayoutInflater;
  9 +
  10 +import java.util.ArrayList;
  11 +import java.util.List;
  12 +
  13 +
  14 +/**
  15 + * Created by zuoxian on 15/9/7.
  16 + */
  17 +public abstract class BaseRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
  18 +
  19 +
  20 + protected List<Object> mItems ;
  21 + protected Context mContext;
  22 + public LayoutInflater inflater;
  23 + public BaseRecyclerAdapter(Context context){
  24 + this.mContext = context;
  25 + inflater = LayoutInflater.from(context);
  26 + mItems = new ArrayList<>();
  27 + }
  28 +
  29 + public List<Object> getList() {
  30 + return mItems;
  31 + }
  32 +
  33 + public void addItem(@Nullable Object item) {
  34 + if(item == null) return ;
  35 + mItems.add(mItems.size(), item);
  36 + notifyItemInserted(mItems.size());
  37 + }
  38 +
  39 + public void addItems(@Nullable List<Object> items){
  40 + if(items == null) return ;
  41 + this.mItems.addAll(items);
  42 + notifyDataSetChanged();
  43 + }
  44 +
  45 + public boolean containsAll(@NonNull List<Object> items){
  46 + return mItems.containsAll(items);
  47 + }
  48 +
  49 + public void updateItem(@Nullable Object tasks, int position) {
  50 + if(tasks == null) return ;
  51 + mItems.set(position, tasks);
  52 + notifyItemChanged(position);
  53 + }
  54 +
  55 + public void updateItems(@Nullable List<Object> items){
  56 + if(items == null) return;
  57 + this.mItems.clear();
  58 + this.mItems.addAll(items);
  59 + Log.v("getItemCount",mItems.size()+"");
  60 +
  61 + notifyDataSetChanged();
  62 + }
  63 +
  64 + public void removeItem(int index) {
  65 + mItems.remove(index);
  66 + notifyItemRemoved(index);
  67 + }
  68 +
  69 + public void getView(int position , RecyclerView.ViewHolder viewHolder, int type, Object item){}
  70 +
  71 + public Object getItem(int location) {
  72 + return mItems.get(location);
  73 + }
  74 +
  75 + @Override
  76 + public int getItemCount() {
  77 + Log.v("getItemCount",mItems.size()+"");
  78 + return mItems == null ? 0 : mItems.size();
  79 + }
  80 +
  81 + public void clear(){
  82 + mItems.clear();
  83 + notifyDataSetChanged();
  84 + }
  85 +
  86 +}
... ...
app/src/main/java/com/cnlive/im/adapter/base/VoiceItemClickListener.java 0 → 100644
  1 +package com.cnlive.im.adapter.base;
  2 +
  3 +import android.net.Uri;
  4 +
  5 +/**
  6 + * @author 陈硕
  7 + * @time 2017/7/14 17:50
  8 + * @desc ${TODD}
  9 + */
  10 +public interface VoiceItemClickListener {
  11 + void onItemClick(Uri uri);
  12 +}
... ...
app/src/main/java/com/cnlive/im/mode/ImagMessage.java 0 → 100644
  1 +package com.cnlive.im.mode;
  2 +
  3 +import com.cnlive.libs.util.chat.model.CNImgMessage;
  4 +
  5 +/**
  6 + * @author 陈硕
  7 + * @time 2017/7/14 11:51
  8 + * @desc ${TODD}
  9 + */
  10 +public class ImagMessage {
  11 + private String type;
  12 + private CNImgMessage cnImgMessage;
  13 + boolean isUserSend;
  14 +
  15 +
  16 + public String getType() {
  17 + return type;
  18 + }
  19 +
  20 + public void setType(String type) {
  21 + this.type = type;
  22 + }
  23 +
  24 + public CNImgMessage getCnImgMessage() {
  25 + return cnImgMessage;
  26 + }
  27 +
  28 + public void setCnImgMessage(CNImgMessage cnImgMessage) {
  29 + this.cnImgMessage = cnImgMessage;
  30 + }
  31 +
  32 + public boolean isUserSend() {
  33 + return isUserSend;
  34 + }
  35 +
  36 + public void setUserSend(boolean userSend) {
  37 + isUserSend = userSend;
  38 + }
  39 +
  40 + public ImagMessage( String type,CNImgMessage cnImgMessage, boolean isUserSend) {
  41 + this.type = type;
  42 + this.cnImgMessage = cnImgMessage;
  43 + this.isUserSend = isUserSend;
  44 + }
  45 +}
... ...
app/src/main/java/com/cnlive/im/mode/StringMessage.java 0 → 100644
  1 +package com.cnlive.im.mode;
  2 +
  3 +import com.cnlive.libs.util.chat.model.CNMessage;
  4 +
  5 +/**
  6 + * @author 陈硕
  7 + * @time 2017/7/14 14:43
  8 + * @desc ${TODD}
  9 + */
  10 +public class StringMessage {
  11 +
  12 + private String type;
  13 + private CNMessage cnMessage;
  14 + boolean isUserSend;
  15 +
  16 + public StringMessage(String type, CNMessage cnMessage, boolean isUserSend) {
  17 + this.type = type;
  18 + this.cnMessage = cnMessage;
  19 + this.isUserSend = isUserSend;
  20 + }
  21 +
  22 + public String getType() {
  23 + return type;
  24 + }
  25 +
  26 + public void setType(String type) {
  27 + this.type = type;
  28 + }
  29 +
  30 + public CNMessage getCnMessage() {
  31 + return cnMessage;
  32 + }
  33 +
  34 + public void setCnMessage(CNMessage cnMessage) {
  35 + this.cnMessage = cnMessage;
  36 + }
  37 +
  38 + public boolean isUserSend() {
  39 + return isUserSend;
  40 + }
  41 +
  42 + public void setUserSend(boolean userSend) {
  43 + isUserSend = userSend;
  44 + }
  45 +}
... ...
app/src/main/java/com/cnlive/im/mode/VoiceMessage.java 0 → 100644
  1 +package com.cnlive.im.mode;
  2 +
  3 +import com.cnlive.libs.util.chat.model.CNVoiceMessage;
  4 +
  5 +/**
  6 + * @author 陈硕
  7 + * @time 2017/7/14 16:51
  8 + * @desc ${TODD}
  9 + */
  10 +public class VoiceMessage {
  11 + private String type;
  12 + private CNVoiceMessage cnVoiceMessage;
  13 + boolean isUserSend;
  14 +
  15 + public VoiceMessage(String type, CNVoiceMessage cnVoiceMessage, boolean isUserSend) {
  16 + this.type = type;
  17 + this.cnVoiceMessage = cnVoiceMessage;
  18 + this.isUserSend = isUserSend;
  19 + }
  20 +
  21 + public String getType() {
  22 + return type;
  23 + }
  24 +
  25 + public void setType(String type) {
  26 + this.type = type;
  27 + }
  28 +
  29 + public CNVoiceMessage getCnVoiceMessage() {
  30 + return cnVoiceMessage;
  31 + }
  32 +
  33 + public void setCnVoiceMessage(CNVoiceMessage cnVoiceMessage) {
  34 + this.cnVoiceMessage = cnVoiceMessage;
  35 + }
  36 +
  37 + public boolean isUserSend() {
  38 + return isUserSend;
  39 + }
  40 +
  41 + public void setUserSend(boolean userSend) {
  42 + isUserSend = userSend;
  43 + }
  44 +}
... ...
app/src/main/java/com/cnlive/im/ui/ChatRoomActivity.java
1 1 package com.cnlive.im.ui;
2 2  
  3 +import android.Manifest;
  4 +import android.app.Activity;
3 5 import android.content.Intent;
  6 +import android.content.pm.PackageManager;
  7 +import android.net.Uri;
  8 +import android.os.Build;
4 9 import android.os.Bundle;
5 10 import android.os.Handler;
  11 +import android.support.v4.content.ContextCompat;
6 12 import android.support.v7.app.AppCompatActivity;
  13 +import android.support.v7.widget.LinearLayoutManager;
  14 +import android.support.v7.widget.RecyclerView;
7 15 import android.util.Log;
  16 +import android.view.MotionEvent;
8 17 import android.view.View;
9 18 import android.widget.Button;
10 19 import android.widget.EditText;
11 20 import android.widget.LinearLayout;
12   -import android.widget.ListView;
13 21 import android.widget.RelativeLayout;
14 22 import android.widget.Toast;
15 23  
16 24 import com.cnlive.im.R;
17   -import com.cnlive.im.adapter.ChatListAdapter;
18   -import com.cnlive.im.mode.CNMessageModole;
19   -import com.cnlive.im.util.ToStringUtils;
  25 +import com.cnlive.im.adapter.ChatRoomAdpter;
  26 +import com.cnlive.im.adapter.base.VoiceItemClickListener;
  27 +import com.cnlive.im.mode.ImagMessage;
  28 +import com.cnlive.im.mode.StringMessage;
  29 +import com.cnlive.im.mode.VoiceMessage;
  30 +import com.cnlive.im.util.MediaRecorderUtil;
  31 +import com.cnlive.im.util.MessageType;
20 32 import com.cnlive.libs.util.chat.ChatUtil;
21 33 import com.cnlive.libs.util.chat.base.IChat;
22   -import com.cnlive.libs.util.chat.model.CNChatRoomInfo;
23   -import com.cnlive.libs.util.chat.model.CNChatRoomMemberInfo;
  34 +import com.cnlive.libs.util.chat.model.CNImgMessage;
24 35 import com.cnlive.libs.util.chat.model.CNMessage;
25 36 import com.cnlive.libs.util.chat.model.CNUserInfo;
  37 +import com.cnlive.libs.util.chat.model.CNVoiceMessage;
26 38  
27 39 import org.json.JSONException;
28   -import org.json.JSONObject;
29 40  
30 41 import java.util.ArrayList;
31   -import java.util.List;
32 42  
33 43  
34 44 /**
... ... @@ -36,24 +46,33 @@ import java.util.List;
36 46 * @time 2017/3/7 14:36
37 47 * @desc ${TODD}
38 48 */
39   -public class ChatRoomActivity extends AppCompatActivity implements View.OnClickListener {
  49 +public class ChatRoomActivity extends AppCompatActivity implements View.OnClickListener, View.OnTouchListener, VoiceItemClickListener {
40 50 private static final String TAG = "ChatRoomActivity";
41   - private ArrayList<CNMessageInfo> groupChatOneListMy;
  51 + private ArrayList<Object> groupChatOneListMy;
42 52 private String roomIdOne = "ChatRoom05";
43 53 private EditText editText;
44 54 private Button send_messageOneBtn;
45   - private ListView listViewOne;
46   - private ChatListAdapter chatListAdapterOne;
  55 + private RecyclerView listViewOne;
  56 + private ChatRoomAdpter chatListAdapterOne;
47 57 private Button foundChatBtn;
48 58 private Handler mHandler;
49 59 private RelativeLayout re_chat;
50 60 private LinearLayout lin_user;
51 61 private EditText user_id, user_name;
52 62 private Button exit_chat1;
53   - private Button chat_info_mationBtn;
54 63 public static String user_name_string;
55   - int i = 0;
56 64 private boolean isUserLogin = false;
  65 + private Button ima_send;
  66 + private Button voice_send;
  67 +
  68 +
  69 + public static final int IMG_FROM_PICTURE = 0x1001;
  70 + public static final int VOICE = 0x1002;
  71 + public static final int PICTURE_REQUEST_CODE = 0x1003;
  72 + public static final int VOICE_REQUEST_CODE = 0x1004;
  73 + private MediaRecorderUtil mediaRecorderUtil;
  74 + private long l;
  75 + int i;
57 76  
58 77 @Override
59 78 protected void onCreate(Bundle savedInstanceState) {
... ... @@ -63,12 +82,11 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL
63 82 initUI();
64 83 //设置监听
65 84 mHandler = new Handler();
  85 + mediaRecorderUtil = new MediaRecorderUtil();
66 86 ChatUtil.setOnConnectStatusListener(connectStatusListener);
67 87 ChatUtil.setOnChatRoomActionListener(chatRoomActionListener);
68 88 ChatUtil.setOnReceiveMessageListener(receiveMessageListener);
69   -
70 89 ChatUtil.setKickedOfflineListener(onKickedOfflineListener);
71   -
72 90 Intent intent = getIntent();
73 91 user_name_string = intent.getStringExtra("user_name_string");
74 92 String user_id_string = intent.getStringExtra("user_id_string");
... ... @@ -80,23 +98,28 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL
80 98  
81 99  
82 100 private void initUI() {
83   - chat_info_mationBtn = (Button) findViewById(R.id.chat_info_mation);
84   - chat_info_mationBtn.setOnClickListener(this);
  101 + voice_send = (Button) findViewById(R.id.voice_send);
  102 + ima_send = (Button) findViewById(R.id.ima_send);
85 103 exit_chat1 = (Button) findViewById(R.id.exit_chat1);
86 104 user_id = (EditText) findViewById(R.id.user_ID);
87 105 user_name = (EditText) findViewById(R.id.user_name);
88 106 lin_user = (LinearLayout) findViewById(R.id.lin_user);
89 107 re_chat = (RelativeLayout) findViewById(R.id.re_chat);
90 108 foundChatBtn = (Button) findViewById(R.id.creatChat);
91   - listViewOne = (ListView) findViewById(R.id.chat_list_viewOne);
  109 + listViewOne = (RecyclerView) findViewById(R.id.chat_list_viewOne);
92 110 editText = (EditText) findViewById(R.id.message_content);
93 111 send_messageOneBtn = (Button) findViewById(R.id.send_messageOne);
  112 + ima_send.setOnClickListener(this);
94 113 exit_chat1.setOnClickListener(this);
95 114 foundChatBtn.setOnClickListener(this);
96 115 send_messageOneBtn.setOnClickListener(this);
97 116 groupChatOneListMy = new ArrayList<>();
98   - chatListAdapterOne = new ChatListAdapter(ChatRoomActivity.this);
  117 + chatListAdapterOne = new ChatRoomAdpter(ChatRoomActivity.this);
  118 + chatListAdapterOne.setonVoiceItemClickListener(this);
  119 + listViewOne.setLayoutManager(new LinearLayoutManager(ChatRoomActivity.this));
99 120 listViewOne.setAdapter(chatListAdapterOne);
  121 + voice_send.setOnTouchListener(this);
  122 +
100 123 }
101 124  
102 125  
... ... @@ -111,23 +134,21 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL
111 134 }
112 135  
113 136 @Override
114   - public void onSuccess(Object o) throws JSONException {
115   - final CNMessage cnMessage = (CNMessage) o;
  137 + public void onSuccess(final Object o) throws JSONException {
116 138 mHandler.post(new Runnable() {
117 139 @Override
118 140 public void run() {
119   - try {
120   - if (((String) new JSONObject(cnMessage.getContent()).get("type")).equals("2"))
121   - return;
122   - } catch (JSONException e) {
123   - e.printStackTrace();
124   - }
125   - if ((roomIdOne).equals(cnMessage.getTargetId())) {
126   - groupChatOneListMy.add(new CNMessageInfo(cnMessage, true));
127   - chatListAdapterOne.updateItems(groupChatOneListMy);
128   - chatListAdapterOne.notifyDataSetChanged();
  141 + if (o instanceof CNMessage) {
  142 + CNMessage o1 = (CNMessage) o;
  143 + chatListAdapterOne.addItem(new StringMessage(MessageType.stringMessage, o1, true));
  144 + } else if (o instanceof CNImgMessage) {
  145 + CNImgMessage o1 = (CNImgMessage) o;
  146 + chatListAdapterOne.addItem(new ImagMessage(MessageType.imaMessage, o1, true));
  147 + } else if (o instanceof CNVoiceMessage) {
  148 + CNVoiceMessage o1 = (CNVoiceMessage) o;
  149 + VoiceMessage voiceMessage = new VoiceMessage(MessageType.voiceMessage, o1, true);
  150 + chatListAdapterOne.addItem(voiceMessage);
129 151 }
130   -
131 152 }
132 153 });
133 154 }
... ... @@ -151,62 +172,25 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL
151 172 private IChat.OnReceiveMessageListener receiveMessageListener = new IChat.OnReceiveMessageListener() {
152 173 @Override
153 174 public void processMessage(final Object o) {
154   - final CNMessage cnMessage = (CNMessage) o;
155   -
156 175 mHandler.post(new Runnable() {
157 176 @Override
158 177 public void run() {
159   - try {
160   - JSONObject jsonObject = new JSONObject(cnMessage.getContent().toString());
161   - String type = (String) jsonObject.get("type");
162   - if ("2".equals(type)) {
163   - Toast.makeText(ChatRoomActivity.this, cnMessage.getUserInfo().getUserName() + "加入聊天室", Toast.LENGTH_SHORT).show();
164   - return;
165   - }
166   - } catch (JSONException e) {
167   - e.printStackTrace();
168   - }
169   - {
170   - groupChatOneListMy.add(new CNMessageInfo(cnMessage, false));
171   - chatListAdapterOne.updateItems(groupChatOneListMy);
172   - chatListAdapterOne.notifyDataSetChanged();
  178 + if (o instanceof CNMessage) {
  179 + CNMessage o1 = (CNMessage) o;
  180 + chatListAdapterOne.addItem(new StringMessage(MessageType.stringMessage, o1, false));
  181 + } else if (o instanceof CNImgMessage) {
  182 + CNImgMessage o1 = (CNImgMessage) o;
  183 + chatListAdapterOne.addItem(new ImagMessage(MessageType.imaMessage, o1, false));
  184 + } else if (o instanceof CNVoiceMessage) {
  185 + CNVoiceMessage o1 = (CNVoiceMessage) o;
  186 + VoiceMessage voiceMessage = new VoiceMessage(MessageType.voiceMessage, o1, false);
  187 + chatListAdapterOne.addItem(voiceMessage);
173 188 }
174 189 }
175 190 });
176   - }
177   - };
178 191  
179   -
180   - //接收消息监听
181   - /*private IChat.OnReceiveMessageListener receiveMessageListener = new IChat.OnReceiveMessageListener() {
182   - @Override
183   - public void processMessage(final CNMessage cnMessage) {
184   - Log.v(TAG, "receiveMessageListener" + " " + cnMessage.getTargetId() + " " + cnMessage.getContent());
185   -
186   - mHandler.post(new Runnable() {
187   - @Override
188   - public void run() {
189   -
190   - try {
191   - JSONObject jsonObject = new JSONObject(cnMessage.getContent().toString());
192   - String type = (String) jsonObject.get("type");
193   - if ("2".equals(type)) {
194   - Toast.makeText(ChatRoomActivity.this, cnMessage.getUserInfo().getUserName() + "加入聊天室", Toast.LENGTH_SHORT).show();
195   - return;
196   - }
197   - } catch (JSONException e) {
198   - e.printStackTrace();
199   - }
200   - {
201   - groupChatOneListMy.add(new CNMessageInfo(cnMessage, false));
202   - chatListAdapterOne.updateItems(groupChatOneListMy);
203   - chatListAdapterOne.notifyDataSetChanged();
204   - }
205   - }
206   - });
207 192 }
208 193 };
209   -*/
210 194  
211 195  
212 196 //聊天室操作
... ... @@ -265,18 +249,7 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL
265 249 @Override
266 250 public void onSuccess(int what, final String extra) {
267 251 Log.v(TAG, +what + extra);
268   - mHandler.post(new Runnable() {
269   - @Override
270   - public void run() {
271   - if (i == 0) {
272   - String objToJsonString = ToStringUtils.objToJsonString(new CNMessageModole(user_name_string + "加入聊天室", "2"));
273   - ChatUtil.sendMessage(IChat.CHATROOM, roomIdOne, objToJsonString, sendMessageListener);
274   - ++i;
275   - }
276   - Toast.makeText(ChatRoomActivity.this, extra, Toast.LENGTH_SHORT).show();
277 252  
278   - }
279   - });
280 253  
281 254 }
282 255  
... ... @@ -296,8 +269,7 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL
296 269 if (editText.getText().toString().isEmpty()) {
297 270 Toast.makeText(this, "不能发送空消息呦~", Toast.LENGTH_SHORT).show();
298 271 } else {
299   - String objToJsonString = ToStringUtils.objToJsonString(new CNMessageModole(editText.getText().toString(), "1"));
300   - ChatUtil.sendMessage(IChat.CHATROOM, roomIdOne, objToJsonString, sendMessageListener);
  272 + ChatUtil.sendMessage(IChat.CHATROOM, roomIdOne, editText.getText().toString(), sendMessageListener);
301 273 editText.setText("");
302 274 }
303 275 break;
... ... @@ -307,25 +279,104 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL
307 279 case R.id.exit_chat1:
308 280 ChatUtil.quitChatRoom(roomIdOne, onOperationListener);
309 281 break;
310   - case R.id.chat_info_mation:
311   - ChatUtil.getChatRoomInfo(roomIdOne, 30, CNChatRoomInfo.ChatRoomMemberOrder.RC_CHAT_ROOM_MEMBER_ASC, new IChat.CNResultCallback<CNChatRoomInfo>() {
312   - @Override
313   - public void onSuccess(CNChatRoomInfo cnChatRoomInfo) {
314   - List<CNChatRoomMemberInfo> memberInfos = cnChatRoomInfo.getMemberInfo();
315   - for (CNChatRoomMemberInfo memberInfo : memberInfos) {
316   - String userId = memberInfo.getUserId();
317   - Log.v("userId", userId);
318   - }
319   - }
  282 + case R.id.ima_send:
  283 + fromPicture();
  284 + break;
  285 + }
  286 + }
320 287  
321   - @Override
322   - public void onError(int i, String s) {
323   - Log.v("userId", i + "" + s);
  288 + public void mediaRecorder() {
  289 + if (Build.VERSION.SDK_INT >= 23) {
  290 + int checkCallPhonePermission = ContextCompat.checkSelfPermission(ChatRoomActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
  291 + int checkCallPhonePermission1 = ContextCompat.checkSelfPermission(ChatRoomActivity.this, Manifest.permission.RECORD_AUDIO);
  292 +
  293 + if (checkCallPhonePermission != PackageManager.PERMISSION_GRANTED || checkCallPhonePermission1 != PackageManager.PERMISSION_GRANTED) {
  294 + requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.RECORD_AUDIO}, VOICE_REQUEST_CODE);
  295 + return;
  296 + } else {
  297 + recorder();
  298 + }
  299 + } else {
  300 + recorder();
  301 + }
  302 + }
324 303  
325   - }
326   - });
  304 +
  305 + public String getRecoderFile() {
  306 +
  307 + return mediaRecorderUtil.getRecorderFile();
  308 +
  309 + }
  310 +
  311 + public void recorder() {
  312 + mediaRecorderUtil.record();
  313 +
  314 + }
  315 +
  316 + public void releaseRecord() {
  317 + mediaRecorderUtil.releaseRecord();
  318 +
  319 + }
  320 +
  321 + public void fromPicture() {
  322 + if (Build.VERSION.SDK_INT >= 23) {
  323 + int checkCallPhonePermission = ContextCompat.checkSelfPermission(ChatRoomActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
  324 + if (checkCallPhonePermission != PackageManager.PERMISSION_GRANTED) {
  325 + requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, PICTURE_REQUEST_CODE);
  326 + return;
  327 + } else {
  328 + toIntentPicture();
  329 + }
  330 + } else {
  331 + toIntentPicture();
  332 + }
  333 + }
  334 +
  335 +
  336 + private void toIntentPicture() {
  337 + Intent intent = new Intent();
  338 + intent.setType("image/*");
  339 + intent.setAction(Intent.ACTION_GET_CONTENT);
  340 + startActivityForResult(intent, IMG_FROM_PICTURE);
  341 + }
  342 +
  343 +
  344 + @Override
  345 + public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
  346 + super.onRequestPermissionsResult(requestCode, permissions, grantResults);
  347 + switch (requestCode) {
  348 + case PICTURE_REQUEST_CODE:
  349 + if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
  350 + toIntentPicture();
  351 + } else {
  352 + Toast.makeText(ChatRoomActivity.this, "权限已被禁止,请打开,再使用此功能", Toast.LENGTH_LONG).show();
  353 + }
  354 + break;
  355 +
  356 + case VOICE_REQUEST_CODE:
  357 + if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
  358 + recorder();
  359 + } else {
  360 + Toast.makeText(ChatRoomActivity.this, "权限已被禁止,请打开,再使用此功能", Toast.LENGTH_LONG).show();
  361 + }
327 362 break;
  363 + }
  364 + }
328 365  
  366 +
  367 + @Override
  368 + public void onActivityResult(int requestCode, int resultCode, Intent data) {
  369 + super.onActivityResult(requestCode, resultCode, data);
  370 + if (resultCode == Activity.RESULT_OK) {
  371 + switch (requestCode) {
  372 + case IMG_FROM_PICTURE:
  373 + Uri uri = data.getData();
  374 + ChatUtil.sendImaMessage(IChat.CHATROOM, roomIdOne, uri, uri, sendMessageListener);
  375 + break;
  376 +
  377 + default:
  378 + break;
  379 + }
329 380 }
330 381 }
331 382  
... ... @@ -354,31 +405,54 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL
354 405 };
355 406  
356 407  
357   - public static class CNMessageInfo {
358   - CNMessage cnMessage;
359   - boolean sendMesageInfo;
  408 + @Override
  409 + public boolean onTouch(View v, MotionEvent event) {
360 410  
361   - public CNMessage getCnMessage() {
362   - return cnMessage;
363   - }
  411 + switch (event.getAction()) {
  412 + case MotionEvent.ACTION_DOWN:
  413 + l = System.currentTimeMillis();
  414 + mediaRecorder();
  415 + break;
  416 + case MotionEvent.ACTION_UP:
364 417  
365   - public void setCnMessage(CNMessage cnMessage) {
366   - this.cnMessage = cnMessage;
367   - }
  418 + if (Build.VERSION.SDK_INT >= 23) {
  419 + int checkCallPhonePermission = ContextCompat.checkSelfPermission(ChatRoomActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
  420 + int checkCallPhonePermission1 = ContextCompat.checkSelfPermission(ChatRoomActivity.this, Manifest.permission.RECORD_AUDIO);
368 421  
369   - public boolean isSendMesageInfo() {
370   - return sendMesageInfo;
371   - }
  422 + if (checkCallPhonePermission != PackageManager.PERMISSION_GRANTED || checkCallPhonePermission1 != PackageManager.PERMISSION_GRANTED) {
  423 + requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.RECORD_AUDIO}, VOICE_REQUEST_CODE);
  424 + } else {
  425 + sendVoice();
  426 + }
  427 + } else {
  428 + sendVoice();
  429 + }
  430 +
  431 +
  432 + break;
372 433  
373   - public void setSendMesageInfo(boolean sendMesageInfo) {
374   - this.sendMesageInfo = sendMesageInfo;
375   - }
376 434  
377   - public CNMessageInfo(CNMessage cnMessage, boolean sendMesageInfo) {
378   - this.cnMessage = cnMessage;
379   - this.sendMesageInfo = sendMesageInfo;
380 435 }
  436 +
  437 + return true;
  438 + }
  439 +
  440 + private void sendVoice() {
  441 + long l1 = System.currentTimeMillis();
  442 + long l2 = (l1 - l) / 1000;
  443 + i = (int) l2;
  444 + releaseRecord();
  445 + String recoderFile = getRecoderFile();
  446 + ChatUtil.sendVoiceMessage(IChat.CHATROOM, roomIdOne, Uri.parse(recoderFile), i, sendMessageListener);
381 447 }
382 448  
  449 + @Override
  450 + public void onItemClick(Uri uri) {
  451 + plaVoice(uri);
383 452  
  453 + }
  454 +
  455 + public void plaVoice(Uri uri) {
  456 + mediaRecorderUtil.plaVoice(uri, this);
  457 + }
384 458 }
... ...
app/src/main/java/com/cnlive/im/ui/LoGinActivity.java
... ... @@ -42,16 +42,15 @@ public class LoGinActivity extends AppCompatActivity implements View.OnClickList
42 42 case R.id.vis_login:
43 43 Intent intent = new Intent(LoGinActivity.this, ChatRoomActivity.class);
44 44 startActivity(intent);
45   -
46 45 break;
47 46 case R.id.user_logOut:
48 47 ChatUtil.disconnect(false);
49 48 LoGinActivity.this.finish();
50 49 break;
51 50 case R.id.user_login:
52   - Intent intent2 = new Intent(LoGinActivity.this, UserLoginActivity.class);
53   - startActivity(intent2);
  51 + startActivity(new Intent(LoGinActivity.this, UserLoginActivity.class));
54 52 break;
  53 +
55 54 }
56 55 }
57 56  
... ...
app/src/main/java/com/cnlive/im/ui/PrivateChatActivity.java
1 1 package com.cnlive.im.ui;
2 2  
3   -import android.content.Intent;
4   -import android.os.Bundle;
5   -import android.os.Handler;
6   -import android.support.v7.app.AppCompatActivity;
7   -import android.util.Log;
8   -import android.view.View;
9   -import android.widget.Button;
10   -import android.widget.EditText;
11   -import android.widget.LinearLayout;
12   -import android.widget.ListView;
13   -import android.widget.Toast;
14   -
15   -import com.cnlive.im.R;
16   -import com.cnlive.im.adapter.ChatListAdapter;
17   -import com.cnlive.im.mode.CNMessageModole;
18   -import com.cnlive.im.util.ToStringUtils;
19   -import com.cnlive.libs.util.chat.ChatUtil;
20   -import com.cnlive.libs.util.chat.base.IChat;
21   -import com.cnlive.libs.util.chat.model.CNMessage;
22   -import com.cnlive.libs.util.chat.model.CNUserInfo;
23   -
24   -import org.json.JSONException;
25   -import org.json.JSONObject;
26   -
27   -import java.util.ArrayList;
28   -
29   -import static com.cnlive.im.R.id.opposite_id_edit;
30   -
31   -
32 3 /**
33 4 * @author 陈硕
34 5 * @time 2017/3/7 14:36
35 6 * @desc ${TODD}
36 7 */
37   -public class PrivateChatActivity extends AppCompatActivity implements View.OnClickListener {
38   -
  8 +public class PrivateChatActivity {
  9 +/*
39 10  
40 11 private static final String TAG = "PrivateChatActivity";
41   - private ListView chatListView;
  12 + private RecyclerView chatListView;
42 13 private EditText messageContent;
43 14 private Button sendMessageBtn;
44 15 private ChatListAdapter chatListAdapter;
45   - private ArrayList<ChatRoomActivity.CNMessageInfo> messageList = new ArrayList<>();
  16 + private ArrayList<Object> messageList = new ArrayList<>();
46 17 private CNMessage cnMessage;
47 18 private LinearLayout linearLayoutUseID;
48 19 private EditText user_id_edit;
... ... @@ -59,6 +30,8 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli
59 30 private LinearLayout agree_reject_lin;
60 31 boolean isCanSendMeaasge = false;
61 32 private Button vistor_btn;
  33 + private ChatRoomAdpter chatRoomAdpter;
  34 +
62 35  
63 36 @Override
64 37 protected void onCreate(Bundle savedInstanceState) {
... ... @@ -72,7 +45,7 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli
72 45  
73 46 private void initView() {
74 47 opposite_name_edit = (EditText) findViewById(R.id.opposite_name_edit);
75   - chatListView = (ListView) findViewById(R.id.private_list_view);
  48 + chatListView = (RecyclerView) findViewById(R.id.private_list_view);
76 49  
77 50 messageContent = (EditText) findViewById(R.id.message_content);
78 51 sendMessageBtn = (Button) findViewById(R.id.send_message);
... ... @@ -92,8 +65,9 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli
92 65 agree_reject_lin = (LinearLayout) findViewById(R.id.agree_reject_lin);
93 66 vistor_btn = (Button) findViewById(R.id.vistor_Btn);
94 67 vistor_btn.setOnClickListener(this);
95   - chatListAdapter = new ChatListAdapter(this);
96   - chatListView.setAdapter(chatListAdapter);
  68 + chatRoomAdpter = new ChatRoomAdpter(this);
  69 + chatListView.setLayoutManager(new LinearLayoutManager(this));
  70 + chatListView.setAdapter(chatRoomAdpter);
97 71 }
98 72  
99 73  
... ... @@ -111,10 +85,9 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli
111 85  
112 86 } else if (sendInfo == 3) {
113 87 Toast.makeText(this, "还没有邀请对方呦~", Toast.LENGTH_SHORT).show();
114   - }
115   - else if (sendInfo == 5) {
  88 + } else if (sendInfo == 5) {
116 89 Toast.makeText(this, "你已经拒绝对方不能发送消息", Toast.LENGTH_SHORT).show();
117   - }else {
  90 + } else {
118 91 if (messageContent.getText().toString().isEmpty()) {
119 92 Toast.makeText(this, "不能发送空消息呦~", Toast.LENGTH_SHORT).show();
120 93 } else {
... ... @@ -139,7 +112,7 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli
139 112 edit_layout.setVisibility(View.VISIBLE);
140 113 chatListView.setVisibility(View.VISIBLE);
141 114 CNUserInfo cnName = new CNUserInfo(user_id_string, user_name_string, "");
142   - ChatUtil.login(cnName,connectListener);
  115 + ChatUtil.login(cnName, connectListener);
143 116  
144 117 }
145 118  
... ... @@ -192,19 +165,19 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli
192 165 };
193 166  
194 167  
195   - /**
  168 + *//**
196 169 * 发送消息监听
197   - */
  170 + *//*
198 171  
199   - private IChat.OnSendMessageListener sendMessageListener = new IChat.OnSendMessageListener() {
  172 + private IChat.OnSendMessageListener sendMessageListener = new IChat.OnSendMessageListener() {
200 173 @Override
201 174 public void onAttached(Object o) {
202 175  
203 176 }
204 177  
205 178 @Override
206   - public void onSuccess(Object o) throws JSONException {
207   - final CNMessage cnMessage = (CNMessage) o;
  179 + public void onSuccess(final Object o) throws JSONException {
  180 +
208 181  
209 182 if (View.VISIBLE == vistor_btn.getVisibility()) {
210 183 vistor_btn.setVisibility(View.GONE);
... ... @@ -213,28 +186,31 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli
213 186 @Override
214 187 public void run() {
215 188 JSONObject jsonObject = null;
216   - try {
217   - jsonObject = new JSONObject(cnMessage.getContent().toString());
218   - String type = (String) jsonObject.get("type");
219   - String message = (String) jsonObject.get("message");
220   - Toast.makeText(PrivateChatActivity.this, "发送消息成功", Toast.LENGTH_SHORT).show();
221   - if ("3".equals(type) && message.equals("你好我们可以进行私聊吗")) {
222   - sendInfo = 2;
223   - Toast.makeText(PrivateChatActivity.this, "申请已发送等待对方验证", Toast.LENGTH_SHORT).show();
224   - } else if ("3".equals(type) && message.equals("拒绝")) {
225   - sendInfo=5;
226   - } else if ("3".equals(type) && message.equals("同意")) {
227   - sendInfo=1;
228   - } else if ("4".equals(type)) {
229   - messageList.add(new ChatRoomActivity.CNMessageInfo(cnMessage, true));
230   - chatListAdapter.updateItems(messageList);
231   - chatListAdapter.notifyDataSetChanged();
232   - }
233   - } catch (JSONException e) {
  189 + if (o instanceof CNMessage) {
  190 + final CNMessage cnMessage = (CNMessage) o;
  191 + try {
  192 + jsonObject = new JSONObject(cnMessage.getContent().toString());
  193 + String type = (String) jsonObject.get("type");
  194 + String message = (String) jsonObject.get("message");
  195 + Toast.makeText(PrivateChatActivity.this, "发送消息成功", Toast.LENGTH_SHORT).show();
  196 + if ("3".equals(type) && message.equals("你好我们可以进行私聊吗")) {
  197 + sendInfo = 2;
  198 + Toast.makeText(PrivateChatActivity.this, "申请已发送等待对方验证", Toast.LENGTH_SHORT).show();
  199 + } else if ("3".equals(type) && message.equals("拒绝")) {
  200 + sendInfo = 5;
  201 + } else if ("3".equals(type) && message.equals("同意")) {
  202 + sendInfo = 1;
  203 + } else if ("4".equals(type)) {
  204 + messageList.add(new StringMessage(MessageType.stringMessage, cnMessage, true));
  205 + }
  206 + } catch (JSONException e) {
  207 +
234 208  
  209 + }
235 210  
236 211 }
237 212  
  213 +
238 214 }
239 215 });
240 216 }
... ... @@ -246,7 +222,6 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli
246 222 };
247 223  
248 224  
249   -
250 225 //连接状态监听
251 226 private IChat.OnConnectStatusListener connectStatusListener = new IChat.OnConnectStatusListener() {
252 227 @Override
... ... @@ -257,7 +232,7 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli
257 232 }
258 233 };
259 234 //接收消息监听
260   - private IChat.OnReceiveMessageListener receiveMessageListener = new IChat.OnReceiveMessageListener() {
  235 + private IChat.OnReceiveMessageListener receiveMessageListener = new IChat.OnReceiveMessageListener() {
261 236 @Override
262 237 public void processMessage(Object o) {
263 238 final CNMessage cnMessage = (CNMessage) o;
... ... @@ -278,48 +253,8 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli
278 253 sendInfo = 4;
279 254 } else if ("4".equals(type)) {
280 255 Log.v(TAG, cnMessage.getContent().toString());
281   - messageList.add(new ChatRoomActivity.CNMessageInfo(cnMessage, false));
282   - chatListAdapter.updateItems(messageList);
283   - chatListAdapter.notifyDataSetChanged();
284   - }
  256 + messageList.add(new StringMessage(MessageType.stringMessage, cnMessage, false));
285 257  
286   - } catch (JSONException e) {
287   - e.printStackTrace();
288   - }
289   -
290   -
291   - }
292   - });
293   -
294   - }
295   - };
296   -
297   -
298   - /* private IChat.OnReceiveMessageListener receiveMessageListener = new IChat.OnReceiveMessageListener() {
299   - @Override
300   - public void processMessage(final CNMessage cnMessage) {
301   -
302   -
303   - mHandler.post(new Runnable() {
304   - @Override
305   - public void run() {
306   - Log.v("cnMessage", cnMessage.getTargetId() + "," + cnMessage.getUserInfo().getUserId());
307   - JSONObject jsonObject = null;
308   - try {
309   - jsonObject = new JSONObject(cnMessage.getContent().toString());
310   - String type = (String) jsonObject.get("type");
311   - if ("3".equals(type) && "你好我们可以进行私聊吗".equals(jsonObject.get("message"))) {
312   - vistor_btn.setVisibility(View.GONE);
313   - agree_reject_lin.setVisibility(View.VISIBLE);
314   - } else if ("3".equals(type) && "同意".equals(jsonObject.get("message"))) {
315   - sendInfo = 1;
316   - } else if ("3".equals(type) && "拒绝".equals(jsonObject.get("message"))) {
317   - sendInfo = 4;
318   - } else if ("4".equals(type)) {
319   - Log.v(TAG, cnMessage.getContent().toString());
320   - messageList.add(new ChatRoomActivity.CNMessageInfo(cnMessage, false));
321   - chatListAdapter.updateItems(messageList);
322   - chatListAdapter.notifyDataSetChanged();
323 258 }
324 259  
325 260 } catch (JSONException e) {
... ...
app/src/main/java/com/cnlive/im/ui/UserLoginActivity.java
... ... @@ -50,7 +50,7 @@ public class UserLoginActivity extends AppCompatActivity implements View.OnClick
50 50 doIntentChatRoom(ChatRoomActivity.class);
51 51 break;
52 52 case R.id.private_chat:
53   - doIntentChatRoom(PrivateChatActivity.class);
  53 + // doIntentChatRoom(PrivateChatActivity.class);
54 54  
55 55 break;
56 56 }
... ...
app/src/main/java/com/cnlive/im/util/MediaRecorderUtil.java 0 → 100644
  1 +package com.cnlive.im.util;
  2 +
  3 +import android.content.Context;
  4 +import android.media.MediaPlayer;
  5 +import android.media.MediaRecorder;
  6 +import android.net.Uri;
  7 +import android.os.Environment;
  8 +
  9 +import java.io.File;
  10 +import java.io.IOException;
  11 +
  12 +/**
  13 + * @author 陈硕
  14 + * @time 2017/7/12 11:54
  15 + * @desc ${TODD}
  16 + */
  17 +public class MediaRecorderUtil {
  18 +
  19 + private String filePath;
  20 + private String saveFile;
  21 + private MediaRecorder mediaRecorder;
  22 +
  23 +
  24 + private void createRecorderFile() {
  25 + String absolutePath = Environment.getExternalStorageDirectory().getAbsolutePath();
  26 + filePath = absolutePath + "/recorder";
  27 + File file = new File(filePath);
  28 + if (!file.exists()) {
  29 + file.mkdir();
  30 + }
  31 + }
  32 +
  33 + public String getRecorderFile() {
  34 + return saveFile;
  35 + }
  36 +
  37 +
  38 + public void releaseRecord() {
  39 + if (mediaRecorder != null) {
  40 + mediaRecorder.release();//释放资源
  41 + mediaRecorder = null;
  42 + }
  43 +
  44 + }
  45 +
  46 +
  47 + public void record() {
  48 +
  49 + mediaRecorder = new MediaRecorder();
  50 + mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
  51 +
  52 + mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
  53 +
  54 + mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
  55 +
  56 + createRecorderFile();//创建保存录音的文件夹
  57 + saveFile = "sdcard/recorder" + "/" + "cnLive" + ".AAC";
  58 + mediaRecorder.setOutputFile(saveFile);
  59 +
  60 +
  61 + try {
  62 + mediaRecorder.prepare();
  63 + mediaRecorder.start();
  64 + } catch (IllegalStateException e) {
  65 + e.printStackTrace();
  66 + } catch (IOException e) {
  67 + e.printStackTrace();
  68 + }
  69 +
  70 + }
  71 +
  72 +
  73 + public void plaVoice(Uri uri, Context context) {
  74 + MediaPlayer mediaPlayer = new MediaPlayer();
  75 +
  76 + try {
  77 + mediaPlayer.setDataSource(context, uri);
  78 + mediaPlayer.prepare();
  79 + } catch (IOException e) {
  80 + e.printStackTrace();
  81 + }
  82 + mediaPlayer.start();
  83 +
  84 + }
  85 +
  86 +
  87 +}
0 88 \ No newline at end of file
... ...
app/src/main/java/com/cnlive/im/util/MessageType.java 0 → 100644
  1 +package com.cnlive.im.util;
  2 +
  3 +/**
  4 + * @author 陈硕
  5 + * @time 2017/7/14 11:40
  6 + * @desc ${TODD}
  7 + */
  8 +public class MessageType {
  9 + public static final String stringMessage = "1";
  10 + public static final String imaMessage = "2";
  11 + public static final String voiceMessage = "3";
  12 +}
... ...
app/src/main/res/drawable-hdpi/voice_msg_left.png 0 → 100644

1.2 KB

app/src/main/res/drawable-hdpi/voice_msg_right.9.png 0 → 100644

1.19 KB

app/src/main/res/layout/activity_groupchat.xml
... ... @@ -8,6 +8,9 @@
8 8 android:id="@+id/re_chat"
9 9 android:layout_width="match_parent"
10 10 android:layout_height="match_parent"
  11 + android:layout_alignParentLeft="true"
  12 + android:layout_alignParentStart="true"
  13 + android:layout_alignParentTop="true"
11 14 android:visibility="visible">
12 15  
13 16 <LinearLayout
... ... @@ -24,16 +27,14 @@
24 27 android:layout_height="match_parent"
25 28 android:orientation="vertical">
26 29  
27   -
28   - <ListView
  30 + <android.support.v7.widget.RecyclerView
29 31 android:id="@+id/chat_list_viewOne"
30   - android:layout_width="match_parent"
31   - android:layout_height="150dp"
  32 + android:layout_width="fill_parent"
  33 + android:layout_height="170dp"
32 34 android:layout_above="@+id/edit_layout"
33   - android:layout_alignParentTop="true"
34 35 android:divider="@null"
35   - android:scrollbars="none"
36   - android:transcriptMode="alwaysScroll"/>
  36 + android:fastScrollEnabled="true"
  37 + android:scrollbars="none" />
37 38 </LinearLayout>
38 39 </LinearLayout>
39 40  
... ... @@ -51,6 +52,7 @@
51 52 android:layout_gravity="center"
52 53 android:layout_weight="0.7" />
53 54  
  55 +
54 56 <Button
55 57 android:id="@+id/send_messageOne"
56 58 android:layout_width="0dp"
... ... @@ -59,7 +61,7 @@
59 61 android:layout_weight="0.2"
60 62 android:text="发送" />
61 63  
62   - </LinearLayout>
  64 + </LinearLayout>
63 65  
64 66 <LinearLayout
65 67 android:layout_width="match_parent"
... ... @@ -79,32 +81,27 @@
79 81 android:text="加入聊天室" />
80 82  
81 83 <Button
82   - android:id="@+id/chat_info_mation"
  84 + android:id="@+id/ima_send"
83 85 android:layout_width="wrap_content"
84 86 android:layout_height="wrap_content"
85   - android:layout_weight="1"
86   - android:text="获取聊天室信息" />
  87 + android:text="图片" />
  88 +
87 89 <Button
88   - android:id="@+id/exit_chat1"
  90 + android:id="@+id/voice_send"
89 91 android:layout_width="wrap_content"
90 92 android:layout_height="wrap_content"
91   - android:text="退出聊天室" />
92   -
93   - </LinearLayout>
94   -
95   -
96   -
97   -
98   -
  93 + android:text="语音" />
99 94  
100 95  
  96 + <Button
  97 + android:id="@+id/exit_chat1"
  98 + android:layout_width="wrap_content"
  99 + android:layout_height="wrap_content"
  100 + android:text="退出" />
101 101  
  102 + </LinearLayout>
102 103  
103 104 </LinearLayout>
104 105 </RelativeLayout>
105 106  
106   -
107   -
108   -
109   -
110 107 </RelativeLayout>
... ...
app/src/main/res/layout/activity_image.xml 0 → 100644
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + android:layout_width="match_parent"
  4 + android:layout_height="match_parent"
  5 + android:orientation="vertical">
  6 +
  7 + <Button
  8 + android:id="@+id/image_send_btn"
  9 + android:layout_width="match_parent"
  10 + android:layout_height="wrap_content"
  11 + android:text="发送图片" />
  12 +
  13 + <Button
  14 + android:id="@+id/voice_btn"
  15 + android:layout_width="wrap_content"
  16 + android:layout_height="wrap_content"
  17 + android:text="音频" />
  18 +
  19 +
  20 +</LinearLayout>
0 21 \ No newline at end of file
... ...
app/src/main/res/layout/activity_login.xml
... ... @@ -33,4 +33,6 @@
33 33 android:text="退出" />
34 34  
35 35 </LinearLayout>
  36 +
  37 +
36 38 </RelativeLayout>
37 39 \ No newline at end of file
... ...
app/src/main/res/layout/activity_private_chat.xml
... ... @@ -10,7 +10,7 @@
10 10 android:orientation="vertical">
11 11  
12 12  
13   - <ListView
  13 + <android.support.v7.widget.RecyclerView
14 14 android:id="@+id/private_list_view"
15 15 android:layout_width="match_parent"
16 16 android:layout_height="300dp"
... ...
app/src/main/res/layout/imag_layout_item_oppsite.xml 0 → 100644
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + android:layout_width="match_parent"
  4 + android:layout_height="match_parent"
  5 + android:orientation="vertical">
  6 +
  7 +
  8 + <RelativeLayout
  9 + android:layout_width="wrap_content"
  10 + android:layout_height="wrap_content">
  11 +
  12 + <TextView
  13 + android:id="@+id/img_user_name"
  14 + android:layout_width="wrap_content"
  15 + android:layout_height="wrap_content"
  16 + android:layout_alignParentLeft="true"
  17 + android:layout_centerVertical="true"
  18 + android:text="游客" />
  19 +
  20 + <ImageView
  21 + android:id="@+id/img_content"
  22 + android:layout_width="wrap_content"
  23 + android:layout_height="wrap_content"
  24 + android:layout_marginLeft="5dp"
  25 + android:layout_toRightOf="@+id/img_user_name"
  26 + android:src="@drawable/vod_detail_good_on" />
  27 +
  28 + </RelativeLayout>
  29 +
  30 +</LinearLayout>
0 31 \ No newline at end of file
... ...
app/src/main/res/layout/imag_layout_item_user.xml 0 → 100644
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + android:layout_width="match_parent"
  4 + android:layout_height="match_parent"
  5 + android:orientation="vertical">
  6 +
  7 + <RelativeLayout
  8 + android:layout_width="wrap_content"
  9 + android:layout_height="wrap_content">
  10 +
  11 + <TextView
  12 + android:layout_centerVertical="true"
  13 + android:id="@+id/img_user_name"
  14 + android:layout_width="wrap_content"
  15 + android:layout_height="wrap_content"
  16 + android:layout_alignParentRight="true"
  17 + android:text="游客" />
  18 +
  19 + <ImageView
  20 + android:layout_toLeftOf="@+id/img_user_name"
  21 + android:layout_marginRight="5dp"
  22 + android:id="@+id/img_content"
  23 + android:layout_width="wrap_content"
  24 + android:layout_height="wrap_content"
  25 + android:src="@drawable/vod_detail_good_on"/>
  26 +
  27 + </RelativeLayout>
  28 +
  29 +</LinearLayout>
0 30 \ No newline at end of file
... ...
app/src/main/res/layout/msg_text_view.xml
... ... @@ -15,6 +15,7 @@
15 15 android:layout_height="wrap_content"
16 16 android:gravity="center_vertical"
17 17 android:textColor="#d61d0c"
  18 + android:text="ddd"
18 19 android:textSize="14sp" />
19 20  
20 21 <TextView
... ... @@ -23,6 +24,7 @@
23 24 android:layout_height="wrap_content"
24 25 android:layout_toRightOf="@id/user_name"
25 26 android:textColor="@android:color/black"
  27 + android:text="vfgfgf"
26 28 android:textSize="15sp" />
27 29 </RelativeLayout>
28 30  
... ...
app/src/main/res/layout/string_layout_item_oppsite.xml 0 → 100644
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + android:layout_width="wrap_content"
  4 + android:layout_height="wrap_content"
  5 + android:orientation="vertical">
  6 +
  7 + <RelativeLayout
  8 + android:id="@+id/re_chat_room"
  9 + android:layout_width="wrap_content"
  10 + android:layout_height="wrap_content">
  11 +
  12 + <TextView
  13 + android:id="@+id/user_name"
  14 + android:layout_width="wrap_content"
  15 + android:layout_height="wrap_content"
  16 + android:gravity="center_vertical"
  17 + android:text="ddd"
  18 + android:textColor="#d61d0c"
  19 + android:textSize="14sp" />
  20 +
  21 + <TextView
  22 + android:id="@+id/msg_text"
  23 + android:layout_width="wrap_content"
  24 + android:layout_height="wrap_content"
  25 + android:layout_toRightOf="@id/user_name"
  26 + android:text="vfgfgf"
  27 + android:textColor="@android:color/black"
  28 + android:textSize="15sp" />
  29 + </RelativeLayout>
  30 +
  31 +</RelativeLayout>
0 32 \ No newline at end of file
... ...
app/src/main/res/layout/string_layout_item_user.xml 0 → 100644
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + android:layout_width="wrap_content"
  4 + android:layout_height="wrap_content">
  5 +
  6 + <RelativeLayout
  7 + android:id="@+id/re_chat_room"
  8 + android:layout_width="wrap_content"
  9 + android:layout_height="wrap_content">
  10 +
  11 + <TextView
  12 + android:id="@+id/user_name"
  13 + android:layout_width="wrap_content"
  14 + android:layout_height="wrap_content"
  15 + android:layout_alignParentRight="true"
  16 + android:gravity="center_vertical"
  17 + android:text="ddd"
  18 + android:textColor="#d61d0c"
  19 + android:textSize="14sp" />
  20 +
  21 + <TextView
  22 + android:id="@+id/msg_text"
  23 + android:layout_width="wrap_content"
  24 + android:layout_height="wrap_content"
  25 + android:layout_toLeftOf="@id/user_name"
  26 + android:text="vfgfgf"
  27 + android:textColor="@android:color/black"
  28 + android:textSize="15sp" />
  29 + </RelativeLayout>
  30 +
  31 +
  32 +</RelativeLayout>
0 33 \ No newline at end of file
... ...
app/src/main/res/layout/voice_layout_item_oppsite.xml 0 → 100644
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + android:layout_width="wrap_content"
  4 + android:layout_height="wrap_content">
  5 +
  6 +
  7 + <RelativeLayout
  8 + android:layout_width="wrap_content"
  9 + android:layout_height="wrap_content">
  10 +
  11 + <TextView
  12 + android:id="@+id/voice_user_name"
  13 + android:layout_width="wrap_content"
  14 + android:layout_height="wrap_content"
  15 + android:layout_alignParentLeft="true"
  16 + android:layout_centerVertical="true"
  17 + android:text="游客" />
  18 +
  19 + <ImageView
  20 + android:id="@+id/voice_content"
  21 + android:layout_width="wrap_content"
  22 + android:layout_height="wrap_content"
  23 + android:layout_toRightOf="@+id/voice_user_name"
  24 + android:src="@drawable/voice_msg_left" />
  25 +
  26 +
  27 + </RelativeLayout>
  28 +
  29 +</RelativeLayout>
0 30 \ No newline at end of file
... ...
app/src/main/res/layout/voice_layout_item_user.xml 0 → 100644
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + android:layout_width="wrap_content"
  4 + android:layout_height="wrap_content">
  5 +
  6 + <RelativeLayout
  7 + android:layout_width="wrap_content"
  8 + android:layout_height="wrap_content">
  9 +
  10 + <TextView
  11 + android:id="@+id/voice_user_name"
  12 + android:layout_width="wrap_content"
  13 + android:layout_height="wrap_content"
  14 + android:layout_alignParentRight="true"
  15 + android:layout_centerVertical="true"
  16 + android:text="游客" />
  17 +
  18 + <ImageView
  19 + android:id="@+id/voice_content"
  20 + android:layout_width="wrap_content"
  21 + android:layout_height="wrap_content"
  22 + android:layout_toLeftOf="@+id/voice_user_name"
  23 + android:src="@drawable/voice_msg_right" />
  24 +
  25 + </RelativeLayout>
  26 +
  27 +</RelativeLayout>
0 28 \ No newline at end of file
... ...