diff --git a/README.md b/README.md index c377df3..94781cb 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![logo](https://raw.githubusercontent.com/epicstudios856/Vectras-VM-Android/master/resources/vectras-logo.png) +![logo](https://github.com/ahmedbarakat2007/Vectras-windows-emulator/assets/118398763/096d4a06-8d3c-489f-9fb5-d273f361200c) [![Telegram Channel][ico-telegram]][link-telegram] [![Latest Version][ico-version]][link-releases] [![Software License][ico-license]](LICENSE.md) diff --git a/app/build.gradle b/app/build.gradle index 6ac037f..9260881 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -20,8 +20,8 @@ android { applicationId "com.vectras.vm" minSdk 21 targetSdk 34 - versionCode 6 - versionName "2.2" + versionCode 7 + versionName "2.3" ndk { abiFilters "armeabi-v7a","arm64-v8a", "x86", "x86_64" } testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" @@ -53,8 +53,8 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.6.1' implementation 'com.google.android.material:material:1.11.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' - implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.2' - implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2' + implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.7.0' + implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.7.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0" implementation 'androidx.navigation:navigation-fragment:2.7.6' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 09bf96c..91024df 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -98,7 +98,9 @@ + android:launchMode="singleTask" + android:theme="@style/Theme.FullScreen" + android:windowSoftInputMode="adjustPan" /> =0) { - SDLActivity.onNativeKeyDown(code); - delayKey(100); - SDLActivity.onNativeKeyUp(code); - delayKey(100); - } - SDLActivity.onNativeKeyUp(KeyEvent.KEYCODE_ALT_LEFT); - delayKey(100); - SDLActivity.onNativeKeyUp(KeyEvent.KEYCODE_CTRL_LEFT); - } + Thread t = new Thread(new Runnable() { + public void run() { + // Log.d("SDL", "Mouse Single Click"); + try { + Thread.sleep(50); + } catch (InterruptedException ex) { + // Log.v("singletap", "Could not sleep"); + } + MainActivity.vmexecutor.onVectrasMouse(Config.SDL_MOUSE_LEFT, MotionEvent.ACTION_DOWN, 1,0, 0); + try { + Thread.sleep(50); + } catch (InterruptedException ex) { + // Log.v("singletap", "Could not sleep"); + } + MainActivity.vmexecutor.onVectrasMouse(Config.SDL_MOUSE_LEFT, MotionEvent.ACTION_UP, 1, 0, 0); + } + }); + t.start(); + } - public void stopTimeListener() { - Log.v("SaveVM", "Stopping Listener"); - synchronized (this.lockTime) { - this.timeQuit = true; - this.lockTime.notifyAll(); - } - } + public void setParams() { - public void onDestroy() { + if (MainActivity.vmexecutor == null) { + return; + } + memory = MainActivity.vmexecutor.memory; + vga_type = MainActivity.vmexecutor.vga_type; + hd_cache = MainActivity.vmexecutor.hd_cache; + snapshot_name = MainActivity.vmexecutor.snapshot_name; + disableacpi = MainActivity.vmexecutor.disableacpi; + disablehpet = MainActivity.vmexecutor.disablehpet; + disabletsc = MainActivity.vmexecutor.disabletsc; + enableqmp = MainActivity.vmexecutor.enableqmp; + enablevnc = MainActivity.vmexecutor.enablevnc; - // Now wait for the SDL thread to quit - Log.v("VectrasSDL", "Waiting for SDL thread to quit"); - if (mSDLThread != null) { - try { - mSDLThread.join(); - } catch (Exception e) { - Log.v("SDL", "Problem stopping thread: " + e); - } - mSDLThread = null; + if (MainActivity.vmexecutor.cpu.endsWith("(64Bit)")) { + cpu = MainActivity.vmexecutor.cpu.split(" ")[0]; + } else { + cpu = MainActivity.vmexecutor.cpu; + } - Log.v("SDL", "Finished waiting for SDL thread"); - } - this.stopTimeListener(); + if (MainActivity.vmexecutor.cd_iso_path == null || MainActivity.vmexecutor.cd_iso_path.equals("None")) { + cd_iso_path = null; + } else { + cd_iso_path = MainActivity.vmexecutor.cd_iso_path; + } + if (MainActivity.vmexecutor.hda_img_path == null || MainActivity.vmexecutor.hda_img_path.equals("None")) { + hda_img_path = null; + } else { + hda_img_path = MainActivity.vmexecutor.hda_img_path; + } - MainActivity.vmexecutor.doStopVM(0); - super.onDestroy(); - } + if (MainActivity.vmexecutor.hdb_img_path == null || MainActivity.vmexecutor.hdb_img_path.equals("None")) { + hdb_img_path = null; + } else { + hdb_img_path = MainActivity.vmexecutor.hdb_img_path; + } - public void startTimeListener() { - this.stopTimeListener(); - timeQuit = false; - try { - Log.v("Listener", "Time Listener Started..."); - - synchronized (lockTime) { - while (timeQuit == false) { - lockTime.wait(); - } - lockTime.notifyAll(); - } - } catch (Exception ex) { - ex.printStackTrace(); - Log.v("SaveVM", "Time listener thread error: " + ex.getMessage()); - } - Log.v("Listener", "Time listener thread exited..."); + if (MainActivity.vmexecutor.hdc_img_path == null || MainActivity.vmexecutor.hdc_img_path.equals("None")) { + hdc_img_path = null; + } else { + hdc_img_path = MainActivity.vmexecutor.hdc_img_path; + } - } + if (MainActivity.vmexecutor.hdd_img_path == null || MainActivity.vmexecutor.hdd_img_path.equals("None")) { + hdd_img_path = null; + } else { + hdd_img_path = MainActivity.vmexecutor.hdd_img_path; + } - public static boolean toggleKeyboardFlag = true; + if (MainActivity.vmexecutor.fda_img_path == null || MainActivity.vmexecutor.fda_img_path.equals("None")) { + fda_img_path = null; + } else { + fda_img_path = MainActivity.vmexecutor.fda_img_path; + } -// @Override -// public boolean onOptionsItemSelected(final MenuItem item) { -// // Log.v("Vectras", "Inside Options Check"); -// super.onOptionsItemSelected(item); -// if (item.getItemId() == R.id.itemReset) { -// Machine.resetVM(activity); -// } else if (item.getItemId() == R.id.itemShutdown) { -// UIUtils.hideKeyboard(this, mSurface); -// Machine.stopVM(activity); -// } else if (item.getItemId() == R.id.itemMouse) { -// onMouseMode(); -// } else if (item.getItemId() == this.KEYBOARD || item.getItemId() == R.id.itemKeyboard) { -// //XXX: need to post after delay to work correctly -// new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { -// @Override -// public void run() { -// toggleKeyboardFlag = UIUtils.onKeyboard(activity, toggleKeyboardFlag, mSurface); -// } -// }, 200); -// -// } -// else if (item.getItemId() == R.id.itemMonitor) { -// if (this.monitorMode) { -// this.onVMConsole(); -// } else { -// this.onMonitor(); -// } -// } else if (item.getItemId() == R.id.itemVolume) { -// this.onSelectMenuVol(); -// } else if (item.getItemId() == R.id.itemSaveState) { -// this.promptPause(activity); -// } else if (item.getItemId() == R.id.itemSaveSnapshot) { -// //TODO: -// //this.promptStateName(activity); -// } else if (item.getItemId() == R.id.itemFitToScreen) { -// onFitToScreen(); -// } else if (item.getItemId() == R.id.itemStretchToScreen) { -// onStretchToScreen(); -// } else if (item.getItemId() == R.id.itemZoomIn) { -// this.setZoomIn(); -// } else if (item.getItemId() == R.id.itemZoomOut) { -// this.setZoomOut(); -// } else if (item.getItemId() == R.id.itemCtrlAltDel) { -// this.onCtrlAltDel(); -// } else if (item.getItemId() == R.id.itemCtrlC) { -// this.onCtrlC(); -// } else if (item.getItemId() == R.id.itemOneToOne) { -// this.onNormalScreen(); -// } else if (item.getItemId() == R.id.itemZoomable) { -// this.setZoomable(); -// } else if (item.getItemId() == this.QUIT) { -// } else if (item.getItemId() == R.id.itemHelp) { -// UIUtils.onHelp(this); -// } else if (item.getItemId() == R.id.itemHideToolbar) { -// this.onHideToolbar(); -// } else if (item.getItemId() == R.id.itemDisplay) { -// this.onSelectMenuSDLDisplay(); -// } else if (item.getItemId() == R.id.itemViewLog) { -// this.onViewLog(); -// } -// // this.canvas.requestFocus(); -// -// -// this.invalidateOptionsMenu(); -// return true; -// } + if (MainActivity.vmexecutor.fdb_img_path == null || MainActivity.vmexecutor.fdb_img_path.equals("None")) { + fdb_img_path = null; + } else { + fdb_img_path = MainActivity.vmexecutor.fdb_img_path; + } + if (MainActivity.vmexecutor.bootdevice == null) { + bootdevice = null; + } else if (MainActivity.vmexecutor.bootdevice.equals("Default")) { + bootdevice = null; + } else if (MainActivity.vmexecutor.bootdevice.equals("CD Rom")) { + bootdevice = "d"; + } else if (MainActivity.vmexecutor.bootdevice.equals("Floppy")) { + bootdevice = "a"; + } else if (MainActivity.vmexecutor.bootdevice.equals("Hard Disk")) { + bootdevice = "c"; + } + + if (MainActivity.vmexecutor.net_cfg == null || MainActivity.vmexecutor.net_cfg.equals("None")) { + net_cfg = "none"; + nic_driver = null; + } else if (MainActivity.vmexecutor.net_cfg.equals("User")) { + net_cfg = "user"; + nic_driver = MainActivity.vmexecutor.nic_card; + } + + soundcard = MainActivity.vmexecutor.sound_card; + + } + + public static void delayKey(int ms) { + try { + Thread.sleep(ms); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + public static void sendCtrlAltKey(int code) { + delayKey(100); + SDLActivity.onNativeKeyDown(KeyEvent.KEYCODE_CTRL_LEFT); + delayKey(100); + SDLActivity.onNativeKeyDown(KeyEvent.KEYCODE_ALT_LEFT); + delayKey(100); + if(code>=0) { + SDLActivity.onNativeKeyDown(code); + delayKey(100); + SDLActivity.onNativeKeyUp(code); + delayKey(100); + } + SDLActivity.onNativeKeyUp(KeyEvent.KEYCODE_ALT_LEFT); + delayKey(100); + SDLActivity.onNativeKeyUp(KeyEvent.KEYCODE_CTRL_LEFT); + } + + public void stopTimeListener() { + Log.v("SaveVM", "Stopping Listener"); + synchronized (this.lockTime) { + this.timeQuit = true; + this.lockTime.notifyAll(); + } + } + + public void onDestroy() { + + // Now wait for the SDL thread to quit + Log.v("MainSDL", "Waiting for SDL thread to quit"); + if (mSDLThread != null) { + try { + mSDLThread.join(); + } catch (Exception e) { + Log.v("SDL", "Problem stopping thread: " + e); + } + mSDLThread = null; + + Log.v("SDL", "Finished waiting for SDL thread"); + } + this.stopTimeListener(); + + MainActivity.vmexecutor.doStopVM(0); + super.onDestroy(); + } + + + public void checkStatus() { + while (timeQuit != true) { + MainActivity.VMStatus status = Machine.checkSaveVMStatus(activity); + Log.v(TAG, "Status: " + status); + if (status == MainActivity.VMStatus.Unknown + || status == MainActivity.VMStatus.Completed + || status == MainActivity.VMStatus.Failed + ) { + Log.v("Inside", "Saving state is done: " + status); + stopTimeListener(); + return; + } + try { + Thread.sleep(1000); + } catch (InterruptedException ex) { + Log.w("SaveVM", "Interrupted"); + } + } + Log.v("SaveVM", "Save state complete"); + + } + + + public void startTimeListener() { + this.stopTimeListener(); + timeQuit = false; + try { + Log.v("Listener", "Time Listener Started..."); + checkStatus(); + synchronized (lockTime) { + while (timeQuit == false) { + lockTime.wait(); + } + lockTime.notifyAll(); + } + } catch (Exception ex) { + ex.printStackTrace(); + Log.v("SaveVM", "Time listener thread error: " + ex.getMessage()); + } + Log.v("Listener", "Time listener thread exited..."); + + } + + public static boolean toggleKeyboardFlag = true; + + @Override + public boolean onOptionsItemSelected(final MenuItem item) { + // Log.v("Limbo", "Inside Options Check"); + super.onOptionsItemSelected(item); + if (item.getItemId() == R.id.itemReset) { + Machine.resetVM(activity); + } else if (item.getItemId() == R.id.itemShutdown) { + UIUtils.hideKeyboard(this, mSurface); + Machine.stopVM(activity); + } else if (item.getItemId() == R.id.itemMouse) { + onMouseMode(); + } else if (item.getItemId() == this.KEYBOARD || item.getItemId() == R.id.itemKeyboard) { + //XXX: need to post after delay to work correctly + new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { + @Override + public void run() { + toggleKeyboardFlag = UIUtils.onKeyboard(activity, toggleKeyboardFlag, mSurface); + } + }, 200); + + } + else if (item.getItemId() == R.id.itemMonitor) { + if (this.monitorMode) { + this.onVMConsole(); + } else { + this.onMonitor(); + } + } else if (item.getItemId() == R.id.itemVolume) { + this.onSelectMenuVol(); + } else if (item.getItemId() == R.id.itemSaveState) { + this.promptPause(activity); + } else if (item.getItemId() == R.id.itemSaveSnapshot) { + //TODO: + //this.promptStateName(activity); + } else if (item.getItemId() == R.id.itemFitToScreen) { + onFitToScreen(); + } else if (item.getItemId() == R.id.itemStretchToScreen) { + onStretchToScreen(); + } else if (item.getItemId() == R.id.itemZoomIn) { + this.setZoomIn(); + } else if (item.getItemId() == R.id.itemZoomOut) { + this.setZoomOut(); + } else if (item.getItemId() == R.id.itemCtrlAltDel) { + this.onCtrlAltDel(); + } else if (item.getItemId() == R.id.itemCtrlC) { + this.onCtrlC(); + } else if (item.getItemId() == R.id.itemOneToOne) { + this.onNormalScreen(); + } else if (item.getItemId() == R.id.itemZoomable) { + this.setZoomable(); + } else if (item.getItemId() == this.QUIT) { + } else if (item.getItemId() == R.id.itemHelp) { + + } else if (item.getItemId() == R.id.itemHideToolbar) { + this.onHideToolbar(); + } else if (item.getItemId() == R.id.itemDisplay) { + this.onSelectMenuSDLDisplay(); + } else if (item.getItemId() == R.id.itemViewLog) { + this.onViewLog(); + } + // this.canvas.requestFocus(); + + + this.invalidateOptionsMenu(); + return true; + } public void onViewLog() { FileUtils.viewVectrasLog(this); @@ -328,7 +462,7 @@ public class MainSDLActivity extends SDLActivity { setUIModeMobile(true); break; case 1: - promptSetUIModeDesktop(false); + promptSetUIModeDesktop(false); break; default: break; @@ -341,45 +475,45 @@ public class MainSDLActivity extends SDLActivity { } - public boolean checkVMResolutionFits() { - int width = mLayout.getWidth(); - int height = mLayout.getHeight(); - ActionBar bar = activity.getSupportActionBar(); + public boolean checkVMResolutionFits() { + int width = mLayout.getWidth(); + int height = mLayout.getHeight(); + ActionBar bar = activity.getSupportActionBar(); - if (!MainSettingsManager.getAlwaysShowMenuToolbar(MainSDLActivity.this) - && bar != null && bar.isShowing()) { - height += bar.getHeight(); - } + if (!MainSettingsManager.getAlwaysShowMenuToolbar(MainSDLActivity.this) + && bar != null && bar.isShowing()) { + height += bar.getHeight(); + } - if(vm_width < width && vm_height < height) - return true; + if(vm_width < width && vm_height < height) + return true; - return false; - } + return false; + } public void calibration() { - //XXX: No need to calibrate for SDL trackpad. + //XXX: No need to calibrate for SDL trackpad. } private void setUIModeMobile(boolean fitToScreen){ - try { - UIUtils.setOrientation(this); - MotionEvent a = MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, 0, 0, 0); + try { + UIUtils.setOrientation(this); + MotionEvent a = MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, 0, 0, 0); - //TODO: needed? - //MainSDLActivity.singleClick(a, 0); - Config.mouseMode = Config.MouseMode.Trackpad; - MainSettingsManager.setDesktopMode(this, false); - MainActivity.vmexecutor.setRelativeMouseMode(1); + //TODO: needed? + //MainSDLActivity.singleClick(a, 0); + Config.mouseMode = Config.MouseMode.Trackpad; + MainSettingsManager.setDesktopMode(this, false); + MainActivity.vmexecutor.setRelativeMouseMode(1); if(Config.showToast) UIUtils.toastShort(this.getApplicationContext(), "Trackpad Enabled"); - if(fitToScreen) - onFitToScreen(); - else - onNormalScreen(); - calibration(); - invalidateOptionsMenu(); + if(fitToScreen) + onFitToScreen(); + else + onNormalScreen(); + calibration(); + invalidateOptionsMenu(); }catch (Exception ex){ if(Config.debug) ex.printStackTrace(); @@ -391,7 +525,7 @@ public class MainSDLActivity extends SDLActivity { final AlertDialog alertDialog; - alertDialog = new AlertDialog.Builder(activity, R.style.MainDialogTheme).create(); + alertDialog = new AlertDialog.Builder(activity).create(); alertDialog.setTitle("Desktop Mode"); LinearLayout mLayout = new LinearLayout(this); @@ -400,19 +534,19 @@ public class MainSDLActivity extends SDLActivity { TextView textView = new TextView(activity); textView.setVisibility(View.VISIBLE); - String desktopInstructions = this.getString(R.string.desktopInstructions); - if(!checkVMResolutionFits()){ - String resolutionWarning = "Warning: Machine resolution " - + vm_width+ "x" + vm_height + - " is too high for Desktop Mode. " + - "Scaling will be used and Mouse Alignment will not be accurate. " + - "Reduce display resolution within the Guest OS for better experience.\n\n"; - desktopInstructions = resolutionWarning + desktopInstructions; - } - textView.setText(desktopInstructions); + String desktopInstructions = this.getString(R.string.desktopInstructions); + if(!checkVMResolutionFits()){ + String resolutionWarning = "Warning: MainActivity.vmexecutor resolution " + + vm_width+ "x" + vm_height + + " is too high for Desktop Mode. " + + "Scaling will be used and Mouse Alignment will not be accurate. " + + "Reduce display resolution within the Guest OS for better experience.\n\n"; + desktopInstructions = resolutionWarning + desktopInstructions; + } + textView.setText(desktopInstructions); - ScrollView scrollView = new ScrollView(this); - scrollView.addView(textView); + ScrollView scrollView = new ScrollView(this); + scrollView.addView(textView); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); @@ -437,7 +571,7 @@ public class MainSDLActivity extends SDLActivity { private void setUIModeDesktop() { - try { + try { MotionEvent a = MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, 0, 0, 0); //TODO: needed? @@ -456,65 +590,65 @@ public class MainSDLActivity extends SDLActivity { calibration(); invalidateOptionsMenu(); }catch (Exception ex){ - if(Config.debug) - ex.printStackTrace(); + if(Config.debug) + ex.printStackTrace(); } - } + } private void onCtrlAltDel() { - SDLActivity.onNativeKeyDown(KeyEvent.KEYCODE_CTRL_RIGHT); - SDLActivity.onNativeKeyDown(KeyEvent.KEYCODE_ALT_RIGHT); - SDLActivity.onNativeKeyDown(KeyEvent.KEYCODE_FORWARD_DEL); - SDLActivity.onNativeKeyUp(KeyEvent.KEYCODE_FORWARD_DEL); - SDLActivity.onNativeKeyUp(KeyEvent.KEYCODE_ALT_RIGHT); - SDLActivity.onNativeKeyUp(KeyEvent.KEYCODE_CTRL_RIGHT); - } + SDLActivity.onNativeKeyDown(KeyEvent.KEYCODE_CTRL_RIGHT); + SDLActivity.onNativeKeyDown(KeyEvent.KEYCODE_ALT_RIGHT); + SDLActivity.onNativeKeyDown(KeyEvent.KEYCODE_FORWARD_DEL); + SDLActivity.onNativeKeyUp(KeyEvent.KEYCODE_FORWARD_DEL); + SDLActivity.onNativeKeyUp(KeyEvent.KEYCODE_ALT_RIGHT); + SDLActivity.onNativeKeyUp(KeyEvent.KEYCODE_CTRL_RIGHT); + } - private void onCtrlC() { + private void onCtrlC() { - SDLActivity.onNativeKeyDown(KeyEvent.KEYCODE_CTRL_RIGHT); - SDLActivity.onNativeKeyDown(KeyEvent.KEYCODE_C); - SDLActivity.onNativeKeyUp(KeyEvent.KEYCODE_C); - SDLActivity.onNativeKeyUp(KeyEvent.KEYCODE_CTRL_RIGHT); - } + SDLActivity.onNativeKeyDown(KeyEvent.KEYCODE_CTRL_RIGHT); + SDLActivity.onNativeKeyDown(KeyEvent.KEYCODE_C); + SDLActivity.onNativeKeyUp(KeyEvent.KEYCODE_C); + SDLActivity.onNativeKeyUp(KeyEvent.KEYCODE_CTRL_RIGHT); + } - //TODO: not working - private void onStretchToScreen() { + //TODO: not working + private void onStretchToScreen() { - new Thread(new Runnable() { - public void run() { - Log.d(TAG, "onStretchToScreen"); - screenMode = SDLScreenMode.Fullscreen; + new Thread(new Runnable() { + public void run() { + Log.d(TAG, "onStretchToScreen"); + screenMode = SDLScreenMode.Fullscreen; sendCtrlAltKey(KeyEvent.KEYCODE_F); // not working if(Config.showToast) UIUtils.toastShort(activity, "Resizing, Please Wait"); resize(null); - } - }).start(); + } + }).start(); - } + } - private void onFitToScreen() { - try { - UIUtils.setOrientation(this); - ActionBar bar = MainSDLActivity.this.getSupportActionBar(); - if (bar != null && !MainSettingsManager.getAlwaysShowMenuToolbar(this)) { - bar.hide(); - } - new Thread(new Runnable() { - public void run() { - Log.d(TAG, "onFitToScreen"); - screenMode = SDLScreenMode.FitToScreen; - if(Config.showToast) - UIUtils.toastShort(activity, "Resizing, Please Wait"); - resize(null); + private void onFitToScreen() { + try { + UIUtils.setOrientation(this); + ActionBar bar = MainSDLActivity.this.getSupportActionBar(); + if (bar != null && !MainSettingsManager.getAlwaysShowMenuToolbar(this)) { + bar.hide(); + } + new Thread(new Runnable() { + public void run() { + Log.d(TAG, "onFitToScreen"); + screenMode = SDLScreenMode.FitToScreen; + if(Config.showToast) + UIUtils.toastShort(activity, "Resizing, Please Wait"); + resize(null); - } - }).start(); + } + }).start(); }catch (Exception ex){ if(Config.debug) ex.printStackTrace(); @@ -522,23 +656,23 @@ public class MainSDLActivity extends SDLActivity { } - private void onNormalScreen() { - try { - ActionBar bar = MainSDLActivity.this.getSupportActionBar(); - if (bar != null && !MainSettingsManager.getAlwaysShowMenuToolbar(this)) { - bar.hide(); - } - setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); - new Thread(new Runnable() { - public void run() { - Log.d(TAG, "onNormalScreen"); - screenMode = SDLScreenMode.Normal; - if(Config.showToast) - UIUtils.toastShort(activity, "Resizing, Please Wait"); - resize(null); + private void onNormalScreen() { + try { + ActionBar bar = MainSDLActivity.this.getSupportActionBar(); + if (bar != null && !MainSettingsManager.getAlwaysShowMenuToolbar(this)) { + bar.hide(); + } + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); + new Thread(new Runnable() { + public void run() { + Log.d(TAG, "onNormalScreen"); + screenMode = SDLScreenMode.Normal; + if(Config.showToast) + UIUtils.toastShort(activity, "Resizing, Please Wait"); + resize(null); - } - }).start(); + } + }).start(); }catch (Exception ex){ if(Config.debug) ex.printStackTrace(); @@ -546,396 +680,629 @@ public class MainSDLActivity extends SDLActivity { } - public void resize(final Configuration newConfig) { + public void resize(final Configuration newConfig) { - //XXX: flag so no mouse events are processed - isResizing = true; + //XXX: flag so no mouse events are processed + isResizing = true; - //XXX: This is needed so Nougat+ devices will update their layout - new Handler(Looper.getMainLooper()).post(new Runnable() { - @Override - public void run() { - ((ExSDLSurface) mSurface).getHolder().setFixedSize(1, 1); + //XXX: This is needed so Nougat+ devices will update their layout + new Handler(Looper.getMainLooper()).post(new Runnable() { + @Override + public void run() { + ((MainSDLSurface) mSurface).getHolder().setFixedSize(1, 1); setLayout(newConfig); new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { @Override public void run() { - //vsdl((VectrasSDLSurface) mSurface).doResize(false, newConfig); + ((MainSDLSurface) mSurface).doResize(false, newConfig); } }, 1000); - } - }); + } + }); - } + } - private void setZoomIn() { + private void setZoomIn() { - new Thread(new Runnable() { - public void run() { - screenMode = SDLScreenMode.Normal; - sendCtrlAltKey(KeyEvent.KEYCODE_4); - } - }).start(); - - } - - private void setZoomOut() { - - - new Thread(new Runnable() { - public void run() { + new Thread(new Runnable() { + public void run() { screenMode = SDLScreenMode.Normal; - sendCtrlAltKey(KeyEvent.KEYCODE_3); + sendCtrlAltKey(KeyEvent.KEYCODE_4); + } + }).start(); - } - }).start(); + } - } - - private void setZoomable() { - - zoomable = true; - - } - -// @Override -// public boolean onPrepareOptionsMenu(Menu menu) { -// menu.clear(); -// return this.setupMenu(menu); -// } -// -// @Override -// public boolean onCreateOptionsMenu(Menu menu) { -// menu.clear(); -// return this.setupMenu(menu); -// } -// -// public boolean setupMenu(Menu menu) { -// // Log.v("Vectras", "Inside Options Created"); -// getMenuInflater().inflate(R.menu.sdlactivitymenu, menu); -// -// int maxMenuItemsShown = 4; -// int actionShow = MenuItemCompat.SHOW_AS_ACTION_IF_ROOM; -// if(UIUtils.isLandscapeOrientation(this)) { -// maxMenuItemsShown = 6; -// actionShow = MenuItemCompat.SHOW_AS_ACTION_ALWAYS; -// } -// -// // if (vncCanvas.scaling != null) { -// // menu.findItem(vncCanvas.scaling.getId()).setChecked(true); -// // } -// -// // Remove snapshots for now -// menu.removeItem(menu.findItem(R.id.itemSaveSnapshot).getItemId()); -// -// // Remove Monitor console for SDL2 it creates 2 SDL windows and SDL for -// // android supports only 1 -// menu.removeItem(menu.findItem(R.id.itemMonitor).getItemId()); -// -// // Remove scaling for now -// menu.removeItem(menu.findItem(R.id.itemScaling).getItemId()); -// -// // Remove external mouse for now -// menu.removeItem(menu.findItem(R.id.itemExternalMouse).getItemId()); -// //menu.removeItem(menu.findItem(R.id.itemUIMode).getItemId()); -// -// menu.removeItem(menu.findItem(R.id.itemCtrlAltDel).getItemId()); -// menu.removeItem(menu.findItem(R.id.itemCtrlC).getItemId()); -// -// if (MainSettingsManager.getAlwaysShowMenuToolbar(activity) || Config.mouseMode == Config.MouseMode.External) { -// menu.removeItem(menu.findItem(R.id.itemHideToolbar).getItemId()); -// maxMenuItemsShown--; -// } -// -// if (soundcard==null || soundcard.equals("None")) { -// menu.removeItem(menu.findItem(R.id.itemVolume).getItemId()); -// maxMenuItemsShown--; -// } -// -// -// -// for (int i = 0; i < menu.size() && i < maxMenuItemsShown; i++) { -// MenuItemCompat.setShowAsAction(menu.getItem(i), actionShow); -// } -// -// return true; -// -// } - - private void onMonitor() { - new Thread(new Runnable() { - public void run() { - monitorMode = true; - // final KeyEvent altDown = new KeyEvent(downTime, eventTime, - // KeyEvent.ACTION_DOWN, - // KeyEvent.KEYCODE_2, 1, KeyEvent.META_ALT_LEFT_ON); - sendCtrlAltKey(KeyEvent.KEYCODE_2); - // sendCtrlAltKey(altDown); - Log.v("Vectras", "Monitor On"); - } - }).start(); - - } - - private void onVMConsole() { - monitorMode = false; - sendCtrlAltKey(KeyEvent.KEYCODE_1); - } + private void setZoomOut() { - // FIXME: We need this to able to catch complex characters strings like - // grave and send it as text - @Override - public boolean dispatchKeyEvent(KeyEvent event) { - if (event.getAction() == KeyEvent.ACTION_MULTIPLE && event.getKeyCode() == KeyEvent.KEYCODE_UNKNOWN) { - sendText(event.getCharacters().toString()); - return true; - } else if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) { - this.onBackPressed(); - return true; - } if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN) { - // We emulate right click with volume down - if(event.getAction() == KeyEvent.ACTION_DOWN) { - MotionEvent e = MotionEvent.obtain(1000, 1000, MotionEvent.ACTION_DOWN, 0, 0, 0, 0, 0, 0, 0, - InputDevice.SOURCE_TOUCHSCREEN, 0); - rightClick(e, 0); - } - return true; - } else if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) { - // We emulate middle click with volume up - if(event.getAction() == KeyEvent.ACTION_DOWN) { - MotionEvent e = MotionEvent.obtain(1000, 1000, MotionEvent.ACTION_DOWN, 0, 0, 0, 0, 0, 0, 0, - InputDevice.SOURCE_TOUCHSCREEN, 0); - middleClick(e, 0); - } - return true; - } else { - return super.dispatchKeyEvent(event); - } + new Thread(new Runnable() { + public void run() { + screenMode = SDLScreenMode.Normal; + sendCtrlAltKey(KeyEvent.KEYCODE_3); - } + } + }).start(); - private static void sendText(String string) { + } - // Log.v("sendText", string); - KeyCharacterMap keyCharacterMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD); - KeyEvent[] keyEvents = keyCharacterMap.getEvents(string.toCharArray()); - if (keyEvents != null) - for (int i = 0; i < keyEvents.length; i++) { + private void setZoomable() { - if (keyEvents[i].getAction() == KeyEvent.ACTION_DOWN) { - // Log.v("sendText", "Up: " + keyEvents[i].getKeyCode()); - SDLActivity.onNativeKeyDown(keyEvents[i].getKeyCode()); - } else if (keyEvents[i].getAction() == KeyEvent.ACTION_UP) { - // Log.v("sendText", "Down: " + keyEvents[i].getKeyCode()); - SDLActivity.onNativeKeyUp(keyEvents[i].getKeyCode()); - } - } - } + zoomable = true; + + } + + @Override + public boolean onPrepareOptionsMenu(Menu menu) { + menu.clear(); + return this.setupMenu(menu); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + menu.clear(); + return this.setupMenu(menu); + } + + public boolean setupMenu(Menu menu) { + // Log.v("Limbo", "Inside Options Created"); + getMenuInflater().inflate(R.menu.sdlactivitymenu, menu); + + int maxMenuItemsShown = 4; + int actionShow = MenuItemCompat.SHOW_AS_ACTION_IF_ROOM; + if(UIUtils.isLandscapeOrientation(this)) { + maxMenuItemsShown = 6; + actionShow = MenuItemCompat.SHOW_AS_ACTION_ALWAYS; + } + + // if (vncCanvas.scaling != null) { + // menu.findItem(vncCanvas.scaling.getId()).setChecked(true); + // } + + // Remove snapshots for now + menu.removeItem(menu.findItem(R.id.itemSaveSnapshot).getItemId()); + + // Remove Monitor console for SDL2 it creates 2 SDL windows and SDL for + // android supports only 1 + menu.removeItem(menu.findItem(R.id.itemMonitor).getItemId()); + + // Remove scaling for now + menu.removeItem(menu.findItem(R.id.itemScaling).getItemId()); + + // Remove external mouse for now + menu.removeItem(menu.findItem(R.id.itemExternalMouse).getItemId()); + //menu.removeItem(menu.findItem(R.id.itemUIMode).getItemId()); + + menu.removeItem(menu.findItem(R.id.itemCtrlAltDel).getItemId()); + menu.removeItem(menu.findItem(R.id.itemCtrlC).getItemId()); + + if (MainSettingsManager.getAlwaysShowMenuToolbar(activity) || Config.mouseMode == Config.MouseMode.External) { + menu.removeItem(menu.findItem(R.id.itemHideToolbar).getItemId()); + maxMenuItemsShown--; + } + + if (soundcard==null || soundcard.equals("None")) { + menu.removeItem(menu.findItem(R.id.itemVolume).getItemId()); + maxMenuItemsShown--; + } - // Setup - protected void onCreate(Bundle savedInstanceState) { - // Log.v("SDL", "onCreate()"); + + for (int i = 0; i < menu.size() && i < maxMenuItemsShown; i++) { + MenuItemCompat.setShowAsAction(menu.getItem(i), actionShow); + } + + return true; + + } + + private void onMonitor() { + new Thread(new Runnable() { + public void run() { + monitorMode = true; + // final KeyEvent altDown = new KeyEvent(downTime, eventTime, + // KeyEvent.ACTION_DOWN, + // KeyEvent.KEYCODE_2, 1, KeyEvent.META_ALT_LEFT_ON); + sendCtrlAltKey(KeyEvent.KEYCODE_2); + // sendCtrlAltKey(altDown); + Log.v("Limbo", "Monitor On"); + } + }).start(); + + } + + private void onVMConsole() { + monitorMode = false; + sendCtrlAltKey(KeyEvent.KEYCODE_1); + } + + + // FIXME: We need this to able to catch complex characters strings like + // grave and send it as text + @Override + public boolean dispatchKeyEvent(KeyEvent event) { + if (event.getAction() == KeyEvent.ACTION_MULTIPLE && event.getKeyCode() == KeyEvent.KEYCODE_UNKNOWN) { + sendText(event.getCharacters().toString()); + return true; + } else if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) { + this.onBackPressed(); + return true; + } if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN) { + // We emulate right click with volume down + if(event.getAction() == KeyEvent.ACTION_DOWN) { + MotionEvent e = MotionEvent.obtain(1000, 1000, MotionEvent.ACTION_DOWN, 0, 0, 0, 0, 0, 0, 0, + InputDevice.SOURCE_TOUCHSCREEN, 0); + rightClick(e, 0); + } + return true; + } else if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) { + // We emulate middle click with volume up + if(event.getAction() == KeyEvent.ACTION_DOWN) { + MotionEvent e = MotionEvent.obtain(1000, 1000, MotionEvent.ACTION_DOWN, 0, 0, 0, 0, 0, 0, 0, + InputDevice.SOURCE_TOUCHSCREEN, 0); + middleClick(e, 0); + } + return true; + } else { + return super.dispatchKeyEvent(event); + } + + } + + private static void sendText(String string) { + + // Log.v("sendText", string); + KeyCharacterMap keyCharacterMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD); + KeyEvent[] keyEvents = keyCharacterMap.getEvents(string.toCharArray()); + if (keyEvents != null) + for (int i = 0; i < keyEvents.length; i++) { + + if (keyEvents[i].getAction() == KeyEvent.ACTION_DOWN) { + // Log.v("sendText", "Up: " + keyEvents[i].getKeyCode()); + SDLActivity.onNativeKeyDown(keyEvents[i].getKeyCode()); + } else if (keyEvents[i].getAction() == KeyEvent.ACTION_UP) { + // Log.v("sendText", "Down: " + keyEvents[i].getKeyCode()); + SDLActivity.onNativeKeyUp(keyEvents[i].getKeyCode()); + } + } + } + + + String[] functionsArray = {"F1", "F2", "F3", "F4", + "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12"}; + + View view; + private final String CREDENTIAL_SHARED_PREF = "settings_prefs"; + private LogsAdapter mLogAdapter; + private RecyclerView logList; + private Timer _timer = new Timer(); + private TimerTask t; + public boolean ctrlClicked = false; + public boolean altClicked = false; + // Setup + @SuppressLint("UseCompatLoadingForDrawables") + protected void onCreate(Bundle savedInstanceState) { + // Log.v("SDL", "onCreate()"); activity = this; - if (MainSettingsManager.getFullscreen(this)) - getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, - WindowManager.LayoutParams.FLAG_FULLSCREEN); + if (MainSettingsManager.getFullscreen(this)) + getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, + WindowManager.LayoutParams.FLAG_FULLSCREEN); - super.onCreate(savedInstanceState); + super.onCreate(savedInstanceState); setupVolume(); - mSingleton = this; + mSingleton = this; - Log.v("SDL", "Max Mem = " + Runtime.getRuntime().maxMemory()); + Log.v("SDL", "Max Mem = " + Runtime.getRuntime().maxMemory()); - this.activity1 = this; + this.activity1 = this; - // So we can call stuff from static callbacks - mSingleton = this; + // So we can call stuff from static callbacks + mSingleton = this; - createUI(0, 0); + createUI(0, 0); - UIUtils.showHints(this); + UIUtils.showHints(this); - this.resumeVM(); + this.resumeVM(); UIUtils.setOrientation(this); - } + View decorView = getWindow().getDecorView(); + int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; + decorView.setSystemUiVisibility(uiOptions); + + onFitToScreen(); + + ImageButton shutdownBtn = findViewById(R.id.shutdownBtn); + ImageButton settingBtn = findViewById(R.id.btnSettings); + ImageButton keyboardBtn = findViewById(R.id.kbdBtn); + ImageButton controllersBtn = findViewById(R.id.btnMode); + ImageButton upBtn = findViewById(R.id.upBtn); + ImageButton leftBtn = findViewById(R.id.leftBtn); + ImageButton downBtn = findViewById(R.id.downBtn); + ImageButton rightBtn = findViewById(R.id.rightBtn); + ImageButton enterBtn = findViewById(R.id.enterBtn); + ImageButton escBtn = findViewById(R.id.escBtn); + ImageButton ctrlBtn = findViewById(R.id.ctrlBtn); + ImageButton altBtn = findViewById(R.id.altBtn); + ImageButton delBtn = findViewById(R.id.delBtn); + Button ctrlAltDelBtn = findViewById(R.id.ctrlAltDelBtn); + ImageButton qmpBtn = findViewById(R.id.btnQmp); + ImageButton btnLogs = findViewById(R.id.btnLogs); + btnLogs.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + FileUtils.viewVectrasLog(activity); + } + }); + shutdownBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Machine.stopVM(activity); + } + }); + keyboardBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { + @Override + public void run() { + toggleKeyboardFlag = UIUtils.onKeyboard(activity, toggleKeyboardFlag, mSurface); + } + }, 200); + } + }); + controllersBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); + // Create and show the dialog. + ControlersOptionsFragment newFragment = new ControlersOptionsFragment(); + newFragment.show(ft, "Controllers"); + } + }); + settingBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + final Dialog alertDialog = new Dialog(activity, R.style.MainDialogTheme); + alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); + alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); + alertDialog.setContentView(R.layout.dialog_setting); + alertDialog.show(); + } + }); + upBtn.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + if (event.getAction() == MotionEvent.ACTION_DOWN) { + SDLActivity.onNativeKeyDown(KeyEvent.KEYCODE_DPAD_UP); + return true; + } else if (event.getAction() == MotionEvent.ACTION_UP) { + SDLActivity.onNativeKeyUp(KeyEvent.KEYCODE_DPAD_UP); + return true; + } + return false; + } + }); + leftBtn.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + if (event.getAction() == MotionEvent.ACTION_DOWN) { + SDLActivity.onNativeKeyDown(KeyEvent.KEYCODE_DPAD_LEFT); + return true; + } else if (event.getAction() == MotionEvent.ACTION_UP) { + SDLActivity.onNativeKeyUp(KeyEvent.KEYCODE_DPAD_LEFT); + return true; + } + return false; + } + }); + downBtn.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + if (event.getAction() == MotionEvent.ACTION_DOWN) { + SDLActivity.onNativeKeyDown(KeyEvent.KEYCODE_DPAD_DOWN); + return true; + } else if (event.getAction() == MotionEvent.ACTION_UP) { + SDLActivity.onNativeKeyUp(KeyEvent.KEYCODE_DPAD_DOWN); + return true; + } + return false; + } + }); + rightBtn.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + if (event.getAction() == MotionEvent.ACTION_DOWN) { + SDLActivity.onNativeKeyDown(KeyEvent.KEYCODE_DPAD_RIGHT); + return true; + } else if (event.getAction() == MotionEvent.ACTION_UP) { + SDLActivity.onNativeKeyUp(KeyEvent.KEYCODE_DPAD_RIGHT); + return true; + } + return false; + } + }); + escBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + delayKey(100); + SDLActivity.onNativeKeyDown(KeyEvent.KEYCODE_ESCAPE); + delayKey(100); + SDLActivity.onNativeKeyUp(KeyEvent.KEYCODE_ESCAPE); + } + }); + enterBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + delayKey(100); + SDLActivity.onNativeKeyDown(KeyEvent.KEYCODE_ENTER); + delayKey(100); + SDLActivity.onNativeKeyDown(KeyEvent.KEYCODE_ENTER); + } + }); + ctrlBtn.setOnClickListener(new View.OnClickListener() { + @SuppressLint("UseCompatLoadingForDrawables") + @Override + public void onClick(View v) { + if (!ctrlClicked) { + SDLActivity.onNativeKeyDown(KeyEvent.KEYCODE_CTRL_LEFT); + ctrlBtn.setBackground(getResources().getDrawable(R.drawable.controls_button2)); + ctrlClicked = true; + } else { + SDLActivity.onNativeKeyUp(KeyEvent.KEYCODE_CTRL_LEFT); + ctrlBtn.setBackground(getResources().getDrawable(R.drawable.controls_button1)); + ctrlClicked = false; + } + } + }); + altBtn.setOnClickListener(new View.OnClickListener() { + @SuppressLint("UseCompatLoadingForDrawables") + @Override + public void onClick(View v) { + if (!altClicked) { + SDLActivity.onNativeKeyDown(KeyEvent.KEYCODE_ALT_LEFT); + altBtn.setBackground(getResources().getDrawable(R.drawable.controls_button2)); + altClicked = true; + } else { + SDLActivity.onNativeKeyUp(KeyEvent.KEYCODE_ALT_LEFT); + altBtn.setBackground(getResources().getDrawable(R.drawable.controls_button1)); + altClicked = false; + } + } + }); + delBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + delayKey(100); + SDLActivity.onNativeKeyDown(KeyEvent.KEYCODE_DEL); + delayKey(100); + SDLActivity.onNativeKeyDown(KeyEvent.KEYCODE_DEL); + } + }); + ctrlAltDelBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + sendCtrlAltKey(KeyEvent.KEYCODE_DEL); + } + }); + qmpBtn.setVisibility(View.GONE); + if (monitorMode) { + qmpBtn.setImageDrawable(getResources().getDrawable(R.drawable.round_terminal_24)); + } else { + qmpBtn.setImageDrawable(getResources().getDrawable(R.drawable.round_computer_24)); + } + + ArrayAdapter adapter = new ArrayAdapter<>(this, + R.layout.container_function, functionsArray); + + ListView listView = findViewById(R.id.functions); + listView.setAdapter(adapter); + /*listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + if (position == 0) { + keyDownUp(KeyEvent.KEYCODE_F1); + } else if (position == 1) { + keyDownUp(KeyEvent.KEYCODE_F2); + } else if (position == 2) { + keyDownUp(KeyEvent.KEYCODE_F3); + } else if (position == 3) { + keyDownUp(KeyEvent.KEYCODE_F4); + } else if (position == 4) { + keyDownUp(KeyEvent.KEYCODE_F5); + } else if (position == 5) { + keyDownUp(KeyEvent.KEYCODE_F6); + } else if (position == 6) { + keyDownUp(KeyEvent.KEYCODE_F7); + } else if (position == 7) { + keyDownUp(KeyEvent.KEYCODE_F8); + } else if (position == 8) { + keyDownUp(KeyEvent.KEYCODE_F9); + } else if (position == 9) { + keyDownUp(KeyEvent.KEYCODE_F10); + } else if (position == 10) { + keyDownUp(KeyEvent.KEYCODE_F11); + } else if (position == 11) { + keyDownUp(KeyEvent.KEYCODE_F12); + } + } + });*/ + } private void createUI(int w, int h) { - //mSurface = new SDLSurface(this); + mSurface = new MainSDLSurface(this); - int width = w; - int height = h; - if (width == 0) { - width = RelativeLayout.LayoutParams.WRAP_CONTENT; - } - if (height == 0) { - height = RelativeLayout.LayoutParams.WRAP_CONTENT; - } + int width = w; + int height = h; + if (width == 0) { + width = RelativeLayout.LayoutParams.WRAP_CONTENT; + } + if (height == 0) { + height = RelativeLayout.LayoutParams.WRAP_CONTENT; + } - setContentView(R.layout.activity_sdl); + setContentView(R.layout.activity_sdl); - //TODO: + //TODO: mLayout = (RelativeLayout) activity.findViewById(R.id.sdl_layout); - mMainLayout = (LinearLayout) activity.findViewById(R.id.main_layout); + mMainLayout = (LinearLayout) activity.findViewById(R.id.main_layout); - RelativeLayout mLayout = (RelativeLayout) findViewById(R.id.sdl); - RelativeLayout.LayoutParams surfaceParams = new RelativeLayout.LayoutParams(width, height); - surfaceParams.addRule(RelativeLayout.CENTER_IN_PARENT); + RelativeLayout mLayout = (RelativeLayout) findViewById(R.id.sdl); + RelativeLayout.LayoutParams surfaceParams = new RelativeLayout.LayoutParams(width, height); + surfaceParams.addRule(RelativeLayout.CENTER_IN_PARENT); - mLayout.addView(mSurface, surfaceParams); + mLayout.addView(mSurface, surfaceParams); - } + } - protected void onPause() { - Log.v("SDL", "onPause()"); - MainService.updateServiceNotification(Config.machinename + ": VM Suspended"); - super.onPause(); + protected void onPause() { + Log.v("SDL", "onPause()"); + MainService.updateServiceNotification("Vectras VM Suspended"); + super.onPause(); - } + } - public void onSelectMenuVol() { + public void onSelectMenuVol() { - final AlertDialog alertDialog; - alertDialog = new AlertDialog.Builder(activity, R.style.MainDialogTheme).create(); - alertDialog.setTitle("Volume"); + final AlertDialog alertDialog; + alertDialog = new AlertDialog.Builder(activity).create(); + alertDialog.setTitle("Volume"); LinearLayout.LayoutParams volParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); - LinearLayout t = createVolumePanel(); - t.setLayoutParams(volParams); + LinearLayout t = createVolumePanel(); + t.setLayoutParams(volParams); - ScrollView s = new ScrollView(activity); - s.addView(t); - alertDialog.setView(s); - alertDialog.setButton(Dialog.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() { + ScrollView s = new ScrollView(activity); + s.addView(t); + alertDialog.setView(s); + alertDialog.setButton(Dialog.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - alertDialog.cancel(); - } - }); - alertDialog.show(); + public void onClick(DialogInterface dialog, int which) { + alertDialog.cancel(); + } + }); + alertDialog.show(); - } + } - public LinearLayout createVolumePanel() { - LinearLayout layout = new LinearLayout (this); - layout.setPadding(20, 20, 20, 20); + public LinearLayout createVolumePanel() { + LinearLayout layout = new LinearLayout (this); + layout.setPadding(20, 20, 20, 20); LinearLayout.LayoutParams volparams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); - SeekBar vol = new SeekBar(this); + SeekBar vol = new SeekBar(this); - int volume = 0; + int volume = 0; - //TODO: - vol.setMax(maxVolume); - volume = getCurrentVolume(); + //TODO: + vol.setMax(maxVolume); + volume = getCurrentVolume(); - vol.setProgress(volume); - vol.setLayoutParams(volparams); + vol.setProgress(volume); + vol.setLayoutParams(volparams); - ((SeekBar) vol).setOnSeekBarChangeListener(new OnSeekBarChangeListener() { + ((SeekBar) vol).setOnSeekBarChangeListener(new OnSeekBarChangeListener() { - public void onProgressChanged(SeekBar s, int progress, boolean touch) { - //TODO: + public void onProgressChanged(SeekBar s, int progress, boolean touch) { + //TODO: setVolume(progress); - } + } - public void onStartTrackingTouch(SeekBar arg0) { + public void onStartTrackingTouch(SeekBar arg0) { - } + } - public void onStopTrackingTouch(SeekBar arg0) { + public void onStopTrackingTouch(SeekBar arg0) { - } - }); + } + }); - layout.addView(vol); + layout.addView(vol); - return layout; + return layout; - } + } - protected void onResume() { - Log.v("SDL", "onResume()"); - MainService.updateServiceNotification(Config.machinename + ": VM Running"); - super.onResume(); - } + protected void onResume() { + Log.v("SDL", "onResume()"); + MainService.updateServiceNotification("Vectras VM Running"); + super.onResume(); + } - // Messages from the SDLMain thread - static int COMMAND_CHANGE_TITLE = 1; - static int COMMAND_SAVEVM = 2; + // Messages from the SDLMain thread + static int COMMAND_CHANGE_TITLE = 1; + static int COMMAND_SAVEVM = 2; - public void loadLibraries() { + public void loadLibraries() { //XXX: override for the specific arch - } + } - public void promptPause(final Activity activity) { + public void promptPause(final Activity activity) { - final AlertDialog alertDialog; - alertDialog = new AlertDialog.Builder(activity, R.style.MainDialogTheme).create(); - alertDialog.setTitle("Pause VM"); - TextView stateView = new TextView(activity); - stateView.setText("This make take a while depending on the RAM size used"); - stateView.setPadding(20, 20, 20, 20); - alertDialog.setView(stateView); + final AlertDialog alertDialog; + alertDialog = new AlertDialog.Builder(activity).create(); + alertDialog.setTitle("Pause VM"); + TextView stateView = new TextView(activity); + stateView.setText("This make take a while depending on the RAM size used"); + stateView.setPadding(20, 20, 20, 20); + alertDialog.setView(stateView); - alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Pause", new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - onPauseVM(); - return; - } - }); - alertDialog.show(); - } + alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Pause", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + onPauseVM(); + return; + } + }); + alertDialog.show(); + } - private void onPauseVM() { - Thread t = new Thread(new Runnable() { - public void run() { - // Delete any previous state file - if (MainActivity.vmexecutor.save_state_name != null) { - File file = new File(MainActivity.vmexecutor.save_state_name); - if (file.exists()) { - file.delete(); - } - } + private void onPauseVM() { + Thread t = new Thread(new Runnable() { + public void run() { + // Delete any previous state file + if (MainActivity.vmexecutor.save_state_name != null) { + File file = new File(MainActivity.vmexecutor.save_state_name); + if (file.exists()) { + file.delete(); + } + } if(Config.showToast) - UIUtils.toastShort(getApplicationContext(), "Please wait while saving VM State"); - MainActivity.vmexecutor.current_fd = MainActivity.vmexecutor.get_fd(MainActivity.vmexecutor.save_state_name); + UIUtils.toastShort(getApplicationContext(), "Please wait while saving VM State"); + MainActivity.vmexecutor.current_fd = MainActivity.vmexecutor.get_fd(MainActivity.vmexecutor.save_state_name); - String uri = "fd:" + MainActivity.vmexecutor.current_fd; - String command = QmpClient.stop(); - String msg = QmpClient.sendCommand(command); - command = QmpClient.migrate(false, false, uri); - msg = QmpClient.sendCommand(command); - if (msg != null) { + String uri = "fd:" + MainActivity.vmexecutor.current_fd; + String command = QmpClient.stop(); + String msg = QmpClient.sendCommand(command); + command = QmpClient.migrate(false, false, uri); + msg = QmpClient.sendCommand(command); + if (msg != null) { processMigrationResponse(msg); } - // XXX: Instead we poll to see if migration is complete - new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { - @Override - public void run() { - VMListener a = new VMListener(); - a.execute(); - } - }, 0); - } - }); - t.start(); + // XXX: Instead we poll to see if migration is complete + new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { + @Override + public void run() { + VMListener a = new VMListener(); + a.execute(); + } + }, 0); + } + }); + t.start(); - } + } private void processMigrationResponse(String response) { String errorStr = null; @@ -943,106 +1310,97 @@ public class MainSDLActivity extends SDLActivity { JSONObject object = new JSONObject(response); errorStr = object.getString("error"); }catch (Exception ex) { - if(Config.debug) - ex.printStackTrace(); + if(Config.debug) + ex.printStackTrace(); } - if (errorStr != null) { - String descStr = null; - - try { - JSONObject descObj = new JSONObject(errorStr); - descStr = descObj.getString("desc"); - }catch (Exception ex) { - if(Config.debug) - ex.printStackTrace(); - } - final String descStr1 = descStr; - - new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { - @Override - public void run() { - Machine.pausedErrorVM(activity, descStr1); - } - }, 100); + if (errorStr != null) { + String descStr = null; + try { + JSONObject descObj = new JSONObject(errorStr); + descStr = descObj.getString("desc"); + }catch (Exception ex) { + if(Config.debug) + ex.printStackTrace(); } + final String descStr1 = descStr; + + new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { + @Override + public void run() { + Machine.pausedErrorVM(activity, descStr1); + } + }, 100); + + } } private class VMListener extends AsyncTask { - @Override - protected Void doInBackground(Void... arg0) { - startTimeListener(); - return null; - } + @Override + protected Void doInBackground(Void... arg0) { + startTimeListener(); + return null; + } - @Override - protected void onPostExecute(Void test) { + @Override + protected void onPostExecute(Void test) { - } - } + } + } - @Override - public boolean onTouchEvent(MotionEvent event) { + @Override + public boolean onTouchEvent(MotionEvent event) { boolean res = false; if(Config.mouseMode == Config.MouseMode.External){ return res; } //TODO: - //vsdlres = ((VectrasSDLSurface) this.mSurface).onTouchProcess(this.mSurface, event); - //vsdlres = ((VectrasSDLSurface) this.mSurface).onTouchEventProcess(event); - return true; - } + res = ((MainSDLSurface) this.mSurface).onTouchProcess(this.mSurface, event); + res = ((MainSDLSurface) this.mSurface).onTouchEventProcess(event); + return true; + } - private void resumeVM() { - if(MainActivity.vmexecutor == null){ - return; - } - Thread t = new Thread(new Runnable() { - public void run() { - if (MainActivity.vmexecutor.paused == 1) { + private void resumeVM() { + if(MainActivity.vmexecutor == null){ + return; + } + Thread t = new Thread(new Runnable() { + public void run() { + if (MainActivity.vmexecutor.paused == 1) { - try { - Thread.sleep(4000); - } catch (InterruptedException ex) { - Logger.getLogger(MainVNCActivity.class.getName()).log(Level.SEVERE, null, ex); - } - MainActivity.vmexecutor.paused = 0; + try { + Thread.sleep(4000); + } catch (InterruptedException ex) { + Logger.getLogger(MainVNCActivity.class.getName()).log(Level.SEVERE, null, ex); + } + MainActivity.vmexecutor.paused = 0; - String command = QmpClient.cont(); - String msg = QmpClient.sendCommand(command); - new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { - @Override - public void run() { - if(Config.mouseMode == Config.MouseMode.External) - setUIModeDesktop(); - else - setUIModeMobile(screenMode == SDLScreenMode.FitToScreen); - } - }, 500); - } - } - }); - t.start(); + String command = QmpClient.cont(); + String msg = QmpClient.sendCommand(command); + new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { + @Override + public void run() { + if(Config.mouseMode == Config.MouseMode.External) + setUIModeDesktop(); + else + setUIModeMobile(screenMode == SDLScreenMode.FitToScreen); + } + }, 500); + } + } + }); + t.start(); - } + } - public void onBackPressed() { - if (!MainSettingsManager.getAlwaysShowMenuToolbar(activity)) { - ActionBar bar = this.getSupportActionBar(); - if (bar != null) { - if (bar.isShowing()) - bar.hide(); - else - bar.show(); - } - } else { - UIUtils.hideKeyboard(this, mSurface); - Machine.stopVM(activity); - } - - } + public void onBackPressed() { + super.onBackPressed(); + UIUtils.hideKeyboard(this, mSurface); + Machine.stopVM(activity); + return; + } @Override public void onConfigurationChanged(Configuration newConfig) { @@ -1053,7 +1411,7 @@ public class MainSDLActivity extends SDLActivity { public void onSelectMenuSDLDisplay() { final AlertDialog alertDialog; - alertDialog = new AlertDialog.Builder(activity, R.style.MainDialogTheme).create(); + alertDialog = new AlertDialog.Builder(activity).create(); alertDialog.setTitle("Display"); LinearLayout.LayoutParams volParams = new LinearLayout.LayoutParams( @@ -1150,9 +1508,9 @@ public class MainSDLActivity extends SDLActivity { }; int currentScaleType = 0; if(screenMode == SDLScreenMode.FitToScreen){ - currentScaleType = 1; - } else if(screenMode == SDLScreenMode.Fullscreen) - currentScaleType = 2; + currentScaleType = 1; + } else if(screenMode == SDLScreenMode.Fullscreen) + currentScaleType = 2; final AlertDialog.Builder mBuilder = new AlertDialog.Builder(this); mBuilder.setTitle("Display Mode"); @@ -1172,12 +1530,12 @@ public class MainSDLActivity extends SDLActivity { onFitToScreen(); break; case 2: - if(Config.mouseMode == Config.MouseMode.External){ - UIUtils.toastShort(MainSDLActivity.this, "Stretch Screen Disabled under Desktop Mode"); - dialog.dismiss(); - return; - } - onStretchToScreen(); + if(Config.mouseMode == Config.MouseMode.External){ + UIUtils.toastShort(MainSDLActivity.this, "Stretch Screen Disabled under Desktop Mode"); + dialog.dismiss(); + return; + } + onStretchToScreen(); break; default: break; @@ -1192,38 +1550,38 @@ public class MainSDLActivity extends SDLActivity { @Override - protected synchronized void runSDLMain(){ + protected synchronized void runSDLMain(){ - //We go through the vm executor - MainActivity.startvm(this, Config.UI_SDL); + //We go through the vm executor + MainActivity.startvm(this, Config.UI_SDL); - //XXX: we hold the thread because SDLActivity will exit - try { - wait(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } + //XXX: we hold the thread because SDLActivity will exit + try { + wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } - public static void onVMResolutionChanged(int w, int h) - { - boolean refreshDisplay = false; + public static void onVMResolutionChanged(int w, int h) + { + boolean refreshDisplay = false; - if(w!=vm_width || h!=vm_height) - refreshDisplay = true; - vm_width = w; - vm_height = h; + if(w!=vm_width || h!=vm_height) + refreshDisplay = true; + vm_width = w; + vm_height = h; - Log.v(TAG, "VM resolution changed to " + vm_width + "x" + vm_height); + Log.v(TAG, "VM resolution changed to " + vm_width + "x" + vm_height); - if(refreshDisplay) { - activity.resize(null); - } + if(refreshDisplay) { + activity.resize(null); + } - } + } - public static boolean isResizing = false; + public static boolean isResizing = false; public enum SDLScreenMode { Normal, @@ -1283,21 +1641,21 @@ public class MainSDLActivity extends SDLActivity { this.invalidateOptionsMenu(); } - /*public class VectrasSDLSurface extends ExSDLSurface implements View.OnKeyListener, View.OnTouchListener { + public class MainSDLSurface extends ExSDLSurface implements View.OnKeyListener, View.OnTouchListener { - public boolean initialized = false; + public boolean initialized = false; - public VectrasSDLSurface(Context context) { - super(context); - setOnKeyListener(this); - setOnTouchListener(this); - gestureDetector = new GestureDetector(activity, new GestureListener()); - setOnGenericMotionListener(new SDLGenericMotionListener_API12()); - } + public MainSDLSurface(Context context) { + super(context); + setOnKeyListener(this); + setOnTouchListener(this); + gestureDetector = new GestureDetector(activity, new GestureListener()); + setOnGenericMotionListener(new SDLGenericMotionListener_API12()); + } - public void surfaceChanged(SurfaceHolder holder, - int format, int width, int height) { - super.surfaceChanged(holder, format, width, height); + public void surfaceChanged(SurfaceHolder holder, + int format, int width, int height) { + super.surfaceChanged(holder, format, width, height); new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { @Override public void run() { @@ -1306,11 +1664,11 @@ public class MainSDLActivity extends SDLActivity { SDLActivity.onNativeKeyUp(KeyEvent.KEYCODE_CTRL_LEFT); } }, 500); - } + } - @Override - public void surfaceCreated(SurfaceHolder holder) { - super.surfaceCreated(holder); + @Override + public void surfaceCreated(SurfaceHolder holder) { + super.surfaceCreated(holder); new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { @Override @@ -1322,69 +1680,68 @@ public class MainSDLActivity extends SDLActivity { setUIModeMobile(screenMode == SDLScreenMode.FitToScreen); } },1000); - } + } - @Override - public void onConfigurationChanged(Configuration newConfig) { - super.onConfigurationChanged(newConfig); + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); Log.d(TAG,"Configuration changed"); resize(newConfig); - } + } - public synchronized void doResize(boolean reverse, final Configuration newConfig) { - //XXX: notify the UI not to process mouse motion - isResizing = true; - Log.v(TAG, "Resizing Display"); + public synchronized void doResize(boolean reverse, final Configuration newConfig) { + //XXX: notify the UI not to process mouse motion + isResizing = true; + Log.v(TAG, "Resizing Display"); + Display display = SDLActivity.mSingleton.getWindowManager().getDefaultDisplay(); + int height = 0; + int width = 0; - Display display = SDLActivity.mSingleton.getWindowManager().getDefaultDisplay(); - int height = 0; - int width = 0; + Point size = new Point(); + display.getSize(size); + int screen_width = size.x; + int screen_height = size.y; - Point size = new Point(); - display.getSize(size); - int screen_width = size.x; - int screen_height = size.y; + final ActionBar bar = ((SDLActivity) activity).getSupportActionBar(); - final ActionBar bar = ((SDLActivity) activity).getSupportActionBar(); + if(MainSDLActivity.mLayout != null) { + width = MainSDLActivity.mLayout.getWidth(); + height = MainSDLActivity.mLayout.getHeight(); + } - if(MainSDLActivity.mLayout != null) { - width = MainSDLActivity.mLayout.getWidth(); - height = MainSDLActivity.mLayout.getHeight(); - } + //native resolution for use with external mouse + if(screenMode != SDLScreenMode.Fullscreen && screenMode != SDLScreenMode.FitToScreen) { + width = MainSDLActivity.vm_width; + height = MainSDLActivity.vm_height; + } - //native resolution for use with external mouse - if(screenMode != SDLScreenMode.Fullscreen && screenMode != SDLScreenMode.FitToScreen) { - width = MainSDLActivity.vm_width; - height = MainSDLActivity.vm_height; - } + if(reverse){ + int temp = width; + width = height; + height = temp; + } - if(reverse){ - int temp = width; - width = height; - height = temp; - } + boolean portrait = SDLActivity.mSingleton.getResources() + .getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT; - boolean portrait = SDLActivity.mSingleton.getResources() - .getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT; - - if (portrait) { - if(Config.mouseMode != Config.MouseMode.External) { + if (portrait) { + if(Config.mouseMode != Config.MouseMode.External) { int height_n = (int) (width / (MainSDLActivity.vm_width / (float) MainSDLActivity.vm_height)); Log.d(TAG, "Resizing portrait: " + width + " x " + height_n); - getHolder().setFixedSize(width, height_n); - } - } else { - if ( (screenMode == SDLScreenMode.Fullscreen || screenMode == SDLScreenMode.FitToScreen) - && !MainSettingsManager.getAlwaysShowMenuToolbar(MainSDLActivity.this) - && bar != null && bar.isShowing()) { - height += bar.getHeight(); - } + getHolder().setFixedSize(width, height_n); + } + } else { + if ( (screenMode == SDLScreenMode.Fullscreen || screenMode == SDLScreenMode.FitToScreen) + && !MainSettingsManager.getAlwaysShowMenuToolbar(MainSDLActivity.this) + && bar != null && bar.isShowing()) { + height += bar.getHeight(); + } Log.d(TAG, "Resizing landscape: " + width + " x " + height); - getHolder().setFixedSize(width, height); - } - initialized = true; + getHolder().setFixedSize(width, height); + } + initialized = true; new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { @Override @@ -1395,357 +1752,357 @@ public class MainSDLActivity extends SDLActivity { - } + } - // XXX: SDL is missing some key codes in sdl2-keymap.h - // So we create them with a Shift Modifier - private boolean handleMissingKeys(int keyCode, int action) { + // XXX: SDL is missing some key codes in sdl2-keymap.h + // So we create them with a Shift Modifier + private boolean handleMissingKeys(int keyCode, int action) { - int keyCodeTmp = keyCode; - switch (keyCode) { - case 77: - keyCodeTmp = 9; - break; - case 81: - keyCodeTmp = 70; - break; - case 17: - keyCodeTmp = 15; - break; - case 18: - keyCodeTmp = 10; - break; - default: - return false; + int keyCodeTmp = keyCode; + switch (keyCode) { + case 77: + keyCodeTmp = 9; + break; + case 81: + keyCodeTmp = 70; + break; + case 17: + keyCodeTmp = 15; + break; + case 18: + keyCodeTmp = 10; + break; + default: + return false; - } - if (action == KeyEvent.ACTION_DOWN) { - SDLActivity.onNativeKeyDown(59); - SDLActivity.onNativeKeyDown(keyCodeTmp); - } else { - SDLActivity.onNativeKeyUp(59); - SDLActivity.onNativeKeyUp(keyCodeTmp); - } - return true; + } + if (action == KeyEvent.ACTION_DOWN) { + SDLActivity.onNativeKeyDown(59); + SDLActivity.onNativeKeyDown(keyCodeTmp); + } else { + SDLActivity.onNativeKeyUp(59); + SDLActivity.onNativeKeyUp(keyCodeTmp); + } + return true; - } + } - @Override - public boolean onKey(View v, int keyCode, KeyEvent event) { + @Override + public boolean onKey(View v, int keyCode, KeyEvent event) { - if ((keyCode == KeyEvent.KEYCODE_BACK) || (keyCode == KeyEvent.KEYCODE_FORWARD)) { - // dismiss android back and forward keys - return true; - } else if (event.getKeyCode() == KeyEvent.KEYCODE_MENU) { - return false; - } else if (event.getAction() == KeyEvent.ACTION_DOWN) { - //Log.v("SDL", "key down: " + keyCode); - if (!handleMissingKeys(keyCode, event.getAction())) - SDLActivity.onNativeKeyDown(keyCode); - return true; - } else if (event.getAction() == KeyEvent.ACTION_UP) { - //Log.v("SDL", "key up: " + keyCode); - if (!handleMissingKeys(keyCode, event.getAction())) - SDLActivity.onNativeKeyUp(keyCode); - return true; - } else { - return super.onKey(v, keyCode, event); - } + if ((keyCode == KeyEvent.KEYCODE_BACK) || (keyCode == KeyEvent.KEYCODE_FORWARD)) { + // dismiss android back and forward keys + return true; + } else if (event.getKeyCode() == KeyEvent.KEYCODE_MENU) { + return false; + } else if (event.getAction() == KeyEvent.ACTION_DOWN) { + //Log.v("SDL", "key down: " + keyCode); + if (!handleMissingKeys(keyCode, event.getAction())) + SDLActivity.onNativeKeyDown(keyCode); + return true; + } else if (event.getAction() == KeyEvent.ACTION_UP) { + //Log.v("SDL", "key up: " + keyCode); + if (!handleMissingKeys(keyCode, event.getAction())) + SDLActivity.onNativeKeyUp(keyCode); + return true; + } else { + return super.onKey(v, keyCode, event); + } - } + } - // Touch events - public boolean onTouchProcess(View v, MotionEvent event) { - int action = event.getAction(); - float x = event.getX(0); - float y = event.getY(0); - float p = event.getPressure(0); + // Touch events + public boolean onTouchProcess(View v, MotionEvent event) { + int action = event.getAction(); + float x = event.getX(0); + float y = event.getY(0); + float p = event.getPressure(0); - int relative = Config.mouseMode == Config.MouseMode.External? 0: 1; + int relative = Config.mouseMode == Config.MouseMode.External? 0: 1; - int sdlMouseButton = 0; - if(event.getButtonState() == MotionEvent.BUTTON_PRIMARY) - sdlMouseButton = Config.SDL_MOUSE_LEFT; - else if(event.getButtonState() == MotionEvent.BUTTON_SECONDARY) - sdlMouseButton = Config.SDL_MOUSE_RIGHT; - else if(event.getButtonState() == MotionEvent.BUTTON_TERTIARY) - sdlMouseButton = Config.SDL_MOUSE_MIDDLE; + int sdlMouseButton = 0; + if(event.getButtonState() == MotionEvent.BUTTON_PRIMARY) + sdlMouseButton = Config.SDL_MOUSE_LEFT; + else if(event.getButtonState() == MotionEvent.BUTTON_SECONDARY) + sdlMouseButton = Config.SDL_MOUSE_RIGHT; + else if(event.getButtonState() == MotionEvent.BUTTON_TERTIARY) + sdlMouseButton = Config.SDL_MOUSE_MIDDLE; - if (event.getAction() == MotionEvent.ACTION_MOVE) { + if (event.getAction() == MotionEvent.ACTION_MOVE) { - if (mouseUp) { - old_x = x; - old_y = y; - mouseUp = false; - } - if (action == MotionEvent.ACTION_MOVE) { - if(Config.mouseMode == Config.MouseMode.External) { - //Log.d("SDL", "onTouch Absolute Move by=" + action + ", X,Y=" + (x) + "," + (y) + " P=" + p); - MainActivity.vmexecutor.onVectrasMouse(0, MotionEvent.ACTION_MOVE,0, x , y ); - }else { - //Log.d("SDL", "onTouch Relative Moving by=" + action + ", X,Y=" + (x - + if (mouseUp) { + old_x = x; + old_y = y; + mouseUp = false; + } + if (action == MotionEvent.ACTION_MOVE) { + if(Config.mouseMode == Config.MouseMode.External) { + //Log.d("SDL", "onTouch Absolute Move by=" + action + ", X,Y=" + (x) + "," + (y) + " P=" + p); + MainActivity.vmexecutor.onVectrasMouse(0, MotionEvent.ACTION_MOVE,0, x , y ); + }else { + //Log.d("SDL", "onTouch Relative Moving by=" + action + ", X,Y=" + (x - // old_x) + "," + (y - old_y) + " P=" + p); - MainActivity.vmexecutor.onVectrasMouse(0, MotionEvent.ACTION_MOVE,1, (x - old_x) * sensitivity_mult, (y - old_y) * sensitivity_mult); - } + MainActivity.vmexecutor.onVectrasMouse(0, MotionEvent.ACTION_MOVE,1, (x - old_x) * sensitivity_mult, (y - old_y) * sensitivity_mult); + } - } - // save current - old_x = x; - old_y = y; + } + // save current + old_x = x; + old_y = y; - } - else if (event.getAction() == event.ACTION_UP ) { - //Log.d("SDL", "onTouch Up: " + sdlMouseButton); - //XXX: it seems that the Button state is not available when Button up so - // we should release all mouse buttons to be safe since we don't know which one fired the event - if(sdlMouseButton == Config.SDL_MOUSE_MIDDLE - ||sdlMouseButton == Config.SDL_MOUSE_RIGHT - ) { - MainActivity.vmexecutor.onVectrasMouse(sdlMouseButton, MotionEvent.ACTION_UP, relative, x, y); - } else if (sdlMouseButton != 0) { - MainActivity.vmexecutor.onVectrasMouse(sdlMouseButton, MotionEvent.ACTION_UP, relative, x, y); - } else { // if we don't have inforamtion about which button we can make some guesses + } + else if (event.getAction() == event.ACTION_UP ) { + //Log.d("SDL", "onTouch Up: " + sdlMouseButton); + //XXX: it seems that the Button state is not available when Button up so + // we should release all mouse buttons to be safe since we don't know which one fired the event + if(sdlMouseButton == Config.SDL_MOUSE_MIDDLE + ||sdlMouseButton == Config.SDL_MOUSE_RIGHT + ) { + MainActivity.vmexecutor.onVectrasMouse(sdlMouseButton, MotionEvent.ACTION_UP, relative, x, y); + } else if (sdlMouseButton != 0) { + MainActivity.vmexecutor.onVectrasMouse(sdlMouseButton, MotionEvent.ACTION_UP, relative, x, y); + } else { // if we don't have inforamtion about which button we can make some guesses - //Or only the last one pressed - if (lastMouseButtonDown > 0) { - if(lastMouseButtonDown == Config.SDL_MOUSE_MIDDLE - ||lastMouseButtonDown == Config.SDL_MOUSE_RIGHT - ) { - MainActivity.vmexecutor.onVectrasMouse(lastMouseButtonDown, MotionEvent.ACTION_UP, relative,x, y); - }else - MainActivity.vmexecutor.onVectrasMouse(lastMouseButtonDown, MotionEvent.ACTION_UP, relative, x, y); - } else { - //ALl buttons - if (Config.mouseMode == Config.MouseMode.Trackpad) { - MainActivity.vmexecutor.onVectrasMouse(Config.SDL_MOUSE_LEFT, MotionEvent.ACTION_UP, 1, 0, 0); - } else if (Config.mouseMode == Config.MouseMode.External) { - MainActivity.vmexecutor.onVectrasMouse(Config.SDL_MOUSE_LEFT, MotionEvent.ACTION_UP, 0, x, y); - MainActivity.vmexecutor.onVectrasMouse(Config.SDL_MOUSE_RIGHT, MotionEvent.ACTION_UP, 0, x, y); - MainActivity.vmexecutor.onVectrasMouse(Config.SDL_MOUSE_MIDDLE, MotionEvent.ACTION_UP, 0, x, y); - } - } - } - lastMouseButtonDown = -1; - mouseUp = true; - } - else if (event.getAction() == event.ACTION_DOWN - && Config.mouseMode == Config.MouseMode.External - ) { + //Or only the last one pressed + if (lastMouseButtonDown > 0) { + if(lastMouseButtonDown == Config.SDL_MOUSE_MIDDLE + ||lastMouseButtonDown == Config.SDL_MOUSE_RIGHT + ) { + MainActivity.vmexecutor.onVectrasMouse(lastMouseButtonDown, MotionEvent.ACTION_UP, relative,x, y); + }else + MainActivity.vmexecutor.onVectrasMouse(lastMouseButtonDown, MotionEvent.ACTION_UP, relative, x, y); + } else { + //ALl buttons + if (Config.mouseMode == Config.MouseMode.Trackpad) { + MainActivity.vmexecutor.onVectrasMouse(Config.SDL_MOUSE_LEFT, MotionEvent.ACTION_UP, 1, 0, 0); + } else if (Config.mouseMode == Config.MouseMode.External) { + MainActivity.vmexecutor.onVectrasMouse(Config.SDL_MOUSE_LEFT, MotionEvent.ACTION_UP, 0, x, y); + MainActivity.vmexecutor.onVectrasMouse(Config.SDL_MOUSE_RIGHT, MotionEvent.ACTION_UP, 0, x, y); + MainActivity.vmexecutor.onVectrasMouse(Config.SDL_MOUSE_MIDDLE, MotionEvent.ACTION_UP, 0, x, y); + } + } + } + lastMouseButtonDown = -1; + mouseUp = true; + } + else if (event.getAction() == event.ACTION_DOWN + && Config.mouseMode == Config.MouseMode.External + ) { - //XXX: Some touch events for touchscreen mode are primary so we force left mouse button - if(sdlMouseButton == 0 && MotionEvent.TOOL_TYPE_FINGER == event.getToolType(0)) { - sdlMouseButton = Config.SDL_MOUSE_LEFT; - } + //XXX: Some touch events for touchscreen mode are primary so we force left mouse button + if(sdlMouseButton == 0 && MotionEvent.TOOL_TYPE_FINGER == event.getToolType(0)) { + sdlMouseButton = Config.SDL_MOUSE_LEFT; + } - MainActivity.vmexecutor.onVectrasMouse(sdlMouseButton, MotionEvent.ACTION_DOWN, relative, x, y); - lastMouseButtonDown = sdlMouseButton; - } - return true; - } + MainActivity.vmexecutor.onVectrasMouse(sdlMouseButton, MotionEvent.ACTION_DOWN, relative, x, y); + lastMouseButtonDown = sdlMouseButton; + } + return true; + } - public boolean onTouch(View v, MotionEvent event) { - boolean res = false; - if(Config.mouseMode == Config.MouseMode.External){ - res = onTouchProcess(v,event); - res = onTouchEventProcess(event); - } - return res; - } + public boolean onTouch(View v, MotionEvent event) { + boolean res = false; + if(Config.mouseMode == Config.MouseMode.External){ + res = onTouchProcess(v,event); + res = onTouchEventProcess(event); + } + return res; + } - public boolean onTouchEvent(MotionEvent event) { - return false; - } + public boolean onTouchEvent(MotionEvent event) { + return false; + } - public boolean onTouchEventProcess(MotionEvent event) { - // Log.v("onTouchEvent", - // "Action=" + event.getAction() + ", X,Y=" + event.getX() + "," - // + event.getY() + " P=" + event.getPressure()); - // MK - if (event.getAction() == MotionEvent.ACTION_CANCEL) - return true; + public boolean onTouchEventProcess(MotionEvent event) { + // Log.v("onTouchEvent", + // "Action=" + event.getAction() + ", X,Y=" + event.getX() + "," + // + event.getY() + " P=" + event.getPressure()); + // MK + if (event.getAction() == MotionEvent.ACTION_CANCEL) + return true; - if (!firstTouch) { - firstTouch = true; - } - if (event.getPointerCount() > 1) { + if (!firstTouch) { + firstTouch = true; + } + if (event.getPointerCount() > 1) { - // XXX: Vectras Legacy enable Right Click with 2 finger touch - // Log.v("Right Click", - // "Action=" + event.getAction() + ", X,Y=" + event.getX() - // + "," + event.getY() + " P=" + event.getPressure()); - // rightClick(event); - return true; - } else - return gestureDetector.onTouchEvent(event); - } - } -*/ - public AudioManager am; - protected int maxVolume; + // XXX: Limbo Legacy enable Right Click with 2 finger touch + // Log.v("Right Click", + // "Action=" + event.getAction() + ", X,Y=" + event.getX() + // + "," + event.getY() + " P=" + event.getPressure()); + // rightClick(event); + return true; + } else + return gestureDetector.onTouchEvent(event); + } + } - protected void setupVolume() { - if (am == null) { - am = (AudioManager) mSingleton.getSystemService(Context.AUDIO_SERVICE); - maxVolume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC); - } - } + public AudioManager am; + protected int maxVolume; - public void setVolume(int volume) { - if(am!=null) - am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0); - } + protected void setupVolume() { + if (am == null) { + am = (AudioManager) mSingleton.getSystemService(Context.AUDIO_SERVICE); + maxVolume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC); + } + } - protected int getCurrentVolume() { - int volumeTmp = 0; - if(am!=null) - volumeTmp = am.getStreamVolume(AudioManager.STREAM_MUSIC); - return volumeTmp; - } + public void setVolume(int volume) { + if(am!=null) + am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0); + } + + protected int getCurrentVolume() { + int volumeTmp = 0; + if(am!=null) + volumeTmp = am.getStreamVolume(AudioManager.STREAM_MUSIC); + return volumeTmp; + } - //XXX: We want to suspend only when app is calling onPause() - @Override - public void onWindowFocusChanged(boolean hasFocus) { + //XXX: We want to suspend only when app is calling onPause() + @Override + public void onWindowFocusChanged(boolean hasFocus) { - } + } - public boolean rightClick(final MotionEvent e, final int i) { - Thread t = new Thread(new Runnable() { - public void run() { - Log.d("SDL", "Mouse Right Click"); - MainActivity.vmexecutor.onVectrasMouse(Config.SDL_MOUSE_RIGHT, MotionEvent.ACTION_DOWN, 1, -1, -1); - try { - Thread.sleep(100); - } catch (InterruptedException ex) { + public boolean rightClick(final MotionEvent e, final int i) { + Thread t = new Thread(new Runnable() { + public void run() { + Log.d("SDL", "Mouse Right Click"); + MainActivity.vmexecutor.onVectrasMouse(Config.SDL_MOUSE_RIGHT, MotionEvent.ACTION_DOWN, 1, -1, -1); + try { + Thread.sleep(100); + } catch (InterruptedException ex) { // Log.v("SDLSurface", "Interrupted: " + ex); - } - MainActivity.vmexecutor.onVectrasMouse(Config.SDL_MOUSE_RIGHT, MotionEvent.ACTION_UP, 1, -1, -1); - } - }); - t.start(); - return true; + } + MainActivity.vmexecutor.onVectrasMouse(Config.SDL_MOUSE_RIGHT, MotionEvent.ACTION_UP, 1, -1, -1); + } + }); + t.start(); + return true; - } + } - public boolean middleClick(final MotionEvent e, final int i) { - Thread t = new Thread(new Runnable() { - public void run() { + public boolean middleClick(final MotionEvent e, final int i) { + Thread t = new Thread(new Runnable() { + public void run() { Log.d("SDL", "Mouse Middle Click"); - MainActivity.vmexecutor.onVectrasMouse(Config.SDL_MOUSE_MIDDLE, MotionEvent.ACTION_DOWN, 1,-1, -1); - try { - Thread.sleep(100); - } catch (InterruptedException ex) { + MainActivity.vmexecutor.onVectrasMouse(Config.SDL_MOUSE_MIDDLE, MotionEvent.ACTION_DOWN, 1,-1, -1); + try { + Thread.sleep(100); + } catch (InterruptedException ex) { // Log.v("SDLSurface", "Interrupted: " + ex); - } - MainActivity.vmexecutor.onVectrasMouse(Config.SDL_MOUSE_MIDDLE, MotionEvent.ACTION_UP, 1,-1, -1); - } - }); - t.start(); - return true; + } + MainActivity.vmexecutor.onVectrasMouse(Config.SDL_MOUSE_MIDDLE, MotionEvent.ACTION_UP, 1,-1, -1); + } + }); + t.start(); + return true; - } + } - private void doubleClick(final MotionEvent event, final int pointer_id) { + private void doubleClick(final MotionEvent event, final int pointer_id) { - Thread t = new Thread(new Runnable() { - public void run() { - //Log.d("SDL", "Mouse Double Click"); - for (int i = 0; i < 2; i++) { - MainActivity.vmexecutor.onVectrasMouse(Config.SDL_MOUSE_LEFT, MotionEvent.ACTION_DOWN, 1, 0, 0); - try { - Thread.sleep(50); - } catch (InterruptedException ex) { - // Log.v("doubletap", "Could not sleep"); - } - MainActivity.vmexecutor.onVectrasMouse(Config.SDL_MOUSE_LEFT, MotionEvent.ACTION_UP, 1,0, 0); - try { - Thread.sleep(50); - } catch (InterruptedException ex) { - // Log.v("doubletap", "Could not sleep"); - } - } - } - }); - t.start(); - } + Thread t = new Thread(new Runnable() { + public void run() { + //Log.d("SDL", "Mouse Double Click"); + for (int i = 0; i < 2; i++) { + MainActivity.vmexecutor.onVectrasMouse(Config.SDL_MOUSE_LEFT, MotionEvent.ACTION_DOWN, 1, 0, 0); + try { + Thread.sleep(50); + } catch (InterruptedException ex) { + // Log.v("doubletap", "Could not sleep"); + } + MainActivity.vmexecutor.onVectrasMouse(Config.SDL_MOUSE_LEFT, MotionEvent.ACTION_UP, 1,0, 0); + try { + Thread.sleep(50); + } catch (InterruptedException ex) { + // Log.v("doubletap", "Could not sleep"); + } + } + } + }); + t.start(); + } - int lastMouseButtonDown = -1; - public float old_x = 0; - public float old_y = 0; - private boolean mouseUp = true; - private float sensitivity_mult = (float) 1.0; - private boolean firstTouch = false; + int lastMouseButtonDown = -1; + public float old_x = 0; + public float old_y = 0; + private boolean mouseUp = true; + private float sensitivity_mult = (float) 1.0; + private boolean firstTouch = false; - private class GestureListener extends GestureDetector.SimpleOnGestureListener { + private class GestureListener extends GestureDetector.SimpleOnGestureListener { - @Override - public boolean onDown(MotionEvent event) { - // Log.v("onDown", "Action=" + event.getAction() + ", X,Y=" + event.getX() - // + "," + event.getY() + " P=" + event.getPressure()); - return true; - } + @Override + public boolean onDown(MotionEvent event) { + // Log.v("onDown", "Action=" + event.getAction() + ", X,Y=" + event.getX() + // + "," + event.getY() + " P=" + event.getPressure()); + return true; + } - @Override - public void onLongPress(MotionEvent event) { - // Log.d("SDL", "Long Press Action=" + event.getAction() + ", X,Y=" - // + event.getX() + "," + event.getY() + " P=" - // + event.getPressure()); - if(Config.mouseMode == Config.MouseMode.External) - return; + @Override + public void onLongPress(MotionEvent event) { + // Log.d("SDL", "Long Press Action=" + event.getAction() + ", X,Y=" + // + event.getX() + "," + event.getY() + " P=" + // + event.getPressure()); + if(Config.mouseMode == Config.MouseMode.External) + return; - if(Config.enableDragOnLongPress) - dragPointer(event); - } + if(Config.enableDragOnLongPress) + dragPointer(event); + } - public boolean onSingleTapConfirmed(MotionEvent event) { - float x1 = event.getX(); - float y1 = event.getY(); + public boolean onSingleTapConfirmed(MotionEvent event) { + float x1 = event.getX(); + float y1 = event.getY(); - if(Config.mouseMode == Config.MouseMode.External) - return true; + if(Config.mouseMode == Config.MouseMode.External) + return true; // Log.d("onSingleTapConfirmed", "Tapped at: (" + x1 + "," + y1 + // ")"); - for (int i = 0; i < event.getPointerCount(); i++) { - int action = event.getAction(); - float x = event.getX(i); - float y = event.getY(i); - float p = event.getPressure(i); + for (int i = 0; i < event.getPointerCount(); i++) { + int action = event.getAction(); + float x = event.getX(i); + float y = event.getY(i); + float p = event.getPressure(i); - //Log.v("onSingleTapConfirmed", "Action=" + action + ", X,Y=" + x + "," + y + " P=" + p); - if (event.getAction() == event.ACTION_DOWN - && MotionEvent.TOOL_TYPE_FINGER == event.getToolType(0)) { - //Log.d("SDL", "onTouch Down: " + event.getButtonState()); - MainSDLActivity.singleClick(event, i); - } - } - return true; + //Log.v("onSingleTapConfirmed", "Action=" + action + ", X,Y=" + x + "," + y + " P=" + p); + if (event.getAction() == event.ACTION_DOWN + && MotionEvent.TOOL_TYPE_FINGER == event.getToolType(0)) { + //Log.d("SDL", "onTouch Down: " + event.getButtonState()); + MainSDLActivity.singleClick(event, i); + } + } + return true; - } + } - // event when double tap occurs - @Override - public boolean onDoubleTap(MotionEvent event) { + // event when double tap occurs + @Override + public boolean onDoubleTap(MotionEvent event) { // Log.d("onDoubleTap", "Tapped at: (" + event.getX() + "," + event.getY() + ")"); - if(Config.mouseMode == Config.MouseMode.External - //&& MotionEvent.TOOL_TYPE_MOUSE == event.getToolType(0) - ) - return true; + if(Config.mouseMode == Config.MouseMode.External + //&& MotionEvent.TOOL_TYPE_MOUSE == event.getToolType(0) + ) + return true; - if(!Config.enableDragOnLongPress) - processDoubleTap(event); + if(!Config.enableDragOnLongPress) + processDoubleTap(event); else doubleClick(event, 0); - return true; - } - } + return true; + } + } private void dragPointer(MotionEvent event) { @@ -1754,7 +2111,7 @@ public class MainSDLActivity extends SDLActivity { if (v.hasVibrator()) { v.vibrate(100); } - } + } private void processDoubleTap(final MotionEvent event) { @@ -1769,89 +2126,89 @@ public class MainSDLActivity extends SDLActivity { if (!mouseUp) { dragPointer(event); } else { - // Log.v("onDoubleTap", "Action=" + action + ", X,Y=" + x + "," + y + " P=" + p); - doubleClick(event, 0); + // Log.v("onDoubleTap", "Action=" + action + ", X,Y=" + x + "," + y + " P=" + p); + doubleClick(event, 0); } } }); t.start(); - } + } class SDLGenericMotionListener_API12 implements View.OnGenericMotionListener { - private ExSDLSurface mSurface; + private MainSDLSurface mSurface; - @Override - public boolean onGenericMotion(View v, MotionEvent event) { - float x, y; - int action; + @Override + public boolean onGenericMotion(View v, MotionEvent event) { + float x, y; + int action; - switch (event.getSource()) { - case InputDevice.SOURCE_JOYSTICK: - case InputDevice.SOURCE_GAMEPAD: - case InputDevice.SOURCE_DPAD: - SDLControllerManager.handleJoystickMotionEvent(event); - return true; + switch (event.getSource()) { + case InputDevice.SOURCE_JOYSTICK: + case InputDevice.SOURCE_GAMEPAD: + case InputDevice.SOURCE_DPAD: + SDLControllerManager.handleJoystickMotionEvent(event); + return true; - case InputDevice.SOURCE_MOUSE: - if(Config.mouseMode == Config.MouseMode.Trackpad) - break; + case InputDevice.SOURCE_MOUSE: + if(Config.mouseMode == Config.MouseMode.Trackpad) + break; - action = event.getActionMasked(); + action = event.getActionMasked(); // Log.d("SDL", "onGenericMotion, action = " + action + "," + event.getX() + ", " + event.getY()); - switch (action) { - case MotionEvent.ACTION_SCROLL: - x = event.getAxisValue(MotionEvent.AXIS_HSCROLL, 0); - y = event.getAxisValue(MotionEvent.AXIS_VSCROLL, 0); + switch (action) { + case MotionEvent.ACTION_SCROLL: + x = event.getAxisValue(MotionEvent.AXIS_HSCROLL, 0); + y = event.getAxisValue(MotionEvent.AXIS_VSCROLL, 0); // Log.d("SDL", "Mouse Scroll: " + x + "," + y); - MainActivity.vmexecutor.onVectrasMouse(0, action, 0, x, y); - return true; + MainActivity.vmexecutor.onVectrasMouse(0, action, 0, x, y); + return true; - case MotionEvent.ACTION_HOVER_MOVE: - if(Config.processMouseHistoricalEvents) { - final int historySize = event.getHistorySize(); - for (int h = 0; h < historySize; h++) { - float ex = event.getHistoricalX(h); - float ey = event.getHistoricalY(h); - float ep = event.getHistoricalPressure(h); - processHoverMouse(ex, ey, ep, action); - } - } + case MotionEvent.ACTION_HOVER_MOVE: + if(Config.processMouseHistoricalEvents) { + final int historySize = event.getHistorySize(); + for (int h = 0; h < historySize; h++) { + float ex = event.getHistoricalX(h); + float ey = event.getHistoricalY(h); + float ep = event.getHistoricalPressure(h); + processHoverMouse(ex, ey, ep, action); + } + } - float ex = event.getX(); - float ey = event.getY(); - float ep = event.getPressure(); - processHoverMouse(ex, ey, ep, action); - return true; + float ex = event.getX(); + float ey = event.getY(); + float ep = event.getPressure(); + processHoverMouse(ex, ey, ep, action); + return true; - case MotionEvent.ACTION_UP: + case MotionEvent.ACTION_UP: - default: - break; - } - break; + default: + break; + } + break; - default: - break; - } + default: + break; + } - // Event was not managed - return false; - } + // Event was not managed + return false; + } - private void processHoverMouse(float x,float y,float p, int action) { + private void processHoverMouse(float x,float y,float p, int action) { - if(Config.mouseMode == Config.MouseMode.External) { - //Log.d("SDL", "Mouse Hover: " + x + "," + y); - MainActivity.vmexecutor.onVectrasMouse(0, action, 0, x, y); - } - } + if(Config.mouseMode == Config.MouseMode.External) { + //Log.d("SDL", "Mouse Hover: " + x + "," + y); + MainActivity.vmexecutor.onVectrasMouse(0, action, 0, x, y); + } + } - } + } - GestureDetector gestureDetector; + GestureDetector gestureDetector; } diff --git a/app/src/main/java/com/vectras/qemu/MainSettingsManager.java b/app/src/main/java/com/vectras/qemu/MainSettingsManager.java index e97ed18..cf246cc 100644 --- a/app/src/main/java/com/vectras/qemu/MainSettingsManager.java +++ b/app/src/main/java/com/vectras/qemu/MainSettingsManager.java @@ -248,7 +248,7 @@ public class MainSettingsManager extends AppCompatActivity implements Preference.OnPreferenceChangeListener { @Override public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); + super.onCreate(savedInstanceState);/* Preference pref = findPreference("customMemory"); if (pref != null) { pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @@ -278,7 +278,7 @@ public class MainSettingsManager extends AppCompatActivity } }); - } + }*/ } private void onMemory() { @@ -629,6 +629,61 @@ public class MainSettingsManager extends AppCompatActivity SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity); return prefs.getBoolean("virtio", false); } + + public static void setAvx(Activity activity, boolean AVX) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity); + SharedPreferences.Editor edit = prefs.edit(); + edit.putBoolean("AVX", AVX); + edit.apply(); + } + + public static boolean getAvx(Activity activity) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity); + return prefs.getBoolean("AVX", false); + } + + public static void setTbSize(Activity activity, String TbSize) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity); + SharedPreferences.Editor edit = prefs.edit(); + edit.putString("TbSize", TbSize); + edit.apply(); + } + + public static String getTbSize(Activity activity) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity); + return prefs.getString("TbSize", "2048"); + } + + public static void setVmUi(Activity activity, String vmUi) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity); + SharedPreferences.Editor edit = prefs.edit(); + edit.putString("vmUi", vmUi); + edit.apply(); + } + public static String getVmUi(Activity activity) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity); + return prefs.getString("vmUi", "VNC"); + } + public static void setUsbTablet(Activity activity, boolean UsbTablet) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity); + SharedPreferences.Editor edit = prefs.edit(); + edit.putBoolean("UsbTablet", UsbTablet); + edit.apply(); + } + public static boolean getUsbTablet(Activity activity) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity); + return prefs.getBoolean("UsbTablet", false); + } + public static void setCustomParams(Activity activity, String customParams) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity); + SharedPreferences.Editor edit = prefs.edit(); + edit.putString("customParams", customParams); + edit.apply(); + } + public static String getCustomParams(Activity activity) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity); + return prefs.getString("customParams", ""); + } public static boolean isFirstLaunch(Activity activity) { PackageInfo pInfo = null; diff --git a/app/src/main/java/com/vectras/qemu/MainVNCActivity.java b/app/src/main/java/com/vectras/qemu/MainVNCActivity.java index c2a9a9e..c6995e0 100644 --- a/app/src/main/java/com/vectras/qemu/MainVNCActivity.java +++ b/app/src/main/java/com/vectras/qemu/MainVNCActivity.java @@ -6,12 +6,14 @@ import android.androidVNC.VncCanvasActivity; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; +import androidx.core.view.GravityCompat; import androidx.core.view.MenuItemCompat; +import androidx.drawerlayout.widget.DrawerLayout; import androidx.fragment.app.FragmentTransaction; import android.annotation.SuppressLint; import android.app.Activity; -import android.app.AlertDialog; +import androidx.appcompat.app.AlertDialog; import android.app.Dialog; import android.app.ProgressDialog; import android.content.DialogInterface; @@ -51,6 +53,7 @@ import android.widget.SeekBar; import android.widget.SeekBar.OnSeekBarChangeListener; import android.widget.TextView; +import com.vectras.qemu.utils.FileUtils; import com.vectras.vm.Fragment.ControlersOptionsFragment; import com.vectras.vm.MainActivity; import com.vectras.vm.R; @@ -124,8 +127,15 @@ public class MainVNCActivity extends VncCanvasActivity { ImageButton ctrlBtn = findViewById(R.id.ctrlBtn); ImageButton altBtn = findViewById(R.id.altBtn); ImageButton delBtn = findViewById(R.id.delBtn); + ImageButton btnLogs = findViewById(R.id.btnLogs); Button ctrlAltDelBtn = findViewById(R.id.ctrlAltDelBtn); qmpBtn = findViewById(R.id.btnQmp); + btnLogs.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + FileUtils.viewVectrasLog(activity); + } + }); shutdownBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -1184,20 +1194,11 @@ public class MainVNCActivity extends VncCanvasActivity { } + public void onBackPressed() { - - // super.onBackPressed(); - if (!MainSettingsManager.getAlwaysShowMenuToolbar(activity)) { - ActionBar bar = this.getSupportActionBar(); - if (bar != null) { - if (bar.isShowing() && Config.mouseMode == Config.MouseMode.Trackpad) { - bar.hide(); - }/* else - bar.show();*/ - } - } else - super.onBackPressed(); - + super.onBackPressed(); + Machine.stopVM(activity); + return; } public void onHideToolbar() { diff --git a/app/src/main/java/com/vectras/qemu/jni/StartVM.java b/app/src/main/java/com/vectras/qemu/jni/StartVM.java index f819182..af035ea 100644 --- a/app/src/main/java/com/vectras/qemu/jni/StartVM.java +++ b/app/src/main/java/com/vectras/qemu/jni/StartVM.java @@ -64,22 +64,22 @@ public class StartVM { public String vnc_passwd = "vectras"; // cpu/board settings - private String cpu; + public String cpu; private String arch = "x86"; private String machine_type; - private int memory = 128; + public int memory = 128; private int cpuNum = 1; public int enablekvm; public int enable_mttcg; // disks public String hda_img_path; - private String hdb_img_path; - private String hdc_img_path; - private String hdd_img_path; + public String hdb_img_path; + public String hdc_img_path; + public String hdd_img_path; public String shared_folder_path; public int shared_folder_readonly = 1; - private String hd_cache = "default"; + public String hd_cache = "default"; //removable devices public String cd_iso_path; @@ -88,26 +88,30 @@ public class StartVM { public String sd_img_path; //boot options - private String bootdevice = null; + public String bootdevice = null; private String kernel; private String initrd; //graphics - private String vga_type = "std"; + public String vga_type = "std"; //audio public String sound_card; // net - private String net_cfg = "None"; - private String nic_card = null; + public String net_cfg = "None"; + public String nic_card = null; private String hostfwd = null; private String guestfwd = null; //advanced - private int disableacpi = 0; - private int disablehpet = 0; - private int disabletsc = 0; + public int disableacpi = 0; + public int disablehpet = 0; + public int disabletsc = 0; + + public boolean enablleAvx = false; + public String tbSize = "2048"; + public String extra_params; /** @@ -120,7 +124,11 @@ public class StartVM { save_dir = Config.getMachineDir() + name; save_state_name = save_dir + "/" + Config.state_filename; hda_img_path = Config.hda_path; + extra_params = Config.extra_params; + extra_params += " "; + extra_params += MainSettingsManager.getCustomParams(MainActivity.activity); + shared_folder_path = Config.sharedFolder; //extra_params = Config.extra_params; this.context = context; @@ -133,6 +141,14 @@ public class StartVM { this.enable_mttcg = 0; this.vnc_allow_external = 0; + this.enablleAvx = MainSettingsManager.getAvx(MainActivity.activity); + + this.tbSize = MainSettingsManager.getTbSize(MainActivity.activity); + + if (MainSettingsManager.getUsbTablet(MainActivity.activity)) + this.mouse = "usb-tablet"; + else + this.mouse = "ps2"; } public static void onVMResolutionChanged(int width, int height) { @@ -283,7 +299,8 @@ public class StartVM { } if (mouse != null && !mouse.equals("ps2")) { - paramsList.add("-usb"); + paramsList.add("-machine"); + paramsList.add("usb=on"); paramsList.add("-device"); paramsList.add(mouse); } @@ -309,7 +326,7 @@ public class StartVM { private void addAudioOptions(ArrayList paramsList) { - if (sound_card != null && !sound_card.equals("None")) { + if (sound_card != null && !sound_card.equals("None") && enablevnc != 1) { paramsList.add("-soundhw"); paramsList.add(sound_card); } @@ -384,7 +401,7 @@ public class StartVM { if (this.cpuNum > 1 && (enablekvm == 1 || enable_mttcg == 1 || !Config.enableSMPOnlyOnKVM)) { paramsList.add("-smp"); - paramsList.add("sockets="+"1"+",cores="+this.cpuNum+",threads="+this.cpuNum+""); + paramsList.add("sockets=" + "1" + ",cores=" + this.cpuNum + ",threads=" + this.cpuNum + ""); } if (machine_type != null && !machine_type.equals("Default")) { @@ -411,7 +428,11 @@ public class StartVM { if (this.cpu != null && !cpu.equals("Default")) { paramsList.add("-cpu"); - paramsList.add(cpu + ",+avx"); + String cpuParams = null; + cpuParams += cpu; + if (enablleAvx) + cpuParams += ",+avx"; + paramsList.add(cpuParams); } @@ -429,7 +450,7 @@ public class StartVM { tcgParams += ",thread=multi"; else tcgParams += ",thread=single"; - tcgParams += ",tb-size=2048"; + tcgParams += ",tb-size=" + tbSize; paramsList.add(tcgParams); //#endif } diff --git a/app/src/main/java/com/vectras/qemu/utils/Machine.java b/app/src/main/java/com/vectras/qemu/utils/Machine.java index 85716c2..e783172 100644 --- a/app/src/main/java/com/vectras/qemu/utils/Machine.java +++ b/app/src/main/java/com/vectras/qemu/utils/Machine.java @@ -1,13 +1,15 @@ package com.vectras.qemu.utils; import android.app.Activity; -import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.os.Build; import android.os.Handler; import android.os.Looper; import android.util.Log; + +import androidx.appcompat.app.AlertDialog; + import com.vectras.qemu.Config; import com.vectras.vm.MainActivity; import com.vectras.vm.R; diff --git a/app/src/main/java/com/vectras/vm/Fragment/LoggerFragment.java b/app/src/main/java/com/vectras/vm/Fragment/LoggerFragment.java index 0c16f6d..f124ccd 100644 --- a/app/src/main/java/com/vectras/vm/Fragment/LoggerFragment.java +++ b/app/src/main/java/com/vectras/vm/Fragment/LoggerFragment.java @@ -1,5 +1,6 @@ package com.vectras.vm.Fragment; +import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -21,6 +22,7 @@ import android.widget.Switch; import android.widget.TextView; import android.widget.Toast; +import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -28,6 +30,7 @@ import androidx.recyclerview.widget.RecyclerView; import com.vectras.vm.R; import com.vectras.vm.RomsManagerActivity; import com.vectras.vm.MainActivity; +import com.vectras.vm.VectrasApp; import com.vectras.vm.adapter.LogsAdapter; import com.vectras.vm.logger.VectrasStatus; import com.vectras.vm.utils.UIUtils; @@ -46,20 +49,21 @@ import java.util.TimerTask; public class LoggerFragment extends Fragment { View view; - MainActivity activity = MainActivity.activity; private final String CREDENTIAL_SHARED_PREF = "settings_prefs"; private LogsAdapter mLogAdapter; private RecyclerView logList; private Timer _timer = new Timer(); private TimerTask t; + Activity activity; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub view = inflater.inflate(R.layout.fragment_logs, container, false); - LinearLayoutManager layoutManager = new LinearLayoutManager(MainActivity.activity); - mLogAdapter = new LogsAdapter(layoutManager, MainActivity.activity); + activity = getActivity(); + LinearLayoutManager layoutManager = new LinearLayoutManager(VectrasApp.getApp()); + mLogAdapter = new LogsAdapter(layoutManager, VectrasApp.getApp()); logList = (RecyclerView) view.findViewById(R.id.recyclerLog); logList.setAdapter(mLogAdapter); logList.setLayoutManager(layoutManager); diff --git a/app/src/main/java/com/vectras/vm/MainActivity.java b/app/src/main/java/com/vectras/vm/MainActivity.java index fb9d999..c9d973c 100644 --- a/app/src/main/java/com/vectras/vm/MainActivity.java +++ b/app/src/main/java/com/vectras/vm/MainActivity.java @@ -6,6 +6,7 @@ import android.androidVNC.RfbProto; import android.androidVNC.VncCanvas; import android.animation.ObjectAnimator; import android.animation.ValueAnimator; +import android.annotation.SuppressLint; import android.app.Activity; import android.app.ActivityManager; import android.app.Dialog; @@ -49,6 +50,7 @@ import androidx.drawerlayout.widget.DrawerLayout; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentPagerAdapter; +import androidx.recyclerview.widget.GridLayoutManager; import androidx.vectordrawable.graphics.drawable.ArgbEvaluator; import androidx.viewpager.widget.ViewPager; @@ -71,6 +73,7 @@ import com.vectras.qemu.utils.Machine; import com.vectras.qemu.utils.QmpClient; import com.vectras.vm.Fragment.HomeFragment; import com.vectras.vm.Fragment.LoggerFragment; +import com.vectras.vm.MainRoms.AdapterMainRoms; import com.vectras.vm.logger.VectrasStatus; import com.vectras.vm.utils.AppUpdater; import com.vectras.qemu.utils.FileInstaller; @@ -146,7 +149,6 @@ public class MainActivity extends AppCompatActivity { setupStrictMode(); execTimer(); checkAndLoadLibs(); - Config.logFilePath = Config.cacheDir + "/vectras/vectras-log.txt"; activity = this; this.setContentView(R.layout.main); this.setupWidgets(); @@ -446,7 +448,7 @@ public class MainActivity extends AppCompatActivity { } }); if (MainSettingsManager.getPromptUpdateVersion(activity)) - updateApp(true); + updateApp(false); /*FirebaseUser user = mAuth.getCurrentUser(); TextView usernameTxt = findViewById(R.id.usernameTxt); TextView emailTxt = findViewById(R.id.emailTxt); @@ -476,6 +478,12 @@ public class MainActivity extends AppCompatActivity { AlertDialog alertDialog; alertDialog = new AlertDialog.Builder(activity, R.style.MainDialogTheme).create(); alertDialog.setTitle("JOIN US ON TELEGRAM"); + TextView title = alertDialog.findViewById(R.id.title_text); + ObjectAnimator rgbAnim=ObjectAnimator.ofObject(title,"textColor",new ArgbEvaluator(), Color.RED,Color.GREEN,Color.BLUE); + rgbAnim.setDuration(1000); + rgbAnim.setRepeatMode(ValueAnimator.REVERSE); + rgbAnim.setRepeatCount(ValueAnimator.INFINITE); + rgbAnim.start(); alertDialog.setMessage("Join us on Telegram where we publish all the news and updates and receive your opinions and bugs"); alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "JOIN", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { @@ -533,6 +541,7 @@ public class MainActivity extends AppCompatActivity { } + @SuppressLint("NotifyDataSetChanged") @Override public void onStart() { super.onStart(); @@ -541,6 +550,8 @@ public class MainActivity extends AppCompatActivity { } else { Config.hd_if_type = "ide"; } + setupFolders(); + Config.ui = MainSettingsManager.getVmUi(activity); InterstitialAd.load(this, "ca-app-pub-3568137780412047/7745973511", adRequest, new InterstitialAdLoadCallback() { @Override @@ -756,21 +767,18 @@ public class MainActivity extends AppCompatActivity { } public static void setupFolders() { - Thread t = new Thread(new Runnable() { - public void run() { + try { + Config.cacheDir = activity.getCacheDir().getAbsolutePath(); + Config.storagedir = Environment.getDataDirectory().toString(); - Config.cacheDir = activity.getCacheDir().getAbsolutePath(); - Config.storagedir = Environment.getExternalStorageDirectory().toString(); + // Create Temp folder + File folder = new File(Config.getTmpFolder()); + if (!folder.exists()) + folder. mkdirs(); - // Create Temp folder - File folder = new File(Config.getTmpFolder()); - if (!folder.exists()) - folder.mkdirs(); + } catch (Exception ignored) { - - } - }); - t.start(); + } } //XXX: sometimes this needs to be called from the main thread otherwise diff --git a/app/src/main/java/com/vectras/vm/utils/UIUtils.java b/app/src/main/java/com/vectras/vm/utils/UIUtils.java index 16d7beb..ad6201a 100644 --- a/app/src/main/java/com/vectras/vm/utils/UIUtils.java +++ b/app/src/main/java/com/vectras/vm/utils/UIUtils.java @@ -1,7 +1,7 @@ package com.vectras.vm.utils; import android.app.Activity; -import android.app.AlertDialog; +import androidx.appcompat.app.AlertDialog; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; diff --git a/app/src/main/java/org/libsdl/app/SDLActivity.java b/app/src/main/java/org/libsdl/app/SDLActivity.java index c12258d..6c2c812 100644 --- a/app/src/main/java/org/libsdl/app/SDLActivity.java +++ b/app/src/main/java/org/libsdl/app/SDLActivity.java @@ -207,11 +207,11 @@ public class SDLActivity extends AppCompatActivity { mClipboardHandler = new SDLClipboardHandler_Old(); } - //Vectras: override + //Limbo: override // Set up the surface //mSurface = new SDLSurface(getApplication()); - //Vectras: override + //Limbo: override //mLayout = new RelativeLayout(this); //mLayout.addView(mSurface); @@ -1079,7 +1079,7 @@ public class SDLActivity extends AppCompatActivity { mClipboardHandler.clipboardSetText(string); } - //Vectras: + //Limbo: protected void runSDLMain(){ } @@ -1105,7 +1105,7 @@ class SDLMain implements Runnable { Log.v("SDL", "Running main function " + function + " from library " + library); - //Vectras: we override + //Limbo: we override //SDLActivity.nativeRunMain(library, function, arguments); SDLActivity.mSingleton.runSDLMain(); @@ -1122,375 +1122,6 @@ class SDLMain implements Runnable { } - -/** - SDLSurface. This is what we draw on, so we need to know when it's created - in order to do anything useful. - - Because of this, that's where we set up the SDL thread -*/ -//Vectras: should be public -class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, - View.OnKeyListener, View.OnTouchListener, SensorEventListener { - - // Sensors - protected static SensorManager mSensorManager; - protected static Display mDisplay; - - // Keep track of the surface size to normalize touch events - protected static float mWidth, mHeight; - - // Startup - public SDLSurface(Context context) { - super(context); - getHolder().addCallback(this); - - setFocusable(true); - setFocusableInTouchMode(true); - requestFocus(); - setOnKeyListener(this); - setOnTouchListener(this); - - mDisplay = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); - mSensorManager = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE); - - if (Build.VERSION.SDK_INT >= 12) { - setOnGenericMotionListener(new SDLGenericMotionListener_API12()); - } - - // Some arbitrary defaults to avoid a potential division by zero - mWidth = 1.0f; - mHeight = 1.0f; - } - - public void handlePause() { - enableSensor(Sensor.TYPE_ACCELEROMETER, false); - } - - public void handleResume() { - setFocusable(true); - setFocusableInTouchMode(true); - requestFocus(); - setOnKeyListener(this); - setOnTouchListener(this); - enableSensor(Sensor.TYPE_ACCELEROMETER, true); - } - - public Surface getNativeSurface() { - return getHolder().getSurface(); - } - - // Called when we have a valid drawing surface - @Override - public void surfaceCreated(SurfaceHolder holder) { - Log.v("SDL", "surfaceCreated()"); - holder.setType(SurfaceHolder.SURFACE_TYPE_GPU); - } - - // Called when we lose the surface - @Override - public void surfaceDestroyed(SurfaceHolder holder) { - Log.v("SDL", "surfaceDestroyed()"); - - // Transition to pause, if needed - SDLActivity.mNextNativeState = SDLActivity.NativeState.PAUSED; - SDLActivity.handleNativeState(); - - SDLActivity.mIsSurfaceReady = false; - SDLActivity.onNativeSurfaceDestroyed(); - } - - // Called when the surface is resized - @Override - public void surfaceChanged(SurfaceHolder holder, - int format, int width, int height) { - Log.v("SDL", "surfaceChanged()"); - - int sdlFormat = 0x15151002; // SDL_PIXELFORMAT_RGB565 by default - switch (format) { - case PixelFormat.A_8: - Log.v("SDL", "pixel format A_8"); - break; - case PixelFormat.LA_88: - Log.v("SDL", "pixel format LA_88"); - break; - case PixelFormat.L_8: - Log.v("SDL", "pixel format L_8"); - break; - case PixelFormat.RGBA_4444: - Log.v("SDL", "pixel format RGBA_4444"); - sdlFormat = 0x15421002; // SDL_PIXELFORMAT_RGBA4444 - break; - case PixelFormat.RGBA_5551: - Log.v("SDL", "pixel format RGBA_5551"); - sdlFormat = 0x15441002; // SDL_PIXELFORMAT_RGBA5551 - break; - case PixelFormat.RGBA_8888: - Log.v("SDL", "pixel format RGBA_8888"); - sdlFormat = 0x16462004; // SDL_PIXELFORMAT_RGBA8888 - break; - case PixelFormat.RGBX_8888: - Log.v("SDL", "pixel format RGBX_8888"); - sdlFormat = 0x16261804; // SDL_PIXELFORMAT_RGBX8888 - break; - case PixelFormat.RGB_332: - Log.v("SDL", "pixel format RGB_332"); - sdlFormat = 0x14110801; // SDL_PIXELFORMAT_RGB332 - break; - case PixelFormat.RGB_565: - Log.v("SDL", "pixel format RGB_565"); - sdlFormat = 0x15151002; // SDL_PIXELFORMAT_RGB565 - break; - case PixelFormat.RGB_888: - Log.v("SDL", "pixel format RGB_888"); - // Not sure this is right, maybe SDL_PIXELFORMAT_RGB24 instead? - sdlFormat = 0x16161804; // SDL_PIXELFORMAT_RGB888 - break; - default: - Log.v("SDL", "pixel format unknown " + format); - break; - } - - mWidth = width; - mHeight = height; - SDLActivity.onNativeResize(width, height, sdlFormat, mDisplay.getRefreshRate()); - Log.v("SDL", "Window size: " + width + "x" + height); - - - boolean skip = false; - int requestedOrientation = SDLActivity.mSingleton.getRequestedOrientation(); - - if (requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) - { - // Accept any - } - else if (requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) - { - if (mWidth > mHeight) { - skip = true; - } - } else if (requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) { - if (mWidth < mHeight) { - skip = true; - } - } - - // Special Patch for Square Resolution: Black Berry Passport - if (skip) { - double min = Math.min(mWidth, mHeight); - double max = Math.max(mWidth, mHeight); - - if (max / min < 1.20) { - Log.v("SDL", "Don't skip on such aspect-ratio. Could be a square resolution."); - skip = false; - } - } - - if (skip) { - Log.v("SDL", "Skip .. Surface is not ready."); - SDLActivity.mIsSurfaceReady = false; - return; - } - - /* Surface is ready */ - SDLActivity.mIsSurfaceReady = true; - - /* If the surface has been previously destroyed by onNativeSurfaceDestroyed, recreate it here */ - SDLActivity.onNativeSurfaceChanged(); - - SDLActivity.handleNativeState(); - } - - // Key events - @Override - public boolean onKey(View v, int keyCode, KeyEvent event) { - // Dispatch the different events depending on where they come from - // Some SOURCE_JOYSTICK, SOURCE_DPAD or SOURCE_GAMEPAD are also SOURCE_KEYBOARD - // So, we try to process them as JOYSTICK/DPAD/GAMEPAD events first, if that fails we try them as KEYBOARD - // - // Furthermore, it's possible a game controller has SOURCE_KEYBOARD and - // SOURCE_JOYSTICK, while its key events arrive from the keyboard source - // So, retrieve the device itself and check all of its sources - if (SDLControllerManager.isDeviceSDLJoystick(event.getDeviceId())) { - // Note that we process events with specific key codes here - if (event.getAction() == KeyEvent.ACTION_DOWN) { - if (SDLControllerManager.onNativePadDown(event.getDeviceId(), keyCode) == 0) { - return true; - } - } else if (event.getAction() == KeyEvent.ACTION_UP) { - if (SDLControllerManager.onNativePadUp(event.getDeviceId(), keyCode) == 0) { - return true; - } - } - } - - if ((event.getSource() & InputDevice.SOURCE_KEYBOARD) != 0) { - if (event.getAction() == KeyEvent.ACTION_DOWN) { - //Log.v("SDL", "key down: " + keyCode); - if (SDLActivity.isTextInputEvent(event)) { - SDLInputConnection.nativeCommitText(String.valueOf((char) event.getUnicodeChar()), 1); - } - SDLActivity.onNativeKeyDown(keyCode); - return true; - } - else if (event.getAction() == KeyEvent.ACTION_UP) { - //Log.v("SDL", "key up: " + keyCode); - SDLActivity.onNativeKeyUp(keyCode); - return true; - } - } - - if ((event.getSource() & InputDevice.SOURCE_MOUSE) != 0) { - // on some devices key events are sent for mouse BUTTON_BACK/FORWARD presses - // they are ignored here because sending them as mouse input to SDL is messy - if ((keyCode == KeyEvent.KEYCODE_BACK) || (keyCode == KeyEvent.KEYCODE_FORWARD)) { - switch (event.getAction()) { - case KeyEvent.ACTION_DOWN: - case KeyEvent.ACTION_UP: - // mark the event as handled or it will be handled by system - // handling KEYCODE_BACK by system will call onBackPressed() - return true; - } - } - } - - return false; - } - - // Touch events - @Override - public boolean onTouch(View v, MotionEvent event) { - /* Ref: http://developer.android.com/training/gestures/multi.html */ - final int touchDevId = event.getDeviceId(); - final int pointerCount = event.getPointerCount(); - int action = event.getActionMasked(); - int pointerFingerId; - int mouseButton; - int i = -1; - float x,y,p; - - // !!! FIXME: dump this SDK check after 2.0.4 ships and require API14. - if (event.getSource() == InputDevice.SOURCE_MOUSE && SDLActivity.mSeparateMouseAndTouch) { - if (Build.VERSION.SDK_INT < 14) { - mouseButton = 1; // all mouse buttons are the left button - } else { - try { - mouseButton = (Integer) event.getClass().getMethod("getButtonState").invoke(event); - } catch(Exception e) { - mouseButton = 1; // oh well. - } - } - SDLActivity.onSDLNativeMouse(mouseButton, action, event.getX(0), event.getY(0)); - } else { - switch(action) { - case MotionEvent.ACTION_MOVE: - for (i = 0; i < pointerCount; i++) { - pointerFingerId = event.getPointerId(i); - x = event.getX(i) / mWidth; - y = event.getY(i) / mHeight; - p = event.getPressure(i); - if (p > 1.0f) { - // may be larger than 1.0f on some devices - // see the documentation of getPressure(i) - p = 1.0f; - } - SDLActivity.onSDLNativeTouch(touchDevId, pointerFingerId, action, x, y, p); - } - break; - - case MotionEvent.ACTION_UP: - case MotionEvent.ACTION_DOWN: - // Primary pointer up/down, the index is always zero - i = 0; - case MotionEvent.ACTION_POINTER_UP: - case MotionEvent.ACTION_POINTER_DOWN: - // Non primary pointer up/down - if (i == -1) { - i = event.getActionIndex(); - } - - pointerFingerId = event.getPointerId(i); - x = event.getX(i) / mWidth; - y = event.getY(i) / mHeight; - p = event.getPressure(i); - if (p > 1.0f) { - // may be larger than 1.0f on some devices - // see the documentation of getPressure(i) - p = 1.0f; - } - SDLActivity.onSDLNativeTouch(touchDevId, pointerFingerId, action, x, y, p); - break; - - case MotionEvent.ACTION_CANCEL: - for (i = 0; i < pointerCount; i++) { - pointerFingerId = event.getPointerId(i); - x = event.getX(i) / mWidth; - y = event.getY(i) / mHeight; - p = event.getPressure(i); - if (p > 1.0f) { - // may be larger than 1.0f on some devices - // see the documentation of getPressure(i) - p = 1.0f; - } - SDLActivity.onSDLNativeTouch(touchDevId, pointerFingerId, MotionEvent.ACTION_UP, x, y, p); - } - break; - - default: - break; - } - } - - return true; - } - - // Sensor events - public void enableSensor(int sensortype, boolean enabled) { - // TODO: This uses getDefaultSensor - what if we have >1 accels? - if (enabled) { - mSensorManager.registerListener(this, - mSensorManager.getDefaultSensor(sensortype), - SensorManager.SENSOR_DELAY_GAME, null); - } else { - mSensorManager.unregisterListener(this, - mSensorManager.getDefaultSensor(sensortype)); - } - } - - @Override - public void onAccuracyChanged(Sensor sensor, int accuracy) { - // TODO - } - - @Override - public void onSensorChanged(SensorEvent event) { - if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { - float x, y; - switch (mDisplay.getRotation()) { - case Surface.ROTATION_90: - x = -event.values[1]; - y = event.values[0]; - break; - case Surface.ROTATION_270: - x = event.values[1]; - y = -event.values[0]; - break; - case Surface.ROTATION_180: - x = -event.values[1]; - y = -event.values[0]; - break; - default: - x = event.values[0]; - y = event.values[1]; - break; - } - SDLActivity.onNativeAccel(-x / SensorManager.GRAVITY_EARTH, - y / SensorManager.GRAVITY_EARTH, - event.values[2] / SensorManager.GRAVITY_EARTH); - } - } -} - /* This is a fake invisible editor view that receives the input and defines the * pan&scan region */ diff --git a/app/src/main/java/org/libsdl/app/SDLSurface.java b/app/src/main/java/org/libsdl/app/SDLSurface.java new file mode 100644 index 0000000..a53c3fa --- /dev/null +++ b/app/src/main/java/org/libsdl/app/SDLSurface.java @@ -0,0 +1,384 @@ +package org.libsdl.app; + +import android.content.Context; +import android.content.pm.ActivityInfo; +import android.graphics.PixelFormat; +import android.hardware.Sensor; +import android.hardware.SensorEvent; +import android.hardware.SensorEventListener; +import android.hardware.SensorManager; +import android.os.Build; +import android.util.Log; +import android.view.Display; +import android.view.InputDevice; +import android.view.KeyEvent; +import android.view.MotionEvent; +import android.view.Surface; +import android.view.SurfaceHolder; +import android.view.SurfaceView; +import android.view.View; +import android.view.WindowManager; + +/** + * SDLSurface. This is what we draw on, so we need to know when it's created + * in order to do anything useful. + *

+ * Because of this, that's where we set up the SDL thread + */ +//Limbo: should be public +public class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, + View.OnKeyListener, View.OnTouchListener, SensorEventListener { + + // Sensors + protected static SensorManager mSensorManager; + protected static Display mDisplay; + + // Keep track of the surface size to normalize touch events + protected static float mWidth, mHeight; + + // Startup + public SDLSurface(Context context) { + super(context); + getHolder().addCallback(this); + + setFocusable(true); + setFocusableInTouchMode(true); + requestFocus(); + setOnKeyListener(this); + setOnTouchListener(this); + + mDisplay = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); + mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); + + if (Build.VERSION.SDK_INT >= 12) { + setOnGenericMotionListener(new SDLGenericMotionListener_API12()); + } + + // Some arbitrary defaults to avoid a potential division by zero + mWidth = 1.0f; + mHeight = 1.0f; + } + + public void handlePause() { + enableSensor(Sensor.TYPE_ACCELEROMETER, false); + } + + public void handleResume() { + setFocusable(true); + setFocusableInTouchMode(true); + requestFocus(); + setOnKeyListener(this); + setOnTouchListener(this); + enableSensor(Sensor.TYPE_ACCELEROMETER, true); + } + + public Surface getNativeSurface() { + return getHolder().getSurface(); + } + + // Called when we have a valid drawing surface + @Override + public void surfaceCreated(SurfaceHolder holder) { + Log.v("SDL", "surfaceCreated()"); + holder.setType(SurfaceHolder.SURFACE_TYPE_GPU); + } + + // Called when we lose the surface + @Override + public void surfaceDestroyed(SurfaceHolder holder) { + Log.v("SDL", "surfaceDestroyed()"); + + // Transition to pause, if needed + SDLActivity.mNextNativeState = SDLActivity.NativeState.PAUSED; + SDLActivity.handleNativeState(); + + SDLActivity.mIsSurfaceReady = false; + SDLActivity.onNativeSurfaceDestroyed(); + } + + // Called when the surface is resized + @Override + public void surfaceChanged(SurfaceHolder holder, + int format, int width, int height) { + Log.v("SDL", "surfaceChanged()"); + + int sdlFormat = 0x15151002; // SDL_PIXELFORMAT_RGB565 by default + switch (format) { + case PixelFormat.A_8: + Log.v("SDL", "pixel format A_8"); + break; + case PixelFormat.LA_88: + Log.v("SDL", "pixel format LA_88"); + break; + case PixelFormat.L_8: + Log.v("SDL", "pixel format L_8"); + break; + case PixelFormat.RGBA_4444: + Log.v("SDL", "pixel format RGBA_4444"); + sdlFormat = 0x15421002; // SDL_PIXELFORMAT_RGBA4444 + break; + case PixelFormat.RGBA_5551: + Log.v("SDL", "pixel format RGBA_5551"); + sdlFormat = 0x15441002; // SDL_PIXELFORMAT_RGBA5551 + break; + case PixelFormat.RGBA_8888: + Log.v("SDL", "pixel format RGBA_8888"); + sdlFormat = 0x16462004; // SDL_PIXELFORMAT_RGBA8888 + break; + case PixelFormat.RGBX_8888: + Log.v("SDL", "pixel format RGBX_8888"); + sdlFormat = 0x16261804; // SDL_PIXELFORMAT_RGBX8888 + break; + case PixelFormat.RGB_332: + Log.v("SDL", "pixel format RGB_332"); + sdlFormat = 0x14110801; // SDL_PIXELFORMAT_RGB332 + break; + case PixelFormat.RGB_565: + Log.v("SDL", "pixel format RGB_565"); + sdlFormat = 0x15151002; // SDL_PIXELFORMAT_RGB565 + break; + case PixelFormat.RGB_888: + Log.v("SDL", "pixel format RGB_888"); + // Not sure this is right, maybe SDL_PIXELFORMAT_RGB24 instead? + sdlFormat = 0x16161804; // SDL_PIXELFORMAT_RGB888 + break; + default: + Log.v("SDL", "pixel format unknown " + format); + break; + } + + mWidth = width; + mHeight = height; + SDLActivity.onNativeResize(width, height, sdlFormat, mDisplay.getRefreshRate()); + Log.v("SDL", "Window size: " + width + "x" + height); + + + boolean skip = false; + int requestedOrientation = SDLActivity.mSingleton.getRequestedOrientation(); + + if (requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { + // Accept any + } else if (requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) { + if (mWidth > mHeight) { + skip = true; + } + } else if (requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) { + if (mWidth < mHeight) { + skip = true; + } + } + + // Special Patch for Square Resolution: Black Berry Passport + if (skip) { + double min = Math.min(mWidth, mHeight); + double max = Math.max(mWidth, mHeight); + + if (max / min < 1.20) { + Log.v("SDL", "Don't skip on such aspect-ratio. Could be a square resolution."); + skip = false; + } + } + + if (skip) { + Log.v("SDL", "Skip .. Surface is not ready."); + SDLActivity.mIsSurfaceReady = false; + return; + } + + /* Surface is ready */ + SDLActivity.mIsSurfaceReady = true; + + /* If the surface has been previously destroyed by onNativeSurfaceDestroyed, recreate it here */ + SDLActivity.onNativeSurfaceChanged(); + + SDLActivity.handleNativeState(); + } + + // Key events + @Override + public boolean onKey(View v, int keyCode, KeyEvent event) { + // Dispatch the different events depending on where they come from + // Some SOURCE_JOYSTICK, SOURCE_DPAD or SOURCE_GAMEPAD are also SOURCE_KEYBOARD + // So, we try to process them as JOYSTICK/DPAD/GAMEPAD events first, if that fails we try them as KEYBOARD + // + // Furthermore, it's possible a game controller has SOURCE_KEYBOARD and + // SOURCE_JOYSTICK, while its key events arrive from the keyboard source + // So, retrieve the device itself and check all of its sources + if (SDLControllerManager.isDeviceSDLJoystick(event.getDeviceId())) { + // Note that we process events with specific key codes here + if (event.getAction() == KeyEvent.ACTION_DOWN) { + if (SDLControllerManager.onNativePadDown(event.getDeviceId(), keyCode) == 0) { + return true; + } + } else if (event.getAction() == KeyEvent.ACTION_UP) { + if (SDLControllerManager.onNativePadUp(event.getDeviceId(), keyCode) == 0) { + return true; + } + } + } + + if ((event.getSource() & InputDevice.SOURCE_KEYBOARD) != 0) { + if (event.getAction() == KeyEvent.ACTION_DOWN) { + //Log.v("SDL", "key down: " + keyCode); + if (SDLActivity.isTextInputEvent(event)) { + SDLInputConnection.nativeCommitText(String.valueOf((char) event.getUnicodeChar()), 1); + } + SDLActivity.onNativeKeyDown(keyCode); + return true; + } else if (event.getAction() == KeyEvent.ACTION_UP) { + //Log.v("SDL", "key up: " + keyCode); + SDLActivity.onNativeKeyUp(keyCode); + return true; + } + } + + if ((event.getSource() & InputDevice.SOURCE_MOUSE) != 0) { + // on some devices key events are sent for mouse BUTTON_BACK/FORWARD presses + // they are ignored here because sending them as mouse input to SDL is messy + if ((keyCode == KeyEvent.KEYCODE_BACK) || (keyCode == KeyEvent.KEYCODE_FORWARD)) { + switch (event.getAction()) { + case KeyEvent.ACTION_DOWN: + case KeyEvent.ACTION_UP: + // mark the event as handled or it will be handled by system + // handling KEYCODE_BACK by system will call onBackPressed() + return true; + } + } + } + + return false; + } + + // Touch events + @Override + public boolean onTouch(View v, MotionEvent event) { + /* Ref: http://developer.android.com/training/gestures/multi.html */ + final int touchDevId = event.getDeviceId(); + final int pointerCount = event.getPointerCount(); + int action = event.getActionMasked(); + int pointerFingerId; + int mouseButton; + int i = -1; + float x, y, p; + + // !!! FIXME: dump this SDK check after 2.0.4 ships and require API14. + if (event.getSource() == InputDevice.SOURCE_MOUSE && SDLActivity.mSeparateMouseAndTouch) { + if (Build.VERSION.SDK_INT < 14) { + mouseButton = 1; // all mouse buttons are the left button + } else { + try { + mouseButton = (Integer) event.getClass().getMethod("getButtonState").invoke(event); + } catch (Exception e) { + mouseButton = 1; // oh well. + } + } + SDLActivity.onSDLNativeMouse(mouseButton, action, event.getX(0), event.getY(0)); + } else { + switch (action) { + case MotionEvent.ACTION_MOVE: + for (i = 0; i < pointerCount; i++) { + pointerFingerId = event.getPointerId(i); + x = event.getX(i) / mWidth; + y = event.getY(i) / mHeight; + p = event.getPressure(i); + if (p > 1.0f) { + // may be larger than 1.0f on some devices + // see the documentation of getPressure(i) + p = 1.0f; + } + SDLActivity.onSDLNativeTouch(touchDevId, pointerFingerId, action, x, y, p); + } + break; + + case MotionEvent.ACTION_UP: + case MotionEvent.ACTION_DOWN: + // Primary pointer up/down, the index is always zero + i = 0; + case MotionEvent.ACTION_POINTER_UP: + case MotionEvent.ACTION_POINTER_DOWN: + // Non primary pointer up/down + if (i == -1) { + i = event.getActionIndex(); + } + + pointerFingerId = event.getPointerId(i); + x = event.getX(i) / mWidth; + y = event.getY(i) / mHeight; + p = event.getPressure(i); + if (p > 1.0f) { + // may be larger than 1.0f on some devices + // see the documentation of getPressure(i) + p = 1.0f; + } + SDLActivity.onSDLNativeTouch(touchDevId, pointerFingerId, action, x, y, p); + break; + + case MotionEvent.ACTION_CANCEL: + for (i = 0; i < pointerCount; i++) { + pointerFingerId = event.getPointerId(i); + x = event.getX(i) / mWidth; + y = event.getY(i) / mHeight; + p = event.getPressure(i); + if (p > 1.0f) { + // may be larger than 1.0f on some devices + // see the documentation of getPressure(i) + p = 1.0f; + } + SDLActivity.onSDLNativeTouch(touchDevId, pointerFingerId, MotionEvent.ACTION_UP, x, y, p); + } + break; + + default: + break; + } + } + + return true; + } + + // Sensor events + public void enableSensor(int sensortype, boolean enabled) { + // TODO: This uses getDefaultSensor - what if we have >1 accels? + if (enabled) { + mSensorManager.registerListener(this, + mSensorManager.getDefaultSensor(sensortype), + SensorManager.SENSOR_DELAY_GAME, null); + } else { + mSensorManager.unregisterListener(this, + mSensorManager.getDefaultSensor(sensortype)); + } + } + + @Override + public void onAccuracyChanged(Sensor sensor, int accuracy) { + // TODO + } + + @Override + public void onSensorChanged(SensorEvent event) { + if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { + float x, y; + switch (mDisplay.getRotation()) { + case Surface.ROTATION_90: + x = -event.values[1]; + y = event.values[0]; + break; + case Surface.ROTATION_270: + x = event.values[1]; + y = -event.values[0]; + break; + case Surface.ROTATION_180: + x = -event.values[1]; + y = -event.values[0]; + break; + default: + x = event.values[0]; + y = event.values[1]; + break; + } + SDLActivity.onNativeAccel(-x / SensorManager.GRAVITY_EARTH, + y / SensorManager.GRAVITY_EARTH, + event.values[2] / SensorManager.GRAVITY_EARTH); + } + } +} diff --git a/app/src/main/res/drawable/ic_a.xml b/app/src/main/res/drawable/ic_a.xml new file mode 100644 index 0000000..2669658 --- /dev/null +++ b/app/src/main/res/drawable/ic_a.xml @@ -0,0 +1,8 @@ + + + + diff --git a/app/src/main/res/drawable/ic_t.xml b/app/src/main/res/drawable/ic_t.xml new file mode 100644 index 0000000..07d6b26 --- /dev/null +++ b/app/src/main/res/drawable/ic_t.xml @@ -0,0 +1,6 @@ + + + diff --git a/app/src/main/res/layout/activity_sdl.xml b/app/src/main/res/layout/activity_sdl.xml index e199db1..61c08af 100644 --- a/app/src/main/res/layout/activity_sdl.xml +++ b/app/src/main/res/layout/activity_sdl.xml @@ -1,18 +1,14 @@ - - + android:orientation="vertical" /> + + - - - \ No newline at end of file diff --git a/app/src/main/res/layout/activity_vnc.xml b/app/src/main/res/layout/activity_vnc.xml index aba9c50..37465e0 100644 --- a/app/src/main/res/layout/activity_vnc.xml +++ b/app/src/main/res/layout/activity_vnc.xml @@ -1,6 +1,7 @@ + android:keepScreenOn="true" /> @@ -62,4 +64,4 @@ android:layout_centerHorizontal="true" /> - \ No newline at end of file + diff --git a/app/src/main/res/layout/controls_fragment.xml b/app/src/main/res/layout/controls_fragment.xml index b457447..dfbf4da 100644 --- a/app/src/main/res/layout/controls_fragment.xml +++ b/app/src/main/res/layout/controls_fragment.xml @@ -195,6 +195,16 @@ android:paddingRight="10dp" android:translationY="-6dp"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml index 83a55a0..07c02c5 100644 --- a/app/src/main/res/values-night/themes.xml +++ b/app/src/main/res/values-night/themes.xml @@ -65,7 +65,7 @@ @anim/popup_in @anim/popup_out - -