Import: individual files chosen by an external app.

This commit is contained in:
Dennis Guse
2020-07-17 18:43:18 +02:00
parent 5f637952aa
commit bf9b6d6627
5 changed files with 77 additions and 46 deletions
+54 -32
View File
@@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="de.dennisguse.opentracks"
android:installLocation="auto">
@@ -24,6 +25,28 @@ limitations under the License.
android:smallScreens="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
android:name=".Startup"
android:allowBackup="false"
@@ -33,7 +56,6 @@ limitations under the License.
android:label="${applicationName}"
android:theme="@style/ThemeCustom">
<!-- Activities -->
<activity android:name=".AboutActivity" />
<activity
@@ -49,18 +71,41 @@ limitations under the License.
<activity
android:name=".io.file.importer.ImportActivity"
android:theme="@style/ThemeCustomTransparentActivity">
<intent-filter>
<action android:name="android.intent.action.ATTACH_DATA" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="*"
android:mimeType="application/vnd.google-earth.kmz" />
</intent-filter>
<data android:mimeType="application/gpx" />
<data android:mimeType="application/gpx+xml" />
<data android:mimeType="application/vnd.google-earth.gpx" />
<data android:mimeType="application/vnd.google-earth.gpx+xml" />
<data android:scheme="file" />
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data
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>
</activity>
@@ -150,27 +195,4 @@ limitations under the License.
android:icon="@drawable/ic_logo_color_24dp"
android:label="@string/recording_service" />
</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>
@@ -44,7 +44,9 @@ import de.dennisguse.opentracks.util.FileUtils;
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();
@@ -59,12 +61,10 @@ public class ImportProgressDialogFragment extends DialogFragment {
private int trackImportSuccessCount;
private int fileCount;
/**
* Create a new instance.
*/
public static void showDialog(FragmentManager fragmentManager, Uri documentFileUri) {
public static void showDialog(FragmentManager fragmentManager, Uri documentFileUri, boolean isDirectory) {
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();
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.
setRetainInstance(true);
Uri directoryUri = getArguments().getParcelable(EXTRA_DIRECTORY_URI_KEY);
DocumentFile documentFile = DocumentFile.fromTreeUri(getContext(), directoryUri);
Uri directoryUri = getArguments().getParcelable(EXTRA_DATA_URI_KEY);
DocumentFile documentFile;
if (getArguments().getBoolean(EXTRA_IS_TREE_KEY)) {
documentFile = DocumentFile.fromTreeUri(getContext(), directoryUri);
} else {
documentFile = DocumentFile.fromSingleUri(getContext(), directoryUri);
}
directoryDisplayName = FileUtils.getPath(documentFile);
importThread = new ImportThread(documentFile);
@@ -33,7 +33,6 @@ public abstract class DirectoryChooserActivity extends AppCompatActivity {
if (resultCode == Activity.RESULT_OK) {
Uri directoryUri = resultData.getData();
startActivity(createIntent(directoryUri));
}
finish();
@@ -16,7 +16,6 @@
package de.dennisguse.opentracks.io.file.importer;
import android.net.Uri;
import android.os.Bundle;
import androidx.annotation.NonNull;
@@ -43,8 +42,12 @@ public class ImportActivity extends FragmentActivity implements ImportProgressDi
super.onCreate(savedInstanceState);
if (savedInstanceState == null || !savedInstanceState.getBoolean(BUNDLE_ACTIVITY_RECREATED, false)) {
Uri directoryUri = getIntent().getParcelableExtra(EXTRA_DIRECTORY_URI_KEY);
ImportProgressDialogFragment.showDialog(getSupportFragmentManager(), directoryUri);
if (getIntent().getData() != null) {
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) {
ArrayList<DocumentFile> files = new ArrayList<>();
if (!file.isDirectory()) return files;
if (!file.isDirectory()) {
files.add(file);
return files;
}
for (DocumentFile candidate : file.listFiles()) {
if (!candidate.isDirectory()) {