<commit_before>/* 
 * Copyright 2014 OpenMarket Ltd
 * 
 * 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 org.matrix.androidsdk.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

import org.matrix.androidsdk.R;

/**
 * View that displays a disc representing a percentage.
 */
public class PieFractionView extends View {

    private static final int START_ANGLE = -90;

    // The fraction between 0 and 100
    private int fraction = 0;

    private RectF rectF;
    private Paint paint;

    private int powerColor;
    private int restColor;

    public int fillColor() {
        return getResources().getColor(R.color.pie_fraction_fill);
    }

    public int getRestColor() {
        return getResources().getColor(R.color.pie_fraction_rest);
    }

    public PieFractionView(Context context, AttributeSet attrs) {
        super(context, attrs);

        int[] attrArray = new int[] {android.R.attr.layout_width, android.R.attr.layout_height};
        TypedArray typedArray = context.obtainStyledAttributes(attrs, attrArray);
        int width = typedArray.getDimensionPixelSize(0, 0);
        int height = typedArray.getDimensionPixelSize(1, 0);
        rectF = new RectF(0, 0, width, height);
        paint = new Paint();

        powerColor = fillColor();
        restColor = getRestColor();
    }

    public void setFraction(int fraction) {
        // bounds check + avoid useless refresh
        if ((fraction >= 0) && (fraction <= 100) && (this.fraction != fraction)) {
            this.fraction = fraction;
            this.invalidate();
        }
    }

    @Override
    protected void onDraw(Canvas canvas) {
        int angle = fraction * 360 / 100;

        // Draw the power part
        paint.setColor(powerColor);
        canvas.drawArc(rectF, START_ANGLE, angle, true, paint);

        // Draw the rest
        paint.setColor(restColor);
        canvas.drawArc(rectF, START_ANGLE + angle, 360 - angle, true, paint);
    }
}
<commit_msg>Fix a lint error<commit_after>/* 
 * Copyright 2014 OpenMarket Ltd
 * 
 * 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 org.matrix.androidsdk.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

import org.matrix.androidsdk.R;

/**
 * View that displays a disc representing a percentage.
 */
public class PieFractionView extends View {

    private static final int START_ANGLE = -90;

    // The fraction between 0 and 100
    private int fraction = 0;

    private RectF rectF;
    private Paint paint;

    private int powerColor;
    private int restColor;

    public int fillColor() {
        return getResources().getColor(R.color.pie_fraction_fill);
    }

    public int getRestColor() {
        return getResources().getColor(R.color.pie_fraction_rest);
    }

    @SuppressWarnings("ResourceType")
    public PieFractionView(Context context, AttributeSet attrs) {
        super(context, attrs);

        int[] attrArray = new int[] {android.R.attr.layout_width, android.R.attr.layout_height};
        TypedArray typedArray = context.obtainStyledAttributes(attrs, attrArray);
        int width = typedArray.getDimensionPixelSize(0, 0);
        int height = typedArray.getDimensionPixelSize(1, 0);
        rectF = new RectF(0, 0, width, height);
        paint = new Paint();

        powerColor = fillColor();
        restColor = getRestColor();
    }

    public void setFraction(int fraction) {
        // bounds check + avoid useless refresh
        if ((fraction >= 0) && (fraction <= 100) && (this.fraction != fraction)) {
            this.fraction = fraction;
            this.invalidate();
        }
    }

    @Override
    protected void onDraw(Canvas canvas) {
        int angle = fraction * 360 / 100;

        // Draw the power part
        paint.setColor(powerColor);
        canvas.drawArc(rectF, START_ANGLE, angle, true, paint);

        // Draw the rest
        paint.setColor(restColor);
        canvas.drawArc(rectF, START_ANGLE + angle, 360 - angle, true, paint);
    }
}

{'fraction_non_alphanumeric': 0.09531803767953739, 'fraction_numerical': 0.01268420070882298, 'mean_word_length': 2.9630450849963044, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4825502', 'n_tokens_mistral': 1556, 'n_tokens_neox': 1455, 'n_words': 484}