Ejemplo n.º 1
0
    /**
     * Set the position of this window in absolute pixels. The window's top-left corner will be
     * positioned at the given x and y, unless you've set a different anchor point with {@link
     * #setAnchorPoint(float, float)}.
     *
     * <p>Changes will not applied until you {@link #commit()}.
     *
     * @param x
     * @param y
     * @param skip Don't call {@link #setPosition(int, int)} and {@link #setSize(int, int)} to avoid
     *     stack overflow.
     * @return The same Editor, useful for method chaining.
     */
    private Editor setPosition(int x, int y, boolean skip) {
      if (mParams != null) {
        if (anchorX < 0 || anchorX > 1 || anchorY < 0 || anchorY > 1) {
          throw new IllegalStateException("Anchor point must be between 0 and 1, inclusive.");
        }

        // sets the x and y correctly according to anchorX and
        // anchorY
        if (x != UNCHANGED) {
          mParams.x = (int) (x - mParams.width * anchorX);
        }
        if (y != UNCHANGED) {
          mParams.y = (int) (y - mParams.height * anchorY);
        }

        if (Utils.isSet(flags, StandOutFlags.FLAG_WINDOW_EDGE_LIMITS_ENABLE)) {
          // if gravity is not TOP|LEFT throw exception
          if (mParams.gravity != (Gravity.TOP | Gravity.LEFT)) {
            throw new IllegalStateException(
                "The window "
                    + id
                    + " gravity must be TOP|LEFT if FLAG_WINDOW_EDGE_LIMITS_ENABLE or FLAG_WINDOW_EDGE_TILE_ENABLE is set.");
          }

          // keep window inside edges
          //					mParams.x = Math.min(Math.max(mParams.x, 0), displayWidth - mParams.width);
          //					mParams.y = Math.min(Math.max(mParams.y, 0), displayHeight - mParams.height);
        }
      }

      return this;
    }