Android Open Source - Visu Signal Box






From Project

Back to project page Visu.

License

The source code is released under:

Apache License

If you think the Android project Visu 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

/*****************************************************************************************
 * SignalBox.java                                     *
 * Clase que representa el rect?ngulo de la pantalla donde se grafica la se?al.      *
 ****************************************************************************************/
package com.ufavaloro.android.visu.draw.channel;
// www.j av a2  s.  c om
import java.text.DecimalFormat;

import android.graphics.Paint;
import android.graphics.Rect;

import com.ufavaloro.android.visu.draw.RGB;
import com.ufavaloro.android.visu.storage.datatypes.StudyData;
import com.ufavaloro.android.visu.study.StudyType;

public class SignalBox{

  // Draw buffer
  private DrawBuffer mDrawBuffer;
    
  // Ancho y alto
  private static float mWidth;
  private static float mHeight;  
  
  // L?mites gr?ficos y l?nea media
  private float mUpperBound;
  private float mLowerBound;
  private float mMidLine;

  private RGB mColor;
        
  private int mAdcChannelNumber;
  private int mChannelIndex;
  
  private Label mMaxAmplitudeLabel;
  private Label mMinAmplitudeLabel;
  
  private Label mMaxVoltageLabel;
  private Label mMinVoltageLabel;
  
  private Label mTimeLabel;
  private int mTimeLabelPixels;
  
  private float mAmplitudeCorrection;
  private float mVoltageCorrection;
  
  protected StudyData studyData;
  
/*****************************************************************************************
* Inicio de m?todos de clase                                  *
*****************************************************************************************/
/*****************************************************************************************
* M?todos principales                                   *
*****************************************************************************************/
  // Constructor para Online SignalBox
  SignalBox(int adcChannelNumber, int totalPages, StudyData studyData) {
    mAdcChannelNumber = adcChannelNumber;        
    this.studyData = studyData;
    mDrawBuffer = new DrawBuffer(mAdcChannelNumber, (int) mWidth, totalPages 
                   , studyData.getAcquisitionData().getBits());

    createMaxAmplitudeLabel();
    createMinAmplitudeLabel();
    createMaxVoltageLabel();
    createMinVoltageLabel();
    createTimeLabel();
          
  }
  
  // Constructor para Ofline SignalBox
  public SignalBox(int channelNumber, StudyData studyData) {
    mAdcChannelNumber = channelNumber;        
    this.studyData = studyData;
    int totalPages = (int) (studyData.getSamplesBuffer().getSize() / mWidth);
    mDrawBuffer = new DrawBuffer(mAdcChannelNumber, studyData, totalPages);

    createMaxAmplitudeLabel();
    createMinAmplitudeLabel();
    createMaxVoltageLabel();
    createMinVoltageLabel();
    createTimeLabel();
  }

  private void createMaxAmplitudeLabel() {
    mMaxAmplitudeLabel = new Label(studyData.getAcquisitionData().getAMax());
    char[] aux = studyData.getAcquisitionData().getStudyType();
    int studyType = aux[0];
    mMaxAmplitudeLabel.setUnits(StudyType.getUnits(StudyType.values(studyType)));
  }
  
  private void createMinAmplitudeLabel() {
    mMinAmplitudeLabel = new Label(studyData.getAcquisitionData().getAMin());
    char[] aux = studyData.getAcquisitionData().getStudyType();
    int studyType = aux[0];
    mMinAmplitudeLabel.setUnits(StudyType.getUnits(StudyType.values(studyType)));
  }
  
  private void createMaxVoltageLabel() {
    mMaxVoltageLabel = new Label(studyData.getAcquisitionData().getVMax());
    mMaxVoltageLabel.setUnits("V");
  }
  
  private void createMinVoltageLabel() {
    mMinVoltageLabel = new Label(studyData.getAcquisitionData().getVMin());
    mMinVoltageLabel.setUnits("V");
  }
  
  private void createTimeLabel() {
    mTimeLabel = new Label();
    mTimeLabelPixels = (int) (mWidth*0.15);
    double ts = 1 / studyData.getAcquisitionData().getFs();
    
    DecimalFormat df = new DecimalFormat();
    df.setMaximumFractionDigits(1);
    String result = df.format(ts * mTimeLabelPixels * mDrawBuffer.getHorizontalZoom());

    mTimeLabel.setText(result + " s");
  }

  public void update(int height, int channelIndex) {
    
    setHeight(height);
    setChannelIndex(channelIndex);
    getDrawBuffer().setVerticalZoom(mHeight/4);
    getDrawBuffer().setHorizontalZoom(1);
    setUpperBound(mChannelIndex*mHeight);
    setLowerBound((mChannelIndex+1)*mHeight);
    setMidLine(getUpperBound() + getHeight()/2);
    
    createMaxAmplitudeLabel();
    createMinAmplitudeLabel();
    createMaxVoltageLabel();
    createMinVoltageLabel();
    
    // Actualizo labels de Amax y Amin
    updateAmplitudeLabelsSize();
    updateAmplitudeLabelsPosition();
    
    // Actualizo labels de Vmax y Vmin
    updateVoltageLabelsSize();
    updateVoltageLabelsPosition();
    
    // Actualizo label de Tiempo
    updateTimeLabelSize();
    updateTimeLabelPosition();
  }

  private void updateTimeLabelPosition() {
    int yTime = (int) (mMidLine + (mHeight*0.5)*0.9);
    mTimeLabel.setY(yTime);
    
    int xTime = (int) (mWidth*0.85);
    mTimeLabel.setX(xTime);
  }

  private void updateVoltageLabelsPosition() {
    mVoltageCorrection = mMinVoltageLabel.getBoundingBox().height();

    int yMaxVoltage = (int) (mMidLine - mHeight/2 + mVoltageCorrection);  
    mMaxVoltageLabel.setY(yMaxVoltage);
    
    
    int yMinVoltage = (int) (mMidLine + mHeight/2);
    mMinVoltageLabel.setY(yMinVoltage);
    
  }

  private void updateAmplitudeLabelsPosition() {
    float yMaxAmplitude = mMidLine - mDrawBuffer.getVerticalZoom();  
    mMaxAmplitudeLabel.setY((int) yMaxAmplitude);
    
    float yMinAmplitude = mMidLine + mDrawBuffer.getVerticalZoom();
    mAmplitudeCorrection = mMinAmplitudeLabel.getBoundingBox().height();
    mMinAmplitudeLabel.setY((int) (yMinAmplitude + mAmplitudeCorrection));  
  }

  private void updateDrawBuffer() {
    mDrawBuffer.setHorizontalZoom(1);
    mDrawBuffer.setVerticalZoom(mHeight/4);
  }
  
  private void updateAmplitudeLabelsSize() {
    
    mMaxAmplitudeLabel.setTextSize(getBoundedTextSize(mMaxAmplitudeLabel));
    mMinAmplitudeLabel.setTextSize(getBoundedTextSize(mMinAmplitudeLabel));

  }

  protected void updateVoltageLabelsSize() {
    
    mMaxVoltageLabel.setTextSize(getBoundedTextSize(mMaxVoltageLabel));
    mMinVoltageLabel.setTextSize(getBoundedTextSize(mMinVoltageLabel));

  }
  
  public void updateVerticalZoom(float newZoomValue) {
    getDrawBuffer().setVerticalZoom(newZoomValue);
    updateAmplitudeLabelsPosition();
  }
  
  public void updateHorizontalZoom(float newZoomValue) {
    getDrawBuffer().setHorizontalZoom(newZoomValue);
    mTimeLabelPixels = (int) (mWidth*0.15);
    double ts = 1 / studyData.getAcquisitionData().getFs();
    
    DecimalFormat df = new DecimalFormat();
    df.setMaximumFractionDigits(1);
    String result = df.format(ts * mTimeLabelPixels * 1/mDrawBuffer.getHorizontalZoom());

    mTimeLabel.setText(result + " s");
  }
  
  protected void updateTimeLabelSize() {
    mTimeLabel.setTextSize(getBoundedTextSize(mTimeLabel));
  }
  
  private int getBoundedTextSize(Label label) {
    Rect rect = new Rect();
    double altoColumna = 0.05 * mHeight;

    int i = 0;
    Paint paint = new Paint();
    
    while (true) {
      paint.setTextSize(i);
      paint.getTextBounds(label.getText(), 0, label.getText().length(), rect);
      double alto = rect.height();
      if (alto > altoColumna) {
        break;
      }
      i++;
    }

    label.setBoundingBox(rect);
    return i;
  }
  
  public void panRight(int panSensitivity) {
    mDrawBuffer.decreaseGraphingIndex(panSensitivity);
  }
  
  public void panLeft(int panSensitivity) {
    mDrawBuffer.increaseGraphingIndex(panSensitivity);
  }
    
  public void resetGraphingIndex() {
    int storingIndex = mDrawBuffer.getStoringIndex();
    mDrawBuffer.setGraphingIndex(storingIndex);
  }

  public static int getWidth() {
    return (int) mWidth;
  }
  
  public static void setWidth(float width) {
    mWidth = width;
  }
  
  public static int getHeight() {
    return (int) mHeight;
  }
  
  public static void setHeight(float height) {
    mHeight = height;
  }
  
  public int getGraphingIndex() {
    return mDrawBuffer.getGraphingIndex();
  }

  public int getChannel() {
    return mAdcChannelNumber;
  }
  
  public RGB getColor() {
    return mColor;
  }
  
  public Label getLabelMaxAmplitude() {
    return mMaxAmplitudeLabel;
  }
  
  public Label getLabelMinAmplitude() {
    return mMinAmplitudeLabel;
  }
  
  public Label getLabelMaxVoltage() {
    return mMaxVoltageLabel;
  }
  
  public Label getLabelMinVoltage() {
    return mMinVoltageLabel;
  }
  
  public Label getTimeLabel() {
    return mTimeLabel;
  }
  
  public float getAmplitudeCorrection() {
    return mAmplitudeCorrection;
  }

  public float getVoltageCorrection() {
    return mVoltageCorrection;
  }
  
  public int getLabelTimePixels() {
    return mTimeLabelPixels;
  }  
  
  public DrawBuffer getDrawBuffer() {
    return mDrawBuffer;
  }

  public float getUpperBound() {
    return mUpperBound;
  }

  public void setUpperBound(float upperBound) {
    mUpperBound = upperBound;
  }

  public float getLowerBound() {
    return mLowerBound;
  }

  public void setLowerBound(float lowerBound) {
    mLowerBound = lowerBound;
  }

  public float getMidLine() {
    return mMidLine;
  }

  public void setMidLine(float midLine) {
    mMidLine = midLine;
  }
  
  public void setChannelIndex(int channelIndex) {
    mChannelIndex = channelIndex;
  }
  
}//SignalBox





Java Source Code List

com.samsung.sprc.fileselector.FileData.java
com.samsung.sprc.fileselector.FileListAdapter.java
com.samsung.sprc.fileselector.FileOperation.java
com.samsung.sprc.fileselector.FileSelector.java
com.samsung.sprc.fileselector.FileUtils.java
com.samsung.sprc.fileselector.OnHandleFileListener.java
com.samsung.sprc.fileselector.SaveLoadClickListener.java
com.samsung.sprc.fileselector.TextViewWithImage.java
com.ufavaloro.android.visu.UI.ChannelOptionsDialog.java
com.ufavaloro.android.visu.UI.LoadFileFromGoogleDriveDialog.java
com.ufavaloro.android.visu.UI.LoadFileFromLocalStorageDialog.java
com.ufavaloro.android.visu.UI.MainActivity.java
com.ufavaloro.android.visu.UI.MainMenuDialog.java
com.ufavaloro.android.visu.UI.NewStudyDialog.java
com.ufavaloro.android.visu.UI.OfflineChannelPropertiesDialog.java
com.ufavaloro.android.visu.UI.OnlineChannelPropertiesDialog.java
com.ufavaloro.android.visu.UI.StopStudyDialog.java
com.ufavaloro.android.visu.bluetooth.BluetoothProtocolMessage.java
com.ufavaloro.android.visu.bluetooth.BluetoothProtocol.java
com.ufavaloro.android.visu.bluetooth.BluetoothServiceMessage.java
com.ufavaloro.android.visu.bluetooth.BluetoothService.java
com.ufavaloro.android.visu.draw.BitmapManager.java
com.ufavaloro.android.visu.draw.DrawHelper.java
com.ufavaloro.android.visu.draw.RGB.java
com.ufavaloro.android.visu.draw.ReferenceMatrix.java
com.ufavaloro.android.visu.draw.TouchPointer.java
com.ufavaloro.android.visu.draw.channel.ChannelList.java
com.ufavaloro.android.visu.draw.channel.Channel.java
com.ufavaloro.android.visu.draw.channel.DrawBuffer.java
com.ufavaloro.android.visu.draw.channel.InfoBox.java
com.ufavaloro.android.visu.draw.channel.Label.java
com.ufavaloro.android.visu.draw.channel.ScreenElement.java
com.ufavaloro.android.visu.draw.channel.SignalBox.java
com.ufavaloro.android.visu.storage.DataConversion.java
com.ufavaloro.android.visu.storage.SamplesBuffer.java
com.ufavaloro.android.visu.storage.StorageHelperMessage.java
com.ufavaloro.android.visu.storage.StorageHelper.java
com.ufavaloro.android.visu.storage.StudyDataParser.java
com.ufavaloro.android.visu.storage.datatypes.AcquisitionData.java
com.ufavaloro.android.visu.storage.datatypes.AdcData.java
com.ufavaloro.android.visu.storage.datatypes.PatientData.java
com.ufavaloro.android.visu.storage.datatypes.StorageData.java
com.ufavaloro.android.visu.storage.datatypes.StudyData.java
com.ufavaloro.android.visu.storage.googledrive.GoogleDriveClientMessage.java
com.ufavaloro.android.visu.storage.googledrive.GoogleDriveClient.java
com.ufavaloro.android.visu.storage.googledrive.GoogleDriveManagerMessage.java
com.ufavaloro.android.visu.storage.googledrive.GoogleDriveManager.java
com.ufavaloro.android.visu.storage.local.LocalStorageManager.java
com.ufavaloro.android.visu.study.StudyMessage.java
com.ufavaloro.android.visu.study.StudyType.java
com.ufavaloro.android.visu.study.Study.java