本文整理汇总了Java中android.graphics.Rect类的典型用法代码示例。如果您正苦于以下问题:Java Rect类的具体用法?Java Rect怎么用?Java Rect使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Rect类属于android.graphics包,在下文中一共展示了Rect类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSize
import android.graphics.Rect; //导入依赖的package包/类
@Override
public int getSize(Paint paint, CharSequence text,
int start, int end,
Paint.FontMetricsInt fm) {
Drawable d = getCachedDrawable();
Rect rect = d.getBounds();
if (fm != null) {
// Centers the text with the ImageSpan
if ((rect.bottom - (fm.descent - fm.ascent)) >= 0) {
// Stores the initial descent and computes the margin available
initialDescent = fm.descent;
extraSpace = rect.bottom - (fm.descent - fm.ascent);
}
fm.descent = extraSpace / 2 + initialDescent;
fm.bottom = fm.descent;
fm.ascent = -rect.bottom + fm.descent;
fm.top = fm.ascent;
}
return rect.right;
}
示例2: getItemOffsets
import android.graphics.Rect; //导入依赖的package包/类
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
if (!AbstractWeakReferenceUtils.isAlive(mWeakRef)) {
return;
}
outRect.left = mSpaceBetweenItems / 2;
outRect.top = 0;
outRect.right = mSpaceBetweenItems / 2;
outRect.bottom = 0;
final int position = ((RecyclerView.LayoutParams) view.getLayoutParams()).getViewAdapterPosition();
final int total = parent.getAdapter().getItemCount();
if (position == 0) {
outRect.left = mSpaceOnBothEnds;
} else if (position == total - 1) {
outRect.right = mSpaceOnBothEnds;
}
}
示例3: getStatusBarHeight
import android.graphics.Rect; //导入依赖的package包/类
public static int getStatusBarHeight(Activity activity) {
int result = 0;
Rect rect = new Rect();
Window window = activity.getWindow();
if (window != null) {
window.getDecorView().getWindowVisibleDisplayFrame(rect);
View v = window.findViewById(Window.ID_ANDROID_CONTENT);
android.view.Display display = ((android.view.WindowManager) activity.getSystemService(activity.WINDOW_SERVICE)).getDefaultDisplay();
//return result title bar height
int result1 = display.getHeight() - v.getBottom() + rect.top;
int result2 = display.getHeight() - v.getBottom();
int result3 = v.getTop() - rect.top;
int result4 = display.getHeight() - v.getHeight();
Log.e("StatusBarHeight==", "result1== " + result1 +" result2 = " + result2 + "result3=" + result3 + "result4=" +result4 ) ;
}
return result;
}
示例4: onGlobalLayout
import android.graphics.Rect; //导入依赖的package包/类
public void onGlobalLayout() {
int i = 0;
int navHeight = this.activity.getResources().getIdentifier("navigation_bar_height", "dimen", "android");
navHeight = navHeight > 0 ? this.activity.getResources().getDimensionPixelSize(navHeight) : 0;
int statusBarHeight = this.activity.getResources().getIdentifier("status_bar_height", "dimen", "android");
if (statusBarHeight > 0) {
i = this.activity.getResources().getDimensionPixelSize(statusBarHeight);
}
Rect rect = new Rect();
activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
if (activity.mDrawerLayout.getRootView().getHeight() - ((navHeight + i) + rect.height()) <= 0) {
activity.onHideKeyboard();
} else {
activity.onShowKeyboard();
}
}
示例5: adjustDropDownSizeAndPosition
import android.graphics.Rect; //导入依赖的package包/类
private void adjustDropDownSizeAndPosition() {
if (mDropDownAnchor.getWidth() > 1) {
Resources res = getContext().getResources();
int anchorPadding = mSearchPlate.getPaddingLeft();
Rect dropDownPadding = new Rect();
int iconOffset = mIconifiedByDefault
? res.getDimensionPixelSize(R.dimen.abs__dropdownitem_icon_width)
+ res.getDimensionPixelSize(R.dimen.abs__dropdownitem_text_padding_left)
: 0;
mQueryTextView.getDropDownBackground().getPadding(dropDownPadding);
mQueryTextView.setDropDownHorizontalOffset(-(dropDownPadding.left + iconOffset)
+ anchorPadding);
mQueryTextView.setDropDownWidth(mDropDownAnchor.getWidth() + dropDownPadding.left
+ dropDownPadding.right + iconOffset - (anchorPadding));
}
}
示例6: testCopyProperties
import android.graphics.Rect; //导入依赖的package包/类
@Test
public void testCopyProperties() {
Rect rect = new Rect(10, 20, 30, 40);
int config = 11;
int level = 100;
boolean visible = true;
int[] stateSet = new int[]{1, 2};
mDrawable.setBounds(rect);
mDrawable.setChangingConfigurations(config);
mDrawable.setLevel(level);
mDrawable.setVisible(visible, false);
mDrawable.setState(stateSet);
Drawable newDrawable = mock(Drawable.class);
mDrawable.setCurrent(newDrawable);
verify(newDrawable).setBounds(rect);
verify(newDrawable).setChangingConfigurations(config);
verify(newDrawable).setLevel(level);
verify(newDrawable).setVisible(visible, false);
verify(newDrawable).setState(stateSet);
}
示例7: setup
import android.graphics.Rect; //导入依赖的package包/类
public void setup(Matrix m, Rect imageRect, RectF cropRect, boolean circle,
boolean maintainAspectRatio) {
if (circle) {
maintainAspectRatio = true;
}
mMatrix = new Matrix(m);
mCropRect = cropRect;
mImageRect = new RectF(imageRect);
mMaintainAspectRatio = maintainAspectRatio;
mCircle = circle;
mInitialAspectRatio = mCropRect.width() / mCropRect.height();
mDrawRect = computeLayout();
mFocusPaint.setARGB(125, 50, 50, 50);
mNoFocusPaint.setARGB(125, 50, 50, 50);
mOutlinePaint.setStrokeWidth(3F);
mOutlinePaint.setStyle(Paint.Style.STROKE);
mOutlinePaint.setAntiAlias(true);
mMode = ModifyMode.None;
init();
}
示例8: onFocusChanged
import android.graphics.Rect; //导入依赖的package包/类
@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
super.onFocusChanged(focused, direction, previouslyFocusedRect);
isFocused = focused;
if (focused && getText().length() > 0) {
if (!isVisible) {
isVisible = true;
startVisibleAnimator();
}
} else {
if (isVisible) {
isVisible = false;
startGoneAnimator();
}
}
}
示例9: draw
import android.graphics.Rect; //导入依赖的package包/类
@Override
protected void draw(Canvas canvas, Rect bounds) {
int saveCount = canvas.save();
RectF arcBounds = mCurrentBounds;
arcBounds.set(bounds);
mPaint.setColor(mBottomColor);
canvas.drawPath(mCurrentBottomWaitPath, mPaint);
mPaint.setColor(mMiddleColor);
canvas.drawPath(mCurrentMiddleWaitPath, mPaint);
mPaint.setColor(mTopColor);
canvas.drawPath(mCurrentTopWaitPath, mPaint);
canvas.restoreToCount(saveCount);
}
示例10: getRoundedCornerBitmap
import android.graphics.Rect; //导入依赖的package包/类
private static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
Bitmap createBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config
.ARGB_8888);
Canvas canvas = new Canvas(createBitmap);
Paint paint = new Paint();
Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
RectF rectF = new RectF(rect);
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(-12434878);
if (RESUTIL_V2_DUBUG) {
canvas.drawRoundRect(rectF, (float) (bitmap.getWidth() / 2), (float) (bitmap
.getHeight() / 2), paint);
} else {
canvas.drawRoundRect(rectF, (float) (bitmap.getWidth() / 6), (float) (bitmap
.getHeight() / 6), paint);
}
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
bitmap.recycle();
return createBitmap;
}
示例11: measuredOutContentStart
import android.graphics.Rect; //导入依赖的package包/类
private void measuredOutContentStart(String content) {
Rect rect = new Rect();
paintOuterText.getTextBounds(content, 0, content.length(), rect);
switch (mGravity) {
case Gravity.CENTER:
if (isOptions||label == null|| label.equals("")||!isCenterLabel) {
drawOutContentStart = (int) ((measuredWidth - rect.width()) * 0.5);
} else {//只显示中间label时,时间选择器内容偏左一点,留出空间绘制单位标签
drawOutContentStart = (int) ((measuredWidth - rect.width()) * 0.25);
}
break;
case Gravity.LEFT:
drawOutContentStart = 0;
break;
case Gravity.RIGHT:
drawOutContentStart = measuredWidth - rect.width()-(int)centerContentOffset;
break;
}
}
示例12: dispatchTouchEvent
import android.graphics.Rect; //导入依赖的package包/类
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
// finishWithUserCanceled() if the user tapped outside the picker
if (MotionEvent.ACTION_DOWN == event.getAction()) {
Rect visibilityRect = new Rect();
mPickerContainer.getGlobalVisibleRect(visibilityRect);
boolean tappedOutsidePicker =
!visibilityRect.contains((int) event.getRawX(), (int) event.getRawY());
if (tappedOutsidePicker) {
finishWithUserCanceled();
}
}
return super.dispatchTouchEvent(event);
}
示例13: drawScanningLine
import android.graphics.Rect; //导入依赖的package包/类
private void drawScanningLine(Canvas canvas, Rect frame) {
if (this.isFirst) {
this.isFirst = false;
this.slideTop = 0;
this.slideBottom = frame.bottom - frame.top;
}
this.slideTop += 6;
if (this.slideTop >= this.slideBottom - MIDDLE_LINE_WIDTH) {
this.slideTop = 0;
}
Rect lineRect = new Rect();
lineRect.left = frame.left + MIDDLE_LINE_PADDING;
lineRect.right = frame.right - MIDDLE_LINE_PADDING;
lineRect.top = frame.top + this.slideTop;
lineRect.bottom = (frame.top + this.slideTop) + MIDDLE_LINE_WIDTH;
canvas.drawBitmap(((BitmapDrawable) getResources().getDrawable(R.drawable.sweep_laser)).getBitmap(), null, lineRect, this.paint);
}
示例14: setIntentByViewGroup
import android.graphics.Rect; //导入依赖的package包/类
private void setIntentByViewGroup(RemoteViews remoteViews, ViewGroup viewGroup, List<RectInfo> list) {
int count = viewGroup.getChildCount();
Rect p = new Rect();
viewGroup.getHitRect(p);
for (int i = 0; i < count; i++) {
View v = viewGroup.getChildAt(i);
if (v instanceof ViewGroup) {
// linearlayout
setIntentByViewGroup(remoteViews, (ViewGroup) v, list);
} else if (v instanceof TextView || v instanceof ImageView) {
// textview
Rect rect = getRect(v);
RectInfo next = findIntent(rect, list);
if (next != null) {
// VLog.d(TAG, next.rect+":setPendIntent:"+i);
// remoteViews.setImageViewBitmap(v.getId(), next.testBg);
remoteViews.setOnClickPendingIntent(v.getId(), next.mPendingIntent);
}
}
}
}
示例15: draw
import android.graphics.Rect; //导入依赖的package包/类
/**
* Draw the progress spinner
*/
public void draw(Canvas c, Rect bounds) {
final RectF arcBounds = mTempBounds;
arcBounds.set(bounds);
arcBounds.inset(mStrokeInset, mStrokeInset);
final float startAngle = (mStartTrim + mRotation) * 360;
final float endAngle = (mEndTrim + mRotation) * 360;
float sweepAngle = endAngle - startAngle;
if (sweepAngle != 0) {
mPaint.setColor(mCurrentColor);
c.drawArc(arcBounds, startAngle, sweepAngle, false, mPaint);
}
drawTriangle(c, startAngle, sweepAngle, bounds);
if (mAlpha < 255) {
mCirclePaint.setColor(mBackgroundColor);
mCirclePaint.setAlpha(255 - mAlpha);
c.drawCircle(bounds.exactCenterX(), bounds.exactCenterY(), bounds.width() / 2,
mCirclePaint);
}
}