예제 #1
1
  void registerSensorListeners() {
    if (config.useAccelerometer) {
      manager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
      if (manager.getSensorList(Sensor.TYPE_ACCELEROMETER).size() == 0) {
        accelerometerAvailable = false;
      } else {
        Sensor accelerometer = manager.getSensorList(Sensor.TYPE_ACCELEROMETER).get(0);
        accelerometerListener =
            new SensorListener(
                this.nativeOrientation, this.accelerometerValues, this.magneticFieldValues);
        accelerometerAvailable =
            manager.registerListener(
                accelerometerListener, accelerometer, SensorManager.SENSOR_DELAY_GAME);
      }
    } else accelerometerAvailable = false;

    if (config.useCompass) {
      if (manager == null)
        manager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
      Sensor sensor = manager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
      if (sensor != null) {
        compassAvailable = accelerometerAvailable;
        if (compassAvailable) {
          compassListener =
              new SensorListener(
                  this.nativeOrientation, this.accelerometerValues, this.magneticFieldValues);
          compassAvailable =
              manager.registerListener(compassListener, sensor, SensorManager.SENSOR_DELAY_GAME);
        }
      } else {
        compassAvailable = false;
      }
    } else compassAvailable = false;
    Gdx.app.log("AndroidInput", "sensor listener setup");
  }
예제 #2
0
  public OrientationProvider(Context context) {

    sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
    accelSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    compassSensor = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
    //  gyroSensor = sensors.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
  }
예제 #3
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);
  }
예제 #4
0
  public CompassSensor(Context context, Handler handler) {
    mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
    accelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    magnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);

    this.handler = handler;
  }
예제 #5
0
  public void resume() {
    mSensorMgr = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
    if (mSensorMgr == null) {
      throw new UnsupportedOperationException("Sensors not supported");
    }
    mAccelerometer = mSensorMgr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    mProximity = mSensorMgr.getDefaultSensor(Sensor.TYPE_PROXIMITY);
    mLight = mSensorMgr.getDefaultSensor(Sensor.TYPE_LIGHT);

    // Check for accelerometer support
    boolean supported =
        mSensorMgr.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME);
    if (!supported) {
      Log.d("WakeService", "Accelerometer not supported.");
      mSensorMgr.unregisterListener(this, mAccelerometer);
    }

    // Check for proximity sensor support
    supported = mSensorMgr.registerListener(this, mProximity, SensorManager.SENSOR_DELAY_GAME);
    if (!supported) {
      Log.d("WakeService", "Proximity sensor not supported.");
      mSensorMgr.unregisterListener(this, mProximity);
    }

    // Check for ambient light sensor support
    supported = mSensorMgr.registerListener(this, mLight, SensorManager.SENSOR_DELAY_FASTEST);
    if (!supported) {
      Log.d("WakeService", "Ambient light sensor not supported.");
      mSensorMgr.unregisterListener(this, mLight);
    }
  }
예제 #6
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_dynamic_filter);
    resultImage = MessageService.image;

    imageView = (ImageView) findViewById(R.id.basicImage);
    imageView.setImageBitmap(resultImage);
    imageView.setOnTouchListener(this);

    // Shake detection
    shakeDetectionListener = new ShakeDetectionListener(this);
    sensorMgr = (SensorManager) getSystemService(SENSOR_SERVICE);
    sensorMgr.registerListener(
        shakeDetectionListener,
        sensorMgr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
        SensorManager.SENSOR_DELAY_NORMAL);

    // Gyroscope detection
    movementDetectionListener = new MovementDetectionListener(this);
    sensorMgr.registerListener(
        movementDetectionListener,
        sensorMgr.getDefaultSensor(Sensor.TYPE_GAME_ROTATION_VECTOR),
        SensorManager.SENSOR_DELAY_NORMAL);

    // Register filter
    filters.add(new ColorFilter());
    filters.add(new GridFilter());
    filters.add(new LightFilter());
    filters.add(new MozFilter());
    filters.add(new BlackAndWhiteFilter());
    filters.add(new InvertFilter());
    filters.add(new BinaryFilter());
    // moved(0, 0, 0);
  }
예제 #7
0
  public void onCreate() {
    super.onCreate();
    intent = new Intent(BROADCAST_ACTION);

    // startup code
    // Barometer Setup
    try {
      sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
      if (sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) != null)
        accelSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
      else throw new Exception("Sensor not available");

      sensorManager.registerListener(this, accelSensor, SensorManager.SENSOR_DELAY_NORMAL);

      x = y = z = 0;

      /** Broadcast Stuff * */
      Toast.makeText(this, "Accel Service Started", Toast.LENGTH_SHORT).show();

      handler.removeCallbacks(sendUpdatesToUI);
      handler.postDelayed(sendUpdatesToUI, 1000); // 1 second
    } catch (Exception e) {
      Log.e(TAG, "Unable to start barometer", e);
      Toast.makeText(this, "Unable to start barometer: " + e.toString(), Toast.LENGTH_LONG).show();
    }
  }
예제 #8
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setAmbientEnabled();

    mContainerView = (BoxInsetLayout) findViewById(R.id.container);
    mImageView = (ImageView) findViewById(R.id.imageView);

    gestureDetector = new GestureDetector(getApplicationContext(), new GameGestureListener());

    mImageView.setOnTouchListener(
        new View.OnTouchListener() {

          @Override
          public boolean onTouch(View v, MotionEvent event) {
            return gestureDetector.onTouchEvent(event);
          }
        });

    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mGyroSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
    mHeartSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE);

    mGoogleApiClient =
        new GoogleApiClient.Builder(this)
            .addApi(Wearable.API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();

    // up vector cal
    mHeadTracker = HeadTracker.createFromContext(getApplicationContext());
    headView = new float[16];
  }
예제 #9
0
  public MyLocationDirectionOverlay(Context context, MapView mapView) {
    super(context);
    // this.context = context;
    this.mapView = mapView;
    // Captor
    sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
    locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    // get compass sensor (ie magnetic field)
    gsensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    msensor = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
    osensor = sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);

    // Conf Dir
    paintDirection = new Paint();
    paintDirection.setColor(Color.RED);
    paintDirection.setAntiAlias(true);
    paintDirection.setStrokeWidth(5);
    paintDirection.setTextSize(20);
    // Paint Position
    paintPosAccuracy = new Paint();
    paintPosAccuracy.setColor(Color.RED);
    paintPosAccuracy.setAntiAlias(true);
    paintPosAccuracy.setAlpha(50);
    // Accuracy
    paintPos = new Paint();
    paintPos.setColor(Color.RED);
    paintPos.setAntiAlias(true);
  }
예제 #10
0
  public void getSensors() {
    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);

    mMagneticFieldSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
    mGyroscopeSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
    mAccelerometerSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
  }
예제 #11
0
  public void onClick(View v) {
    switch (v.getId()) {
      case R.id.calibration_button:
        calButton.setEnabled(false);

        if (SensorCalibration.PSH_SUPPORT) {
          calSensor = sensorManager.getDefaultSensor(110);
          sensorManager.registerListener(this, calSensor, 10000);
        } else {
          FileWriter fw = null;
          try {
            fw = new FileWriter("/data/gyro.conf");
            String s = "0 0 0\n";
            fw.write(s);
            fw.flush();
          } catch (IOException e) {
            e.printStackTrace();
          }

          try {
            if (fw != null) fw.close();
          } catch (IOException e) {
            e.printStackTrace();
          }

          gyroSensor = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
          sensorManager.registerListener(this, gyroSensor, SensorManager.SENSOR_DELAY_GAME);
        }

        inCalibration = true;
        break;
    }
  }
예제 #12
0
 @Override
 protected void onStop() {
   super.onStop();
   sensorManager.unregisterListener(
       this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER));
   sensorManager.unregisterListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION));
 }
예제 #13
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));
   }
 }
  public void startDeadReckoningService() {

    sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    Sensor acceleromererSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    Sensor orientationSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
    sensorManager.registerListener(accelerometerListener, acceleromererSensor, 10000);
    sensorManager.registerListener(
        orientationListener, orientationSensor, SensorManager.SENSOR_DELAY_FASTEST);
    System.out.println("deadReckoningService started");
  }
예제 #15
0
 protected void onResume() {
   // Ideally a game should implement onResume() and onPause()
   // to take appropriate action when the activity looses focus
   super.onResume();
   getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
   Sensor gsensor = sensors.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
   Sensor msensor = sensors.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
   sensors.registerListener(this, gsensor, SensorManager.SENSOR_DELAY_GAME);
   sensors.registerListener(this, msensor, SensorManager.SENSOR_DELAY_GAME);
 }
예제 #16
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    TextView tv = (TextView) findViewById(R.id.label1);
    tv.setText("Lab 1: Sensors\n");

    TextView Title1 = (TextView) findViewById(R.id.label2);
    Title1.setText("Accelerometer\n");

    TextView Title2 = (TextView) findViewById(R.id.label3);
    Title2.setText("Linear Acceleration\n");

    LinearLayout l1 = (LinearLayout) findViewById(R.id.layout);
    l1.setOrientation(LinearLayout.VERTICAL);

    TextView tv1 = new TextView(getApplicationContext());
    l1.addView(tv1);

    TextView list1 = (TextView) findViewById(R.id.label4);
    list1.setText("Max Values\n");

    TextView tv2 = new TextView(getApplicationContext());
    l1.addView(tv2);

    TextView tv3 = new TextView(getApplicationContext());
    l1.addView(tv3);
    tv3.setText("Counts\n");

    // Button b1 = (Button) findViewById(R.id.button1);
    Button b2 = (Button) findViewById(R.id.button2);

    SensorManager sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

    LineGraphView graph;

    graph = new LineGraphView(getApplicationContext(), 100, Arrays.asList("x", "y", "z"));
    l1.addView(graph);
    graph.setVisibility(View.VISIBLE);

    Sensor accelerometerSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION);
    a = new AccelerometerSensorEventListener(tv1, tv3, graph);
    sensorManager.registerListener(a, accelerometerSensor, SensorManager.SENSOR_DELAY_FASTEST);

    Sensor orienSensor = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
    sensorManager.registerListener(a, orienSensor, SensorManager.SENSOR_DELAY_FASTEST);
    //		MapView mv = new MapView ( getApplicationContext () , 400 , 400 , 60 , 60);
    //		// In your Activity ’ s onCreate () method :
    //		registerForContextMenu ( mv );
    //		NavigationalMap map = MapLoader . loadMap ( getExternalFilesDir ( null ) ,
    //				" Lab - room - peninsula . svg ");
    //				mapView . setMap ( map );

  }
예제 #17
0
 public SensorsWrapper(Activity activity) {
   super(TOPIC);
   sensorManager = (SensorManager) activity.getSystemService(Context.SENSOR_SERVICE);
   rotationSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR);
   pressureSensor = sensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE);
   try {
     register(false);
   } catch (ProducerAlreadyRegisteredException e) {
     e.printStackTrace();
   }
 }
예제 #18
0
 @Override
 protected void onResume() {
   super.onResume();
   sensorManager.registerListener(
       this,
       sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
       sensorManager.SENSOR_DELAY_GAME);
   sensorManager.registerListener(
       this,
       sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION),
       sensorManager.SENSOR_DELAY_GAME);
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);
    mNavigationDrawerFragment =
        (NavigationDrawerFragment)
            getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
    mTitle = getTitle();

    // Set up the drawer.
    mNavigationDrawerFragment.setUp(
        R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout));

    FragmentManager fragmentManager = getFragmentManager();
    // GlobalFeedFragment feedFragment = new GlobalFeedFragment();
    // fragmentManager.beginTransaction().replace(R.id.container, feedFragment).commit();

    mStepValue = 0;
    mPaceValue = 0;

    startService(new Intent(this, Time.class));
    Log.i(TAG, "Started service");

    try {
      if (!mIsRunning) {
        p1_button.setText("Start ►");
        // p1_button.setBackgroundResource(R.drawable.resume);
      } else if (mIsRunning) {
        p1_button.setText("Stop ◼");
        // p1_button.setBackgroundResource(R.drawable.pause);

      }
    } catch (NullPointerException e) {

    }

    mPedometerUtils = PedometerUtils.getInstance();

    RebootSteps = (TextView) findViewById(R.id.time);
    RS = (TextView) findViewById(R.id.textView8);

    PackageManager m = getPackageManager();
    if (!m.hasSystemFeature(PackageManager.FEATURE_SENSOR_STEP_COUNTER)) {
      RS.setVisibility(View.INVISIBLE);
      RebootSteps.setVisibility(View.INVISIBLE);
    }

    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mStepCounterSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
    mStepDetectorSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR);
  }
예제 #20
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    view1 = (TextView) findViewById(R.id.textView1);
    view2 = (TextView) findViewById(R.id.textView2);
    sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
    accelerometerGrav = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    accelerometerNoGrav = sensorManager.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION);
    sensorManager.registerListener(this, accelerometerGrav, SensorManager.SENSOR_DELAY_NORMAL);
    sensorManager.registerListener(this, accelerometerNoGrav, SensorManager.SENSOR_DELAY_NORMAL);
  }
  @Override
  protected void onResume() {
    super.onResume();

    Sensor accelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    Sensor magnetic = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);

    mSensorManager.registerListener(
        mSensorEventListener2, accelerometer, SensorManager.SENSOR_DELAY_GAME);

    mSensorManager.registerListener(
        mSensorEventListener2, magnetic, SensorManager.SENSOR_DELAY_GAME);
  }
예제 #22
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    /**
     * This method bring the user to the next screen.
     *
     * <p>show the usage of various javadoc Tags.
     *
     * @param view
     * @return Nothing
     */
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_radialulnardeviation);

    Intent intentRadialUlnarDeviation = getIntent();

    // Keep the screen on
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    // Grab the layout TextView
    tv = (TextView) findViewById(R.id.tv_tilt);

    // Setup the sensors
    sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    if (accelerometer == null) {
      Log.d(TAG, "accelerometer is null");
    }
    magnetometer = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
    if (magnetometer == null) {
      Log.d(TAG, "magnetometer is null");
    }

    // Detect the window position
    switch (getWindowManager().getDefaultDisplay().getRotation()) {
      case Surface.ROTATION_0:
        Log.d(TAG, "Rotation 0");
        break;
      case Surface.ROTATION_90:
        Log.d(TAG, "Rotation 90");
        break;
      case Surface.ROTATION_180:
        Log.d(TAG, "Rotation 180");
        break;
      case Surface.ROTATION_270:
        Log.d(TAG, "Rotation 270");
        break;
      default:
        Log.w(TAG, "Rotation unknown");
        break;
    }
  }
예제 #23
0
  public SREnviron(Activity activity) {
    mSensorManager = (SensorManager) activity.getSystemService(SENSOR_SERVICE);
    mAmbTemp = mSensorManager.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE);
    mLight = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
    mPressure = mSensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE);
    mHumidity = mSensorManager.getDefaultSensor(Sensor.TYPE_RELATIVE_HUMIDITY);

    mSensorManager.registerListener(this, mAmbTemp, SensorManager.SENSOR_DELAY_GAME);
    mSensorManager.registerListener(this, mLight, SensorManager.SENSOR_DELAY_GAME);
    if (SRCfg.doPressureMonitoring) {
      mSensorManager.registerListener(this, mPressure, SensorManager.SENSOR_DELAY_GAME);
    }
    mSensorManager.registerListener(this, mHumidity, SensorManager.SENSOR_DELAY_GAME);
  }
예제 #24
0
  @Override
  public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    switch (buttonView.getId()) {
      case R.id.scan_toggle_button:
        if (isChecked) {
          buttonView.setChecked(true);
          buttonView.setBackgroundColor(Color.parseColor("#FF0505")); // red

          mSensorManager.registerListener(
              this,
              mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
              SensorManager.SENSOR_DELAY_FASTEST);
          mSensorManager.registerListener(
              this,
              mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE),
              SensorManager.SENSOR_DELAY_FASTEST);
          mSensorManager.registerListener(
              this,
              mSensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY),
              SensorManager.SENSOR_DELAY_FASTEST);
          mSensorManager.registerListener(
              this,
              mSensorManager.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION),
              SensorManager.SENSOR_DELAY_FASTEST);
          mSensorManager.registerListener(
              this,
              mSensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR),
              SensorManager.SENSOR_DELAY_FASTEST);
          mSensorManager.registerListener(
              this,
              mSensorManager.getDefaultSensor(Sensor.TYPE_GAME_ROTATION_VECTOR),
              SensorManager.SENSOR_DELAY_FASTEST);
          mSensorManager.registerListener(
              this,
              mSensorManager.getDefaultSensor(Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR),
              SensorManager.SENSOR_DELAY_FASTEST);
          mSensorManager.registerListener(
              this,
              mSensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE),
              SensorManager.SENSOR_DELAY_FASTEST);

        } else {
          buttonView.setChecked(false);
          buttonView.setBackgroundColor(Color.parseColor("#259C25")); // greed

          mSensorManager.unregisterListener(this);

          //                    Serialization.serExternalData(Serialization.DATA_FILE, sensorData);

          if (!isRestarted) {
            showInputDialog();
            isRestarted = false;
          }
        }
        break;
      default:
        Log.e("Error", "Toggle Button not found!");
    }
  }
  @Override
  protected void onResume() {

    int i = 0;
    if (i == 0) {
      Sensor sensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
      sensorManager.registerListener(listener, sensor, SensorManager.SENSOR_DELAY_NORMAL);
    } else {

      Sensor sensor1 = sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
      sensorManager.registerListener(listener, sensor1, SensorManager.SENSOR_DELAY_NORMAL);
    }

    super.onResume();
  }
예제 #26
0
  public void start(final BearingsListener bl) {
    handler.removeCallbacksAndMessages(null);

    if (sensorManager == null) return;

    bearingsListener = bl;
    sensorManager.registerListener(
        sensorEventListener,
        sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
        (int) (1 * 1e6));
    sensorManager.registerListener(
        sensorEventListener,
        sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),
        (int) (1 * 1e6));
  }
  /** @param savedInstanceState */
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    /**
     * Se llama en la creación de la actividad Llamada a las funciones que vienen implementadas
     * dentro de la clase SensorManager Permite la obtencion de los distintos valores del sensor
     */
    super.onCreate(savedInstanceState);
    setContentView(R.layout.content_podometro);
    textView = (TextView) findViewById(R.id.texto);
    texto = (TextView) findViewById(R.id.noSensor);

    sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mStepCounterSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
    mStepDetectorSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR);
  }
예제 #28
0
 public void onDestroy() {
   Log.d(TAG, "onDestroy() - Stopping Service");
   try {
     sManager.unregisterListener(
         eventListener, sManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER));
     sManager.unregisterListener(eventListener, sManager.getDefaultSensor(Sensor.TYPE_LIGHT));
     if (isFileOpen) {
       closeBufferedWriter(dataStream);
       isFileOpen = false;
     }
     isServiceInitialized = false;
   } catch (Exception e) {
     Log.e(TAG, "Failed unregistering llisteners");
   }
 }
예제 #29
0
  /**
   * Initiate the Caster Activity, load the sounds up, set up touch listener, vibrator, sensor
   * manager, and accelerometer sensor
   *
   * @param savedInstanceState
   */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    setContentView(R.layout.caster);

    castDistance = 0;

    casterBackground = (ImageView) findViewById(R.id.caster_background);
    casterBackground.setOnTouchListener(this);

    audioTask = new AudioTask();

    soundManager = SoundManager.getInstance();

    // TODO: background animation once we get the assets.
    vibrotron = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
    sensorManager =
        (SensorManager) getApplicationContext().getSystemService(Context.SENSOR_SERVICE);
    accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
  }
예제 #30
0
  /**
   * initializing viewport set window properties (width, height, fullscreen, orientation based on
   * config) initialize touch listener if config.sensor initialize sound if config.sound initialize
   * music if config.music
   *
   * @param state
   */
  public void create(Bundle state) {
    super.onCreate(state);
    restore(getIntent().getExtras());
    if (config.fullscreen) {
      requestWindowFeature(Window.FEATURE_NO_TITLE);
      getWindow()
          .setFlags(
              WindowManager.LayoutParams.FLAG_FULLSCREEN,
              WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }
    if (config.orientation == Config.LANDSCAPE) {
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    } else {
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
    view = new GLSurfaceView(this);
    view.setRenderer(this);
    setContentView(view);
    view.setOnTouchListener(this);
    this.resources = getResources();
    this.screen = new Size(config.width, config.height);
    // this.strech = config.strech;

    if (config.sound) {
      sound = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
      // volume = (AudioManager) getSystemService (AUDIO_SERVICE);
    }
    if (config.sensor) {
      sensor = (SensorManager) getSystemService(SENSOR_SERVICE);
      accelerometer = sensor.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    }
  }