本文整理汇总了Java中android.graphics.Rect.offsetTo方法的典型用法代码示例。如果您正苦于以下问题:Java Rect.offsetTo方法的具体用法?Java Rect.offsetTo怎么用?Java Rect.offsetTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.Rect
的用法示例。
在下文中一共展示了Rect.offsetTo方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawOnCanvas
import android.graphics.Rect; //导入方法依赖的package包/类
public void drawOnCanvas(ToDraw actual, Canvas canvas) {
//this gets the source rectangle. trust my strange calculations :P
Rect source = new Rect(-Math.min(actual.getX(), 0), -Math.min(0, actual.getY()), actual.getWidth(), actual.getHeight());
//this gets the destination of the rectangle
Rect destination = new Rect(source);
destination.offsetTo(Math.max(actual.getX(), 0), Math.max(actual.getY(), 0));
// Picture pic = new Picture();
// Canvas tempc = pic.beginRecording(width, height);
// tempc.rotate(-30, destination.centerX(),destination.centerY());
// tempc.drawBitmap(actual.getTexture(),0,0,p);
// tempc.drawBitmap(actual.getTexture(), source, destination, p);
//tempc.rotate(30, destination.centerX(),destination.centerY());
//pic.endRecording();
//pic.draw(canvas);
canvas.drawBitmap(actual.getTexture(), source, destination, p);
}
示例2: getDrawableBounds
import android.graphics.Rect; //导入方法依赖的package包/类
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;
}
示例3: scrollToPage
import android.graphics.Rect; //导入方法依赖的package包/类
public void scrollToPage(int pageNumber)
{
// scroll to bring the page into view
int scrollTime = 400;
// get current viewport
Rect viewport = new Rect();
getGlobalVisibleRect(viewport);
// offset it based on current scroll position
Point viewportOrigin = new Point();
viewportOrigin.set(getScrollX(), getScrollY());
viewport.offsetTo(viewportOrigin.x, viewportOrigin.y);
// get page rect from last layout
DocPageView cv = (DocPageView) getOrCreateChild(pageNumber);
Rect childRect = cv.getChildRect();
// scroll
if ((childRect.height()) > viewport.height())
{
// put the top of the page at the top and the left at 0
smoothScrollBy(getScrollX(), getScrollY() - childRect.top, scrollTime);
}
else
{
// if the whole page is not visible, move the center of the page at the center
if (childRect.top < viewport.top || childRect.bottom > viewport.bottom)
{
if (childRect.top == 0)
smoothScrollBy(0, getScrollY(), scrollTime);
else
smoothScrollBy(0, getScrollY() + viewport.height() / 2 - (childRect.bottom + childRect.top) / 2, scrollTime);
}
}
}
示例4: onDraw
import android.graphics.Rect; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
Canvas c = canvas;
if (mExternalSurface != null) {
try {
Rect r = new Rect();
r = canvas.getClipBounds();
int [] location = new int[2];
getLocationOnScreen(location);
r.offsetTo(location[0],location[1]);
// Log.d(TAG, "Spacer "+r.toString());
c = mExternalSurface.lockCanvas(null);
c.save();
c.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
c.clipRect(r);
c.translate(location[0],location[1]);
if (mBackground != null)
mBackground.draw(c);
} catch (Exception e) {
}
}
super.onDraw(c);
if (c != canvas) {
c.restore();
mExternalSurface.unlockCanvasAndPost(c);
}
}
示例5: onDraw
import android.graphics.Rect; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
if (mBitmap != null) {
Canvas c = canvas;
if (mExternalSurface != null) {
try {
Rect r = new Rect();
r = canvas.getClipBounds();
int [] location = new int[2];
getLocationOnScreen(location);
r.offsetTo(location[0],location[1]);
c = mExternalSurface.lockCanvas(null);
c.save();
c.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
c.clipRect(r);
c.translate(location[0],location[1]);
} catch (Exception e) {
Log.d(TAG, "Can not lock canvas!!!!");
}
}
Bitmap draw = Bitmap.createScaledBitmap(mBitmap, mDrawWidth, mDrawHeight, true);
c.drawBitmap(draw, mDrawX, 0, mPaint);
draw.recycle();
if (c != canvas) {
c.restore();
mExternalSurface.unlockCanvasAndPost(c);
}
}
}
示例6: drawTo
import android.graphics.Rect; //导入方法依赖的package包/类
@Override
public void drawTo(Canvas drawCanvas, float left, float top, Paint paint, boolean onlyDirty) {
final Rect src = new Rect(0, 0, mTileSize, mTileSize);
final Rect dst = new Rect(0, 0, mTileSize, mTileSize);
drawCanvas.save();
drawCanvas.translate(-left, -top);
drawCanvas.clipRect(0, 0, mWidth, mHeight);
for (int j=0; j<mTilesY; j++) {
for (int i=0; i<mTilesX; i++) {
dst.offsetTo(i*mTileSize, j*mTileSize);
final int p = j * mTilesX + i;
final Tile tile = mTiles[p];
if (!onlyDirty || tile.dirty) {
drawCanvas.drawBitmap(tile.getBitmap(), src, dst, paint);
tile.dirty = false;
if (mDebug) {
mDrawCount++;
dbgPaint.setColor(DEBUG_COLORS[tile.top % DEBUG_COLORS.length]);
//drawCanvas.drawRect(dst, (mDrawCount % 2 == 0) ? dbgPaint1 : dbgPaint2);
drawCanvas.drawRect(dst, dbgPaint);
//drawCanvas.drawRect(dst, dbgStroke);
drawCanvas.drawText(
String.format("%d,%d v%d", tile.x, tile.y, tile.top),
dst.left + 4, dst.bottom - 4, dbgTextPaint);
}
}
}
}
drawCanvas.restore();
}
示例7: getDrawableBounds
import android.graphics.Rect; //导入方法依赖的package包/类
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);
}
if (d instanceof PreloadIconDrawable) {
int inset = -((PreloadIconDrawable) d).getOutset();
bounds.inset(inset, inset);
}
return bounds;
}
示例8: onDraw
import android.graphics.Rect; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
final int width = getWidth();
final int height = getHeight();
final int sideLength = generateSideLength();
BoxBody body = generateBoxBody(width, height, sideLength);
mPaint.setColor(ColorUtils.setAlphaComponent(mAccentColor, 150));
canvas.drawPath(generateBoxBodyPath(body), mPaint);
mPaint.setColor(mAccentColor);
canvas.drawPath(generateBoxCoverPath(body), mPaint);
if (isInEditMode()) {
mDropOutPercent = 2.5f;
}
if (mDropOutPercent > 0) {
canvas.clipPath(generateClipPath(body, width));
final float percent1 = Math.min(mDropOutPercent, 1);
Rect bounds1 = mDrawable1.getBounds();
bounds1.offsetTo(width / 2 - bounds1.width() / 2, (int)((body.boxCenterY - bounds1.height() / 2 + bounds1.height()) * percent1) - bounds1.height());
mDrawable1.draw(canvas);
final float percent2 = Math.min(Math.max(mDropOutPercent - 1, 0), 1);
Rect bounds2 = mDrawable2.getBounds();
bounds2.offsetTo(width / 2 - bounds2.width() / 2, (int)((body.boxCenterY - bounds2.height() / 2 + bounds2.height()) * percent2) - bounds2.height());
mDrawable2.draw(canvas);
final float percent3 = Math.min(Math.max(mDropOutPercent - 2, 0), 1);
Rect bounds3 = mDrawable3.getBounds();
bounds3.offsetTo(width / 2 - bounds3.width() / 2, (int) ((body.boxCenterY - bounds3.height() / 2 + bounds3.height()) * percent3) - bounds3.height());
mDrawable3.draw(canvas);
if (mDropOutOverFlow) {
bounds1.offsetTo(width / 2 - bounds1.width() / 2, ((body.boxCenterY - bounds1.height() / 2)));
mDrawable1.draw(canvas);
bounds2.offsetTo(width / 2 - bounds2.width() / 2, ((body.boxCenterY - bounds2.height() / 2)));
mDrawable2.draw(canvas);
bounds3.offsetTo(width / 2 - bounds3.width() / 2, ((body.boxCenterY - bounds3.height() / 2)));
mDrawable3.draw(canvas);
}
}
}
示例9: getRectInsideCircle
import android.graphics.Rect; //导入方法依赖的package包/类
private Rect getRectInsideCircle(Point center, float radius) {
Rect rect = new Rect(0, 0, (int) ((radius * 2) / Math.sqrt(2)), (int) ((radius * 2) / Math.sqrt(2)));
rect.offsetTo(center.x - rect.width() / 2, center.y - rect.width() / 2);
return rect;
}