List of usage examples for android.graphics Rect set
public void set(int left, int top, int right, int bottom)
From source file:com.superrecycleview.superlibrary.utils.SuperDivider.java
@Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { if (parent.getLayoutManager() == null || parent.getAdapter() == null) { return;//from w ww. j av a 2 s . c o m } int childAdapterPosition = parent.getChildAdapterPosition(view); int itemCount = parent.getAdapter().getItemCount(); int realChildAdapterPosition = childAdapterPosition; int realItemCount = itemCount; if (isNeedSkip(childAdapterPosition, realItemCount)) { outRect.set(0, 0, 0, 0); } else { if (mOrientation == LinearLayout.VERTICAL) { getVerticalItemOffsets(outRect); } else { outRect.set(mSize, 0, 0, 0); } } }
From source file:com.android.leanlauncher.WidgetPreviewLoader.java
public Bitmap generateWidgetPreview(AppWidgetProviderInfo info, int cellHSpan, int cellVSpan, int maxPreviewWidth, int maxPreviewHeight, Bitmap preview, int[] preScaledWidthOut) { // Load the preview image if possible if (maxPreviewWidth < 0) maxPreviewWidth = Integer.MAX_VALUE; Drawable drawable = null;//from www.ja v a 2 s . c o m if (info.previewImage != 0) { drawable = mManager.loadPreview(info); if (drawable != null) { drawable = mutateOnMainThread(drawable); } else { Log.w(TAG, "Can't load widget preview drawable 0x" + Integer.toHexString(info.previewImage) + " for provider: " + info.provider); } } int previewWidth; int previewHeight; Bitmap defaultPreview = null; boolean widgetPreviewExists = (drawable != null); if (widgetPreviewExists) { previewWidth = drawable.getIntrinsicWidth(); previewHeight = drawable.getIntrinsicHeight(); } else { // Generate a preview image if we couldn't load one if (cellHSpan < 1) cellHSpan = 1; if (cellVSpan < 1) cellVSpan = 1; // This Drawable is not directly drawn, so there's no need to mutate it. BitmapDrawable previewDrawable = (BitmapDrawable) mContext.getResources() .getDrawable(R.drawable.widget_tile); final int previewDrawableWidth = previewDrawable.getIntrinsicWidth(); final int previewDrawableHeight = previewDrawable.getIntrinsicHeight(); previewWidth = previewDrawableWidth * cellHSpan; previewHeight = previewDrawableHeight * cellVSpan; defaultPreview = Bitmap.createBitmap(previewWidth, previewHeight, Config.ARGB_8888); final Canvas c = mCachedAppWidgetPreviewCanvas.get(); c.setBitmap(defaultPreview); Paint p = mDefaultAppWidgetPreviewPaint.get(); if (p == null) { p = new Paint(); p.setShader(new BitmapShader(previewDrawable.getBitmap(), Shader.TileMode.REPEAT, Shader.TileMode.REPEAT)); mDefaultAppWidgetPreviewPaint.set(p); } final Rect dest = mCachedAppWidgetPreviewDestRect.get(); dest.set(0, 0, previewWidth, previewHeight); c.drawRect(dest, p); c.setBitmap(null); // Draw the icon in the top left corner int minOffset = (int) (mAppIconSize * WIDGET_PREVIEW_ICON_PADDING_PERCENTAGE); int smallestSide = Math.min(previewWidth, previewHeight); float iconScale = Math.min((float) smallestSide / (mAppIconSize + 2 * minOffset), 1f); try { Bitmap icon = mIconCache.getIconForComponent(info.configure, UserHandleCompat.myUserHandle()); if (icon != null) { int hoffset = (int) ((previewDrawableWidth - mAppIconSize * iconScale) / 2); int yoffset = (int) ((previewDrawableHeight - mAppIconSize * iconScale) / 2); renderBitmapIconOnPreview(icon, defaultPreview, hoffset, yoffset, (int) (mAppIconSize * iconScale), (int) (mAppIconSize * iconScale)); } } catch (Resources.NotFoundException ignored) { } } // Scale to fit width only - let the widget preview be clipped in the // vertical dimension float scale = 1f; if (preScaledWidthOut != null) { preScaledWidthOut[0] = previewWidth; } if (previewWidth > maxPreviewWidth) { scale = maxPreviewWidth / (float) previewWidth; } if (scale != 1f) { previewWidth = (int) (scale * previewWidth); previewHeight = (int) (scale * previewHeight); } // If a bitmap is passed in, we use it; otherwise, we create a bitmap of the right size if (preview == null) { preview = Bitmap.createBitmap(previewWidth, previewHeight, Config.ARGB_8888); } // Draw the scaled preview into the final bitmap int x = (preview.getWidth() - previewWidth) / 2; if (widgetPreviewExists) { renderDrawableToBitmap(drawable, preview, x, 0, previewWidth, previewHeight); } else { final Canvas c = mCachedAppWidgetPreviewCanvas.get(); final Rect src = mCachedAppWidgetPreviewSrcRect.get(); final Rect dest = mCachedAppWidgetPreviewDestRect.get(); c.setBitmap(preview); src.set(0, 0, defaultPreview.getWidth(), defaultPreview.getHeight()); dest.set(x, 0, x + previewWidth, previewHeight); Paint p = mCachedAppWidgetPreviewPaint.get(); if (p == null) { p = new Paint(); p.setFilterBitmap(true); mCachedAppWidgetPreviewPaint.set(p); } c.drawBitmap(defaultPreview, src, dest, p); c.setBitmap(null); } return preview; }
From source file:com.android.utils.traversal.DirectionalTraversalStrategy.java
@Override public AccessibilityNodeInfoCompat focusInitial(AccessibilityNodeInfoCompat root, int direction) { if (root == null) { return null; }// w ww . ja v a2 s. co m Rect rootRect = new Rect(); root.getBoundsInScreen(rootRect); AccessibilityNodeInfoCompat focusedNode = root.findFocus(AccessibilityNodeInfoCompat.FOCUS_ACCESSIBILITY); Rect searchRect = new Rect(); if (focusedNode != null) { getSearchStartRect(focusedNode, direction, searchRect); } else if (direction == TraversalStrategy.SEARCH_FOCUS_LEFT) { searchRect.set(rootRect.right, rootRect.top, rootRect.right + 1, rootRect.bottom); } else if (direction == TraversalStrategy.SEARCH_FOCUS_RIGHT) { searchRect.set(rootRect.left - 1, rootRect.top, rootRect.left, rootRect.bottom); } else if (direction == TraversalStrategy.SEARCH_FOCUS_UP) { searchRect.set(rootRect.left, rootRect.bottom, rootRect.right, rootRect.bottom + 1); } else { searchRect.set(rootRect.left, rootRect.top - 1, rootRect.right, rootRect.top); } AccessibilityNodeInfoCompat newFocus = findFocus(focusedNode, searchRect, direction); if (newFocus != null) { return AccessibilityNodeInfoCompat.obtain(newFocus); } return null; }
From source file:com.xyczero.customswipelistview.CustomSwipeListView.java
/** * True if clicking in the itemswipeview position. * //from w w w. ja v a 2s. c o m * @param x * the x coordinate which gets in the down action * @param y * the y coordinate which gets in the down action * @return */ private boolean isInSwipePosition(int x, int y) { Rect frame = mTouchFrame; if (frame == null) { mTouchFrame = new Rect(); frame = mTouchFrame; } // The premise is that the itemswipeview is visible. if (isItemSwipeViewVisible) { frame.set(mCurItemSwipeView.getLeft(), getChildAt(mSelectedPosition - getFirstVisiblePosition()).getTop(), mCurItemSwipeView.getRight(), getChildAt(mSelectedPosition - getFirstVisiblePosition()).getBottom()); if (frame.contains(x, y)) { return true; } } return false; }
From source file:com.github.jdsjlzx.ItemDecoration.DoubleHeaderDecoration.java
/** * {@inheritDoc}//from w w w. j a v a 2 s .c om */ @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 && hasSubHeader(position)) { if (hasHeader(position)) { View header = getHeader(parent, position).itemView; headerHeight += header.getHeight(); } View header = getSubHeader(parent, position).itemView; headerHeight += header.getHeight(); } outRect.set(0, headerHeight, 0, 0); }
From source file:cn.lanmei.com.dingdong_2.ItemDecoration.StickyHeaderDecoration.java
/** * {@inheritDoc}//w w w. j a v a2 s. c om */ @Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { LRecyclerViewAdapter adapter = (LRecyclerViewAdapter) parent.getAdapter(); RecyclerView.Adapter ra = adapter.getInnerAdapter(); int count = ra.getItemCount(); int position = parent.getChildAdapterPosition(view); int headerHeight = 0; // L.MyLog("sticky","getItemOffsets:"+position+"count"+count); if (count > 0 && position != RecyclerView.NO_POSITION && hasHeader(position)) { View header = getHeader(parent, position).itemView; headerHeight = getHeaderHeightForLayout(header); } outRect.set(0, headerHeight, 0, 0); }
From source file:com.alibaba.android.layoutmanager.example.OnePlusNLayoutActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_activity); mFirstText = (TextView) findViewById(R.id.first); mLastText = (TextView) findViewById(R.id.last); mCountText = (TextView) findViewById(R.id.count); mTotalOffsetText = (TextView) findViewById(R.id.total_offset); final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.main_view); findViewById(R.id.jump).setOnClickListener(new View.OnClickListener() { @Override/*www . j ava 2 s.com*/ public void onClick(View v) { EditText position = (EditText) findViewById(R.id.position); if (!TextUtils.isEmpty(position.getText())) { try { int pos = Integer.parseInt(position.getText().toString()); recyclerView.scrollToPosition(pos); } catch (Exception e) { Log.e("VlayoutActivity", e.getMessage(), e); } } else { recyclerView.requestLayout(); } } }); final VirtualLayoutManager layoutManager = new VirtualLayoutManager(this); recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(RecyclerView recyclerView, int scrollState) { } @Override public void onScrolled(RecyclerView recyclerView, int i, int i2) { mFirstText.setText("First: " + layoutManager.findFirstVisibleItemPosition()); mLastText.setText( "Existing: " + MainViewHolder.existing + " Created: " + MainViewHolder.createdTimes); mCountText.setText("Count: " + recyclerView.getChildCount()); mTotalOffsetText.setText("Total Offset: " + layoutManager.getOffsetToStart()); } }); recyclerView.setLayoutManager(layoutManager); // layoutManager.setReverseLayout(true); RecyclerView.ItemDecoration itemDecoration = new RecyclerView.ItemDecoration() { public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { int position = ((LayoutParams) view.getLayoutParams()).getViewPosition(); outRect.set(4, 4, 4, 4); } }; final RecyclerView.RecycledViewPool viewPool = new RecyclerView.RecycledViewPool(); recyclerView.setRecycledViewPool(viewPool); // recyclerView.addItemDecoration(itemDecoration); viewPool.setMaxRecycledViews(0, 20); final DelegateAdapter delegateAdapter = new DelegateAdapter(layoutManager, true); recyclerView.setAdapter(delegateAdapter); List<DelegateAdapter.Adapter> adapters = new LinkedList<>(); if (BANNER_LAYOUT) { adapters.add(new SubAdapter(this, new LinearLayoutHelper(), 1) { @Override public void onViewRecycled(MainViewHolder holder) { if (holder.itemView instanceof ViewPager) { ((ViewPager) holder.itemView).setAdapter(null); } } @Override public MainViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { if (viewType == 1) return new MainViewHolder(LayoutInflater.from(OnePlusNLayoutActivity.this) .inflate(R.layout.view_pager, parent, false)); return super.onCreateViewHolder(parent, viewType); } @Override public int getItemViewType(int position) { return 1; } @Override protected void onBindViewHolderWithOffset(MainViewHolder holder, int position, int offsetTotal) { } @Override public void onBindViewHolder(MainViewHolder holder, int position) { if (holder.itemView instanceof ViewPager) { ViewPager viewPager = (ViewPager) holder.itemView; viewPager.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 200)); // from position to get adapter viewPager.setAdapter(new PagerAdapter(this, viewPool)); } } }); } if (GRID_LAYOUT) { GridLayoutHelper layoutHelper; layoutHelper = new GridLayoutHelper(4); layoutHelper.setMargin(0, 10, 0, 10); layoutHelper.setHGap(3); layoutHelper.setAspectRatio(4f); adapters.add(new SubAdapter(this, layoutHelper, 8)); } if (HORIZONTAL_SCROLL_LAYOUT) { } if (GRID_LAYOUT) { GridLayoutHelper layoutHelper; layoutHelper = new GridLayoutHelper(2); layoutHelper.setMargin(0, 10, 0, 10); layoutHelper.setHGap(3); layoutHelper.setAspectRatio(3f); adapters.add(new SubAdapter(this, layoutHelper, 2)); } if (ONEN_LAYOUT) { OnePlusNLayoutHelper helper = new OnePlusNLayoutHelper(); helper.setBgColor(0xff876384); helper.setMargin(10, 10, 10, 10); helper.setPadding(10, 10, 10, 10); adapters.add(new SubAdapter(this, helper, 3) { @Override public void onBindViewHolder(MainViewHolder holder, int position) { super.onBindViewHolder(holder, position); // LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300); // layoutParams.leftMargin = 10; // layoutParams.topMargin = 10; // layoutParams.rightMargin = 10; // layoutParams.bottomMargin = 10; // holder.itemView.setLayoutParams(layoutParams); } }); } if (ONEN_LAYOUT) { OnePlusNLayoutHelper helper = new OnePlusNLayoutHelper(); helper.setBgColor(0xff876384); helper.setMargin(0, 10, 0, 10); adapters.add(new SubAdapter(this, helper, 4)); } if (ONEN_LAYOUT) { OnePlusNLayoutHelper helper = new OnePlusNLayoutHelper(); helper.setBgColor(0xff876384); helper.setMargin(0, 10, 0, 10); adapters.add(new SubAdapter(this, helper, 5)); } if (ONEN_LAYOUT) { OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx(); helper.setBgColor(0xff876384); helper.setMargin(0, 10, 0, 10); adapters.add(new SubAdapter(this, helper, 5)); } if (ONEN_LAYOUT) { OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx(); helper.setBgColor(0xff876384); helper.setMargin(0, 10, 0, 10); helper.setColWeights(new float[] { 40f, 45f, 15f, 60f, 0f }); adapters.add(new SubAdapter(this, helper, 5)); } if (ONEN_LAYOUT) { OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx(); helper.setBgColor(0xff876384); helper.setMargin(0, 10, 0, 10); helper.setColWeights(new float[] { 20f, 80f, 0f, 60f, 20f }); helper.setAspectRatio(4); adapters.add(new SubAdapter(this, helper, 5)); } if (ONEN_LAYOUT) { OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx(); helper.setBgColor(0xff876384); helper.setMargin(0, 10, 0, 10); adapters.add(new SubAdapter(this, helper, 6)); } if (ONEN_LAYOUT) { OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx(); helper.setBgColor(0xff876384); helper.setMargin(0, 10, 0, 10); adapters.add(new SubAdapter(this, helper, 7)); } if (ONEN_LAYOUT) { OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx(); helper.setBgColor(0xff876384); helper.setMargin(0, 10, 0, 10); helper.setColWeights(new float[] { 40f, 45f, 15f, 60f, 0f, 30f, 30f }); adapters.add(new SubAdapter(this, helper, 7)); } if (ONEN_LAYOUT) { OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx(); helper.setBgColor(0xffed7612); // helper.setMargin(10, 10, 10, 10); // helper.setPadding(10, 10, 10, 10); helper.setColWeights(new float[] { 30f, 20f, 50f, 40f, 30f, 35f, 35f }); adapters.add(new SubAdapter(this, helper, 7) { @Override public void onBindViewHolder(MainViewHolder holder, int position) { super.onBindViewHolder(holder, position); // LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300); // layoutParams.leftMargin = 10; // layoutParams.topMargin = 10; // layoutParams.rightMargin = 10; // layoutParams.bottomMargin = 10; // holder.itemView.setLayoutParams(layoutParams); } }); } if (STICKY_LAYOUT) { StickyLayoutHelper layoutHelper = new StickyLayoutHelper(); layoutHelper.setAspectRatio(4); adapters.add(new SubAdapter(this, layoutHelper, 1, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 100))); } if (SCROLL_FIX_LAYOUT) { ScrollFixLayoutHelper layoutHelper = new ScrollFixLayoutHelper(FixLayoutHelper.BOTTOM_RIGHT, 20, 20); layoutHelper.setShowType(ScrollFixLayoutHelper.SHOW_ON_LEAVE); adapters.add(new SubAdapter(this, layoutHelper, 1) { @Override public void onBindViewHolder(MainViewHolder holder, int position) { super.onBindViewHolder(holder, position); LayoutParams layoutParams = new LayoutParams(50, 50); holder.itemView.setLayoutParams(layoutParams); } }); } if (LINEAR_LAYOUT) adapters.add(new SubAdapter(this, new LinearLayoutHelper(), 100)); delegateAdapter.setAdapters(adapters); final Handler mainHandler = new Handler(Looper.getMainLooper()); trigger = new Runnable() { @Override public void run() { // recyclerView.scrollToPosition(22); // recyclerView.getAdapter().notifyDataSetChanged(); recyclerView.requestLayout(); // mainHandler.postDelayed(trigger, 1000); } }; mainHandler.postDelayed(trigger, 1000); }
From source file:com.example.rx.ui.OnePlusNLayoutActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_activity2); mFirstText = (TextView) findViewById(R.id.first); mLastText = (TextView) findViewById(R.id.last); mCountText = (TextView) findViewById(R.id.count); mTotalOffsetText = (TextView) findViewById(R.id.total_offset); final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.main_view); findViewById(R.id.jump).setOnClickListener(new View.OnClickListener() { @Override// www. j a v a 2 s . c o m public void onClick(View v) { EditText position = (EditText) findViewById(R.id.position); if (!TextUtils.isEmpty(position.getText())) { try { int pos = Integer.parseInt(position.getText().toString()); recyclerView.scrollToPosition(pos); } catch (Exception e) { Log.e("VlayoutActivity", e.getMessage(), e); } } else { recyclerView.requestLayout(); } } }); final VirtualLayoutManager layoutManager = new VirtualLayoutManager(this); recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(RecyclerView recyclerView, int scrollState) { } @Override public void onScrolled(RecyclerView recyclerView, int i, int i2) { mFirstText.setText("First: " + layoutManager.findFirstVisibleItemPosition()); mLastText.setText( "Existing: " + MainViewHolder.existing + " Created: " + MainViewHolder.createdTimes); mCountText.setText("Count: " + recyclerView.getChildCount()); mTotalOffsetText.setText("Total Offset: " + layoutManager.getOffsetToStart()); } }); recyclerView.setLayoutManager(layoutManager); // layoutManager.setReverseLayout(true); RecyclerView.ItemDecoration itemDecoration = new RecyclerView.ItemDecoration() { public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { int position = ((LayoutParams) view.getLayoutParams()).getViewPosition(); outRect.set(4, 4, 4, 4); } }; final RecyclerView.RecycledViewPool viewPool = new RecyclerView.RecycledViewPool(); recyclerView.setRecycledViewPool(viewPool); // recyclerView.addItemDecoration(itemDecoration); viewPool.setMaxRecycledViews(0, 20); final DelegateAdapter delegateAdapter = new DelegateAdapter(layoutManager, true); recyclerView.setAdapter(delegateAdapter); List<DelegateAdapter.Adapter> adapters = new LinkedList<>(); if (BANNER_LAYOUT) { adapters.add(new SubAdapter(this, new LinearLayoutHelper(), 1) { @Override public void onViewRecycled(MainViewHolder holder) { if (holder.itemView instanceof ViewPager) { ((ViewPager) holder.itemView).setAdapter(null); } } @Override public MainViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { if (viewType == 1) return new MainViewHolder(LayoutInflater.from(OnePlusNLayoutActivity.this) .inflate(R.layout.view_pager, parent, false)); return super.onCreateViewHolder(parent, viewType); } @Override public int getItemViewType(int position) { return 1; } @Override protected void onBindViewHolderWithOffset(MainViewHolder holder, int position, int offsetTotal) { } @Override public void onBindViewHolder(MainViewHolder holder, int position) { if (holder.itemView instanceof ViewPager) { ViewPager viewPager = (ViewPager) holder.itemView; viewPager.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 200)); // from position to get adapter viewPager.setAdapter(new PagerAdapter(this, viewPool)); } } }); } if (GRID_LAYOUT) { GridLayoutHelper layoutHelper; layoutHelper = new GridLayoutHelper(4); layoutHelper.setMargin(0, 10, 0, 10); layoutHelper.setHGap(3); layoutHelper.setAspectRatio(4f); adapters.add(new SubAdapter(this, layoutHelper, 8)); } if (HORIZONTAL_SCROLL_LAYOUT) { } if (GRID_LAYOUT) { GridLayoutHelper layoutHelper; layoutHelper = new GridLayoutHelper(2); layoutHelper.setMargin(0, 10, 0, 10); layoutHelper.setHGap(3); layoutHelper.setAspectRatio(3f); adapters.add(new SubAdapter(this, layoutHelper, 2)); } if (ONEN_LAYOUT) { OnePlusNLayoutHelper helper = new OnePlusNLayoutHelper(); helper.setBgColor(0xff876384); helper.setMargin(10, 10, 10, 10); helper.setPadding(10, 10, 10, 10); adapters.add(new SubAdapter(this, helper, 3) { @Override public void onBindViewHolder(MainViewHolder holder, int position) { super.onBindViewHolder(holder, position); // LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300); // layoutParams.leftMargin = 10; // layoutParams.topMargin = 10; // layoutParams.rightMargin = 10; // layoutParams.bottomMargin = 10; // holder.itemView.setLayoutParams(layoutParams); } }); } if (ONEN_LAYOUT) { OnePlusNLayoutHelper helper = new OnePlusNLayoutHelper(); helper.setBgColor(0xff876384); helper.setMargin(0, 10, 0, 10); adapters.add(new SubAdapter(this, helper, 4)); } if (ONEN_LAYOUT) { OnePlusNLayoutHelper helper = new OnePlusNLayoutHelper(); helper.setBgColor(0xff876384); helper.setMargin(0, 10, 0, 10); adapters.add(new SubAdapter(this, helper, 5)); } if (ONEN_LAYOUT) { OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx(); helper.setBgColor(0xff876384); helper.setMargin(0, 10, 0, 10); adapters.add(new SubAdapter(this, helper, 5)); } if (ONEN_LAYOUT) { OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx(); helper.setBgColor(0xff876384); helper.setMargin(0, 10, 0, 10); helper.setColWeights(new float[] { 40f, 45f, 15f, 60f, 0f }); adapters.add(new SubAdapter(this, helper, 5)); } if (ONEN_LAYOUT) { OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx(); helper.setBgColor(0xff876384); helper.setMargin(0, 10, 0, 10); helper.setColWeights(new float[] { 20f, 80f, 0f, 60f, 20f }); helper.setAspectRatio(4); adapters.add(new SubAdapter(this, helper, 5)); } if (ONEN_LAYOUT) { OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx(); helper.setBgColor(0xff876384); helper.setMargin(0, 10, 0, 10); adapters.add(new SubAdapter(this, helper, 6)); } if (ONEN_LAYOUT) { OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx(); helper.setBgColor(0xff876384); helper.setMargin(0, 10, 0, 10); adapters.add(new SubAdapter(this, helper, 7)); } if (ONEN_LAYOUT) { OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx(); helper.setBgColor(0xff876384); helper.setMargin(0, 10, 0, 10); helper.setColWeights(new float[] { 40f, 45f, 15f, 60f, 0f, 30f, 30f }); adapters.add(new SubAdapter(this, helper, 7)); } if (ONEN_LAYOUT) { OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx(); helper.setBgColor(0xffed7612); // helper.setMargin(10, 10, 10, 10); // helper.setPadding(10, 10, 10, 10); helper.setColWeights(new float[] { 30f, 20f, 50f, 40f, 30f, 35f, 35f }); adapters.add(new SubAdapter(this, helper, 7) { @Override public void onBindViewHolder(MainViewHolder holder, int position) { super.onBindViewHolder(holder, position); // LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300); // layoutParams.leftMargin = 10; // layoutParams.topMargin = 10; // layoutParams.rightMargin = 10; // layoutParams.bottomMargin = 10; // holder.itemView.setLayoutParams(layoutParams); } }); } if (STICKY_LAYOUT) { StickyLayoutHelper layoutHelper = new StickyLayoutHelper(); layoutHelper.setAspectRatio(4); adapters.add(new SubAdapter(this, layoutHelper, 1, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 100))); } if (SCROLL_FIX_LAYOUT) { ScrollFixLayoutHelper layoutHelper = new ScrollFixLayoutHelper(FixLayoutHelper.BOTTOM_RIGHT, 20, 20); layoutHelper.setShowType(ScrollFixLayoutHelper.SHOW_ON_LEAVE); adapters.add(new SubAdapter(this, layoutHelper, 1) { @Override public void onBindViewHolder(MainViewHolder holder, int position) { super.onBindViewHolder(holder, position); LayoutParams layoutParams = new LayoutParams(50, 50); holder.itemView.setLayoutParams(layoutParams); } }); } if (LINEAR_LAYOUT) adapters.add(new SubAdapter(this, new LinearLayoutHelper(), 100)); delegateAdapter.setAdapters(adapters); final Handler mainHandler = new Handler(Looper.getMainLooper()); trigger = new Runnable() { @Override public void run() { // recyclerView.scrollToPosition(22); // recyclerView.getAdapter().notifyDataSetChanged(); recyclerView.requestLayout(); // mainHandler.postDelayed(trigger, 1000); } }; mainHandler.postDelayed(trigger, 1000); }
From source file:android.support.design.widget.FloatingActionButton.java
/** * Return in {@code rect} the bounds of the actual floating action button content in view-local * coordinates. This is defined as anything within any visible shadow. * * @return true if this view actually has been laid out and has a content rect, else false. */// www. jav a 2 s . c o m public boolean getContentRect(@NonNull Rect rect) { if (ViewCompat.isLaidOut(this)) { rect.set(0, 0, getWidth(), getHeight()); rect.left += mShadowPadding.left; rect.top += mShadowPadding.top; rect.right -= mShadowPadding.right; rect.bottom -= mShadowPadding.bottom; return true; } else { return false; } }
From source file:com.android.utils.traversal.DirectionalTraversalStrategy.java
/** * Given a focus rectangle, returns another rectangle that is placed at the beginning of the * row or column of the focused object, depending on the direction in which we are navigating. * * Example:// w w w . ja v a 2 s . co m * <pre> * +---------+ * | | node=# * A| # | When direction=TraversalStrategy.SEARCH_FOCUS_RIGHT, then a rectangle A with * | | same width and height as node gets returned. * | | When direction=TraversalStrategy.SEARCH_FOCUS_UP, then a rectangle B with same * +---------+ width and height as node gets returned. * B * </pre> */ private void getSearchStartRect(AccessibilityNodeInfoCompat node, int direction, Rect rect) { Rect focusedRect = new Rect(); node.getBoundsInScreen(focusedRect); Rect rootBounds = new Rect(); mRoot.getBoundsInScreen(rootBounds); switch (direction) { case TraversalStrategy.SEARCH_FOCUS_LEFT: // Start from right and move leftwards. rect.set(rootBounds.right, focusedRect.top, rootBounds.right + focusedRect.width(), focusedRect.bottom); break; case TraversalStrategy.SEARCH_FOCUS_RIGHT: // Start from left and move rightwards. rect.set(rootBounds.left - focusedRect.width(), focusedRect.top, rootBounds.left, focusedRect.bottom); break; case TraversalStrategy.SEARCH_FOCUS_UP: // Start from bottom and move upwards. rect.set(focusedRect.left, rootBounds.bottom, focusedRect.right, rootBounds.bottom + focusedRect.height()); break; case TraversalStrategy.SEARCH_FOCUS_DOWN: // Start from top and move downwards. rect.set(focusedRect.left, rootBounds.top - focusedRect.height(), focusedRect.right, rootBounds.top); break; default: throw new IllegalArgumentException("direction must be a SearchDirection"); } }