parent
205f5563d5
commit
7bff3f6be8
@ -1,14 +1,84 @@
|
||||
package com.example.sixaunyi;
|
||||
|
||||
import static androidx.constraintlayout.motion.utils.Oscillator.TAG;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.SeekBar;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
public class SettingActivity extends AppCompatActivity {
|
||||
|
||||
private final static String SEND_to_IP = "192.168.39.47";
|
||||
private SeekBar Speed_btn;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_setting);
|
||||
Speed_btn= findViewById(R.id.speed);
|
||||
Speed_btn.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
int speed=progress+10;
|
||||
String s = "SPEED " + Integer.toString(speed);
|
||||
try {
|
||||
InitUdpSend(s);
|
||||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {}
|
||||
});
|
||||
}
|
||||
/*
|
||||
* UDP数据发送线程
|
||||
* */
|
||||
public static class UdpSendThread extends Thread {
|
||||
|
||||
private InetAddress sendToIP; // 目标 IP 地址
|
||||
private int sendPort; // 目标端口号
|
||||
private byte[] sendData; // 要发送的数据
|
||||
|
||||
public UdpSendThread(InetAddress sendToIP, int sendPort, byte[] sendData) {
|
||||
this.sendToIP = sendToIP;
|
||||
this.sendPort = sendPort;
|
||||
this.sendData = sendData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
DatagramSocket sendSocket = new DatagramSocket(); // 创建一个新的 DatagramSocket 对象
|
||||
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, sendToIP, sendPort); // 将要发送的数据打包成一个 DatagramPacket 对象
|
||||
sendSocket.send(sendPacket); // 发送 DatagramPacket
|
||||
sendSocket.close(); // 发送完毕后关闭 DatagramSocket
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
private static void InitUdpSend(String Sendstr) throws UnknownHostException {
|
||||
InetAddress sendIP = InetAddress.getByName(SEND_to_IP); // 目标 IP 地址
|
||||
int sendPort = 8888; // 目标端口号
|
||||
byte[] sendData = Sendstr.getBytes(); // 要发送的数据
|
||||
VideoActivity.UdpSendThread sendThread = new VideoActivity.UdpSendThread(sendIP, sendPort, sendData); // 创建新的线程对象
|
||||
sendThread.start(); // 启动线程发送数据
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#80000000" />
|
||||
|
||||
<!-- 这里是其他控件 -->
|
||||
<LinearLayout
|
||||
android:layout_width="414dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="right"
|
||||
android:background="#80FFFFFF"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<Switch
|
||||
android:id="@+id/switch1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:text="飞行速度(高)"
|
||||
android:textSize="28dp" />
|
||||
|
||||
<Switch
|
||||
android:id="@+id/switch2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="图像高画质"
|
||||
android:textSize="28dp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="低电量预警"
|
||||
android:textSize="28dp" />
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/seekBar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:thumbTint='@color/teal_200' />
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
Loading…
Reference in new issue