From 32e41ccbee71b3b7d3afeaff03ea5a9519fd7c86 Mon Sep 17 00:00:00 2001 From: dgis Date: Sat, 29 Dec 2018 22:36:37 +0000 Subject: [PATCH] Fix Port2 settings --- app/src/main/AndroidManifest.xml | 50 +++++--- app/src/main/cpp/emu48-jni.c | 52 +++------ app/src/main/cpp/win32-layer.c | 5 + .../com/regis/cosnier/emu48/MainActivity.java | 110 ++++++++++-------- .../regis/cosnier/emu48/SettingsActivity.java | 6 +- 5 files changed, 121 insertions(+), 102 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 7cba440..c629474 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -4,8 +4,8 @@ package="com.regis.cosnier.emu48"> - - + + - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0) -// try { -// if(ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { -// ActivityCompat.requestPermissions(this, new String[]{ Manifest.permission.WRITE_EXTERNAL_STORAGE }, PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE); -// //return; -// } else { - if(onFileOpen(documentToOpenUrl) != 0 && documentToOpenUri != null) { - SharedPreferences.Editor editor = sharedPreferences.edit(); - editor.putString("lastDocument", documentToOpenUrl); - editor.commit(); - makeUriPersistable(intent, documentToOpenUri); + try { + if(isFileAndNeedPermission + && ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions(this, new String[]{ Manifest.permission.WRITE_EXTERNAL_STORAGE }, PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE); + //return; + } else { + if(onFileOpen(documentToOpenUrl) != 0) { + saveLastDocument(documentToOpenUrl); + if(intent != null && documentToOpenUri != null && !isFileAndNeedPermission) + makeUriPersistable(intent, documentToOpenUri); } -// } -// } catch (Exception e) { -// Log.e(TAG, e.getMessage()); -// } + } + } catch (Exception e) { + Log.e(TAG, e.getMessage()); + } else if(drawer != null) drawer.openDrawer(GravityCompat.START); } @@ -238,25 +242,30 @@ public class MainActivity extends AppCompatActivity super.onDestroy(); } -// @Override -// public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) { -// switch (requestCode) { -// case PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE: { -// // If request is cancelled, the result arrays are empty. -//// if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { -//// -//// } else { -//// //Toast.makeText(this, R.string.toast_access_location_denied, Toast.LENGTH_SHORT).show(); -//// } -// String lastDocumentUrl = sharedPreferences.getString("lastDocument", ""); -// if(lastDocumentUrl.length() > 0) -// onFileOpen(lastDocumentUrl); -//// return; -// } -//// default: -//// super.onRequestPermissionsResult(requestCode, permissions, grantResults); -// } -// } + @Override + public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) { + switch (requestCode) { + case PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE: { + // If request is cancelled, the result arrays are empty. +// if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { +// +// } else { +// //Toast.makeText(this, R.string.toast_access_location_denied, Toast.LENGTH_SHORT).show(); +// } + String lastDocumentUrl = sharedPreferences.getString("lastDocument", ""); + if(lastDocumentUrl.length() > 0) { + if(onFileOpen(lastDocumentUrl) != 0) + try { + makeUriPersistable(getIntent(), Uri.parse(lastDocumentUrl)); + } catch (Exception e) { + } + } +// return; + } +// default: +// super.onRequestPermissionsResult(requestCode, permissions, grantResults); + } + } @Override public void onBackPressed() { @@ -549,9 +558,7 @@ public class MainActivity extends AppCompatActivity @Override public void run() { NativeLib.onFileClose(); - SharedPreferences.Editor editor = sharedPreferences.edit(); - editor.putString("lastDocument", ""); - editor.commit(); + saveLastDocument(""); updateNavigationDrawerItems(); displayFilename(""); if(drawer != null) { @@ -720,9 +727,7 @@ public class MainActivity extends AppCompatActivity String url = uri.toString(); if(onFileOpen(url) != 0) { - SharedPreferences.Editor editor = sharedPreferences.edit(); - editor.putString("lastDocument", url); - editor.commit(); + saveLastDocument(url); makeUriPersistable(data, uri); } } else if(requestCode == INTENT_GETSAVEFILENAME) { @@ -733,10 +738,7 @@ public class MainActivity extends AppCompatActivity String url = uri.toString(); if(NativeLib.onFileSaveAs(url) != 0) { - SharedPreferences.Editor editor = sharedPreferences.edit(); - editor.putString("lastDocument", url); - editor.commit(); - + saveLastDocument(url); makeUriPersistable(data, uri); displayFilename(url); if(fileSaveAsCallback != null) @@ -765,6 +767,12 @@ public class MainActivity extends AppCompatActivity super.onActivityResult(requestCode, resultCode, data); } + private void saveLastDocument(String url) { + SharedPreferences.Editor editor = sharedPreferences.edit(); + editor.putString("lastDocument", url); + editor.commit(); + } + private void makeUriPersistable(Intent data, Uri uri) { //grantUriPermission(getPackageName(), uri, Intent.FLAG_GRANT_READ_URI_PERMISSION); final int takeFlags = data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); diff --git a/app/src/main/java/com/regis/cosnier/emu48/SettingsActivity.java b/app/src/main/java/com/regis/cosnier/emu48/SettingsActivity.java index fd38623..be763a0 100644 --- a/app/src/main/java/com/regis/cosnier/emu48/SettingsActivity.java +++ b/app/src/main/java/com/regis/cosnier/emu48/SettingsActivity.java @@ -283,7 +283,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { String stringValue = value.toString(); preference.setSummary(stringValue); preferencePort1en.setEnabled(enablePortPreferences); - preferencePort1wr.setEnabled(enablePortPreferences && booleanValue.booleanValue()); + preferencePort1wr.setEnabled(enablePortPreferences /*&& booleanValue.booleanValue()*/); return true; } }; @@ -308,8 +308,8 @@ public class SettingsActivity extends AppCompatPreferenceActivity { String stringValue = value.toString(); preference.setSummary(stringValue); preferencePort2en.setEnabled(enablePortPreferences); - preferencePort2wr.setEnabled(enablePortPreferences && booleanValue.booleanValue()); - preferencePort2load.setEnabled(enablePortPreferences && booleanValue.booleanValue()); + preferencePort2wr.setEnabled(enablePortPreferences /*&& booleanValue.booleanValue()*/); + preferencePort2load.setEnabled(enablePortPreferences /*&& booleanValue.booleanValue()*/); return true; } };