Android Open Source - audiopulse-androidclient Monitor Handler






From Project

Back to project page audiopulse-androidclient.

License

The source code is released under:

GNU General Public License

If you think the Android project audiopulse-androidclient listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.audiopulse.activities;
//from w w  w .j  a va 2s  .com
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;

public class MonitorHandler extends Handler
{
  public static final String TAG = "MonitorHandler";
  private TestEarActivity parentActivity = null; 
  public static final String LOGUI="logUI";
  public volatile boolean dataIsReady;
  public MonitorHandler(TestEarActivity testActivity)
  {
    parentActivity = testActivity;
  }

  public static class Messages {
    public static final int CLEAR_LOG = 1;        //clear the test log
    public static final int LOG = 2;          //add to the test log
    public static final int PROGRESS = 3;        //progress has been made
    public static final int IO_COMPLETE = 4;      //io phase is complete
    public static final int RECORDING_COMPLETE = 5;    //analysis block complete
    public static final int PROCEDURE_COMPLETE = 6;    //entire test procedure is complete
    public static final int ANALYZE_DATA = 7;
    public static final int TEST_FREQUENCY = 8;
  }
  
  @Override
  public void handleMessage(Message msg) {
    
    Bundle data = msg.getData();
    switch (msg.what) {
    case Messages.CLEAR_LOG:
      parentActivity.app_out.setText("");
      break;
    case Messages.LOG:
      String pm = data.getString(LOGUI);
      parentActivity.app_out.append(pm);
      break;
    case Messages.TEST_FREQUENCY:
      parentActivity.doOneTest();//Starts recording for one frequency
      break;
    case Messages.RECORDING_COMPLETE:
      dataIsReady=false;
      try{
      parentActivity.app_out.append("\nRetrieving data...");
      parentActivity.getData();
      parentActivity.app_out.append("Recorded data size=" + parentActivity.getPSDSize());
      if(parentActivity.psd != null){
        //The analysis should be quick enough to do on the UI without getting ANR error.
        //In the case we do get it, we may want to push this to the MonitorThread class.
        parentActivity.analyzePSD();
        double diff=(parentActivity.respSPL-parentActivity.noiseSPL);
        parentActivity.app_out.append("\nResp: " + parentActivity.respSPL
            + " dB, noise= " + parentActivity.noiseSPL + " dB , diff: " +
            diff + " SPL");
        parentActivity.plotdata_button.setEnabled(true);
        dataIsReady=true;
      }
      }catch(Exception e) {
        //In this case the recording failed. Should we try again ??
        parentActivity.app_out.append(e.getMessage());
      }
      break;
    }
  }
  
  public synchronized void setCurrentFrequency(short f1, short f2) {
    parentActivity.setCurrentTestFrequencies(f1, f2);
  }
  
  public synchronized short getCurrentF1() {
    return parentActivity.getCurrentF1();
  }
  
  public synchronized short getCurrentF2() {
    return parentActivity.getCurrentF2();
  }

}




Java Source Code List

org.audiopulse.activities.AudioPulseActivity.java
org.audiopulse.activities.MonitorHandler.java
org.audiopulse.activities.MonitorThread.java
org.audiopulse.activities.PlotSpectralActivity.java
org.audiopulse.activities.TestEarActivity.java
org.audiopulse.activities.UsbTestActivity.java
org.audiopulse.analysis.DPOAEAnalyzer.java
org.audiopulse.analysis.DPOAEResults.java
org.audiopulse.analysis.SignalProcessing.java
org.audiopulse.analysis.SpectralWindows.java
org.audiopulse.graphics.DemoView.java
org.audiopulse.graphics.PlotSpectralView.java
org.audiopulse.hardware.APulseIface.java
org.audiopulse.hardware.USBIface.java
org.audiopulse.io.AudioPulseFilePackager.java
org.audiopulse.io.AudioPulseFileWriter.java
org.audiopulse.io.UsbAudioEmulator.java
org.audiopulse.io.UsbAudioInterface.java