本文整理匯總了Java中android.graphics.Rect.offset方法的典型用法代碼示例。如果您正苦於以下問題:Java Rect.offset方法的具體用法?Java Rect.offset怎麽用?Java Rect.offset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.graphics.Rect
的用法示例。
在下文中一共展示了Rect.offset方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onRequestChildRectangleOnScreen
import android.graphics.Rect; //導入方法依賴的package包/類
@Override
public boolean onRequestChildRectangleOnScreen(CoordinatorLayout parent, View child,
Rect rectangle, boolean immediate) {
final AppBarLayout header = findFirstDependency(parent.getDependencies(child));
if (header != null) {
// Offset the rect by the child's left/top
rectangle.offset(child.getLeft(), child.getTop());
final Rect parentRect = mTempRect1;
parentRect.set(0, 0, parent.getWidth(), parent.getHeight());
if (!parentRect.contains(rectangle)) {
// If the rectangle can not be fully seen the visible bounds, collapse
// the AppBarLayout
header.setExpanded(false, !immediate);
return true;
}
}
return false;
}
示例2: createAccessibilityNodeInfoForInputText
import android.graphics.Rect; //導入方法依賴的package包/類
private AccessibilityNodeInfoCompat createAccessibilityNodeInfoForInputText(
int left, int top, int right, int bottom) {
AccessibilityNodeInfoCompat info = AccessibilityNodeInfoCompat.obtain(getInputText());
info.setSource(mNumberPicker, VIRTUAL_VIEW_ID_INPUT);
if (mAccessibilityFocusedView != VIRTUAL_VIEW_ID_INPUT) {
info.addAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS);
}
if (mAccessibilityFocusedView == VIRTUAL_VIEW_ID_INPUT) {
info.addAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
}
Rect boundsInParent = mTempRect;
boundsInParent.set(left, top, right, bottom);
info.setVisibleToUser(isVisibleToUser(boundsInParent));
info.setBoundsInParent(boundsInParent);
Rect boundsInScreen = boundsInParent;
int[] locationOnScreen = mTempArray;
mNumberPicker.getLocationOnScreen(locationOnScreen);
boundsInScreen.offset(locationOnScreen[0], locationOnScreen[1]);
info.setBoundsInScreen(boundsInScreen);
return info;
}
示例3: createAccessibiltyNodeInfoForInputText
import android.graphics.Rect; //導入方法依賴的package包/類
private AccessibilityNodeInfo createAccessibiltyNodeInfoForInputText(
int left, int top, int right, int bottom) {
AccessibilityNodeInfoCompat info = AccessibilityNodeInfoCompat.wrap(mInputText.createAccessibilityNodeInfo());
info.setSource(NumberPicker.this, VIRTUAL_VIEW_ID_INPUT);
if (mAccessibilityFocusedView != VIRTUAL_VIEW_ID_INPUT) {
info.addAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
}
if (mAccessibilityFocusedView == VIRTUAL_VIEW_ID_INPUT) {
info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
}
Rect boundsInParent = mTempRect;
boundsInParent.set(left, top, right, bottom);
info.setVisibleToUser(isVisibleToUser(boundsInParent));
info.setBoundsInParent(boundsInParent);
Rect boundsInScreen = boundsInParent;
int[] locationOnScreen = mTempArray;
getLocationOnScreen(locationOnScreen);
boundsInScreen.offset(locationOnScreen[0], locationOnScreen[1]);
info.setBoundsInScreen(boundsInScreen);
return info.unwrap();
}
示例4: getTile
import android.graphics.Rect; //導入方法依賴的package包/類
@Override
public Bitmap getTile(int level, int x, int y, Bitmap bitmap) {
int tileSize = getTileSize();
if (bitmap == null) {
bitmap = Bitmap.createBitmap(tileSize, tileSize, Bitmap.Config.ARGB_8888);
}
Canvas c = new Canvas(bitmap);
Rect bounds = new Rect(0, 0, getImageWidth(), getImageHeight());
bounds.offset(-x, -y);
mDrawable.setBounds(bounds);
mDrawable.draw(c);
c.setBitmap(null);
return bitmap;
}
示例5: getDirectionVectorForDrop
import android.graphics.Rect; //導入方法依賴的package包/類
private void getDirectionVectorForDrop(int dragViewCenterX, int dragViewCenterY, int spanX,
int spanY, View dragView, int[] resultDirection) {
int[] targetDestination = new int[2];
findNearestArea(dragViewCenterX, dragViewCenterY, spanX, spanY, targetDestination);
Rect dragRect = new Rect();
regionToRect(targetDestination[0], targetDestination[1], spanX, spanY, dragRect);
dragRect.offset(dragViewCenterX - dragRect.centerX(), dragViewCenterY - dragRect.centerY());
Rect dropRegionRect = new Rect();
getViewsIntersectingRegion(targetDestination[0], targetDestination[1], spanX, spanY,
dragView, dropRegionRect, mIntersectingViews);
int dropRegionSpanX = dropRegionRect.width();
int dropRegionSpanY = dropRegionRect.height();
regionToRect(dropRegionRect.left, dropRegionRect.top, dropRegionRect.width(),
dropRegionRect.height(), dropRegionRect);
int deltaX = (dropRegionRect.centerX() - dragViewCenterX) / spanX;
int deltaY = (dropRegionRect.centerY() - dragViewCenterY) / spanY;
if (dropRegionSpanX == mCountX || spanX == mCountX) {
deltaX = 0;
}
if (dropRegionSpanY == mCountY || spanY == mCountY) {
deltaY = 0;
}
if (deltaX == 0 && deltaY == 0) {
// No idea what to do, give a random direction.
resultDirection[0] = 1;
resultDirection[1] = 0;
} else {
computeDirectionVector(deltaX, deltaY, resultDirection);
}
}
示例6: getIconRect
import android.graphics.Rect; //導入方法依賴的package包/類
protected Rect getIconRect(int viewWidth, int viewHeight, int drawableWidth, int drawableHeight) {
DragLayer dragLayer = mLauncher.getDragLayer();
// Find the rect to animate to (the view is center aligned)
Rect to = new Rect();
dragLayer.getViewRectRelativeToSelf(this, to);
final int width = drawableWidth;
final int height = drawableHeight;
final int left;
final int right;
if (Utilities.isRtl(getResources())) {
right = to.right - getPaddingRight();
left = right - width;
} else {
left = to.left + getPaddingLeft();
right = left + width;
}
final int top = to.top + (getMeasuredHeight() - height) / 2;
final int bottom = top + height;
to.set(left, top, right, bottom);
// Center the destination rect about the trash icon
final int xOffset = (int) -(viewWidth - width) / 2;
final int yOffset = (int) -(viewHeight - height) / 2;
to.offset(xOffset, yOffset);
return to;
}
示例7: scaleRectAboutCenter
import android.graphics.Rect; //導入方法依賴的package包/類
public static void scaleRectAboutCenter(Rect r, float scale) {
if (scale != 1.0f) {
int cx = r.centerX();
int cy = r.centerY();
r.offset(-cx, -cy);
r.left = (int) (r.left * scale + 0.5f);
r.top = (int) (r.top * scale + 0.5f);
r.right = (int) (r.right * scale + 0.5f);
r.bottom = (int) (r.bottom * scale + 0.5f);
r.offset(cx, cy);
}
}
示例8: scaleRectAboutCenter
import android.graphics.Rect; //導入方法依賴的package包/類
static void scaleRectAboutCenter(Rect r, float scale) {
if (scale != 1.0f) {
int cx = r.centerX();
int cy = r.centerY();
r.offset(-cx, -cy);
r.left = (int) (r.left * scale + 0.5f);
r.top = (int) (r.top * scale + 0.5f);
r.right = (int) (r.right * scale + 0.5f);
r.bottom = (int) (r.bottom * scale + 0.5f);
r.offset(cx, cy);
}
}
示例9: createDragOutline
import android.graphics.Rect; //導入方法依賴的package包/類
@Override
public Bitmap createDragOutline(Canvas canvas) {
Workspace workspace = Launcher.getLauncher(mView.getContext()).getWorkspace();
int[] size = workspace.estimateItemSize(mAddInfo, false);
int w = size[0];
int h = size[1];
final Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ALPHA_8);
canvas.setBitmap(b);
Rect src = new Rect(0, 0, mPreviewBitmap.getWidth(), mPreviewBitmap.getHeight());
float scaleFactor = Math.min((w - DRAG_BITMAP_PADDING) / (float) mPreviewBitmap.getWidth(),
(h - DRAG_BITMAP_PADDING) / (float) mPreviewBitmap.getHeight());
int scaledWidth = (int) (scaleFactor * mPreviewBitmap.getWidth());
int scaledHeight = (int) (scaleFactor * mPreviewBitmap.getHeight());
Rect dst = new Rect(0, 0, scaledWidth, scaledHeight);
// center the image
dst.offset((w - scaledWidth) / 2, (h - scaledHeight) / 2);
canvas.drawBitmap(mPreviewBitmap, src, dst, null);
// Don't clip alpha values for the drag outline if we're using the default widget preview
boolean clipAlpha = !(mAddInfo instanceof PendingAddWidgetInfo &&
(((PendingAddWidgetInfo) mAddInfo).previewImage == 0));
HolographicOutlineHelper.obtain(mView.getContext())
.applyExpensiveOutlineWithBlur(b, canvas, clipAlpha);
canvas.setBitmap(null);
return b;
}
示例10: requestChildRectangleOnScreen
import android.graphics.Rect; //導入方法依賴的package包/類
public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate) {
int rectTopWithinChild = rect.top;
rect.offset(child.getLeft(), child.getTop());
rect.offset(-child.getScrollX(), -child.getScrollY());
int height = getHeight();
int listUnfadedTop = getScrollY();
int listUnfadedBottom = listUnfadedTop + height;
int fadingEdge = getVerticalFadingEdgeLength();
if (showingTopFadingEdge() && rectTopWithinChild > fadingEdge) {
listUnfadedTop += fadingEdge;
}
int bottomOfBottomChild = getChildAt(getChildCount() - 1).getBottom();
if (showingBottomFadingEdge() && rect.bottom < bottomOfBottomChild - fadingEdge) {
listUnfadedBottom -= fadingEdge;
}
int scrollYDelta = 0;
if (rect.bottom > listUnfadedBottom && rect.top > listUnfadedTop) {
if (rect.height() > height) {
scrollYDelta = 0 + (rect.top - listUnfadedTop);
} else {
scrollYDelta = 0 + (rect.bottom - listUnfadedBottom);
}
scrollYDelta = Math.min(scrollYDelta, bottomOfBottomChild - listUnfadedBottom);
} else if (rect.top < listUnfadedTop && rect.bottom < listUnfadedBottom) {
if (rect.height() > height) {
scrollYDelta = 0 - (listUnfadedBottom - rect.bottom);
} else {
scrollYDelta = 0 - (listUnfadedTop - rect.top);
}
scrollYDelta = Math.max(scrollYDelta, getChildAt(0).getTop() - listUnfadedTop);
}
boolean scroll = scrollYDelta != 0;
if (scroll) {
scrollListItemsBy(-scrollYDelta);
positionSelector(child);
this.mSelectedTop = child.getTop();
invalidate();
}
return scroll;
}
示例11: requestChildRectangleOnScreen
import android.graphics.Rect; //導入方法依賴的package包/類
public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate) {
int rectLeftWithinChild = rect.left;
rect.offset(child.getLeft(), child.getTop());
rect.offset(-child.getScrollX(), -child.getScrollY());
int width = getWidth();
int listUnfadedLeft = getScrollX();
int listUnfadedRight = listUnfadedLeft + width;
int fadingEdge = getHorizontalFadingEdgeLength();
if (showingLeftFadingEdge() && (this.mSelectedPosition > 0 || rectLeftWithinChild > fadingEdge)) {
listUnfadedLeft += fadingEdge;
}
int rightOfRightChild = getChildAt(getChildCount() - 1).getRight();
if (showingRightFadingEdge() && (this.mSelectedPosition < this.mItemCount - 1 || rect.right < rightOfRightChild - fadingEdge)) {
listUnfadedRight -= fadingEdge;
}
int scrollXDelta = 0;
if (rect.right > listUnfadedRight && rect.left > listUnfadedLeft) {
if (rect.width() > width) {
scrollXDelta = 0 + (rect.left - listUnfadedLeft);
} else {
scrollXDelta = 0 + (rect.right - listUnfadedRight);
}
scrollXDelta = Math.min(scrollXDelta, rightOfRightChild - listUnfadedRight);
} else if (rect.left < listUnfadedLeft && rect.right < listUnfadedRight) {
if (rect.width() > width) {
scrollXDelta = 0 - (listUnfadedRight - rect.right);
} else {
scrollXDelta = 0 - (listUnfadedLeft - rect.left);
}
scrollXDelta = Math.max(scrollXDelta, getChildAt(0).getLeft() - listUnfadedLeft);
}
boolean scroll = scrollXDelta != 0;
if (scroll) {
scrollListItemsBy(-scrollXDelta);
positionSelector(-1, child);
this.mSelectedLeft = child.getTop();
invalidate();
}
return scroll;
}
示例12: getBadgeBitmap
import android.graphics.Rect; //導入方法依賴的package包/類
@Override
public Bitmap getBadgeBitmap(LauncherAppWidgetProviderInfo info, Bitmap bitmap,
int imageWidth, int imageHeight) {
if (info.isCustomWidget || info.getProfile().equals(android.os.Process.myUserHandle())) {
return bitmap;
}
// Add a user badge in the bottom right of the image.
final Resources res = mContext.getResources();
final int badgeMinTop = res.getDimensionPixelSize(R.dimen.profile_badge_minimum_top);
// choose min between badge size defined for widget tray versus width, height of the image.
// Width, height of the image can be smaller than widget tray badge size when being dropped
// to the workspace.
final int badgeSize = Math.min(res.getDimensionPixelSize(R.dimen.profile_badge_size),
Math.min(imageWidth, imageHeight - badgeMinTop));
final Rect badgeLocation = new Rect(0, 0, badgeSize, badgeSize);
final int top = Math.max(imageHeight - badgeSize, badgeMinTop);
if (res.getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
badgeLocation.offset(0, top);
} else {
badgeLocation.offset(bitmap.getWidth() - badgeSize, top);
}
Drawable drawable = mPm.getUserBadgedDrawableForDensity(
new BitmapDrawable(res, bitmap), info.getProfile(), badgeLocation, 0);
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
}
bitmap.eraseColor(Color.TRANSPARENT);
Canvas c = new Canvas(bitmap);
drawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
drawable.draw(c);
c.setBitmap(null);
return bitmap;
}
示例13: onSave
import android.graphics.Rect; //導入方法依賴的package包/類
@Override
public void onSave(final WallpaperPickerActivity a) {
boolean finishActivityWhenDone = true;
BitmapCropTask.OnBitmapCroppedHandler h = new BitmapCropTask.OnBitmapCroppedHandler() {
@Override
public void onBitmapCropped(byte[] imageBytes, Rect hint) {
Bitmap thumb = null;
Point thumbSize = getDefaultThumbnailSize(a.getResources());
if (imageBytes != null) {
// rotation is set to 0 since imageBytes has already been correctly rotated
thumb = createThumbnail(
thumbSize, null, null, imageBytes, null, 0, 0, true);
a.getSavedImages().writeImage(thumb, imageBytes);
} else {
try {
// Generate thumb
Point size = getDefaultThumbnailSize(a.getResources());
Rect finalCropped = new Rect();
Utils.getMaxCropRect(hint.width(), hint.height(), size.x, size.y, false)
.roundOut(finalCropped);
finalCropped.offset(hint.left, hint.top);
InputStream in = a.getContentResolver().openInputStream(mUri);
BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(in, true);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = finalCropped.width() / size.x;
thumb = decoder.decodeRegion(finalCropped, options);
decoder.recycle();
Utils.closeSilently(in);
if (thumb != null) {
thumb = Bitmap.createScaledBitmap(thumb, size.x, size.y, true);
}
} catch (IOException e) { }
PointF center = a.mCropView.getCenter();
Float[] extras = new Float[] {
a.mCropView.getScale(),
center.x,
center.y
};
a.getSavedImages().writeImage(thumb, mUri, extras);
}
}
};
boolean shouldFadeOutOnFinish = a.getWallpaperParallaxOffset() == 0f;
a.cropImageAndSetWallpaper(mUri, h, finishActivityWhenDone, shouldFadeOutOnFinish);
}
示例14: bang
import android.graphics.Rect; //導入方法依賴的package包/類
public void bang(final View view, float radius, SmallBangListener listener) {
// set listener
if (listener != null) {
setmListener(listener);
this.mListener.onAnimationStart();
}
Rect r = new Rect();
view.getGlobalVisibleRect(r);
int[] location = new int[2];
getLocationOnScreen(location);
r.offset(-location[0], -location[1]);
r.inset(-mExpandInset[0], -mExpandInset[1]);
centerX = r.left + r.width() / 2;
centerY = r.top + r.height() / 2;
if (radius != -1) {
initRadius(radius);
} else {
initRadius(Math.max(r.width(), r.height()));
}
view.setScaleX(0.1f);
view.setScaleY(0.1f);
ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f).setDuration((long) (ANIMATE_DURATION * 0.5f));
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float animatedFraction = animation.getAnimatedFraction();
view.setScaleX(0.1f + animatedFraction * 0.9f);
view.setScaleY(0.1f + animatedFraction * 0.9f);
}
});
animator.setInterpolator(new OvershootInterpolator(2));
animator.setStartDelay((long) (ANIMATE_DURATION * P3));
animator.start();
bang();
}
示例15: createAccessibilityNodeInfoForNumberPicker
import android.graphics.Rect; //導入方法依賴的package包/類
private AccessibilityNodeInfo createAccessibilityNodeInfoForNumberPicker(int left, int top,
int right, int bottom) {
AccessibilityNodeInfoCompat info = AccessibilityNodeInfoCompat.obtain();
info.setClassName(NumberPicker.class.getName());
info.setPackageName(getContext().getPackageName());
info.setSource(NumberPicker.this);
if (hasVirtualDecrementButton()) {
info.addChild(NumberPicker.this, VIRTUAL_VIEW_ID_DECREMENT);
}
info.addChild(NumberPicker.this, VIRTUAL_VIEW_ID_INPUT);
if (hasVirtualIncrementButton()) {
info.addChild(NumberPicker.this, VIRTUAL_VIEW_ID_INCREMENT);
}
//info.setParent((View) getParentForAccessibility());
info.setParent((View) ViewCompat.getParentForAccessibility(NumberPicker.this));
info.setEnabled(NumberPicker.this.isEnabled());
info.setScrollable(true);
// FIXME final float applicationScale = getContext().getResources().getCompatibilityInfo().applicationScale;
final float applicationScale = 1f;
Rect boundsInParent = mTempRect;
boundsInParent.set(left, top, right, bottom);
//boundsInParent.scale(applicationScale);
scaleRect(boundsInParent, applicationScale);
info.setBoundsInParent(boundsInParent);
info.setVisibleToUser(isVisibleToUser());
Rect boundsInScreen = boundsInParent;
int[] locationOnScreen = mTempArray;
getLocationOnScreen(locationOnScreen);
boundsInScreen.offset(locationOnScreen[0], locationOnScreen[1]);
// boundsInScreen.scale(applicationScale);
scaleRect(boundsInScreen, applicationScale);
info.setBoundsInScreen(boundsInScreen);
if (mAccessibilityFocusedView != View.NO_ID) {
info.addAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS);
}
if (mAccessibilityFocusedView == View.NO_ID) {
info.addAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
}
if (NumberPicker.this.isEnabled()) {
if (getWrapSelectorWheel() || getValue() < getMaxValue()) {
info.addAction(AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD);
}
if (getWrapSelectorWheel() || getValue() > getMinValue()) {
info.addAction(AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD);
}
}
return info.unwrap();
}