2015-12-18 14:37:11 -08:00
|
|
|
package org.thoughtcrime.securesms.components.location;
|
|
|
|
|
2018-04-03 03:22:29 -07:00
|
|
|
import android.net.Uri;
|
2016-01-04 13:02:22 -08:00
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
import android.support.annotation.Nullable;
|
2015-12-18 14:37:11 -08:00
|
|
|
import android.text.TextUtils;
|
2016-01-04 13:02:22 -08:00
|
|
|
import android.util.Log;
|
2015-12-18 14:37:11 -08:00
|
|
|
|
2016-01-04 13:02:22 -08:00
|
|
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
|
|
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
2015-12-18 14:37:11 -08:00
|
|
|
import com.google.android.gms.location.places.Place;
|
|
|
|
import com.google.android.gms.maps.model.LatLng;
|
|
|
|
|
2016-01-04 13:02:22 -08:00
|
|
|
import org.thoughtcrime.securesms.util.JsonUtils;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
2015-12-18 14:37:11 -08:00
|
|
|
public class SignalPlace {
|
|
|
|
|
2018-04-03 03:22:29 -07:00
|
|
|
private static final String URL = "https://maps.google.com/maps";
|
2016-01-04 13:02:22 -08:00
|
|
|
private static final String TAG = SignalPlace.class.getSimpleName();
|
|
|
|
|
|
|
|
@JsonProperty
|
2017-05-24 10:03:35 -07:00
|
|
|
private CharSequence name;
|
2015-12-18 14:37:11 -08:00
|
|
|
|
2016-01-04 13:02:22 -08:00
|
|
|
@JsonProperty
|
2017-05-24 10:03:35 -07:00
|
|
|
private CharSequence address;
|
2016-01-04 13:02:22 -08:00
|
|
|
|
|
|
|
@JsonProperty
|
|
|
|
private double latitude;
|
|
|
|
|
|
|
|
@JsonProperty
|
|
|
|
private double longitude;
|
2015-12-18 14:37:11 -08:00
|
|
|
|
|
|
|
public SignalPlace(Place place) {
|
2017-05-24 10:03:35 -07:00
|
|
|
this.name = place.getName();
|
|
|
|
this.address = place.getAddress();
|
2016-01-04 13:02:22 -08:00
|
|
|
this.latitude = place.getLatLng().latitude;
|
|
|
|
this.longitude = place.getLatLng().longitude;
|
2015-12-18 14:37:11 -08:00
|
|
|
}
|
|
|
|
|
2016-01-04 13:02:22 -08:00
|
|
|
public SignalPlace() {}
|
|
|
|
|
|
|
|
@JsonIgnore
|
2015-12-18 14:37:11 -08:00
|
|
|
public LatLng getLatLong() {
|
2016-01-04 13:02:22 -08:00
|
|
|
return new LatLng(latitude, longitude);
|
2015-12-18 14:37:11 -08:00
|
|
|
}
|
|
|
|
|
2016-01-04 13:02:22 -08:00
|
|
|
@JsonIgnore
|
2015-12-18 14:37:11 -08:00
|
|
|
public String getDescription() {
|
|
|
|
String description = "";
|
|
|
|
|
2016-01-04 13:02:22 -08:00
|
|
|
if (!TextUtils.isEmpty(name)) {
|
|
|
|
description += (name + "\n");
|
2015-12-18 14:37:11 -08:00
|
|
|
}
|
|
|
|
|
2016-01-04 13:02:22 -08:00
|
|
|
if (!TextUtils.isEmpty(address)) {
|
|
|
|
description += (address + "\n");
|
2015-12-18 14:37:11 -08:00
|
|
|
}
|
|
|
|
|
2018-04-03 03:22:29 -07:00
|
|
|
description += Uri.parse(URL)
|
|
|
|
.buildUpon()
|
|
|
|
.appendQueryParameter("q", String.format("%s,%s", latitude, longitude))
|
|
|
|
.build().toString();
|
2015-12-18 14:37:11 -08:00
|
|
|
|
|
|
|
return description;
|
|
|
|
}
|
2016-01-04 13:02:22 -08:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2015-12-18 14:37:11 -08:00
|
|
|
}
|