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();
}
}
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));
}
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);
}
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);
}
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();
}
Aggregations