Skip to content

Commit b99fb60

Browse files
committed
Code clean-up, exception handling and layout trimming.
1 parent 4d11b68 commit b99fb60

File tree

9 files changed

+29
-42
lines changed

9 files changed

+29
-42
lines changed

.idea/caches/build_file_checksums.ser

-1 Bytes
Binary file not shown.

.idea/gradle.xml

-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+2-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ dependencies {
2525
testImplementation 'junit:junit:4.12'
2626
androidTestImplementation 'com.android.support.test:runner:1.0.2'
2727
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
28-
2928
implementation 'org.osmdroid:osmdroid-android:6.1.0'
3029
implementation 'com.github.MKergall:osmbonuspack:6.6.0'
3130
}

app/src/main/java/com/teamfire/picontroller/AutoDriveActivity.java

+3-9
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,15 @@ public boolean longPressHelper(GeoPoint p) {
122122
btn_showCoordinates.setOnClickListener(new View.OnClickListener() {
123123
@Override
124124
public void onClick(View view) {
125-
if (mapLat.getText() != null && mapLon.getText() != null) {
125+
try {
126126
GeoPoint markerPoint = new GeoPoint(Double.parseDouble(mapLat.getText().toString()), Double.parseDouble(mapLon.getText().toString()));
127127
startMarker.setPosition(markerPoint);
128128
startMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
129129
startMarker.setTitle("Target location");
130130
map.getOverlays().add(startMarker);
131131
map.invalidate();
132+
} catch (NumberFormatException e) {
133+
e.printStackTrace();
132134
}
133135
}
134136
});
@@ -165,12 +167,4 @@ public void onPause() {
165167
//Configuration.getInstance().save(this, prefs);
166168
map.onPause(); //needed for compass, my location overlays, v6.0.0 and up
167169
}
168-
169-
protected void onStop() {
170-
super.onStop();
171-
SharedPreferences.Editor editor = getSharedPreferences("IP", MODE_PRIVATE).edit();
172-
editor.putString("IP", ipAddress.getText().toString());
173-
editor.commit();
174-
}
175-
176170
}

app/src/main/java/com/teamfire/picontroller/MainActivity.java

-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.net.Socket;
2222
import java.net.UnknownHostException;
2323

24-
2524
public class MainActivity extends AppCompatActivity {
2625

2726
Button btn_down, btn_up, btn_left, btn_right, btn_autodrive, btn_camera;
@@ -33,7 +32,6 @@ public class MainActivity extends AppCompatActivity {
3332
public static int CMD;
3433
public String newUrl;
3534

36-
3735
@Override
3836
protected void onCreate(Bundle savedInstanceState) {
3937
super.onCreate(savedInstanceState);

app/src/main/res/layout/activity_autodrive.xml

+21-14
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<EditText
1010
android:id="@+id/ipAddress"
11-
android:layout_width="wrap_content"
11+
android:layout_width="200dp"
1212
android:layout_height="50dp"
1313
android:ems="10"
1414
android:inputType="textPersonName"
@@ -31,8 +31,8 @@
3131
style="@style/Widget.AppCompat.Button.Colored"
3232
android:layout_width="75dp"
3333
android:layout_height="60dp"
34-
android:layout_marginTop="8dp"
3534
android:layout_marginEnd="8dp"
35+
android:layout_marginTop="8dp"
3636
android:backgroundTint="@color/colorSecondary"
3737
android:text="MANUAL DRIVE"
3838
android:textSize="12dp"
@@ -44,20 +44,22 @@
4444
style="@style/Widget.AppCompat.Button.Colored"
4545
android:layout_width="65dp"
4646
android:layout_height="60dp"
47+
android:layout_marginEnd="4dp"
48+
android:layout_marginTop="8dp"
4749
android:backgroundTint="@color/colorPrimary"
4850
android:text="CAMERA"
4951
android:textSize="10dp"
5052
app:layout_constraintEnd_toStartOf="@+id/btn_manualDrive"
51-
app:layout_constraintTop_toTopOf="@+id/btn_manualDrive" />
53+
app:layout_constraintTop_toTopOf="parent" />
5254

5355
<WebView
5456
android:id="@+id/wb_liveFeed"
5557
android:layout_width="0dp"
5658
android:layout_height="0dp"
57-
android:layout_marginStart="8dp"
58-
android:layout_marginTop="8dp"
59-
android:layout_marginEnd="8dp"
6059
android:layout_marginBottom="8dp"
60+
android:layout_marginEnd="8dp"
61+
android:layout_marginStart="8dp"
62+
android:layout_marginTop="4dp"
6163
app:layout_constraintBottom_toTopOf="@+id/guideline"
6264
app:layout_constraintEnd_toEndOf="parent"
6365
app:layout_constraintStart_toStartOf="parent"
@@ -74,9 +76,10 @@
7476
android:id="@+id/mapLat"
7577
android:layout_width="0dp"
7678
android:layout_height="wrap_content"
79+
android:layout_marginEnd="2dp"
7780
android:layout_marginStart="8dp"
78-
android:layout_marginEnd="4dp"
7981
android:hint="Latitude"
82+
android:inputType="text"
8083
android:maxLines="1"
8184
android:textSize="12sp"
8285
app:layout_constraintEnd_toStartOf="@id/mapLon"
@@ -87,40 +90,44 @@
8790
android:id="@+id/mapLon"
8891
android:layout_width="0dp"
8992
android:layout_height="wrap_content"
90-
android:layout_marginStart="4dp"
91-
android:layout_marginEnd="8dp"
93+
android:layout_marginEnd="4dp"
94+
android:layout_marginStart="2dp"
95+
android:hint="Longitude"
96+
android:inputType="text"
9297
android:maxLines="1"
9398
android:textSize="12sp"
94-
android:hint="Longitude"
9599
app:layout_constraintEnd_toStartOf="@+id/btn_ShowCoordinates"
96100
app:layout_constraintStart_toEndOf="@+id/mapLat"
97101
app:layout_constraintTop_toTopOf="@+id/mapLat" />
98102

99103
<Button
100104
android:id="@+id/btn_ShowCoordinates"
105+
style="@style/Widget.AppCompat.Button.Colored"
101106
android:layout_width="wrap_content"
102107
android:layout_height="wrap_content"
103108
android:layout_marginEnd="8dp"
109+
android:backgroundTint="@color/colorShow"
104110
android:text="Show"
105111
app:layout_constraintEnd_toEndOf="parent"
106112
app:layout_constraintTop_toTopOf="@+id/mapLat" />
107113

108114
<org.osmdroid.views.MapView
109115
android:id="@+id/map"
110116
android:layout_width="wrap_content"
111-
android:layout_height="305dp"
112-
android:layout_marginTop="8dp"
117+
android:layout_height="0dp"
113118
app:layout_constraintBottom_toBottomOf="parent"
114119
app:layout_constraintEnd_toEndOf="parent"
115120
app:layout_constraintStart_toStartOf="parent"
116-
app:layout_constraintTop_toBottomOf="@+id/mapLat" />
121+
app:layout_constraintTop_toBottomOf="@+id/btn_ShowCoordinates" />
117122

118123
<Button
119124
android:id="@+id/btn_GPS"
125+
style="@style/Widget.AppCompat.Button.Colored"
120126
android:layout_width="wrap_content"
121127
android:layout_height="wrap_content"
122-
android:layout_marginStart="8dp"
123128
android:layout_marginBottom="8dp"
129+
android:layout_marginStart="8dp"
130+
android:backgroundTint="@color/colorGPS"
124131
android:text="GPS"
125132
app:layout_constraintBottom_toBottomOf="@+id/map"
126133
app:layout_constraintStart_toStartOf="parent" />

app/src/main/res/layout/activity_main.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
<EditText
4646
android:id="@+id/ipAddress"
47-
android:layout_width="wrap_content"
47+
android:layout_width="200dp"
4848
android:layout_height="50dp"
4949
android:ems="10"
5050
android:inputType="textPersonName"

app/src/main/res/values/colors.xml

+2
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@
1414
<color name="safePressed">#5c5c5c</color>
1515
<color name="emergency">#740000</color>
1616
<color name="emergencyPressed">#b97373</color>
17+
<color name="colorShow">#5caf76</color>
18+
<color name="colorGPS">#4e72be</color>
1719
</resources>

0 commit comments

Comments
 (0)