add the voice send

addvoice
李富 9 years ago
parent 8ce3abe8b9
commit 6ec464ead7

@ -1,5 +1,6 @@
package cn.bmob.imdemo.ui;
import android.app.Activity;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
@ -63,643 +64,12 @@ import cn.bmob.v3.exception.BmobException;
* @project:ChatActivity
* @date :2016-01-25-18:23
*/
public class ChatActivity extends ParentWithNaviActivity implements ObseverListener,MessageListHandler{
public class ChatActivity extends Activity {
@Bind(R.id.ll_chat)
LinearLayout ll_chat;
@Bind(R.id.sw_refresh)
SwipeRefreshLayout sw_refresh;
@Bind(R.id.rc_view)
RecyclerView rc_view;
@Bind(R.id.edit_msg)
EditText edit_msg;
@Bind(R.id.btn_chat_add)
Button btn_chat_add;
@Bind(R.id.btn_chat_emo)
Button btn_chat_emo;
@Bind(R.id.btn_speak)
Button btn_speak;
@Bind(R.id.btn_chat_voice)
Button btn_chat_voice;
@Bind(R.id.btn_chat_keyboard)
Button btn_chat_keyboard;
@Bind(R.id.btn_chat_send)
Button btn_chat_send;
@Bind(R.id.layout_more)
LinearLayout layout_more;
@Bind(R.id.layout_add)
LinearLayout layout_add;
@Bind(R.id.layout_emo)
LinearLayout layout_emo;
// 语音有关
@Bind(R.id.layout_record)
RelativeLayout layout_record;
@Bind(R.id.tv_voice_tips)
TextView tv_voice_tips;
@Bind(R.id.iv_record)
ImageView iv_record;
private Drawable[] drawable_Anims;// 话筒动画
BmobRecordManager recordManager;
ChatAdapter adapter;
protected LinearLayoutManager layoutManager;
BmobIMConversation c;
@Override
protected String title() {
return c.getConversationTitle();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chat);
c= BmobIMConversation.obtain(BmobIMClient.getInstance(), (BmobIMConversation) getBundle().getSerializable("c"));
initNaviView();
initSwipeLayout();
initVoiceView();
initBottomView();
}
private void initSwipeLayout(){
sw_refresh.setEnabled(true);
layoutManager = new LinearLayoutManager(this);
rc_view.setLayoutManager(layoutManager);
adapter = new ChatAdapter(this,c);
rc_view.setAdapter(adapter);
ll_chat.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
ll_chat.getViewTreeObserver().removeGlobalOnLayoutListener(this);
sw_refresh.setRefreshing(true);
//自动刷新
queryMessages(null);
}
});
//下拉加载
sw_refresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
BmobIMMessage msg = adapter.getFirstMessage();
queryMessages(msg);
}
});
//设置RecyclerView的点击事件
adapter.setOnRecyclerViewListener(new OnRecyclerViewListener() {
@Override
public void onItemClick(int position) {
Logger.i(""+position);
}
@Override
public boolean onItemLongClick(int position) {
//这里省了个懒,直接长按就删除了该消息
c.deleteMessage(adapter.getItem(position));
adapter.remove(position);
return true;
}
});
}
private void initBottomView(){
edit_msg.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_DOWN||event.getAction()==MotionEvent.ACTION_UP){
scrollToBottom();
}
return false;
}
});
edit_msg.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
scrollToBottom();
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (!TextUtils.isEmpty(s)) {
btn_chat_send.setVisibility(View.VISIBLE);
btn_chat_keyboard.setVisibility(View.GONE);
btn_chat_voice.setVisibility(View.GONE);
} else {
if (btn_chat_voice.getVisibility() != View.VISIBLE) {
btn_chat_voice.setVisibility(View.VISIBLE);
btn_chat_send.setVisibility(View.GONE);
btn_chat_keyboard.setVisibility(View.GONE);
}
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
}
/**
*
* @param
* @return void
*/
private void initVoiceView() {
btn_speak.setOnTouchListener(new VoiceTouchListener());
initVoiceAnimRes();
initRecordManager();
}
/**
*
* @Title: initVoiceAnimRes
* @param
* @return void
*/
private void initVoiceAnimRes() {
drawable_Anims = new Drawable[] {
getResources().getDrawable(R.mipmap.chat_icon_voice2),
getResources().getDrawable(R.mipmap.chat_icon_voice3),
getResources().getDrawable(R.mipmap.chat_icon_voice4),
getResources().getDrawable(R.mipmap.chat_icon_voice5),
getResources().getDrawable(R.mipmap.chat_icon_voice6) };
}
private void initRecordManager(){
// 语音相关管理器
recordManager = BmobRecordManager.getInstance(this);
// 设置音量大小监听--在这里开发者可以自己实现当剩余10秒情况下的给用户的提示类似微信的语音那样
recordManager.setOnRecordChangeListener(new OnRecordChangeListener() {
@Override
public void onVolumnChanged(int value) {
iv_record.setImageDrawable(drawable_Anims[value]);
}
@Override
public void onTimeChanged(int recordTime, String localPath) {
Logger.i("voice", "已录音长度:" + recordTime);
if (recordTime >= BmobRecordManager.MAX_RECORD_TIME) {// 1分钟结束发送消息
// 需要重置按钮
btn_speak.setPressed(false);
btn_speak.setClickable(false);
// 取消录音框
layout_record.setVisibility(View.INVISIBLE);
// 发送语音消息
sendVoiceMessage(localPath, recordTime);
//是为了防止过了录音时间后,会多发一条语音出去的情况。
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
btn_speak.setClickable(true);
}
}, 1000);
}
}
});
}
/**
*
* @author smile
* @date 2014-7-1 6:10:16
*/
class VoiceTouchListener implements View.OnTouchListener {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
if (!Util.checkSdCard()) {
toast("发送语音需要sdcard支持");
return false;
}
try {
v.setPressed(true);
layout_record.setVisibility(View.VISIBLE);
tv_voice_tips.setText(getString(R.string.voice_cancel_tips));
// 开始录音
recordManager.startRecording(c.getConversationId());
} catch (Exception e) {
e.printStackTrace();
}
return true;
case MotionEvent.ACTION_MOVE: {
if (event.getY() < 0) {
tv_voice_tips.setText(getString(R.string.voice_cancel_tips));
tv_voice_tips.setTextColor(Color.RED);
} else {
tv_voice_tips.setText(getString(R.string.voice_up_tips));
tv_voice_tips.setTextColor(Color.WHITE);
}
return true;
}
case MotionEvent.ACTION_UP:
v.setPressed(false);
layout_record.setVisibility(View.INVISIBLE);
try {
if (event.getY() < 0) {// 放弃录音
recordManager.cancelRecording();
Logger.i("voice", "放弃发送语音");
} else {
int recordTime = recordManager.stopRecording();
if (recordTime > 1) {
// 发送语音文件
sendVoiceMessage(recordManager.getRecordFilePath(c.getConversationId()),recordTime);
} else {// 录音时间过短,则提示录音过短的提示
layout_record.setVisibility(View.GONE);
showShortToast().show();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return true;
default:
return false;
}
}
}
Toast toast;
/**
* Toast
* @Title: showShortToast
* @return void
*/
private Toast showShortToast() {
if (toast == null) {
toast = new Toast(this);
}
View view = LayoutInflater.from(this).inflate(
R.layout.include_chat_voice_short, null);
toast.setView(view);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.setDuration(Toast.LENGTH_SHORT);
return toast;
}
@OnClick(R.id.edit_msg)
public void onEditClick(View view){
if (layout_more.getVisibility() == View.VISIBLE) {
layout_add.setVisibility(View.GONE);
layout_emo.setVisibility(View.GONE);
layout_more.setVisibility(View.GONE);
}
}
@OnClick(R.id.btn_chat_emo)
public void onEmoClick(View view){
if (layout_more.getVisibility() == View.GONE) {
showEditState(true);
} else {
if (layout_add.getVisibility() == View.VISIBLE) {
layout_add.setVisibility(View.GONE);
layout_emo.setVisibility(View.VISIBLE);
} else {
layout_more.setVisibility(View.GONE);
}
}
}
@OnClick(R.id.btn_chat_add)
public void onAddClick(View view){
if (layout_more.getVisibility() == View.GONE) {
layout_more.setVisibility(View.VISIBLE);
layout_add.setVisibility(View.VISIBLE);
layout_emo.setVisibility(View.GONE);
hideSoftInputView();
} else {
if (layout_emo.getVisibility() == View.VISIBLE) {
layout_emo.setVisibility(View.GONE);
layout_add.setVisibility(View.VISIBLE);
} else {
layout_more.setVisibility(View.GONE);
}
}
}
@OnClick(R.id.btn_chat_voice)
public void onVoiceClick(View view){
edit_msg.setVisibility(View.GONE);
layout_more.setVisibility(View.GONE);
btn_chat_voice.setVisibility(View.GONE);
btn_chat_keyboard.setVisibility(View.VISIBLE);
btn_speak.setVisibility(View.VISIBLE);
hideSoftInputView();
}
@OnClick(R.id.btn_chat_keyboard)
public void onKeyClick(View view){
showEditState(false);
}
@OnClick(R.id.btn_chat_send)
public void onSendClick(View view){
sendMessage();
}
@OnClick(R.id.tv_picture)
public void onPictureClick(View view){
// sendLocalImageMessage();
// sendOtherMessage();
sendVideoMessage();
}
@OnClick(R.id.tv_camera)
public void onCameraClick(View view){
sendRemoteImageMessage();
}
@OnClick(R.id.tv_location)
public void onLocationClick(View view){
sendLocationMessage();
}
/**
*
* @param isEmo
* @return void
*/
private void showEditState(boolean isEmo) {
edit_msg.setVisibility(View.VISIBLE);
btn_chat_keyboard.setVisibility(View.GONE);
btn_chat_voice.setVisibility(View.VISIBLE);
btn_speak.setVisibility(View.GONE);
edit_msg.requestFocus();
if (isEmo) {
layout_more.setVisibility(View.VISIBLE);
layout_more.setVisibility(View.VISIBLE);
layout_emo.setVisibility(View.VISIBLE);
layout_add.setVisibility(View.GONE);
hideSoftInputView();
} else {
layout_more.setVisibility(View.GONE);
showSoftInputView();
}
}
/**
*
*/
public void showSoftInputView() {
if (getWindow().getAttributes().softInputMode == WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
if (getCurrentFocus() != null)
((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE))
.showSoftInput(edit_msg, 0);
}
}
/**
*
*/
private void sendMessage(){
String text=edit_msg.getText().toString();
if(TextUtils.isEmpty(text.trim())){
toast("请输入内容");
return;
}
BmobIMTextMessage msg =new BmobIMTextMessage();
msg.setContent(text);
//可设置额外信息
Map<String,Object> map =new HashMap<>();
map.put("level", "1");//随意增加信息
msg.setExtraMap(map);
c.sendMessage(msg, listener);
}
/**
*
*/
public void sendRemoteImageMessage(){
BmobIMImageMessage image =new BmobIMImageMessage();
image.setRemoteUrl("http://img.lakalaec.com/ad/57ab6dc2-43f2-4087-81e2-b5ab5681642d.jpg");
c.sendMessage(image, listener);
}
/**
*
*/
public void sendLocalImageMessage(){
//正常情况下,需要调用系统的图库或拍照功能获取到图片的本地地址,开发者只需要将本地的文件地址传过去就可以发送文件类型的消息
BmobIMImageMessage image =new BmobIMImageMessage("/storage/emulated/0/bimagechooser/IMG_20160302_172003.jpg");
c.sendMessage(image, listener);
// //因此也可以使用BmobIMFileMessage来发送文件消息
// BmobIMFileMessage file =new BmobIMFileMessage("文件地址");
// c.sendMessage(file,listener);
}
/**
*
* @Title: sendVoiceMessage
* @param local
* @param length
* @return void
*/
private void sendVoiceMessage(String local, int length) {
BmobIMAudioMessage audio =new BmobIMAudioMessage(local);
//可设置额外信息-开发者设置的额外信息需要开发者自己从extra中取出来
Map<String,Object> map =new HashMap<>();
map.put("from", "优酷");
audio.setExtraMap(map);
//设置语音文件时长:可选
// audio.setDuration(length);
c.sendMessage(audio, listener);
}
/**
*
*/
private void sendVideoMessage(){
BmobIMVideoMessage video =new BmobIMVideoMessage("/storage/sdcard0/bimagechooser/11.png");
c.sendMessage(video, listener);
}
/**
*
*/
public void sendLocationMessage(){
//测试数据真实数据需要从地图SDK中获取
Bundle bundle = new Bundle();
bundle.putSerializable("c", c);
startActivity(LocActivity.class , bundle, true);
/*BmobIMLocationMessage location =new BmobIMLocationMessage("广州番禺区",23.5,112.0);
Map<String,Object> map =new HashMap<>();
map.put("from", "百度地图");
location.setExtraMap(map);
c.sendMessage(location, listener);*/
}
/**
*
*/
public MessageSendListener listener =new MessageSendListener() {
@Override
public void onProgress(int value) {
super.onProgress(value);
//文件类型的消息才有进度值
Logger.i("onProgress"+value);
}
@Override
public void onStart(BmobIMMessage msg) {
super.onStart(msg);
adapter.addMessage(msg);
edit_msg.setText("");
scrollToBottom();
}
@Override
public void done(BmobIMMessage msg, BmobException e) {
adapter.notifyDataSetChanged();
edit_msg.setText("");
scrollToBottom();
if (e != null) {
toast(e.getMessage());
}
}
};
/**msgnullmsg
* @param msg
*/
public void queryMessages(BmobIMMessage msg){
c.queryMessages(msg, 10, new MessagesQueryListener() {
@Override
public void done(List<BmobIMMessage> list, BmobException e) {
sw_refresh.setRefreshing(false);
if (e == null) {
if (null != list && list.size() > 0) {
adapter.addMessages(list);
layoutManager.scrollToPositionWithOffset(list.size() - 1, 0);
}
} else {
toast(e.getMessage() + "(" + e.getErrorCode() + ")");
}
}
});
}
private void scrollToBottom() {
layoutManager.scrollToPositionWithOffset(adapter.getItemCount() - 1, 0);
}
@Override
public void onMessageReceive(List<MessageEvent> list) {
Logger.i("聊天页面接收到消息:" + list.size());
//当注册页面消息监听时候,有消息(包含离线消息)到来时会回调该方法
for (int i=0;i<list.size();i++){
addMessage2Chat(list.get(i));
}
}
// /**接收到聊天消息
// * @param event
// */
// @Subscribe
// public void onEventMainThread(MessageEvent event){
// addMessage2Chat(event);
// }
//
// @Subscribe
// public void onEventMainThread(OfflineMessageEvent event){
// Map<String,List<MessageEvent>> map =event.getEventMap();
// if(map!=null&&map.size()>0){
// //只获取当前聊天对象的离线消息
// List<MessageEvent> list = map.get(c.getConversationId());
// if(list!=null && list.size()>0){
// for (int i=0;i<list.size();i++){
// addMessage2Chat(list.get(i));
// }
// }
// }
// }
/**
* @param event
*/
private void addMessage2Chat(MessageEvent event){
BmobIMMessage msg =event.getMessage();
if(c!=null && event!=null && c.getConversationId().equals(event.getConversation().getConversationId()) //如果是当前会话的消息
&& !msg.isTransient()){//并且不为暂态消息
if(adapter.findPosition(msg)<0){//如果未添加到界面中
adapter.addMessage(msg);
//更新该会话下面的已读状态
c.updateReceiveStatus(msg);
}
scrollToBottom();
}else{
Logger.i("不是与当前聊天对象的消息");
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (layout_more.getVisibility() == View.VISIBLE) {
layout_more.setVisibility(View.GONE);
return false;
} else {
return super.onKeyDown(keyCode, event);
}
} else {
return super.onKeyDown(keyCode, event);
}
}
@Override
protected void onResume() {
//锁屏期间的收到的未读消息需要添加到聊天界面中
addUnReadMessage();
//添加页面消息监听器
BmobIM.getInstance().addMessageListHandler(this);
// 有可能锁屏期间,在聊天界面出现通知栏,这时候需要清除通知
BmobNotificationManager.getInstance(this).cancelNotification();
super.onResume();
}
/**
*
*/
private void addUnReadMessage(){
List<MessageEvent> cache = BmobNotificationManager.getInstance(this).getNotificationCacheList();
if(cache.size()>0){
int size =cache.size();
for(int i=0;i<size;i++){
MessageEvent event = cache.get(i);
addMessage2Chat(event);
}
}
scrollToBottom();
}
@Override
protected void onPause() {
//移除页面消息监听器
BmobIM.getInstance().removeMessageListHandler(this);
super.onPause();
}
@Override
protected void onDestroy() {
//清理资源
if(recordManager!=null){
recordManager.clear();
}
//更新此会话的所有消息为已读状态
if(c!=null){
c.updateLocalCache();
}
hideSoftInputView();
super.onDestroy();
}
}

@ -1,8 +1,18 @@
package cn.bmob.imdemo.ui;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Message;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.baidu.location.BDLocation;
@ -30,20 +40,25 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import butterknife.Bind;
import cn.bmob.imdemo.R;
import cn.bmob.imdemo.adapter.ChatAdapter;
import cn.bmob.imdemo.base.ParentWithNaviActivity;
import cn.bmob.imdemo.util.Util;
import cn.bmob.imdemo.util.Utils;
import cn.bmob.imdemo.bean.FindUOverlayManager;
import cn.bmob.newim.BmobIM;
import cn.bmob.newim.bean.BmobIMAudioMessage;
import cn.bmob.newim.bean.BmobIMConversation;
import cn.bmob.newim.bean.BmobIMLocationMessage;
import cn.bmob.newim.bean.BmobIMMessage;
import cn.bmob.newim.core.BmobIMClient;
import cn.bmob.newim.core.BmobRecordManager;
import cn.bmob.newim.event.MessageEvent;
import cn.bmob.newim.listener.MessageListHandler;
import cn.bmob.newim.listener.MessageSendListener;
import cn.bmob.newim.listener.ObseverListener;
import cn.bmob.newim.listener.OnRecordChangeListener;
import cn.bmob.v3.exception.BmobException;
public class LocActivity extends ParentWithNaviActivity implements ObseverListener,MessageListHandler {
@ -52,6 +67,19 @@ public class LocActivity extends ParentWithNaviActivity implements ObseverListen
public LocationClient mLocationClient = null;
public BDLocationListener myListener = new MyLocationListener();
@Bind(R.id.btn_speak)
Button btn_speak;
@Bind(R.id.iv_record)
ImageView iv_record;
@Bind(R.id.layout_record)
RelativeLayout layout_record;
@Bind(R.id.tv_voice_tips)
TextView tv_voice_tips;
private Drawable[] drawable_Anims;// 话筒动画
BmobRecordManager recordManager;
public LatLng my_loc = new LatLng(28.233982,113.003927);
public LatLng friend_loc = new LatLng(28.233982,113.003927);
@ -75,6 +103,8 @@ public class LocActivity extends ParentWithNaviActivity implements ObseverListen
//adapter = new ChatAdapter(this, c);
initNaviView();
initVoiceView();
initBottomView();
initLocation();
mMapView = (MapView) findViewById(R.id.bmapView);
@ -83,6 +113,164 @@ public class LocActivity extends ParentWithNaviActivity implements ObseverListen
mLocationClient.start();
}
private void initBottomView() {
btn_speak.setVisibility(View.VISIBLE);
}
private void initVoiceView() {
btn_speak.setOnTouchListener(new VoiceTouchListener());
initVoiceAnimRes();
initRecordManager();
}
/**
*
* @Title: initVoiceAnimRes
* @param
* @return void
*/
private void initVoiceAnimRes() {
drawable_Anims = new Drawable[] {
getResources().getDrawable(R.mipmap.chat_icon_voice2),
getResources().getDrawable(R.mipmap.chat_icon_voice3),
getResources().getDrawable(R.mipmap.chat_icon_voice4),
getResources().getDrawable(R.mipmap.chat_icon_voice5),
getResources().getDrawable(R.mipmap.chat_icon_voice6) };
}
private void initRecordManager(){
// 语音相关管理器
recordManager = BmobRecordManager.getInstance(this);
// 设置音量大小监听--在这里开发者可以自己实现当剩余10秒情况下的给用户的提示类似微信的语音那样
recordManager.setOnRecordChangeListener(new OnRecordChangeListener() {
@Override
public void onVolumnChanged(int value) {
iv_record.setImageDrawable(drawable_Anims[value]);
}
@Override
public void onTimeChanged(int recordTime, String localPath) {
Logger.i("voice", "已录音长度:" + recordTime);
if (recordTime >= BmobRecordManager.MAX_RECORD_TIME) {// 1分钟结束发送消息
// 需要重置按钮
btn_speak.setPressed(false);
btn_speak.setClickable(false);
// 取消录音框
layout_record.setVisibility(View.INVISIBLE);
// 发送语音消息
sendVoiceMessage(localPath, recordTime);
//是为了防止过了录音时间后,会多发一条语音出去的情况。
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
btn_speak.setClickable(true);
}
}, 1000);
}
}
});
}
/**
*
* @author smile
* @date 2014-7-1 6:10:16
*/
class VoiceTouchListener implements View.OnTouchListener {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
if (!Util.checkSdCard()) {
toast("发送语音需要sdcard支持");
return false;
}
try {
v.setPressed(true);
layout_record.setVisibility(View.VISIBLE);
tv_voice_tips.setText(getString(R.string.voice_cancel_tips));
// 开始录音
recordManager.startRecording(c.getConversationId());
} catch (Exception e) {
e.printStackTrace();
}
return true;
case MotionEvent.ACTION_MOVE: {
if (event.getY() < 0) {
tv_voice_tips.setText(getString(R.string.voice_cancel_tips));
tv_voice_tips.setTextColor(Color.RED);
} else {
tv_voice_tips.setText(getString(R.string.voice_up_tips));
tv_voice_tips.setTextColor(Color.WHITE);
}
return true;
}
case MotionEvent.ACTION_UP:
v.setPressed(false);
layout_record.setVisibility(View.INVISIBLE);
try {
if (event.getY() < 0) {// 放弃录音
recordManager.cancelRecording();
Logger.i("voice", "放弃发送语音");
} else {
int recordTime = recordManager.stopRecording();
if (recordTime > 1) {
// 发送语音文件
sendVoiceMessage(recordManager.getRecordFilePath(c.getConversationId()),recordTime);
} else {// 录音时间过短,则提示录音过短的提示
layout_record.setVisibility(View.GONE);
showShortToast().show();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return true;
default:
return false;
}
}
}
Toast toast;
/**
* Toast
* @Title: showShortToast
* @return void
*/
private Toast showShortToast() {
if (toast == null) {
toast = new Toast(this);
}
View view = LayoutInflater.from(this).inflate(
R.layout.include_chat_voice_short, null);
toast.setView(view);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.setDuration(Toast.LENGTH_SHORT);
return toast;
}
/**
*
* @Title: sendVoiceMessage
* @param local
* @param length
* @return void
*/
private void sendVoiceMessage(String local, int length) {
BmobIMAudioMessage audio =new BmobIMAudioMessage(local);
//可设置额外信息-开发者设置的额外信息需要开发者自己从extra中取出来
Map<String,Object> map =new HashMap<>();
map.put("from", "优酷");
audio.setExtraMap(map);
//设置语音文件时长:可选
// audio.setDuration(length);
c.sendMessage(audio, listener);
}
/**
@ -347,6 +535,9 @@ public class LocActivity extends ParentWithNaviActivity implements ObseverListen
friend_loc = new LatLng(recv_loc_msg.getLatitude(), recv_loc_msg.getLongitude());
refresh_map();
}
else if ( msg.getMsgType().equals("audio")){
}
}

@ -41,17 +41,13 @@ import cn.bmob.v3.exception.BmobException;
*/
public class MainActivity extends BaseActivity implements ObseverListener{
@Bind(R.id.btn_conversation)
Button btn_conversation;
@Bind(R.id.btn_set)
Button btn_set;
@Bind(R.id.btn_contact)
Button btn_contact;
@Bind(R.id.iv_conversation_tips)
ImageView iv_conversation_tips;
@Bind(R.id.iv_contact_tips)
ImageView iv_contact_tips;
@ -95,10 +91,9 @@ public class MainActivity extends BaseActivity implements ObseverListener{
@Override
protected void initView() {
super.initView();
mTabs = new Button[3];
mTabs[0] = btn_conversation;
mTabs[1] = btn_contact;
mTabs[2] =btn_set;
mTabs = new Button[2];
mTabs[0] = btn_contact;
mTabs[1] =btn_set;
mTabs[0].setSelected(true);
initTab();
}
@ -107,25 +102,21 @@ public class MainActivity extends BaseActivity implements ObseverListener{
conversationFragment = new ConversationFragment();
setFragment = new SetFragment();
contactFragment=new ContactFragment();
fragments = new Fragment[] {conversationFragment, contactFragment,setFragment};
fragments = new Fragment[] {contactFragment,setFragment};
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_container, conversationFragment).
add(R.id.fragment_container, contactFragment)
.add(R.id.fragment_container, contactFragment)
.add(R.id.fragment_container, setFragment)
.hide(setFragment).hide(contactFragment)
.show(conversationFragment).commit();
.hide(setFragment)
.show(contactFragment).commit();
}
public void onTabSelect(View view) {
switch (view.getId()) {
case R.id.btn_conversation:
index = 0;
break;
case R.id.btn_contact:
index = 1;
index = 0;
break;
case R.id.btn_set:
index = 2;
index = 1;
break;
}
onTabIndex(index);
@ -189,9 +180,9 @@ public class MainActivity extends BaseActivity implements ObseverListener{
private void checkRedPoint(){
int count = (int)BmobIM.getInstance().getAllUnReadCount();
if(count>0){
iv_conversation_tips.setVisibility(View.VISIBLE);
iv_contact_tips.setVisibility(View.VISIBLE);
}else{
iv_conversation_tips.setVisibility(View.GONE);
iv_contact_tips.setVisibility(View.GONE);
}
//是否有好友添加的请求
if(NewFriendManager.getInstance(this).hasNewFriendInvitation()){

@ -27,6 +27,7 @@ import cn.bmob.imdemo.bean.User;
import cn.bmob.imdemo.event.RefreshEvent;
import cn.bmob.imdemo.model.UserModel;
import cn.bmob.imdemo.ui.ChatActivity;
import cn.bmob.imdemo.ui.LocActivity;
import cn.bmob.imdemo.ui.NewFriendActivity;
import cn.bmob.imdemo.ui.SearchUserActivity;
import cn.bmob.newim.BmobIM;
@ -141,7 +142,8 @@ public class ContactFragment extends ParentWithNaviFragment {
BmobIMConversation c = BmobIM.getInstance().startPrivateConversation(info, null);
Bundle bundle = new Bundle();
bundle.putSerializable("c", c);
startActivity(ChatActivity.class, bundle);
startActivity(LocActivity.class, bundle);
//startActivity(ChatActivity.class, bundle);
}
}

@ -2,12 +2,12 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll_chat"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<include layout="@layout/include_navi"/>
<FrameLayout
<!--<FrameLayout
android:layout_weight="1.0"
android:layout_width="match_parent"
android:layout_height="0dp">
@ -51,6 +51,6 @@
android:textSize="14sp" />
</RelativeLayout>
</FrameLayout>
-->
<include layout="@layout/include_chat_bottom_bar"/>
</LinearLayout>

@ -9,10 +9,46 @@
<include layout="@layout/include_navi"/>
<FrameLayout
android:layout_weight="1.0"
android:layout_width="match_parent"
android:layout_height="0dp">
<com.baidu.mapapi.map.MapView
android:id="@+id/bmapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true" />
<RelativeLayout
android:id="@+id/layout_record"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_gravity="center"
android:visibility="invisible"
android:background="@drawable/chat_top_voice_bg"
android:padding="10dp" >
<ImageView
android:id="@+id/iv_record"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerHorizontal="true"
android:contentDescription="@string/action_settings"
android:src="@mipmap/chat_icon_voice1" />
<TextView
android:id="@+id/tv_voice_tips"
style="@style/style_text_white"
android:layout_below="@id/iv_record"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="@string/voice_up_tips"
android:textSize="14sp" />
</RelativeLayout>
</FrameLayout>
<include layout="@layout/include_chat_bottom_bar"/>
</LinearLayout>

@ -11,41 +11,6 @@
android:gravity="center_vertical"
android:orientation="horizontal" >
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" >
<Button
android:id="@+id/btn_conversation"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/top_bar"
android:drawableTop="@drawable/tab_message_btn"
android:onClick="onTabSelect"
android:paddingBottom="2dip"
android:paddingTop="7dip"
android:scaleType="matrix"
android:text="@string/main_tab_recent"
android:textColor="@drawable/tab_textcolor"
android:textSize="12sp" />
<ImageView
android:id="@+id/iv_conversation_tips"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="30dp"
android:layout_marginTop="7dp"
android:background="@mipmap/msg_tips"
android:contentDescription="@string/action_settings"
android:gravity="center"
android:textColor="@android:color/white"
android:textSize="12sp"
android:visibility="gone" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"

@ -6,6 +6,7 @@
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:fitsSystemWindows="true"
android:background="@color/base_bg"
tools:context="cn.bmob.imdemo.ui.SplashActivity">
<ImageView

@ -14,12 +14,14 @@
android:orientation="horizontal">
<Button
android:id="@+id/btn_chat_add"
android:id="@+id/btn_chat_voice"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/btn_chat_add_selector"
android:layout_marginLeft="6dp"
android:background="@drawable/btn_chat_voice_selector"
android:gravity="center"
android:onClick="toAction" />
android:textColor="@color/base_color_text_black" >
</Button>
<Button
android:id="@+id/btn_chat_emo"
@ -31,23 +33,6 @@
android:gravity="center"
android:onClick="toAction" />
<EditText
android:id="@+id/edit_msg"
android:textSize="@dimen/text_size_medium"
android:layout_marginLeft="6dp"
android:textColor="@color/color_1e1e1e"
android:hint="请输入新消息"
android:textColorHint="@color/color_b4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="left|center"
android:lineSpacingExtra="@dimen/margin_3"
android:background="@drawable/drawable_edit_normal"
android:imeOptions="flagNoExtractUi"
android:minHeight="@dimen/height_40"
android:padding="@dimen/margin_5"/>
<Button
android:id="@+id/btn_speak"
style="@style/style_text_black"
@ -62,16 +47,6 @@
android:text="@string/longclick_speak" >
</Button>
<Button
android:id="@+id/btn_chat_voice"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="6dp"
android:background="@drawable/btn_chat_voice_selector"
android:gravity="center"
android:textColor="@color/base_color_text_black" >
</Button>
<Button
android:id="@+id/btn_chat_keyboard"
android:layout_width="30dp"
@ -91,37 +66,6 @@
android:background="@drawable/btn_chat_send_selector"
android:gravity="center"
/>
</LinearLayout>
<View android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:background="@color/color_emote_divder"
android:focusable="false" />
<LinearLayout
android:id="@+id/layout_more"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/layout_emo"
android:layout_width="match_parent"
android:layout_height="120dp"
android:orientation="vertical"
android:visibility="gone" >
<android.support.v4.view.ViewPager
android:id="@+id/pager_emo"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<include
android:id="@+id/layout_add"
android:visibility="gone"
layout="@layout/include_chat_add" />
</LinearLayout>
</LinearLayout>

@ -19,7 +19,7 @@
<color name="theme_bg_color">#f0f2f5</color>
<color name="c_f98800">#ed4e23</color>
<color name="base_bg">#f4f6f6</color>
<color name="base_bg">#ffffff</color>
<color name="dialog_color_title">#f82c22</color>
<color name="guide_color">#898989</color>

Loading…
Cancel
Save