Search in sources :

Example 1 with ReadFileTask

use of com.amaze.filemanager.asynchronous.asynctasks.ReadFileTask 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.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;
        }
    }).execute();
}
Also used : ImageButton(android.widget.ImageButton) Bundle(android.os.Bundle) PreferencesConstants(com.amaze.filemanager.fragments.preference_fragments.PreferencesConstants) ColorUsage(com.amaze.filemanager.utils.color.ColorUsage) Uri(android.net.Uri) WindowManager(android.view.WindowManager) FrameLayout(android.widget.FrameLayout) Timer(java.util.Timer) Animator(android.animation.Animator) ThemedActivity(com.amaze.filemanager.activities.superclasses.ThemedActivity) AppTheme(com.amaze.filemanager.utils.theme.AppTheme) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) Map(java.util.Map) View(android.view.View) TimerTask(java.util.TimerTask) GeneralDialogCreation(com.amaze.filemanager.ui.dialogs.GeneralDialogCreation) ObjectAnimator(android.animation.ObjectAnimator) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ViewAnimationUtils(android.view.ViewAnimationUtils) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) DisplayMetrics(android.util.DisplayMetrics) ViewGroup(android.view.ViewGroup) FileNotFoundException(java.io.FileNotFoundException) RelativeLayout(android.widget.RelativeLayout) MapEntry(com.amaze.filemanager.utils.MapEntry) R(com.amaze.filemanager.R) PREFERENCE_COLORED_NAVIGATION(com.amaze.filemanager.fragments.preference_fragments.PreferencesConstants.PREFERENCE_COLORED_NAVIGATION) Snackbar(android.support.design.widget.Snackbar) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Window(android.view.Window) EditorInfo(android.view.inputmethod.EditorInfo) PREFERENCE_TEXTEDITOR_NEWSTACK(com.amaze.filemanager.fragments.preference_fragments.PreferencesConstants.PREFERENCE_TEXTEDITOR_NEWSTACK) TextWatcher(android.text.TextWatcher) Typeface(android.graphics.Typeface) ActivityManager(android.app.ActivityManager) Context(android.content.Context) Spanned(android.text.Spanned) Editable(android.text.Editable) MenuItem(android.view.MenuItem) InputMethodManager(android.view.inputmethod.InputMethodManager) ArrayList(java.util.ArrayList) Toast(android.widget.Toast) PreferenceUtils(com.amaze.filemanager.utils.PreferenceUtils) Menu(android.view.Menu) SystemBarTintManager(com.readystatesoftware.systembartint.SystemBarTintManager) Build(android.os.Build) WriteFileAbstraction(com.amaze.filemanager.asynchronous.asynctasks.WriteFileAbstraction) ReadFileTask(com.amaze.filemanager.asynchronous.asynctasks.ReadFileTask) EditableFileAbstraction(com.amaze.filemanager.filesystem.EditableFileAbstraction) SearchTextTask(com.amaze.filemanager.asynchronous.asynctasks.SearchTextTask) BackgroundColorSpan(android.text.style.BackgroundColorSpan) File(java.io.File) Color(android.graphics.Color) Utils(com.amaze.filemanager.utils.Utils) ScrollView(android.widget.ScrollView) FileUtils(com.amaze.filemanager.utils.files.FileUtils) EditText(android.widget.EditText) ReadFileTask(com.amaze.filemanager.asynchronous.asynctasks.ReadFileTask) Snackbar(android.support.design.widget.Snackbar)

Example 2 with ReadFileTask

use of com.amaze.filemanager.asynchronous.asynctasks.ReadFileTask 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();
}
Also used : ImageButton(android.widget.ImageButton) CONTENT(com.amaze.filemanager.filesystem.EditableFileAbstraction.Scheme.CONTENT) Bundle(android.os.Bundle) Uri(android.net.Uri) Timer(java.util.Timer) Animator(android.animation.Animator) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) PREFERENCE_TEXTEDITOR_NEWSTACK(com.amaze.filemanager.ui.fragments.preference_fragments.PreferencesConstants.PREFERENCE_TEXTEDITOR_NEWSTACK) Map(java.util.Map) View(android.view.View) TimerTask(java.util.TimerTask) GeneralDialogCreation(com.amaze.filemanager.ui.dialogs.GeneralDialogCreation) ObjectAnimator(android.animation.ObjectAnimator) ViewAnimationUtils(android.view.ViewAnimationUtils) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) FileUtils(com.amaze.filemanager.filesystem.files.FileUtils) DisplayMetrics(android.util.DisplayMetrics) RelativeLayout(android.widget.RelativeLayout) MapEntry(com.amaze.filemanager.utils.MapEntry) R(com.amaze.filemanager.R) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) AppTheme(com.amaze.filemanager.ui.theme.AppTheme) Snackbar(com.google.android.material.snackbar.Snackbar) EditorInfo(android.view.inputmethod.EditorInfo) TextWatcher(android.text.TextWatcher) Typeface(android.graphics.Typeface) Context(android.content.Context) Spanned(android.text.Spanned) OpenMode(com.amaze.filemanager.file_operations.filesystem.OpenMode) Editable(android.text.Editable) ArrayList(java.util.ArrayList) MenuItem(android.view.MenuItem) InputMethodManager(android.view.inputmethod.InputMethodManager) HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) Toast(android.widget.Toast) Menu(android.view.Menu) Build(android.os.Build) WriteFileAbstraction(com.amaze.filemanager.asynchronous.asynctasks.WriteFileAbstraction) ReadFileTask(com.amaze.filemanager.asynchronous.asynctasks.ReadFileTask) EditableFileAbstraction(com.amaze.filemanager.filesystem.EditableFileAbstraction) SearchTextTask(com.amaze.filemanager.asynchronous.asynctasks.SearchTextTask) BackgroundColorSpan(android.text.style.BackgroundColorSpan) File(java.io.File) Color(android.graphics.Color) Utils(com.amaze.filemanager.utils.Utils) ScrollView(android.widget.ScrollView) ThemedActivity(com.amaze.filemanager.ui.activities.superclasses.ThemedActivity) FILE(com.amaze.filemanager.filesystem.EditableFileAbstraction.Scheme.FILE) EditText(android.widget.EditText) ReadFileTask(com.amaze.filemanager.asynchronous.asynctasks.ReadFileTask) Snackbar(com.google.android.material.snackbar.Snackbar)

Aggregations

Animator (android.animation.Animator)2 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)2 ObjectAnimator (android.animation.ObjectAnimator)2 Context (android.content.Context)2 Color (android.graphics.Color)2 Typeface (android.graphics.Typeface)2 Uri (android.net.Uri)2 Build (android.os.Build)2 Bundle (android.os.Bundle)2 Editable (android.text.Editable)2 Spanned (android.text.Spanned)2 TextWatcher (android.text.TextWatcher)2 BackgroundColorSpan (android.text.style.BackgroundColorSpan)2 DisplayMetrics (android.util.DisplayMetrics)2 Menu (android.view.Menu)2 MenuItem (android.view.MenuItem)2 View (android.view.View)2 ViewAnimationUtils (android.view.ViewAnimationUtils)2 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)2 EditorInfo (android.view.inputmethod.EditorInfo)2