Search in sources :

Example 1 with NumericConversion

use of com.fr3ts0n.ecu.NumericConversion in project AndrOBD by fr3ts0n.

the class ObdItemAdapter 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) {
    // get data PV
    EcuDataPv currPv = (EcuDataPv) getItem(position);
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.obd_item, parent, false);
    }
    // fill view fields with data
    // description text
    TextView tvDescr = (TextView) convertView.findViewById(R.id.obd_label);
    tvDescr.setText(String.valueOf(currPv.get(EcuDataPv.FID_DESCRIPT)));
    TextView tvValue = (TextView) convertView.findViewById(R.id.obd_value);
    TextView tvUnits = (TextView) convertView.findViewById(R.id.obd_units);
    ProgressBar pb = (ProgressBar) convertView.findViewById(R.id.bar);
    // format value string
    String fmtText;
    Object colVal = currPv.get(EcuDataPv.FID_VALUE);
    Object cnvObj = currPv.get(EcuDataPv.FID_CNVID);
    Number min = (Number) currPv.get(EcuDataPv.FID_MIN);
    Number max = (Number) currPv.get(EcuDataPv.FID_MAX);
    int pid = currPv.getAsInt(EcuDataPv.FID_PID);
    try {
        if (cnvObj != null && cnvObj instanceof Conversion[] && ((Conversion[]) cnvObj)[EcuDataItem.cnvSystem] != null) {
            Conversion cnv;
            cnv = ((Conversion[]) cnvObj)[EcuDataItem.cnvSystem];
            // set formatted text
            fmtText = cnv.physToPhysFmtString((Number) colVal, (String) currPv.get(EcuDataPv.FID_FORMAT));
            // set progress bar only on LinearConversion
            if (min != null && max != null && cnv instanceof NumericConversion) {
                pb.setVisibility(ProgressBar.VISIBLE);
                pb.getProgressDrawable().setColorFilter(ChartActivity.getItemColor(pid), PorterDuff.Mode.SRC_IN);
                pb.setProgress((int) (100 * ((((Number) colVal).doubleValue() - min.doubleValue()) / (max.doubleValue() - min.doubleValue()))));
            } else {
                pb.setVisibility(ProgressBar.GONE);
            }
        } else {
            fmtText = String.valueOf(colVal);
        }
    } catch (Exception ex) {
        fmtText = String.valueOf(colVal);
    }
    // set value
    tvValue.setText(fmtText);
    tvUnits.setText(currPv.getUnits());
    return convertView;
}
Also used : EcuDataPv(com.fr3ts0n.ecu.EcuDataPv) NumericConversion(com.fr3ts0n.ecu.NumericConversion) TextView(android.widget.TextView) ProgressBar(android.widget.ProgressBar) NumericConversion(com.fr3ts0n.ecu.NumericConversion) Conversion(com.fr3ts0n.ecu.Conversion)

Aggregations

ProgressBar (android.widget.ProgressBar)1 TextView (android.widget.TextView)1 Conversion (com.fr3ts0n.ecu.Conversion)1 EcuDataPv (com.fr3ts0n.ecu.EcuDataPv)1 NumericConversion (com.fr3ts0n.ecu.NumericConversion)1