本文整理汇总了Java中android.graphics.Rect.centerX方法的典型用法代码示例。如果您正苦于以下问题:Java Rect.centerX方法的具体用法?Java Rect.centerX怎么用?Java Rect.centerX使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.Rect
的用法示例。
在下文中一共展示了Rect.centerX方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleAccessibleDrop
import android.graphics.Rect; //导入方法依赖的package包/类
/**
* @param clickedTarget the actual view that was clicked
* @param dropLocation relative to {@param clickedTarget}. If provided, its center is used
* as the actual drop location otherwise the views center is used.
*/
public void handleAccessibleDrop(View clickedTarget, Rect dropLocation,
String confirmation) {
if (!isInAccessibleDrag()) return;
int[] loc = new int[2];
if (dropLocation == null) {
loc[0] = clickedTarget.getWidth() / 2;
loc[1] = clickedTarget.getHeight() / 2;
} else {
loc[0] = dropLocation.centerX();
loc[1] = dropLocation.centerY();
}
mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(clickedTarget, loc);
mLauncher.getDragController().completeAccessibleDrag(loc);
if (!TextUtils.isEmpty(confirmation)) {
announceConfirmation(confirmation);
}
}
示例2: offsetIfNeeded
import android.graphics.Rect; //导入方法依赖的package包/类
private void offsetIfNeeded(CoordinatorLayout parent, FloatingActionButton fab) {
Rect padding = fab.mShadowPadding;
if (padding != null && padding.centerX() > 0 && padding.centerY() > 0) {
LayoutParams lp = (LayoutParams) fab.getLayoutParams();
int offsetTB = 0;
int offsetLR = 0;
if (fab.getRight() >= parent.getWidth() - lp.rightMargin) {
offsetLR = padding.right;
} else if (fab.getLeft() <= lp.leftMargin) {
offsetLR = -padding.left;
}
if (fab.getBottom() >= parent.getBottom() - lp.bottomMargin) {
offsetTB = padding.bottom;
} else if (fab.getTop() <= lp.topMargin) {
offsetTB = -padding.top;
}
fab.offsetTopAndBottom(offsetTB);
fab.offsetLeftAndRight(offsetLR);
}
}
示例3: calculateCircleOval
import android.graphics.Rect; //导入方法依赖的package包/类
/**
* Calculates rectangle(square) that will constraint chart circle.
*/
private void calculateCircleOval() {
Rect contentRect = computator.getContentRectMinusAllMargins();
final float circleRadius = Math.min(contentRect.width() / 2f, contentRect.height() / 2f);
final float centerX = contentRect.centerX();
final float centerY = contentRect.centerY();
final float left = centerX - circleRadius + touchAdditional;
final float top = centerY - circleRadius + touchAdditional;
final float right = centerX + circleRadius - touchAdditional;
final float bottom = centerY + circleRadius - touchAdditional;
originCircleOval.set(left, top, right, bottom);
final float inest = 0.5f * originCircleOval.width() * (1.0f - circleFillRatio);
originCircleOval.inset(inest, inest);
}
示例4: 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);
}
}
示例5: 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);
}
}
示例6: getDrawRect
import android.graphics.Rect; //导入方法依赖的package包/类
public Rect getDrawRect() {
Rect original = getBounds();
int cX = original.centerX(), cY = original.centerY();
rect.left = cX - (fullSize ? bigImgSize : drawImgSize) / 2;
rect.right = cX + (fullSize ? bigImgSize : drawImgSize) / 2;
rect.top = cY - (fullSize ? bigImgSize : drawImgSize) / 2;
rect.bottom = cY + (fullSize ? bigImgSize : drawImgSize) / 2;
return rect;
}
示例7: findClosestColumn
import android.graphics.Rect; //导入方法依赖的package包/类
/**
* Returns the column (0 indexed) closest to the previouslyFocusedRect or center if null.
* The 0 index is related to the first day of the week.
*/
private int findClosestColumn(@Nullable Rect previouslyFocusedRect) {
if (previouslyFocusedRect == null) {
return DAYS_IN_WEEK / 2;
} else {
int mPaddingLeft = ViewCompat.getPaddingStart(this); // TODO is this good?
int centerX = previouslyFocusedRect.centerX() - mPaddingLeft;
final int columnFromLeft =
mathConstrain(centerX / mCellWidth, 0, DAYS_IN_WEEK - 1);
return isLayoutRtl() ? DAYS_IN_WEEK - columnFromLeft - 1 : columnFromLeft;
}
}
示例8: PopupLayer
import android.graphics.Rect; //导入方法依赖的package包/类
public PopupLayer(Activity context, int radius) {
super(context);
mRadius = radius;
mContext = context;
Display display = context.getWindow().getWindowManager().getDefaultDisplay();
mRectWindowRange = new Rect();
btTempRect = new Rect();
display.getRectSize(mRectWindowRange);
mWindowCenterPoint = new Point(mRectWindowRange.centerX(), mRectWindowRange.centerY());
mShadowView = new View(context);
mShadowView.setBackgroundColor(Color.parseColor("#66000000"));
mShadowView.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
addView(mShadowView);
}
示例9: onBoundsChange
import android.graphics.Rect; //导入方法依赖的package包/类
@Override
protected void onBoundsChange(Rect bounds) {
super.onBoundsChange(bounds);
bounds = clipSquare(bounds);
int radius = (int) (bounds.width() * Math.PI / 3f / getChildCount());
int left = bounds.centerX() - radius;
int right = bounds.centerX() + radius;
for (int i = 0; i < getChildCount(); i++) {
Dot dot = getChildAt(i);
dot.setDrawBounds(left, bounds.top, right, bounds.top + radius * 2);
}
}
示例10: offsetIfNeeded
import android.graphics.Rect; //导入方法依赖的package包/类
/**
* Pre-Lollipop we use padding so that the shadow has enough space to be drawn. This method
* offsets our layout position so that we're positioned correctly if we're on one of
* our parent's edges.
*/
private void offsetIfNeeded(CoordinatorLayout parent, FloatingActionButton fab) {
final Rect padding = fab.mShadowPadding;
if (padding != null && padding.centerX() > 0 && padding.centerY() > 0) {
final CoordinatorLayout.LayoutParams lp =
(CoordinatorLayout.LayoutParams) fab.getLayoutParams();
int offsetTB = 0, offsetLR = 0;
if (fab.getRight() >= parent.getWidth() - lp.rightMargin) {
// If we're on the right edge, shift it the right
offsetLR = padding.right;
} else if (fab.getLeft() <= lp.leftMargin) {
// If we're on the left edge, shift it the left
offsetLR = -padding.left;
}
if (fab.getBottom() >= parent.getHeight() - lp.bottomMargin) {
// If we're on the bottom edge, shift it down
offsetTB = padding.bottom;
} else if (fab.getTop() <= lp.topMargin) {
// If we're on the top edge, shift it up
offsetTB = -padding.top;
}
if (offsetTB != 0) {
ViewCompat.offsetTopAndBottom(fab, offsetTB);
}
if (offsetLR != 0) {
ViewCompat.offsetLeftAndRight(fab, offsetLR);
}
}
}
示例11: draw
import android.graphics.Rect; //导入方法依赖的package包/类
@Override
public void draw(@NonNull Canvas canvas) {
Rect bounds = getBounds();
mBackground.draw(canvas);
if (mText != null)
canvas.drawText(mText, bounds.centerX(), bounds.centerY() - (mPaint.descent() + mPaint.ascent()) / 2, mPaint);
if (mContentDrawable != null) {
int cw = mContentDrawable.getIntrinsicWidth();
int ch = mContentDrawable.getIntrinsicHeight();
int cx = bounds.centerX() - cw / 2;
int cy = bounds.centerY() - ch / 2;
mContentDrawable.setBounds(cx, cy, cx + cw, cy + ch);
mContentDrawable.draw(canvas);
}
}
示例12: IntroductoryOverlay
import android.graphics.Rect; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public IntroductoryOverlay(Builder builder, AttributeSet attrs, int defStyleAttr) {
super(builder.mContext, attrs, defStyleAttr);
mIsSingleTime = builder.mSingleTime;
LayoutInflater inflater = LayoutInflater.from(getContext());
inflater.inflate(R.layout.ccl_intro_overlay, this);
mButton = (Button) findViewById(R.id.button);
mTitleText = (TextView) findViewById(R.id.textTitle);
mSubtitleText = (TextView) findViewById(R.id.textSubtitle);
TypedArray typedArray = getContext().getTheme()
.obtainStyledAttributes(attrs, R.styleable.CCLIntroOverlay,
R.attr.CCLIntroOverlayStyle, R.style.CCLIntroOverlay);
if (builder.mOverlayColor != 0) {
mOverlayColorId = builder.mOverlayColor;
} else {
mOverlayColorId = typedArray
.getColor(R.styleable.CCLIntroOverlay_ccl_IntroBackgroundColor,
Color.argb(0, 0, 0, 0));
}
mFocusRadius = builder.mRadius;
mListener = builder.mListener;
if (mFocusRadius == 0) {
mFocusRadius = typedArray
.getDimension(R.styleable.CCLIntroOverlay_ccl_IntroFocusRadius, 0);
}
View view = builder.mView;
Rect rect = new Rect();
view.getGlobalVisibleRect(rect);
mCenterX = rect.centerX();
mCenterY = rect.centerY();
setFitsSystemWindows(true);
setupHolePaint();
setText(builder.mTitleText, builder.mSubtitleText);
setButton(builder.mButtonText, typedArray);
typedArray.recycle();
}
示例13: calculateCircleOval
import android.graphics.Rect; //导入方法依赖的package包/类
private void calculateCircleOval() {
Rect contentRect = this.computator.getContentRectMinusAllMargins();
float circleRadius = Math.min(((float) contentRect.width()) / 2.0f, ((float) contentRect.height()) / 2.0f);
float centerX = (float) contentRect.centerX();
float centerY = (float) contentRect.centerY();
this.originCircleOval.set((centerX - circleRadius) + ((float) this.touchAdditional), (centerY - circleRadius) + ((float) this.touchAdditional), (centerX + circleRadius) - ((float) this.touchAdditional), (centerY + circleRadius) - ((float) this.touchAdditional));
float inest = (0.5f * this.originCircleOval.width()) * (1.0f - this.circleFillRatio);
this.originCircleOval.inset(inest, inest);
}
示例14: centerX
import android.graphics.Rect; //导入方法依赖的package包/类
public static float centerX (Rect bounds, float withOf){
float xStart;
xStart=bounds.centerX()- (withOf/2f);
return xStart;
}
示例15: updateTextPosition
import android.graphics.Rect; //导入方法依赖的package包/类
/**
* Update (x,y) positions of text.
* @param textBounds Rect bounds based on text value.
* @param width View width.
*/
private void updateTextPosition(Rect textBounds, int width) {
textY = (int) ((lineY - linePaint.getStrokeWidth() / 2) - textMetrics.descent);
textX = width / 2 - textBounds.centerX();
}