mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-23 17:48:50 +00:00
Support for location messages
Start with encoding as a simple image thumbnail for compatibility with MMS and iOS // FREEBIE
This commit is contained in:
@@ -33,6 +33,7 @@ public class AttachmentTypeSelector extends PopupWindow {
|
||||
public static final int ADD_SOUND = 3;
|
||||
public static final int ADD_CONTACT_INFO = 4;
|
||||
public static final int TAKE_PHOTO = 5;
|
||||
public static final int ADD_LOCATION = 6;
|
||||
|
||||
private static final int ANIMATION_DURATION = 300;
|
||||
|
||||
@@ -43,6 +44,7 @@ public class AttachmentTypeSelector extends PopupWindow {
|
||||
private final @NonNull ImageView videoButton;
|
||||
private final @NonNull ImageView contactButton;
|
||||
private final @NonNull ImageView cameraButton;
|
||||
private final @NonNull ImageView locationButton;
|
||||
private final @NonNull ImageView closeButton;
|
||||
|
||||
private @Nullable View currentAnchor;
|
||||
@@ -54,21 +56,27 @@ public class AttachmentTypeSelector extends PopupWindow {
|
||||
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.attachment_type_selector, null, true);
|
||||
|
||||
this.listener = listener;
|
||||
this.imageButton = ViewUtil.findById(layout, R.id.gallery_button);
|
||||
this.audioButton = ViewUtil.findById(layout, R.id.audio_button);
|
||||
this.videoButton = ViewUtil.findById(layout, R.id.video_button);
|
||||
this.contactButton = ViewUtil.findById(layout, R.id.contact_button);
|
||||
this.cameraButton = ViewUtil.findById(layout, R.id.camera_button);
|
||||
this.closeButton = ViewUtil.findById(layout, R.id.close_button);
|
||||
this.listener = listener;
|
||||
this.imageButton = ViewUtil.findById(layout, R.id.gallery_button);
|
||||
this.audioButton = ViewUtil.findById(layout, R.id.audio_button);
|
||||
this.videoButton = ViewUtil.findById(layout, R.id.video_button);
|
||||
this.contactButton = ViewUtil.findById(layout, R.id.contact_button);
|
||||
this.cameraButton = ViewUtil.findById(layout, R.id.camera_button);
|
||||
this.closeButton = ViewUtil.findById(layout, R.id.close_button);
|
||||
this.locationButton = ViewUtil.findById(layout, R.id.location_button);
|
||||
|
||||
this.imageButton.setOnClickListener(new PropagatingClickListener(ADD_IMAGE));
|
||||
this.audioButton.setOnClickListener(new PropagatingClickListener(ADD_SOUND));
|
||||
this.videoButton.setOnClickListener(new PropagatingClickListener(ADD_VIDEO));
|
||||
this.contactButton.setOnClickListener(new PropagatingClickListener(ADD_CONTACT_INFO));
|
||||
this.cameraButton.setOnClickListener(new PropagatingClickListener(TAKE_PHOTO));
|
||||
this.locationButton.setOnClickListener(new PropagatingClickListener(ADD_LOCATION));
|
||||
this.closeButton.setOnClickListener(new CloseClickListener());
|
||||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
|
||||
this.locationButton.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
|
||||
setContentView(layout);
|
||||
setWidth(LinearLayout.LayoutParams.MATCH_PARENT);
|
||||
setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||
|
@@ -0,0 +1,98 @@
|
||||
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;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.android.gms.location.places.Place;
|
||||
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.MarkerOptions;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture;
|
||||
import org.thoughtcrime.securesms.util.concurrent.SettableFuture;
|
||||
|
||||
public class SignalMapView extends LinearLayout {
|
||||
|
||||
private MapView mapView;
|
||||
private ImageView imageView;
|
||||
private TextView textView;
|
||||
|
||||
public SignalMapView(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public SignalMapView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
initialize(context);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
public SignalMapView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
initialize(context);
|
||||
}
|
||||
|
||||
private void initialize(Context context) {
|
||||
setOrientation(LinearLayout.VERTICAL);
|
||||
LayoutInflater.from(context).inflate(R.layout.signal_map_view, this, true);
|
||||
|
||||
this.mapView = ViewUtil.findById(this, R.id.map_view);
|
||||
this.imageView = ViewUtil.findById(this, R.id.image_view);
|
||||
this.textView = ViewUtil.findById(this, R.id.address_view);
|
||||
}
|
||||
|
||||
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() {
|
||||
@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();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
this.textView.setText(place.getDescription());
|
||||
|
||||
return future;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
package org.thoughtcrime.securesms.components.location;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.google.android.gms.location.places.Place;
|
||||
import com.google.android.gms.maps.model.LatLng;
|
||||
|
||||
public class SignalPlace {
|
||||
|
||||
private static final String URL = "https://maps.google.com/maps?q=%s,%s";
|
||||
|
||||
private final Place place;
|
||||
|
||||
public SignalPlace(Place place) {
|
||||
this.place = place;
|
||||
}
|
||||
|
||||
public LatLng getLatLong() {
|
||||
return place.getLatLng();
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
String description = "";
|
||||
|
||||
if (!TextUtils.isEmpty(place.getName())) {
|
||||
description += (place.getName() + "\n");
|
||||
}
|
||||
|
||||
if (!TextUtils.isEmpty(place.getAddress())) {
|
||||
description += (place.getAddress() + "\n");
|
||||
}
|
||||
|
||||
description += String.format(URL, place.getLatLng().latitude, place.getLatLng().longitude);
|
||||
|
||||
return description;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user