1
1
package com .teamfire .picontroller ;
2
2
3
+ import android .content .Context ;
3
4
import android .content .Intent ;
5
+ import android .preference .PreferenceManager ;
4
6
import android .support .v7 .app .AppCompatActivity ;
5
7
import android .os .Bundle ;
6
8
import android .view .View ;
9
+ import android .view .WindowManager ;
10
+ import android .webkit .WebView ;
11
+ import android .webkit .WebViewClient ;
7
12
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
+
8
21
9
22
public class AutoDriveActivity extends AppCompatActivity {
10
23
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 ;
12
31
13
32
@ Override
14
33
protected void onCreate (Bundle savedInstanceState ) {
15
34
super .onCreate (savedInstanceState );
16
35
setContentView (R .layout .activity_autodrive );
36
+ this .getWindow ().setSoftInputMode (WindowManager .LayoutParams .SOFT_INPUT_STATE_ALWAYS_HIDDEN );
17
37
18
38
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
+ });
19
57
20
58
btn_manualDrive .setOnClickListener (new View .OnClickListener () {
21
59
@ Override
@@ -24,5 +62,46 @@ public void onClick(View view) {
24
62
finish ();
25
63
}
26
64
});
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
27
106
}
28
107
}
0 commit comments