/**
* Copyright (C) 2009, 2010 SC 4ViewSoft SRL
*
* 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.achartengine.chartdemo.demo;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.achartengine.chartdemo.demo.chart.AverageTemperatureChart;
import org.achartengine.chartdemo.demo.chart.BudgetDoughnutChart;
import org.achartengine.chartdemo.demo.chart.BudgetPieChart;
import org.achartengine.chartdemo.demo.chart.IChart;
import org.achartengine.chartdemo.demo.chart.MyChart;
import org.achartengine.chartdemo.demo.chart.ProjectStatusBubbleChart;
import org.achartengine.chartdemo.demo.chart.ProjectStatusChart;
import org.achartengine.chartdemo.demo.chart.SalesBarChart;
import org.achartengine.chartdemo.demo.chart.SalesComparisonChart;
import org.achartengine.chartdemo.demo.chart.SalesGrowthChart;
import org.achartengine.chartdemo.demo.chart.SalesStackedBarChart;
import org.achartengine.chartdemo.demo.chart.ScatterChart;
import org.achartengine.chartdemo.demo.chart.SensorValuesChart;
import org.achartengine.chartdemo.demo.chart.TemperatureChart;
import org.achartengine.chartdemo.demo.chart.TrigonometricFunctionsChart;
import org.achartengine.chartdemo.demo.chart.WeightDialChart;
import org.achartengine.chartdemo.demo.chart.XYChartBuilder;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;
public class ChartDemo extends ListActivity {
private IChart[] mCharts = new IChart[] {new AverageTemperatureChart(), new SalesStackedBarChart(),
new SalesBarChart(), new TrigonometricFunctionsChart(), new ScatterChart(), new SalesComparisonChart(),
new ProjectStatusChart(), new SalesGrowthChart(), new BudgetPieChart(), new BudgetDoughnutChart(),
new ProjectStatusBubbleChart(), new TemperatureChart(), new WeightDialChart(), new SensorValuesChart(),
new MyChart()};
private String[] mMenuText;
private String[] mMenuSummary;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
int length = mCharts.length;
mMenuText = new String[length + 2];
mMenuSummary = new String[length + 2];
mMenuText[0] = "Embedded chart demo";
mMenuSummary[0] = "A demo on how to include a chart into a graphical activity";
for (int i = 0; i < length; i++) {
mMenuText[i + 1] = mCharts[i].getName();
mMenuSummary[i + 1] = mCharts[i].getDesc();
}
mMenuText[length + 1] = "Random values charts";
mMenuSummary[length + 1] = "Chart demos using randomly generated values";
setListAdapter(new SimpleAdapter(this, getListValues(), android.R.layout.simple_list_item_2,
new String[] { IChart.NAME, IChart.DESC }, new int[] { android.R.id.text1, android.R.id.text2 }));
}
private List<Map<String, String>> getListValues() {
List<Map<String, String>> values = new ArrayList<Map<String, String>>();
int length = mMenuText.length;
for (int i = 0; i < length; i++) {
Map<String, String> v = new HashMap<String, String>();
v.put(IChart.NAME, mMenuText[i]);
v.put(IChart.DESC, mMenuSummary[i]);
values.add(v);
}
return values;
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Intent intent = null;
if (position == 0) {
intent = new Intent(this, XYChartBuilder.class);
} else if (position <= mCharts.length) {
intent = mCharts[position - 1].execute(this);
} else {
intent = new Intent(this, GeneratedChartDemo.class);
}
startActivity(intent);
}
}