Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.app.Activity;

import android.graphics.Bitmap;
import android.graphics.Rect;

import android.view.ViewGroup;
import android.view.Window;

public class Main {
    private static Bitmap sCoverBitmap = null;
    private static int sWidth = -1;

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