Android Open Source - CopresenceDataCollector S D Setup Activity






From Project

Back to project page CopresenceDataCollector.

License

The source code is released under:

Copyright (c) 2014, Xiang Gao All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Re...

If you think the Android project CopresenceDataCollector 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.sesy.coco.datacollector;
//from   www.  jav  a 2 s .  c  o  m
import com.sensorcon.sensordrone.DroneEventHandler;
import com.sensorcon.sensordrone.DroneEventObject;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class SDSetupActivity extends Activity {
  
  private PrefManager pM;
  private static int wid = 0;
  public TextView tvMAC, tvConnStatus;
  public Button btnConnect, btnReconnect, btnDisconnect; 
  public DroneEventHandler myDroneEventHandler;
  
  @Override
  public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sdsetup);
    
    tvMAC = (TextView)findViewById(R.id.textViewSDMAC);
    tvConnStatus = (TextView)findViewById(R.id.textViewConnectionStatus);
    btnConnect = (Button)findViewById(R.id.buttonConnect);
    btnReconnect = (Button)findViewById(R.id.buttonReconnect);
    btnDisconnect = (Button)findViewById(R.id.buttonDisconnect);
    
    pM = new PrefManager(getApplicationContext());
    
    if(DaemonService.myDrone.isConnected){
      tvMAC.setText(DaemonService.myDrone.lastMAC);
      tvConnStatus.setText("is connected.");
    }else{
      tvMAC.setText("");
      tvConnStatus.setText("is not connected.");
    }
    
    myDroneEventHandler = new DroneEventHandler(){

      @Override
      public void parseEvent(DroneEventObject droneEventObject) {
        // TODO Auto-generated method stub
        if(droneEventObject.matches(DroneEventObject.droneEventType.CONNECTED)){
          tvMAC.setText(DaemonService.myDrone.lastMAC);
          tvConnStatus.setText("is connected.");
        }else if(droneEventObject.matches(DroneEventObject.droneEventType.DISCONNECTED)){
          tvMAC.setText("");
          tvConnStatus.setText("is not connected.");
        }
        
      }
      
    };
    
    btnConnect.setOnClickListener(new OnClickListener(){

      @Override
      public void onClick(View v) {
        // TODO Auto-generated method stub
        if(!DaemonService.myDrone.isConnected){
          DaemonService.myHelper.connectFromPairedDevices(DaemonService.myDrone, SDSetupActivity.this);
        }else{
          Toast.makeText(getApplicationContext(), "Sensordrone is already connected", Toast.LENGTH_SHORT).show();
        }
      }
      
    });
    
    btnReconnect.setOnClickListener(new OnClickListener(){

      @Override
      public void onClick(View v) {
        // TODO Auto-generated method stub
        if(!DaemonService.myDrone.isConnected){
          if(pM.getSensordroneMAC() != ""){
            DaemonService.myDrone.btConnect(pM.getSensordroneMAC());
          }else{
            Toast.makeText(getApplicationContext(), "Last MAC not found... Please connect once", Toast.LENGTH_SHORT).show();
          }
        }else{
          Toast.makeText(getApplicationContext(), "Sensordrone is already connected", Toast.LENGTH_SHORT).show();
        }
      }
      
    });
    
    btnDisconnect.setOnClickListener(new OnClickListener(){

      @Override
      public void onClick(View v) {
        // TODO Auto-generated method stub
        if(DaemonService.myDrone.isConnected){
          DaemonService.myDrone.disconnect();
        }else{
          Toast.makeText(getApplicationContext(), "Sensordrone is already disconnected", Toast.LENGTH_SHORT).show();
        }
      }
      
    });
    
  }
  
  @Override
  public void onResume(){
    super.onResume();
    DaemonService.myDrone.registerDroneListener(myDroneEventHandler);
  }
  
  @Override
  public void onPause(){
    super.onResume();
    DaemonService.myDrone.unregisterDroneListener(myDroneEventHandler);
  }
  
  @Override
  public void onDestroy(){
    Thread thr = new Thread(null, sTask, "StatusUpdate");
        thr.start();
    super.onDestroy();
  }

  Runnable sTask = new Runnable() {
        public void run() {
          DataMonitor.sendData(SDSetupActivity.this, DataMonitor.class, wid, DataMonitor.APP_SDSETUP_FINISHED_CODE, null, null, DataMonitor.DISREGARD_ID);
        //log.info("main send to datamonitor");
        }
  };
}




Java Source Code List

org.sesy.coco.datacollector.ARPWorker.java
org.sesy.coco.datacollector.AlarmService.java
org.sesy.coco.datacollector.AppLauncher.java
org.sesy.coco.datacollector.AudioProc.java
org.sesy.coco.datacollector.AudioWorker.java
org.sesy.coco.datacollector.BindActivity.java
org.sesy.coco.datacollector.BluetoothWorker.java
org.sesy.coco.datacollector.CellWorker.java
org.sesy.coco.datacollector.Constants.java
org.sesy.coco.datacollector.DaemonService.java
org.sesy.coco.datacollector.DataMonitor.java
org.sesy.coco.datacollector.GpsWorker.java
org.sesy.coco.datacollector.HelpActivity.java
org.sesy.coco.datacollector.MainActivity.java
org.sesy.coco.datacollector.MyPreference.java
org.sesy.coco.datacollector.MyWidgetProvider.java
org.sesy.coco.datacollector.PluginManager.java
org.sesy.coco.datacollector.PrefManager.java
org.sesy.coco.datacollector.ReportErrActivity.java
org.sesy.coco.datacollector.SDSetupActivity.java
org.sesy.coco.datacollector.SensorActivity.java
org.sesy.coco.datacollector.SensorListener.java
org.sesy.coco.datacollector.SensordroneWorker.java
org.sesy.coco.datacollector.SettingActivity.java
org.sesy.coco.datacollector.StatusActivity.java
org.sesy.coco.datacollector.StatusManager.java
org.sesy.coco.datacollector.TriggerService.java
org.sesy.coco.datacollector.UpdateWidgetService.java
org.sesy.coco.datacollector.WifiWorker.java
org.sesy.coco.datacollector.WorkerService.java
org.sesy.coco.datacollector.audio.Convolution.java
org.sesy.coco.datacollector.audio.CrossCorrelation.java
org.sesy.coco.datacollector.audio.ExtAudioRecorder.java
org.sesy.coco.datacollector.audio.XCorrAndDistFromWav.java
org.sesy.coco.datacollector.communication.HttpFileUploader.java
org.sesy.coco.datacollector.database.Entry.java
org.sesy.coco.datacollector.file.FileHelper.java
org.sesy.coco.datacollector.log.ConfigureLog4J.java
org.sesy.coco.datacollector.net.NetInfo.java
org.sesy.coco.datacollector.plugin.PlugInterface.java
wei.mark.standout.StandOutWindow.java
wei.mark.standout.Utils.java
wei.mark.standout.WindowCache.java
wei.mark.standout.constants.StandOutFlags.java
wei.mark.standout.ui.TouchInfo.java
wei.mark.standout.ui.Window.java