1 /* 2 * Copyright 2012 AndroidPlot.com 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.androidplot.demos; 18 19 import android.app.Activity; 20 import android.graphics.*; 21 import android.os.Bundle; 22 import android.widget.SeekBar; 23 import android.widget.TextView; 24 import com.androidplot.pie.PieChart; 25 import com.androidplot.pie.PieRenderer; 26 import com.androidplot.pie.Segment; 27 import com.androidplot.pie.SegmentFormatter; 28 29 /** 30 * The simplest possible example of using AndroidPlot to plot some data. 31 */ 32 public class SimplePieChartActivity extends Activity 33 { 34 35 private TextView donutSizeTextView; 36 private SeekBar donutSizeSeekBar; 37 38 private PieChart pie; 39 40 private Segment s1; 41 private Segment s2; 42 private Segment s3; 43 private Segment s4; 44 45 @Override 46 public void onCreate(Bundle savedInstanceState) 47 { 48 49 super.onCreate(savedInstanceState); 50 setContentView(R.layout.pie_chart); 51 52 // initialize our XYPlot reference: 53 pie = (PieChart) findViewById(R.id.mySimplePieChart); 54 55 56 donutSizeSeekBar = (SeekBar) findViewById(R.id.donutSizeSeekBar); 57 58 donutSizeSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 59 @Override 60 public void onProgressChanged(SeekBar seekBar, int i, boolean b) {} 61 62 @Override 63 public void onStartTrackingTouch(SeekBar seekBar) {} 64 65 @Override 66 public void onStopTrackingTouch(SeekBar seekBar) { 67 pie.getRenderer(PieRenderer.class).setDonutSize(seekBar.getProgress()/100f, 68 PieRenderer.DonutMode.PERCENT); 69 pie.redraw(); 70 updateDonutText(); 71 } 72 }); 73 74 donutSizeTextView = (TextView) findViewById(R.id.donutSizeTextView); 75 updateDonutText(); 76 77 s1 = new Segment("s1", 10); 78 s2 = new Segment("s2", 1); 79 s3 = new Segment("s3", 10); 80 s4 = new Segment("s4", 10); 81 82 EmbossMaskFilter emf = new EmbossMaskFilter( 83 new float[]{1, 1, 1}, 0.4f, 10, 8.2f); 84 85 SegmentFormatter sf1 = new SegmentFormatter(); 86 sf1.configure(getApplicationContext(), R.xml.pie_segment_formatter1); 87 88 sf1.getFillPaint().setMaskFilter(emf); 89 90 SegmentFormatter sf2 = new SegmentFormatter(); 91 sf2.configure(getApplicationContext(), R.xml.pie_segment_formatter2); 92 93 sf2.getFillPaint().setMaskFilter(emf); 94 95 SegmentFormatter sf3 = new SegmentFormatter(); 96 sf3.configure(getApplicationContext(), R.xml.pie_segment_formatter3); 97 98 sf3.getFillPaint().setMaskFilter(emf); 99 100 SegmentFormatter sf4 = new SegmentFormatter(); 101 sf4.configure(getApplicationContext(), R.xml.pie_segment_formatter4); 102 103 sf4.getFillPaint().setMaskFilter(emf); 104 105 pie.addSeries(s1, sf1); 106 pie.addSeries(s2, sf2); 107 pie.addSeries(s3, sf3); 108 pie.addSeries(s4, sf4); 109 110 pie.getBorderPaint().setColor(Color.TRANSPARENT); 111 pie.getBackgroundPaint().setColor(Color.TRANSPARENT); 112 } 113 114 protected void updateDonutText() { 115 donutSizeTextView.setText(donutSizeSeekBar.getProgress() + "%"); 116 } 117 } 118