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); }
/** 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(); } }
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(); }
public int getCenteredXOffset() { return (rfbconn.framebufferWidth() - getWidth()) / 2; }
public int getImageWidth() { return rfbconn.framebufferWidth(); }
/** * 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; }