Quantcast
Channel: PipisCrew Official Homepage
Viewing all articles
Browse latest Browse all 11347

[android] DoughnutChartView

$
0
0

Snap56

//MainActivity.java
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.widget.TextView;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.maind);

		DoughnutChartView x = (DoughnutChartView) findViewById(R.id.doughnut_chart);
		x.setTotalAmount(60);

		int[] arrayOfInt2 = new int[4];
		arrayOfInt2[0] = MainActivity.this.getResources().getColor(R.color.pie_income_1);
		arrayOfInt2[1] = MainActivity.this.getResources().getColor(R.color.pie_income_2);
		arrayOfInt2[2] = MainActivity.this.getResources().getColor(R.color.pie_income_3);
		arrayOfInt2[3] = MainActivity.this.getResources().getColor(R.color.pie_income_4);

		x.setProgressColorList(arrayOfInt2);

		double[] arrayOfDouble = new double[4];
		arrayOfDouble[0] = 30;
		arrayOfDouble[1] = 10;
		arrayOfDouble[2] = 10;
		arrayOfDouble[3] = 10;

		x.setCirclePieAmountList(arrayOfDouble);

		TextView c1 = (TextView) findViewById(R.id.doughtnut_chart_color1);
		c1.setBackgroundResource(R.color.pie_income_1);

		c1 = (TextView) findViewById(R.id.doughtnut_chart_text1);
		c1.setText("asdf1");

		TextView c2 = (TextView) findViewById(R.id.doughtnut_chart_color2);
		c2.setBackgroundResource(R.color.pie_income_2);

		c2 = (TextView) findViewById(R.id.doughtnut_chart_text2);
		c2.setText("asdf2");

		TextView c3 = (TextView) findViewById(R.id.doughtnut_chart_color3);
		c3.setBackgroundResource(R.color.pie_income_3);

		c3 = (TextView) findViewById(R.id.doughtnut_chart_text3);
		c3.setText("asdf3");

		TextView c4 = (TextView) findViewById(R.id.doughtnut_chart_color4);
		c4.setBackgroundResource(R.color.pie_income_4);

		c4 = (TextView) findViewById(R.id.doughtnut_chart_text4);
		c4.setText("asdf4");
	}
}

 
 

//DoughnutChartView.java
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.view.View;

public class DoughnutChartView extends View {
    private boolean fpa;
    private int fpb;
    private final RectF fpc;
    private float fpd;
    private int[] fpe;
    private double fpf;
    private double[] fpg;
    private final Paint fph;
    private final int fpi;
    private int fpj;
    private int fpk;
    private float fpl;
    private float fpm;

    public DoughnutChartView(Context arg2) {
        this(arg2, null);
    }

    public DoughnutChartView(Context arg4, AttributeSet arg5) {
        super(arg4, arg5);
        this.fpa = true;
        this.fpb = 10;
        this.fpc = new RectF();
        this.fpj = 0;
        this.fpk = 0;
        this.setWheelSize(20);
        this.fpi = 1;
        this.fph = new Paint(1);
        this.fph.setStyle(Paint.Style.STROKE);
        this.fph.setStrokeWidth(((float)this.fpb));
        this.fpa = false;
    }

    public double[] getCirclePieAmountList() {
        return this.fpg;
    }

    public int[] getProgressColorList() {
        return this.fpe;
    }

    public double getTotalAmount() {
        return this.fpf;
    }

    private float mpa(double arg5) {
    	   if (this.fpf == 0.0D) {
    		      return 0.0F;
    		    }
    		    return (float)(360.0D * arg5 / this.fpf);
    }

    private void mpa(int arg4, int arg5) {
        int v0 = this.fpi;
        switch(v0 & 7) {
            case 3: {
                this.fpj = 0;
                break;
            }
            case 5: {
                this.fpj = arg4;
                break;
            }
            default: {
                this.fpj = arg4 / 2;
                break;
            }
        }

        switch(v0 & 112) {
            case 48: {
                this.fpk = 0;
                break;
            }
            case 80: {
                this.fpk = arg5;
                break;
            }
            default: {
                this.fpk = arg5 / 2;
                break;
            }
        }
    }

    protected void onDraw(Canvas arg13) {
        float v11 = 1f;
        double v0 = 0;
        if(this.fpf != v0 && this.fpg.length != 0) {
            arg13.translate(this.fpl, this.fpm);
            int v9 = this.fpg.length;
            float v2 = 270f;
            int v6 = 0;
            double v7 = v0;
            while(v6 < v9) {
                this.fph.setColor(this.fpe[v6]);
                float v10 = this.mpa(this.fpg[v6]);
                arg13.drawArc(this.fpc, v2, v10 - v11, false, this.fph);
                float v3 = v2 + v10;
                double v1 = v7 + this.fpg[v6];
                ++v6;
                v7 = v1;
                v2 = v3;
            }

            if(this.fpf > v7) {
                float v0_1 = this.mpa(this.fpf - v7);
                this.fph.setColor(this.fpe[3]);
                arg13.drawArc(this.fpc, v2, v0_1 - v11, false, this.fph);
            }
        }
    }

    protected void onMeasure(int arg10, int arg11) {
        int v0 = DoughnutChartView.getDefaultSize(this.getSuggestedMinimumHeight(), arg11);
        int v1 = DoughnutChartView.getDefaultSize(this.getSuggestedMinimumWidth(), arg10);
        int v2 = Math.min(v1, v0);
        this.setMeasuredDimension(v2, v0);
        float v3 = 0.5f * (((float)v2));
        this.fpd = v3 - (((float)this.fpb));
        this.fpc.set(-this.fpd, -this.fpd, this.fpd, this.fpd);
        this.mpa(v1 - v2, v0 - v2);
        this.fpl = (((float)this.fpj)) + v3;
        this.fpm = (((float)this.fpk)) + v3;
    }

    protected void onRestoreInstanceState(Parcelable paramParcelable)
    {
      if ((paramParcelable instanceof Bundle))
      {
        super.onRestoreInstanceState(((Bundle)paramParcelable).getParcelable("saved_state"));
        return;
      }
      super.onRestoreInstanceState(paramParcelable);
    }

    protected Parcelable onSaveInstanceState() {
        Bundle v0 = new Bundle();
        v0.putParcelable("saved_state", super.onSaveInstanceState());
        v0.putFloat("progress", 180f);
        return ((Parcelable)v0);
    }

    public void setCirclePieAmountList(double[] arg1) {
        this.fpg = arg1;
    }

    public void setProgressColorList(int[] arg1) {
        this.fpe = arg1;
    }

    public void setTotalAmount(double arg1) {
        this.fpf = arg1;
    }

    private void setWheelSize(int arg1) {
        this.fpb = arg1;
    }
}

Viewing all articles
Browse latest Browse all 11347

Trending Articles