BasicAirData/GPSLogger

Ability to share position with other apps

TVEgit opened this issue · 14 comments

Hello,

I'd like to copy Lat/Lon values into the clipboard buffer or directly extract those values to share with a text messaging app.
This is for emergency or at least for requesting assistance simply.
The coordinates are currently displayed but the values may not be copied.
I'd suggest a long press on the lat/lon display bring the standard Android copy menu.

Thank you.

It is an interesting feature that could be easily added to the app.
Since we don't have anything associated with a long click on coordinates, we could copy the coordinates simply with a long click.

I write this comment as a note for an hypothetical implementation of the feature.

We can implement the copy to the clipboard feature by adding the following longClickListener to FragmentGPSFix.java onCreateView:

        tlCoordinates.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(CLIPBOARD_SERVICE);
                   // Coordinates GG°MM'SS.SSSS"
//                ClipData clip = ClipData.newPlainText("Coordinates",
//                        Location.convert(Math.abs(location.getLatitude()), Location.FORMAT_SECONDS)
//                                .replaceFirst(":", "°")
//                                .replaceFirst(":", "'")
//                                .concat(location.getLatitude() >= 0 ? "\"N " : "\"S ")
//                           + Location.convert(Math.abs(location.getLongitude()), Location.FORMAT_SECONDS)
//                                .replaceFirst(":", "°")
//                                .replaceFirst(":", "'")
//                                .concat(location.getLongitude() >= 0 ? "\"E" : "\"W"));
                   // Coordinates GG.GGGGGGGGG, to be preferred
                ClipData clip = ClipData.newPlainText("Coordinates",
                        String.format(Locale.getDefault(), "%.9f", Math.abs(location.getLatitude()))
                           + ", "
                           + String.format(Locale.getDefault(), "%.9f", Math.abs(location.getLongitude()))
                );
                clipboard.setPrimaryClip(clip);
                Toast.makeText(gpsApp.getApplicationContext(), android.R.string.copy, Toast.LENGTH_SHORT).show();

                return false;
            }
        });

The Copy feature is the more clean solution, but needs a new string in order to give to the users the feedback about the operation. Something like a Toast with the text "Copied to clipboard".

As alternative we could implement a Share with... feature, that shows the list of available apps (the list includes email, SMS, and also Copy to clipboard on many devices):

photo_2022-03-07_22-30-33

        tlCoordinates.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                if (location != null) {
                    Intent sendIntent = new Intent();
                    sendIntent.setAction(Intent.ACTION_SEND);
                    sendIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    sendIntent.putExtra(Intent.EXTRA_TEXT,
                            String.format(Locale.getDefault(), "%.9f", Math.abs(location.getLatitude()))
                                    + ", "
                                    + String.format(Locale.getDefault(), "%.9f", Math.abs(location.getLongitude())));
                    sendIntent.setType("text/plain");

                    try {
                        Intent shareIntent = Intent.createChooser(sendIntent, getString(R.string.card_menu_share));
                        if (shareIntent != null) startActivity(shareIntent);
                    } catch (NullPointerException e) {
                        //Log.w("myApp", "[#] FragmentTracklist.java - Unable to start the Activity");
                    }
                }

                return false;
            }
        });

In this case we could add an icon to the upper toolbar, and maybe a dialog to let the user select which data of the fix should be shared (coordinates, time, speed, and so on).
We must add also the corresponding intent query to AndroidManifest.xml:

        <intent>
            <action android:name="android.intent.action.SEND" />
            <data android:mimeType="text/plain" />
        </intent>

Maybe I would prefer the first approach, that doesn't block the UI and doesn't show a lot of useless choices like a text/plain share selector does.

We have a similar need, where we'd like the current position to be output to some specific on-device location - one that (ideally) could be queried by a javascript (or similar). The ultimate need is for the device to then POST its current location to a back-end web server. (This is for a captive application, used by internal employees only.)

We tried to query you via your "contact us" form on https://www.basicairdata.eu/, but that kept failing. :) My client would be willing to pay for at least some of the development of the feature.

@JDRuggiero We are used to be free to evaluate the inclusion of a feature basing on users requests; unfortunately we don't develop dedicated features, paid or not. Moreover we develop the app in our spare time, thus we cannot (and we don't want to) work with constraint and deadlines.

But GPS Logger is open source software: you can easily fork it and, with a bit of java knowledge, customize the app for your use adding any dedicated feature you want under the terms of the GPL license. The feature you requested should be relatively simple to implement.

JLJu commented

@JDRuggiero >>> We tried to query you via your "contact us" form on https://www.basicairdata.eu/, but that kept failing. :)

Now the form is running fine. Thank you for the heads-up.

Today I started to think the implementation of this feature, and I'm trying the less invasive clipboard approach.
A lazy but functional way to implement it could be like the following mock-up:

Copy_coordinates_20221112

A small "Copy" icon should be visible near the corner of the coordinates tile.
Clicking it will copy the coordinates to Clipboard.
When the coordinates are copied a toast should appear to inform the user about the operation performed: something like "Copied to Clipboard".

If in the future we'll add more feature on this tile, we could easily switch to a contextual menu.

In the previous commit we always copy the coordinates to the clipboard in decimal format;
for example 48.143624037, 13.007297192.
This way Google Maps can easily view them with copy/paste.

But we could copy the coordinates in DDºMM'SSSSSS (12º43'49965877"), or in the format used for visualization;
is the decimal format the best way to copy them?

szpak commented

Is it possible to get also the "long tap" here? To show more options to user (with one of them use by default on a "regular tap")?

Simple decimal is what we need. The use case is to allow other apps to use the data.
A good complement option would be to use a format understood by Android to be a map location and offer in the "open with" dialog a choice of apps capable of displaying the.ap at these coordinates. I think it works with some kind of url format but I haven't researched the matter.

Ok, let's go straight with the decimal format as first (and lazy) implementation.
We'll collect user's feedback in order to evaluate if and how we should expand the feature on the next updates.
In that case the "long tap" could be a good idea to consider.

Thanks @szpak, @JDRuggiero, and @TVEgit for your very useful feedback!

@TVEgit: I think you are referring to the "geo:" Uri, that can open for example Google Maps on the specified position. I tried also it when I was experimenting with the coordinates: it was not listed on the possibilities above because it is good for visualization, but not for data sharing. It could be one of the possible future expansions. For example we could have a menu with Copy, Share and View instead of a single icon.

Good decision.
@GrazianoCapelli : Yes that's what I meant. You are right to make a difference between visualization and data sharing. My suggestion was based on assuming that most frequent use case of data sharing is visualization. It would improve user experience to propose a one-step action. Particularly for many people who do not know how to use plain geo data (including - but not limited to - my wife).
A good candidate for a next version.

The feature has been merged into develop branch, and it will be included into the next release of the app.
I close the issue, feel free to comment here or re-open it in case of need.