@@ -0,0 +1,2882 @@
+package com.basgeekball.screenshotsnanny.core;%0A%0Aimport android.app.Activity;%0Aimport android.graphics.Bitmap;%0Aimport android.os.Build;%0Aimport android.os.Environment;%0Aimport android.os.Handler;%0Aimport android.view.View;%0Aimport android.view.ViewTreeObserver;%0A%0Aimport java.io.File;%0Aimport java.io.FileOutputStream;%0Aimport java.io.IOException;%0A%0Apublic class ScreenshotsCapturer %7B%0A%0A    private Bitmap captureScreenshot(Activity activity) %7B%0A        View rootView = activity.findViewById(android.R.id.content).getRootView();%0A        rootView.setDrawingCacheEnabled(true);%0A        rootView.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);%0A        return rootView.getDrawingCache();%0A    %7D%0A%0A    private boolean isExternalStorageWritable() %7B%0A        String state = Environment.getExternalStorageState();%0A        return Environment.MEDIA_MOUNTED.equals(state);%0A    %7D%0A%0A    private void createDirIfNotExist(File dir) %7B%0A        if (!dir.exists()) %7B%0A            dir.mkdirs();%0A        %7D%0A    %7D%0A%0A    private void saveToFile(Bitmap bitmap, String filename, Activity activity) %7B%0A        String appName = activity.getString(activity.getApplicationInfo().labelRes);%0A        File screenshotDir = new File(Environment.getExternalStorageDirectory() + %22/Screenshots/%22 + appName);%0A        createDirIfNotExist(screenshotDir);%0A        File screenshot = new File(screenshotDir.getPath() + File.separator + filename + %22.png%22);%0A        try %7B%0A            screenshot.createNewFile();%0A            FileOutputStream outputStream = new FileOutputStream(screenshot);%0A            bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream);%0A            outputStream.flush();%0A            outputStream.close();%0A        %7D catch (IOException e) %7B%0A            e.printStackTrace();%0A        %7D%0A    %7D%0A%0A    public void execute(final Activity activity, final int delay) %7B%0A        final View contentView = activity.findViewById(android.R.id.content);%0A        final ViewTreeObserver viewTreeObserver = contentView.getViewTreeObserver();%0A        viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() %7B%0A            @Override%0A            public void onGlobalLayout() %7B%0A                // call getViewTreeObserver() again, because previous ViewTreeObserver is not alive%0A                if (Build.VERSION.SDK_INT %3E= Build.VERSION_CODES.JELLY_BEAN) %7B%0A                    contentView.getViewTreeObserver().removeOnGlobalLayoutListener(this);%0A                %7D else %7B%0A                    contentView.getViewTreeObserver().removeGlobalOnLayoutListener(this);%0A                %7D%0A                new Handler().postDelayed(new Runnable() %7B%0A                    @Override%0A                    public void run() %7B%0A                        saveToFile(captureScreenshot(activity), activity.getClass().getSimpleName(), activity);%0A                    %7D%0A                %7D, delay);%0A            %7D%0A        %7D);%0A    %7D%0A%7D%0A

Add ScreenshotsCapturer class