Esempio n. 1
0
  private synchronized void startListening() {
    Log.d(TAG, "startListening called");

    convWorker = new ConversionWorker();

    if (state == null) {
      state = new RobotStateHandler(handler);
      state.start();
      while (state.handler == null) {
        try {
          Thread.sleep(10);
        } catch (InterruptedException e) {
        }
      }
    }

    if (sensorListener == null) {
      sensorListener = new SensorListenerImpl(state.handler, wifiManager);
    }

    SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
    RobotStateHandler.ROBOT_ID = settings.getString("ROBOT_ID", RobotStateHandler.ROBOT_ID);

    // Toast.makeText(CONTEXT, "Current IP:" + state.getLocalIpAddress(),
    // Toast.LENGTH_LONG);
    // ProgressDialog.show(me, msg,
    // "Searching for a Bluetooth serial port...");

    ProgressDialog btDialog = null;

    String connectivity_context = Context.WIFI_SERVICE;
    WifiManager wifi = (WifiManager) getSystemService(connectivity_context);

    this.registerReceiver(
        sensorListener.mBatInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

    this.registerReceiver(
        sensorListener.mWifiInfoReceiver, new IntentFilter(WifiManager.RSSI_CHANGED_ACTION));

    if (OrientationManager.isSupported()) {
      OrientationManager.startListening(sensorListener);
    }

    if (LightSensorManager.isSupported()) {
      LightSensorManager.startListening(sensorListener);
    }

    if (CompassManager.isSupported()) {
      CompassManager.startListening(sensorListener);
    }
  }
Esempio n. 2
0
  private synchronized void stopListening() {

    Log.d(TAG, "stopListening called");

    convWorker.kill();

    try {
      this.unregisterReceiver(sensorListener.mBatInfoReceiver);
    } catch (Exception e) {
    }

    try {
      this.unregisterReceiver(sensorListener.mWifiInfoReceiver);
    } catch (Exception e) {
    }

    OrientationManager.stopListening();
    LightSensorManager.stopListening();
    CompassManager.stopListening();

    // if (state.isAlive())
    // {
    // state.stopListening();
    // }

  }