<commit_before>package com.silvestr.dotprogressbar;

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Build;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.Transformation;

/**
 * @author <NAME>.
 */
public class DotProgressBar extends View {

  /**
   * Dots amount
   */
  private static final int DOT_AMOUNT = 5;

  /**
   * Drawing tools
   */
  private Paint paint;

  /**
   * Animation tools
   */
  private static final int ANIMATION_TIME = 300;
  private BounceAnimation bounceAnimation;
  private float animatedRadius;
  private boolean isFirstLaunch = true;
  private float mInterpolatedTime;

  /**
   * Circle size
   */
  private float dotRadius;
  private float bounceDotRadius;

  /**
   * Circle coordinates
   */
  private float xCoordinate;
  private int dotPosition;

  @TargetApi(Build.VERSION_CODES.LOLLIPOP)
  public DotProgressBar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);
    init();
  }

  public DotProgressBar(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    init();
  }

  public DotProgressBar(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
  }

  public DotProgressBar(Context context) {
    super(context);
    init();
  }

  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    setMeasuredDimension(getMeasuredWidth(), getMeasuredHeight());

    if (getMeasuredHeight() > getMeasuredWidth()) {
      dotRadius = getMeasuredWidth() / DOT_AMOUNT / 4;
    } else {
      dotRadius = getMeasuredHeight() / 4;
    }

    bounceDotRadius = dotRadius + (dotRadius / 3);
    float circlesWidth = (DOT_AMOUNT * (dotRadius * 2)) + dotRadius * (DOT_AMOUNT - 1);
    xCoordinate = (getMeasuredWidth() - circlesWidth) / 2 + dotRadius;
  }

  private void init() {
    paint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    paint.setColor(Color.BLACK);
    paint.setStrokeJoin(Paint.Join.ROUND);
    paint.setStrokeCap(Paint.Cap.ROUND);
    paint.setStrokeWidth(20);
  }

  private void drawCircles(Canvas canvas, float radius) {
    float step = 0;
    for (int i = 0; i < DOT_AMOUNT; i++) {
      if (dotPosition == i) {
        canvas.drawCircle(xCoordinate + step, getMeasuredHeight() / 2, dotRadius + radius, paint);
      } else {
        if ((i == (DOT_AMOUNT - 1) && dotPosition == 0 && !isFirstLaunch) || ((dotPosition - 1) == i)) {
          canvas.drawCircle(xCoordinate + step, getMeasuredHeight() / 2, bounceDotRadius - radius, paint);
        } else {
          canvas.drawCircle(xCoordinate + step, getMeasuredHeight() / 2, dotRadius, paint);
        }
      }

      step += dotRadius * 3;
    }
  }

  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    drawCircles(canvas, animatedRadius);
  }

  private void stopAnimation() {
    this.clearAnimation();
    postInvalidate();
  }

  private void startAnimation() {
    bounceAnimation = new BounceAnimation();
    bounceAnimation.setDuration(ANIMATION_TIME);
    bounceAnimation.setRepeatCount(Animation.INFINITE);
    bounceAnimation.setInterpolator(new LinearInterpolator());
    bounceAnimation.setAnimationListener(new Animation.AnimationListener() {
      @Override
      public void onAnimationStart(Animation animation) {

      }

      @Override
      public void onAnimationEnd(Animation animation) {

      }

      @Override
      public void onAnimationRepeat(Animation animation) {
        dotPosition++;
        if (dotPosition == DOT_AMOUNT) {
          dotPosition = 0;
        }
        isFirstLaunch = false;
      }
    });
    startAnimation(bounceAnimation);
  }

  public static int darker (int color, float factor) {<commit_msg>need refactoring<commit_after>package com.silvestr.dotprogressbar;

import android.animation.ArgbEvaluator;
import android.animation.ValueAnimator;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Build;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.Transformation;

/**
 * @author <NAME>.
 */
public class DotProgressBar extends View {

  /**
   * Dots amount
   */
  private static final int DOT_AMOUNT = 5;

  /**
   * Drawing tools
   */
  private Paint paint;
  private Paint secondColorPaint;
  private Paint thirdColorPaint;

  /**
   * Animation tools
   */
  private static final int ANIMATION_TIME = 300;
  private BounceAnimation bounceAnimation;
  private float animatedRadius;
  private boolean isFirstLaunch = true;
  private float mInterpolatedTime;

  /**
   * Circle size
   */
  private float dotRadius;
  private float bounceDotRadius;

  /**
   * Circle coordinates
   */
  private float xCoordinate;
  private int dotPosition;

  @TargetApi(Build.VERSION_CODES.LOLLIPOP)
  public DotProgressBar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);
    init();
  }

  public DotProgressBar(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    init();
  }

  public DotProgressBar(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
  }

  public DotProgressBar(Context context) {
    super(context);
    init();
  }

  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    setMeasuredDimension(getMeasuredWidth(), getMeasuredHeight());

    if (getMeasuredHeight() > getMeasuredWidth()) {
      dotRadius = getMeasuredWidth() / DOT_AMOUNT / 4;
    } else {
      dotRadius = getMeasuredHeight() / 4;
    }

    bounceDotRadius = dotRadius + (dotRadius / 3);
    float circlesWidth = (DOT_AMOUNT * (dotRadius * 2)) + dotRadius * (DOT_AMOUNT - 1);
    xCoordinate = (getMeasuredWidth() - circlesWidth) / 2 + dotRadius;
  }

  private void init() {
    paint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    paint.setColor(Color.parseColor("#0D47A1"));
    paint.setStrokeJoin(Paint.Join.ROUND);
    paint.setStrokeCap(Paint.Cap.ROUND);
    paint.setStrokeWidth(20);

    secondColorPaint = new Paint(paint);
    thirdColorPaint = new Paint(paint);
  }

  private void drawCircles(Canvas canvas, float radius) {
    float step = 0;
    for (int i = 0; i < DOT_AMOUNT; i++) {
      if (dotPosition == i) {
        canvas.drawCircle(xCoordinate + step, getMeasuredHeight() / 2, dotRadius + radius, secondColorPaint);
      } else {
        if ((i == (DOT_AMOUNT - 1) && dotPosition == 0 && !isFirstLaunch) || ((dotPosition - 1) == i)) {
          canvas.drawCircle(xCoordinate + step, getMeasuredHeight() / 2, bounceDotRadius - radius, thirdColorPaint);
        } else {
          canvas.drawCircle(xCoordinate + step, getMeasuredHeight() / 2, dotRadius, paint);
        }
      }

      step += dotRadius * 3;
    }
  }

  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    drawCircles(canvas, animatedRadius);
  }

  private void stopAnimation() {
    this.clearAnimation();
    postInvalidate();
  }

  private void startAnimation() {
    bounceAnimation = new BounceAnimation();
    bounceAnimation.setDuration(ANIMATION_TIME);
    bounceAnimation.setRepeatCount(Animation.INFINITE);
    bounceAnimation.setInterpolator(new LinearInterpolator());
    bounceAnimation.setAnimationListener(new Animation.AnimationListener() {
      @Override
      public void onAnimationStart(Animation animation) {

      }

      @Override
      public void onAnimationEnd(Animation animation) {

      }

      @Override
      public void onAnimationRepeat(Animation animation) {
        dotPosition++;
        if (dotPosition == DOT_AMOUNT) {
          dotPosition = 0;
        }

        ValueAnimator valueAnimator = ValueAnimator.ofInt(Color.parseColor("#0D47A1"), Color.parseColor("#1976D2"));
        valueAnimator.setDuration(ANIMATION_TIME);
        valueAnimator.setEvaluator(new ArgbEvaluator());
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            secondColorPaint.setColor(((Integer) animation.getAnimatedValue()));
          }
        });
        valueAnimator.start();

        ValueAnimator valueAnimator1 = ValueAnimator.ofInt(Color.parseColor("#1976D2"), Color.parseColor("#0D47A1"));
        valueAnimator1.setDuration(ANIMATION_TIME);
        valueAnimator1.setEvaluator(new ArgbEvaluator());
        valueAnimator1.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            thirdColorPaint.setColor(((Integer) animation.getAnimatedValue()));
          }
        });
        valueAnimator1.start();

        isFirstLaunch = false;
      }
    });
    startAnimation(bounceAnimation);
  }

  public static int darker (int color, float factor) {
{'fraction_non_alphanumeric': 0.10584698320547377, 'fraction_numerical': 0.00736056396433755, 'mean_word_length': 3.466203703703704, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3318637', 'n_tokens_mistral': 2962, 'n_tokens_neox': 2816, 'n_words': 617}