<commit_before>package com.chenjishi.slidedemo.base;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.view.View;

import java.lang.ref.SoftReference;
import java.util.*;

/**
 * Created by jishichen on 2017/6/16.
 */
public class Slide {

    private static final Slide INSTANCE = new Slide();

    private Stack<Bitmap> stack;

    private Set<SoftReference<Bitmap>> mReusableBitmaps;

    private Slide() {
        mReusableBitmaps = Collections.synchronizedSet(new HashSet<SoftReference<Bitmap>>());
        stack = new Stack<>();
    }

    public void clear() {
        stack.clear();
        Iterator<SoftReference<Bitmap>> iterator = mReusableBitmaps.iterator();
        while (iterator.hasNext()) {
            Bitmap bitmap = iterator.next().get();
            if (null != bitmap) {
                bitmap.recycle();
            }
            iterator.remove();
        }
    }

    public static Slide getInstance() {
        return INSTANCE;
    }

    public Bitmap peekBitmap() {
        if (stack.empty()) return null;
        return stack.peek();
    }

    public void popBitmap() {
        if (stack.empty()) return;

        Bitmap bitmap = stack.pop();
        mReusableBitmaps.add(new SoftReference<Bitmap>(bitmap));
    }

    public void startActivity(final Context context, Intent intent) {
        new Thread() {
            @Override
            public void run() {
                captureScreen(context);
            }
        }.start();
        context.startActivity(intent);
    }

    private void captureScreen(Context context) {
        View v = ((Activity) context).findViewById(android.R.id.content);
        Bitmap bmp = null;

        if (null != mReusableBitmaps && !mReusableBitmaps.isEmpty()) {
            synchronized (mReusableBitmaps) {
                final Iterator<SoftReference<Bitmap>> iterator = mReusableBitmaps.iterator();
                while (iterator.hasNext()) {
                    bmp = iterator.next().get();
                    if (null != bmp) {
                        iterator.remove();
                        break;
                    }
                }
            }
        } else {
            bmp = Bitmap.createBitmap(v.getWidth(), v.getHeight(),
                    Bitmap.Config.ARGB_8888);
        }

        if (null != bmp) {
            v.draw(new Canvas(bmp));<commit_msg>bug fixed<commit_after>package com.chenjishi.slidedemo.base;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.view.View;

import java.lang.ref.SoftReference;
import java.util.*;

/**
 * Created by jishichen on 2017/6/16.
 */
public class Slide {

    private static final Slide INSTANCE = new Slide();

    private Stack<Bitmap> stack;

    private Set<SoftReference<Bitmap>> mReusableBitmaps;

    private Slide() {
        mReusableBitmaps = Collections.synchronizedSet(new HashSet<SoftReference<Bitmap>>());
        stack = new Stack<>();
    }

    public void clear() {
        stack.clear();
        Iterator<SoftReference<Bitmap>> iterator = mReusableBitmaps.iterator();
        while (iterator.hasNext()) {
            Bitmap bitmap = iterator.next().get();
            if (null != bitmap) {
                bitmap.recycle();
            }
            iterator.remove();
        }
    }

    public static Slide getInstance() {
        return INSTANCE;
    }

    public Bitmap peekBitmap() {
        if (stack.empty()) return null;
        return stack.peek();
    }

    public void popBitmap() {
        if (stack.empty()) return;

        Bitmap bitmap = stack.pop();
        mReusableBitmaps.add(new SoftReference<Bitmap>(bitmap));
    }

    public void startActivity(final Context context, Intent intent) {
        captureScreen(context);
        context.startActivity(intent);
    }

    private void captureScreen(Context context) {
        View v = ((Activity) context).findViewById(android.R.id.content);
        Bitmap bmp = null;

        if (null != mReusableBitmaps && !mReusableBitmaps.isEmpty()) {
            synchronized (mReusableBitmaps) {
                final Iterator<SoftReference<Bitmap>> iterator = mReusableBitmaps.iterator();
                while (iterator.hasNext()) {
                    bmp = iterator.next().get();
                    if (null != bmp) {
                        iterator.remove();
                        break;
                    }
                }
            }
        } else {
            bmp = Bitmap.createBitmap(v.getWidth(), v.getHeight(),
                    Bitmap.Config.ARGB_8888);
        }

        if (null != bmp) {
            v.draw(new Canvas(bmp));
{'fraction_non_alphanumeric': 0.11546434494195688, 'fraction_numerical': 0.004560530679933665, 'mean_word_length': 1.9876160990712075, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '534514', 'n_tokens_mistral': 1359, 'n_tokens_neox': 1268, 'n_words': 285}