private static void setShadowElevation(View view, float shadowElevation) { if (shadowElevation != 0) { ViewCompat.setElevation(view, shadowElevation); } }
private static void unsetShadowElevation(View view, float shadowElevation) { if (shadowElevation != 0) { ViewCompat.setElevation(view, 0); } }
/** * modify the elevation of multiples views * * @param elevation the new elevation * @param views */ static void setElevation(float elevation, View... views) { for (View view : views) { if (view != null) { ViewCompat.setElevation(view, elevation); } } }
@Override public void setElevationShadow(int backgroundColor, float elevation) { mView.setBackgroundColor(backgroundColor); ViewCompat.setElevation(mView,elevation); mView.invalidate(); } }
/** * must setting a color when set shadow, not transparent. * @param backgroundColor * @param elevation */ public void setElevationShadow(int backgroundColor, float elevation) { setBackgroundColor(backgroundColor); ViewCompat.setElevation(this, elevation); }
@Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); float elevation; if (recyclerView.canScrollVertically(SCROLL_DIRECTION_UP)) { elevation = getResources().getDimension(R.dimen.search_scrolling_elevation); } else { elevation = getResources().getDimension(R.dimen.search_resting_elevation); } ViewCompat.setElevation(currentPlaceCardView, elevation); ViewCompat.setElevation(searchCardView, elevation); } });
@Override public void onAnimationEnd(Animator animation) { ViewCompat.setElevation(getToolbar(), Utils.dpToPx(8)); animateContent(); } })
@Override public void onBackPressed() { ViewCompat.setElevation(getToolbar(), 0); contentRoot.animate() .translationY(Utils.getScreenHeight(this)) .setDuration(200) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { CommentsActivity.super.onBackPressed(); overridePendingTransition(0, 0); } }) .start(); }
private void startIntroAnimation() { ViewCompat.setElevation(getToolbar(), 0); contentRoot.setScaleY(0.1f); contentRoot.setPivotY(drawingStartLocation); llAddComment.setTranslationY(200); contentRoot.animate() .scaleY(1) .setDuration(200) .setInterpolator(new AccelerateInterpolator()) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { ViewCompat.setElevation(getToolbar(), Utils.dpToPx(8)); animateContent(); } }) .start(); }
public IntentPickerSheetView(Context context, final Intent intent, final String title, final OnIntentPickedListener listener) { super(context); this.intent = intent; inflate(context, R.layout.grid_sheet_view, this); appGrid = (GridView) findViewById(R.id.grid); titleView = (TextView) findViewById(R.id.title); titleView.setText(title); appGrid.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { listener.onIntentPicked(adapter.getItem(position)); } }); ViewCompat.setElevation(this, Util.dp2px(getContext(), 16f)); }
@Override public void onBindViewHolder(final VideoItemHolder holder, final int position) { ViewCompat.setElevation(holder.card, PUtil.dip2px(mContext, 3)); updateWH(holder); final VideoBean item = getItem(position);
private void initBackground(float radius) { final float density = getContext().getResources().getDisplayMetrics().density; final int diameter = (int) (radius * density * 2); final int shadowYOffset = (int) (density * Y_OFFSET); final int shadowXOffset = (int) (density * X_OFFSET); final int color = Color.parseColor("#FFFAFAFA"); mShadowRadius = (int) (density * SHADOW_RADIUS); ShapeDrawable circle; if (elevationSupported()) { circle = new ShapeDrawable(new OvalShape()); ViewCompat.setElevation(this, SHADOW_ELEVATION * density); } else { OvalShape oval = new OvalShadow(mShadowRadius, diameter); circle = new ShapeDrawable(oval); ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, circle.getPaint()); circle.getPaint().setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset, KEY_SHADOW_COLOR); final int padding = mShadowRadius; // set padding so the inner image sits correctly within the shadow. setPadding(padding, padding, padding, padding); } circle.getPaint().setColor(color); setBackgroundDrawable(circle); }
public CircleImageView(Context context, int color, final float radius) { super(context); final float density = getContext().getResources().getDisplayMetrics().density; final int diameter = (int) (radius * density * 2); final int shadowYOffset = (int) (density * Y_OFFSET); final int shadowXOffset = (int) (density * X_OFFSET); mShadowRadius = (int) (density * SHADOW_RADIUS); ShapeDrawable circle; if (elevationSupported()) { circle = new ShapeDrawable(new OvalShape()); ViewCompat.setElevation(this, SHADOW_ELEVATION * density); } else { OvalShape oval = new OvalShadow(mShadowRadius, diameter); circle = new ShapeDrawable(oval); ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, circle.getPaint()); circle.getPaint().setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset, KEY_SHADOW_COLOR); final int padding = mShadowRadius; // set padding so the inner image sits correctly within the shadow. setPadding(padding, padding, padding, padding); } circle.getPaint().setColor(color); setBackgroundDrawable(circle); }
/** * @param context Context to construct the view with * @param menuType LIST or GRID * @param title Title for the sheet. Can be null * @param listener Listener for menu item clicks in the sheet */ public MenuSheetView(final Context context, final MenuType menuType, @Nullable final CharSequence title, final OnMenuItemClickListener listener) { super(context); // Set up the menu this.menu = new MenuBuilder(context); this.menuType = menuType; // Inflate the appropriate view and set up the absListView inflate(context, menuType == GRID ? R.layout.grid_sheet_view : R.layout.list_sheet_view, this); absListView = (AbsListView) findViewById(menuType == GRID ? R.id.grid : R.id.list); if (listener != null) { absListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { listener.onMenuItemClick(adapter.getItem(position).getMenuItem()); } }); } // Set up the title titleView = (TextView) findViewById(R.id.title); originalListPaddingTop = absListView.getPaddingTop(); setTitle(title); ViewCompat.setElevation(this, Util.dp2px(getContext(), 16f)); }
/** * Sets the elevation level of the header view. If you are not able to see the elevation shadow * you should set a background(-color) to the header. * * @param elevation The elevation that shall be set to the table header. */ public void setHeaderElevation(final int elevation) { ViewCompat.setElevation(tableHeaderView, elevation); }
tileLayout = builder.tileLayout; ViewCompat.setElevation(this, Util.dp2px(getContext(), 16f));
ViewCompat.setElevation(this, SHADOW_ELEVATION * density); } else { OvalShape oval = new OvalShadow(mShadowRadius, mDiameter - mShadowRadius * 2);
ViewCompat.setElevation(this, SHADOW_ELEVATION * density); } else { OvalShape oval = new OvalShadow(mShadowRadius, mDiameter - mShadowRadius * 2);
/** * This is an experimental feature for elevation of material design. */ private void updateElevation() { float elevation = getDomObject().getAttrs().getElevation(getInstance().getViewPortWidth()); if (!Float.isNaN(elevation)) { ViewCompat.setElevation(getHostView(), elevation); } }
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); width = getMeasuredWidth(); height = getMeasuredHeight(); mClipPath = PathProvider.getClipPath(width, height, curvatureHeight, curvatureDirection, gravity); ViewCompat.setElevation(this, ViewCompat.getElevation(this)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { try { setOutlineProvider(getOutlineProvider()); } catch (Exception e) { Log.d(TAG, e.getMessage()); } } }