@ -0,0 +1,57 @@
|
||||
package com.example.sixaunyi;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class LoginActivity extends AppCompatActivity {
|
||||
|
||||
private EditText mUsername;
|
||||
private EditText mPassword;
|
||||
private Button mLoginButton;
|
||||
private Map<String, String> mUsers = new HashMap<>();
|
||||
{
|
||||
mUsers.put("admin", "123456");
|
||||
mUsers.put("tiequan", "8731");
|
||||
mUsers.put("zhenghaoyuan", "6666");
|
||||
}
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_login);
|
||||
// 获取输入框和按钮的实例
|
||||
mUsername = findViewById(R.id.username);
|
||||
mPassword = findViewById(R.id.password);
|
||||
mLoginButton = findViewById(R.id.login);
|
||||
// 设置登录按钮的点击事件
|
||||
mLoginButton.setOnClickListener(v -> {
|
||||
attemptLogin();
|
||||
});
|
||||
}
|
||||
private void attemptLogin() {
|
||||
String username = mUsername.getText().toString();
|
||||
String password = mPassword.getText().toString();
|
||||
boolean if_correct = verifyUser(username,password);
|
||||
if (if_correct) {
|
||||
Toast.makeText(this, "登录成功", Toast.LENGTH_SHORT).show();
|
||||
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
|
||||
startActivity(intent);
|
||||
finish(); // 关闭登录界面
|
||||
} else {
|
||||
Toast.makeText(this, "用户名或密码错误", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean verifyUser(String username, String password){
|
||||
if (mUsers.containsKey(username) && mUsers.get(username).equals(password)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,14 +1,181 @@
|
||||
package com.example.sixaunyi;
|
||||
|
||||
import static androidx.constraintlayout.motion.utils.Oscillator.TAG;
|
||||
|
||||
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.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 {
|
||||
|
||||
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
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
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: 7.2 KiB |
After Width: | Height: | Size: 5.9 KiB |
After Width: | Height: | Size: 4.0 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 992 B |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 600 KiB |
After Width: | Height: | Size: 1.3 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/auto" android:state_checked="false" /> <!-- 当未选中时的背景 -->
|
||||
<item android:drawable="@drawable/manual" android:state_checked="true" /> <!-- 当选中时的背景 -->
|
||||
</selector>
|
@ -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>
|
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>
|
@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:background="@drawable/bg"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
android:background="@drawable/android"
|
||||
android:layout_marginTop="200dp"
|
||||
android:layout_gravity="center"/>
|
||||
<EditText
|
||||
android:id="@+id/username"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="账号:"
|
||||
android:layout_marginTop="30dp"
|
||||
android:layout_marginLeft="30dp"
|
||||
android:layout_marginRight="30dp"/>
|
||||
<EditText
|
||||
android:id="@+id/password"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="密码:"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginLeft="30dp"
|
||||
android:layout_marginRight="30dp"/>
|
||||
<CheckBox
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="记住密码"
|
||||
android:layout_marginLeft="280dp"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<Button
|
||||
android:id="@+id/login"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="57dp"
|
||||
android:gravity="center"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:text="登录" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<style name="TransparentTheme" parent="Theme.AppCompat.Light.NoActionBar">
|
||||
<item name="android:windowBackground">#00000000</item>
|
||||
<item name="android:windowIsTranslucent">true</item>
|
||||
<item name="android:windowContentOverlay">@null</item>
|
||||
<item name="android:colorBackgroundCacheHint">@null</item>
|
||||
<item name="android:windowAnimationStyle">@android:style/Animation</item>
|
||||
</style>
|
||||
</resources>
|