Android Open Source - Visu Info 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

package com.ufavaloro.android.visu.draw.channel;
/*ww  w. j  av a2  s.co  m*/
import java.util.ArrayList;

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

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


public class InfoBox{
  
  protected StudyData studyData;
  
  // Ancho y Alto
  private static float mWidth;
  private static float mHeight;

  // Array de Labels
  private ArrayList<Label> mLabelList = new ArrayList<Label>();

  // Posici?n de la l?nea que divide un SignalBox de un InfoBox
  private static int mVerticalDivisorXPosition;
  
  // Porcentaje del ancho del InfoBox que pueden ocupar los labels
  private final double mLabelWidthPercent = 0.85;
  
  // Padding a izquierda para centrar los Labels
  private final double mLeftPadding = (mWidth*(1-mLabelWidthPercent))/3;
  
  // Padding entre Labels para espaciarlos mejor
  private final double mInterLabelPadding = 0;//mHeight*0.01; 
  
  // Label con el # de canal
  private Label mChannelLabel;
  private final double mChannelLabelHeightPercent = 0.2;
  
  // Label de Nombre de Paciente
  private Label mPatientLabel;
  private final double mPatientLabelHeightPercent = 0.1;

  // Label de Pausa
  private Label mPausedLabel;
  private final double mPausedLabelHeightPercent = 0.1;

  // Canal que representa
  private int mAdcChannelNumber;
  private int mChannelIndex;
  
  // Color
  private RGB mColor;

  InfoBox(int channelNumber, StudyData studyData) {
    this.studyData = studyData;
    mAdcChannelNumber = channelNumber;
    
    createChannelLabel();
    //createElapsedTimeLabel();
    createPatientLabel();
    //createBitsLabel();
    //createHorizontalZoomLabel();
    //createVerticalZoomLabel();
    //createPausedLabel();
  }
  
  // Cuando se agrega o elimina un canal, se redimensionan los boxes
  protected void update(int height, int channelIndex) {
    
    setHeight(height);
    setChannelIndex(channelIndex);
    
    
    mLabelList.clear();
    
    createChannelLabel();
    //createElapsedTimeLabel();
    createPatientLabel();
    
    // Actualizo tama?os
    updateChannelLabelSize();
    updatePatientLabelSize();
    //updatePausedLabelSize();
    
    // Seteo tama?o m?nimo global de texto
    setMinimumSize();
    
    // Actualizo posiciones
    updateChannelLabelPosition();
    updatePatientLabelPosition();
    //UpdatePausedLabelPosition();

  }

  protected void createChannelLabel() {
    String channelLabel;
    if(studyData.getAcquisitionData().getStudyType() != null) {
      char[] aux = studyData.getAcquisitionData().getStudyType();
      int studyType = aux[0];
      channelLabel = String.valueOf(StudyType.values(studyType));
    } else {
      channelLabel = "Canal " + String.valueOf(mAdcChannelNumber + 1);
    }
    mChannelLabel = new Label(0, 0, 0, channelLabel);
  }

  protected void createPatientLabel() {
    String patientLabel;
    if(studyData.getPatientData() != null) {
      String patientName = String.valueOf(studyData.getPatientData().getPatientName());
      patientName = patientName.trim().replace('_', ' ');
      
      String patientSurname = String.valueOf(studyData.getPatientData().getPatientSurname());
      patientSurname = patientSurname.trim().replace('_', ' ');
      
      patientLabel = String.valueOf(patientSurname) + ", " + String.valueOf(patientName);
    } else {
      patientLabel = "Sin Paciente";
    }
    mPatientLabel = new Label(0, 0, 0, patientLabel);
  }

  private void createPausedLabel() {
    String text = "EN PAUSA";
    mPausedLabel = new Label(0, 0, 0, text);
  }
  
  protected void updateChannelLabelSize() {
    int textSize = getBoundedTextSize(mChannelLabel, mLabelWidthPercent * mWidth
                      , mChannelLabelHeightPercent * mHeight);
    mChannelLabel.setTextSize(textSize);
    
    mLabelList.add(mChannelLabel);
  }

  protected void updatePatientLabelSize() {
    int textSize = getBoundedTextSize(mPatientLabel, mLabelWidthPercent * mWidth
                      , mPatientLabelHeightPercent * mHeight);
    mPatientLabel.setTextSize(textSize);

    mLabelList.add(mPatientLabel);
  }
  
  private void updatePausedLabelSize() {
    int textSize = getBoundedTextSize(mPausedLabel, mLabelWidthPercent * mWidth
                      , mPausedLabelHeightPercent * mHeight);
    mPausedLabel.setTextSize(textSize);
    
    mLabelList.add(mPausedLabel);
  }  
  
  private void setMinimumSize() {
    
    int minTextSize = (int) mLabelList.get(0).getTextSize();
    
    // Obtengo tama?o de texto m?nimo
    for(int i = 1; i < mLabelList.size(); i++) {
      if(mLabelList.get(i).getTextSize() < minTextSize) {
        minTextSize = (int) mLabelList.get(i).getTextSize();
      }
    }
    
    // Seteo como tama?o de texto el m?nimo de todos los tama?os calculados
    // mediante getMaxTextSize()
    for (int i = 1; i < mLabelList.size(); i++) {
      mLabelList.get(i).setTextSize(minTextSize);
    }
  }

  // Acualizo el Label con el # de canal
  private void updateChannelLabelPosition() {
    
    mChannelLabel.setX((int) (mVerticalDivisorXPosition + mLeftPadding));
    mChannelLabel.setY((int) (mChannelLabel.getBoundingBox().height() 
                  + mChannelIndex*mHeight
                  + mInterLabelPadding));
  
  }

  // Update Patient Label
  private void updatePatientLabelPosition() {
    
    mPatientLabel.setX((int) (mVerticalDivisorXPosition + mLeftPadding));
    mPatientLabel.setY((int) (mPatientLabel.getBoundingBox().height()
                   + mChannelLabel.getY()
                   + mInterLabelPadding));
  
  }
    
  // Acualizo el Label de Pausa
  private void UpdatePausedLabelPosition() {
    
    mPausedLabel.setX((int) (mVerticalDivisorXPosition + mLeftPadding));
    mPausedLabel.setY((int) (mHeight - mInterLabelPadding));
    
  }  
    
  public int getChannel() {
    return mAdcChannelNumber;
  }
  
  public Label getLabelChannel() {
    return mChannelLabel;
  }

  public Label getPatientLabel() {
    return mPatientLabel;
  }

  public Label getLabelPaused() {
    return mPausedLabel;
  }
  
  public static void setWidth(float boxWidth) {
    mWidth = boxWidth;
  }
  
  public static void setHeight(float boxHeight) {
    mHeight = boxHeight;
  }

  public static float getBoxHeight() {
    return mHeight;
  }
  
  public static float getBoxWidth() {
    return InfoBox.mWidth;
  }

  public RGB getColor() {
    return mColor;
  }
  
  public void setColor(RGB mColor) {
    this.mColor = mColor;
  }

  // M?todo para obtener el tama?o de texto apropiado
  private int getBoundedTextSize(Label label, double boxWidth, double boxHeight) {
    
    Rect rect = new Rect();
    Paint paint = new Paint();

    int i = 0;
    
    while (true) {
      
      paint.setTextSize(i);
      paint.getTextBounds(label.getText(), 0, label.getText().length(), rect);
      
      double width = rect.width();
      double height = rect.height();
      
      if (width > boxWidth || height > boxHeight) {
        break;
        
      }
      
      i++;
      
    }

    return i;
  }
  
  public static int getVerticalDivisorXPosition() {
    return mVerticalDivisorXPosition;
  }

  public static void setVerticalDivisorXPosition(int mVerticalDivisorXPosition) {
    InfoBox.mVerticalDivisorXPosition = mVerticalDivisorXPosition;
  }

  public void setChannelIndex(int channelIndex) {
    mChannelIndex = channelIndex;
  }
  
  public void setChannelNumber(int channelNumber) {
    mAdcChannelNumber = channelNumber;
  }
}




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