From f5bb381dff3e015577a658a370118e9d0da604bf Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Fri, 23 May 2014 12:47:36 +0200 Subject: [PATCH] Added (preferred) support for file managers that support file picking vai the GET_CONTENT action adn file/* mime type. --- .../core/gui/search/FilePickerHelper.java | 42 +++++++++++-------- .../core/gui/search/SearchActivity.java | 1 + 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/core/src/org/transdroid/core/gui/search/FilePickerHelper.java b/core/src/org/transdroid/core/gui/search/FilePickerHelper.java index 8d15e397..5ace06d4 100644 --- a/core/src/org/transdroid/core/gui/search/FilePickerHelper.java +++ b/core/src/org/transdroid/core/gui/search/FilePickerHelper.java @@ -42,23 +42,31 @@ public class FilePickerHelper { @SuppressLint("ValidFragment") public static void startFilePicker(final SherlockFragmentActivity activity) { try { - // Start a file manager that can handle the PICK_FILE intent (specifically IO File Manager) - activity.startActivityForResult(new Intent("org.openintents.action.PICK_FILE"), ACTIVITY_FILEPICKER); - } catch (Exception e) { - // Can't start the file manager, for example with a SecurityException or when IO File Manager is not present - new DialogFragment() { - public android.app.Dialog onCreateDialog(android.os.Bundle savedInstanceState) { - return new AlertDialog.Builder(activity).setIcon(android.R.drawable.ic_dialog_alert) - .setMessage(activity.getString(R.string.search_filemanagernotfound)) - .setPositiveButton(android.R.string.yes, new OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - if (activity != null) - activity.startActivity(new Intent(Intent.ACTION_VIEW, FILEMANAGER_MARKET_URI)); - } - }).setNegativeButton(android.R.string.no, null).create(); - }; - }.show(activity.getSupportFragmentManager(), "installfilemanager"); + // Start a file manager that can handle the file/* file/* intents + activity.startActivityForResult(new Intent(Intent.ACTION_GET_CONTENT).setType("file/*"), + ACTIVITY_FILEPICKER); + } catch (Exception e1) { + try { + // Start a file manager that can handle the PICK_FILE intent (specifically IO File Manager) + activity.startActivityForResult(new Intent("org.openintents.action.PICK_FILE"), ACTIVITY_FILEPICKER); + } catch (Exception e2) { + // Can't start the file manager, for example with a SecurityException or when IO File Manager is not + // present + new DialogFragment() { + public android.app.Dialog onCreateDialog(android.os.Bundle savedInstanceState) { + return new AlertDialog.Builder(activity).setIcon(android.R.drawable.ic_dialog_alert) + .setMessage(activity.getString(R.string.search_filemanagernotfound)) + .setPositiveButton(android.R.string.yes, new OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + if (activity != null) + activity.startActivity(new Intent(Intent.ACTION_VIEW, + FILEMANAGER_MARKET_URI)); + } + }).setNegativeButton(android.R.string.no, null).create(); + }; + }.show(activity.getSupportFragmentManager(), "installfilemanager"); + } } } diff --git a/core/src/org/transdroid/core/gui/search/SearchActivity.java b/core/src/org/transdroid/core/gui/search/SearchActivity.java index 163168d1..8e458eed 100644 --- a/core/src/org/transdroid/core/gui/search/SearchActivity.java +++ b/core/src/org/transdroid/core/gui/search/SearchActivity.java @@ -242,6 +242,7 @@ public class SearchActivity extends SherlockFragmentActivity implements OnNaviga } else if (intent.getAction().equals(Intent.ACTION_SEND)) { query = SendIntentHelper.cleanUpText(intent); } + query = query.trim(); if (query != null && query.length() > 0) { // Remember this search query to later show as a suggestion