android.graphics.drawable.Drawable#copyBounds()源码实例Demo

下面列出了android.graphics.drawable.Drawable#copyBounds() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android_9.0.0_r45   文件: AbsSeekBar.java
@Override
void drawTrack(Canvas canvas) {
    final Drawable thumbDrawable = mThumb;
    if (thumbDrawable != null && mSplitTrack) {
        final Insets insets = thumbDrawable.getOpticalInsets();
        final Rect tempRect = mTempRect;
        thumbDrawable.copyBounds(tempRect);
        tempRect.offset(mPaddingLeft - mThumbOffset, mPaddingTop);
        tempRect.left += insets.left;
        tempRect.right -= insets.right;

        final int saveCount = canvas.save();
        canvas.clipRect(tempRect, Op.DIFFERENCE);
        super.drawTrack(canvas);
        drawTickMarks(canvas);
        canvas.restoreToCount(saveCount);
    } else {
        super.drawTrack(canvas);
        drawTickMarks(canvas);
    }
}
 
源代码2 项目: StockChart-MPAndroidChart   文件: Utils.java
public static void drawImage(Canvas canvas,
                             Drawable drawable,
                             int x, int y,
                             int width, int height) {

    MPPointF drawOffset = MPPointF.getInstance();
    drawOffset.x = x - (width / 2);
    drawOffset.y = y - (height / 2);

    drawable.copyBounds(mDrawableBoundsCache);
    drawable.setBounds(
            mDrawableBoundsCache.left,
            mDrawableBoundsCache.top,
            mDrawableBoundsCache.left + width,
            mDrawableBoundsCache.top + width);

    int saveId = canvas.save();
    // translate to the correct position and draw
    canvas.translate(drawOffset.x, drawOffset.y);
    drawable.draw(canvas);
    canvas.restoreToCount(saveId);
}
 
源代码3 项目: Ticket-Analysis   文件: Utils.java
public static void drawImage(Canvas canvas,
                             Drawable drawable,
                             int x, int y,
                             int width, int height) {

    MPPointF drawOffset = MPPointF.getInstance();
    drawOffset.x = x - (width / 2);
    drawOffset.y = y - (height / 2);

    drawable.copyBounds(mDrawableBoundsCache);
    drawable.setBounds(
            mDrawableBoundsCache.left,
            mDrawableBoundsCache.top,
            mDrawableBoundsCache.left + width,
            mDrawableBoundsCache.top + width);

    int saveId = canvas.save();
    // translate to the correct position and draw
    canvas.translate(drawOffset.x, drawOffset.y);
    drawable.draw(canvas);
    canvas.restoreToCount(saveId);
}
 
源代码4 项目: android-kline   文件: Utils.java
public static void drawImage(Canvas canvas,
                             Drawable drawable,
                             int x, int y,
                             int width, int height) {

    MPPointF drawOffset = MPPointF.getInstance();
    drawOffset.x = x - (width / 2);
    drawOffset.y = y - (height / 2);

    drawable.copyBounds(mDrawableBoundsCache);
    drawable.setBounds(
            mDrawableBoundsCache.left,
            mDrawableBoundsCache.top,
            mDrawableBoundsCache.left + width,
            mDrawableBoundsCache.top + width);

    int saveId = canvas.save();
    // translate to the correct position and draw
    canvas.translate(drawOffset.x, drawOffset.y);
    drawable.draw(canvas);
    canvas.restoreToCount(saveId);
}
 
源代码5 项目: osmdroid   文件: ItemizedOverlay.java
/**
 * @since 6.0.2
 */
protected boolean isEventOnItem(final Item pItem, final int pEventX, final int pEventY, final MapView pMapView) {
	if (pItem == null) {
		return false;
	}
	pMapView.getProjection().toPixels(pItem.getPoint(), mCurScreenCoords);
	final int state = (mDrawFocusedItem && (mFocusedItem == pItem) ? OverlayItem.ITEM_STATE_FOCUSED_MASK : 0);
	Drawable marker = pItem.getMarker(state);
	if (marker == null) {
		marker = getDefaultMarker(state);
	}
	boundToHotspot(marker, pItem.getMarkerHotspot());
	marker.copyBounds(mRect);
	mRect.offset(mCurScreenCoords.x, mCurScreenCoords.y);
	RectL.getBounds(mRect, mCurScreenCoords.x, mCurScreenCoords.y, -pMapView.getMapOrientation(), mOrientedMarkerRect);
	return mOrientedMarkerRect.contains(pEventX, pEventY);
}
 
源代码6 项目: android_9.0.0_r45   文件: WallpaperColors.java
/**
 * Constructs {@link WallpaperColors} from a drawable.
 * <p>
 * Main colors will be extracted from the drawable.
 *
 * @param drawable Source where to extract from.
 */
public static WallpaperColors fromDrawable(Drawable drawable) {
    if (drawable == null) {
        throw new IllegalArgumentException("Drawable cannot be null");
    }

    Rect initialBounds = drawable.copyBounds();
    int width = drawable.getIntrinsicWidth();
    int height = drawable.getIntrinsicHeight();

    // Some drawables do not have intrinsic dimensions
    if (width <= 0 || height <= 0) {
        width = MAX_BITMAP_SIZE;
        height = MAX_BITMAP_SIZE;
    }

    Size optimalSize = calculateOptimalSize(width, height);
    Bitmap bitmap = Bitmap.createBitmap(optimalSize.getWidth(), optimalSize.getHeight(),
            Bitmap.Config.ARGB_8888);
    final Canvas bmpCanvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
    drawable.draw(bmpCanvas);

    final WallpaperColors colors = WallpaperColors.fromBitmap(bitmap);
    bitmap.recycle();

    drawable.setBounds(initialBounds);
    return colors;
}
 
源代码7 项目: WhereYouGo   文件: RotationMarker.java
@Override
public synchronized boolean draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas,
                                 Point canvasPosition) {
    GeoPoint geoPoint = this.getGeoPoint();
    Drawable drawable = this.getDrawable();
    if (geoPoint == null || drawable == null) {
        return false;
    }

    double latitude = geoPoint.latitude;
    double longitude = geoPoint.longitude;
    int pixelX =
            (int) (MercatorProjection.longitudeToPixelX(longitude, zoomLevel) - canvasPosition.x);
    int pixelY =
            (int) (MercatorProjection.latitudeToPixelY(latitude, zoomLevel) - canvasPosition.y);

    Rect drawableBounds = drawable.copyBounds();
    int left = pixelX + drawableBounds.left;
    int top = pixelY + drawableBounds.top;
    int right = pixelX + drawableBounds.right;
    int bottom = pixelY + drawableBounds.bottom;

    if (!intersect(canvas, left, top, right, bottom)) {
        return false;
    }

    int saveCount = canvas.save();
    canvas.rotate(rotation, (float) pixelX, (float) pixelY);
    drawable.setBounds(left, top, right, bottom);
    drawable.draw(canvas);
    drawable.setBounds(drawableBounds);
    canvas.restoreToCount(saveCount);
    return true;
}
 
源代码8 项目: osmdroid   文件: ItemizedOverlay.java
/**
 * Draws an item located at the provided screen coordinates to the canvas.
 *
 * @param canvas
 *            what the item is drawn upon
 * @param item
 *            the item to be drawn
 * @param curScreenCoords
 * @param pProjection
 * @return true if the item was actually drawn
 */
protected boolean onDrawItem(final Canvas canvas, final Item item, final Point curScreenCoords,
		final Projection pProjection) {

	

	final int state = (mDrawFocusedItem && (mFocusedItem == item) ? OverlayItem.ITEM_STATE_FOCUSED_MASK
			: 0);
	final Drawable marker = (item.getMarker(state) == null) ? getDefaultMarker(state) : item
			.getMarker(state);
	final HotspotPlace hotspot = item.getMarkerHotspot();

	boundToHotspot(marker, hotspot);

	int x = mCurScreenCoords.x;
	int y = mCurScreenCoords.y;

	marker.copyBounds(mRect);
	mMarkerRect.set(mRect);
	mRect.offset(x, y);
	RectL.getBounds(mRect, x, y, pProjection.getOrientation(), mOrientedMarkerRect);
	final boolean displayed = Rect.intersects(mOrientedMarkerRect, canvas.getClipBounds());
	if (displayed) {
		if (pProjection.getOrientation() != 0) { // optimization: step 1/2
			canvas.save();
			canvas.rotate(-pProjection.getOrientation(), x, y);
		}
		marker.setBounds(mRect);
		marker.draw(canvas);
		if (pProjection.getOrientation() != 0) { // optimization: step 2/2
			canvas.restore();
		}
		marker.setBounds(mMarkerRect);
	}

	return displayed;
}
 
源代码9 项目: LaunchEnr   文件: DragPreviewProvider.java
protected static Rect getDrawableBounds(Drawable d) {
    Rect bounds = new Rect();
    d.copyBounds(bounds);
    if (bounds.width() == 0 || bounds.height() == 0) {
        bounds.set(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
    } else {
        bounds.offsetTo(0, 0);
    }
    return bounds;
}
 
源代码10 项目: Trebuchet   文件: Workspace.java
private static Rect getDrawableBounds(Drawable d) {
    Rect bounds = new Rect();
    d.copyBounds(bounds);
    if (bounds.width() == 0 || bounds.height() == 0) {
        bounds.set(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
    } else {
        bounds.offsetTo(0, 0);
    }
    if (d instanceof PreloadIconDrawable) {
        int inset = -((PreloadIconDrawable) d).getOutset();
        bounds.inset(inset, inset);
    }
    return bounds;
}
 
源代码11 项目: AlbumSelector   文件: CropView.java
public Bitmap asBitmap(Drawable drawable, int minWidth, int minHeight) {
    final Rect tmpRect = new Rect();
    drawable.copyBounds(tmpRect);
    if (tmpRect.isEmpty()) {
        tmpRect.set(0, 0, Math.max(minWidth, drawable.getIntrinsicWidth()), Math.max(minHeight, drawable.getIntrinsicHeight()));
        drawable.setBounds(tmpRect);
    }
    Bitmap bitmap = Bitmap.createBitmap(tmpRect.width(), tmpRect.height(), Bitmap.Config.ARGB_8888);
    drawable.draw(new Canvas(bitmap));
    return bitmap;
}
 
源代码12 项目: TurboLauncher   文件: WidgetPreviewLoader.java
private static void renderDrawableToBitmap(
        Drawable d, Bitmap bitmap, int x, int y, int w, int h,
        float scale) {
    if (bitmap != null) {
        Canvas c = new Canvas(bitmap);
        c.scale(scale, scale);
        Rect oldBounds = d.copyBounds();
        d.setBounds(x, y, x + w, y + h);
        d.draw(c);
        d.setBounds(oldBounds); // Restore the bounds
        c.setBitmap(null);
    }
}
 
源代码13 项目: TabletClock   文件: ColorDialog.java
@Override
public void onClick(View v) {
	Drawable d = v.getBackground();
	Bitmap bmp;
	Canvas c = new Canvas(bmp = Bitmap.createBitmap(1, 1,
			Bitmap.Config.ARGB_8888));
	Rect oldRect = d.copyBounds();
	d.setBounds(0, 0, 1, 1);
	d.draw(c);
	d.setBounds(oldRect);

	setSeekColor(bmp.getPixel(0, 0));
}
 
源代码14 项目: scissors   文件: Utils.java
public static Bitmap asBitmap(Drawable drawable, int minWidth, int minHeight) {
    final Rect tmpRect = new Rect();
    drawable.copyBounds(tmpRect);
    if (tmpRect.isEmpty()) {
        tmpRect.set(0, 0, Math.max(minWidth, drawable.getIntrinsicWidth()), Math.max(minHeight, drawable.getIntrinsicHeight()));
        drawable.setBounds(tmpRect);
    }
    Bitmap bitmap = Bitmap.createBitmap(tmpRect.width(), tmpRect.height(), Bitmap.Config.ARGB_8888);
    drawable.draw(new Canvas(bitmap));
    return bitmap;
}
 
源代码15 项目: LB-Launcher   文件: WidgetPreviewLoader.java
private static void renderDrawableToBitmap(
        Drawable d, Bitmap bitmap, int x, int y, int w, int h) {
    if (bitmap != null) {
        Canvas c = new Canvas(bitmap);
        Rect oldBounds = d.copyBounds();
        d.setBounds(x, y, x + w, y + h);
        d.draw(c);
        d.setBounds(oldBounds); // Restore the bounds
        c.setBitmap(null);
    }
}
 
源代码16 项目: osmdroid   文件: Overlay.java
/**
 * Convenience method to draw a Drawable at an offset. x and y are pixel coordinates. You can
 * find appropriate coordinates from latitude/longitude using the MapView.getProjection() method
 * on the MapView passed to you in draw(Canvas, MapView, boolean).
 *
 * @param shadow
 *            If true, draw only the drawable's shadow. Otherwise, draw the drawable itself.
 * @param aMapOrientation
 */
protected synchronized static void drawAt(final Canvas canvas, final Drawable drawable,
										  final int x, final int y, final boolean shadow,
										  final float aMapOrientation) {
	canvas.save();
	canvas.rotate(-aMapOrientation, x, y);
	drawable.copyBounds(mRect);
	drawable.setBounds(mRect.left + x, mRect.top + y, mRect.right + x, mRect.bottom + y);
	drawable.draw(canvas);
	drawable.setBounds(mRect);
	canvas.restore();
}
 
源代码17 项目: scene   文件: AbsoluteChangeBounds.java
@Override
public void set(Drawable object, PointF value) {
    object.copyBounds(mBounds);
    mBounds.offsetTo(Math.round(value.x), Math.round(value.y));
    object.setBounds(mBounds);
}
 
源代码18 项目: scene   文件: AbsoluteChangeBounds.java
@Override
public PointF get(Drawable object) {
    object.copyBounds(mBounds);
    return new PointF(mBounds.left, mBounds.top);
}
 
源代码19 项目: android_9.0.0_r45   文件: ChangeBounds.java
@Override
public void set(Drawable object, PointF value) {
    object.copyBounds(mBounds);
    mBounds.offsetTo(Math.round(value.x), Math.round(value.y));
    object.setBounds(mBounds);
}
 
源代码20 项目: android_9.0.0_r45   文件: ChangeBounds.java
@Override
public PointF get(Drawable object) {
    object.copyBounds(mBounds);
    return new PointF(mBounds.left, mBounds.top);
}