use of com.amaze.filemanager.filesystem.EditableFileAbstraction.Scheme.FILE in project AmazeFileManager by TeamAmaze.
the class TextEditorActivity method saveFile.
/**
* Method initiates a worker thread which writes the {@link #mInput} bytes to the defined file/uri
* 's output stream
*
* @param editTextString the edit text string
*/
private void saveFile(final String editTextString) {
Toast.makeText(this, R.string.saving, Toast.LENGTH_SHORT).show();
new WriteFileAbstraction(this, getContentResolver(), mFile, editTextString, cacheFile, isRootExplorer(), (errorCode) -> {
switch(errorCode) {
case WriteFileAbstraction.NORMAL:
mOriginal = editTextString;
mModified = false;
invalidateOptionsMenu();
Toast.makeText(getApplicationContext(), getString(R.string.done), Toast.LENGTH_SHORT).show();
break;
case WriteFileAbstraction.EXCEPTION_STREAM_NOT_FOUND:
Toast.makeText(getApplicationContext(), R.string.error_file_not_found, Toast.LENGTH_SHORT).show();
break;
case WriteFileAbstraction.EXCEPTION_IO:
Toast.makeText(getApplicationContext(), R.string.error_io, Toast.LENGTH_SHORT).show();
break;
case WriteFileAbstraction.EXCEPTION_SHELL_NOT_RUNNING:
Toast.makeText(getApplicationContext(), R.string.root_failure, Toast.LENGTH_SHORT).show();
break;
}
}).execute();
}
use of com.amaze.filemanager.filesystem.EditableFileAbstraction.Scheme.FILE in project AmazeFileManager by TeamAmaze.
the class TextEditorActivity method load.
/**
* Initiates loading of file/uri by getting an input stream associated with it on a worker thread
*/
private void load() {
Snackbar.make(scrollView, R.string.loading, Snackbar.LENGTH_SHORT).show();
new ReadFileTask(getContentResolver(), mFile, getExternalCacheDir(), isRootExplorer(), (data) -> {
switch(data.error) {
case ReadFileTask.NORMAL:
cacheFile = data.cachedFile;
mOriginal = data.fileContents;
try {
mInput.setText(data.fileContents);
if (mFile.scheme.equals(FILE) && getExternalCacheDir() != null && mFile.hybridFileParcelable.getPath().contains(getExternalCacheDir().getPath()) && cacheFile == null) {
// file in cache, and not a root temporary file
mInput.setInputType(EditorInfo.TYPE_NULL);
mInput.setSingleLine(false);
mInput.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION);
Snackbar snackbar = Snackbar.make(mInput, getResources().getString(R.string.file_read_only), Snackbar.LENGTH_INDEFINITE);
snackbar.setAction(getResources().getString(R.string.got_it).toUpperCase(), v -> snackbar.dismiss());
snackbar.show();
}
if (data.fileContents.isEmpty()) {
mInput.setHint(R.string.file_empty);
} else {
mInput.setHint(null);
}
} catch (OutOfMemoryError e) {
Toast.makeText(getApplicationContext(), R.string.error, Toast.LENGTH_SHORT).show();
finish();
}
break;
case ReadFileTask.EXCEPTION_STREAM_NOT_FOUND:
Toast.makeText(getApplicationContext(), R.string.error_file_not_found, Toast.LENGTH_SHORT).show();
finish();
break;
case ReadFileTask.EXCEPTION_IO:
Toast.makeText(getApplicationContext(), R.string.error_io, Toast.LENGTH_SHORT).show();
finish();
break;
case ReadFileTask.EXCEPTION_OOM:
Toast.makeText(getApplicationContext(), R.string.error_file_too_large, Toast.LENGTH_SHORT).show();
finish();
break;
}
}).execute();
}
Aggregations