Android Open Source - MovisensGattSensorExample App






From Project

Back to project page MovisensGattSensorExample.

License

The source code is released under:

GNU General Public License

If you think the Android project MovisensGattSensorExample 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.movisens.gattsensorexample.application;
/*from   w w w .j a  v  a2 s. c o m*/
import android.app.Application;
import android.content.SharedPreferences;
import android.os.Handler;
import android.os.Looper;
import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.Toast;

import com.movisens.gattsensorexample.R;
import com.movisens.gattsensorexample.activities.Preferences;
import com.movisens.gattsensorexample.model.CurrentSensorData;
import com.movisens.gattsensorexample.services.SamplingService;
import com.movisens.movisensgattlib.characteristics.MovementAcceleration;
import com.movisens.smartgattlib.characteristics.BatteryLevel;

import de.greenrobot.event.EventBus;

public class App extends Application {

  private static final String TAG = "MovisensGattSensorExample";

  private static App instance = null;
  private Handler handler;
  private CurrentSensorData sensorData = new CurrentSensorData();

  private BatteryLevel batteryLevel = null;

  public static App app() {
    return instance;
  }

  public void showToast(final CharSequence text, final int duration) {
    handler.post(new Runnable() {
      public void run() {
        Toast.makeText(app(), text, duration).show();
      }
    });
  }

  @Override
  public void onCreate() {
    Log.i(TAG, "Initialize MovisensGattSensorExample Application");

    handler = new Handler(Looper.getMainLooper());
    instance = this;

    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);

    EventBus.getDefault().register(this);

    Boolean wasSamplingRunning = wasSamplingRunning();
    Log.d(TAG, "Sampling_Started was " + wasSamplingRunning);
    if (wasSamplingRunning) {
      SamplingService.start(instance);
    }

    super.onCreate();
  }

  public SharedPreferences getPrefs() {
    return PreferenceManager.getDefaultSharedPreferences(this);
  }

  public boolean isSamplingRunning() {
    return getPrefs().getBoolean(Preferences.SAMPLING_RUNNING, false);
  }

  public Boolean wasSamplingRunning() {
    return getPrefs().getBoolean(Preferences.SAMPLING_RUNNING, false);
  }

  public boolean isSensorSelected() {
    return !getPrefs().getString(Preferences.SENSOR_ADDRESS, "").equals("");
  }

  public String getSensor() {
    String sensor = "No Sensor selected";
    if (isSensorSelected()) {
      sensor = getPrefs().getString(Preferences.SENSOR_NAME, "") + " ("
          + getPrefs().getString(Preferences.SENSOR_ADDRESS, "")
          + ")";
    }
    return sensor;
  }

  public void onEventMainThread(MovementAcceleration movement) {
    this.sensorData.movementAcceleration = movement.getValue();
    EventBus.getDefault().post(this.sensorData);
  }

  public CurrentSensorData getCurrentSensorData() {
    return this.sensorData;
  }

  public void onEventMainThread(BatteryLevel batteryLevel) {
    this.batteryLevel = batteryLevel;
  }

  public BatteryLevel getCurrentBatteryLevel() {
    return this.batteryLevel;
  }

  public void shutDown() {
    Log.d(TAG, "Shutting down...");
    SamplingService.stop(this, true);
  }
}




Java Source Code List

com.movisens.gattsensorexample.activities.DeviceScanActivity.java
com.movisens.gattsensorexample.activities.Preferences.java
com.movisens.gattsensorexample.activities.SensorConnected.java
com.movisens.gattsensorexample.activities.SensorDisconnected.java
com.movisens.gattsensorexample.activities.StartActivity.java
com.movisens.gattsensorexample.activities.TimePreference.java
com.movisens.gattsensorexample.application.App.java
com.movisens.gattsensorexample.events.BLEEvent.java
com.movisens.gattsensorexample.events.MeasurementStatus.java
com.movisens.gattsensorexample.events.SensorStatusEvent.java
com.movisens.gattsensorexample.model.CurrentSensorData.java
com.movisens.gattsensorexample.receivers.SystemStateReceiver.java
com.movisens.gattsensorexample.receivers.UpdateAppReceiver.java
com.movisens.gattsensorexample.sensors.MovisensSensor.java
com.movisens.gattsensorexample.services.BluetoothLeService.java
com.movisens.gattsensorexample.services.SamplingService.java
com.movisens.gattsensorexample.utils.BleQueue.java
com.movisens.gattsensorexample.utils.BleUtils.java