@Override public boolean onOptionsItemSelected(MenuItem item) { // refer to http://tools.android.com/tips/non-constant-fields why we can't use switch/case here // .. int itemId = item.getItemId(); if (itemId == R.id.session_touch_pointer) { // toggle touch pointer if (touchPointerView.getVisibility() == View.VISIBLE) { touchPointerView.setVisibility(View.INVISIBLE); sessionView.setTouchPointerPadding(0, 0); } else { touchPointerView.setVisibility(View.VISIBLE); sessionView.setTouchPointerPadding( touchPointerView.getPointerWidth(), touchPointerView.getPointerHeight()); } } else if (itemId == R.id.session_sys_keyboard) { showKeyboard(!sysKeyboardVisible, false); } else if (itemId == R.id.session_ext_keyboard) { showKeyboard(false, !extKeyboardVisible); } else if (itemId == R.id.session_disconnect) { showKeyboard(false, false); LibFreeRDP.disconnect(session.getInstance()); } return true; }
@Override public void onTouchPointerMove(int x, int y) { Point p = mapScreenCoordToSessionCoord(x, y); LibFreeRDP.sendCursorEvent(session.getInstance(), p.x, p.y, Mouse.getMoveEvent()); if (autoScrollTouchPointer && !uiHandler.hasMessages(UIHandler.SCROLLING_REQUESTED)) { Log.v(TAG, "Starting auto-scroll"); uiHandler.sendEmptyMessageDelayed(UIHandler.SCROLLING_REQUESTED, SCROLLING_TIMEOUT); } }
@Override public void OnGraphicsUpdate(int x, int y, int width, int height) { LibFreeRDP.updateGraphics(session.getInstance(), bitmap, x, y, width, height); sessionView.addInvalidRegion(new Rect(x, y, x + width, y + height)); /* since sessionView can only be modified from the UI thread * any modifications to it need to be scheduled */ uiHandler.sendEmptyMessage(UIHandler.REFRESH_SESSIONVIEW); }
private void sendDelayedMoveEvent(int x, int y) { if (uiHandler.hasMessages(UIHandler.SEND_MOVE_EVENT)) { uiHandler.removeMessages(UIHandler.SEND_MOVE_EVENT); discardedMoveEvents++; } else discardedMoveEvents = 0; if (discardedMoveEvents > MAX_DISCARDED_MOVE_EVENTS) LibFreeRDP.sendCursorEvent(session.getInstance(), x, y, Mouse.getMoveEvent()); else uiHandler.sendMessageDelayed( Message.obtain(null, UIHandler.SEND_MOVE_EVENT, x, y), SEND_MOVE_EVENT_TIMEOUT); }
@Override protected void onDestroy() { super.onDestroy(); Log.v(TAG, "Session.onDestroy"); // unregister freerdp events broadcast receiver unregisterReceiver(libFreeRDPBroadcastReceiver); // free session GlobalApp.freeSession(session.getInstance()); session = null; }
@Override public void onSessionViewLeftTouch(int x, int y, boolean down) { if (!down) cancelDelayedMoveEvent(); LibFreeRDP.sendCursorEvent( session.getInstance(), x, y, toggleMouseButtons ? Mouse.getRightButtonEvent(down) : Mouse.getLeftButtonEvent(down)); if (!down) toggleMouseButtons = false; }
private void connect(BookmarkBase bookmark) { session = GlobalApp.createSession(bookmark); session.setUIEventListener(this); // set writeable data directory LibFreeRDP.setDataDirectory(session.getInstance(), getFilesDir().toString()); BookmarkBase.ScreenSettings screenSettings = session.getBookmark().getActiveScreenSettings(); Log.v(TAG, "Screen Resolution: " + screenSettings.getResolutionString()); if (screenSettings.isAutomatic()) { if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE) { // large screen device i.e. tablet: simply use screen info screenSettings.setHeight(screen_height); screenSettings.setWidth(screen_width); } else { // small screen device i.e. phone: // Automatic uses the largest side length of the screen and makes a 16:10 resolution setting // out of it int screenMax = (screen_width > screen_height) ? screen_width : screen_height; screenSettings.setHeight(screenMax); screenSettings.setWidth((int) ((float) screenMax * 1.6f)); } } progressDialog = new ProgressDialog(this); progressDialog.setTitle(bookmark.getLabel()); progressDialog.setMessage(getResources().getText(R.string.dlg_msg_connecting)); progressDialog.setButton( ProgressDialog.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { connectCancelledByUser = true; LibFreeRDP.cancelConnection(session.getInstance()); } }); progressDialog.setCancelable(false); progressDialog.show(); Thread thread = new Thread( new Runnable() { public void run() { session.connect(); } }); thread.start(); }
@Override public void processUnicodeKey(int unicodeKey) { LibFreeRDP.sendUnicodeKeyEvent(session.getInstance(), unicodeKey); }
// **************************************************************************** // KeyboardMapper.KeyProcessingListener implementation @Override public void processVirtualKey(int virtualKeyCode, boolean down) { LibFreeRDP.sendKeyEvent(session.getInstance(), virtualKeyCode, down); }
@Override public void onTouchPointerScroll(boolean down) { LibFreeRDP.sendCursorEvent(session.getInstance(), 0, 0, Mouse.getScrollEvent(down)); }
@Override public void onTouchPointerRightClick(int x, int y, boolean down) { Point p = mapScreenCoordToSessionCoord(x, y); LibFreeRDP.sendCursorEvent(session.getInstance(), p.x, p.y, Mouse.getRightButtonEvent(down)); }