|
|
@@ -9,23 +9,26 @@ import android.content.pm.PackageManager;
|
|
|
import android.net.Uri;
|
|
|
import android.os.Bundle;
|
|
|
import android.support.v4.content.LocalBroadcastManager;
|
|
|
+import android.view.Gravity;
|
|
|
+import android.view.LayoutInflater;
|
|
|
import android.view.Menu;
|
|
|
import android.view.MenuItem;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.LinearLayout;
|
|
|
+import android.widget.PopupWindow;
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
import com.baidu.mapapi.map.MapView;
|
|
|
import com.baidu.mapapi.model.LatLng;
|
|
|
import com.baidu.mapapi.navi.BaiduMapAppNotSupportNaviException;
|
|
|
-import com.baidu.mapapi.navi.BaiduMapNavigation;
|
|
|
-import com.baidu.mapapi.navi.NaviParaOption;
|
|
|
import com.baidu.mapapi.search.core.SearchResult;
|
|
|
import com.baidu.mapapi.search.route.DrivingRoutePlanOption;
|
|
|
import com.baidu.mapapi.search.route.DrivingRouteResult;
|
|
|
import com.baidu.mapapi.search.route.OnGetRoutePlanResultListener;
|
|
|
import com.baidu.mapapi.search.route.PlanNode;
|
|
|
import com.baidu.mapapi.search.route.RoutePlanSearch;
|
|
|
-import com.common.LogUtil;
|
|
|
import com.common.data.ListUtils;
|
|
|
+import com.common.system.DisplayUtil;
|
|
|
import com.core.app.Constants;
|
|
|
import com.core.base.BaseActivity;
|
|
|
import com.core.utils.BaiduMapUtil;
|
|
|
@@ -46,7 +49,6 @@ public class NavigationActivity extends BaseActivity {
|
|
|
@ViewInject(R.id.baiduMap)
|
|
|
private MapView baiduMap;
|
|
|
private LatLng toLocation;
|
|
|
- private List<String > mapList=null;
|
|
|
|
|
|
|
|
|
private BroadcastReceiver upLocationReceiver = new BroadcastReceiver() {
|
|
|
@@ -75,7 +77,7 @@ public class NavigationActivity extends BaseActivity {
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
if (item.getItemId() == R.id.other_map) {
|
|
|
//使用其他地图
|
|
|
- userOtherMap();
|
|
|
+ showPopupWindow();
|
|
|
}
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
}
|
|
|
@@ -142,16 +144,6 @@ public class NavigationActivity extends BaseActivity {
|
|
|
};
|
|
|
|
|
|
|
|
|
- private void userOtherMap() {
|
|
|
- if (isInstallBaidu()) {
|
|
|
- LogUtil.i("百度地图客户端已经安装");
|
|
|
- startNaviBaidu();
|
|
|
- } else {
|
|
|
- LogUtil.i("百度地图客户端没有安装");
|
|
|
- ToastMessage("系统检测到本机没有安装百度地图,请安装后使用");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
private boolean isInstallBaidu() {
|
|
|
return new File("/data/data/" + "com.baidu.BaiduMap").exists();
|
|
|
@@ -161,8 +153,12 @@ public class NavigationActivity extends BaseActivity {
|
|
|
return new File("/data/data/" + "com.autonavi.minimap").exists();
|
|
|
}
|
|
|
|
|
|
+ private boolean isInstallGoogle() {
|
|
|
+ return isAvilible(this, "com.google.android.apps.maps");
|
|
|
+ }
|
|
|
+
|
|
|
//是否安装腾讯地图
|
|
|
- public boolean isHaveTencentMap() {
|
|
|
+ public boolean isInstallTencent() {
|
|
|
try {
|
|
|
if (!new File("/data/data/" + "com.tencent.map").exists()) {
|
|
|
return false;
|
|
|
@@ -194,15 +190,10 @@ public class NavigationActivity extends BaseActivity {
|
|
|
|
|
|
//开启百度导航
|
|
|
public void startNaviBaidu() {
|
|
|
- //百度地图,从起点是LatLng ll_location = new LatLng("你的纬度latitude","你的经度longitude");
|
|
|
- //终点是LatLng ll = new LatLng("你的纬度latitude","你的经度longitude");
|
|
|
- NaviParaOption para = new NaviParaOption();
|
|
|
- para.startPoint(UasLocationHelper.getInstance().getUASLocation().getLocation());
|
|
|
- para.startName(UasLocationHelper.getInstance().getUASLocation().getName());
|
|
|
- para.endPoint(toLocation);
|
|
|
- para.endName("到这里结束");
|
|
|
try {
|
|
|
- BaiduMapNavigation.openBaiduMapNavi(para, this);
|
|
|
+ Intent intent = new Intent();
|
|
|
+ intent.setData(Uri.parse("baidumap://map/navi?location=" + toLocation.latitude + "," + toLocation.longitude));
|
|
|
+ startActivity(intent);
|
|
|
} catch (BaiduMapAppNotSupportNaviException e) {
|
|
|
e.printStackTrace();
|
|
|
ToastUtil.showToast(ct, "您尚未安装百度地图或地图版本过低");
|
|
|
@@ -242,7 +233,7 @@ public class NavigationActivity extends BaseActivity {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public void openTencentMap() {
|
|
|
+ public void startNaviTencent() {
|
|
|
try {
|
|
|
String url = "qqmap://map/routeplan?type=drive&to=" + "到这里结束" + "&tocoord=" + toLocation.latitude + "," + toLocation.longitude + "&policy=2&referer=myapp";
|
|
|
Intent intent = new Intent("android.intent.action.VIEW", android.net.Uri.parse(url));
|
|
|
@@ -251,4 +242,107 @@ public class NavigationActivity extends BaseActivity {
|
|
|
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ private PopupWindow selectWindow;
|
|
|
+
|
|
|
+ private void showPopupWindow() {
|
|
|
+ if (selectWindow == null) {
|
|
|
+ selectWindow = initPopupWindow();
|
|
|
+ }
|
|
|
+ if (selectWindow==null){
|
|
|
+ ToastUtil.showToast(ct,"当前手机没有安装相应的地图软件,请在应用市场上安装相应软件");
|
|
|
+ }else{
|
|
|
+ selectWindow.showAtLocation(getWindow().getDecorView().
|
|
|
+ findViewById(android.R.id.content), Gravity.BOTTOM, 0, 0);
|
|
|
+ DisplayUtil.backgroundAlpha(this, 0.7f);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void closePopupWindow() {
|
|
|
+ if (selectWindow != null)
|
|
|
+ selectWindow.dismiss();
|
|
|
+ DisplayUtil.backgroundAlpha(this, 1f);
|
|
|
+ }
|
|
|
+
|
|
|
+ private PopupWindow initPopupWindow() {
|
|
|
+ View viewContext = LayoutInflater.from(mContext).inflate(com.uas.appme.R.layout.pop_navigation_select, null);
|
|
|
+ boolean hasMap = false;
|
|
|
+ if (isInstallBaidu()) {
|
|
|
+ hasMap = true;
|
|
|
+ View view = viewContext.findViewById(R.id.baiduMapTv);
|
|
|
+ view.setVisibility(View.VISIBLE);
|
|
|
+ view.setOnClickListener(mSelectOnclickLister);
|
|
|
+ viewContext.findViewById(R.id.baiduMapTag).setVisibility(View.VISIBLE);
|
|
|
+ } else {
|
|
|
+ viewContext.findViewById(R.id.baiduMapTv).setVisibility(View.GONE);
|
|
|
+ viewContext.findViewById(R.id.baiduMapTag).setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ if (isInstallGaode()) {
|
|
|
+ hasMap = true;
|
|
|
+ View view = viewContext.findViewById(R.id.gaodeMapTv);
|
|
|
+ view.setVisibility(View.VISIBLE);
|
|
|
+ view.setOnClickListener(mSelectOnclickLister);
|
|
|
+ viewContext.findViewById(R.id.gaodeMapTag).setVisibility(View.VISIBLE);
|
|
|
+ } else {
|
|
|
+ viewContext.findViewById(R.id.gaodeMapTv).setVisibility(View.GONE);
|
|
|
+ viewContext.findViewById(R.id.gaodeMapTag).setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ if (isInstallTencent()) {
|
|
|
+ hasMap = true;
|
|
|
+ View view = viewContext.findViewById(R.id.tencentMapTv);
|
|
|
+ view.setVisibility(View.VISIBLE);
|
|
|
+ view.setOnClickListener(mSelectOnclickLister);
|
|
|
+ viewContext.findViewById(R.id.tencentMapTag).setVisibility(View.VISIBLE);
|
|
|
+ } else {
|
|
|
+ viewContext.findViewById(R.id.tencentMapTv).setVisibility(View.GONE);
|
|
|
+ viewContext.findViewById(R.id.tencentMapTag).setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ if (isInstallGoogle()) {
|
|
|
+ hasMap = true;
|
|
|
+ View view = viewContext.findViewById(R.id.googleMapTv);
|
|
|
+ view.setVisibility(View.VISIBLE);
|
|
|
+ view.setOnClickListener(mSelectOnclickLister);
|
|
|
+ } else {
|
|
|
+ viewContext.findViewById(R.id.googleMapTv).setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ if (hasMap) {
|
|
|
+ viewContext.findViewById(com.uas.appme.R.id.cancel_tv).setOnClickListener(mSelectOnclickLister);
|
|
|
+ PopupWindow selectWindow = new PopupWindow(viewContext,
|
|
|
+ LinearLayout.LayoutParams.MATCH_PARENT,
|
|
|
+ LinearLayout.LayoutParams.WRAP_CONTENT, true);
|
|
|
+ selectWindow.setAnimationStyle(com.uas.appme.R.style.MenuAnimationFade);
|
|
|
+ selectWindow.setBackgroundDrawable(mContext.getResources().getDrawable(com.uas.appme.R.drawable.bg_popuwin));
|
|
|
+ selectWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
|
|
|
+ @Override
|
|
|
+ public void onDismiss() {
|
|
|
+ closePopupWindow();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return selectWindow;
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private View.OnClickListener mSelectOnclickLister = new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ int id = view.getId();
|
|
|
+ if (id == R.id.baiduMapTv) {
|
|
|
+ startNaviBaidu();
|
|
|
+ } else if (id == R.id.gaodeMapTv) {
|
|
|
+ startNaviGao();
|
|
|
+ } else if (id == R.id.tencentMapTv) {
|
|
|
+ startNaviTencent();
|
|
|
+ } else if (id == R.id.googleMapTv) {
|
|
|
+ startNaviGoogle();
|
|
|
+ } else {
|
|
|
+ closePopupWindow();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ };
|
|
|
}
|