Ejemplo n.º 1
0
  public void onDestroy() {
    running = false;
    if (scanThread != null) scanThread.interrupt();

    if (myWLocate != null) myWLocate.doPause();

    sensorManager.unregisterListener(
        this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER));

    if (scanData.getmView() != null) {
      ((WindowManager) getSystemService(WINDOW_SERVICE)).removeView(scanData.getmView());
      scanData.setmView(null);
    }
    try {
      if (wl != null) wl.release();
    } catch (RuntimeException re) {
    }
    wl = null;
    try {
      scanThread.join(1000);
    } catch (InterruptedException ie) {

    }
    System.exit(0);
  }
Ejemplo n.º 2
0
 // Sensor events
 public void enableSensor(int sensortype, boolean enabled) {
   // TODO: This uses getDefaultSensor - what if we have >1 accels?
   if (enabled) {
     mSensorManager.registerListener(
         this, mSensorManager.getDefaultSensor(sensortype), SensorManager.SENSOR_DELAY_GAME, null);
   } else {
     mSensorManager.unregisterListener(this, mSensorManager.getDefaultSensor(sensortype));
   }
 }
Ejemplo n.º 3
0
 @Override
 protected void onPause() {
   super.onPause();
   activityRunning = false;
   sensorManager.unregisterListener(this, countSensor);
   sensorManager.unregisterListener(this, mAccelerometer);
   sensorManager.unregisterListener(this, mMagnetometer);
   // if you unregister the last listener, the hardware will stop detecting step events
   //        sensorManager.unregisterListener(this);
 }
Ejemplo n.º 4
0
 @Override
 protected void onPause() {
   super.onPause();
   mView.onPause();
   mSensorManager.unregisterListener(this);
   GodotLib.focusout();
 }
Ejemplo n.º 5
0
 @Override
 protected void onResume() {
   super.onResume();
   mView.onResume();
   mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);
   GodotLib.focusin();
 }
Ejemplo n.º 6
0
 @Override
 public void onSensorChanged(SensorEvent event) {
   Sensor sensor = event.sensor;
   if (sensor.getType() == Sensor.TYPE_STEP_COUNTER) {
     if (first) {
       first = false;
       System.out.println("error first");
       // Toast.makeText(this, "sensor result", Toast.LENGTH_LONG).show();
       count1 = Float.parseFloat(String.valueOf(event.values[0]));
     }
     if (activityRunning) {
       System.out.println("error later");
       // Toast.makeText(this, "sensor value 1", Toast.LENGTH_LONG).show();
       drawView.invalidate();
       count.setText((Float.parseFloat(String.valueOf(event.values[0])) - count1) + "");
     }
   }
   if (event.sensor == mAccelerometer) {
     System.arraycopy(event.values, 0, mLastAccelerometer, 0, event.values.length);
     mLastAccelerometerSet = true;
   } else if (event.sensor == mMagnetometer) {
     System.arraycopy(event.values, 0, mLastMagnetometer, 0, event.values.length);
     mLastMagnetometerSet = true;
   }
   if (mLastAccelerometerSet && mLastMagnetometerSet) {
     Toast.makeText(this, "I am here", Toast.LENGTH_LONG).show();
     SensorManager.getRotationMatrix(mR, null, mLastAccelerometer, mLastMagnetometer);
     SensorManager.getOrientation(mR, mOrientation);
     float azimuthInRadians = mOrientation[0];
     float azimuthInDegress = (float) (Math.toDegrees(azimuthInRadians) + 360) % 360;
     angle.setText(azimuthInRadians + " radians and " + azimuthInDegress + " degrees");
     float diff = Math.abs(azimuthInDegress - previousdegree);
     if (diff > 90) {
       previousdegree = azimuthInDegress;
       if (azimuthInDegress < 45 || azimuthInDegress > 315) {
         drawView.current = DrawView.Side.North;
       } else if (azimuthInDegress > 45 || azimuthInDegress < 135) {
         drawView.current = DrawView.Side.East;
       } else if (azimuthInDegress > 135 || azimuthInDegress < 225) {
         drawView.current = DrawView.Side.South;
       } else {
         drawView.current = DrawView.Side.West;
       }
     }
   }
 }
Ejemplo n.º 7
0
  private void initializeGodot() {

    if (expansion_pack_path != null) {

      String[] new_cmdline;
      int cll = 0;
      if (command_line != null) {
        Log.d("GODOT", "initializeGodot: command_line: is not null");
        new_cmdline = new String[command_line.length + 2];
        cll = command_line.length;
        for (int i = 0; i < command_line.length; i++) {
          new_cmdline[i] = command_line[i];
        }
      } else {
        Log.d("GODOT", "initializeGodot: command_line: is null");
        new_cmdline = new String[2];
      }

      new_cmdline[cll] = "-main_pack";
      new_cmdline[cll + 1] = expansion_pack_path;
      command_line = new_cmdline;
    }

    io = new GodotIO(this);
    io.unique_id = Secure.getString(getContentResolver(), Secure.ANDROID_ID);
    GodotLib.io = io;
    Log.d("GODOT", "command_line is null? " + ((command_line == null) ? "yes" : "no"));
    /*if(command_line != null){
        Log.d("GODOT", "Command Line:");
        for(int w=0;w <command_line.length;w++){
            Log.d("GODOT","   " + command_line[w]);
        }
    }*/
    GodotLib.initialize(this, io.needsReloadHooks(), command_line);
    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME);

    result_callback = null;

    mPaymentsManager = PaymentsManager.createManager(this).initService();
    godot_initialized = true;
  }
Ejemplo n.º 8
0
  /** Called when the activity is first created. */
  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mInitialized = false;

    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    sOrientation = mSensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR);

    mSensorManager.registerListener(this, sOrientation, SensorManager.SENSOR_DELAY_NORMAL);

    Button message_txt = (Button) findViewById(R.id.send_message);
    // sent_txt = (TextView)findViewById(R.id.button_listen);

    Button button_listen = (Button) findViewById(R.id.button_listen);

    message_txt.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {

            WantConnection = true;

            connected = connectSocket("192.168.43.200");

            mInitialized = false;
          }
        });

    button_listen.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            // sendData(Float.toString(delta[0])+""+Float.toString(delta[1])+""+Float.toString(delta[2]));

            float testFloat = (float) 0.1010101;
            sendData(Float.toString(testFloat));
          }
        });
  }
Ejemplo n.º 9
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    countSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
    mAccelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    mMagnetometer = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);

    sensorManager.registerListener(this, countSensor, SensorManager.SENSOR_DELAY_UI);
    sensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_UI);
    sensorManager.registerListener(this, mMagnetometer, SensorManager.SENSOR_DELAY_UI);

    setContentView(R.layout.activity_main);
    layout = (RelativeLayout) findViewById(R.id.relativeLayout);
    count = (TextView) findViewById(R.id.count);
    angle = (TextView) findViewById(R.id.Angle);

    drawView = new DrawView(this);
    drawView.setBackgroundColor(Color.BLACK);
    drawView.setMinimumHeight(73);
    RelativeLayout.LayoutParams params =
        new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.BELOW, count.getId());

    layout.addView(drawView, params);
  }
Ejemplo n.º 10
0
  @Override
  protected void onCreate(Bundle icicle) {

    super.onCreate(icicle);

    Window window = getWindow();
    window.addFlags(
        WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
            | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    io = new GodotIO(this);
    io.unique_id = Secure.getString(getContentResolver(), Secure.ANDROID_ID);
    GodotLib.io = io;
    GodotLib.initialize(this, io.needsReloadHooks());
    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);

    result_callback = null;

    //	instanceSingleton( new GodotFacebook(this) );

  }
Ejemplo n.º 11
0
  @Override
  protected void onPause() {
    super.onPause();
    if (!godot_initialized) {
      if (null != mDownloaderClientStub) {
        mDownloaderClientStub.disconnect(this);
      }
      return;
    }
    mView.onPause();
    mSensorManager.unregisterListener(this);
    GodotLib.focusout();

    for (int i = 0; i < singleton_count; i++) {
      singletons[i].onMainPause();
    }
  }
Ejemplo n.º 12
0
  @Override
  protected void onResume() {
    super.onResume();
    if (!godot_initialized) {
      if (null != mDownloaderClientStub) {
        mDownloaderClientStub.connect(this);
      }
      return;
    }

    mView.onResume();
    mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);
    GodotLib.focusin();

    for (int i = 0; i < singleton_count; i++) {

      singletons[i].onMainResume();
    }
  }
Ejemplo n.º 13
0
 /* (non-Javadoc)
  * @see jcu.sal.managers.ManagerFactory#remove(java.lang.Object)
  */
 @Override
 protected void remove(AbstractProtocol component) {
   ProtocolID pid = component.getID();
   // logger.debug("Removing protocol " + pid.toString());
   component.remove(this);
   /**
    * the sensors associated with the protocol must be removed AFTER the protocol otherwise the
    * autodetection could try and create them again between the moment we remove them and the
    * moment we remove the protocol
    */
   SensorManager.getSensorManager().destroyComponents(component.getSensors());
   componentRemovable(pid);
   ev.queueEvent(
       new ProtocolListEvent(
           ProtocolListEvent.PROTOCOL_REMOVED,
           component.getID().getName(),
           Constants.PROTOCOL_MANAGER_PRODUCER_ID));
   logger.debug(
       "Removed protocol '" + component.getID().getName() + "' - type: " + component.getType());
 }
Ejemplo n.º 14
0
  /**
   * Creates all protocols, associated endpoints and sensors given SML and PCML
   *
   * @throws ConfigurationException if there is a problem parsing the XML files
   */
  public void init(String sml, String pcml) throws ConfigurationException {
    try {
      conf.init(pcml, sml);
    } catch (ConfigurationException e) {
      logger.error("Could not read the configuration files");
      throw e;
    }

    for (ProtocolConfiguration p : conf.getProtocols())
      try {
        createComponent(p);
      } catch (ConfigurationException e) {
      }

    for (SMLDescription s : conf.getSensors())
      try {
        SensorManager.getSensorManager().createComponent(s);
      } catch (ConfigurationException e) {
      }
  }
Ejemplo n.º 15
0
  @Subscribe
  public synchronized void onEvent(SensorEvent event) {
    event = sensorEventTransformer.transform(event);

    double value = event.getValue();
    String sensorName = event.getSensorName();
    Sensor sensor = sensorManager.getSensorByName(sensorName);
    recentMeasurements.put(sensorName, value);

    Location location = getLocation();
    if (location != null && sensor != null && sensor.isEnabled()) {
      double latitude = location.getLatitude();
      double longitude = location.getLongitude();
      Measurement measurement =
          new Measurement(latitude, longitude, value, event.getMeasuredValue(), event.getDate());
      if (state.recording().isRecording()) {
        MeasurementStream stream = prepareStream(event);
        tracker.addMeasurement(stream, measurement);
      }
      eventBus.post(new MeasurementEvent(measurement, sensor));
    }
  }
Ejemplo n.º 16
0
  /**
   * Returns the protocol associated with a SensorID (assuming the sensor owner is already
   * associated with a protocol)
   *
   * @throws NotFoundException if the sensor can not be found
   * @throws SALRunTimeException if the sensoor isnt associated with any protocol, or the protocol
   *     object cant be found (shouldnt happen, but...)
   */
  AbstractProtocol getProtocol(SensorID sid) throws NotFoundException {
    AbstractProtocol p = null;
    String pName = null;
    Sensor s;

    if ((s = SensorManager.getSensorManager().getComponent(sid)) == null) {
      // logger.error("Cannot find the any sensor with this sensorID: " + sid.toString());
      throw new NotFoundException("No sensor with this sensorID");
    }
    if ((pName = s.getID().getPIDName()) == null) {
      logger.error("Cannot find the protocolID associated with this sensorID: " + sid.toString());
      throw new SALRunTimeException(
          "we shouldnt be here - sensor not associated with any protocol ??");
    }
    if ((p = getComponent(new ProtocolID(pName))) == null) {
      logger.error("Cannot find the protocol associated with this sensorID: " + sid.toString());
      throw new SALRunTimeException(
          "We shouldnt be here - cant find the protocol the sensor is associated with");
    }

    return p;
  }
Ejemplo n.º 17
0
  @Override
  protected void onResume() {
    super.onResume();
    activityRunning = true;
    countSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
    mAccelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    mMagnetometer = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);

    if (countSensor != null) {
      sensorManager.registerListener(this, countSensor, SensorManager.SENSOR_DELAY_UI);
    } else {
      Toast.makeText(this, "Count sensor not available!", Toast.LENGTH_LONG).show();
    }
    if (mAccelerometer != null) {
      sensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_UI);
    } else {
      Toast.makeText(this, "Accelerometer not available!", Toast.LENGTH_LONG).show();
    }
    if (mMagnetometer != null) {
      sensorManager.registerListener(this, mMagnetometer, SensorManager.SENSOR_DELAY_UI);
    } else {
      Toast.makeText(this, "Accelerometer not available!", Toast.LENGTH_LONG).show();
    }
  }
Ejemplo n.º 18
0
 public void stopListeningForUpdates() {
   sensorManager.unregisterListener(stepListener);
 }
Ejemplo n.º 19
0
 public void startListeningForUpdates() {
   Sensor accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
   sensorManager.registerListener(stepListener, accelerometer, SensorManager.SENSOR_DELAY_NORMAL);
 }
Ejemplo n.º 20
0
 protected void onPause() {
   super.onPause();
   mSensorManager.unregisterListener(this);
 }
Ejemplo n.º 21
0
 protected void onResume() {
   super.onResume();
   mSensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR);
 }
  public static void start(final Context applicationContext) {
    if (started) return;
    // SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(applicationContext);

    sensor_manager = (SensorManager) applicationContext.getSystemService(Context.SENSOR_SERVICE);
    sensor_event_listener =
        new SensorEventListener() {
          @Override
          public void onSensorChanged(SensorEvent event) {
            // SharedPreferences prefs = PreferenceManager.getSharedPreferences("GyroTester",
            // MODE_WORLD_READABLE);

            int type = event.sensor.getType();

            if (type == Sensor.TYPE_MAGNETIC_FIELD) {
              mag_reading = event.values.clone();

              if (isAppActive) {
                Intent i = new Intent("MAG_UPDATED");
                i.putExtra("x", Float.toString(mag_reading[0]));
                i.putExtra("y", Float.toString(mag_reading[1]));
                i.putExtra("z", Float.toString(mag_reading[2]));

                applicationContext.sendBroadcast(i);
              }
            }

            if (type == Sensor.TYPE_GYROSCOPE) {
              gyro_reading = event.values.clone();

              if (isAppActive) {
                Intent i = new Intent("GYRO_UPDATED");
                i.putExtra("x", Float.toString(gyro_reading[0]));
                i.putExtra("y", Float.toString(gyro_reading[1]));
                i.putExtra("z", Float.toString(gyro_reading[2]));

                applicationContext.sendBroadcast(i);
              }
            }

            if (type == Sensor.TYPE_ACCELEROMETER) {
              accel_reading = event.values.clone();

              if (isAppActive) {

                if (gravityFilter) {
                  Intent i = new Intent("ACCEL_UPDATED");
                  i.putExtra("x", Float.toString(accel_reading[0] - gravity_accel[0]));
                  i.putExtra("y", Float.toString(accel_reading[1] - gravity_accel[1]));
                  i.putExtra("z", Float.toString(accel_reading[2] - gravity_accel[2]));

                  //                            i.putExtra("x",  gravity_accel[0]);
                  //                            i.putExtra("y",  gravity_accel[1]);
                  //                            i.putExtra("z",  gravity_accel[2]);
                  applicationContext.sendBroadcast(i);
                } else {
                  Intent i = new Intent("ACCEL_UPDATED");
                  i.putExtra("x", Float.toString(accel_reading[0]));
                  i.putExtra("y", Float.toString(accel_reading[1]));
                  i.putExtra("z", Float.toString(accel_reading[2]));

                  applicationContext.sendBroadcast(i);
                }
              }
            }

            if (type == Sensor.TYPE_GRAVITY) {
              gravity_accel = event.values.clone();
            }

            if (loggingActive) {
              AddLogEntry(event.timestamp);
            }

            sensor_manager.getRotationMatrix(
                rotation_matrix, inclination_matrix, accel_reading, mag_reading);
            sensor_manager.getOrientation(rotation_matrix, attitude);

            attitude_in_degrees[0] = (int) Math.round(attitude[0] * RAD2DEG); // azimuth
            attitude_in_degrees[1] = (int) Math.round(attitude[1] * RAD2DEG); // pitch
            attitude_in_degrees[2] = (int) Math.round(attitude[2] * RAD2DEG); // roll
          }

          @Override
          public void onAccuracyChanged(Sensor sensor, int accuracy) {}
        };

    sensor_manager.registerListener(
        sensor_event_listener,
        sensor_manager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
        SensorManager.SENSOR_DELAY_UI);
    sensor_manager.registerListener(
        sensor_event_listener,
        sensor_manager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),
        SensorManager.SENSOR_DELAY_UI);
    sensor_manager.registerListener(
        sensor_event_listener,
        sensor_manager.getDefaultSensor(Sensor.TYPE_GRAVITY),
        SensorManager.SENSOR_DELAY_UI);
    sensor_manager.registerListener(
        sensor_event_listener,
        sensor_manager.getDefaultSensor(Sensor.TYPE_GYROSCOPE),
        SensorManager.SENSOR_DELAY_UI);

    started = true;
  }
 public static void stop() {
   if (started) {
     sensor_manager.unregisterListener(sensor_event_listener);
     started = false;
   }
 }
Ejemplo n.º 24
0
  @Override
  public boolean execute(String action, final JSONArray args, final CallbackContext callbackContext)
      throws JSONException {

    JSONObject returnObj = new JSONObject();

    if (action.equals("isSupported")) {

      addProperty(returnObj, "isSupported", isSupported);

    } else if (action.equals("initialize")) {

      if (args.length() > 0) {
        bioProfile = args.getJSONObject(0);
      }

      startService();

      settings = PreferenceManager.getDefaultSharedPreferences(cordova.getActivity());
      initialStepsCount = settings.getFloat("todayStepsCount", 0);
      initialStepsDate = new Date(settings.getLong("todayStepsDate", (new Date()).getTime()));

      sensorManager =
          (SensorManager) cordova.getActivity().getSystemService(Context.SENSOR_SERVICE);
      Sensor countSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
      if (countSensor != null) {
        sensorManager.registerListener(this, countSensor, SensorManager.SENSOR_DELAY_UI);
      } else {
        isSupported = false;
      }

    } else if (action.equals("getCurrentReading")) {

      int todaySteps = (int) (settings.getFloat("todayStepsCount", 0));
      int todayMeters = bioProfile == null ? 0 : bioProfile.getInt("stride") * todaySteps / 100;
      addProperty(returnObj, "todayWalkingSteps", todaySteps);
      addProperty(returnObj, "todayWalkingMinutes", 0);
      addProperty(returnObj, "todayWalkingMeters", todayMeters);
      addProperty(returnObj, "todayRunningSteps", 0);
      addProperty(returnObj, "todayRunningMinutes", 0);

      if (lastRunStart != null) {
        Date runFinish = lastRunFinish != null ? lastRunFinish : new Date();
        addProperty(returnObj, "lastRunSteps", (int) (stepsCount - lastRunStartSteps));
        addProperty(
            returnObj,
            "lastRunMinutes",
            (int) ((runFinish.getTime() / 60000) - (lastRunStart.getTime() / 60000)));
      } else {
        addProperty(returnObj, "lastRunSteps", 0);
        addProperty(returnObj, "lastRunMinutes", 0);
      }

    } else if (action.equals("start")) {

      lastRunStart = new Date();
      lastRunFinish = null;
      lastRunStartSteps = stepsCount;

      addProperty(returnObj, "isSuccessful", true);

    } else if (action.equals("stop")) {

      lastRunFinish = new Date();
      addProperty(returnObj, "isSuccessful", true);

    } else {

      addProperty(returnObj, "isSuccessful", true);
    }

    callbackContext.success(returnObj);
    return true;
  }
Ejemplo n.º 25
0
  public void onCreate() {
    int flags, screenLightVal = 1;
    Sensor mSensor;
    List<Sensor> sensors;

    if (scanData == null) return; // no ScanData, not possible to run correctly...

    PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
    SP = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    try {
      screenLightVal = Integer.parseInt(SP.getString("screenLight", "2"));
    } catch (NumberFormatException nfe) {
    }
    if (screenLightVal == 1) flags = PowerManager.PARTIAL_WAKE_LOCK;
    else if (screenLightVal == 3) flags = PowerManager.FULL_WAKE_LOCK;
    else flags = PowerManager.SCREEN_DIM_WAKE_LOCK;
    wl = pm.newWakeLock(flags, "OpenWLANMap");
    wl.acquire();
    while (myWLocate == null) {
      try {
        myWLocate = new MyWLocate(this);
        break;
      } catch (IllegalArgumentException iae) {
        myWLocate = null;
      }
      try {
        Thread.sleep(100);
      } catch (InterruptedException ie) {
      }
    }

    try {
      scanData.setUploadThres(Integer.parseInt(SP.getString("autoUpload", "0")));
    } catch (NumberFormatException nfe) {
    }
    try {
      scanData.setNoGPSExitInterval(
          Integer.parseInt(SP.getString("noGPSExitInterval", "0")) * 60 * 1000);
    } catch (NumberFormatException nfe) {
    }

    Intent intent = new Intent(this, OWMapAtAndroid.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendIntent = PendingIntent.getActivity(this, 0, intent, 0);

    notification =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.icon)
            .setContentTitle(getResources().getText(R.string.app_name))
            .setContentText("")
            .setContentIntent(pendIntent)
            .build();

    notification.flags |= Notification.FLAG_NO_CLEAR;
    notification.flags |= Notification.FLAG_ONGOING_EVENT;
    startForeground(1703, notification);

    getScanData().setService(this);
    getScanData().setmView(new HUDView(this));
    getScanData().getmView().setValue(getScanData().incStoredValues());
    WindowManager.LayoutParams params =
        new WindowManager.LayoutParams(
            WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
            WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
                | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
            PixelFormat.TRANSLUCENT);
    params.gravity = Gravity.LEFT | Gravity.BOTTOM;
    params.setTitle("Load Average");
    WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
    wm.addView(getScanData().getmView(), params);

    sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

    sensorManager.registerListener(
        this,
        sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
        SensorManager.SENSOR_DELAY_GAME);
    sensorManager.registerListener(
        this,
        sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION),
        SensorManager.SENSOR_DELAY_GAME);
    sensors = sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER);
    mSensor = sensors.get(0);
    getScanData().getTelemetryData().setAccelMax(mSensor.getMaximumRange());
    telemetryDir = Environment.getExternalStorageDirectory().getPath() + "/telemetry/";
    File dir = new File(telemetryDir);
    dir.mkdir();

    connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
  }