Exemplo n.º 1
0
  @Override
  protected void onMeasure(int widthSpec, int heightSpec) {
    int previewWidth = MeasureSpec.getSize(widthSpec);
    int previewHeight = MeasureSpec.getSize(heightSpec);

    // Get the padding of the border background.
    int hPadding = mPaddingLeft + mPaddingRight;
    int vPadding = mPaddingTop + mPaddingBottom;

    // Resize the preview frame with correct aspect ratio.
    previewWidth -= hPadding;
    previewHeight -= vPadding;
    if (previewWidth > previewHeight * mAspectRatio) {
      previewWidth = (int) (previewHeight * mAspectRatio + .5);
    } else {
      previewHeight = (int) (previewWidth / mAspectRatio + .5);
    }

    // Add the padding of the border.
    previewWidth += hPadding;
    previewHeight += vPadding;

    // Ask children to follow the new preview dimension.
    super.onMeasure(
        MeasureSpec.makeMeasureSpec(previewWidth, MeasureSpec.EXACTLY),
        MeasureSpec.makeMeasureSpec(previewHeight, MeasureSpec.EXACTLY));
  }
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    width = getMeasuredWidth();
    height = getMeasuredHeight();
  }
Exemplo n.º 3
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

    setMeasuredDimension(getDefaultSize(0, widthMeasureSpec), getDefaultSize(0, heightMeasureSpec));

    int childWidthSize = getMeasuredWidth();
    int childHeightSize = getMeasuredHeight();

    int tempSize;
    if (childWidthSize == 0 || childHeightSize == 0) {
      if (childWidthSize != 0) {
        tempSize = childWidthSize;
      } else if (childHeightSize != 0) {
        tempSize = childHeightSize;
      } else {
        tempSize = 0;
      }
    } else {
      tempSize = Math.min(childWidthSize, childHeightSize);
    }

    if (tempSize != 0) {
      heightMeasureSpec =
          widthMeasureSpec = MeasureSpec.makeMeasureSpec(tempSize, MeasureSpec.EXACTLY);
    }
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  }
Exemplo n.º 4
0
  @SuppressWarnings("unused")
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

    // For simple implementation, or internal size is always 0.

    // We depend on the container to specify the layout size of

    // our view. We can't really know what it is since we will be

    // adding and removing different arbitrary views and do not

    // want the layout to change as this happens.

    setMeasuredDimension(getDefaultSize(0, widthMeasureSpec), getDefaultSize(0, heightMeasureSpec));

    // Children are just made to fill our space.

    int childWidthSize = getMeasuredWidth();
    int childHeightSize = getMeasuredHeight();

    heightMeasureSpec =
        widthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidthSize, MeasureSpec.EXACTLY);

    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  }
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    parentWidth = (int) (MeasureSpec.getSize(widthMeasureSpec));
    parentHeight = (int) (MeasureSpec.getSize(heightMeasureSpec));
    startX = (parentWidth - button.getWidth()) / 2;
    startY = (parentHeight - button.getHeight()) / 2;
  }
Exemplo n.º 6
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    setMeasuredDimension(getDefaultSize(0, widthMeasureSpec), getDefaultSize(0, heightMeasureSpec));

    int childWidthSize = getMeasuredWidth();

    heightMeasureSpec =
        widthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidthSize, MeasureSpec.EXACTLY);
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  }
Exemplo n.º 7
0
 @Override
 /**
  * Determines where in the ActionBar various views should go. Gives priority to HIGH Priority
  * buttons, then the title, then LOW Priority buttons. If the title won't fit, force it to by
  * cutting off excess. If any buttons won't fit, move them to the OverflowMenu. *
  */
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
   super.onMeasure(widthMeasureSpec, heightMeasureSpec);
   if (mLayoutFinished && mNeedsLayout) {
     mController.onMeasure(
         mControllerContainer.getMeasuredWidth(), mControllerContainer.getMeasuredHeight());
     mNeedsLayout = false;
   }
 }
Exemplo n.º 8
0
  @SuppressWarnings("unused")
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

    setMeasuredDimension(getDefaultSize(0, widthMeasureSpec), getDefaultSize(0, heightMeasureSpec));

    // Children are just made to fill our space.
    int childWidthSize = getMeasuredWidth();
    int childHeightSize = getMeasuredHeight();
    // 高度和宽度一样
    heightMeasureSpec =
        widthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidthSize, MeasureSpec.EXACTLY);
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  }
 /** Set our margins and title area height proportionally to the available display size */
 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
   int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
   int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
   final Resources resources = getContext().getResources();
   float titleHeight = resources.getFraction(R.dimen.setup_title_height, 1, 1);
   float sideMargin = resources.getFraction(R.dimen.setup_border_width, 1, 1);
   int bottom = resources.getDimensionPixelSize(R.dimen.setup_margin_bottom);
   setPaddingRelative(
       (int) (parentWidth * sideMargin), 0, (int) (parentWidth * sideMargin), bottom);
   View title = findViewById(R.id.title_area);
   if (title != null) {
     title.setMinimumHeight((int) (parentHeight * titleHeight));
   }
   super.onMeasure(widthMeasureSpec, heightMeasureSpec);
 }
Exemplo n.º 10
0
  /**
   * ***********************************
   *
   * <p>ActionsCode(author:hexibin, change_code)
   */
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    // ActionsCode(hexibin, bugfix BUG00297099)
    if (mIsFixedTitleBar && mShowing) {
      int margin = getMeasuredHeight() - calculateEmbeddedHeight();
      mBaseUi.setContentViewMarginTop(-margin);
    } else {
      mBaseUi.setContentViewMarginTop(0);
    }

    // ActionsCode(hexibin, bugfix BUG00297099)
    if (!mShowing) {
      setMeasuredDimension(0, 0);
    }
  }
  /** 1.根据父类传入参数获取宽高 2.初始化每个子View的宽度,以及笔触宽度 3.初始化新建所有子View,设定ID,设置布局参数,设置模式,添加View */
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    mWidth = MeasureSpec.getSize(widthMeasureSpec);
    mHeight = MeasureSpec.getSize(heightMeasureSpec);
    mHeight = mWidth = mWidth < mHeight ? mWidth : mHeight;
    mGestureLockViewWidth = (int) (4 * mWidth * 1.0f / (5 * mCount + 1));
    mMarginBetweenLockView = (int) (mGestureLockViewWidth * 0.25);
    mPaint.setStrokeWidth(mGestureLockViewWidth * 0.29f);

    if (mGestureLockViews == null) {
      mGestureLockViews = new GestureLockView[mCount * mCount];
      for (int i = 0; i < mGestureLockViews.length; i++) {
        mGestureLockViews[i] =
            new GestureLockView(
                this.getContext(),
                mNoFingerInnerCircleColor,
                mNoFingerOuterCircleColor,
                mFingerOnColor,
                mFingerUpColor);
        mGestureLockViews[i].setId(i + 1);
        RelativeLayout.LayoutParams layoutParams =
            new RelativeLayout.LayoutParams(mGestureLockViewWidth, mGestureLockViewWidth);
        if (i % mCount != 0) { // 不是第一列的元素都排放在上个元素的右边
          layoutParams.addRule(RIGHT_OF, mGestureLockViews[i - 1].getId());
        }
        if (i > mCount - 1) { // 从第二行开始,设置为上一个对应元素的下面
          layoutParams.addRule(BELOW, mGestureLockViews[i - mCount].getId());
        }
        int rightMargin = mMarginBetweenLockView; // 其他view都存在右下间隔参数
        int bottomMargin = mMarginBetweenLockView;
        int topMargin = 0;
        int leftMargin = 0;

        if (i >= 0 && i < mCount) { // 第一行,存在topMargin
          topMargin = mMarginBetweenLockView;
        }
        if (i % mCount == 0) { // 第一列存在leftMargin
          leftMargin = mMarginBetweenLockView;
        }
        layoutParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);
        mGestureLockViews[i].setCurrentMode(GestureLockView.Mode.STATUS_NO_FINGER);
        addView(mGestureLockViews[i], layoutParams);
      }
    }
  }
Exemplo n.º 12
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    int w = getMeasuredWidth();
    int h = getMeasuredHeight();
    mHeaderHeight = mHeaderContainer.getMeasuredHeight();

    if (DEBUG) {
      Log.d(
          LOG_TAG,
          String.format(
              "onMeasure %s getMeasuredHeight: %s", h, mHeaderContainer.getMeasuredHeight()));
    }

    mContentViewContainer.measure(
        MeasureSpec.makeMeasureSpec(w, MeasureSpec.EXACTLY),
        MeasureSpec.makeMeasureSpec(h, MeasureSpec.AT_MOST));
  }
 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
   if (getContext() instanceof Activity) {
     int height = MeasureSpec.getSize(heightMeasureSpec);
     Activity activity = (Activity) getContext();
     Rect rect = new Rect();
     Window wd = activity.getWindow();
     wd.getDecorView().getWindowVisibleDisplayFrame(rect);
     int statusBarHeight = rect.top;
     int screenHeight = DisplayUtils.getScreenHeight(getContext());
     int diff = (screenHeight - statusBarHeight) - height;
     boolean isShowing = diff > 128;
     if (listener != null) {
       listener.onSoftKeyboardShown(isShowing); // 一般软键盘高度至少大于128px
     }
   }
   super.onMeasure(widthMeasureSpec, heightMeasureSpec);
 }
Exemplo n.º 14
0
	@Override
	public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);

		int widthMode = MeasureSpec.getMode(widthMeasureSpec);
		int heightMode = MeasureSpec.getMode(heightMeasureSpec);

		int tmpWidth = widthMeasureSpec;
		int tmpHeight = heightMeasureSpec;

		if (widthMode == MeasureSpec.AT_MOST)
			tmpWidth = 200;

		if (heightMode == MeasureSpec.AT_MOST)
			tmpHeight = 100;

		setMeasuredDimension(tmpWidth, tmpHeight);
	}
Exemplo n.º 15
0
  /** 测量Layout的宽和高,以及设置Item的宽和高,这里忽略wrap_content 以宽、高之中的最小值绘制正方形 */
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    // 获得正方形的边长
    int length = Math.min(getMeasuredHeight(), getMeasuredWidth());
    // 获得Item的宽度
    int childWidth = (length - mPadding * 2 - mMargin * (mColumn - 1)) / mColumn;

    if (!once) {
      if (mGame2048Items == null) {
        mGame2048Items = new Game2048Item[mColumn * mColumn];
      }
      // 放置Item
      for (int i = 0; i < mGame2048Items.length; i++) {
        Game2048Item item = new Game2048Item(getContext());

        mGame2048Items[i] = item;
        item.setId(i + 1);
        RelativeLayout.LayoutParams lp = new LayoutParams(childWidth, childWidth);
        // 设置横向边距,不是最后一列
        if ((i + 1) % mColumn != 0) {
          lp.rightMargin = mMargin;
        }
        // 如果不是第一列
        if (i % mColumn != 0) {
          lp.addRule(
              RelativeLayout.RIGHT_OF, //
              mGame2048Items[i - 1].getId());
        }
        // 如果不是第一行,//设置纵向边距,非最后一行
        if ((i + 1) > mColumn) {
          lp.topMargin = mMargin;
          lp.addRule(
              RelativeLayout.BELOW, //
              mGame2048Items[i - mColumn].getId());
        }
        addView(item, lp);
      }
      generateNum();
    }
    once = true;

    setMeasuredDimension(length, length);
  }
Exemplo n.º 16
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    int widthSize = MeasureSpec.getSize(widthMeasureSpec);
    int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    int heightSize = MeasureSpec.getSize(heightMeasureSpec);

    int size;
    if (widthMode == MeasureSpec.EXACTLY && widthSize > 0) {
      size = widthSize;
    } else if (heightMode == MeasureSpec.EXACTLY && heightSize > 0) {
      size = heightSize;
    } else {
      size = widthSize < heightSize ? widthSize : heightSize;
    }

    int finalMeasureSpec = MeasureSpec.makeMeasureSpec(size, MeasureSpec.EXACTLY);
    super.onMeasure(finalMeasureSpec, finalMeasureSpec);
  }
Exemplo n.º 17
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    viewWidth = getMeasuredWidth();
    viewHeight = getMeasuredHeight();

    int count = getChildCount();
    if (count > 0) {
      firstView = getChildAt(0);
      firstViewTop = firstView.getTop();
      firstViewHeight = firstView.getMeasuredHeight();
      if (firstView instanceof ScrollView) {
        firstViewMaxHeight = ((ScrollView) firstView).getChildAt(0).getMeasuredHeight();
      } else {
        firstViewMaxHeight = firstViewHeight;
      }
    }
    if (count > 1) {
      secondView = getChildAt(1);
    }
  }
  @Override
  /**
   * 监听measurement事件,根据view的高度判断软键盘是否弹出
   *
   * @param widthMeasureSpec
   * @param heightMeasureSpec
   */
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    int width, height;

    height = MeasureSpec.getSize(heightMeasureSpec);
    width = MeasureSpec.getSize(widthMeasureSpec);

    // 初始状态
    if (mOldHeight == 0 || mOldHeight == height) {
      XLog.d(CLASS_NAME, "Ignore this event");
    }
    // 转屏
    else if (mScreenHeight == width) {
      int tmp_var = mScreenHeight;
      mScreenHeight = mScreenWidth;
      mScreenWidth = tmp_var;
      XLog.i(CLASS_NAME, "Orientation Change");
    }
    // 软键盘隐藏了
    else if (height > mOldHeight) {
      XLog.i(CLASS_NAME, "Soft Keyboard Hidden");
      mCurrentSysTimeWhenSoftKeyboardHidden = System.currentTimeMillis();
    }

    // 软键盘弹出
    else if (height < mOldHeight) {
      XLog.i(CLASS_NAME, "Soft Keyboard Shown");
    }
    mOldHeight = height;
    mOldWidth = width;
  }
Exemplo n.º 19
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int oldHeight = getMeasuredHeight();
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    int newHeight = getMeasuredHeight();

    if (!mAnimating && oldHeight != 0 && oldHeight != newHeight) {
      mAnimating = true;
      setMeasuredDimension(getMeasuredWidth(), oldHeight);

      // Animate the difference of suggestion row height
      Animation anim = new HeightChangeAnimation(this, oldHeight, newHeight);
      anim.setDuration(ANIMATION_DURATION);
      anim.setInterpolator(new DecelerateInterpolator());
      anim.setAnimationListener(
          new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {}

            @Override
            public void onAnimationRepeat(Animation animation) {}

            @Override
            public void onAnimationEnd(Animation animation) {
              post(
                  new Runnable() {
                    @Override
                    public void run() {
                      finishAnimation();
                    }
                  });
            }
          });
      startAnimation(anim);
    }
  }
Exemplo n.º 20
0
 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
   super.onMeasure(widthMeasureSpec, heightMeasureSpec);
 }
 protected void onMeasure(int paramInt1, int paramInt2) {
   super.onMeasure(paramInt1, paramInt1);
 }
 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
   if (!isInEditMode()) mHelper.adjustChildren();
   super.onMeasure(widthMeasureSpec, heightMeasureSpec);
 }