|
|
|
@ -2,6 +2,10 @@ package com.example.sixaunyi;
|
|
|
|
|
|
|
|
|
|
import static androidx.constraintlayout.motion.utils.Oscillator.TAG;
|
|
|
|
|
|
|
|
|
|
import androidx.activity.result.ActivityResult;
|
|
|
|
|
import androidx.activity.result.ActivityResultCallback;
|
|
|
|
|
import androidx.activity.result.ActivityResultLauncher;
|
|
|
|
|
import androidx.activity.result.contract.ActivityResultContracts;
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
|
|
|
|
|
|
import android.app.AlertDialog;
|
|
|
|
@ -9,6 +13,7 @@ import android.app.Dialog;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
|
import android.content.res.TypedArray;
|
|
|
|
|
import android.graphics.Bitmap;
|
|
|
|
|
import android.graphics.BitmapFactory;
|
|
|
|
@ -56,6 +61,7 @@ public class VideoActivity extends AppCompatActivity {
|
|
|
|
|
private final static String Recieve_IP = "192.168.39.47";//填服务器IP,与send_to_IP为同一个
|
|
|
|
|
private final static int SEND_PORT = 8888; //发送端口号
|
|
|
|
|
private final static int RECEIVE_PORT = 9999; //接收端口号
|
|
|
|
|
private static final int REQUEST_CODE = 1;
|
|
|
|
|
private static boolean listenStatus = true; //接收线程的循环标识
|
|
|
|
|
private byte[] buf;
|
|
|
|
|
static Bitmap bp;
|
|
|
|
@ -86,9 +92,13 @@ public class VideoActivity extends AppCompatActivity {
|
|
|
|
|
private UdpDataThread warning_thread;
|
|
|
|
|
private TextView battery_warning;
|
|
|
|
|
private ImageButton show_status;
|
|
|
|
|
private String value;
|
|
|
|
|
private String batteryStatus="未获取";
|
|
|
|
|
private String speedStatus="未获取";
|
|
|
|
|
private String distanceStatus="未获取";
|
|
|
|
|
private ActivityResultLauncher<Intent> launcher;
|
|
|
|
|
private int batteryNum;
|
|
|
|
|
private SharedPreferences sharedPreferences;
|
|
|
|
|
//ReceiveData()显示到imageView
|
|
|
|
|
//manager部分:打开线程,接收
|
|
|
|
|
//model部分:发送视频流
|
|
|
|
@ -113,15 +123,40 @@ public class VideoActivity extends AppCompatActivity {
|
|
|
|
|
battery_warning =findViewById(R.id.warning);
|
|
|
|
|
show_status=findViewById(R.id.show_status_button);
|
|
|
|
|
battery_warning.setTextColor(Color.RED);
|
|
|
|
|
sharedPreferences = getSharedPreferences("battery", MODE_PRIVATE);
|
|
|
|
|
batteryNum = sharedPreferences.getInt("battery_num", 0);
|
|
|
|
|
launcher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(),
|
|
|
|
|
new ActivityResultCallback<ActivityResult>() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onActivityResult(ActivityResult result) {
|
|
|
|
|
int resultCode = result.getResultCode();
|
|
|
|
|
Intent data = result.getData();
|
|
|
|
|
if (resultCode == RESULT_OK) {
|
|
|
|
|
if (data != null) {
|
|
|
|
|
batteryNum = data.getIntExtra("BATTERY_NUM", 0);
|
|
|
|
|
SharedPreferences.Editor editor = sharedPreferences.edit();
|
|
|
|
|
editor.putInt("battery_num", batteryNum);
|
|
|
|
|
editor.apply();
|
|
|
|
|
if (batteryStatus.compareTo(String.valueOf(batteryNum))<0 || batteryStatus.equals(String.valueOf(batteryNum))) {
|
|
|
|
|
battery_warning.setText("电量不足,当前值:"+batteryStatus);}else{
|
|
|
|
|
battery_warning.setText("");
|
|
|
|
|
}
|
|
|
|
|
Log.i(TAG, "2222222222222222222222"+String.valueOf(batteryNum));
|
|
|
|
|
|
|
|
|
|
// 根据需求处理返回的参数
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 在此处理子 Activity 返回的结果
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
Animation anim = new AlphaAnimation(0.0f, 1.0f);
|
|
|
|
|
anim.setDuration(500); // 闪烁时间间隔
|
|
|
|
|
anim.setStartOffset(20);
|
|
|
|
|
anim.setRepeatMode(Animation.REVERSE);
|
|
|
|
|
anim.setRepeatCount(Animation.INFINITE);
|
|
|
|
|
battery_warning.startAnimation(anim);
|
|
|
|
|
Intent i = getIntent();
|
|
|
|
|
mdistance = i.getFloatExtra("Distance",0);
|
|
|
|
|
mangle = i.getStringExtra("Angle");
|
|
|
|
|
warning_thread = new UdpDataThread();
|
|
|
|
|
warning_thread.start();
|
|
|
|
|
try {
|
|
|
|
@ -253,7 +288,7 @@ public class VideoActivity extends AppCompatActivity {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
Intent intent = new Intent(VideoActivity.this, SettingActivity.class);
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
launcher.launch(intent);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
@ -431,8 +466,8 @@ public class VideoActivity extends AppCompatActivity {
|
|
|
|
|
batteryStatus = jsonObject.getString("battery");
|
|
|
|
|
speedStatus = jsonObject.getString("speed");
|
|
|
|
|
distanceStatus = jsonObject.getString("distance");
|
|
|
|
|
if (batteryStatus.equals("10")) {
|
|
|
|
|
battery_warning.setText("电量仅剩"+batteryStatus);}else{
|
|
|
|
|
if (batteryStatus.compareTo(String.valueOf(batteryNum))<0 || batteryStatus.equals(String.valueOf(batteryNum))) {
|
|
|
|
|
battery_warning.setText("电量不足,当前值:"+batteryStatus);}else{
|
|
|
|
|
battery_warning.setText("");
|
|
|
|
|
}
|
|
|
|
|
System.out.println("接收到数据:" + batteryStatus);
|
|
|
|
@ -475,43 +510,8 @@ public class VideoActivity extends AppCompatActivity {
|
|
|
|
|
AlertDialog dialog = builder.create();
|
|
|
|
|
dialog.show();
|
|
|
|
|
}
|
|
|
|
|
//初始化UDP发送线程
|
|
|
|
|
// private static void sendCommand(String Sendstr) throws UnknownHostException {
|
|
|
|
|
// InetAddress sendIP = InetAddress.getByName(SEND_to_IP); // 目标 IP 地址
|
|
|
|
|
// int sendPort = 8888; // 目标端口号
|
|
|
|
|
// byte[] sendData = Sendstr.getBytes(); // 要发送的数据
|
|
|
|
|
// UdpSendThread sendCommandThread = new UdpSendThread(sendIP, sendPort, sendData); // 创建新的线程对象
|
|
|
|
|
// sendCommandThread.start(); // 启动线程发送数据
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//设置按钮
|
|
|
|
|
// public void showDialog(View view) {
|
|
|
|
|
// Dialog dialog = new Dialog(VideoActivity.this);
|
|
|
|
|
// dialog.setContentView(R.layout.dialog_takeoff);
|
|
|
|
|
//
|
|
|
|
|
// SlideUnlockView slideUnlockView = (SlideUnlockView) dialog.findViewById(R.id.slide_unlock_view);
|
|
|
|
|
// slideUnlockView.setOnUnlockListener(new SlideUnlockView.OnUnlockListener() {
|
|
|
|
|
// @Override
|
|
|
|
|
// public void onUnlock() {
|
|
|
|
|
// // 在用户滑动解锁后执行操作
|
|
|
|
|
//// try {
|
|
|
|
|
//// sendCommand("TAKEOFF"+"___"+angle+"___"+String.valueOf(distance));
|
|
|
|
|
//// } catch (UnknownHostException e) {
|
|
|
|
|
//// throw new RuntimeException(e);
|
|
|
|
|
//// }
|
|
|
|
|
// UdpReceiveThread udpReceiveThread = new UdpReceiveThread();
|
|
|
|
|
// udpReceiveThread.start();
|
|
|
|
|
//
|
|
|
|
|
// Log.i(TAG, "onClick: 2222222222222222222222222");
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
// dialog.show();
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////滑动开关//////////////////////////////
|
|
|
|
|
public static class SlideUnlockView extends View{
|
|
|
|
|
|
|
|
|
|