@Override
  protected void onResume() {
    super.onResume();

    // initialize our preferences
    tempUomPref = Integer.parseInt(prefs.getString("prefs_uom_temp", "1"));
    afrNotEqualTargetPref = prefs.getBoolean("prefs_afrnottarget_pref", false);
    afrNotEqualTargetTolerance = prefs.getFloat("prefs_afrnottarget_tolerance_pref", 5f);
    waterTempPref = prefs.getBoolean("prefs_watertemp_pref", false);
    remoteName = prefs.getString("prefs_remote_name", "");
    remoteMacAddr = prefs.getString("prefs_remote_mac", "");
    autoConnect = prefs.getBoolean("prefs_auto_connect", false);

    // need to set gauge scale based on uom selected
    switch (tempUomPref) {
      case 0:
        minimumWaterTemp =
            prefs.getFloat("prefs_min_water_temp", AdaptivePreferences.MIN_WATER_TEMP_CELCIUS);
        maximumWaterTemp =
            prefs.getFloat("prefs_max_water_temp", AdaptivePreferences.MAX_WATER_TEMP_CELCIUS);

        iatNeedle.setPivotPoint(.5f);
        iatNeedle.setMinValue(0);
        iatNeedle.setMaxValue(100);
        iatNeedle.setMinDegrees(-180);
        iatNeedle.setMaxDegrees(90);

        imgIat.setImageResource(R.drawable.iatgauge_celcius);
        break;

      case 1:
        minimumWaterTemp =
            prefs.getFloat("prefs_min_water_temp", AdaptivePreferences.MIN_WATER_TEMP_FAHRENHEIT);
        maximumWaterTemp =
            prefs.getFloat("prefs_max_water_temp", AdaptivePreferences.MAX_WATER_TEMP_FAHRENHEIT);

        iatNeedle.setPivotPoint(.5f);
        iatNeedle.setMinValue(0);
        iatNeedle.setMaxValue(200);
        iatNeedle.setMinDegrees(-180);
        iatNeedle.setMaxDegrees(90);

        imgIat.setImageResource(R.drawable.iatgauge);
        break;
    }

    afrAlarmLogging = prefs.getBoolean("prefs_afr_alarm_logging", false);
    if (menuShareLog != null) {
      menuShareLog.setVisible(afrAlarmLogging && !afrAlarmLogItems.getItems().isEmpty());
    }

    // ensure both fragments are hidden
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.hide(adaptiveFragment);
    ft.hide(gaugesFragment);
    ft.hide(fuelFragment);
    ft.commit();

    ActionBar bar = getActionBar();
    bar.selectTab(bar.getTabAt(prefs.getInt("prefs_last_tab", 1)));

    // EVAN
    String action = getIntent().getAction();

    if (Intent.ACTION_MAIN.equals(action) || UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) {
      if (DEBUG_MODE) Log.d(TAG, "USB Device Attached");

      connected = UsbConnectedThread.checkConnectedUsbDevice(this, connectionHandler);

      if (connected != null) {
        lastUpdateInMillis = System.currentTimeMillis();
      }
    }
    // END EVAN

    if (connected != null && connected.isAlive()) {
      refreshHandler.postDelayed(RefreshRunnable, LONG_PAUSE);
    } else {
      if (autoConnect && remoteMacAddr.length() > 0) {
        disconnect();
        new Handler()
            .postDelayed(
                (new Runnable() {
                  public void run() {
                    connect(remoteName, remoteMacAddr);
                  }
                }),
                1000);
        //        		connect(remoteName,  remoteMacAddr);
      }
    }
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    ctx = this;
    prefs = PreferenceManager.getDefaultSharedPreferences(ctx);

    adaptiveFragment = getFragmentManager().findFragmentById(R.id.frag_adaptive);
    gaugesFragment = getFragmentManager().findFragmentById(R.id.frag_gauges);
    fuelFragment = getFragmentManager().findFragmentById(R.id.frag_fuel);

    ActionBar bar = getActionBar();

    bar.addTab(bar.newTab().setText(R.string.tab_adaptive).setTabListener(this), false);
    bar.addTab(bar.newTab().setText(R.string.tab_gauges).setTabListener(this), false);
    bar.addTab(bar.newTab().setText("Fuel Map").setTabListener(this), false);

    mActionBarView = getLayoutInflater().inflate(R.layout.action_bar_custom, null);

    bar.setCustomView(mActionBarView);
    bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_USE_LOGO);
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    bar.setDisplayShowHomeEnabled(true);

    txtData = (TextView) findViewById(R.id.txtData);
    lvDevices = (ListView) findViewById(R.id.lvDevices);
    layoutDevices = (RelativeLayout) findViewById(R.id.layoutDevices);
    imgStatus = (ImageView) findViewById(R.id.imgStatus);

    txtFuelLearn = (TextView) findViewById(R.id.fuellearn);

    imgIWait = (ImageView) findViewById(R.id.imgIWait);
    imgIRpm = (ImageView) findViewById(R.id.imgIRpm);
    imgILoad = (ImageView) findViewById(R.id.imgILoad);

    imgFWait = (ImageView) findViewById(R.id.imgFWait);
    imgFRpm = (ImageView) findViewById(R.id.imgFRpm);
    imgFLoad = (ImageView) findViewById(R.id.imgFLoad);

    imgIat = (ImageView) findViewById(R.id.iat);

    gridData = (GridView) findViewById(R.id.gridData);

    dataArray = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
    dataArray.add("RPM\n ----");
    dataArray.add("MAP\n ---");
    dataArray.add("MAT\n ---\u00B0");
    dataArray.add("AFR\n --.-");
    dataArray.add("TAFR\n --.-");
    dataArray.add("WAT\n ---\u00B0");

    gridData.setAdapter(dataArray);

    lvDevices.setOnItemClickListener(DevicesClickListener);

    waterNeedle = (GaugeNeedle) findViewById(R.id.waterneedle);
    iatNeedle = (GaugeNeedle) findViewById(R.id.iatneedle);
    mapNeedle = (GaugeNeedle) findViewById(R.id.mapneedle);
    afrNeedle = (GaugeNeedle) findViewById(R.id.afrneedle);
    targetAfrNeedle = (GaugeNeedle) findViewById(R.id.targetafrneedle);
    rpmNeedle = (GaugeNeedle) findViewById(R.id.rpmneedle);

    waterNeedle.setPivotPoint(.65f);
    waterNeedle.setMinValue(100);
    waterNeedle.setMaxValue(240);
    waterNeedle.setMinDegrees(-50);
    waterNeedle.setMaxDegrees(55);

    afrNeedle.setPivotPoint(.5f);
    afrNeedle.setMinValue(AFR_MIN);
    afrNeedle.setMaxValue(AFR_MAX);
    afrNeedle.setMinDegrees(-180);
    afrNeedle.setMaxDegrees(90);

    targetAfrNeedle.setPivotPoint(.5f);
    targetAfrNeedle.setMinValue(AFR_MIN);
    targetAfrNeedle.setMaxValue(AFR_MAX);
    targetAfrNeedle.setMinDegrees(-180);
    targetAfrNeedle.setMaxDegrees(90);

    mapNeedle.setPivotPoint(.5f);
    mapNeedle.setMinValue(0);
    mapNeedle.setMaxValue(200);
    mapNeedle.setMinDegrees(-150);
    mapNeedle.setMaxDegrees(140);

    rpmNeedle.setPivotPoint(.5f);
    rpmNeedle.setMinValue(0);
    rpmNeedle.setMaxValue(9000);
    rpmNeedle.setMinDegrees(-130);
    rpmNeedle.setMaxDegrees(157);

    ChangeLog cl = new ChangeLog(this);
    if (cl.firstRun()) {
      cl.getLogDialog().show();
    }

    LinearLayout group = (LinearLayout) findViewById(R.id.linearLayoutTchart);
    chart = new TChart(this);
    chart.setAutoRepaint(false);

    group.addView(chart);

    ThemesList.applyTheme(chart.getChart(), 1);

    chart.removeAllSeries();
    ser = new Surface(chart.getChart());

    chart.getAspect().setView3D(true);
    ser.setIrregularGrid(true);

    ser.setUseColorRange(false);
    ser.setUsePalette(true);
    ser.setPaletteStyle(PaletteStyle.RAINBOW);

    chart.getPanel().setBorderRound(7);

    chart.getAspect().setView3D(true);
    chart.getAspect().setChart3DPercent(100);
    chart.getAspect().setOrthogonal(false);
    chart.getAspect().setZoom(75);
    chart.getAspect().setRotation(350);
    chart.getAspect().setElevation(350);
    chart.getAspect().setPerspective(37);

    chart.getAxes().getDepth().setVisible(true);
    chart.getLegend().setVisible(false);
    chart.getHeader().setText("Fuel Map #1 (VE)");
    chart.getHeader().getFont().setSize(18);
    chart.getHeader().getFont().setBold(true);

    ser.setColor(com.steema.teechart.drawing.Color.darkGray);
    new Rotate(chart.getChart());

    // EVAN
    mUsbDetachedFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
    registerReceiver(mUsbReceiver, mUsbDetachedFilter);
    // END EVAN

  }