更新控件

zhenghaoyuan_branch
zhenghaoyuan20 2 years ago
parent 71324ec7f8
commit 5f21f5e7be

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<targetSelectedWithDropDown>
<Target>
<type value="QUICK_BOOT_TARGET" />
<deviceKey>
<Key>
<type value="VIRTUAL_DEVICE_PATH" />
<value value="C:\Users\郑皓原\.android\avd\Pixel_2_XL_API_22_2.avd" />
</Key>
</deviceKey>
</Target>
</targetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2023-06-22T00:46:45.782451800Z" />
</component>
</project>

@ -3,12 +3,17 @@
<component name="DesignSurface">
<option name="filePathToZoomLevelMap">
<map>
<entry key="..\:/AndroidTool/AndriodProject/Shaobing/src/sixaunyi/app/src/main/res/drawable/icon_favorite_red.xml" value="0.1235" />
<entry key="..\:/AndroidTool/AndriodProject/Shaobing/src/sixaunyi/app/src/main/res/drawable/selector_toggle_icon.xml" value="0.2265" />
<entry key="..\:/AndroidTool/AndriodProject/Shaobing/src/sixaunyi/app/src/main/res/drawable/txt_radiuborder.xml" value="0.2505" />
<entry key="..\:/AndroidTool/AndriodProject/Shaobing/src/sixaunyi/app/src/main/res/layout-land/activity_control.xml" value="0.21472663139329806" />
<entry key="..\:/AndroidTool/AndriodProject/Shaobing/src/sixaunyi/app/src/main/res/layout-v26/activity_setting.xml" value="0.264" />
<entry key="..\:/AndroidTool/AndriodProject/Shaobing/src/sixaunyi/app/src/main/res/layout/activity_control.xml" value="0.25364583333333335" />
<entry key="..\:/AndroidTool/AndriodProject/Shaobing/src/sixaunyi/app/src/main/res/layout/activity_login.xml" value="0.25364583333333335" />
<entry key="..\:/AndroidTool/AndriodProject/Shaobing/src/sixaunyi/app/src/main/res/layout/activity_main.xml" value="0.25364583333333335" />
<entry key="..\:/AndroidTool/AndriodProject/Shaobing/src/sixaunyi/app/src/main/res/layout/activity_setting.xml" value="0.1" />
<entry key="..\:/AndroidTool/AndriodProject/Shaobing/src/sixaunyi/app/src/main/res/layout/activity_video.xml" value="0.25364583333333335" />
<entry key="..\:/AndroidTool/AndriodProject/Shaobing/src/sixaunyi/app/src/main/res/layout/content_detect.xml" value="0.25364583333333335" />
<entry key="..\:/AndroidTool/AndriodProject/Shaobing/src/sixaunyi/app/src/main/res/layout/custom_info_contents.xml" value="0.1125" />
<entry key="..\:/AndroidTool/AndriodProject/Shaobing/src/sixaunyi/app/src/main/res/layout/custom_info_window.xml" value="0.1125" />
<entry key="..\:/AndroidTool/AndriodProject/Shaobing/src/sixaunyi/app/src/main/res/layout/fragment_second.xml" value="0.1125" />

@ -28,6 +28,8 @@ android {
buildFeatures {
viewBinding true
}
buildToolsVersion '30.0.3'
ndkVersion '21.1.6352462'
}
dependencies {

@ -37,7 +37,7 @@ public class SettingActivity extends AppCompatActivity {
private final static String SEND_to_IP = "192.168.39.47";
private SeekBar Speed_btn;
private Button Battery_btn;
private Switch Battery_btn;
private ImageButton return_btn;
private final static int SEND_PORT = 8888;
private ExecutorService mThreadPool = Executors.newCachedThreadPool();
@ -51,6 +51,7 @@ public class SettingActivity extends AppCompatActivity {
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);
@ -59,6 +60,8 @@ public class SettingActivity extends AppCompatActivity {
int speedProgress = sharedPreferences.getInt("speed_progress", 0);
Speed_btn.setProgress(speedProgress);
tvProgress.setText(String.valueOf(speedProgress+10));
boolean battery_btn_state= sharedPreferences.getBoolean("battery_btn_state", false);
Battery_btn.setChecked(battery_btn_state);
photo_btn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
@ -68,6 +71,15 @@ public class SettingActivity extends AppCompatActivity {
editor.apply();
}
});
Battery_btn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// 保存Switch状态
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("battery_btn_state", isChecked);
editor.apply();
}
});
Speed_btn.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
@ -118,6 +130,25 @@ public class SettingActivity extends AppCompatActivity {
}
}
});
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();
}
}
}
});
}
/*
* UDP线

@ -3,7 +3,8 @@ package com.example.sixaunyi;
import static androidx.constraintlayout.motion.utils.Oscillator.TAG;
import androidx.appcompat.app.AppCompatActivity;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
@ -35,8 +36,6 @@ import android.widget.Toast;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.*;
import java.util.concurrent.ExecutorService;
@ -75,6 +74,7 @@ public class VideoActivity extends AppCompatActivity {
private float mdistance;
// 创建一个可缓存的线程池
private ExecutorService mThreadPool = Executors.newCachedThreadPool();
private UdpDataThread warning_thread;
//ReceiveData()显示到imageView
//manager部分打开线程接收
//model部分发送视频流
@ -224,6 +224,54 @@ public class VideoActivity extends AppCompatActivity {
}
});
}
public class UdpDataThread extends Thread {
private DatagramSocket socket;
private boolean isRunning;
public UdpDataThread() {
isRunning = true;
}
@Override
public void run() {
byte[] buffer = new byte[1024];
try {
// 创建DatagramSocket对象并绑定指定的端口
socket = new DatagramSocket(6666);
while (isRunning) {
// 创建空的DatagramPacket对象用于接收数据
DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
// 接收数据
socket.receive(packet);
// 从接收到的数据包中提取数据并进行处理
String receivedData = new String(packet.getData(), 0, packet.getLength());
// 进行数据处理操作...
Toast.makeText(VideoActivity.this,receivedData, Toast.LENGTH_SHORT).show();
// 打印接收到的数据包内容
System.out.println("Received: " + receivedData);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (socket != null) {
// 关闭Socket
socket.close();
}
}
}
public void stopReceiver() {
isRunning = false;
}
}
class ReceiveHandler extends Handler{
@Override
public void handleMessage(Message msg) {

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/zidongkongzhi" android:state_checked="false" /> <!-- 当未选中时的图标 -->
<item android:drawable="@drawable/shoudong" android:state_checked="true" /> <!-- 当选中时的图标 -->
</selector>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/zidongkongzhi" android:state_checked="false" /> <!-- 当未选中时的图标 -->
<item android:drawable="@drawable/shoudong" android:state_checked="true" /> <!-- 当选中时的图标 -->
</selector>

@ -230,7 +230,24 @@
/>
</LinearLayout>
<LinearLayout
android:id="@+id/top_right_buttons_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp"
android:layout_gravity="right|top">
<ToggleButton
android:id="@+id/toggleButton2"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_weight="2"
android:background="@drawable/selector_toggle_icon"
android:text="ToggleButton"
android:textOff=""
android:textOn="" />
</LinearLayout>
</FrameLayout>

@ -29,7 +29,8 @@
android:hint="密码:"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"/>
android:layout_marginRight="30dp"
android:maxLines="1"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -46,7 +47,8 @@
android:layout_width="295dp"
android:layout_height="57dp"
android:layout_marginLeft="175dp"
android:text="登录" />
android:text="登录"
android:maxLines="1"/>
</LinearLayout>

Loading…
Cancel
Save