Example usage for android.view ViewGroup setDrawingCacheEnabled

List of usage examples for android.view ViewGroup setDrawingCacheEnabled

Introduction

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

Prototype

@Deprecated
public void setDrawingCacheEnabled(boolean enabled) 

Source Link

Document

Enables or disables the drawing cache.

Usage

From source file:Main.java

/**
 * Take screenshot of the activity including the action bar
 * //from ww w . j a v a  2s.c om
 * @param activity
 * @return The screenshot of the activity including the action bar
 */
public static Bitmap takeScreenshot(Activity activity) {
    ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
    ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
    decorChild.setDrawingCacheEnabled(true);
    decorChild.buildDrawingCache();
    Bitmap drawingCache = decorChild.getDrawingCache(true);
    Bitmap bitmap = Bitmap.createBitmap(drawingCache);
    decorChild.setDrawingCacheEnabled(false);
    return bitmap;
}

From source file:Main.java

public static void prepare(Activity activity, int id, int width) {
    if (sCoverBitmap != null) {
        sCoverBitmap.recycle();// ww  w .  j av 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;
}

From source file:com.vuze.android.remote.activity.LoginActivity.java

@SuppressWarnings("deprecation")
private void setBackgroundGradient() {

    ViewGroup mainLayout = (ViewGroup) findViewById(R.id.main_loginlayout);
    assert mainLayout != null;
    int h = mainLayout.getHeight();
    int w = mainLayout.getWidth();
    View viewCenterOn = findViewById(R.id.login_frog_logo);
    assert viewCenterOn != null;

    RectShape shape = new RectShape();
    ShapeDrawable mDrawable = new ShapeDrawable(shape);
    int color1 = AndroidUtilsUI.getStyleColor(this, R.attr.login_grad_color_1);
    int color2 = AndroidUtilsUI.getStyleColor(this, R.attr.login_grad_color_2);

    RadialGradient shader;// www  .  ja va 2  s .c  om
    if (w > h) {
        int left = viewCenterOn.getLeft() + (viewCenterOn.getWidth() / 2);
        int top = viewCenterOn.getTop() + (viewCenterOn.getHeight() / 2);
        int remaining = w - left;
        shader = new RadialGradient(left, top, remaining, new int[] { color1, color2 }, new float[] { 0, 1.0f },
                Shader.TileMode.CLAMP);
    } else {
        int top = viewCenterOn.getTop() + (viewCenterOn.getHeight() / 2);
        shader = new RadialGradient(w / 2, top, w * 2 / 3, color1, color2, Shader.TileMode.CLAMP);
    }
    mDrawable.setBounds(0, 0, w, h);
    mDrawable.getPaint().setShader(shader);
    mDrawable.getPaint().setDither(true);
    mDrawable.getPaint().setAntiAlias(true);
    mDrawable.setDither(true);

    mainLayout.setDrawingCacheEnabled(true);
    mainLayout.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
    mainLayout.setAnimationCacheEnabled(false);

    mainLayout.setBackgroundDrawable(mDrawable);
}