Skip to content

Commit 4d11b68

Browse files
erenkundakciAlim Öncül
authored and
Alim Öncül
committed
AutoDriveActivity updates (#3)
* Added camera view and OpenStreetMaps MapView for Auto-Drive Activity. * A few code adjustments. * Map marker and GPS location added.
1 parent fad6e5d commit 4d11b68

10 files changed

+238
-40
lines changed

.idea/assetWizardSettings.xml

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

.idea/caches/build_file_checksums.ser

0 Bytes
Binary file not shown.

.idea/caches/gradle_models.ser

4.62 KB
Binary file not shown.

app/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ dependencies {
2727
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
2828

2929
implementation 'org.osmdroid:osmdroid-android:6.1.0'
30+
implementation 'com.github.MKergall:osmbonuspack:6.6.0'
3031
}

app/src/main/AndroidManifest.xml

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
android:roundIcon="@mipmap/ic_launcher_round"
1717
android:supportsRtl="true"
1818
android:theme="@style/AppTheme">
19-
<activity android:name=".AutoDriveActivity"></activity>
19+
<activity
20+
android:name=".AutoDriveActivity"
21+
android:windowSoftInputMode="adjustNothing"
22+
android:configChanges="orientation"
23+
android:screenOrientation="portrait"></activity>
2024
<activity
2125
android:name=".MainActivity"
2226
android:windowSoftInputMode="adjustNothing"
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,51 @@
11
package com.teamfire.picontroller;
22

3+
import android.app.Activity;
34
import android.content.Context;
45
import android.content.Intent;
6+
import android.content.SharedPreferences;
57
import android.preference.PreferenceManager;
8+
import android.support.v4.content.ContextCompat;
69
import android.support.v7.app.AppCompatActivity;
710
import android.os.Bundle;
811
import android.view.View;
9-
import android.view.WindowManager;
1012
import android.webkit.WebView;
1113
import android.webkit.WebViewClient;
1214
import android.widget.Button;
1315
import android.widget.EditText;
1416

1517
import org.osmdroid.api.IMapController;
1618
import org.osmdroid.config.Configuration;
19+
import org.osmdroid.events.MapEventsReceiver;
1720
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
1821
import org.osmdroid.util.GeoPoint;
1922
import org.osmdroid.views.MapView;
20-
23+
import org.osmdroid.views.overlay.MapEventsOverlay;
24+
import org.osmdroid.views.overlay.Marker;
2125

2226
public class AutoDriveActivity extends AppCompatActivity {
2327

24-
Button btn_manualDrive, btn_camera;
25-
WebView wb_liveFeed;
26-
EditText ipAddress;
27-
MapView map = null;
2828
public static String wifiModuleIP;
2929
public static int wifiModulePort;
3030
public String newUrl;
31+
Button btn_manualDrive, btn_camera, btn_showCoordinates, btn_GPS;
32+
WebView wb_liveFeed;
33+
EditText ipAddress, mapLat, mapLon;
34+
MapView map = null;
3135

3236
@Override
3337
protected void onCreate(Bundle savedInstanceState) {
3438
super.onCreate(savedInstanceState);
3539
setContentView(R.layout.activity_autodrive);
36-
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
3740

3841
btn_manualDrive = findViewById(R.id.btn_manualDrive);
39-
btn_camera = findViewById(R.id.btn_camera2);
40-
ipAddress = findViewById(R.id.ipAddress2);
41-
wb_liveFeed = findViewById(R.id.wb_liveFeed2);
42-
42+
btn_camera = findViewById(R.id.btn_camera);
43+
btn_showCoordinates = findViewById(R.id.btn_ShowCoordinates);
44+
btn_GPS = findViewById(R.id.btn_GPS);
45+
mapLat = findViewById(R.id.mapLat);
46+
mapLon = findViewById(R.id.mapLon);
47+
ipAddress = findViewById(R.id.ipAddress);
48+
wb_liveFeed = findViewById(R.id.wb_liveFeed);
4349
ipAddress.setText(getIntent().getStringExtra("IP_ADDRESS"));
4450

4551
btn_camera.setOnClickListener(new View.OnClickListener() {
@@ -58,26 +64,81 @@ public void onClick(View view) {
5864
btn_manualDrive.setOnClickListener(new View.OnClickListener() {
5965
@Override
6066
public void onClick(View view) {
61-
setResult(RESULT_OK, new Intent());
67+
String enteredIPAddress = ipAddress.getText().toString();
68+
Intent resultIntent = new Intent();
69+
resultIntent.putExtra("IP_ADDRESS_FROM_AUTODRIVE", enteredIPAddress);
70+
setResult(Activity.RESULT_OK, resultIntent);
6271
finish();
6372
}
6473
});
6574

6675
Context ctx = getApplicationContext();
6776
Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx));
6877

69-
7078
//inflate and create the map
7179
map = findViewById(R.id.map);
7280
map.setTileSource(TileSourceFactory.MAPNIK);
7381
map.setMultiTouchControls(true);
7482

7583
//default map view point
76-
IMapController mapController = map.getController();
77-
mapController.setZoom(7);
78-
GeoPoint startPoint = new GeoPoint(39.1667, 35.6667);
84+
final IMapController mapController = map.getController();
85+
mapController.setZoom(9);
86+
final GeoPoint startPoint = new GeoPoint(40.1022, 26.5167);
7987
mapController.setCenter(startPoint);
8088

89+
//GPS location marker
90+
Marker GPSMarker = new Marker(map);
91+
final GeoPoint markerPointGPS = new GeoPoint(40.15311283875724, 26.41108989715576);
92+
GPSMarker.setPosition(markerPointGPS);
93+
GPSMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
94+
GPSMarker.setIcon(ContextCompat.getDrawable(this, R.drawable.gps_marker));
95+
GPSMarker.setTitle("Device Location");
96+
map.getOverlays().add(GPSMarker);
97+
map.invalidate();
98+
99+
//marker placement
100+
final Marker startMarker = new Marker(map);
101+
final MapEventsReceiver mReceive = new MapEventsReceiver() {
102+
@Override
103+
public boolean singleTapConfirmedHelper(GeoPoint p) {
104+
mapLat.setText(String.valueOf(p.getLatitude()));
105+
mapLon.setText(String.valueOf(p.getLongitude()));
106+
GeoPoint markerPoint = new GeoPoint(p.getLatitude(), p.getLongitude());
107+
startMarker.setPosition(markerPoint);
108+
startMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
109+
startMarker.setTitle("Target location");
110+
map.getOverlays().add(startMarker);
111+
map.invalidate();
112+
return false;
113+
}
114+
115+
@Override
116+
public boolean longPressHelper(GeoPoint p) {
117+
return false;
118+
}
119+
};
120+
map.getOverlays().add(new MapEventsOverlay(mReceive));
121+
122+
btn_showCoordinates.setOnClickListener(new View.OnClickListener() {
123+
@Override
124+
public void onClick(View view) {
125+
if (mapLat.getText() != null && mapLon.getText() != null) {
126+
GeoPoint markerPoint = new GeoPoint(Double.parseDouble(mapLat.getText().toString()), Double.parseDouble(mapLon.getText().toString()));
127+
startMarker.setPosition(markerPoint);
128+
startMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
129+
startMarker.setTitle("Target location");
130+
map.getOverlays().add(startMarker);
131+
map.invalidate();
132+
}
133+
}
134+
});
135+
136+
btn_GPS.setOnClickListener(new View.OnClickListener() {
137+
@Override
138+
public void onClick(View view) {
139+
mapController.setCenter(markerPointGPS);
140+
}
141+
});
81142
}
82143

83144
public void getIPandPort() {
@@ -87,7 +148,7 @@ public void getIPandPort() {
87148
wifiModulePort = Integer.valueOf(temp[1]);
88149
}
89150

90-
public void onResume(){
151+
public void onResume() {
91152
super.onResume();
92153
//this will refresh the osmdroid configuration on resuming.
93154
//if you make changes to the configuration, use
@@ -96,12 +157,20 @@ public void onResume(){
96157
map.onResume(); //needed for compass, my location overlays, v6.0.0 and up
97158
}
98159

99-
public void onPause(){
160+
public void onPause() {
100161
super.onPause();
101162
//this will refresh the osmdroid configuration on resuming.
102163
//if you make changes to the configuration, use
103164
//SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
104165
//Configuration.getInstance().save(this, prefs);
105166
map.onPause(); //needed for compass, my location overlays, v6.0.0 and up
106167
}
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+
107176
}

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

+25-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.teamfire.picontroller;
22

3+
import android.app.Activity;
34
import android.content.Intent;
45
import android.content.SharedPreferences;
56
import android.os.AsyncTask;
@@ -13,6 +14,7 @@
1314
import android.webkit.WebViewClient;
1415
import android.widget.Button;
1516
import android.widget.EditText;
17+
1618
import java.io.IOException;
1719
import java.io.PrintStream;
1820
import java.net.InetAddress;
@@ -61,6 +63,15 @@ public void onClick(View v) {
6163
}
6264
});
6365

66+
btn_autodrive.setOnClickListener(new View.OnClickListener() {
67+
@Override
68+
public void onClick(View view) {
69+
Intent intent = new Intent(MainActivity.this, AutoDriveActivity.class);
70+
intent.putExtra("IP_ADDRESS", ipAddress.getText().toString());
71+
startActivityForResult(intent, REQ_CODE);
72+
}
73+
});
74+
6475
btn_up.setOnTouchListener(new View.OnTouchListener() {
6576
private Handler mHandler;
6677

@@ -248,15 +259,6 @@ public void run() {
248259
}
249260
};
250261
});
251-
252-
btn_autodrive.setOnClickListener(new View.OnClickListener() {
253-
@Override
254-
public void onClick(View view) {
255-
Intent intent = new Intent(MainActivity.this, AutoDriveActivity.class);
256-
intent.putExtra("IP_ADDRESS", ipAddress.getText().toString());
257-
startActivityForResult(intent, REQ_CODE);
258-
}
259-
});
260262
}
261263

262264
@Override
@@ -267,6 +269,20 @@ protected void onStop() {
267269
editor.commit();
268270
}
269271

272+
@Override
273+
public void onActivityResult(int requestCode, int resultCode, Intent data) {
274+
super.onActivityResult(requestCode, resultCode, data);
275+
switch (requestCode) {
276+
case (REQ_CODE): {
277+
if (resultCode == Activity.RESULT_OK) {
278+
String newText = data.getStringExtra("IP_ADDRESS_FROM_AUTODRIVE");
279+
ipAddress.setText(newText);
280+
}
281+
break;
282+
}
283+
}
284+
}
285+
270286
public void getIPandPort() {
271287
String iPandPort = ipAddress.getText().toString();
272288
String temp[] = iPandPort.split(":");
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<vector android:alpha="0.6"
2+
android:height="24dp"
3+
android:tint="#0000FF"
4+
android:viewportHeight="24.0"
5+
android:viewportWidth="24.0"
6+
android:width="24dp"
7+
xmlns:android="http://schemas.android.com/apk/res/android">
8+
<path
9+
android:fillColor="#FF000000"
10+
android:pathData="M12,8c-2.21,0 -4,1.79 -4,4s1.79,4 4,4 4,-1.79 4,-4 -1.79,-4 -4,-4zM20.94,11c-0.46,-4.17 -3.77,-7.48 -7.94,-7.94L13,1h-2v2.06C6.83,3.52 3.52,6.83 3.06,11L1,11v2h2.06c0.46,4.17 3.77,7.48 7.94,7.94L11,23h2v-2.06c4.17,-0.46 7.48,-3.77 7.94,-7.94L23,13v-2h-2.06zM12,19c-3.87,0 -7,-3.13 -7,-7s3.13,-7 7,-7 7,3.13 7,7 -3.13,7 -7,7z" />
11+
</vector>

0 commit comments

Comments
 (0)