|
|
|
@ -13,6 +13,7 @@ import android.content.Context;
|
|
|
|
|
import android.Manifest;
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.graphics.Bitmap;
|
|
|
|
|
import android.graphics.BitmapFactory;
|
|
|
|
|
import android.location.Location;
|
|
|
|
|
import android.nfc.Tag;
|
|
|
|
@ -108,10 +109,11 @@ public class MainActivity extends AppCompatActivity implements AMapLocationList
|
|
|
|
|
//private ActivityResultLauncher<Intent> launcher;
|
|
|
|
|
|
|
|
|
|
////////////////////////////可修改部分/////////////////////////////
|
|
|
|
|
private final LatLng Monitorlatlng = new LatLng(28.258348849051746,113.04552182879037);
|
|
|
|
|
private final LatLng Monitorlatlng = new LatLng(28.257553,113.0417);
|
|
|
|
|
|
|
|
|
|
private final static String Recieve_IP = "192.168.39.46";
|
|
|
|
|
private final static int RECEIVE_PORT = 9987;
|
|
|
|
|
private final static String SEND_to_IP = "192.168.39.47";
|
|
|
|
|
private final static int RECEIVE_PORT = 9975;
|
|
|
|
|
private final static String SEND_to_IP = "192.168.39.195";
|
|
|
|
|
private final static int SEND_PORT = 8888;
|
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
|
private InetAddress serverAddr;
|
|
|
|
@ -126,6 +128,7 @@ public class MainActivity extends AppCompatActivity implements AMapLocationList
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
setContentView(R.layout.activity_main);
|
|
|
|
|
|
|
|
|
|
if (savedInstanceState != null) {
|
|
|
|
|
// 从保存的状态数据中恢复状态
|
|
|
|
|
value = savedInstanceState.getString("key");
|
|
|
|
@ -145,9 +148,10 @@ public class MainActivity extends AppCompatActivity implements AMapLocationList
|
|
|
|
|
//检查安卓版本
|
|
|
|
|
checkingAndroidVersion();
|
|
|
|
|
|
|
|
|
|
udpReceiveThread = new UdpReceiveThread();
|
|
|
|
|
udpReceiveThread.startListening();
|
|
|
|
|
|
|
|
|
|
addSensorMarker(Monitorlatlng);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 检查Android版本
|
|
|
|
@ -248,7 +252,7 @@ public class MainActivity extends AppCompatActivity implements AMapLocationList
|
|
|
|
|
// 设置为true表示显示定位层并可触发定位,false表示隐藏定位层并不可触发定位,默认是false
|
|
|
|
|
aMap.setMyLocationEnabled(true);
|
|
|
|
|
//设置最小缩放等级为16 ,缩放级别范围为[3, 20]
|
|
|
|
|
aMap.setMinZoomLevel(18);
|
|
|
|
|
aMap.setMinZoomLevel(14);
|
|
|
|
|
//设置地图标志点击事件
|
|
|
|
|
aMap.setOnMarkerClickListener(this);
|
|
|
|
|
//设置地图标志拖拽事件
|
|
|
|
@ -302,7 +306,10 @@ public class MainActivity extends AppCompatActivity implements AMapLocationList
|
|
|
|
|
city = aMapLocation.getCity();
|
|
|
|
|
//当前位置经纬度坐标
|
|
|
|
|
Current_latlng = new LatLng(aMapLocation.getLatitude(), aMapLocation.getLongitude());
|
|
|
|
|
|
|
|
|
|
MonitorDistance = AMapUtils.calculateLineDistance(Current_latlng,Monitorlatlng);
|
|
|
|
|
Log.i(TAG, String.valueOf(Current_latlng.longitude));
|
|
|
|
|
Log.i(TAG, String.valueOf(Current_latlng.latitude));
|
|
|
|
|
//
|
|
|
|
|
//获取纬度
|
|
|
|
|
double latitude = aMapLocation.getLatitude();
|
|
|
|
|
//获取经度
|
|
|
|
@ -310,6 +317,8 @@ public class MainActivity extends AppCompatActivity implements AMapLocationList
|
|
|
|
|
|
|
|
|
|
Log.d("MainActivity", aMapLocation.getCity());
|
|
|
|
|
showMsg(address);
|
|
|
|
|
udpReceiveThread = new UdpReceiveThread();
|
|
|
|
|
udpReceiveThread.startListening();
|
|
|
|
|
//停止定位后,本地定位服务并不会被销毁
|
|
|
|
|
mLocationClient.stopLocation();
|
|
|
|
|
if (mListener != null) {
|
|
|
|
@ -391,7 +400,7 @@ public class MainActivity extends AppCompatActivity implements AMapLocationList
|
|
|
|
|
.draggable(true)
|
|
|
|
|
//标点图标
|
|
|
|
|
.icon(BitmapDescriptorFactory.
|
|
|
|
|
fromBitmap(BitmapFactory.decodeResource(getResources(),R.drawable.img)))
|
|
|
|
|
fromBitmap(BitmapFactory.decodeResource(getResources(),R.drawable.weizhi)))
|
|
|
|
|
//备注
|
|
|
|
|
.title("路径点")
|
|
|
|
|
.snippet("距离:")
|
|
|
|
@ -435,7 +444,7 @@ public class MainActivity extends AppCompatActivity implements AMapLocationList
|
|
|
|
|
fromBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.drone)))
|
|
|
|
|
// 备注
|
|
|
|
|
.title("无人机")
|
|
|
|
|
.snippet("距离:")
|
|
|
|
|
|
|
|
|
|
);
|
|
|
|
|
droneMarker.showInfoWindow();
|
|
|
|
|
}
|
|
|
|
@ -631,14 +640,32 @@ public class MainActivity extends AppCompatActivity implements AMapLocationList
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ReceiveHandler extends Handler{
|
|
|
|
|
@Override
|
|
|
|
|
public void handleMessage(Message msg) {
|
|
|
|
|
if (msg.what == 1) {
|
|
|
|
|
runOnUiThread(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
Context context = MainActivity.this;
|
|
|
|
|
showAlert(context,"传感器报警");
|
|
|
|
|
addDroneMarker();
|
|
|
|
|
moveDrone();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class UdpReceiveThread extends Thread {
|
|
|
|
|
private static final String TAG = "UdpReceiveThread";
|
|
|
|
|
private static final int mRECEIVE_PORT = RECEIVE_PORT;
|
|
|
|
|
private boolean mRunning;
|
|
|
|
|
private boolean mRunning = true;
|
|
|
|
|
private String mReceiveIp = Recieve_IP;
|
|
|
|
|
private String mExpectedData = "Motion detected!";
|
|
|
|
|
private float udpMonitorDistance = MonitorDistance;
|
|
|
|
|
private String udpMonitorAngle = MonitorAngle;
|
|
|
|
|
private Handler receiveHandler = new ReceiveHandler();
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
@ -654,11 +681,9 @@ public class MainActivity extends AppCompatActivity implements AMapLocationList
|
|
|
|
|
Log.d(TAG, "Received data: " + receivedString);
|
|
|
|
|
if (receivedString.equals(mExpectedData)) {
|
|
|
|
|
Log.i(TAG, "run: 222222222222222222222222222");
|
|
|
|
|
receiveHandler.sendEmptyMessage(1);
|
|
|
|
|
sendCommand("WARNING "+String.valueOf(udpMonitorDistance)+" "+udpMonitorAngle);
|
|
|
|
|
Context context = MainActivity.this;
|
|
|
|
|
showAlert(context,"传感器报警");
|
|
|
|
|
addDroneMarker();
|
|
|
|
|
moveDrone();
|
|
|
|
|
|
|
|
|
|
mRunning = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -672,6 +697,16 @@ public class MainActivity extends AppCompatActivity implements AMapLocationList
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public void startListening() {
|
|
|
|
|
mRunning = true;
|
|
|
|
|
start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void stopListening() {
|
|
|
|
|
mRunning = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void showAlert(Context context, String message) {
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
|
|
|
|
builder.setTitle("警告");
|
|
|
|
@ -683,16 +718,6 @@ public class MainActivity extends AppCompatActivity implements AMapLocationList
|
|
|
|
|
dialog.show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void startListening() {
|
|
|
|
|
mRunning = true;
|
|
|
|
|
start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void stopListening() {
|
|
|
|
|
mRunning = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//以北为0度
|
|
|
|
|
public static String calcAngle(Double centerLat, Double centerLon, Double anotherLat, Double anotherLon) {
|
|
|
|
|
//差值
|
|
|
|
|