Java Code Examples for android.view.View.setElevation()

The following are Jave code examples for showing how to use setElevation() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: FlickLauncher   File: DeepShortcutsContainer.java   Source Code and License Vote up 7 votes
/**
 * Adds an arrow view pointing at the original icon.
 * @param horizontalOffset the horizontal offset of the arrow, so that it
 *                              points at the center of the original icon
 */
private View addArrowView(int horizontalOffset, int verticalOffset, int width, int height) {
    LinearLayout.LayoutParams layoutParams = new LayoutParams(width, height);
    if (mIsLeftAligned) {
        layoutParams.gravity = Gravity.LEFT;
        layoutParams.leftMargin = horizontalOffset;
    } else {
        layoutParams.gravity = Gravity.RIGHT;
        layoutParams.rightMargin = horizontalOffset;
    }
    if (mIsAboveIcon) {
        layoutParams.topMargin = verticalOffset;
    } else {
        layoutParams.bottomMargin = verticalOffset;
    }

    View arrowView = new View(getContext());
    ShapeDrawable arrowDrawable = new ShapeDrawable(TriangleShape.create(
            width, height, !mIsAboveIcon));
    arrowDrawable.getPaint().setColor(Color.WHITE);
    arrowView.setBackground(arrowDrawable);
    arrowView.setElevation(getElevation());
    addView(arrowView, mIsAboveIcon ? getChildCount() : 0, layoutParams);
    return arrowView;
}
 
Example 2
Project: FancyTab   File: FancyTabLayout.java   Source Code and License Vote up 7 votes
private void setAppbarEvent() {
    AppBarLayout appBar = (AppBarLayout) getParent();

    if (appBar.getParent().getClass().equals(CoordinatorLayout.class)) {
        CoordinatorLayout rootLayout = (CoordinatorLayout) appBar.getParent();

        View tabs = getChildAt(0);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            tabs.setElevation(getResources().getDimensionPixelOffset(R.dimen.tabs_elevation));
        }

        removeView(tabs);
        rootLayout.addView(tabs);

        getLayoutParams().height = getResources().getDimensionPixelOffset(R.dimen.fancy_tab_layout_height);
        requestLayout();
        isFloating = true;
    }

    appBar.addOnOffsetChangedListener(onOffsetChangedListener);
}
 
Example 3
Project: pius1   File: CardViewApi21.java   Source Code and License Vote up 6 votes
@Override
public void initialize(CardViewDelegate cardView, Context context, int backgroundColor,
        float radius, float elevation, float maxElevation) {
    final RoundRectDrawable backgroundDrawable = new RoundRectDrawable(backgroundColor, radius);
    cardView.setBackgroundDrawable(backgroundDrawable);
    View view = (View) cardView;
    view.setClipToOutline(true);
    view.setElevation(elevation);
    setMaxElevation(cardView, maxElevation);
}
 
Example 4
Project: LaunchEnr   File: PopupContainerWithArrow.java   Source Code and License Vote up 6 votes
/**
 * Adds an arrow view pointing at the original icon.
 * @param horizontalOffset the horizontal offset of the arrow, so that it
 *                              points at the center of the original icon
 */
private View addArrowView(int horizontalOffset, int verticalOffset, int width, int height) {
    LayoutParams layoutParams = new LayoutParams(width, height);
    if (mIsLeftAligned) {
        layoutParams.gravity = Gravity.START;
        layoutParams.leftMargin = horizontalOffset;
    } else {
        layoutParams.gravity = Gravity.END;
        layoutParams.rightMargin = horizontalOffset;
    }
    if (mIsAboveIcon) {
        layoutParams.topMargin = verticalOffset;
    } else {
        layoutParams.bottomMargin = verticalOffset;
    }

    View arrowView = new View(getContext());
    if (Gravity.isVertical(((FrameLayout.LayoutParams) getLayoutParams()).gravity)) {
        // This is only true if there wasn't room for the container next to the icon,
        // so we centered it instead. In that case we don't want to show the arrow.
        arrowView.setVisibility(INVISIBLE);
    } else {
        ShapeDrawable arrowDrawable = new ShapeDrawable(TriangleShape.create(
                width, height, !mIsAboveIcon));
        Paint arrowPaint = arrowDrawable.getPaint();
        // Note that we have to use getChildAt() instead of getItemViewAt(),
        // since the latter expects the arrow which hasn't been added yet.
        PopupItemView itemAttachedToArrow = (PopupItemView)
                (getChildAt(mIsAboveIcon ? getChildCount() - 1 : 0));
        arrowPaint.setColor(itemAttachedToArrow.getArrowColor(mIsAboveIcon));
        // The corner path effect won't be reflected in the shadow, but shouldn't be noticeable.
        int radius = getResources().getDimensionPixelSize(R.dimen.popup_arrow_corner_radius);
        arrowPaint.setPathEffect(new CornerPathEffect(radius));
        arrowView.setBackground(arrowDrawable);
        arrowView.setElevation(getElevation());
    }
    addView(arrowView, mIsAboveIcon ? getChildCount() : 0, layoutParams);
    return arrowView;
}
 
Example 5
Project: LiteReader   File: BaseBindingAdapter.java   Source Code and License Vote up 6 votes
@BindingAdapter("elevation")
public static void elevationBoolean(View view, boolean elevation) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && elevation) {
        view.setElevation(view.getContext().getResources().getInteger(R.integer.common_elevation));
    } else {
        jLogger.w("Sorry, the system version of the device is under API 21, elevation will take no effect.");
    }
}
 
Example 6
Project: chromium-net-for-android   File: ApiCompatibilityUtils.java   Source Code and License Vote up 6 votes
/**
 * Set elevation if supported.
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static boolean setElevation(View view, float elevationValue) {
    if (!isElevationSupported()) return false;

    view.setElevation(elevationValue);
    return true;
}
 
Example 7
Project: SlidingRootNav   File: ElevationTransformation.java   Source Code and License Vote up 6 votes
@Override
public void transform(float dragProgress, View rootView) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        float elevation = SideNavUtils.evaluate(dragProgress, START_ELEVATION, endElevation);
        rootView.setElevation(elevation);
    }
}
 
Example 8
Project: spline   File: SaturationValuePicker.java   Source Code and License Vote up 6 votes
public SaturationValuePicker(Context context, AttributeSet attrs) {
    super(context, attrs);
    mColor = new Color();

    setClipChildren(false);
    setClipToPadding(false);

    DisplayMetrics metrics = context.getResources().getDisplayMetrics();
    mDensity = metrics.density;

    mSelectorRadius = SELECTOR_RADIUS_DP * mDensity;

    View v = new View(context);
    v.setLayoutParams(new LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT
    ));

    // We want the selector to protrude as minimally as possible from the selection drawable and
    // we want to inset the gradients in the drawable so that the color under the selector's
    // midpoint always reflects the current color (thus the limits of the saturation-value
    // gradients have to be clamped at this inset. The inset value is thus the shorter side of
    // a 45 degree triangle (1 / root 2) with hypotnus equal to the radius of the selector.
    mInset = mSelectorRadius / (float) Math.sqrt(2);
    mSVDrawable = new SaturationValueDrawable(mInset);
    v.setBackground(mSVDrawable);
    addView(v);

    mSelectorParams = new LayoutParams(
            Math.round(mSelectorRadius * 2), Math.round(mSelectorRadius * 2)
    );
    mSelector = new View(context);
    mSelector.setLayoutParams(mSelectorParams);
    mSelectorDrawable = (GradientDrawable) ContextCompat.getDrawable(
            context, R.drawable.drawable_selector);
    mSelector.setBackground(mSelectorDrawable);
    mSelector.setElevation(SELECTOR_ELEVATION_DP * mDensity);
    addView(mSelector);
}
 
Example 9
Project: boohee_v5.6   File: CardViewApi21.java   Source Code and License Vote up 6 votes
public void initialize(CardViewDelegate cardView, Context context, int backgroundColor, float radius, float elevation, float maxElevation) {
    cardView.setBackgroundDrawable(new RoundRectDrawable(backgroundColor, radius));
    View view = (View) cardView;
    view.setClipToOutline(true);
    view.setElevation(elevation);
    setMaxElevation(cardView, maxElevation);
}
 
Example 10
Project: GitHub   File: WoWoElevationAnimation.java   Source Code and License Vote up 5 votes
@Override
protected void toStartState(View view) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        view.setElevation(fromElevation);
    }
}
 
Example 11
Project: android_additive_animations   File: ElevationProperties.java   Source Code and License Vote up 5 votes
@Override
public void set(View object, Float value) {
    object.setElevation(value);
}
 
Example 12
Project: GitHub   File: WoWoElevationAnimation.java   Source Code and License Vote up 5 votes
@Override
protected void toEndState(View view) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        view.setElevation(toElevation);
    }
}
 
Example 13
Project: GitHub   File: CustomAnimation.java   Source Code and License Vote up 5 votes
@Override
protected void toMiddleState(View view, float offset) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        view.setElevation(fromElevation + (toElevation - fromElevation) * offset);
    }
}
 
Example 14
Project: GitHub   File: CustomAnimation.java   Source Code and License Vote up 5 votes
@Override
protected void toEndState(View view) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        view.setElevation(toElevation);
    }
}
 
Example 15
Project: Orin   File: PlaylistAdapter.java   Source Code and License Vote up 5 votes
public ViewHolder(@NonNull View itemView, int itemViewType) {
    super(itemView);

    if (itemViewType == SMART_PLAYLIST) {
        if (shortSeparator != null) {
            shortSeparator.setVisibility(View.GONE);
        }
        itemView.setBackgroundColor(ATHUtil.resolveColor(activity, R.attr.cardBackgroundColor));
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            itemView.setElevation(activity.getResources().getDimensionPixelSize(R.dimen.card_elevation));
        }
    }

    if (image != null) {
        int iconPadding = activity.getResources().getDimensionPixelSize(R.dimen.list_item_image_icon_padding);
        image.setPadding(iconPadding, iconPadding, iconPadding, iconPadding);
        image.setColorFilter(ATHUtil.resolveColor(activity, R.attr.iconColor), PorterDuff.Mode.SRC_IN);
    }

    if (menu != null) {
        menu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final Playlist playlist = dataSet.get(getAdapterPosition());
                final PopupMenu popupMenu = new PopupMenu(activity, view);
                popupMenu.inflate(getItemViewType() == SMART_PLAYLIST ? R.menu.menu_item_smart_playlist : R.menu.menu_item_playlist);
                if (playlist instanceof LastAddedPlaylist) {
                    popupMenu.getMenu().findItem(R.id.action_clear_playlist).setVisible(false);
                }
                popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                    @Override
                    public boolean onMenuItemClick(@NonNull MenuItem item) {
                        if (item.getItemId() == R.id.action_clear_playlist) {
                            if (playlist instanceof AbsSmartPlaylist) {
                                ClearSmartPlaylistDialog.create((AbsSmartPlaylist) playlist).show(activity.getSupportFragmentManager(), "CLEAR_SMART_PLAYLIST_" + playlist.name);
                                return true;
                            }
                        }
                        return PlaylistMenuHelper.handleMenuClick(
                                activity, dataSet.get(getAdapterPosition()), item);
                    }
                });
                popupMenu.show();
            }
        });
    }
}
 
Example 16
Project: Orin   File: SearchAdapter.java   Source Code and License Vote up 5 votes
public ViewHolder(@NonNull View itemView, int itemViewType) {
    super(itemView);
    itemView.setOnLongClickListener(null);

    if (itemViewType != HEADER) {
        itemView.setBackgroundColor(ATHUtil.resolveColor(activity, R.attr.cardBackgroundColor));
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            itemView.setElevation(activity.getResources().getDimensionPixelSize(R.dimen.card_elevation));
        }
        if (shortSeparator != null) {
            shortSeparator.setVisibility(View.GONE);
        }
    }

    if (menu != null) {
        if (itemViewType == SONG) {
            menu.setVisibility(View.VISIBLE);
            menu.setOnClickListener(new SongMenuHelper.OnClickSongMenu(activity) {
                @Override
                public Song getSong() {
                    return (Song) dataSet.get(getAdapterPosition());
                }
            });
        } else {
            menu.setVisibility(View.GONE);
        }
    }

    switch (itemViewType) {
        case ALBUM:
            setImageTransitionName(activity.getString(R.string.transition_album_art));
            break;
        case ARTIST:
            setImageTransitionName(activity.getString(R.string.transition_artist_image));
            break;
        default:
            View container = itemView.findViewById(R.id.image_container);
            if (container != null) {
                container.setVisibility(View.GONE);
            }
            break;
    }
}
 
Example 17
Project: letv   File: ViewCompatLollipop.java   Source Code and License Vote up 5 votes
public static void setElevation(View view, float elevation) {
    view.setElevation(elevation);
}
 
Example 18
Project: uob-timetable-android   File: AndroidUtilities.java   Source Code and License Vote up 5 votes
public static void trySetElevation(View control, float elevation){

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
            control.setElevation(elevation);
    }
 
Example 19
Project: spline   File: HuePicker.java   Source Code and License Vote up 5 votes
public HuePicker(Context context, AttributeSet attrs) {
    super(context, attrs);

    mListeners = new ArrayList<OnHueChangeListener>();

    setClipChildren(false);
    setClipToPadding(false);

    DisplayMetrics metrics = context.getResources().getDisplayMetrics();
    mDensity = metrics.density;

    mSelectorRadius = SELECTOR_RADIUS_DP * mDensity;

    // We want the selector to protrude as minimally as possible from the background drawable
    // and we want to inset the gradients in the drawable so that the color under the
    // selector's midpoint always reflects the current color (thus the limits of the background
    // gradient have to be clamped at this inset. The inset value is thus the base side of a
    // triangle extending from the midpoint of the selector placed in the desired position, a
    // hypotenuse equal to the selector radius and a height side equal to half of the height of
    // the background drawable.
    float height = BACKGROUND_HEIGHT_DP * mDensity / 2.0f;
    mInset = Math.round(
            Math.sqrt(mSelectorRadius * mSelectorRadius - height * height)
    );

    mSelectorParams = new LayoutParams(
            Math.round(mSelectorRadius * 2), Math.round(mSelectorRadius * 2)
    );

    mBackground = new View(context);
    mBackground.setBackground(new HueDrawable());
    addView(mBackground);

    mSelector = new View(getContext());
    mSelector.setLayoutParams(mSelectorParams);
    mSelectorDrawable = (GradientDrawable) ContextCompat.getDrawable(
            getContext(),
            R.drawable.drawable_selector);
    mSelector.setBackground(mSelectorDrawable);
    mSelector.setElevation(SELECTOR_ELEVATION_DP * mDensity);
    addView(mSelector);

    // Full saturation / full value color used for the selector background
    mHueColor = new Color(0xffff0000);
    updateSelectorColor();
}
 
Example 20
Project: Phial   File: ViewCompat.java   Source Code and License Vote up 5 votes
public static void setElevation(View view, float elevation) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        view.setElevation(elevation);
    }
}