public void drawScaledImage( Image Image, int x, int y, int width, int height, /* int srcX,int srcY, int srcWidth, int srcHeight,*/ float scale /*,int originX, int originY*/) { /*srcRect.left=srcX; srcRect.top=srcY; srcRect.right=srcX+srcWidth; srcRect.bottom=srcY+srcHeight;*/ srcRect.left = 0; srcRect.top = 0; srcRect.right = Image.getWidth(); srcRect.bottom = Image.getHeight(); dstRect.left = (int) (x); dstRect.top = (int) (((y))); dstRect.right = (int) (((x + (width * scale)))); dstRect.bottom = (int) (((y + (height * scale)))); /* dstRect.left= (int) (originX+((x-originX)*scale)); dstRect.top=(int) (originY+((y-originY)*scale)); dstRect.right=(int) (originX+((x+width-originX)*scale)); dstRect.bottom=(int) (originY+((y+height-originY)*scale));*/ canvas.drawBitmap(((AndroidImage) Image).bitmap, srcRect, dstRect, null); }
@Override public void setParameter(ZDepthParam param, int left, int top, int right, int bottom) { mRectTopShadow.left = left; mRectTopShadow.top = (int) (top + param.mOffsetYTopShadowPx); mRectTopShadow.right = right; mRectTopShadow.bottom = (int) (bottom + param.mOffsetYTopShadowPx); mRectBottomShadow.left = left; mRectBottomShadow.top = (int) (top + param.mOffsetYBottomShadowPx); mRectBottomShadow.right = right; mRectBottomShadow.bottom = (int) (bottom + param.mOffsetYBottomShadowPx); mTopShadow.getPaint().setColor(Color.argb(param.mAlphaTopShadow, 0, 0, 0)); if (0 < param.mBlurTopShadowPx) { mTopShadow .getPaint() .setMaskFilter(new BlurMaskFilter(param.mBlurTopShadowPx, BlurMaskFilter.Blur.NORMAL)); } else { mTopShadow.getPaint().setMaskFilter(null); } mBottomShadow.getPaint().setColor(Color.argb(param.mAlphaBottomShadow, 0, 0, 0)); if (0 < param.mBlurBottomShadowPx) { mBottomShadow .getPaint() .setMaskFilter(new BlurMaskFilter(param.mBlurBottomShadowPx, BlurMaskFilter.Blur.NORMAL)); } else { mBottomShadow.getPaint().setMaskFilter(null); } }
public void calculateTapAreaByTopLeft( int focusWidth, int focusHeight, float areaMultiple, int top, int left, int previewWidth, int previewHeight, Rect rect) { int areaWidth = (int) (focusWidth * areaMultiple); int areaHeight = (int) (focusHeight * areaMultiple); int right = Util.clamp(left + areaWidth, areaWidth, previewWidth); int bottom = Util.clamp(top + areaHeight, areaHeight, previewHeight); RectF rectF = new RectF(left, top, right, bottom); mMatrix.mapRect(rectF); Util.rectFToRect(rectF, rect); if (rect.left < -1000) rect.left = -1000; if (rect.left > 1000) rect.left = 1000; if (rect.right < -1000) rect.right = -1000; if (rect.right > 1000) rect.right = 1000; if (rect.top < -1000) rect.top = -1000; if (rect.top > 1000) rect.top = 1000; if (rect.bottom < -1000) rect.bottom = -1000; if (rect.bottom > 1000) rect.bottom = 1000; }
BorderCropDrawable( Drawable child, boolean cropLeft, boolean cropTop, boolean cropRight, boolean cropBottom) { mChild = child; mBoundsShift = new Rect(); mPadding = new Rect(); mChild.getPadding(mPadding); if (cropLeft) { mBoundsShift.left = -mPadding.left; mPadding.left = 0; } if (cropTop) { mBoundsShift.top = -mPadding.top; mPadding.top = 0; } if (cropRight) { mBoundsShift.right = mPadding.right; mPadding.right = 0; } if (cropBottom) { mBoundsShift.bottom = mPadding.bottom; mPadding.bottom = 0; } }
/** * 获取扫描框相对于预览界面的矩形 * * @param cameraPreviewSize 相机预览分辨率 * @return 扫描框相对的预览界面的矩形 */ public Rect getRectInPreview(Camera.Size cameraPreviewSize) { if (rectInPreview == null) { // 在相对于屏幕的矩形的基础上创建相对于预览界面的矩形,然后在修改其各项属性 rectInPreview = new Rect(getRectInScreen()); // 获取屏幕分辨率 WindowManager windowManager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); Display display = windowManager.getDefaultDisplay(); // 如果是横屏 if (getContext().getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { rectInPreview.left = rectInPreview.left * cameraPreviewSize.width / display.getWidth(); rectInPreview.right = rectInPreview.right * cameraPreviewSize.width / display.getWidth(); rectInPreview.top = rectInPreview.top * cameraPreviewSize.height / display.getHeight(); rectInPreview.bottom = rectInPreview.bottom * cameraPreviewSize.height / display.getHeight(); } else { rectInPreview.left = rectInPreview.left * cameraPreviewSize.height / display.getWidth(); rectInPreview.right = rectInPreview.right * cameraPreviewSize.height / display.getWidth(); rectInPreview.top = rectInPreview.top * cameraPreviewSize.width / display.getHeight(); rectInPreview.bottom = rectInPreview.bottom * cameraPreviewSize.width / display.getHeight(); } } return rectInPreview; }
@Override public void draw(Canvas c, Layer l) { if (layer == l && alpha > 0) { paint.setAlpha(alpha); int width = numbers.getMinimumWidth() / 10; location.top = top; location.bottom = top + getPrologHeight(); location.left = left + (getWidth() - prolog.getMinimumWidth()) / 2; location.right = location.left + prolog.getMinimumWidth(); c.drawBitmap(prolog.getBitmap(), null, location, paint); source.top = 0; source.bottom = numbers.getIntrinsicHeight(); location.top = top + numbers_offset; location.bottom = top + getTotalHeight(); for (int i = digits - 1, n = number > 0 ? number : 0; i >= 0; --i, n = n / 10) { location.left = left + (getWidth() - width * digits) / 2 + i * width; location.right = location.left + width; source.left = (n % 10) * width; source.right = source.left + width; c.drawBitmap(numbers.getBitmap(), source, location, paint); } } }
@Override public void getItemOffsets( Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { int position = parent.getChildAdapterPosition(view); outRect.left = mSpace; outRect.right = mSpace; outRect.top = 0; outRect.bottom = mSpace; if (parent.getLayoutManager() instanceof StaggeredGridLayoutManager) { outRect.left = 0; outRect.right = 0; outRect.top = 0; outRect.bottom = 0; if (position < ((StaggeredGridLayoutManager) parent.getLayoutManager()).getSpanCount()) { // 利用item的margin配合RecyclerView的margin值使得间隔相等,这里只需设第一行item的相对顶部的高度 outRect.top = mSpace; } } else if (parent.getLayoutManager() instanceof GridLayoutManager) { if (position < ((GridLayoutManager) parent.getLayoutManager()).getSpanCount()) { // 保证第一行有相对顶部有高度 outRect.top = mSpace; } } else if (parent.getLayoutManager() instanceof LinearLayoutManager) { if (position == 0) { // 保证第一行有相对顶部有高度 outRect.top = mSpace; } } }
/** * Handles scrolling in response to a "home/end" shortcut press. This method will scroll the view * to the top or bottom and give the focus to the topmost/bottommost component in the new visible * area. If no component is a good candidate for focus, this scrollview reclaims the focus. * * @param direction the scroll direction: {@link android.view.View#FOCUS_UP} to go the top of the * view or {@link android.view.View#FOCUS_DOWN} to go the bottom * @return true if the key event is consumed by this method, false otherwise */ public boolean fullScroll(int direction, boolean horizontal) { if (!horizontal) { boolean down = direction == View.FOCUS_DOWN; int height = getHeight(); mTempRect.top = 0; mTempRect.bottom = height; if (down) { int count = getChildCount(); if (count > 0) { View view = getChildAt(count - 1); mTempRect.bottom = view.getBottom(); mTempRect.top = mTempRect.bottom - height; } } return scrollAndFocus(direction, mTempRect.top, mTempRect.bottom, 0, 0, 0); } else { boolean right = direction == View.FOCUS_DOWN; int width = getWidth(); mTempRect.left = 0; mTempRect.right = width; if (right) { int count = getChildCount(); if (count > 0) { View view = getChildAt(count - 1); mTempRect.right = view.getBottom(); mTempRect.left = mTempRect.right - width; } } return scrollAndFocus(0, 0, 0, direction, mTempRect.top, mTempRect.bottom); } }
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // TODO: handle vertical labels if (isEnabled() && mLabelLayout != null) { final int sweepHeight = mSweep.getIntrinsicHeight(); final int templateHeight = mLabelLayout.getHeight(); mSweepOffset.x = 0; mSweepOffset.y = 0; mSweepOffset.y = (int) ((templateHeight / 2) - getTargetInset()); setMeasuredDimension(mSweep.getIntrinsicWidth(), Math.max(sweepHeight, templateHeight)); } else { mSweepOffset.x = 0; mSweepOffset.y = 0; setMeasuredDimension(mSweep.getIntrinsicWidth(), mSweep.getIntrinsicHeight()); } if (mFollowAxis == VERTICAL) { final int targetHeight = mSweep.getIntrinsicHeight() - mSweepPadding.top - mSweepPadding.bottom; mMargins.top = -(mSweepPadding.top + (targetHeight / 2)); mMargins.bottom = 0; mMargins.left = -mSweepPadding.left; mMargins.right = mSweepPadding.right; } else { final int targetWidth = mSweep.getIntrinsicWidth() - mSweepPadding.left - mSweepPadding.right; mMargins.left = -(mSweepPadding.left + (targetWidth / 2)); mMargins.right = 0; mMargins.top = -mSweepPadding.top; mMargins.bottom = mSweepPadding.bottom; } mContentOffset.set(0, 0, 0, 0); // make touch target area larger final int widthBefore = getMeasuredWidth(); final int heightBefore = getMeasuredHeight(); if (mFollowAxis == HORIZONTAL) { final int widthAfter = widthBefore * 3; setMeasuredDimension(widthAfter, heightBefore); mContentOffset.left = (widthAfter - widthBefore) / 2; final int offset = mSweepPadding.bottom * 2; mContentOffset.bottom -= offset; mMargins.bottom += offset; } else { final int heightAfter = heightBefore * 2; setMeasuredDimension(widthBefore, heightAfter); mContentOffset.offset(0, (heightAfter - heightBefore) / 2); final int offset = mSweepPadding.right * 2; mContentOffset.right -= offset; mMargins.right += offset; } mSweepOffset.offset(mContentOffset.left, mContentOffset.top); mMargins.offset(-mSweepOffset.x, -mSweepOffset.y); }
@Override protected void onDraw(Canvas canvas) { mPaint.setAntiAlias(true); mPaint.setStrokeWidth(mCircleWidth); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStyle(Paint.Style.STROKE); int center = getWidth() / 2; int radius = center - mCircleWidth / 2; drawOval(canvas, center, radius); int relRadius = radius - mCircleWidth / 2; mRect.left = (int) (relRadius - Math.sqrt(2) * 1.0f / 2 * relRadius) + mCircleWidth; mRect.top = (int) (relRadius - Math.sqrt(2) * 1.0f / 2 * relRadius) + mCircleWidth; mRect.bottom = (int) (mRect.left + Math.sqrt(2) * relRadius); mRect.right = (int) (mRect.left + Math.sqrt(2) * relRadius); /** 如果图片比较小,那么根据图片的尺寸放置到正中心 */ if (mImage.getWidth() < Math.sqrt(2) * relRadius) { mRect.left = (int) (mRect.left + Math.sqrt(2) * relRadius * 1.0f / 2 - mImage.getWidth() * 1.0f / 2); mRect.top = (int) (mRect.top + Math.sqrt(2) * relRadius * 1.0f / 2 - mImage.getHeight() * 1.0f / 2); mRect.right = (int) (mRect.left + mImage.getWidth()); mRect.bottom = (int) (mRect.top + mImage.getHeight()); } // 绘图 canvas.drawBitmap(mImage, null, mRect, mPaint); }
private void computeDirtyRect(int d) { dirtyRectTop = dirtyRectLeft = Integer.MAX_VALUE; dirtyRectBottom = dirtyRectRight = -1; int i = 0; for (int row = 0; row < trsScreenRows; row++) { for (int col = 0; col < trsScreenCols / d; col++) { if (lastScreenBuffer[i] != screenBuffer[i]) { if (dirtyRectTop > row) { dirtyRectTop = row; } if (dirtyRectBottom < row) { dirtyRectBottom = row; } if (dirtyRectLeft > col) { dirtyRectLeft = col; } if (dirtyRectRight < col) { dirtyRectRight = col; } lastScreenBuffer[i] = screenBuffer[i]; } i += d; } } if (dirtyRectBottom == -1) { return; } clipRect.left = adjustedClipRect.left = trsCharWidth * dirtyRectLeft * d; clipRect.right = adjustedClipRect.right = trsCharWidth * (dirtyRectRight + 1) * d; clipRect.top = adjustedClipRect.top = trsCharHeight * dirtyRectTop; clipRect.bottom = adjustedClipRect.bottom = trsCharHeight * (dirtyRectBottom + 1); }
@Override public void getItemOffsets(Rect outRect, View view, RecyclerView rv, RecyclerView.State state) { super.getItemOffsets(outRect, view, rv, state); debugLog("getItemOffsets"); debugLog("View top = " + view.getTop()); if (selectedDragItemPos != -1) { int itemPos = rv.getChildPosition(view); debugLog("itemPos =" + itemPos); if (!canDragOver(itemPos)) { return; } // Movement of finger float totalMovement = fingerY - fingerAnchorY; if (itemPos == selectedDragItemPos) { view.setVisibility(View.INVISIBLE); } else { // Make view visible incase invisible view.setVisibility(View.VISIBLE); // Find middle of the floatingItem float floatMiddleY = floatingItemBounds.top + floatingItemBounds.height() / 2; // Moving down the list // These will auto-animate if the device continually sends touch motion events // if (totalMovment>0) { if ((itemPos > selectedDragItemPos) && (view.getTop() < floatMiddleY)) { float amountUp = (floatMiddleY - view.getTop()) / (float) view.getHeight(); // amountUp *= 0.5f; if (amountUp > 1) amountUp = 1; outRect.top = -(int) (floatingItemBounds.height() * amountUp); outRect.bottom = (int) (floatingItemBounds.height() * amountUp); } } // Moving up the list // else if (totalMovment < 0) { if ((itemPos < selectedDragItemPos) && (view.getBottom() > floatMiddleY)) { float amountDown = ((float) view.getBottom() - floatMiddleY) / (float) view.getHeight(); // amountDown *= 0.5f; if (amountDown > 1) amountDown = 1; outRect.top = (int) (floatingItemBounds.height() * amountDown); outRect.bottom = -(int) (floatingItemBounds.height() * amountDown); } } } } else { outRect.top = 0; outRect.bottom = 0; // Make view visible incase invisible view.setVisibility(View.VISIBLE); } }
/** * Computes the offsets based on the vertical and horizontal spacing values. The spacing * computation has to ensure that the lane sizes are the same after applying the offsets. This * means we have to shift the spacing unevenly across items depending on their position in the * layout. */ public void getItemOffsets(Rect outRect, int itemPosition, RecyclerView parent) { final BaseLayoutManager lm = (BaseLayoutManager) parent.getLayoutManager(); lm.getLaneForPosition(mTempLaneInfo, itemPosition, TwoWayLayoutManager.Direction.END); final int lane = mTempLaneInfo.startLane; final int laneSpan = lm.getLaneSpanForPosition(itemPosition); final int laneCount = lm.getLanes().getCount(); final int itemCount = parent.getAdapter().getItemCount(); final boolean isVertical = lm.isVertical(); final boolean firstLane = (lane == 0); final boolean secondLane = isSecondLane(lm, itemPosition, lane); final boolean lastLane = (lane + laneSpan == laneCount); final boolean beforeLastLane = (lane + laneSpan == laneCount - 1); final int laneSpacing = (isVertical ? mHorizontalSpacing : mVerticalSpacing); final int laneOffsetStart; final int laneOffsetEnd; if (firstLane) { laneOffsetStart = 0; } else if (lastLane && !secondLane) { laneOffsetStart = (int) (laneSpacing * 0.75); } else if (secondLane && !lastLane) { laneOffsetStart = (int) (laneSpacing * 0.25); } else { laneOffsetStart = (int) (laneSpacing * 0.5); } if (lastLane) { laneOffsetEnd = 0; } else if (firstLane && !beforeLastLane) { laneOffsetEnd = (int) (laneSpacing * 0.75); } else if (beforeLastLane && !firstLane) { laneOffsetEnd = (int) (laneSpacing * 0.25); } else { laneOffsetEnd = (int) (laneSpacing * 0.5); } final boolean isFirstInLane = isFirstChildInLane(lm, itemPosition); final boolean isLastInLane = !mAddSpacingAtEnd && isLastChildInLane(lm, itemPosition, itemCount); if (isVertical) { outRect.left = laneOffsetStart; outRect.top = (isFirstInLane ? 0 : mVerticalSpacing / 2); outRect.right = laneOffsetEnd; outRect.bottom = (isLastInLane ? 0 : mVerticalSpacing / 2); } else { outRect.left = (isFirstInLane ? 0 : mHorizontalSpacing / 2); outRect.top = laneOffsetStart; outRect.right = (isLastInLane ? 0 : mHorizontalSpacing / 2); outRect.bottom = laneOffsetEnd; } }
public void drawImage( Image Image, int x, int y, int srcX, int srcY, int srcWidth, int srcHeight) { srcRect.left = srcX; srcRect.top = srcY; srcRect.right = srcX + srcWidth; srcRect.bottom = srcY + srcHeight; dstRect.left = x; dstRect.top = y; dstRect.right = x + srcWidth; dstRect.bottom = y + srcHeight; canvas.drawBitmap(((AndroidImage) Image).bitmap, srcRect, dstRect, null); }
@Override public void drawPixmap( Pixmap pixmap, int x, int y, int srcX, int srcY, int srcWidth, int srcHeight) { srcRect.left = srcX; srcRect.top = srcY; srcRect.right = srcX + srcWidth - 1; srcRect.bottom = srcY + srcHeight - 1; dstRect.left = x; dstRect.top = y; dstRect.right = x + srcWidth - 1; dstRect.bottom = y + srcHeight - 1; canvas.drawBitmap(((AndroidPixmap) pixmap).bitmap, srcRect, dstRect, null); }
/** * This will generate a bitmap with the pattern as big as the rectangle we were allow to draw on. * We do this to chache the bitmap so we don't need to recreate it each time draw() is called * since it takes a few milliseconds. */ private void generatePatternBitmap() { if (getBounds().width() <= 0 || getBounds().height() <= 0) { return; } mBitmap = Bitmap.createBitmap(getBounds().width(), getBounds().height(), Config.ARGB_8888); Canvas canvas = new Canvas(mBitmap); Rect r = new Rect(); boolean verticalStartWhite = true; for (int i = 0; i <= numRectanglesVertical; i++) { boolean isWhite = verticalStartWhite; for (int j = 0; j <= numRectanglesHorizontal; j++) { r.top = i * mRectangleSize; r.left = j * mRectangleSize; r.bottom = r.top + mRectangleSize; r.right = r.left + mRectangleSize; canvas.drawRect(r, isWhite ? mPaintWhite : mPaintGray); isWhite = !isWhite; } verticalStartWhite = !verticalStartWhite; } }
private void initialize(Context context, AttributeSet attrs, int defStyleAttr) { TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.CardView, defStyleAttr, R.style.CardView_Light); int backgroundColor = a.getColor(R.styleable.CardView_cardBackgroundColor, 0); float radius = a.getDimension(R.styleable.CardView_cardCornerRadius, 0); float elevation = a.getDimension(R.styleable.CardView_cardElevation, 0); float maxElevation = a.getDimension(R.styleable.CardView_cardMaxElevation, 0); mCompatPadding = a.getBoolean(R.styleable.CardView_cardUseCompatPadding, false); mPreventCornerOverlap = a.getBoolean(R.styleable.CardView_cardPreventCornerOverlap, true); int defaultPadding = a.getDimensionPixelSize(R.styleable.CardView_contentPadding, 0); mContentPadding.left = a.getDimensionPixelSize(R.styleable.CardView_contentPaddingLeft, defaultPadding); mContentPadding.top = a.getDimensionPixelSize(R.styleable.CardView_contentPaddingTop, defaultPadding); mContentPadding.right = a.getDimensionPixelSize(R.styleable.CardView_contentPaddingRight, defaultPadding); mContentPadding.bottom = a.getDimensionPixelSize(R.styleable.CardView_contentPaddingBottom, defaultPadding); if (elevation > maxElevation) { maxElevation = elevation; } a.recycle(); IMPL.initialize(this, context, backgroundColor, radius, elevation, maxElevation); }
@Override public void getItemOffsets( Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { super.getItemOffsets(outRect, view, parent, state); if (mDivider == null) { return; } int position = parent.getChildAdapterPosition(view); if (position == RecyclerView.NO_POSITION || (position == 0 && !mShowFirstDivider)) { return; } if (mOrientation == -1) getOrientation(parent); if (mOrientation == LinearLayoutManager.VERTICAL) { outRect.top = mDivider.getIntrinsicHeight(); if (mShowLastDivider && position == (state.getItemCount() - 1)) { outRect.bottom = outRect.top; } } else { outRect.left = mDivider.getIntrinsicWidth(); if (mShowLastDivider && position == (state.getItemCount() - 1)) { outRect.right = outRect.left; } } }
public void onClick(View v) { try { String pos = (String) v.getTag(); Intent intent = new Intent(LauncherIntent.Action.ACTION_VIEW_CLICK); intent.setComponent(mAppWidgetProvider); intent .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId) .putExtra(LauncherIntent.Extra.EXTRA_APPWIDGET_ID, mAppWidgetId); intent.putExtra(LauncherIntent.Extra.EXTRA_VIEW_ID, v.getId()); intent.putExtra(LauncherIntent.Extra.Scroll.EXTRA_LISTVIEW_ID, mListViewId); intent.putExtra(LauncherIntent.Extra.Scroll.EXTRA_ITEM_POS, pos); Rect srcRect = new Rect(); final int[] location = new int[2]; v.getLocationOnScreen(location); srcRect.left = location[0]; srcRect.top = location[1]; srcRect.right = srcRect.left + v.getWidth(); srcRect.bottom = srcRect.top + v.getHeight(); intent.putExtra(LauncherIntent.Extra.Scroll.EXTRA_SOURCE_BOUNDS, srcRect); v.getContext().sendBroadcast(intent); } catch (Exception e) { e.printStackTrace(); } }
/** Measures and layouts the scrollbar and decorations. */ public void updatePopAlphabetLayout() { // Prevent re-entry when RTL properties change as a side-effect of // resolving padding. if (mUpdatingLayout) { return; } mUpdatingLayout = true; updateContainerRect(); final Rect bounds = mTempBounds; measurePreview(mPrimaryText, bounds); applyLayout(mPrimaryText, bounds); measurePreview(mSecondaryText, bounds); applyLayout(mSecondaryText, bounds); if (mPreviewImage != null) { // Apply preview image padding. bounds.left -= mPreviewImage.getPaddingLeft(); bounds.top -= mPreviewImage.getPaddingTop(); bounds.right += mPreviewImage.getPaddingRight(); bounds.bottom += mPreviewImage.getPaddingBottom(); applyLayout(mPreviewImage, bounds); } }
private void updateIndicator() { // M: Theme manager @{ if (FeatureOption.MTK_THEMEMANAGER_APP) { Resources res = getContext().getResources(); int themeColor = res.getThemeMainColor(); if (themeColor != 0) { mLeftColor = themeColor; mMiddleColor = themeColor; } } // M: Theme manager @} int off = getPaddingTop() - getPaddingBottom(); if (off < 0) off = 0; mRect.top = off; mRect.bottom = getHeight(); if (mShowingGreen) { mColorGradientPaint.setShader( new LinearGradient( 0, 0, 0, off - 2, mRightColor & 0xffffff, mRightColor, Shader.TileMode.CLAMP)); } else { mColorGradientPaint.setShader( new LinearGradient( 0, 0, 0, off - 2, mMiddleColor & 0xffffff, mMiddleColor, Shader.TileMode.CLAMP)); } mEdgeGradientPaint.setShader( new LinearGradient(0, 0, 0, off / 2, 0x00a0a0a0, 0xffa0a0a0, Shader.TileMode.CLAMP)); }
public static Bitmap maskBitmap(Bitmap bitmap, Bitmap mask, int width, int height) { if (null == bitmap || mask == null) { return null; } // 定义期望大小的bitmap Xfermode mode = new PorterDuffXfermode(Mode.SRC_IN); Bitmap dstBmp = Bitmap.createBitmap(width, height, Config.ARGB_8888); // 定义一个画布 Canvas canvas = new Canvas(dstBmp); // 创建一个取消锯齿画笔 Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); // 定义需要绘制的某图片上的那一部分矩形空间 Rect src = new Rect(0, 0, mask.getWidth(), mask.getHeight()); // 定义需要将上面的矩形绘制成新的矩形大小 Rect dst = new Rect(0, 0, width, height); // 将蒙版图片绘制成imageview本身的大小,这样从大小才会和UE标注的一样大 canvas.drawBitmap(mask, src, dst, paint); // 设置两张图片的相交模式 // 至于这个函数介绍参考网址:http://blog.csdn.net/wm111/article/details/7299294 paint.setXfermode(mode); // 将src修改为需要添加mask的bitmap大小,因为是要将此bitmap整个添加上蒙版 src.right = bitmap.getWidth(); src.bottom = bitmap.getHeight(); // 在已经绘制的mask上叠加bitmap canvas.drawBitmap(bitmap, src, dst, paint); return dstBmp; }
// 새로운 도형을 목록에 추가한다. void AddNewShape() { Shape shape = new Shape(); int idx; boolean bFindIntersect; Rect rt = new Rect(); // 기존 도형과 겹치지 않는 새 위치를 찾는다. for (; ; ) { // 크기는 32, 48, 64 중 하나 선택 int Size = 32 + 16 * Rnd.nextInt(3); // 위치는 난수로 선택 rt.left = Rnd.nextInt(getWidth()); rt.top = Rnd.nextInt(getHeight()); rt.right = rt.left + Size; rt.bottom = rt.top + Size; // 화면을 벗어나면 안된다. if (rt.right > getWidth() || rt.bottom > getHeight()) { continue; } // 기존 도형 순회하며 겹치는지 조사한다. bFindIntersect = false; for (idx = 0; idx < arShape.size(); idx++) { if (rt.intersect(arShape.get(idx).rt) == true) { bFindIntersect = true; } } // 겹치지 않을 때 확정한다. 겹치면 계속 새 위치 선정한다. if (bFindIntersect == false) { break; } } // 새 도형 정보 작성. 모양, 색상 등을 난수 선택한다. shape.what = Rnd.nextInt(3); switch (Rnd.nextInt(5)) { case 0: shape.color = Color.WHITE; break; case 1: shape.color = Color.RED; break; case 2: shape.color = Color.GREEN; break; case 3: shape.color = Color.BLUE; break; case 4: shape.color = Color.YELLOW; break; } shape.rt = rt; arShape.add(shape); }
@Override public void getItemOffsets( Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { super.getItemOffsets(outRect, view, parent, state); if (size <= 0) { return; } if (showFirstDivider && parent.getChildLayoutPosition(view) < 1 || parent.getChildLayoutPosition(view) >= 1) { if (getOrientation(parent) == LinearLayoutManager.VERTICAL) { outRect.top = size; } else { outRect.left = size; } } if (showLastDivider && parent.getChildAdapterPosition(view) == getTotalItemCount(parent) - 1) { if (getOrientation(parent) == LinearLayoutManager.VERTICAL) { outRect.bottom = size; } else { outRect.right = size; } } }
public void move(int x, int y) { mDest.left = x - widthHalf; mDest.right = x + widthHalf; mDest.top = y - 2 * heightHalf; mDest.bottom = y; invalidate(); }
public void redraw(Canvas c, int width, int height, float now, float totalTime) { // window [-2.0, 1.0, -1.5, 1.5] float dperiod = period * 2 * 10; float ratio = (now % dperiod) / dperiod; float trans; dstR.right = width; dstR.bottom = height; c.drawBitmap(background, srcR, dstR, null); if (ratio > 0.5) trans = (1 - ratio) * 50; else trans = ratio * 50; float radius = width / 2; pTag.setColor(Color.argb((int) (trans * 0.7), 255, 255, 255)); c.drawCircle(width / 4, height / 2, radius, pTag); pTag.setColor(Color.argb((int) (trans * 0.4), 255, 255, 255)); c.drawCircle(width / 4 - 20, height / 2 + 20, radius * 0.7f, pTag); pTag.setColor(Color.argb((int) trans, 255, 255, 255)); c.drawCircle(width / 4, height / 2, radius * 0.4f, pTag); }
@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.top = parent.getPaddingTop() + mMarginProvider.dividerTopMargin(position, parent) + transitionY; bounds.bottom = parent.getHeight() - parent.getPaddingBottom() - mMarginProvider.dividerBottomMargin(position, parent) + transitionY; int dividerSize = getDividerSize(position, parent); if (mDividerType == DividerType.DRAWABLE) { bounds.left = child.getRight() + params.leftMargin + transitionX; bounds.right = bounds.left + dividerSize; } else { bounds.left = child.getRight() + params.leftMargin + dividerSize / 2 + transitionX; bounds.right = bounds.left; } return bounds; }
@Override public boolean onLoadInt(int command_, int intData_) { try { switch (command_) { case FILECOMMAND_RELATIVEIMAGESTATEBITMAPRECTLEFT: _BitmapRect.left = intData_; break; case FILECOMMAND_RELATIVEIMAGESTATEBITMAPRECTTOP: _BitmapRect.top = intData_; break; case FILECOMMAND_RELATIVEIMAGESTATEBITMAPRECTRIGHT: _BitmapRect.right = intData_; break; case FILECOMMAND_RELATIVEIMAGESTATEBITMAPRECTBOTTOM: _BitmapRect.bottom = intData_; break; // case FILECOMMAND_RELATIVEIMAGESTATEPOSLEFT: // _PositionRect.left = intData_; // break; // case FILECOMMAND_RELATIVEIMAGESTATEPOSTOP: // _PositionRect.top = intData_; // break; // case FILECOMMAND_RELATIVEIMAGESTATEPOSRIGHT: // _PositionRect.right = intData_; // break; // case FILECOMMAND_RELATIVEIMAGESTATEPOSBOTTOM: // _PositionRect.bottom = intData_; // break; } } catch (Exception e) { return false; } return true; }
public final void onDraw$13fcd2ff(Canvas paramCanvas, RecyclerView paramRecyclerView) { this.mCardStackBoundsRect.setEmpty(); int i = paramRecyclerView.getChildCount(); for (int j = 0; j < i; j++) { View localView = paramRecyclerView.getChildAt(j); if ((localView instanceof CardSection)) { boolean bool = localView instanceof DetailsPeekingSection; int k = 0; if (bool) { k = ((DetailsPeekingSection) localView).getTopPeekAmount(); } this.mCardStackBoundsRect.union( localView.getLeft(), k + localView.getTop(), localView.getRight(), localView.getBottom()); } } if (this.mCardStackBoundsRect.isEmpty()) { return; } Rect localRect1 = this.mCardStackBoundsRect; localRect1.left -= this.mVerticalPadding; Rect localRect2 = this.mCardStackBoundsRect; localRect2.top -= this.mVerticalPadding; Rect localRect3 = this.mCardStackBoundsRect; localRect3.right += this.mVerticalPadding; Rect localRect4 = this.mCardStackBoundsRect; localRect4.bottom += this.mVerticalPadding; this.mCardDrawable.setBounds(this.mCardStackBoundsRect); this.mCardDrawable.draw(paramCanvas); }
private void drawSurface(Bitmap bmp) { if (bmp != null) { Rect srcRect = new Rect(0, 0, bmp.getWidth(), bmp.getHeight()); Rect dstRect = new Rect(0, 0, sv.getWidth(), sv.getHeight()); int ew = bmp.getWidth() * sv.getHeight() / bmp.getHeight(); if (ew < bmp.getWidth()) { dstRect.right = ew; dstRect.bottom = bmp.getHeight() * ew / bmp.getWidth(); } int dx = (sv.getWidth() - dstRect.right) >> 1; int dy = (sv.getHeight() - dstRect.bottom) >> 1; dstRect.offset(dx, dy); synchronized (sh) { Log.d(TAG, "Start drawing bmp"); Canvas canvas = sh.lockCanvas(); if (canvas != null) { canvas.drawColor(Color.BLACK); canvas.drawBitmap(bmp, srcRect, dstRect, null); sh.unlockCanvasAndPost(canvas); } Log.d(TAG, "Stop bmp"); } } }