|
1 | 1 | package org.sofwerx.torgi.ui; |
2 | 2 |
|
3 | 3 | import android.Manifest; |
| 4 | +import android.app.Activity; |
4 | 5 | import android.app.AlertDialog; |
5 | 6 | import android.content.ActivityNotFoundException; |
6 | 7 | import android.content.ComponentName; |
|
24 | 25 | import android.support.v4.app.FragmentActivity; |
25 | 26 | import android.support.v4.content.ContextCompat; |
26 | 27 | import android.util.Log; |
| 28 | +import android.view.Menu; |
| 29 | +import android.view.MenuInflater; |
| 30 | +import android.view.MenuItem; |
27 | 31 | import android.view.View; |
28 | 32 | import android.widget.TextView; |
29 | 33 |
|
|
44 | 48 | import org.sofwerx.torgi.R; |
45 | 49 | import org.sofwerx.torgi.service.TorgiService; |
46 | 50 |
|
47 | | -public class MainActivity extends FragmentActivity implements GnssMeasurementListener { |
| 51 | +public class MainActivity extends Activity implements GnssMeasurementListener { |
48 | 52 | protected static final int REQUEST_DISABLE_BATTERY_OPTIMIZATION = 401; |
49 | 53 | private double CENTER_US_LAT = 39.181071d; |
50 | 54 | private double CENTER_US_LNG = -99.938295d; |
@@ -73,6 +77,11 @@ protected void onCreate(Bundle savedInstanceState) { |
73 | 77 | stat_tv = findViewById(R.id.status_text); |
74 | 78 | cur_tv = findViewById(R.id.current_text); |
75 | 79 | meas_tv = findViewById(R.id.measurement_text); |
| 80 | + View buttonMonitor = findViewById(R.id.mainButtonMonitor); |
| 81 | + buttonMonitor.setOnClickListener(v -> { |
| 82 | + startActivity(new Intent(MainActivity.this, MonitorActivity.class)); |
| 83 | + finish(); |
| 84 | + }); |
76 | 85 |
|
77 | 86 | meas_tv.setText("Acquiring satellites...\n", TextView.BufferType.EDITABLE); |
78 | 87 | stat_tv.setText("Acquiring satellites...\n", TextView.BufferType.EDITABLE); |
@@ -101,6 +110,28 @@ private void osmMapSetup() { |
101 | 110 | osmMap.setTilesScaledToDpi(true); //scales tiles to the current screen's DPI, helps with readability of labels |
102 | 111 | } |
103 | 112 |
|
| 113 | + @Override |
| 114 | + public boolean onCreateOptionsMenu(Menu menu) { |
| 115 | + MenuInflater inflater = getMenuInflater(); |
| 116 | + inflater.inflate(R.menu.menu_main, menu); |
| 117 | + return true; |
| 118 | + } |
| 119 | + |
| 120 | + @Override |
| 121 | + public boolean onOptionsItemSelected(MenuItem item) { |
| 122 | + // Handle item selection |
| 123 | + switch (item.getItemId()) { |
| 124 | + case R.id.action_settings: |
| 125 | + //TODO |
| 126 | + return true; |
| 127 | + case R.id.action_about: |
| 128 | + startActivity(new Intent(this,AboutActivity.class)); |
| 129 | + return true; |
| 130 | + default: |
| 131 | + return super.onOptionsItemSelected(item); |
| 132 | + } |
| 133 | + } |
| 134 | + |
104 | 135 | @Override |
105 | 136 | public void onResume() { |
106 | 137 | super.onResume(); |
@@ -180,7 +211,7 @@ private void drawMarker(LatLng pos, String info) { |
180 | 211 | currentOSM.setPosition(new GeoPoint(pos.latitude,pos.longitude)); |
181 | 212 | currentOSM.setAnchor(org.osmdroid.views.overlay.Marker.ANCHOR_CENTER,org.osmdroid.views.overlay.Marker.ANCHOR_CENTER); |
182 | 213 | currentOSM.setIcon(getResources().getDrawable(R.drawable.map_icon)); |
183 | | - currentOSM.setTitle("GPS"); |
| 214 | + currentOSM.setTitle("GNSS Fix"); |
184 | 215 | osmMap.getOverlays().add(currentOSM); |
185 | 216 | if (osmMap != null) { |
186 | 217 | osmMap.getController().setZoom(18d); |
@@ -390,30 +421,27 @@ public void run() { |
390 | 421 |
|
391 | 422 | @Override |
392 | 423 | public void onLocationChanged(final Location loc) { |
393 | | - runOnUiThread(new Runnable() { |
394 | | - @Override |
395 | | - public void run() { |
396 | | - StringBuffer out = new StringBuffer(); |
397 | | - |
398 | | - out.append("Lat: "+ String.valueOf(loc.getLatitude()) + "\n"); |
399 | | - out.append("Lon: " + String.valueOf(loc.getLongitude()) + "\n"); |
400 | | - out.append("Alt: " + String.valueOf(loc.getAltitude()) + "\n"); |
401 | | - out.append("Provider: " + String.valueOf(loc.getProvider()) + "\n"); |
402 | | - out.append("Time: " + fmtTime.format(loc.getTime()) + "\n"); |
403 | | - int sats = loc.getExtras().getInt("satellites"); |
404 | | - if (sats > 0) |
405 | | - out.append("FixSatCount: " + String.valueOf(sats) + "\n"); |
406 | | - if (loc.hasAccuracy()) |
407 | | - out.append("RadialAccuracy: " + String.valueOf(loc.getAccuracy()) + "\n"); |
408 | | - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { |
409 | | - if (loc.hasVerticalAccuracy()) |
410 | | - out.append("VerticalAccuracy: " + String.valueOf(loc.getVerticalAccuracyMeters()) + "\n"); |
411 | | - } |
412 | | - |
413 | | - String txt = out.toString() + "\n" + (serviceBound?torgiService.getGeoPackageRecorder().getGpkgFilename():"") + " SDK v" + Build.VERSION.SDK_INT; |
414 | | - cur_tv.setText(txt); |
415 | | - drawMarker(new LatLng(loc.getLatitude(), loc.getLongitude()),fmtTime.format(loc.getTime())+", ±"+(loc.hasAccuracy()?fmtAccuracy.format(loc.getAccuracy()):"")+"m"); |
| 424 | + runOnUiThread(() -> { |
| 425 | + StringBuffer out = new StringBuffer(); |
| 426 | + |
| 427 | + out.append("Lat: "+ String.valueOf(loc.getLatitude()) + "\n"); |
| 428 | + out.append("Lon: " + String.valueOf(loc.getLongitude()) + "\n"); |
| 429 | + out.append("Alt: " + String.valueOf(loc.getAltitude()) + "\n"); |
| 430 | + out.append("Provider: " + String.valueOf(loc.getProvider()) + "\n"); |
| 431 | + out.append("Time: " + fmtTime.format(loc.getTime()) + "\n"); |
| 432 | + int sats = loc.getExtras().getInt("satellites"); |
| 433 | + if (sats > 0) |
| 434 | + out.append("FixSatCount: " + String.valueOf(sats) + "\n"); |
| 435 | + if (loc.hasAccuracy()) |
| 436 | + out.append("RadialAccuracy: " + String.valueOf(loc.getAccuracy()) + "\n"); |
| 437 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { |
| 438 | + if (loc.hasVerticalAccuracy()) |
| 439 | + out.append("VerticalAccuracy: " + String.valueOf(loc.getVerticalAccuracyMeters()) + "\n"); |
416 | 440 | } |
| 441 | + |
| 442 | + String txt = out.toString() + "\n" + (serviceBound?torgiService.getGeoPackageRecorder().getGpkgFilename():"") + " SDK v" + Build.VERSION.SDK_INT; |
| 443 | + cur_tv.setText(txt); |
| 444 | + drawMarker(new LatLng(loc.getLatitude(), loc.getLongitude()),fmtTime.format(loc.getTime())+", ±"+(loc.hasAccuracy()?fmtAccuracy.format(loc.getAccuracy()):"")+"m"); |
417 | 445 | }); |
418 | 446 | } |
419 | 447 |
|
|
0 commit comments