aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de')
-rw-r--r--src/main/java/de/pixart/messenger/services/NotificationService.java2
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationFragment.java15
-rw-r--r--src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java2
-rw-r--r--src/main/java/de/pixart/messenger/utils/GeoHelper.java75
4 files changed, 72 insertions, 22 deletions
diff --git a/src/main/java/de/pixart/messenger/services/NotificationService.java b/src/main/java/de/pixart/messenger/services/NotificationService.java
index dd40adf53..9d0eeea2b 100644
--- a/src/main/java/de/pixart/messenger/services/NotificationService.java
+++ b/src/main/java/de/pixart/messenger/services/NotificationService.java
@@ -772,7 +772,7 @@ public class NotificationService {
}
private PendingIntent createShowLocationIntent(final Message message) {
- Iterable<Intent> intents = GeoHelper.createGeoIntentsFromMessage(message, mXmppConnectionService);
+ Iterable<Intent> intents = GeoHelper.createGeoIntentsFromMessage(mXmppConnectionService, message);
for (Intent intent : intents) {
if (intent.resolveActivity(mXmppConnectionService.getPackageManager()) != null) {
return PendingIntent.getActivity(mXmppConnectionService, generateRequestCode(message.getConversation(), 18), intent, PendingIntent.FLAG_UPDATE_CURRENT);
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
index 2e9325ea2..eba4c88c5 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
@@ -108,6 +108,7 @@ import de.pixart.messenger.ui.util.SendButtonAction;
import de.pixart.messenger.ui.util.SendButtonTool;
import de.pixart.messenger.ui.util.ShareUtil;
import de.pixart.messenger.ui.widget.EditMessage;
+import de.pixart.messenger.utils.GeoHelper;
import de.pixart.messenger.utils.MenuDoubleTabUtil;
import de.pixart.messenger.utils.MessageUtils;
import de.pixart.messenger.utils.NickValidityChecker;
@@ -1283,6 +1284,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
final boolean receiving = m.getStatus() == Message.STATUS_RECEIVED && (t instanceof JingleConnection || t instanceof HttpDownloadConnection);
activity.getMenuInflater().inflate(R.menu.message_context, menu);
menu.setHeaderTitle(R.string.message_options);
+ MenuItem openWith = menu.findItem(R.id.open_with);
MenuItem copyMessage = menu.findItem(R.id.copy_message);
MenuItem copyLink = menu.findItem(R.id.copy_link);
MenuItem quoteMessage = menu.findItem(R.id.quote_message);
@@ -1314,6 +1316,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
}
if (!showError
&& relevantForCorrection.getType() == Message.TYPE_TEXT
+ && !m.isGeoUri()
&& relevantForCorrection.isLastCorrectableMessage()
&& m.getConversation() instanceof Conversation
&& (((Conversation) m.getConversation()).getMucOptions().nonanonymous() || m.getConversation().getMode() == Conversation.MODE_SINGLE)) {
@@ -1355,6 +1358,9 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
if (showError) {
showErrorMessage.setVisible(true);
}
+ if (m.isGeoUri() && GeoHelper.openInOsmAnd(getActivity(),m)) {
+ openWith.setVisible(true);
+ }
}
}
@@ -1400,6 +1406,9 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
case R.id.show_error_message:
showErrorMessage(selectedMessage);
return true;
+ case R.id.open_with:
+ openWith(selectedMessage);
+ return true;
default:
return super.onContextItemSelected(item);
}
@@ -1843,6 +1852,12 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
return null;
}
+ private void openWith(final Message message) {
+ if (message.isGeoUri()) {
+ GeoHelper.view(getActivity(), message);
+ }
+ }
+
private void showErrorMessage(final Message message) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.error_message);
diff --git a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
index e9ea940f1..ba0f5e991 100644
--- a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
+++ b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
@@ -1132,7 +1132,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
}
public void showLocation(Message message) {
- for (Intent intent : GeoHelper.createGeoIntentsFromMessage(message, this.getContext())) {
+ for (Intent intent : GeoHelper.createGeoIntentsFromMessage(this.getContext(), message)) {
if (intent.resolveActivity(getContext().getPackageManager()) != null) {
getContext().startActivity(intent);
activity.overridePendingTransition(R.animator.fade_in, R.animator.fade_out);
diff --git a/src/main/java/de/pixart/messenger/utils/GeoHelper.java b/src/main/java/de/pixart/messenger/utils/GeoHelper.java
index 209fd75db..f6af7c018 100644
--- a/src/main/java/de/pixart/messenger/utils/GeoHelper.java
+++ b/src/main/java/de/pixart/messenger/utils/GeoHelper.java
@@ -4,6 +4,8 @@ import android.content.Context;
import android.content.Intent;
import android.net.Uri;
+import org.osmdroid.util.GeoPoint;
+
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
@@ -11,6 +13,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import de.pixart.messenger.Config;
+import de.pixart.messenger.R;
import de.pixart.messenger.entities.Contact;
import de.pixart.messenger.entities.Conversation;
import de.pixart.messenger.entities.Conversational;
@@ -43,41 +46,43 @@ public class GeoHelper {
return "https://xmpp.pix-art.de/staticmap/staticmap.php?center=" + latitude + "," + longitude + "&size=500x500&markers=" + latitude + "," + longitude + "&zoom= " + Config.DEFAULT_ZOOM;
}
- public static ArrayList<Intent> createGeoIntentsFromMessage(Message message, Context context) {
- final ArrayList<Intent> intents = new ArrayList<>();
- Matcher matcher = GEO_URI.matcher(message.getBody());
+ private static GeoPoint parseGeoPoint(String body) throws IllegalArgumentException {
+ Matcher matcher = GEO_URI.matcher(body);
+ ;
if (!matcher.matches()) {
- return intents;
+ throw new IllegalArgumentException("Invalid geo uri");
}
double latitude;
double longitude;
try {
latitude = Double.parseDouble(matcher.group(1));
if (latitude > 90.0 || latitude < -90.0) {
- return intents;
+ throw new IllegalArgumentException("Invalid geo uri");
}
longitude = Double.parseDouble(matcher.group(2));
if (longitude > 180.0 || longitude < -180.0) {
- return intents;
+ throw new IllegalArgumentException("Invalid geo uri");
}
- } catch (NumberFormatException nfe) {
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException("Invalid geo uri", e);
+ }
+ return new GeoPoint(latitude, longitude);
+ }
+
+ public static ArrayList<Intent> createGeoIntentsFromMessage(Context context, Message message) {
+ final ArrayList<Intent> intents = new ArrayList<>();
+ final GeoPoint geoPoint;
+ try {
+ geoPoint = parseGeoPoint(message.getBody());
+ } catch (IllegalArgumentException e) {
return intents;
}
final Conversational conversation = message.getConversation();
- String label;
- if (conversation instanceof Conversation && conversation.getMode() == Conversation.MODE_SINGLE && message.getStatus() == Message.STATUS_RECEIVED) {
- try {
- label = "(" + URLEncoder.encode(((Conversation) conversation).getName().toString(), "UTF-8") + ")";
- } catch (UnsupportedEncodingException e) {
- label = "";
- }
- } else {
- label = "";
- }
+ final String label = getLabel(context, message);
Intent locationPluginIntent = new Intent(context, ShowLocationActivity.class);
- locationPluginIntent.putExtra("latitude", latitude);
- locationPluginIntent.putExtra("longitude", longitude);
+ locationPluginIntent.putExtra("latitude", geoPoint.getLatitude());
+ locationPluginIntent.putExtra("longitude", geoPoint.getLongitude());
if (message.getStatus() != Message.STATUS_RECEIVED) {
locationPluginIntent.putExtra("jid", conversation.getAccount().getJid().toString());
locationPluginIntent.putExtra("name", conversation.getAccount().getJid().getLocal());
@@ -93,8 +98,38 @@ public class GeoHelper {
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));
+ geoIntent.setData(Uri.parse("geo:" + String.valueOf(geoPoint.getLatitude()) + "," + String.valueOf(geoPoint.getLongitude()) + "?q=" + String.valueOf(geoPoint.getLatitude()) + "," + String.valueOf(geoPoint.getLongitude()) + label));
intents.add(geoIntent);
return intents;
}
+
+ public static void view(Context context, Message message) {
+ final GeoPoint geoPoint = parseGeoPoint(message.getBody());
+ final String label = getLabel(context, message);
+ context.startActivity(geoIntent(geoPoint, label));
+ }
+
+ private static Intent geoIntent(GeoPoint geoPoint, String label) {
+ Intent geoIntent = new Intent(Intent.ACTION_VIEW);
+ geoIntent.setData(Uri.parse("geo:" + String.valueOf(geoPoint.getLatitude()) + "," + String.valueOf(geoPoint.getLongitude()) + "?q=" + String.valueOf(geoPoint.getLatitude()) + "," + String.valueOf(geoPoint.getLongitude()) + "(" + label + ")"));
+ return geoIntent;
+ }
+
+ public static boolean openInOsmAnd(Context context, Message message) {
+ final GeoPoint geoPoint = parseGeoPoint(message.getBody());
+ final String label = getLabel(context, message);
+ return geoIntent(geoPoint, label).resolveActivity(context.getPackageManager()) != null;
+ }
+
+ private static String getLabel(Context context, Message message) {
+ if (message.getStatus() == Message.STATUS_RECEIVED) {
+ try {
+ return URLEncoder.encode(UIHelper.getMessageDisplayName(message), "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ throw new AssertionError(e);
+ }
+ } else {
+ return context.getString(R.string.me);
+ }
+ }
} \ No newline at end of file