Skip to content

Commit

Permalink
OSMDroid seems done
Browse files Browse the repository at this point in the history
  • Loading branch information
thermatk committed Apr 18, 2017
1 parent 1ec35e6 commit ac3dff9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2082,14 +2082,16 @@ public void onClick(DialogInterface dialogInterface, int i) {
builder.setNegativeButton(LocaleController.getString("ShareYouLocationUnableManually", R.string.ShareYouLocationUnableManually), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
/*

if (mainFragmentsStack.isEmpty()) {
return;
}
BaseFragment lastFragment = mainFragmentsStack.get(mainFragmentsStack.size() - 1);
/* OSMDroid!
if (!AndroidUtilities.isGoogleMapsInstalled(lastFragment)) {
return;
}
*/
LocationActivity fragment = new LocationActivity();
fragment.setDelegate(new LocationActivity.LocationActivityDelegate() {
@Override
Expand All @@ -2100,9 +2102,7 @@ public void didSelectLocation(TLRPC.MessageMedia location) {
}
}
});
presentFragment(fragment);*/

Toast.makeText(getApplicationContext(),"Telegram-FOSS: Disabled for now.", Toast.LENGTH_LONG).show();
presentFragment(fragment);
}
});
builder.setMessage(LocaleController.getString("ShareYouLocationUnable", R.string.ShareYouLocationUnable));
Expand Down
28 changes: 28 additions & 0 deletions TMessagesProj/src/main/java/org/telegram/ui/LocationActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@

import org.osmdroid.api.IMapController;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapController;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.Marker;

import org.osmdroid.views.overlay.mylocation.GpsMyLocationProvider;
import org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay;
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.UserObject;
import org.telegram.messenger.ApplicationLoader;
Expand Down Expand Up @@ -117,6 +120,8 @@ public class LocationActivity extends BaseFragment implements NotificationCenter
private final static int map_list_menu_satellite = 3;
private final static int map_list_menu_hybrid = 4;

private MyLocationNewOverlay myLocationOverlay;

public interface LocationActivityDelegate {
void didSelectLocation(TLRPC.MessageMedia location);
}
Expand Down Expand Up @@ -654,6 +659,22 @@ public void onMyLocationChange(Location location) {
positionMarker(location);
}
});*/
Activity parentActivity = getParentActivity();
GpsMyLocationProvider imlp = new GpsMyLocationProvider(parentActivity);
imlp.setLocationUpdateMinDistance(1000);
imlp.setLocationUpdateMinTime(60000);
myLocationOverlay = new MyLocationNewOverlay(imlp, mapView);
myLocationOverlay.enableMyLocation();
mapView.getOverlays().add(myLocationOverlay);
myLocationOverlay.setDrawAccuracyEnabled(true);

myLocationOverlay.runOnFirstFix(new Runnable() {
public void run() {

MapController mapController = (MapController) mapView.getController();
mapController.animateTo(myLocationOverlay.getMyLocation());
}
});

//mapView.setBuiltInZoomControls(true);
positionMarker(myLocation = getLastLocation());
Expand Down Expand Up @@ -783,6 +804,10 @@ public void run() {

private Location getLastLocation() {
LocationManager lm = (LocationManager) ApplicationLoader.applicationContext.getSystemService(Context.LOCATION_SERVICE);

if (getParentActivity().checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
getParentActivity().requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION}, 2);
}
List<String> providers = lm.getProviders(true);
Location l = null;
for (int i = providers.size() - 1; i >= 0; i--) {
Expand Down Expand Up @@ -903,6 +928,8 @@ public void didReceivedNotification(int id, Object... args) {
public void onPause() {
super.onPause();
if (mapView != null && mapsInitialized) {

myLocationOverlay.disableMyLocation();
/*
try {
mapView.onPause();
Expand All @@ -919,6 +946,7 @@ public void onResume() {
super.onResume();
AndroidUtilities.removeAdjustResize(getParentActivity(), classGuid);
if (mapView != null && mapsInitialized) {
myLocationOverlay.enableMyLocation();
/*
try {
mapView.onResume();
Expand Down

0 comments on commit ac3dff9

Please sign in to comment.