Android Open Source - Visu Study






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

/*****************************************************************************************
 * Study.java                                       *
 * Clase que administra todas las otras clases.                       *
 ****************************************************************************************/
//from  ww w. j  av a 2 s  .  c o m
package com.ufavaloro.android.visu.study;

import java.util.ArrayList;

import android.content.IntentSender.SendIntentException;
import android.os.Handler;
import android.os.Message;
import android.util.SparseArray;
import android.widget.Toast;

import com.ufavaloro.android.visu.R;
import com.ufavaloro.android.visu.UI.MainActivity;
import com.ufavaloro.android.visu.bluetooth.BluetoothProtocol;
import com.ufavaloro.android.visu.bluetooth.BluetoothProtocolMessage;
import com.ufavaloro.android.visu.draw.DrawHelper;
import com.ufavaloro.android.visu.storage.SamplesBuffer;
import com.ufavaloro.android.visu.storage.StorageHelper;
import com.ufavaloro.android.visu.storage.StorageHelperMessage;
import com.ufavaloro.android.visu.storage.datatypes.AcquisitionData;
import com.ufavaloro.android.visu.storage.datatypes.AdcData;
import com.ufavaloro.android.visu.storage.datatypes.PatientData;
import com.ufavaloro.android.visu.storage.datatypes.StorageData;
import com.ufavaloro.android.visu.storage.datatypes.StudyData;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.drive.DriveId;

public class Study {

/*****************************************************************************************
* Inicio de atributos de clase                                 *
*****************************************************************************************/
  // Helpers
  public StorageHelper storage;
  public BluetoothProtocol bluetooth;
  public DrawHelper draw;

  public StudyData[] onlineStudyData;
  public ArrayList<StudyData> offlineStudyData;
  
  // Context de StudyActivity
  private MainActivity mainActivity;
  
  // Canal Bluetooth asociado al estudio
  private int mBluetoothChannel;
  
  // Cantidad total de canales del estudio
  private int mTotalAdcChannels;
  
  private boolean mAdcDataOk = true;
  
  // Flags principales
  //
  // bluetoothHelper.connected
  // bluetoothHelper.totalAdcChannels
  //
  // drawHelper.onlineDrawBuffersOk
  //
  // storageHelper.driveManager.connected
  // storageHelper.sdManager.rootFoldersOk
  // storageHelper.sdManager.studyFoldersOk
  // storageHelper.sdManager.studyFilesOk
  // storageHelper.buffersOk
  // storageHelper.patientDataOk
  // storageHelper.recordingStarted

/*****************************************************************************************
* Inicio de m?todos de clase                                 *
*****************************************************************************************/

/*****************************************************************************************
* M?todos principales                                     *
*****************************************************************************************/
  // Constructor
  public Study(MainActivity mainActivity) {
    this.mainActivity = mainActivity;
    draw = (DrawHelper) mainActivity.findViewById(R.id.drawSurface);
    bluetooth = new BluetoothProtocol(mBluetoothProtocolHandler);
    storage = new StorageHelper(mainActivity, mStorageHelperHandler);  
    
    offlineStudyData = new ArrayList<StudyData>();
  }

/*****************************************************************************************
* M?todos de almacenamiento                                   *
*****************************************************************************************/
   // M?todo que genera un nuevo estudio Offline y, si estoy conectado al Drive, lo crea
  // tambi?n ah?
  public void newStudy(String patientName, String patientSurname, String studyName
             , SparseArray<Integer> channelsToStore) {
          
    PatientData patientData = new PatientData(patientName, patientSurname, studyName);

    for(int i = 0; i < channelsToStore.size(); i++) {
      int index = channelsToStore.valueAt(i);
      onlineStudyData[index].setMarkedForStoring(true);
    }
    
    for(int i = 0; i < onlineStudyData.length; i++) {
      onlineStudyData[i].setPatientData(patientData);
      draw.getChannels().getChannelAtIndex(i).getStudyData().setPatientData(patientData);
    }
    
    draw.getChannels().update();
    
    // Creo carpetas locales y en google drive
    storage.createStudyFolders(onlineStudyData);
    
    // Creo archivos .vis de los estudios
    storage.createLocalStudyFiles(onlineStudyData);
   
   }
   
  public void saveStudyToGoogleDrive() {
    storage.createGoogleDriveStudyFiles(onlineStudyData);  
  }

  public void setStudyType(int studyType, int channel) {
    // Guardo valor en los buffers de almacenamiento
    onlineStudyData[channel].getAcquisitionData().setStudyType(studyType);
    // Guardo valor en los buffers de dibujo
    draw.getChannels().getChannelAtIndex(channel).setStudyType(studyType);
    draw.getChannels().update();
  }
  
  public void setAMax(double aMax, int channel) {
    // Guardo valor en los buffers de almacenamiento
    onlineStudyData[channel].getAcquisitionData().setAMax(aMax);
    // Guardo valor en los buffers de dibujo
    draw.getChannels().getChannelAtIndex(channel).setAMax(aMax);
    draw.getChannels().update();
  }
  
  public void setAMin(double aMin, int channel) {
    // Guardo valor en los buffers de almacenamiento
    onlineStudyData[channel].getAcquisitionData().setAMin(aMin);
    // Guardo valor en los buffers de dibujo
    draw.getChannels().getChannelAtIndex(channel).setAMin(aMin);
    draw.getChannels().update();
  }
  
  // M?todo para saber si estoy conectado a Google Drive
  public boolean googleDriveConnectionOk() {
    return storage.googleDrive.isConnected();
  }

  // M?todo para abrir un archivo desde Google Drive
  public void loadFileFromGoogleDrive(DriveId driveId) {
    storage.loadFileFromGoogleDrive(driveId);
  }

  public void loadFileFromLocalStorage(String filePath) {
    storage.loadFileFromLocalStorage(filePath);
  }
  
/*****************************************************************************************
* M?todos de Conexi?n Bluetooth                                 *
*****************************************************************************************/
  // M?todo que agrega una conexi?n Bluetooth 
  public void newBluetoothConnection() {
    bluetooth.addBluetoothConnection();
  }
  
  // M?todo que informa el estado de la conexi?n
  public boolean connectedToRemoteDevice() {
    return bluetooth.getConnected();
  }
  
  // Getter de la cantidad de canales del adc
  public int getTotalAdcChannels() {  
    return bluetooth.getTotalAdcChannels();
  }
  
  // M?todo para obtener el dispositivo con el cual me conect?
  public String getRemoteDevice() {
    return bluetooth.getActualRemoteDevice();
  }

/*****************************************************************************************
* M?todos de Graficaci?n                                   *
*****************************************************************************************/
  // M?todo para crear buffers de graficaci?n online
  public void addChannel(int channel) {
    
    if(channel >= getTotalAdcChannels()) return;
    
    draw.addChannel(onlineStudyData[channel], true);

    draw.onlineDrawBuffersOk = true;
  
  }
  
  public void hideChannel(int channel) {
    draw.hideChannel(channel);
  }
  
  public void removeChannel(int channel) {
    draw.removeChannel(channel);
  }
  
  public boolean buffersOk() {
    return draw.onlineDrawBuffersOk;
  }
  
  public boolean adcDataOk() {
    return mAdcDataOk;
  }
  
   public void startDrawing() {
    draw.startDrawing();
  }

   public void startRecording() {     
     draw.currentlyRecording = true;
     storage.recording = true;
   }

   public void stopRecording() {    
     draw.currentlyRecording = false;
    storage.recording = false;
   }
   
   private void onGoogleDriveFileOpened(Object object) {
     StudyData studyData = (StudyData) object;
     offlineStudyData.add(studyData);
     draw.addChannel(studyData, false);   
   }
   
   private void onLocalStorageFileOpened(Object object) {
     StudyData studyData = (StudyData) object;
     if(studyData.getSamplesBuffer().getSize() == 0) {
       Toast.makeText(mainActivity, "El archivo no posee muestras", Toast.LENGTH_LONG).show();
       return;
     } else {
       offlineStudyData.add(studyData);
       draw.addChannel(studyData, false);
     }
   }
   
   private void onNewSamplesBatch(short[] samples, int channel) {
     if(draw.onlineDrawBuffersOk == true) draw.draw(samples, channel);
    if(storage.recording == true) storage.saveSamplesBatch(onlineStudyData[channel], samples);
   }
   
   private void onTotalAdcChannels(int totalAdcChannels) {
     mTotalAdcChannels = totalAdcChannels;
   }
   
   private void onAdcData(AdcData[] adcData) {
     onlineStudyData = new StudyData[mTotalAdcChannels];
     AcquisitionData acquisitionData;
     SamplesBuffer samplesBuffer;
     
     for(int i = 0; i < mTotalAdcChannels; i++) {
       onlineStudyData[i] = new StudyData();
       
       acquisitionData = new AcquisitionData(adcData[i]);
       onlineStudyData[i].setAcquisitionData(acquisitionData);
       
       samplesBuffer = new SamplesBuffer(onlineStudyData[i].getAcquisitionData(), "");
       onlineStudyData[i].setSamplesBuffer(samplesBuffer);
     }
     
     mAdcDataOk = true;
     
     mainActivity.onConfigurationOk();
   }
   
   private void onGoogleDriveConnected() {
     mainActivity.shortToast("Conectado a Google Drive");
   }
   
   private void onGoogleDriveSuspended() {
     
   }
   
   private void onGoogleDriveDisconnected() {
     
   }
   
   private void onGoogleDriveConnectionFailed(Message msg) {
 
     
   }
   
  private final Handler mBluetoothProtocolHandler = new Handler() {
    
    // M?todo para manejar el mensaje
    @Override
    public void handleMessage(Message msg) {
    
      // Tipo de mensaje recibido
      BluetoothProtocolMessage bluetoothHelperMessage = BluetoothProtocolMessage.values(msg.what);
      
      switch (bluetoothHelperMessage) {
        
        // Succesfully connected to Google Play Services
        case NEW_SAMPLES_BATCH:
          short[] samples = (short[]) msg.obj;
          int channel = msg.arg2;
          onNewSamplesBatch(samples, channel);
          break;
        
        case ADC_DATA:
          AdcData[] adcData = (AdcData[]) msg.obj;
          onAdcData(adcData);
          break;
          
        case TOTAL_ADC_CHANNELS:
          int totalAdcChannels = (Integer) msg.obj;
          onTotalAdcChannels(totalAdcChannels);
          break;
          
        default:
          break;
      
      }
    }
  };
  
  private final Handler mStorageHelperHandler = new Handler() {
    
    // M?todo para manejar el mensaje
    @Override
    public void handleMessage(Message msg) {
      
      // Tipo de mensaje recibido
      StorageHelperMessage storageHelperMessage = StorageHelperMessage.values(msg.what);
      
      switch (storageHelperMessage) {
        
        case GOOGLE_DRIVE_CONNECTED:
          onGoogleDriveConnected();
          break;
          
        case GOOGLE_DRIVE_SUSPENDED:
          onGoogleDriveSuspended();
          break;
          
        case GOOGLE_DRIVE_DISCONNECTED:
          onGoogleDriveDisconnected();
          break;
          
        case GOOGLE_DRIVE_CONNECTION_FAILED:
          onGoogleDriveConnectionFailed(msg);
          break;
          
        case GOOGLE_DRIVE_FILE_OPENED:
          onGoogleDriveFileOpened(msg.obj);
          break;
        
        case LOCAL_STORAGE_FILE_OPENED:
          onLocalStorageFileOpened(msg.obj);
        
        default:
          break;
      }
    }
    
  };



}




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