mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-26 03:40:56 +01:00
Fix chosen location not being sent sometimes.
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
package org.thoughtcrime.securesms.components.location;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Build;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -11,16 +9,20 @@ import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
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.OnMapReadyCallback;
|
||||
import com.google.android.gms.maps.model.LatLng;
|
||||
import com.google.android.gms.maps.model.MarkerOptions;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture;
|
||||
import org.thoughtcrime.securesms.util.concurrent.SettableFuture;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class SignalMapView extends LinearLayout {
|
||||
|
||||
private MapView mapView;
|
||||
@@ -53,42 +55,50 @@ public class SignalMapView extends LinearLayout {
|
||||
public ListenableFuture<Bitmap> display(final SignalPlace place) {
|
||||
final SettableFuture<Bitmap> future = new SettableFuture<>();
|
||||
|
||||
this.mapView.onCreate(null);
|
||||
this.mapView.onResume();
|
||||
|
||||
this.mapView.setVisibility(View.VISIBLE);
|
||||
this.imageView.setVisibility(View.GONE);
|
||||
|
||||
this.mapView.getMapAsync(new OnMapReadyCallback() {
|
||||
this.textView.setText(place.getDescription());
|
||||
snapshot(place, mapView).addListener(new ListenableFuture.Listener<Bitmap>() {
|
||||
@Override
|
||||
public void onMapReady(final GoogleMap googleMap) {
|
||||
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(place.getLatLong(), 13));
|
||||
googleMap.addMarker(new MarkerOptions().position(place.getLatLong()));
|
||||
googleMap.setBuildingsEnabled(true);
|
||||
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
|
||||
googleMap.getUiSettings().setAllGesturesEnabled(false);
|
||||
googleMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
|
||||
@Override
|
||||
public void onMapLoaded() {
|
||||
googleMap.snapshot(new GoogleMap.SnapshotReadyCallback() {
|
||||
@Override
|
||||
public void onSnapshotReady(Bitmap bitmap) {
|
||||
future.set(bitmap);
|
||||
imageView.setImageBitmap(bitmap);
|
||||
imageView.setVisibility(View.VISIBLE);
|
||||
mapView.setVisibility(View.GONE);
|
||||
mapView.onPause();
|
||||
mapView.onDestroy();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
public void onSuccess(Bitmap result) {
|
||||
future.set(result);
|
||||
imageView.setImageBitmap(result);
|
||||
imageView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(ExecutionException e) {
|
||||
future.setException(e);
|
||||
}
|
||||
});
|
||||
|
||||
this.textView.setText(place.getDescription());
|
||||
|
||||
return future;
|
||||
}
|
||||
|
||||
public static ListenableFuture<Bitmap> snapshot(final LatLng place, @NonNull final MapView mapView) {
|
||||
final SettableFuture<Bitmap> future = new SettableFuture<>();
|
||||
mapView.onCreate(null);
|
||||
mapView.onResume();
|
||||
|
||||
mapView.setVisibility(View.VISIBLE);
|
||||
|
||||
mapView.getMapAsync(googleMap -> {
|
||||
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(place, 13));
|
||||
googleMap.addMarker(new MarkerOptions().position(place));
|
||||
googleMap.setBuildingsEnabled(true);
|
||||
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
|
||||
googleMap.getUiSettings().setAllGesturesEnabled(false);
|
||||
googleMap.setOnMapLoadedCallback(() -> googleMap.snapshot(bitmap -> {
|
||||
future.set(bitmap);
|
||||
mapView.setVisibility(View.GONE);
|
||||
mapView.onPause();
|
||||
mapView.onDestroy();
|
||||
}));
|
||||
});
|
||||
|
||||
return future;
|
||||
}
|
||||
public static ListenableFuture<Bitmap> snapshot(final SignalPlace place, @NonNull final MapView mapView) {
|
||||
return snapshot(place.getLatLong(), mapView);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user