android 基于高德地圖的軌跡回放

android 基于高德地圖的軌跡回放

前段時(shí)間公司項(xiàng)目有一個(gè)需求,就是需要看到設(shè)備上傳之后的軌跡路線,并且可以實(shí)現(xiàn)回放的整個(gè)過(guò)程,功能包括路線回放、地圖位置插點(diǎn)、回放之后的軌跡標(biāo)記顏色、回放加速等功能。下面是開(kāi)發(fā)的整個(gè)過(guò)程。

首先,軌跡回放是基于地圖做的,我這里用的是高德地圖,軌跡回放是基于高德地圖3D地圖開(kāi)發(fā)的,2D地圖好像暫時(shí)不支持。必要的就是申請(qǐng)高德地圖的key,然后配置到自己的項(xiàng)目里,這一步就不說(shuō)了,高德地圖上這些步驟很詳細(xì),也很簡(jiǎn)單,直接跳過(guò)到開(kāi)發(fā)軌跡回放這一步。

首先上一個(gè)效果圖:


開(kāi)始回放
軌跡地圖頁(yè)面

接下來(lái)是先接入地圖,初始化整個(gè)地圖,這一步也直接跳過(guò)吧,我最后會(huì)把整個(gè)代碼貼出來(lái),如果有需要可以自己看看,直接說(shuō)軌跡回放在地圖上劃線的代碼:

首先,新建一個(gè)存放經(jīng)緯度的數(shù)組:

List<LatLng>?points = new ArrayList<LatLng>();

然后把你獲取到的經(jīng)緯度add到數(shù)組里面

//添加經(jīng)緯度至數(shù)組,添加下標(biāo),防止新數(shù)據(jù)占用老數(shù)據(jù)位置

points.add(i, new LatLng(latitude, longitude));

接下來(lái)就是用獲取到的經(jīng)緯度在地圖上添加海量的marker點(diǎn):

//添加海量marker點(diǎn)

MarkerOptions markerOption= new MarkerOptions();

// markerOption.position(new LatLng(aLocation.getLatitude(), aLocation.getLongitude()));

markerOption.position(new LatLng(latitude, longitude));

markerOption.visible(true);//標(biāo)記可見(jiàn)

markerOption.icon(

? ? ? ? BitmapDescriptorFactory.fromBitmap(BitmapFactory

? ? ? ? ? ? ? ? .decodeResource(getResources(),

? ? ? ? ? ? ? ? ? ? ? ? R.drawable.marker_blue)));

markerOption.anchor(0.5f, 0.5f);

Marker marker= aMap.addMarker(markerOption);

// marker.setIcon();

marker.setObject(map);// 這里可以存儲(chǔ)用戶數(shù)據(jù)

listMarker.add(marker);

然后在地圖上劃線,就是把points的點(diǎn)連接起來(lái):

/*劃線*/

private void showline() {

? ? addPolylineInPlayGround();

? ? Log.e("tag", points.toString());

? ? // 獲取軌跡坐標(biāo)點(diǎn)

? ? LatLngBounds.Builder b= LatLngBounds.builder();

? ? for (int i= 0; i< points.size(); i++) {

? ? ? ? b.include(points.get(i));

}

? ? LatLngBounds bounds= b.build();

? ? aMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100));

}

/*添加線條*/

private void addPolylineInPlayGround() {

? ? List list= points;

? ? List colorList= new ArrayList();

? ? aMap.addPolyline(new PolylineOptions().setCustomTexture(BitmapDescriptorFactory.fromResource(R.drawable.custtexture)) //setCustomTextureList(bitmapDescriptors)

? ? ? ? ? ? .addAll(list)

? ? ? ? ? ? .useGradient(true)

? ? ? ? ? ? .width(18));

}

現(xiàn)在線已經(jīng)畫(huà)好的,然后就可以進(jìn)行軌跡回放以及暫停,銷(xiāo)毀,加速的這些步驟:

/*開(kāi)始移動(dòng)*/

? ? public void startMove() {

? ? ? ? final PolylineOptions options= new PolylineOptions();

? ? ? ? State = 1;

? ? ? ? playback = 1;

? ? ? ? play.setVisibility(View.GONE);

? ? ? ? Fast_forward.setVisibility(View.VISIBLE);

? ? ? ? stop.setVisibility(View.VISIBLE);

? ? ? ? tingzhi.setVisibility(View.VISIBLE);

? ? ? ? // 設(shè)置滑動(dòng)的圖標(biāo)

? ? ? ? smoothMarker.setDescriptor(BitmapDescriptorFactory.fromResource(R.mipmap.carr));

? ? ? ? ? ? /*//當(dāng)移動(dòng)Marker的當(dāng)前位置不在軌跡起點(diǎn),先從當(dāng)前位置移動(dòng)到軌跡上,再開(kāi)始平滑移動(dòng)? ? ? ? ? ? // LatLng drivePoint = points.get(0);//設(shè)置小車(chē)當(dāng)前位置,可以是任意點(diǎn),這里直接設(shè)置為軌跡起點(diǎn)? ? ? ? ? ? LatLng drivePoint = new LatLng(39.980521,116.351905);//設(shè)置小車(chē)當(dāng)前位置,可以是任意點(diǎn)Pair pair = PointsUtil.calShortestDistancePoint(points, drivePoint);

points.set(pair.first, drivePoint);

List subList = points.subList(pair.first, points.size());

? ? ? ? ? ? // 設(shè)置滑動(dòng)的軌跡左邊點(diǎn)smoothMarker.setPoints(subList);*/

? ? ? ? //計(jì)算軌跡運(yùn)行之后的距離,重新開(kāi)始回放

? ? ? ? smoothMarker.setPoints(points);//設(shè)置平滑移動(dòng)的軌跡list

? ? ? ? // 設(shè)置移動(dòng)的監(jiān)聽(tīng)事件? 返回 距終點(diǎn)的距離? 單位 米

? ? ? ? smoothMarker.setMoveListener(new SmoothMoveMarker.MoveListener() {

? ? ? ? ? ? @Override

? ? ? ? ? ? public void move(final double distance) {

? ? ? ? ? ? ? ? runOnUiThread(new Runnable() {

? ? ? ? ? ? ? ? ? ? @Override

? ? ? ? ? ? ? ? ? ? public void run() {

? ? ? ? ? ? ? ? ? ? ? ? //添加快進(jìn)按鈕,回放速度快進(jìn)一倍

? ? ? ? ? ? ? ? ? ? ? ? if (speed == 1) {

? ? ? ? ? ? ? ? ? ? ? ? ? ? if ((int) distance > 1500000) {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(500);//設(shè)置平滑移動(dòng)的總時(shí)間

? ? ? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? ? ? ? ? if ((int) distance < 1500000 && (int) distance > 100000) {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(400);//設(shè)置平滑移動(dòng)的總時(shí)間

? ? ? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? ? ? ? ? if ((int) distance < 100000 && (int) distance > 50000) {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(250);//設(shè)置平滑移動(dòng)的總時(shí)間

? ? ? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? ? ? ? ? if ((int) distance < 50000 && (int) distance > 10000) {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(150);//設(shè)置平滑移動(dòng)的總時(shí)間

? ? ? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? ? ? ? ? if ((int) distance < 10000) {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(50);//設(shè)置平滑移動(dòng)的總時(shí)間

? ? ? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? ? ? } else {

? ? ? ? ? ? ? ? ? ? ? ? ? ? //正?;胤潘俣?/p>

? ? ? ? ? ? ? ? ? ? ? ? ? ? if ((int) distance > 1500000) {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(1000);//設(shè)置平滑移動(dòng)的總時(shí)間

? ? ? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? ? ? ? ? if ((int) distance < 1500000 && (int) distance > 100000) {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(800);//設(shè)置平滑移動(dòng)的總時(shí)間

? ? ? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? ? ? ? ? if ((int) distance < 100000 && (int) distance > 50000) {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(500);//設(shè)置平滑移動(dòng)的總時(shí)間

? ? ? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? ? ? ? ? if ((int) distance < 50000 && (int) distance > 10000) {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(300);//設(shè)置平滑移動(dòng)的總時(shí)間

? ? ? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? ? ? ? ? if ((int) distance < 10000) {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(100);//設(shè)置平滑移動(dòng)的總時(shí)間

? ? ? ? ? ? ? ? ? ? ? ? ? ? }

}

? ? ? ? ? ? ? ? ? ? ? ? if ((int) distance < 1) {

? ? ? ? ? ? ? ? ? ? ? ? ? ? play.setVisibility(View.VISIBLE);

? ? ? ? ? ? ? ? ? ? ? ? ? ? stop.setVisibility(View.GONE);

? ? ? ? ? ? ? ? ? ? ? ? ? ? tingzhi.setVisibility(View.VISIBLE);

? ? ? ? ? ? ? ? ? ? ? ? ? ? Fast_forward.setVisibility(View.GONE);

? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? ? ? //獲取當(dāng)前的移動(dòng)marker點(diǎn),設(shè)置地圖中心坐標(biāo)點(diǎn)

? ? ? ? ? ? ? ? ? ? ? ? LatLng position= smoothMarker.getPosition();

? ? ? ? ? ? ? ? ? ? ? ? aMap.moveCamera(CameraUpdateFactory.changeLatLng(position));

? ? ? ? ? ? ? ? ? ? ? ? redpoints.add(redpoints.size(), position);

? ? ? ? ? ? ? ? ? ? ? ? aMap.addPolyline(options.color(Color.RED) //setCustomTextureList(bitmapDescriptors)

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? .add(position)

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? .useGradient(true)

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? .visible(true)

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? .width(18));

}

? ? ? ? ? ? ? ? });

}

? ? ? ? });

? ? ? ? //設(shè)置地圖縮放比例

? ? ? ? aMap.moveCamera(CameraUpdateFactory.zoomTo(17));

? ? ? ? smoothMarker.startSmoothMove();

? ? ? ? smoothMarker.getMarker().setVisible(true);

}

? ? /*停止平滑移動(dòng)*/

? ? public void stopMove() {

? ? ? ? State = 2;

? ? ? ? playback = 2;

? ? ? ? smoothMarker.stopMove();

? ? ? ? LatLng position1= smoothMarker.getPosition();

? ? ? ? //暫停之后重新開(kāi)始回放,繼續(xù)之前的路徑

//? ? ? ? smoothMarker.startSmoothMove();

? ? ? ? play.setVisibility(View.VISIBLE);

? ? ? ? stop.setVisibility(View.GONE);

? ? ? ? tingzhi.setVisibility(View.VISIBLE);

? ? ? ? Fast_forward.setVisibility(View.GONE);

}

? ? /*繼續(xù)中斷的軌跡回放路線*/

? ? public void startmove() {

? ? ? ? State = 3;

? ? ? ? play.setVisibility(View.GONE);

? ? ? ? stop.setVisibility(View.VISIBLE);

? ? ? ? Fast_forward.setVisibility(View.VISIBLE);

? ? ? ? tingzhi.setVisibility(View.VISIBLE);

? ? ? ? smoothMarker.startSmoothMove();

}

? ? /*停止軌跡回放*/

? ? public void cease() {

? ? ? ? State = 4;

? ? ? ? playback = 3;

? ? ? ? smoothMarker.destroy();

? ? ? ? play.setVisibility(View.VISIBLE);

? ? ? ? stop.setVisibility(View.GONE);

? ? ? ? tingzhi.setVisibility(View.GONE);

? ? ? ? Fast_forward.setVisibility(View.GONE);

? ? ? ? aMap.clear();

? ? ? ? points.clear();

? ? }

正常的軌跡回放需求就是這些,如果沒(méi)有任何問(wèn)題的話,軌跡回放以及快進(jìn)的功能已經(jīng)做好了,在這里說(shuō)一下我的經(jīng)緯度信息是從百度鷹眼上獲取到的,所以不用進(jìn)行軌跡糾偏,所以這一步驟我也沒(méi)有詳細(xì)的研究,大概誤差不會(huì)太高。要注意的一點(diǎn)就是給經(jīng)緯度數(shù)組add數(shù)據(jù)的時(shí)候一定要添加下標(biāo),不然新的數(shù)組會(huì)添加到老數(shù)據(jù)之前,這樣就會(huì)造成軌跡回放的時(shí)候會(huì)先從最后的一段路線開(kāi)始,結(jié)束的時(shí)候是第一段路線,所以這里一定要注意。還有一個(gè)小小的問(wèn)題就是有時(shí)候進(jìn)入頁(yè)面的時(shí)候路線還是有一點(diǎn)小問(wèn)題,暫時(shí)我還沒(méi)想到解決的辦法,歡迎指正。下面是我整個(gè)頁(yè)面的詳細(xì)代碼:

public class MapActivity extends Activity implements View.OnClickListener, AMap.OnMarkerClickListener {

? ? private List points = new ArrayList();

? ? private List redpoints = new ArrayList();

? ? private LinearLayout infoWindowLayout, linear3;

? ? private TextView title;

? ? private TextView snippet;

? ? private MapBean mapbean;

? ? private LayoutInflater factory;

? ? private MarkerOptions markerOption;

? ? private MapView mapView;

? ? private AMap aMap;

? ? private OkHttpClient okHttpClient;

? ? private Handler mHandler = new Handler();

? ? private ImageView play, stop, massage, tingzhi, Fast_forward;

? ? private SmoothMoveMarker smoothMarker;

? ? private PopupWindow popupWindow;

? ? private CustomPopWindow popupWindow1;

? ? private String username, key, current_timestamp, type, number, strttime, endtime, url, sensor, Alarmtime, id;

? ? private ImageView back;

? ? private List list;

? ? private String Smessage;

? ? private ProgressDialogEx progressDlgEx;

? ? private int State, playback;

? ? private List listMarker = new ArrayList();

? ? private int speed = 0;

? ? @Override

? ? protected void onCreate(Bundle savedInstanceState) {

? ? ? ? super.onCreate(savedInstanceState);

? ? ? ? setContentView(R.layout.activity_map);

? ? ? ? progressDlgEx = new ProgressDialogEx(this, mHandler);

? ? ? ? factory = LayoutInflater.from(MapActivity.this);

? ? ? ? play = (ImageView) this.findViewById(R.id.play);

? ? ? ? stop = (ImageView) this.findViewById(R.id.stop);

? ? ? ? massage = (ImageView) this.findViewById(R.id.massage);

? ? ? ? massage.setOnClickListener(this);

? ? ? ? back = (ImageView) this.findViewById(R.id.back);

? ? ? ? back.setOnClickListener(this);

? ? ? ? play = (ImageView) this.findViewById(R.id.play);

? ? ? ? play.setOnClickListener(this);

? ? ? ? stop = (ImageView) this.findViewById(R.id.stop);

? ? ? ? stop.setOnClickListener(this);

? ? ? ? tingzhi = (ImageView) this.findViewById(R.id.tingzhi);

? ? ? ? tingzhi.setOnClickListener(this);

? ? ? ? Fast_forward = (ImageView) this.findViewById(R.id.Fast_forward);

? ? ? ? Fast_forward.setOnClickListener(this);

? ? ? ? // 獲取用戶名

? ? ? ? username = SharedPreferencesUtils.getString(MapActivity.this, "userName", "");

? ? ? ? key = Data.getInstance().key;

? ? ? ? //時(shí)間戳

? ? ? ? current_timestamp = Data.getInstance().current_timestamp;

? ? ? ? Intent intent= getIntent();

? ? ? ? type = intent.getStringExtra("type");//設(shè)備類(lèi)型? 1冷藏車(chē)? 2保溫箱

? ? ? ? number = intent.getStringExtra("number");//設(shè)備號(hào)? 車(chē)牌號(hào)或保溫箱號(hào)

? ? ? ? strttime = intent.getStringExtra("strttime");//開(kāi)始時(shí)間

? ? ? ? endtime = intent.getStringExtra("endtime");//結(jié)束時(shí)間

? ? ? ? sensor = intent.getStringExtra("sensor");//sensor

? ? ? ? id = intent.getStringExtra("id");

? ? ? ? mapView = (MapView) findViewById(R.id.map);

? ? ? ? mapView.onCreate(savedInstanceState);// 此方法必須重寫(xiě)

? ? ? ? init();

? ? ? ? DeviceWorkTime();

? ? ? ? ShowMessage();

}

? ? /*比較時(shí)間截取,分割時(shí)間不大于24小時(shí)*/

? ? private void CycleTime(String num, int startdate, int enddate) {

? ? ? ? //相差6天以上

? ? ? ? if (enddate- startdate>= 518400) {

? ? ? ? ? ? String onetime= String.valueOf(enddate- 86399);

? ? ? ? ? ? String twotime= String.valueOf(Integer.parseInt(onetime) - 86399);

? ? ? ? ? ? String thretime= String.valueOf(Integer.parseInt(twotime) - 86399);

? ? ? ? ? ? String foretime= String.valueOf(Integer.parseInt(threetime) - 86399);

? ? ? ? ? ? String fivetime= String.valueOf(Integer.parseInt(foretime) - 86399);

? ? ? ? ? ? String sixtime= String.valueOf(Integer.parseInt(fivetime) - 86399);

? ? ? ? ? ? //strttime,sixtime? sixtime,fivetime? fivetime,foretime? ? foretime,threetime? threetime,twotime? twotime,onetime? onetime,endtime

? ? ? ? ? ? show(num, String.valueOf(startdate), sixtime);

? ? ? ? ? ? show(num, sixtime, fivetime);

? ? ? ? ? ? show(num, fivetime, foretime);

? ? ? ? ? ? show(num, foretime, threetime);

? ? ? ? ? ? show(num, threetime, twotime);

? ? ? ? ? ? show(num, twotime, onetime);

? ? ? ? ? ? show(num, onetime, String.valueOf(enddate));

}

? ? ? ? //小于1天

? ? ? ? else if (enddate- startdate< 86400) {

? ? ? ? ? ? show(num, String.valueOf(startdate), String.valueOf(enddate));

}

}

? ? /*獲取設(shè)備工作時(shí)間段*/

? ? private void DeviceWorkTime() {

? ? ? ? points.clear();

? ? ? ? new Thread() {

? ? ? ? ? ? @Override

? ? ? ? ? ? public void run() {

? ? ? ? ? ? ? ? progressDlgEx.simpleModeShowHandleThread();

? ? ? ? ? ? ? ? OkHttpClient okHttpClient= new OkHttpClient();

? ? ? ? ? ? ? ? String format= String.format(KeyPath.Path.head + KeyPath.Path.deviceworktime, username, key, current_timestamp, type, strttime, endtime, id);

? ? ? ? ? ? ? ? Request build1= new Request.Builder().url(format).build();

? ? ? ? ? ? ? ? okHttpClient.newCall(build1).enqueue(new Callback() {

? ? ? ? ? ? ? ? ? ? @Overrid

? ? ? ? ? ? ? ? ? ? public void onFailure(Call call, IOException e) {

}

? ? ? ? ? ? ? ? ? ? @Override

? ? ? ? ? ? ? ? ? ? public void onResponse(Call call, Response response) throws IOException {

? ? ? ? ? ? ? ? ? ? ? ? String string= response.body().string();

? ? ? ? ? ? ? ? ? ? ? ? if (string!= null) {

? ? ? ? ? ? ? ? ? ? ? ? ? ? try {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? final JSONObject jsonObject= new JSONObject(string);

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? int status= jsonObject.getInt("status");

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if (status== 1) {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? mHandler.post(new Runnable() {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? @Override

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? public void run() {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? try {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? JSONObject data= jsonObject.getJSONObject("data");

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? JSONArray items= data.getJSONArray("device");

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? final List listt= JsonUtils.parseJsonArray(items);

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Data.getInstance().list = listt;

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? for (int i= 0; i< listt.size(); i++) {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Map map= (Map) listt.get(i);

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? String boxmac= map.get("boxmac").toString();

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? int startdate= Integer.parseInt(map.get("startdate").toString());

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? int enddate= Integer.parseInt(map.get("enddate").toString());

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? CycleTime(boxmac, startdate, enddate);

}

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? } catch (JSONException e) {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? e.printStackTrace();

}

}

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? });

}

? ? ? ? ? ? ? ? ? ? ? ? ? ? } catch (JSONException e) {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? e.printStackTrace();

? ? ? ? ? ? ? ? ? ? ? ? ? ? } finally {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? progressDlgEx.closeHandleThread();

}

}

}

? ? ? ? ? ? ? ? });

}

? ? ? ? }.start();

}

? ? /**

? ? * 初始化AMap對(duì)象

? ? */

? ? private void init() {

? ? ? ? if (aMap == null) {

? ? ? ? ? ? aMap = mapView.getMap();

}

? ? ? ? aMap.setOnMarkerClickListener(this);// 設(shè)置點(diǎn)擊marker事件監(jiān)聽(tīng)器

? ? ? ? smoothMarker = new SmoothMoveMarker(aMap);

}

? ? /**

? ? * 方法必須重寫(xiě)

? ? */

? ? @Override

? ? protected void onResume() {

? ? ? ? super.onResume();

? ? ? ? mapView.onResume()

}


? ? /**


? ? * 方法必須重寫(xiě)


? ? */


? ? @Override


? ? protected void onPause() {


? ? ? ? super.onPause();


? ? ? ? mapView.onPause();


}


? ? /**


? ? * 方法必須重寫(xiě)


? ? */


? ? @Override


? ? protected void onSaveInstanceState(Bundle outState) {


? ? ? ? super.onSaveInstanceState(outState);


? ? ? ? mapView.onSaveInstanceState(outState);


}


? ? /**


? ? * 方法必須重寫(xiě)


? ? */


? ? @Override


? ? protected void onDestroy() {


? ? ? ? super.onDestroy();


? ? ? ? mapView.onDestroy();


}


? ? /*劃線*/


? ? private void showline() {


? ? ? ? addPolylineInPlayGround();


? ? ? ? Log.e("tag", points.toString());


? ? ? ? // 獲取軌跡坐標(biāo)點(diǎn)


? ? ? ? LatLngBounds.Builder b= LatLngBounds.builder();


? ? ? ? for (int i= 0; i< points.size(); i++) {


? ? ? ? ? ? b.include(points.get(i));


}


? ? ? ? LatLngBounds bounds= b.build();


? ? ? ? aMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100));


}


? ? /*開(kāi)始移動(dòng)*/


? ? public void startMove() {


? ? ? ? final PolylineOptions options= new PolylineOptions();


? ? ? ? State = 1;


? ? ? ? playback = 1;


? ? ? ? play.setVisibility(View.GONE);


? ? ? ? Fast_forward.setVisibility(View.VISIBLE);


? ? ? ? stop.setVisibility(View.VISIBLE);


? ? ? ? tingzhi.setVisibility(View.VISIBLE);


? ? ? ? // 設(shè)置滑動(dòng)的圖標(biāo)


? ? ? ? smoothMarker.setDescriptor(BitmapDescriptorFactory.fromResource(R.mipmap.carr));


? ? ? ? ? ? /*//當(dāng)移動(dòng)Marker的當(dāng)前位置不在軌跡起點(diǎn),先從當(dāng)前位置移動(dòng)到軌跡上,再開(kāi)始平滑移動(dòng)? ? ? ? ? ? // LatLng drivePoint = points.get(0);//設(shè)置小車(chē)當(dāng)前位置,可以是任意點(diǎn),這里直接設(shè)置為軌跡起點(diǎn)? ? ? ? ? ? LatLng drivePoint = new LatLng(39.980521,116.351905);//設(shè)置小車(chē)當(dāng)前位置,可以是任意點(diǎn)Pair pair = PointsUtil.calShortestDistancePoint(points, drivePoint);


points.set(pair.first, drivePoint);


List subList = points.subList(pair.first, points.size());


? ? ? ? ? ? // 設(shè)置滑動(dòng)的軌跡左邊點(diǎn)smoothMarker.setPoints(subList);*/


? ? ? ? //計(jì)算軌跡運(yùn)行之后的距離,重新開(kāi)始回放


? ? ? ? smoothMarker.setPoints(points);//設(shè)置平滑移動(dòng)的軌跡list


? ? ? ? // 設(shè)置移動(dòng)的監(jiān)聽(tīng)事件? 返回 距終點(diǎn)的距離? 單位 米


? ? ? ? smoothMarker.setMoveListener(new SmoothMoveMarker.MoveListener() {


? ? ? ? ? ? @Override


? ? ? ? ? ? public void move(final double distance) {


? ? ? ? ? ? ? ? runOnUiThread(new Runnable() {


? ? ? ? ? ? ? ? ? ? @Override


? ? ? ? ? ? ? ? ? ? public void run() {


? ? ? ? ? ? ? ? ? ? ? ? //添加快進(jìn)按鈕,回放速度快進(jìn)一倍


? ? ? ? ? ? ? ? ? ? ? ? if (speed == 1) {


? ? ? ? ? ? ? ? ? ? ? ? ? ? if ((int) distance > 1500000) {


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(500);//設(shè)置平滑移動(dòng)的總時(shí)間


? ? ? ? ? ? ? ? ? ? ? ? ? ? }


? ? ? ? ? ? ? ? ? ? ? ? ? ? if ((int) distance < 1500000 && (int) distance > 100000) {


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(400);//設(shè)置平滑移動(dòng)的總時(shí)間


? ? ? ? ? ? ? ? ? ? ? ? ? ? }


? ? ? ? ? ? ? ? ? ? ? ? ? ? if ((int) distance < 100000 && (int) distance > 50000) {


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(250);//設(shè)置平滑移動(dòng)的總時(shí)間


? ? ? ? ? ? ? ? ? ? ? ? ? ? }


? ? ? ? ? ? ? ? ? ? ? ? ? ? if ((int) distance < 50000 && (int) distance > 10000) {


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(150);//設(shè)置平滑移動(dòng)的總時(shí)間


? ? ? ? ? ? ? ? ? ? ? ? ? ? }


? ? ? ? ? ? ? ? ? ? ? ? ? ? if ((int) distance < 10000) {


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(50);//設(shè)置平滑移動(dòng)的總時(shí)間


? ? ? ? ? ? ? ? ? ? ? ? ? ? }


? ? ? ? ? ? ? ? ? ? ? ? } else {


? ? ? ? ? ? ? ? ? ? ? ? ? ? //正?;胤潘俣?/p>


? ? ? ? ? ? ? ? ? ? ? ? ? ? if ((int) distance > 1500000) {


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(1000);//設(shè)置平滑移動(dòng)的總時(shí)間


? ? ? ? ? ? ? ? ? ? ? ? ? ? }


? ? ? ? ? ? ? ? ? ? ? ? ? ? if ((int) distance < 1500000 && (int) distance > 100000) {


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(800);//設(shè)置平滑移動(dòng)的總時(shí)間


? ? ? ? ? ? ? ? ? ? ? ? ? ? }


? ? ? ? ? ? ? ? ? ? ? ? ? ? if ((int) distance < 100000 && (int) distance > 50000) {


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(500);//設(shè)置平滑移動(dòng)的總時(shí)間


? ? ? ? ? ? ? ? ? ? ? ? ? ? }


? ? ? ? ? ? ? ? ? ? ? ? ? ? if ((int) distance < 50000 && (int) distance > 10000) {


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(300);//設(shè)置平滑移動(dòng)的總時(shí)間


? ? ? ? ? ? ? ? ? ? ? ? ? ? }


? ? ? ? ? ? ? ? ? ? ? ? ? ? if ((int) distance < 10000) {


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(100);//設(shè)置平滑移動(dòng)的總時(shí)間


? ? ? ? ? ? ? ? ? ? ? ? ? ? }


}


? ? ? ? ? ? ? ? ? ? ? ? if ((int) distance < 1) {


? ? ? ? ? ? ? ? ? ? ? ? ? ? play.setVisibility(View.VISIBLE);


? ? ? ? ? ? ? ? ? ? ? ? ? ? stop.setVisibility(View.GONE);


? ? ? ? ? ? ? ? ? ? ? ? ? ? tingzhi.setVisibility(View.VISIBLE);


? ? ? ? ? ? ? ? ? ? ? ? ? ? Fast_forward.setVisibility(View.GONE);


//? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? aMap.clear();


//? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? points.clear();


//? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? options.addAll(redpoints);


//? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? showline();


//? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? DeviceWorkTime();


? ? ? ? ? ? ? ? ? ? ? ? }


? ? ? ? ? ? ? ? ? ? ? ? //獲取當(dāng)前的移動(dòng)marker點(diǎn),設(shè)置地圖中心坐標(biāo)點(diǎn)


? ? ? ? ? ? ? ? ? ? ? ? LatLng position= smoothMarker.getPosition();


? ? ? ? ? ? ? ? ? ? ? ? aMap.moveCamera(CameraUpdateFactory.changeLatLng(position));


? ? ? ? ? ? ? ? ? ? ? ? redpoints.add(redpoints.size(), position);


//? ? ? ? ? ? ? ? ? ? ? ? ? ? options.addAll(redpoints);


//? ? ? ? ? ? ? ? ? ? ? ? ? ? options.add(position);


//? ? ? ? ? ? ? ? ? ? ? ? ? ? options.width(18);


//? ? ? ? ? ? ? ? ? ? ? ? ? ? options.useGradient(true);


//? ? ? ? ? ? ? ? ? ? ? ? ? ? options.color(Color.RED);


//? ? ? ? ? ? ? ? ? ? ? ? ? ? aMap.addPolyline(options);


? ? ? ? ? ? ? ? ? ? ? ? aMap.addPolyline(options.color(Color.RED) //setCustomTextureList(bitmapDescriptors)


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? .add(position)


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? .useGradient(true)


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? .visible(true)


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? .width(18));


}


? ? ? ? ? ? ? ? });


}


? ? ? ? });


? ? ? ? //設(shè)置地圖縮放比例


? ? ? ? aMap.moveCamera(CameraUpdateFactory.zoomTo(17));


? ? ? ? smoothMarker.startSmoothMove();


? ? ? ? smoothMarker.getMarker().setVisible(true);


}


? ? /*停止平滑移動(dòng)*/


? ? public void stopMove() {


? ? ? ? State = 2;


? ? ? ? playback = 2;


? ? ? ? smoothMarker.stopMove();


? ? ? ? LatLng position1= smoothMarker.getPosition();


? ? ? ? //暫停之后重新開(kāi)始回放,繼續(xù)之前的路徑


//? ? ? ? smoothMarker.startSmoothMove();


? ? ? ? play.setVisibility(View.VISIBLE);


? ? ? ? stop.setVisibility(View.GONE);


? ? ? ? tingzhi.setVisibility(View.VISIBLE);


? ? ? ? Fast_forward.setVisibility(View.GONE);


}


? ? /*繼續(xù)中斷的軌跡回放路線*/


? ? public void startmove() {


? ? ? ? State = 3;


? ? ? ? play.setVisibility(View.GONE);


? ? ? ? stop.setVisibility(View.VISIBLE);


? ? ? ? Fast_forward.setVisibility(View.VISIBLE);


? ? ? ? tingzhi.setVisibility(View.VISIBLE);


? ? ? ? smoothMarker.startSmoothMove();


}


? ? /*停止軌跡回放*/


? ? public void cease() {


? ? ? ? State = 4;


? ? ? ? playback = 3;


? ? ? ? smoothMarker.destroy();


? ? ? ? play.setVisibility(View.VISIBLE);


? ? ? ? stop.setVisibility(View.GONE);


? ? ? ? tingzhi.setVisibility(View.GONE);


? ? ? ? Fast_forward.setVisibility(View.GONE);


? ? ? ? aMap.clear();


? ? ? ? points.clear();


? ? ? ? DeviceWorkTime();


//? ? ? ? List colorList = new ArrayList();


//? ? ? ? aMap.addPolyline(options.setCustomTexture(BitmapDescriptorFactory.fromResource(R.drawable.custtexture)) //setCustomTextureList(bitmapDescriptors)


//? ? ? ? ? ? ? ? .addAll(points)


//? ? ? ? ? ? ? ? .useGradient(true)


//? ? ? ? ? ? ? ? .width(18));


? ? }


? ? /*添加線條*/


? ? private void addPolylineInPlayGround() {


? ? ? ? List list= points;


? ? ? ? List colorList= new ArrayList();


? ? ? ? aMap.addPolyline(new PolylineOptions().setCustomTexture(BitmapDescriptorFactory.fromResource(R.drawable.custtexture)) //setCustomTextureList(bitmapDescriptors)


? ? ? ? ? ? ? ? .addAll(list)


? ? ? ? ? ? ? ? .useGradient(true)


? ? ? ? ? ? ? ? .width(18));


}


? ? /*百度鷹眼接口返回經(jīng)緯度數(shù)據(jù)*/


? ? public void show(final String num, final String strttime, final String endtime) {


? ? ? ? new Thread() {


? ? ? ? ? ? @Override


? ? ? ? ? ? public void run() {


? ? ? ? ? ? ? ? progressDlgEx.simpleModeShowHandleThread();


? ? ? ? ? ? ? ? OkHttpClient okHttpClient= new OkHttpClient();


//這里是百度鷹眼的接口,為了不造成麻煩,我就不發(fā)出去了


? ? ? ? ? ? ? ? Request build1= new Request.Builder().url(format).build();


? ? ? ? ? ? ? ? okHttpClient.newCall(build1).enqueue(new Callback() {


? ? ? ? ? ? ? ? ? ? @Override


? ? ? ? ? ? ? ? ? ? public void onFailure(Call call, IOException e) {


}


? ? ? ? ? ? ? ? ? ? @Override


? ? ? ? ? ? ? ? ? ? public void onResponse(Call call, Response response) throws IOException {


? ? ? ? ? ? ? ? ? ? ? ? String string= response.body().string();


? ? ? ? ? ? ? ? ? ? ? ? if (string!= null) {


? ? ? ? ? ? ? ? ? ? ? ? ? ? try {


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? final JSONObject jsonObject= new JSONObject(string);


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? int status= jsonObject.getInt("status");


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if (status== 0) {


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? mHandler.post(new Runnable() {


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? @Override


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? public void run() {


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? try {


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? JSONArray pointss= jsonObject.getJSONArray("points");


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? final List listt= JsonUtils.parseJsonArray(pointss);


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? for (int i= 0; i< listt.size(); i++) {


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Map map= (Map) listt.get(i);


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? final double latitude= Double.parseDouble(map.get("latitude").toString());


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? final double longitude= Double.parseDouble(map.get("longitude").toString());


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? final String address= map.get("address").toString();


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? final int loc_time= Integer.parseInt(map.get("loc_time").toString());


//


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //添加經(jīng)緯度至數(shù)組,添加下標(biāo),防止新數(shù)據(jù)占用老數(shù)據(jù)位置


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? points.add(i, new LatLng(latitude, longitude));


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //添加海量marker點(diǎn)


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? MarkerOptions markerOption= new MarkerOptions();


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // markerOption.position(new LatLng(aLocation.getLatitude(), aLocation.getLongitude()));


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? markerOption.position(new LatLng(latitude, longitude));


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? markerOption.visible(true);//標(biāo)記可見(jiàn)


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? markerOption.icon(


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? BitmapDescriptorFactory.fromBitmap(BitmapFactory


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? .decodeResource(getResources(),


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? R.drawable.marker_blue)));


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? markerOption.anchor(0.5f, 0.5f);


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Marker marker= aMap.addMarker(markerOption);


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // marker.setIcon();


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? marker.setObject(map);// 這里可以存儲(chǔ)用戶數(shù)據(jù)


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? listMarker.add(marker);


}


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? showline();


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? } catch (JSONException e) {


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? e.printStackTrace();


}


}


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? });


}


? ? ? ? ? ? ? ? ? ? ? ? ? ? } catch (JSONException e) {


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? e.printStackTrace();


? ? ? ? ? ? ? ? ? ? ? ? ? ? } finally {


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? progressDlgEx.closeHandleThread();


}


}


}


? ? ? ? ? ? ? ? });


}


? ? ? ? }.start();


}


? ? /**


? ? * 點(diǎn)擊Marker


*/


? ? public boolean onMarkerClick(Marker arg0) {


? ? ? ? // TODO Auto-generated method stub


? ? ? ? // String streenName = "中山路";


? ? ? ? Map map= (Map) arg0.getObject();


? ? ? ? final double latitude= Double.parseDouble(map.get("latitude").toString());


? ? ? ? final double longitude= Double.parseDouble(map.get("longitude").toString());


? ? ? ? final String address= map.get("address").toString();


? ? ? ? final int loc_time= Integer.parseInt(map.get("loc_time").toString());


//? ? ? ? arg0.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.purple_pin));


? ? ? ? arg0.setTitle("詳細(xì)信息");


? ? ? ? ShowSensor(String.valueOf(loc_time), latitude, longitude, address);


? ? ? ? return false;


}


? ? @Override


? ? public void onClick(View v) {


? ? ? ? switch (v.getId()) {


? ? ? ? ? ? case R.id.Fast_forward:


? ? ? ? ? ? ? ? DialogUtils.showPopMsgInHandleThread(MapActivity.this, mHandler, "快進(jìn)一倍回放!");


? ? ? ? ? ? ? ? Fast_forward.setVisibility(View.GONE);


? ? ? ? ? ? ? ? speed = 1;


? ? ? ? ? ? ? ? break;


? ? ? ? ? ? case R.id.back:


? ? ? ? ? ? ? ? finish();


? ? ? ? ? ? ? ? points.clear();


? ? ? ? ? ? ? ? break;


? ? ? ? ? ? case R.id.play:


? ? ? ? ? ? ? ? if (points.size() < 1) {


? ? ? ? ? ? ? ? ? ? Toast.makeText(MapActivity.this, MapActivity.this.getString(R.string.zwjl), Toast.LENGTH_SHORT).show();


? ? ? ? ? ? ? ? } else {


? ? ? ? ? ? ? ? ? ? if (playback == 1) {


? ? ? ? ? ? ? ? ? ? ? ? DialogUtils.showPopMsgInHandleThread(MapActivity.this, mHandler, "請(qǐng)先停止軌跡回放路線!");


? ? ? ? ? ? ? ? ? ? ? ? return;


? ? ? ? ? ? ? ? ? ? } else {


? ? ? ? ? ? ? ? ? ? ? ? DialogUtils.showPopMsgInHandleThread(MapActivity.this, mHandler, "開(kāi)始回放軌跡路線!");


? ? ? ? ? ? ? ? ? ? ? ? speed = 0;


? ? ? ? ? ? ? ? ? ? ? ? if (State == 2) {


? ? ? ? ? ? ? ? ? ? ? ? ? ? startmove();


? ? ? ? ? ? ? ? ? ? ? ? } else {


? ? ? ? ? ? ? ? ? ? ? ? ? ? startMove();


}


}


}


? ? ? ? ? ? ? ? break;


? ? ? ? ? ? case R.id.stop:


? ? ? ? ? ? ? ? DialogUtils.showPopMsgInHandleThread(MapActivity.this, mHandler, "暫停軌跡回放!");


? ? ? ? ? ? ? ? speed = 0;


? ? ? ? ? ? ? ? stopMove();


? ? ? ? ? ? ? ? break;


? ? ? ? ? ? case R.id.tingzhi:


? ? ? ? ? ? ? ? DialogUtils.showPopMsgInHandleThread(MapActivity.this, mHandler, "停止軌跡回放!");


? ? ? ? ? ? ? ? cease();


? ? ? ? ? ? ? ? break;


? ? ? ? ? ? case R.id.massage:


? ? ? ? ? ? ? ? if (points.size() < 1) {


? ? ? ? ? ? ? ? ? ? Toast.makeText(MapActivity.this, MapActivity.this.getString(R.string.zwjl), Toast.LENGTH_SHORT).show();


? ? ? ? ? ? ? ? } else {


? ? ? ? ? ? ? ? ? ? if (popupWindow != null && popupWindow.isShowing()) {


? ? ? ? ? ? ? ? ? ? ? ? return;


}


? ? ? ? ? ? ? ? ? ? LinearLayout layout= (LinearLayout) getLayoutInflater().inflate(R.layout.map_pop, null);


? ? ? ? ? ? ? ? ? ? popupWindow = new PopupWindow(layout, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);


? ? ? ? ? ? ? ? ? ? //點(diǎn)擊空白處時(shí),隱藏掉pop窗口


? ? ? ? ? ? ? ? ? ? popupWindow.setFocusable(true);


? ? ? ? ? ? ? ? ? ? popupWindow.setBackgroundDrawable(new BitmapDrawable());


? ? ? ? ? ? ? ? ? ? //添加彈出、彈入的動(dòng)畫(huà)


? ? ? ? ? ? ? ? ? ? popupWindow.setAnimationStyle(R.style.Popupwindow);


? ? ? ? ? ? ? ? ? ? int[] location= new int[2];


? ? ? ? ? ? ? ? ? ? massage.getLocationOnScreen(location);


? ? ? ? ? ? ? ? ? ? popupWindow.showAtLocation(massage, Gravity.CENTER | Gravity.BOTTOM, 0, -location[1]);


? ? ? ? ? ? ? ? ? ? //添加按鍵事件監(jiān)聽(tīng)


? ? ? ? ? ? ? ? ? ? //setButtonListeners(layout);


? ? ? ? ? ? ? ? ? ? //添加pop窗口關(guān)閉事件,主要是實(shí)現(xiàn)關(guān)閉時(shí)改變背景的透明度


? ? ? ? ? ? ? ? ? ? //popupWindow.setOnDismissListener(new poponDismissListener());


//backgroundAlpha(1f);


? ? ? ? ? ? ? ? ? ? linear3 = (LinearLayout) layout.findViewById(R.id.linear3);


? ? ? ? ? ? ? ? ? ? for (int i= 0; i< Data.getInstance().list.size(); i++) {


? ? ? ? ? ? ? ? ? ? ? ? Map map= (Map) Data.getInstance().list.get(i);


? ? ? ? ? ? ? ? ? ? ? ? String boxmac= map.get("boxmac").toString();


? ? ? ? ? ? ? ? ? ? ? ? int startdate= Integer.parseInt(map.get("startdate").toString());


? ? ? ? ? ? ? ? ? ? ? ? int enddate= Integer.parseInt(map.get("enddate").toString());


? ? ? ? ? ? ? ? ? ? ? ? SplitTime(boxmac, startdate, enddate);


? ? ? ? ? ? ? ? ? ? ? ? Log.e("TAG", boxmac+ startdate+ enddate);


}


}


? ? ? ? ? ? ? ? break;


? ? ? ? ? ? default:


? ? ? ? ? ? ? ? break;


}


}


}


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容