Java Code Examples for android.hardware.Sensor#TYPE_LINEAR_ACCELERATION

The following examples show how to use android.hardware.Sensor#TYPE_LINEAR_ACCELERATION . 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: FtcAndroidAccel.java    From FtcSamples with MIT License 5 votes vote down vote up
/**
 * Constructor: Creates an instance of the object.
 *
 * @param instanceName specifies the instance name.
 * @param filters specifies an array of filters to use for filtering sensor noise, one for each axis. Since we
 *                have 3 axes, the array should have 3 elements. If no filters are used, it can be set to null.
 */
public FtcAndroidAccel(String instanceName, TrcFilter[] filters)
{
    super(instanceName, 3,
          ACCEL_HAS_X_AXIS | ACCEL_HAS_Y_AXIS | ACCEL_HAS_Z_AXIS | ACCEL_INTEGRATE | ACCEL_DOUBLE_INTEGRATE,
          filters);

    if (debugEnabled)
    {
        dbgTrace = new TrcDbgTrace(moduleName + "." + instanceName, tracingEnabled, traceLevel, msgLevel);
    }

    sensor = new FtcAndroidSensor(instanceName, Sensor.TYPE_LINEAR_ACCELERATION, 3);
}
 
Example 2
Source File: LinearAccelerationUpdatesProvider.java    From PrivacyStreams with Apache License 2.0 4 votes vote down vote up
LinearAccelerationUpdatesProvider(int sensorDelay) {
    super(Sensor.TYPE_LINEAR_ACCELERATION, sensorDelay);
}
 
Example 3
Source File: AccelerometerMonitor.java    From habpanelviewer with GNU General Public License v3.0 4 votes vote down vote up
public AccelerometerMonitor(Context ctx, SensorManager sensorManager, ServerConnection serverConnection) {
    super(ctx, sensorManager, serverConnection, ctx.getString(R.string.pref_accelerometer), "accelerometer", Sensor.TYPE_LINEAR_ACCELERATION);
}
 
Example 4
Source File: PLinearAcceleration.java    From PHONK with GNU General Public License v3.0 4 votes vote down vote up
public PLinearAcceleration(AppRunner appRunner) {
    super(appRunner);

    type = Sensor.TYPE_LINEAR_ACCELERATION;
}
 
Example 5
Source File: DeviceSensors.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
void sensorChanged(int type, float[] values) {
    switch (type) {
        case Sensor.TYPE_ACCELEROMETER:
            if (mDeviceMotionIsActive) {
                gotAccelerationIncludingGravity(values[0], values[1], values[2]);
            }
            if (mDeviceOrientationIsActiveWithBackupSensors) {
                getOrientationFromGeomagneticVectors(values, mMagneticFieldVector);
            }
            break;
        case Sensor.TYPE_LINEAR_ACCELERATION:
            if (mDeviceMotionIsActive) {
                gotAcceleration(values[0], values[1], values[2]);
            }
            break;
        case Sensor.TYPE_GYROSCOPE:
            if (mDeviceMotionIsActive) {
                gotRotationRate(values[0], values[1], values[2]);
            }
            break;
        case Sensor.TYPE_ROTATION_VECTOR:
            if (mDeviceOrientationAbsoluteIsActive) {
                convertRotationVectorToAngles(values, mRotationAngles);
                gotOrientationAbsolute(
                        mRotationAngles[0], mRotationAngles[1], mRotationAngles[2]);
            }
            if (mDeviceOrientationIsActive
                    && mDeviceOrientationSensors == DEVICE_ORIENTATION_SENSORS_B) {
                if (!mDeviceOrientationAbsoluteIsActive) {
                    // only compute if not already computed for absolute orientation above.
                    convertRotationVectorToAngles(values, mRotationAngles);
                }
                gotOrientation(mRotationAngles[0], mRotationAngles[1], mRotationAngles[2]);
            }
            break;
        case Sensor.TYPE_GAME_ROTATION_VECTOR:
            if (mDeviceOrientationIsActive) {
                convertRotationVectorToAngles(values, mRotationAngles);
                gotOrientation(mRotationAngles[0], mRotationAngles[1], mRotationAngles[2]);
            }
            break;
        case Sensor.TYPE_MAGNETIC_FIELD:
            if (mDeviceOrientationIsActiveWithBackupSensors) {
                if (mMagneticFieldVector == null) {
                    mMagneticFieldVector = new float[3];
                }
                System.arraycopy(
                        values, 0, mMagneticFieldVector, 0, mMagneticFieldVector.length);
            }
            break;
        default:
            // Unexpected
            return;
    }
}
 
Example 6
Source File: SensorUtil.java    From Sensor-Disabler with MIT License 4 votes vote down vote up
public static String[] getLabelsForSensor(Context context, Sensor sensor) {
    String[] labels;
    switch (sensor.getType()) {
        case Sensor.TYPE_ACCELEROMETER:
            labels = context.getResources().getStringArray(R.array.accelerometer_values);
            break;
        case Sensor.TYPE_AMBIENT_TEMPERATURE:
            labels = context.getResources().getStringArray(R.array.ambient_temperature_values);
            break;
        case Sensor.TYPE_GAME_ROTATION_VECTOR:
            labels = context.getResources().getStringArray(R.array.game_rotation_vector_values);
            break;
        case Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR:
            labels = context.getResources().getStringArray(R.array.rotation_vector_values);
            break;
        case Sensor.TYPE_GRAVITY:
            labels = context.getResources().getStringArray(R.array.gravity_values);
            break;
        case Sensor.TYPE_GYROSCOPE:
            labels = context.getResources().getStringArray(R.array.gyroscore_values);
            break;
        case Sensor.TYPE_GYROSCOPE_UNCALIBRATED:
            labels = context.getResources().getStringArray(R.array.gyroscore_uncalibrated_values);
            break;
        case Sensor.TYPE_HEART_RATE:
            labels = context.getResources().getStringArray(R.array.heart_rate_values);
            break;
        case Sensor.TYPE_LIGHT:
            labels = context.getResources().getStringArray(R.array.light_values);
            break;
        case Sensor.TYPE_LINEAR_ACCELERATION:
            labels = context.getResources().getStringArray(R.array.linear_acceleration_values);
            break;
        case Sensor.TYPE_MAGNETIC_FIELD:
            labels = context.getResources().getStringArray(R.array.magnetic_values);
            break;
        case Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED:
            labels = context.getResources().getStringArray(R.array.magnetic_field_uncalibrated_values);
            break;
        case Sensor.TYPE_PRESSURE:
            labels = context.getResources().getStringArray(R.array.pressure_values);
            break;
        case Sensor.TYPE_PROXIMITY:
            labels = context.getResources().getStringArray(R.array.proximity_values);
            break;
        case Sensor.TYPE_RELATIVE_HUMIDITY:
            labels = context.getResources().getStringArray(R.array.relative_humidity_values);
            break;
        case Sensor.TYPE_ROTATION_VECTOR:
            labels = context.getResources().getStringArray(R.array.rotation_vector_values);
            break;
        case Sensor.TYPE_STEP_COUNTER:
            labels = context.getResources().getStringArray(R.array.step_counter_values);
            break;
        default:
            labels = new String[]{};
    }
    return labels;
}
 
Example 7
Source File: SensorUtil.java    From Sensor-Disabler with MIT License 4 votes vote down vote up
@Nullable
public static String getHumanStringType(Sensor sensor) {
    switch (sensor.getType()) {
        case Sensor.TYPE_ACCELEROMETER:
            return "Accelerometer";

        case Sensor.TYPE_AMBIENT_TEMPERATURE:
            return "Ambient Temperature";

        case Sensor.TYPE_GAME_ROTATION_VECTOR:
            return "Game Rotation Vector";

        case Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR:
            return "Geomagnetic Rotation Vector";

        case Sensor.TYPE_GRAVITY:
            return "Gravity";

        case Sensor.TYPE_GYROSCOPE:
            return "Gyroscope";

        case Sensor.TYPE_GYROSCOPE_UNCALIBRATED:
            return "Gyroscope (Uncalibrated)";

        case Sensor.TYPE_HEART_RATE:
            return "Heart Rate";

        case Sensor.TYPE_LIGHT:
            return "Light";

        case Sensor.TYPE_LINEAR_ACCELERATION:
            return "Linear Acceleration";

        case Sensor.TYPE_MAGNETIC_FIELD:
            return "Magnetic Field";

        case Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED:
            return "Magnetic Field (Uncalibrated)";

        case Sensor.TYPE_PRESSURE:
            return "Pressure";

        case Sensor.TYPE_PROXIMITY:
            return "Proximity";

        case Sensor.TYPE_RELATIVE_HUMIDITY:
            return "Relative Humidity";

        case Sensor.TYPE_ROTATION_VECTOR:
            return "Rotation Vector";

        case Sensor.TYPE_SIGNIFICANT_MOTION:
            return "Significant Motion";

        case Sensor.TYPE_STEP_COUNTER:
            return "Step Counter";

        case Sensor.TYPE_STEP_DETECTOR:
            return "Step Detector";

        case Sensor.TYPE_ORIENTATION:
            return "Orientation";

        case Sensor.TYPE_TEMPERATURE:
            return "Temperature";
    }
    return null;
}
 
Example 8
Source File: SensorUtil.java    From Sensor-Disabler with MIT License 4 votes vote down vote up
public static String getDescription(Sensor sensor) {
    switch (sensor.getType()) {
        case Sensor.TYPE_ACCELEROMETER:
            return "Measures the acceleration force in m/s² that is applied to a device on all three physical axes (x, y, and z), including the force of gravity.";

        case Sensor.TYPE_AMBIENT_TEMPERATURE:
            return "Measures the ambient room temperature in degrees Celsius (°C).";

        case Sensor.TYPE_GRAVITY:
            return "Measures the force of gravity in m/s² that is applied to a device on all three physical axes (x, y, z).";

        case Sensor.TYPE_GYROSCOPE:
            return "Measures a device's rate of rotation in rad/s around each of the three physical axes (x, y, and z).";

        case Sensor.TYPE_HEART_RATE:
            return "Measures heart rate.";

        case Sensor.TYPE_LIGHT:
            return "Measures the ambient light level (illumination) in lx.";

        case Sensor.TYPE_LINEAR_ACCELERATION:
            return "Measures the acceleration force in m/s² that is applied to a device on all three physical axes (x, y, and z), excluding the force of gravity.";

        case Sensor.TYPE_MAGNETIC_FIELD:
            return "Measures the ambient geomagnetic field for all three physical axes (x, y, z) in μT.";

        case Sensor.TYPE_PRESSURE:
            return "Measures the ambient air pressure in hPa or mbar.";

        case Sensor.TYPE_PROXIMITY:
            return "Measures the proximity of an object in cm relative to the view screen of a device. This sensor is typically used to determine whether a handset is being held up to a person's ear.";

        case Sensor.TYPE_RELATIVE_HUMIDITY:
            return "Measures the relative ambient humidity in percent (%).";

        case Sensor.TYPE_ROTATION_VECTOR:
            return "Measures the orientation of a device by providing the three elements of the device's rotation vector.";

        case Sensor.TYPE_ORIENTATION:
            return "Measures degrees of rotation that a device makes around all three physical axes (x, y, z). ";

        case Sensor.TYPE_TEMPERATURE:
            return "Measures the temperature of the device in degrees Celsius (°C). ";

        default:
            return "Information about this sensor is unavailable.";
    }
}
 
Example 9
Source File: SensorDetailFragment.java    From AndroidDemoProjects with Apache License 2.0 4 votes vote down vote up
private void populateTypeField( int type ) {
	if( type == 0 || mTypeRow == null || mType == null )
		return;

	String typeName;

	switch( type ) {
		case Sensor.TYPE_ACCELEROMETER: {
			typeName = "Accelerometer";
			break;
		}
		case Sensor.TYPE_AMBIENT_TEMPERATURE: {
			typeName = "Ambient Temperature";
			break;
		}
		case Sensor.TYPE_GAME_ROTATION_VECTOR: {
			typeName = "Game Rotation Vector";
			break;
		}
		case Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR: {
			typeName = "Geomagnetic Rotation Vector";
			break;
		}
		case Sensor.TYPE_GRAVITY: {
			typeName = "Gravity";
			break;
		}
		case Sensor.TYPE_GYROSCOPE: {
			typeName = "Gyroscope";
			break;
		}
		case Sensor.TYPE_GYROSCOPE_UNCALIBRATED: {
			typeName = "Uncalibrated Gyroscope";
			break;
		}
		case Sensor.TYPE_LIGHT: {
			typeName = "Light";
			break;
		}
		case Sensor.TYPE_LINEAR_ACCELERATION: {
			typeName = "Linear Acceleration";
			break;
		}
		case Sensor.TYPE_MAGNETIC_FIELD: {
			typeName = "Magnetic Field";
			break;
		}
		case Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED: {
			typeName = "Uncalibrated Magnetic Field";
			break;
		}
		case Sensor.TYPE_PRESSURE: {
			typeName = "Pressure";
			break;
		}
		case Sensor.TYPE_PROXIMITY: {
			typeName = "Proximity";
			break;
		}
		case Sensor.TYPE_RELATIVE_HUMIDITY: {
			typeName = "Relative Humidity";
			break;
		}
		case Sensor.TYPE_ROTATION_VECTOR: {
			typeName = "Rotation Vector";
			break;
		}
		case Sensor.TYPE_SIGNIFICANT_MOTION: {
			typeName = "Significant Motion";
			break;
		}
		case Sensor.TYPE_STEP_COUNTER: {
			typeName = "Step Counter";
			break;
		}
		case Sensor.TYPE_STEP_DETECTOR: {
			typeName = "Step Detector";
			break;
		}
		default: {
			typeName = "Other";
		}
	}
	mType.setText( typeName );
	mTypeRow.setVisibility( View.VISIBLE );
}
 
Example 10
Source File: SKAbstractNativeSensorModule.java    From SensingKit-Android with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressLint("InlinedApi")  // There is a check in STEP_DETECTOR and STEP_COUNTER
private static int getSensorType(SKSensorModuleType sensorType) throws SKException{

    switch (sensorType) {

        case ACCELEROMETER:
            return Sensor.TYPE_ACCELEROMETER;

        case GRAVITY:
            return Sensor.TYPE_GRAVITY;

        case LINEAR_ACCELERATION:
            return Sensor.TYPE_LINEAR_ACCELERATION;

        case GYROSCOPE:
            return Sensor.TYPE_GYROSCOPE;

        case ROTATION:
            return Sensor.TYPE_ROTATION_VECTOR;

        case MAGNETOMETER:
            return Sensor.TYPE_MAGNETIC_FIELD;

        case AMBIENT_TEMPERATURE:
            return Sensor.TYPE_AMBIENT_TEMPERATURE;

        case STEP_DETECTOR:

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                return Sensor.TYPE_STEP_DETECTOR;
            }
            else
            {
                throw new SKException(TAG, "STEP_DETECTOR requires Android KitKat or greater.", SKExceptionErrorCode.UNKNOWN_ERROR);
            }

        case STEP_COUNTER:

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                return Sensor.TYPE_STEP_COUNTER;
            }
            else
            {
                throw new SKException(TAG, "STEP_COUNTER requires Android KitKat or greater.", SKExceptionErrorCode.UNKNOWN_ERROR);
            }

        case LIGHT:
            return Sensor.TYPE_LIGHT;

        case LOCATION:
        case ACTIVITY:
        case BATTERY:
            throw new SKException(TAG, "Not a native SensorModule.", SKExceptionErrorCode.UNKNOWN_ERROR);

        default:
            throw new SKException(TAG, "Unknown SensorModule", SKExceptionErrorCode.UNKNOWN_ERROR);

    }
}
 
Example 11
Source File: DeviceMotionAndOrientation.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@VisibleForTesting
void sensorChanged(int type, float[] values) {

    switch (type) {
        case Sensor.TYPE_ACCELEROMETER:
            if (mAccelerationIncludingGravityVector == null) {
                mAccelerationIncludingGravityVector = new float[3];
            }
            System.arraycopy(values, 0, mAccelerationIncludingGravityVector,
                    0, mAccelerationIncludingGravityVector.length);
            if (mDeviceMotionIsActive) {
                gotAccelerationIncludingGravity(
                        mAccelerationIncludingGravityVector[0],
                        mAccelerationIncludingGravityVector[1],
                        mAccelerationIncludingGravityVector[2]);
            }
            if (mDeviceOrientationIsActive) {
                getOrientationUsingGetRotationMatrix();
            }
            break;
        case Sensor.TYPE_LINEAR_ACCELERATION:
            if (mDeviceMotionIsActive) {
                gotAcceleration(values[0], values[1], values[2]);
            }
            break;
        case Sensor.TYPE_GYROSCOPE:
            if (mDeviceMotionIsActive) {
                gotRotationRate(values[0], values[1], values[2]);
            }
            break;
        case Sensor.TYPE_MAGNETIC_FIELD:
            if (mMagneticFieldVector == null) {
                mMagneticFieldVector = new float[3];
            }
            System.arraycopy(values, 0, mMagneticFieldVector, 0, mMagneticFieldVector.length);
            if (mDeviceOrientationIsActive) {
                getOrientationUsingGetRotationMatrix();
            }
            break;
        default:
            // Unexpected
            return;
    }
}
 
Example 12
Source File: XSensorManager.java    From XPrivacy with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
private boolean isRestricted(XParam param, int type) throws Throwable {
	if (type == Sensor.TYPE_ALL)
		return false;
	else if (type == Sensor.TYPE_ACCELEROMETER || type == Sensor.TYPE_LINEAR_ACCELERATION) {
		if (isRestricted(param, "acceleration"))
			return true;
	} else if (type == Sensor.TYPE_GRAVITY) {
		if (isRestricted(param, "gravity"))
			return true;
	} else if (type == Sensor.TYPE_RELATIVE_HUMIDITY) {
		if (isRestricted(param, "humidity"))
			return true;
	} else if (type == Sensor.TYPE_LIGHT) {
		if (isRestricted(param, "light"))
			return true;
	} else if (type == Sensor.TYPE_MAGNETIC_FIELD || type == Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED) {
		if (isRestricted(param, "magnetic"))
			return true;
	} else if (type == Sensor.TYPE_SIGNIFICANT_MOTION) {
		if (isRestricted(param, "motion"))
			return true;
	} else if (type == Sensor.TYPE_ORIENTATION || type == Sensor.TYPE_GYROSCOPE
			|| type == Sensor.TYPE_GYROSCOPE_UNCALIBRATED) {
		if (isRestricted(param, "orientation"))
			return true;
	} else if (type == Sensor.TYPE_PRESSURE) {
		if (isRestricted(param, "pressure"))
			return true;
	} else if (type == Sensor.TYPE_PROXIMITY) {
		if (isRestricted(param, "proximity"))
			return true;
	} else if (type == Sensor.TYPE_GAME_ROTATION_VECTOR || type == Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR
			|| type == Sensor.TYPE_ROTATION_VECTOR) {
		if (isRestricted(param, "rotation"))
			return true;
	} else if (type == Sensor.TYPE_TEMPERATURE || type == Sensor.TYPE_AMBIENT_TEMPERATURE) {
		if (isRestricted(param, "temperature"))
			return true;
	} else if (type == Sensor.TYPE_STEP_COUNTER || type == Sensor.TYPE_STEP_DETECTOR) {
		if (isRestricted(param, "step"))
			return true;
	} else if (type == Sensor.TYPE_HEART_RATE) {
		if (isRestricted(param, "heartrate"))
			return true;
	} else if (type == 22) {
		// 22 = TYPE_TILT_DETECTOR
		// Do nothing
	} else if (type == 23 || type == 24 || type == 25) {
		// 23 = TYPE_WAKE_GESTURE
		// 24 = TYPE_GLANCE_GESTURE
		// 25 = TYPE_PICK_UP_GESTURE
		// 23/24 This sensor is expected to only be used by the system ui
		// 25 Expected to be used internally for always on display
	} else
		Util.log(this, Log.WARN, "Unknown sensor type=" + type);
	return false;
}
 
Example 13
Source File: DeviceMotionAndOrientation.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@VisibleForTesting
void sensorChanged(int type, float[] values) {

    switch (type) {
        case Sensor.TYPE_ACCELEROMETER:
            if (mAccelerationIncludingGravityVector == null) {
                mAccelerationIncludingGravityVector = new float[3];
            }
            System.arraycopy(values, 0, mAccelerationIncludingGravityVector,
                    0, mAccelerationIncludingGravityVector.length);
            if (mDeviceMotionIsActive) {
                gotAccelerationIncludingGravity(
                        mAccelerationIncludingGravityVector[0],
                        mAccelerationIncludingGravityVector[1],
                        mAccelerationIncludingGravityVector[2]);
            }
            if (mDeviceOrientationIsActive) {
                getOrientationUsingGetRotationMatrix();
            }
            break;
        case Sensor.TYPE_LINEAR_ACCELERATION:
            if (mDeviceMotionIsActive) {
                gotAcceleration(values[0], values[1], values[2]);
            }
            break;
        case Sensor.TYPE_GYROSCOPE:
            if (mDeviceMotionIsActive) {
                gotRotationRate(values[0], values[1], values[2]);
            }
            break;
        case Sensor.TYPE_MAGNETIC_FIELD:
            if (mMagneticFieldVector == null) {
                mMagneticFieldVector = new float[3];
            }
            System.arraycopy(values, 0, mMagneticFieldVector, 0, mMagneticFieldVector.length);
            if (mDeviceOrientationIsActive) {
                getOrientationUsingGetRotationMatrix();
            }
            break;
        default:
            // Unexpected
            return;
    }
}