From e4727e01923ba8f1e6b6cb6f2750923733a91814 Mon Sep 17 00:00:00 2001 From: Regis Cosnier Date: Wed, 20 Mar 2019 19:06:36 +0100 Subject: [PATCH] - Fix a bug about the timer delay in timeSetEvent(). I hope it fix the slow down. - Fix deprecated classes in the settings. - Add a haptic feedback when touching a button. --- ReadMe.txt | 5 +- app/build.gradle | 14 +++--- app/src/main/assets/ReadMe.txt | 6 ++- app/src/main/cpp/android-emu48.c | 6 ++- app/src/main/cpp/emu48-jni.c | 13 ++++++ app/src/main/cpp/win32-layer.c | 19 ++++---- app/src/main/cpp/win32-layer.h | 1 + .../emulator/forty/eight/MainActivity.java | 15 +++++- .../forty/eight/SettingsActivity.java | 16 +++++-- app/src/main/res/values/strings.xml | 16 +++++++ app/src/main/res/xml/pref_general.xml | 46 ++++++++----------- 11 files changed, 105 insertions(+), 52 deletions(-) diff --git a/ReadMe.txt b/ReadMe.txt index f8146d8..f7222ab 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -40,6 +40,10 @@ CHANGES Version 1.3alpha (2019-03-xx) - Fix the red and blue color inversion. +- Add the HP 50g (Calypso 2K/4K) KML script from Carl Reinke (4K is a slow because there is no hardware acceleration). +- Fix a bug about the timer delay in timeSetEvent(). I hope it fix the slow down. +- Fix deprecated classes in the settings. +- Add a haptic feedback when touching a button. Version 1.2 (2019-03-14) @@ -93,7 +97,6 @@ TODO - Add a separation between the pixels (Suggestion from Jaime Meza) - Sometimes the "busy" annunciator gets stuck - Add KML script loading dependencies fallback to the inner ROM (and may be KML include?) -- Add haptic feedback when touch a button - Add a true fullscreen mode under the status bar and the bottom buttons - Improve the access to the menu - Change the logo following the template diff --git a/app/build.gradle b/app/build.gradle index 31b7042..5b1967f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,7 +7,7 @@ def keystoreProperties = new Properties() def canSign = false if(keystorePropertiesFile.exists()) { canSign = true - println("The release flavor will signed in app/build/outputs/apk/release/app-release.apk") + println("The release flavor will signed in the folder app/build/outputs/apk/release/") // Load your keystore.properties file into the keystoreProperties object. keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) @@ -35,6 +35,7 @@ android { targetSdkVersion 28 versionCode 4 versionName "1.3" + setProperty("archivesBaseName", "Emu48-v$versionName") testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" externalNativeBuild { cmake { @@ -44,13 +45,10 @@ android { } } } -// if(project.hasProperty("MyProject.properties") -// && new File(project.property("MyProject.properties")).exists()) { if(canSign) { signingConfigs { release { -// storeFile new File(keystoreProperties['storeFile']) storeFile file(keystoreProperties['storeFile']) storePassword keystoreProperties['storePassword'] keyAlias keystoreProperties['keyAlias'] @@ -78,11 +76,11 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'androidx.appcompat:appcompat:1.1.0-alpha02' + implementation 'androidx.appcompat:appcompat:1.1.0-alpha03' implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3' + implementation 'androidx.preference:preference:1.0.0' implementation 'com.google.android.material:material:1.1.0-alpha04' - implementation 'com.android.support.constraint:constraint-layout:1.1.3' testImplementation 'junit:junit:4.12' - androidTestImplementation 'androidx.test:runner:1.1.2-alpha01' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.2-alpha01' + androidTestImplementation 'androidx.test:runner:1.1.2-alpha02' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-alpha02' } diff --git a/app/src/main/assets/ReadMe.txt b/app/src/main/assets/ReadMe.txt index a42e9d3..2dc121a 100644 --- a/app/src/main/assets/ReadMe.txt +++ b/app/src/main/assets/ReadMe.txt @@ -23,7 +23,7 @@ QUICK START NOTES -- When using a custom KML script by selecting a folder, you must take care of the case sensitivity of its dependencies. +- When using a custom KML script by selecting a folder, you must take care of the case sensitivity of its dependency files. NOT WORKING YET @@ -40,6 +40,10 @@ CHANGES Version 1.3alpha (2019-03-xx) - Fix the red and blue color inversion. +- Add the HP 50g (Calypso 2K/4K) KML script from Carl Reinke (4K is a slow because there is no hardware acceleration). +- Fix a bug about the timer delay in timeSetEvent(). I hope it fix the slow down. +- Fix deprecated classes in the settings. +- Add a haptic feedback when touching a button. Version 1.2 (2019-03-14) diff --git a/app/src/main/cpp/android-emu48.c b/app/src/main/cpp/android-emu48.c index 5c837d0..311f308 100644 --- a/app/src/main/cpp/android-emu48.c +++ b/app/src/main/cpp/android-emu48.c @@ -141,7 +141,11 @@ static LRESULT OnPaint(HWND hWindow) static LRESULT OnLButtonDown(UINT nFlags, WORD x, WORD y) { if (nMacroState == MACRO_PLAY) return 0; // playing macro - if (nState == SM_RUN) MouseButtonDownAt(nFlags, x,y); + if (nState == SM_RUN) { + MouseButtonDownAt(nFlags, x,y); + if(MouseIsButton(x,y)) + performHapticFeedback(); + } return 0; } diff --git a/app/src/main/cpp/emu48-jni.c b/app/src/main/cpp/emu48-jni.c index bcffee8..26e4b05 100644 --- a/app/src/main/cpp/emu48-jni.c +++ b/app/src/main/cpp/emu48-jni.c @@ -238,6 +238,19 @@ const TCHAR * clipboardPasteText() { return NULL; } +void performHapticFeedback() { + JNIEnv *jniEnv = getJNIEnvironment(); + if(jniEnv) { + jclass mainActivityClass = (*jniEnv)->GetObjectClass(jniEnv, mainActivity); + if(mainActivityClass) { + jmethodID midStr = (*jniEnv)->GetMethodID(jniEnv, mainActivityClass, "performHapticFeedback", "()V"); + (*jniEnv)->CallVoidMethod(jniEnv, mainActivity, midStr); + (*jniEnv)->DeleteLocalRef(jniEnv, mainActivityClass); + } + } +} + + JNIEXPORT void JNICALL Java_org_emulator_forty_eight_NativeLib_start(JNIEnv *env, jobject thisz, jobject assetMgr, jobject bitmapMainScreen0, jobject activity, jobject view) { chooseCurrentKmlMode = ChooseKmlMode_UNKNOWN; diff --git a/app/src/main/cpp/win32-layer.c b/app/src/main/cpp/win32-layer.c index 3d7eb1c..09c900e 100644 --- a/app/src/main/cpp/win32-layer.c +++ b/app/src/main/cpp/win32-layer.c @@ -1679,6 +1679,9 @@ HANDLE WINAPI GetClipboardData(UINT uFormat) { return szText; } +//#define TIMER_LOGD LOGD +#define TIMER_LOGD + void deleteTimeEvent(UINT uTimerID) { timer_delete(timerEvents[uTimerID - 1].timer); timerEvents[uTimerID - 1].valid = FALSE; @@ -1688,13 +1691,13 @@ void timerCallback(int timerId) { timerEvents[timerId].fptc((UINT) (timerId + 1), 0, (DWORD) timerEvents[timerId].dwUser, 0, 0); if(timerEvents[timerId].fuEvent == TIME_ONESHOT) { - //LOGD("timerCallback remove timer uTimerID [%d]", timerId + 1); + TIMER_LOGD("timerCallback remove timer uTimerID [%d]", timerId + 1); deleteTimeEvent((UINT) (timerId + 1)); } } } MMRESULT timeSetEvent(UINT uDelay, UINT uResolution, LPTIMECALLBACK fptc, DWORD_PTR dwUser, UINT fuEvent) { - //LOGD("timeSetEvent(uDelay: %d, fuEvent: %d)", uDelay, fuEvent); + TIMER_LOGD("timeSetEvent(uDelay: %d, fuEvent: %d)", uDelay, fuEvent); // Find a timer id int timerId = -1; @@ -1705,7 +1708,7 @@ MMRESULT timeSetEvent(UINT uDelay, UINT uResolution, LPTIMECALLBACK fptc, DWORD_ } } if(timerId == -1) { - //LOGD("timeSetEvent() ERROR: No more timer available"); + TIMER_LOGD("timeSetEvent() ERROR: No more timer available"); return NULL; } timerEvents[timerId].timerId = timerId; @@ -1721,11 +1724,11 @@ MMRESULT timeSetEvent(UINT uDelay, UINT uResolution, LPTIMECALLBACK fptc, DWORD_ sev.sigev_notify_attributes = NULL; timer_t * timer = &(timerEvents[timerId].timer); if (timer_create(CLOCK_REALTIME, &sev, timer) == -1) { - //LOGD("timeSetEvent() ERROR in timer_create"); + TIMER_LOGD("timeSetEvent() ERROR in timer_create"); return NULL; } - long long freq_nanosecs = uDelay * 1000000; + long long freq_nanosecs = uDelay * 1000000L; struct itimerspec its; its.it_value.tv_sec = freq_nanosecs / 1000000000; its.it_value.tv_nsec = freq_nanosecs % 1000000000; @@ -1738,15 +1741,15 @@ MMRESULT timeSetEvent(UINT uDelay, UINT uResolution, LPTIMECALLBACK fptc, DWORD_ } if (timer_settime(timerEvents[timerId].timer, 0, &its, NULL) == -1) { timer_delete(timerEvents[timerId].timer); - //LOGD("timeSetEvent() ERROR in timer_settime"); + TIMER_LOGD("timeSetEvent() ERROR in timer_settime"); return NULL; } timerEvents[timerId].valid = TRUE; - //LOGD("timeSetEvent() -> timerId+1: [%d]", timerId + 1); + TIMER_LOGD("timeSetEvent() -> timerId+1: [%d]", timerId + 1); return (MMRESULT) (timerId + 1); // No error } MMRESULT timeKillEvent(UINT uTimerID) { - //LOGD("timeKillEvent(uTimerID: [%d])", uTimerID); + TIMER_LOGD("timeKillEvent(uTimerID: [%d])", uTimerID); deleteTimeEvent(uTimerID); return 0; //No error } diff --git a/app/src/main/cpp/win32-layer.h b/app/src/main/cpp/win32-layer.h index c4c4f8f..b248bbd 100644 --- a/app/src/main/cpp/win32-layer.h +++ b/app/src/main/cpp/win32-layer.h @@ -1141,3 +1141,4 @@ extern enum ChooseKmlMode chooseCurrentKmlMode; BOOL getFirstKMLFilenameForType(BYTE chipsetType, TCHAR * firstKMLFilename, size_t firstKMLFilenameSize); void clipboardCopyText(const TCHAR * text); const TCHAR * clipboardPasteText(); +void performHapticFeedback(); 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 724e61b..0301d94 100644 --- a/app/src/main/java/org/emulator/forty/eight/MainActivity.java +++ b/app/src/main/java/org/emulator/forty/eight/MainActivity.java @@ -17,6 +17,7 @@ import android.os.Bundle; import android.os.ParcelFileDescriptor; import android.preference.PreferenceManager; import android.util.Log; +import android.view.HapticFeedbackConstants; import android.view.Menu; import android.view.MenuItem; import android.view.SubMenu; @@ -1181,6 +1182,11 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On return ""; } + void performHapticFeedback() { + if(sharedPreferences.getBoolean("settings_haptic_feedback", true)) + mainScreenView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING); + } + private void setPort1Settings(boolean port1Plugged, boolean port1Writable) { SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putBoolean("settings_port1en", port1Plugged); @@ -1192,7 +1198,10 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On private void updateFromPreferences(String key, boolean isDynamic) { int isDynamicValue = isDynamic ? 1 : 0; if(key == null) { - String[] settingKeys = { "settings_realspeed", "settings_grayscale", "settings_allow_rotation", "settings_fill_screen", "settings_scale", "settings_allow_sound", "settings_kml", "settings_port1", "settings_port2" }; + String[] settingKeys = { + "settings_realspeed", "settings_grayscale", "settings_allow_rotation", "settings_fill_screen", + "settings_scale", "settings_allow_sound", "settings_haptic_feedback", + "settings_kml", "settings_port1", "settings_port2" }; for (String settingKey : settingKeys) { updateFromPreferences(settingKey, false); } @@ -1223,6 +1232,10 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On sharedPreferences.getBoolean("settings_allow_sound", true) ? 64 : 0, 0, null); break; + case "settings_haptic_feedback": + // Nothing to do + break; + case "settings_kml": case "settings_kml_default": case "settings_kml_folder": 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 fd1184b..86af7cc 100644 --- a/app/src/main/java/org/emulator/forty/eight/SettingsActivity.java +++ b/app/src/main/java/org/emulator/forty/eight/SettingsActivity.java @@ -6,9 +6,6 @@ import android.content.SharedPreferences; import android.net.Uri; import android.os.Build; import android.os.Bundle; -import android.preference.Preference; -import android.preference.PreferenceFragment; -import android.preference.PreferenceManager; import android.view.MenuItem; import java.util.HashSet; @@ -16,6 +13,9 @@ import java.util.HashSet; import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; +import androidx.preference.PreferenceFragmentCompat; +import androidx.preference.Preference; +import androidx.preference.PreferenceManager; public class SettingsActivity extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener { @@ -40,7 +40,7 @@ public class SettingsActivity extends AppCompatActivity implements SharedPrefere } generalPreferenceFragment = new GeneralPreferenceFragment(); - getFragmentManager().beginTransaction().replace(android.R.id.content, generalPreferenceFragment).commit(); + getSupportFragmentManager().beginTransaction().replace(android.R.id.content, generalPreferenceFragment).commit(); } @Override @@ -104,13 +104,14 @@ public class SettingsActivity extends AppCompatActivity implements SharedPrefere * This fragment shows general preferences only. It is used when the * activity is showing a two-pane settings UI. */ - public static class GeneralPreferenceFragment extends PreferenceFragment { + public static class GeneralPreferenceFragment extends PreferenceFragmentCompat { Preference preferencePort2load = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + addPreferencesFromResource(R.xml.pref_general); setHasOptionsMenu(true); @@ -167,6 +168,11 @@ public class SettingsActivity extends AppCompatActivity implements SharedPrefere }); } + @Override + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { + + } + public void updatePort2LoadFilename(String port2Filename) { if(preferencePort2load != null) { String displayName = port2Filename; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0c482e1..6af57b6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -56,6 +56,22 @@ Are you sure you want to press the Reset Button? You cannot change the KML script when Emu48 is not running. Use the File, New menu item to create a new calculator. KML Script Compilation Result + General + Authentic Calculator Speed + Enable Virtual LCD Delay + Automatically Save Files + Show Load Object Warning + Always Show KML Compilation Result + Allow rotation + Fill screen + Allow sounds + Allow haptic feedback + Memory Cards + Port 1 is Plugged + Port 1 is Writable + Port 2 is Plugged + Port 2 is Writable + Port 2 File diff --git a/app/src/main/res/xml/pref_general.xml b/app/src/main/res/xml/pref_general.xml index e3e32ce..209a8d3 100644 --- a/app/src/main/res/xml/pref_general.xml +++ b/app/src/main/res/xml/pref_general.xml @@ -2,54 +2,46 @@ xmlns:app="http://schemas.android.com/apk/res-auto"> - + + - - - - - - - - - - - - - +