Skip to content

Commit

Permalink
实时显示船的状态,包括陀螺仪方向角、目标方向角、当前舵量,以及目标地的标记
Browse files Browse the repository at this point in the history
  • Loading branch information
rty813 committed Dec 21, 2017
1 parent 7d62f2e commit fafdce1
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 29 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
applicationId "com.xyz.rty813.cleanship"
minSdkVersion 16
targetSdkVersion 26
versionCode 9
versionName "0.6"
versionCode 10
versionName "0.7"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Binary file modified app/release/app-release.apk
Binary file not shown.
2 changes: 1 addition & 1 deletion app/release/output.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":9},"path":"app-release.apk","properties":{"packageId":"com.xyz.rty813.cleanship","split":"","minSdkVersion":"16"}}]
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":10},"path":"app-release.apk","properties":{"packageId":"com.xyz.rty813.cleanship","split":"","minSdkVersion":"16"}}]
40 changes: 38 additions & 2 deletions app/src/main/java/com/xyz/rty813/cleanship/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import com.amap.api.maps.AMap;
Expand Down Expand Up @@ -99,8 +100,11 @@ public class MainActivity extends AppCompatActivity implements AMap.OnMapClickLi
private static final String CHANNEL = "SELF";
private MyReceiver receiver;
private ArrayList<LatLng> shipPointList;
private ArrayList<LatLng> aimPointList;
private SmoothMoveMarker smoothMoveMarker;

private TextView tvAimAngle;
private TextView tvGyroAngle;
private TextView tvCurrGas;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -150,12 +154,15 @@ public void onPermissionRationaleShouldBeShown(PermissionRequest permission, Per
aMap.setOnMarkerClickListener(this);
aMap.setOnMapClickListener(this);
initSmoothMove();
aimPointList = new ArrayList<>();
findViewById(R.id.btn_start).setOnClickListener(this);
findViewById(R.id.btn_cancel).setOnClickListener(this);
findViewById(R.id.btn_clear).setOnClickListener(this);
findViewById(R.id.btn_detail).setOnClickListener(this);
findViewById(R.id.btn_history).setOnClickListener(this);

tvAimAngle = findViewById(R.id.tv_aim_angle);
tvCurrGas = findViewById(R.id.tv_curr_gas);
tvGyroAngle = findViewById(R.id.tv_gyro_angle);
}

private void checkUpdate() {
Expand Down Expand Up @@ -280,6 +287,8 @@ public void onClick(View view) {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
aMap.clear();
shipPointList.removeAll(shipPointList);
aimPointList.removeAll(aimPointList);
markers.removeAll(markers);
polylines.removeAll(polylines);
}
Expand Down Expand Up @@ -496,6 +505,8 @@ public void run() {
serialPort.closeDevice();
}
aMap.clear();
shipPointList.removeAll(shipPointList);
aimPointList.removeAll(aimPointList);
markers.removeAll(markers);
polylines.removeAll(polylines);
}
Expand Down Expand Up @@ -598,6 +609,8 @@ private void saveRoute(String time, String route, String address){
private void loadRoute(@Nullable String id){
SQLiteDatabase database = MainActivity.dbHelper.getReadableDatabase();
aMap.clear();
shipPointList.removeAll(shipPointList);
aimPointList.removeAll(aimPointList);
markers.removeAll(markers);
polylines.removeAll(polylines);
Cursor cursor;
Expand Down Expand Up @@ -682,5 +695,28 @@ public void move(){
smoothMoveMarker.startSmoothMove();
}
}

public void setCurrGas(String currGas) {
this.tvCurrGas.setText(currGas);
}

public void setAimAngle(String aimAngle){
this.tvAimAngle.setText(aimAngle);
}

public void setGyroAngle(String gyroAngle){
this.tvGyroAngle.setText(gyroAngle);
}

public void setAimPoint(LatLng aimPoint){
if (!aimPointList.contains(aimPoint)){
aimPointList.add(aimPoint);
MarkerOptions markerOptions = new MarkerOptions().position(aimPoint);
markerOptions.title(String.valueOf(aimPointList.size()));
markerOptions.snippet("纬度:" + aimPoint.latitude + "\n经度:" + aimPoint.longitude);
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.aim)));
aMap.addMarker(markerOptions);
}
}
}

31 changes: 28 additions & 3 deletions app/src/main/java/com/xyz/rty813/cleanship/MyReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,33 @@ public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
activity = (MainActivity) context;
activity.getShipPointList().add(new LatLng(intent.getDoubleExtra("lat", 0),
intent.getDoubleExtra("lng", 0)));
activity.move();
String rawData = intent.getStringExtra("data");
String[] datas = rawData.split(",");
// type代表数据类型
// 0=>当前经纬度 1=>目标经纬度 2=>陀螺仪方向角 3=>目标方向角 4=>当前舵量
switch (intent.getIntExtra("type", -1)) {
case 0:
Double lat = Double.parseDouble(datas[0]);
Double lng = Double.parseDouble(datas[1]);
activity.getShipPointList().add(new LatLng(lat, lng));
activity.move();
break;
case 1:
lat = Double.parseDouble(datas[0]);
lng = Double.parseDouble(datas[1]);
activity.setAimPoint(new LatLng(lat, lng));
break;
case 2:
activity.setGyroAngle(rawData);
break;
case 3:
activity.setAimAngle(rawData);
break;
case 4:
activity.setCurrGas(rawData);
break;
default:
break;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,13 @@ public boolean openDevice(UsbDevice device){
@Override
public void run() {
while (mContext.state != UNREADY){
// System.out.println(readData());
String data = readData();
if (data != null && !data.equals("")){
String[] strings = data.split(",");
double lat = Double.parseDouble(strings[0]);
double lng = Double.parseDouble(strings[1]);
String[] strings = data.split(";");
System.out.println(data + "\t" + strings.length);
if (strings.length == 2){
Intent intent = new Intent(MyReceiver.ACTION_DATA_RECEIVED);
intent.putExtra("raw", data);
intent.putExtra("lat", lat);
intent.putExtra("lng", lng);
intent.putExtra("type", Integer.parseInt(strings[0]));
intent.putExtra("data", strings[1]);
mContext.sendBroadcast(intent);
}
}
Expand Down
Binary file added app/src/main/res/drawable/aim.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/ship.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/textview_border.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
android:radius="20dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp" />
<solid android:color="#d4ffffff" />
<solid android:color="#85000000" />
<stroke android:width="1dip" android:color="#afafaf"/>
</shape>
70 changes: 58 additions & 12 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,64 @@
android:layout_gravity="center_horizontal|bottom"
android:layout_marginBottom="30dp"/>

<!--<TextView-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_gravity="center_horizontal|top"-->
<!--android:layout_marginTop="10dp"-->
<!--android:background="@drawable/textview_border"-->
<!--android:paddingTop="5dp"-->
<!--android:paddingBottom="5dp"-->
<!--android:paddingLeft="10dp"-->
<!--android:paddingRight="10dp"-->
<!--android:text="设备状态:未连接"-->
<!--/>-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:padding="5dp"
android:background="@drawable/textview_border"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:textColor="@color/mb_white"
android:text="@string/gyro_angle"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:textColor="@color/mb_white"
android:text="@string/aim_angle"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:textColor="@color/mb_white"
android:text="@string/curr_gas"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/mb_white"
android:id="@+id/tv_gyro_angle"
android:text="0.0"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/mb_white"
android:id="@+id/tv_aim_angle"
android:text="0.0"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/mb_white"
android:id="@+id/tv_curr_gas"
android:text="0.0"/>
</LinearLayout>


</LinearLayout>



<app.dinus.com.loadingdrawable.LoadingView
android:id="@+id/loadingview"
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<resources>
<string name="app_name">清洁船内测版</string>
<string name="aim_angle">目标方向角:</string>
<string name="gyro_angle">陀螺仪方向角:</string>
<string name="curr_gas">当前舵量:</string>
</resources>

0 comments on commit fafdce1

Please sign in to comment.