Java Code Examples for android.graphics.Rect

The following are top voted examples for showing how to use android.graphics.Rect. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: ceji_android   File: CenteredImageSpan.java   View source code 6 votes vote down vote up
@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;
}
 
Example 2
Project: tenor-android-demo-search   File: SearchSuggestionRecyclerView.java   View source code 6 votes vote down vote up
@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;
    }
}
 
Example 3
Project: weex-3d-map   File: ScreenShot.java   View source code 6 votes vote down vote up
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;

}
 
Example 4
Project: javaide   File: ProjectManagerActivity.java   View source code 6 votes vote down vote up
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();
    }
}
 
Example 5
Project: CSipSimple   File: SearchView.java   View source code 6 votes vote down vote up
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));
    }
}
 
Example 6
Project: GitHub   File: ForwardingDrawableTest.java   View source code 6 votes vote down vote up
@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);
}
 
Example 7
Project: MyAnimeViewer   File: HighlightView.java   View source code 6 votes vote down vote up
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();
}
 
Example 8
Project: UnversityFinance   File: ClearEditText.java   View source code 6 votes vote down vote up
@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();
        }
    }
}
 
Example 9
Project: JueDiQiuSheng   File: CoolWaitLoadingRenderer.java   View source code 6 votes vote down vote up
@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);
}
 
Example 10
Project: boohee_v5.6   File: SocialResHelper.java   View source code 6 votes vote down vote up
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;
}
 
Example 11
Project: GitHub   File: WheelView.java   View source code 6 votes vote down vote up
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;
    }
}
 
Example 12
Project: OpenYOLO-Android   File: ProviderPickerActivity.java   View source code 6 votes vote down vote up
@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);
}
 
Example 13
Project: letv   File: ViewfinderView.java   View source code 6 votes vote down vote up
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);
}
 
Example 14
Project: VirtualHook   File: PendIntentCompat.java   View source code 6 votes vote down vote up
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);
                }
            }
        }
    }
 
Example 15
Project: SmartRefreshLayout   File: MaterialProgressDrawable.java   View source code 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example 16
Project: MeiLa_GNN   File: CameraManager.java   View source code 6 votes vote down vote up
/**
     * 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;
    }
 
Example 17
Project: XERUNG   File: BadgeDrawable.java   View source code 6 votes vote down vote up
@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);
}
 
Example 18
Project: Virtualview-Android   File: TMReminderTagsView.java   View source code 6 votes vote down vote up
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();
}
 
Example 19
Project: RX_Demo   File: HorizontalDividerItemDecoration.java   View source code 6 votes vote down vote up
@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;
}
 
Example 20
Project: HeadlineNews   File: ImageUtils.java   View source code 6 votes vote down vote up
/**
 * 转为圆形图片
 *
 * @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;
}
 
Example 21
Project: Zxing   File: ViewfinderView.java   View source code 6 votes vote down vote up
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);
}
 
Example 22
Project: qmui   File: QMUIMaterialProgressDrawable.java   View source code 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example 23
Project: Views   File: SwipeLayout.java   View source code 6 votes vote down vote up
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);
    }
}
 
Example 24
Project: InfiniteTabsView   File: TabLayoutManager.java   View source code 6 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 25
Project: GitHub   File: ChargeAmountDividerDecoration.java   View source code 6 votes vote down vote up
@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;
//            }
        }
 
Example 26
Project: stynico   File: bilibili.java   View source code 6 votes vote down vote up
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;
   }
 
Example 27
Project: Lunary-Ethereum-Wallet   File: Blockies.java   View source code 6 votes vote down vote up
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;
}
 
Example 28
Project: letv   File: NestedScrollView.java   View source code 6 votes vote down vote up
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);
}
 
Example 29
Project: stynico   File: SunLineView.java   View source code 6 votes vote down vote up
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();
}
 
Example 30
Project: PlusGram   File: RecyclerView.java   View source code 6 votes vote down vote up
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;
}
 
Example 31
Project: TPlayer   File: PendIntentCompat.java   View source code 6 votes vote down vote up
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;
}
 
Example 32
Project: OSchina_resources_android   File: SwipeBackLayout.java   View source code 6 votes vote down vote up
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);
    }
}
 
Example 33
Project: PeSanKita-android   File: StickyHeaderDecoration.java   View source code 5 votes vote down vote up
/**
 * {@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);
}
 
Example 34
Project: DateTimePicker   File: NumberPicker.java   View source code 5 votes vote down vote up
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);
    }
}
 
Example 35
Project: RLibrary   File: RExItemDecoration.java   View source code 5 votes vote down vote up
@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));
}
 
Example 36
Project: ChatExchange-old   File: CustomViewAbove.java   View source code 5 votes vote down vote up
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;
}
 
Example 37
Project: Huochexing12306   File: ShareUtil.java   View source code 5 votes vote down vote up
/**
 * 保存截图到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;
}
 
Example 38
Project: SimpleUILauncher   File: DragPreviewProvider.java   View source code 5 votes vote down vote up
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;
}
 
Example 39
Project: AndroidDigIn   File: TouchDelegateViewGroup.java   View source code 5 votes vote down vote up
public void setDelegateAreaColor(@ColorInt int color, Rect rect) {
    paint = new Paint();
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(color);
    this.rect = rect;
    invalidate();
}
 
Example 40
Project: LaunchEnr   File: ClickShadowView.java   View source code 5 votes vote down vote up
/**
 * 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 */
            );
}