|
|
|
@ -1,7 +1,11 @@
|
|
|
|
|
package cn.bmob.imdemo.ui;
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.graphics.Color;
|
|
|
|
|
import android.graphics.drawable.AnimationDrawable;
|
|
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
|
import android.media.AudioManager;
|
|
|
|
|
import android.media.MediaPlayer;
|
|
|
|
|
import android.os.Handler;
|
|
|
|
|
import android.os.Message;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
@ -34,6 +38,8 @@ import com.baidu.mapapi.model.LatLng;
|
|
|
|
|
import com.baidu.mapapi.utils.DistanceUtil;
|
|
|
|
|
import com.orhanobut.logger.Logger;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.LinkedList;
|
|
|
|
@ -52,6 +58,7 @@ 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.BmobDownloadManager;
|
|
|
|
|
import cn.bmob.newim.core.BmobIMClient;
|
|
|
|
|
import cn.bmob.newim.core.BmobRecordManager;
|
|
|
|
|
import cn.bmob.newim.event.MessageEvent;
|
|
|
|
@ -66,6 +73,10 @@ public class LocActivity extends ParentWithNaviActivity implements ObseverListen
|
|
|
|
|
public BaiduMap mBaiduMap = null;
|
|
|
|
|
public LocationClient mLocationClient = null;
|
|
|
|
|
public BDLocationListener myListener = new MyLocationListener();
|
|
|
|
|
BmobIMAudioMessage audio_msg;
|
|
|
|
|
MediaPlayer mediaPlayer = null;
|
|
|
|
|
Context mContext;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Bind(R.id.btn_speak)
|
|
|
|
|
Button btn_speak;
|
|
|
|
@ -97,6 +108,8 @@ public class LocActivity extends ParentWithNaviActivity implements ObseverListen
|
|
|
|
|
SDKInitializer.initialize(getApplicationContext());
|
|
|
|
|
mLocationClient.registerLocationListener(myListener);
|
|
|
|
|
|
|
|
|
|
mContext = getApplicationContext();
|
|
|
|
|
|
|
|
|
|
setContentView(R.layout.activity_loc);
|
|
|
|
|
c = BmobIMConversation.obtain(BmobIMClient.getInstance(), (BmobIMConversation) getBundle().getSerializable("c"));
|
|
|
|
|
BmobIM.getInstance().addMessageListHandler(this);
|
|
|
|
@ -313,28 +326,6 @@ public class LocActivity extends ParentWithNaviActivity implements ObseverListen
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
protected void onDestroy() {
|
|
|
|
|
super.onDestroy();
|
|
|
|
|
mLocationClient.unRegisterLocationListener( myListener );
|
|
|
|
|
mLocationClient.stop();
|
|
|
|
|
// 当不需要定位图层时关闭定位图层
|
|
|
|
|
mBaiduMap.setMyLocationEnabled(false);
|
|
|
|
|
//在activity执行onDestroy时执行mMapView.onDestroy(),实现地图生命周期管理
|
|
|
|
|
mMapView.onDestroy();
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
protected void onResume() {
|
|
|
|
|
super.onResume();
|
|
|
|
|
//在activity执行onResume时执行mMapView. onResume (),实现地图生命周期管理
|
|
|
|
|
mMapView.onResume();
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
protected void onPause() {
|
|
|
|
|
super.onPause();
|
|
|
|
|
//在activity执行onPause时执行mMapView. onPause (),实现地图生命周期管理
|
|
|
|
|
mMapView.onPause();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected String title() {
|
|
|
|
@ -527,22 +518,104 @@ public class LocActivity extends ParentWithNaviActivity implements ObseverListen
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void process_recv_msg(MessageEvent event) {
|
|
|
|
|
Logger.i( "we are in process recv msg\n");
|
|
|
|
|
BmobIMMessage msg =event.getMessage();
|
|
|
|
|
Logger.i( msg.getMsgType() );
|
|
|
|
|
|
|
|
|
|
if( msg.getMsgType().equals("location")) {
|
|
|
|
|
Logger.i( "获取的msg的类型:" + msg.getMsgType() );
|
|
|
|
|
BmobIMLocationMessage recv_loc_msg = BmobIMLocationMessage.buildFromDB( msg );
|
|
|
|
|
friend_loc = new LatLng(recv_loc_msg.getLatitude(), recv_loc_msg.getLongitude());
|
|
|
|
|
refresh_map();
|
|
|
|
|
}
|
|
|
|
|
else if ( msg.getMsgType().equals("audio")){
|
|
|
|
|
else if ( msg.getMsgType().equals("sound")){
|
|
|
|
|
audio_msg = BmobIMAudioMessage.buildFromDB(true,msg);
|
|
|
|
|
String localPath = BmobDownloadManager.getDownLoadFilePath(audio_msg);
|
|
|
|
|
startPlayRecord(localPath, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void startPlayRecord(String filePath, boolean isUseSpeaker) {
|
|
|
|
|
if (!(new File(filePath).exists())) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Logger.i("start play Record ");
|
|
|
|
|
|
|
|
|
|
/*AudioManager audioManager = (AudioManager) mContext
|
|
|
|
|
.getSystemService(Context.AUDIO_SERVICE);
|
|
|
|
|
mediaPlayer = new MediaPlayer();
|
|
|
|
|
if (isUseSpeaker) {
|
|
|
|
|
audioManager.setMode(AudioManager.MODE_NORMAL);
|
|
|
|
|
audioManager.setSpeakerphoneOn(true);
|
|
|
|
|
mediaPlayer.setAudioStreamType(AudioManager.STREAM_RING);
|
|
|
|
|
} else {
|
|
|
|
|
audioManager.setSpeakerphoneOn(false);
|
|
|
|
|
audioManager.setMode(AudioManager.MODE_IN_CALL);
|
|
|
|
|
mediaPlayer.setAudioStreamType(AudioManager.STREAM_VOICE_CALL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
mediaPlayer.reset();
|
|
|
|
|
// 单独使用此方法会报错播放错误:setDataSourceFD failed.: status=0x80000000
|
|
|
|
|
// mediaPlayer.setDataSource(filePath);
|
|
|
|
|
// 因此采用此方式会避免这种错误
|
|
|
|
|
FileInputStream fis = new FileInputStream(new File(filePath));
|
|
|
|
|
//mediaPlayer.setDataSource(fis.getFD());
|
|
|
|
|
mediaPlayer.setDataSource(filePath);
|
|
|
|
|
mediaPlayer.prepare();
|
|
|
|
|
mediaPlayer.start();
|
|
|
|
|
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onPrepared(MediaPlayer arg0) {
|
|
|
|
|
|
|
|
|
|
arg0.start();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
mediaPlayer
|
|
|
|
|
.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onCompletion(MediaPlayer mp) {
|
|
|
|
|
stopPlayRecord();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}*/
|
|
|
|
|
}
|
|
|
|
|
public void stopPlayRecord() {
|
|
|
|
|
if (mediaPlayer != null) {
|
|
|
|
|
mediaPlayer.stop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
class LocationEntity {
|
|
|
|
|
BDLocation location;
|
|
|
|
|
long time;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onDestroy() {
|
|
|
|
|
super.onDestroy();
|
|
|
|
|
mLocationClient.unRegisterLocationListener( myListener );
|
|
|
|
|
mLocationClient.stop();
|
|
|
|
|
// 当不需要定位图层时关闭定位图层
|
|
|
|
|
mBaiduMap.setMyLocationEnabled(false);
|
|
|
|
|
//在activity执行onDestroy时执行mMapView.onDestroy(),实现地图生命周期管理
|
|
|
|
|
//mMapView.onDestroy();
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
protected void onResume() {
|
|
|
|
|
super.onResume();
|
|
|
|
|
//在activity执行onResume时执行mMapView. onResume (),实现地图生命周期管理
|
|
|
|
|
mMapView.onResume();
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
protected void onPause() {
|
|
|
|
|
super.onPause();
|
|
|
|
|
//在activity执行onPause时执行mMapView. onPause (),实现地图生命周期管理
|
|
|
|
|
mMapView.onPause();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|