forked from upstream-mirrors/OpenTracks
Dashboard API: fallback to "open as KMZ" implemented as proxy activity.
We are not allowed to query for installed packages as of Android R (API 30).
This commit is contained in:
@@ -111,6 +111,13 @@ limitations under the License.
|
|||||||
|
|
||||||
<activity android:name=".settings.SettingsActivity" />
|
<activity android:name=".settings.SettingsActivity" />
|
||||||
|
|
||||||
|
<activity android:name=".util.IntentUtils$ShowOnMapProxyActivity">
|
||||||
|
<intent-filter android:label="@string/open_track_as_file">
|
||||||
|
<action android:name="Intent.OpenTracks-Dashboard" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
|
||||||
<provider
|
<provider
|
||||||
android:name=".content.provider.ShareContentProvider"
|
android:name=".content.provider.ShareContentProvider"
|
||||||
android:authorities="${applicationId}.content"
|
android:authorities="${applicationId}.content"
|
||||||
|
|||||||
@@ -171,9 +171,7 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
|
|||||||
private final Runnable bindChangedCallback = new Runnable() {
|
private final Runnable bindChangedCallback = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
/*
|
// After binding changes (e.g., becomes available), update the total time in trackController.
|
||||||
* After binding changes (e.g., becomes available), update the total time in trackController.
|
|
||||||
*/
|
|
||||||
runOnUiThread(() -> trackController.update(PreferencesUtils.isRecording(recordingTrackId), recordingTrackPaused));
|
runOnUiThread(() -> trackController.update(PreferencesUtils.isRecording(recordingTrackId), recordingTrackPaused));
|
||||||
|
|
||||||
if (!startGps) {
|
if (!startGps) {
|
||||||
@@ -479,7 +477,7 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
|
|||||||
Intent intent;
|
Intent intent;
|
||||||
switch (itemId) {
|
switch (itemId) {
|
||||||
case R.id.list_context_menu_show_on_map:
|
case R.id.list_context_menu_show_on_map:
|
||||||
IntentUtils.showTrackOnMap(this, trackIds);
|
IntentUtils.showTrackOnMapDashboard(this, trackIds);
|
||||||
return true;
|
return true;
|
||||||
case R.id.list_context_menu_share:
|
case R.id.list_context_menu_share:
|
||||||
intent = IntentUtils.newShareFileIntent(this, trackIds);
|
intent = IntentUtils.newShareFileIntent(this, trackIds);
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ public class TrackRecordedActivity extends AbstractListActivity implements Choos
|
|||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
case R.id.track_detail_menu_show_on_map:
|
case R.id.track_detail_menu_show_on_map:
|
||||||
IntentUtils.showTrackOnMap(this, new long[]{trackId});
|
IntentUtils.showTrackOnMapDashboard(this, new long[]{trackId});
|
||||||
return true;
|
return true;
|
||||||
case R.id.track_detail_markers:
|
case R.id.track_detail_markers:
|
||||||
intent = IntentUtils.newIntent(this, MarkerListActivity.class)
|
intent = IntentUtils.newIntent(this, MarkerListActivity.class)
|
||||||
|
|||||||
@@ -338,7 +338,7 @@ public class TrackRecordingActivity extends AbstractActivity implements ChooseAc
|
|||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
case R.id.track_detail_menu_show_on_map:
|
case R.id.track_detail_menu_show_on_map:
|
||||||
IntentUtils.showTrackOnMap(this, new long[]{trackId});
|
IntentUtils.showTrackOnMapDashboard(this, new long[]{trackId});
|
||||||
return true;
|
return true;
|
||||||
case R.id.track_detail_markers:
|
case R.id.track_detail_markers:
|
||||||
intent = IntentUtils.newIntent(this, MarkerListActivity.class)
|
intent = IntentUtils.newIntent(this, MarkerListActivity.class)
|
||||||
|
|||||||
@@ -910,5 +910,4 @@ public class ContentProviderUtils {
|
|||||||
public static String[] parseTrackIdsFromUri(Uri url) {
|
public static String[] parseTrackIdsFromUri(Uri url) {
|
||||||
return TextUtils.split(url.getLastPathSegment(), ID_SEPARATOR);
|
return TextUtils.split(url.getLastPathSegment(), ID_SEPARATOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,11 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import de.dennisguse.opentracks.R;
|
||||||
import de.dennisguse.opentracks.content.data.TrackPointsColumns;
|
import de.dennisguse.opentracks.content.data.TrackPointsColumns;
|
||||||
import de.dennisguse.opentracks.content.data.TracksColumns;
|
import de.dennisguse.opentracks.content.data.TracksColumns;
|
||||||
import de.dennisguse.opentracks.content.provider.ContentProviderUtils;
|
import de.dennisguse.opentracks.content.provider.ContentProviderUtils;
|
||||||
@@ -24,10 +27,13 @@ public class IntentDashboardUtils {
|
|||||||
private static final String EXTRAS_SHOULD_KEEP_SCREEN_ON = "EXTRAS_SHOULD_KEEP_SCREEN_ON";
|
private static final String EXTRAS_SHOULD_KEEP_SCREEN_ON = "EXTRAS_SHOULD_KEEP_SCREEN_ON";
|
||||||
private static final String EXTRAS_SHOW_WHEN_LOCKED = "EXTRAS_SHOULD_KEEP_SCREEN_ON";
|
private static final String EXTRAS_SHOW_WHEN_LOCKED = "EXTRAS_SHOULD_KEEP_SCREEN_ON";
|
||||||
|
|
||||||
|
private static int TRACK_URI_INDEX = 0;
|
||||||
|
private static int TRACKPOINTS_URI_INDEX = 1;
|
||||||
|
|
||||||
private IntentDashboardUtils() {
|
private IntentDashboardUtils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean startDashboard(Context context, long[] trackIds) {
|
public static void startDashboard(Context context, long[] trackIds) {
|
||||||
ArrayList<Uri> uris = new ArrayList<>();
|
ArrayList<Uri> uris = new ArrayList<>();
|
||||||
String trackIdList = ContentProviderUtils.formatIdListForUri(trackIds);
|
String trackIdList = ContentProviderUtils.formatIdListForUri(trackIds);
|
||||||
|
|
||||||
@@ -42,16 +48,23 @@ public class IntentDashboardUtils {
|
|||||||
intent.putExtra(EXTRAS_SHOW_WHEN_LOCKED, PreferencesUtils.shouldShowStatsOnLockscreen(context));
|
intent.putExtra(EXTRAS_SHOW_WHEN_LOCKED, PreferencesUtils.shouldShowStatsOnLockscreen(context));
|
||||||
|
|
||||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||||
ClipData clipData = ClipData.newRawUri(null, uris.get(0));
|
ClipData clipData = ClipData.newRawUri(null, uris.get(TRACK_URI_INDEX));
|
||||||
clipData.addItem(new ClipData.Item(uris.get(1)));
|
clipData.addItem(new ClipData.Item(uris.get(TRACKPOINTS_URI_INDEX)));
|
||||||
intent.setClipData(clipData);
|
intent.setClipData(clipData);
|
||||||
|
|
||||||
if (intent.resolveActivity(context.getPackageManager()) != null) {
|
context.startActivity(Intent.createChooser(intent, context.getString(R.string.open_track_using_dashboard)));
|
||||||
context.startActivity(Intent.createChooser(intent, null));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static long[] extractTrackIdsFromIntent(@NonNull Intent intent) {
|
||||||
|
final ArrayList<Uri> uris = intent.getParcelableArrayListExtra(ACTION_DASHBOARD_PAYLOAD);
|
||||||
|
final Uri tracksUri = uris.get(TRACK_URI_INDEX);
|
||||||
|
|
||||||
|
String[] trackIdsString = ContentProviderUtils.parseTrackIdsFromUri(tracksUri);
|
||||||
|
long[] trackIds = new long[trackIdsString.length];
|
||||||
|
for (int i = 0; i < trackIdsString.length; i++) {
|
||||||
|
trackIds[i] = Long.parseLong(trackIdsString[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return trackIds;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,15 +16,15 @@
|
|||||||
|
|
||||||
package de.dennisguse.opentracks.util;
|
package de.dennisguse.opentracks.util;
|
||||||
|
|
||||||
import android.content.ActivityNotFoundException;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.core.content.FileProvider;
|
import androidx.core.content.FileProvider;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -52,6 +52,8 @@ public class IntentUtils {
|
|||||||
|
|
||||||
private static final String JPEG_EXTENSION = "jpeg";
|
private static final String JPEG_EXTENSION = "jpeg";
|
||||||
|
|
||||||
|
private static final TrackFileFormat SHOWONMAP_TRACKFILEFORMAT = TrackFileFormat.KMZ_WITH_TRACKDETAIL;
|
||||||
|
|
||||||
private IntentUtils() {
|
private IntentUtils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,41 +155,45 @@ public class IntentUtils {
|
|||||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||||
intent.setData(Uri.parse(uri));
|
intent.setData(Uri.parse(uri));
|
||||||
|
|
||||||
try {
|
|
||||||
context.startActivity(intent);
|
context.startActivity(Intent.createChooser(intent, null));
|
||||||
} catch (ActivityNotFoundException e) {
|
|
||||||
Toast.makeText(context, context.getString(R.string.app_not_installed_show_on_map), Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send intent to show tracks on a map (needs an another app).
|
* Send intent to show tracks on a map (needs an another app) as resource URIs.
|
||||||
*
|
*
|
||||||
* @param context the context
|
* @param context the context
|
||||||
* @param trackIds the track ids
|
* @param trackIds the track ids
|
||||||
*/
|
*/
|
||||||
public static void showTrackOnMap(Context context, long[] trackIds) {
|
public static void showTrackOnMapDashboard(Context context, long[] trackIds) {
|
||||||
if (trackIds.length == 0) {
|
if (trackIds.length == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IntentDashboardUtils.startDashboard(context, trackIds)) {
|
IntentDashboardUtils.startDashboard(context, trackIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send intent to show tracks on a map (needs an another app) as KMZ.
|
||||||
|
*
|
||||||
|
* @param context the context
|
||||||
|
* @param trackIds the track ids
|
||||||
|
*/
|
||||||
|
public static void showTrackOnMapKMZ(Context context, long[] trackIds) {
|
||||||
|
if (trackIds.length == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
|
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
intent.putExtra(TrackPointsColumns.TRACKID, trackIds[0]);
|
intent.putExtra(TrackPointsColumns.TRACKID, trackIds[0]);
|
||||||
Pair<Uri, String> uriAndMime = ShareContentProvider.createURI(trackIds, "SharingTrack", TrackFileFormat.KMZ_WITH_TRACKDETAIL);
|
Pair<Uri, String> uriAndMime = ShareContentProvider.createURI(trackIds, "SharingTrack", SHOWONMAP_TRACKFILEFORMAT);
|
||||||
intent.setDataAndType(uriAndMime.first, uriAndMime.second);
|
intent.setDataAndType(uriAndMime.first, uriAndMime.second);
|
||||||
|
|
||||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||||
if (intent.resolveActivity(context.getPackageManager()) != null) {
|
|
||||||
context.startActivity(intent);
|
context.startActivity(Intent.createChooser(intent, context.getString(R.string.open_track_as_trackfileformat, SHOWONMAP_TRACKFILEFORMAT.getExtension())));
|
||||||
} else {
|
|
||||||
Toast.makeText(context, context.getString(R.string.app_not_installed_show_on_map), Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -209,4 +215,19 @@ public class IntentUtils {
|
|||||||
.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
|
.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
|
||||||
return new Pair<>(intent, photoUri);
|
return new Pair<>(intent, photoUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to convert showTrackOnMapDashboard-requests to showTrackOnMapKMZ.
|
||||||
|
*/
|
||||||
|
public static class ShowOnMapProxyActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
protected void onCreate(final Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
long[] trackIds = IntentDashboardUtils.extractTrackIdsFromIntent(getIntent());
|
||||||
|
|
||||||
|
showTrackOnMapKMZ(this, trackIds);
|
||||||
|
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,6 +95,10 @@ limitations under the License.
|
|||||||
g) do whatever you think helps OpenTracks.
|
g) do whatever you think helps OpenTracks.
|
||||||
</string>
|
</string>
|
||||||
|
|
||||||
|
<string name="open_track_using_dashboard">Open using OpenTracks-Dashboard</string>
|
||||||
|
<string name="open_track_as_file">Open as file</string>
|
||||||
|
<string name="open_track_as_trackfileformat">Open as %1$s</string>
|
||||||
|
|
||||||
<!-- Activity Type -->
|
<!-- Activity Type -->
|
||||||
<string name="activity_type_airplane">airplane</string>
|
<string name="activity_type_airplane">airplane</string>
|
||||||
<string name="activity_type_atv">ATV</string>
|
<string name="activity_type_atv">ATV</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user