Beispiel #1
0
  /**
   * This method retrieves the key that is placed at the given x,y coordinates, considering the flip
   * status
   *
   * @param x The X coordinate to use at key lookup
   * @param y The Y coordinate to use at key lookup
   * @return The key placed at the given coordinate, or null if none is found
   */
  private IAndroidKey getSkinKey(int x, int y) {
    IAndroidKey keyToReturn = null;
    IAndroidEmulatorInstance instance = UIHelper.getInstanceAssociatedToControl(this);

    Collection<IAndroidKey> keyAreas = skin.getKeyDataCollection(instance.getCurrentLayout());
    if (keyAreas != null) {
      for (IAndroidKey key : keyAreas) {
        if (key.isInsideKey(x, y)) {
          if (key instanceof AndroidPressKey) {
            AndroidPressKey defaultKeyData = (AndroidPressKey) key;

            // if
            // (!defaultKeyData.isFlipSlideValid(instance.isFlipSlideClosed()))
            if (!defaultKeyData.isFlipSlideValid(false)) {
              continue;
            }
          }

          keyToReturn = key;
          break;
        }
      }
    }

    return keyToReturn;
  }
Beispiel #2
0
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.swt.widgets.Widget#dispose()
   */
  @Override
  public void dispose() {
    if (androidInput != null) {
      androidInput.dispose();
    }

    if (currentSkinImage != null) {
      currentSkinImage.dispose();
    }

    Layout layout = getLayout();
    if (layout instanceof AndroidSkinLayout) {
      ((AndroidSkinLayout) layout).dispose();
    }

    skin = null;
    currentKey = null;
    keyListener = null;
    mainDisplayMouseListener = null;
    mainDisplayMouseMoveListener = null;

    if (!Platform.getOS().equals(Platform.OS_MACOSX)) {
      long hnd = androidInstance.getWindowHandle();
      if (hnd > 0) {
        NativeUIUtils.showWindow(hnd);
        NativeUIUtils.restoreWindow(hnd);
      }

      // Force update on redrawing
      androidInstance.setWindowHandle(0);
    }

    super.dispose();
  }
Beispiel #3
0
 private void hideEmulatorWindow() {
   int port =
       AndroidLogicUtils.getEmulatorPort(
           DDMSFacade.getSerialNumberByName(androidInstance.getName()));
   long windowHandle = NativeUIUtils.getWindowHandle(androidInstance.getName(), port);
   androidInstance.setWindowHandle(windowHandle);
   NativeUIUtils.hideWindow(windowHandle);
 }
Beispiel #4
0
  /**
   * Performs the skin draw operation.
   *
   * @param gcUsedToDraw The gc object associated with the skin composite that is used to draw the
   *     images
   */
  private void drawSkin(GC gcUsedToDraw, IAndroidKey changedKey) {
    if (currentSkinImage == null) {
      IAndroidEmulatorInstance instance = UIHelper.getInstanceAssociatedToControl(this);
      ImageData initialSkinImage = getImageData(false, false);
      setSkinImage(initialSkinImage, null, false);
      applyLayout(instance.getCurrentLayout());

      if (scrollBarsUsed) {
        synchronizeScrollBars();
      }
    }

    if (displayRectangle != null) {
      int srcXPos, srcYPos, srcWidth, srcHeight;
      int destXPos, destYPos, destWidth, destHeight;
      if (changedKey == null) {
        srcXPos = displayRectangle.x;
        srcYPos = displayRectangle.y;
        srcWidth = displayRectangle.width;
        srcHeight = displayRectangle.height;
        destXPos = 0;
        destYPos = 0;
        destWidth = Math.min(currentSkinImage.getImageData().width, displayRectangle.width);
        destHeight = Math.min(currentSkinImage.getImageData().height, displayRectangle.height);
      } else {
        srcXPos =
            ((int) (changedKey.getKeyArea().x > 0 ? changedKey.getKeyArea().x * zoomFactor : 0));
        srcYPos =
            ((int) (changedKey.getKeyArea().y > 0 ? changedKey.getKeyArea().y * zoomFactor : 0));
        srcWidth = ((int) (changedKey.getKeyArea().width * zoomFactor));
        srcHeight = ((int) (changedKey.getKeyArea().height * zoomFactor));
        destXPos = srcXPos - displayRectangle.x;
        destYPos = srcYPos - displayRectangle.y;
        destWidth = srcWidth;
        destHeight = srcHeight;
      }

      gcUsedToDraw.drawImage(
          currentSkinImage,
          srcXPos,
          srcYPos,
          srcWidth,
          srcHeight,
          destXPos,
          destYPos,
          destWidth,
          destHeight);
    }
  }
Beispiel #5
0
  /**
   * Retrieves an image data. If it has never been used at the current session, loads it from skin.
   * Released image is retrieved if both parameters are false.
   *
   * @param isPressed true if the image to be retrieved is the pressed image
   * @param isEnter true if the image to be retrieved is the enter image. It only has effect if
   *     isPressed == false
   * @return An image data containing the desired image pixels
   */
  private ImageData getImageData(boolean isPressed, boolean isEnter) {

    ImageData imageData = null;

    IAndroidEmulatorInstance instance = UIHelper.getInstanceAssociatedToControl(this);

    try {
      if (isPressed) {
        imageData = skin.getPressedImageData(instance.getCurrentLayout());

      } else {
        if (isEnter) {
          imageData = skin.getEnterImageData(instance.getCurrentLayout());

        } else {
          imageData = skin.getReleasedImageData(instance.getCurrentLayout());
        }
      }
    } catch (SkinException e) {
      error(
          "The image requested from skin could not be retrieved. isPressed="
              + isPressed
              + "; message="
              + e.getMessage());
      EclipseUtils.showErrorDialog(e);
      error("The skin could not provide an important resource. Stopping the instance");
      try {
        instance.stop(true);
      } catch (InstanceStopException e1) {
        error("Error while running service for stopping virtual machine");
        EclipseUtils.showErrorDialog(
            EmulatorNLS.GEN_Error, EmulatorNLS.EXC_General_CannotRunStopService);
      }
    }

    return imageData;
  }
Beispiel #6
0
  /**
   * Creates a SkinComposite This composite holds the screens in the correct positions and maps the
   * keys
   *
   * @param parent The parent composite in which the UI part of the instance shall be created
   * @param androidSkin The skin object that contain data for getting skin information
   */
  public SkinComposite(
      Composite parent, IAndroidSkin androidSkin, IAndroidEmulatorInstance instance) {
    super(parent, SWT.BACKGROUND | SWT.H_SCROLL | SWT.V_SCROLL);
    skin = androidSkin;
    androidInstance = instance;

    // Add listeners
    addListeners();
    createListenersForMainDisplay();

    setToolTipText(null);

    androidInput = instance.getInputLogic();

    // Init the scroll bars
    initScrollBars();

    if (!Platform.getOS().equals(Platform.OS_MACOSX)) {
      hideEmulatorWindow();
    }
  }