diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b10ff8a8..4c2a95f7 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -73,31 +73,6 @@ - - - - - - - - - - - - + * Note that this replaces providing an activity matching the ACTION_GET_CONTENT intent: + *

+ * "A document provider and ACTION_GET_CONTENT should be considered mutually exclusive. If you + * support both of them simultaneously, your app will appear twice in the system picker UI, + * offering two different ways of accessing your stored data. This would be confusing for users." + * - http://developer.android.com/guide/topics/providers/document-provider.html#43 */ public class TermuxDocumentsProvider extends DocumentsProvider { @@ -173,7 +180,7 @@ public class TermuxDocumentsProvider extends DocumentsProvider { } /** - * Get the file given a document id (the reverse of {@link #getFileForDocId(String)}). + * Get the file given a document id (the reverse of {@link #getDocIdForFile(File)}). */ private static File getFileForDocId(String docId) throws FileNotFoundException { final File f = new File(docId); diff --git a/app/src/main/java/com/termux/filepicker/TermuxFilePickerActivity.java b/app/src/main/java/com/termux/filepicker/TermuxFilePickerActivity.java deleted file mode 100644 index 1e2cec7b..00000000 --- a/app/src/main/java/com/termux/filepicker/TermuxFilePickerActivity.java +++ /dev/null @@ -1,103 +0,0 @@ -package com.termux.filepicker; - -import android.app.Activity; -import android.app.ListActivity; -import android.content.Intent; -import android.net.Uri; -import android.os.Bundle; -import android.view.MenuItem; -import android.view.View; -import android.widget.ArrayAdapter; -import android.widget.ListView; - -import com.termux.R; -import com.termux.app.TermuxService; - -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - -/** Activity allowing picking files from the $HOME folder. */ -public class TermuxFilePickerActivity extends ListActivity { - - private File mCurrentDirectory; - private final List mFiles = new ArrayList<>(); - private final List mFileNames = new ArrayList<>(); - private ArrayAdapter mAdapter; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.file_picker); - - mAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mFileNames); - - enterDirectory(new File(TermuxService.HOME_PATH)); - setListAdapter(mAdapter); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - int id = item.getItemId(); - if (id == android.R.id.home) { - enterDirectory(mCurrentDirectory.getParentFile()); - return true; - } else { - return super.onOptionsItemSelected(item); - } - } - - @Override - protected void onListItemClick(ListView l, View v, int position, long id) { - super.onListItemClick(l, v, position, id); - File requestFile = mFiles.get(position); - if (requestFile.isDirectory()) { - enterDirectory(requestFile); - } else { - Uri returnUri = Uri.withAppendedPath(Uri.parse("content://com.termux.filepicker.provider/"), requestFile.getAbsolutePath()); - Intent returnIntent = new Intent().setData(returnUri); - returnIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - setResult(Activity.RESULT_OK, returnIntent); - finish(); - } - } - - void enterDirectory(File directory) { - getActionBar().setDisplayHomeAsUpEnabled(!directory.getAbsolutePath().equals(TermuxService.HOME_PATH)); - - String title = directory.getAbsolutePath() + "/"; - if (title.startsWith(TermuxService.HOME_PATH)) { - title = "~" + title.substring(TermuxService.HOME_PATH.length(), title.length()); - } - setTitle(title); - - mCurrentDirectory = directory; - mFiles.clear(); - mFileNames.clear(); - mFiles.addAll(Arrays.asList(mCurrentDirectory.listFiles())); - - Collections.sort(mFiles, new Comparator() { - @Override - public int compare(File f1, File f2) { - final String n1 = f1.getName(); - final String n2 = f2.getName(); - // Display dot folders last: - if (n1.startsWith(".") && !n2.startsWith(".")) { - return 1; - } else if (n2.startsWith(".") && !n1.startsWith(".")) { - return -1; - } - return n1.compareToIgnoreCase(n2); - } - }); - - for (File file : mFiles) { - mFileNames.add(file.getName() + (file.isDirectory() ? "/" : "")); - } - mAdapter.notifyDataSetChanged(); - } - -} diff --git a/app/src/main/java/com/termux/filepicker/TermuxFilePickerProvider.java b/app/src/main/java/com/termux/filepicker/TermuxFilePickerProvider.java deleted file mode 100644 index a59a2b66..00000000 --- a/app/src/main/java/com/termux/filepicker/TermuxFilePickerProvider.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.termux.filepicker; - - -import android.content.ContentProvider; -import android.content.ContentValues; -import android.database.Cursor; -import android.net.Uri; -import android.os.ParcelFileDescriptor; -import android.support.annotation.NonNull; -import android.webkit.MimeTypeMap; - -import java.io.File; -import java.io.FileNotFoundException; - -/** Provider of files content uris picked from {@link com.termux.filepicker.TermuxFilePickerActivity}. */ -public class TermuxFilePickerProvider extends ContentProvider { - @Override - public boolean onCreate() { - return true; - } - - @Override - public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { - return null; - } - - @Override - public String getType(@NonNull Uri uri) { - String contentType = null; - String path = uri.getPath(); - int lastDotIndex = path.lastIndexOf('.'); - String possibleFileExtension = path.substring(lastDotIndex + 1, path.length()); - if (possibleFileExtension.contains("/")) { - // The dot was in the path, so not a file extension. - } else { - MimeTypeMap mimeTypes = MimeTypeMap.getSingleton(); - // Lower casing makes it work with e.g. "JPG": - contentType = mimeTypes.getMimeTypeFromExtension(possibleFileExtension.toLowerCase()); - } - - if (contentType == null) contentType = "application/octet-stream"; - return contentType; - } - - @Override - public Uri insert(@NonNull Uri uri, ContentValues values) { - return null; - } - - @Override - public int delete(@NonNull Uri uri, String selection, String[] selectionArgs) { - return 0; - } - - @Override - public int update(@NonNull Uri uri, ContentValues values, String selection, String[] selectionArgs) { - return 0; - } - - @Override - public ParcelFileDescriptor openFile(@NonNull Uri uri, @NonNull String mode) throws FileNotFoundException { - File file = new File(uri.getPath()); - return ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY); - } -} diff --git a/app/src/main/res/layout/file_picker.xml b/app/src/main/res/layout/file_picker.xml deleted file mode 100644 index 6d84cde5..00000000 --- a/app/src/main/res/layout/file_picker.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 52121b32..f6268513 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -53,8 +53,6 @@ Wake Wifi - Empty folder. - Save file in ~/downloads/ Edit Open folder