mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-28 04:46:51 +01:00
add GPX receiver via intent
This commit is contained in:
parent
fffe7e37c4
commit
4a5d639d01
@ -621,5 +621,18 @@
|
||||
<activity
|
||||
android:name=".devices.um25.Activity.DataActivity"
|
||||
android:exported="true" />
|
||||
|
||||
<activity
|
||||
android:name=".activities.GpxReceiverActivity"
|
||||
android:label="@string/gpx_receiver_activity_title"
|
||||
android:screenOrientation="portrait"
|
||||
android:windowSoftInputMode="stateHidden">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEND" />
|
||||
<action android:name="android.intent.action.SEND_MULTIPLE" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<data android:mimeType="*/*" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
@ -288,6 +288,7 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
|
||||
public void onClick(View view) {
|
||||
export_path = get_path();
|
||||
filesGpxList = get_gpx_file_list();
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(ActivitySummaryDetail.this);
|
||||
builder.setTitle(R.string.activity_summary_detail_select_gpx_track);
|
||||
ArrayAdapter<String> directory_listing = new ArrayAdapter<String>(ActivitySummaryDetail.this, android.R.layout.simple_list_item_1, filesGpxList);
|
||||
@ -374,7 +375,7 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
|
||||
try {
|
||||
path = FileUtils.getExternalFilesDir();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
LOG.error("Error getting path", e);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
@ -576,7 +577,7 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
|
||||
shareScreenshot(targetFile, context);
|
||||
GB.toast(getApplicationContext(), "Screenshot saved", Toast.LENGTH_LONG, GB.INFO);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
LOG.error("Error getting screenshot", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,163 @@
|
||||
/* Copyright (C) 2015-2020 abettenburg, Andreas Shimokawa, Carsten Pfeiffer,
|
||||
Daniele Gobbetti, Lem Dulfo
|
||||
|
||||
This file is part of Gadgetbridge.
|
||||
|
||||
Gadgetbridge is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Gadgetbridge is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
package nodomain.freeyourgadget.gadgetbridge.activities;
|
||||
|
||||
import android.content.ClipData;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
||||
|
||||
public class GpxReceiverActivity extends AbstractGBActivity {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ActivitySummaryDetail.class);
|
||||
boolean toOverwrite = false;
|
||||
ArrayList<FileToProcess> fileList = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_gpx_receiver);
|
||||
Button gpx_receiver_ok = findViewById(R.id.gpx_receiver_ok);
|
||||
Button gpx_receiver_cancel = findViewById(R.id.gpx_receiver_cancel);
|
||||
View gpx_receiver_overwrite_label = findViewById(R.id.gpx_receiver_overwrite_label);
|
||||
TextView gpx_receiver_files_listing = findViewById(R.id.gpx_receiver_files_listing);
|
||||
TextView gpx_receiver_received_label = findViewById(R.id.gpx_receiver_received_label);
|
||||
|
||||
gpx_receiver_cancel.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
gpx_receiver_ok.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
for (FileToProcess fileToProcess : fileList) {
|
||||
save_file(fileToProcess.source, fileToProcess.destination);
|
||||
}
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
final Intent intent = getIntent();
|
||||
final ClipData intentClipData = intent.getClipData();
|
||||
StringBuilder fileListingText = new StringBuilder();
|
||||
ArrayList<Uri> documentUris = new ArrayList<>();
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
if (intent.getData() != null) {
|
||||
documentUris.add(intent.getData());
|
||||
} else {
|
||||
if (intentClipData != null && intentClipData.getItemCount() > 0) {
|
||||
for (int i = 0; i < intentClipData.getItemCount(); i++) {
|
||||
documentUris.add(intentClipData.getItemAt(i).getUri());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (documentUris != null) {
|
||||
for (Uri uri : documentUris) {
|
||||
if (uri.getPath().toLowerCase().endsWith(".gpx")) {
|
||||
FileToProcess file = new FileToProcess(uri);
|
||||
fileList.add(file);
|
||||
fileListingText.append(String.format("%s %s\n\n", file.name, file.exists ? getString(R.string.dbmanagementactivity_overwrite) : ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (toOverwrite) {
|
||||
gpx_receiver_overwrite_label.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
gpx_receiver_overwrite_label.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
gpx_receiver_received_label.setText(String.format("%s %s", getString(R.string.gpx_receiver_files_received), fileList.toArray().length));
|
||||
gpx_receiver_files_listing.setText(fileListingText.toString());
|
||||
}
|
||||
|
||||
private String get_file_name(Uri source) {
|
||||
int cut = source.getPath().lastIndexOf("/");
|
||||
String fileName = null;
|
||||
if (cut != -1) {
|
||||
fileName = source.getPath().substring(cut + 1);
|
||||
}
|
||||
return fileName;
|
||||
}
|
||||
|
||||
private File create_file_from_uri(Uri source) {
|
||||
File destination = null;
|
||||
try {
|
||||
File external = FileUtils.getExternalFilesDir();
|
||||
String fileName = get_file_name(source);
|
||||
|
||||
if (fileName != null) {
|
||||
destination = new File(external + "/" + fileName);
|
||||
}
|
||||
} catch (IOException exception) {
|
||||
LOG.error("Error creating file", exception);
|
||||
}
|
||||
return destination;
|
||||
}
|
||||
|
||||
private void save_file(Uri source, File destination) {
|
||||
try {
|
||||
String fileName = get_file_name(source);
|
||||
if (fileName != null) {
|
||||
FileUtils.copyURItoFile(GpxReceiverActivity.this, source, destination);
|
||||
}
|
||||
|
||||
} catch (IOException exception) {
|
||||
LOG.error("Error copying file", exception);
|
||||
}
|
||||
}
|
||||
|
||||
private class FileToProcess {
|
||||
String name;
|
||||
Uri source;
|
||||
File destination;
|
||||
boolean exists;
|
||||
|
||||
FileToProcess(Uri file) {
|
||||
this.name = get_file_name(file);
|
||||
this.source = file;
|
||||
this.destination = create_file_from_uri(file);
|
||||
this.exists = this.destination.exists();
|
||||
|
||||
if (this.exists) {
|
||||
toOverwrite = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
69
app/src/main/res/layout/activity_gpx_receiver.xml
Normal file
69
app/src/main/res/layout/activity_gpx_receiver.xml
Normal file
@ -0,0 +1,69 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/gpx_receiver_received_label"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/about_margin"
|
||||
android:layout_marginTop="20sp"
|
||||
android:layout_marginRight="@dimen/about_margin"
|
||||
android:layout_marginBottom="20sp"
|
||||
android:fontFamily="sans-serif-black"
|
||||
android:textSize="20sp" />
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dip"
|
||||
android:layout_marginLeft="@dimen/about_margin"
|
||||
android:layout_marginRight="@dimen/about_margin"
|
||||
android:layout_weight="1">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/gpx_receiver_files_listing"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20sp"
|
||||
android:layout_marginBottom="20sp"
|
||||
android:textSize="16sp" />
|
||||
</ScrollView>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/gpx_receiver_overwrite_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/gpx_receiver_overwrite_label"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/gpx_receiver_overwrite_some_files"
|
||||
android:textAlignment="center"
|
||||
android:textSize="20sp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/gpx_receiver_cancel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/Cancel" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/gpx_receiver_ok"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/ok" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
@ -1015,6 +1015,9 @@
|
||||
<string name="about_title">About</string>
|
||||
<string name="about_version">Version %s</string>
|
||||
<string name="about_activity_title">About Gadgetbridge</string>
|
||||
<string name="gpx_receiver_activity_title">GPX Receiver Gadgetbridge</string>
|
||||
<string name="gpx_receiver_files_received">GPX file(s) received:</string>
|
||||
<string name="gpx_receiver_overwrite_some_files">Some file(s) already exist. Overwrite?</string>
|
||||
<string name="about_description">Cloudless copylefted libre replacement for closed source Android gadget apps from vendors.</string>
|
||||
<string name="about_core_team_title">Core Team (in order of first code contribution)</string>
|
||||
<string name="about_contributors">Contributors</string>
|
||||
|
Loading…
Reference in New Issue
Block a user