Beispiel #1
0
  /** Show popup mWindow */
  public void show(View anchor) {
    preShow();

    int[] location = new int[2];

    mDidAction = false;

    anchor.getLocationOnScreen(location);

    Rect anchorRect =
        new Rect(
            location[0],
            location[1],
            location[0] + anchor.getWidth(),
            location[1] + anchor.getHeight());

    // mRootView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
    // LayoutParams.WRAP_CONTENT));
    mRootView.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    int rootWidth = mRootView.getMeasuredWidth();
    int rootHeight = mRootView.getMeasuredHeight();

    int screenWidth = mWindowManager.getDefaultDisplay().getWidth();
    // int screenHeight 	= mWindowManager.getDefaultDisplay().getHeight();

    // int xPos 			= (screenWidth - rootWidth) / 2;
    int xPos = anchorRect.left;
    int yPos = anchorRect.top - rootHeight;

    boolean onTop = true;

    // display on bottom
    if (rootHeight > anchor.getTop()) {
      yPos = anchorRect.bottom;
      onTop = false;
    }

    showArrow(((onTop) ? R.id.arrow_down : R.id.arrow_up), anchorRect.centerX());

    setAnimationStyle(screenWidth, anchorRect.centerX(), onTop);

    mWindow.showAtLocation(anchor, Gravity.NO_GRAVITY, xPos, yPos);

    if (mAnimateTrack) mTrack.startAnimation(mTrackAnim);
  }
Beispiel #2
0
  /** Show quickaction popup. Popup is automatically positioned, on top or bottom of anchor view. */
  public void show(View anchor) {
    preShow();

    int xPos, yPos, arrowPos;

    mDidAction = false;

    int[] location = new int[2];

    anchor.getLocationOnScreen(location);

    Rect anchorRect =
        new Rect(
            location[0],
            location[1],
            location[0] + anchor.getWidth(),
            location[1] + anchor.getHeight());

    // mRootView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
    // LayoutParams.WRAP_CONTENT));

    mRootView.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    int rootHeight = mRootView.getMeasuredHeight();

    if (rootWidth == 0) {
      rootWidth = mRootView.getMeasuredWidth();
    }

    int screenWidth = mWindowManager.getDefaultDisplay().getWidth();
    int screenHeight = mWindowManager.getDefaultDisplay().getHeight();

    // automatically get X coord of popup (top left)
    if ((anchorRect.left + rootWidth) > screenWidth) {
      xPos = anchorRect.left - (rootWidth - anchor.getWidth());
      xPos = (xPos < 0) ? 0 : xPos;

      arrowPos = anchorRect.centerX() - xPos;

    } else {
      if (anchor.getWidth() > rootWidth) {
        xPos = anchorRect.centerX() - (rootWidth / 2);
      } else {
        xPos = anchorRect.left;
      }

      arrowPos = anchorRect.centerX() - xPos;
    }

    int dyTop = anchorRect.top;
    int dyBottom = screenHeight - anchorRect.bottom;

    boolean onTop = (dyTop > dyBottom) ? true : false;

    if (onTop) {
      if (rootHeight > dyTop) {
        yPos = 15;
        LayoutParams l = mScroller.getLayoutParams();
        l.height = dyTop - anchor.getHeight();
      } else {
        yPos = anchorRect.top - rootHeight;
      }
    } else {
      yPos = anchorRect.bottom;

      if (rootHeight > dyBottom) {
        LayoutParams l = mScroller.getLayoutParams();
        l.height = dyBottom;
      }
    }

    showArrow(((onTop) ? R.id.arrow_down : R.id.arrow_up), arrowPos);

    setAnimationStyle(screenWidth, anchorRect.centerX(), onTop);

    mWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    mWindow.showAtLocation(anchor, Gravity.NO_GRAVITY, xPos, yPos);
  }