Java Code Examples for android.support.v4.view.ViewCompat#setLayerType()
The following examples show how to use
android.support.v4.view.ViewCompat#setLayerType() .
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: MaterialBadgeTextView.java From Android with MIT License | 6 votes |
/** * * @param isDisplayInToolbarMenu */ public void setHighLightMode(boolean isDisplayInToolbarMenu){ isHighLightMode = true; ViewGroup.LayoutParams params = getLayoutParams(); params.width = ViewGroup.LayoutParams.WRAP_CONTENT; params.height = params.width; if(isDisplayInToolbarMenu && params instanceof FrameLayout.LayoutParams){ ((FrameLayout.LayoutParams)params).topMargin=dp2px(getContext(), 10); ((FrameLayout.LayoutParams)params).rightMargin=dp2px(getContext(), 10); } setLayoutParams(params); final int diameter = getWidth() - (int) (2.5 * (float) mShadowRadius); OvalShadow oval = new OvalShadow(mShadowRadius, diameter); ShapeDrawable drawable = new ShapeDrawable(oval); ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, drawable.getPaint()); drawable.getPaint().setColor(backgroundColor); drawable.getPaint().setAntiAlias(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { setBackground(drawable); } else { setBackgroundDrawable(drawable); } setText(""); setVisibility(View.VISIBLE); }
Example 2
Source File: SlidingPaneLayout.java From V.FlyoutTest with MIT License | 6 votes |
private void dimChildView(View v, float mag, int fadeColor) { final LayoutParams lp = (LayoutParams) v.getLayoutParams(); if (mag > 0 && fadeColor != 0) { final int baseAlpha = (fadeColor & 0xff000000) >>> 24; int imag = (int) (baseAlpha * mag); int color = imag << 24 | (fadeColor & 0xffffff); if (lp.dimPaint == null) { lp.dimPaint = new Paint(); } lp.dimPaint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_OVER)); if (ViewCompat.getLayerType(v) != ViewCompat.LAYER_TYPE_HARDWARE) { ViewCompat.setLayerType(v, ViewCompat.LAYER_TYPE_HARDWARE, lp.dimPaint); } invalidateChildRegion(v); } else if (ViewCompat.getLayerType(v) != ViewCompat.LAYER_TYPE_NONE) { if (lp.dimPaint != null) { lp.dimPaint.setColorFilter(null); } final DisableLayerRunnable dlr = new DisableLayerRunnable(v); mPostedRunnables.add(dlr); ViewCompat.postOnAnimation(this, dlr); } }
Example 3
Source File: SlidingPaneLayout.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
private void dimChildView(View v, float mag, int fadeColor) { final LayoutParams lp = (LayoutParams) v.getLayoutParams(); if (mag > 0 && fadeColor != 0) { final int baseAlpha = (fadeColor & 0xff000000) >>> 24; int imag = (int) (baseAlpha * mag); int color = imag << 24 | (fadeColor & 0xffffff); if (lp.dimPaint == null) { lp.dimPaint = new Paint(); } lp.dimPaint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_OVER)); if (ViewCompat.getLayerType(v) != ViewCompat.LAYER_TYPE_HARDWARE) { ViewCompat.setLayerType(v, ViewCompat.LAYER_TYPE_HARDWARE, lp.dimPaint); } invalidateChildRegion(v); } else if (ViewCompat.getLayerType(v) != ViewCompat.LAYER_TYPE_NONE) { if (lp.dimPaint != null) { lp.dimPaint.setColorFilter(null); } final DisableLayerRunnable dlr = new DisableLayerRunnable(v); mPostedRunnables.add(dlr); ViewCompat.postOnAnimation(this, dlr); } }
Example 4
Source File: ResideLayout.java From ResideLayout with Apache License 2.0 | 6 votes |
private void dimChildView(View v, float mag, int fadeColor) { final LayoutParams lp = (LayoutParams) v.getLayoutParams(); if (mag > 0 && fadeColor != 0) { final int baseAlpha = (fadeColor & 0xff000000) >>> 24; int imag = (int) (baseAlpha * mag); int color = imag << 24 | (fadeColor & 0xffffff); if (lp.dimPaint == null) { lp.dimPaint = new Paint(); } lp.dimPaint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_OVER)); if (ViewCompat.getLayerType(v) != ViewCompat.LAYER_TYPE_HARDWARE) { ViewCompat.setLayerType(v, ViewCompat.LAYER_TYPE_HARDWARE, lp.dimPaint); } invalidateChildRegion(v); } else if (ViewCompat.getLayerType(v) != ViewCompat.LAYER_TYPE_NONE) { if (lp.dimPaint != null) { lp.dimPaint.setColorFilter(null); } final DisableLayerRunnable dlr = new DisableLayerRunnable(v); mPostedRunnables.add(dlr); ViewCompat.postOnAnimation(this, dlr); } }
Example 5
Source File: SlidingPaneLayout.java From adt-leanback-support with Apache License 2.0 | 6 votes |
private void dimChildView(View v, float mag, int fadeColor) { final LayoutParams lp = (LayoutParams) v.getLayoutParams(); if (mag > 0 && fadeColor != 0) { final int baseAlpha = (fadeColor & 0xff000000) >>> 24; int imag = (int) (baseAlpha * mag); int color = imag << 24 | (fadeColor & 0xffffff); if (lp.dimPaint == null) { lp.dimPaint = new Paint(); } lp.dimPaint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_OVER)); if (ViewCompat.getLayerType(v) != ViewCompat.LAYER_TYPE_HARDWARE) { ViewCompat.setLayerType(v, ViewCompat.LAYER_TYPE_HARDWARE, lp.dimPaint); } invalidateChildRegion(v); } else if (ViewCompat.getLayerType(v) != ViewCompat.LAYER_TYPE_NONE) { if (lp.dimPaint != null) { lp.dimPaint.setColorFilter(null); } final DisableLayerRunnable dlr = new DisableLayerRunnable(v); mPostedRunnables.add(dlr); ViewCompat.postOnAnimation(this, dlr); } }
Example 6
Source File: VelocityViewPager.java From Rey-MusicPlayer with Apache License 2.0 | 5 votes |
private void enableLayers(boolean enable) { final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final int layerType = enable ? ViewCompat.LAYER_TYPE_HARDWARE : ViewCompat.LAYER_TYPE_NONE; ViewCompat.setLayerType(getChildAt(i), layerType, null); } }
Example 7
Source File: ViewPagerCompat.java From android-project-wo2b with Apache License 2.0 | 5 votes |
private void enableLayers(boolean enable) { final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final int layerType = enable ? ViewCompat.LAYER_TYPE_HARDWARE : ViewCompat.LAYER_TYPE_NONE; ViewCompat.setLayerType(getChildAt(i), layerType, null); } }
Example 8
Source File: SwipeBackLayout.java From AndroidProjects with MIT License | 5 votes |
@Override public void run() { if (mChildView.getParent() == SwipeBackLayout.this) { ViewCompat.setLayerType(mChildView, ViewCompat.LAYER_TYPE_NONE, null); invalidateChildRegion(mChildView); } mPostedRunnables.remove(this); }
Example 9
Source File: VerticalViewPager.java From VerticalViewPager with MIT License | 5 votes |
private void enableLayers(boolean enable) { final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final int layerType = enable ? ViewCompat.LAYER_TYPE_HARDWARE : ViewCompat.LAYER_TYPE_NONE; ViewCompat.setLayerType(getChildAt(i), layerType, null); } }
Example 10
Source File: SlidingPaneLayout.java From VCL-Android with Apache License 2.0 | 5 votes |
@Override public void run() { if (mChildView.getParent() == SlidingPaneLayout.this) { ViewCompat.setLayerType(mChildView, ViewCompat.LAYER_TYPE_NONE, null); invalidateChildRegion(mChildView); } mPostedRunnables.remove(this); }
Example 11
Source File: SlidingPaneLayout.java From guideshow with MIT License | 5 votes |
@Override public void run() { if (mChildView.getParent() == SlidingPaneLayout.this) { ViewCompat.setLayerType(mChildView, ViewCompat.LAYER_TYPE_NONE, null); invalidateChildRegion(mChildView); } mPostedRunnables.remove(this); }
Example 12
Source File: SlidingUpPanel.java From Android-SlidingUpPanel with MIT License | 5 votes |
private void enableLayers(boolean enable) { final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final int layerType = enable ? ViewCompat.LAYER_TYPE_HARDWARE : ViewCompat.LAYER_TYPE_NONE; ViewCompat.setLayerType(getChildAt(i), layerType, null); } }
Example 13
Source File: SlidingPaneLayout.java From android-recipes-app with Apache License 2.0 | 5 votes |
@Override public void run() { if (mChildView.getParent() == SlidingPaneLayout.this) { ViewCompat.setLayerType(mChildView, ViewCompat.LAYER_TYPE_NONE, null); invalidateChildRegion(mChildView); } mPostedRunnables.remove(this); }
Example 14
Source File: NineOldViewPager.java From ncalc with GNU General Public License v3.0 | 5 votes |
private void enableLayers(boolean enable) { final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final int layerType = enable ? ViewCompat.LAYER_TYPE_HARDWARE : ViewCompat.LAYER_TYPE_NONE; ViewCompat.setLayerType(getChildAt(i), layerType, null); } }
Example 15
Source File: OrientedViewPager.java From FlippableStackView with Apache License 2.0 | 5 votes |
private void enableLayers(boolean enable) { final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final int layerType = enable ? ViewCompat.LAYER_TYPE_HARDWARE : ViewCompat.LAYER_TYPE_NONE; ViewCompat.setLayerType(getChildAt(i), layerType, null); } }
Example 16
Source File: ViewPagerEx.java From AndroidImageSlider with MIT License | 5 votes |
private void enableLayers(boolean enable) { final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final int layerType = enable ? ViewCompat.LAYER_TYPE_HARDWARE : ViewCompat.LAYER_TYPE_NONE; ViewCompat.setLayerType(getChildAt(i), layerType, null); } }
Example 17
Source File: YViewPager.java From YViewPagerDemo with Apache License 2.0 | 5 votes |
private void enableLayers(boolean enable) { final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final int layerType = enable ? ViewCompat.LAYER_TYPE_HARDWARE : ViewCompat.LAYER_TYPE_NONE; ViewCompat.setLayerType(getChildAt(i), layerType, null); } }
Example 18
Source File: DirectionalViewpager.java From fangzhuishushenqi with Apache License 2.0 | 5 votes |
private void enableLayers(boolean enable) { final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final int layerType = enable ? ViewCompat.LAYER_TYPE_HARDWARE : ViewCompat.LAYER_TYPE_NONE; ViewCompat.setLayerType(getChildAt(i), layerType, null); } }
Example 19
Source File: MainActivity.java From ShadowViewHelper with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); shadowViewA = findViewById(R.id.activity_main_shadow_view_a); shadowViewB = findViewById(R.id.activity_main_shadow_view_b); shadowViewC = findViewById(R.id.activity_main_shadow_view_c); shadowViewC.setOnClickListener(this); shadowImageC = findViewById(R.id.activity_main_shadow_view_c_iv); shadowViewD = findViewById(R.id.activity_main_shadow_view_d); shadowTvC = (TextView) findViewById(R.id.activity_main_shadow_view_c_tv); // all sides shadow ShadowProperty sp = new ShadowProperty() .setShadowColor(0x77000000) .setShadowDy(dip2px(this, 0.5f)) .setShadowRadius(dip2px(this, 3)) .setShadowSide(ShadowProperty.ALL); ShadowViewDrawable sd = new ShadowViewDrawable(sp, Color.WHITE, 0, 0); ViewCompat.setBackground(shadowViewA, sd); ViewCompat.setLayerType(shadowViewA, ViewCompat.LAYER_TYPE_SOFTWARE, null); // only left and top sides shadow sp = new ShadowProperty() .setShadowColor(0x77FF0000) .setShadowDy(dip2px(this, 0.5f)) .setShadowRadius(dip2px(this, 3)) .setShadowSide(ShadowProperty.LEFT | ShadowProperty.BOTTOM); sd = new ShadowViewDrawable(sp, Color.TRANSPARENT, 0, 0); ViewCompat.setBackground(shadowViewB, sd); ViewCompat.setLayerType(shadowViewB, ViewCompat.LAYER_TYPE_SOFTWARE, null); // only top and bottom sides shadow sp = new ShadowProperty() .setShadowColor(0x77000000) .setShadowDy(dip2px(this, 0.5f)) .setShadowRadius(dip2px(this, 3)) .setShadowSide(ShadowProperty.TOP | ShadowProperty.BOTTOM); sd = new ShadowViewDrawable(sp, Color.WHITE, 0, 0); ViewCompat.setBackground(shadowViewC, sd); ViewCompat.setLayerType(shadowViewC, ViewCompat.LAYER_TYPE_SOFTWARE, null); sp = new ShadowProperty() .setShadowColor(0x77000000) .setShadowDy(dip2px(this, 0.5f)) .setShadowRadius(dip2px(this, 3)) .setShadowSide(ShadowProperty.BOTTOM | ShadowProperty.RIGHT); sd = new ShadowViewDrawable(sp, Color.WHITE, 0, 0); ViewCompat.setBackground(shadowImageC, sd); ViewCompat.setLayerType(shadowImageC, ViewCompat.LAYER_TYPE_SOFTWARE, null); // only all sides except top shadow sp = new ShadowProperty() .setShadowColor(0x770000FF) .setShadowDy(dip2px(this, 0.5f)) .setShadowRadius(dip2px(this, 3)) .setShadowSide(ShadowProperty.LEFT | ShadowProperty.RIGHT | ShadowProperty.BOTTOM); sd = new ShadowViewDrawable(sp, Color.TRANSPARENT, 0, 0); ViewCompat.setBackground(shadowViewD, sd); ViewCompat.setLayerType(shadowViewD, ViewCompat.LAYER_TYPE_SOFTWARE, null); }
Example 20
Source File: NavigationTabStrip.java From iGap-Android with GNU Affero General Public License v3.0 | 4 votes |
public NavigationTabStrip(final Context context, final AttributeSet attrs, final int defStyleAttr) { super(context, attrs, defStyleAttr); //Init NTS // Always draw setWillNotDraw(false); // Speed and fix for pre 17 API ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, null); setLayerType(LAYER_TYPE_SOFTWARE, null); DEFAULT_TITLE_BADGE_TOP = (int) getResources().getDimension(R.dimen.dp12); PADDING = (int) getResources().getDimension(R.dimen.dp4); final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NavigationTabStrip); try { setStripColor(typedArray.getColor(R.styleable.NavigationTabStrip_nts_color, DEFAULT_STRIP_COLOR)); setTitleSize(typedArray.getDimension(R.styleable.NavigationTabStrip_nts_size, DEFAULT_TITLE_SIZE)); setStripWeight(typedArray.getDimension(R.styleable.NavigationTabStrip_nts_weight, DEFAULT_STRIP_WEIGHT)); setStripFactor(typedArray.getFloat(R.styleable.NavigationTabStrip_nts_factor, DEFAULT_STRIP_FACTOR)); setStripType(typedArray.getInt(R.styleable.NavigationTabStrip_nts_type, StripType.LINE_INDEX)); setStripGravity(typedArray.getInt(R.styleable.NavigationTabStrip_nts_gravity, StripGravity.BOTTOM_INDEX)); setTypeface(typedArray.getString(R.styleable.NavigationTabStrip_nts_typeface)); setInactiveColor(typedArray.getColor(R.styleable.NavigationTabStrip_nts_inactive_color, DEFAULT_INACTIVE_COLOR)); setActiveColor(typedArray.getColor(R.styleable.NavigationTabStrip_nts_active_color, DEFAULT_ACTIVE_COLOR)); setAnimationDuration(typedArray.getInteger(R.styleable.NavigationTabStrip_nts_animation_duration, DEFAULT_ANIMATION_DURATION)); setCornersRadius(typedArray.getDimension(R.styleable.NavigationTabStrip_nts_corners_radius, DEFAULT_CORNER_RADIUS)); // Get titles String[] titles = null; try { final int titlesResId = typedArray.getResourceId(R.styleable.NavigationTabStrip_nts_titles, 0); titles = titlesResId == 0 ? null : typedArray.getResources().getStringArray(titlesResId); } catch (Exception exception) { titles = null; exception.printStackTrace(); } finally { if (titles == null) { if (isInEditMode()) { titles = new String[new Random().nextInt(5) + 1]; Arrays.fill(titles, PREVIEW_TITLE); } else { titles = new String[0]; } } setTitles(titles); } // Init animator mAnimator.setFloatValues(MIN_FRACTION, MAX_FRACTION); mAnimator.setInterpolator(new LinearInterpolator()); mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(final ValueAnimator animation) { updateIndicatorPosition((Float) animation.getAnimatedValue()); } }); } finally { typedArray.recycle(); } }