parent
db545bbb14
commit
d99f8f6612
@ -1,14 +1,181 @@
|
|||||||
package com.example.sixaunyi;
|
package com.example.sixaunyi;
|
||||||
|
|
||||||
|
import static androidx.constraintlayout.motion.utils.Oscillator.TAG;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.CompoundButton;
|
||||||
|
import android.widget.ImageButton;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.SeekBar;
|
||||||
|
import android.widget.Switch;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.DatagramPacket;
|
||||||
|
import java.net.DatagramSocket;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
public class SettingActivity extends AppCompatActivity {
|
public class SettingActivity extends AppCompatActivity {
|
||||||
private boolean if_jiankong;
|
|
||||||
|
private final static String SEND_to_IP = "192.168.39.47";
|
||||||
|
private SeekBar Speed_btn;
|
||||||
|
private Switch Battery_btn;
|
||||||
|
private ImageButton return_btn;
|
||||||
|
private final static int SEND_PORT = 8888;
|
||||||
|
private ExecutorService mThreadPool = Executors.newCachedThreadPool();
|
||||||
|
private Switch photo_btn;
|
||||||
|
private Context context;
|
||||||
|
private SharedPreferences sharedPreferences;
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_setting);
|
setContentView(R.layout.activity_setting);
|
||||||
|
Speed_btn= findViewById(R.id.speed);
|
||||||
|
return_btn=findViewById(R.id.returns);
|
||||||
|
photo_btn = findViewById(R.id.photo);
|
||||||
|
Battery_btn = findViewById(R.id.Battery_warning);
|
||||||
|
TextView tvProgress = (TextView) findViewById(R.id.tvProgress);
|
||||||
|
sharedPreferences = getSharedPreferences("control_state", MODE_PRIVATE);
|
||||||
|
boolean photo_btn_state= sharedPreferences.getBoolean("photo_btn_state", false);
|
||||||
|
photo_btn.setChecked(photo_btn_state);
|
||||||
|
// 恢复SeekBar状态
|
||||||
|
int speedProgress = sharedPreferences.getInt("speed_progress", 0);
|
||||||
|
Speed_btn.setProgress(speedProgress);
|
||||||
|
tvProgress.setText(String.valueOf(speedProgress+10));
|
||||||
|
photo_btn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
|
// 保存Switch状态
|
||||||
|
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||||
|
editor.putBoolean("photo_btn_state", isChecked);
|
||||||
|
editor.apply();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Speed_btn.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||||
|
tvProgress.setText(String.valueOf(progress+10));
|
||||||
|
int speed=progress+10;
|
||||||
|
String s = "SPEED " + Integer.toString(speed);
|
||||||
|
try {
|
||||||
|
sendCommand(s);
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||||
|
editor.putInt("speed_progress", progress);
|
||||||
|
editor.apply();
|
||||||
|
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onStartTrackingTouch(SeekBar seekBar) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStopTrackingTouch(SeekBar seekBar) {}
|
||||||
|
|
||||||
|
});
|
||||||
|
Battery_btn.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (Battery_btn.isChecked()) {
|
||||||
|
try {
|
||||||
|
sendCommand("battery_warning");
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
sendCommand("warning_cancel");
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
return_btn.setOnClickListener(new View.OnClickListener(){
|
||||||
|
public void onClick(View v) {
|
||||||
|
Intent intent = new Intent(SettingActivity.this, VideoActivity.class);
|
||||||
|
// 启动目标 Activity
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
photo_btn.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (photo_btn.isChecked()) {
|
||||||
|
try {
|
||||||
|
sendCommand("photo_high");
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
sendCommand("photo_low");
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* UDP数据发送线程
|
||||||
|
* */
|
||||||
|
class SendRunnable implements Runnable {
|
||||||
|
byte[] mData;
|
||||||
|
InetAddress mAddress;
|
||||||
|
int mPort;
|
||||||
|
public SendRunnable(byte[] data, InetAddress address, int port) {
|
||||||
|
mData = data;
|
||||||
|
mAddress = address;
|
||||||
|
mPort = port;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
// 创建发送数据报文
|
||||||
|
DatagramPacket packet = new DatagramPacket(mData, mData.length, mAddress, mPort);
|
||||||
|
// 创建 DatagramSocket 对象并发送数据报文
|
||||||
|
DatagramSocket socket = new DatagramSocket();
|
||||||
|
socket.send(packet);
|
||||||
|
|
||||||
|
// 关闭 DatagramSocket 对象
|
||||||
|
socket.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*封装函数*/
|
||||||
|
private void sendCommand(String str) throws UnknownHostException {
|
||||||
|
byte[] sendData = str.getBytes();
|
||||||
|
InetAddress address = InetAddress.getByName(SEND_to_IP);
|
||||||
|
SendRunnable sendRunnable1 = new SendRunnable(sendData, address, SEND_PORT);
|
||||||
|
mThreadPool.execute(sendRunnable1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
After Width: | Height: | Size: 4.0 KiB |
After Width: | Height: | Size: 992 B |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.6 KiB |
@ -0,0 +1,24 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<!-- 设置透明背景色 -->
|
||||||
|
<solid android:color="#80000000" />
|
||||||
|
|
||||||
|
<!-- 设置一个黑色边框 -->
|
||||||
|
<stroke
|
||||||
|
android:width="2px"
|
||||||
|
android:color="#000000" />
|
||||||
|
<!-- 设置四个圆角的半径 -->
|
||||||
|
<corners
|
||||||
|
android:bottomLeftRadius="10px"
|
||||||
|
android:bottomRightRadius="10px"
|
||||||
|
android:topLeftRadius="10px"
|
||||||
|
android:topRightRadius="10px" />
|
||||||
|
<!-- 设置一下边距,让空间大一点 -->
|
||||||
|
<padding
|
||||||
|
android:bottom="5dp"
|
||||||
|
android:left="5dp"
|
||||||
|
android:right="5dp"
|
||||||
|
android:top="5dp" />
|
||||||
|
|
||||||
|
</shape>
|
Loading…
Reference in new issue