<commit_before>/*
 * Copyright 2014 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.flaviofaria.kenburnsview;

import android.graphics.RectF;
import android.view.animation.Interpolator;
import android.view.animation.AccelerateDecelerateInterpolator;

import java.util.Random;

public class RandomTransitionGenerator implements TransitionGenerator {

    /** Default value for the transition duration in milliseconds. */
    public static final int DEFAULT_TRANSITION_DURATION = 10000;

    /** Minimum rect dimension factor, according to the maximum one. */
    private static final float MIN_RECT_FACTOR = 0.5f;

    /** Random object used to generate arbitrary rects. */
    private final Random mRandom = new Random(System.currentTimeMillis());

    /** The duration, in milliseconds, of each transition. */
    private long mTransitionDuration;

    /** The last generated transition. */
    private Transition mLastGenTrans;


    public RandomTransitionGenerator() {
        this(DEFAULT_TRANSITION_DURATION);
    }


    public RandomTransitionGenerator(long transitionDuration) {
        setTransitionDuration(transitionDuration);
    }


    @Override
    public Transition generateNextTransition(RectF viewport, RectF drawableBounds) {
        RectF srcRect;
        if (mLastGenTrans == null) {
            srcRect = generateRandomRect(viewport, drawableBounds);
        } else {
            srcRect = mLastGenTrans.getDestinyRect();
        }
        RectF dstRect = generateRandomRect(viewport, drawableBounds);
        Interpolator interpolator = new AccelerateDecelerateInterpolator();
        mLastGenTrans = new Transition(srcRect, dstRect, mTransitionDuration, interpolator);
        return mLastGenTrans;
    }


    /**
     * Generates a random rect in as scale that varies between
     * {@link #MIN_RECT_FACTOR} and 1. This scale is relative to {@code viewPortRect} and
     * will be 1 when {@code viewPortRect} and the generated rect are exactly the same dimensions.
     * @return an arbitrary generated rect smaller or equals than {@link #mViewPortRect}.
     */
    private RectF generateRandomRect(RectF viewPortRect, RectF drawableBounds) {
        float factor = MIN_RECT_FACTOR + (mRandom.nextFloat() / 2);
        float width = factor * viewPortRect.width();
        float height = factor * viewPortRect.height();
        int widthDiff = (int) (viewPortRect.width() - width);
        int heightDiff = (int) (viewPortRect.height() - height);
        int left = widthDiff > 0 ? mRandom.nextInt(widthDiff) : 0;
        int top = heightDiff > 0 ? mRandom.nextInt(heightDiff) : 0;
        return new RectF(left, top, left + width, top + height);
    }


    /**
     * Sets the duration, in milliseconds, for each transition generated.
     * @param transitionDuration the transition duration.
     */
    public void setTransitionDuration(long transitionDuration) {
        mTransitionDuration = transitionDuration;
    }
}
<commit_msg>Fixed javadoc and parameter typo.<commit_after>/*
 * Copyright 2014 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.flaviofaria.kenburnsview;

import android.graphics.RectF;
import android.view.animation.Interpolator;
import android.view.animation.AccelerateDecelerateInterpolator;

import java.util.Random;

public class RandomTransitionGenerator implements TransitionGenerator {

    /** Default value for the transition duration in milliseconds. */
    public static final int DEFAULT_TRANSITION_DURATION = 10000;

    /** Minimum rect dimension factor, according to the maximum one. */
    private static final float MIN_RECT_FACTOR = 0.5f;

    /** Random object used to generate arbitrary rects. */
    private final Random mRandom = new Random(System.currentTimeMillis());

    /** The duration, in milliseconds, of each transition. */
    private long mTransitionDuration;

    /** The last generated transition. */
    private Transition mLastGenTrans;


    public RandomTransitionGenerator() {
        this(DEFAULT_TRANSITION_DURATION);
    }


    public RandomTransitionGenerator(long transitionDuration) {
        setTransitionDuration(transitionDuration);
    }


    @Override
    public Transition generateNextTransition(RectF viewport, RectF drawableBounds) {
        RectF srcRect;
        if (mLastGenTrans == null) {
            srcRect = generateRandomRect(viewport, drawableBounds);
        } else {
            srcRect = mLastGenTrans.getDestinyRect();
        }
        RectF dstRect = generateRandomRect(viewport, drawableBounds);
        Interpolator interpolator = new AccelerateDecelerateInterpolator();
        mLastGenTrans = new Transition(srcRect, dstRect, mTransitionDuration, interpolator);
        return mLastGenTrans;
    }


    /**
     * Generates a random rect in as scale that varies between
     * {@link #MIN_RECT_FACTOR} and 1. This scale is relative to {@code viewPortRect} and
     * will be 1 when {@code viewPortRect} and the generated rect are exactly the same dimensions.
     * @return an arbitrary generated rect smaller or equals than {@code viewportRect}.
     */
    private RectF generateRandomRect(RectF viewportRect, RectF drawableBounds) {
        float factor = MIN_RECT_FACTOR + (mRandom.nextFloat() / 2);
        float width = factor * viewportRect.width();
        float height = factor * viewportRect.height();
        int widthDiff = (int) (viewportRect.width() - width);
        int heightDiff = (int) (viewportRect.height() - height);
        int left = widthDiff > 0 ? mRandom.nextInt(widthDiff) : 0;
        int top = heightDiff > 0 ? mRandom.nextInt(heightDiff) : 0;
        return new RectF(left, top, left + width, top + height);
    }


    /**
     * Sets the duration, in milliseconds, for each transition generated.
     * @param transitionDuration the transition duration.
     */
    public void setTransitionDuration(long transitionDuration) {
        mTransitionDuration = transitionDuration;
    }
}

{'fraction_non_alphanumeric': 0.08069575135443399, 'fraction_numerical': 0.006273167949814656, 'mean_word_length': 3.357142857142857, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2019104', 'n_tokens_mistral': 1861, 'n_tokens_neox': 1778, 'n_words': 632}