Search in sources :

Example 1 with DialRenderer

use of org.achartengine.renderer.DialRenderer in project AndrOBD by fr3ts0n.

the class ObdGaugeAdapter method getView.

/* (non-Javadoc)
	 * @see android.widget.ArrayAdapter#getView(int, android.view.View, android.view.ViewGroup)
	 */
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    EcuDataPv currPv = getItem(position);
    int pid = currPv.getAsInt(EcuDataPv.FID_PID);
    // if no recycled convertView delivered, then create a new one
    if (convertView == null) {
        convertView = mInflater.inflate(resourceId, parent, false);
        holder = new ViewHolder();
        // get all views into view holder
        holder.gauge = (FrameLayout) convertView.findViewById(R.id.gauge);
        holder.tvDescr = (TextView) convertView.findViewById(R.id.label);
        // remember this view holder
        convertView.setTag(holder);
    } else {
        // recall previous holder
        holder = (ViewHolder) convertView.getTag();
    }
    convertView.getLayoutParams().width = minWidth;
    convertView.getLayoutParams().height = minHeight;
    // if no rendering component is registered with PV, then create and register new one
    DialChart chartView = (DialChart) currPv.getRenderingComponent();
    if (chartView == null) {
        CategorySeries category = (CategorySeries) currPv.get(FID_GAUGE_SERIES);
        Number minValue = (Number) currPv.get(EcuDataPv.FID_MIN);
        Number maxValue = (Number) currPv.get(EcuDataPv.FID_MAX);
        if (minValue == null)
            minValue = 0f;
        if (maxValue == null)
            maxValue = 255f;
        DialRenderer renderer = new DialRenderer();
        renderer.setScale(1.25f);
        // dial background
        renderer.setPanEnabled(false);
        renderer.setShowLegend(false);
        renderer.setShowLabels(true);
        renderer.setLabelsTextSize(mDisplayMetrics.densityDpi / 10);
        renderer.setLabelsColor(Color.WHITE);
        renderer.setShowLabels(true);
        renderer.setVisualTypes(new DialRenderer.Type[] { DialRenderer.Type.NEEDLE });
        renderer.setMinValue(minValue.doubleValue());
        renderer.setMaxValue(maxValue.doubleValue());
        renderer.setChartTitle(currPv.getUnits());
        renderer.setChartTitleTextSize(mDisplayMetrics.densityDpi / 10);
        SimpleSeriesRenderer r = new SimpleSeriesRenderer();
        r.setColor(ChartActivity.getItemColor(pid));
        try {
            r.setChartValuesFormat(labelFormat);
        } catch (Exception e) {
        // ignore
        }
        renderer.addSeriesRenderer(0, r);
        // create chart view and register with PV
        chartView = new DialChart(category, renderer);
        currPv.setRenderingComponent(chartView);
    }
    convertView.setBackgroundColor(ChartActivity.getItemColor(pid) & 0x08FFFFFF);
    // set new values for display
    holder.tvDescr.setTextColor(ChartActivity.getItemColor(pid));
    holder.tvDescr.setText(String.valueOf(currPv.get(EcuDataPv.FID_DESCRIPT)));
    // replace DialChart if needed
    holder.gauge.removeViewAt(0);
    holder.gauge.addView(new GraphicalView(getContext(), chartView), 0);
    return convertView;
}
Also used : EcuDataPv(com.fr3ts0n.ecu.EcuDataPv) SimpleSeriesRenderer(org.achartengine.renderer.SimpleSeriesRenderer) GraphicalView(org.achartengine.GraphicalView) CategorySeries(org.achartengine.model.CategorySeries) DialRenderer(org.achartengine.renderer.DialRenderer) DialChart(org.achartengine.chart.DialChart)

Aggregations

EcuDataPv (com.fr3ts0n.ecu.EcuDataPv)1 GraphicalView (org.achartengine.GraphicalView)1 DialChart (org.achartengine.chart.DialChart)1 CategorySeries (org.achartengine.model.CategorySeries)1 DialRenderer (org.achartengine.renderer.DialRenderer)1 SimpleSeriesRenderer (org.achartengine.renderer.SimpleSeriesRenderer)1