From 42e15a19aad7a5856f7d66cb59cfd6c9b4efd377 Mon Sep 17 00:00:00 2001 From: dgis Date: Sat, 9 Feb 2019 23:19:17 +0000 Subject: [PATCH] --- .../emulator/forty/eight/MainActivity.java | 47 ++++++++++--------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/org/emulator/forty/eight/MainActivity.java b/app/src/main/java/org/emulator/forty/eight/MainActivity.java index 43a2cd5..6fcacdc 100644 --- a/app/src/main/java/org/emulator/forty/eight/MainActivity.java +++ b/app/src/main/java/org/emulator/forty/eight/MainActivity.java @@ -508,29 +508,33 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On } } else { Uri kmlFolderUri = Uri.parse(kmlFolderURL); - //DocumentFile.fromTreeUri(this, kmlFolderUri); - - //Uri docUri = DocumentsContract.buildDocumentUriUsingTree(kmlFolderUri, DocumentsContract.getTreeDocumentId(kmlFolderUri)); - Uri childrenUri = DocumentsContract.buildChildDocumentsUriUsingTree(kmlFolderUri, DocumentsContract.getTreeDocumentId(kmlFolderUri)); - - //String[] calculatorsAssetFilenames = new String[0]; - List calculatorsAssetFilenames = new LinkedList<>(); - Cursor cursor = getContentResolver().query(childrenUri, new String[]{DocumentsContract.Document.COLUMN_DOCUMENT_ID, DocumentsContract.Document.COLUMN_DISPLAY_NAME, DocumentsContract.Document.COLUMN_MIME_TYPE}, null, null, null); - try { - while (cursor.moveToNext()) { - final String docId = cursor.getString(0); - final String name = cursor.getString(1); - final String mime = cursor.getString(2); - Log.d(TAG, "docId: " + docId + ", name: " + name + ", mime: " + mime); - if(kmlMimeType.equals(mime)) { - calculatorsAssetFilenames.add(docId); - } - } - } finally { - cursor.close(); - } +// Uri childrenUri = DocumentsContract.buildChildDocumentsUriUsingTree(kmlFolderUri, DocumentsContract.getTreeDocumentId(kmlFolderUri)); +// Cursor cursor = getContentResolver().query(childrenUri, new String[]{DocumentsContract.Document.COLUMN_DOCUMENT_ID, DocumentsContract.Document.COLUMN_DISPLAY_NAME, DocumentsContract.Document.COLUMN_MIME_TYPE}, null, null, null); +// try { +// while (cursor.moveToNext()) { +// final String url = cursor.getString(0); +// final String name = cursor.getString(1); +// final String mime = cursor.getString(2); +// Log.d(TAG, "url: " + url + ", name: " + name + ", mime: " + mime); +// if(kmlMimeType.equals(mime)) { +// calculatorsAssetFilenames.add(url); +// } +// } +// } finally { +// cursor.close(); +// } + DocumentFile kmlFolderDocumentFile = DocumentFile.fromTreeUri(this, kmlFolderUri); + for (DocumentFile file : kmlFolderDocumentFile.listFiles()) { + final String url = file.getUri().toString(); + final String name = file.getName(); + final String mime = file.getType(); + Log.d(TAG, "url: " + url + ", name: " + name + ", mime: " + mime); + if(kmlMimeType.equals(mime)) { + calculatorsAssetFilenames.add(url); + } + } String cKmlType = null; //"S"; kmlScripts.clear(); Pattern patternGlobalTitle = Pattern.compile("\\s*Title\\s+\"(.*)\""); @@ -542,6 +546,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On try { Uri calculatorsAssetFilenameUri = Uri.parse(calculatorsAssetFilename); DocumentFile documentFile = DocumentFile.fromSingleUri(this, calculatorsAssetFilenameUri); + Uri documentFileUri = documentFile.getUri(); InputStream inputStream = getContentResolver().openInputStream(documentFile.getUri()); reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8")); // do reading, usually loop until end of file reading