Пример #1
0
  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();
  }
Пример #2
0
  @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;
  }
Пример #3
0
 // binds the current session to the activity by wiring it up with the sessionView and updating all
 // internal objects accordingly
 private void bindSession() {
   Log.v("SessionActivity", "bindSession called");
   session.setUIEventListener(this);
   sessionView.onSurfaceChange(session);
   scrollView.requestLayout();
   keyboardMapper.reset(this);
 }
Пример #4
0
  private void processIntent(Intent intent) {
    // get either session instance or create one from a bookmark
    Bundle bundle = intent.getExtras();
    if (bundle.containsKey(PARAM_INSTANCE)) {
      int inst = bundle.getInt(PARAM_INSTANCE);
      session = GlobalApp.getSession(inst);
      bitmap = session.getSurface().getBitmap();
      bindSession();
    } else if (bundle.containsKey(PARAM_CONNECTION_REFERENCE)) {
      BookmarkBase bookmark = null;
      String refStr = bundle.getString(PARAM_CONNECTION_REFERENCE);
      if (ConnectionReference.isHostnameReference(refStr)) {
        bookmark = new ManualBookmark();
        bookmark.<ManualBookmark>get().setHostname(ConnectionReference.getHostname(refStr));
      } else if (ConnectionReference.isBookmarkReference(refStr)) {
        if (ConnectionReference.isManualBookmarkReference(refStr))
          bookmark =
              GlobalApp.getManualBookmarkGateway()
                  .findById(ConnectionReference.getManualBookmarkId(refStr));
        else assert false;
      }

      if (bookmark != null) connect(bookmark);
      else closeSessionActivity(RESULT_CANCELED);
    } else {
      // no session found - exit
      closeSessionActivity(RESULT_CANCELED);
    }
  }
Пример #5
0
  @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);
    }
  }
Пример #6
0
  @Override
  public void OnGraphicsResize(int width, int height, int bpp) {
    // replace bitmap
    if (bpp > 16) bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    else bitmap = Bitmap.createBitmap(width, height, Config.RGB_565);
    session.setSurface(new BitmapDrawable(bitmap));

    /* since sessionView can only be modified from the UI thread
     * any modifications to it need to be scheduled */
    uiHandler.sendEmptyMessage(UIHandler.GRAPHICS_CHANGED);
  }
Пример #7
0
  @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);
  }
Пример #8
0
  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);
  }
Пример #9
0
  @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;
  }
Пример #10
0
  @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;
  }
Пример #11
0
  // ****************************************************************************
  // LibFreeRDP UI event listener implementation
  @Override
  public void OnSettingsChanged(int width, int height, int bpp) {

    if (bpp > 16) bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    else bitmap = Bitmap.createBitmap(width, height, Config.RGB_565);

    session.setSurface(new BitmapDrawable(bitmap));

    // check this settings and initial settings - if they are not equal the server doesn't support
    // our settings
    // FIXME: the additional check (settings.getWidth() != width + 1) is for the RDVH bug fix to
    // avoid accidental notifications
    // (refer to android_freerdp.c for more info on this problem)
    BookmarkBase.ScreenSettings settings = session.getBookmark().getActiveScreenSettings();
    if ((settings.getWidth() != width && settings.getWidth() != width + 1)
        || settings.getHeight() != height
        || settings.getColors() != bpp)
      uiHandler.sendMessage(
          Message.obtain(
              null,
              UIHandler.DISPLAY_TOAST,
              getResources().getText(R.string.info_capabilities_changed)));
  }
Пример #12
0
 @Override
 public void processUnicodeKey(int unicodeKey) {
   LibFreeRDP.sendUnicodeKeyEvent(session.getInstance(), unicodeKey);
 }
Пример #13
0
 // ****************************************************************************
 // KeyboardMapper.KeyProcessingListener implementation
 @Override
 public void processVirtualKey(int virtualKeyCode, boolean down) {
   LibFreeRDP.sendKeyEvent(session.getInstance(), virtualKeyCode, down);
 }
Пример #14
0
 @Override
 public void onTouchPointerScroll(boolean down) {
   LibFreeRDP.sendCursorEvent(session.getInstance(), 0, 0, Mouse.getScrollEvent(down));
 }
Пример #15
0
 @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));
 }