aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/utils/GeoHelper.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/pixart/messenger/utils/GeoHelper.java')
-rw-r--r--src/main/java/de/pixart/messenger/utils/GeoHelper.java120
1 files changed, 60 insertions, 60 deletions
diff --git a/src/main/java/de/pixart/messenger/utils/GeoHelper.java b/src/main/java/de/pixart/messenger/utils/GeoHelper.java
index 0fe63e095..8f263c593 100644
--- a/src/main/java/de/pixart/messenger/utils/GeoHelper.java
+++ b/src/main/java/de/pixart/messenger/utils/GeoHelper.java
@@ -14,13 +14,13 @@ import de.pixart.messenger.entities.Conversation;
import de.pixart.messenger.entities.Message;
public class GeoHelper {
- public static Pattern GEO_URI = Pattern.compile("geo:([\\-0-9.]+),([\\-0-9.]+)(?:,([\\-0-9.]+))?(?:\\?(.*))?", Pattern.CASE_INSENSITIVE);
+ public static Pattern GEO_URI = Pattern.compile("geo:([\\-0-9.]+),([\\-0-9.]+)(?:,([\\-0-9.]+))?(?:\\?(.*))?", Pattern.CASE_INSENSITIVE);
- public static boolean isGeoUri(String body) {
- return body != null && GEO_URI.matcher(body).matches();
- }
+ public static boolean isGeoUri(String body) {
+ return body != null && GEO_URI.matcher(body).matches();
+ }
- public static String MapPreviewUri (Message message) {
+ public static String MapPreviewUri(Message message) {
Matcher matcher = GEO_URI.matcher(message.getBody());
if (!matcher.matches()) {
return null;
@@ -42,62 +42,62 @@ public class GeoHelper {
return "https://maps.google.com/maps/api/staticmap?center=" + latitude + "," + longitude + "&size=500x500&scale=2&format=jpg&markers=" + latitude + "," + longitude + "&sensor=false";
}
- public static ArrayList<Intent> createGeoIntentsFromMessage(Message message) {
- final ArrayList<Intent> intents = new ArrayList<>();
- Matcher matcher = GEO_URI.matcher(message.getBody());
- if (!matcher.matches()) {
- return intents;
- }
- double latitude;
- double longitude;
- try {
- latitude = Double.parseDouble(matcher.group(1));
- if (latitude > 90.0 || latitude < -90.0) {
- return intents;
- }
- longitude = Double.parseDouble(matcher.group(2));
- if (longitude > 180.0 || longitude < -180.0) {
- return intents;
- }
- } catch (NumberFormatException nfe) {
- return intents;
- }
- final Conversation conversation = message.getConversation();
- String label;
- if (conversation.getMode() == Conversation.MODE_SINGLE && message.getStatus() == Message.STATUS_RECEIVED) {
- try {
- label = "(" + URLEncoder.encode(message.getConversation().getName(), "UTF-8") + ")";
- } catch (UnsupportedEncodingException e) {
- label = "";
- }
- } else {
- label = "";
- }
+ public static ArrayList<Intent> createGeoIntentsFromMessage(Message message) {
+ final ArrayList<Intent> intents = new ArrayList<>();
+ Matcher matcher = GEO_URI.matcher(message.getBody());
+ if (!matcher.matches()) {
+ return intents;
+ }
+ double latitude;
+ double longitude;
+ try {
+ latitude = Double.parseDouble(matcher.group(1));
+ if (latitude > 90.0 || latitude < -90.0) {
+ return intents;
+ }
+ longitude = Double.parseDouble(matcher.group(2));
+ if (longitude > 180.0 || longitude < -180.0) {
+ return intents;
+ }
+ } catch (NumberFormatException nfe) {
+ return intents;
+ }
+ final Conversation conversation = message.getConversation();
+ String label;
+ if (conversation.getMode() == Conversation.MODE_SINGLE && message.getStatus() == Message.STATUS_RECEIVED) {
+ try {
+ label = "(" + URLEncoder.encode(message.getConversation().getName(), "UTF-8") + ")";
+ } catch (UnsupportedEncodingException e) {
+ label = "";
+ }
+ } else {
+ label = "";
+ }
- Intent locationPluginIntent = new Intent("de.pixart.messenger.location.show");
- locationPluginIntent.putExtra("latitude",latitude);
- locationPluginIntent.putExtra("longitude",longitude);
- if (message.getStatus() != Message.STATUS_RECEIVED) {
- locationPluginIntent.putExtra("jid",conversation.getAccount().getJid().toString());
- locationPluginIntent.putExtra("name",conversation.getAccount().getJid().getLocalpart());
- } else {
- Contact contact = message.getContact();
- if (contact != null) {
- locationPluginIntent.putExtra("name", contact.getDisplayName());
- locationPluginIntent.putExtra("jid", contact.getJid().toString());
- } else {
- locationPluginIntent.putExtra("name", UIHelper.getDisplayedMucCounterpart(message.getCounterpart()));
- }
- }
- intents.add(locationPluginIntent);
+ Intent locationPluginIntent = new Intent("de.pixart.messenger.location.show");
+ locationPluginIntent.putExtra("latitude", latitude);
+ locationPluginIntent.putExtra("longitude", longitude);
+ if (message.getStatus() != Message.STATUS_RECEIVED) {
+ locationPluginIntent.putExtra("jid", conversation.getAccount().getJid().toString());
+ locationPluginIntent.putExtra("name", conversation.getAccount().getJid().getLocalpart());
+ } else {
+ Contact contact = message.getContact();
+ if (contact != null) {
+ locationPluginIntent.putExtra("name", contact.getDisplayName());
+ locationPluginIntent.putExtra("jid", contact.getJid().toString());
+ } else {
+ locationPluginIntent.putExtra("name", UIHelper.getDisplayedMucCounterpart(message.getCounterpart()));
+ }
+ }
+ intents.add(locationPluginIntent);
- Intent geoIntent = new Intent(Intent.ACTION_VIEW);
- geoIntent.setData(Uri.parse("geo:" + String.valueOf(latitude) + "," + String.valueOf(longitude) + "?q=" + String.valueOf(latitude) + "," + String.valueOf(longitude) + label));
- intents.add(geoIntent);
+ Intent geoIntent = new Intent(Intent.ACTION_VIEW);
+ geoIntent.setData(Uri.parse("geo:" + String.valueOf(latitude) + "," + String.valueOf(longitude) + "?q=" + String.valueOf(latitude) + "," + String.valueOf(longitude) + label));
+ intents.add(geoIntent);
- Intent httpIntent = new Intent(Intent.ACTION_VIEW);
- httpIntent.setData(Uri.parse("https://maps.google.com/maps?q=loc:"+String.valueOf(latitude) + "," + String.valueOf(longitude) +label));
- intents.add(httpIntent);
- return intents;
- }
+ Intent httpIntent = new Intent(Intent.ACTION_VIEW);
+ httpIntent.setData(Uri.parse("https://maps.google.com/maps?q=loc:" + String.valueOf(latitude) + "," + String.valueOf(longitude) + label));
+ intents.add(httpIntent);
+ return intents;
+ }
} \ No newline at end of file