2015-12-18 14:37:11 -08:00
|
|
|
package org.thoughtcrime.securesms.components.location;
|
|
|
|
|
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 {
|
|
|
|
|
|
|
|
private static final String URL = "https://maps.google.com/maps?q=%s,%s";
|
2016-01-04 13:02:22 -08:00
|
|
|
private static final String TAG = SignalPlace.class.getSimpleName();
|
|
|
|
|
|
|
|
@JsonProperty
|
|
|
|
private String name;
|
2015-12-18 14:37:11 -08:00
|
|
|
|
2016-01-04 13:02:22 -08:00
|
|
|
@JsonProperty
|
|
|
|
private String address;
|
|
|
|
|
|
|
|
@JsonProperty
|
|
|
|
private double latitude;
|
|
|
|
|
|
|
|
@JsonProperty
|
|
|
|
private double longitude;
|
2015-12-18 14:37:11 -08:00
|
|
|
|
|
|
|
public SignalPlace(Place place) {
|
2016-01-04 13:02:22 -08:00
|
|
|
this.name = place.getName().toString();
|
|
|
|
this.address = place.getAddress().toString();
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-01-04 13:02:22 -08:00
|
|
|
description += String.format(URL, latitude, longitude);
|
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
|
|
|
}
|