Exemplo n.º 1
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    // handle touching outside
    switch (event.getAction()) {
      case MotionEvent.ACTION_OUTSIDE:
        // unfocus window
        if (mContext.getFocusedWindow() == this) {
          mContext.unfocus(this);
        }

        // notify implementation that ACTION_OUTSIDE occurred
        mContext.onTouchBody(id, this, this, event);
        break;
    }

    // handle multitouch
    if (event.getPointerCount() >= 2
        && Utils.isSet(flags, StandOutFlags.FLAG_WINDOW_PINCH_RESIZE_ENABLE)) {
      // 2 fingers or more

      float x0 = event.getX(0);
      float y0 = event.getY(0);
      float x1 = event.getX(1);
      float y1 = event.getY(1);

      double dist = Math.sqrt(Math.pow(x0 - x1, 2) + Math.pow(y0 - y1, 2));

      switch (event.getAction() & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_MOVE:
          if (touchInfo.dist == -1) {
            touchInfo.dist = dist;
          }
          touchInfo.scale *= dist / touchInfo.dist;
          touchInfo.dist = dist;

          // scale the window with anchor point set to middle
          edit()
              .setAnchorPoint(.5f, .5f)
              .setSize(
                  (int) (touchInfo.firstWidth * touchInfo.scale),
                  (int) (touchInfo.firstHeight * touchInfo.scale))
              .commit();
          break;
      }
      mContext.onResize(id, this, this, event);
    }

    return true;
  }
Exemplo n.º 2
0
  @Override
  public boolean onInterceptTouchEvent(MotionEvent event) {
    StandOutLayoutParams params = getLayoutParams();

    // focus window
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
      if (mContext.getFocusedWindow() != this) {
        mContext.focus(id);
      }
    }

    // multitouch
    if (event.getPointerCount() >= 2
        && Utils.isSet(flags, StandOutFlags.FLAG_WINDOW_PINCH_RESIZE_ENABLE)
        && (event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_POINTER_DOWN) {
      touchInfo.scale = 1;
      touchInfo.dist = -1;
      touchInfo.firstWidth = params.width;
      touchInfo.firstHeight = params.height;
      return true;
    }

    return false;
  }
Exemplo n.º 3
0
  public Window(final StandOutWindow context, final int id) {
    super(context);
    context.setTheme(context.getThemeStyle());

    mContext = context;
    mLayoutInflater = LayoutInflater.from(context);

    this.cls = context.getClass();
    this.id = id;
    this.originalParams = context.getParams(id, this);
    this.flags = context.getFlags(id);
    this.touchInfo = new TouchInfo();
    touchInfo.ratio = (float) originalParams.width / originalParams.height;
    this.data = new Bundle();
    DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
    displayWidth = metrics.widthPixels;
    displayHeight = (int) (metrics.heightPixels - 25 * metrics.density);

    // create the window contents
    View content;
    FrameLayout body;

    if (Utils.isSet(flags, StandOutFlags.FLAG_DECORATION_SYSTEM)) {
      // requested system window decorations
      content = getSystemDecorations();
      body = (FrameLayout) content.findViewById(R.id.body);
    } else {
      // did not request decorations. will provide own implementation
      content = new FrameLayout(context);
      content.setId(R.id.content);
      body = (FrameLayout) content;
    }

    addView(content);

    body.setOnTouchListener(
        new OnTouchListener() {

          @Override
          public boolean onTouch(View v, MotionEvent event) {
            // pass all touch events to the implementation
            boolean consumed = false;

            // handle move and bring to front
            consumed = context.onTouchHandleMove(id, Window.this, v, event) || consumed;

            // alert implementation
            consumed = context.onTouchBody(id, Window.this, v, event) || consumed;

            return consumed;
          }
        });

    // attach the view corresponding to the id from the
    // implementation
    context.createAndAttachView(id, body);

    // make sure the implementation attached the view
    if (body.getChildCount() == 0) {
      throw new RuntimeException(
          "You must attach your view to the given frame in createAndAttachView()");
    }

    // implement StandOut specific workarounds
    if (!Utils.isSet(flags, StandOutFlags.FLAG_FIX_COMPATIBILITY_ALL_DISABLE)) {
      fixCompatibility(body);
    }
    // implement StandOut specific additional functionality
    if (!Utils.isSet(flags, StandOutFlags.FLAG_ADD_FUNCTIONALITY_ALL_DISABLE)) {
      addFunctionality(body);
    }

    // attach the existing tag from the frame to the window
    setTag(body.getTag());
  }