Example usage for android.view View setWillNotCacheDrawing

List of usage examples for android.view View setWillNotCacheDrawing

Introduction

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

Prototype

@Deprecated
public void setWillNotCacheDrawing(boolean willNotCacheDrawing) 

Source Link

Document

When a View's drawing cache is enabled, drawing is redirected to an offscreen bitmap.

Usage

From source file:Main.java

public static void viewBaseSetting(View target) {
    target.setFadingEdgeLength(0);/*from   ww  w .jav  a2s.com*/
    //      target.setWillNotDraw(true);
    target.setWillNotCacheDrawing(true);
    target.setBackgroundColor(0x00000000);
}

From source file:Main.java

public static Bitmap convertViewToBitmap(View comBitmap, int width, int height) {
    Bitmap bitmap = null;/*from  w ww.  j av a 2s. c o  m*/
    if (comBitmap != null) {
        comBitmap.clearFocus();
        comBitmap.setPressed(false);

        boolean willNotCache = comBitmap.willNotCacheDrawing();
        comBitmap.setWillNotCacheDrawing(false);

        // Reset the drawing cache background color to fully transparent
        // for the duration of this operation
        int color = comBitmap.getDrawingCacheBackgroundColor();
        comBitmap.setDrawingCacheBackgroundColor(0);
        float alpha = comBitmap.getAlpha();
        comBitmap.setAlpha(1.0f);

        if (color != 0) {
            comBitmap.destroyDrawingCache();
        }

        int widthSpec = View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY);
        int heightSpec = View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY);
        comBitmap.measure(widthSpec, heightSpec);
        comBitmap.layout(0, 0, width, height);

        comBitmap.buildDrawingCache();
        Bitmap cacheBitmap = comBitmap.getDrawingCache();
        if (cacheBitmap == null) {
            Log.e("view.ProcessImageToBlur", "failed getViewBitmap(" + comBitmap + ")", new RuntimeException());
            return null;
        }
        bitmap = Bitmap.createBitmap(cacheBitmap);
        // Restore the view
        comBitmap.setAlpha(alpha);
        comBitmap.destroyDrawingCache();
        comBitmap.setWillNotCacheDrawing(willNotCache);
        comBitmap.setDrawingCacheBackgroundColor(color);
    }
    return bitmap;
}

From source file:com.yk.notification.util.BitmapUtil.java

/**
 * View??bitmap//from   w ww  . j ava 2s .co m
 * 
 * @param view
 *            View
 * @return Bitmap
 */
public static Bitmap getBitmapFromView2(View view) {

    view.clearFocus();
    view.setPressed(false);

    // false
    boolean willNotCache = view.willNotCacheDrawing();
    view.setWillNotCacheDrawing(false);
    int color = view.getDrawingCacheBackgroundColor();
    view.setDrawingCacheBackgroundColor(0);
    if (color != 0) {
        view.destroyDrawingCache();
    }
    view.buildDrawingCache();
    Bitmap cacheBitmap = view.getDrawingCache();
    if (cacheBitmap == null) {
        if (DEBUG) {
            Log.e(TAG, "failed getViewBitmap(" + view + ")", new RuntimeException());
        }
        return null;
    }
    Bitmap bitmap = Bitmap.createBitmap(cacheBitmap);
    // Restore the view
    view.destroyDrawingCache();
    view.setWillNotCacheDrawing(willNotCache);
    view.setDrawingCacheBackgroundColor(color);
    return bitmap;
}

From source file:org.appcelerator.titanium.util.TiUIHelper.java

/**
 * Draw the view into a bitmap.//from ww w .ja  v  a 2 s . c  om
 */
public static Bitmap getViewBitmap(final View v) {
    v.clearFocus();
    v.setPressed(false);

    boolean willNotCache = v.willNotCacheDrawing();

    // Reset the drawing cache background color to fully transparent
    // for the duration of this operation
    int color = v.getDrawingCacheBackgroundColor();

    if (willNotCache || color != 0) {
        v.setWillNotCacheDrawing(false);
        v.setDrawingCacheBackgroundColor(0);
        v.destroyDrawingCache();
    }

    boolean isDrawinCacheEnabled = v.isDrawingCacheEnabled();

    Bitmap bitmap = null;

    try {
        v.setDrawingCacheEnabled(true);
        v.buildDrawingCache(true);
        bitmap = Bitmap.createBitmap(v.getDrawingCache(true));
    } catch (Exception e) {
        bitmap = null;
    }
    v.setDrawingCacheEnabled(isDrawinCacheEnabled);

    // Restore the view
    if (willNotCache || color != 0) {
        v.destroyDrawingCache();
        v.setDrawingCacheBackgroundColor(color);
        v.setWillNotCacheDrawing(willNotCache);
    }

    return bitmap;
}

From source file:com.example.android_test.loopviewpager.LoopViewPager.java

Bitmap getViewBitmap(View v) {
    v.clearFocus();/*from  w  w w .  ja va  2 s .c o m*/
    v.setPressed(false);

    // ??????????
    boolean willNotCache = v.willNotCacheDrawing();
    int color = v.getDrawingCacheBackgroundColor();

    // ???????
    v.setWillNotCacheDrawing(false);

    // ???????
    v.setDrawingCacheBackgroundColor(0);

    // ????
    if (color != 0) {
        v.destroyDrawingCache();
    }

    // ??????
    v.buildDrawingCache();

    // ? Bitmap ?
    Bitmap cacheBitmap = v.getDrawingCache();
    if (cacheBitmap == null) {
        Log.e(TAG, "failed getViewBitmap(" + v + ")", new RuntimeException());
        return null;
    }

    // ? Bitmap ???????? Bitmap ?
    Bitmap bitmap = Bitmap.createBitmap(cacheBitmap);

    // ??????????
    v.destroyDrawingCache();
    v.setWillNotCacheDrawing(willNotCache);
    v.setDrawingCacheBackgroundColor(color);

    return bitmap;
}

From source file:org.chinenv.onroad.loopview.LoopViewPager.java

Bitmap getViewBitmap(View v) {
    v.clearFocus();/*  w  w  w . ja  va 2  s  .  co m*/
    v.setPressed(false);

    // ??????????
    boolean willNotCache = v.willNotCacheDrawing();
    int color = v.getDrawingCacheBackgroundColor();

    // ????????
    v.setWillNotCacheDrawing(false);

    // ????????
    v.setDrawingCacheBackgroundColor(0);

    // ?????
    if (color != 0) {
        v.destroyDrawingCache();
    }

    // ??????
    v.buildDrawingCache();

    // ?Bitmap ??
    Bitmap cacheBitmap = v.getDrawingCache();
    if (cacheBitmap == null) {
        Log.e(TAG, "failed getViewBitmap(" + v + ")", new RuntimeException());
        return null;
    }

    // ?Bitmap ???????? Bitmap ?
    Bitmap bitmap = Bitmap.createBitmap(cacheBitmap);

    // ??????????
    v.destroyDrawingCache();
    v.setWillNotCacheDrawing(willNotCache);
    v.setDrawingCacheBackgroundColor(color);

    return bitmap;
}

From source file:com.baiiu.autoloopviewpager.loopvp.LoopViewPager.java

Bitmap getViewBitmap(View v) {
    v.clearFocus();//  w  ww.j  a v  a  2 s.co  m
    v.setPressed(false);

    // ??????????
    boolean willNotCache = v.willNotCacheDrawing();
    int color = v.getDrawingCacheBackgroundColor();

    // ???????
    v.setWillNotCacheDrawing(false);

    // ???????
    v.setDrawingCacheBackgroundColor(0);

    // ????
    if (color != 0) {
        v.destroyDrawingCache();
    }

    // ??????
    v.buildDrawingCache();

    // ? Bitmap ?
    Bitmap cacheBitmap = v.getDrawingCache();
    if (cacheBitmap == null) {
        if (DEBUG)
            Log.e(TAG, "failed getViewBitmap(" + v + ")", new RuntimeException());
        return null;
    }

    // ? Bitmap ???????? Bitmap ?
    Bitmap bitmap = Bitmap.createBitmap(cacheBitmap);

    // ??????????
    v.destroyDrawingCache();
    v.setWillNotCacheDrawing(willNotCache);
    v.setDrawingCacheBackgroundColor(color);

    return bitmap;
}