- Prevent empty MRU.

- Allow to go back from the settings in Android 4.4 and may be more recent versions.
This commit is contained in:
Regis Cosnier 2019-03-10 00:48:14 +01:00
parent abf9e905cc
commit 8583bcefdb
6 changed files with 50 additions and 164 deletions

View file

@ -21,6 +21,11 @@ QUICK START
4. And the calculator should now be opened.
NOTES
- When using a custom KML script by selecting a folder, you must take care of the case sensitivity of its dependencies.
NOT WORKING YET
- Disassembler
@ -43,6 +48,8 @@ Version 1.2alpha (2019-03-XX)
- Allow to build the project with "gradlew build".
- Fix issues with back button in the Settings, Help and About.
- Build with Android 4.4 support.
- Prevent empty MRU.
- Allow to go back from the settings in Android 4.4 and may be more recent versions.
Version 1.1 (2019-03-01)
@ -70,7 +77,7 @@ Note: some included files are not covered by the GPL; these include ROM image fi
The Eric's Real scripts ("real*.kml" and "real*.bmp") are embedded in this application with the kind permission of Eric Rechlin.
TODO
- Issue with random settings in Android 4.4
- Issue with random settings in Android 4.4 emulator
- 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?)

View file

@ -21,6 +21,11 @@ QUICK START
4. And the calculator should now be opened.
NOTES
- When using a custom KML script by selecting a folder, you must take care of the case sensitivity of its dependencies.
NOT WORKING YET
- Disassembler
@ -43,6 +48,8 @@ Version 1.2alpha (2019-03-XX)
- Allow to build the project with "gradlew build".
- Fix issues with back button in the Settings, Help and About.
- Build with Android 4.4 support.
- Prevent empty MRU.
- Allow to go back from the settings in Android 4.4 and may be more recent versions.
Version 1.1 (2019-03-01)

View file

@ -42,7 +42,7 @@ extern void OnBackupRestore();
extern void OnBackupDelete();
JNIEnv *getJNIEnvironment();
//JNIEnv *getJNIEnvironment();
JavaVM *java_machine;
JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
@ -66,6 +66,11 @@ JNIEnv *getJNIEnvironment() {
return jniEnv;
}
int jniDetachCurrentThread() {
jint ret = (*java_machine)->DetachCurrentThread(java_machine);
return ret;
}
enum CALLBACK_TYPE {
CALLBACK_TYPE_INVALIDATE = 0,
CALLBACK_TYPE_WINDOW_RESIZE = 1

View file

@ -472,12 +472,17 @@ int UnlockedWaitForEvent(HANDLE hHandle, uint64_t milliseconds)
return result;
}
extern int jniDetachCurrentThread();
static DWORD ThreadStart(LPVOID lpThreadParameter) {
HANDLE handle = (HANDLE)lpThreadParameter;
if(handle) {
handle->threadStartAddress(handle->threadParameter);
}
//
jniDetachCurrentThread();
CloseHandle(handle->threadEventMessage);
}

View file

@ -12,6 +12,7 @@ import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.preference.PreferenceManager;
@ -131,7 +132,8 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
Set<String> savedMRU = sharedPreferences.getStringSet("MRU", null);
if(savedMRU != null) {
for (String url : savedMRU) {
mruLinkedHashMap.put(url, null);
if(url != null & !url.isEmpty())
mruLinkedHashMap.put(url, null);
}
}
updateMRU();
@ -698,6 +700,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
startActivity(Intent.createChooser(intent, getString(R.string.message_share_screenshot)));
} catch (Exception e) {
e.printStackTrace();
showAlert(e.getMessage());
}
}
private void OnStackCopy() {
@ -813,6 +816,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
if(changedKeys != null) {
HashSet<String> changedKeysCleaned = new HashSet<>();
for (String key : changedKeys) {
//Log.d(TAG, "ChangedKey): " + key);
switch (key) {
case "settings_port1en":
case "settings_port1wr":
@ -840,7 +844,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
if (url != null) {
switch (requestCode) {
case INTENT_GETOPENFILENAME: {
Log.d(TAG, "onActivityResult INTENT_GETOPENFILENAME " + url);
//Log.d(TAG, "onActivityResult INTENT_GETOPENFILENAME " + url);
if (onFileOpen(url) != 0) {
saveLastDocument(url);
makeUriPersistable(data, uri);
@ -848,7 +852,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
break;
}
case INTENT_GETSAVEFILENAME: {
Log.d(TAG, "onActivityResult INTENT_GETSAVEFILENAME " + url);
//Log.d(TAG, "onActivityResult INTENT_GETSAVEFILENAME " + url);
if (NativeLib.onFileSaveAs(url) != 0) {
showAlert(getString(R.string.message_state_saved));
saveLastDocument(url);
@ -860,19 +864,19 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
break;
}
case INTENT_OBJECT_LOAD: {
Log.d(TAG, "onActivityResult INTENT_OBJECT_LOAD " + url);
//Log.d(TAG, "onActivityResult INTENT_OBJECT_LOAD " + url);
NativeLib.onObjectLoad(url);
break;
}
case INTENT_OBJECT_SAVE: {
Log.d(TAG, "onActivityResult INTENT_OBJECT_SAVE " + url);
//Log.d(TAG, "onActivityResult INTENT_OBJECT_SAVE " + url);
NativeLib.onObjectSave(url);
break;
}
case INTENT_PICK_KML_FOLDER_FOR_NEW_FILE:
case INTENT_PICK_KML_FOLDER_FOR_CHANGING:
case INTENT_PICK_KML_FOLDER_FOR_SETTINGS: {
Log.d(TAG, "onActivityResult INTENT_PICK_KML_FOLDER " + url);
//Log.d(TAG, "onActivityResult INTENT_PICK_KML_FOLDER " + url);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("settings_kml_default", false);
editor.putString("settings_kml_folder", url);
@ -908,17 +912,20 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
editor.putString("lastDocument", url);
editor.apply();
mruLinkedHashMap.put(url, null);
if(url != null & !url.isEmpty())
mruLinkedHashMap.put(url, null);
updateMRU();
}
private void makeUriPersistable(Intent data, Uri uri) {
final int takeFlags = data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
getContentResolver().takePersistableUriPermission(uri, takeFlags);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
getContentResolver().takePersistableUriPermission(uri, takeFlags);
}
private void makeUriPersistableReadOnly(Intent data, Uri uri) {
final int takeFlags = data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION);
getContentResolver().takePersistableUriPermission(uri, takeFlags);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
getContentResolver().takePersistableUriPermission(uri, takeFlags);
}

View file

@ -1,41 +1,23 @@
package org.emulator.forty.eight;
import android.app.Activity;
import android.content.Context;
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.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.util.ArraySet;
import android.view.MenuItem;
import com.google.android.material.navigation.NavigationView;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.core.app.NavUtils;
import androidx.appcompat.app.AppCompatActivity;
/**
* A {@link PreferenceActivity} that presents a set of application settings. On
* handset devices, settings are presented as a single list. On tablets,
* settings are split by category, with category headers shown to the left of
* the list of settings.
* <p>
* See <a href="http://developer.android.com/design/patterns/settings.html">
* Android Design: Settings</a> for design guidelines and the <a
* href="http://developer.android.com/guide/topics/ui/settings.html">Settings
* API Guide</a> for more information on developing a Settings UI.
*/
public class SettingsActivity extends AppCompatPreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
public class SettingsActivity extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
//private static final String TAG = "SettingsActivity";
private static SharedPreferences sharedPreferences;
@ -68,15 +50,13 @@ public class SettingsActivity extends AppCompatPreferenceActivity implements Sha
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
if (!super.onMenuItemSelected(featureId, item)) {
NavUtils.navigateUpFromSameTask(this);
}
onBackPressed();
return true;
}
return super.onMenuItemSelected(featureId, item);
return super.onOptionsItemSelected(item);
}
@Override
@ -88,33 +68,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity implements Sha
//super.onBackPressed();
}
/**
* Helper method to determine if the device has an extra-large screen. For
* example, 10" tablets are extra-large.
*/
private static boolean isXLargeTablet(Context context) {
return (context.getResources().getConfiguration().screenLayout
& Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE;
}
/**
* {@inheritDoc}
*/
@Override
public boolean onIsMultiPane() {
return isXLargeTablet(this);
}
/**
* This method stops fragment injection in malicious applications.
* Make sure to deny any unknown fragments here.
*/
protected boolean isValidFragment(String fragmentName) {
return PreferenceFragment.class.getName().equals(fragmentName)
|| GeneralPreferenceFragment.class.getName().equals(fragmentName)
;
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
settingsKeyChanged.add(key);
@ -143,7 +96,8 @@ public class SettingsActivity extends AppCompatPreferenceActivity implements Sha
private void makeUriPersistable(Intent data, Uri uri) {
final int takeFlags = data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
getContentResolver().takePersistableUriPermission(uri, takeFlags);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
getContentResolver().takePersistableUriPermission(uri, takeFlags);
}
/**
@ -160,69 +114,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity implements Sha
addPreferencesFromResource(R.xml.pref_general);
setHasOptionsMenu(true);
// General settings
Preference preferenceRealspeed = findPreference("settings_realspeed");
Preference.OnPreferenceChangeListener onPreferenceChangeListenerRealspeed = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
String stringValue = value.toString();
preference.setSummary(stringValue);
return true;
}
};
preferenceRealspeed.setOnPreferenceChangeListener(onPreferenceChangeListenerRealspeed);
onPreferenceChangeListenerRealspeed.onPreferenceChange(preferenceRealspeed, sharedPreferences.getBoolean(preferenceRealspeed.getKey(), false));
Preference preferenceGrayscale = findPreference("settings_grayscale");
Preference.OnPreferenceChangeListener onPreferenceChangeListenerGrayscale = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
String stringValue = value.toString();
preference.setSummary(stringValue);
return true;
}
};
preferenceGrayscale.setOnPreferenceChangeListener(onPreferenceChangeListenerGrayscale);
onPreferenceChangeListenerGrayscale.onPreferenceChange(preferenceGrayscale, sharedPreferences.getBoolean(preferenceGrayscale.getKey(), false));
Preference preferenceAutosave = findPreference("settings_autosave");
Preference.OnPreferenceChangeListener onPreferenceChangeListenerAutosave = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
String stringValue = value.toString();
preference.setSummary(stringValue);
return true;
}
};
preferenceAutosave.setOnPreferenceChangeListener(onPreferenceChangeListenerAutosave);
onPreferenceChangeListenerAutosave.onPreferenceChange(preferenceAutosave, sharedPreferences.getBoolean(preferenceAutosave.getKey(), false));
Preference preferenceObjectloadwarning = findPreference("settings_objectloadwarning");
Preference.OnPreferenceChangeListener onPreferenceChangeListenerObjectloadwarning = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
String stringValue = value.toString();
preference.setSummary(stringValue);
return true;
}
};
preferenceObjectloadwarning.setOnPreferenceChangeListener(onPreferenceChangeListenerObjectloadwarning);
onPreferenceChangeListenerObjectloadwarning.onPreferenceChange(preferenceObjectloadwarning, sharedPreferences.getBoolean(preferenceObjectloadwarning.getKey(), false));
Preference preferenceAlwaysdisplog = findPreference("settings_alwaysdisplog");
Preference.OnPreferenceChangeListener onPreferenceChangeListenerAlwaysdisplog = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
String stringValue = value.toString();
preference.setSummary(stringValue);
return true;
}
};
preferenceAlwaysdisplog.setOnPreferenceChangeListener(onPreferenceChangeListenerAlwaysdisplog);
onPreferenceChangeListenerAlwaysdisplog.onPreferenceChange(preferenceAlwaysdisplog, sharedPreferences.getBoolean(preferenceAlwaysdisplog.getKey(), false));
Preference preferenceAllowSound = findPreference("settings_allow_sound");
if(preferenceAllowSound != null && !NativeLib.getSoundEnabled()) {
preferenceAllowSound.setSummary("Cannot initialize the sound engine.");
@ -242,8 +133,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity implements Sha
Preference.OnPreferenceChangeListener onPreferenceChangeListenerPort1en = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
String stringValue = value.toString();
preference.setSummary(stringValue);
preferencePort1en.setEnabled(enablePortPreferences);
preferencePort1wr.setEnabled(enablePortPreferences);
return true;
@ -252,22 +141,9 @@ public class SettingsActivity extends AppCompatPreferenceActivity implements Sha
preferencePort1en.setOnPreferenceChangeListener(onPreferenceChangeListenerPort1en);
onPreferenceChangeListenerPort1en.onPreferenceChange(preferencePort1en, sharedPreferences.getBoolean(preferencePort1en.getKey(), false));
Preference.OnPreferenceChangeListener onPreferenceChangeListenerPort1wr = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
String stringValue = value.toString();
preference.setSummary(stringValue);
return true;
}
};
preferencePort1wr.setOnPreferenceChangeListener(onPreferenceChangeListenerPort1wr);
onPreferenceChangeListenerPort1wr.onPreferenceChange(preferencePort1wr, sharedPreferences.getBoolean(preferencePort1wr.getKey(), false));
Preference.OnPreferenceChangeListener onPreferenceChangeListenerPort2en = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
String stringValue = value.toString();
preference.setSummary(stringValue);
preferencePort2en.setEnabled(enablePortPreferences);
preferencePort2wr.setEnabled(enablePortPreferences);
preferencePort2load.setEnabled(enablePortPreferences);
@ -277,17 +153,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity implements Sha
preferencePort2en.setOnPreferenceChangeListener(onPreferenceChangeListenerPort2en);
onPreferenceChangeListenerPort2en.onPreferenceChange(preferencePort2en, sharedPreferences.getBoolean(preferencePort2en.getKey(), false));
Preference.OnPreferenceChangeListener onPreferenceChangeListenerPort2wr = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
String stringValue = value.toString();
preference.setSummary(stringValue);
return true;
}
};
preferencePort2wr.setOnPreferenceChangeListener(onPreferenceChangeListenerPort2wr);
onPreferenceChangeListenerPort2wr.onPreferenceChange(preferencePort2wr, sharedPreferences.getBoolean(preferencePort2wr.getKey(), false));
updatePort2LoadFilename(sharedPreferences.getString(preferencePort2load.getKey(), ""));
preferencePort2load.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
@ -302,16 +167,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity implements Sha
});
}
// @Override
// public boolean onOptionsItemSelected(MenuItem item) {
// int id = item.getItemId();
// if (id == android.R.id.home) {
// startActivity(new Intent(getActivity(), SettingsActivity.class));
// return true;
// }
// return super.onOptionsItemSelected(item);
// }
public void updatePort2LoadFilename(String port2Filename) {
if(preferencePort2load != null) {
String displayName = port2Filename;