<commit_before>package de.danoeh.antennapod.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.Nullable;

public class PlaybackSpeedIndicatorView extends View {
    private final Paint arcPaint = new Paint();
    private final Paint indicatorPaint = new Paint();
    private final Path trianglePath = new Path();
    float angle = 0;
    float targetAngle = 0.5f;
    float degreePerFrame = 2;
    float paddingArc = 20;
    float paddingIndicator = 10;
    double deg2rad = Math.PI / 180;
    float paddingAngle = 30;

    public PlaybackSpeedIndicatorView(Context context) {
        super(context);
        setup();
    }

    public PlaybackSpeedIndicatorView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        setup();
    }

    public PlaybackSpeedIndicatorView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        setup();
    }

    private void setup() {
        arcPaint.setAntiAlias(true);
        arcPaint.setColor(Color.GRAY);
        arcPaint.setStyle(Paint.Style.STROKE);
        arcPaint.setStrokeCap(Paint.Cap.ROUND);
        arcPaint.setStrokeWidth(10);

        indicatorPaint.setAntiAlias(true);
        indicatorPaint.setColor(Color.GRAY);
        indicatorPaint.setStyle(Paint.Style.FILL);

        trianglePath.setFillType(Path.FillType.EVEN_ODD);
    }

    public void setSpeed(float value) {
        float MAX_ANGLE_PER_DIRECTION = 90+45- 2*paddingArc;
        if (value >= 1) {
            targetAngle = MAX_ANGLE_PER_DIRECTION * ((value-1)/3);
        } else {
            targetAngle = -MAX_ANGLE_PER_DIRECTION * (1-((value - 0.5f)*2));
        }
        degreePerFrame = Math.abs(targetAngle - angle) / 20;
        invalidate();
    }

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

        paddingArc = getMeasuredHeight()/5;
        paddingIndicator = getMeasuredHeight()/10;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        float radiusInnerCircle = getWidth()/8;
        canvas.drawCircle(getWidth() / 2, getHeight() / 2, radiusInnerCircle, indicatorPaint);

        trianglePath.rewind();
        float bigRadius = getHeight() / 2 - paddingIndicator;
        trianglePath.moveTo(getWidth() / 2 + (float)(bigRadius * Math.sin((-angle + 180) * deg2rad)),
                getHeight() / 2 + (float)(bigRadius * Math.cos((-angle + 180) * deg2rad)));
        trianglePath.lineTo(getWidth() / 2 + (float)(radiusInnerCircle * Math.sin((-angle + 180 -90) * deg2rad)),
                getHeight() / 2 + (float)(radiusInnerCircle * Math.cos((-angle + 180-90) * deg2rad)));
        trianglePath.lineTo(getWidth() / 2 + (float)(radiusInnerCircle * Math.sin((-angle + 180+90) * deg2rad)),
                getHeight() / 2 + (float)(radiusInnerCircle * Math.cos((-angle + 180+90) * deg2rad)));
        trianglePath.close();
        canvas.drawPath(trianglePath, indicatorPaint);

        RectF arcBounds = new RectF(paddingArc, paddingArc, getWidth()-paddingArc, getHeight()-paddingArc);
        canvas.drawArc(arcBounds, -180-45, 90+45+angle-paddingAngle, false, arcPaint);
        canvas.drawArc(arcBounds, -90 + paddingAngle+angle, 90+45 - paddingAngle-angle, false, arcPaint);


        if (Math.abs(angle - targetAngle) > 0.5) {
            angle += Math.signum(targetAngle - angle) * Math.min(degreePerFrame, Math.abs(targetAngle - angle));
            invalidate();
        }
    }
}<commit_msg>Make indicator work on small screens<commit_after>package de.danoeh.antennapod.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.Nullable;

public class PlaybackSpeedIndicatorView extends View {
    private static final float DEG_2_RAD = (float) (Math.PI / 180);
    private static final float PADDING_ANGLE = 30;

    private final Paint arcPaint = new Paint();
    private final Paint indicatorPaint = new Paint();
    private final Path trianglePath = new Path();
    private float angle = 0;
    private float targetAngle = 0.5f;
    private float degreePerFrame = 2;
    private float paddingArc = 20;
    private float paddingIndicator = 10;

    public PlaybackSpeedIndicatorView(Context context) {
        super(context);
        setup();
    }

    public PlaybackSpeedIndicatorView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        setup();
    }

    public PlaybackSpeedIndicatorView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        setup();
    }

    private void setup() {
        arcPaint.setAntiAlias(true);
        arcPaint.setColor(Color.GRAY);
        arcPaint.setStyle(Paint.Style.STROKE);
        arcPaint.setStrokeCap(Paint.Cap.ROUND);

        indicatorPaint.setAntiAlias(true);
        indicatorPaint.setColor(Color.GRAY);
        indicatorPaint.setStyle(Paint.Style.FILL);

        trianglePath.setFillType(Path.FillType.EVEN_ODD);
    }

    public void setSpeed(float value) {
        float maxAnglePerDirection = 90 + 45 - 2 * paddingArc;
        if (value >= 1) {
            // Speed values above 3 are probably not too common. Cap at 3 for better differentiation
            targetAngle = maxAnglePerDirection * ((Math.min(3, value) - 1) / 2);
        } else {
            targetAngle = -maxAnglePerDirection * (1 - ((value - 0.5f) * 2));
        }
        degreePerFrame = Math.abs(targetAngle - angle) / 20;
        invalidate();
    }

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

        paddingArc = getMeasuredHeight() / 5f;
        paddingIndicator = getMeasuredHeight() / 10f;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        float radiusInnerCircle = getWidth() / 8f;
        canvas.drawCircle(getWidth() / 2f, getHeight() / 2f, radiusInnerCircle, indicatorPaint);

        trianglePath.rewind();
        float bigRadius = getHeight() / 2f - paddingIndicator;
        trianglePath.moveTo(getWidth() / 2f + (float) (bigRadius * Math.sin((-angle + 180) * DEG_2_RAD)),
                getHeight() / 2f + (float) (bigRadius * Math.cos((-angle + 180) * DEG_2_RAD)));
        trianglePath.lineTo(getWidth() / 2f + (float) (radiusInnerCircle * Math.sin((-angle + 180 - 90) * DEG_2_RAD)),
                getHeight() / 2f + (float) (radiusInnerCircle * Math.cos((-angle + 180 - 90) * DEG_2_RAD)));
        trianglePath.lineTo(getWidth() / 2f + (float) (radiusInnerCircle * Math.sin((-angle + 180 + 90) * DEG_2_RAD)),
                getHeight() / 2f + (float) (radiusInnerCircle * Math.cos((-angle + 180 + 90) * DEG_2_RAD)));
        trianglePath.close();
        canvas.drawPath(trianglePath, indicatorPaint);

        arcPaint.setStrokeWidth(getHeight() / 15f);
        RectF arcBounds = new RectF(paddingArc, paddingArc, getWidth() - paddingArc, getHeight() - paddingArc);
        canvas.drawArc(arcBounds, -180 - 45, 90 + 45 + angle - PADDING_ANGLE, false, arcPaint);
        canvas.drawArc(arcBounds, -90 + PADDING_ANGLE + angle, 90 + 45 - PADDING_ANGLE - angle, false, arcPaint);

        if (Math.abs(angle - targetAngle) > 0.5) {
            angle += Math.signum(targetAngle - angle) * Math.min(degreePerFrame, Math.abs(targetAngle - angle));
            invalidate();
        }
    }
}
{'fraction_non_alphanumeric': 0.1175730110775428, 'fraction_numerical': 0.023539778449144007, 'mean_word_length': 2.9409722222222223, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2406987', 'n_tokens_mistral': 2520, 'n_tokens_neox': 2339, 'n_words': 523}