This commit is contained in:
parent
ed46bee627
commit
0250c5cfe2
6 changed files with 164 additions and 81 deletions
|
@ -21,6 +21,7 @@ AndroidBitmapInfo androidBitmapInfo;
|
|||
enum ChooseKmlMode chooseCurrentKmlMode;
|
||||
TCHAR szChosenCurrentKml[MAX_PATH];
|
||||
TCHAR szKmlLog[10240];
|
||||
TCHAR szKmlLogBackup[10240];
|
||||
TCHAR szKmlTitle[10240];
|
||||
BOOL settingsPort2en;
|
||||
BOOL settingsPort2wr;
|
||||
|
@ -826,23 +827,25 @@ JNIEXPORT void JNICALL Java_org_emulator_forty_eight_NativeLib_onViewReset(JNIEn
|
|||
SwitchToState(SM_RUN);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_emulator_forty_eight_NativeLib_onViewScript(JNIEnv *env, jobject thisz, jstring kmlFilename) {
|
||||
JNIEXPORT int JNICALL Java_org_emulator_forty_eight_NativeLib_onViewScript(JNIEnv *env, jobject thisz, jstring kmlFilename) {
|
||||
|
||||
TCHAR szKmlFile[MAX_PATH];
|
||||
BOOL bKMLChanged,bSucc;
|
||||
// BOOL bKMLChanged,bSucc;
|
||||
BYTE cType = cCurrentRomType;
|
||||
SwitchToState(SM_INVALID);
|
||||
|
||||
const char *filenameUTF8 = (*env)->GetStringUTFChars(env, kmlFilename , NULL) ;
|
||||
_tcscpy(szCurrentKml, filenameUTF8);
|
||||
(*env)->ReleaseStringUTFChars(env, kmlFilename, filenameUTF8);
|
||||
|
||||
// make a copy of the current KML script file name
|
||||
_ASSERT(sizeof(szKmlFile) == sizeof(szCurrentKml));
|
||||
lstrcpyn(szKmlFile,szCurrentKml,ARRAYSIZEOF(szKmlFile));
|
||||
|
||||
bKMLChanged = FALSE; // KML script not changed
|
||||
bSucc = TRUE; // KML script successful loaded
|
||||
const char *filenameUTF8 = (*env)->GetStringUTFChars(env, kmlFilename , NULL) ;
|
||||
_tcscpy(szCurrentKml, filenameUTF8);
|
||||
(*env)->ReleaseStringUTFChars(env, kmlFilename, filenameUTF8);
|
||||
|
||||
// bKMLChanged = FALSE; // KML script not changed
|
||||
BOOL bSucc = TRUE; // KML script successful loaded
|
||||
|
||||
chooseCurrentKmlMode = ChooseKmlMode_CHANGE_KML;
|
||||
|
||||
// do
|
||||
// {
|
||||
|
@ -866,12 +869,27 @@ JNIEXPORT void JNICALL Java_org_emulator_forty_eight_NativeLib_onViewScript(JNIE
|
|||
// }
|
||||
// else // quit with Ok
|
||||
// {
|
||||
bKMLChanged = TRUE; // KML script changed
|
||||
// bKMLChanged = TRUE; // KML script changed
|
||||
bSucc = InitKML(szCurrentKml,FALSE);
|
||||
// }
|
||||
// }
|
||||
// while (!bSucc); // retry if KML script is invalid
|
||||
|
||||
BOOL result = bSucc;
|
||||
|
||||
if(!bSucc) {
|
||||
// restore KML script file name
|
||||
lstrcpyn(szCurrentKml,szKmlFile,ARRAYSIZEOF(szCurrentKml));
|
||||
|
||||
_tcsncpy(szKmlLogBackup, szKmlLog, sizeof(szKmlLog) / sizeof(TCHAR));
|
||||
|
||||
// try to restore old KML script
|
||||
bSucc = InitKML(szCurrentKml,FALSE);
|
||||
|
||||
_tcsncpy(szKmlLog, szKmlLogBackup, sizeof(szKmlLog) / sizeof(TCHAR));
|
||||
}
|
||||
chooseCurrentKmlMode = ChooseKmlMode_UNKNOWN;
|
||||
|
||||
if (bSucc)
|
||||
{
|
||||
if (Chipset.wRomCrc != wRomCrc) // ROM changed
|
||||
|
@ -890,6 +908,8 @@ JNIEXPORT void JNICALL Java_org_emulator_forty_eight_NativeLib_onViewScript(JNIE
|
|||
}
|
||||
mainViewResizeCallback(nBackgroundW, nBackgroundH);
|
||||
draw();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_emulator_forty_eight_NativeLib_onBackupSave(JNIEnv *env, jobject thisz) {
|
||||
|
|
|
@ -97,7 +97,7 @@ HANDLE CreateFile(LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
|
|||
|
||||
TCHAR * foundDocumentScheme = _tcsstr(lpFileName, documentScheme);
|
||||
|
||||
if(chooseCurrentKmlMode == ChooseKmlMode_FILE_OPEN) {
|
||||
if(chooseCurrentKmlMode == ChooseKmlMode_FILE_OPEN || chooseCurrentKmlMode == ChooseKmlMode_CHANGE_KML) {
|
||||
// When we open a new E48 state document
|
||||
TCHAR * fileExtension = _tcsrchr(lpFileName, _T('.'));
|
||||
if(fileExtension && ((fileExtension[1] == 'K' && fileExtension[2] == 'M' && fileExtension[3] == 'L') ||
|
||||
|
|
|
@ -1128,7 +1128,8 @@ extern TCHAR szChosenCurrentKml[MAX_PATH];
|
|||
enum ChooseKmlMode {
|
||||
ChooseKmlMode_UNKNOWN,
|
||||
ChooseKmlMode_FILE_NEW,
|
||||
ChooseKmlMode_FILE_OPEN
|
||||
ChooseKmlMode_FILE_OPEN,
|
||||
ChooseKmlMode_CHANGE_KML
|
||||
};
|
||||
extern enum ChooseKmlMode chooseCurrentKmlMode;
|
||||
BOOL getFirstKMLFilenameForType(BYTE chipsetType, TCHAR * firstKMLFilename, size_t firstKMLFilenameSize);
|
||||
|
|
|
@ -66,8 +66,10 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|||
public static final int INTENT_OBJECT_SAVE = 4;
|
||||
public static final int INTENT_SETTINGS = 5;
|
||||
public static final int INTENT_PORT2LOAD = 6;
|
||||
public static final int INTENT_PICK_KML_FOLDER = 7;
|
||||
//public static final int INTENT_PICK_KML_FILE = 8;
|
||||
public static final int INTENT_PICK_KML_FOLDER_FOR_NEW_FILE = 7;
|
||||
public static final int INTENT_PICK_KML_FOLDER_FOR_CHANGING = 8;
|
||||
public static final int INTENT_PICK_KML_FOLDER_FOR_SETTINGS = 9;
|
||||
//public static final int INTENT_PICK_KML_FILE = 10;
|
||||
|
||||
public static MainActivity mainActivity;
|
||||
|
||||
|
@ -630,44 +632,52 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|||
// By default Port1 is set
|
||||
setPort1Settings(true, true);
|
||||
|
||||
extractKMLScripts();
|
||||
|
||||
ensureDocumentSaved(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final int lastIndex = kmlScripts.size();
|
||||
final String[] kmlScriptTitles = new String[lastIndex + 2];
|
||||
for (int i = 0; i < kmlScripts.size(); i++)
|
||||
kmlScriptTitles[i] = kmlScripts.get(i).title;
|
||||
kmlScriptTitles[lastIndex] = getResources().getString(R.string.load_custom_kml);
|
||||
kmlScriptTitles[lastIndex + 1] = getResources().getString(R.string.load_default_kml);
|
||||
new AlertDialog.Builder(MainActivity.this)
|
||||
.setTitle(getResources().getString(R.string.pick_calculator))
|
||||
.setItems(kmlScriptTitles, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if(which == lastIndex) {
|
||||
// Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
|
||||
// intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
// intent.setType(kmlMimeType);
|
||||
// intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
|
||||
// startActivityForResult(intent, INTENT_PICK_KML_FILE);
|
||||
|
||||
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
|
||||
startActivityForResult(intent, INTENT_PICK_KML_FOLDER);
|
||||
} else if(which == lastIndex + 1) {
|
||||
// Reset to default KML folder
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.putBoolean("settings_kml_default", true);
|
||||
//editor.putString("settings_kml_folder", url);
|
||||
editor.apply();
|
||||
OnFileNew();
|
||||
} else {
|
||||
String kmlScriptFilename = kmlScripts.get(which).filename;
|
||||
newFileFromKML(kmlScriptFilename);
|
||||
}
|
||||
}
|
||||
}).show();
|
||||
// extractKMLScripts();
|
||||
//
|
||||
// final ArrayList<KMLScriptItem> kmlScriptsForCurrentModel = kmlScripts;
|
||||
//
|
||||
// final int lastIndex = kmlScriptsForCurrentModel.size();
|
||||
// final String[] kmlScriptTitles = new String[lastIndex + 2];
|
||||
// for (int i = 0; i < kmlScriptsForCurrentModel.size(); i++)
|
||||
// kmlScriptTitles[i] = kmlScriptsForCurrentModel.get(i).title;
|
||||
// kmlScriptTitles[lastIndex] = getResources().getString(R.string.load_custom_kml);
|
||||
// kmlScriptTitles[lastIndex + 1] = getResources().getString(R.string.load_default_kml);
|
||||
// new AlertDialog.Builder(MainActivity.this)
|
||||
// .setTitle(getResources().getString(R.string.pick_calculator))
|
||||
// .setItems(kmlScriptTitles, new DialogInterface.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(DialogInterface dialog, int which) {
|
||||
// if(which == lastIndex) {
|
||||
//// Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
|
||||
//// intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
//// intent.setType(kmlMimeType);
|
||||
//// intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
|
||||
//// startActivityForResult(intent, INTENT_PICK_KML_FILE);
|
||||
//
|
||||
// Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
|
||||
// Bundle bundle = new Bundle();
|
||||
// bundle.putString("mode", "new-kml");
|
||||
// intent.putExtras(bundle);
|
||||
// startActivityForResult(intent, INTENT_PICK_KML_FOLDER);
|
||||
// } else if(which == lastIndex + 1) {
|
||||
// // Reset to default KML folder
|
||||
// SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
// editor.putBoolean("settings_kml_default", true);
|
||||
// //editor.putString("settings_kml_folder", url);
|
||||
// editor.apply();
|
||||
// OnFileNew();
|
||||
// //OnViewScript();
|
||||
// } else {
|
||||
// String kmlScriptFilename = kmlScriptsForCurrentModel.get(which).filename;
|
||||
// newFileFromKML(kmlScriptFilename);
|
||||
// }
|
||||
// }
|
||||
// }).show();
|
||||
showKMLPicker(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -842,38 +852,71 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|||
|
||||
}
|
||||
private void OnViewScript() {
|
||||
extractKMLScripts();
|
||||
|
||||
if (NativeLib.getState() != 0 /*SM_RUN*/)
|
||||
{
|
||||
if (NativeLib.getState() != 0 /*SM_RUN*/) {
|
||||
showAlert("You cannot change the KML script when Emu48 is not running.\n"
|
||||
+ "Use the File,New menu item to create a new calculator.");
|
||||
return;
|
||||
}
|
||||
final ArrayList<KMLScriptItem> kmlScriptsForCurrentModel = new ArrayList<>();
|
||||
char m = (char)NativeLib.getCurrentModel();
|
||||
for (int i = 0; i < kmlScripts.size(); i++) {
|
||||
KMLScriptItem kmlScriptItem = kmlScripts.get(i);
|
||||
if (kmlScriptItem.model.charAt(0) == m)
|
||||
kmlScriptsForCurrentModel.add(kmlScriptItem);
|
||||
}
|
||||
|
||||
final String[] kmlScriptTitles = new String[kmlScriptsForCurrentModel.size()];
|
||||
showKMLPicker(true);
|
||||
}
|
||||
|
||||
private void showKMLPicker(final boolean changeKML) {
|
||||
extractKMLScripts();
|
||||
|
||||
final ArrayList<KMLScriptItem> kmlScriptsForCurrentModel;
|
||||
if(changeKML) {
|
||||
kmlScriptsForCurrentModel = new ArrayList<KMLScriptItem>();
|
||||
char m = (char) NativeLib.getCurrentModel();
|
||||
for (int i = 0; i < kmlScripts.size(); i++) {
|
||||
KMLScriptItem kmlScriptItem = kmlScripts.get(i);
|
||||
if (kmlScriptItem.model.charAt(0) == m)
|
||||
kmlScriptsForCurrentModel.add(kmlScriptItem);
|
||||
}
|
||||
} else
|
||||
kmlScriptsForCurrentModel = kmlScripts;
|
||||
|
||||
final int lastIndex = kmlScriptsForCurrentModel.size();
|
||||
final String[] kmlScriptTitles = new String[lastIndex + 2];
|
||||
for (int i = 0; i < kmlScriptsForCurrentModel.size(); i++)
|
||||
kmlScriptTitles[i] = kmlScriptsForCurrentModel.get(i).title;
|
||||
kmlScriptTitles[lastIndex] = getResources().getString(R.string.load_custom_kml);
|
||||
kmlScriptTitles[lastIndex + 1] = getResources().getString(R.string.load_default_kml);
|
||||
new AlertDialog.Builder(MainActivity.this)
|
||||
.setTitle("Pick a calculator")
|
||||
.setTitle(getResources().getString(R.string.pick_calculator))
|
||||
.setItems(kmlScriptTitles, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
String kmlScriptFilename = kmlScriptsForCurrentModel.get(which).filename;
|
||||
NativeLib.onViewScript(kmlScriptFilename);
|
||||
displayKMLTitle();
|
||||
showKMLLog();
|
||||
updateNavigationDrawerItems();
|
||||
if(which == lastIndex) {
|
||||
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
|
||||
startActivityForResult(intent, changeKML ? INTENT_PICK_KML_FOLDER_FOR_CHANGING : INTENT_PICK_KML_FOLDER_FOR_NEW_FILE);
|
||||
} else if(which == lastIndex + 1) {
|
||||
// Reset to default KML folder
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.putBoolean("settings_kml_default", true);
|
||||
//editor.putString("settings_kml_folder", url);
|
||||
editor.apply();
|
||||
if(changeKML)
|
||||
OnViewScript();
|
||||
else
|
||||
OnFileNew();
|
||||
} else {
|
||||
String kmlScriptFilename = kmlScriptsForCurrentModel.get(which).filename;
|
||||
if(changeKML) {
|
||||
int result = NativeLib.onViewScript(kmlScriptFilename);
|
||||
if(result > 0) {
|
||||
displayKMLTitle();
|
||||
showKMLLog();
|
||||
} else
|
||||
showKMLLogForce();
|
||||
updateNavigationDrawerItems();
|
||||
} else
|
||||
newFileFromKML(kmlScriptFilename);
|
||||
}
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
|
||||
private void OnTopics() {
|
||||
startActivity(new Intent(this, InfoWebActivity.class));
|
||||
}
|
||||
|
@ -930,14 +973,27 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|||
// DocumentFile parentDocumentFile = documentFile.getParentFile();
|
||||
// break;
|
||||
// }
|
||||
case INTENT_PICK_KML_FOLDER: {
|
||||
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);
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.putBoolean("settings_kml_default", false);
|
||||
editor.putString("settings_kml_folder", url);
|
||||
editor.apply();
|
||||
makeUriPersistableReadOnly(data, uri);
|
||||
OnFileNew();
|
||||
|
||||
switch (requestCode) {
|
||||
case INTENT_PICK_KML_FOLDER_FOR_NEW_FILE:
|
||||
OnFileNew();
|
||||
break;
|
||||
case INTENT_PICK_KML_FOLDER_FOR_CHANGING:
|
||||
OnViewScript();
|
||||
break;
|
||||
case INTENT_PICK_KML_FOLDER_FOR_SETTINGS:
|
||||
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
|
@ -38,7 +38,7 @@ public class NativeLib {
|
|||
public static native void onStackCopy();
|
||||
public static native void onStackPaste();
|
||||
public static native void onViewReset();
|
||||
public static native void onViewScript(String kmlFilename);
|
||||
public static native int onViewScript(String kmlFilename);
|
||||
public static native void onBackupSave();
|
||||
public static native void onBackupRestore();
|
||||
public static native void onBackupDelete();
|
||||
|
|
|
@ -305,7 +305,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
|
||||
startActivityForResult(intent, MainActivity.INTENT_PICK_KML_FOLDER);
|
||||
startActivityForResult(intent, MainActivity.INTENT_PICK_KML_FOLDER_FOR_SETTINGS);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
@ -413,22 +413,28 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||
if(resultCode == Activity.RESULT_OK) {
|
||||
if(resultCode == Activity.RESULT_OK && data != null) {
|
||||
if(requestCode == MainActivity.INTENT_PORT2LOAD) {
|
||||
Uri uri = data.getData();
|
||||
//Log.d(TAG, "onActivityResult INTENT_PORT2LOAD " + uri.toString());
|
||||
String url = uri.toString();
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.putString("settings_port2load", url);
|
||||
editor.apply();
|
||||
makeUriPersistable(data, uri);
|
||||
} else if(requestCode == MainActivity.INTENT_PICK_KML_FOLDER) {
|
||||
String url = null;
|
||||
if (uri != null) {
|
||||
url = uri.toString();
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.putString("settings_port2load", url);
|
||||
editor.apply();
|
||||
makeUriPersistable(data, uri);
|
||||
}
|
||||
} else if(requestCode == MainActivity.INTENT_PICK_KML_FOLDER_FOR_SETTINGS) {
|
||||
Uri uri = data.getData();
|
||||
String url = uri.toString();
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.putString("settings_kml_folder", url);
|
||||
editor.apply();
|
||||
makeUriPersistableReadOnly(data, uri);
|
||||
String url = null;
|
||||
if (uri != null) {
|
||||
url = uri.toString();
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.putString("settings_kml_folder", url);
|
||||
editor.apply();
|
||||
makeUriPersistableReadOnly(data, uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
|
Loading…
Reference in a new issue