Search in sources :

Example 1 with EditableFileAbstraction

use of com.amaze.filemanager.filesystem.EditableFileAbstraction in project AmazeFileManager by TeamAmaze.

the class TextEditorActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (getAppTheme().equals(AppTheme.DARK))
        getWindow().getDecorView().setBackgroundColor(Utils.getColor(this, R.color.holo_dark_background));
    else if (getAppTheme().equals(AppTheme.BLACK))
        getWindow().getDecorView().setBackgroundColor(Utils.getColor(this, android.R.color.black));
    setContentView(R.layout.search);
    searchViewLayout = findViewById(R.id.searchview);
    toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    toolbar.setBackgroundColor(getColorPreference().getColor(ColorUsage.getPrimary(MainActivity.currentTab)));
    searchViewLayout.setBackgroundColor(getColorPreference().getColor(ColorUsage.getPrimary(MainActivity.currentTab)));
    if (Build.VERSION.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);
    }
    searchEditText = searchViewLayout.findViewById(R.id.search_box);
    upButton = searchViewLayout.findViewById(R.id.prev);
    downButton = searchViewLayout.findViewById(R.id.next);
    closeButton = searchViewLayout.findViewById(R.id.close);
    searchEditText.addTextChangedListener(this);
    upButton.setOnClickListener(this);
    // upButton.setEnabled(false);
    downButton.setOnClickListener(this);
    // downButton.setEnabled(false);
    closeButton.setOnClickListener(this);
    getSupportActionBar().setBackgroundDrawable(getColorPreference().getDrawable(ColorUsage.getPrimary(MainActivity.currentTab)));
    boolean useNewStack = getBoolean(PREFERENCE_TEXTEDITOR_NEWSTACK);
    getSupportActionBar().setDisplayHomeAsUpEnabled(!useNewStack);
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT_WATCH || Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
        SystemBarTintManager tintManager = new SystemBarTintManager(this);
        tintManager.setStatusBarTintEnabled(true);
        tintManager.setStatusBarTintColor(getColorPreference().getColor(ColorUsage.getPrimary(MainActivity.currentTab)));
        FrameLayout.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) findViewById(R.id.texteditor).getLayoutParams();
        SystemBarTintManager.SystemBarConfig config = tintManager.getConfig();
        p.setMargins(0, config.getStatusBarHeight(), 0, 0);
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        boolean colourednavigation = getBoolean(PREFERENCE_COLORED_NAVIGATION);
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.setStatusBarColor(PreferenceUtils.getStatusColor(getColorPreference().getColorAsString(ColorUsage.getPrimary(MainActivity.currentTab))));
        if (colourednavigation)
            window.setNavigationBarColor(PreferenceUtils.getStatusColor(getColorPreference().getColorAsString(ColorUsage.getPrimary(MainActivity.currentTab))));
    }
    mInput = findViewById(R.id.fname);
    scrollView = findViewById(R.id.editscroll);
    final Uri uri = getIntent().getData();
    if (uri != null) {
        try {
            mFile = new EditableFileAbstraction(this, uri);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            Toast.makeText(this, R.string.no_file_error, Toast.LENGTH_LONG).show();
            finish();
        }
    } else {
        Toast.makeText(this, R.string.no_file_error, Toast.LENGTH_LONG).show();
        finish();
    }
    getSupportActionBar().setTitle(mFile.name);
    mInput.addTextChangedListener(this);
    if (getAppTheme().equals(AppTheme.DARK))
        mInput.setBackgroundColor(Utils.getColor(this, R.color.holo_dark_background));
    else if (getAppTheme().equals(AppTheme.BLACK))
        mInput.setBackgroundColor(Utils.getColor(this, android.R.color.black));
    mInputTypefaceDefault = mInput.getTypeface();
    mInputTypefaceMono = Typeface.MONOSPACE;
    if (savedInstanceState != null) {
        mOriginal = savedInstanceState.getString(KEY_ORIGINAL_TEXT);
        int index = savedInstanceState.getInt(KEY_INDEX);
        mInput.setText(savedInstanceState.getString(KEY_MODIFIED_TEXT));
        mInput.setScrollY(index);
        if (savedInstanceState.getBoolean(KEY_MONOFONT))
            mInput.setTypeface(mInputTypefaceMono);
    } else {
        load();
    }
}
Also used : Window(android.view.Window) FileNotFoundException(java.io.FileNotFoundException) SystemBarTintManager(com.readystatesoftware.systembartint.SystemBarTintManager) ActivityManager(android.app.ActivityManager) Uri(android.net.Uri) EditableFileAbstraction(com.amaze.filemanager.filesystem.EditableFileAbstraction) FrameLayout(android.widget.FrameLayout)

Example 2 with EditableFileAbstraction

use of com.amaze.filemanager.filesystem.EditableFileAbstraction in project AmazeFileManager by TeamAmaze.

the class TextEditorActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.search);
    toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    searchViewLayout = findViewById(R.id.searchview);
    searchViewLayout.setBackgroundColor(getPrimary());
    searchEditText = searchViewLayout.findViewById(R.id.search_box);
    upButton = searchViewLayout.findViewById(R.id.prev);
    downButton = searchViewLayout.findViewById(R.id.next);
    closeButton = searchViewLayout.findViewById(R.id.close);
    searchEditText.addTextChangedListener(this);
    upButton.setOnClickListener(this);
    // upButton.setEnabled(false);
    downButton.setOnClickListener(this);
    // downButton.setEnabled(false);
    closeButton.setOnClickListener(this);
    boolean useNewStack = getBoolean(PREFERENCE_TEXTEDITOR_NEWSTACK);
    getSupportActionBar().setDisplayHomeAsUpEnabled(!useNewStack);
    mInput = findViewById(R.id.fname);
    scrollView = findViewById(R.id.editscroll);
    final Uri uri = getIntent().getData();
    if (uri != null) {
        mFile = new EditableFileAbstraction(this, uri);
    } else {
        Toast.makeText(this, R.string.no_file_error, Toast.LENGTH_LONG).show();
        finish();
        return;
    }
    getSupportActionBar().setTitle(mFile.name);
    mInput.addTextChangedListener(this);
    if (getAppTheme().equals(AppTheme.DARK))
        mInput.setBackgroundColor(Utils.getColor(this, R.color.holo_dark_background));
    else if (getAppTheme().equals(AppTheme.BLACK))
        mInput.setBackgroundColor(Utils.getColor(this, android.R.color.black));
    if (mInput.getTypeface() == null)
        mInput.setTypeface(Typeface.DEFAULT);
    mInputTypefaceDefault = mInput.getTypeface();
    mInputTypefaceMono = Typeface.MONOSPACE;
    if (savedInstanceState != null) {
        mOriginal = savedInstanceState.getString(KEY_ORIGINAL_TEXT);
        int index = savedInstanceState.getInt(KEY_INDEX);
        mInput.setText(savedInstanceState.getString(KEY_MODIFIED_TEXT));
        mInput.setScrollY(index);
        if (savedInstanceState.getBoolean(KEY_MONOFONT))
            mInput.setTypeface(mInputTypefaceMono);
    } else {
        load();
    }
    initStatusBarResources(findViewById(R.id.texteditor));
}
Also used : Uri(android.net.Uri) EditableFileAbstraction(com.amaze.filemanager.filesystem.EditableFileAbstraction)

Example 3 with EditableFileAbstraction

use of com.amaze.filemanager.filesystem.EditableFileAbstraction in project AmazeFileManager by TeamAmaze.

the class WriteFileAbstractionTest method testWriteFileRootShellNotRunning.

@Test
@Config(shadows = { ShellNotRunningRootUtils.class })
public void testWriteFileRootShellNotRunning() throws IOException {
    File file = new File(Environment.getExternalStorageDirectory(), "test.txt");
    Uri uri = Uri.fromFile(file);
    File cacheFile = File.createTempFile("test.txt", "cache");
    cacheFile.deleteOnExit();
    Context ctx = ApplicationProvider.getApplicationContext();
    ContentResolver cr = ctx.getContentResolver();
    WriteFileAbstraction task = new WriteFileAbstraction(ctx, cr, new EditableFileAbstraction(ctx, uri), contents, cacheFile, true, null);
    int result = task.doInBackground();
    assertEquals(EXCEPTION_SHELL_NOT_RUNNING, result);
}
Also used : Context(android.content.Context) File(java.io.File) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver) EditableFileAbstraction(com.amaze.filemanager.filesystem.EditableFileAbstraction) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 4 with EditableFileAbstraction

use of com.amaze.filemanager.filesystem.EditableFileAbstraction in project AmazeFileManager by TeamAmaze.

the class WriteFileAbstractionTest method testWriteFileOverwriting.

@Test
public void testWriteFileOverwriting() throws IOException {
    File file = new File(Environment.getExternalStorageDirectory(), "test.txt");
    IoUtils.copy(new StringReader("Dummy test content"), new FileWriter(file), 1024);
    Uri uri = Uri.fromFile(file);
    Context ctx = ApplicationProvider.getApplicationContext();
    ContentResolver cr = ctx.getContentResolver();
    WriteFileAbstraction task = new WriteFileAbstraction(ctx, cr, new EditableFileAbstraction(ctx, uri), contents, null, false, null);
    int result = task.doInBackground();
    assertEquals(NORMAL, result);
    String verify = IoUtils.readFully(new FileInputStream(file));
    assertEquals(contents, verify);
}
Also used : Context(android.content.Context) FileWriter(java.io.FileWriter) StringReader(java.io.StringReader) File(java.io.File) Uri(android.net.Uri) FileInputStream(java.io.FileInputStream) ContentResolver(android.content.ContentResolver) EditableFileAbstraction(com.amaze.filemanager.filesystem.EditableFileAbstraction) Test(org.junit.Test)

Example 5 with EditableFileAbstraction

use of com.amaze.filemanager.filesystem.EditableFileAbstraction in project AmazeFileManager by TeamAmaze.

the class WriteFileAbstractionTest method testWriteBogeyUri.

@Test(expected = IllegalArgumentException.class)
public void testWriteBogeyUri() {
    Uri uri = Uri.parse("ftp://bogey.ftp/test.txt");
    Context ctx = ApplicationProvider.getApplicationContext();
    ContentResolver cr = ctx.getContentResolver();
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    shadowOf(cr).registerOutputStream(uri, bout);
    WriteFileAbstraction task = new WriteFileAbstraction(ctx, cr, new EditableFileAbstraction(ctx, uri), contents, null, false, null);
    task.doInBackground();
}
Also used : Context(android.content.Context) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver) EditableFileAbstraction(com.amaze.filemanager.filesystem.EditableFileAbstraction) Test(org.junit.Test)

Aggregations

Uri (android.net.Uri)10 EditableFileAbstraction (com.amaze.filemanager.filesystem.EditableFileAbstraction)10 ContentResolver (android.content.ContentResolver)8 Context (android.content.Context)8 Test (org.junit.Test)8 File (java.io.File)6 Config (org.robolectric.annotation.Config)4 FileInputStream (java.io.FileInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ActivityManager (android.app.ActivityManager)1 Window (android.view.Window)1 FrameLayout (android.widget.FrameLayout)1 SystemBarTintManager (com.readystatesoftware.systembartint.SystemBarTintManager)1 FileNotFoundException (java.io.FileNotFoundException)1 FileWriter (java.io.FileWriter)1 StringReader (java.io.StringReader)1