package com.yyrh.utils;


import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.provider.MediaStore;
import android.view.View;





/**
 * Created by admin on 2017/8/1.
 */

public class ScreenShotUtil {
    public static boolean shotByDialog(Context context, Dialog dialog) {
        boolean isShot;
        View view = dialog.getWindow().getDecorView();

        view.buildDrawingCache();
        view.setDrawingCacheEnabled(false);
        Bitmap bmp = view.getDrawingCache();

        String title = "GameScreen" + System.currentTimeMillis();

        try {
            MediaStore.Images.Media.insertImage(context.getContentResolver(),
                    bmp, title, "Register Account and password");
            isShot = true;
        } catch (Exception e) {
            isShot = false;
        }
        view.destroyDrawingCache();
        return isShot;

    }
    public static boolean shotByView(Context context, View view) {
        boolean isShot;


        view.buildDrawingCache();
        view.setDrawingCacheEnabled(false);
        Bitmap bmp = view.getDrawingCache();

        String title = "GameScreen" + System.currentTimeMillis();
        try {
            MediaStore.Images.Media.insertImage(context.getContentResolver(),
                    bmp, title, "Register Account and password");
            isShot = true;
        } catch (Exception e) {
            isShot = false;
        }
        view.destroyDrawingCache();
        return isShot;

    }


}
