예제 #1
0
 /**
  * Somehow our parent {@link TerminalView} was destroyed. Now we don't need to redraw anywhere,
  * and we can recycle our internal bitmap.
  */
 public synchronized void parentDestroyed() {
   parent = null;
   discardBitmap();
 }
예제 #2
0
  /**
   * Something changed in our parent {@link TerminalView}, maybe it's a new parent, or maybe it's an
   * updated font size. We should recalculate terminal size information and request a PTY resize.
   */
  public final synchronized void parentChanged(TerminalView parent) {
    if (manager != null && !manager.isResizeAllowed()) {
      Log.d(TAG, "Resize is not allowed now");
      return;
    }

    this.parent = parent;
    final int width = parent.getWidth();
    final int height = parent.getHeight();

    // Something has gone wrong with our layout; we're 0 width or height!
    if (width <= 0 || height <= 0) return;

    clipboard = (ClipboardManager) parent.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
    keyListener.setClipboardManager(clipboard);

    if (!forcedSize) {
      // recalculate buffer size
      int newColumns, newRows;

      newColumns = width / charWidth;
      newRows = height / charHeight;

      // If nothing has changed in the terminal dimensions and not an intial
      // draw then don't blow away scroll regions and such.
      if (newColumns == columns && newRows == rows) return;

      columns = newColumns;
      rows = newRows;
    }

    // reallocate new bitmap if needed
    boolean newBitmap = (bitmap == null);
    if (bitmap != null) newBitmap = (bitmap.getWidth() != width || bitmap.getHeight() != height);

    if (newBitmap) {
      discardBitmap();
      bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
      canvas.setBitmap(bitmap);
    }

    // clear out any old buffer information
    defaultPaint.setColor(Color.BLACK);
    canvas.drawPaint(defaultPaint);

    // Stroke the border of the terminal if the size is being forced;
    if (forcedSize) {
      int borderX = (columns * charWidth) + 1;
      int borderY = (rows * charHeight) + 1;

      defaultPaint.setColor(Color.GRAY);
      defaultPaint.setStrokeWidth(0.0f);
      if (width >= borderX) canvas.drawLine(borderX, 0, borderX, borderY + 1, defaultPaint);
      if (height >= borderY) canvas.drawLine(0, borderY, borderX + 1, borderY, defaultPaint);
    }

    try {
      // request a terminal pty resize
      synchronized (buffer) {
        buffer.setScreenSize(columns, rows, true);
      }

      if (transport != null) transport.setDimensions(columns, rows, width, height);
    } catch (Exception e) {
      Log.e(TAG, "Problem while trying to resize screen or PTY", e);
    }

    // redraw local output if we don't have a sesson to receive our resize request
    if (transport == null) {
      synchronized (localOutput) {
        ((vt320) buffer).reset();

        for (String line : localOutput) ((vt320) buffer).putString(line);
      }
    }

    // force full redraw with new buffer size
    fullRedraw = true;
    redraw();

    parent.notifyUser(String.format("%d x %d", columns, rows));

    Log.i(TAG, String.format("parentChanged() now width=%d, height=%d", columns, rows));
  }