mirror of
https://github.com/MGislv/NekoX.git
synced 2024-07-04 11:13:36 +00:00
[TF][MAPS] replace Google Maps with OSMDroid: ChatAttachAlertLocationLayout
(cherry picked from commit c58ae42234f5681e19d18c5da9d1d9627fa4d1c7)
This commit is contained in:
parent
5999186123
commit
6a3c15a231
|
@ -20,17 +20,21 @@ import android.content.Intent;
|
|||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Outline;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.location.Location;
|
||||
import android.location.LocationManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.text.Html;
|
||||
import android.text.TextUtils;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.view.MotionEvent;
|
||||
|
@ -44,20 +48,21 @@ import android.widget.ImageView;
|
|||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.android.gms.maps.CameraUpdate;
|
||||
import com.google.android.gms.maps.CameraUpdateFactory;
|
||||
import com.google.android.gms.maps.GoogleMap;
|
||||
import com.google.android.gms.maps.MapView;
|
||||
import com.google.android.gms.maps.MapsInitializer;
|
||||
import com.google.android.gms.maps.Projection;
|
||||
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
|
||||
import com.google.android.gms.maps.model.CameraPosition;
|
||||
import com.google.android.gms.maps.model.CircleOptions;
|
||||
import com.google.android.gms.maps.model.LatLng;
|
||||
import com.google.android.gms.maps.model.MapStyleOptions;
|
||||
import com.google.android.gms.maps.model.Marker;
|
||||
import com.google.android.gms.maps.model.MarkerOptions;
|
||||
|
||||
import org.osmdroid.api.IGeoPoint;
|
||||
import org.osmdroid.api.IMapController;
|
||||
import org.osmdroid.events.MapListener;
|
||||
import org.osmdroid.events.ScrollEvent;
|
||||
import org.osmdroid.events.ZoomEvent;
|
||||
import org.osmdroid.tileprovider.tilesource.ITileSource;
|
||||
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
|
||||
import org.osmdroid.tileprovider.tilesource.XYTileSource;
|
||||
import org.osmdroid.util.GeoPoint;
|
||||
import org.osmdroid.views.MapView;
|
||||
import org.osmdroid.views.Projection;
|
||||
import org.osmdroid.views.overlay.Marker;
|
||||
import org.osmdroid.views.overlay.mylocation.GpsMyLocationProvider;
|
||||
import org.osmdroid.views.overlay.mylocation.IMyLocationProvider;
|
||||
import org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay;
|
||||
import org.telegram.messenger.AndroidUtilities;
|
||||
import org.telegram.messenger.ApplicationLoader;
|
||||
import org.telegram.messenger.FileLog;
|
||||
|
@ -108,16 +113,14 @@ public class ChatAttachAlertLocationLayout extends ChatAttachAlert.AttachAlertLa
|
|||
private ActionBarMenuItem searchItem;
|
||||
private MapOverlayView overlayView;
|
||||
|
||||
private GoogleMap googleMap;
|
||||
private MapView mapView;
|
||||
private CameraUpdate forceUpdate;
|
||||
private IGeoPoint forceUpdate;
|
||||
private float yOffset;
|
||||
|
||||
private boolean ignoreLayout;
|
||||
|
||||
private boolean scrolling;
|
||||
|
||||
private View loadingMapView;
|
||||
private FrameLayout mapViewClip;
|
||||
private LocationActivityAdapter adapter;
|
||||
private RecyclerListView listView;
|
||||
|
@ -128,6 +131,8 @@ public class ChatAttachAlertLocationLayout extends ChatAttachAlert.AttachAlertLa
|
|||
private AvatarDrawable avatarDrawable;
|
||||
private ActionBarMenuItem otherItem;
|
||||
|
||||
private TextView attributionOverlay;
|
||||
|
||||
private boolean currentMapStyleDark;
|
||||
|
||||
private boolean checkGpsEnabled = true;
|
||||
|
@ -164,7 +169,7 @@ public class ChatAttachAlertLocationLayout extends ChatAttachAlert.AttachAlertLa
|
|||
private boolean userLocationMoved;
|
||||
private boolean searchedForCustomLocations;
|
||||
private boolean firstWas;
|
||||
private CircleOptions circleOptions;
|
||||
|
||||
private LocationActivityDelegate delegate;
|
||||
|
||||
private int locationType;
|
||||
|
@ -174,10 +179,11 @@ public class ChatAttachAlertLocationLayout extends ChatAttachAlert.AttachAlertLa
|
|||
private int clipSize;
|
||||
private int nonClipSize;
|
||||
|
||||
private final static int map_list_menu_map = 2;
|
||||
private final static int map_list_menu_satellite = 3;
|
||||
private final static int map_list_menu_hybrid = 4;
|
||||
private final static int map_list_menu_osm = 2;
|
||||
private final static int map_list_menu_wiki = 3;
|
||||
private final static int map_list_menu_cartodark = 4;
|
||||
|
||||
private MyLocationNewOverlay myLocationOverlay;
|
||||
public final static int LOCATION_TYPE_SEND = 0;
|
||||
public final static int LOCATION_TYPE_SEND_WITH_LIVE = 1;
|
||||
|
||||
|
@ -233,8 +239,7 @@ public class ChatAttachAlertLocationLayout extends ChatAttachAlert.AttachAlertLa
|
|||
super(context);
|
||||
}
|
||||
|
||||
public void addInfoView(Marker marker) {
|
||||
VenueLocation location = (VenueLocation) marker.getTag();
|
||||
public void addInfoView(Marker marker, VenueLocation location) {
|
||||
if (lastPressedVenue == location) {
|
||||
return;
|
||||
}
|
||||
|
@ -338,7 +343,8 @@ public class ChatAttachAlertLocationLayout extends ChatAttachAlert.AttachAlertLa
|
|||
|
||||
views.put(marker, frameLayout);
|
||||
|
||||
googleMap.animateCamera(CameraUpdateFactory.newLatLng(marker.getPosition()), 300, null);
|
||||
final IMapController controller = mapView.getController();
|
||||
controller.animateTo(marker.getPosition(),mapView.getZoomLevelDouble(),300L);
|
||||
}
|
||||
|
||||
public void removeInfoView(Marker marker) {
|
||||
|
@ -349,15 +355,16 @@ public class ChatAttachAlertLocationLayout extends ChatAttachAlert.AttachAlertLa
|
|||
}
|
||||
}
|
||||
|
||||
//TODO
|
||||
public void updatePositions() {
|
||||
if (googleMap == null) {
|
||||
if (mapView == null) {
|
||||
return;
|
||||
}
|
||||
Projection projection = googleMap.getProjection();
|
||||
Projection projection = mapView.getProjection();
|
||||
for (HashMap.Entry<Marker, View> entry : views.entrySet()) {
|
||||
Marker marker = entry.getKey();
|
||||
View view = entry.getValue();
|
||||
Point point = projection.toScreenLocation(marker.getPosition());
|
||||
Point point = projection.toPixels(marker.getPosition(),null);
|
||||
view.setTranslationX(point.x - view.getMeasuredWidth() / 2);
|
||||
view.setTranslationY(point.y - view.getMeasuredHeight() + AndroidUtilities.dp(22));
|
||||
}
|
||||
|
@ -496,9 +503,6 @@ public class ChatAttachAlertLocationLayout extends ChatAttachAlert.AttachAlertLa
|
|||
};
|
||||
mapViewClip.setWillNotDraw(false);
|
||||
|
||||
loadingMapView = new View(context);
|
||||
loadingMapView.setBackgroundDrawable(new MapPlaceholderDrawable());
|
||||
|
||||
searchAreaButton = new SearchButton(context);
|
||||
searchAreaButton.setTranslationX(-AndroidUtilities.dp(80));
|
||||
searchAreaButton.setVisibility(INVISIBLE);
|
||||
|
@ -542,9 +546,9 @@ public class ChatAttachAlertLocationLayout extends ChatAttachAlert.AttachAlertLa
|
|||
mapTypeButton.setSubMenuOpenSide(2);
|
||||
mapTypeButton.setAdditionalXOffset(AndroidUtilities.dp(10));
|
||||
mapTypeButton.setAdditionalYOffset(-AndroidUtilities.dp(10));
|
||||
mapTypeButton.addSubItem(map_list_menu_map, R.drawable.msg_map, LocaleController.getString("Map", R.string.Map));
|
||||
mapTypeButton.addSubItem(map_list_menu_satellite, R.drawable.msg_satellite, LocaleController.getString("Satellite", R.string.Satellite));
|
||||
mapTypeButton.addSubItem(map_list_menu_hybrid, R.drawable.msg_hybrid, LocaleController.getString("Hybrid", R.string.Hybrid));
|
||||
mapTypeButton.addSubItem(map_list_menu_osm, R.drawable.msg_map, "Standard OSM");
|
||||
mapTypeButton.addSubItem(map_list_menu_wiki, R.drawable.msg_map, "Wikimedia");
|
||||
mapTypeButton.addSubItem(map_list_menu_cartodark, R.drawable.msg_map, "Carto Dark");
|
||||
mapTypeButton.setContentDescription(LocaleController.getString("AccDescrMoreOptions", R.string.AccDescrMoreOptions));
|
||||
drawable = Theme.createSimpleSelectorCircleDrawable(AndroidUtilities.dp(40), Theme.getColor(Theme.key_location_actionBackground), Theme.getColor(Theme.key_location_actionPressedBackground));
|
||||
if (Build.VERSION.SDK_INT < 21) {
|
||||
|
@ -571,18 +575,38 @@ public class ChatAttachAlertLocationLayout extends ChatAttachAlert.AttachAlertLa
|
|||
mapViewClip.addView(mapTypeButton, LayoutHelper.createFrame(Build.VERSION.SDK_INT >= 21 ? 40 : 44, Build.VERSION.SDK_INT >= 21 ? 40 : 44, Gravity.RIGHT | Gravity.TOP, 0, 12, 12, 0));
|
||||
mapTypeButton.setOnClickListener(v -> mapTypeButton.toggleSubMenu());
|
||||
mapTypeButton.setDelegate(id -> {
|
||||
if (googleMap == null) {
|
||||
if (mapView == null) {
|
||||
return;
|
||||
}
|
||||
if (id == map_list_menu_map) {
|
||||
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
|
||||
} else if (id == map_list_menu_satellite) {
|
||||
googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
|
||||
} else if (id == map_list_menu_hybrid) {
|
||||
googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
|
||||
if (id == map_list_menu_osm) {
|
||||
attributionOverlay.setText(Html.fromHtml("© <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> contributors"));
|
||||
mapView.setTileSource(TileSourceFactory.MAPNIK);
|
||||
} else if (id == map_list_menu_wiki) {
|
||||
// Create a custom tile source
|
||||
ITileSource tileSource = new XYTileSource(
|
||||
"Wikimedia", 0, 19,
|
||||
256, ".png",
|
||||
new String[] {"https://maps.wikimedia.org/osm-intl/"},
|
||||
"© OpenStreetMap contributors");
|
||||
attributionOverlay.setText(Html.fromHtml("© <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> contributors"));
|
||||
mapView.setTileSource(tileSource);
|
||||
} else if (id == map_list_menu_cartodark) {
|
||||
// Create a custom tile source
|
||||
ITileSource tileSource = new XYTileSource(
|
||||
"Carto Dark", 0, 20,
|
||||
256, ".png",
|
||||
new String[]{
|
||||
"https://cartodb-basemaps-a.global.ssl.fastly.net/dark_all/",
|
||||
"https://cartodb-basemaps-b.global.ssl.fastly.net/dark_all/",
|
||||
"https://cartodb-basemaps-c.global.ssl.fastly.net/dark_all/",
|
||||
"https://cartodb-basemaps-d.global.ssl.fastly.net/dark_all/"},
|
||||
"© OpenStreetMap contributors, © CARTO");
|
||||
attributionOverlay.setText(Html.fromHtml("© <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> contributors, © <a href=\"https://carto.com/attributions\">CARTO</a>"));
|
||||
mapView.setTileSource(tileSource);
|
||||
}
|
||||
});
|
||||
|
||||
mapViewClip.addView(getAttributionOverlay(context), LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM, LocaleController.isRTL ? 0 : 4, 0, LocaleController.isRTL ? 4 : 0, 20));
|
||||
locationButton = new ImageView(context);
|
||||
drawable = Theme.createSimpleSelectorCircleDrawable(AndroidUtilities.dp(40), Theme.getColor(Theme.key_location_actionBackground), Theme.getColor(Theme.key_location_actionPressedBackground));
|
||||
if (Build.VERSION.SDK_INT < 21) {
|
||||
|
@ -622,13 +646,14 @@ public class ChatAttachAlertLocationLayout extends ChatAttachAlert.AttachAlertLa
|
|||
}
|
||||
}
|
||||
}
|
||||
if (myLocation != null && googleMap != null) {
|
||||
if (myLocation != null && mapView != null) {
|
||||
locationButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_location_actionActiveIcon), PorterDuff.Mode.MULTIPLY));
|
||||
locationButton.setTag(Theme.key_location_actionActiveIcon);
|
||||
adapter.setCustomLocation(null);
|
||||
userLocationMoved = false;
|
||||
showSearchPlacesButton(false);
|
||||
googleMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(myLocation.getLatitude(), myLocation.getLongitude())));
|
||||
final IMapController controller = mapView.getController();
|
||||
controller.animateTo(new GeoPoint(myLocation.getLatitude(), myLocation.getLongitude()));
|
||||
if (searchedForCustomLocations) {
|
||||
if (myLocation != null) {
|
||||
adapter.searchPlacesWithQuery(null, myLocation, true, true);
|
||||
|
@ -773,7 +798,8 @@ public class ChatAttachAlertLocationLayout extends ChatAttachAlert.AttachAlertLa
|
|||
}
|
||||
} else if (object instanceof LiveLocation) {
|
||||
LiveLocation liveLocation = (LiveLocation) object;
|
||||
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(liveLocation.marker.getPosition(), googleMap.getMaxZoomLevel() - 4));
|
||||
final IMapController controller = mapView.getController();
|
||||
controller.animateTo(liveLocation.marker.getPosition(), mapView.getMaxZoomLevel() -2,null);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -799,7 +825,7 @@ public class ChatAttachAlertLocationLayout extends ChatAttachAlert.AttachAlertLa
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||
public boolean onTouchEvent(MotionEvent ev) {
|
||||
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
if (animatorSet != null) {
|
||||
animatorSet.cancel();
|
||||
|
@ -825,52 +851,33 @@ public class ChatAttachAlertLocationLayout extends ChatAttachAlert.AttachAlertLa
|
|||
locationButton.setTag(Theme.key_location_actionIcon);
|
||||
userLocationMoved = true;
|
||||
}
|
||||
if (googleMap != null) {
|
||||
if (mapView != null) {
|
||||
if (userLocation != null) {
|
||||
userLocation.setLatitude(googleMap.getCameraPosition().target.latitude);
|
||||
userLocation.setLongitude(googleMap.getCameraPosition().target.longitude);
|
||||
userLocation.setLatitude(mapView.getMapCenter().getLatitude());
|
||||
userLocation.setLongitude(mapView.getMapCenter().getLongitude());
|
||||
}
|
||||
}
|
||||
adapter.setCustomLocation(userLocation);
|
||||
}
|
||||
return super.onInterceptTouchEvent(ev);
|
||||
return super.onTouchEvent(ev);
|
||||
}
|
||||
};
|
||||
final MapView map = mapView;
|
||||
new Thread(() -> {
|
||||
try {
|
||||
map.onCreate(null);
|
||||
} catch (Exception e) {
|
||||
//this will cause exception, but will preload google maps?
|
||||
}
|
||||
AndroidUtilities.runOnUIThread(() -> {
|
||||
if (mapView != null && getParentActivity() != null) {
|
||||
try {
|
||||
map.onCreate(null);
|
||||
MapsInitializer.initialize(ApplicationLoader.applicationContext);
|
||||
mapView.getMapAsync(map1 -> {
|
||||
googleMap = map1;
|
||||
googleMap.setOnMapLoadedCallback(() -> AndroidUtilities.runOnUIThread(() -> {
|
||||
loadingMapView.setTag(1);
|
||||
loadingMapView.animate().alpha(0.0f).setDuration(180).start();
|
||||
}));
|
||||
onMapInit();
|
||||
mapsInitialized = true;
|
||||
if (isActiveThemeDark()) {
|
||||
currentMapStyleDark = true;
|
||||
/*currentMapStyleDark = true;
|
||||
MapStyleOptions style = MapStyleOptions.loadRawResourceStyle(ApplicationLoader.applicationContext, R.raw.mapstyle_night);
|
||||
googleMap.setMapStyle(style);
|
||||
*/
|
||||
//TODO Dark?
|
||||
}
|
||||
onMapInit();
|
||||
});
|
||||
mapsInitialized = true;
|
||||
if (onResumeCalled) {
|
||||
mapView.onResume();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}).start();
|
||||
|
||||
markerImageView = new ImageView(context);
|
||||
markerImageView.setImageResource(R.drawable.map_pin2);
|
||||
|
@ -922,6 +929,15 @@ public class ChatAttachAlertLocationLayout extends ChatAttachAlert.AttachAlertLa
|
|||
updateEmptyView();
|
||||
}
|
||||
|
||||
private TextView getAttributionOverlay(Context context) {
|
||||
attributionOverlay = new TextView(context);
|
||||
attributionOverlay.setText(Html.fromHtml("© <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> contributors"));
|
||||
attributionOverlay.setShadowLayer(1, -1, -1, Color.WHITE);
|
||||
attributionOverlay.setLinksClickable(true);
|
||||
attributionOverlay.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
return attributionOverlay;
|
||||
}
|
||||
|
||||
@Override
|
||||
void onPause() {
|
||||
if (mapView != null && mapsInitialized) {
|
||||
|
@ -930,6 +946,10 @@ public class ChatAttachAlertLocationLayout extends ChatAttachAlert.AttachAlertLa
|
|||
} catch (Exception e) {
|
||||
FileLog.e(e);
|
||||
}
|
||||
if(mapView.getOverlays().contains(myLocationOverlay)) {
|
||||
mapView.getOverlays().remove(myLocationOverlay);
|
||||
}
|
||||
myLocationOverlay.disableMyLocation();
|
||||
}
|
||||
onResumeCalled = false;
|
||||
}
|
||||
|
@ -937,27 +957,19 @@ public class ChatAttachAlertLocationLayout extends ChatAttachAlert.AttachAlertLa
|
|||
@Override
|
||||
void onDestroy() {
|
||||
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.locationPermissionGranted);
|
||||
try {
|
||||
if (googleMap != null) {
|
||||
googleMap.setMyLocationEnabled(false);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e(e);
|
||||
}
|
||||
// TODO
|
||||
// proper exit, like upstream does with
|
||||
// setMyLocationEnabled(false);
|
||||
if (mapView != null) {
|
||||
mapView.setTranslationY(-AndroidUtilities.displaySize.y * 3);
|
||||
}
|
||||
try {
|
||||
if (mapView != null) {
|
||||
mapView.onPause();
|
||||
if(mapView.getOverlays().contains(myLocationOverlay)) {
|
||||
mapView.getOverlays().remove(myLocationOverlay);
|
||||
}
|
||||
} catch (Exception ignore) {
|
||||
|
||||
}
|
||||
try {
|
||||
if (mapView != null) {
|
||||
mapView.onDestroy();
|
||||
mapView = null;
|
||||
myLocationOverlay.disableMyLocation();
|
||||
}
|
||||
} catch (Exception ignore) {
|
||||
|
||||
|
@ -1163,23 +1175,37 @@ public class ChatAttachAlertLocationLayout extends ChatAttachAlert.AttachAlertLa
|
|||
return;
|
||||
}
|
||||
for (int a = 0, N = placeMarkers.size(); a < N; a++) {
|
||||
placeMarkers.get(a).marker.remove();
|
||||
placeMarkers.get(a).marker.remove(mapView);
|
||||
}
|
||||
placeMarkers.clear();
|
||||
for (int a = 0, N = places.size(); a < N; a++) {
|
||||
TLRPC.TL_messageMediaVenue venue = places.get(a);
|
||||
try {
|
||||
MarkerOptions options = new MarkerOptions().position(new LatLng(venue.geo.lat, venue.geo._long));
|
||||
options.icon(BitmapDescriptorFactory.fromBitmap(createPlaceBitmap(a)));
|
||||
options.anchor(0.5f, 0.5f);
|
||||
options.title(venue.title);
|
||||
options.snippet(venue.address);
|
||||
Marker marker = new Marker(mapView);
|
||||
marker.setPosition(new GeoPoint(venue.geo.lat, venue.geo._long));
|
||||
marker.setIcon(new BitmapDrawable(getParentActivity().getResources(), createPlaceBitmap(a)));
|
||||
marker.setAnchor(0.5f, 0.5f);
|
||||
mapView.getOverlays().add(marker);
|
||||
marker.setTitle(venue.title);
|
||||
marker.setSnippet(venue.address);
|
||||
VenueLocation venueLocation = new VenueLocation();
|
||||
venueLocation.num = a;
|
||||
venueLocation.marker = googleMap.addMarker(options);
|
||||
venueLocation.marker = marker;
|
||||
venueLocation.venue = venue;
|
||||
venueLocation.marker.setTag(venueLocation);
|
||||
placeMarkers.add(venueLocation);
|
||||
marker.setOnMarkerClickListener(new Marker.OnMarkerClickListener() {
|
||||
@Override
|
||||
public boolean onMarkerClick(Marker marker, MapView mapView) {
|
||||
markerImageView.setVisibility(View.INVISIBLE);
|
||||
if (!userLocationMoved) {
|
||||
locationButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_location_actionIcon), PorterDuff.Mode.MULTIPLY));
|
||||
locationButton.setTag(Theme.key_location_actionIcon);
|
||||
userLocationMoved = true;
|
||||
}
|
||||
overlayView.addInfoView(marker, venueLocation);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
FileLog.e(e);
|
||||
}
|
||||
|
@ -1203,24 +1229,50 @@ public class ChatAttachAlertLocationLayout extends ChatAttachAlert.AttachAlertLa
|
|||
}
|
||||
|
||||
private void onMapInit() {
|
||||
if (googleMap == null) {
|
||||
if (mapView == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
userLocation = new Location("network");
|
||||
userLocation.setLatitude(20.659322);
|
||||
userLocation.setLongitude(-11.406250);
|
||||
//Paris, Tour Eiffel
|
||||
GeoPoint initLocation = new GeoPoint(48.85825, 2.29448);
|
||||
final IMapController controller = mapView.getController();
|
||||
mapView.setMaxZoomLevel(20.0);
|
||||
mapView.setMultiTouchControls(true);
|
||||
mapView.setBuiltInZoomControls(false);
|
||||
controller.setCenter(initLocation);
|
||||
controller.setZoom(7.);
|
||||
|
||||
try {
|
||||
googleMap.setMyLocationEnabled(true);
|
||||
} catch (Exception e) {
|
||||
FileLog.e(e);
|
||||
userLocation = new Location("network");
|
||||
userLocation.setLatitude(48.85825);
|
||||
userLocation.setLongitude(2.29448);
|
||||
|
||||
GpsMyLocationProvider imlp = new GpsMyLocationProvider(getParentActivity());
|
||||
imlp.setLocationUpdateMinDistance(10);
|
||||
imlp.setLocationUpdateMinTime(10000);
|
||||
imlp.addLocationSource(LocationManager.NETWORK_PROVIDER);
|
||||
myLocationOverlay = new MyLocationNewOverlay(imlp, mapView) {
|
||||
@Override
|
||||
public void onLocationChanged(final Location location, IMyLocationProvider source) {
|
||||
super.onLocationChanged(location, source);
|
||||
if (location != null) {
|
||||
AndroidUtilities.runOnUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
positionMarker(location);
|
||||
getLocationController().setGoogleMapLocation(location, isFirstLocation);
|
||||
isFirstLocation = false;
|
||||
}
|
||||
googleMap.getUiSettings().setMyLocationButtonEnabled(false);
|
||||
googleMap.getUiSettings().setZoomControlsEnabled(false);
|
||||
googleMap.getUiSettings().setCompassEnabled(false);
|
||||
googleMap.setOnCameraMoveStartedListener(reason -> {
|
||||
if (reason == GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE) {
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
myLocationOverlay.enableMyLocation();
|
||||
myLocationOverlay.setDrawAccuracyEnabled(true);
|
||||
//TODO
|
||||
|
||||
mapView.addMapListener(new MapListener() {
|
||||
@Override
|
||||
public boolean onScroll(ScrollEvent event) {
|
||||
showSearchPlacesButton(true);
|
||||
removeInfoView();
|
||||
|
||||
|
@ -1232,48 +1284,49 @@ public class ChatAttachAlertLocationLayout extends ChatAttachAlert.AttachAlertLa
|
|||
int min = locationType == LOCATION_TYPE_SEND ? 0 : AndroidUtilities.dp(66);
|
||||
int top = view.getTop();
|
||||
if (top < -min) {
|
||||
CameraPosition cameraPosition = googleMap.getCameraPosition();
|
||||
forceUpdate = CameraUpdateFactory.newLatLngZoom(cameraPosition.target, cameraPosition.zoom);
|
||||
forceUpdate = mapView.getMapCenter(); //TODO. Strange variable
|
||||
listView.smoothScrollBy(0, top + min);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onZoom(ZoomEvent event) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
googleMap.setOnMyLocationChangeListener(location -> {
|
||||
if (parentAlert == null || parentAlert.baseFragment == null) {
|
||||
return;
|
||||
}
|
||||
positionMarker(location);
|
||||
getLocationController().setGoogleMapLocation(location, isFirstLocation);
|
||||
myLocationOverlay.runOnFirstFix(new Runnable() {
|
||||
public void run() {
|
||||
AndroidUtilities.runOnUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
positionMarker(myLocationOverlay.getLastFix());
|
||||
getLocationController().setGoogleMapLocation(myLocationOverlay.getLastFix(), isFirstLocation);
|
||||
isFirstLocation = false;
|
||||
});
|
||||
googleMap.setOnMarkerClickListener(marker -> {
|
||||
if (!(marker.getTag() instanceof VenueLocation)) {
|
||||
return true;
|
||||
}
|
||||
markerImageView.setVisibility(INVISIBLE);
|
||||
if (!userLocationMoved) {
|
||||
locationButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_location_actionIcon), PorterDuff.Mode.MULTIPLY));
|
||||
locationButton.setTag(Theme.key_location_actionIcon);
|
||||
userLocationMoved = true;
|
||||
}
|
||||
overlayView.addInfoView(marker);
|
||||
return true;
|
||||
});
|
||||
googleMap.setOnCameraMoveListener(() -> {
|
||||
}
|
||||
});
|
||||
mapView.getOverlays().add(myLocationOverlay);
|
||||
mapView.addMapListener(new MapListener() {
|
||||
@Override
|
||||
public boolean onScroll(ScrollEvent event) {
|
||||
if (overlayView != null) {
|
||||
overlayView.updatePositions();
|
||||
}
|
||||
});
|
||||
AndroidUtilities.runOnUIThread(() -> {
|
||||
if (loadingMapView.getTag() == null) {
|
||||
loadingMapView.animate().alpha(0.0f).setDuration(180).start();
|
||||
return false;
|
||||
}
|
||||
}, 2000);
|
||||
positionMarker(myLocation = getLastLocation());
|
||||
|
||||
@Override
|
||||
public boolean onZoom(ZoomEvent event) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
positionMarker(myLocation = getLastLocation());
|
||||
attributionOverlay.bringToFront();
|
||||
if (checkGpsEnabled && getParentActivity() != null) {
|
||||
checkGpsEnabled = false;
|
||||
if (!getParentActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS)) {
|
||||
|
@ -1402,8 +1455,8 @@ public class ChatAttachAlertLocationLayout extends ChatAttachAlert.AttachAlertLa
|
|||
mapViewClip.invalidate();
|
||||
|
||||
mapViewClip.setTranslationY(top - nonClipSize);
|
||||
if (googleMap != null) {
|
||||
googleMap.setPadding(0, AndroidUtilities.dp(6), 0, clipSize + AndroidUtilities.dp(6));
|
||||
if (mapView != null) {
|
||||
mapView.setPadding(0, AndroidUtilities.dp(6), 0, clipSize + AndroidUtilities.dp(6));
|
||||
}
|
||||
if (overlayView != null) {
|
||||
overlayView.setTranslationY(trY);
|
||||
|
@ -1412,20 +1465,21 @@ public class ChatAttachAlertLocationLayout extends ChatAttachAlert.AttachAlertLa
|
|||
mapTypeButton.setTranslationY(translationY);
|
||||
searchAreaButton.setTranslation(translationY);
|
||||
locationButton.setTranslationY(-clipSize);
|
||||
markerImageView.setTranslationY(markerTop = (mapHeight - clipSize) / 2 - AndroidUtilities.dp(48) + trY);
|
||||
markerImageView.setTranslationY(markerTop = (mapHeight) / 2 - AndroidUtilities.dp(48) + trY);
|
||||
if (prevClipSize != clipSize) {
|
||||
LatLng location;
|
||||
GeoPoint location;
|
||||
if (lastPressedMarker != null) {
|
||||
location = lastPressedMarker.getPosition();
|
||||
} else if (userLocationMoved) {
|
||||
location = new LatLng(userLocation.getLatitude(), userLocation.getLongitude());
|
||||
location = new GeoPoint(userLocation.getLatitude(), userLocation.getLongitude());
|
||||
} else if (myLocation != null) {
|
||||
location = new LatLng(myLocation.getLatitude(), myLocation.getLongitude());
|
||||
location = new GeoPoint(myLocation.getLatitude(), myLocation.getLongitude());
|
||||
} else {
|
||||
location = null;
|
||||
}
|
||||
if (location != null) {
|
||||
googleMap.moveCamera(CameraUpdateFactory.newLatLng(location));
|
||||
final IMapController controller = mapView.getController();
|
||||
controller.setCenter(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1470,6 +1524,9 @@ public class ChatAttachAlertLocationLayout extends ChatAttachAlert.AttachAlertLa
|
|||
}
|
||||
|
||||
private Location getLastLocation() {
|
||||
if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && getParentActivity().checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||
return null;
|
||||
} else {
|
||||
LocationManager lm = (LocationManager) ApplicationLoader.applicationContext.getSystemService(Context.LOCATION_SERVICE);
|
||||
List<String> providers = lm.getProviders(true);
|
||||
Location l = null;
|
||||
|
@ -1481,6 +1538,7 @@ public class ChatAttachAlertLocationLayout extends ChatAttachAlert.AttachAlertLa
|
|||
}
|
||||
return l;
|
||||
}
|
||||
}
|
||||
|
||||
private void positionMarker(Location location) {
|
||||
if (location == null) {
|
||||
|
@ -1488,8 +1546,8 @@ public class ChatAttachAlertLocationLayout extends ChatAttachAlert.AttachAlertLa
|
|||
}
|
||||
myLocation = new Location(location);
|
||||
|
||||
if (googleMap != null) {
|
||||
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
|
||||
if (mapView != null) {
|
||||
GeoPoint latLng = new GeoPoint(location.getLatitude(), location.getLongitude());
|
||||
if (adapter != null) {
|
||||
if (!searchedForCustomLocations) {
|
||||
adapter.searchPlacesWithQuery(null, myLocation, true);
|
||||
|
@ -1499,12 +1557,13 @@ public class ChatAttachAlertLocationLayout extends ChatAttachAlert.AttachAlertLa
|
|||
if (!userLocationMoved) {
|
||||
userLocation = new Location(location);
|
||||
if (firstWas) {
|
||||
CameraUpdate position = CameraUpdateFactory.newLatLng(latLng);
|
||||
googleMap.animateCamera(position);
|
||||
final IMapController controller = mapView.getController();
|
||||
controller.animateTo(latLng);
|
||||
} else {
|
||||
firstWas = true;
|
||||
CameraUpdate position = CameraUpdateFactory.newLatLngZoom(latLng, googleMap.getMaxZoomLevel() - 4);
|
||||
googleMap.moveCamera(position);
|
||||
final IMapController controller = mapView.getController();
|
||||
controller.setZoom(mapView.getMaxZoomLevel() - 2);
|
||||
controller.setCenter(latLng);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -1515,12 +1574,8 @@ public class ChatAttachAlertLocationLayout extends ChatAttachAlert.AttachAlertLa
|
|||
@Override
|
||||
public void didReceivedNotification(int id, int account, Object... args) {
|
||||
if (id == NotificationCenter.locationPermissionGranted) {
|
||||
if (googleMap != null) {
|
||||
try {
|
||||
googleMap.setMyLocationEnabled(true);
|
||||
} catch (Exception e) {
|
||||
FileLog.e(e);
|
||||
}
|
||||
if (mapView != null && mapsInitialized) {
|
||||
myLocationOverlay.enableMyLocation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1533,6 +1588,8 @@ public class ChatAttachAlertLocationLayout extends ChatAttachAlert.AttachAlertLa
|
|||
} catch (Throwable e) {
|
||||
FileLog.e(e);
|
||||
}
|
||||
mapView.getOverlays().add(myLocationOverlay);
|
||||
myLocationOverlay.enableMyLocation();
|
||||
}
|
||||
onResumeCalled = true;
|
||||
}
|
||||
|
@ -1543,7 +1600,6 @@ public class ChatAttachAlertLocationLayout extends ChatAttachAlert.AttachAlertLa
|
|||
if (mapView.getParent() == null) {
|
||||
mapViewClip.addView(mapView, 0, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, overScrollHeight + AndroidUtilities.dp(10), Gravity.TOP | Gravity.LEFT));
|
||||
mapViewClip.addView(overlayView, 1, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, overScrollHeight + AndroidUtilities.dp(10), Gravity.TOP | Gravity.LEFT));
|
||||
mapViewClip.addView(loadingMapView, 2, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
|
||||
}
|
||||
searchItem.setVisibility(VISIBLE);
|
||||
|
||||
|
@ -1555,13 +1611,6 @@ public class ChatAttachAlertLocationLayout extends ChatAttachAlert.AttachAlertLa
|
|||
}
|
||||
}
|
||||
onResumeCalled = true;
|
||||
if (googleMap != null) {
|
||||
try {
|
||||
googleMap.setMyLocationEnabled(true);
|
||||
} catch (Exception e) {
|
||||
FileLog.e(e);
|
||||
}
|
||||
}
|
||||
fixLayoutInternal(true);
|
||||
if (checkPermission && Build.VERSION.SDK_INT >= 23) {
|
||||
Activity activity = getParentActivity();
|
||||
|
@ -1591,17 +1640,16 @@ public class ChatAttachAlertLocationLayout extends ChatAttachAlert.AttachAlertLa
|
|||
mapTypeButton.setPopupItemsColor(Theme.getColor(Theme.key_actionBarDefaultSubmenuItemIcon), true);
|
||||
mapTypeButton.setPopupItemsColor(Theme.getColor(Theme.key_actionBarDefaultSubmenuItem), false);
|
||||
|
||||
if (googleMap != null) {
|
||||
if (mapView != null) {
|
||||
if (isActiveThemeDark()) {
|
||||
if (!currentMapStyleDark) {
|
||||
currentMapStyleDark = true;
|
||||
MapStyleOptions style = MapStyleOptions.loadRawResourceStyle(ApplicationLoader.applicationContext, R.raw.mapstyle_night);
|
||||
googleMap.setMapStyle(style);
|
||||
// TODO dark
|
||||
}
|
||||
} else {
|
||||
if (currentMapStyleDark) {
|
||||
currentMapStyleDark = false;
|
||||
googleMap.setMapStyle(null);
|
||||
// TODO dark
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user