Example usage for android.view ViewGroup getDrawingCache

List of usage examples for android.view ViewGroup getDrawingCache

Introduction

In this page you can find the example usage for android.view ViewGroup getDrawingCache.

Prototype

@Deprecated
public Bitmap getDrawingCache() 

Source Link

Document

Calling this method is equivalent to calling getDrawingCache(false).

Usage

From source file:Main.java

public static void prepare(Activity activity, int id, int width) {
    if (sCoverBitmap != null) {
        sCoverBitmap.recycle();//  www  .  j  a  v a 2 s  .c  o  m
    }
    Rect rectgle = new Rect();
    Window window = activity.getWindow();
    window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
    int statusBarHeight = rectgle.top;

    ViewGroup v1 = (ViewGroup) activity.findViewById(id).getRootView();
    v1.setDrawingCacheEnabled(true);
    Bitmap source = Bitmap.createBitmap(v1.getDrawingCache());
    v1.setDrawingCacheEnabled(false);
    if (statusBarHeight != 0) {
        sCoverBitmap = Bitmap.createBitmap(source, 0, statusBarHeight, source.getWidth(),
                source.getHeight() - statusBarHeight);
        source.recycle();
    } else {
        sCoverBitmap = source;
    }
    sWidth = width;
}