Android Open Source - Visu Main Activity






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

/*****************************************************************************************
 * MainActivity.java                                   *
 * Clase que administra la interfaz de usuario.                           *
 ****************************************************************************************/
/*from w w w. ja  v  a 2  s  .c om*/
package com.ufavaloro.android.visu.UI;

import java.io.File;

import com.ufavaloro.android.visu.R;
import com.ufavaloro.android.visu.draw.channel.Channel;
import com.ufavaloro.android.visu.storage.datatypes.StorageData;
import com.ufavaloro.android.visu.study.Study;
import com.google.android.gms.drive.DriveId;
import com.google.android.gms.drive.OpenFileActivityBuilder;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.Window;
import android.widget.Toast;

public class MainActivity extends Activity {
  
  // Estudio
  private Study mStudy;
  // Request c?digo de apertura de archivo de Google Drive
  private static final int GOOGLE_DRIVE_REQUEST_CODE_OPENER = 1;
  // View para manejar Status Bar y Navigation Bar
  private View mRootView;
    
  // M?todo que se ejecuta luego de haberse creado el SurfaceView asociado
  public void setupAfterSurfaceCreated() {
    mStudy = new Study(this);    
    mStudy.newBluetoothConnection();    
  }
  
  // M?todo que se ejecuta una vez conectado al sensor y configurado el SurfaceView
  public void onConfigurationOk() {    
    // Creo canales de dibujo
    int totalAdcChannels = mStudy.getTotalAdcChannels();
    for(int i = 0; i < totalAdcChannels; i++) {
      mStudy.addChannel(i);
    }
    
    // Empiezo a dibujar
    mStudy.startDrawing();  
    //mStudy.draw.hideChannel(2);
    //mStudy.draw.hideChannel(0);
    //mStudy.draw.hideChannel(0);
  }

/*****************************************************************************************
* Dialogs                                               *
*****************************************************************************************/
  // Dialog de men? principal
  public void mainMenuDialog() {
    int theme = android.R.style.Theme_DeviceDefault_Light_Dialog_NoActionBar_MinWidth;
    MainMenuDialog dialog = new MainMenuDialog(this, theme);
    dialog.setMainActivity(this);
    dialog.setup();
  }
    
  // Dialog de nuevo estudio
  public void newStudyDialog() {
    int theme = android.R.style.Theme_DeviceDefault_Light_Dialog_NoActionBar_MinWidth;
    NewStudyDialog dialog = new NewStudyDialog(this, theme);
    dialog.setStudy(mStudy);
    dialog.setup();
    dialog.show();
  }
  
  // Dialog para abrir un archivo desde la memoria interna
  public void loadFileFromLocalStorageDialog() {
    LoadFileFromLocalStorageDialog dialog = new LoadFileFromLocalStorageDialog(this, mStudy);
    dialog.setup();
  }

  // Dialog para abrir un archivo desde Google Drive
  public void loadFileFromGoogleDriveDialog() {
    LoadFileFromGoogleDriveDialog dialog = new LoadFileFromGoogleDriveDialog(this, mStudy);
    dialog.setup();
  }
    
  // Dialog de parar estudio
  public void stopStudyDialog() {
    int theme = android.R.style.Theme_DeviceDefault_Light_Dialog_NoActionBar_MinWidth;
    StopStudyDialog dialog = new StopStudyDialog(this, theme);
    dialog.setStudy(mStudy);
    dialog.setup();
  }
  
  // Dialog con las opciones del canal
  public void channelOptionsDialog(int channelNumber) {
    int theme = android.R.style.Theme_DeviceDefault_Light_Dialog_NoActionBar_MinWidth;
    ChannelOptionsDialog dialog = new ChannelOptionsDialog(this, theme, channelNumber);
    dialog.setMainActivity(this);
    dialog.setStudy(mStudy);
    dialog.setup();
  }
    
  // Dialog de configuraci?n de canales ONLINE
  public void onlineChannelPropertiesDialog(int channel) {
    int theme = android.R.style.Theme_DeviceDefault_Light_Dialog_NoActionBar_MinWidth;
    OnlineChannelPropertiesDialog dialog = new OnlineChannelPropertiesDialog(this, theme, channel);
    dialog.setStudy(mStudy);
    dialog.setup();
    dialog.show();
  }
  
  // Dialog con las propiedades del canal OFFLINE
  public void offlineChannelPropertiesDialog(int channelNumber) {
    int theme = android.R.style.Theme_DeviceDefault_Light_Dialog_NoActionBar_MinWidth;
    OfflineChannelPropertiesDialog dialog = new OfflineChannelPropertiesDialog(this, theme, channelNumber);
    dialog.setStudy(mStudy);
    dialog.setup();
    dialog.show();
  }
  
/*****************************************************************************************
* Visibilidad de Status Bar y Navigation Bar                   *
*****************************************************************************************/
  // M?todo que muestra Status y Navigation bars
  private void showSystemUi(boolean visible) {
      int flag = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
              | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
              | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
              | View.SYSTEM_UI_FLAG_IMMERSIVE;
      if (!visible) {
      // We used the deprecated "STATUS_BAR_HIDDEN" for unbundling
          flag |= View.SYSTEM_UI_FLAG_FULLSCREEN
                  | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
      }
      mRootView.setSystemUiVisibility(flag);
  }

  // M?todo que escucha la pantalla para decidir cuando mostrar la UI
  private void setOnSystemUiVisibilityChangeListener() {
      mRootView.setOnSystemUiVisibilityChangeListener(
        new View.OnSystemUiVisibilityChangeListener() {
            @Override
            public void onSystemUiVisibilityChange(int visibility) {
              
              // Note that system bars will only be "visible" if none of the
                // LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set.
                if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
                    // The system bars are visible. Make any desired
                    // adjustments to your UI, such as showing the action bar or
                    // other navigational controls.
                  if(mStudy.draw != null) mStudy.draw.setUiVisibility(true);
                } else {
                    // The system bars are NOT visible. Make any desired
                    // adjustments to your UI, such as hiding the action bar or
                    // other navigational controls.
                  if(mStudy.draw != null) mStudy.draw.setUiVisibility(false);
                }
                
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        showSystemUi(false);
                    }
                }, 4000);
            }
        });
  }

/*****************************************************************************************
* Otros m?todos                                       *
*****************************************************************************************/
  // Getter de la carpeta de estudios
  public static File getStudiesFolder() {
    return StorageData.studiesFolder;
  }
  
  // Toast corto
  public void shortToast(String toToast) {
    Toast.makeText(getApplicationContext(), toToast, Toast.LENGTH_SHORT).show();
  }
  
  // Toast largo
  public void longToast(String toToast) {
    Toast.makeText(getApplicationContext(), toToast, Toast.LENGTH_LONG).show();
  }
  
/*****************************************************************************************
* Ciclo de vida de la activity                                 *
*****************************************************************************************/
  // this.activity on create  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    setContentView(R.layout.activity_main);
  }
  
  // this.activity on start
  @Override
  public void onStart() {
    super.onStart();  
  }
  
  // this.activity on resume
  @Override
  public void onResume() {
    super.onResume();
    mRootView = getWindow().getDecorView();
    setOnSystemUiVisibilityChangeListener();
    showSystemUi(false);
  }
    
  // this.activity on pause
  @Override
  public void onPause() {
    super.onPause();  
  }
  
  // this.activity on stop
  @Override
  public void onStop() {
    super.onStop();
  }
  
  // this.activity on destroy
  @Override
  public void onDestroy() {
    super.onDestroy();
    // Paro todos los Threads
     mStudy.bluetooth.stopConnections();
  }
  
  // this.activity on back pressed
  public void onBackPressed() {
      moveTaskToBack(true);
  }

  // this.activity onActivityResult
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        
    switch (requestCode) {
        
    case GOOGLE_DRIVE_REQUEST_CODE_OPENER:
          if (resultCode == RESULT_OK) {
            if(!mStudy.googleDriveConnectionOk()) return;
            DriveId driveId = (DriveId) data.getParcelableExtra(OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID);
            mStudy.loadFileFromGoogleDrive(driveId);
            shortToast("Abriendo archivo...");
          }               
        break;
        
        default:
          break;
        
        }
        
    }

}//MainActivity





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