forked from upstream-mirrors/OpenTracks
Import: individual files chosen by an external app.
This commit is contained in:
@@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
package="de.dennisguse.opentracks"
|
package="de.dennisguse.opentracks"
|
||||||
android:installLocation="auto">
|
android:installLocation="auto">
|
||||||
|
|
||||||
@@ -24,6 +25,28 @@ limitations under the License.
|
|||||||
android:smallScreens="true"
|
android:smallScreens="true"
|
||||||
android:xlargeScreens="true" />
|
android:xlargeScreens="true" />
|
||||||
|
|
||||||
|
<uses-feature
|
||||||
|
android:name="android.hardware.location.gps"
|
||||||
|
android:required="true" />
|
||||||
|
<uses-feature
|
||||||
|
android:name="android.hardware.android.hardware.bluetooth_le"
|
||||||
|
android:required="false" />
|
||||||
|
<uses-feature
|
||||||
|
android:name="android.hardware.camera"
|
||||||
|
android:required="false" />
|
||||||
|
<uses-feature
|
||||||
|
android:name="android.hardware.sensor.compass"
|
||||||
|
android:required="false" />
|
||||||
|
<uses-feature
|
||||||
|
android:name="android.hardware.touchscreen"
|
||||||
|
android:required="false" />
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||||
|
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||||
|
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||||
|
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:name=".Startup"
|
android:name=".Startup"
|
||||||
android:allowBackup="false"
|
android:allowBackup="false"
|
||||||
@@ -33,7 +56,6 @@ limitations under the License.
|
|||||||
android:label="${applicationName}"
|
android:label="${applicationName}"
|
||||||
android:theme="@style/ThemeCustom">
|
android:theme="@style/ThemeCustom">
|
||||||
|
|
||||||
<!-- Activities -->
|
|
||||||
<activity android:name=".AboutActivity" />
|
<activity android:name=".AboutActivity" />
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
@@ -49,18 +71,41 @@ limitations under the License.
|
|||||||
<activity
|
<activity
|
||||||
android:name=".io.file.importer.ImportActivity"
|
android:name=".io.file.importer.ImportActivity"
|
||||||
android:theme="@style/ThemeCustomTransparentActivity">
|
android:theme="@style/ThemeCustomTransparentActivity">
|
||||||
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.ATTACH_DATA" />
|
|
||||||
<action android:name="android.intent.action.VIEW" />
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
|
||||||
<category android:name="android.intent.category.BROWSABLE" />
|
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<data
|
||||||
|
android:host="*"
|
||||||
|
android:mimeType="application/vnd.google-earth.kmz" />
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
<data android:mimeType="application/gpx" />
|
<intent-filter>
|
||||||
<data android:mimeType="application/gpx+xml" />
|
<action android:name="android.intent.action.VIEW" />
|
||||||
<data android:mimeType="application/vnd.google-earth.gpx" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
<data android:mimeType="application/vnd.google-earth.gpx+xml" />
|
<data
|
||||||
<data android:scheme="file" />
|
android:host="*"
|
||||||
|
android:mimeType="application/vnd.google-earth.kml+xml" />
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<data
|
||||||
|
android:host="*"
|
||||||
|
android:mimeType="*/*"
|
||||||
|
android:pathPattern=".*\\.kmz"
|
||||||
|
android:scheme="file" />
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<data
|
||||||
|
android:host="*"
|
||||||
|
android:mimeType="*/*"
|
||||||
|
android:pathPattern=".*\\.kml"
|
||||||
|
android:scheme="file" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
@@ -150,27 +195,4 @@ limitations under the License.
|
|||||||
android:icon="@drawable/ic_logo_color_24dp"
|
android:icon="@drawable/ic_logo_color_24dp"
|
||||||
android:label="@string/recording_service" />
|
android:label="@string/recording_service" />
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
<!-- Permissions to record locations -->
|
|
||||||
<uses-feature
|
|
||||||
android:name="android.hardware.location.gps"
|
|
||||||
android:required="true" />
|
|
||||||
<uses-feature
|
|
||||||
android:name="android.hardware.android.hardware.bluetooth_le"
|
|
||||||
android:required="false" />
|
|
||||||
<uses-feature
|
|
||||||
android:name="android.hardware.camera"
|
|
||||||
android:required="false" />
|
|
||||||
<uses-feature
|
|
||||||
android:name="android.hardware.sensor.compass"
|
|
||||||
android:required="false" />
|
|
||||||
<uses-feature
|
|
||||||
android:name="android.hardware.touchscreen"
|
|
||||||
android:required="false" />
|
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
|
||||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
|
||||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
|
||||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
|
||||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|||||||
@@ -44,7 +44,9 @@ import de.dennisguse.opentracks.util.FileUtils;
|
|||||||
|
|
||||||
public class ImportProgressDialogFragment extends DialogFragment {
|
public class ImportProgressDialogFragment extends DialogFragment {
|
||||||
|
|
||||||
private static final String EXTRA_DIRECTORY_URI_KEY = "directory_uri";
|
private static final String EXTRA_IS_TREE_KEY = "tree_uri";
|
||||||
|
|
||||||
|
private static final String EXTRA_DATA_URI_KEY = "data_uri";
|
||||||
|
|
||||||
private static final String TAG = ImportProgressDialogFragment.class.getSimpleName();
|
private static final String TAG = ImportProgressDialogFragment.class.getSimpleName();
|
||||||
|
|
||||||
@@ -59,12 +61,10 @@ public class ImportProgressDialogFragment extends DialogFragment {
|
|||||||
private int trackImportSuccessCount;
|
private int trackImportSuccessCount;
|
||||||
private int fileCount;
|
private int fileCount;
|
||||||
|
|
||||||
/**
|
public static void showDialog(FragmentManager fragmentManager, Uri documentFileUri, boolean isDirectory) {
|
||||||
* Create a new instance.
|
|
||||||
*/
|
|
||||||
public static void showDialog(FragmentManager fragmentManager, Uri documentFileUri) {
|
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putParcelable(EXTRA_DIRECTORY_URI_KEY, documentFileUri);
|
bundle.putParcelable(EXTRA_DATA_URI_KEY, documentFileUri);
|
||||||
|
bundle.putBoolean(EXTRA_IS_TREE_KEY, isDirectory);
|
||||||
|
|
||||||
ImportProgressDialogFragment dialogFragment = new ImportProgressDialogFragment();
|
ImportProgressDialogFragment dialogFragment = new ImportProgressDialogFragment();
|
||||||
dialogFragment.setArguments(bundle);
|
dialogFragment.setArguments(bundle);
|
||||||
@@ -79,9 +79,13 @@ public class ImportProgressDialogFragment extends DialogFragment {
|
|||||||
// This fragment uses a background thread, so it should not be recreated during activity re-creation.
|
// This fragment uses a background thread, so it should not be recreated during activity re-creation.
|
||||||
setRetainInstance(true);
|
setRetainInstance(true);
|
||||||
|
|
||||||
Uri directoryUri = getArguments().getParcelable(EXTRA_DIRECTORY_URI_KEY);
|
Uri directoryUri = getArguments().getParcelable(EXTRA_DATA_URI_KEY);
|
||||||
DocumentFile documentFile = DocumentFile.fromTreeUri(getContext(), directoryUri);
|
DocumentFile documentFile;
|
||||||
|
if (getArguments().getBoolean(EXTRA_IS_TREE_KEY)) {
|
||||||
|
documentFile = DocumentFile.fromTreeUri(getContext(), directoryUri);
|
||||||
|
} else {
|
||||||
|
documentFile = DocumentFile.fromSingleUri(getContext(), directoryUri);
|
||||||
|
}
|
||||||
directoryDisplayName = FileUtils.getPath(documentFile);
|
directoryDisplayName = FileUtils.getPath(documentFile);
|
||||||
|
|
||||||
importThread = new ImportThread(documentFile);
|
importThread = new ImportThread(documentFile);
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ public abstract class DirectoryChooserActivity extends AppCompatActivity {
|
|||||||
if (resultCode == Activity.RESULT_OK) {
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
Uri directoryUri = resultData.getData();
|
Uri directoryUri = resultData.getData();
|
||||||
|
|
||||||
|
|
||||||
startActivity(createIntent(directoryUri));
|
startActivity(createIntent(directoryUri));
|
||||||
}
|
}
|
||||||
finish();
|
finish();
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package de.dennisguse.opentracks.io.file.importer;
|
package de.dennisguse.opentracks.io.file.importer;
|
||||||
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@@ -43,8 +42,12 @@ public class ImportActivity extends FragmentActivity implements ImportProgressDi
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
if (savedInstanceState == null || !savedInstanceState.getBoolean(BUNDLE_ACTIVITY_RECREATED, false)) {
|
if (savedInstanceState == null || !savedInstanceState.getBoolean(BUNDLE_ACTIVITY_RECREATED, false)) {
|
||||||
Uri directoryUri = getIntent().getParcelableExtra(EXTRA_DIRECTORY_URI_KEY);
|
if (getIntent().getData() != null) {
|
||||||
ImportProgressDialogFragment.showDialog(getSupportFragmentManager(), directoryUri);
|
ImportProgressDialogFragment.showDialog(getSupportFragmentManager(), getIntent().getData(), false);
|
||||||
|
} else {
|
||||||
|
// Started from DirectoryChooserActivity
|
||||||
|
ImportProgressDialogFragment.showDialog(getSupportFragmentManager(), getIntent().getParcelableExtra(EXTRA_DIRECTORY_URI_KEY), true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -309,7 +309,10 @@ public class FileUtils {
|
|||||||
public static ArrayList<DocumentFile> getFiles(DocumentFile file) {
|
public static ArrayList<DocumentFile> getFiles(DocumentFile file) {
|
||||||
ArrayList<DocumentFile> files = new ArrayList<>();
|
ArrayList<DocumentFile> files = new ArrayList<>();
|
||||||
|
|
||||||
if (!file.isDirectory()) return files;
|
if (!file.isDirectory()) {
|
||||||
|
files.add(file);
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
for (DocumentFile candidate : file.listFiles()) {
|
for (DocumentFile candidate : file.listFiles()) {
|
||||||
if (!candidate.isDirectory()) {
|
if (!candidate.isDirectory()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user