Skip to content

Commit

Permalink
Release 0.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
hajdam committed Sep 27, 2024
1 parent a9e146a commit 3860f62
Show file tree
Hide file tree
Showing 17 changed files with 134 additions and 104 deletions.
6 changes: 6 additions & 0 deletions .idea/appInsightsSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ plugins {
}

android {
compileSdkVersion 34
compileSdk 34
defaultConfig {
applicationId "org.exbin.bined.editor.android"
minSdkVersion 27
targetSdkVersion 34
versionCode 4
versionName "0.2.1-SNAPSHOT"
minSdk 27
targetSdk 34
versionCode 5
versionName "0.2.1"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
buildTypes {
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="true"
android:icon="@mipmap/bined"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
tools:targetApi="34">
<activity
android:name=".SettingsActivity"
android:exported="false"
Expand All @@ -29,6 +31,6 @@

<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="33" />
android:maxSdkVersion="32" />

</manifest>
155 changes: 82 additions & 73 deletions app/src/main/java/org/exbin/bined/editor/android/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.os.Build;
import android.os.Bundle;
import android.os.LocaleList;
import android.provider.DocumentsContract;
import android.text.Editable;
import android.text.InputType;
import android.text.method.KeyListener;
Expand Down Expand Up @@ -81,6 +82,7 @@
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.nio.charset.Charset;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -119,8 +121,10 @@ public class MainActivity extends AppCompatActivity {
private Menu menu;
private static ByteArrayEditableData fileData = null;
private Uri currentFileUri = null;
private Uri pickerInitialUri = null;
private final BinaryStatusHandler binaryStatus = new BinaryStatusHandler(this);
private BinarySearchService searchService;
private Runnable postSaveAsAction = null;
private final BinarySearchService.SearchStatusListener searchStatusListener = new BinarySearchService.SearchStatusListener() {
@Override
public void setStatus(BinarySearchService.FoundMatches foundMatches, SearchParameters.MatchMode matchMode) {
Expand Down Expand Up @@ -319,33 +323,10 @@ public boolean onCreateOptionsMenu(Menu menu) {
codeArea.addSelectionChangedListener(this::updateEditActionsState);
updateEditActionsState();

menu.findItem(R.id.code_colorization).setChecked(appPreferences.getCodeAreaPreferences().isCodeColorization());
int bytesPerRow = appPreferences.getCodeAreaPreferences().getMaxBytesPerRow();
switch (bytesPerRow) {
case 0: {
menu.findItem(R.id.bytes_per_row_fill).setChecked(true);
break;
}
case 4: {
menu.findItem(R.id.bytes_per_row_4).setChecked(true);
break;
}
case 8: {
menu.findItem(R.id.bytes_per_row_8).setChecked(true);
break;
}
case 12: {
menu.findItem(R.id.bytes_per_row_12).setChecked(true);
break;
}
case 16: {
menu.findItem(R.id.bytes_per_row_16).setChecked(true);
break;
}
}
updateViewActionsState();

MenuItem searchMenuItem = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView) searchMenuItem.getActionView();
SearchView searchView = Objects.requireNonNull((SearchView) searchMenuItem.getActionView());
searchView.setSubmitButtonEnabled(true);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
Expand All @@ -371,9 +352,9 @@ public boolean onQueryTextChange(String newText) {
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuItem selectionStartMenuItem = menu.add(0, SELECTION_START_POPUP_ID, 0, getResources().getString(R.string.action_selection_start));
MenuItem selectionEndMenuItem = menu.add(0, SELECTION_END_POPUP_ID, 1, getResources().getString(R.string.action_selection_end));
MenuItem clearSelectionMenuItem = menu.add(0, CLEAR_SELECTION_POPUP_ID, 2, getResources().getString(R.string.action_clear_selection));
menu.add(0, SELECTION_START_POPUP_ID, 0, getResources().getString(R.string.action_selection_start));
menu.add(0, SELECTION_END_POPUP_ID, 1, getResources().getString(R.string.action_selection_end));
menu.add(0, CLEAR_SELECTION_POPUP_ID, 2, getResources().getString(R.string.action_clear_selection));
MenuItem cutMenuItem = menu.add(1, CUT_ACTION_POPUP_ID, 3, getResources().getString(R.string.action_cut));
cutMenuItem.setEnabled(codeArea.isEditable() && codeArea.hasSelection());
MenuItem copyMenuItem = menu.add(1, COPY_ACTION_POPUP_ID, 4, getResources().getString(R.string.action_copy));
Expand All @@ -384,7 +365,7 @@ public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMen
menu.add(1, PASTE_FROM_CODE_ACTION_POPUP_ID, 5, getResources().getString(R.string.action_paste_from_code));
MenuItem deleteMenuItem = menu.add(1, DELETE_ACTION_POPUP_ID, 7, getResources().getString(R.string.action_delete));
deleteMenuItem.setEnabled(codeArea.isEditable() && codeArea.hasSelection());
MenuItem selectAllMenuItem = menu.add(1, SELECT_ALL_ACTION_POPUP_ID, 8, getResources().getString(R.string.action_select_all));
menu.add(1, SELECT_ALL_ACTION_POPUP_ID, 8, getResources().getString(R.string.action_select_all));
}

@Override
Expand Down Expand Up @@ -459,33 +440,30 @@ public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();

if (id == R.id.action_new) {
releaseFile(successful -> {
if (successful) {
codeArea.setContentData(new ByteArrayEditableData());
undoRedo.clear();
releaseFile(() -> {
codeArea.setContentData(new ByteArrayEditableData());
undoRedo.clear();
currentFileUri = null;

documentOriginalSize = 0;
}
documentOriginalSize = 0;
});

return true;
} else if (id == R.id.action_open) {
releaseFile(successful -> {
if (successful) {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
intent.putExtra(Intent.EXTRA_LOCALE_LIST, getLanguageLocaleList());
}

// Optionally, specify a URI for the file that should appear in the
// system file picker when it loads.
// intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, pickerInitialUri);
releaseFile(() -> {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
intent.putExtra(Intent.EXTRA_LOCALE_LIST, getLanguageLocaleList());
}

// startActivityForResult(intent, 1);
openFileLauncher.launch(Intent.createChooser(intent, getResources().getString(R.string.select_file)));
if (pickerInitialUri != null) {
intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, pickerInitialUri);
}

// startActivityForResult(intent, 1);
openFileLauncher.launch(Intent.createChooser(intent, getResources().getString(R.string.select_file)));
});

return true;
Expand Down Expand Up @@ -513,10 +491,8 @@ public boolean onOptionsItemSelected(MenuItem item) {

return true;
} else if (id == R.id.action_exit) {
releaseFile(successful -> {
if (successful) {
System.exit(0);
}
releaseFile(() -> {
System.exit(0);
});

return true;
Expand Down Expand Up @@ -660,39 +636,47 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}

public void releaseFile(PostReleaseAction postReleaseAction) {
public void releaseFile(Runnable postReleaseAction) {
if (!undoRedo.isModified()) {
postReleaseAction.released(true);
postReleaseAction.run();
return;
}

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.file_modified);
builder.setPositiveButton(R.string.button_save, (dialog, which) -> {
saveFile(currentFileUri);
postReleaseAction.released(true);
if (currentFileUri == null) {
saveAs();
} else {
saveFile(currentFileUri);
}
postReleaseAction.run();
});
builder.setNeutralButton(R.string.button_discard, (dialog, which) -> {
postReleaseAction.released(true);
});
builder.setNegativeButton(R.string.button_cancel, (dialog, which) -> {
postReleaseAction.released(false);
postReleaseAction.run();
});
builder.setNegativeButton(R.string.button_cancel, null);
AlertDialog alertDialog = builder.create();
alertDialog.show();
}

public void saveAs() {
saveAs(null);
}

public void saveAs(@Nullable Runnable postSaveAsAction) {
this.postSaveAsAction = postSaveAsAction;

Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
intent.putExtra(Intent.EXTRA_LOCALE_LIST, getLanguageLocaleList());
}

// Optionally, specify a URI for the file that should appear in the
// system file picker when it loads.
// intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, pickerInitialUri);
if (pickerInitialUri != null) {
intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, pickerInitialUri);
}

saveFileLauncher.launch(Intent.createChooser(intent, getResources().getString(R.string.save_as_file)));
}
Expand All @@ -710,6 +694,7 @@ public void openFile(Uri fileUri) {
undoRedo.clear();
codeArea.setContentData(fileData);
currentFileUri = fileUri;
pickerInitialUri = fileUri;
} catch (IOException ex) {
Logger.getLogger(MainActivity.class.getName()).log(Level.SEVERE, null, ex);
}
Expand All @@ -727,6 +712,7 @@ public void saveFile(Uri fileUri) {
documentOriginalSize = contentData.getDataSize();
undoRedo.setSyncPosition();
currentFileUri = fileUri;
pickerInitialUri = fileUri;
} catch (IOException ex) {
Logger.getLogger(MainActivity.class.getName()).log(Level.SEVERE, null, ex);
}
Expand Down Expand Up @@ -846,6 +832,33 @@ private void updateEditActionsState() {
deleteMenuItem.setEnabled(codeArea.isEditable() && codeArea.hasSelection());
}

private void updateViewActionsState() {
menu.findItem(R.id.code_colorization).setChecked(appPreferences.getCodeAreaPreferences().isCodeColorization());
int bytesPerRow = appPreferences.getCodeAreaPreferences().getMaxBytesPerRow();
switch (bytesPerRow) {
case 0: {
menu.findItem(R.id.bytes_per_row_fill).setChecked(true);
break;
}
case 4: {
menu.findItem(R.id.bytes_per_row_4).setChecked(true);
break;
}
case 8: {
menu.findItem(R.id.bytes_per_row_8).setChecked(true);
break;
}
case 12: {
menu.findItem(R.id.bytes_per_row_12).setChecked(true);
break;
}
case 16: {
menu.findItem(R.id.bytes_per_row_16).setChecked(true);
break;
}
}
}

private void updateUndoState() {
MenuItem saveMenuItem = menu.findItem(R.id.action_save);
saveMenuItem.setEnabled(currentFileUri == null || undoRedo.isModified());
Expand Down Expand Up @@ -878,15 +891,15 @@ private void saveFileResultCallback(ActivityResult activityResult) {
}

saveFile(data.getData());
if (postSaveAsAction != null) {
postSaveAsAction.run();
postSaveAsAction = null;
}
}

private void settingsResultCallback(ActivityResult activityResult) {
int resultCode = activityResult.getResultCode();
if (resultCode != MainActivity.RESULT_OK) {
return;
}

applySettings();
updateViewActionsState();
}

public void buttonAction0(View view) {
Expand Down Expand Up @@ -992,8 +1005,4 @@ public void buttonActionBk(View view) {
public void buttonActionTab(View view) {
codeArea.getCommandHandler().keyPressed(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_TAB));
}

public interface PostReleaseAction {
void released(boolean successful);
}
}
Loading

0 comments on commit 3860f62

Please sign in to comment.