Reorganization of MainActivity code.
This commit is contained in:
parent
35d9b8ccfb
commit
f040aaa514
|
|
@ -103,6 +103,7 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//<editor-fold defaultstate="collapsed" desc="Activity life cycle">
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
@ -237,92 +238,6 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeStatusTrace() {
|
|
||||||
serviceGps.toggleTraceurActivation();
|
|
||||||
if (serviceGps.isTraceurActivated()) {
|
|
||||||
this.start_stop_trace.setText(R.string.trail_stop);
|
|
||||||
this.add_object.setVisibility(View.VISIBLE);
|
|
||||||
this.add_object.setText(R.string.trail_object);
|
|
||||||
this.start_stop_dog_trace.setVisibility(View.GONE);
|
|
||||||
updateDistance();
|
|
||||||
} else {
|
|
||||||
this.start_stop_trace.setText(R.string.trail_start);
|
|
||||||
this.add_object.setVisibility(View.GONE);
|
|
||||||
this.start_stop_dog_trace.setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void changeStatusDogTrace() {
|
|
||||||
serviceGps.toggleDogActivation();
|
|
||||||
if (serviceGps.isDogActivated()) {
|
|
||||||
this.start_stop_dog_trace.setText(R.string.dog_stop);
|
|
||||||
this.add_object.setVisibility(View.VISIBLE);
|
|
||||||
this.add_object.setText(R.string.dog_object);
|
|
||||||
this.start_stop_trace.setVisibility(View.GONE);
|
|
||||||
this.textViewCurrentLocation.setVisibility(View.GONE);
|
|
||||||
updateDistance();
|
|
||||||
} else {
|
|
||||||
this.start_stop_dog_trace.setText(R.string.dog_start);
|
|
||||||
this.add_object.setVisibility(View.GONE);
|
|
||||||
this.start_stop_trace.setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addMarker(GeoPoint gp, boolean isFound) {
|
|
||||||
Marker marker = new Marker(map);
|
|
||||||
marker.setIcon(getResources().getDrawable(isFound ? R.drawable.ic_marker_blue : R.drawable.ic_marker_red));
|
|
||||||
marker.setPosition(gp);
|
|
||||||
marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
|
|
||||||
marker.setTitle("Object");
|
|
||||||
marker.setDraggable(false);
|
|
||||||
marker.setOnMarkerClickListener(new Marker.OnMarkerClickListener() {
|
|
||||||
@Override
|
|
||||||
public boolean onMarkerClick(Marker marker, MapView mapView) {
|
|
||||||
if (serviceGps.isDogActivated()) {
|
|
||||||
GeoPoint gp = marker.getPosition();
|
|
||||||
WayPointLocation wpl = serviceGps.getPointTrail(gp.getLatitude(), gp.getLongitude());
|
|
||||||
if (wpl != null) {
|
|
||||||
wpl.setFound();
|
|
||||||
marker.setIcon(getResources().getDrawable(R.drawable.ic_marker_blue));
|
|
||||||
marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
map.getOverlays().add(marker);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void markAsFound() {
|
|
||||||
List<WayPointLocation> wpls = serviceGps.foundNearObjects();
|
|
||||||
boolean findMarker = false;
|
|
||||||
for (WayPointLocation wpl : wpls) {
|
|
||||||
if (wpl != null && !wpl.isFound()) {
|
|
||||||
wpl.setFound();
|
|
||||||
for (Overlay o : map.getOverlays()) {
|
|
||||||
if (o instanceof Marker) {
|
|
||||||
Marker marker = (Marker) o;
|
|
||||||
GeoPoint gp = marker.getPosition();
|
|
||||||
if (wpl.isEquals(gp.getLatitude(), gp.getLongitude())) {
|
|
||||||
marker.setIcon(getResources().getDrawable(R.drawable.ic_marker_blue));
|
|
||||||
marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
serviceGps.addPointObjectDog();
|
|
||||||
findMarker = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (wpls.isEmpty() || !findMarker) {
|
|
||||||
// if no object is near
|
|
||||||
WayPointLocation wpl = serviceGps.addPointObjectDog();
|
|
||||||
GeoPoint gp = new GeoPoint(wpl.getLatitude(), wpl.getLongitude(), wpl.getAltitude());
|
|
||||||
addMarker(gp, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume(){
|
public void onResume(){
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
@ -410,7 +325,9 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
||||||
}
|
}
|
||||||
zoomed = false;
|
zoomed = false;
|
||||||
}
|
}
|
||||||
|
//</editor-fold>
|
||||||
|
|
||||||
|
//<editor-fold defaultstate="collapsed" desc="Menu management">
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
// Inflate the menu; this adds items to the action bar if it is present.
|
// Inflate the menu; this adds items to the action bar if it is present.
|
||||||
|
|
@ -466,6 +383,7 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
||||||
|
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
//</editor-fold>
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
|
@ -529,7 +447,6 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onOrientationChanged(float orientationToMagneticNorth, IOrientationProvider source) {
|
public void onOrientationChanged(float orientationToMagneticNorth, IOrientationProvider source) {
|
||||||
//note, on devices without a compass this never fires...
|
//note, on devices without a compass this never fires...
|
||||||
|
|
@ -570,6 +487,94 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//<editor-fold defaultstate="collapsed" desc="Map management">
|
||||||
|
private void changeStatusTrace() {
|
||||||
|
serviceGps.toggleTraceurActivation();
|
||||||
|
if (serviceGps.isTraceurActivated()) {
|
||||||
|
this.start_stop_trace.setText(R.string.trail_stop);
|
||||||
|
this.add_object.setVisibility(View.VISIBLE);
|
||||||
|
this.add_object.setText(R.string.trail_object);
|
||||||
|
this.start_stop_dog_trace.setVisibility(View.GONE);
|
||||||
|
updateDistance();
|
||||||
|
} else {
|
||||||
|
this.start_stop_trace.setText(R.string.trail_start);
|
||||||
|
this.add_object.setVisibility(View.GONE);
|
||||||
|
this.start_stop_dog_trace.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void changeStatusDogTrace() {
|
||||||
|
serviceGps.toggleDogActivation();
|
||||||
|
if (serviceGps.isDogActivated()) {
|
||||||
|
this.start_stop_dog_trace.setText(R.string.dog_stop);
|
||||||
|
this.add_object.setVisibility(View.VISIBLE);
|
||||||
|
this.add_object.setText(R.string.dog_object);
|
||||||
|
this.start_stop_trace.setVisibility(View.GONE);
|
||||||
|
this.textViewCurrentLocation.setVisibility(View.GONE);
|
||||||
|
updateDistance();
|
||||||
|
} else {
|
||||||
|
this.start_stop_dog_trace.setText(R.string.dog_start);
|
||||||
|
this.add_object.setVisibility(View.GONE);
|
||||||
|
this.start_stop_trace.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addMarker(GeoPoint gp, boolean isFound) {
|
||||||
|
Marker marker = new Marker(map);
|
||||||
|
marker.setIcon(getResources().getDrawable(isFound ? R.drawable.ic_marker_blue : R.drawable.ic_marker_red));
|
||||||
|
marker.setPosition(gp);
|
||||||
|
marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
|
||||||
|
marker.setTitle("Object");
|
||||||
|
marker.setDraggable(false);
|
||||||
|
marker.setOnMarkerClickListener(new Marker.OnMarkerClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onMarkerClick(Marker marker, MapView mapView) {
|
||||||
|
if (serviceGps.isDogActivated()) {
|
||||||
|
GeoPoint gp = marker.getPosition();
|
||||||
|
WayPointLocation wpl = serviceGps.getPointTrail(gp.getLatitude(), gp.getLongitude());
|
||||||
|
if (wpl != null) {
|
||||||
|
wpl.setFound();
|
||||||
|
marker.setIcon(getResources().getDrawable(R.drawable.ic_marker_blue));
|
||||||
|
marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
map.getOverlays().add(marker);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void markAsFound() {
|
||||||
|
List<WayPointLocation> wpls = serviceGps.foundNearObjects();
|
||||||
|
boolean findMarker = false;
|
||||||
|
for (WayPointLocation wpl : wpls) {
|
||||||
|
if (wpl != null && !wpl.isFound()) {
|
||||||
|
wpl.setFound();
|
||||||
|
for (Overlay o : map.getOverlays()) {
|
||||||
|
if (o instanceof Marker) {
|
||||||
|
Marker marker = (Marker) o;
|
||||||
|
GeoPoint gp = marker.getPosition();
|
||||||
|
if (wpl.isEquals(gp.getLatitude(), gp.getLongitude())) {
|
||||||
|
marker.setIcon(getResources().getDrawable(R.drawable.ic_marker_blue));
|
||||||
|
marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
serviceGps.addPointObjectDog();
|
||||||
|
findMarker = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (wpls.isEmpty() || !findMarker) {
|
||||||
|
// if no object is near
|
||||||
|
WayPointLocation wpl = serviceGps.addPointObjectDog();
|
||||||
|
GeoPoint gp = new GeoPoint(wpl.getLatitude(), wpl.getLongitude(), wpl.getAltitude());
|
||||||
|
addMarker(gp, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void calculTrailDistance() {
|
private void calculTrailDistance() {
|
||||||
List<MyLocation> listLoc = serviceGps.getListGeoPointTraceur();
|
List<MyLocation> listLoc = serviceGps.getListGeoPointTraceur();
|
||||||
MyLocation last = null;
|
MyLocation last = null;
|
||||||
|
|
@ -621,6 +626,18 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
||||||
map.invalidate();
|
map.invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<GeoPoint> convertListLocation(MyLocationArray list) {
|
||||||
|
List<GeoPoint> ret = new ArrayList<>();
|
||||||
|
if (list != null) {
|
||||||
|
for (MyLocation loc : list) {
|
||||||
|
ret.add(new GeoPoint(loc.getLatitude(), loc.getLongitude(), loc.getAltitude()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
//</editor-fold>
|
||||||
|
|
||||||
|
//<editor-fold defaultstate="collapsed" desc="Service callback">
|
||||||
@Override
|
@Override
|
||||||
public void update(Observable observable, Object o) {
|
public void update(Observable observable, Object o) {
|
||||||
if (observable == serviceGps) {
|
if (observable == serviceGps) {
|
||||||
|
|
@ -714,17 +731,9 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//</editor-fold>
|
||||||
|
|
||||||
private List<GeoPoint> convertListLocation(MyLocationArray list) {
|
//<editor-fold defaultstate="collapsed" desc="Placeholder management">
|
||||||
List<GeoPoint> ret = new ArrayList<>();
|
|
||||||
if (list != null) {
|
|
||||||
for (MyLocation loc : list) {
|
|
||||||
ret.add(new GeoPoint(loc.getLatitude(), loc.getLongitude(), loc.getAltitude()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateDistance() {
|
private void updateDistance() {
|
||||||
String text = null;
|
String text = null;
|
||||||
if (serviceGps.isTraceurActivated()) {
|
if (serviceGps.isTraceurActivated()) {
|
||||||
|
|
@ -770,4 +779,5 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
||||||
this.textViewCurrentLocation.setVisibility(View.VISIBLE);
|
this.textViewCurrentLocation.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//</editor-fold>
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue