提交 6f30a95b 编写于 作者: 门心叼龙's avatar 门心叼龙

more common move add

上级 3f301ff0
此差异已折叠。
package com.mxdl.movecar.service;
/**
* Description: <MoveCarCustomThread><br>
* Author: mxdl<br>
* Date: 2019/7/10<br>
* Version: V1.0.0<br>
* Update: <br>
*/
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.utils.overlay.MovingPointOverlay;
import com.mxdl.movecar.MainActivity;
import com.mxdl.movecar.contract.IMoveCar;
import com.mxdl.movecar.enums.MOVE_STATE;
import java.lang.ref.WeakReference;
import java.util.List;
/**
* Description: <MoveCarCustomThread><br>
* Author: mxdl<br>
* Date: 2019/7/10<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public class MoveCarSmoothThread1 extends Thread implements IMoveCar {
public static final String TAG = MoveCarSmoothThread1.class.getSimpleName();
private MovingPointOverlay mMovingPointOverlay;
private WeakReference<MainActivity> mActivityWeakReference;
private MOVE_STATE currMoveState = MOVE_STATE.START_STATUS;
private Handler mHandler;
public Handler getHandler() {
return mHandler;
}
@Override
public void run() {
super.run();
Looper.prepare();
mHandler = new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (msg.obj != null && msg.obj instanceof List) {
List<LatLng> latLngList = (List<LatLng>) msg.obj;
startMove(latLngList);
}
}
};
Looper.loop();
}
public void setCurrMoveState(MOVE_STATE currMoveState) {
this.currMoveState = currMoveState;
}
public MOVE_STATE getCurrMoveState() {
return currMoveState;
}
public MoveCarSmoothThread1(MainActivity activity) {
mActivityWeakReference = new WeakReference<>(activity);
}
@Override
public void startMove(List<LatLng> latLngs) {
if (latLngs == null || latLngs.size() == 0) {
return;
}
Log.v("MYTAG","startMove start:"+Thread.currentThread().getName());
Log.v(TAG, "moveCoarseTrack start.........................................................");
long startTime = System.currentTimeMillis();
Log.v(TAG, "startTime:" + startTime);
final MainActivity mainActivity = mActivityWeakReference.get();
if (mMovingPointOverlay == null) {
mMovingPointOverlay = new MovingPointOverlay(mainActivity.mAMap, mainActivity.mCarMarker);
mMovingPointOverlay.setTotalDuration(5);
mMovingPointOverlay.setMoveListener(new MovingPointOverlay.MoveListener() {
@Override
public void move(double v) {
Log.v("MYTAG","MoveCarSmoolthThread move start:"+Thread.currentThread().getName());
LatLng position = mMovingPointOverlay.getPosition();
mainActivity.mLatLngList.add(position);// 向轨迹集合增加轨迹点
mainActivity.mMovePolyline.setPoints(mainActivity.mLatLngList);// 轨迹画线开始
Message message = Message.obtain();
message.what = MainActivity.EventType.MapMove;
message.obj = position;
message.arg1 = (int)v;
mainActivity.mMainHandler.sendMessage(message);
}
});
}
mMovingPointOverlay.setPoints(latLngs);
mMovingPointOverlay.startSmoothMove();
long endTime = System.currentTimeMillis();
Log.v(TAG, "endTime:" + endTime);
Log.v(TAG, "moveCoarseTrack end.........................................................");
}
@Override
public void reStartMove() {
if(mMovingPointOverlay != null){
mMovingPointOverlay.startSmoothMove();
}
}
@Override
public void pauseMove(){
if(mMovingPointOverlay != null){
mMovingPointOverlay.stopMove();
}
}
@Override
public void stopMove(){
if(mMovingPointOverlay != null){
mMovingPointOverlay.destroy();
mMovingPointOverlay = null;
}
if(mActivityWeakReference.get() != null){
mActivityWeakReference.get().mLatLngList.clear();
}
}
}
......@@ -12,14 +12,22 @@
android:id="@+id/btn_coarse_move"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="开始普通移动"
android:text="开始单次普通移动"
/>
<Button
android:id="@+id/btn_coarse_move1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="模拟多次普通移动"
android:layout_below="@+id/btn_coarse_move"
/>
<Button
android:id="@+id/btn_smooth_move"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="开始单次平滑移动"
android:layout_below="@+id/btn_coarse_move"
android:layout_below="@+id/btn_coarse_move1"
/>
<Button
android:id="@+id/btn_smooth_move1"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册