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;
}
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);
}
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);
}
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);
}
}
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?
}
}
Aggregations