Java Code Examples for androidx.core.view.ViewCompat#getElevation()
The following examples show how to use
androidx.core.view.ViewCompat#getElevation() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ItemTouchUIUtilImpl.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
@Override public void onDraw(Canvas c, RecyclerView recyclerView, View view, float dX, float dY, int actionState, boolean isCurrentlyActive) { if (Build.VERSION.SDK_INT >= 21) { if (isCurrentlyActive) { Object originalElevation = view.getTag(); if (originalElevation == null) { originalElevation = ViewCompat.getElevation(view); float newElevation = 1f + findMaxElevation(recyclerView, view); ViewCompat.setElevation(view, newElevation); view.setTag(originalElevation); } } } view.setTranslationX(dX); view.setTranslationY(dY); }
Example 2
Source File: ContentViewHolder.java From FlexibleAdapter with Apache License 2.0 | 6 votes |
/** * @param view The {@link View} being hosted in this ViewHolder * @param adapter Adapter instance of type {@link FlexibleAdapter} * @param stickyHeader true if the ViewHolder is a header to be sticky * @since 5.0.0-b7 */ ContentViewHolder(View view, FlexibleAdapter adapter, boolean stickyHeader) { // Since itemView is declared "final", the split is done before the View is initialized super(stickyHeader ? new FrameLayout(view.getContext()) : view); if (stickyHeader) { itemView.setLayoutParams(adapter.getRecyclerView().getLayoutManager() .generateLayoutParams(view.getLayoutParams())); ((FrameLayout) itemView).addView(view); //Add View after setLayoutParams float elevation = ViewCompat.getElevation(view); if (elevation > 0) { ViewCompat.setBackground(itemView, view.getBackground()); ViewCompat.setElevation(itemView, elevation); } contentView = view; } }
Example 3
Source File: ItemTouchUIUtilImpl.java From Carbon with Apache License 2.0 | 6 votes |
@Override public void onDraw(Canvas c, RecyclerView recyclerView, View view, float dX, float dY, int actionState, boolean isCurrentlyActive) { if (isCurrentlyActive) { Object originalElevation = view.getTag(R.id.item_touch_helper_previous_elevation); if (originalElevation == null) { originalElevation = view instanceof ShadowView ? ((ShadowView) view).getElevation() : ViewCompat.getElevation(view); float newElevation = 1f + findMaxElevation(recyclerView, view); if (view instanceof ShadowView) { ((ShadowView) view).setElevation(newElevation); } else { ViewCompat.setElevation(view, newElevation); } view.setTag(R.id.item_touch_helper_previous_elevation, originalElevation); } } super.onDraw(c, recyclerView, view, dX, dY, actionState, isCurrentlyActive); }
Example 4
Source File: ItemTouchUIUtilImpl.java From Telegram with GNU General Public License v2.0 | 6 votes |
@Override public void onDraw(Canvas c, RecyclerView recyclerView, View view, float dX, float dY, int actionState, boolean isCurrentlyActive) { if (Build.VERSION.SDK_INT >= 21) { if (isCurrentlyActive) { Object originalElevation = view.getTag(); if (originalElevation == null) { originalElevation = ViewCompat.getElevation(view); float newElevation = 1f + findMaxElevation(recyclerView, view); ViewCompat.setElevation(view, newElevation); view.setTag(originalElevation); } } } view.setTranslationX(dX); view.setTranslationY(dY); }
Example 5
Source File: FabTransformationBehavior.java From material-components-android with Apache License 2.0 | 6 votes |
@TargetApi(VERSION_CODES.LOLLIPOP) private void createElevationAnimation( View dependency, @NonNull View child, boolean expanded, boolean currentlyAnimating, @NonNull FabTransformationSpec spec, @NonNull List<Animator> animations, List<AnimatorListener> unusedListeners) { float translationZ = ViewCompat.getElevation(child) - ViewCompat.getElevation(dependency); Animator animator; if (expanded) { if (!currentlyAnimating) { child.setTranslationZ(-translationZ); } animator = ObjectAnimator.ofFloat(child, View.TRANSLATION_Z, 0f); } else { animator = ObjectAnimator.ofFloat(child, View.TRANSLATION_Z, -translationZ); } MotionTiming timing = spec.timings.getTiming("elevation"); timing.apply(animator); animations.add(animator); }
Example 6
Source File: ItemTouchUIUtilImpl.java From Telegram with GNU General Public License v2.0 | 5 votes |
private static float findMaxElevation(RecyclerView recyclerView, View itemView) { final int childCount = recyclerView.getChildCount(); float max = 0; for (int i = 0; i < childCount; i++) { final View child = recyclerView.getChildAt(i); if (child == itemView) { continue; } final float elevation = ViewCompat.getElevation(child); if (elevation > max) { max = elevation; } } return max; }
Example 7
Source File: ItemTouchUIUtilImpl.java From monero-wallet-android-app with MIT License | 5 votes |
@Override public void onDraw(Canvas c, RecyclerView recyclerView, View view, float dX, float dY, int actionState, boolean isCurrentlyActive) { if (isCurrentlyActive) { Object originalElevation = view.getTag(R.id.item_touch_helper_previous_elevation); if (originalElevation == null) { originalElevation = ViewCompat.getElevation(view); float newElevation = 1f + findMaxElevation(recyclerView, view); ViewCompat.setElevation(view, newElevation); view.setTag(R.id.item_touch_helper_previous_elevation, originalElevation); } } super.onDraw(c, recyclerView, view, dX, dY, actionState, isCurrentlyActive); }
Example 8
Source File: StickyHeaderHelper.java From FlexibleAdapter with Apache License 2.0 | 5 votes |
private void configureLayoutElevation() { // 1. Take elevation from header item layout (most important) mElevation = ViewCompat.getElevation(mStickyHeaderViewHolder.getContentView()); if (mElevation == 0f) { // 2. Take elevation settings mElevation = mRecyclerView.getContext().getResources().getDisplayMetrics().density * mAdapter.getStickyHeaderElevation(); } if (mElevation > 0) { // Needed to elevate the view ViewCompat.setBackground(mStickyHolderLayout, mStickyHeaderViewHolder.getContentView().getBackground()); } }
Example 9
Source File: SimpleElevationItemTouchHelperCallback.java From RecyclerExt with Apache License 2.0 | 5 votes |
/** * Finds the elevation of the highest visible viewHolder to make sure the elevated view * from {@link #updateElevation(RecyclerView, RecyclerView.ViewHolder, boolean)} is above * all others. * * @param recyclerView The RecyclerView to use when determining the height of all the visible ViewHolders */ protected float findMaxElevation(@NonNull RecyclerView recyclerView) { float maxChildElevation = 0; for (int i = 0; i < recyclerView.getChildCount(); i++) { View child = recyclerView.getChildAt(i); float elevation = ViewCompat.getElevation(child); if (elevation > maxChildElevation) { maxChildElevation = elevation; } } return maxChildElevation; }
Example 10
Source File: SimpleElevationItemTouchHelperCallback.java From RecyclerExt with Apache License 2.0 | 5 votes |
/** * Updates the elevation for the specified <code>holder</code> by either increasing * or decreasing by the specified amount * * @param recyclerView The recyclerView to use when calculating the new elevation * @param holder The ViewHolder to increase or decrease the elevation for * @param elevate True if the <code>holder</code> should have it's elevation increased */ protected void updateElevation(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder holder, boolean elevate) { if (elevate) { originalElevation = ViewCompat.getElevation(holder.itemView); float newElevation = activeElevationChange + findMaxElevation(recyclerView); ViewCompat.setElevation(holder.itemView, newElevation); isElevated = true; } else { ViewCompat.setElevation(holder.itemView, originalElevation); originalElevation = 0; isElevated = false; } }
Example 11
Source File: ItemTouchUIUtilImpl.java From Carbon with Apache License 2.0 | 5 votes |
private float findMaxElevation(RecyclerView recyclerView, View itemView) { final int childCount = recyclerView.getChildCount(); float max = 0; for (int i = 0; i < childCount; i++) { final View child = recyclerView.getChildAt(i); if (child == itemView) { continue; } final float elevation = ViewCompat.getElevation(child); if (elevation > max) { max = elevation; } } return max; }
Example 12
Source File: ObliqueView.java From Oblique with Apache License 2.0 | 5 votes |
@Override protected void onDraw(Canvas canvas) { // super.onDraw(canvas); //Log.e("logs","onDraw"); paint.setStyle(Paint.Style.FILL); switch (config.getType()) { case 0: paint.setColor(config.getBaseColor()); break; case 1: paint.setShader(config.getLinearGradient(config.getAngle(), width, height)); break; case 2: paint.setShader(config.getRadialGradient(width, height)); break; case 3: setupBitmap(this, width, height); paint.setShader(bitmapShader); break; } paint.setStrokeJoin(Paint.Join.ROUND); // set the join to round you want paint.setStrokeCap(Paint.Cap.ROUND); // set the paint cap to round too ViewCompat.setElevation(this, config.getShadow()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && ViewCompat.getElevation(this) > 0f) { try { setOutlineProvider(getOutlineProvider()); } catch (Exception e) { Log.e("Exception", e.getMessage()); e.printStackTrace(); } } paint.setXfermode(pdMode); canvas.drawPath(path, paint); }
Example 13
Source File: ItemTouchUIUtilImpl.java From CrazyDaily with Apache License 2.0 | 5 votes |
private float findMaxElevation(RecyclerView recyclerView, View itemView) { final int childCount = recyclerView.getChildCount(); float max = 0; for (int i = 0; i < childCount; i++) { final View child = recyclerView.getChildAt(i); if (child == itemView) { continue; } final float elevation = ViewCompat.getElevation(child); if (elevation > max) { max = elevation; } } return max; }
Example 14
Source File: ItemTouchUIUtilImpl.java From CrazyDaily with Apache License 2.0 | 5 votes |
@Override public void onDraw(Canvas c, RecyclerView recyclerView, View view, float dX, float dY, int actionState, boolean isCurrentlyActive) { if (isCurrentlyActive) { Object originalElevation = view.getTag(R.id.item_touch_helper_previous_elevation); if (originalElevation == null) { originalElevation = ViewCompat.getElevation(view); float newElevation = 1f + findMaxElevation(recyclerView, view); ViewCompat.setElevation(view, newElevation); view.setTag(R.id.item_touch_helper_previous_elevation, originalElevation); } } super.onDraw(c, recyclerView, view, dX, dY, actionState, isCurrentlyActive); }
Example 15
Source File: SimpleItemTouchHelperCallback.java From call_manage with MIT License | 5 votes |
/** * Updates the elevation for the specified <code>holder</code> by either increasing * or decreasing by the specified amount * * @param recyclerView The recyclerView to use when calculating the new elevation * @param holder The ViewHolder to increase or decrease the elevation for * @param elevate True if the <code>holder</code> should have it's elevation increased */ protected void updateElevation(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder holder, boolean elevate) { if (elevate) { originalElevation = ViewCompat.getElevation(holder.itemView); float newElevation = Utilities.convertDpToPixel(recyclerView.getContext(), 4f); ViewCompat.setElevation(holder.itemView, newElevation); isElevated = true; } else { ViewCompat.setElevation(holder.itemView, originalElevation); originalElevation = 0; isElevated = false; } }
Example 16
Source File: ItemTouchUIUtilImpl.java From monero-wallet-android-app with MIT License | 5 votes |
private float findMaxElevation(RecyclerView recyclerView, View itemView) { final int childCount = recyclerView.getChildCount(); float max = 0; for (int i = 0; i < childCount; i++) { final View child = recyclerView.getChildAt(i); if (child == itemView) { continue; } final float elevation = ViewCompat.getElevation(child); if (elevation > max) { max = elevation; } } return max; }
Example 17
Source File: ShapeOfView.java From ArcLayout with Apache License 2.0 | 4 votes |
private void calculateLayout(int width, int height) { rectView.reset(); rectView.addRect(0f, 0f, 1f * getWidth(), 1f * getHeight(), Path.Direction.CW); if (clipManager != null) { if (width > 0 && height > 0) { clipManager.setupClipLayout(width, height); clipPath.reset(); clipPath.set(clipManager.createMask(width, height)); if (requiresBitmap()) { if (clipBitmap != null) { clipBitmap.recycle(); } clipBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(clipBitmap); if (drawable != null) { drawable.setBounds(0, 0, width, height); drawable.draw(canvas); } else { canvas.drawPath(clipPath, clipManager.getPaint()); } } //invert the path for android P if(Build.VERSION.SDK_INT > Build.VERSION_CODES.O_MR1) { final boolean success = rectView.op(clipPath, Path.Op.DIFFERENCE); } //this needs to be fixed for 25.4.0 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && ViewCompat.getElevation(this) > 0f) { try { setOutlineProvider(getOutlineProvider()); } catch (Exception e) { e.printStackTrace(); } } } } postInvalidate(); }
Example 18
Source File: MaterialContainerTransform.java From material-components-android with Apache License 2.0 | 4 votes |
private static float getElevationOrDefault(float elevation, View view) { return elevation != ELEVATION_NOT_SET ? elevation : ViewCompat.getElevation(view); }
Example 19
Source File: MaterialContainerTransform.java From material-components-android with Apache License 2.0 | 4 votes |
private static float getElevationOrDefault(float elevation, View view) { return elevation != ELEVATION_NOT_SET ? elevation : ViewCompat.getElevation(view); }
Example 20
Source File: ShapeOfView.java From ShapeOfView with Apache License 2.0 | 4 votes |
private void calculateLayout(int width, int height) { rectView.reset(); rectView.addRect(0f, 0f, 1f * getWidth(), 1f * getHeight(), Path.Direction.CW); if (clipManager != null) { if (width > 0 && height > 0) { clipManager.setupClipLayout(width, height); clipPath.reset(); clipPath.set(clipManager.createMask(width, height)); if (requiresBitmap()) { if (clipBitmap != null) { clipBitmap.recycle(); } clipBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(clipBitmap); if (drawable != null) { drawable.setBounds(0, 0, width, height); drawable.draw(canvas); } else { canvas.drawPath(clipPath, clipManager.getPaint()); } } //invert the path for android P if(Build.VERSION.SDK_INT > Build.VERSION_CODES.O_MR1) { final boolean success = rectView.op(clipPath, Path.Op.DIFFERENCE); } //this needs to be fixed for 25.4.0 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && ViewCompat.getElevation(this) > 0f) { try { setOutlineProvider(getOutlineProvider()); } catch (Exception e) { e.printStackTrace(); } } } } postInvalidate(); }