Skip to content

Commit fad6e5d

Browse files
erenkundakciAlim Öncül
authored and
Alim Öncül
committed
Added camera view and OpenStreetMaps MapView for Auto-Drive Activity. (#2)
1 parent fb104c7 commit fad6e5d

File tree

9 files changed

+136
-1
lines changed

9 files changed

+136
-1
lines changed

.idea/caches/build_file_checksums.ser

1 Byte
Binary file not shown.

.idea/caches/gradle_models.ser

3.13 KB
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.

app/build.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -25,4 +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+
29+
implementation 'org.osmdroid:osmdroid-android:6.1.0'
2830
}

app/src/main/AndroidManifest.xml

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
package="com.teamfire.picontroller">
44

55
<uses-permission android:name="android.permission.INTERNET" />
6+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
7+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
8+
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
9+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
10+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
611

712
<application
813
android:allowBackup="true"
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,59 @@
11
package com.teamfire.picontroller;
22

3+
import android.content.Context;
34
import android.content.Intent;
5+
import android.preference.PreferenceManager;
46
import android.support.v7.app.AppCompatActivity;
57
import android.os.Bundle;
68
import android.view.View;
9+
import android.view.WindowManager;
10+
import android.webkit.WebView;
11+
import android.webkit.WebViewClient;
712
import android.widget.Button;
13+
import android.widget.EditText;
14+
15+
import org.osmdroid.api.IMapController;
16+
import org.osmdroid.config.Configuration;
17+
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
18+
import org.osmdroid.util.GeoPoint;
19+
import org.osmdroid.views.MapView;
20+
821

922
public class AutoDriveActivity extends AppCompatActivity {
1023

11-
Button btn_manualDrive;
24+
Button btn_manualDrive, btn_camera;
25+
WebView wb_liveFeed;
26+
EditText ipAddress;
27+
MapView map = null;
28+
public static String wifiModuleIP;
29+
public static int wifiModulePort;
30+
public String newUrl;
1231

1332
@Override
1433
protected void onCreate(Bundle savedInstanceState) {
1534
super.onCreate(savedInstanceState);
1635
setContentView(R.layout.activity_autodrive);
36+
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
1737

1838
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+
43+
ipAddress.setText(getIntent().getStringExtra("IP_ADDRESS"));
44+
45+
btn_camera.setOnClickListener(new View.OnClickListener() {
46+
@Override
47+
public void onClick(View view) {
48+
getIPandPort();
49+
wb_liveFeed.getSettings().setJavaScriptEnabled(true);
50+
wb_liveFeed.getSettings().setUseWideViewPort(true);
51+
wb_liveFeed.getSettings().setLoadWithOverviewMode(true);
52+
wb_liveFeed.setWebViewClient(new WebViewClient());
53+
newUrl = "http://" + wifiModuleIP + ":8000/index.html";
54+
wb_liveFeed.loadData("<iframe src='" + newUrl + "' style='border: 0; width: 100%; height: 100%'></iframe>", "text/html; charset=utf-8", "UTF-8");
55+
}
56+
});
1957

2058
btn_manualDrive.setOnClickListener(new View.OnClickListener() {
2159
@Override
@@ -24,5 +62,46 @@ public void onClick(View view) {
2462
finish();
2563
}
2664
});
65+
66+
Context ctx = getApplicationContext();
67+
Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx));
68+
69+
70+
//inflate and create the map
71+
map = findViewById(R.id.map);
72+
map.setTileSource(TileSourceFactory.MAPNIK);
73+
map.setMultiTouchControls(true);
74+
75+
//default map view point
76+
IMapController mapController = map.getController();
77+
mapController.setZoom(7);
78+
GeoPoint startPoint = new GeoPoint(39.1667, 35.6667);
79+
mapController.setCenter(startPoint);
80+
81+
}
82+
83+
public void getIPandPort() {
84+
String iPandPort = ipAddress.getText().toString();
85+
String temp[] = iPandPort.split(":");
86+
wifiModuleIP = temp[0];
87+
wifiModulePort = Integer.valueOf(temp[1]);
88+
}
89+
90+
public void onResume(){
91+
super.onResume();
92+
//this will refresh the osmdroid configuration on resuming.
93+
//if you make changes to the configuration, use
94+
//SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
95+
//Configuration.getInstance().load(this, PreferenceManager.getDefaultSharedPreferences(this));
96+
map.onResume(); //needed for compass, my location overlays, v6.0.0 and up
97+
}
98+
99+
public void onPause(){
100+
super.onPause();
101+
//this will refresh the osmdroid configuration on resuming.
102+
//if you make changes to the configuration, use
103+
//SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
104+
//Configuration.getInstance().save(this, prefs);
105+
map.onPause(); //needed for compass, my location overlays, v6.0.0 and up
27106
}
28107
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ public void run() {
253253
@Override
254254
public void onClick(View view) {
255255
Intent intent = new Intent(MainActivity.this, AutoDriveActivity.class);
256+
intent.putExtra("IP_ADDRESS", ipAddress.getText().toString());
256257
startActivityForResult(intent, REQ_CODE);
257258
}
258259
});

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

+44
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,48 @@
3838
android:textSize="12dp"
3939
app:layout_constraintEnd_toEndOf="parent"
4040
app:layout_constraintTop_toTopOf="parent" />
41+
42+
<Button
43+
android:id="@+id/btn_camera2"
44+
style="@style/Widget.AppCompat.Button.Colored"
45+
android:layout_width="65dp"
46+
android:layout_height="60dp"
47+
android:backgroundTint="@color/colorPrimary"
48+
android:text="CAMERA"
49+
android:textSize="10dp"
50+
app:layout_constraintEnd_toStartOf="@+id/btn_manualDrive"
51+
app:layout_constraintTop_toTopOf="@+id/btn_manualDrive" />
52+
53+
<WebView
54+
android:id="@+id/wb_liveFeed2"
55+
android:layout_width="0dp"
56+
android:layout_height="0dp"
57+
android:layout_marginStart="8dp"
58+
android:layout_marginTop="8dp"
59+
android:layout_marginEnd="8dp"
60+
android:layout_marginBottom="8dp"
61+
app:layout_constraintBottom_toTopOf="@+id/guideline"
62+
app:layout_constraintEnd_toEndOf="parent"
63+
app:layout_constraintStart_toStartOf="parent"
64+
app:layout_constraintTop_toBottomOf="@+id/ipAddress2" />
65+
66+
<android.support.constraint.Guideline
67+
android:id="@+id/guideline"
68+
android:layout_width="wrap_content"
69+
android:layout_height="wrap_content"
70+
android:orientation="horizontal"
71+
app:layout_constraintGuide_percent="0.5" />
72+
73+
<org.osmdroid.views.MapView
74+
android:id="@+id/map"
75+
android:layout_width="wrap_content"
76+
android:layout_height="0dp"
77+
android:layout_marginStart="8dp"
78+
android:layout_marginEnd="8dp"
79+
android:layout_marginBottom="4dp"
80+
app:layout_constraintBottom_toBottomOf="parent"
81+
app:layout_constraintEnd_toEndOf="parent"
82+
app:layout_constraintStart_toStartOf="parent"
83+
app:layout_constraintTop_toBottomOf="@id/guideline" />
84+
4185
</android.support.constraint.ConstraintLayout>

build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ allprojects {
1919
repositories {
2020
google()
2121
jcenter()
22+
mavenCentral()
2223
}
2324
}
2425

0 commit comments

Comments
 (0)