Example usage for android.view View setLayerType

List of usage examples for android.view View setLayerType

Introduction

In this page you can find the example usage for android.view View setLayerType.

Prototype

public void setLayerType(int layerType, @Nullable Paint paint) 

Source Link

Document

Specifies the type of layer backing this view.

Usage

From source file:Main.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static void setLayerTypeSoftwareToView(View view) {
    if (Build.VERSION.SDK_INT >= 11) {
        view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }/*from  w w w. j  a va2 s.c o m*/
}

From source file:Main.java

/**
 * This method setting layer type to sowftware.
 *
 * @param view view which would be set./*  ww  w .  j  a v a 2 s.co m*/
 */
public static void setLayerToSW(View view) {
    if (!view.isInEditMode() && Build.VERSION.SDK_INT >= 11) {
        view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }
}

From source file:Main.java

/**
 * Method that removes the support for HardwareAcceleration from a {@link View}.<br/>
 * <br/>/*from  ww  w . j  av a  2  s .  c o m*/
 * Check AOSP notice:<br/>
 * <pre>
 * 'ComposeShader can only contain shaders of different types (a BitmapShader and a
 * LinearGradient for instance, but not two instances of BitmapShader)'. But, 'If your
 * application is affected by any of these missing features or limitations, you can turn
 * off hardware acceleration for just the affected portion of your application by calling
 * setLayerType(View.LAYER_TYPE_SOFTWARE, null).'</pre>
 *
 * @param v The view
 */
public static void removeHardwareAccelerationSupport(View v) {
    if (v.getLayerType() != View.LAYER_TYPE_SOFTWARE) {
        v.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }
}

From source file:Main.java

@SuppressLint("NewApi")
public static void disableHardwareAcceleration(View v) {
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB)
        v.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static void disableHardwareAcceleration(View view) {
    // HA was introduced in Honeycomb.
    if (isHoneycomb())
        view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}

From source file:Main.java

public static void compatDisableViewHardware(View view) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        try {/*w  ww .j av a2  s .com*/
            view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        } catch (NoSuchMethodError e) {
        }
    }
}

From source file:Main.java

@TargetApi(11)
public static void setLayerType(View view, int layerType, Paint paint) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        view.setLayerType(layerType, paint);
    }/*from  ww w .  j  a  v  a  2  s  . c o  m*/
}

From source file:com.android.deskclock.Utils.java

/**
 * For screensavers to dim the lights if necessary.
 *//*from  www.jav  a  2 s  . c  o m*/
public static void dimClockView(boolean dim, View clockView) {
    Paint paint = new Paint();
    paint.setColor(Color.WHITE);
    paint.setColorFilter(new PorterDuffColorFilter((dim ? 0x40FFFFFF : 0xC0FFFFFF), PorterDuff.Mode.MULTIPLY));
    clockView.setLayerType(View.LAYER_TYPE_HARDWARE, paint);
}

From source file:Main.java

public static void expand(final View v, final int targetHeight, int duration, Interpolator interpolator,
        final Animation.AnimationListener listener) {
    final int initialHeight = v.getMeasuredHeight();
    Animation a = new Animation() {
        @Override//  w  ww.  j  a  v a2 s .c om
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            v.getLayoutParams().height = initialHeight + (int) (targetHeight * interpolatedTime);
            v.requestLayout();
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };
    a.setDuration(duration);
    if (interpolator != null) {
        a.setInterpolator(interpolator);
    }
    a.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
            v.setLayerType(View.LAYER_TYPE_HARDWARE, null);
            if (listener != null)
                listener.onAnimationStart(animation);
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            v.setLayerType(View.LAYER_TYPE_NONE, null);
            if (listener != null)
                listener.onAnimationEnd(animation);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            if (listener != null)
                onAnimationRepeat(animation);
        }
    });

    v.startAnimation(a);
}

From source file:com.app.chatbot.fragment.BaseFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(getFragmentLayout(), container, false);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH
            && Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }//from w w w.ja  v  a 2 s .c om
    injectViews(view);
    return view;
}