The sound can be adjusted by number in addition to the slider by touching the number.

This commit is contained in:
dgis 2019-12-04 00:03:58 +01:00
parent 3e8ea1aa78
commit ea970cbed3
7 changed files with 70 additions and 36 deletions

View file

@ -169,6 +169,7 @@ The Eric's Real scripts ("real*.kml" and "real*.bmp/png") are embedded in this a
TODO TODO
- Autosave only works once a manual save has been done (William Hostman from comment). - 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". - Add the name of the file in the toast "State saved".
- The clock seems unsynchronized sometimes. - The clock seems unsynchronized sometimes.
- Retain a key by right clicking if it is from a mouse. - Retain a key by right clicking if it is from a mouse.
@ -183,7 +184,7 @@ TODO
BUILD 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. And to generate an installable APK file with a real Android device, it MUST be signed.
Either use Android Studio: Either use Android Studio:

View file

@ -80,13 +80,13 @@ android {
dependencies { dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0-rc01' implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2' implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta3'
implementation 'androidx.preference:preference:1.1.0-rc01' implementation 'androidx.preference:preference:1.1.0'
implementation 'com.google.android.material:material:1.1.0-alpha08' implementation 'com.google.android.material:material:1.2.0-alpha02'
implementation 'androidx.legacy:legacy-support-v4:1.0.0' 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' 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'
} }

View file

@ -219,8 +219,6 @@ public class LCDOverlappingView extends View {
protected void onDraw(Canvas canvas) { protected void onDraw(Canvas canvas) {
//if(debug) Log.d(TAG, "onDraw()"); //if(debug) Log.d(TAG, "onDraw()");
//canvas.drawColor(Color.RED);
if(this.overlappingLCDMode != OVERLAPPING_LCD_MODE_NONE && bitmapLCD != null) { if(this.overlappingLCDMode != OVERLAPPING_LCD_MODE_NONE && bitmapLCD != null) {
int x = NativeLib.getScreenPositionX(); int x = NativeLib.getScreenPositionX();
int y = NativeLib.getScreenPositionY(); int y = NativeLib.getScreenPositionY();
@ -304,8 +302,10 @@ public class LCDOverlappingView extends View {
firstTime = false; firstTime = false;
post(() -> { post(() -> {
float scale = sharedPreferences.getFloat("settings_lcd_overlapping_scale", 1.0f); float scale = sharedPreferences.getFloat("settings_lcd_overlapping_scale", 1.0f);
if (scale < 0.01f) if (scale < 0.5f)
scale = 0.01f; scale = 0.5f;
if (scale > 20.0f)
scale = 20.0f;
int viewWidth = (int) (lcdWidth * scale); int viewWidth = (int) (lcdWidth * scale);
int viewHeight = (int) (lcdHeight * scale); int viewHeight = (int) (lcdHeight * scale);
if (viewWidth < minViewSize && viewHeight < minViewSize) { if (viewWidth < minViewSize && viewHeight < minViewSize) {

View file

@ -15,8 +15,10 @@
package org.emulator.calculator; package org.emulator.calculator;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.database.Cursor; import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.provider.OpenableColumns; import android.provider.OpenableColumns;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
@ -63,6 +65,17 @@ public class Utils {
return -1; 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) { public static String getFileName(Context context, String url) {
String result = null; String result = null;
try { try {

View file

@ -233,7 +233,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
if(onFileOpen(documentToOpenUrl) != 0) { if(onFileOpen(documentToOpenUrl) != 0) {
saveLastDocument(documentToOpenUrl); saveLastDocument(documentToOpenUrl);
if(intent != null && documentToOpenUri != null) if(intent != null && documentToOpenUri != null)
makeUriPersistable(intent, documentToOpenUri); Utils.makeUriPersistable(this, intent, documentToOpenUri);
} }
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, e.getMessage()); Log.e(TAG, e.getMessage());
@ -1029,7 +1029,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
int openResult = onFileOpen(url); int openResult = onFileOpen(url);
if (openResult > 0) { if (openResult > 0) {
saveLastDocument(url); saveLastDocument(url);
makeUriPersistable(data, uri); Utils.makeUriPersistable(this, data, uri);
} else if(openResult == -2 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // >= API 21 } 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! // For security reason, you must select the folder where are the KML and ROM files and then, reopen this file!
new AlertDialog.Builder(this) new AlertDialog.Builder(this)
@ -1047,7 +1047,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
if (NativeLib.onFileSaveAs(url) != 0) { if (NativeLib.onFileSaveAs(url) != 0) {
showAlert(getString(R.string.message_state_saved)); showAlert(getString(R.string.message_state_saved));
saveLastDocument(url); saveLastDocument(url);
makeUriPersistable(data, uri); Utils.makeUriPersistable(this, data, uri);
displayFilename(url); displayFilename(url);
if (fileSaveAsCallback != null) if (fileSaveAsCallback != null)
fileSaveAsCallback.run(); fileSaveAsCallback.run();
@ -1074,7 +1074,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
editor.putString("settings_kml_folder", url); editor.putString("settings_kml_folder", url);
editor.apply(); editor.apply();
updateFromPreferences("settings_kml", true); updateFromPreferences("settings_kml", true);
makeUriPersistableReadOnly(data, uri); Utils.makeUriPersistableReadOnly(this, data, uri);
switch (requestCode) { switch (requestCode) {
case INTENT_PICK_KML_FOLDER_FOR_NEW_FILE: case INTENT_PICK_KML_FOLDER_FOR_NEW_FILE:
@ -1153,17 +1153,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
navigationView.post(this::updateMRU); 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) { private void showCalculatorView(boolean show) {
if(show) { if(show) {
mainScreenView.setEnablePanAndScale(true); mainScreenView.setEnablePanAndScale(true);

View file

@ -15,21 +15,30 @@
package org.emulator.forty.eight; package org.emulator.forty.eight;
import android.app.Activity; import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.text.InputType;
import android.view.MenuItem; import android.view.MenuItem;
import android.widget.EditText;
import android.widget.LinearLayout;
import java.util.HashSet; import java.util.HashSet;
import java.util.Locale;
import java.util.Objects;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import androidx.preference.SeekBarPreference;
import org.emulator.calculator.NativeLib; import org.emulator.calculator.NativeLib;
import org.emulator.calculator.Utils; import org.emulator.calculator.Utils;
@ -105,15 +114,34 @@ public class SettingsActivity extends AppCompatActivity implements SharedPrefere
// Sound settings // Sound settings
// Preference preferenceAllowSound = findPreference("settings_allow_sound"); SeekBarPreference preferenceSoundVolume = findPreference("settings_sound_volume");
// if(preferenceAllowSound != null && !NativeLib.getSoundEnabled()) { if(preferenceSoundVolume != null) {
// preferenceAllowSound.setSummary("Cannot initialize the sound engine."); if(!NativeLib.getSoundEnabled()) {
// preferenceAllowSound.setEnabled(false); preferenceSoundVolume.setSummary("Cannot initialize the sound engine.");
// } preferenceSoundVolume.setEnabled(false);
Preference preferenceSoundVolume = findPreference("settings_sound_volume"); } else {
if(preferenceSoundVolume != null && !NativeLib.getSoundEnabled()) { preferenceSoundVolume.setOnPreferenceClickListener(preference -> {
preferenceSoundVolume.setSummary("Cannot initialize the sound engine."); AlertDialog.Builder alert = new AlertDialog.Builder(Objects.requireNonNull(getContext()));
preferenceSoundVolume.setEnabled(false); 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 // Background color settings

View file

@ -73,6 +73,8 @@
<string name="message_do_you_want_to_save">Do you want to save changes?\n(BACK to cancel)</string> <string name="message_do_you_want_to_save">Do you want to save changes?\n(BACK to cancel)</string>
<string name="message_yes">Yes</string> <string name="message_yes">Yes</string>
<string name="message_no">No</string> <string name="message_no">No</string>
<string name="message_ok">Ok</string>
<string name="message_cancel">Cancel</string>
<string name="message_object_load">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?</string> <string name="message_object_load">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?</string>
<string name="message_object_save_program">Select Program</string> <string name="message_object_save_program">Select Program</string>
<string name="message_screenshot">Screenshot</string> <string name="message_screenshot">Screenshot</string>
@ -112,6 +114,7 @@
<string name="settings_hide_bar_nav">Hide the navigation bar</string> <string name="settings_hide_bar_nav">Hide the navigation bar</string>
<string name="settings_hide_button_menu">Hide the button menu</string> <string name="settings_hide_button_menu">Hide the button menu</string>
<string name="settings_sound_volume_title">Sound Volume</string> <string name="settings_sound_volume_title">Sound Volume</string>
<string name="settings_sound_volume_dialog_title">Sound Volume (0-255)</string>
<string name="settings_haptic_feedback_title">Allow haptic feedback</string> <string name="settings_haptic_feedback_title">Allow haptic feedback</string>
<string name="settings_category_background_title">Background Color</string> <string name="settings_category_background_title">Background Color</string>