first action for #414 remove all the location things.

This commit is contained in:
Angelo Fuchs
2019-01-22 14:08:34 +01:00
parent 170b0d86c3
commit 7e7a5560ef
9 changed files with 0 additions and 320 deletions
-24
View File
@@ -162,30 +162,6 @@
</LinearLayout>
<LinearLayout android:id="@+id/location_linear_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<org.thoughtcrime.securesms.components.CircleColorImageView
android:id="@+id/location_button"
android:layout_width="53dp"
android:layout_height="53dp"
android:src="@drawable/ic_location_on_white_24dp"
android:scaleType="center"
android:contentDescription="@string/location"
app:circleColor="@color/location_icon"/>
<TextView android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/AttachmentTypeLabel"
android:text="@string/location"/>
</LinearLayout>
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
@@ -14,13 +14,6 @@
android:layout_height="wrap_content"
android:layout_gravity="center">
<org.thoughtcrime.securesms.components.location.SignalMapView
android:id="@+id/attachment_location"
android:layout_width="210dp"
android:layout_height="210dp"
android:layout_gravity="center_horizontal"
android:visibility="gone"/>
<org.thoughtcrime.securesms.components.ThumbnailView
android:id="@+id/attachment_thumbnail"
android:layout_width="230dp"
@@ -80,7 +80,6 @@ import org.thoughtcrime.securesms.components.camera.QuickAttachmentDrawer;
import org.thoughtcrime.securesms.components.camera.QuickAttachmentDrawer.AttachmentDrawerListener;
import org.thoughtcrime.securesms.components.camera.QuickAttachmentDrawer.DrawerState;
import org.thoughtcrime.securesms.components.emoji.EmojiDrawer;
import org.thoughtcrime.securesms.components.location.SignalPlace;
import org.thoughtcrime.securesms.components.reminder.ReminderView;
import org.thoughtcrime.securesms.connect.ApplicationDcContext;
import org.thoughtcrime.securesms.connect.DcHelper;
@@ -152,7 +151,6 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
private static final int PICK_CONTACT = 4;
private static final int GROUP_EDIT = 6;
private static final int TAKE_PHOTO = 7;
private static final int PICK_LOCATION = 9;
private static final int SMS_DEFAULT = 11;
private GlideRequests glideRequests;
@@ -368,10 +366,6 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
setMedia(attachmentManager.getCaptureUri(), MediaType.IMAGE);
}
break;
case PICK_LOCATION:
SignalPlace place = new SignalPlace(PlacePicker.getPlace(data, this));
attachmentManager.setLocation(place, getCurrentMediaConstraints());
break;
case ScribbleActivity.SCRIBBLE_REQUEST_CODE:
setMedia(data.getData(), MediaType.IMAGE);
break;
@@ -790,8 +784,6 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
AttachmentManager.selectAudio(this, PICK_AUDIO); break;
case AttachmentTypeSelector.ADD_CONTACT_INFO:
startContactChooserActivity(); break;
case AttachmentTypeSelector.ADD_LOCATION:
AttachmentManager.selectLocation(this, PICK_LOCATION); break;
case AttachmentTypeSelector.TAKE_PHOTO:
attachmentManager.capturePhoto(this, TAKE_PHOTO); break;
}
@@ -14,9 +14,6 @@ public abstract class Attachment {
@Nullable
private final String fileName;
@Nullable
private final String location;
@Nullable
private final String fastPreflightId;
@@ -35,7 +32,6 @@ public abstract class Attachment {
this.transferState = transferState;
this.size = size;
this.fileName = fileName;
this.location = location;
this.fastPreflightId = fastPreflightId;
this.voiceNote = voiceNote;
this.width = width;
@@ -71,11 +67,6 @@ public abstract class Attachment {
return contentType;
}
@Nullable
public String getLocation() {
return location;
}
@Nullable
public String getFastPreflightId() {
return fastPreflightId;
@@ -37,7 +37,6 @@ 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;
@@ -51,7 +50,6 @@ public class AttachmentTypeSelector extends PopupWindow {
private final @NonNull ImageView documentButton;
private final @NonNull ImageView contactButton;
private final @NonNull ImageView cameraButton;
private final @NonNull ImageView locationButton;
private final @NonNull ImageView closeButton;
private @Nullable View currentAnchor;
@@ -71,7 +69,6 @@ public class AttachmentTypeSelector extends PopupWindow {
this.documentButton = ViewUtil.findById(layout, R.id.document_button);
this.contactButton = ViewUtil.findById(layout, R.id.contact_button);
this.cameraButton = ViewUtil.findById(layout, R.id.camera_button);
this.locationButton = ViewUtil.findById(layout, R.id.location_button);
this.closeButton = ViewUtil.findById(layout, R.id.close_button);
this.imageButton.setOnClickListener(new PropagatingClickListener(ADD_GALLERY));
@@ -79,14 +76,9 @@ public class AttachmentTypeSelector extends PopupWindow {
this.documentButton.setOnClickListener(new PropagatingClickListener(ADD_DOCUMENT));
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());
this.recentRail.setListener(new RecentPhotoSelectedListener());
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
ViewUtil.findById(layout, R.id.location_linear_layout).setVisibility(View.INVISIBLE);
}
setContentView(layout);
setWidth(LinearLayout.LayoutParams.MATCH_PARENT);
setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
@@ -129,7 +121,6 @@ public class AttachmentTypeSelector extends PopupWindow {
animateButtonIn(cameraButton, ANIMATION_DURATION / 2);
animateButtonIn(audioButton, ANIMATION_DURATION / 3);
animateButtonIn(locationButton, ANIMATION_DURATION / 3);
animateButtonIn(documentButton, ANIMATION_DURATION / 4);
animateButtonIn(contactButton, 0);
animateButtonIn(closeButton, 0);
@@ -1,98 +0,0 @@
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;
}
}
@@ -1,81 +0,0 @@
package org.thoughtcrime.securesms.components.location;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.android.gms.location.places.Place;
import com.google.android.gms.maps.model.LatLng;
import org.thoughtcrime.securesms.util.JsonUtils;
import java.io.IOException;
public class SignalPlace {
private static final String URL = "https://maps.google.com/maps";
private static final String TAG = SignalPlace.class.getSimpleName();
@JsonProperty
private CharSequence name;
@JsonProperty
private CharSequence address;
@JsonProperty
private double latitude;
@JsonProperty
private double longitude;
public SignalPlace(Place place) {
this.name = place.getName();
this.address = place.getAddress();
this.latitude = place.getLatLng().latitude;
this.longitude = place.getLatLng().longitude;
}
public SignalPlace() {}
@JsonIgnore
public LatLng getLatLong() {
return new LatLng(latitude, longitude);
}
@JsonIgnore
public String getDescription() {
String description = "";
if (!TextUtils.isEmpty(name)) {
description += (name + "\n");
}
if (!TextUtils.isEmpty(address)) {
description += (address + "\n");
}
description += Uri.parse(URL)
.buildUpon()
.appendQueryParameter("q", String.format("%s,%s", latitude, longitude))
.build().toString();
return description;
}
public @Nullable String serialize() {
try {
return JsonUtils.toJson(this);
} catch (IOException e) {
Log.w(TAG, e);
return null;
}
}
public static SignalPlace deserialize(@NonNull String serialized) throws IOException {
return JsonUtils.fromJson(serialized, SignalPlace.class);
}
}
@@ -49,8 +49,6 @@ import org.thoughtcrime.securesms.components.AudioView;
import org.thoughtcrime.securesms.components.DocumentView;
import org.thoughtcrime.securesms.components.RemovableEditableMediaView;
import org.thoughtcrime.securesms.components.ThumbnailView;
import org.thoughtcrime.securesms.components.location.SignalMapView;
import org.thoughtcrime.securesms.components.location.SignalPlace;
import org.thoughtcrime.securesms.permissions.Permissions;
import org.thoughtcrime.securesms.providers.PersistentBlobProvider;
import org.thoughtcrime.securesms.scribbles.ScribbleActivity;
@@ -84,7 +82,6 @@ public class AttachmentManager {
private ThumbnailView thumbnail;
private AudioView audioView;
private DocumentView documentView;
private SignalMapView mapView;
private @NonNull List<Uri> garbage = new LinkedList<>();
private @NonNull Optional<Slide> slide = Optional.absent();
@@ -103,7 +100,6 @@ public class AttachmentManager {
this.thumbnail = ViewUtil.findById(root, R.id.attachment_thumbnail);
this.audioView = ViewUtil.findById(root, R.id.attachment_audio);
this.documentView = ViewUtil.findById(root, R.id.attachment_document);
this.mapView = ViewUtil.findById(root, R.id.attachment_location);
this.removableMediaView = ViewUtil.findById(root, R.id.removable_media_view);
removableMediaView.setRemoveClickListener(new RemoveButtonListener());
@@ -180,34 +176,6 @@ public class AttachmentManager {
this.slide = Optional.of(slide);
}
public ListenableFuture<Boolean> setLocation(@NonNull final SignalPlace place,
@NonNull final MediaConstraints constraints)
{
inflateStub();
SettableFuture<Boolean> returnResult = new SettableFuture<>();
ListenableFuture<Bitmap> future = mapView.display(place);
attachmentViewStub.get().setVisibility(View.VISIBLE);
removableMediaView.display(mapView, false);
future.addListener(new AssertedSuccessListener<Bitmap>() {
@Override
public void onSuccess(@NonNull Bitmap result) {
byte[] blob = BitmapUtil.toByteArray(result);
Uri uri = PersistentBlobProvider.getInstance(context)
.create(context, blob, MediaUtil.IMAGE_PNG, null);
LocationSlide locationSlide = new LocationSlide(context, uri, blob.length, place);
setSlide(locationSlide);
attachmentListener.onAttachmentChanged();
returnResult.set(true);
}
});
return returnResult;
}
@SuppressLint("StaticFieldLeak")
public ListenableFuture<Boolean> setMedia(@NonNull final GlideRequests glideRequests,
@NonNull final Uri uri,
@@ -373,21 +341,6 @@ public class AttachmentManager {
.execute();
}
public static void selectLocation(Activity activity, int requestCode) {
Permissions.with(activity)
.request(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION)
.ifNecessary()
.withPermanentDenialDialog(activity.getString(R.string.perm_explain_access_to_location_denied))
.onAllGranted(() -> {
try {
activity.startActivityForResult(new PlacePicker.IntentBuilder().build(activity), requestCode);
} catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) {
Log.w(TAG, e);
}
})
.execute();
}
private @Nullable Uri getSlideUri() {
return slide.isPresent() ? slide.get().getUri() : null;
}
@@ -1,37 +0,0 @@
package org.thoughtcrime.securesms.mms;
import android.content.Context;
import android.net.Uri;
import android.support.annotation.NonNull;
import org.thoughtcrime.securesms.components.location.SignalPlace;
import org.thoughtcrime.securesms.util.guava.Optional;
public class LocationSlide extends ImageSlide {
@NonNull
private final SignalPlace place;
public LocationSlide(@NonNull Context context, @NonNull Uri uri, long size, @NonNull SignalPlace place)
{
super(context, uri, size, 0, 0);
this.place = place;
}
@Override
@NonNull
public Optional<String> getBody() {
return Optional.of(place.getDescription());
}
@NonNull
public SignalPlace getPlace() {
return place;
}
@Override
public boolean hasLocation() {
return true;
}
}