<commit_before>package eightbitlab.com.blurview;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.ViewTreeObserver;

/**
 * Blur Controller that handles all blur logic for attached View.
 * It honors View size changes, View animation and Visibility changes.
 *
 * The basic idea is to draw view hierarchy on internal bitmap, excluding the attached View.
 * After that, BlurController blurs this bitmap and draws it on system Canvas.
 * Default implementation uses {@link ViewTreeObserver.OnPreDrawListener} to detect when
 * blur should be redrawn.
 */
public class DefaultBlurController implements BlurController {
    private static final String TAG = DefaultBlurController.class.getSimpleName();

    public static final float DEFAULT_SCALE_FACTOR = 8f;
    public static final int DEFAULT_BLUR_RADIUS = 8;

    protected final float scaleFactor;
    protected int blurRadius = DEFAULT_BLUR_RADIUS;

    protected BlurAlgorithm blurAlgorithm;
    @Nullable
    protected Paint blurredBitmapPaint;

    protected Canvas internalCanvas;
    protected Canvas overlayCanvas;

    /**
     * View hierarchy is drawn here
     */
    protected Bitmap internalBitmap;
    /**
     * Blurred content is drawn here
     */
    protected Bitmap blurredOverlay;

    protected View blurView;
    protected View rootView;
    protected ViewTreeObserver.OnPreDrawListener drawListener;

    /**
     * Used to distinct parent draw() calls from Controller's draw() calls
     */
    protected boolean isMeDrawingNow;

    @NonNull
    protected Handler handler;

    //must be set from message queue
    @NonNull
    private final Runnable onDrawEndTask = new Runnable() {
        @Override
        public void run() {
            isMeDrawingNow = false;
        }
    };

    /**
     * By default, window's background is not drawn on canvas. We need to draw it manually
     */
    @Nullable
    private Drawable windowBackground;

    /**
     * @param blurView    View which will draw it's blurred underlying content
     * @param rootView    Root View where blurView's underlying content starts drawing.
     *                    Can be Activity's root content layout (android.R.id.content)
     *                    or some of your custom root layouts.
     * @param scaleFactor sets scale factor to downscale blurred bitmap for faster calculations
     *                    Default scale factor is {@link DefaultBlurController#DEFAULT_SCALE_FACTOR}
     */
    public DefaultBlurController(@NonNull View blurView, @NonNull View rootView, float scaleFactor) {
        blurredBitmapPaint = new Paint();
        blurredBitmapPaint.setFlags(Paint.FILTER_BITMAP_FLAG);

        handler = new Handler(Looper.getMainLooper());

        this.scaleFactor = scaleFactor;
        this.rootView = rootView;
        this.blurView = blurView;
        this.blurAlgorithm = new StackBlur(true);

        int measuredWidth = blurView.getMeasuredWidth();
        int measuredHeight = blurView.getMeasuredHeight();

        if (isZeroSized(measuredWidth, measuredHeight)) {
            deferBitmapsCreation();
            return;
        }

        init(measuredWidth, measuredHeight);
    }

    private int downScaleSize(float value) {<commit_msg>Throwing exception in case of invalid scale factor<commit_after>package eightbitlab.com.blurview;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.ViewTreeObserver;

/**
 * Blur Controller that handles all blur logic for attached View.
 * It honors View size changes, View animation and Visibility changes.
 *
 * The basic idea is to draw view hierarchy on internal bitmap, excluding the attached View.
 * After that, BlurController blurs this bitmap and draws it on system Canvas.
 * Default implementation uses {@link ViewTreeObserver.OnPreDrawListener} to detect when
 * blur should be redrawn.
 */
public class DefaultBlurController implements BlurController {
    private static final String TAG = DefaultBlurController.class.getSimpleName();

    public static final float DEFAULT_SCALE_FACTOR = 8f;
    public static final int DEFAULT_BLUR_RADIUS = 8;

    protected final float scaleFactor;
    protected int blurRadius = DEFAULT_BLUR_RADIUS;

    protected BlurAlgorithm blurAlgorithm;
    @Nullable
    protected Paint blurredBitmapPaint;

    protected Canvas internalCanvas;
    protected Canvas overlayCanvas;

    /**
     * View hierarchy is drawn here
     */
    protected Bitmap internalBitmap;
    /**
     * Blurred content is drawn here
     */
    protected Bitmap blurredOverlay;

    protected View blurView;
    protected View rootView;
    protected ViewTreeObserver.OnPreDrawListener drawListener;

    /**
     * Used to distinct parent draw() calls from Controller's draw() calls
     */
    protected boolean isMeDrawingNow;

    @NonNull
    protected Handler handler;

    //must be set from message queue
    @NonNull
    private final Runnable onDrawEndTask = new Runnable() {
        @Override
        public void run() {
            isMeDrawingNow = false;
        }
    };

    /**
     * By default, window's background is not drawn on canvas. We need to draw it manually
     */
    @Nullable
    private Drawable windowBackground;

    /**
     * @param blurView    View which will draw it's blurred underlying content
     * @param rootView    Root View where blurView's underlying content starts drawing.
     *                    Can be Activity's root content layout (android.R.id.content)
     *                    or some of your custom root layouts.
     * @param scaleFactor sets scale factor to downscale blurred bitmap for faster calculations
     *                    Default scale factor is {@link DefaultBlurController#DEFAULT_SCALE_FACTOR}
     */
    public DefaultBlurController(@NonNull View blurView, @NonNull View rootView, float scaleFactor) {
        throwIfInvalidScaleFactor(scaleFactor);

        blurredBitmapPaint = new Paint();
        blurredBitmapPaint.setFlags(Paint.FILTER_BITMAP_FLAG);

        handler = new Handler(Looper.getMainLooper());

        this.scaleFactor = scaleFactor;
        this.rootView = rootView;
        this.blurView = blurView;
        this.blurAlgorithm = new StackBlur(true);

        int measuredWidth = blurView.getMeasuredWidth();
        int measuredHeight = blurView.getMeasuredHeight();

        if (isZeroSized(measuredWidth, measuredHeight)) {
            deferBitmapsCreation();
            return;
        }

        init(measuredWidth, measuredHeight);
    }

    private void throwIfInvalidScaleFactor(float scaleFactor) {
        if (scaleFactor < 1) {
            throw new RuntimeException("scaleFactor can't be < 1");
        }
    }

    private int downScaleSize(float value) {
{'fraction_non_alphanumeric': 0.06762295081967214, 'fraction_numerical': 0.000819672131147541, 'mean_word_length': 3.0492256637168142, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '3635364', 'n_tokens_mistral': 1907, 'n_tokens_neox': 1801, 'n_words': 623}