use of com.amaze.filemanager.adapters.data.StorageDirectoryParcelable in project AmazeFileManager by TeamAmaze.
the class UsbOtgTest method usbConnectionTest.
@Test
public void usbConnectionTest() {
ActivityController<MainActivity> controller = Robolectric.buildActivity(MainActivity.class).create();
MainActivity activity = controller.get();
addUsbOtgDevice(activity);
activity = controller.resume().get();
boolean hasOtgStorage = false;
ArrayList<StorageDirectoryParcelable> storageDirectories = activity.getStorageDirectories();
for (StorageDirectoryParcelable storageDirectory : storageDirectories) {
if (storageDirectory.path.startsWith(OTGUtil.PREFIX_OTG)) {
hasOtgStorage = true;
break;
}
}
assertTrue("No usb storage, known storages: '" + TextUtils.join("', '", storageDirectories) + "'", hasOtgStorage);
}
use of com.amaze.filemanager.adapters.data.StorageDirectoryParcelable in project AmazeFileManager by TeamAmaze.
the class MainActivity method getStorageDirectoriesLegacy.
/**
* Returns all available SD-Cards in the system (include emulated)
*
* <p>Warning: Hack! Based on Android source code of version 4.3 (API 18) Because there was no
* standard way to get it before android N
*
* @return All available SD-Cards in the system (include emulated)
*/
public synchronized ArrayList<StorageDirectoryParcelable> getStorageDirectoriesLegacy() {
List<String> rv = new ArrayList<>();
// Primary physical SD-CARD (not emulated)
final String rawExternalStorage = System.getenv("EXTERNAL_STORAGE");
// All Secondary SD-CARDs (all exclude primary) separated by ":"
final String rawSecondaryStoragesStr = System.getenv("SECONDARY_STORAGE");
// Primary emulated SD-CARD
final String rawEmulatedStorageTarget = System.getenv("EMULATED_STORAGE_TARGET");
if (TextUtils.isEmpty(rawEmulatedStorageTarget)) {
// Device has physical external storage; use plain paths.
if (TextUtils.isEmpty(rawExternalStorage)) {
// Check for actual existence of the directory before adding to list
if (new File(DEFAULT_FALLBACK_STORAGE_PATH).exists()) {
rv.add(DEFAULT_FALLBACK_STORAGE_PATH);
} else {
// We know nothing else, use Environment's fallback
rv.add(Environment.getExternalStorageDirectory().getAbsolutePath());
}
} else {
rv.add(rawExternalStorage);
}
} else {
// Device has emulated storage; external storage paths should have
// userId burned into them.
final String rawUserId;
if (SDK_INT < JELLY_BEAN_MR1) {
rawUserId = "";
} else {
final String path = Environment.getExternalStorageDirectory().getAbsolutePath();
final String[] folders = DIR_SEPARATOR.split(path);
final String lastFolder = folders[folders.length - 1];
boolean isDigit = false;
try {
Integer.valueOf(lastFolder);
isDigit = true;
} catch (NumberFormatException ignored) {
}
rawUserId = isDigit ? lastFolder : "";
}
// /storage/emulated/0[1,2,...]
if (TextUtils.isEmpty(rawUserId)) {
rv.add(rawEmulatedStorageTarget);
} else {
rv.add(rawEmulatedStorageTarget + File.separator + rawUserId);
}
}
// Add all secondary storages
if (!TextUtils.isEmpty(rawSecondaryStoragesStr)) {
// All Secondary SD-CARDs splited into array
final String[] rawSecondaryStorages = rawSecondaryStoragesStr.split(File.pathSeparator);
Collections.addAll(rv, rawSecondaryStorages);
}
if (SDK_INT >= M && checkStoragePermission())
rv.clear();
if (SDK_INT >= KITKAT) {
String[] strings = ExternalSdCardOperation.getExtSdCardPathsForActivity(this);
for (String s : strings) {
File f = new File(s);
if (!rv.contains(s) && FileUtils.canListFiles(f))
rv.add(s);
}
}
File usb = getUsbDrive();
if (usb != null && !rv.contains(usb.getPath()))
rv.add(usb.getPath());
if (SDK_INT >= KITKAT) {
if (SingletonUsbOtg.getInstance().isDeviceConnected()) {
rv.add(OTGUtil.PREFIX_OTG + "/");
}
}
// Assign a label and icon to each directory
ArrayList<StorageDirectoryParcelable> volumes = new ArrayList<>();
for (String file : rv) {
File f = new File(file);
@DrawableRes int icon;
if ("/storage/emulated/legacy".equals(file) || "/storage/emulated/0".equals(file) || "/mnt/sdcard".equals(file)) {
icon = R.drawable.ic_phone_android_white_24dp;
} else if ("/storage/sdcard1".equals(file)) {
icon = R.drawable.ic_sd_storage_white_24dp;
} else if ("/".equals(file)) {
icon = R.drawable.ic_drawer_root_white;
} else {
icon = R.drawable.ic_sd_storage_white_24dp;
}
@StorageNaming.DeviceDescription int deviceDescription = StorageNaming.getDeviceDescriptionLegacy(f);
String name = StorageNamingHelper.getNameForDeviceDescription(this, f, deviceDescription);
volumes.add(new StorageDirectoryParcelable(file, name, icon));
}
return volumes;
}
use of com.amaze.filemanager.adapters.data.StorageDirectoryParcelable in project AmazeFileManager by TeamAmaze.
the class Drawer method refreshDrawer.
public void refreshDrawer() {
Menu menu = navView.getMenu();
menu.clear();
actionViewStateManager.deselectCurrentActionView();
int order = 0;
ArrayList<StorageDirectoryParcelable> storageDirectories = mainActivity.getStorageDirectories();
ArrayList<String> storageDirectoryPaths = new ArrayList<>();
phoneStorageCount = 0;
for (StorageDirectoryParcelable storageDirectory : storageDirectories) {
String file = storageDirectory.path;
File f = new File(file);
String name = storageDirectory.name;
int icon = storageDirectory.iconRes;
storageDirectoryPaths.add(file);
if (file.contains(OTGUtil.PREFIX_OTG) || file.startsWith(OTGUtil.PREFIX_MEDIA_REMOVABLE)) {
addNewItem(menu, STORAGES_GROUP, order++, "OTG", new MenuMetadata(file), R.drawable.ic_usb_white_24dp, R.drawable.ic_show_chart_black_24dp);
continue;
}
if (f.isDirectory() || f.canExecute()) {
addNewItem(menu, STORAGES_GROUP, order++, name, new MenuMetadata(file), icon, R.drawable.ic_show_chart_black_24dp);
if (phoneStorageCount == 0)
firstPath = file;
else if (phoneStorageCount == 1)
secondPath = file;
phoneStorageCount++;
}
}
dataUtils.setStorages(storageDirectoryPaths);
if (dataUtils.getServers().size() > 0) {
Collections.sort(dataUtils.getServers(), new BookSorter());
synchronized (dataUtils.getServers()) {
for (String[] file : dataUtils.getServers()) {
addNewItem(menu, SERVERS_GROUP, order++, file[0], new MenuMetadata(file[1]), R.drawable.ic_settings_remote_white_24dp, R.drawable.ic_edit_24dp);
}
}
}
ArrayList<String[]> accountAuthenticationList = new ArrayList<>();
if (CloudSheetFragment.isCloudProviderAvailable(mainActivity)) {
for (CloudStorage cloudStorage : dataUtils.getAccounts()) {
@DrawableRes int deleteIcon = R.drawable.ic_delete_grey_24dp;
if (cloudStorage instanceof Dropbox) {
addNewItem(menu, CLOUDS_GROUP, order++, CloudHandler.CLOUD_NAME_DROPBOX, new MenuMetadata(CloudHandler.CLOUD_PREFIX_DROPBOX + "/"), R.drawable.ic_dropbox_white_24dp, deleteIcon);
accountAuthenticationList.add(new String[] { CloudHandler.CLOUD_NAME_DROPBOX, CloudHandler.CLOUD_PREFIX_DROPBOX + "/" });
} else if (cloudStorage instanceof Box) {
addNewItem(menu, CLOUDS_GROUP, order++, CloudHandler.CLOUD_NAME_BOX, new MenuMetadata(CloudHandler.CLOUD_PREFIX_BOX + "/"), R.drawable.ic_box_white_24dp, deleteIcon);
accountAuthenticationList.add(new String[] { CloudHandler.CLOUD_NAME_BOX, CloudHandler.CLOUD_PREFIX_BOX + "/" });
} else if (cloudStorage instanceof OneDrive) {
addNewItem(menu, CLOUDS_GROUP, order++, CloudHandler.CLOUD_NAME_ONE_DRIVE, new MenuMetadata(CloudHandler.CLOUD_PREFIX_ONE_DRIVE + "/"), R.drawable.ic_onedrive_white_24dp, deleteIcon);
accountAuthenticationList.add(new String[] { CloudHandler.CLOUD_NAME_ONE_DRIVE, CloudHandler.CLOUD_PREFIX_ONE_DRIVE + "/" });
} else if (cloudStorage instanceof GoogleDrive) {
addNewItem(menu, CLOUDS_GROUP, order++, CloudHandler.CLOUD_NAME_GOOGLE_DRIVE, new MenuMetadata(CloudHandler.CLOUD_PREFIX_GOOGLE_DRIVE + "/"), R.drawable.ic_google_drive_white_24dp, deleteIcon);
accountAuthenticationList.add(new String[] { CloudHandler.CLOUD_NAME_GOOGLE_DRIVE, CloudHandler.CLOUD_PREFIX_GOOGLE_DRIVE + "/" });
}
}
Collections.sort(accountAuthenticationList, new BookSorter());
}
if (mainActivity.getBoolean(PREFERENCE_SHOW_SIDEBAR_FOLDERS)) {
if (dataUtils.getBooks().size() > 0) {
Collections.sort(dataUtils.getBooks(), new BookSorter());
synchronized (dataUtils.getBooks()) {
for (String[] file : dataUtils.getBooks()) {
addNewItem(menu, FOLDERS_GROUP, order++, file[0], new MenuMetadata(file[1]), R.drawable.ic_folder_white_24dp, R.drawable.ic_edit_24dp);
}
}
}
}
Boolean[] quickAccessPref = TinyDB.getBooleanArray(mainActivity.getPrefs(), QuickAccessPref.KEY, QuickAccessPref.Companion.getDEFAULT());
if (mainActivity.getBoolean(PREFERENCE_SHOW_SIDEBAR_QUICKACCESSES)) {
if (quickAccessPref[0]) {
addNewItem(menu, QUICKACCESSES_GROUP, order++, R.string.quick, new MenuMetadata("5"), R.drawable.ic_star_white_24dp, null);
}
if (quickAccessPref[1]) {
addNewItem(menu, QUICKACCESSES_GROUP, order++, R.string.recent, new MenuMetadata("6"), R.drawable.ic_history_white_24dp, null);
}
if (quickAccessPref[2]) {
addNewItem(menu, QUICKACCESSES_GROUP, order++, R.string.images, new MenuMetadata("0"), R.drawable.ic_photo_library_white_24dp, null);
}
if (quickAccessPref[3]) {
addNewItem(menu, QUICKACCESSES_GROUP, order++, R.string.videos, new MenuMetadata("1"), R.drawable.ic_video_library_white_24dp, null);
}
if (quickAccessPref[4]) {
addNewItem(menu, QUICKACCESSES_GROUP, order++, R.string.audio, new MenuMetadata("2"), R.drawable.ic_library_music_white_24dp, null);
}
if (quickAccessPref[5]) {
addNewItem(menu, QUICKACCESSES_GROUP, order++, R.string.documents, new MenuMetadata("3"), R.drawable.ic_library_books_white_24dp, null);
}
if (quickAccessPref[6]) {
addNewItem(menu, QUICKACCESSES_GROUP, order++, R.string.apks, new MenuMetadata("4"), R.drawable.ic_apk_library_white_24dp, null);
}
}
addNewItem(menu, LASTGROUP, order++, R.string.ftp, new MenuMetadata(() -> {
FragmentTransaction transaction2 = mainActivity.getSupportFragmentManager().beginTransaction();
transaction2.replace(R.id.content_frame, new FtpServerFragment());
mainActivity.getAppbar().getAppbarLayout().animate().translationY(0).setInterpolator(new DecelerateInterpolator(2)).start();
pending_fragmentTransaction = transaction2;
if (!isDrawerLocked)
close();
else
onDrawerClosed();
}), R.drawable.ic_ftp_white_24dp, null);
addNewItem(menu, LASTGROUP, order++, R.string.apps, new MenuMetadata(() -> {
FragmentTransaction transaction2 = mainActivity.getSupportFragmentManager().beginTransaction();
transaction2.replace(R.id.content_frame, new AppsListFragment());
mainActivity.getAppbar().getAppbarLayout().animate().translationY(0).setInterpolator(new DecelerateInterpolator(2)).start();
pending_fragmentTransaction = transaction2;
if (!isDrawerLocked)
close();
else
onDrawerClosed();
}), R.drawable.ic_android_white_24dp, null);
addNewItem(menu, LASTGROUP, order++, R.string.setting, new MenuMetadata(() -> {
Intent in = new Intent(mainActivity, PreferencesActivity.class);
mainActivity.startActivity(in);
mainActivity.finish();
}), R.drawable.ic_settings_white_24dp, null);
for (int i = 0; i < navView.getMenu().size(); i++) {
navView.getMenu().getItem(i).setEnabled(true);
}
for (int group : GROUPS) {
menu.setGroupCheckable(group, true, true);
}
MenuItem item = navView.getSelected();
if (item != null) {
item.setChecked(true);
actionViewStateManager.selectActionView(item);
}
}
use of com.amaze.filemanager.adapters.data.StorageDirectoryParcelable in project AmazeFileManager by TeamAmaze.
the class MainActivity method getStorageDirectoriesNew.
/**
* @return All available storage volumes (including internal storage, SD-Cards and USB devices)
*/
@TargetApi(N)
public synchronized ArrayList<StorageDirectoryParcelable> getStorageDirectoriesNew() {
// Final set of paths
ArrayList<StorageDirectoryParcelable> volumes = new ArrayList<>();
StorageManager sm = getSystemService(StorageManager.class);
for (StorageVolume volume : sm.getStorageVolumes()) {
if (!volume.getState().equalsIgnoreCase(Environment.MEDIA_MOUNTED) && !volume.getState().equalsIgnoreCase(Environment.MEDIA_MOUNTED_READ_ONLY)) {
continue;
}
File path = Utils.getVolumeDirectory(volume);
String name = volume.getDescription(this);
if (INTERNAL_SHARED_STORAGE.equalsIgnoreCase(name)) {
name = getString(R.string.storage_internal);
}
int icon;
if (!volume.isRemovable()) {
icon = R.drawable.ic_phone_android_white_24dp;
} else {
// However it is often enough to check for "USB" String
if (name.toUpperCase().contains("USB") || path.getPath().toUpperCase().contains("USB")) {
icon = R.drawable.ic_usb_white_24dp;
} else {
icon = R.drawable.ic_sd_storage_white_24dp;
}
}
volumes.add(new StorageDirectoryParcelable(path.getPath(), name, icon));
}
return volumes;
}
Aggregations