@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; }
@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; } }
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; }
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(); } }
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)); } }
@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); }
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(); }
@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(); } } }
@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); }
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; }
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; } }
@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); }
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); }
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); } } } }
/** * 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); } }
/** * Like {@link #getFramingRect} but coordinates are in terms of the preview frame, * not UI / screen. */ public Rect getFramingRectInPreview() { if (framingRectInPreview == null) { Rect rect = new Rect(getFramingRect()); Point cameraResolution = configManager.getCameraResolution(); Point screenResolution = configManager.getScreenResolution(); //modify here // rect.left = rect.left * cameraResolution.x / screenResolution.x; // rect.right = rect.right * cameraResolution.x / screenResolution.x; // rect.top = rect.top * cameraResolution.y / screenResolution.y; // rect.bottom = rect.bottom * cameraResolution.y / screenResolution.y; rect.left = rect.left * cameraResolution.y / screenResolution.x; rect.right = rect.right * cameraResolution.y / screenResolution.x; rect.top = rect.top * cameraResolution.x / screenResolution.y; rect.bottom = rect.bottom * cameraResolution.x / screenResolution.y; framingRectInPreview = rect; } return framingRectInPreview; }
@Override public void draw(Canvas canvas) { if (!mWillDraw) { return; } Rect bounds = getBounds(); float width = 50; float height = 50; // Position the badge in the top-right quadrant of the icon. float radius = ((Math.min(width, height) / 2) - 1) / 2; float centerX = width - radius - 1; float centerY = radius + 1; // Draw badge circle. canvas.drawCircle(centerX, centerY, radius, mBadgePaint); // Draw badge count text inside the circle. mTextPaint.getTextBounds(mCount, 0, mCount.length(), mTxtRect); float textHeight = mTxtRect.bottom - mTxtRect.top; float textY = centerY + (textHeight / 2f); canvas.drawText(mCount, centerX, textY, mTextPaint); }
public TMReminderTagsView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); if (mDensity == -1) { initWith(context); } textPaint = new TextPaint(); textPaint.setAntiAlias(true); textPaint.setColor(Color.rgb(255, 59, 68)); textPaint.setTextSize(dp2px(10)); bgPaint = new Paint(); bgPaint.setColor(Color.rgb(250, 211, 213)); tagsGap = dp2px(7); hPadding = dp2px(3); tagRect = new Rect(); textFontMetrics = textPaint.getFontMetrics(); }
@Override protected Rect getDividerBound(int position, RecyclerView parent, View child) { Rect bounds = new Rect(0, 0, 0, 0); int transitionX = (int) ViewCompat.getTranslationX(child); int transitionY = (int) ViewCompat.getTranslationY(child); RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); bounds.left = parent.getPaddingLeft() + mMarginProvider.dividerLeftMargin(position, parent) + transitionX; bounds.right = parent.getWidth() - parent.getPaddingRight() - mMarginProvider.dividerRightMargin(position, parent) + transitionX; int dividerSize = getDividerSize(position, parent); if (mDividerType == DividerType.DRAWABLE) { bounds.top = child.getBottom() + params.topMargin + transitionY; bounds.bottom = bounds.top + dividerSize; } else { bounds.top = child.getBottom() + params.topMargin + dividerSize / 2 + transitionY; bounds.bottom = bounds.top; } return bounds; }
/** * 转为圆形图片 * * @param src 源图片 * @param recycle 是否回收 * @return 圆形图片 */ public static Bitmap toRound(final Bitmap src, final boolean recycle) { if (isEmptyBitmap(src)) return null; int width = src.getWidth(); int height = src.getHeight(); int radius = Math.min(width, height) >> 1; Bitmap ret = Bitmap.createBitmap(width, height, src.getConfig()); Paint paint = new Paint(); Canvas canvas = new Canvas(ret); Rect rect = new Rect(0, 0, width, height); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); canvas.drawCircle(width >> 1, height >> 1, radius, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(src, rect, rect, paint); if (recycle && !src.isRecycled()) src.recycle(); return ret; }
public ViewfinderView(Context context, AttributeSet attrs) { super(context, attrs); // Initialize these once for performance rather than calling them every // time in onDraw(). paint = new Paint(); Resources resources = getResources(); maskColor = resources.getColor(R.color.viewfinder_mask); resultColor = resources.getColor(R.color.result_view); resultPointColor = resources.getColor(R.color.possible_result_points); possibleResultPoints = new HashSet<ResultPoint>(5); path = new Path(); lineRect = new Rect(); /** * 获取屏幕密度 */ density = context.getResources().getDisplayMetrics().density; ScreenRate = (int) (20 * density); }
/** * 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; 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); } }
void layoutLayDown() { View surfaceView = getSurfaceView(); Rect surfaceRect = mViewBoundCache.get(surfaceView); if (surfaceRect == null) surfaceRect = computeSurfaceLayoutArea(false); if (surfaceView != null) { surfaceView.layout(surfaceRect.left, surfaceRect.top, surfaceRect.right, surfaceRect.bottom); bringChildToFront(surfaceView); } View currentBottomView = getCurrentBottomView(); Rect bottomViewRect = mViewBoundCache.get(currentBottomView); if (bottomViewRect == null) bottomViewRect = computeBottomLayoutAreaViaSurface(ShowMode.LayDown, surfaceRect); if (currentBottomView != null) { currentBottomView.layout(bottomViewRect.left, bottomViewRect.top, bottomViewRect.right, bottomViewRect.bottom); } }
/** * Fill right of the center view * * @param recycler * @param startPosition start position to fill right * @param startOffset layout start offset * @param rightEdge */ private void fillRight(RecyclerView.Recycler recycler, int startPosition, int startOffset, int rightEdge) { View scrap; int topOffset; int scrapWidth, scrapHeight; Rect scrapRect = new Rect(); int height = getVerticalSpace(); for (int i = startPosition; i < getItemCount() && startOffset < rightEdge; i++) { scrap = recycler.getViewForPosition(i); addView(scrap); measureChildWithMargins(scrap, 0, 0); scrapWidth = getDecoratedMeasuredWidth(scrap); scrapHeight = getDecoratedMeasuredHeight(scrap); topOffset = (int) (getPaddingTop() + (height - scrapHeight) / 2.0f); scrapRect.set(startOffset, topOffset, startOffset + scrapWidth, topOffset + scrapHeight); layoutDecorated(scrap, scrapRect.left, scrapRect.top, scrapRect.right, scrapRect.bottom); startOffset = scrapRect.right; mLastVisiblePos = i; if (getState().mItemsFrames.get(i) == null) { getState().mItemsFrames.put(i, scrapRect); } else { getState().mItemsFrames.get(i).set(scrapRect); } } }
@Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { // outRect.left = space; // outRect.right = space; // outRect.bottom = space; outRect.set(0, 20, 20, 20); // Add top margin only for the first item to avoid double space between items // if (parent.getChildLayoutPosition(view) == 0) { // outRect.top = space; // } else { // outRect.top = 0; // } }
private Bitmap getCircleBitmap(final int radius) { final Bitmap output = Bitmap.createBitmap(originBitmap.getWidth(), originBitmap.getHeight(), Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(output); final Paint paint = new Paint(); final Rect rect = new Rect((int)(x - radius), (int)(y - radius), (int)(x + radius), (int)(y + radius)); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); canvas.drawCircle(x, y, radius, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(originBitmap, rect, rect, paint); return output; }
public static Bitmap getCroppedBitmap(Bitmap bitmap) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getWidth() / 2, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
public NestedScrollView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); this.mTempRect = new Rect(); this.mIsLayoutDirty = true; this.mIsLaidOut = false; this.mChildToScrollTo = null; this.mIsBeingDragged = false; this.mSmoothScrollingEnabled = true; this.mActivePointerId = -1; this.mScrollOffset = new int[2]; this.mScrollConsumed = new int[2]; initScrollView(); TypedArray a = context.obtainStyledAttributes(attrs, SCROLLVIEW_STYLEABLE, defStyleAttr, 0); setFillViewport(a.getBoolean(0, false)); a.recycle(); this.mParentHelper = new NestedScrollingParentHelper(this); this.mChildHelper = new NestedScrollingChildHelper(this); setNestedScrollingEnabled(true); ViewCompat.setAccessibilityDelegate(this, ACCESSIBILITY_DELEGATE); }
private void init() { Log.i(Tag, "init"); mLineWidth = changeDp(1); mLineHeight = changeDp(3); mFixLineHeight = changeDp(6); mSunRadius = changeDp(12); mLineColor = Color.RED; mLineLevel = 30; //线的配置 mLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG); mLinePaint.setColor(mLineColor); mLinePaint.setStyle(Paint.Style.FILL_AND_STROKE); // 设置画笔宽度 mLinePaint.setStrokeWidth(mLineWidth); mDrawFilter = new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG); debugRect = new Rect(); mouthRect = new RectF(); }
Rect getItemDecorInsetsForChild(View child) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (!lp.mInsetsDirty) { return lp.mDecorInsets; } final Rect insets = lp.mDecorInsets; insets.set(0, 0, 0, 0); final int decorCount = mItemDecorations.size(); for (int i = 0; i < decorCount; i++) { mTempRect.set(0, 0, 0, 0); mItemDecorations.get(i).getItemOffsets(mTempRect, child, this, mState); insets.left += mTempRect.left; insets.top += mTempRect.top; insets.right += mTempRect.right; insets.bottom += mTempRect.bottom; } lp.mInsetsDirty = false; return insets; }
private Rect getRect(View view) { Rect rect = new Rect(); rect.top = view.getTop(); rect.left = view.getLeft(); rect.right = view.getRight(); rect.bottom = view.getBottom(); ViewParent viewParent = view.getParent(); if (viewParent != null) { if (viewParent instanceof ViewGroup) { Rect prect = getRect((ViewGroup) viewParent); rect.top += prect.top; rect.left += prect.left; rect.right += prect.left; rect.bottom += prect.top; } } return rect; }
private void drawShadow(Canvas canvas, View child) { final Rect childRect = mTmpRect; child.getHitRect(childRect); if ((mEdgeFlag & EDGE_LEFT) != 0) { mShadowLeft.setBounds(childRect.left - mShadowLeft.getIntrinsicWidth(), childRect.top, childRect.left, childRect.bottom); mShadowLeft.setAlpha((int) (mScrimOpacity * FULL_ALPHA)); mShadowLeft.draw(canvas); } if ((mEdgeFlag & EDGE_RIGHT) != 0) { mShadowRight.setBounds(childRect.right, childRect.top, childRect.right + mShadowRight.getIntrinsicWidth(), childRect.bottom); mShadowRight.setAlpha((int) (mScrimOpacity * FULL_ALPHA)); mShadowRight.draw(canvas); } if ((mEdgeFlag & EDGE_BOTTOM) != 0) { mShadowBottom.setBounds(childRect.left, childRect.bottom, childRect.right, childRect.bottom + mShadowBottom.getIntrinsicHeight()); mShadowBottom.setAlpha((int) (mScrimOpacity * FULL_ALPHA)); mShadowBottom.draw(canvas); } }
/** * {@inheritDoc} */ @Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { int position = parent.getChildAdapterPosition(view); int headerHeight = 0; if (position != RecyclerView.NO_POSITION && hasHeader(parent, adapter, position)) { View header = getHeader(parent, adapter, position).itemView; headerHeight = getHeaderHeightForLayout(header); } outRect.set(0, headerHeight, 0, 0); }
private void scaleRect(Rect rect, float scale) { if (scale != 1.0f) { rect.left = (int) (rect.left * scale + 0.5f); rect.top = (int) (rect.top * scale + 0.5f); rect.right = (int) (rect.right * scale + 0.5f); rect.bottom = (int) (rect.bottom * scale + 0.5f); } }
@Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { final RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();//布局管理器 final RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) view.getLayoutParams(); final int viewLayoutPosition = layoutParams.getViewLayoutPosition();//布局时当前View的位置 final int viewAdapterPosition = layoutParams.getViewAdapterPosition(); getItemOffsets(outRect, layoutManager, viewAdapterPosition, getEdge(viewAdapterPosition, layoutManager)); }
private boolean isInIgnoredView(MotionEvent ev) { Rect rect = new Rect(); for (View v : mIgnoredViews) { v.getHitRect(rect); if (rect.contains((int) ev.getX(), (int) ev.getY())) { return true; } } return false; }
/** * 保存截图到sd卡 并返回截图路径 * @param activity * @return */ public String getScreenShut(Activity activity){ View view = activity.getWindow().getDecorView(); view.setDrawingCacheEnabled(true); view.buildDrawingCache(); Bitmap b1 = view.getDrawingCache(); // 获取状态栏高度 Rect frame = new Rect(); activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); int statusBarHeight = frame.top; // 获取屏幕长和高 int width = activity.getWindowManager().getDefaultDisplay().getWidth(); int height = activity.getWindowManager().getDefaultDisplay() .getHeight(); // 去掉标题栏 Bitmap b = Bitmap.createBitmap(b1, 0, statusBarHeight, width, height - statusBarHeight); view.destroyDrawingCache(); //保存到sd卡 String sdCardRoot = Environment.getExternalStorageDirectory().getAbsolutePath(); String fileName = "shareIMG"+new Date().getTime()+".png"; String path = sdCardRoot+"/HuoCheXing/shareImage/"+fileName; if(saveBitmapToSDCard(b,path)){ return path; } return null; }
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; }
public void setDelegateAreaColor(@ColorInt int color, Rect rect) { paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setColor(color); this.rect = rect; invalidate(); }
/** * Aligns the shadow with {@param view} * @param viewParent immediate parent of {@param view}. It must be a sibling of this view. */ public void alignWithIconView(BubbleTextView view, ViewGroup viewParent, View clipAgainstView) { float leftShift = view.getLeft() + viewParent.getLeft() - getLeft(); float topShift = view.getTop() + viewParent.getTop() - getTop(); int iconWidth = view.getRight() - view.getLeft(); int iconHeight = view.getBottom() - view.getTop(); int iconHSpace = iconWidth - view.getCompoundPaddingRight() - view.getCompoundPaddingLeft(); float drawableWidth = view.getIcon().getBounds().width(); if (clipAgainstView != null) { // Set the bounds to clip against int[] coords = new int[] {0, 0}; Utilities.getDescendantCoordRelativeToAncestor(clipAgainstView, (View) getParent(), coords, false); int clipLeft = (int) Math.max(0, coords[0] - leftShift - mShadowPadding); int clipTop = (int) Math.max(0, coords[1] - topShift - mShadowPadding) ; setClipBounds(new Rect(clipLeft, clipTop, clipLeft + iconWidth, clipTop + iconHeight)); } else { // Reset the clip bounds setClipBounds(null); } setTranslationX(leftShift + viewParent.getTranslationX() + view.getCompoundPaddingLeft() * view.getScaleX() + (iconHSpace - drawableWidth) * view.getScaleX() / 2 /* drawable gap */ + iconWidth * (1 - view.getScaleX()) / 2 /* gap due to scale */ - mShadowPadding /* extra shadow size */ ); setTranslationY(topShift + viewParent.getTranslationY() + view.getPaddingTop() * view.getScaleY() /* drawable gap */ + view.getHeight() * (1 - view.getScaleY()) / 2 /* gap due to scale */ - mShadowPadding /* extra shadow size */ ); }