Skip to content

Commit

Permalink
[TF] add sending location objects via geo: send intents
Browse files Browse the repository at this point in the history
This patch adds the ability for Telegram to parse locations from send intents
containing a geo:<lat>,<lon>,<zoom> string.

This is done by various map applications, including the popular OSMAnd
and Orux maps. This patch enables the user to share the position of a
POI or destination with Telegram and have it send as a location.
  • Loading branch information
Marcus Hoffmann committed Nov 30, 2017
1 parent eb2a17b commit d692cfa
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3614,6 +3614,29 @@ public void run() {
});
}

public static void prepareSendingLocation(final Location location, final long dialog_id) {
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
@Override
public void run() {
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public void run() {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
TLRPC.TL_messageMediaGeo mediaGeo = new TLRPC.TL_messageMediaGeo();
mediaGeo.geo = new TLRPC.TL_geoPoint();
mediaGeo.geo.lat = location.getLatitude();
mediaGeo.geo._long = location.getLongitude();
SendMessagesHelper.getInstance().sendMessage(mediaGeo, dialog_id, null, null, null);
}
});
}
});
}
});
}

public static void prepareSendingPhotos(ArrayList<String> paths, ArrayList<Uri> uris, final long dialog_id, final MessageObject reply_to_msg, final ArrayList<String> captions, final ArrayList<ArrayList<TLRPC.InputDocument>> masks, final InputContentInfoCompat inputContent, final boolean forceDocument, final ArrayList<Integer> ttls) {
if (paths == null && uris == null || paths != null && paths.isEmpty() || uris != null && uris.isEmpty()) {
return;
Expand Down
23 changes: 18 additions & 5 deletions TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.graphics.Point;
import android.graphics.Shader;
import android.graphics.drawable.BitmapDrawable;
import android.location.Location;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
Expand Down Expand Up @@ -90,11 +91,15 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class LaunchActivity extends Activity implements ActionBarLayout.ActionBarLayoutDelegate, NotificationCenter.NotificationCenterDelegate, DialogsActivity.DialogsActivityDelegate {

private boolean finished;
private String videoPath;
final private Pattern r = Pattern.compile("geo: ?(-?\\d+\\.\\d+),(-?\\d+\\.\\d+)(,|\\?z=)(-?\\d+)");
private Location sendingLocation;
private String sendingText;
private ArrayList<Uri> photoPathsArray;
private ArrayList<String> documentsPathsArray;
Expand Down Expand Up @@ -806,8 +811,13 @@ private boolean handleIntent(Intent intent, boolean isNew, boolean restore, bool
}
}
String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT);

if (text != null && text.length() != 0) {
Matcher m = r.matcher(text);
if(m.find()) {
sendingLocation = new Location("");
sendingLocation.setLatitude(Double.parseDouble(m.group(1)));
sendingLocation.setLongitude(Double.parseDouble(m.group(2)));
}
else if (text != null && text.length() != 0) {
if ((text.startsWith("http://") || text.startsWith("https://")) && subject != null && subject.length() != 0) {
text = subject + "\n" + text;
}
Expand Down Expand Up @@ -859,7 +869,7 @@ private boolean handleIntent(Intent intent, boolean isNew, boolean restore, bool
}
}
}
} else if (sendingText == null) {
} else if (sendingText == null && sendingLocation == null) {
error = true;
}
}
Expand Down Expand Up @@ -1206,7 +1216,7 @@ public void run() {
}
actionBarLayout.presentFragment(new AudioPlayerActivity(), false, true, true);
pushOpened = true;
} else if (videoPath != null || photoPathsArray != null || sendingText != null || documentsPathsArray != null || contactsToSend != null || documentsUrisArray != null) {
} else if (videoPath != null || photoPathsArray != null || sendingText != null || sendingLocation != null || documentsPathsArray != null || contactsToSend != null || documentsUrisArray != null) {
if (!AndroidUtilities.isTablet()) {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
}
Expand Down Expand Up @@ -1763,7 +1773,9 @@ public void didSelectDialog(DialogsActivity dialogsFragment, long dialog_id, boo
if (sendingText != null) {
SendMessagesHelper.prepareSendingText(sendingText, dialog_id);
}

if (sendingLocation != null) {
SendMessagesHelper.prepareSendingLocation(sendingLocation, dialog_id);
}
if (documentsPathsArray != null || documentsUrisArray != null) {
SendMessagesHelper.prepareSendingDocuments(documentsPathsArray, documentsOriginalPathsArray, documentsUrisArray, documentsMimeType, dialog_id, null, null);
}
Expand All @@ -1777,6 +1789,7 @@ public void didSelectDialog(DialogsActivity dialogsFragment, long dialog_id, boo
photoPathsArray = null;
videoPath = null;
sendingText = null;
sendingLocation = null;
documentsPathsArray = null;
documentsOriginalPathsArray = null;
contactsToSend = null;
Expand Down

0 comments on commit d692cfa

Please sign in to comment.