Java Code Examples for android.support.v4.view.ViewCompat#getElevation()

The following examples show how to use android.support.v4.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: BottomNavigationBehavior.java    From NanoIconPack with Apache License 2.0 6 votes vote down vote up
@Override
public void updateSnackbar(CoordinatorLayout parent, View dependency, View child) {
    if (dependency instanceof Snackbar.SnackbarLayout) {
        if (mSnackbarHeight == -1) {
            mSnackbarHeight = dependency.getHeight();
        }

        int targetPadding = child.getMeasuredHeight();

        int shadow = (int) ViewCompat.getElevation(child);
        ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) dependency.getLayoutParams();
        layoutParams.bottomMargin = targetPadding - shadow;
        child.bringToFront();
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
            child.getParent().requestLayout();
            ((View) child.getParent()).invalidate();
        }

    }
}
 
Example 2
Source File: ItemTouchUIUtilImpl.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onDraw(Canvas c, RecyclerView recyclerView, View view,
        float dX, float dY, int actionState, boolean isCurrentlyActive) {
    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);
        }
    }
    super.onDraw(c, recyclerView, view, dX, dY, actionState, isCurrentlyActive);
}
 
Example 3
Source File: ItemTouchUIUtilImpl.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
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 4
Source File: ReItemTouchUIUtilImpl.java    From ReSwipeCard with Apache License 2.0 5 votes vote down vote up
@Override
public void onDraw(Canvas c, RecyclerView recyclerView, View view,
                   float dX, float dY, int actionState, boolean isCurrentlyActive) {
    if (isCurrentlyActive) {
        Object originalElevation = view.getTag(android.support.v7.recyclerview.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(android.support.v7.recyclerview.R.id.item_touch_helper_previous_elevation, originalElevation);
        }
    }
    super.onDraw(c, recyclerView, view, dX, dY, actionState, isCurrentlyActive);
}
 
Example 5
Source File: ReItemTouchUIUtilImpl.java    From ReSwipeCard with Apache License 2.0 5 votes vote down vote up
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 6
Source File: ItemTouchUIUtilImpl.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onDraw(Canvas c, RecyclerView recyclerView, View view,
        float dX, float dY, int actionState, boolean isCurrentlyActive) {
    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);
        }
    }
    super.onDraw(c, recyclerView, view, dX, dY, actionState, isCurrentlyActive);
}
 
Example 7
Source File: ItemTouchUIUtilImpl.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
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 8
Source File: ItemTouchUIUtilImpl.java    From letv with Apache License 2.0 5 votes vote down vote up
private float findMaxElevation(RecyclerView recyclerView, View itemView) {
    int childCount = recyclerView.getChildCount();
    float max = 0.0f;
    for (int i = 0; i < childCount; i++) {
        View child = recyclerView.getChildAt(i);
        if (child != itemView) {
            float elevation = ViewCompat.getElevation(child);
            if (elevation > max) {
                max = elevation;
            }
        }
    }
    return max;
}
 
Example 9
Source File: ClassifyView.java    From ClassifyView with Apache License 2.0 5 votes vote down vote up
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 10
Source File: ClassifyView.java    From ClassifyView with Apache License 2.0 5 votes vote down vote up
private float findMaxElevation(RecyclerView recyclerView) {
    final int childCount = recyclerView.getChildCount();
    float max = 0;
    for (int i = 0; i < childCount; i++) {
        final View child = recyclerView.getChildAt(i);

        final float elevation = ViewCompat.getElevation(child);
        if (elevation > max) {
            max = elevation;
        }
    }
    return max;
}
 
Example 11
Source File: QueueItemViewHolder.java    From PainlessMusicPlayer with Apache License 2.0 5 votes vote down vote up
QueueItemViewHolder(@NonNull final View itemView) {
    super(itemView);
    btnMenu = itemView.findViewById(R.id.btnMenu);
    textTitle = itemView.findViewById(R.id.textTitle);
    textArtist = itemView.findViewById(R.id.textArtist);
    textDuration = itemView.findViewById(R.id.textDuration);

    mDefaultBackground = itemView.getBackground();
    mDefaultElevation = ViewCompat.getElevation(itemView);

    mElevationSelected = itemView.getResources()
            .getDimension(R.dimen.list_drag_selected_item_elevation);
}
 
Example 12
Source File: AnimationOrAnimatorResourceExecutor.java    From scene with Apache License 2.0 4 votes vote down vote up
@Override
public void executePushChangeCancelable(@NonNull final AnimationInfo fromInfo, @NonNull final AnimationInfo toInfo, @NonNull final Runnable endAction, @NonNull CancellationSignal cancellationSignal) {
    // Cannot be placed in onAnimationStart, as there it a post interval, it will splash
    final View fromView = fromInfo.mSceneView;
    final View toView = toInfo.mSceneView;

    AnimatorUtility.resetViewStatus(fromView);
    AnimatorUtility.resetViewStatus(toView);
    fromView.setVisibility(View.VISIBLE);

    final float fromViewElevation = ViewCompat.getElevation(fromView);
    if (fromViewElevation > 0) {
        ViewCompat.setElevation(fromView, 0);
    }

    // In the case of pushAndClear, it is possible that the Scene come from has been destroyed.
    if (fromInfo.mSceneState.value < State.VIEW_CREATED.value) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            mAnimationViewGroup.getOverlay().add(fromView);
        } else {
            mAnimationViewGroup.addView(fromView);
        }
    }

    Runnable animationEndAction = new CountRunnable(2, new Runnable() {
        @Override
        public void run() {
            if (!toInfo.mIsTranslucent) {
                fromView.setVisibility(View.GONE);
            }

            if (fromViewElevation > 0) {
                ViewCompat.setElevation(fromView, fromViewElevation);
            }

            AnimatorUtility.resetViewStatus(fromView);
            AnimatorUtility.resetViewStatus(toView);

            if (fromInfo.mSceneState.value < State.VIEW_CREATED.value) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
                    mAnimationViewGroup.getOverlay().remove(fromView);
                } else {
                    mAnimationViewGroup.removeView(fromView);
                }
            }
            endAction.run();
        }
    });

    mEnterAnimator.addEndAction(animationEndAction);
    mExitAnimator.addEndAction(animationEndAction);

    mExitAnimator.start(fromView);
    mEnterAnimator.start(toView);
    cancellationSignal.setOnCancelListener(new CancellationSignal.OnCancelListener() {
        @Override
        public void onCancel() {
            mEnterAnimator.end();
            mExitAnimator.end();
        }
    });
}
 
Example 13
Source File: DrawerLayout.java    From letv with Apache License 2.0 4 votes vote down vote up
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    int widthSize = MeasureSpec.getSize(widthMeasureSpec);
    int heightSize = MeasureSpec.getSize(heightMeasureSpec);
    if (!(widthMode == 1073741824 && heightMode == 1073741824)) {
        if (isInEditMode()) {
            if (widthMode != Integer.MIN_VALUE) {
                if (widthMode == 0) {
                    widthSize = 300;
                }
            }
            if (heightMode != Integer.MIN_VALUE) {
                if (heightMode == 0) {
                    heightSize = 300;
                }
            }
        } else {
            throw new IllegalArgumentException("DrawerLayout must be measured with MeasureSpec.EXACTLY.");
        }
    }
    setMeasuredDimension(widthSize, heightSize);
    boolean applyInsets = this.mLastInsets != null && ViewCompat.getFitsSystemWindows(this);
    int layoutDirection = ViewCompat.getLayoutDirection(this);
    boolean hasDrawerOnLeftEdge = false;
    boolean hasDrawerOnRightEdge = false;
    int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = getChildAt(i);
        if (child.getVisibility() != 8) {
            MarginLayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (applyInsets) {
                int cgrav = GravityCompat.getAbsoluteGravity(lp.gravity, layoutDirection);
                if (ViewCompat.getFitsSystemWindows(child)) {
                    IMPL.dispatchChildInsets(child, this.mLastInsets, cgrav);
                } else {
                    IMPL.applyMarginInsets(lp, this.mLastInsets, cgrav);
                }
            }
            if (isContentView(child)) {
                child.measure(MeasureSpec.makeMeasureSpec((widthSize - lp.leftMargin) - lp.rightMargin, 1073741824), MeasureSpec.makeMeasureSpec((heightSize - lp.topMargin) - lp.bottomMargin, 1073741824));
            } else if (isDrawerView(child)) {
                if (SET_DRAWER_SHADOW_FROM_ELEVATION && ViewCompat.getElevation(child) != this.mDrawerElevation) {
                    ViewCompat.setElevation(child, this.mDrawerElevation);
                }
                int childGravity = getDrawerViewAbsoluteGravity(child) & 7;
                boolean isLeftEdgeDrawer = childGravity == 3;
                if (!(isLeftEdgeDrawer && hasDrawerOnLeftEdge) && (isLeftEdgeDrawer || !hasDrawerOnRightEdge)) {
                    if (isLeftEdgeDrawer) {
                        hasDrawerOnLeftEdge = true;
                    } else {
                        hasDrawerOnRightEdge = true;
                    }
                    child.measure(getChildMeasureSpec(widthMeasureSpec, (this.mMinDrawerMargin + lp.leftMargin) + lp.rightMargin, lp.width), getChildMeasureSpec(heightMeasureSpec, lp.topMargin + lp.bottomMargin, lp.height));
                } else {
                    throw new IllegalStateException("Child drawer has absolute gravity " + gravityToString(childGravity) + " but this " + TAG + " already has a " + "drawer view along that edge");
                }
            } else {
                throw new IllegalStateException("Child " + child + " at index " + i + " does not have a valid layout_gravity - must be Gravity.LEFT, " + "Gravity.RIGHT or Gravity.NO_GRAVITY");
            }
        }
    }
}
 
Example 14
Source File: OnScrollerGoDownListener.java    From FlowGeek with GNU General Public License v2.0 4 votes vote down vote up
public State onSaveInstanceState() {
    state.translationY = view.getTranslationY();
    state.elevation = ViewCompat.getElevation(view);
    return state;
}
 
Example 15
Source File: ShapeOfView.java    From DiagonalLayout with Apache License 2.0 4 votes vote down vote up
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();
}