|
|
@ -3,6 +3,9 @@ package com.example.sixaunyi;
|
|
|
|
import static androidx.constraintlayout.motion.utils.Oscillator.TAG;
|
|
|
|
import static androidx.constraintlayout.motion.utils.Oscillator.TAG;
|
|
|
|
|
|
|
|
|
|
|
|
import static java.lang.Math.PI;
|
|
|
|
import static java.lang.Math.PI;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.activity.result.ActivityResultLauncher;
|
|
|
|
|
|
|
|
import androidx.activity.result.contract.ActivityResultContracts;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.app.AlertDialog;
|
|
|
@ -19,6 +22,7 @@ import android.os.Handler;
|
|
|
|
import android.os.Message;
|
|
|
|
import android.os.Message;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.View;
|
|
|
|
|
|
|
|
import android.widget.ImageButton;
|
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.Toast;
|
|
|
|
import android.widget.Toast;
|
|
|
|
import android.animation.Animator;
|
|
|
|
import android.animation.Animator;
|
|
|
@ -92,14 +96,17 @@ public class MainActivity extends AppCompatActivity implements AMapLocationList
|
|
|
|
//浮动按钮 清空地图标点
|
|
|
|
//浮动按钮 清空地图标点
|
|
|
|
private FloatingActionButton ClearMarker_btn;
|
|
|
|
private FloatingActionButton ClearMarker_btn;
|
|
|
|
//浮动按钮 更换活动
|
|
|
|
//浮动按钮 更换活动
|
|
|
|
private FloatingActionButton ChangeAct_btn;
|
|
|
|
private ImageButton ChangeAct_btn;
|
|
|
|
//标点列表
|
|
|
|
//标点列表
|
|
|
|
private List<Marker> markerList = new ArrayList<>();
|
|
|
|
private List<Marker> markerList = new ArrayList<>();
|
|
|
|
//标识参数类
|
|
|
|
//标识参数类
|
|
|
|
private MarkerOptions markerOption = new MarkerOptions();
|
|
|
|
private MarkerOptions markerOption = new MarkerOptions();
|
|
|
|
//
|
|
|
|
//
|
|
|
|
private DatagramSocket reveSocket;
|
|
|
|
private DatagramSocket reveSocket;
|
|
|
|
|
|
|
|
private String value;
|
|
|
|
private ExecutorService mThreadPool = Executors.newCachedThreadPool();
|
|
|
|
private ExecutorService mThreadPool = Executors.newCachedThreadPool();
|
|
|
|
|
|
|
|
//private ActivityResultLauncher<Intent> launcher;
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////可修改部分/////////////////////////////
|
|
|
|
////////////////////////////可修改部分/////////////////////////////
|
|
|
|
private final LatLng Monitorlatlng = new LatLng(28.258348849051746,113.04552182879037);
|
|
|
|
private final LatLng Monitorlatlng = new LatLng(28.258348849051746,113.04552182879037);
|
|
|
|
private final static String Recieve_IP = "192.168.39.46";
|
|
|
|
private final static String Recieve_IP = "192.168.39.46";
|
|
|
@ -119,14 +126,19 @@ public class MainActivity extends AppCompatActivity implements AMapLocationList
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_main);
|
|
|
|
setContentView(R.layout.activity_main);
|
|
|
|
fabPOI = findViewById(R.id.fab_poi);
|
|
|
|
if (savedInstanceState != null) {
|
|
|
|
|
|
|
|
// 从保存的状态数据中恢复状态
|
|
|
|
|
|
|
|
value = savedInstanceState.getString("key");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ClearMarker_btn = findViewById(R.id.clearMarker_btn);
|
|
|
|
ClearMarker_btn = findViewById(R.id.clearMarker_btn);
|
|
|
|
ChangeAct_btn = findViewById(R.id.change_btn);
|
|
|
|
ChangeAct_btn = findViewById(R.id.change_btn);
|
|
|
|
ChangeAct_btn.show();
|
|
|
|
ChangeAct_btn.setOnClickListener(new View.OnClickListener() {
|
|
|
|
//tvContent = findViewById(R.id.tv_content);
|
|
|
|
@Override
|
|
|
|
/*初始化定位,需要在检查版本之前
|
|
|
|
public void onClick(View v) {
|
|
|
|
*因为配置好之后才能启动定位,否则会报错
|
|
|
|
changeAct();
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
initLocation();
|
|
|
|
initLocation();
|
|
|
|
//初始化地图
|
|
|
|
//初始化地图
|
|
|
|
initMap(savedInstanceState);
|
|
|
|
initMap(savedInstanceState);
|
|
|
@ -235,6 +247,8 @@ public class MainActivity extends AppCompatActivity implements AMapLocationList
|
|
|
|
aMap.setLocationSource(this);
|
|
|
|
aMap.setLocationSource(this);
|
|
|
|
// 设置为true表示显示定位层并可触发定位,false表示隐藏定位层并不可触发定位,默认是false
|
|
|
|
// 设置为true表示显示定位层并可触发定位,false表示隐藏定位层并不可触发定位,默认是false
|
|
|
|
aMap.setMyLocationEnabled(true);
|
|
|
|
aMap.setMyLocationEnabled(true);
|
|
|
|
|
|
|
|
//设置最小缩放等级为16 ,缩放级别范围为[3, 20]
|
|
|
|
|
|
|
|
aMap.setMinZoomLevel(18);
|
|
|
|
//设置地图标志点击事件
|
|
|
|
//设置地图标志点击事件
|
|
|
|
aMap.setOnMarkerClickListener(this);
|
|
|
|
aMap.setOnMarkerClickListener(this);
|
|
|
|
//设置地图标志拖拽事件
|
|
|
|
//设置地图标志拖拽事件
|
|
|
@ -288,7 +302,7 @@ public class MainActivity extends AppCompatActivity implements AMapLocationList
|
|
|
|
city = aMapLocation.getCity();
|
|
|
|
city = aMapLocation.getCity();
|
|
|
|
//当前位置经纬度坐标
|
|
|
|
//当前位置经纬度坐标
|
|
|
|
Current_latlng = new LatLng(aMapLocation.getLatitude(), aMapLocation.getLongitude());
|
|
|
|
Current_latlng = new LatLng(aMapLocation.getLatitude(), aMapLocation.getLongitude());
|
|
|
|
MonitorDistance = AMapUtils.calculateLineDistance(Current_latlng,Monitorlatlng);
|
|
|
|
|
|
|
|
//获取纬度
|
|
|
|
//获取纬度
|
|
|
|
double latitude = aMapLocation.getLatitude();
|
|
|
|
double latitude = aMapLocation.getLatitude();
|
|
|
|
//获取经度
|
|
|
|
//获取经度
|
|
|
@ -331,6 +345,7 @@ public class MainActivity extends AppCompatActivity implements AMapLocationList
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onSaveInstanceState(Bundle outState) {
|
|
|
|
protected void onSaveInstanceState(Bundle outState) {
|
|
|
|
super.onSaveInstanceState(outState);
|
|
|
|
super.onSaveInstanceState(outState);
|
|
|
|
|
|
|
|
outState.putString("key", value);
|
|
|
|
//在activity执行onSaveInstanceState时执行mMapView.onSaveInstanceState (outState),保存地图当前的状态
|
|
|
|
//在activity执行onSaveInstanceState时执行mMapView.onSaveInstanceState (outState),保存地图当前的状态
|
|
|
|
mapView.onSaveInstanceState(outState);
|
|
|
|
mapView.onSaveInstanceState(outState);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -391,7 +406,6 @@ public class MainActivity extends AppCompatActivity implements AMapLocationList
|
|
|
|
|
|
|
|
|
|
|
|
private void addSensorMarker(LatLng latLng) {
|
|
|
|
private void addSensorMarker(LatLng latLng) {
|
|
|
|
// 显示浮动按钮
|
|
|
|
// 显示浮动按钮
|
|
|
|
|
|
|
|
|
|
|
|
// 添加传感器标点
|
|
|
|
// 添加传感器标点
|
|
|
|
MarkerOptions sensorMarkerOption = new MarkerOptions();
|
|
|
|
MarkerOptions sensorMarkerOption = new MarkerOptions();
|
|
|
|
sensorMarker = aMap.addMarker(sensorMarkerOption
|
|
|
|
sensorMarker = aMap.addMarker(sensorMarkerOption
|
|
|
@ -402,7 +416,6 @@ public class MainActivity extends AppCompatActivity implements AMapLocationList
|
|
|
|
fromBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.sensor)))
|
|
|
|
fromBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.sensor)))
|
|
|
|
// 备注
|
|
|
|
// 备注
|
|
|
|
.title("传感器")
|
|
|
|
.title("传感器")
|
|
|
|
.snippet("距离:")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
);
|
|
|
|
);
|
|
|
|
sensorMarker.showInfoWindow();
|
|
|
|
sensorMarker.showInfoWindow();
|
|
|
@ -524,16 +537,16 @@ public class MainActivity extends AppCompatActivity implements AMapLocationList
|
|
|
|
moveUtil.moveDroneMarker(Monitorlatlng,time);
|
|
|
|
moveUtil.moveDroneMarker(Monitorlatlng,time);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void changeAct(View view) {
|
|
|
|
public void changeAct() {
|
|
|
|
udpReceiveThread.stopListening();
|
|
|
|
udpReceiveThread.stopListening();
|
|
|
|
Intent intent = new Intent(MainActivity.this, VideoActivity.class);
|
|
|
|
Intent intent = new Intent(MainActivity.this, VideoActivity.class);
|
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
|
|
|
|
|
|
Bundle b = new Bundle();
|
|
|
|
Bundle b = new Bundle();
|
|
|
|
b.putString("Angle", MonitorAngle);
|
|
|
|
b.putString("Angle", MonitorAngle);
|
|
|
|
b.putFloat("Distance", MonitorDistance);
|
|
|
|
b.putFloat("Distance", MonitorDistance);
|
|
|
|
intent.putExtras(b);
|
|
|
|
intent.putExtras(b);
|
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
|
|
|
|
int requestCode = 1; // 可以是任何非负整数
|
|
|
|
startActivity(intent);
|
|
|
|
startActivity(intent);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|