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 | |
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
20 files changed, 318 insertions, 117 deletions
diff --git a/res/drawable-hdpi/ic_holo_light_send.png b/res/drawable-hdpi/ic_holo_light_send.png Binary files differnew file mode 100644 index 00000000..47ae1867 --- /dev/null +++ b/res/drawable-hdpi/ic_holo_light_send.png diff --git a/res/drawable-mdpi/ic_holo_light_send.png b/res/drawable-mdpi/ic_holo_light_send.png Binary files differnew file mode 100644 index 00000000..8aa52bc7 --- /dev/null +++ b/res/drawable-mdpi/ic_holo_light_send.png diff --git a/res/drawable-xhdpi/ic_holo_light_send.png b/res/drawable-xhdpi/ic_holo_light_send.png Binary files differnew file mode 100644 index 00000000..cdafd8ab --- /dev/null +++ b/res/drawable-xhdpi/ic_holo_light_send.png diff --git a/res/layout/associations_dialog.xml b/res/layout/associations_dialog.xml index 80afce6e..99fb003c 100644 --- a/res/layout/associations_dialog.xml +++ b/res/layout/associations_dialog.xml @@ -18,7 +18,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" - android:layout_margin="@dimen/default_margin"> + android:gravity="center|center_horizontal"> <GridView android:id="@+id/associations_gridview" android:layout_width="match_parent" @@ -26,7 +26,6 @@ android:stretchMode="columnWidth" android:scrollbars="vertical" android:horizontalSpacing="@dimen/default_margin" - android:verticalSpacing="@dimen/default_margin" android:numColumns="3" /> <CheckBox android:id="@+id/associations_remember" diff --git a/res/layout/bookmarks_item.xml b/res/layout/bookmarks_item.xml index 5e879afe..b4e69b47 100644 --- a/res/layout/bookmarks_item.xml +++ b/res/layout/bookmarks_item.xml @@ -55,7 +55,7 @@ android:textAppearance="@style/primary_text_appearance" /> <TextView - android:id="@+id/bookmarks_item_directory" + android:id="@+id/bookmarks_item_path" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" diff --git a/res/menu/actions.xml b/res/menu/actions.xml index c07be492..877d4cfd 100644 --- a/res/menu/actions.xml +++ b/res/menu/actions.xml @@ -87,6 +87,10 @@ android:showAsAction="ifRoom" android:title="@string/actions_menu_open_with"/> <item + android:id="@+id/mnu_actions_send" + android:showAsAction="ifRoom" + android:title="@string/actions_menu_send"/> + <item android:id="@+id/mnu_actions_add_to_bookmarks" android:showAsAction="ifRoom" android:title="@string/actions_menu_add_to_bookmarks"/> diff --git a/res/values/strings.xml b/res/values/strings.xml index 6d60349e..8f81a577 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -395,6 +395,10 @@ <string name="actions_menu_open">Open</string> <!-- Actions Dialog * Menu * Open with --> <string name="actions_menu_open_with">Open with</string> + <!-- Actions Dialog * Menu * Send --> + <string name="actions_menu_send">Send</string> + <!-- Actions Dialog * Menu * Share --> + <string name="actions_menu_share">Share</string> <!-- Actions Dialog * Menu * Delete --> <string name="actions_menu_delete">Delete</string> <!-- Actions Dialog * Menu * Rename --> @@ -431,6 +435,10 @@ <string name="associations_dialog_openwith_title">Open with</string> <!-- Associations Dialog * Open action --> <string name="associations_dialog_openwith_action">Open</string> + <!-- Associations Dialog * Send with Title --> + <string name="associations_dialog_sendwith_title">Send with</string> + <!-- Associations Dialog * Send action --> + <string name="associations_dialog_sendwith_action">Send</string> <!-- Inline Autocomplete Widget * Tab message nothing to complete --> <string name="inline_autocomplete_tab_nothing_to_complete_msg">Nothing to complete</string> diff --git a/src/com/cyanogenmod/explorer/activities/BookmarksActivity.java b/src/com/cyanogenmod/explorer/activities/BookmarksActivity.java index d005fe80..d02fda0b 100644 --- a/src/com/cyanogenmod/explorer/activities/BookmarksActivity.java +++ b/src/com/cyanogenmod/explorer/activities/BookmarksActivity.java @@ -41,15 +41,20 @@ import android.widget.Toast; import com.android.internal.util.XmlUtils; import com.cyanogenmod.explorer.R; import com.cyanogenmod.explorer.adapters.BookmarksAdapter; +import com.cyanogenmod.explorer.console.NoSuchFileOrDirectory; import com.cyanogenmod.explorer.model.Bookmark; import com.cyanogenmod.explorer.model.Bookmark.BOOKMARK_TYPE; +import com.cyanogenmod.explorer.model.FileSystemObject; import com.cyanogenmod.explorer.preferences.Bookmarks; import com.cyanogenmod.explorer.preferences.ExplorerSettings; import com.cyanogenmod.explorer.preferences.Preferences; import com.cyanogenmod.explorer.ui.dialogs.InitialDirectoryDialog; +import com.cyanogenmod.explorer.util.CommandHelper; import com.cyanogenmod.explorer.util.DialogHelper; +import com.cyanogenmod.explorer.util.ExceptionUtil; import java.io.File; +import java.io.FileNotFoundException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; @@ -177,7 +182,7 @@ public class BookmarksActivity extends Activity implements OnItemClickListener, @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Bookmark bookmark = ((BookmarksAdapter)parent.getAdapter()).getItem(position); - back(false, bookmark.mDirectory); + back(false, bookmark.mPath); } /** @@ -221,15 +226,31 @@ public class BookmarksActivity extends Activity implements OnItemClickListener, * Method that returns to previous activity and. * * @param canceled Indicates if the activity was canceled - * @param directory The directory of the selected bookmark + * @param path The path of the selected bookmark */ - private void back(final boolean canceled, final String directory) { + private void back(final boolean canceled, final String path) { Intent intent = new Intent(); if (canceled) { setResult(RESULT_CANCELED, intent); } else { - intent.putExtra(NavigationActivity.EXTRA_BOOKMARK_SELECTION, directory); - setResult(RESULT_OK, intent); + // Check that the bookmark exists + try { + FileSystemObject fso = CommandHelper.getFileInfo(this, path, null); + intent.putExtra(NavigationActivity.EXTRA_BOOKMARK_SELECTION, fso); + setResult(RESULT_OK, intent); + } catch (Exception e) { + // Capture the exception + ExceptionUtil.translateException(this, e); + if (e instanceof NoSuchFileOrDirectory || e instanceof FileNotFoundException) { + // The bookmark not exists, delete the user-defined bookmark + try { + Bookmark b = Bookmarks.getBookmark(getContentResolver(), path); + Bookmarks.removeBookmark(this, b); + refresh(); + } catch (Exception ex) {/**NON BLOCK**/} + } + return; + } } finish(); } diff --git a/src/com/cyanogenmod/explorer/activities/NavigationActivity.java b/src/com/cyanogenmod/explorer/activities/NavigationActivity.java index 517e7729..af526f79 100644 --- a/src/com/cyanogenmod/explorer/activities/NavigationActivity.java +++ b/src/com/cyanogenmod/explorer/activities/NavigationActivity.java @@ -694,15 +694,18 @@ public class NavigationActivity extends Activity switch (requestCode) { case INTENT_REQUEST_BOOKMARK: if (resultCode == RESULT_OK) { - //Change - getCurrentNavigationView().changeCurrentDir( - data.getStringExtra(EXTRA_BOOKMARK_SELECTION)); + FileSystemObject fso = + (FileSystemObject)data.getSerializableExtra(EXTRA_BOOKMARK_SELECTION); + if (fso != null) { + //Open the fso + getCurrentNavigationView().open(fso); + } } break; case INTENT_REQUEST_HISTORY: if (resultCode == RESULT_OK) { - //Change + //Change current directory History history = (History)data.getSerializableExtra(EXTRA_HISTORY_ENTRY_SELECTION); navigateToHistory(history); @@ -712,12 +715,14 @@ public class NavigationActivity extends Activity case INTENT_REQUEST_SEARCH: if (resultCode == RESULT_OK) { //Change directory? - String newDir = data.getStringExtra(EXTRA_SEARCH_ENTRY_SELECTION); + FileSystemObject fso = + (FileSystemObject)data. + getSerializableExtra(EXTRA_SEARCH_ENTRY_SELECTION); SearchInfoParcelable searchInfo = data.getParcelableExtra(EXTRA_SEARCH_LAST_SEARCH_DATA); - if (newDir != null) { + if (fso != null) { //Goto to new directory - getCurrentNavigationView().changeCurrentDir(newDir, searchInfo); + getCurrentNavigationView().open(fso, searchInfo); } } else if (resultCode == RESULT_CANCELED) { SearchInfoParcelable searchInfo = @@ -777,7 +782,11 @@ public class NavigationActivity extends Activity @Override public void onRequestRemove(Object o) { if (o instanceof FileSystemObject) { + // Remove from view this.getCurrentNavigationView().removeItem((FileSystemObject)o); + + //Remove from history + removeFromHistory((FileSystemObject)o); } } @@ -1058,7 +1067,7 @@ public class NavigationActivity extends Activity * Method that navigates to the passed history reference. * * @param history The history reference - * @return boolean + * @return boolean A problem occurs while navigate */ public boolean navigateToHistory(History history) { try { @@ -1131,6 +1140,23 @@ public class NavigationActivity extends Activity * @return boolean If a back action was applied */ public boolean back() { + // Check that has valid history + while (this.mHistory.size() > 0) { + History h = this.mHistory.get(this.mHistory.size() - 1); + if (h.getItem() instanceof NavigationViewInfoParcelable) { + // Verify that the path exists + String path = ((NavigationViewInfoParcelable)h.getItem()).getCurrentDir(); + + try { + CommandHelper.getFileInfo(this, path, null); + break; + } catch (Exception e) { + ExceptionUtil.translateException(this, e, true, false); + this.mHistory.remove(this.mHistory.size() - 1); + } + } + } + //Extract a history from the if (this.mHistory.size() > 0) { //Navigate to history @@ -1212,4 +1238,23 @@ public class NavigationActivity extends Activity onSearchRequested(); } + /** + * Method that remove the {@link FileSystemObject} from the history + */ + private void removeFromHistory(FileSystemObject fso) { + if( this.mHistory != null ) { + for (int i = this.mHistory.size()-1; i >= 0 ; i--) { + History history = this.mHistory.get(i); + if (history.getItem() instanceof NavigationViewInfoParcelable) { + String p0 = fso.getFullPath(); + String p1 = + ((NavigationViewInfoParcelable)history.getItem()).getCurrentDir(); + if (p0.compareTo(p1) == 0) { + this.mHistory.remove(i); + } + } + } + } + } + } diff --git a/src/com/cyanogenmod/explorer/activities/SearchActivity.java b/src/com/cyanogenmod/explorer/activities/SearchActivity.java index 322a407e..139d3e25 100644 --- a/src/com/cyanogenmod/explorer/activities/SearchActivity.java +++ b/src/com/cyanogenmod/explorer/activities/SearchActivity.java @@ -56,7 +56,6 @@ import com.cyanogenmod.explorer.console.NoSuchFileOrDirectory; import com.cyanogenmod.explorer.listeners.OnRequestRefreshListener; import com.cyanogenmod.explorer.model.Directory; import com.cyanogenmod.explorer.model.FileSystemObject; -import com.cyanogenmod.explorer.model.ParentDirectory; import com.cyanogenmod.explorer.model.Query; import com.cyanogenmod.explorer.model.SearchResult; import com.cyanogenmod.explorer.model.Symlink; @@ -784,15 +783,16 @@ public class SearchActivity extends Activity try { SearchResult result = ((SearchResultAdapter)parent.getAdapter()).getItem(position); FileSystemObject fso = result.getFso(); - if (fso instanceof ParentDirectory) { - back(false, fso.getParent()); - } else if (fso instanceof Directory) { - back(false, fso.getFullPath()); + if (fso instanceof Directory) { + back(false, fso); } else if (fso instanceof Symlink) { Symlink symlink = (Symlink)fso; if (symlink.getLinkRef() != null && symlink.getLinkRef() instanceof Directory) { - back(false, symlink.getLinkRef().getFullPath()); + back(false, symlink.getLinkRef()); } + } else { + // Open the file with the preferred registered app + back(false, fso); } } catch (Throwable ex) { ExceptionUtil.translateException(this.mSearchListView.getContext(), ex); @@ -822,7 +822,7 @@ public class SearchActivity extends Activity // Open with else if (this.mDefaultLongClickAction.compareTo( DefaultLongClickAction.OPEN_WITH) == 0) { - // FIXME Invoke ActionPolicy open with + ActionsPolicy.openFileSystemObject(this, fso, true); } // Show properties @@ -836,8 +836,6 @@ public class SearchActivity extends Activity DefaultLongClickAction.SHOW_ACTIONS) == 0) { onRequestMenu(fso); } - - return true; //Always consume the event } @@ -932,10 +930,10 @@ public class SearchActivity extends Activity * Method that returns to previous activity. * * @param canceled Indicates if the activity was canceled - * @param directory The directory to which navigate to + * @param item The fso * @hide */ - void back(final boolean canceled, String directory) { + void back(final boolean canceled, FileSystemObject item) { Intent intent = new Intent(); if (canceled) { if (SearchActivity.this.mDrawingSearchResultTask != null @@ -949,11 +947,33 @@ public class SearchActivity extends Activity } setResult(RESULT_CANCELED, intent); } else { - intent.putExtra(NavigationActivity.EXTRA_SEARCH_ENTRY_SELECTION, directory); - intent.putExtra( - NavigationActivity.EXTRA_SEARCH_LAST_SEARCH_DATA, - (Parcelable)createSearchInfo()); - setResult(RESULT_OK, intent); + // Check that the bookmark exists + try { + FileSystemObject fso = CommandHelper.getFileInfo(this, item.getFullPath(), null); + if (FileHelper.isDirectory(fso)) { + intent.putExtra(NavigationActivity.EXTRA_SEARCH_ENTRY_SELECTION, fso); + intent.putExtra( + NavigationActivity.EXTRA_SEARCH_LAST_SEARCH_DATA, + (Parcelable)createSearchInfo()); + setResult(RESULT_OK, intent); + } else { + // Open the file here, so when focus back to the app, the search activity + // its in top of the stack + ActionsPolicy.openFileSystemObject(this, fso, false); + return; + } + + } catch (Exception e) { + // Capture the exception + ExceptionUtil.translateException(this, e); + if (e instanceof NoSuchFileOrDirectory || e instanceof FileNotFoundException) { + // The fso not exists, delete the fso from the search + try { + removeItem(item); + } catch (Exception ex) {/**NON BLOCK**/} + } + return; + } } finish(); } diff --git a/src/com/cyanogenmod/explorer/adapters/BookmarksAdapter.java b/src/com/cyanogenmod/explorer/adapters/BookmarksAdapter.java index 5618b9e7..c4d90172 100644 --- a/src/com/cyanogenmod/explorer/adapters/BookmarksAdapter.java +++ b/src/com/cyanogenmod/explorer/adapters/BookmarksAdapter.java @@ -53,7 +53,7 @@ public class BookmarksAdapter extends ArrayAdapter<Bookmark> { } ImageView mIvIcon; TextView mTvName; - TextView mTvDirectory; + TextView mTvPath; ImageButton mBtAction; } @@ -69,7 +69,7 @@ public class BookmarksAdapter extends ArrayAdapter<Bookmark> { } Drawable mDwIcon; String mName; - String mDirectory; + String mPath; Drawable mDwAction; String mActionCd; } @@ -88,7 +88,7 @@ public class BookmarksAdapter extends ArrayAdapter<Bookmark> { //The resource of the item name private static final int RESOURCE_ITEM_NAME = R.id.bookmarks_item_name; //The resource of the item directory - private static final int RESOURCE_ITEM_DIRECTORY = R.id.bookmarks_item_directory; + private static final int RESOURCE_ITEM_PATH = R.id.bookmarks_item_path; //The resource of the item button action private static final int RESOURCE_ITEM_ACTION = R.id.bookmarks_item_action; @@ -142,7 +142,7 @@ public class BookmarksAdapter extends ArrayAdapter<Bookmark> { this.mData[i].mDwIcon = this.mIconHolder.getDrawable(getContext(), BookmarksHelper.getIcon(bookmark)); this.mData[i].mName = bookmark.mName; - this.mData[i].mDirectory = bookmark.mDirectory; + this.mData[i].mPath = bookmark.mPath; this.mData[i].mDwAction = null; this.mData[i].mActionCd = null; if (bookmark.mType.compareTo(BOOKMARK_TYPE.HOME) == 0) { @@ -175,7 +175,7 @@ public class BookmarksAdapter extends ArrayAdapter<Bookmark> { ViewHolder viewHolder = new BookmarksAdapter.ViewHolder(); viewHolder.mIvIcon = (ImageView)v.findViewById(RESOURCE_ITEM_ICON); viewHolder.mTvName = (TextView)v.findViewById(RESOURCE_ITEM_NAME); - viewHolder.mTvDirectory = (TextView)v.findViewById(RESOURCE_ITEM_DIRECTORY); + viewHolder.mTvPath = (TextView)v.findViewById(RESOURCE_ITEM_PATH); viewHolder.mBtAction = (ImageButton)v.findViewById(RESOURCE_ITEM_ACTION); viewHolder.mBtAction.setTag(Integer.valueOf(position)); v.setTag(viewHolder); @@ -190,7 +190,7 @@ public class BookmarksAdapter extends ArrayAdapter<Bookmark> { //Set the data viewHolder.mIvIcon.setImageDrawable(dataHolder.mDwIcon); viewHolder.mTvName.setText(dataHolder.mName); - viewHolder.mTvDirectory.setText(dataHolder.mDirectory); + viewHolder.mTvPath.setText(dataHolder.mPath); boolean hasAction = dataHolder.mDwAction != null; viewHolder.mBtAction.setImageDrawable(hasAction ? dataHolder.mDwAction : null); viewHolder.mBtAction.setVisibility(hasAction ? View.VISIBLE : View.GONE); diff --git a/src/com/cyanogenmod/explorer/adapters/HistoryAdapter.java b/src/com/cyanogenmod/explorer/adapters/HistoryAdapter.java index fcb13171..90789b5e 100644 --- a/src/com/cyanogenmod/explorer/adapters/HistoryAdapter.java +++ b/src/com/cyanogenmod/explorer/adapters/HistoryAdapter.java @@ -141,6 +141,10 @@ public class HistoryAdapter extends ArrayAdapter<History> { getContext(), R.drawable.ic_holo_light_history_search); } this.mData[i].mName = history.getItem().getTitle(); + if (this.mData[i].mName == null || this.mData[i].mName.trim().length() == 0) { + // Root directory + this.mData[i].mName = getContext().getString(R.string.root_directory_name); + } this.mData[i].mDirectory = history.getItem().getDescription(); this.mData[i].mPosition = String.format("#%d", Integer.valueOf(i + 1)); //$NON-NLS-1$ } diff --git a/src/com/cyanogenmod/explorer/model/Bookmark.java b/src/com/cyanogenmod/explorer/model/Bookmark.java index a920ca39..8e216a9a 100644 --- a/src/com/cyanogenmod/explorer/model/Bookmark.java +++ b/src/com/cyanogenmod/explorer/model/Bookmark.java @@ -76,21 +76,21 @@ public class Bookmark implements Serializable, Comparable<Bookmark>, Parcelable "/bookmarks")); //$NON-NLS-1$ /** - * The directory of the bookmark + * The path of the bookmark * <P>Type: TEXT</P> */ - public static final String DIRECTORY = "directory"; //$NON-NLS-1$ + public static final String PATH = "path"; //$NON-NLS-1$ /** * The default sort order for this table */ public static final String DEFAULT_SORT_ORDER = - DIRECTORY + " ASC"; //$NON-NLS-1$ + PATH + " ASC"; //$NON-NLS-1$ /** * @hide */ - public static final String[] BOOKMARK_QUERY_COLUMNS = {_ID, DIRECTORY}; + public static final String[] BOOKMARK_QUERY_COLUMNS = {_ID, PATH}; /** * These save calls to cursor.getColumnIndexOrThrow() @@ -103,7 +103,7 @@ public class Bookmark implements Serializable, Comparable<Bookmark>, Parcelable /** * @hide */ - public static final int BOOKMARK_DIRECTORY_INDEX = 1; + public static final int BOOKMARK_PATH_INDEX = 1; } /** @hide **/ @@ -113,21 +113,21 @@ public class Bookmark implements Serializable, Comparable<Bookmark>, Parcelable /** @hide **/ public String mName; /** @hide **/ - public String mDirectory; + public String mPath; /** * Constructor of <code>Bookmark</code>. * * @param type The type of the bookmark * @param name The name of the bookmark - * @param directory The directory that the bookmark points to + * @param path The path that the bookmark points to * @hide */ - public Bookmark(BOOKMARK_TYPE type, String name, String directory) { + public Bookmark(BOOKMARK_TYPE type, String name, String path) { super(); this.mType = type; this.mName = name; - this.mDirectory = directory; + this.mPath = path; } /** @@ -139,8 +139,8 @@ public class Bookmark implements Serializable, Comparable<Bookmark>, Parcelable super(); this.mId = c.getInt(Columns.BOOKMARK_ID_INDEX); this.mType = BOOKMARK_TYPE.USER_DEFINED; - this.mDirectory = c.getString(Columns.BOOKMARK_DIRECTORY_INDEX); - this.mName = new File(this.mDirectory).getName(); + this.mPath = c.getString(Columns.BOOKMARK_PATH_INDEX); + this.mName = new File(this.mPath).getName(); } /** @@ -150,7 +150,7 @@ public class Bookmark implements Serializable, Comparable<Bookmark>, Parcelable public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((this.mDirectory == null) ? 0 : this.mDirectory.hashCode()); + result = prime * result + ((this.mPath == null) ? 0 : this.mPath.hashCode()); result = prime * result + ((this.mName == null) ? 0 : this.mName.hashCode()); result = prime * result + ((this.mType == null) ? 0 : this.mType.hashCode()); return result; @@ -171,11 +171,11 @@ public class Bookmark implements Serializable, Comparable<Bookmark>, Parcelable return false; } Bookmark other = (Bookmark) obj; - if (this.mDirectory == null) { - if (other.mDirectory != null) { + if (this.mPath == null) { + if (other.mPath != null) { return false; } - } else if (!this.mDirectory.equals(other.mDirectory)) { + } else if (!this.mPath.equals(other.mPath)) { return false; } if (this.mName == null) { @@ -207,7 +207,7 @@ public class Bookmark implements Serializable, Comparable<Bookmark>, Parcelable dest.writeInt(this.mId); dest.writeString(this.mType.toString()); dest.writeString(this.mName); - dest.writeString(this.mDirectory); + dest.writeString(this.mPath); } /** @@ -219,8 +219,8 @@ public class Bookmark implements Serializable, Comparable<Bookmark>, Parcelable int id = in.readInt(); BOOKMARK_TYPE type = BOOKMARK_TYPE.valueOf(in.readString()); String name = in.readString(); - String directory = in.readString(); - Bookmark b = new Bookmark(type, name, directory); + String path = in.readString(); + Bookmark b = new Bookmark(type, name, path); b.mId = id; return b; } @@ -240,7 +240,7 @@ public class Bookmark implements Serializable, Comparable<Bookmark>, Parcelable if (c != 0) { return c; } - return this.mDirectory.compareTo(another.mDirectory); + return this.mPath.compareTo(another.mPath); } /** @@ -250,7 +250,7 @@ public class Bookmark implements Serializable, Comparable<Bookmark>, Parcelable public String toString() { return "Bookmark [id=" + this.mId + ", type=" + //$NON-NLS-1$//$NON-NLS-2$ this.mType + ", name=" + this.mName + //$NON-NLS-1$ - ", directory=" + this.mDirectory + "]"; //$NON-NLS-1$//$NON-NLS-2$ + ", path=" + this.mPath + "]"; //$NON-NLS-1$//$NON-NLS-2$ } } diff --git a/src/com/cyanogenmod/explorer/preferences/Bookmarks.java b/src/com/cyanogenmod/explorer/preferences/Bookmarks.java index 4b0c0ce8..a493e216 100644 --- a/src/com/cyanogenmod/explorer/preferences/Bookmarks.java +++ b/src/com/cyanogenmod/explorer/preferences/Bookmarks.java @@ -41,13 +41,13 @@ public class Bookmarks { */ public static Bookmark addBookmark(Context context, Bookmark bookmark) { // Check that has a valid information - if (bookmark.mDirectory == null) return null; + if (bookmark.mPath == null) return null; // Retrieve the content resolver ContentResolver contentResolver = context.getContentResolver(); // Check that the bookmarks not exists - Bookmark b = getBookmark(contentResolver, bookmark.mDirectory); + Bookmark b = getBookmark(contentResolver, bookmark.mPath); if (b != null) return b; // Create the content values @@ -113,18 +113,18 @@ public class Bookmarks { } /** - * Method that return the bookmark from his directory + * Method that return the bookmark from his path * * @param contentResolver The content resolver - * @param directory The bookmark directory + * @param path The bookmark path * @return Bookmark The bookmark. null if no bookmark exists. */ - public static Bookmark getBookmark(ContentResolver contentResolver, String directory) { - final String where = Bookmark.Columns.DIRECTORY + " = ?"; //$NON-NLS-1$ + public static Bookmark getBookmark(ContentResolver contentResolver, String path) { + final String where = Bookmark.Columns.PATH + " = ?"; //$NON-NLS-1$ Cursor cursor = contentResolver.query( Bookmark.Columns.CONTENT_URI, Bookmark.Columns.BOOKMARK_QUERY_COLUMNS, - where, new String[]{directory}, null); + where, new String[]{path}, null); Bookmark bookmark = null; if (cursor != null) { if (cursor.moveToFirst()) { @@ -143,7 +143,7 @@ public class Bookmarks { */ private static ContentValues createContentValues(Bookmark bookmark) { ContentValues values = new ContentValues(1); - values.put(Bookmark.Columns.DIRECTORY, bookmark.mDirectory); + values.put(Bookmark.Columns.PATH, bookmark.mPath); return values; } } diff --git a/src/com/cyanogenmod/explorer/preferences/BookmarksDatabaseHelper.java b/src/com/cyanogenmod/explorer/preferences/BookmarksDatabaseHelper.java index 1269d900..84107c0d 100644 --- a/src/com/cyanogenmod/explorer/preferences/BookmarksDatabaseHelper.java +++ b/src/com/cyanogenmod/explorer/preferences/BookmarksDatabaseHelper.java @@ -50,7 +50,7 @@ public class BookmarksDatabaseHelper extends SQLiteOpenHelper { public void onCreate(SQLiteDatabase db) { db.execSQL("CREATE TABLE bookmarks (" + //$NON-NLS-1$ "_id INTEGER PRIMARY KEY," + //$NON-NLS-1$ - "directory TEXT);"); //$NON-NLS-1$ + "path TEXT);"); //$NON-NLS-1$ } /** 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); |