mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-28 11:35:48 +01:00
Add menus to share GPX, raw summary, raw details
This commit is contained in:
parent
9851493cf1
commit
a8b9d22313
@ -188,7 +188,7 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
|
||||
}
|
||||
|
||||
layout.startAnimation(animFadeRight);
|
||||
show_hide_gpx_menu();
|
||||
updateMenuItems();
|
||||
} else {
|
||||
layout.startAnimation(animBounceRight);
|
||||
}
|
||||
@ -211,7 +211,7 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
|
||||
|
||||
|
||||
layout.startAnimation(animFadeLeft);
|
||||
show_hide_gpx_menu();
|
||||
updateMenuItems();
|
||||
} else {
|
||||
layout.startAnimation(animBounceLeft);
|
||||
}
|
||||
@ -560,8 +560,17 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
|
||||
case R.id.activity_action_take_screenshot:
|
||||
take_share_screenshot(ActivitySummaryDetail.this);
|
||||
return true;
|
||||
case R.id.activity_action_show_gpx:
|
||||
viewGpxTrack(ActivitySummaryDetail.this);
|
||||
return true;
|
||||
case R.id.activity_action_share_gpx:
|
||||
share_gpx_track(ActivitySummaryDetail.this);
|
||||
shareGpxTrack(ActivitySummaryDetail.this, currentItem);
|
||||
return true;
|
||||
case R.id.activity_action_dev_share_raw_summary:
|
||||
shareRawSummary(ActivitySummaryDetail.this, currentItem);
|
||||
return true;
|
||||
case R.id.activity_action_dev_share_raw_details:
|
||||
shareRawDetails(ActivitySummaryDetail.this, currentItem);
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
@ -604,7 +613,7 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
|
||||
}
|
||||
}
|
||||
|
||||
private void share_gpx_track(Context context) {
|
||||
private void viewGpxTrack(Context context) {
|
||||
final String gpxTrack = currentItem.getGpxTrack();
|
||||
|
||||
if (gpxTrack != null) {
|
||||
@ -618,16 +627,63 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
|
||||
}
|
||||
}
|
||||
|
||||
private void show_hide_gpx_menu() {
|
||||
String gpxTrack = null;
|
||||
private static void shareGpxTrack(final Context context, final BaseActivitySummary summary) {
|
||||
try {
|
||||
AndroidUtils.shareFile(context, new File(summary.getGpxTrack()));
|
||||
} catch (final Exception e) {
|
||||
GB.toast(context, "Unable to share GPX track: " + e.getMessage(), Toast.LENGTH_LONG, GB.ERROR, e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void shareRawSummary(final Context context, final BaseActivitySummary summary) {
|
||||
if (summary.getRawSummaryData() == null) {
|
||||
GB.toast(context, "No raw summary in this activity", Toast.LENGTH_LONG, GB.WARN);
|
||||
return;
|
||||
}
|
||||
|
||||
final String rawSummaryFilename = FileUtils.makeValidFileName(String.format("%s_summary.bin", DateTimeUtils.formatIso8601(summary.getStartTime())));
|
||||
|
||||
try {
|
||||
AndroidUtils.shareBytesAsFile(context, rawSummaryFilename, summary.getRawSummaryData());
|
||||
} catch (final Exception e) {
|
||||
GB.toast(context, "Unable to share GPX track: " + e.getMessage(), Toast.LENGTH_LONG, GB.ERROR, e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void shareRawDetails(final Context context, final BaseActivitySummary summary) {
|
||||
if (summary.getRawDetailsPath() == null) {
|
||||
GB.toast(context, "No raw details in this activity", Toast.LENGTH_LONG, GB.WARN);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
AndroidUtils.shareFile(context, new File(summary.getRawDetailsPath()));
|
||||
} catch (final Exception e) {
|
||||
GB.toast(context, "Unable to share raw details: " + e.getMessage(), Toast.LENGTH_LONG, GB.ERROR, e);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateMenuItems() {
|
||||
boolean hasGpx = false;
|
||||
boolean hasRawSummary = false;
|
||||
boolean hasRawDetails = false;
|
||||
|
||||
if (currentItem != null) {
|
||||
gpxTrack = currentItem.getGpxTrack();
|
||||
}
|
||||
if (gpxTrack == null) {
|
||||
mOptionsMenu.findItem(R.id.activity_detail_overflowMenu).getSubMenu().findItem(R.id.activity_action_share_gpx).setVisible(false);
|
||||
} else {
|
||||
mOptionsMenu.findItem(R.id.activity_detail_overflowMenu).getSubMenu().findItem(R.id.activity_action_share_gpx).setVisible(true);
|
||||
hasGpx = currentItem.getGpxTrack() != null;
|
||||
hasRawSummary = currentItem.getRawSummaryData() != null;
|
||||
|
||||
final String rawDetailsPath = currentItem.getRawDetailsPath();
|
||||
if (rawDetailsPath != null) {
|
||||
hasRawDetails = new File(rawDetailsPath).exists();
|
||||
}
|
||||
}
|
||||
|
||||
mOptionsMenu.findItem(R.id.activity_detail_overflowMenu).getSubMenu().findItem(R.id.activity_action_show_gpx).setVisible(hasGpx);
|
||||
mOptionsMenu.findItem(R.id.activity_detail_overflowMenu).getSubMenu().findItem(R.id.activity_action_share_gpx).setVisible(hasGpx);
|
||||
mOptionsMenu.findItem(R.id.activity_detail_overflowMenu).getSubMenu().findItem(R.id.activity_action_dev_share_raw_summary).setVisible(hasRawSummary);
|
||||
mOptionsMenu.findItem(R.id.activity_detail_overflowMenu).getSubMenu().findItem(R.id.activity_action_dev_share_raw_details).setVisible(hasRawDetails);
|
||||
final MenuItem devToolsMenu = mOptionsMenu.findItem(R.id.activity_detail_overflowMenu).getSubMenu().findItem(R.id.activity_action_dev_tools);
|
||||
devToolsMenu.setVisible(devToolsMenu.getSubMenu().hasVisibleItems());
|
||||
}
|
||||
|
||||
private void showCanvas() {
|
||||
@ -663,7 +719,7 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
|
||||
super.onCreateOptionsMenu(menu);
|
||||
mOptionsMenu = menu;
|
||||
getMenuInflater().inflate(R.menu.activity_take_screenshot_menu, menu);
|
||||
show_hide_gpx_menu();
|
||||
updateMenuItems();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,6 @@ import android.content.res.Configuration;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.os.ParcelUuid;
|
||||
import android.os.Parcelable;
|
||||
@ -40,7 +39,11 @@ import androidx.annotation.Nullable;
|
||||
import androidx.core.content.FileProvider;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Locale;
|
||||
@ -49,6 +52,8 @@ import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
|
||||
public class AndroidUtils {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AndroidUtils.class);
|
||||
|
||||
/**
|
||||
* Creates a new {@link ParcelUuid} array with the contents of the given uuids.
|
||||
* The given array is expected to contain only {@link ParcelUuid} elements.
|
||||
@ -244,4 +249,47 @@ public class AndroidUtils {
|
||||
Toast.makeText(context, R.string.activity_error_no_app_for_gpx, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
public static void shareBytesAsFile(final Context context, final String name, final byte[] bytes) throws IOException {
|
||||
final File cacheDir = context.getCacheDir();
|
||||
final File rawCacheDir = new File(cacheDir, "raw");
|
||||
rawCacheDir.mkdir();
|
||||
final File file = new File(rawCacheDir, name);
|
||||
|
||||
try (FileOutputStream outputStream = new FileOutputStream(file)) {
|
||||
outputStream.write(bytes);
|
||||
} catch (final IOException e) {
|
||||
LOG.error("Failed to write bytes to temporary file", e);
|
||||
return;
|
||||
}
|
||||
|
||||
shareFile(context, file);
|
||||
}
|
||||
|
||||
public static void shareFile(final Context context, final File file) throws IOException {
|
||||
if (!file.exists()) {
|
||||
LOG.warn("File {} does not exist", file.getPath());
|
||||
return;
|
||||
}
|
||||
|
||||
shareFile(context, file, "*/*");
|
||||
}
|
||||
|
||||
public static void shareFile(final Context context, final File file, final String type) throws IOException {
|
||||
final Uri contentUri = FileProvider.getUriForFile(
|
||||
context,
|
||||
context.getApplicationContext().getPackageName() + ".screenshot_provider",
|
||||
file
|
||||
);
|
||||
|
||||
final Intent intent = new Intent(Intent.ACTION_SEND);
|
||||
intent.setType(type);
|
||||
intent.putExtra(Intent.EXTRA_STREAM, contentUri);
|
||||
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
try {
|
||||
context.startActivity(Intent.createChooser(intent, "Share file"));
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Toast.makeText(context, R.string.activity_error_share_failed, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,11 +17,35 @@
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/activity_action_share_gpx"
|
||||
android:id="@+id/activity_action_show_gpx"
|
||||
android:icon="@drawable/ic_map"
|
||||
android:title="@string/activity_detail_show_gps_label"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/activity_action_share_gpx"
|
||||
android:icon="@drawable/ic_share"
|
||||
android:title="@string/activity_detail_share_gps_label"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/activity_action_dev_tools"
|
||||
android:icon="@drawable/ic_developer_mode"
|
||||
android:title="@string/dev_tools"
|
||||
app:showAsAction="never">
|
||||
<menu>
|
||||
<item
|
||||
android:id="@+id/activity_action_dev_share_raw_summary"
|
||||
android:title="@string/activity_detail_share_raw_summary"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/activity_action_dev_share_raw_details"
|
||||
android:title="@string/activity_detail_share_raw_details"
|
||||
app:showAsAction="never" />
|
||||
</menu>
|
||||
</item>
|
||||
|
||||
</menu>
|
||||
</item>
|
||||
</menu>
|
||||
|
@ -1188,6 +1188,7 @@
|
||||
<string name="activity_type_exercise">Exercise</string>
|
||||
<string name="activity_error_no_app_for_gpx">To view activity trace, install app which can handle GPX files.</string>
|
||||
<string name="activity_error_no_app_for_png">To share this screenshot, install an app which can handle image files.</string>
|
||||
<string name="activity_error_share_failed">Sharing file failed.</string>
|
||||
<string name="select_all">Select all</string>
|
||||
<string name="share">Share</string>
|
||||
<string name="reset_index">Reset fetch date</string>
|
||||
@ -1618,7 +1619,11 @@
|
||||
<string name="activity_detail_end_label">End</string>
|
||||
<string name="activity_detail_duration_label">Duration</string>
|
||||
<string name="activity_detail_show_gps_label">Show GPS Track</string>
|
||||
<string name="activity_detail_share_gps_label">Share GPS Track</string>
|
||||
<string name="activity_detail_share_raw_summary">Share Raw Summary</string>
|
||||
<string name="activity_detail_share_raw_details">Share Raw Details</string>
|
||||
<string name="gps_track">GPS track</string>
|
||||
<string name="dev_tools">Dev Tools</string>
|
||||
<!-- Device Actions Preferences -->
|
||||
<string name="prefs_events_forwarding_summary">Use device events to trigger actions and Android broadcasts</string>
|
||||
<string name="prefs_events_forwarding_title">Device actions</string>
|
||||
|
@ -2,5 +2,6 @@
|
||||
<!-- defines directories shared to other applications -->
|
||||
<paths xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<external-path name="external_files" path="."/>
|
||||
<files-path name="gpx" path="./"/>
|
||||
</paths>
|
||||
<files-path name="gpx" path="./" />
|
||||
<cache-path name="raw" path="raw/" />
|
||||
</paths>
|
||||
|
Loading…
Reference in New Issue
Block a user