diff --git a/ReadMe.txt b/ReadMe.txt index b61bf2e..7c47e2f 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -169,6 +169,7 @@ The Eric's Real scripts ("real*.kml" and "real*.bmp/png") are embedded in this a TODO - Autosave only works once a manual save has been done (William Hostman from comment). + SO, INVITE TO SAVE JUST AFTER THE NEW TO PREVENT TO LOOSE EVERYTHING - Add the name of the file in the toast "State saved". - The clock seems unsynchronized sometimes. - Retain a key by right clicking if it is from a mouse. @@ -183,7 +184,7 @@ TODO BUILD -Emu48 for Android is built with Android Studio 3.4 (2019). +Emu48 for Android is built with Android Studio 3.5 (2019). And to generate an installable APK file with a real Android device, it MUST be signed. Either use Android Studio: diff --git a/app/build.gradle b/app/build.gradle index 1f5a5df..6a8ad18 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -80,13 +80,13 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'androidx.appcompat:appcompat:1.1.0-rc01' - implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2' - implementation 'androidx.preference:preference:1.1.0-rc01' - implementation 'com.google.android.material:material:1.1.0-alpha08' + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta3' + implementation 'androidx.preference:preference:1.1.0' + implementation 'com.google.android.material:material:1.2.0-alpha02' implementation 'androidx.legacy:legacy-support-v4:1.0.0' - testImplementation 'junit:junit:4.13-beta-3' - androidTestImplementation 'androidx.test:runner:1.3.0-alpha01' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha01' implementation 'androidx.viewpager:viewpager:1.0.0' + testImplementation 'junit:junit:4.13-beta-3' + androidTestImplementation 'androidx.test:runner:1.3.0-alpha02' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha02' } diff --git a/app/src/main/java/org/emulator/calculator/LCDOverlappingView.java b/app/src/main/java/org/emulator/calculator/LCDOverlappingView.java index b6768ba..693daff 100644 --- a/app/src/main/java/org/emulator/calculator/LCDOverlappingView.java +++ b/app/src/main/java/org/emulator/calculator/LCDOverlappingView.java @@ -219,8 +219,6 @@ public class LCDOverlappingView extends View { protected void onDraw(Canvas canvas) { //if(debug) Log.d(TAG, "onDraw()"); - //canvas.drawColor(Color.RED); - if(this.overlappingLCDMode != OVERLAPPING_LCD_MODE_NONE && bitmapLCD != null) { int x = NativeLib.getScreenPositionX(); int y = NativeLib.getScreenPositionY(); @@ -304,8 +302,10 @@ public class LCDOverlappingView extends View { firstTime = false; post(() -> { float scale = sharedPreferences.getFloat("settings_lcd_overlapping_scale", 1.0f); - if (scale < 0.01f) - scale = 0.01f; + if (scale < 0.5f) + scale = 0.5f; + if (scale > 20.0f) + scale = 20.0f; int viewWidth = (int) (lcdWidth * scale); int viewHeight = (int) (lcdHeight * scale); if (viewWidth < minViewSize && viewHeight < minViewSize) { diff --git a/app/src/main/java/org/emulator/calculator/Utils.java b/app/src/main/java/org/emulator/calculator/Utils.java index 56fd74b..7030c54 100644 --- a/app/src/main/java/org/emulator/calculator/Utils.java +++ b/app/src/main/java/org/emulator/calculator/Utils.java @@ -15,8 +15,10 @@ package org.emulator.calculator; import android.content.Context; +import android.content.Intent; import android.database.Cursor; import android.net.Uri; +import android.os.Build; import android.provider.OpenableColumns; import android.util.Log; import android.view.View; @@ -63,6 +65,17 @@ public class Utils { return -1; } + public static void makeUriPersistable(Context context, Intent data, Uri uri) { + int takeFlags = data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) + context.getContentResolver().takePersistableUriPermission(uri, takeFlags); + } + public static void makeUriPersistableReadOnly(Context context, Intent data, Uri uri) { + int takeFlags = data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) + context.getContentResolver().takePersistableUriPermission(uri, takeFlags); + } + public static String getFileName(Context context, String url) { String result = null; try { diff --git a/app/src/main/java/org/emulator/forty/eight/MainActivity.java b/app/src/main/java/org/emulator/forty/eight/MainActivity.java index 1deff17..ea56577 100644 --- a/app/src/main/java/org/emulator/forty/eight/MainActivity.java +++ b/app/src/main/java/org/emulator/forty/eight/MainActivity.java @@ -233,7 +233,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On if(onFileOpen(documentToOpenUrl) != 0) { saveLastDocument(documentToOpenUrl); if(intent != null && documentToOpenUri != null) - makeUriPersistable(intent, documentToOpenUri); + Utils.makeUriPersistable(this, intent, documentToOpenUri); } } catch (Exception e) { Log.e(TAG, e.getMessage()); @@ -1029,7 +1029,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On int openResult = onFileOpen(url); if (openResult > 0) { saveLastDocument(url); - makeUriPersistable(data, uri); + Utils.makeUriPersistable(this, data, uri); } else if(openResult == -2 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // >= API 21 // For security reason, you must select the folder where are the KML and ROM files and then, reopen this file! new AlertDialog.Builder(this) @@ -1047,7 +1047,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On if (NativeLib.onFileSaveAs(url) != 0) { showAlert(getString(R.string.message_state_saved)); saveLastDocument(url); - makeUriPersistable(data, uri); + Utils.makeUriPersistable(this, data, uri); displayFilename(url); if (fileSaveAsCallback != null) fileSaveAsCallback.run(); @@ -1074,7 +1074,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On editor.putString("settings_kml_folder", url); editor.apply(); updateFromPreferences("settings_kml", true); - makeUriPersistableReadOnly(data, uri); + Utils.makeUriPersistableReadOnly(this, data, uri); switch (requestCode) { case INTENT_PICK_KML_FOLDER_FOR_NEW_FILE: @@ -1153,17 +1153,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On navigationView.post(this::updateMRU); } - private void makeUriPersistable(Intent data, Uri uri) { - int takeFlags = data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) - getContentResolver().takePersistableUriPermission(uri, takeFlags); - } - private void makeUriPersistableReadOnly(Intent data, Uri uri) { - int takeFlags = data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) - getContentResolver().takePersistableUriPermission(uri, takeFlags); - } - private void showCalculatorView(boolean show) { if(show) { mainScreenView.setEnablePanAndScale(true); diff --git a/app/src/main/java/org/emulator/forty/eight/SettingsActivity.java b/app/src/main/java/org/emulator/forty/eight/SettingsActivity.java index 753e63c..591a3c8 100644 --- a/app/src/main/java/org/emulator/forty/eight/SettingsActivity.java +++ b/app/src/main/java/org/emulator/forty/eight/SettingsActivity.java @@ -15,21 +15,30 @@ package org.emulator.forty.eight; import android.app.Activity; +import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; +import android.content.res.Configuration; import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.text.InputType; import android.view.MenuItem; +import android.widget.EditText; +import android.widget.LinearLayout; import java.util.HashSet; +import java.util.Locale; +import java.util.Objects; import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; +import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceManager; +import androidx.preference.SeekBarPreference; import org.emulator.calculator.NativeLib; import org.emulator.calculator.Utils; @@ -105,15 +114,34 @@ public class SettingsActivity extends AppCompatActivity implements SharedPrefere // Sound settings -// Preference preferenceAllowSound = findPreference("settings_allow_sound"); -// if(preferenceAllowSound != null && !NativeLib.getSoundEnabled()) { -// preferenceAllowSound.setSummary("Cannot initialize the sound engine."); -// preferenceAllowSound.setEnabled(false); -// } - Preference preferenceSoundVolume = findPreference("settings_sound_volume"); - if(preferenceSoundVolume != null && !NativeLib.getSoundEnabled()) { - preferenceSoundVolume.setSummary("Cannot initialize the sound engine."); - preferenceSoundVolume.setEnabled(false); + SeekBarPreference preferenceSoundVolume = findPreference("settings_sound_volume"); + if(preferenceSoundVolume != null) { + if(!NativeLib.getSoundEnabled()) { + preferenceSoundVolume.setSummary("Cannot initialize the sound engine."); + preferenceSoundVolume.setEnabled(false); + } else { + preferenceSoundVolume.setOnPreferenceClickListener(preference -> { + AlertDialog.Builder alert = new AlertDialog.Builder(Objects.requireNonNull(getContext())); + alert.setTitle(R.string.settings_sound_volume_dialog_title); + final EditText input = new EditText(getContext()); + input.setInputType(InputType.TYPE_CLASS_NUMBER); + input.setRawInputType(Configuration.KEYBOARD_12KEY); + input.setFocusable(true); + input.setText(String.format(Locale.US,"%d", preferenceSoundVolume.getValue())); + alert.setView(input); + alert.setPositiveButton(R.string.message_ok, (dialog, whichButton) -> { + String newValueText = input.getText().toString(); + try { + int newValue = Integer.parseInt(newValueText); + if(newValue >= preferenceSoundVolume.getMin() && newValue <= preferenceSoundVolume.getMax()) + preferenceSoundVolume.setValue(newValue); + } catch (NumberFormatException ignored) {} + }); + alert.setNegativeButton(R.string.message_cancel, (dialog, whichButton) -> {}); + alert.show(); + return true; + }); + } } // Background color settings diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 23ce76b..d299b75 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -73,6 +73,8 @@ Do you want to save changes?\n(BACK to cancel) Yes No + Ok + Cancel Warning: Trying to load an object while the emulator is busy will certainly result in a memory lost. Before loading an object you should be sure that the calculator is in idle state. Do you want to see this warning next time you try to load an object? Select Program Screenshot @@ -112,6 +114,7 @@ Hide the navigation bar Hide the button menu Sound Volume + Sound Volume (0-255) Allow haptic feedback Background Color