コード例 #1
0
ファイル: DatLog.java プロジェクト: JohannaMaisel/DataMonitor
  private void open_files() throws FileNotFoundException {
    // Adjust view
    mbtn_start.setEnabled(false);
    mbtn_stop.setEnabled(true);
    mTabWidget.setEnabled(false);

    // Refs
    CSensorStates lSenStates = mSenStates;
    CLocProvStates lLPStates = mLPStates;
    DataOutputStream[] lfout = fout;

    // Open the files and register the listeners
    if (lSenStates.getNumAct() > 0) {
      lfout[0] =
          new DataOutputStream(
              new BufferedOutputStream(new FileOutputStream(file_location("_sensors.bin"))));
    } else lfout[0] = null;

    if (lLPStates.getNumAct() > 0) {
      lfout[1] =
          new DataOutputStream(
              new BufferedOutputStream(new FileOutputStream(file_location("_locprovider.bin"))));
    } else lfout[1] = null;

    if (mGPSState) {
      lfout[2] =
          new DataOutputStream(
              new BufferedOutputStream(new FileOutputStream(file_location("_gpsstate.bin"))));
    } else lfout[2] = null;
  }
コード例 #2
0
ファイル: DatLog.java プロジェクト: JohannaMaisel/DataMonitor
  private void show_registered() {
    CSensorStates lSenStates = mSenStates;
    CLocProvStates lLPStates = mLPStates;

    String nt = "Registered Sources:";
    int n = 0;
    for (int i = 0; i < lSenStates.getNum(); i++) {
      if (lSenStates.getActive(i)) {
        nt = nt + "\n\t" + lSenStates.getName(i);
        n++;
      }
    }

    for (int i = 0; i < lLPStates.getNum(); i++) {
      if (lLPStates.getActive(i)) {
        nt = nt + "\n\t" + lLPStates.getName(i);
        n++;
      }
    }

    if (mGPSState) {
      nt = nt + "\n\tGPS Status";
      n++;
    }

    if (n == 0) {
      nt = "No Registered Source.";
    }

    mLV.addtext(nt);
  }
コード例 #3
0
ファイル: DatLog.java プロジェクト: JohannaMaisel/DataMonitor
  @Override
  protected void onDestroy() {
    CSensorStates lSenStates = mSenStates;
    CLocProvStates lLPStates = mLPStates;

    // Write the preferences
    SharedPreferences lPrefs = getSharedPreferences("DatLogPrefs", MODE_PRIVATE);
    SharedPreferences.Editor lPrefEd = lPrefs.edit();

    // Gps prefs
    for (int i = 0; i < lLPStates.getNum(); i++) {
      lPrefEd.putBoolean(lLPStates.getName(i), lLPStates.getActive(i));
      lPrefEd.putFloat(lLPStates.getName(i) + "_mindist", lLPStates.getMinDist(i));
      lPrefEd.putLong(lLPStates.getName(i) + "_mintime", lLPStates.getMinTime(i));
    }
    lPrefEd.putBoolean("gps_status", mGPSState);

    // Sensor prefs
    for (int i = 0; i < lSenStates.getNum(); i++) {
      lPrefEd.putBoolean(lSenStates.getName(i), lSenStates.getActive(i));
      lPrefEd.putInt(lSenStates.getName(i) + "_rate", lSenStates.getRate(i));
    }

    lPrefEd.commit();

    super.onDestroy();
  }
コード例 #4
0
ファイル: DatLog.java プロジェクト: JohannaMaisel/DataMonitor
  private void read_prefs() {
    SharedPreferences lPrefs = getSharedPreferences("DatLogPrefs", MODE_PRIVATE);
    CLocProvStates lLPStates = mLPStates;
    CSensorStates lSenNames = mSenStates;
    float mindist;
    long mintime;
    boolean val;
    int rate;

    // Read the sensor preferences
    for (int i = 0; i < lSenNames.getNum(); i++) {
      val = lPrefs.getBoolean(lSenNames.getName(i), false);
      lSenNames.setActive(i, val);
      rate = lPrefs.getInt(lSenNames.getName(i) + "_rate", SensorManager.SENSOR_DELAY_FASTEST);
      lSenNames.setRate(i, rate);
    }

    // Read the location provider preferences
    for (int i = 0; i < lLPStates.getNum(); i++) {
      val = lPrefs.getBoolean(lLPStates.getName(i), false);
      lLPStates.setActive(i, val);
      mindist = lPrefs.getFloat(lLPStates.getName(i) + "_mindist", 0);
      mintime = lPrefs.getLong(lLPStates.getName(i) + "_mintime", 0);
      lLPStates.setCriterion(i, mindist, mintime);
    }

    // Read the GPS Status preference
    val = lPrefs.getBoolean("gps_status", false);
  }
コード例 #5
0
ファイル: DatLog.java プロジェクト: JohannaMaisel/DataMonitor
  private void register_listeners() {

    CSensorStates lSenStates = mSenStates;
    CLocProvStates lLPStates = mLPStates;
    DataOutputStream[] lfout = fout;
    SensorManager lSenMan = mSenMan;
    LocationManager lLocMan = mLocMan;

    // Register the sensors
    if (lfout[0] != null) {
      for (int i = 0; i < lSenStates.getNum(); i++) {
        if (lSenStates.getActive(i))
          lSenMan.registerListener(
              this, lSenMan.getDefaultSensor(lSenStates.getType(i)), lSenStates.getRate(i));
      }
    }

    // Register listeners for active location providers
    if (lfout[1] != null) {
      for (int i = 0; i < lLPStates.getNum(); i++) {
        if (lLPStates.getActive(i))
          lLocMan.requestLocationUpdates(
              lLPStates.getName(i), lLPStates.getMinTime(i), lLPStates.getMinDist(i), this);
      }
    }

    if (lfout[2] != null) {
      lLocMan.addGpsStatusListener(this);
    }
  }
コード例 #6
0
ファイル: DatLog.java プロジェクト: JohannaMaisel/DataMonitor
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    SensorManager lSenMan = (SensorManager) getSystemService(SENSOR_SERVICE);
    LocationManager lLocMan = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    mSenMan = lSenMan;
    mLocMan = lLocMan;

    // Get the names of all sources
    mSenStates = new CSensorStates(lSenMan.getSensorList(Sensor.TYPE_ALL));
    mLPStates = new CLocProvStates(lLocMan.getAllProviders());
    mGPSState = false;
    mSenStates.setRate(
        SensorManager.SENSOR_DELAY_FASTEST); // Set the sensor rate to the maximum (default is UI)
    CSensorStates lSenStates = mSenStates;
    CLocProvStates lLPStates = mLPStates;

    // Read the prefs
    read_prefs();

    // Construct the view
    setContentView(R.layout.datlog);
    // Main Tab (tab0)
    mLV = (CLogView) findViewById(R.id.DLtv1);
    Button lbtn_start = (Button) findViewById(R.id.DLbtn0);
    Button lbtn_event = (Button) findViewById(R.id.DLbtn1);
    Button lbtn_stop = (Button) findViewById(R.id.DLbtn2);
    Button lbtn_erec = (Button) findViewById(R.id.DLbtn3);
    Button lbtn_show = (Button) findViewById(R.id.DLbtn4);

    lbtn_start.setOnClickListener(this);
    lbtn_event.setOnClickListener(this);
    lbtn_stop.setOnClickListener(this);
    lbtn_erec.setOnClickListener(this);
    lbtn_show.setOnClickListener(this);

    lbtn_stop.setEnabled(false);
    mbtn_start = lbtn_start;
    mbtn_stop = lbtn_stop;

    // The sensor selection tab
    ListView llistview1 = (ListView) findViewById(R.id.DLtab2);
    ArrayAdapter<String> ladapter1 =
        new ArrayAdapter<String>(
            this, android.R.layout.simple_list_item_multiple_choice, lSenStates.getNames());
    llistview1.setAdapter(ladapter1);
    // Show the current sensor selection
    for (int i = 0; i < lSenStates.getNum(); i++) {
      llistview1.setItemChecked(i, lSenStates.getActive(i));
    }
    llistview1.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {

          public void onItemClick(AdapterView<?> arg0, View aview, int position, long arg3) {
            mSenStates.setActToggle(position);
          }
        });

    // Location Provider Selection Tab
    ListView llistview2 = (ListView) findViewById(R.id.DLtab3);
    llistview2.setAdapter(
        new ArrayAdapter<String>(
            this, android.R.layout.simple_list_item_multiple_choice, lLPStates.getNames()));
    // Show the current sensor selection
    for (int i = 0; i < lLPStates.getNum(); i++) {
      llistview2.setItemChecked(i, lLPStates.getActive(i));
    }
    llistview2.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {

          public void onItemClick(AdapterView<?> arg0, View aview, int position, long arg3) {
            mLPStates.setActToggle(position);
          }
        });

    // Gps Status selection tab
    CheckedTextView lcheckview = (CheckedTextView) findViewById(R.id.DLck1);
    lcheckview.setChecked(mGPSState);
    lcheckview.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            mGPSState = !mGPSState;
            ((CheckedTextView) v).setChecked(mGPSState);
          };
        });

    // Create the tabs
    TabHost lTabHost = getTabHost();
    lTabHost.addTab(lTabHost.newTabSpec("tab1").setIndicator("Control").setContent(R.id.DLtab1));
    lTabHost.addTab(lTabHost.newTabSpec("tab2").setIndicator("Sensors").setContent(R.id.DLtab2));
    lTabHost.addTab(lTabHost.newTabSpec("tab3").setIndicator("Providers").setContent(R.id.DLtab3));
    if (mLPStates.isExist(LocationManager.GPS_PROVIDER))
      lTabHost.addTab(
          lTabHost.newTabSpec("tab4").setIndicator("GPS Status").setContent(R.id.DLtab4));

    lTabHost.setCurrentTab(0);
    mTabWidget = lTabHost.getTabWidget();
  }