Add dog's trace on map.
This commit is contained in:
parent
cc9fe02195
commit
3b3ff12f72
|
|
@ -66,11 +66,13 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
private final int REQUEST_CODE_ASK_PERMISSION = 123;
|
||||
|
||||
private static final float LINE_WIDTH_BIG = 12;
|
||||
private static final int COLOR_POLYLINE_STATIC = Color.RED;
|
||||
List<GeoPoint> lGeoPoint = new ArrayList<>();
|
||||
List<GeoPoint> lGeoPointTraceur = new ArrayList<>();
|
||||
List<GeoPoint> lGeoPointDog = new ArrayList<>();
|
||||
|
||||
private FloatingActionButton start_stop_trace;
|
||||
private FloatingActionButton start_stop_dog_trace;
|
||||
private boolean traceurActivated = false;
|
||||
private boolean dogActivated = false;
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||
protected void checkPermissions() {
|
||||
|
|
@ -84,20 +86,6 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
/*
|
||||
setContentView(R.layout.activity_main);
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
||||
fab.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
|
||||
.setAction("Action", null).show();
|
||||
}
|
||||
});
|
||||
*/
|
||||
//handle permissions first, before map is created. not depicted here
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
checkPermissions();
|
||||
|
|
@ -158,6 +146,13 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
changeStatusTrace();
|
||||
}
|
||||
});
|
||||
start_stop_dog_trace = (FloatingActionButton) findViewById(R.id.start_stop_dog_trace);
|
||||
start_stop_dog_trace.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
changeStatusDogTrace();
|
||||
}
|
||||
});
|
||||
|
||||
if (serviceGps == null) {
|
||||
serviceGps = new ServiceGps();
|
||||
|
|
@ -174,6 +169,15 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
}
|
||||
}
|
||||
|
||||
private void changeStatusDogTrace() {
|
||||
this.dogActivated = !this.dogActivated;
|
||||
if (this.dogActivated) {
|
||||
this.start_stop_dog_trace.setImageResource(R.drawable.ic_menu_offline);
|
||||
} else {
|
||||
this.start_stop_dog_trace.setImageResource(R.drawable.ic_menu_mylocation);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume(){
|
||||
super.onResume();
|
||||
|
|
@ -223,7 +227,7 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onPause(){
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
pause();
|
||||
}
|
||||
|
|
@ -346,22 +350,36 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
@Override
|
||||
public void update(Observable observable, Object o) {
|
||||
if (observable == serviceGps) {
|
||||
if (o instanceof String && (String) o == ServiceGps.NOTIF_NEW_LOCATION && traceurActivated) {
|
||||
lGeoPoint.add(((ServiceGps) serviceGps).getCurrentGeoPoint());
|
||||
map.getController().setCenter(((ServiceGps) serviceGps).getCurrentGeoPoint());
|
||||
if (o instanceof String && (String) o == ServiceGps.NOTIF_NEW_LOCATION) {
|
||||
GeoPoint currentPoint = ((ServiceGps) serviceGps).getCurrentGeoPoint();
|
||||
Polyline line = null;
|
||||
if (traceurActivated) {
|
||||
lGeoPointTraceur.add(((ServiceGps) serviceGps).getCurrentGeoPoint());
|
||||
map.getController().setCenter(currentPoint);
|
||||
|
||||
Polyline line = new Polyline(map);
|
||||
line.setTitle("Traceur");
|
||||
line.setSubDescription(Polyline.class.getCanonicalName());
|
||||
line.setWidth(LINE_WIDTH_BIG);
|
||||
line.setColor(COLOR_POLYLINE_STATIC);
|
||||
line.setPoints(lGeoPoint);
|
||||
line.setGeodesic(true);
|
||||
line.setInfoWindow(new BasicInfoWindow(R.layout.bonuspack_bubble, map));
|
||||
map.getOverlayManager().add(line);
|
||||
map.invalidate();
|
||||
line = new Polyline(map);
|
||||
line.setTitle("Traceur");
|
||||
line.setColor(Color.RED);
|
||||
line.setPoints(lGeoPointTraceur);
|
||||
|
||||
} else if (dogActivated) {
|
||||
lGeoPointDog.add(((ServiceGps) serviceGps).getCurrentGeoPoint());
|
||||
map.getController().setCenter(currentPoint);
|
||||
|
||||
line = new Polyline(map);
|
||||
line.setTitle("Dog");
|
||||
line.setColor(Color.BLUE);
|
||||
line.setPoints(lGeoPointDog);
|
||||
}
|
||||
|
||||
if (line != null) {
|
||||
line.setSubDescription(Polyline.class.getCanonicalName());
|
||||
line.setWidth(LINE_WIDTH_BIG);
|
||||
line.setGeodesic(true);
|
||||
line.setInfoWindow(new BasicInfoWindow(R.layout.bonuspack_bubble, map));
|
||||
map.getOverlayManager().add(line);
|
||||
map.invalidate();
|
||||
}
|
||||
float orientation = ((ServiceGps) serviceGps).getOrientation(deviceOrientation);
|
||||
if (orientation >= 0) {
|
||||
map.setMapOrientation(orientation);
|
||||
|
|
|
|||
|
|
@ -27,5 +27,15 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|start"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:background="@color/colorAccent"
|
||||
app:srcCompat="@android:drawable/ic_media_play" />
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/start_stop_dog_trace"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:background="@color/colorPrimary"
|
||||
app:srcCompat="@android:drawable/ic_media_play" />
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
|
|
|
|||
Loading…
Reference in New Issue