当前位置: 首页>>代码示例>>Java>>正文


Java Rect.width方法代码示例

本文整理汇总了Java中android.graphics.Rect.width方法的典型用法代码示例。如果您正苦于以下问题:Java Rect.width方法的具体用法?Java Rect.width怎么用?Java Rect.width使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.graphics.Rect的用法示例。


在下文中一共展示了Rect.width方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: calcColorDistance

import android.graphics.Rect; //导入方法依赖的package包/类
/**
 * Calc color distance between average color in rect
 * and each pixel
 */
private int calcColorDistance(Rect rect) {
    int averageColor = averageColor(rect);
    int red = Color.red(averageColor);
    int green = Color.green(averageColor);
    int blue = Color.blue(averageColor);
    int colorSum = 0;

    // Calculates the distance
    for (int i = rect.left; i < rect.right; i++) {
        for (int j = rect.top; j < rect.bottom; j++) {
            int cellColor = pixelsBitmap[i][j];
            colorSum += Math.abs(red - Color.red(cellColor));
            colorSum += Math.abs(green - Color.green(cellColor));
            colorSum += Math.abs(blue - Color.blue(cellColor));
        }
    }

    // Calculates distance, and returns the result.
    return colorSum / (3 * (rect.width() * rect.height())); //divide by 3, because use R. G. B.
}
 
开发者ID:SlavaKyrai,项目名称:QuadTreeAndroid,代码行数:25,代码来源:QuadTreeSplitter.java

示例2: updateDragging

import android.graphics.Rect; //导入方法依赖的package包/类
private void updateDragging(MotionEvent ev) {
    setHotspot(ev.getX(), ev.getY());
    int x = (int) ev.getX();
    Rect oldBounds = mThumb.getBounds();
    int halfThumb = oldBounds.width() / 2;
    int addedThumb = mAddedTouchBounds;
    int newX = x - mDragOffset + halfThumb;
    int left = getPaddingLeft() + halfThumb + addedThumb;
    int right = getWidth() - (getPaddingRight() + halfThumb + addedThumb);
    if (newX < left) {
        newX = left;
    } else if (newX > right) {
        newX = right;
    }

    int available = right - left;
    float scale = (float) (newX - left) / (float) available;
    if (isRtl()) {
        scale = 1f - scale;
    }
    int progress = Math.round((scale * (mMax - mMin)) + mMin);
    setProgress(progress, true);
}
 
开发者ID:dmllr,项目名称:IdealMedia,代码行数:24,代码来源:DiscreteSeekBar.java

示例3: updateProgressFromAnimation

import android.graphics.Rect; //导入方法依赖的package包/类
private void updateProgressFromAnimation(float scale) {
    Rect bounds = mThumb.getBounds();
    int halfThumb = bounds.width() / 2;
    int addedThumb = mAddedTouchBounds;
    int left = getPaddingLeft() + halfThumb + addedThumb;
    int right = getWidth() - (getPaddingRight() + halfThumb + addedThumb);
    int available = right - left;
    int progress = Math.round((scale * (mMax - mMin)) + mMin);
    //we don't want to just call setProgress here to avoid the animation being cancelled,
    //and this position is not bound to a real progress value but interpolated
    if (progress != getProgress()) {
        mValue = progress;
        notifyProgress(mValue, true);
        updateProgressMessage(progress);
    }
    final int thumbPos = (int) (scale * available + 0.5f);
    updateThumbPos(thumbPos);
}
 
开发者ID:tranleduy2000,项目名称:screenfilter,代码行数:19,代码来源:DiscreteSeekBar.java

示例4: measureTextWidthHeight

import android.graphics.Rect; //导入方法依赖的package包/类
/**
 * 计算最大len的Text的宽高度
 */
private void measureTextWidthHeight() {
    Rect rect = new Rect();
    for (int i = 0; i < adapter.getItemsCount(); i++) {
        String s1 = getContentText(adapter.getItem(i));
        paintCenterText.getTextBounds(s1, 0, s1.length(), rect);
        int textWidth = rect.width();
        if (textWidth > maxTextWidth) {
            maxTextWidth = textWidth;
        }
        paintCenterText.getTextBounds("\u661F\u671F", 0, 2, rect); // 星期
        int textHeight = rect.height();
        if (textHeight > maxTextHeight) {
            maxTextHeight = textHeight;
        }
    }
    itemHeight = lineSpacingMultiplier * maxTextHeight;
}
 
开发者ID:crazysunj,项目名称:Android-PickerDialog,代码行数:21,代码来源:WheelView.java

示例5: draw

import android.graphics.Rect; //导入方法依赖的package包/类
@Override
public void draw(@NonNull Canvas canvas) {
    Rect bounds = getBounds();
    int width = bounds.width();
    int height = bounds.height();
    if (mPaint.getAlpha() == 0xFF) {
        canvas.save();
        canvas.translate(bounds.left-mStartX, bounds.top-mStartY);
        if (mPaths != null) {
            for (int i = 0; i < mPaths.size(); i++) {
                if (mColors != null && i < mColors.size()) {
                    mPaint.setColor(mColors.get(i));
                }
                canvas.drawPath(mPaths.get(i), mPaint);
            }
            mPaint.setAlpha(0xFF);
        }
        canvas.restore();
    } else {
        createCachedBitmapIfNeeded(width, height);
        if (!canReuseCache()) {
            updateCachedBitmap(width, height);
            updateCacheStates();
        }
        canvas.drawBitmap(mCachedBitmap, bounds.left, bounds.top, mPaint);
    }
}
 
开发者ID:scwang90,项目名称:SmartRefreshLayout,代码行数:28,代码来源:PathsDrawable.java

示例6: buildLuminanceSource

import android.graphics.Rect; //导入方法依赖的package包/类
/**
 * A factory method to build the appropriate LuminanceSource object based on the format
 * of the preview buffers, as described by Camera.Parameters.
 *
 * @param data   A preview frame.
 * @param width  The width of the image.
 * @param height The height of the image.
 * @return A PlanarYUVLuminanceSource instance.
 */
public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int height) {
    Rect rect = getFramingRectInPreview();
    if (rect == null) {
        return null;
    }
    // Go ahead and assume it's YUV rather than die.
    return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top,
        rect.width(), rect.height(), false);
}
 
开发者ID:crisfg86,项目名称:Zxing-Custom,代码行数:19,代码来源:CameraManager.java

示例7: buildLuminanceSource

import android.graphics.Rect; //导入方法依赖的package包/类
public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int height) {
    Rect rect = getFramingRectInPreview();
    int previewFormat = this.configManager.getPreviewFormat();
    String previewFormatString = this.configManager.getPreviewFormatString();
    switch (previewFormat) {
        case 16:
        case 17:
            return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top, rect.width(), rect.height());
        default:
            if ("yuv420p".equals(previewFormatString)) {
                return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top, rect.width(), rect.height());
            }
            throw new IllegalArgumentException("Unsupported picture format: " + previewFormat + LetvUtils.CHARACTER_BACKSLASH + previewFormatString);
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:16,代码来源:CameraManager.java

示例8: drawText

import android.graphics.Rect; //导入方法依赖的package包/类
private void drawText(Canvas canvas, String num, int i) {
	Rect mTextBound = new Rect();
	pswTextPaint.getTextBounds(num, 0, num.length(), mTextBound);
	Paint.FontMetrics fontMetrics = pswTextPaint.getFontMetrics();
	float textX = (float) ((i * (borderWidth + spacingWidth)) + (borderWidth / 2 - mTextBound.width() / 2) + (0.45 * spacingWidth));
	float textY = (height - fontMetrics.bottom + fontMetrics.top) / 2 - fontMetrics.top;
	if (saveResult != 0 || saveResult < result.size()) {
		canvas.drawText(num, textX, textY, pswTextPaint);
	}
}
 
开发者ID:rokudol,项目名称:PswText,代码行数:11,代码来源:PswText.java

示例9: onBoundsChange

import android.graphics.Rect; //导入方法依赖的package包/类
/**
 */
@Override
protected void onBoundsChange(Rect bounds) {
	super.onBoundsChange(bounds);
	this.mSize = bounds.width();
	this.updateOval();
}
 
开发者ID:universum-studios,项目名称:android_ui,代码行数:9,代码来源:CircularProgressDrawable.java

示例10: buildLuminanceSource

import android.graphics.Rect; //导入方法依赖的package包/类
/**
 * A factory method to build the appropriate LuminanceSource object based on
 * the format of the preview buffers, as described by Camera.Parameters.
 *
 * @param data   A preview frame.
 * @param width  The width of the image.
 * @param height The height of the image.
 * @return A PlanarYUVLuminanceSource instance.
 */
public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int height) {
    // 扫码区域大小,可以调整扫码区域大小
    Rect rect = activity.getCropRect();
    if (rect == null) {
        return null;
    }
    // Go ahead and assume it's YUV rather than die.
    return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top, rect.width(), rect
            .height(), false);
}
 
开发者ID:CardInfoLink,项目名称:QRScanner,代码行数:20,代码来源:DecodeHandler.java

示例11: onBoundsChange

import android.graphics.Rect; //导入方法依赖的package包/类
@Override protected void onBoundsChange(Rect bounds) {
  super.onBoundsChange(bounds);
  int height = bounds.height();
  int width = bounds.width();
  numRectanglesHorizontal = (int) Math.ceil((width / rectangleSize));
  numRectanglesVertical = (int) Math.ceil(height / rectangleSize);
  generatePatternBitmap();
}
 
开发者ID:Blankeer,项目名称:MDWechat,代码行数:9,代码来源:AlphaPatternDrawable.java

示例12: drawBorder

import android.graphics.Rect; //导入方法依赖的package包/类
private void drawBorder(Canvas canvas) {
    int[] headRect = new int[4];
    int[] bodyRect = new int[4];
    if(mHeadOrientation == HEAD_ORIENTATION_LEFT){
        headRect[0] = 0;
        headRect[1] = mHeight/4;
        headRect[2] = HEAD_WIDTH;
        headRect[3] = mHeight*3/4;

        bodyRect[0] = HEAD_WIDTH;
        bodyRect[1] = 0;
        bodyRect[2] = mWidth;
        bodyRect[3] = mHeight;
    }else if(mHeadOrientation == HEAD_ORIENTATION_RIGHT){
        headRect[0] = mWidth - HEAD_WIDTH;
        headRect[1] = mHeight/4;
        headRect[2] = mWidth;
        headRect[3] = mHeight*3/4;

        bodyRect[0] = 0;
        bodyRect[1] = 0;
        bodyRect[2] = mWidth - HEAD_WIDTH;
        bodyRect[3] = mHeight;
    }
    mBorderPaint.setStyle(Paint.Style.FILL);
    canvas.drawRect(new RectF(headRect[0],headRect[1],headRect[2],headRect[3]),mBorderPaint);
    mBorderPaint.setStyle(Paint.Style.STROKE);
    Rect rect = new Rect(bodyRect[0], bodyRect[1], bodyRect[2], bodyRect[3]);
    mBodyWidth = rect.width();
    canvas.drawRect(rect,mBorderPaint);
}
 
开发者ID:jiajunhui,项目名称:PlayerBase,代码行数:32,代码来源:BatteryView.java

示例13: cropBitmap

import android.graphics.Rect; //导入方法依赖的package包/类
/**
 * Crop image bitmap from URI by decoding it with specific width and height to down-sample if required.
 *
 * @param orgWidth used to get rectangle from points (handle edge cases to limit rectangle)
 * @param orgHeight used to get rectangle from points (handle edge cases to limit rectangle)
 * @param sampleMulti used to increase the sampling of the image to handle memory issues.
 */
private static BitmapSampled cropBitmap(Context context, Uri loadedImageUri, float[] points, int degreesRotated,
                                        int orgWidth, int orgHeight, boolean fixAspectRatio, int aspectRatioX, int aspectRatioY,
                                        int reqWidth, int reqHeight, boolean flipHorizontally, boolean flipVertically, int sampleMulti) {

    // get the rectangle in original image that contains the required cropped area (larger for non rectangular crop)
    Rect rect = getRectFromPoints(points, orgWidth, orgHeight, fixAspectRatio, aspectRatioX, aspectRatioY);

    int width = reqWidth > 0 ? reqWidth : rect.width();
    int height = reqHeight > 0 ? reqHeight : rect.height();

    Bitmap result = null;
    int sampleSize = 1;
    try {
        // decode only the required image from URI, optionally sub-sampling if reqWidth/reqHeight is given.
        BitmapSampled bitmapSampled = decodeSampledBitmapRegion(context, loadedImageUri, rect, width, height, sampleMulti);
        result = bitmapSampled.bitmap;
        sampleSize = bitmapSampled.sampleSize;
    } catch (Exception ignored) {
    }

    if (result != null) {
        try {
            // rotate the decoded region by the required amount
            result = rotateAndFlipBitmapInt(result, degreesRotated, flipHorizontally, flipVertically);

            // rotating by 0, 90, 180 or 270 degrees doesn't require extra cropping
            if (degreesRotated % 90 != 0) {

                // extra crop because non rectangular crop cannot be done directly on the image without rotating first
                result = cropForRotatedImage(result, points, rect, degreesRotated, fixAspectRatio, aspectRatioX, aspectRatioY);
            }
        } catch (OutOfMemoryError e) {
            if (result != null) {
                result.recycle();
            }
            throw e;
        }
        return new BitmapSampled(result, sampleSize);
    } else {
        // failed to decode region, may be skia issue, try full decode and then crop
        return cropBitmap(context, loadedImageUri, points, degreesRotated, fixAspectRatio, aspectRatioX, aspectRatioY, sampleMulti,
                rect, width, height, flipHorizontally, flipVertically);
    }
}
 
开发者ID:garretyoder,项目名称:Cluttr,代码行数:52,代码来源:BitmapUtils.java

示例14: getTextRect

import android.graphics.Rect; //导入方法依赖的package包/类
public void getTextRect(Context context, float scale, Rect outRect) {
    Paint textPaint = getPaint(context, scale, false);
    Paint outlineTextPaint = getPaint(context, scale, true);
    Paint.FontMetrics fontMetrics = textPaint.getFontMetrics();

    String[] text = preprocessText();

    float fullheight = 0, fullwidth = 0;
    float[] heightArray = new float[text.length];
    float[] widthArray = new float[text.length];

    for (int i = 0; i < text.length; i++) {
        Rect bounds = new Rect();
        if (outlineTextPaint != null) {
            outlineTextPaint.getTextBounds(text[i], 0, text[i].length(), bounds);
        } else {
            textPaint.getTextBounds(text[i], 0, text[i].length(), bounds);
        }

        widthArray[i] = bounds.width();
        heightArray[i] = fontMetrics.bottom - fontMetrics.top;

        if (i < text.length - 1) {
            heightArray[i] = heightArray[i] + (int) (heightArray[i] * (lineSpacing - 1));
        }

        fullheight += heightArray[i];
        fullwidth = fullwidth < widthArray[i] ? widthArray[i] : fullwidth;
    }

    fullwidth = fullwidth * 1.2f;
    fullheight = fullheight * 1.2f;

    float fullWidthDP = fullwidth / context.getResources().getDisplayMetrics().density;
    float fullHeightDP = fullheight / context.getResources().getDisplayMetrics().density;

    widthTextRatio = fullWidthDP / (textSize * scale);
    heightTextRatio = fullHeightDP / (textSize * scale);

    outRect.set(0, 0, (int) fullwidth, (int) fullheight);
}
 
开发者ID:monthlypub,项目名称:SmingZZick_App,代码行数:42,代码来源:TextMakingInfo.java

示例15: configureBounds

import android.graphics.Rect; //导入方法依赖的package包/类
/**
 * Determines bounds for the underlying drawable and a matrix that should be applied on it.
 * Adopted from android.widget.ImageView
 */
@VisibleForTesting void configureBounds() {
  Drawable underlyingDrawable = getCurrent();
  Rect bounds = getBounds();
  int viewWidth = bounds.width();
  int viewHeight = bounds.height();
  int underlyingWidth = mUnderlyingWidth = underlyingDrawable.getIntrinsicWidth();
  int underlyingHeight = mUnderlyingHeight = underlyingDrawable.getIntrinsicHeight();

  // If the drawable has no intrinsic size, we just fill our entire view.
  if (underlyingWidth <= 0 || underlyingHeight <= 0) {
    underlyingDrawable.setBounds(bounds);
    mDrawMatrix = null;
    return;
  }

  // If the drawable fits exactly, no transform needed.
  if (underlyingWidth == viewWidth && underlyingHeight == viewHeight) {
    underlyingDrawable.setBounds(bounds);
    mDrawMatrix = null;
    return;
  }

  // If we're told to scale to fit, we just fill our entire view.
  // (ScaleType.getTransform would do, but this is faster)
  if (mScaleType == ScaleType.FIT_XY) {
    underlyingDrawable.setBounds(bounds);
    mDrawMatrix = null;
    return;
  }

  // We need to do the scaling ourselves, so have the underlying drawable use its preferred size.
  underlyingDrawable.setBounds(0, 0, underlyingWidth, underlyingHeight);
  mScaleType.getTransform(
      mTempMatrix,
      bounds,
      underlyingWidth,
      underlyingHeight,
      (mFocusPoint != null) ? mFocusPoint.x : 0.5f,
      (mFocusPoint != null) ? mFocusPoint.y : 0.5f);
  mDrawMatrix = mTempMatrix;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:46,代码来源:ScaleTypeDrawable.java


注:本文中的android.graphics.Rect.width方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。