升级电量预警

zhenghaoyuan_branch
zhenghaoyuan20 2 years ago
parent 28a401608c
commit f1c304fb69

@ -12,7 +12,7 @@
<entry key="..\:/AndroidTool/AndriodProject/Shaobing/src/sixaunyi/app/src/main/res/layout/activity_detect.xml" value="0.1125" />
<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_setting.xml" value="0.264" />
<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_dialog.xml" value="0.2526041666666667" />

@ -18,7 +18,7 @@
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:icon="@drawable/bg"
android:label="哨兵软件系统"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"

@ -527,10 +527,10 @@ public class MainActivity extends AppCompatActivity implements AMapLocationList
public void changeAct(View view) {
udpReceiveThread.stopListening();
Intent intent = new Intent(MainActivity.this, VideoActivity.class);
Bundle b = new Bundle();
b.putString("Angle", MonitorAngle);
b.putFloat("Distance", MonitorDistance);
intent.putExtras(b);
// Bundle b = new Bundle();
// b.putString("Angle", MonitorAngle);
// b.putFloat("Distance", MonitorDistance);
// intent.putExtras(b);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
}

@ -37,13 +37,15 @@ public class SettingActivity extends AppCompatActivity {
private final static String SEND_to_IP = "192.168.39.47";
private SeekBar Speed_btn;
private Switch Battery_btn;
private SeekBar 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;
private TextView tvProgress;
private TextView Battery_warning;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -51,8 +53,9 @@ 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);
Battery_btn = findViewById(R.id.warning_num);
tvProgress = findViewById(R.id.tvProgress);
Battery_warning=findViewById(R.id.Battery_warning);
sharedPreferences = getSharedPreferences("control_state", MODE_PRIVATE);
boolean photo_btn_state= sharedPreferences.getBoolean("photo_btn_state", false);
photo_btn.setChecked(photo_btn_state);
@ -60,8 +63,9 @@ 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);
int warning_num= sharedPreferences.getInt("battery_num", 0);
Battery_btn.setProgress(warning_num);
Battery_warning.setText(String.valueOf(warning_num));
photo_btn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
@ -71,15 +75,6 @@ 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) {
@ -102,30 +97,25 @@ public class SettingActivity extends AppCompatActivity {
public void onStopTrackingTouch(SeekBar seekBar) {}
});
Battery_btn.setOnClickListener(new View.OnClickListener() {
Battery_btn.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@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();
}
}
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
Battery_warning.setText(String.valueOf(progress));
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putInt("battery_num", progress);
editor.apply();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {}
});
return_btn.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Intent intent = new Intent(SettingActivity.this, VideoActivity.class);
// 启动目标 Activity
finish();
passingParameters();
}
});
photo_btn.setOnClickListener(new View.OnClickListener() {
@ -133,14 +123,14 @@ public class SettingActivity extends AppCompatActivity {
public void onClick(View v) {
if (photo_btn.isChecked()) {
try {
sendCommand("photo_high");
sendCommand("PHOTO_HIGH");
} catch (UnknownHostException e) {
e.printStackTrace();
}
}else
{
try {
sendCommand("photo_low");
sendCommand("PHOTO_LOW");
} catch (UnknownHostException e) {
e.printStackTrace();
}
@ -186,5 +176,19 @@ public class SettingActivity extends AppCompatActivity {
mThreadPool.execute(sendRunnable1);
}
@Override
public void onBackPressed() {
// 在这里处理返回事件的逻辑
super.onBackPressed(); // 调用父类的方法,执行默认的返回操作
passingParameters();
}
private void passingParameters(){
int warning_num= sharedPreferences.getInt("battery_num", 0);
Log.i(TAG, "111111111111111111111"+String.valueOf(warning_num));
Intent intent = new Intent(SettingActivity.this,VideoActivity.class);
intent.putExtra("BATTERY_NUM", warning_num); // 设置要传递的参数
setResult(RESULT_OK, intent);
finish();
}
}

@ -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{

@ -250,12 +250,12 @@
<TextView
android:id="@+id/warning"
android:layout_width="131dp"
android:layout_width="231dp"
android:layout_height="40dp"
android:layout_marginTop="70dp"
android:layout_marginLeft="20dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="75dp"
android:text=""
android:textSize="22dp"/>
android:textSize="20dp" />
</FrameLayout>

@ -26,14 +26,37 @@
android:scaleType="centerInside"
app:srcCompat="@drawable/returns" />
<Switch
android:id="@+id/Battery_warning"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="电量预警"
android:textColor="@color/white"
android:textSize="28dp"
android:background="@drawable/txt_radiuborder"/>
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:background="@drawable/txt_radiuborder">
<TextView
android:layout_width="150dp"
android:layout_height="50dp"
android:text="电量预警"
android:textColor="@color/white"
android:textSize="28dp" />
<SeekBar
android:id="@+id/warning_num"
android:layout_width="180dp"
android:layout_height="50dp"
android:max="100"
android:progress="0"
android:thumbTint='@color/teal_200' />
<TextView
android:id="@+id/Battery_warning"
android:layout_width="77dp"
android:layout_height="30dp"
android:text="0"
android:textColor="@color/white"
android:textSize="18dp" />
</LinearLayout>
<Switch
android:id="@+id/photo"

Loading…
Cancel
Save