Fix Port2 settings
This commit is contained in:
parent
b61ec6d7f5
commit
32e41ccbee
5 changed files with 121 additions and 102 deletions
|
@ -4,8 +4,8 @@
|
|||
package="com.regis.cosnier.emu48">
|
||||
|
||||
<!--<uses-permission android:name="android.permission.MANAGE_DOCUMENTS"/>-->
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
<!--<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />-->
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:required="false" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
|
@ -25,17 +25,41 @@
|
|||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<action android:name="android.intent.action.SEND" />
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
|
||||
<!--<data android:mimeType="*/*" />-->
|
||||
<data android:scheme="file"
|
||||
android:mimeType="*/*"
|
||||
android:pathPattern=".*\\.e48"
|
||||
android:host="*"/>
|
||||
<!--<action android:name="android.intent.action.VIEW" />-->
|
||||
<!--<action android:name="android.intent.action.SEND" />-->
|
||||
<!--<category android:name="android.intent.category.DEFAULT" />-->
|
||||
<!--<data android:scheme="content"-->
|
||||
<!--android:mimeType="*/*"-->
|
||||
<!--android:pathPattern=".*\\.e38"-->
|
||||
<!--android:host="*"/>-->
|
||||
<!--<data android:scheme="content"-->
|
||||
<!--android:mimeType="*/*"-->
|
||||
<!--android:pathPattern=".*\\.e39"-->
|
||||
<!--android:host="*"/>-->
|
||||
<!--<data android:scheme="content"-->
|
||||
<!--android:mimeType="*/*"-->
|
||||
<!--android:pathPattern=".*\\.e48"-->
|
||||
<!--android:host="*"/>-->
|
||||
<!--<data android:scheme="content"-->
|
||||
<!--android:mimeType="*/*"-->
|
||||
<!--android:pathPattern=".*\\.e49"-->
|
||||
<!--android:host="*"/>-->
|
||||
<!--<data android:scheme="file"-->
|
||||
<!--android:mimeType="*/*"-->
|
||||
<!--android:pathPattern=".*\\.e38"-->
|
||||
<!--android:host="*"/>-->
|
||||
<!--<data android:scheme="file"-->
|
||||
<!--android:mimeType="*/*"-->
|
||||
<!--android:pathPattern=".*\\.e39"-->
|
||||
<!--android:host="*"/>-->
|
||||
<!--<data android:scheme="file"-->
|
||||
<!--android:mimeType="*/*"-->
|
||||
<!--android:pathPattern=".*\\.e48"-->
|
||||
<!--android:host="*"/>-->
|
||||
<!--<data android:scheme="file"-->
|
||||
<!--android:mimeType="*/*"-->
|
||||
<!--android:pathPattern=".*\\.e49"-->
|
||||
<!--android:host="*"/>-->
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
|
|
|
@ -22,6 +22,8 @@ AndroidBitmapInfo androidBitmapInfo;
|
|||
TCHAR szChosenCurrentKml[MAX_PATH];
|
||||
TCHAR szKmlLog[10240];
|
||||
TCHAR szKmlTitle[10240];
|
||||
BOOL settingsPort2en;
|
||||
BOOL settingsPort2wr;
|
||||
|
||||
|
||||
|
||||
|
@ -846,8 +848,8 @@ JNIEXPORT void JNICALL Java_com_regis_cosnier_emu48_NativeLib_setConfiguration(J
|
|||
SwitchToState(nOldState);
|
||||
}
|
||||
} else if(_tcscmp(_T("settings_port2"), configKey) == 0) {
|
||||
BOOL settingsPort2en = (BOOL)intValue1;
|
||||
BOOL settingsPort2wr = (BOOL)intValue2;
|
||||
settingsPort2en = (BOOL)intValue1;
|
||||
settingsPort2wr = (BOOL)intValue2;
|
||||
const char * settingsPort2load = settingsPort2en ? configStringValue : NULL;
|
||||
|
||||
LPCTSTR szActPort2Filename = _T("");
|
||||
|
@ -857,24 +859,22 @@ JNIEXPORT void JNICALL Java_com_regis_cosnier_emu48_NativeLib_setConfiguration(J
|
|||
// HP48SX/GX port2 change settings detection
|
||||
if (cCurrentRomType=='S' || cCurrentRomType=='G' || cCurrentRomType==0)
|
||||
{
|
||||
//bPort2IsShared = settingsPort2isshared;
|
||||
const char * szNewPort2Filename = NULL;
|
||||
if(settingsPort2load) {
|
||||
szNewPort2Filename = settingsPort2load;
|
||||
}
|
||||
// else
|
||||
// szNewPort2Filename = _T("SHARED.BIN");
|
||||
|
||||
if(szNewPort2Filename && _tcscmp(szPort2Filename, szNewPort2Filename) != 0) {
|
||||
_tcscpy(szPort2Filename, szNewPort2Filename);
|
||||
if(settingsPort2en && settingsPort2load) {
|
||||
if(_tcscmp(szPort2Filename, settingsPort2load) != 0) {
|
||||
_tcscpy(szPort2Filename, settingsPort2load);
|
||||
bPort2CfgChange = TRUE; // slot2 configuration changed
|
||||
}
|
||||
szActPort2Filename = szPort2Filename;
|
||||
bPort2CfgChange = TRUE; // slot2 configuration changed
|
||||
|
||||
// R/W port
|
||||
if (*szActPort2Filename != 0 && (BOOL)settingsPort2wr != bPort2Writeable)
|
||||
{
|
||||
bPort2AttChange = TRUE; // slot2 file R/W attribute changed
|
||||
bPort2CfgChange = TRUE; // slot2 configuration changed
|
||||
if (*szActPort2Filename != 0 && (BOOL) settingsPort2wr != bPort2Writeable) {
|
||||
bPort2AttChange = TRUE; // slot2 file R/W attribute changed
|
||||
bPort2CfgChange = TRUE; // slot2 configuration changed
|
||||
}
|
||||
} else {
|
||||
if(szPort2Filename[0] != '\0') {
|
||||
bPort2CfgChange = TRUE; // slot2 configuration changed
|
||||
szPort2Filename[0] = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -885,24 +885,6 @@ JNIEXPORT void JNICALL Java_com_regis_cosnier_emu48_NativeLib_setConfiguration(J
|
|||
|
||||
UnmapPort2(); // unmap port2
|
||||
|
||||
// if (bPort2AttChange) // slot2 R/W mode changed
|
||||
// {
|
||||
// DWORD dwFileAtt;
|
||||
//
|
||||
// SetCurrentDirectory(szEmuDirectory);
|
||||
// dwFileAtt = GetFileAttributes(szActPort2Filename);
|
||||
// if (dwFileAtt != 0xFFFFFFFF)
|
||||
// {
|
||||
// if (IsDlgButtonChecked(hDlg,IDC_PORT2WR))
|
||||
// dwFileAtt &= ~FILE_ATTRIBUTE_READONLY;
|
||||
// else
|
||||
// dwFileAtt |= FILE_ATTRIBUTE_READONLY;
|
||||
//
|
||||
// SetFileAttributes(szActPort2Filename,dwFileAtt);
|
||||
// }
|
||||
// SetCurrentDirectory(szCurrentDirectory);
|
||||
// }
|
||||
|
||||
if (cCurrentRomType) // ROM defined
|
||||
{
|
||||
MapPort2(szActPort2Filename);
|
||||
|
|
|
@ -63,12 +63,17 @@ BOOL SetCurrentDirectory(LPCTSTR path)
|
|||
return chdir(path);
|
||||
}
|
||||
|
||||
extern BOOL settingsPort2en;
|
||||
extern BOOL settingsPort2wr;
|
||||
|
||||
HANDLE CreateFile(LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPVOID lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, LPVOID hTemplateFile)
|
||||
{
|
||||
BOOL forceNormalFile = FALSE;
|
||||
if(_tcscmp(lpFileName, szPort2Filename) == 0) {
|
||||
// Special case for Port2 filename
|
||||
forceNormalFile = TRUE;
|
||||
if(!settingsPort2wr && (dwDesiredAccess & GENERIC_WRITE))
|
||||
return INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
if(!forceNormalFile && (szCurrentDirectorySet || _tcsncmp(lpFileName, assetsPrefix, assetsPrefixLength / sizeof(TCHAR)) == 0)) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.regis.cosnier.emu48;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.ClipData;
|
||||
|
@ -8,6 +9,7 @@ import android.content.Context;
|
|||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.AssetManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
|
@ -54,6 +56,7 @@ import androidx.appcompat.app.ActionBarDrawerToggle;
|
|||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.FileProvider;
|
||||
import androidx.core.view.GravityCompat;
|
||||
import androidx.drawerlayout.widget.DrawerLayout;
|
||||
|
@ -77,7 +80,7 @@ public class MainActivity extends AppCompatActivity
|
|||
private NavigationView navigationView;
|
||||
private DrawerLayout drawer;
|
||||
|
||||
//private final static int PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE = 2;
|
||||
private final static int PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE = 2;
|
||||
|
||||
enum FileType {
|
||||
PDF,
|
||||
|
@ -122,6 +125,7 @@ public class MainActivity extends AppCompatActivity
|
|||
|
||||
|
||||
|
||||
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||
mainActivity = this;
|
||||
|
||||
|
||||
|
@ -145,7 +149,9 @@ public class MainActivity extends AppCompatActivity
|
|||
toolbar.setVisibility(View.GONE);
|
||||
mainScreenContainer.addView(mainScreenView, 0);
|
||||
|
||||
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||
AssetManager assetManager = getResources().getAssets();
|
||||
NativeLib.start(assetManager, mainScreenView.getBitmapMainScreen(), this, mainScreenView);
|
||||
|
||||
updateFromPreferences(null, false);
|
||||
sharedPreferenceChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
|
||||
@Override
|
||||
|
@ -155,15 +161,12 @@ public class MainActivity extends AppCompatActivity
|
|||
};
|
||||
sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
|
||||
|
||||
|
||||
AssetManager assetManager = getResources().getAssets();
|
||||
NativeLib.start(assetManager, mainScreenView.getBitmapMainScreen(), this, mainScreenView);
|
||||
|
||||
updateNavigationDrawerItems();
|
||||
|
||||
|
||||
String documentToOpenUrl = sharedPreferences.getString("lastDocument", "");
|
||||
Uri documentToOpenUri = null;
|
||||
boolean isFileAndNeedPermission = false;
|
||||
Intent intent = getIntent();
|
||||
if(intent != null) {
|
||||
String action = intent.getAction();
|
||||
|
@ -171,9 +174,10 @@ public class MainActivity extends AppCompatActivity
|
|||
if (action.equals(Intent.ACTION_VIEW)) {
|
||||
documentToOpenUri = intent.getData();
|
||||
if (documentToOpenUri != null) {
|
||||
if(documentToOpenUri.getScheme().compareTo("file") == 0)
|
||||
if(documentToOpenUri.getScheme().compareTo("file") == 0) {
|
||||
documentToOpenUrl = documentToOpenUri.getPath();
|
||||
else
|
||||
isFileAndNeedPermission = true;
|
||||
} else
|
||||
documentToOpenUrl = documentToOpenUri.toString();
|
||||
}
|
||||
} else if (action.equals(Intent.ACTION_SEND)) {
|
||||
|
@ -187,22 +191,22 @@ public class MainActivity extends AppCompatActivity
|
|||
|
||||
//https://developer.android.com/guide/topics/providers/document-provider#permissions
|
||||
if(documentToOpenUrl.length() > 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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue