diff options
author | jruesga <jorge@ruesga.com> | 2012-10-12 00:51:28 +0200 |
---|---|---|
committer | jruesga <jorge@ruesga.com> | 2012-10-12 00:51:28 +0200 |
commit | 719efac56e8665b431d8ecdfbfa82a2283485212 (patch) | |
tree | 4f4bf55ffd6a6bf4406760fdb7a6e7cc7520675d | |
parent | fe687a5df00ab02a258d9804f99a31c774be2fe9 (diff) | |
download | android_packages_apps_CMFileManager-719efac56e8665b431d8ecdfbfa82a2283485212.tar.gz android_packages_apps_CMFileManager-719efac56e8665b431d8ecdfbfa82a2283485212.tar.bz2 android_packages_apps_CMFileManager-719efac56e8665b431d8ecdfbfa82a2283485212.zip |
Create StorageHelper, and redesign BookmarksActivity
-rw-r--r-- | res/values/strings.xml | 6 | ||||
-rw-r--r-- | src/com/cyanogenmod/explorer/activities/BookmarksActivity.java | 75 |
2 files changed, 10 insertions, 71 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml index a347059a..cfc0744c 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -151,6 +151,10 @@ <!-- The parent directory of the current directory in navigation view --> <string name="parent_dir">Parent Directory</string> + <!-- External Storage descripton --> + <string name="external_storage">External storage</string> + <!-- Usb Storage descripton --> + <string name="usb_storage">Usb storage</string> <!-- ActionBar Buttons > FileSystem --> <string name="actionbar_button_filesystem_cd">Filesystem info</string> @@ -351,8 +355,6 @@ <string name="bookmarks_root_folder">Root folder</string> <!-- Bookmark name * System folder --> <string name="bookmarks_system_folder">System folder</string> - <!-- Bookmark name * External Storage --> - <string name="bookmarks_external_storage">External storage</string> <!-- Bookmark name * Button * Initial directory content description --> <string name="bookmarks_button_config_cd">Set the initial directory</string> <!-- Bookmark name * Button * Remove bookmark content description --> diff --git a/src/com/cyanogenmod/explorer/activities/BookmarksActivity.java b/src/com/cyanogenmod/explorer/activities/BookmarksActivity.java index d02fda0b..71cd07f9 100644 --- a/src/com/cyanogenmod/explorer/activities/BookmarksActivity.java +++ b/src/com/cyanogenmod/explorer/activities/BookmarksActivity.java @@ -18,14 +18,11 @@ package com.cyanogenmod.explorer.activities; import android.app.ActionBar; import android.app.Activity; -import android.content.Context; import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.res.XmlResourceParser; import android.database.Cursor; import android.os.Bundle; -import android.os.Environment; -import android.os.storage.StorageManager; import android.os.storage.StorageVolume; import android.util.Log; import android.view.KeyEvent; @@ -52,10 +49,9 @@ 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 com.cyanogenmod.explorer.util.StorageHelper; -import java.io.File; import java.io.FileNotFoundException; -import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; @@ -360,59 +356,28 @@ public class BookmarksActivity extends Activity implements OnItemClickListener, try { //Recovery sdcards from storage manager - //IMP!! Android SDK doesn't have a "getVolumeList" but is supported by CM10. - //Use reflect to get this value (if possible) - StorageManager sm = (StorageManager) getSystemService(Context.STORAGE_SERVICE); - Method method = sm.getClass().getMethod("getVolumeList"); //$NON-NLS-1$ - StorageVolume[] volumes = (StorageVolume[])method.invoke(sm); + StorageVolume[] volumes = StorageHelper.getStorageVolumes(getApplication()); int cc = volumes.length; for (int i = 0; i < cc ; i++) { if (volumes[i].getPath().toLowerCase().indexOf("usb") != -1) { //$NON-NLS-1$ bookmarks.add( new Bookmark( BOOKMARK_TYPE.USB, - getStorageVolumeDescription(volumes[i]), + StorageHelper.getStorageVolumeDescription( + getApplication(), volumes[i]), volumes[i].getPath())); } else { bookmarks.add( new Bookmark( BOOKMARK_TYPE.SDCARD, - getStorageVolumeDescription(volumes[i]), + StorageHelper.getStorageVolumeDescription( + getApplication(), volumes[i]), volumes[i].getPath())); } } //Return the bookmarks return bookmarks; - - } catch (NoSuchMethodException nsmex) { - //Ignore. Android SDK StorageManager class doesn't have this method - //Use default android information from environment - try { - File externalStorage = Environment.getExternalStorageDirectory(); - if (externalStorage != null) { - String path = externalStorage.getCanonicalPath(); - if (path.toLowerCase().indexOf("usb") != -1) { //$NON-NLS-1$ - bookmarks.add( - new Bookmark( - BOOKMARK_TYPE.USB, - getString(R.string.bookmarks_external_storage), - path)); - } else { - bookmarks.add( - new Bookmark( - BOOKMARK_TYPE.SDCARD, - getString(R.string.bookmarks_external_storage), - path)); - } - } - //Return the bookmarks - return bookmarks; - } catch (Throwable ex) { - /**NON BLOCK**/ - } - - } catch (Throwable ex) { Log.e(TAG, "Load filesystem bookmarks failed", ex); //$NON-NLS-1$ } @@ -422,34 +387,6 @@ public class BookmarksActivity extends Activity implements OnItemClickListener, } /** - * Method that returns the storage volume description. This method uses - * reflection to retrieve the description because CM10 has a {@link Context} - * as first parameter, that AOSP hasn't. - * - * @param volume The storage volume - * @return String The description of the storage volume - */ - private String getStorageVolumeDescription(StorageVolume volume) { - try { - Method method = volume.getClass().getMethod( - "getDescription", //$NON-NLS-1$ - new Class[]{Context.class}); - if (method == null) { - // AOSP - method = volume.getClass().getMethod("getDescription"); //$NON-NLS-1$ - return (String)method.invoke(volume); - } - - // CM10 - return (String)method.invoke(volume, (Context)getApplication()); - - } catch (Throwable _throw) { - // Returns the volume storage path - return volume.getPath(); - } - } - - /** * Method that loads the user bookmarks (added by the user). * * @return List<Bookmark> The bookmarks loaded |