diff --git a/app/src/main/java/cn/bmob/imdemo/ui/ChatActivity.java b/app/src/main/java/cn/bmob/imdemo/ui/ChatActivity.java index 42ae877..cd54378 100755 --- a/app/src/main/java/cn/bmob/imdemo/ui/ChatActivity.java +++ b/app/src/main/java/cn/bmob/imdemo/ui/ChatActivity.java @@ -525,7 +525,11 @@ public class ChatActivity extends ParentWithNaviActivity implements ObseverListe */ public void sendLocationMessage(){ //测试数据,真实数据需要从地图SDK中获取 - startActivity(LocActivity.class , null, true); + + Bundle bundle = new Bundle(); + bundle.putSerializable("c", c); + startActivity(LocActivity.class , bundle, true); + /*BmobIMLocationMessage location =new BmobIMLocationMessage("广州番禺区",23.5,112.0); Map map =new HashMap<>(); map.put("from", "百度地图"); diff --git a/app/src/main/java/cn/bmob/imdemo/ui/LocActivity.java b/app/src/main/java/cn/bmob/imdemo/ui/LocActivity.java index 5fc1eed..00b6e87 100644 --- a/app/src/main/java/cn/bmob/imdemo/ui/LocActivity.java +++ b/app/src/main/java/cn/bmob/imdemo/ui/LocActivity.java @@ -16,8 +16,11 @@ import com.baidu.mapapi.map.BitmapDescriptorFactory; import com.baidu.mapapi.map.MapStatusUpdateFactory; import com.baidu.mapapi.map.MapView; import com.baidu.mapapi.map.MarkerOptions; +import com.baidu.mapapi.map.MyLocationConfiguration; +import com.baidu.mapapi.map.MyLocationData; import com.baidu.mapapi.map.OverlayOptions; import com.baidu.mapapi.model.LatLng; + import com.baidu.mapapi.utils.DistanceUtil; import com.orhanobut.logger.Logger; @@ -43,13 +46,16 @@ public class LocActivity extends ParentWithNaviActivity{ BaiduMap mBaiduMap = null; public LocationClient mLocationClient = null; public BDLocationListener myListener = new MyLocationListener(); - private LinkedList locationList = new LinkedList(); // 存放历史定位结果的链表,最大存放当前结果的前5次定位结果 - //BmobIMConversation c; - //ChatAdapter adapter; + private MyLocationData mylocdata = null; + private MyLocationData friendlocdata = null; - Toast loc_toast = null; + private LinkedList locationList = new LinkedList(); // 存放历史定位结果的链表,最大存放当前结果的前5次定位结果 + int exe_count = 0; + BmobIMConversation c; + ChatAdapter adapter; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -60,23 +66,32 @@ public class LocActivity extends ParentWithNaviActivity{ mLocationClient.registerLocationListener( myListener ); setContentView(R.layout.activity_loc); - //c= BmobIMConversation.obtain(BmobIMClient.getInstance(), (BmobIMConversation) getBundle().getSerializable("c")); - + c= BmobIMConversation.obtain(BmobIMClient.getInstance(), (BmobIMConversation) getBundle().getSerializable("c")); + adapter = new ChatAdapter(this,c); initNaviView(); - //initLocation(); + initLocation(); mMapView = (MapView) findViewById(R.id.bmapView); mBaiduMap = mMapView.getMap(); mBaiduMap.setMapType(BaiduMap.MAP_TYPE_NORMAL); // 开启定位图层 - mBaiduMap.setMyLocationEnabled(true); - mBaiduMap.setMapStatus(MapStatusUpdateFactory.zoomTo(16)); + mLocationClient.start(); - mLocationClient.requestLocation(); - mBaiduMap.clear(); + Logger.i("before \n"); + //mLocationClient.requestLocation(); + + Logger.i("after \n"); + + + + + + //mBaiduMap.clear(); + + //mLocationClient.requestLocation(); //send_recv_real_time(); @@ -114,7 +129,7 @@ public class LocActivity extends ParentWithNaviActivity{ /** * 消息发送监听器 */ - /* public MessageSendListener listener =new MessageSendListener() { + public MessageSendListener listener =new MessageSendListener() { @Override public void onProgress(int value) { @@ -127,21 +142,17 @@ public class LocActivity extends ParentWithNaviActivity{ 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()); } } }; -*/ + @Override public ParentWithNaviActivity.ToolBarListener setToolBarListener() { return new ParentWithNaviActivity.ToolBarListener() { @@ -160,6 +171,8 @@ public class LocActivity extends ParentWithNaviActivity{ super.onDestroy(); mLocationClient.unRegisterLocationListener( myListener ); mLocationClient.stop(); + // 当不需要定位图层时关闭定位图层 + mBaiduMap.setMyLocationEnabled(false); //在activity执行onDestroy时执行mMapView.onDestroy(),实现地图生命周期管理 mMapView.onDestroy(); } @@ -227,6 +240,7 @@ public class LocActivity extends ParentWithNaviActivity{ } } Logger.i(sb.toString());*/ + exe_count = exe_count + 1; if (location != null && (location.getLocType() == 161 || location.getLocType() == 66)) { Message locMsg = locHander.obtainMessage(); Bundle locData; @@ -237,6 +251,28 @@ public class LocActivity extends ParentWithNaviActivity{ locHander.sendMessage(locMsg); } } + StringBuffer sb = new StringBuffer(256); + sb.append("execute times :"); + sb.append( exe_count ); + sb.append("\n"); + Logger.i( sb.toString() ); + mBaiduMap.setMyLocationEnabled(true); + /* + // 构造定位数据 + MyLocationData locData = new MyLocationData.Builder() + .accuracy(location.getRadius()) + // 此处设置开发者获取到的方向信息,顺时针0-360 + .direction(100).latitude(location.getLatitude()) + .longitude(location.getLongitude()).build(); + // 设置定位数据 + mBaiduMap.setMyLocationData(locData); + + // 设置定位图层的配置(定位模式,是否允许方向信息,用户自定义定位图标) + BitmapDescriptor mCurrentMarker = BitmapDescriptorFactory + .fromResource(R.drawable.chat_voice_bg); + MyLocationConfiguration config = new MyLocationConfiguration(MyLocationConfiguration.LocationMode.NORMAL, true, mCurrentMarker); + mBaiduMap.setMyLocationConfigeration(config); + */ } } /*** @@ -331,9 +367,28 @@ public class LocActivity extends ParentWithNaviActivity{ overlayManager.setData(aslist); mBaiduMap.setOnMarkerClickListener(overlayManager); overlayManager.addToMap(); - overlayManager.zoomToSpan(); + if( exe_count < 3) + overlayManager.zoomToSpan(); mBaiduMap.setMapStatus(MapStatusUpdateFactory.newLatLng( new LatLng ( (point.latitude + point2.latitude )/ 2,(point.longitude + point2.longitude)/2)) ); + BmobIMLocationMessage loc_msg =new BmobIMLocationMessage("myloc",location.getLatitude(),location.getAltitude()); + c.sendMessage(loc_msg, new MessageSendListener() { + + @Override + public void onStart(BmobIMMessage msg) { + adapter.addMessage(msg); + adapter.notifyDataSetChanged(); + } + + @Override + public void done(BmobIMMessage msg, BmobException e) { + adapter.notifyDataSetChanged(); + if (e != null) { + toast(e.getMessage()); + } + } + }); + } } catch (Exception e) { // TODO: handle exception diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png old mode 100755 new mode 100644 index 2e0b2b5..88c5c0c Binary files a/app/src/main/res/mipmap-hdpi/ic_launcher.png and b/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_bak.png b/app/src/main/res/mipmap-hdpi/ic_launcher_bak.png new file mode 100755 index 0000000..2e0b2b5 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher_bak.png differ diff --git a/app/src/main/res/mipmap-hdpi/login_logo.png b/app/src/main/res/mipmap-hdpi/login_logo.png old mode 100755 new mode 100644 index 6102f88..96d655d Binary files a/app/src/main/res/mipmap-hdpi/login_logo.png and b/app/src/main/res/mipmap-hdpi/login_logo.png differ diff --git a/app/src/main/res/mipmap-hdpi/login_logo_bak.png b/app/src/main/res/mipmap-hdpi/login_logo_bak.png new file mode 100755 index 0000000..6102f88 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/login_logo_bak.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png deleted file mode 100755 index c133a0c..0000000 Binary files a/app/src/main/res/mipmap-mdpi/ic_launcher.png and /dev/null differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png old mode 100755 new mode 100644 index bfa42f0..564cf69 Binary files a/app/src/main/res/mipmap-xhdpi/ic_launcher.png and b/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png old mode 100755 new mode 100644 index 324e72c..1a8629a Binary files a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png old mode 100755 new mode 100644 index aee44e1..2a82451 Binary files a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ