Add follow me button.
This commit is contained in:
parent
645f21b4b3
commit
0ee473a356
|
|
@ -15,7 +15,9 @@ import android.support.v7.app.AppCompatActivity;
|
|||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.Surface;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.osmdroid.api.IMapController;
|
||||
|
|
@ -23,6 +25,7 @@ import org.osmdroid.config.Configuration;
|
|||
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
|
||||
import org.osmdroid.util.GeoPoint;
|
||||
import org.osmdroid.views.MapView;
|
||||
import org.osmdroid.views.overlay.compass.CompassOverlay;
|
||||
import org.osmdroid.views.overlay.compass.IOrientationConsumer;
|
||||
import org.osmdroid.views.overlay.compass.IOrientationProvider;
|
||||
import org.osmdroid.views.overlay.compass.InternalCompassOrientationProvider;
|
||||
|
|
@ -40,11 +43,13 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
public static final String TAG = "MainActivity";
|
||||
|
||||
private MyLocationNewOverlay mLocationOverlay;
|
||||
private CompassOverlay mCompassOverlay;
|
||||
private IOrientationProvider compass = null;
|
||||
private IServiceGps serviceGps = null;
|
||||
|
||||
private Context ctx = null;
|
||||
private MapView map = null;
|
||||
private ImageButton btFollowMe;
|
||||
|
||||
private Float trueNorth = 0f;
|
||||
private int deviceOrientation = 0;
|
||||
|
|
@ -104,6 +109,11 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
GeoPoint startPoint = new GeoPoint(45.0000, 5.0000);
|
||||
mapController.setCenter(startPoint);
|
||||
|
||||
// Compass
|
||||
this.mCompassOverlay = new CompassOverlay(ctx, new InternalCompassOrientationProvider(ctx), map);
|
||||
map.getOverlays().add(this.mCompassOverlay);
|
||||
this.mCompassOverlay.enableCompass();
|
||||
|
||||
// Current position on the map
|
||||
this.mLocationOverlay = new MyLocationNewOverlay(new GpsMyLocationProvider(ctx), map);
|
||||
map.getOverlays().add(this.mLocationOverlay);
|
||||
|
|
@ -111,6 +121,21 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
mLocationOverlay.enableFollowLocation();
|
||||
mLocationOverlay.setOptionsMenuEnabled(true);
|
||||
|
||||
// Follow me
|
||||
btFollowMe = (ImageButton) findViewById(R.id.ic_follow_me);
|
||||
btFollowMe.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (!mLocationOverlay.isFollowLocationEnabled()) {
|
||||
mLocationOverlay.enableFollowLocation();
|
||||
btFollowMe.setImageResource(R.drawable.osm_ic_follow_me_on);
|
||||
} else {
|
||||
mLocationOverlay.disableFollowLocation();
|
||||
btFollowMe.setImageResource(R.drawable.osm_ic_follow_me);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (serviceGps == null) {
|
||||
serviceGps = new ServiceGps();
|
||||
((Observable) serviceGps).addObserver(this);
|
||||
|
|
@ -172,6 +197,9 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
}
|
||||
|
||||
private void pause() {
|
||||
if (mCompassOverlay != null) {
|
||||
mCompassOverlay.disableCompass();
|
||||
}
|
||||
if (compass != null) {
|
||||
compass.stopOrientationProvider();
|
||||
compass.destroy();
|
||||
|
|
|
|||
|
|
@ -1,9 +1,22 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/parent_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" >
|
||||
|
||||
<org.osmdroid.views.MapView android:id="@+id/map"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" />
|
||||
</LinearLayout>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/ic_follow_me"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_marginTop="11dp"
|
||||
android:background="#00ffffff"
|
||||
android:contentDescription="@string/bt_follow_me_description"
|
||||
android:cropToPadding="true"
|
||||
android:src="@drawable/osm_ic_follow_me_on" />
|
||||
</RelativeLayout>
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
<resources>
|
||||
<string name="app_name">MyTrackingDog</string>
|
||||
<string name="action_settings">Settings</string>
|
||||
<string name="bt_follow_me_description">Follow me</string>
|
||||
</resources>
|
||||
|
|
|
|||
Loading…
Reference in New Issue