Search in sources :

Example 66 with Rect

use of android.graphics.Rect in project native-navigation by airbnb.

the class ViewUtils method getViewBounds.

/**
   * Gets the screen bounds of a view. This should be more accurate than
   * getScreenLocationMinusStatusBar since it doesn't need to estimate the status bar height. Try to
   * use this method if possible.
   *
   * @return Rect the view Rect(top, left, width, height) bounds on screen
   */
public static Rect getViewBounds(View view) {
    Rect loc = new Rect();
    int[] coords = new int[2];
    view.getLocationOnScreen(coords);
    loc.set(coords[0], coords[1], coords[0] + view.getWidth(), coords[1] + view.getHeight());
    return loc;
}
Also used : Rect(android.graphics.Rect)

Example 67 with Rect

use of android.graphics.Rect in project 9GAG by Mixiaoxiao.

the class MxxBlurView method init.

private void init() {
    mMatrixScale = new Matrix();
    mMatrixScaleInv = new Matrix();
    mCanvas = new Canvas();
    mRectVisibleGlobal = new Rect();
    radius = MxxUiUtil.dip2px(getContext(), radius);
    radius = Math.round(radius * BITMAP_SCALE_FACTOR);
}
Also used : Rect(android.graphics.Rect) Matrix(android.graphics.Matrix) Canvas(android.graphics.Canvas)

Example 68 with Rect

use of android.graphics.Rect in project Fragmentation by YoKeyword.

the class WechatFirstTabFragment method onLazyInitView.

@Override
public void onLazyInitView(@Nullable Bundle savedInstanceState) {
    super.onLazyInitView(savedInstanceState);
    mRefreshLayout.setOnRefreshListener(this);
    mRecy.setLayoutManager(new LinearLayoutManager(_mActivity));
    mRecy.setHasFixedSize(true);
    final int space = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 0.5f, getResources().getDisplayMetrics());
    mRecy.addItemDecoration(new RecyclerView.ItemDecoration() {

        @Override
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            outRect.set(0, 0, 0, space);
        }
    });
    mAdapter = new ChatAdapter(_mActivity);
    mRecy.setAdapter(mAdapter);
    mRecy.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            mScrollTotal += dy;
            if (mScrollTotal <= 0) {
                mInAtTop = true;
            } else {
                mInAtTop = false;
            }
        }
    });
    mAdapter.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(int position, View view, RecyclerView.ViewHolder vh) {
            // 因为启动的MsgFragment是MainFragment的兄弟Fragment,所以需要MainFragment.start()
            // 这里我使用EventBus通知父MainFragment处理跳转(接耦),
            EventBus.getDefault().post(new StartBrotherEvent(MsgFragment.newInstance(mAdapter.getMsg(position))));
        // 也可以像使用getParentFragment()的方式,拿到父Fragment的引用来操作 (不建议)
        //              ((MainFragment) getParentFragment()).startMsgBrother(MsgFragment.newInstance());
        }
    });
    List<Chat> chatList = initDatas();
    mAdapter.setDatas(chatList);
}
Also used : Rect(android.graphics.Rect) OnItemClickListener(me.yokeyword.sample.demo_wechat.listener.OnItemClickListener) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) StartBrotherEvent(me.yokeyword.sample.demo_wechat.event.StartBrotherEvent) Chat(me.yokeyword.sample.demo_wechat.entity.Chat) RecyclerView(android.support.v7.widget.RecyclerView) ChatAdapter(me.yokeyword.sample.demo_wechat.adapter.ChatAdapter)

Example 69 with Rect

use of android.graphics.Rect in project Fragmentation by YoKeyword.

the class SwipeBackLayout method drawShadow.

private void drawShadow(Canvas canvas, View child) {
    final Rect childRect = mTmpRect;
    child.getHitRect(childRect);
    if ((mCurrentSwipeOrientation & EDGE_LEFT) != 0) {
        mShadowLeft.setBounds(childRect.left - mShadowLeft.getIntrinsicWidth(), childRect.top, childRect.left, childRect.bottom);
        mShadowLeft.setAlpha((int) (mScrimOpacity * FULL_ALPHA));
        mShadowLeft.draw(canvas);
    } else if ((mCurrentSwipeOrientation & EDGE_RIGHT) != 0) {
        mShadowRight.setBounds(childRect.right, childRect.top, childRect.right + mShadowRight.getIntrinsicWidth(), childRect.bottom);
        mShadowRight.setAlpha((int) (mScrimOpacity * FULL_ALPHA));
        mShadowRight.draw(canvas);
    }
}
Also used : Rect(android.graphics.Rect)

Example 70 with Rect

use of android.graphics.Rect in project Carbon by ZieIony.

the class CheckableDrawable method renderSVGs.

private void renderSVGs() {
    Rect bounds = getBounds();
    if (bounds.width() <= 0 && bounds.height() <= 0)
        return;
    try {
        {
            SVG svg = SVG.getFromResource(context, checkedRes);
            checkedBitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(checkedBitmap);
            svg.setDocumentWidth(checkedBitmap.getWidth());
            svg.setDocumentHeight(checkedBitmap.getHeight());
            svg.renderToCanvas(canvas);
            checkedShader = new BitmapShader(checkedBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
            Matrix matrix = new Matrix();
            matrix.postTranslate(bounds.left, bounds.top);
            checkedShader.setLocalMatrix(matrix);
        }
        {
            SVG svg2 = SVG.getFromResource(context, uncheckedRes);
            uncheckedBitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(uncheckedBitmap);
            svg2.setDocumentWidth(uncheckedBitmap.getWidth());
            svg2.setDocumentHeight(uncheckedBitmap.getHeight());
            svg2.renderToCanvas(canvas);
        }
        {
            SVG svg3 = SVG.getFromResource(context, filledRes);
            filledBitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(filledBitmap);
            svg3.setDocumentWidth(filledBitmap.getWidth());
            svg3.setDocumentHeight(filledBitmap.getHeight());
            svg3.renderToCanvas(canvas);
        }
        maskBitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ARGB_8888);
        maskCanvas = new Canvas(maskBitmap);
        radius = (float) (Math.sqrt(2) * bounds.width() / 2);
    } catch (SVGParseException e) {
        Log.e(CheckableDrawable.class.getSimpleName(), "There was an error parsing SVG");
    } catch (NullPointerException e) {
    // TODO: what is this catch for?
    }
}
Also used : Rect(android.graphics.Rect) Matrix(android.graphics.Matrix) SVG(com.caverock.androidsvg.SVG) SVGParseException(com.caverock.androidsvg.SVGParseException) Canvas(android.graphics.Canvas) BitmapShader(android.graphics.BitmapShader)

Aggregations

Rect (android.graphics.Rect)4805 Paint (android.graphics.Paint)1052 View (android.view.View)687 Point (android.graphics.Point)563 Bitmap (android.graphics.Bitmap)467 Canvas (android.graphics.Canvas)372 RectF (android.graphics.RectF)266 Drawable (android.graphics.drawable.Drawable)241 Matrix (android.graphics.Matrix)125 ViewGroup (android.view.ViewGroup)121 ArrayList (java.util.ArrayList)121 TextView (android.widget.TextView)119 SuppressLint (android.annotation.SuppressLint)116 Resources (android.content.res.Resources)112 TextPaint (android.text.TextPaint)110 PorterDuffXfermode (android.graphics.PorterDuffXfermode)105 ImageView (android.widget.ImageView)97 BitmapDrawable (android.graphics.drawable.BitmapDrawable)95 SmallTest (android.test.suitebuilder.annotation.SmallTest)94 RemoteException (android.os.RemoteException)93