diff --git a/doc/“哨兵”软件系统软件设计规格说明书.doc b/doc/“哨兵”软件系统软件设计规格说明书.doc index 1f1a7da..648bda4 100644 Binary files a/doc/“哨兵”软件系统软件设计规格说明书.doc and b/doc/“哨兵”软件系统软件设计规格说明书.doc differ diff --git a/src/sixaunyi/.idea/sonarlint/issuestore/2/a/2ab0711d9aa5839cecbb6cf0ed96f5a3f6470de5 b/src/sixaunyi/.idea/sonarlint/issuestore/2/a/2ab0711d9aa5839cecbb6cf0ed96f5a3f6470de5 new file mode 100644 index 0000000..e69de29 diff --git a/src/sixaunyi/.idea/sonarlint/issuestore/7/1/71fd1993763df2214bbdad8cfee650733993fe44 b/src/sixaunyi/.idea/sonarlint/issuestore/7/1/71fd1993763df2214bbdad8cfee650733993fe44 index d6cf065..7233058 100644 --- a/src/sixaunyi/.idea/sonarlint/issuestore/7/1/71fd1993763df2214bbdad8cfee650733993fe44 +++ b/src/sixaunyi/.idea/sonarlint/issuestore/7/1/71fd1993763df2214bbdad8cfee650733993fe44 @@ -1,137 +1,133 @@ -` java:S112g"FDefine and throw a dedicated exception instead of using a generic one.(҂ -` java:S112r"FDefine and throw a dedicated exception instead of using a generic one.(҂ -` java:S112}"FDefine and throw a dedicated exception instead of using a generic one.(҂ -a java:S112"FDefine and throw a dedicated exception instead of using a generic one.(҂ -a java:S112"FDefine and throw a dedicated exception instead of using a generic one.(҂ -a java:S112"FDefine and throw a dedicated exception instead of using a generic one.(҂ -a java:S112"FDefine and throw a dedicated exception instead of using a generic one.(҂ -a java:S112"FDefine and throw a dedicated exception instead of using a generic one.(҂ -g java:S117"QRename this local variable to match the regular expression '^[a-z][a-zA-Z0-9]*$'.( +` java:S112h"FDefine and throw a dedicated exception instead of using a generic one.(҂ +a java:S112"FDefine and throw a dedicated exception instead of using a generic one.(҂ +a java:S112"FDefine and throw a dedicated exception instead of using a generic one.(҂ +a java:S112"FDefine and throw a dedicated exception instead of using a generic one.(҂ +a java:S112"FDefine and throw a dedicated exception instead of using a generic one.(҂ +a java:S112"FDefine and throw a dedicated exception instead of using a generic one.(҂ +a java:S112"FDefine and throw a dedicated exception instead of using a generic one.(҂ +h java:S112"FDefine and throw a dedicated exception instead of using a generic one.(҂8̇1 +h java:S112"FDefine and throw a dedicated exception instead of using a generic one.(҂8̇1 +s java:S117"QRename this local variable to match the regular expression '^[a-z][a-zA-Z0-9]*$'.(ᮾ8̇1 > -java:S1604a"(Make this anonymous inner class a lambda( -C -java:S1604l"(Make this anonymous inner class a lambda(ݳ -C -java:S1604w"(Make this anonymous inner class a lambda( +java:S1604b"(Make this anonymous inner class a lambda(Ʒ +> +java:S1604m"(Make this anonymous inner class a lambda( +> +java:S1604z"(Make this anonymous inner class a lambda( +K +java:S1604"(Make this anonymous inner class a lambda(ݳ8̇1 D -java:S1604"(Make this anonymous inner class a lambda( +java:S1604"(Make this anonymous inner class a lambda( D -java:S1604"(Make this anonymous inner class a lambda( -? -java:S1604"(Make this anonymous inner class a lambda( +java:S1604"(Make this anonymous inner class a lambda( +D +java:S1604"(Make this anonymous inner class a lambda( ? -java:S1604"(Make this anonymous inner class a lambda(ڊ +java:S1604"(Make this anonymous inner class a lambda( ? -java:S1604"(Make this anonymous inner class a lambda( +java:S1604"(Make this anonymous inner class a lambda(ڊ ? -java:S1604"(Make this anonymous inner class a lambda( -V -java:S2184"@Cast one of the operands of this integer division to a "double".([ -X -java:S2184"ACast one of the operands of this division operation to a "float".(ϓ -] -java:S2184"ACast one of the operands of this division operation to a "float".( -[ -java:S2184"DCast one of the operands of this subtraction operation to a "float".( -] -java:S2184"ACast one of the operands of this division operation to a "float".( -[ -java:S2184"DCast one of the operands of this subtraction operation to a "float".( -[ -java:S2184"DCast one of the operands of this subtraction operation to a "float".( -] -java:S2184"ACast one of the operands of this addition operation to a "float".( -` -java:S2184"DCast one of the operands of this subtraction operation to a "float".( +java:S1604"(Make this anonymous inner class a lambda( +F +java:S1604"(Make this anonymous inner class a lambda(8̇1 ] -java:S2184"ACast one of the operands of this division operation to a "float".(Ҍ -\ -java:S2184"@Cast one of the operands of this integer division to a "double".( +java:S2184"@Cast one of the operands of this integer division to a "double".([8͇1 +_ +java:S2184"ACast one of the operands of this division operation to a "float".(ϓ8͇1 +d +java:S2184"ACast one of the operands of this division operation to a "float".(8͇1 +b +java:S2184"DCast one of the operands of this subtraction operation to a "float".(8͇1 +d +java:S2184"ACast one of the operands of this division operation to a "float".(8͇1 +b +java:S2184"DCast one of the operands of this subtraction operation to a "float".(8͇1 +b +java:S2184"DCast one of the operands of this subtraction operation to a "float".(8͇1 +d +java:S2184"ACast one of the operands of this addition operation to a "float".(8͇1 +g +java:S2184"DCast one of the operands of this subtraction operation to a "float".(8͇1 +d +java:S2184"ACast one of the operands of this division operation to a "float".(Ҍ8͇1 c -java:S2095"LUse try-with-resources or close this "DatagramSocket" in a "finally" clause.( -o java:S115-"ZRename this constant name to match the regular expression '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.(ƴư -t java:S115."ZRename this constant name to match the regular expression '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.(ܶ -t java:S116;"ZRename this field "Trans_to_Detect" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.( -k java:S116>"VRename this field "Forward_btn" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.(ѕ -m java:S116?"SRename this field "Back_btn" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.( -h java:S116@"SRename this field "Left_btn" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.( -i java:S116A"TRename this field "Right_btn" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.(Ο -m java:S116B"SRename this field "Down_btn" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.(缎 -k java:S116C"QRename this field "Up_btn" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.(ф -q java:S116D"WRename this field "TurnLeft_btn" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.(ݎ -l java:S116E"XRename this field "TurnRight_btn" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.(p -k java:S116F"VRename this field "Setting_btn" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.( -p java:S116G"VRename this field "TakeOff_btn" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.( -p java:S116H"VRename this field "Landing_btn" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.(ԓ +java:S2184"@Cast one of the operands of this integer division to a "double".(8͇1 +j +java:S2095"LUse try-with-resources or close this "DatagramSocket" in a "finally" clause.(8͇1 +o java:S115/"ZRename this constant name to match the regular expression '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.(ƴư +t java:S1150"ZRename this constant name to match the regular expression '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.(ܶ +k java:S1163"WRename this field "TimeInterval" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.(n +t java:S116<"ZRename this field "Trans_to_Detect" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.( +k java:S116?"VRename this field "Forward_btn" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.(ѕ +m java:S116@"SRename this field "Back_btn" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.( +h java:S116A"SRename this field "Left_btn" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.( +i java:S116B"TRename this field "Right_btn" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.(Ο +m java:S116C"SRename this field "Down_btn" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.(缎 +k java:S116D"QRename this field "Up_btn" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.(ф +q java:S116E"WRename this field "TurnLeft_btn" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.(ݎ +l java:S116F"XRename this field "TurnRight_btn" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.(p +k java:S116G"VRename this field "Setting_btn" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.( +p java:S116H"VRename this field "TakeOff_btn" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.( +p java:S116I"VRename this field "Landing_btn" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.( u -java:S1450G"ZRemove the "TakeOff_btn" field and declare it as a local variable in the relevant methods.( +java:S1450I"ZRemove the "Landing_btn" field and declare it as a local variable in the relevant methods.( +u +java:S1450H"ZRemove the "TakeOff_btn" field and declare it as a local variable in the relevant methods.( o -java:S1450I"TRemove the "angle" field and declare it as a local variable in the relevant methods.( +java:S1450J"TRemove the "angle" field and declare it as a local variable in the relevant methods.( r -java:S1450J"WRemove the "distance" field and declare it as a local variable in the relevant methods.(׾ -q -java:S1450<"VRemove the "imgShow" field and declare it as a local variable in the relevant methods.( +java:S1450K"WRemove the "distance" field and declare it as a local variable in the relevant methods.(׾ [ -java:S1124-"EReorder the modifiers to comply with the Java Language Specification.(ƴư +java:S1124/"EReorder the modifiers to comply with the Java Language Specification.(ƴư ` -java:S1124."EReorder the modifiers to comply with the Java Language Specification.(ܶ +java:S11240"EReorder the modifiers to comply with the Java Language Specification.(ܶ [ -java:S1124/"EReorder the modifiers to comply with the Java Language Specification.(ß +java:S11241"EReorder the modifiers to comply with the Java Language Specification.(ß [ -java:S11240"EReorder the modifiers to comply with the Java Language Specification.(Ӿ -h java:S100`"NRename this method name to match the regular expression '^[a-z][a-zA-Z0-9]*$'.( -m -java:S3776`"RRefactor this method to reduce its Cognitive Complexity from 16 to the 15 allowed.( -R java:S125"Rename "serverAddr" which hides the field declared at line 56.( -R -java:S2696"6Make the enclosing method "static" or remove this set.( -d java:S100"NRename this method name to match the regular expression '^[a-z][a-zA-Z0-9]*$'.( -G -java:S1172"+Remove this unused method parameter "view".( -W java:S125""'Remove this unused "btn" private field.(ȧ D -java:S1068I")Remove this unused "angle" private field.( +java:S1068J")Remove this unused "angle" private field.( G -java:S1068J",Remove this unused "distance" private field.(׾ -@ -java:S1068")Remove this unused "mPath" private field.(䓍 -F -java:S1068"/Remove this unused "mIsUnlocked" private field.( \ No newline at end of file +java:S1068K",Remove this unused "distance" private field.(׾ +J +java:S1068M"/Remove this unused "mThreadPool" private field.( +G +java:S1068")Remove this unused "mPath" private field.(䓍8·1 +M +java:S1068"/Remove this unused "mIsUnlocked" private field.(8·1 \ No newline at end of file diff --git a/src/sixaunyi/.idea/sonarlint/issuestore/7/c/7c120b7216f76ce98d1573d90803ab36f481640c b/src/sixaunyi/.idea/sonarlint/issuestore/7/c/7c120b7216f76ce98d1573d90803ab36f481640c index 07aa046..01d0bae 100644 --- a/src/sixaunyi/.idea/sonarlint/issuestore/7/c/7c120b7216f76ce98d1573d90803ab36f481640c +++ b/src/sixaunyi/.idea/sonarlint/issuestore/7/c/7c120b7216f76ce98d1573d90803ab36f481640c @@ -1,13 +1,13 @@ -l java:S117"QRename this local variable to match the regular expression '^[a-z][a-zA-Z0-9]*$'.( +l java:S117"QRename this local variable to match the regular expression '^[a-z][a-zA-Z0-9]*$'.( p java:S1104D"[Make mLocationClient a static final constant or non-public and provide accessors if needed.(L q java:S1104F"[Make mLocationOption a static final constant or non-public and provide accessors if needed.( d -java:S2259"MA "NullPointerException" could be thrown; "mLocationClient" is nullable here.(Թ +java:S2259"MA "NullPointerException" could be thrown; "mLocationClient" is nullable here.(Թ c -java:S2095"LUse try-with-resources or close this "DatagramSocket" in a "finally" clause.( +java:S2095"LUse try-with-resources or close this "DatagramSocket" in a "finally" clause.( o java:S115d"ZRename this constant name to match the regular expression '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.(뿧 s java:S116I"YRename this field "Current_latlng" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.( o java:S116["ZRename this field "ClearMarker_btn" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.( @@ -16,7 +16,7 @@ d java:S116i"PRename this field "Angle" to match the regular expression '^[a-z q java:S116j"WRename this field "MonitorAngle" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.(Ԁ o java:S116l"ZRename this field "MonitorDistance" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.(  -java:S1186"Add a nested comment explaining why this method is empty, throw an UnsupportedOperationException or complete the implementation.( +java:S1186"Add a nested comment explaining why this method is empty, throw an UnsupportedOperationException or complete the implementation.( i java:S1450i"TRemove the "Angle" field and declare it as a local variable in the relevant methods.(D w @@ -36,34 +36,34 @@ java:S1124d"EReorder the modifiers to comply with the Java Language Specificati ` java:S1124e"EReorder the modifiers to comply with the Java Language Specification.( Q java:S125h"Use isEmpty() to check whether the collection is empty or not.( +java:S1155">Use isEmpty() to check whether the collection is empty or not.( G -java:S1172"+Remove this unused method parameter "view".(ɑ -Q java:S125" java:S1068H"(Remove this unused "city" private field.( ? @@ -81,4 +81,4 @@ java:S1068f"0Remove this unused "listenStatus" private field.( I java:S1068g".Remove this unused "serverAddr" private field.( E -java:S1068".Remove this unused "mReceiveIp" private field.( \ No newline at end of file +java:S1068".Remove this unused "mReceiveIp" private field.( \ No newline at end of file diff --git a/src/sixaunyi/.idea/sonarlint/issuestore/8/c/8c55c3ccc257e5907959013f99656e4c8ec3903e b/src/sixaunyi/.idea/sonarlint/issuestore/8/c/8c55c3ccc257e5907959013f99656e4c8ec3903e index e69de29..48e3a42 100644 --- a/src/sixaunyi/.idea/sonarlint/issuestore/8/c/8c55c3ccc257e5907959013f99656e4c8ec3903e +++ b/src/sixaunyi/.idea/sonarlint/issuestore/8/c/8c55c3ccc257e5907959013f99656e4c8ec3903e @@ -0,0 +1,2 @@ + +R xml:S55943"1Implement permissions on this exported component.(81 \ No newline at end of file diff --git a/src/sixaunyi/.idea/sonarlint/issuestore/f/7/f7730cde41931660f06cfc32899edf44acf4d104 b/src/sixaunyi/.idea/sonarlint/issuestore/f/7/f7730cde41931660f06cfc32899edf44acf4d104 new file mode 100644 index 0000000..77f57c1 --- /dev/null +++ b/src/sixaunyi/.idea/sonarlint/issuestore/f/7/f7730cde41931660f06cfc32899edf44acf4d104 @@ -0,0 +1,10 @@ + +k java:S117'"QRename this local variable to match the regular expression '^[a-z][a-zA-Z0-9]*$'.(ߏ +q +java:S1450"[Remove the "mLoginButton" field and declare it as a local variable in the relevant methods.(Ձ +t +java:S1171"YMove the contents of this initializer to a standard constructor or to field initializers.( +G +java:S1602 ",Remove useless curly braces around statement( +V +java:S11263"AReplace this if-then-else statement by a single return statement.(ցz \ No newline at end of file diff --git a/src/sixaunyi/.idea/sonarlint/issuestore/index.pb b/src/sixaunyi/.idea/sonarlint/issuestore/index.pb index 8976264..a42e3f3 100644 --- a/src/sixaunyi/.idea/sonarlint/issuestore/index.pb +++ b/src/sixaunyi/.idea/sonarlint/issuestore/index.pb @@ -15,17 +15,21 @@ i settings.gradle,0\5\05efc8b1657769a27696d478ded1e95f38737233 @ app/build.gradle,f\4\f4a01d6a4fcb971362ec00a83903fd3902f52164 -k -;app/src/main/java/com/example/sixaunyi/ControlActivity.java,c\9\c99a584c2117ed2df42496451bb97ac1147f5ea0 j :app/src/main/java/com/example/sixaunyi/SecondFragment.java,1\2\12963d86ac5c2888cc2a9ae459de5665bc06b01f j :app/src/main/java/com/example/sixaunyi/MapApplication.java,7\7\776a4b5f215e52628a4164ac15ef90fa338360ce j :app/src/main/java/com/example/sixaunyi/DetectActivity.java,9\6\9668392b13e33166876f2a7d3f10eb5405e757ad -i -9app/src/main/java/com/example/sixaunyi/VideoActivity.java,7\1\71fd1993763df2214bbdad8cfee650733993fe44 +k +;app/src/main/java/com/example/sixaunyi/ControlActivity.java,c\9\c99a584c2117ed2df42496451bb97ac1147f5ea0 P app/src/main/AndroidManifest.xml,8\c\8c55c3ccc257e5907959013f99656e4c8ec3903e +k +;app/src/main/java/com/example/sixaunyi/SettingActivity.java,2\a\2ab0711d9aa5839cecbb6cf0ed96f5a3f6470de5 +i +9app/src/main/java/com/example/sixaunyi/LoginActivity.java,f\7\f7730cde41931660f06cfc32899edf44acf4d104 h -8app/src/main/java/com/example/sixaunyi/MainActivity.java,7\c\7c120b7216f76ce98d1573d90803ab36f481640c \ No newline at end of file +8app/src/main/java/com/example/sixaunyi/MainActivity.java,7\c\7c120b7216f76ce98d1573d90803ab36f481640c +i +9app/src/main/java/com/example/sixaunyi/VideoActivity.java,7\1\71fd1993763df2214bbdad8cfee650733993fe44 \ No newline at end of file diff --git a/src/sixaunyi/app/src/main/AndroidManifest.xml b/src/sixaunyi/app/src/main/AndroidManifest.xml index 2b1df5b..afb4a7a 100644 --- a/src/sixaunyi/app/src/main/AndroidManifest.xml +++ b/src/sixaunyi/app/src/main/AndroidManifest.xml @@ -25,10 +25,14 @@ android:theme="@style/Theme.Sixaunyi" tools:targetApi="31"> - + android:theme="@style/TransparentTheme"/> + + /> + + @@ -55,4 +65,5 @@ + \ No newline at end of file diff --git a/src/sixaunyi/app/src/main/java/com/example/sixaunyi/LoginActivity.java b/src/sixaunyi/app/src/main/java/com/example/sixaunyi/LoginActivity.java new file mode 100644 index 0000000..7531f91 --- /dev/null +++ b/src/sixaunyi/app/src/main/java/com/example/sixaunyi/LoginActivity.java @@ -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 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; + } + } +} diff --git a/src/sixaunyi/app/src/main/java/com/example/sixaunyi/MainActivity.java b/src/sixaunyi/app/src/main/java/com/example/sixaunyi/MainActivity.java index 7d9ec3e..a9ffef4 100644 --- a/src/sixaunyi/app/src/main/java/com/example/sixaunyi/MainActivity.java +++ b/src/sixaunyi/app/src/main/java/com/example/sixaunyi/MainActivity.java @@ -106,6 +106,7 @@ public class MainActivity extends AppCompatActivity implements AMapLocationListe private String MonitorAngle; private float distance; private float MonitorDistance; + private UdpReceiveThread udpReceiveThread; @SuppressLint("MissingInflatedId") @Override @@ -126,7 +127,7 @@ public class MainActivity extends AppCompatActivity implements AMapLocationListe //检查安卓版本 checkingAndroidVersion(); - UdpReceiveThread udpReceiveThread = new UdpReceiveThread(); + udpReceiveThread = new UdpReceiveThread(); udpReceiveThread.startListening(); } @@ -394,6 +395,7 @@ public class MainActivity extends AppCompatActivity implements AMapLocationListe } public void changeAct(View view) { + udpReceiveThread.stopListening(); Intent intent = new Intent(MainActivity.this, VideoActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); startActivity(intent); @@ -472,7 +474,7 @@ public class MainActivity extends AppCompatActivity implements AMapLocationListe RegeocodeAddress regeocodeAddress = regeocodeResult.getRegeocodeAddress(); //显示解析后的地址 showMsg("地址:"+regeocodeAddress.getFormatAddress()); - }else { + } else { showMsg("获取地址失败"); } } @@ -583,7 +585,7 @@ public class MainActivity extends AppCompatActivity implements AMapLocationListe angle = 90-angle; } else if (subLat < 0) { // 此时的点在中心点的左下角 - angle += 180; + angle = 270-angle; } } } diff --git a/src/sixaunyi/app/src/main/java/com/example/sixaunyi/SettingActivity.java b/src/sixaunyi/app/src/main/java/com/example/sixaunyi/SettingActivity.java new file mode 100644 index 0000000..1be7ece --- /dev/null +++ b/src/sixaunyi/app/src/main/java/com/example/sixaunyi/SettingActivity.java @@ -0,0 +1,14 @@ +package com.example.sixaunyi; + +import androidx.appcompat.app.AppCompatActivity; + +import android.os.Bundle; + +public class SettingActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_setting); + } +} \ No newline at end of file diff --git a/src/sixaunyi/app/src/main/java/com/example/sixaunyi/VideoActivity.java b/src/sixaunyi/app/src/main/java/com/example/sixaunyi/VideoActivity.java index c6fe042..3edfe37 100644 --- a/src/sixaunyi/app/src/main/java/com/example/sixaunyi/VideoActivity.java +++ b/src/sixaunyi/app/src/main/java/com/example/sixaunyi/VideoActivity.java @@ -38,6 +38,8 @@ import java.net.DatagramPacket; import java.net.DatagramSocket; import java.net.InetAddress; import java.net.*; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import android.os.Bundle; @@ -46,11 +48,10 @@ 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; //接收端口号 - + int TimeInterval = 5; private static boolean listenStatus = true; //接收线程的循环标识 private byte[] buf; static Bitmap bp; - private DatagramSocket receiveSocket; private DatagramSocket reveSocket; private DatagramSocket sendSocket; private static InetAddress serverAddr; @@ -69,9 +70,14 @@ public class VideoActivity extends AppCompatActivity { private ImageButton TurnRight_btn; private ImageButton Setting_btn; private ImageButton TakeOff_btn; - private Button Landing_btn; + private ImageButton Landing_btn; private String angle; private float distance; + // 创建一个可缓存的线程池 + private ExecutorService mThreadPool = Executors.newCachedThreadPool(); + //ReceiveData()显示到imageView + //manager部分:打开线程,接收 + //model部分:发送视频流 @Override protected void onCreate(Bundle savedInstanceState) { @@ -79,14 +85,33 @@ public class VideoActivity extends AppCompatActivity { setContentView(R.layout.activity_control); imgShow = findViewById(R.id.imageView); Forward_btn = findViewById(R.id.forward_button); + Back_btn = findViewById(R.id.backward_button); Left_btn = findViewById(R.id.left_button); Right_btn = findViewById(R.id.right_button); Down_btn = findViewById(R.id.down_button); Up_btn = findViewById(R.id.up_button); TurnLeft_btn = findViewById(R.id.rotate_left_button); + Landing_btn = findViewById(R.id.landing_button); TurnRight_btn = findViewById(R.id.rotate_right_button); TakeOff_btn = findViewById(R.id.takeoff_button); + TakeOff_btn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + try { + sendOrder("TAKEOFF"); + } catch (UnknownHostException e) { + throw new RuntimeException(e); + } + Log.i(TAG, "onClick: BBBBBBBBackward"); + } + }); + Landing_btn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + new UdpReceiveThread().start(); + } + }); Setting_btn = findViewById(R.id.setting_button); Button_Init(); Intent i = getIntent(); @@ -98,7 +123,7 @@ public class VideoActivity extends AppCompatActivity { @Override public void onClick(View v) { try { - InitUdpSend("FORWARD"); + sendOrder("FORWARD"); } catch (UnknownHostException e) { throw new RuntimeException(e); } @@ -109,7 +134,7 @@ public class VideoActivity extends AppCompatActivity { @Override public void onClick(View v) { try { - InitUdpSend("BACKWORD"); + sendOrder("BACKWORD"); } catch (UnknownHostException e) { throw new RuntimeException(e); } @@ -120,7 +145,7 @@ public class VideoActivity extends AppCompatActivity { @Override public void onClick(View v) { try { - InitUdpSend("LEFT"); + sendOrder("LEFT"); } catch (UnknownHostException e) { throw new RuntimeException(e); } @@ -131,7 +156,7 @@ public class VideoActivity extends AppCompatActivity { @Override public void onClick(View v) { try { - InitUdpSend("RIGHT"); + sendOrder("RIGHT"); } catch (UnknownHostException e) { throw new RuntimeException(e); } @@ -142,7 +167,7 @@ public class VideoActivity extends AppCompatActivity { @Override public void onClick(View v) { try { - InitUdpSend("DOWN"); + sendOrder("DOWN"); } catch (UnknownHostException e) { throw new RuntimeException(e); } @@ -153,7 +178,7 @@ public class VideoActivity extends AppCompatActivity { @Override public void onClick(View v) { try { - InitUdpSend("UP"); + sendOrder("UP"); } catch (UnknownHostException e) { throw new RuntimeException(e); } @@ -164,7 +189,7 @@ public class VideoActivity extends AppCompatActivity { @Override public void onClick(View v) { try { - InitUdpSend("TURN_LEFT"); + sendOrder("TURN_LEFT"); } catch (UnknownHostException e) { throw new RuntimeException(e); } @@ -175,7 +200,7 @@ public class VideoActivity extends AppCompatActivity { @Override public void onClick(View v) { try { - InitUdpSend("TURN_RIGHT"); + sendOrder("TURN_RIGHT"); } catch (UnknownHostException e) { throw new RuntimeException(e); } @@ -185,8 +210,8 @@ public class VideoActivity extends AppCompatActivity { Setting_btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - //Intent intent = new Intent(VideoActivity.this, SpeedActivity.class); - //startActivity(intent); + Intent intent = new Intent(VideoActivity.this, SettingActivity.class); + startActivity(intent); } }); } @@ -194,7 +219,7 @@ public class VideoActivity extends AppCompatActivity { @Override public void handleMessage(Message msg) { super.handleMessage(msg); - + imgShow.setImageBitmap(bp); } } @@ -216,11 +241,13 @@ public class VideoActivity extends AppCompatActivity { try { reveSocket = new DatagramSocket(RECEIVE_PORT); - InetAddress serverAddr = InetAddress.getByName(Recieve_IP); + serverAddr = InetAddress.getByName(Recieve_IP); + //ByteArrayOutputStream out = new ByteArrayOutputStream(); while(listenStatus) { byte[] inBuf= new byte[1024*1024]; DatagramPacket inPacket=new DatagramPacket(inBuf,inBuf.length); + //out.write(inPacket.getData()); reveSocket.receive(inPacket); if(!inPacket.getAddress().equals(serverAddr)){ throw new IOException("未知名的报文"); @@ -228,13 +255,12 @@ public class VideoActivity extends AppCompatActivity { ByteArrayInputStream in = new ByteArrayInputStream(inPacket.getData()); receiveHandler.sendEmptyMessage(1); bp = BitmapFactory.decodeStream(in); - } - - } - catch (Exception e) + } catch (Exception e) { e.printStackTrace(); + }finally { + reveSocket.close(); } } } @@ -265,38 +291,45 @@ public class VideoActivity extends AppCompatActivity { e.printStackTrace(); } } + } //初始化UDP发送线程 - private static void InitUdpSend(String Sendstr) throws UnknownHostException { + private static void sendOrder(String Sendstr) throws UnknownHostException { InetAddress sendIP = InetAddress.getByName(SEND_to_IP); // 目标 IP 地址 int sendPort = 8888; // 目标端口号 byte[] sendData = Sendstr.getBytes(); // 要发送的数据 - UdpSendThread sendThread = new UdpSendThread(sendIP, sendPort, sendData); // 创建新的线程对象 - sendThread.start(); // 启动线程发送数据 + UdpSendThread sendOrderThread = new UdpSendThread(sendIP, sendPort, sendData); // 创建新的线程对象 + sendOrderThread.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 { -// InitUdpSend("TAKEOFF"+"___"+angle+"___"+String.valueOf(distance)); -// } catch (UnknownHostException e) { -// throw new RuntimeException(e); -// } - new UdpReceiveThread().start(); - dialog.dismiss(); - Log.i(TAG, "onClick: 2222222222222222222222222"); - } - }); - dialog.show(); - } + + + +//设置按钮 +// 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 { +//// sendOrder("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{ diff --git a/src/sixaunyi/app/src/main/res/drawable/android.png b/src/sixaunyi/app/src/main/res/drawable/android.png new file mode 100644 index 0000000..0caf395 Binary files /dev/null and b/src/sixaunyi/app/src/main/res/drawable/android.png differ diff --git a/src/sixaunyi/app/src/main/res/drawable/bg.png b/src/sixaunyi/app/src/main/res/drawable/bg.png new file mode 100644 index 0000000..ab41860 Binary files /dev/null and b/src/sixaunyi/app/src/main/res/drawable/bg.png differ diff --git a/src/sixaunyi/app/src/main/res/layout-land/activity_control.xml b/src/sixaunyi/app/src/main/res/layout-land/activity_control.xml index 2404caa..08c7341 100644 --- a/src/sixaunyi/app/src/main/res/layout-land/activity_control.xml +++ b/src/sixaunyi/app/src/main/res/layout-land/activity_control.xml @@ -180,9 +180,9 @@ android:scaleType="centerCrop" android:src="@drawable/takeoff" android:text="起飞" - android:onClick="showDialog" android:contentDescription="@string/takeoff_button" /> + diff --git a/src/sixaunyi/app/src/main/res/layout/activity_login.xml b/src/sixaunyi/app/src/main/res/layout/activity_login.xml new file mode 100644 index 0000000..a398864 --- /dev/null +++ b/src/sixaunyi/app/src/main/res/layout/activity_login.xml @@ -0,0 +1,55 @@ + + + + + + + + + + +