android.hardware.SensorManager Java Examples

The following examples show how to use android.hardware.SensorManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GyroHelper.java    From libcommon with Apache License 2.0 7 votes vote down vote up
private void getOrientation(final float[] rotateMatrix, final float[] result) {

			switch (mRotation) {
			case Surface.ROTATION_0:
				SensorManager.getOrientation(rotateMatrix, result);
				return;
			case Surface.ROTATION_90:
				SensorManager.remapCoordinateSystem(
					rotateMatrix, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, outR);
				break;
			case Surface.ROTATION_180:
				SensorManager.remapCoordinateSystem(
					rotateMatrix, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, outR2);
				SensorManager.remapCoordinateSystem(
					outR2, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, outR);
				break;
			case Surface.ROTATION_270:
				SensorManager.remapCoordinateSystem(
					outR, SensorManager.AXIS_MINUS_Y, SensorManager.AXIS_MINUS_X, outR);
				break;
			}
			SensorManager.getOrientation(outR, result);
		}
 
Example #2
Source File: ProximitySensor.java    From AcDisplay with GNU General Public License v2.0 7 votes vote down vote up
@Override
public void onStart(@NonNull SensorManager sensorManager) {
    if (DEBUG) Log.d(TAG, "Starting proximity sensor...");

    mHistory.clear();
    mHistory.add(new Event(false, getTimeNow()));

    Config.getInstance().registerListener(this);
    updateWave2WakeProgram();

    // Ignore pocket program's start delay,
    // so app can act just after it has started.
    mFirstChange = true;
    mPocketProgram.dataArray[0].timeMin = 0;

    Sensor proximitySensor = sensorManager.getDefaultSensor(getType());
    sensorManager.registerListener(this, proximitySensor, SensorManager.SENSOR_DELAY_NORMAL);

    mMaximumRange = proximitySensor.getMaximumRange();
    sAttached = true;
}
 
Example #3
Source File: SensorChange.java    From VirtualSensor with GNU Lesser General Public License v3.0 7 votes vote down vote up
private float[] getGyroscopeValues(float timeDifference) {
    float[] angularRates = new float[] {0.0F, 0.0F, 0.0F};
    float[] rotationMatrix = new float[9];
    float[] gravityRot = new float[3];
    float[] angleChange = new float[3];

    SensorManager.getRotationMatrix(rotationMatrix, null, this.accelerometerValues, this.magneticValues);
    gravityRot[0] = GRAVITY[0] * rotationMatrix[0] + GRAVITY[1] * rotationMatrix[3] + GRAVITY[2] * rotationMatrix[6];
    gravityRot[1] = GRAVITY[0] * rotationMatrix[1] + GRAVITY[1] * rotationMatrix[4] + GRAVITY[2] * rotationMatrix[7];
    gravityRot[2] = GRAVITY[0] * rotationMatrix[2] + GRAVITY[1] * rotationMatrix[5] + GRAVITY[2] * rotationMatrix[8];
    SensorManager.getRotationMatrix(rotationMatrix, null, gravityRot, this.magneticValues);

    SensorManager.getAngleChange(angleChange, rotationMatrix, this.prevRotationMatrix);
    angularRates[0] = -(angleChange[1]) / timeDifference;
    angularRates[1] = (angleChange[2]) / timeDifference;
    angularRates[2] = (angleChange[0]) / timeDifference;

    this.prevRotationMatrix = rotationMatrix;
    return angularRates;
}
 
Example #4
Source File: AndroidSensor.java    From ssj with GNU General Public License v3.0 7 votes vote down vote up
/**
*
   */
  @Override
  protected boolean connect() throws SSJFatalException
  {
      manager = (SensorManager) SSJApplication.getAppContext().getSystemService(Context.SENSOR_SERVICE);

      boolean ok = true;
      for(SensorListener l : listeners)
      {
          Sensor s = manager.getDefaultSensor(l.getType().getType());
          if (s == null)
          {
              Log.e(l.getType().getName() + " not found on device");
              ok = false;
          }
          else
          {
              ok &= manager.registerListener(l, s, options.sensorDelay.get());
          }
      }

      return ok;
  }
 
Example #5
Source File: AlternativeAccelHandler.java    From Alite with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onSensorChanged(SensorEvent event) {
	if (!getUpdates) {
		SensorManager manager = (SensorManager) game.getSystemService(Context.SENSOR_SERVICE);
		if (manager.getSensorList(Sensor.TYPE_ACCELEROMETER).size() > 0) {
			manager.unregisterListener(this);
		}			
		return;
	}
	switch (event.sensor.getType()) {
		case Sensor.TYPE_ACCELEROMETER:
			for (int i = 0; i < 3; i++) {
				accelValues[i] = event.values[i];
			}
			break;
	}

	float roll  = (float) Math.atan2(accelValues[0], accelValues[2]);
	float pitch = (float) Math.atan2(accelValues[1], accelValues[2]);

	accelValues[2] = -roll;
	accelValues[1] = -pitch;
	accelValues[0] = 0;
	adjustAccelOrientation(accelValues);
}
 
Example #6
Source File: AccelerometerCompassProvider.java    From tilt-game-android with MIT License 6 votes vote down vote up
@Override
public void onSensorChanged(SensorEvent event) {

    // we received a sensor event. it is a good practice to check
    // that we received the proper event
    if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
        magnitudeValues = event.values.clone();
    } else if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        accelerometerValues = event.values.clone();
    }

    if (magnitudeValues != null && accelerometerValues != null) {
        float[] i = new float[16];

        // Fuse accelerometer with compass
        SensorManager.getRotationMatrix(currentOrientationRotationMatrix.matrix, i, accelerometerValues,
                magnitudeValues);
        // Transform rotation matrix to quaternion
        currentOrientationQuaternion.setRowMajor(currentOrientationRotationMatrix.matrix);
    }
}
 
Example #7
Source File: ReadingDetailsActivity.java    From Leisure with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Language
    mLang = Utils.getCurrentLanguage();
    if (mLang > -1) {
        Utils.changeLanguage(this, mLang);
    }


    //set Theme
    if(Settings.isNightMode){
        this.setTheme(R.style.NightTheme);
    }else{
        this.setTheme(R.style.DayTheme);
    }

    setContentView(R.layout.activity_reading_details);
    initData();

    mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

}
 
Example #8
Source File: ShakeDetectEventListener.java    From android-wear-gopro-remote with Apache License 2.0 6 votes vote down vote up
@Override
public void onSensorChanged(SensorEvent event) {
    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {

        long curTime = System.currentTimeMillis();
        // if a shake in last X seconds ignore.
        if (lastShake != 0 && (curTime - lastShake) < IGNORE_EVENTS_AFTER_SHAKE) return;

        float x = event.values[SensorManager.DATA_X];
        float y = event.values[SensorManager.DATA_Y];
        float z = event.values[SensorManager.DATA_Z];
        if (last_x != 0 && last_y != 0 && last_z != 0 && (last_x != x || last_y != y || last_z != z)) {
            DataPoint dp = new DataPoint(last_x-x, last_y-y, last_z-z, curTime);
            //Log.i("XYZ",Float.toString(dp.x)+"   "+Float.toString(dp.y)+"   "+Float.toString(dp.z)+"   ");
            dataPoints.add(dp);

            if ((curTime - lastUpdate) > SHAKE_CHECK_THRESHOLD) {
                lastUpdate = curTime;
                checkForShake();
            }
        }
        last_x = x;
        last_y = y;
        last_z = z;
    }
}
 
Example #9
Source File: DataManager.java    From ibm-wearables-android-sdk with Apache License 2.0 6 votes vote down vote up
/**
 * register the default sensor of specific type
 * @param type sensor id
 */
private void registerSensor(int type){
    Sensor defaultSensor = sensorManager.getDefaultSensor(type);

    //set normalization factor
    if (type == Sensor.TYPE_ACCELEROMETER){
        gestureDataHolder.allowSensorDataCollection(type);

        //normalize to range form -2 to 2
        gestureDataHolder.setNormalizationFactor(type, 2 / defaultSensor.getMaximumRange());
    }

    if (type == Sensor.TYPE_GYROSCOPE){
        gestureDataHolder.allowSensorDataCollection(type);

        //from rad to deg
        gestureDataHolder.setNormalizationFactor(type, 57.2958);
    }

    sensorManager.registerListener(this, defaultSensor, SensorManager.SENSOR_DELAY_GAME);
    //sensorManager.registerListener(this, defaultSensor, SensorManager.SENSOR_DELAY_FASTEST);
}
 
Example #10
Source File: StreamActivity.java    From Pocket-Plays-for-Twitch with GNU General Public License v3.0 6 votes vote down vote up
protected void update(float[] vectors) {
	int worldAxisX = SensorManager.AXIS_X;
	int worldAxisZ = SensorManager.AXIS_Z;

	float[] rotationMatrix = new float[9];
	float[] adjustedRotationMatrix = new float[9];
	float[] orientation = new float[3];

	SensorManager.getRotationMatrixFromVector(rotationMatrix, vectors);
	SensorManager.remapCoordinateSystem(rotationMatrix, worldAxisX, worldAxisZ, adjustedRotationMatrix);
	SensorManager.getOrientation(adjustedRotationMatrix, orientation);

	float roll = orientation[2] * FROM_RADS_TO_DEGS;

	if (roll > -45 && roll < 45) {
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
		Log.d(LOG_TAG, "Requesting undefined");
	}
	Log.d(LOG_TAG, "Roll: " + roll);
}
 
Example #11
Source File: SensorsDataAPI.java    From sa-sdk-android with Apache License 2.0 6 votes vote down vote up
@Override
public void enableTrackScreenOrientation(boolean enable) {
    try {
        if (enable) {
            if (mOrientationDetector == null) {
                mOrientationDetector = new SensorsDataScreenOrientationDetector(mContext, SensorManager.SENSOR_DELAY_NORMAL);
            }
            mOrientationDetector.enable();
        } else {
            if (mOrientationDetector != null) {
                mOrientationDetector.disable();
                mOrientationDetector = null;
            }
        }
    } catch (Exception e) {
        com.sensorsdata.analytics.android.sdk.SALog.printStackTrace(e);
    }
}
 
Example #12
Source File: Engine.java    From tilt-game-android with MIT License 6 votes vote down vote up
/**
 * @return <code>true</code> when the sensor was successfully enabled, <code>false</code> otherwise.
 */
public boolean enableAccelerationSensor(final Context pContext, final IAccelerationListener pAccelerationListener, final AccelerationSensorOptions pAccelerationSensorOptions) {
	final SensorManager sensorManager = (SensorManager) pContext.getSystemService(Context.SENSOR_SERVICE);
	if (this.isSensorSupported(sensorManager, Sensor.TYPE_ACCELEROMETER)) {
		this.mAccelerationListener = pAccelerationListener;

		this.initDefaultDisplay(pContext);

		if (this.mAccelerationData == null) {
			this.mAccelerationData = new AccelerationData();
		}

		this.registerSelfAsSensorListener(sensorManager, Sensor.TYPE_ACCELEROMETER, pAccelerationSensorOptions.getSensorDelay());

		return true;
	} else {
		return false;
	}
}
 
Example #13
Source File: MainActivity.java    From Android-Example with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ProximitySensor = (TextView)findViewById(R.id.proximitySensor);
    ProximityMax = (TextView)findViewById(R.id.proximityMax);
    ProximityReading = (TextView)findViewById(R.id.proximityReading);
    // Now in the SensorActivity we access the device sensor using SensorManager, an instance of this class is got by calling getSystemService(SENSOR_SERVICE) . We implement the class with theSensorEventListener interface to override its methods to do actions on sensor value change.
    mySensorManager = (SensorManager)getSystemService(
      Context.SENSOR_SERVICE);
    myProximitySensor = mySensorManager.getDefaultSensor(
      Sensor.TYPE_PROXIMITY);
    
    if (myProximitySensor == null){
     ProximitySensor.setText("No Proximity Sensor!"); 
    }else{
     ProximitySensor.setText(myProximitySensor.getName());
     ProximityMax.setText("Maximum Range: "
       + String.valueOf(myProximitySensor.getMaximumRange()));
     mySensorManager.registerListener(proximitySensorEventListener,
       myProximitySensor,
       SensorManager.SENSOR_DELAY_NORMAL);
    }
}
 
Example #14
Source File: SensorUtil.java    From Sensor-Disabler with MIT License 6 votes vote down vote up
public static Sensor getSensorFromUniqueSensorKey(Context context, String key) {
    String[] data = key.split(Pattern.quote(SENSOR_SEPARATOR)); //Regex, man. Regex.
    if (data.length >= 4) {
        try {
            String name = data[0];
            String vendor = data[1];
            int version = Integer.parseInt(data[2]);
            int type = Integer.parseInt(data[3]);
            SensorManager manager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
            for (Sensor sensor : manager.getSensorList(type)) {
                if (sensor.getName().equals(name)
                        && sensor.getVendor().equals(vendor)
                        && sensor.getVersion() == version) {
                    return sensor;
                }
            }
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException("Unable to get unique sensor from key.");
        }
    } else {
        Log.e("SensorUtil", "Unable to parse \"" + key + "\" as Sensor data.");
    }
    return null;
}
 
Example #15
Source File: AmbientLightManager.java    From ProjectX with Apache License 2.0 6 votes vote down vote up
private void setTorch() {
    switch (mMode) {
        case MODE_AUTO:
            if (sensorManager != null) {
                sensorManager.registerListener(this,
                        sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT),
                        SensorManager.SENSOR_DELAY_NORMAL);
            }
            break;
        case MODE_OPEN:
            if (sensorManager != null) {
                sensorManager.unregisterListener(this);
            }
            if (mCallBack != null)
                mCallBack.onChange(true);
            break;
        case MODE_CLOSE:
            if (sensorManager != null) {
                sensorManager.unregisterListener(this);
            }
            if (mCallBack != null)
                mCallBack.onChange(false);
            break;
    }
}
 
Example #16
Source File: AeyriumSensorPlugin.java    From aeyrium-sensor with MIT License 6 votes vote down vote up
SensorEventListener createSensorEventListener(final EventChannel.EventSink events) {
  return new SensorEventListener() {
    @Override
    public void onAccuracyChanged(Sensor sensor, int accuracy) {
      if (mLastAccuracy != accuracy) {
        mLastAccuracy = accuracy;
      }
    }

    @Override
    public void onSensorChanged(SensorEvent event) {
      if (mLastAccuracy == SensorManager.SENSOR_STATUS_UNRELIABLE) {
        return;
      }

      updateOrientation(event.values, events);
    }
  };
}
 
Example #17
Source File: CompassActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_compass);
  mCompassView = findViewById(R.id.compassView);

  mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
  WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);

  Display display = wm.getDefaultDisplay();
  mScreenRotation = display.getRotation();

  mNewestValues = new float[] {0, 0, 0};

  Timer updateTimer = new Timer("compassUpdate");
  updateTimer.scheduleAtFixedRate(new TimerTask() {
    public void run() {
      updateGUI();
    }
  }, 0, 1000/60);
}
 
Example #18
Source File: SensorFilteredValuesActivity.java    From coursera-android with MIT License 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    mXValueView = findViewById(R.id.x_value_view);
    mYValueView = findViewById(R.id.y_value_view);
    mZValueView = findViewById(R.id.z_value_view);

    mXGravityView = findViewById(R.id.x_lowpass_view);
    mYGravityView = findViewById(R.id.y_lowpass_view);
    mZGravityView = findViewById(R.id.z_lowpass_view);

    mXAccelView = findViewById(R.id.x_highpass_view);
    mYAccelView = findViewById(R.id.y_highpass_view);
    mZAccelView = findViewById(R.id.z_highpass_view);

    // Get reference to SensorManager
    mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

    if (null != mSensorManager) {
        // Get reference to Accelerometer
        mAccelerometer = mSensorManager
                .getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
        if (null == mAccelerometer) finish();

        mLastUpdate = System.currentTimeMillis();
    }
}
 
Example #19
Source File: ViewCrawler.java    From ans-android-sdk with GNU General Public License v3.0 5 votes vote down vote up
private void uninstallConnectionSensor() {
    if (mIsSensorRegistered && CommonUtils.isMainProcess(mContext) && VisualAgent.isInDebug()) {
        final SensorManager sensorManager = (SensorManager) mContext.getSystemService
                (Context.SENSOR_SERVICE);
        sensorManager.unregisterListener(mFlipGesture);
        mFlipGesture.reset();
        mIsSensorRegistered = false;
    }
}
 
Example #20
Source File: AccelerometerHandler.java    From Alite with GNU General Public License v3.0 5 votes vote down vote up
public void dispose() {
	if (deviceOrientationManager != null) {
		deviceOrientationManager.disable();
	}
	SensorManager manager = (SensorManager) game.getSystemService(Context.SENSOR_SERVICE);
	if (manager.getSensorList(Sensor.TYPE_ACCELEROMETER).size() > 0) {
		manager.unregisterListener(this);			
	}
	getUpdates = false;
}
 
Example #21
Source File: BatchStepSensorFragment.java    From android-BatchStepSensor with Apache License 2.0 5 votes vote down vote up
/**
 * Unregisters the sensor listener if it is registered.
 */
private void unregisterListeners() {
    // BEGIN_INCLUDE(unregister)
    SensorManager sensorManager =
            (SensorManager) getActivity().getSystemService(Activity.SENSOR_SERVICE);
    sensorManager.unregisterListener(mListener);
    Log.i(TAG, "Sensor listener unregistered.");

    // END_INCLUDE(unregister)
}
 
Example #22
Source File: ShakeListener.java    From ShareSDK-for-Android with MIT License 5 votes vote down vote up
public void start() {
	// 获得传感器管理器
	sensorManager = (SensorManager) context
			.getSystemService(Context.SENSOR_SERVICE);
	if (sensorManager != null) {
		// 获得重力传感器
		sensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
	}
	// 注册
	if (sensor != null) {
		sensorManager.registerListener(this, sensor,
				SensorManager.SENSOR_DELAY_GAME);
	}
}
 
Example #23
Source File: DoodleFragment.java    From CSCI4669-Fall15-Android with Apache License 2.0 5 votes vote down vote up
public void disableAccelerometerListening()
{
   // get the SensorManager
   SensorManager sensorManager = 
      (SensorManager) getActivity().getSystemService(
         Context.SENSOR_SERVICE);

   // stop listening for accelerometer events
   sensorManager.unregisterListener(sensorEventListener, 
      sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER));         
}
 
Example #24
Source File: TiltSensor.java    From WindowView with MIT License 5 votes vote down vote up
/**
 * Computes the latest rotation, remaps it according to the current {@link #screenRotation},
 * and stores it in {@link #rotationMatrix}.
 * <p>
 * Should only be called if {@link #haveDataNecessaryToComputeOrientation()} returns true and
 * {@link #haveRotVecData} is false, else result may be undefined.
 *
 * @return true if rotation was retrieved and recalculated, false otherwise.
 */
private boolean computeRotationMatrix() {
    if (SensorManager.getRotationMatrix(rotationMatrixTemp, null, latestAccelerations, latestMagFields)) {
        switch (screenRotation) {
            case Surface.ROTATION_0:
                SensorManager.remapCoordinateSystem(rotationMatrixTemp,
                        SensorManager.AXIS_X, SensorManager.AXIS_Y, rotationMatrix);
                break;
            case Surface.ROTATION_90:
                //noinspection SuspiciousNameCombination
                SensorManager.remapCoordinateSystem(rotationMatrixTemp,
                        SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, rotationMatrix);
                break;
            case Surface.ROTATION_180:
                SensorManager.remapCoordinateSystem(rotationMatrixTemp,
                        SensorManager.AXIS_MINUS_X, SensorManager.AXIS_MINUS_Y, rotationMatrix);
                break;
            case Surface.ROTATION_270:
                //noinspection SuspiciousNameCombination
                SensorManager.remapCoordinateSystem(rotationMatrixTemp,
                        SensorManager.AXIS_MINUS_Y, SensorManager.AXIS_X, rotationMatrix);
                break;
        }
        return true;
    }
    return false;
}
 
Example #25
Source File: CameraNoteActivity.java    From geopaparazzi with GNU General Public License v3.0 5 votes vote down vote up
public void onCreate(final Bundle icicle) {
    super.onCreate(icicle);

    Bundle extras = getIntent().getExtras();
    SensorManager sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    orientationSensor = new OrientationSensor(sensorManager, null);
    orientationSensor.register(this, SensorManager.SENSOR_DELAY_NORMAL);
    noteId = extras.getLong(LibraryConstants.DATABASE_ID);
    lon = extras.getDouble(LibraryConstants.LONGITUDE);
    lat = extras.getDouble(LibraryConstants.LATITUDE);
    elevation = extras.getDouble(LibraryConstants.ELEVATION);


    final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
    boolean warningAlreadyShown = preferences.getBoolean(LibraryConstants.PREFS_KEY_CAMERA_WARNING_SHOWN, false);
    if (warningAlreadyShown) {
        doTakePicture(icicle);
    } else {
        GPDialogs.infoDialog(this, getString(R.string.first_camera_open_warning), new Runnable() {
            @Override
            public void run() {
                doTakePicture(icicle);
                SharedPreferences.Editor editor = preferences.edit();
                editor.putBoolean(LibraryConstants.PREFS_KEY_CAMERA_WARNING_SHOWN, true);
                editor.apply();
            }
        });
    }
}
 
Example #26
Source File: ActiveModeService.java    From AcDisplay with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Builds the array of supported {@link ActiveModeSensor sensors}.
 *
 * @return The array of supported {@link ActiveModeSensor sensors}.
 * @see ActiveModeSensor
 */
@NonNull
public static ActiveModeSensor[] buildAvailableSensorsList(@NonNull Context context) {
    SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
    ActiveModeSensor[] sensors = new ActiveModeSensor[]{ // all available sensors
            AccelerometerSensor.getInstance(),
            GyroscopeSensor.getInstance(),
            ProximitySensor.getInstance()
    };

    // Count the number of supported sensors, and
    // mark unsupported.
    int count = sensors.length;
    boolean[] supportList = new boolean[sensors.length];
    for (int i = 0; i < sensors.length; i++) {
        supportList[i] = sensors[i].isSupported(sensorManager);
        if (!supportList[i]) {
            count--;
        }
    }

    // Create the list of proven sensors.
    ActiveModeSensor[] sensorsSupported = new ActiveModeSensor[count];
    for (int i = 0, j = 0; i < sensors.length; i++) {
        if (supportList[i]) {
            sensorsSupported[j++] = sensors[i];
        }
    }

    return sensorsSupported;
}
 
Example #27
Source File: AmbientLightManager.java    From ZXing-Orient with Apache License 2.0 5 votes vote down vote up
void start(CameraManager cameraManager) {
  this.cameraManager = cameraManager;
  SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
  if (FrontLightMode.readPref(sharedPrefs) == FrontLightMode.AUTO) {
    SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
    lightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
    if (lightSensor != null) {
      sensorManager.registerListener(this, lightSensor, SensorManager.SENSOR_DELAY_NORMAL);
    }
  }
}
 
Example #28
Source File: Compass.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void onResume() {
	super.onResume();
	sensorManager.registerListener(sensorListener,
			SensorManager.SENSOR_ORIENTATION,
			SensorManager.SENSOR_DELAY_FASTEST);
}
 
Example #29
Source File: PlayService.java    From LitePlayer with Apache License 2.0 5 votes vote down vote up
@Override
public IBinder onBind(Intent intent) {
	mSensorManager.registerListener(mSensorEventListener,
			mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
			SensorManager.SENSOR_DELAY_GAME);
	return new PlayBinder();
}
 
Example #30
Source File: AmbientLightManager.java    From AndroidWebServ with Apache License 2.0 5 votes vote down vote up
void start(CameraManager cameraManager) {
    this.cameraManager = cameraManager;
    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
    if (FrontLightMode.readPref(sharedPrefs) == FrontLightMode.AUTO) {
        SensorManager sensorManager = (SensorManager) context
                .getSystemService(Context.SENSOR_SERVICE);
        lightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
        if (lightSensor != null) {
            sensorManager
                    .registerListener(this, lightSensor, SensorManager.SENSOR_DELAY_NORMAL);
        }
    }
}