@ -1,59 +0,0 @@
@@ -1,59 +0,0 @@
|
||||
package com.kanglai.push.entity; |
||||
|
||||
import android.os.Parcel; |
||||
import android.os.Parcelable; |
||||
|
||||
import com.amap.api.services.core.LatLonPoint; |
||||
|
||||
import lombok.Data; |
||||
import lombok.experimental.Accessors; |
||||
|
||||
/** |
||||
*<p> |
||||
* 路线规划活动传输点 |
||||
*</p> |
||||
* |
||||
* @Author: entfrm开发团队-王翔 |
||||
* @since: 2022/11/11 |
||||
*/ |
||||
@Data |
||||
@Accessors |
||||
public class RoutePlanLatPoint implements Parcelable { |
||||
|
||||
/** 起点 */ |
||||
private LatLonPoint originPoint; |
||||
|
||||
/** 终点 */ |
||||
private LatLonPoint destinationPoint; |
||||
|
||||
public RoutePlanLatPoint() { |
||||
} |
||||
|
||||
public RoutePlanLatPoint(Parcel in) { |
||||
originPoint = in.readTypedObject(LatLonPoint.CREATOR); |
||||
destinationPoint = in.readTypedObject(LatLonPoint.CREATOR); |
||||
} |
||||
|
||||
@Override |
||||
public int describeContents() { |
||||
return 0; |
||||
} |
||||
|
||||
@Override |
||||
public void writeToParcel(Parcel dest, int flags) { |
||||
dest.writeTypedObject(originPoint, flags); |
||||
dest.writeTypedObject(destinationPoint, flags); |
||||
} |
||||
|
||||
public static final Creator<RoutePlanLatPoint> CREATOR = new Creator() { |
||||
@Override |
||||
public RoutePlanLatPoint createFromParcel(Parcel in) { |
||||
return new RoutePlanLatPoint(in); |
||||
} |
||||
|
||||
@Override |
||||
public RoutePlanLatPoint[] newArray(int size) { |
||||
return new RoutePlanLatPoint[size]; |
||||
} |
||||
}; |
||||
} |
@ -1,157 +0,0 @@
@@ -1,157 +0,0 @@
|
||||
package com.kanglai.push.listener; |
||||
|
||||
import android.content.Context; |
||||
import android.hardware.Sensor; |
||||
import android.hardware.SensorEvent; |
||||
import android.hardware.SensorEventListener; |
||||
import android.hardware.SensorManager; |
||||
import android.view.Display; |
||||
import android.view.Surface; |
||||
import android.view.WindowManager; |
||||
|
||||
import com.amap.api.maps.AMap; |
||||
import com.amap.api.maps.CameraUpdateFactory; |
||||
import com.amap.api.maps.model.Marker; |
||||
import com.kanglai.push.ui.fragment.DemoMapFragment; |
||||
|
||||
/** |
||||
*<p> |
||||
* 地图gps方位旋转传感器监听 |
||||
* 参考: |
||||
* https://blog.csdn.net/bob_fly1984/article/details/80717335?spm=1001.2014.3001.5506
|
||||
* https://blog.csdn.net/liu857279611/article/details/50606484?spm=1001.2014.3001.5506
|
||||
* https://github.com/amap-demo/android-location-rotation-effect/blob/master/app/src/main/java/com/amap/location/rotation/MainActivity.java
|
||||
*</p> |
||||
* |
||||
* @Author: entfrm开发团队-王翔 |
||||
* @since: 2022/10/31 |
||||
*/ |
||||
public class MapGpsSensorEventListener implements SensorEventListener { |
||||
|
||||
/** 上次方向旋转传感器时间 */ |
||||
private long lastTime = 0; |
||||
|
||||
/** 传感器时间精度,控制旋转间隔 */ |
||||
private final int TIME_SENSOR = 100; |
||||
|
||||
/** gps位置标记 */ |
||||
private Marker mMarker; |
||||
|
||||
/** 当前活动上下文 */ |
||||
private Context mContext; |
||||
|
||||
/** 传感器管理 */ |
||||
private SensorManager mSensorManager; |
||||
|
||||
/** 传感器 */ |
||||
private Sensor magneticSensor, accelerometerSensor; |
||||
|
||||
/** 磁场传器数据 */ |
||||
private float[] gravity = new float[3]; |
||||
|
||||
/** 加速传感器数据 */ |
||||
private float[] geomagnetic= new float[3]; |
||||
|
||||
/** 手机旋转角度 */ |
||||
private float mAngle; |
||||
|
||||
/** 高德地图组件 */ |
||||
private AMap aMap; |
||||
|
||||
public MapGpsSensorEventListener(Context context) { |
||||
this.mContext = context; |
||||
// 初始化传感器
|
||||
mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); |
||||
// 计算手机方位根据加速度传感器和地磁场传感器计算获取
|
||||
magneticSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); |
||||
accelerometerSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); |
||||
} |
||||
|
||||
public void registerSensorListener() { |
||||
mSensorManager.registerListener(this, magneticSensor, SensorManager.SENSOR_DELAY_NORMAL); |
||||
mSensorManager.registerListener(this, accelerometerSensor, SensorManager.SENSOR_DELAY_NORMAL); |
||||
} |
||||
|
||||
public void unRegisterSensorListener() { |
||||
mSensorManager.unregisterListener(this); |
||||
} |
||||
|
||||
public void setGpsMarker(Marker marker) { |
||||
mMarker = marker; |
||||
} |
||||
|
||||
public void setAMap(AMap aMap) { |
||||
this.aMap = aMap; |
||||
} |
||||
|
||||
@Override |
||||
/** 当有新的传感器事件时(手机方向改变时调用)调用 */ |
||||
public void onSensorChanged(SensorEvent event) { |
||||
if (System.currentTimeMillis() - lastTime < TIME_SENSOR) return; |
||||
if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) { |
||||
geomagnetic = event.values; |
||||
} |
||||
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { |
||||
gravity = event.values; |
||||
} |
||||
if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD || event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { |
||||
// 用来保存手机的旋转弧度
|
||||
float[] values = new float[3]; |
||||
// 被填充的旋转矩阵
|
||||
float[] r = new float[9]; |
||||
// 传入gravity和geomagnetic,通过计算它们得到旋转矩阵R
|
||||
// 而第二个参数倾斜矩阵I是用于将磁场数据转换进实际的重力坐标系中的,一般默认设置为NULL即可
|
||||
SensorManager.getRotationMatrix(r, null, gravity, geomagnetic); |
||||
// 根据旋转矩阵R计算设备的方向,将结果存储在values中
|
||||
// values[0]记录着手机围绕 Z 轴的旋转弧度
|
||||
// values[1]记录着手机围绕 X 轴的旋转弧度
|
||||
// values[2]记录着手机围绕 Y 轴的旋转弧度
|
||||
SensorManager.getOrientation(r, values); |
||||
|
||||
// 地心旋转弧度转为角度
|
||||
float x = (float) Math.toDegrees(values[0]); |
||||
x += getScreenRotationOnPhone(mContext); |
||||
x %= 360.0F; |
||||
if (x > 180.0F) |
||||
x -= 360.0F; |
||||
else if (x < -180.0F) |
||||
x += 360.0F; |
||||
if (Math.abs(mAngle - x) < 3.0f) return; |
||||
mAngle = Float.isNaN(x) ? 0 : x; |
||||
x = (360 - mAngle); |
||||
if (mMarker != null) mMarker.setRotateAngle(x); |
||||
if (aMap != null && !DemoMapFragment.userMoveToLocationMark) aMap.moveCamera(CameraUpdateFactory.changeBearing(360 - mAngle)); |
||||
lastTime = System.currentTimeMillis(); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
/** 当注册传感器的精度发生变化时调用 */ |
||||
public void onAccuracyChanged(Sensor sensor, int accuracy) { |
||||
} |
||||
|
||||
/** |
||||
* 获取当前屏幕旋转角度 |
||||
* @param context 当前活动上下文 |
||||
* @return 0表示是竖屏; 90表示是左横屏; 180表示是反向竖屏; 270表示是右横屏 |
||||
*/ |
||||
public static int getScreenRotationOnPhone(Context context) { |
||||
final Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); |
||||
|
||||
switch (display.getRotation()) { |
||||
case Surface.ROTATION_0: |
||||
return 0; |
||||
|
||||
case Surface.ROTATION_90: |
||||
return 90; |
||||
|
||||
case Surface.ROTATION_180: |
||||
return 180; |
||||
|
||||
case Surface.ROTATION_270: |
||||
return -90; |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
} |
@ -1,55 +0,0 @@
@@ -1,55 +0,0 @@
|
||||
package com.kanglai.push.ui.activity; |
||||
|
||||
import android.content.Intent; |
||||
import android.os.Bundle; |
||||
import android.widget.ListView; |
||||
import android.widget.TextView; |
||||
|
||||
import com.amap.api.services.route.DrivePath; |
||||
import com.dolphin.core.base.BaseActivity; |
||||
import com.dolphin.core.util.AMapCommonUtil; |
||||
import com.kanglai.push.BR; |
||||
import com.kanglai.push.R; |
||||
import com.kanglai.push.databinding.ActivityRoutePlanDetailBinding; |
||||
import com.kanglai.push.ui.adapter.DriveListAdapter; |
||||
import com.kanglai.push.ui.vm.ToolbarViewModel; |
||||
|
||||
/** |
||||
*<p> |
||||
* 驾车路线详情活动 |
||||
*</p> |
||||
* |
||||
* @Author: entfrm开发团队-王翔 |
||||
* @since: 2022/11/11 |
||||
*/ |
||||
public class DriveRouteDetailActivity extends BaseActivity<ActivityRoutePlanDetailBinding, ToolbarViewModel> { |
||||
|
||||
@Override |
||||
public int setContentView(Bundle savedInstanceState) { |
||||
return R.layout.activity_route_plan_detail; |
||||
} |
||||
|
||||
@Override |
||||
public int setVariableId() { |
||||
return BR.viewModel; |
||||
} |
||||
|
||||
@Override |
||||
public void onCreate(Bundle savedInstanceState) { |
||||
super.onCreate(savedInstanceState); |
||||
Intent intent = getIntent(); |
||||
if (intent == null) return; |
||||
DrivePath mDrivePath = intent.getParcelableExtra("drive_path"); |
||||
mViewModel.setTitleText("驾车路线详情"); |
||||
TextView mRouteTime = findViewById(R.id.route_time); |
||||
int distance = (int) mDrivePath.getDistance(); |
||||
int duration = (int) mDrivePath.getDuration(); |
||||
String routeDetail = AMapCommonUtil.getPlanTime(duration) + "(" + AMapCommonUtil.getPlanKilometer(distance) + ")"; |
||||
mRouteTime.setText(routeDetail); |
||||
// 配置列表视图数据
|
||||
ListView mDriveList = findViewById(R.id.route_list); |
||||
DriveListAdapter mDriveListAdapter = new DriveListAdapter(this.getApplicationContext(), mDrivePath.getSteps()); |
||||
mDriveList.setAdapter(mDriveListAdapter); |
||||
} |
||||
|
||||
} |
@ -1,94 +0,0 @@
@@ -1,94 +0,0 @@
|
||||
package com.kanglai.push.ui.activity; |
||||
|
||||
import android.content.Intent; |
||||
import android.os.Bundle; |
||||
|
||||
import com.amap.api.navi.AMapNaviViewOptions; |
||||
import com.amap.api.navi.enums.NaviType; |
||||
import com.amap.api.navi.model.AMapCalcRouteResult; |
||||
import com.amap.api.navi.model.NaviLatLng; |
||||
import com.amap.api.services.core.LatLonPoint; |
||||
import com.dolphin.core.amap.NaviBaseActivity; |
||||
import com.kanglai.push.R; |
||||
import com.kanglai.push.constant.CommonConstant; |
||||
import com.kanglai.push.entity.RoutePlanLatPoint; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
*<p> |
||||
* 驾车导航单路线计算活动 |
||||
*</p> |
||||
* |
||||
* @Author: wangxiang4 |
||||
* @since: 2023/2/8 |
||||
*/ |
||||
public class DriveSingleRouteCalculateActivity extends NaviBaseActivity { |
||||
|
||||
private LatLonPoint mOriginPoint; |
||||
private LatLonPoint mDestinationPoint; |
||||
// 起点
|
||||
private List<NaviLatLng> sList = new ArrayList(); |
||||
// 终点
|
||||
private List<NaviLatLng> eList = new ArrayList(); |
||||
// 途经点
|
||||
private List<NaviLatLng> mWayPointList = new ArrayList(); |
||||
|
||||
@Override |
||||
protected void onCreate(Bundle savedInstanceState) { |
||||
super.onCreate(savedInstanceState); |
||||
setContentView(R.layout.activity_basic_navi); |
||||
// 获取传递参数
|
||||
RoutePlanLatPoint routePlanLatPoint = getIntent().getParcelableExtra(CommonConstant.ROUTE_PLAN_LAT_POINT); |
||||
mOriginPoint = routePlanLatPoint.getOriginPoint(); |
||||
mDestinationPoint = routePlanLatPoint.getDestinationPoint(); |
||||
mAMapNaviView = findViewById(R.id.navi_view); |
||||
mAMapNaviView.onCreate(savedInstanceState); |
||||
mAMapNaviView.setAMapNaviViewListener(this); |
||||
AMapNaviViewOptions options = new AMapNaviViewOptions(); |
||||
options.setTilt(0); |
||||
mAMapNaviView.setViewOptions(options); |
||||
|
||||
setResult(RESULT_CANCELED, new Intent().putExtra(RoutePlanActivity.DEMO_RESULT_LAUNCHER_RESULT_KEY, "驾车导航失败!")); |
||||
} |
||||
|
||||
@Override |
||||
public void onInitNaviSuccess() { |
||||
super.onInitNaviSuccess(); |
||||
sList.add(new NaviLatLng(mOriginPoint.getLatitude(), mOriginPoint.getLongitude())); |
||||
eList.add(new NaviLatLng(mDestinationPoint .getLatitude(), mDestinationPoint.getLongitude())); |
||||
|
||||
/** |
||||
* 方法: int strategy=mAMapNavi.strategyConvert(congestion, avoidhightspeed, cost, hightspeed, multipleroute); 参数: |
||||
* |
||||
* @congestion 躲避拥堵 |
||||
* @avoidhightspeed 不走高速 |
||||
* @cost 避免收费 |
||||
* @hightspeed 高速优先 |
||||
* @multipleroute 多路径 |
||||
* |
||||
* 说明: 以上参数都是boolean类型,其中multipleroute参数表示是否多条路线,如果为true则此策略会算出多条路线。 |
||||
* 注意: 不走高速与高速优先不能同时为true 高速优先与避免收费不能同时为true |
||||
*/ |
||||
int strategy = 0; |
||||
try { |
||||
// 再次强调,最后一个参数为true时代表多路径,否则代表单路径
|
||||
strategy = mAMapNavi.strategyConvert(true, false, false, false, false); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
// mAMapNavi.calculateDriveRoute(sList, eList, mWayPointList, strategy);
|
||||
mAMapNavi.calculateDriveRoute(sList, eList, null, strategy); |
||||
|
||||
// 设置回调结果
|
||||
setResult(RESULT_OK, new Intent().putExtra(RoutePlanActivity.DEMO_RESULT_LAUNCHER_RESULT_KEY, "驾车导航成功!")); |
||||
} |
||||
|
||||
@Override |
||||
public void onCalculateRouteSuccess(AMapCalcRouteResult aMapCalcRouteResult) { |
||||
super.onCalculateRouteSuccess(aMapCalcRouteResult); |
||||
mAMapNavi.startNavi(NaviType.EMULATOR); |
||||
} |
||||
|
||||
} |
@ -1,54 +0,0 @@
@@ -1,54 +0,0 @@
|
||||
package com.kanglai.push.ui.activity; |
||||
|
||||
import android.content.Intent; |
||||
import android.os.Bundle; |
||||
|
||||
import com.amap.api.navi.enums.NaviType; |
||||
import com.amap.api.navi.model.AMapCalcRouteResult; |
||||
import com.amap.api.navi.model.NaviLatLng; |
||||
import com.amap.api.services.core.LatLonPoint; |
||||
import com.dolphin.core.amap.NaviBaseActivity; |
||||
import com.kanglai.push.R; |
||||
import com.kanglai.push.constant.CommonConstant; |
||||
import com.kanglai.push.entity.RoutePlanLatPoint; |
||||
|
||||
/** |
||||
*<p> |
||||
* 骑行导航路线计算活动 |
||||
*</p> |
||||
* |
||||
* @Author: wangxiang4 |
||||
* @since: 2023/2/8 |
||||
*/ |
||||
public class RideRouteCalculateActivity extends NaviBaseActivity { |
||||
|
||||
private LatLonPoint mOriginPoint; |
||||
private LatLonPoint mDestinationPoint; |
||||
|
||||
@Override |
||||
protected void onCreate(Bundle savedInstanceState) { |
||||
super.onCreate(savedInstanceState); |
||||
setContentView(R.layout.activity_basic_navi); |
||||
// 获取传递参数
|
||||
RoutePlanLatPoint routePlanLatPoint = getIntent().getParcelableExtra(CommonConstant.ROUTE_PLAN_LAT_POINT); |
||||
mOriginPoint = routePlanLatPoint.getOriginPoint(); |
||||
mDestinationPoint = routePlanLatPoint.getDestinationPoint(); |
||||
mAMapNaviView = findViewById(R.id.navi_view); |
||||
mAMapNaviView.onCreate(savedInstanceState); |
||||
mAMapNaviView.setAMapNaviViewListener(this); |
||||
setResult(RESULT_CANCELED, new Intent().putExtra(RoutePlanActivity.DEMO_RESULT_LAUNCHER_RESULT_KEY, "骑行导航失败!")); |
||||
} |
||||
|
||||
@Override |
||||
public void onInitNaviSuccess() { |
||||
super.onInitNaviSuccess(); |
||||
mAMapNavi.calculateRideRoute(new NaviLatLng(mOriginPoint.getLatitude(), mOriginPoint.getLongitude()), new NaviLatLng(mDestinationPoint.getLatitude(), mDestinationPoint.getLongitude())); |
||||
setResult(RESULT_OK, new Intent().putExtra(RoutePlanActivity.DEMO_RESULT_LAUNCHER_RESULT_KEY, "骑行导航成功!")); |
||||
} |
||||
|
||||
@Override |
||||
public void onCalculateRouteSuccess(AMapCalcRouteResult aMapCalcRouteResult) { |
||||
super.onCalculateRouteSuccess(aMapCalcRouteResult); |
||||
mAMapNavi.startNavi(NaviType.EMULATOR); |
||||
} |
||||
} |
@ -1,56 +0,0 @@
@@ -1,56 +0,0 @@
|
||||
package com.kanglai.push.ui.activity; |
||||
|
||||
import android.content.Intent; |
||||
import android.os.Bundle; |
||||
import android.widget.ListView; |
||||
import android.widget.TextView; |
||||
|
||||
import com.amap.api.services.route.RidePath; |
||||
import com.dolphin.core.base.BaseActivity; |
||||
import com.dolphin.core.util.AMapCommonUtil; |
||||
import com.kanglai.push.BR; |
||||
import com.kanglai.push.R; |
||||
import com.kanglai.push.databinding.ActivityRoutePlanDetailBinding; |
||||
import com.kanglai.push.ui.adapter.RideListAdapter; |
||||
import com.kanglai.push.ui.vm.ToolbarViewModel; |
||||
|
||||
/** |
||||
*<p> |
||||
* 骑行路线详情活动 |
||||
*</p> |
||||
* |
||||
* @Author: entfrm开发团队-王翔 |
||||
* @since: 2022/11/11 |
||||
*/ |
||||
public class RideRouteDetailActivity extends BaseActivity<ActivityRoutePlanDetailBinding, ToolbarViewModel> { |
||||
|
||||
@Override |
||||
public int setContentView(Bundle savedInstanceState) { |
||||
return R.layout.activity_route_plan_detail; |
||||
} |
||||
|
||||
@Override |
||||
public int setVariableId() { |
||||
return BR.viewModel; |
||||
} |
||||
|
||||
@Override |
||||
public void onCreate(Bundle savedInstanceState) { |
||||
super.onCreate(savedInstanceState); |
||||
Intent intent = getIntent(); |
||||
if (intent == null) return; |
||||
RidePath mRidePath = intent.getParcelableExtra("ride_path"); |
||||
mViewModel.setTitleText("骑行路线详情"); |
||||
TextView mRouteTime = findViewById(R.id.route_time); |
||||
int distance = (int) mRidePath.getDistance(); |
||||
int duration = (int) mRidePath.getDuration(); |
||||
String routeDetail = AMapCommonUtil.getPlanTime(duration) + "(" + AMapCommonUtil.getPlanKilometer(distance) + ")"; |
||||
mRouteTime.setText(routeDetail); |
||||
// 配置列表视图数据
|
||||
ListView mDriveList = findViewById(R.id.route_list); |
||||
RideListAdapter mRideListAdapter = new RideListAdapter(this.getApplicationContext(), mRidePath.getSteps()); |
||||
mDriveList.setAdapter(mRideListAdapter); |
||||
} |
||||
|
||||
|
||||
} |
@ -1,345 +0,0 @@
@@ -1,345 +0,0 @@
|
||||
package com.kanglai.push.ui.activity; |
||||
|
||||
import android.content.Context; |
||||
import android.content.Intent; |
||||
import android.os.Bundle; |
||||
import android.view.View; |
||||
import android.widget.Button; |
||||
import android.widget.ImageView; |
||||
import android.widget.LinearLayout; |
||||
import android.widget.RelativeLayout; |
||||
import android.widget.TextView; |
||||
|
||||
import androidx.activity.result.ActivityResultLauncher; |
||||
import androidx.activity.result.contract.ActivityResultContract; |
||||
import androidx.annotation.NonNull; |
||||
import androidx.annotation.Nullable; |
||||
|
||||
import com.afollestad.materialdialogs.MaterialDialog; |
||||
import com.amap.api.maps.AMap; |
||||
import com.amap.api.maps.CameraUpdateFactory; |
||||
import com.amap.api.maps.MapView; |
||||
import com.amap.api.maps.model.CameraPosition; |
||||
import com.amap.api.maps.model.LatLng; |
||||
import com.amap.api.services.core.AMapException; |
||||
import com.amap.api.services.core.LatLonPoint; |
||||
import com.amap.api.services.route.BusRouteResult; |
||||
import com.amap.api.services.route.DrivePath; |
||||
import com.amap.api.services.route.DriveRouteResult; |
||||
import com.amap.api.services.route.RidePath; |
||||
import com.amap.api.services.route.RideRouteResult; |
||||
import com.amap.api.services.route.RouteSearch; |
||||
import com.amap.api.services.route.RouteSearch.DriveRouteQuery; |
||||
import com.amap.api.services.route.RouteSearch.OnRouteSearchListener; |
||||
import com.amap.api.services.route.RouteSearch.RideRouteQuery; |
||||
import com.amap.api.services.route.WalkRouteResult; |
||||
import com.dolphin.core.amap.overlay.DrivingRouteOverlay; |
||||
import com.dolphin.core.amap.overlay.RideRouteOverlay; |
||||
import com.dolphin.core.base.BaseActivity; |
||||
import com.dolphin.core.util.AMapCommonUtil; |
||||
import com.dolphin.core.util.ToastUtil; |
||||
import com.kanglai.push.BR; |
||||
import com.kanglai.push.R; |
||||
import com.kanglai.push.constant.CommonConstant; |
||||
import com.kanglai.push.databinding.ActivityRoutePlanBinding; |
||||
import com.kanglai.push.entity.RoutePlanLatPoint; |
||||
import com.kanglai.push.ui.vm.RoutePlanViewModel; |
||||
|
||||
/** |
||||
*<p> |
||||
* 导航路线规划 |
||||
*</p> |
||||
* |
||||
* @Author: entfrm开发团队-王翔 |
||||
* @since: 2022/11/9 |
||||
*/ |
||||
public class RoutePlanActivity extends BaseActivity<ActivityRoutePlanBinding, RoutePlanViewModel> implements OnRouteSearchListener { |
||||
|
||||
|
||||
private AMap aMap; |
||||
private MapView mapView; |
||||
private RouteSearch mRouteSearch; |
||||
private final int ROUTE_TYPE_DRIVE = 1; |
||||
private final int ROUTE_TYPE_RIDE = 2; |
||||
|
||||
private Button mBtnStartNavi; |
||||
private RelativeLayout mRouteDriveLayout; |
||||
private TextView mRouteTime; |
||||
private ImageView mDrive; |
||||
private ImageView mRide; |
||||
private LinearLayout mRouteDetail; |
||||
private LatLonPoint mOriginPoint; |
||||
private LatLonPoint mDestinationPoint; |
||||
private MaterialDialog mMaterialDialog; |
||||
|
||||
private ActivityResultLauncher<RoutePlanLatPoint> driveNaviLauncherResult; |
||||
private ActivityResultLauncher<RoutePlanLatPoint> rideNaviLauncherResult; |
||||
|
||||
public static final String DEMO_RESULT_LAUNCHER_RESULT_KEY = "DEMO_RESULT_LAUNCHER_RESULT_KEY"; |
||||
interface DefaultConfig { |
||||
|
||||
// 默认中心点长沙望城区域砂之船奥莱
|
||||
double mapCentreLat = 28.288623; |
||||
double mapCentreLng = 112.919043; |
||||
// 地图缩放级别
|
||||
float zoom = 17f; |
||||
// 3D地图倾斜度
|
||||
float tilt = 55f; |
||||
// 正视前方可视区域方向
|
||||
float bearing = 300; |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public int setContentView(Bundle savedInstanceState) { |
||||
return R.layout.activity_route_plan; |
||||
} |
||||
|
||||
@Override |
||||
public int setVariableId() { |
||||
return BR.viewModel; |
||||
} |
||||
|
||||
public RoutePlanActivity getActivityContext(){ |
||||
return this; |
||||
} |
||||
|
||||
@Override |
||||
protected void onCreate(Bundle bundle) { |
||||
super.onCreate(bundle); |
||||
// 获取传递参数
|
||||
RoutePlanLatPoint routePlanLatPoint = getIntent().getParcelableExtra(CommonConstant.ROUTE_PLAN_LAT_POINT); |
||||
mOriginPoint = routePlanLatPoint.getOriginPoint(); |
||||
mDestinationPoint = routePlanLatPoint.getDestinationPoint(); |
||||
// 初始化高德地图
|
||||
mapView = findViewById(R.id.route_map); |
||||
mapView.onCreate(bundle); |
||||
aMap = mapView.getMap(); |
||||
aMap.getUiSettings().setLogoBottomMargin(-100); |
||||
aMap.getUiSettings().setZoomControlsEnabled(false); |
||||
try { |
||||
mRouteSearch = new RouteSearch(this); |
||||
mRouteSearch.setRouteSearchListener(this); |
||||
} catch (AMapException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
LatLng latLng = new LatLng(DefaultConfig.mapCentreLat, DefaultConfig.mapCentreLng); |
||||
// 首次定位移动到地图中心点并修改一些默认属性
|
||||
aMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(latLng, DefaultConfig.zoom, DefaultConfig.tilt, DefaultConfig.bearing))); |
||||
mBtnStartNavi = findViewById(R.id.btn_start_navi); |
||||
mRouteDriveLayout = findViewById(R.id.layout_route_drive); |
||||
mRouteTime = findViewById(R.id.route_time); |
||||
mRouteDetail = findViewById(R.id.route_detail); |
||||
mDrive = findViewById(R.id.route_drive); |
||||
mRide = findViewById(R.id.route_ride); |
||||
mRouteDriveLayout.performClick(); |
||||
|
||||
// 注册驾车导航活动结果
|
||||
driveNaviLauncherResult = registerForActivityResult(new ActivityResultContract<RoutePlanLatPoint, String>() { |
||||
@Override |
||||
public String parseResult(int resultCode, @Nullable Intent intent) { |
||||
if (intent == null) { |
||||
return null; |
||||
} |
||||
if (resultCode == RESULT_OK) { |
||||
return intent.getStringExtra(DEMO_RESULT_LAUNCHER_RESULT_KEY); |
||||
} else { |
||||
return intent.getStringExtra(DEMO_RESULT_LAUNCHER_RESULT_KEY) + "ð"; |
||||
} |
||||
} |
||||
@Override |
||||
public Intent createIntent(@NonNull Context context, RoutePlanLatPoint routePlanLatPoint) { |
||||
Intent intent = new Intent(getActivityContext(), DriveSingleRouteCalculateActivity.class); |
||||
intent.putExtra(CommonConstant.ROUTE_PLAN_LAT_POINT, routePlanLatPoint); |
||||
return intent; |
||||
} |
||||
}, result -> ToastUtil.show(result)); |
||||
|
||||
// 注册骑行导航活动结果
|
||||
rideNaviLauncherResult = registerForActivityResult(new ActivityResultContract<RoutePlanLatPoint, String>() { |
||||
@Override |
||||
public String parseResult(int resultCode, @Nullable Intent intent) { |
||||
if (intent == null) { |
||||
return null; |
||||
} |
||||
if (resultCode == RESULT_OK) { |
||||
return intent.getStringExtra(DEMO_RESULT_LAUNCHER_RESULT_KEY); |
||||
} else { |
||||
return intent.getStringExtra(DEMO_RESULT_LAUNCHER_RESULT_KEY) + "ð"; |
||||
} |
||||
} |
||||
@Override |
||||
public Intent createIntent(@NonNull Context context, RoutePlanLatPoint routePlanLatPoint) { |
||||
Intent intent = new Intent(getActivityContext(), RideRouteCalculateActivity.class); |
||||
intent.putExtra(CommonConstant.ROUTE_PLAN_LAT_POINT, routePlanLatPoint); |
||||
return intent; |
||||
} |
||||
}, result -> ToastUtil.show(result)); |
||||
} |
||||
|
||||
public void onDriveClick(View view) { |
||||
searchRouteResult(ROUTE_TYPE_DRIVE, RouteSearch.DRIVING_SINGLE_DEFAULT); |
||||
mDrive.setImageResource(R.drawable.icon_route_drive_select); |
||||
mRide.setImageResource(R.drawable.icon_route_ride_normal); |
||||
} |
||||
|
||||
public void onRideClick(View view) { |
||||
searchRouteResult(ROUTE_TYPE_RIDE, RouteSearch.DRIVING_SINGLE_DEFAULT); |
||||
mDrive.setImageResource(R.drawable.icon_route_drive_normal); |
||||
mRide.setImageResource(R.drawable.icon_route_ride_select); |
||||
} |
||||
|
||||
public void searchRouteResult(int routeType, int mode) { |
||||
if (mOriginPoint == null) { |
||||
ToastUtil.show("起点未设置"); |
||||
return; |
||||
} |
||||
if (mDestinationPoint == null) { |
||||
ToastUtil.show("终点未设置"); |
||||
return; |
||||
} |
||||
showProgressDialog(); |
||||
final RouteSearch.FromAndTo fromAndTo = new RouteSearch.FromAndTo(mOriginPoint, mDestinationPoint); |
||||
if (routeType == ROUTE_TYPE_DRIVE) { |
||||
DriveRouteQuery query = new DriveRouteQuery(fromAndTo, mode, null, null, ""); |
||||
mRouteSearch.calculateDriveRouteAsyn(query); |
||||
} else if (routeType == ROUTE_TYPE_RIDE) { |
||||
RideRouteQuery query = new RideRouteQuery(fromAndTo, mode); |
||||
mRouteSearch.calculateRideRouteAsyn(query); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void onBusRouteSearched(BusRouteResult result, int errorCode) {} |
||||
|
||||
@Override |
||||
public void onDriveRouteSearched(DriveRouteResult result, int errorCode) { |
||||
closeProgressDialog(); |
||||
aMap.clear(); |
||||
if (errorCode != AMapException.CODE_AMAP_SUCCESS) { |
||||
ToastUtil.showAmapError(errorCode); |
||||
return; |
||||
} |
||||
if (result == null && result.getPaths() == null) { |
||||
ToastUtil.show("对不起,没有搜索到相关数据!"); |
||||
return; |
||||
} |
||||
if (result.getPaths().size() > 0) { |
||||
final DrivePath drivePath = result.getPaths().get(0); |
||||
if (drivePath == null) return; |
||||
DrivingRouteOverlay drivingRouteOverlay = new DrivingRouteOverlay( |
||||
this, |
||||
aMap, |
||||
drivePath, |
||||
result.getStartPos(), |
||||
result.getTargetPos(), |
||||
null |
||||
); |
||||
drivingRouteOverlay.removeFromMap(); |
||||
drivingRouteOverlay.drawDrivingRoute(); |
||||
drivingRouteOverlay.zoomToRouteBounds(); |
||||
|
||||
int distance = (int) drivePath.getDistance(); |
||||
int duration = (int) drivePath.getDuration(); |
||||
|
||||
String routeDetail = AMapCommonUtil.getPlanTime(duration) + "(" + AMapCommonUtil.getPlanKilometer(distance) + ")"; |
||||
mRouteTime.setText(routeDetail); |
||||
mRouteDetail.setOnClickListener(view -> { |
||||
Intent intent = new Intent(this, DriveRouteDetailActivity.class); |
||||
intent.putExtra("drive_path", drivePath); |
||||
startActivity(intent); |
||||
}); |
||||
mBtnStartNavi.setOnClickListener(view -> |
||||
driveNaviLauncherResult.launch(new RoutePlanLatPoint().setOriginPoint(mOriginPoint).setDestinationPoint(mDestinationPoint))); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void onRideRouteSearched(RideRouteResult result, int errorCode) { |
||||
closeProgressDialog(); |
||||
aMap.clear(); |
||||
if (errorCode != AMapException.CODE_AMAP_SUCCESS) { |
||||
ToastUtil.showAmapError(errorCode); |
||||
return; |
||||
} |
||||
if (result == null && result.getPaths() == null) { |
||||
ToastUtil.show("对不起,没有搜索到相关数据!"); |
||||
return; |
||||
} |
||||
if (result.getPaths().size() > 0) { |
||||
final RidePath ridePath = result.getPaths().get(0); |
||||
if (ridePath == null) return; |
||||
RideRouteOverlay rideRouteOverlay = new RideRouteOverlay( |
||||
this, |
||||
aMap, |
||||
ridePath, |
||||
result.getStartPos(), |
||||
result.getTargetPos() |
||||
); |
||||
rideRouteOverlay.removeFromMap(); |
||||
rideRouteOverlay.drawDrivingRoute(); |
||||
rideRouteOverlay.zoomToRouteBounds(); |
||||
|
||||
int distance = (int) ridePath.getDistance(); |
||||
int duration = (int) ridePath.getDuration(); |
||||
|
||||
String routeDetail = AMapCommonUtil.getPlanTime(duration) + "(" + AMapCommonUtil.getPlanKilometer(distance) + ")"; |
||||
mRouteTime.setText(routeDetail); |
||||
mRouteDetail.setOnClickListener(view -> { |
||||
Intent intent = new Intent(this, RideRouteDetailActivity.class); |
||||
intent.putExtra("ride_path", ridePath); |
||||
startActivity(intent); |
||||
}); |
||||
mBtnStartNavi.setOnClickListener(view -> |
||||
rideNaviLauncherResult.launch(new RoutePlanLatPoint().setOriginPoint(mOriginPoint).setDestinationPoint(mDestinationPoint))); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void onWalkRouteSearched(WalkRouteResult result, int errorCode) {} |
||||
|
||||
@Override |
||||
protected void onResume() { |
||||
super.onResume(); |
||||
mapView.onResume(); |
||||
} |
||||
|
||||
@Override |
||||
protected void onPause() { |
||||
super.onPause(); |
||||
mapView.onPause(); |
||||
} |
||||
|
||||
@Override |
||||
protected void onSaveInstanceState(Bundle outState) { |
||||
super.onSaveInstanceState(outState); |
||||
mapView.onSaveInstanceState(outState); |
||||
} |
||||
|
||||
@Override |
||||
protected void onDestroy() { |
||||
super.onDestroy(); |
||||
mapView.onDestroy(); |
||||
} |
||||
|
||||
private void showProgressDialog() { |
||||
if (mMaterialDialog == null) { |
||||
mMaterialDialog= new MaterialDialog.Builder(this) |
||||
.progress(true, 0) |
||||
.progressIndeterminateStyle(true) |
||||
.canceledOnTouchOutside(false) |
||||
.backgroundColorRes(R.color.white) |
||||
.keyListener((dialog, keyCode, event) -> false).build(); |
||||
} |
||||
mMaterialDialog = mMaterialDialog.getBuilder().title("正在搜索").build(); |
||||
mMaterialDialog.show(); |
||||
} |
||||
|
||||
private void closeProgressDialog() { |
||||
if (mMaterialDialog != null) { |
||||
mMaterialDialog.dismiss(); |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
@ -1,105 +0,0 @@
@@ -1,105 +0,0 @@
|
||||
package com.kanglai.push.ui.adapter; |
||||
|
||||
import android.content.Context; |
||||
import android.view.View; |
||||
import android.view.ViewGroup; |
||||
import android.widget.BaseAdapter; |
||||
import android.widget.ImageView; |
||||
import android.widget.TextView; |
||||
|
||||
import com.amap.api.services.route.DriveStep; |
||||
import com.kanglai.push.R; |
||||
import com.dolphin.core.util.AMapCommonUtil; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
*<p> |
||||
* 驾车表格数据适配器 |
||||
*</p> |
||||
* |
||||
* @Author: entfrm开发团队-王翔 |
||||
* @since: 2022/11/11 |
||||
*/ |
||||
public class DriveListAdapter extends BaseAdapter { |
||||
|
||||
private Context mContext; |
||||
private List<DriveStep> mItemList = new ArrayList(); |
||||
|
||||
public DriveListAdapter(Context context, List<DriveStep> list) { |
||||
this.mContext = context; |
||||
mItemList.add(new DriveStep()); |
||||
for (DriveStep driveStep : list) { |
||||
mItemList.add(driveStep); |
||||
} |
||||
mItemList.add(new DriveStep()); |
||||
} |
||||
|
||||
@Override |
||||
public int getCount() { |
||||
return mItemList.size(); |
||||
} |
||||
|
||||
@Override |
||||
public Object getItem(int position) { |
||||
return mItemList.get(position); |
||||
} |
||||
|
||||
@Override |
||||
public long getItemId(int position) { |
||||
return position; |
||||
} |
||||
|
||||
@Override |
||||
public View getView(int position, View convertView, ViewGroup parent) { |
||||
ViewHolder holder; |
||||
if (convertView == null) { |
||||
holder = new ViewHolder(); |
||||
convertView = View.inflate(mContext, R.layout.item_route_plan, null); |
||||
holder.driveDirIcon = convertView.findViewById(R.id.route_dir_icon); |
||||
holder.driveLineName = convertView.findViewById(R.id.route_line_name); |
||||
holder.driveDirUp = convertView.findViewById(R.id.route_dir_icon_up); |
||||
holder.driveDirDown = convertView.findViewById(R.id.route_dir_icon_down); |
||||
holder.splitLine = convertView.findViewById(R.id.route_split_line); |
||||
convertView.setTag(holder); |
||||
} else { |
||||
holder = (ViewHolder) convertView.getTag(); |
||||
} |
||||
final DriveStep item = mItemList.get(position); |
||||
if (position == 0) { |
||||
holder.driveDirIcon.setImageResource(R.drawable.icon_orgin); |
||||
holder.driveLineName.setText("出发"); |
||||
holder.driveDirUp.setVisibility(View.GONE); |
||||
holder.driveDirDown.setVisibility(View.VISIBLE); |
||||
holder.splitLine.setVisibility(View.GONE); |
||||
return convertView; |
||||
} else if (position == mItemList.size() - 1) { |
||||
holder.driveDirIcon.setImageResource(R.drawable.icon_destination); |
||||
holder.driveLineName.setText("到达终点"); |
||||
holder.driveDirUp.setVisibility(View.VISIBLE); |
||||
holder.driveDirDown.setVisibility(View.GONE); |
||||
holder.splitLine.setVisibility(View.VISIBLE); |
||||
return convertView; |
||||
} else { |
||||
String actionName = item.getAction(); |
||||
int resID = AMapCommonUtil.getDrivingActionResource(actionName); |
||||
holder.driveDirIcon.setImageResource(resID); |
||||
holder.driveLineName.setText(item.getInstruction()); |
||||
holder.driveDirUp.setVisibility(View.VISIBLE); |
||||
holder.driveDirDown.setVisibility(View.VISIBLE); |
||||
holder.splitLine.setVisibility(View.VISIBLE); |
||||
return convertView; |
||||
} |
||||
|
||||
} |
||||
|
||||
private class ViewHolder { |
||||
TextView driveLineName; |
||||
ImageView driveDirIcon; |
||||
ImageView driveDirUp; |
||||
ImageView driveDirDown; |
||||
ImageView splitLine; |
||||
} |
||||
|
||||
} |
@ -1,103 +0,0 @@
@@ -1,103 +0,0 @@
|
||||
package com.kanglai.push.ui.adapter; |
||||
|
||||
import android.content.Context; |
||||
import android.view.View; |
||||
import android.view.ViewGroup; |
||||
import android.widget.BaseAdapter; |
||||
import android.widget.ImageView; |
||||
import android.widget.TextView; |
||||
|
||||
import com.amap.api.services.route.RideStep; |
||||
import com.kanglai.push.R; |
||||
import com.dolphin.core.util.AMapCommonUtil; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
*<p> |
||||
* 骑行表格数据适配器 |
||||
*</p> |
||||
* |
||||
* @Author: entfrm开发团队-王翔 |
||||
* @since: 2022/11/11 |
||||
*/ |
||||
public class RideListAdapter extends BaseAdapter { |
||||
|
||||
private Context mContext; |
||||
private List<RideStep> mItemList = new ArrayList(); |
||||
|
||||
public RideListAdapter(Context context, List<RideStep> list) { |
||||
this.mContext = context; |
||||
mItemList.add(new RideStep()); |
||||
for (RideStep rideStep : list) { |
||||
mItemList.add(rideStep); |
||||
} |
||||
mItemList.add(new RideStep()); |
||||
} |
||||
|
||||
@Override |
||||
public int getCount() { |
||||
return mItemList.size(); |
||||
} |
||||
|
||||
@Override |
||||
public Object getItem(int position) { |
||||
return mItemList.get(position); |
||||
} |
||||
|
||||
@Override |
||||
public long getItemId(int position) { |
||||
return position; |
||||
} |
||||
|
||||
@Override |
||||
public View getView(int position, View convertView, ViewGroup parent) { |
||||
ViewHolder holder; |
||||
if (convertView == null) { |
||||
holder = new ViewHolder(); |
||||
convertView = View.inflate(mContext, R.layout.item_route_plan, null); |
||||
holder.lineName = convertView.findViewById(R.id.route_line_name); |
||||
holder.dirIcon = convertView.findViewById(R.id.route_dir_icon); |
||||
holder.dirUp = convertView.findViewById(R.id.route_dir_icon_up); |
||||
holder.dirDown = convertView.findViewById(R.id.route_dir_icon_down); |
||||
holder.splitLine = convertView.findViewById(R.id.route_split_line); |
||||
convertView.setTag(holder); |
||||
} else { |
||||
holder = (ViewHolder) convertView.getTag(); |
||||
} |
||||
final RideStep item = mItemList.get(position); |
||||
if (position == 0) { |
||||
holder.dirIcon.setImageResource(R.drawable.icon_orgin); |
||||
holder.lineName.setText("出发"); |
||||
holder.dirUp.setVisibility(View.INVISIBLE); |
||||
holder.dirDown.setVisibility(View.VISIBLE); |
||||
holder.splitLine.setVisibility(View.INVISIBLE); |
||||
return convertView; |
||||
} else if (position == mItemList.size() - 1) { |
||||
holder.dirIcon.setImageResource(R.drawable.icon_destination); |
||||
holder.lineName.setText("到达终点"); |
||||
holder.dirUp.setVisibility(View.VISIBLE); |
||||
holder.dirDown.setVisibility(View.INVISIBLE); |
||||
return convertView; |
||||
} else { |
||||
holder.splitLine.setVisibility(View.VISIBLE); |
||||
holder.dirUp.setVisibility(View.VISIBLE); |
||||
holder.dirDown.setVisibility(View.VISIBLE); |
||||
String actionName = item.getAction(); |
||||
int resID = AMapCommonUtil.getWalkActionResource(actionName); |
||||
holder.dirIcon.setImageResource(resID); |
||||
holder.lineName.setText(item.getInstruction()); |
||||
return convertView; |
||||
} |
||||
} |
||||
|
||||
private class ViewHolder { |
||||
TextView lineName; |
||||
ImageView dirIcon; |
||||
ImageView dirUp; |
||||
ImageView dirDown; |
||||
ImageView splitLine; |
||||
} |
||||
|
||||
} |
@ -1,360 +0,0 @@
@@ -1,360 +0,0 @@
|
||||
package com.kanglai.push.ui.fragment; |
||||
|
||||
import android.os.Bundle; |
||||
import android.view.LayoutInflater; |
||||
import android.view.MotionEvent; |
||||
import android.view.View; |
||||
import android.view.ViewGroup; |
||||
import android.view.animation.LinearInterpolator; |
||||
|
||||
import androidx.annotation.NonNull; |
||||
import androidx.annotation.Nullable; |
||||
|
||||
import com.amap.api.location.AMapLocationClient; |
||||
import com.amap.api.location.AMapLocationListener; |
||||
import com.amap.api.location.AMapLocationQualityReport; |
||||
import com.amap.api.maps.AMap; |
||||
import com.amap.api.maps.CameraUpdateFactory; |
||||
import com.amap.api.maps.LocationSource; |
||||
import com.amap.api.maps.MapView; |
||||
import com.amap.api.maps.model.BitmapDescriptorFactory; |
||||
import com.amap.api.maps.model.CameraPosition; |
||||
import com.amap.api.maps.model.LatLng; |
||||
import com.amap.api.maps.model.Marker; |
||||
import com.amap.api.maps.model.MarkerOptions; |
||||
import com.amap.api.maps.model.animation.Animation; |
||||
import com.amap.api.maps.model.animation.ScaleAnimation; |
||||
import com.amap.api.services.core.AMapException; |
||||
import com.amap.api.services.core.LatLonPoint; |
||||
import com.amap.api.services.route.BusRouteResult; |
||||
import com.amap.api.services.route.DrivePath; |
||||
import com.amap.api.services.route.DriveRouteResult; |
||||
import com.amap.api.services.route.RideRouteResult; |
||||
import com.amap.api.services.route.RouteSearch; |
||||
import com.amap.api.services.route.WalkRouteResult; |
||||
import com.blankj.utilcode.util.CollectionUtils; |
||||
import com.blankj.utilcode.util.LogUtils; |
||||
import com.blankj.utilcode.util.ObjectUtils; |
||||
import com.dolphin.core.amap.LocationRequest; |
||||
import com.dolphin.core.amap.overlay.DrivingRouteOverlay; |
||||
import com.dolphin.core.base.BaseFragment; |
||||
import com.dolphin.core.util.PermissionUtil; |
||||
import com.dolphin.core.util.ToastUtil; |
||||
import com.kanglai.push.BR; |
||||
import com.kanglai.push.R; |
||||
import com.kanglai.push.databinding.FragmentMapBinding; |
||||
import com.kanglai.push.listener.MapGpsSensorEventListener; |
||||
import com.kanglai.push.ui.vm.MapViewModel; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
*<p> |
||||
* 高德地图 |
||||
*</p> |
||||
* |
||||
* @Author: entfrm开发团队-王翔 |
||||
* @Date: 2022/7/15 |
||||
*/ |
||||
public class DemoMapFragment extends BaseFragment<FragmentMapBinding, MapViewModel> implements LocationSource, AMap.OnMapTouchListener, RouteSearch.OnRouteSearchListener { |
||||
|
||||
/** 高德地图组件 */ |
||||
private AMap aMap; |
||||
|
||||
/** 高德地图ui视图 */ |
||||
private MapView mapView; |
||||
|
||||
/** LBS定位请求 */ |
||||
private LocationRequest locationRequest; |
||||
|
||||
/** 当前位置gps标记 */ |
||||
private Marker locationMarker; |
||||
|
||||
/** 用户手动移动地图标记 */ |
||||
public static boolean userMoveToLocationMark = true; |
||||
|
||||
/** 地图旋转gps方向传感监听 */ |
||||
private MapGpsSensorEventListener mapGpsSensorEventListener; |
||||
|
||||
/** 路线搜索 */ |
||||
private RouteSearch mRouteSearch; |
||||
|
||||
/** 中间途径点 */ |
||||
private List<LatLonPoint> throughPoints; |
||||
|
||||
/** 默认地图配置 */ |
||||
interface DefaultConfig { |
||||
|
||||
// 默认中心点长沙望城区域砂之船奥莱
|
||||
double mapCentreLat = 28.288623; |
||||
double mapCentreLng = 112.919043; |
||||
// 地图缩放级别
|
||||
float zoom = 17f; |
||||
// 3D地图倾斜度
|
||||
float tilt = 55f; |
||||
// 正视前方可视区域方向
|
||||
float bearing = 300; |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public int setContentView(LayoutInflater inflater, @Nullable ViewGroup parentContainer, @Nullable Bundle savedInstanceState) { |
||||
return R.layout.fragment_map; |
||||
} |
||||
|
||||
@Override |
||||
public int setVariableId() { |
||||
return BR.viewModel; |
||||
} |
||||
|
||||
@Override |
||||
public void onCreate(Bundle savedInstanceState) { |
||||
super.onCreate(savedInstanceState); |
||||
locationRequest = new LocationRequest(getActivity().getClass()); |
||||
mapGpsSensorEventListener = new MapGpsSensorEventListener(getActivity()); |
||||
locationRequest.setLocationListen(locationListener); |
||||
singleAMapLocationClient(); |
||||
} |
||||
|
||||
AMapLocationListener locationListener = location -> { |
||||
if (null != location && aMap != null && location.getErrorCode() == 0) { |
||||
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude()); |
||||
if (locationMarker == null) { |
||||
locationMarker = aMap.addMarker(new MarkerOptions().position(latLng) |
||||
.icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_map_gps)) |
||||
.anchor(0.5f, 0.5f)); |
||||
mapGpsSensorEventListener.setGpsMarker(locationMarker); |
||||
mapGpsSensorEventListener.setAMap(aMap); |
||||
} else if (userMoveToLocationMark) { |
||||
locationMarker.setPosition(latLng); |
||||
} else { |
||||
locationMarker.setPosition(latLng); |
||||
// 地图画布动画移动的时间,最好不要比定位间隔长,如果定位间隔2000ms动画移动时间最好小于2000ms,可以使用1000ms
|
||||
// 如果超过了,需要在myCancelCallback中进行处理被打断的情况
|
||||
aMap.animateCamera(CameraUpdateFactory.changeLatLng(latLng), 1000, new AMap.CancelableCallback() { |
||||
@Override |
||||
public void onFinish() { |
||||
locationMarker.setPosition(latLng); |
||||
} |
||||
@Override |
||||
public void onCancel() { |
||||
locationMarker.setPosition(latLng); |
||||
} |
||||
}); |
||||
} |
||||
} else { |
||||
ToastUtil.showAmapError(location.getErrorCode()); |
||||
} |
||||
}; |
||||
|
||||
@Override |
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { |
||||
super.onViewCreated(view, savedInstanceState); |
||||
mapView = getView().findViewById(R.id.amap); |
||||
mapView.onCreate(savedInstanceState); |
||||
aMap = mapView.getMap(); |
||||
aMap.getUiSettings().setLogoBottomMargin(-100); |
||||
// 设置高德地图ui交互
|
||||
aMap.getUiSettings().setMyLocationButtonEnabled(true); |
||||
// 打开定位图层
|
||||
aMap.setMyLocationEnabled(true); |
||||
// 自定义地图模式
|
||||
aMap.setLocationSource(this); |
||||
aMap.setOnMapTouchListener(this); |
||||
// 设置地图默认中心点
|
||||
LatLng latLng = new LatLng(DefaultConfig.mapCentreLat, DefaultConfig.mapCentreLng); |
||||
// 首次定位移动到地图中心点并修改一些默认属性
|
||||
aMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(latLng, DefaultConfig.zoom, DefaultConfig.tilt, DefaultConfig.bearing))); |
||||
mapGpsSensorEventListener.registerSensorListener(); |
||||
locationRequest.start(); |
||||
try { |
||||
mRouteSearch = new RouteSearch(getActivity()); |
||||
mRouteSearch.setRouteSearchListener(this); |
||||
} catch (AMapException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
|
||||
class PointData { |
||||
String id; |
||||
String label; |
||||
Double mapLng; |
||||
Double mapLat; |
||||
public PointData(String id, String label, Double mapLng, Double mapLat) { |
||||
this.id = id; |
||||
this.label = label; |
||||
this.mapLng = mapLng; |
||||
this.mapLat = mapLat; |
||||
} |
||||
} |
||||
|
||||
List<PointData> carPointData = CollectionUtils.newArrayList( |
||||
new PointData("001","小黄车", 112.918119, 28.282891), |
||||
new PointData("002","小绿车", 112.918919, 28.282991), |
||||
new PointData("003","小红车", 112.918019, 28.283991) |
||||
); |
||||
|
||||
List<PointData> gasStationPointData = CollectionUtils.newArrayList( |
||||
new PointData("001","地沟油加油站", 112.919043, 28.288623), |
||||
new PointData("002","一路平安加油站", 112.919165, 28.289924), |
||||
new PointData("003","一把火加油站", 112.919965, 28.289924) |
||||
); |
||||
|
||||
@Override |
||||
public void onStart() { |
||||
super.onStart(); |
||||
try { |
||||
carPointData.forEach(item -> { |
||||
if(ObjectUtils.isNotEmpty(item.mapLat) && ObjectUtils.isNotEmpty(item.mapLng)){ |
||||
setMapDataPointMarker(new LatLng(item.mapLat, item.mapLng), item.label, 0); |
||||
} |
||||
}); |
||||
gasStationPointData.forEach(item -> { |
||||
if(ObjectUtils.isNotEmpty(item.mapLat) && ObjectUtils.isNotEmpty(item.mapLng)){ |
||||
setMapDataPointMarker(new LatLng(item.mapLat, item.mapLng), item.label, 1); |
||||
} |
||||
}); |
||||
throughPoints = CollectionUtils.newArrayList(new LatLonPoint(carPointData.get(1).mapLat, carPointData.get(1).mapLng)); |
||||
// 渲染导航路线
|
||||
final RouteSearch.FromAndTo fromAndTo = new RouteSearch.FromAndTo(new LatLonPoint(carPointData.get(0).mapLat, carPointData.get(0).mapLng), new LatLonPoint(gasStationPointData.get(1).mapLat, gasStationPointData.get(1).mapLng)); |
||||
// 第一个参数表示路径规划的起点和终点,第二个参数表示驾车模式,第三个参数表示途经点,第四个参数表示避让区域,第五个参数表示避让道路
|
||||
RouteSearch.DriveRouteQuery query = new RouteSearch.DriveRouteQuery(fromAndTo, RouteSearch.DRIVING_SINGLE_DEFAULT, throughPoints, null, ""); |
||||
mRouteSearch.calculateDriveRouteAsyn(query); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
|
||||
public void setMapDataPointMarker(LatLng latlng, String title, Integer type) { |
||||
int resourcesId; |
||||
switch (type) { |
||||
case 0: |
||||
resourcesId = R.drawable.icon_car; |
||||
break; |
||||
case 1: |
||||
resourcesId = R.drawable.icon_gasstation; |
||||
break; |
||||
default: |
||||
throw new IllegalStateException("Unexpected value: " + type); |
||||
} |
||||
MarkerOptions markerOptions = new MarkerOptions() |
||||
.title(title) |
||||
.icon(BitmapDescriptorFactory.fromResource(resourcesId)) |
||||
.position(latlng).anchor(0.5f, 0.5f); |
||||
Marker marker = aMap.addMarker(markerOptions); |
||||
// 设置生长动画
|
||||
Animation animation = new ScaleAnimation(0,1,0,1); |
||||
animation.setInterpolator(new LinearInterpolator()); |
||||
// 设置持续时间
|
||||
animation.setDuration(1000); |
||||
// 设置动画
|
||||
marker.setAnimation(animation); |
||||
// 开始动画
|
||||
marker.startAnimation(); |
||||
} |
||||
|
||||
@Override |
||||
public void onBusRouteSearched(BusRouteResult busRouteResult, int errorCode) {} |
||||
|
||||
@Override |
||||
public void onDriveRouteSearched(DriveRouteResult result, int errorCode) { |
||||
if (errorCode != AMapException.CODE_AMAP_SUCCESS) { |
||||
ToastUtil.showAmapError(errorCode); |
||||
return; |
||||
} |
||||
if (result == null && result.getPaths() == null) { |
||||
ToastUtil.show("对不起,没有搜索到相关数据!"); |
||||
return; |
||||
} |
||||
if (result.getPaths().size() > 0) { |
||||
final DrivePath drivePath = result.getPaths().get(0); |
||||
if(drivePath == null) return; |
||||
DrivingRouteOverlay drivingRouteOverlay = new DrivingRouteOverlay( |
||||
getActivity(), |
||||
aMap, |
||||
drivePath, |
||||
result.getStartPos(), |
||||
result.getTargetPos(), |
||||
throughPoints |
||||
); |
||||
drivingRouteOverlay.removeFromMap(); |
||||
drivingRouteOverlay.drawDrivingRoute(); |
||||
drivingRouteOverlay.zoomToRouteBounds(); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void onWalkRouteSearched(WalkRouteResult walkRouteResult, int errorCode) {} |
||||
|
||||
@Override |
||||
public void onRideRouteSearched(RideRouteResult rideRouteResult, int errorCode) {} |
||||
|
||||
@Override |
||||
public void onResume() { |
||||
super.onResume(); |
||||
mapView.onResume(); |
||||
mapGpsSensorEventListener.registerSensorListener(); |
||||
} |
||||
|
||||
@Override |
||||
public void onPause() { |
||||
super.onPause(); |
||||
mapView.onPause(); |
||||
mapGpsSensorEventListener.unRegisterSensorListener(); |
||||
} |
||||
|
||||
@Override |
||||
public void onSaveInstanceState(@NonNull Bundle outState) { |
||||
super.onSaveInstanceState(outState); |
||||
mapView.onSaveInstanceState(outState); |
||||
} |
||||
|
||||
@Override |
||||
public void onDestroy() { |
||||
super.onDestroy(); |
||||
//fixme 内部高德视图组件销毁修改了内存标记,安卓11后不让修改,会导致内存漏动
|
||||
// 等待后面高德库更新修复这个问题,目前只能关闭堆指针标记
|
||||
// https://source.android.com/devices/tech/debug/tagged-pointers
|
||||
mapView.onDestroy(); |
||||
} |
||||
|
||||
/** 单次定位,用于判断设备权限以及缺少GPS的硬件提示不能使用此软件(针对首次进入时判断) */ |
||||
private void singleAMapLocationClient() { |
||||
AMapLocationClient singleLocationClient = locationRequest.initLocation(locationRequest.getDefaultOption().setOnceLocation(true)); |
||||
singleLocationClient.startLocation(); |
||||
singleLocationClient.setLocationListener(location -> { |
||||
if (null != location) { |
||||
switch (location.getLocationQualityReport().getGPSStatus()) { |
||||
case AMapLocationQualityReport.GPS_STATUS_NOGPSPROVIDER: |
||||
ToastUtil.show("手机中没有GPS模块提供,无法进行GPS定位,请更换设备"); |
||||
break; |
||||
case AMapLocationQualityReport.GPS_STATUS_OFF: |
||||
PermissionUtil.openApplicationSettings(getActivity(), "GPS关闭,建议开启GPS,提高定位质量"); |
||||
break; |
||||
case AMapLocationQualityReport.GPS_STATUS_NOGPSPERMISSION: |
||||
PermissionUtil.openApplicationSettings(getActivity(), "没有GPS定位权限,建议开启gps定位权限"); |
||||
break; |
||||
} |
||||
} else ToastUtil.show("定位失败,请联系系统管理员!"); |
||||
singleLocationClient.onDestroy(); |
||||
}); |
||||
} |
||||
|
||||
@Override |
||||
public void activate(OnLocationChangedListener onLocationChangedListener) { |
||||
userMoveToLocationMark = false; |
||||
if (locationRequest.getLocationClient() == null) { |
||||
locationRequest.getLocationClient().startLocation(); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void deactivate() { |
||||
LogUtils.i("地图暂停时不结束后台定位,让定位在后台也能运行!"); |
||||
} |
||||
|
||||
@Override |
||||
public void onTouch(MotionEvent motionEvent) { |
||||
userMoveToLocationMark = true; |
||||
} |
||||
} |
@ -1,29 +0,0 @@
@@ -1,29 +0,0 @@
|
||||
package com.kanglai.push.ui.vm; |
||||
|
||||
import android.app.Application; |
||||
|
||||
import androidx.annotation.NonNull; |
||||
import androidx.lifecycle.LifecycleOwner; |
||||
|
||||
/** |
||||
*<p> |
||||
* 地图视图模型层 |
||||
*</p> |
||||
* |
||||
* @Author: entfrm开发团队-王翔 |
||||
* @since: 2022/11/1 |
||||
*/ |
||||
public class MapViewModel extends ToolbarViewModel { |
||||
|
||||
|
||||
public MapViewModel(@NonNull Application application) { |
||||
super(application); |
||||
} |
||||
|
||||
@Override |
||||
public void onCreate(@NonNull LifecycleOwner owner) { |
||||
super.onCreate(owner); |
||||
super.setTitleText("高德地图"); |
||||
} |
||||
|
||||
} |
@ -1,13 +0,0 @@
@@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:orientation="vertical"> |
||||
|
||||
<com.amap.api.navi.AMapNaviView |
||||
android:id="@+id/navi_view" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:layout_weight="1"/> |
||||
</LinearLayout> |
||||
|
@ -1,118 +0,0 @@
@@ -1,118 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:binding="http://schemas.android.com/apk/res-auto" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
tools:context="com.kanglai.push.ui.activity.RoutePlanActivity"> |
||||
<data> |
||||
<variable name="viewModel" type="com.kanglai.push.ui.vm.RoutePlanViewModel" /> |
||||
</data> |
||||
<RelativeLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:background="@color/black5"> |
||||
<include |
||||
android:id="@+id/layout_toolbar" |
||||
layout="@layout/layout_toolbar" |
||||
binding:toolbarViewModel="@{viewModel.toolbarViewModel}" /> |
||||
<RelativeLayout |
||||
android:id="@+id/route_plan_header" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:layout_below="@id/layout_toolbar" |
||||
android:background="@drawable/icon_bg_bottom_bar"> |
||||
<LinearLayout |
||||
android:id="@+id/route_plan_choose" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="44dp" |
||||
android:background="@drawable/icon_bg_bottom_bar" |
||||
android:paddingLeft="10dp" |
||||
android:paddingRight="10dp"> |
||||
<RelativeLayout |
||||
android:id="@+id/layout_route_drive" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:layout_weight="1" |
||||
android:onClick="onDriveClick"> |
||||
<ImageView |
||||
android:id="@+id/route_drive" |
||||
android:layout_width="22dp" |
||||
android:layout_height="22dp" |
||||
android:layout_centerInParent="true" |
||||
android:layout_gravity="center" |
||||
android:src="@drawable/icon_route_drive_normal" /> |
||||
</RelativeLayout> |
||||
<RelativeLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:layout_weight="1" |
||||
android:onClick="onRideClick"> |
||||
<ImageView |
||||
android:id="@+id/route_ride" |
||||
android:layout_width="22dp" |
||||
android:layout_height="22dp" |
||||
android:layout_centerInParent="true" |
||||
android:layout_gravity="center" |
||||
android:layout_weight="1" |
||||
android:src="@drawable/icon_route_ride_normal" /> |
||||
</RelativeLayout> |
||||
</LinearLayout> |
||||
</RelativeLayout> |
||||
<RelativeLayout |
||||
android:id="@+id/route_plan_bottom" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="90dp" |
||||
android:layout_alignParentBottom="true" |
||||
android:background="@drawable/icon_bg_bottom_bar" |
||||
android:gravity="center_vertical" |
||||
android:padding="5dp"> |
||||
<TextView |
||||
android:id="@+id/route_time" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="35dp" |
||||
android:layout_marginLeft="12dp" |
||||
android:singleLine="true" |
||||
android:textColor="@color/black" |
||||
android:textSize="16sp" /> |
||||
<Button |
||||
android:id="@+id/btn_start_navi" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:layout_below="@+id/route_time" |
||||
android:background="@drawable/icon_btn_primary_radius_bg" |
||||
android:gravity="center" |
||||
android:text="开始导航" |
||||
android:textColor="@color/white" /> |
||||
<LinearLayout |
||||
android:id="@+id/route_detail" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="35dp" |
||||
android:layout_alignParentRight="true" |
||||
android:layout_marginRight="10dp" |
||||
android:gravity="center_vertical" |
||||
android:orientation="horizontal"> |
||||
<TextView |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="match_parent" |
||||
android:gravity="center_vertical" |
||||
android:text="详情" |
||||
android:textColor="@color/blue" |
||||
android:textSize="14sp" |
||||
android:textStyle="bold"/> |
||||
<Button |
||||
android:layout_width="7dp" |
||||
android:layout_height="13dp" |
||||
android:layout_marginLeft="4dp" |
||||
android:background="@drawable/icon_arrow_right_blue" |
||||
android:gravity="center_vertical" /> |
||||
</LinearLayout> |
||||
</RelativeLayout> |
||||
<com.amap.api.maps.MapView |
||||
android:id="@+id/route_map" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:layout_above="@id/route_plan_bottom" |
||||
android:layout_below="@id/route_plan_header" |
||||
android:layout_marginTop="0dp" |
||||
android:layout_marginBottom="0dp" /> |
||||
</RelativeLayout> |
||||
</layout> |
@ -1,56 +0,0 @@
@@ -1,56 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:binding="http://schemas.android.com/apk/res-auto" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
tools:context="com.kanglai.push.ui.activity.RideRouteDetailActivity"> |
||||
<data> |
||||
<variable name="viewModel" type="com.kanglai.push.ui.vm.ToolbarViewModel" /> |
||||
</data> |
||||
<LinearLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:background="@color/black5" |
||||
android:orientation="vertical"> |
||||
<include |
||||
android:id="@+id/layout_toolbar" |
||||
layout="@layout/layout_toolbar" |
||||
binding:toolbarViewModel="@{viewModel.toolbarViewModel}" /> |
||||
<LinearLayout |
||||
android:id="@+id/route_path" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:orientation="vertical"> |
||||
<LinearLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="70dp" |
||||
android:background="@drawable/icon_bg_bottom_bar" |
||||
android:gravity="center_vertical" |
||||
android:orientation="vertical" |
||||
android:padding="5dp"> |
||||
<TextView |
||||
android:id="@+id/route_time" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="35dp" |
||||
android:layout_marginLeft="12dp" |
||||
android:singleLine="true" |
||||
android:textColor="@color/black" |
||||
android:textSize="16sp" /> |
||||
</LinearLayout> |
||||
<ImageView |
||||
android:layout_width="match_parent" |
||||
android:layout_height="1dp" |
||||
android:background="#e0e0e0" /> |
||||
<ListView |
||||
android:id="@+id/route_list" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:cacheColorHint="@color/transparent" |
||||
android:divider="@color/transparent" |
||||
android:fadingEdge="none" |
||||
android:fadingEdgeLength="0dp" |
||||
android:footerDividersEnabled="false" |
||||
android:headerDividersEnabled="false" |
||||
android:listSelector="@color/transparent" /> |
||||
</LinearLayout> |
||||
</LinearLayout> |
||||
</layout> |
@ -1,24 +0,0 @@
@@ -1,24 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:binding="http://schemas.android.com/apk/res-auto" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
tools:context="com.kanglai.push.ui.fragment.DemoMapFragment"> |
||||
<data> |
||||
<variable name="viewModel" type="com.kanglai.push.ui.vm.MapViewModel" /> |
||||
</data> |
||||
<LinearLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:background="@color/black5" |
||||
android:orientation="vertical"> |
||||
<include |
||||
android:id="@+id/layout_toolbar" |
||||
layout="@layout/layout_toolbar" |
||||
binding:toolbarViewModel="@{viewModel.toolbarViewModel}" /> |
||||
<com.amap.api.maps.MapView |
||||
android:id="@+id/amap" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="0dp" |
||||
android:layout_weight="14" /> |
||||
</LinearLayout> |
||||
</layout> |
@ -1,61 +0,0 @@
@@ -1,61 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:background="@color/white"> |
||||
<ImageView |
||||
android:id="@+id/route_split_line" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="1dp" |
||||
android:layout_marginStart="50dp" |
||||
android:layout_marginLeft="50dp" |
||||
android:background="#e0e0e0" /> |
||||
<RelativeLayout |
||||
android:id="@+id/bus_route_direction" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="44dp" |
||||
android:layout_alignParentStart="true" |
||||
android:layout_alignParentLeft="true" |
||||
android:layout_marginStart="11dp" |
||||
android:layout_marginLeft="11dp"> |
||||
<ImageView |
||||
android:id="@+id/route_dir_icon" |
||||
android:layout_width="@dimen/dp_25" |
||||
android:layout_height="@dimen/dp_15" |
||||
android:layout_centerVertical="true" |
||||
android:src="@drawable/icon_orgin" /> |
||||
<ImageView |
||||
android:id="@+id/route_dir_icon_up" |
||||
android:layout_width="2dp" |
||||
android:layout_height="match_parent" |
||||
android:layout_above="@id/route_dir_icon" |
||||
android:layout_centerHorizontal="true" |
||||
android:background="#b6b6b6" |
||||
android:visibility="gone" /> |
||||
<ImageView |
||||
android:id="@+id/route_dir_icon_down" |
||||
android:layout_width="2dp" |
||||
android:layout_height="match_parent" |
||||
android:layout_below="@id/route_dir_icon" |
||||
android:layout_centerHorizontal="true" |
||||
android:background="#b6b6b6" |
||||
android:visibility="gone" /> |
||||
</RelativeLayout> |
||||
<RelativeLayout |
||||
android:id="@+id/route_item" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="44dp"> |
||||
<TextView |
||||
android:id="@+id/route_line_name" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_centerVertical="true" |
||||
android:layout_marginStart="50dp" |
||||
android:layout_marginLeft="50dp" |
||||
android:layout_marginEnd="70dp" |
||||
android:layout_marginRight="70dp" |
||||
android:text="出发" |
||||
android:textColor="#333333" |
||||
android:textSize="14sp" /> |
||||
</RelativeLayout> |
||||
</RelativeLayout> |
@ -1,224 +0,0 @@
@@ -1,224 +0,0 @@
|
||||
package com.dolphin.core.util; |
||||
|
||||
import com.amap.api.maps.model.LatLng; |
||||
import com.amap.api.services.core.LatLonPoint; |
||||
import com.amap.api.services.route.BusPath; |
||||
import com.amap.api.services.route.BusStep; |
||||
import com.amap.api.services.route.RouteBusLineItem; |
||||
import com.amap.api.services.route.RouteRailwayItem; |
||||
import com.blankj.utilcode.util.ObjectUtils; |
||||
import com.blankj.utilcode.util.StringUtils; |
||||
import com.dolphin.core.R; |
||||
|
||||
import java.text.DecimalFormat; |
||||
import java.util.List; |
||||
|
||||
import lombok.experimental.UtilityClass; |
||||
|
||||
/** |
||||
*<p> |
||||
* 高德地图通用工具 |
||||
*</p> |
||||
* |
||||
* @Author: entfrm开发团队-王翔 |
||||
* @since: 2022/11/4 |
||||
*/ |
||||
@UtilityClass |
||||
public class AMapCommonUtil { |
||||
|
||||
/** |
||||
* 获取规划公里数 |
||||
* @param distance 出行路线规划总距离 |
||||
* @return 公里 |
||||
*/ |
||||
public String getPlanKilometer(int distance) { |
||||
// 10 km
|
||||
if (distance > 10000) { |
||||
int dis = distance / 1000; |
||||
return dis + "公里"; |
||||
} |
||||
|
||||
// 1 km
|
||||
if (distance > 1000) { |
||||
float dis = (float) distance / 1000; |
||||
DecimalFormat decimalFormat = new DecimalFormat("##0.0"); |
||||
String str = decimalFormat.format(dis); |
||||
return str + "公里"; |
||||
} |
||||
|
||||
if (distance > 100) { |
||||
int dis = distance / 50 * 50; |
||||
return dis + "公里"; |
||||
} |
||||
|
||||
int dis = distance / 10 * 10; |
||||
if (dis == 0) { |
||||
dis = 10; |
||||
} |
||||
|
||||
return dis + "公里"; |
||||
} |
||||
|
||||
/** |
||||
* 获规划预计时间 |
||||
* @param duration 持续时间 |
||||
* @return 时间 |
||||
*/ |
||||
public String getPlanTime(int duration) { |
||||
if (duration > 3600) { |
||||
int hour = duration / 3600; |
||||
int minutes = (duration % 3600) / 60; |
||||
return hour + "小时" + minutes + "分钟"; |
||||
} |
||||
if (duration >= 60) { |
||||
int minutes = duration / 60; |
||||
return minutes + "分钟"; |
||||
} |
||||
return duration + "秒"; |
||||
} |
||||
|
||||
/** |
||||
* 获取行驶动作指示资源 |
||||
* @param actionName 行驶动作名称 |
||||
* @return 图片 |
||||
*/ |
||||
public int getDrivingActionResource(String actionName) { |
||||
if ("左转".equals(actionName)) { |
||||
return R.drawable.icon_driving2; |
||||
} |
||||
if ("右转".equals(actionName)) { |
||||
return R.drawable.icon_driving1; |
||||
} |
||||
if ("向左前方行驶".equals(actionName) || "靠左".equals(actionName)) { |
||||
return R.drawable.icon_driving6; |
||||
} |
||||
if ("向右前方行驶".equals(actionName) || "靠右".equals(actionName)) { |
||||
return R.drawable.icon_driving5; |
||||
} |
||||
if ("向左后方行驶".equals(actionName) || "左转调头".equals(actionName)) { |
||||
return R.drawable.icon_driving7; |
||||
} |
||||
if ("向右后方行驶".equals(actionName)) { |
||||
return R.drawable.icon_driving8; |
||||
} |
||||
if ("直行".equals(actionName)) { |
||||
return R.drawable.icon_driving3; |
||||
} |
||||
if ("减速行驶".equals(actionName)) { |
||||
return R.drawable.icon_driving4; |
||||
} |
||||
return R.drawable.icon_driving3; |
||||
} |
||||
|
||||
/** |
||||
* 获取步行动作指示资源 |
||||
* @param actionName 步行动作名称 |
||||
* @return 图片 |
||||
*/ |
||||
public int getWalkActionResource(String actionName) { |
||||
if ("左转".equals(actionName)) { |
||||
return R.drawable.icon_driving2; |
||||
} |
||||
if ("右转".equals(actionName)) { |
||||
return R.drawable.icon_driving1; |
||||
} |
||||
if ("向左前方".equals(actionName) || "靠左".equals(actionName) || actionName.contains("向左前方")) { |
||||
return R.drawable.icon_driving6; |
||||
} |
||||
if ("向右前方".equals(actionName) || "靠右".equals(actionName) || actionName.contains("向右前方")) { |
||||
return R.drawable.icon_driving5; |
||||
} |
||||
if ("向左后方".equals(actionName)|| actionName.contains("向左后方")) { |
||||
return R.drawable.icon_driving7; |
||||
} |
||||
if ("向右后方".equals(actionName)|| actionName.contains("向右后方")) { |
||||
return R.drawable.icon_driving8; |
||||
} |
||||
if ("直行".equals(actionName)) { |
||||
return R.drawable.icon_driving3; |
||||
} |
||||
if ("通过人行横道".equals(actionName)) { |
||||
return R.drawable.icon_driving9; |
||||
} |
||||
if ("通过过街天桥".equals(actionName)) { |
||||
return R.drawable.icon_driving11; |
||||
} |
||||
if ("通过地下通道".equals(actionName)) { |
||||
return R.drawable.icon_driving10; |
||||
} |
||||
return R.drawable.icon_driving13; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 获取公交规划路线标题(包含多种规划到达路线) |
||||
* @param busPath 公交路线 |
||||
* @return 标题 |
||||
*/ |
||||
public String getBusPathTitle(BusPath busPath) { |
||||
if (ObjectUtils.isEmpty(busPath)) return ""; |
||||
// 公交规划线路行驶步骤
|
||||
List<BusStep> busSteps = busPath.getSteps(); |
||||
if (ObjectUtils.isEmpty(busSteps)) return ""; |
||||
// 规划路线标题
|
||||
StringBuffer sb = new StringBuffer(); |
||||
for (BusStep busStep : busSteps) { |
||||
StringBuffer title = new StringBuffer(); |
||||
if (busStep.getBusLines().size() > 0) { |
||||
for (RouteBusLineItem busLine : busStep.getBusLines()) { |
||||
if (busLine == null) continue; |
||||
// 去掉详细地名
|
||||
String busLineName = StringUtils.isTrimEmpty(busLine.getBusLineName()) ? "" |
||||
: busLine.getBusLineName().replaceAll("\\(.*?\\)", ""); |
||||
title.append(busLineName); |
||||
title.append(" / "); |
||||
} |
||||
sb.append(title.substring(0, title.length() - 3)); |
||||
sb.append(" > "); |
||||
} |
||||
// 获取地铁名称
|
||||
if (busStep.getRailway() != null) { |
||||
RouteRailwayItem railway = busStep.getRailway(); |
||||
sb.append(railway.getTrip()+"("+railway.getDeparturestop().getName() + " - "+railway.getArrivalstop().getName()+")"); |
||||
sb.append(" > "); |
||||
} |
||||
} |
||||
// 返回并去掉最后的 >
|
||||
return sb.substring(0, sb.length() - 3); |
||||
} |
||||
|
||||
/** |
||||
* 获取公交规划路线预计规划信息 |
||||
* @param busPath 公交路线 |
||||
* @return 预计规划信息 |
||||
*/ |
||||
public String getBusPathPlanInfo(BusPath busPath) { |
||||
if (ObjectUtils.isEmpty(busPath)) return ""; |
||||
long duration = busPath.getDuration(); |
||||
String time = getPlanTime((int) duration); |
||||
float subDistance = busPath.getDistance(); |
||||
String subDis = getPlanKilometer((int) subDistance); |
||||
float walkDistance = busPath.getWalkDistance(); |
||||
String walkDis = getPlanKilometer((int) walkDistance); |
||||
return time + " | " + subDis + " | 步行" + walkDis; |
||||
} |
||||
|
||||
/** |
||||
* 经纬度点对象转经纬度地理坐标对象 |
||||
* @param latLonPoint 经纬度点对象 |
||||
* @return 经纬度地理坐标对象 |
||||
*/ |
||||
public static LatLng convertToLatLng(LatLonPoint latLonPoint) { |
||||
return new LatLng(latLonPoint.getLatitude(), latLonPoint.getLongitude()); |
||||
} |
||||
|
||||
/** |
||||
* 经纬度地理坐标对象转经纬度点对象 |
||||
* @param latLng 经纬度地理坐标对象 |
||||
* @return 经纬度点对象 |
||||
*/ |
||||
public static LatLonPoint convertToLatLonPoint(LatLng latLng) { |
||||
return new LatLonPoint(latLng.latitude, latLng.longitude); |
||||
} |
||||
|
||||
} |
Before Width: | Height: | Size: 971 B |
Before Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 4.6 KiB |
Before Width: | Height: | Size: 702 B |
Before Width: | Height: | Size: 910 B |
Before Width: | Height: | Size: 941 B |
Before Width: | Height: | Size: 883 B |
Before Width: | Height: | Size: 699 B |
Before Width: | Height: | Size: 712 B |
Before Width: | Height: | Size: 711 B |
Before Width: | Height: | Size: 838 B |
Before Width: | Height: | Size: 832 B |
Before Width: | Height: | Size: 791 B |
Before Width: | Height: | Size: 824 B |
Before Width: | Height: | Size: 942 B |
Before Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 4.4 KiB |