This commit is contained in:
parent
dbe24a0891
commit
33686c480a
6 changed files with 187 additions and 13 deletions
|
@ -34,6 +34,8 @@ extern void mainViewResizeCallback(int x, int y);
|
|||
extern int openFileFromContentResolver(const TCHAR * url, int writeAccess);
|
||||
extern int closeFileFromContentResolver(int fd);
|
||||
extern int showAlert(const TCHAR * messageText, int flags);
|
||||
extern void sendMenuItemCommand(int menuItem);
|
||||
|
||||
void clipboardCopyText(const TCHAR * text);
|
||||
const TCHAR * clipboardPasteText();
|
||||
|
||||
|
|
|
@ -126,6 +126,13 @@ int showAlert(const TCHAR * messageText, int flags) {
|
|||
return IDOK;
|
||||
}
|
||||
|
||||
void sendMenuItemCommand(int menuItem) {
|
||||
JNIEnv *jniEnv = getJNIEnvironment();
|
||||
jclass mainActivityClass = (*jniEnv)->GetObjectClass(jniEnv, mainActivity);
|
||||
jmethodID midStr = (*jniEnv)->GetMethodID(jniEnv, mainActivityClass, "sendMenuItemCommand", "(I)V");
|
||||
(*jniEnv)->CallVoidMethod(jniEnv, mainActivity, midStr, menuItem);
|
||||
}
|
||||
|
||||
void clipboardCopyText(const TCHAR * text) {
|
||||
JNIEnv *jniEnv = getJNIEnvironment();
|
||||
jclass mainActivityClass = (*jniEnv)->GetObjectClass(jniEnv, mainActivity);
|
||||
|
|
|
@ -657,8 +657,9 @@ LRESULT SendMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {
|
|||
BOOL PostMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {
|
||||
//TODO
|
||||
if(hWnd == 0 && Msg == WM_COMMAND) {
|
||||
int menuCommand = (wParam & 0xffff);
|
||||
int menuCommand = (wParam & 0xffff) - 40000;
|
||||
LOGD("Menu Item %d", menuCommand);
|
||||
sendMenuItemCommand(menuCommand);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1510,9 +1511,6 @@ BOOL StretchBlt(HDC hdcDest, int xDest, int yDest, int wDest, int hDest, HDC hdc
|
|||
}
|
||||
UINT SetDIBColorTable(HDC hdc, UINT iStart, UINT cEntries, CONST RGBQUAD *prgbq) {
|
||||
if(prgbq
|
||||
// && hdc && hdc->selectedPalette && hdc->selectedPalette->paletteLog && hdc->selectedPalette->paletteLog->palPalEntry
|
||||
// && hdc->selectedPalette->paletteLog->palNumEntries > 0 && iStart < hdc->selectedPalette->paletteLog->palNumEntries) {
|
||||
// PALETTEENTRY * palPalEntry = hdc->selectedPalette->paletteLog->palPalEntry;
|
||||
&& hdc && hdc->realizedPalette && hdc->realizedPalette->paletteLog && hdc->realizedPalette->paletteLog->palPalEntry
|
||||
&& hdc->realizedPalette->paletteLog->palNumEntries > 0 && iStart < hdc->realizedPalette->paletteLog->palNumEntries) {
|
||||
PALETTEENTRY * palPalEntry = hdc->realizedPalette->paletteLog->palPalEntry;
|
||||
|
|
|
@ -22,6 +22,7 @@ import android.provider.MediaStore;
|
|||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.SubMenu;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
@ -45,8 +46,10 @@ import java.util.Comparator;
|
|||
import java.util.Date;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
@ -95,6 +98,15 @@ public class MainActivity extends AppCompatActivity
|
|||
Print
|
||||
}
|
||||
|
||||
private int MRU_ID_START = 10000;
|
||||
private int MAX_MRU = 5;
|
||||
private LinkedHashMap<String, String> mruLinkedHashMap = new LinkedHashMap<String, String>(5, 1.0f, true) {
|
||||
@Override
|
||||
protected boolean removeEldestEntry(Map.Entry eldest) {
|
||||
return size() > MAX_MRU;
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -152,6 +164,15 @@ public class MainActivity extends AppCompatActivity
|
|||
AssetManager assetManager = getResources().getAssets();
|
||||
NativeLib.start(assetManager, mainScreenView.getBitmapMainScreen(), this, mainScreenView);
|
||||
|
||||
Set<String> savedMRU = sharedPreferences.getStringSet("MRU", null);
|
||||
if(savedMRU != null) {
|
||||
for (String url : savedMRU) {
|
||||
mruLinkedHashMap.put(url, null);
|
||||
}
|
||||
}
|
||||
|
||||
updateMRU();
|
||||
|
||||
updateFromPreferences(null, false);
|
||||
sharedPreferenceChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
|
||||
@Override
|
||||
|
@ -211,6 +232,25 @@ public class MainActivity extends AppCompatActivity
|
|||
drawer.openDrawer(GravityCompat.START);
|
||||
}
|
||||
|
||||
private void updateMRU() {
|
||||
Menu menu = navigationView.getMenu();
|
||||
MenuItem recentsMenuItem = menu.findItem(R.id.nav_item_recents);
|
||||
SubMenu recentsSubMenu = null;
|
||||
if(recentsMenuItem != null) {
|
||||
recentsSubMenu = recentsMenuItem.getSubMenu();
|
||||
if (recentsSubMenu != null)
|
||||
recentsSubMenu.clear();
|
||||
}
|
||||
if (recentsSubMenu != null) {
|
||||
Set<String> mruLinkedHashMapKeySet = mruLinkedHashMap.keySet();
|
||||
String[] mrus = mruLinkedHashMapKeySet.toArray(new String[mruLinkedHashMapKeySet.size()]);
|
||||
for (int i = mrus.length - 1; i >= 0; i--) {
|
||||
String displayName = getFilenameFromURL(mrus[i]);
|
||||
recentsSubMenu.add(Menu.NONE, MRU_ID_START + i, Menu.NONE, displayName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
@ -228,9 +268,15 @@ public class MainActivity extends AppCompatActivity
|
|||
if(NativeLib.isDocumentAvailable() && sharedPreferences.getBoolean("settings_autosave", true)) {
|
||||
String currentFilename = NativeLib.getCurrentFilename();
|
||||
if (currentFilename != null && currentFilename.length() > 0) {
|
||||
NativeLib.onFileSave();
|
||||
if(NativeLib.onFileSave() == 1)
|
||||
showAlert("State saved");
|
||||
}
|
||||
}
|
||||
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.putStringSet("MRU", mruLinkedHashMap.keySet());
|
||||
editor.apply();
|
||||
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
|
@ -342,6 +388,25 @@ public class MainActivity extends AppCompatActivity
|
|||
OnTopics();
|
||||
} else if (id == R.id.nav_about) {
|
||||
OnAbout();
|
||||
} else if(id >= MRU_ID_START && id < MRU_ID_START + MAX_MRU) {
|
||||
|
||||
Set<String> mruLinkedHashMapKeySet = mruLinkedHashMap.keySet();
|
||||
int mruLength = mruLinkedHashMapKeySet.size();
|
||||
String[] mrus = mruLinkedHashMapKeySet.toArray(new String[mruLength]);
|
||||
|
||||
int mruClickedIndex = id - MRU_ID_START;
|
||||
final String url = mrus[mruClickedIndex];
|
||||
mruLinkedHashMap.get(url);
|
||||
|
||||
ensureDocumentSaved(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if(onFileOpen(url) != 0) {
|
||||
saveLastDocument(url);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
|
@ -462,7 +527,8 @@ public class MainActivity extends AppCompatActivity
|
|||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (which == DialogInterface.BUTTON_POSITIVE) {
|
||||
if (hasFilename) {
|
||||
NativeLib.onFileSave();
|
||||
if(NativeLib.onFileSave() == 1)
|
||||
showAlert("State saved");
|
||||
if (continueCallback != null)
|
||||
continueCallback.run();
|
||||
} else {
|
||||
|
@ -529,7 +595,6 @@ public class MainActivity extends AppCompatActivity
|
|||
});
|
||||
}
|
||||
private void OnFileSave() {
|
||||
//NativeLib.onFileSave();
|
||||
ensureDocumentSaved(null);
|
||||
}
|
||||
private void OnFileSaveAs() {
|
||||
|
@ -703,6 +768,7 @@ public class MainActivity extends AppCompatActivity
|
|||
public void onClick(DialogInterface dialog, int which) {
|
||||
String kmlScriptFilename = kmlScriptsForCurrentModel.get(which).filename;
|
||||
NativeLib.onViewScript(kmlScriptFilename);
|
||||
displayKMLTitle();
|
||||
showKMLLog();
|
||||
updateNavigationDrawerItems();
|
||||
}
|
||||
|
@ -738,6 +804,7 @@ public class MainActivity extends AppCompatActivity
|
|||
|
||||
String url = uri.toString();
|
||||
if(NativeLib.onFileSaveAs(url) != 0) {
|
||||
showAlert("State saved");
|
||||
saveLastDocument(url);
|
||||
makeUriPersistable(data, uri);
|
||||
displayFilename(url);
|
||||
|
@ -770,7 +837,10 @@ public class MainActivity extends AppCompatActivity
|
|||
private void saveLastDocument(String url) {
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.putString("lastDocument", url);
|
||||
editor.commit();
|
||||
editor.apply();
|
||||
|
||||
mruLinkedHashMap.put(url, null);
|
||||
updateMRU();
|
||||
}
|
||||
|
||||
private void makeUriPersistable(Intent data, Uri uri) {
|
||||
|
@ -788,19 +858,30 @@ public class MainActivity extends AppCompatActivity
|
|||
}
|
||||
|
||||
private void displayFilename(String url) {
|
||||
String displayName = getFilenameFromURL(url);
|
||||
View header = displayKMLTitle();
|
||||
TextView textViewSubtitle = header.findViewById(R.id.nav_header_subtitle);
|
||||
if(textViewSubtitle != null)
|
||||
textViewSubtitle.setText(displayName);
|
||||
}
|
||||
|
||||
private String getFilenameFromURL(String url) {
|
||||
String displayName = "";
|
||||
try {
|
||||
displayName = SettingsActivity.getFileName(this, url);
|
||||
} catch(Exception e) {
|
||||
// Do nothing
|
||||
}
|
||||
return displayName;
|
||||
}
|
||||
|
||||
private View displayKMLTitle() {
|
||||
NavigationView navigationView = findViewById(R.id.nav_view);
|
||||
View header = navigationView.getHeaderView(0);
|
||||
TextView textViewTitle = header.findViewById(R.id.nav_header_title);
|
||||
if(textViewTitle != null)
|
||||
textViewTitle.setText(NativeLib.getKMLTitle());
|
||||
TextView textViewSubtitle = header.findViewById(R.id.nav_header_subtitle);
|
||||
if(textViewSubtitle != null)
|
||||
textViewSubtitle.setText(displayName);
|
||||
return header;
|
||||
}
|
||||
|
||||
private void showKMLLog() {
|
||||
|
@ -858,8 +939,86 @@ public class MainActivity extends AppCompatActivity
|
|||
}
|
||||
|
||||
void showAlert(String text) {
|
||||
Snackbar.make(getWindow().getDecorView().getRootView(), "text", Snackbar.LENGTH_LONG).setAction("Action", null).show();
|
||||
Snackbar.make(findViewById(R.id.main_coordinator), text, Snackbar.LENGTH_SHORT).setAction("Action", null).show();
|
||||
}
|
||||
|
||||
void sendMenuItemCommand(int menuItem) {
|
||||
switch (menuItem) {
|
||||
case 1: // FILE_NEW
|
||||
OnFileNew();
|
||||
break;
|
||||
case 2: // FILE_OPEN
|
||||
OnFileOpen();
|
||||
break;
|
||||
case 3: // FILE_SAVE
|
||||
OnFileSave();
|
||||
break;
|
||||
case 4: // FILE_SAVEAS
|
||||
OnFileSaveAs();
|
||||
break;
|
||||
case 5: // FILE_EXIT
|
||||
break;
|
||||
case 6: // EDIT_COPY_SCREEN
|
||||
OnViewCopy();
|
||||
break;
|
||||
case 7: // FILE_SETTINGS
|
||||
OnSettings();
|
||||
break;
|
||||
case 8: // EDIT_RESET
|
||||
OnViewReset();
|
||||
break;
|
||||
case 9: // EDIT_LOAD_OBJECT
|
||||
OnObjectLoad();
|
||||
break;
|
||||
case 10: // EDIT_SAVE_OBJECT
|
||||
OnObjectSave();
|
||||
break;
|
||||
case 11: // HELP_ABOUT
|
||||
OnAbout();
|
||||
break;
|
||||
case 12: // HELP_TOPICS
|
||||
OnTopics();
|
||||
break;
|
||||
case 13: // FILE_CLOSE
|
||||
OnFileClose();
|
||||
break;
|
||||
case 14: // EDIT_BACKUP_SAVE
|
||||
OnBackupSave();
|
||||
break;
|
||||
case 15: // EDIT_BACKUP_RESTORE
|
||||
OnBackupRestore();
|
||||
break;
|
||||
case 16: // EDIT_BACKUP_DELETE
|
||||
OnBackupDelete();
|
||||
break;
|
||||
case 17: // VIEW_SCRIPT
|
||||
OnViewScript();
|
||||
break;
|
||||
case 18: // EDIT_PORT_CONFIGURATION
|
||||
break;
|
||||
case 19: // EDIT_COPY_STRING
|
||||
OnStackCopy();
|
||||
break;
|
||||
case 20: // EDIT_PASTE_STRING
|
||||
OnStackPaste();
|
||||
break;
|
||||
case 21: // TOOL_DISASM
|
||||
break;
|
||||
case 22: // TOOL_DEBUG
|
||||
break;
|
||||
case 23: // TOOL_MACRO_RECORD
|
||||
break;
|
||||
case 24: // TOOL_MACRO_PLAY
|
||||
break;
|
||||
case 25: // TOOL_MACRO_STOP
|
||||
break;
|
||||
case 26: // TOOL_MACRO_SETTINGS
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void clipboardCopyText(String text) {
|
||||
// Gets a handle to the clipboard service.
|
||||
ClipboardManager clipboard = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/main_coordinator"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".MainActivity">
|
||||
|
|
|
@ -93,6 +93,12 @@ info *action
|
|||
android:title="@string/action_settings" />
|
||||
</group>
|
||||
|
||||
<item android:id="@+id/nav_item_recents"
|
||||
android:title="Recent">
|
||||
<menu android:id="@+id/nav_menu_recents">
|
||||
</menu>
|
||||
</item>
|
||||
|
||||
<item android:title="Edit">
|
||||
<menu>
|
||||
<item
|
||||
|
|
Loading…
Reference in a new issue