diff options
author | jruesga <jorge@ruesga.com> | 2012-10-06 18:16:14 +0200 |
---|---|---|
committer | jruesga <jorge@ruesga.com> | 2012-10-06 18:16:14 +0200 |
commit | 78a56ac66696f399026166dcb893b3352c19cb0b (patch) | |
tree | 1ee1d2d6141d2f3169d3629cee91ef3b201185fc /src/com/cyanogenmod/explorer/ui | |
parent | 0b1564bd02bd5a60d6ee1e353a43ade4a602d3d8 (diff) | |
download | android_packages_apps_CMFileManager-78a56ac66696f399026166dcb893b3352c19cb0b.tar.gz android_packages_apps_CMFileManager-78a56ac66696f399026166dcb893b3352c19cb0b.tar.bz2 android_packages_apps_CMFileManager-78a56ac66696f399026166dcb893b3352c19cb0b.zip |
A bunch of changes.
* Add send action for file
* Add handler for open action on click in navigation, search and
bookmarks
* Allow file bookmarks
* Upload AssociationsDialog
* Fix root directory name in history
* Add controls to navigation and history for deleted folders
* Remove history of delete folders
* Add open with action for onLongClickListener handler
Diffstat (limited to 'src/com/cyanogenmod/explorer/ui')
5 files changed, 150 insertions, 50 deletions
diff --git a/src/com/cyanogenmod/explorer/ui/dialogs/ActionsDialog.java b/src/com/cyanogenmod/explorer/ui/dialogs/ActionsDialog.java index f3e3b065..53b3379d 100644 --- a/src/com/cyanogenmod/explorer/ui/dialogs/ActionsDialog.java +++ b/src/com/cyanogenmod/explorer/ui/dialogs/ActionsDialog.java @@ -197,6 +197,10 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen case R.id.mnu_actions_open_with: ActionsPolicy.openFileSystemObject(this.mContext, this.mFso, true); break; + //- Send + case R.id.mnu_actions_send: + ActionsPolicy.sendFileSystemObject(this.mContext, this.mFso); + break; //- Add to bookmarks case R.id.mnu_actions_add_to_bookmarks: @@ -316,15 +320,16 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen menu.removeItem(R.id.mnu_actions_deselect); } - //- Open/Open with -> Only when the fso is not a folder or is not a system file + //- Open/Open with -> Only when the fso is not a folder and is not a system file if (FileHelper.isDirectory(this.mFso) || FileHelper.isSystemFile(this.mFso)) { menu.removeItem(R.id.mnu_actions_open); menu.removeItem(R.id.mnu_actions_open_with); + menu.removeItem(R.id.mnu_actions_send); } } //- Add to bookmarks -> Only directories - if (this.mFso != null && !FileHelper.isDirectory(this.mFso)) { + if (this.mFso != null && FileHelper.isRootDirectory(this.mFso)) { menu.removeItem(R.id.mnu_actions_add_to_bookmarks); menu.removeItem(R.id.mnu_actions_add_to_bookmarks_current_folder); } diff --git a/src/com/cyanogenmod/explorer/ui/dialogs/AssociationsDialog.java b/src/com/cyanogenmod/explorer/ui/dialogs/AssociationsDialog.java index ced108f3..d586b200 100644 --- a/src/com/cyanogenmod/explorer/ui/dialogs/AssociationsDialog.java +++ b/src/com/cyanogenmod/explorer/ui/dialogs/AssociationsDialog.java @@ -57,9 +57,10 @@ public class AssociationsDialog implements OnItemClickListener { private static final String TAG = "AssociationsDialog"; //$NON-NLS-1$ - final Context mContext; + private final Context mContext; private final List<ResolveInfo> mIntents; private final ResolveInfo mPreferred; + private final boolean mAllowPreferred; /** * @hide */ @@ -87,10 +88,12 @@ public class AssociationsDialog implements OnItemClickListener { * @param requestIntent The original request * @param intents The list of available intents that can handle an action * @param preferred The preferred intent. null if no preferred exists + * @param allowPreferred If allow the user to mark the selected app as preferred */ public AssociationsDialog( Context context, int icon, String title, String action, - Intent requestIntent, List<ResolveInfo> intents, ResolveInfo preferred) { + Intent requestIntent, List<ResolveInfo> intents, ResolveInfo preferred, + boolean allowPreferred) { super(); //Save the data @@ -98,6 +101,7 @@ public class AssociationsDialog implements OnItemClickListener { this.mRequestIntent = requestIntent; this.mIntents = intents; this.mPreferred = preferred; + this.mAllowPreferred = allowPreferred; this.mLoaded = false; //Initialize dialog @@ -121,7 +125,8 @@ public class AssociationsDialog implements OnItemClickListener { (LayoutInflater)this.mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = li.inflate(R.layout.associations_dialog, null, false); this.mRemember = (CheckBox)v.findViewById(R.id.associations_remember); - this.mRemember.setVisibility(isPlatformSigned ? View.VISIBLE : View.GONE); + this.mRemember.setVisibility( + isPlatformSigned && this.mAllowPreferred ? View.VISIBLE : View.GONE); this.mGrid = (GridView)v.findViewById(R.id.associations_gridview); this.mGrid.setAdapter(new AssociationsAdapter(this.mContext, this.mIntents, this)); @@ -388,7 +393,7 @@ public class AssociationsDialog implements OnItemClickListener { // intent boolean isPlatformSigned = ExplorerApplication.isAppPlatformSignature(this.mContext); - if (isPlatformSigned) { + if (isPlatformSigned && this.mAllowPreferred) { if (filter != null && !isPreferredSelected()) { try { AssociationsAdapter adapter = (AssociationsAdapter)this.mGrid.getAdapter(); diff --git a/src/com/cyanogenmod/explorer/ui/dialogs/FsoPropertiesDialog.java b/src/com/cyanogenmod/explorer/ui/dialogs/FsoPropertiesDialog.java index 9fb83657..11694aef 100644 --- a/src/com/cyanogenmod/explorer/ui/dialogs/FsoPropertiesDialog.java +++ b/src/com/cyanogenmod/explorer/ui/dialogs/FsoPropertiesDialog.java @@ -905,7 +905,7 @@ public class FsoPropertiesDialog FsoPropertiesDialog.this.mFolderUsage = (FolderUsage)(((FolderUsage)partialResults).clone()); printFolderUsage(true, false); - }catch (Exception ex) {/** NON BLOCK**/} + } catch (Exception ex) {/** NON BLOCK**/} } /** diff --git a/src/com/cyanogenmod/explorer/ui/policy/ActionsPolicy.java b/src/com/cyanogenmod/explorer/ui/policy/ActionsPolicy.java index a46cf469..dc730429 100644 --- a/src/com/cyanogenmod/explorer/ui/policy/ActionsPolicy.java +++ b/src/com/cyanogenmod/explorer/ui/policy/ActionsPolicy.java @@ -130,8 +130,8 @@ public final class ActionsPolicy { } /** - * Method that opens a {@link FileSystemObject} with the default application registered - * by the system. + * Method that opens a {@link FileSystemObject} with the default registered application + * by the system, or ask the user for select a registered application. * * @param ctx The current context * @param fso The file system object @@ -153,48 +153,48 @@ public final class ActionsPolicy { intent.setData(Uri.fromFile(file)); } - //Retrieve the activities that can handle the file - final PackageManager packageManager = ctx.getPackageManager(); - if (DEBUG) { - intent.addFlags(Intent.FLAG_DEBUG_LOG_RESOLUTION); - } - List<ResolveInfo> info = - packageManager. - queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); - - // Retrieve the preferred activity that can handle the file - final ResolveInfo mPreferredInfo = packageManager.resolveActivity(intent, 0); - - // Now we have the list of activities that can handle the file. The next steps are: - // - // 1.- If choose, then show open with dialog - // 2.- If info size == 0. No default application, then show open with dialog - // 3.- If !choose, seek inside our database the default activity for the extension - // and open the file with this application - // 4.- If no default activity saved, then use system default - - // No registered application - if (info.size() == 0) { - DialogHelper.createWarningDialog(ctx, R.string.msgs_not_registered_app); - } + // Resolve the intent + resolveIntent( + ctx, + intent, + choose, + R.drawable.ic_holo_light_open, + R.string.associations_dialog_openwith_title, + R.string.associations_dialog_openwith_action, + true); - // Is a simple open and we have an application that can handle the file? - if (!choose && (mPreferredInfo.match != 0 || info.size() == 1)) { - ctx.startActivity(intent); - return; - } + } catch (Exception e) { + ExceptionUtil.translateException(ctx, e); + } + } - // Otherwise, we have to show the open with dialog - AssociationsDialog dialog = - new AssociationsDialog( - ctx, - R.drawable.ic_holo_light_open, - ctx.getString(R.string.associations_dialog_openwith_title), - ctx.getString(R.string.associations_dialog_openwith_action), - intent, - info, - mPreferredInfo); - dialog.show(); + /** + * Method that sends a {@link FileSystemObject} with the default registered application + * by the system, or ask the user for select a registered application. + * + * @param ctx The current context + * @param fso The file system object + */ + public static void sendFileSystemObject( + final Context ctx, final FileSystemObject fso) { + try { + // Create the intent to + Intent intent = new Intent(); + intent.setAction(android.content.Intent.ACTION_SEND); + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + intent.setType(MimeTypeHelper.getMimeType(ctx, fso)); + Uri uri = Uri.fromFile(new File(fso.getFullPath())); + intent.putExtra(Intent.EXTRA_STREAM, uri); + + // Resolve the intent + resolveIntent( + ctx, + intent, + false, + R.drawable.ic_holo_light_send, + R.string.associations_dialog_sendwith_title, + R.string.associations_dialog_sendwith_action, + false); } catch (Exception e) { ExceptionUtil.translateException(ctx, e); @@ -202,6 +202,68 @@ public final class ActionsPolicy { } /** + * Method that resolve + * + * @param ctx The current context + * @param intent The intent to resolve + * @param choose If allow the user to select the application to select the registered + * application. If no preferred app or more than one exists the dialog is shown. + * @param icon The icon of the dialog + * @param title The title of the dialog + * @param action The button title of the dialog + * @param allowPreferred If allow the user to mark the selected app as preferred + */ + private static void resolveIntent( + Context ctx, Intent intent, boolean choose, + int icon, int title, int action, boolean allowPreferred) { + //Retrieve the activities that can handle the file + final PackageManager packageManager = ctx.getPackageManager(); + if (DEBUG) { + intent.addFlags(Intent.FLAG_DEBUG_LOG_RESOLUTION); + } + List<ResolveInfo> info = + packageManager. + queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); + + // Retrieve the preferred activity that can handle the file + final ResolveInfo mPreferredInfo = packageManager.resolveActivity(intent, 0); + + // Now we have the list of activities that can handle the file. The next steps are: + // + // 1.- If choose, then show open with dialog + // 2.- If info size == 0. No default application, then show open with dialog + // 3.- If !choose, seek inside our database the default activity for the extension + // and open the file with this application + // 4.- If no default activity saved, then use system default + + // No registered application + if (info.size() == 0) { + Toast.makeText(ctx, R.string.msgs_not_registered_app, Toast.LENGTH_SHORT).show(); + return; + } + + // Is a simple open and we have an application that can handle the file? + if (!choose && + ((mPreferredInfo != null && mPreferredInfo.match != 0) || info.size() == 1)) { + ctx.startActivity(intent); + return; + } + + // Otherwise, we have to show the open with dialog + AssociationsDialog dialog = + new AssociationsDialog( + ctx, + icon, + ctx.getString(title), + ctx.getString(action), + intent, + info, + mPreferredInfo, + allowPreferred); + dialog.show(); + } + + /** * Method that adds the {@link FileSystemObject} to the bookmarks database. * * @param ctx The current context diff --git a/src/com/cyanogenmod/explorer/ui/widgets/NavigationView.java b/src/com/cyanogenmod/explorer/ui/widgets/NavigationView.java index 755a505d..040a5d4e 100644 --- a/src/com/cyanogenmod/explorer/ui/widgets/NavigationView.java +++ b/src/com/cyanogenmod/explorer/ui/widgets/NavigationView.java @@ -728,7 +728,7 @@ public class NavigationView extends RelativeLayout implements // Open with else if (this.mDefaultLongClickAction.compareTo( DefaultLongClickAction.OPEN_WITH) == 0) { - // FIXME Invoke ActionPolicy open with + ActionsPolicy.openFileSystemObject(getContext(), fso, true); } // Show properties @@ -745,6 +745,31 @@ public class NavigationView extends RelativeLayout implements return true; //Always consume the event } + + /** + * Method that opens or navigates to the {@link FileSystemObject} + * + * @param fso The file system object + */ + public void open(FileSystemObject fso) { + open(fso, null); + } + + /** + * Method that opens or navigates to the {@link FileSystemObject} + * + * @param fso The file system object + * @param searchInfo The search info + */ + public void open(FileSystemObject fso, SearchInfoParcelable searchInfo) { + // If is a folder, then navigate to + if (FileHelper.isDirectory(fso)) { + changeCurrentDir(fso.getFullPath(), searchInfo); + } else { + // Open the file with the preferred registered app + ActionsPolicy.openFileSystemObject(getContext(), fso, false); + } + } /** * {@inheritDoc} @@ -763,6 +788,9 @@ public class NavigationView extends RelativeLayout implements changeCurrentDir( symlink.getLinkRef().getFullPath(), true, false, false, null, null); } + } else { + // Open the file with the preferred registered app + ActionsPolicy.openFileSystemObject(getContext(), fso, false); } } catch (Throwable ex) { ExceptionUtil.translateException(getContext(), ex); |