/**
* @Author: Mervyn
* @Date:   2016,May,12 22:58:28
* @Last modified by:   Mervyn
* @Last modified time: 2016,May,19 23:24:43
*/

package com.modules.screen;

import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ActivityEventListener;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.uimanager.IllegalViewOperationException;

// import java.util.HashMap;
// import java.util.Map;
import java.io.FileOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.UUID;

import android.app.Activity;
import android.graphics.Bitmap;
import android.view.WindowManager;
import android.view.View;
import android.view.Display;
import android.os.Environment;


public class ScreenModule extends ReactContextBaseJavaModule {
    public ScreenModule(ReactApplicationContext reactContext) {
        super(reactContext);
    }
    @Override
    public String getName() {
        return "Screen";
    }
    
    @ReactMethod
    public void screenShot() {
        // 获取当前的activity
        Activity currentActivity = getCurrentActivity();
        
        View view = currentActivity.getWindow().getDecorView();
        view.buildDrawingCache();
        view.setDrawingCacheEnabled(true);
        
        // 获取display
        Display display = currentActivity.getWindowManager().getDefaultDisplay();
        int widths = display.getWidth();
        int heights = display.getHeight();
        
        // 生成bitmap
        Bitmap Bmp = Bitmap.createBitmap(view.getDrawingCache(), 0, 0, widths, heights);
        // 文件名
        String filename = "ScreenShot-" + UUID.randomUUID().toString() + ".png";
        // 路径
        File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
        // 生成文件
        File file = new File(path, filename);
        
        try {
            // 输出文件
            FileOutputStream fos = new FileOutputStream(file);
            Bmp.compress(Bitmap.CompressFormat.PNG, 90, fos);  
            fos.flush();
            fos.close();
 
        } catch (IOException e) {  
            e.printStackTrace();  
        }  
    }
}
@@ -113,19 +113,19 @@
 May,
-19 23:24:43
+20 00:20:02
 %0A*/%0A
@@ -1179,16 +1179,58 @@
 tivity =
+ new Activity();%0A        currentActivity =
  getCurr
@@ -1708,16 +1708,81 @@
 ights);%0A
+        // %E5%8E%BB%E9%99%A4%E7%BC%93%E5%AD%98%EF%BC%8C%E4%B8%8D%E7%84%B6%E4%B9%8B%E5%90%8E%E7%9A%84%E6%AF%8F%E6%AC%A1%E6%88%AA%E5%9B%BE%E9%83%BD%E4%B8%80%E6%A0%B7%0A        view.destroyDrawingCache();%0A
         

solve bug of cache when scrennshot