use of com.amaze.filemanager.filesystem.HybridFileParcelable in project AmazeFileManager by TeamAmaze.
the class MoveFiles method doInBackground.
@Override
protected Boolean doInBackground(ArrayList<String>... strings) {
paths = strings[0];
if (files.size() == 0)
return true;
switch(mode) {
case SMB:
for (int i = 0; i < paths.size(); i++) {
for (HybridFileParcelable f : files.get(i)) {
try {
SmbFile source = new SmbFile(f.getPath());
SmbFile dest = new SmbFile(paths.get(i) + "/" + f.getName());
source.renameTo(dest);
} catch (MalformedURLException e) {
e.printStackTrace();
return false;
} catch (SmbException e) {
e.printStackTrace();
return false;
}
}
}
break;
case FILE:
for (int i = 0; i < paths.size(); i++) {
for (HybridFileParcelable f : files.get(i)) {
File dest = new File(paths.get(i) + "/" + f.getName());
File source = new File(f.getPath());
if (!source.renameTo(dest)) {
// check if we have root
if (mainFrag.getMainActivity().isRootExplorer()) {
try {
if (!RootUtils.rename(f.getPath(), paths.get(i) + "/" + f.getName()))
return false;
} catch (ShellNotRunningException e) {
e.printStackTrace();
return false;
}
} else
return false;
}
}
}
break;
case DROPBOX:
case BOX:
case ONEDRIVE:
case GDRIVE:
for (int i = 0; i < paths.size(); i++) {
for (HybridFileParcelable baseFile : files.get(i)) {
DataUtils dataUtils = DataUtils.getInstance();
CloudStorage cloudStorage = dataUtils.getAccount(mode);
String targetPath = paths.get(i) + "/" + baseFile.getName();
if (baseFile.getMode() == mode) {
// source and target both in same filesystem, use API method
try {
cloudStorage.move(CloudUtil.stripPath(mode, baseFile.getPath()), CloudUtil.stripPath(mode, targetPath));
} catch (Exception e) {
return false;
}
} else {
// not in same filesystem, execute service
return false;
}
}
}
default:
return false;
}
return true;
}
use of com.amaze.filemanager.filesystem.HybridFileParcelable in project AmazeFileManager by TeamAmaze.
the class CopyService method onStartCommand.
@Override
public int onStartCommand(Intent intent, int flags, final int startId) {
Bundle b = new Bundle();
isRootExplorer = intent.getBooleanExtra(TAG_IS_ROOT_EXPLORER, false);
ArrayList<HybridFileParcelable> files = intent.getParcelableArrayListExtra(TAG_COPY_SOURCES);
String targetPath = intent.getStringExtra(TAG_COPY_TARGET);
int mode = intent.getIntExtra(TAG_COPY_OPEN_MODE, OpenMode.UNKNOWN.ordinal());
final boolean move = intent.getBooleanExtra(TAG_COPY_MOVE, false);
mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
b.putInt(TAG_COPY_START_ID, startId);
Intent notificationIntent = new Intent(this, MainActivity.class);
notificationIntent.setAction(Intent.ACTION_MAIN);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
notificationIntent.putExtra(MainActivity.KEY_INTENT_PROCESS_VIEWER, true);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
mBuilder = new NotificationCompat.Builder(c, NotificationConstants.CHANNEL_NORMAL_ID).setContentIntent(pendingIntent).setContentTitle(getResources().getString(R.string.copying)).setSmallIcon(R.drawable.ic_content_copy_white_36dp);
NotificationConstants.setMetadata(c, mBuilder, NotificationConstants.TYPE_NORMAL);
startForeground(NotificationConstants.COPY_ID, mBuilder.build());
b.putBoolean(TAG_COPY_MOVE, move);
b.putString(TAG_COPY_TARGET, targetPath);
b.putInt(TAG_COPY_OPEN_MODE, mode);
b.putParcelableArrayList(TAG_COPY_SOURCES, files);
// going async
new DoInBackground(isRootExplorer).execute(b);
// If we get killed, after returning from here, restart
return START_STICKY;
}
use of com.amaze.filemanager.filesystem.HybridFileParcelable in project AmazeFileManager by TeamAmaze.
the class ZipService method onStartCommand.
@Override
public int onStartCommand(Intent intent, int flags, final int startId) {
String mZipPath = intent.getStringExtra(KEY_COMPRESS_PATH);
ArrayList<HybridFileParcelable> baseFiles = intent.getParcelableArrayListExtra(KEY_COMPRESS_FILES);
File zipFile = new File(mZipPath);
mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (!zipFile.exists()) {
try {
zipFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
Intent notificationIntent = new Intent(this, MainActivity.class);
notificationIntent.putExtra(MainActivity.KEY_INTENT_PROCESS_VIEWER, true);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
mBuilder = new NotificationCompat.Builder(this, NotificationConstants.CHANNEL_NORMAL_ID).setContentIntent(pendingIntent).setContentTitle(getResources().getString(R.string.compressing)).setSmallIcon(R.drawable.ic_zip_box_grey600_36dp);
NotificationConstants.setMetadata(this, mBuilder, NotificationConstants.TYPE_NORMAL);
startForeground(NotificationConstants.ZIP_ID, mBuilder.build());
asyncTask = new CompressAsyncTask(this, baseFiles, mZipPath);
asyncTask.execute();
// If we get killed, after returning from here, restart
return START_STICKY;
}
use of com.amaze.filemanager.filesystem.HybridFileParcelable in project AmazeFileManager by TeamAmaze.
the class CountItemsOrAndSizeTask method doInBackground.
@Override
protected String doInBackground(Void[] params) {
String items = "";
long fileLength = file.length(context);
if (file.isDirectory(context)) {
final AtomicInteger x = new AtomicInteger(0);
file.forEachChildrenFile(context, false, new OnFileFound() {
@Override
public void onFileFound(HybridFileParcelable file) {
x.incrementAndGet();
}
});
final int folderLength = x.intValue();
long folderSize;
if (isStorage) {
folderSize = file.getUsableSpace();
} else {
folderSize = FileUtils.folderSize(file, new OnProgressUpdate<Long>() {
@Override
public void onUpdate(Long data) {
publishProgress(new Pair<>(folderLength, data));
}
});
}
items = getText(folderLength, folderSize, false);
} else {
items = Formatter.formatFileSize(context, fileLength) + (" (" + fileLength + " " + // truncation is insignificant
context.getResources().getQuantityString(R.plurals.bytes, (int) fileLength) + ")");
}
return items;
}
use of com.amaze.filemanager.filesystem.HybridFileParcelable in project AmazeFileManager by TeamAmaze.
the class MainActivity method onCreate.
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initialisePreferences();
initializeInteractiveShell();
dataUtils.registerOnDataChangedListener(this);
CustomSshJConfig.init();
AppConfig.setActivityContext(con);
setContentView(R.layout.main_toolbar);
appbar = new AppBar(this, getPrefs(), queue -> {
if (!queue.isEmpty()) {
mainActivityHelper.search(getPrefs(), queue);
}
});
initialiseViews();
tabHandler = new TabHandler(this);
utilsHandler = AppConfig.getInstance().getUtilsHandler();
cloudHandler = new CloudHandler(this);
mainActivityHelper = new MainActivityHelper(this);
// TODO: 7/12/2017 not init when actionIntent != null
initialiseFab();
if (CloudSheetFragment.isCloudProviderAvailable(this)) {
getSupportLoaderManager().initLoader(REQUEST_CODE_CLOUD_LIST_KEYS, null, this);
}
path = getIntent().getStringExtra("path");
openProcesses = getIntent().getBooleanExtra(KEY_INTENT_PROCESS_VIEWER, false);
intent = getIntent();
if (intent.getStringArrayListExtra(TAG_INTENT_FILTER_FAILED_OPS) != null) {
ArrayList<HybridFileParcelable> failedOps = intent.getParcelableArrayListExtra(TAG_INTENT_FILTER_FAILED_OPS);
if (failedOps != null) {
mainActivityHelper.showFailedOperationDialog(failedOps, this);
}
}
checkForExternalIntent(intent);
if (savedInstanceState != null) {
drawer.setSomethingSelected(savedInstanceState.getBoolean(KEY_DRAWER_SELECTED));
}
// setting window background color instead of each item, in order to reduce pixel overdraw
if (getAppTheme().equals(AppTheme.LIGHT)) {
/*if(Main.IS_LIST)
getWindow().setBackgroundDrawableResource(android.R.color.white);
else
getWindow().setBackgroundDrawableResource(R.color.grid_background_light);
*/
getWindow().setBackgroundDrawableResource(android.R.color.white);
} else if (getAppTheme().equals(AppTheme.BLACK)) {
getWindow().setBackgroundDrawableResource(android.R.color.black);
} else {
getWindow().setBackgroundDrawableResource(R.color.holo_dark_background);
}
/*findViewById(R.id.drawer_buttton).setOnClickListener(new ImageView.OnClickListener() {
@Override
public void onClick(View view) {
if (mDrawerLayout.isOpen(mDrawerLinear)) {
mDrawerLayout.close(mDrawerLinear);
} else mDrawerLayout.openDrawer(mDrawerLinear);
}
});*/
drawer.setDrawerIndicatorEnabled();
// recents header color implementation
if (SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription("Amaze", ((BitmapDrawable) getResources().getDrawable(R.mipmap.ic_launcher)).getBitmap(), getColorPreference().getColor(ColorUsage.getPrimary(MainActivity.currentTab)));
setTaskDescription(taskDescription);
}
if (!getBoolean(PREFERENCE_BOOKMARKS_ADDED)) {
utilsHandler.addCommonBookmarks();
getPrefs().edit().putBoolean(PREFERENCE_BOOKMARKS_ADDED, true).commit();
}
AppConfig.runInBackground(new AppConfig.CustomAsyncCallbacks() {
@Override
public <E> E doInBackground() {
dataUtils.setHiddenFiles(utilsHandler.getHiddenFilesConcurrentRadixTree());
dataUtils.setHistory(utilsHandler.getHistoryLinkedList());
dataUtils.setGridfiles(utilsHandler.getGridViewList());
dataUtils.setListfiles(utilsHandler.getListViewList());
dataUtils.setBooks(utilsHandler.getBookmarksList());
ArrayList<String[]> servers = new ArrayList<String[]>();
servers.addAll(utilsHandler.getSmbList());
servers.addAll(utilsHandler.getSftpList());
dataUtils.setServers(servers);
return null;
}
@Override
public Void onPostExecute(Object result) {
drawer.refreshDrawer();
if (savedInstanceState == null) {
if (openProcesses) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.content_frame, new ProcessViewerFragment(), KEY_INTENT_PROCESS_VIEWER);
// transaction.addToBackStack(null);
drawer.setSomethingSelected(true);
openProcesses = false;
// title.setText(utils.getString(con, R.string.process_viewer));
// Commit the transaction
transaction.commit();
supportInvalidateOptionsMenu();
} else if (intent.getAction() != null && intent.getAction().equals(TileService.ACTION_QS_TILE_PREFERENCES)) {
// tile preferences, open ftp fragment
FragmentTransaction transaction2 = getSupportFragmentManager().beginTransaction();
transaction2.replace(R.id.content_frame, new FTPServerFragment());
appBarLayout.animate().translationY(0).setInterpolator(new DecelerateInterpolator(2)).start();
drawer.setSomethingSelected(true);
drawer.deselectEverything();
transaction2.commit();
} else {
if (path != null && path.length() > 0) {
HybridFile file = new HybridFile(OpenMode.UNKNOWN, path);
file.generateMode(MainActivity.this);
if (file.isDirectory(MainActivity.this))
goToMain(path);
else {
goToMain(null);
FileUtils.openFile(new File(path), MainActivity.this, getPrefs());
}
} else {
goToMain(null);
}
}
} else {
pasteHelper = savedInstanceState.getParcelable(PASTEHELPER_BUNDLE);
oppathe = savedInstanceState.getString(KEY_OPERATION_PATH);
oppathe1 = savedInstanceState.getString(KEY_OPERATED_ON_PATH);
oparrayList = savedInstanceState.getParcelableArrayList(KEY_OPERATIONS_PATH_LIST);
operation = savedInstanceState.getInt(KEY_OPERATION);
// mainFragment = (Main) savedInstanceState.getParcelable("main_fragment");
}
return null;
}
@Override
public Void onPreExecute() {
return null;
}
@Override
public Void publishResult(Object... result) {
return null;
}
@Override
public <T> T[] params() {
return null;
}
});
}
Aggregations