Ejemplo n.º 1
0
  /** Make sure mouse is visible on displayable part of screen */
  public void panToMouse() {
    if (rfbconn == null) return;

    boolean panX = true;
    boolean panY = true;

    // Don't pan in a certain direction if dimension scaled is already less
    // than the dimension of the visible part of the screen.
    if (rfbconn.framebufferWidth() <= getVisibleWidth()) panX = false;
    if (rfbconn.framebufferHeight() <= getVisibleHeight()) panY = false;

    // We only pan if the current scaling is able to pan.
    if (scaling != null && !scaling.isAbleToPan()) return;

    int x = pointer.getX();
    int y = pointer.getY();
    boolean panned = false;
    int w = getVisibleWidth();
    int h = getVisibleHeight();
    int iw = getImageWidth();
    int ih = getImageHeight();
    int wthresh = 30;
    int hthresh = 30;

    int newX = absoluteXPosition;
    int newY = absoluteYPosition;

    if (x - absoluteXPosition >= w - wthresh) {
      newX = x - (w - wthresh);
      if (newX + w > iw) newX = iw - w;
    } else if (x < absoluteXPosition + wthresh) {
      newX = x - wthresh;
      if (newX < 0) newX = 0;
    }
    if (panX && newX != absoluteXPosition) {
      absoluteXPosition = newX;
      panned = true;
    }

    if (y - absoluteYPosition >= h - hthresh) {
      newY = y - (h - hthresh);
      if (newY + h > ih) newY = ih - h;
    } else if (y < absoluteYPosition + hthresh) {
      newY = y - hthresh;
      if (newY < 0) newY = 0;
    }
    if (panY && newY != absoluteYPosition) {
      absoluteYPosition = newY;
      panned = true;
    }

    if (panned) {
      // scrollBy(newX - absoluteXPosition, newY - absoluteYPosition);
      scrollToAbsolute();
    }
  }
Ejemplo n.º 2
0
  void initializeBitmap(int dx, int dy) throws IOException {
    Log.i(TAG, "Desktop name is " + rfbconn.desktopName());
    Log.i(
        TAG, "Desktop size is " + rfbconn.framebufferWidth() + " x " + rfbconn.framebufferHeight());
    int fbsize = rfbconn.framebufferWidth() * rfbconn.framebufferHeight();
    capacity =
        BCFactory.getInstance()
            .getBCActivityManager()
            .getMemoryClass(Utils.getActivityManager(getContext()));

    if (connection.getForceFull() == BitmapImplHint.AUTO) {
      if (fbsize * CompactBitmapData.CAPACITY_MULTIPLIER <= capacity * 1024 * 1024) {
        useFull = true;
        compact = true;
      } else if (fbsize * FullBufferBitmapData.CAPACITY_MULTIPLIER <= capacity * 1024 * 1024) {
        useFull = true;
      } else {
        useFull = false;
      }
    } else useFull = (connection.getForceFull() == BitmapImplHint.FULL);

    if (!useFull) {
      bitmapData = new LargeBitmapData(rfbconn, this, dx, dy, capacity);
      android.util.Log.i(TAG, "Using LargeBitmapData.");
    } else {
      try {
        // TODO: Remove this if Android 4.2 receives a fix which causes it to stop drawing
        // the bitmap in CompactBitmapData when under load (say playing a video over VNC).
        if (!compact || android.os.Build.VERSION.SDK_INT == 17) {
          bitmapData = new FullBufferBitmapData(rfbconn, this, capacity);
          android.util.Log.i(TAG, "Using FullBufferBitmapData.");
        } else {
          bitmapData = new CompactBitmapData(rfbconn, this);
          android.util.Log.i(TAG, "Using CompactBufferBitmapData.");
        }
      } catch (Throwable e) { // If despite our efforts we fail to allocate memory, use LBBM.
        if (bitmapData != null) bitmapData.dispose();
        bitmapData = null;
        System.gc();
        useFull = false;
        bitmapData = new LargeBitmapData(rfbconn, this, dx, dy, capacity);
        android.util.Log.i(TAG, "Using LargeBitmapData.");
      }
    }

    decoder.setBitmapData(bitmapData);
  }
Ejemplo n.º 3
0
 public void writeFullUpdateRequest(boolean incremental) {
   bitmapData.prepareFullUpdateRequest(incremental);
   rfbconn.writeFramebufferUpdateRequest(
       bitmapData.getXoffset(),
       bitmapData.getYoffset(),
       bitmapData.bmWidth(),
       bitmapData.bmHeight(),
       incremental);
 }
Ejemplo n.º 4
0
  public void closeConnection() {
    maintainConnection = false;

    if (keyboard != null) {
      // Tell the server to release any meta keys.
      keyboard.clearMetaState();
      keyboard.processLocalKeyEvent(0, new KeyEvent(KeyEvent.ACTION_UP, 0));
    }
    // Close the rfb connection.
    if (rfbconn != null) rfbconn.close();

    // rfbconn = null;
    // rfb = null;
    // cc = null;
    // sock = null;

    // Close the SSH tunnel.
    if (sshConnection != null) {
      sshConnection.terminateSSHTunnel();
      sshConnection = null;
    }
    onDestroy();
  }
Ejemplo n.º 5
0
  public void showConnectionInfo() {
    if (rfbconn == null) return;

    String msg = null;
    int idx = rfbconn.desktopName().indexOf("(");
    if (idx > 0) {
      // Breakup actual desktop name from IP addresses for improved
      // readability
      String dn = rfbconn.desktopName().substring(0, idx).trim();
      String ip = rfbconn.desktopName().substring(idx).trim();
      msg = dn + "\n" + ip;
    } else msg = rfbconn.desktopName();
    msg += "\n" + rfbconn.framebufferWidth() + "x" + rfbconn.framebufferHeight();
    String enc = rfbconn.getEncoding();
    // Encoding might not be set when we display this message
    if (decoder.getColorModel() != null) {
      if (enc != null && !enc.equals(""))
        msg += ", " + rfbconn.getEncoding() + " encoding, " + decoder.getColorModel().toString();
      else msg += ", " + decoder.getColorModel().toString();
    }
    Toast.makeText(getContext(), msg, Toast.LENGTH_SHORT).show();
  }
Ejemplo n.º 6
0
 public int getCenteredYOffset() {
   return (rfbconn.framebufferHeight() - getHeight()) / 2;
 }
Ejemplo n.º 7
0
 public int getCenteredXOffset() {
   return (rfbconn.framebufferWidth() - getWidth()) / 2;
 }
Ejemplo n.º 8
0
 public int getImageHeight() {
   return rfbconn.framebufferHeight();
 }
Ejemplo n.º 9
0
 public int getImageWidth() {
   return rfbconn.framebufferWidth();
 }
Ejemplo n.º 10
0
 /**
  * Computes the X and Y offset for converting coordinates from full-frame coordinates to view
  * coordinates.
  */
 public void computeShiftFromFullToView() {
   shiftX = (rfbconn.framebufferWidth() - getWidth()) / 2;
   shiftY = (rfbconn.framebufferHeight() - getHeight()) / 2;
 }
Ejemplo n.º 11
0
 public void writeFramebufferUpdateRequest(int x, int y, int w, int h, boolean incremental)
     throws IOException {
   bitmapData.prepareFullUpdateRequest(incremental);
   rfbconn.writeFramebufferUpdateRequest(x, y, w, h, incremental);
 }