@Override protected void onPause() { Log.i("MoSync", "onPause"); super.onPause(); if (theMoSyncThreadIsDead()) { return; } mMoSyncThread.onPause(); // Moved the release hardware to the correct position seems to solve the problem. mMoSyncThread.releaseHardware(); if (nfcForegroundHandler != null) { nfcForegroundHandler.disableForeground(); } // Notify the local notifications manager that the application // has lost focus. LocalNotificationsManager.focusLost(); SYSLOG("Posting EVENT_TYPE_FOCUS_LOST to MoSync"); int[] event = new int[1]; event[0] = EVENT_TYPE_FOCUS_LOST; mMoSyncThread.postEvent(event); }
@Override protected void onResume() { Log.i("MoSync", "onResume"); super.onResume(); if (theMoSyncThreadIsDead()) { return; } mMoSyncThread.acquireHardware(); mMoSyncThread.onResume(); if (nfcForegroundHandler != null) { nfcForegroundHandler.enableForeground(); } // Notify the local notifications manager that the application // has gained focus. LocalNotificationsManager.focusGained(); SYSLOG("Posting EVENT_TYPE_FOCUS_GAINED to MoSync"); int[] event = new int[1]; event[0] = EVENT_TYPE_FOCUS_GAINED; mMoSyncThread.postEvent(event); }
/** Posts an EVENT_TYPE_CLOSE to the MoSync events queue. */ private void sendCloseEvent() { if (!mEventTypeCloseHasBeenSent) { // Send EVENT_TYPE_CLOSE int[] event = new int[1]; event[0] = EVENT_TYPE_CLOSE; mMoSyncThread.postEvent(event); mEventTypeCloseHasBeenSent = true; } }
/** * Send a pointer event. * * @param type The type of event to send, e.g. EVENT_TYPE_POINTER_MOVE. * @param eventData An array containing, in order: the x position, the y position, the id of the * pointer. * @return */ public boolean sendPointerEvent(int type, int[] eventData) { // TO-DO : Proper error handling if (eventData == null) { return false; } int[] touchEvent = new int[4]; touchEvent[0] = type; touchEvent[1] = eventData[0]; touchEvent[2] = eventData[1]; touchEvent[3] = eventData[2]; mMoSyncThread.postEvent(touchEvent); return true; }
@Override public boolean onKeyDown(int keyCode, KeyEvent keyEvent) { SYSLOG("onKeyDown: " + keyEvent.toString()); // If the key is being held down we shouldn't send any more events. if (keyEvent.getRepeatCount() != 0) return true; int[] event = new int[3]; event[0] = EVENT_TYPE_KEY_PRESSED; event[1] = convertToMoSyncKeyCode(keyCode, keyEvent); event[2] = keyCode; mMoSyncThread.postEvent(event); // We need to intercept the back key otherwise the // activity will be terminated. if (keyCode == KeyEvent.KEYCODE_BACK) { return true; } else { return super.onKeyDown(keyCode, keyEvent); } }
@Override public boolean onKeyUp(int keyCode, KeyEvent keyEvent) { SYSLOG("onKeyUp: " + keyEvent.toString()); int[] event = new int[3]; event[0] = EVENT_TYPE_KEY_RELEASED; event[1] = convertToMoSyncKeyCode(keyCode, keyEvent); event[2] = keyCode; mMoSyncThread.postEvent(event); // We need to intercept the back key otherwise the // activity will be terminated. if (keyCode == KeyEvent.KEYCODE_BACK) { // Pass on the back event in case we want to handle it. mMoSyncThread.handleBack(); return true; } else { return super.onKeyUp(keyCode, keyEvent); } }