@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int width = MeasureSpec.getSize(widthMeasureSpec); int height = MeasureSpec.getSize(heightMeasureSpec); int widthWithoutPadding = width - mPaddingLeft - mPaddingRight; int heightWithoutPadding = height - mPaddingTop - mPaddingBottom; // Measure the content mContent.measure( MeasureSpec.makeMeasureSpec(widthWithoutPadding, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(widthWithoutPadding, MeasureSpec.EXACTLY)); // Measure the bar view, and action button mHeaderView.measure( MeasureSpec.makeMeasureSpec(widthWithoutPadding, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(mConfig.taskBarHeight, MeasureSpec.EXACTLY)); mActionButtonView.measure( MeasureSpec.makeMeasureSpec(widthWithoutPadding, MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(heightWithoutPadding, MeasureSpec.AT_MOST)); // Measure the thumbnail to be square mThumbnailView.measure( MeasureSpec.makeMeasureSpec(widthWithoutPadding, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(widthWithoutPadding, MeasureSpec.EXACTLY)); setMeasuredDimension(width, height); invalidateOutline(); }
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { long start = System.currentTimeMillis(); if (IS_LARGE) { setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), getPx(80)); } else { setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), getPx(68)); } // Logger.d(TAG, "onMeasure in " + (System.currentTimeMillis() - start) + " ms"); }
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // Try for a width based on our minimum int minw = getPaddingLeft() + getPaddingRight() + getSuggestedMinimumWidth(); int w = Math.max(minw, MeasureSpec.getSize(widthMeasureSpec)); // Whatever the width ends up being, ask for a height that would let the pie // get as big as it can int minh = (w - (int) mTextWidth) + getPaddingBottom() + getPaddingTop(); int h = Math.min(MeasureSpec.getSize(heightMeasureSpec), minh); setMeasuredDimension(w, h); }
private int measure(int measureSpec) { int result = 0; int specMode = MeasureSpec.getMode(measureSpec); int specSize = MeasureSpec.getSize(measureSpec); if (specMode == MeasureSpec.UNSPECIFIED) { result = 200; } else { result = specSize; } return result; }
private int measureHeight(int measureSpecHeight, int measureSpecWidth) { int result = 0; int specMode = MeasureSpec.getMode(measureSpecHeight); int specSize = MeasureSpec.getSize(measureSpecHeight); if (specMode == MeasureSpec.EXACTLY) { result = specSize; } else { result = viewHeight; } return (result + 2); }
private int measureWidth(int measureSpec) { int result = 0; int specMode = MeasureSpec.getMode(measureSpec); int specSize = MeasureSpec.getSize(measureSpec); if (specMode == MeasureSpec.EXACTLY) { result = specSize; } else { result = viewWidth; } return result; }
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { final int widthMode = MeasureSpec.getMode(widthMeasureSpec); final int heightMode = MeasureSpec.getMode(heightMeasureSpec); final int widthSize = MeasureSpec.getSize(widthMeasureSpec); final int heightSize = MeasureSpec.getSize(heightMeasureSpec); final int w; final int h; if (adapter != null) { this.rowCount = adapter.getRowCount(); this.columnCount = adapter.getColumnCount(); widths = new int[columnCount + 1]; for (int i = -1; i < columnCount; i++) { widths[i + 1] += adapter.getWidth(i); } heights = new int[rowCount + 1]; for (int i = -1; i < rowCount; i++) { heights[i + 1] += adapter.getHeight(i); } if (widthMode == MeasureSpec.AT_MOST) { w = Math.min(widthSize, sumArray(widths)); } else if (widthMode == MeasureSpec.UNSPECIFIED) { w = sumArray(widths); } else { w = widthSize; int sumArray = sumArray(widths); if (sumArray < widthSize) { final float factor = widthSize / (float) sumArray; for (int i = 1; i < widths.length; i++) { widths[i] = Math.round(widths[i] * factor); } widths[0] = widthSize - sumArray(widths, 1, widths.length - 1); } } if (heightMode == MeasureSpec.AT_MOST) { h = Math.min(heightSize, sumArray(heights)); } else if (heightMode == MeasureSpec.UNSPECIFIED) { h = sumArray(heights); } else { h = heightSize; } } else { if (heightMode == MeasureSpec.AT_MOST || widthMode == MeasureSpec.UNSPECIFIED) { w = 0; h = 0; } else { w = widthSize; h = heightSize; } } if (firstRow >= rowCount || getMaxScrollY() - getActualScrollY() < 0) { firstRow = 0; scrollY = Integer.MAX_VALUE; } if (firstColumn >= columnCount || getMaxScrollX() - getActualScrollX() < 0) { firstColumn = 0; scrollX = Integer.MAX_VALUE; } setMeasuredDimension(w, h); }
@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); if (mBitmap != null) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); // Bypasses a baffling bug when used within a ScrollView, where // heightSize is set to 0. if (heightSize == 0) heightSize = mBitmap.getHeight(); int desiredWidth; int desiredHeight; double viewToBitmapWidthRatio = Double.POSITIVE_INFINITY; double viewToBitmapHeightRatio = Double.POSITIVE_INFINITY; // Checks if either width or height needs to be fixed if (widthSize < mBitmap.getWidth()) { viewToBitmapWidthRatio = (double) widthSize / (double) mBitmap.getWidth(); } if (heightSize < mBitmap.getHeight()) { viewToBitmapHeightRatio = (double) heightSize / (double) mBitmap.getHeight(); } // If either needs to be fixed, choose smallest ratio and calculate // from there if (viewToBitmapWidthRatio != Double.POSITIVE_INFINITY || viewToBitmapHeightRatio != Double.POSITIVE_INFINITY) { if (viewToBitmapWidthRatio <= viewToBitmapHeightRatio) { desiredWidth = widthSize; desiredHeight = (int) (mBitmap.getHeight() * viewToBitmapWidthRatio); } else { desiredHeight = heightSize; desiredWidth = (int) (mBitmap.getWidth() * viewToBitmapHeightRatio); } } // Otherwise, the picture is within frame layout bounds. Desired // width is // simply picture size else { desiredWidth = mBitmap.getWidth(); desiredHeight = mBitmap.getHeight(); } int width = getOnMeasureSpec(widthMode, widthSize, desiredWidth); int height = getOnMeasureSpec(heightMode, heightSize, desiredHeight); mLayoutWidth = width; mLayoutHeight = height; final Rect bitmapRect = ImageViewUtil.getBitmapRectCenterInside( mBitmap.getWidth(), mBitmap.getHeight(), mLayoutWidth, mLayoutHeight); mCropOverlayView.setBitmapRect(bitmapRect); // MUST CALL THIS setMeasuredDimension(mLayoutWidth, mLayoutHeight); } else { mCropOverlayView.setBitmapRect(EMPTY_RECT); setMeasuredDimension(widthSize, heightSize); } }