本文整理匯總了Java中android.hardware.Sensor.TYPE_ORIENTATION屬性的典型用法代碼示例。如果您正苦於以下問題:Java Sensor.TYPE_ORIENTATION屬性的具體用法?Java Sensor.TYPE_ORIENTATION怎麽用?Java Sensor.TYPE_ORIENTATION使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.hardware.Sensor
的用法示例。
在下文中一共展示了Sensor.TYPE_ORIENTATION屬性的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onSensorChanged
@Override
public void onSensorChanged(SensorEvent event) {
if (internalCompassListener == null) {
return;
}
// check when the last time the compass was updated, return if too soon.
long currentTime = SystemClock.elapsedRealtime();
if (currentTime < compassUpdateNextTimestamp) {
return;
}
if (lastAccuracy == SensorManager.SENSOR_STATUS_UNRELIABLE) {
Timber.d("Compass sensor is unreliable, device calibration is needed.");
return;
}
if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) {
updateOrientation(event.values);
// Update the compassUpdateNextTimestamp
compassUpdateNextTimestamp = currentTime + LocationLayerConstants.COMPASS_UPDATE_RATE_MS;
} else if (event.sensor.getType() == Sensor.TYPE_ORIENTATION) {
internalCompassListener.onCompassChanged((event.values[0] + 360) % 360);
for (CompassListener compassListener : compassListeners) {
compassListener.onCompassChanged((event.values[0] + 360) % 360);
}
}
}
示例2: onSensorChanged
@SuppressWarnings(
{ "deprecation" })
@Override
public void onSensorChanged(SensorEvent event)
{
if (event.sensor.getType() == Sensor.TYPE_ORIENTATION)
{
float x = event.values[SensorManager.DATA_X];
if (Math.abs(x - lastX) > 1.0)
{
if (mOnOrientationListener != null)
{
mOnOrientationListener.onOrientationChanged(x);
}
}
lastX = x;
}
}
示例3: onSensorChanged
@Override
public void onSensorChanged(SensorEvent event) {
if(event.sensor.getType()== Sensor.TYPE_ORIENTATION)
{
float x=event.values[SensorManager.DATA_X];
if(Math.abs(x-lastX)>1.0)
{
if(mOnOrientationListener!=null)
{
mOnOrientationListener.onOrientationChanged(x);
}
}
lastX=x;
}
}
示例4: isRestricted
@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;
}
示例5: onSensorChanged
@Override
public void onSensorChanged(SensorEvent event) {
if (System.currentTimeMillis() - lastTime < TIME_SENSOR) {
return;
}
switch (event.sensor.getType()) {
case Sensor.TYPE_ORIENTATION: {
float x = event.values[0];
x += getScreenRotationOnPhone(mContext);
x %= 360.0F;
if (x > 180.0F)
x -= 360.0F;
else if (x < -180.0F)
x += 360.0F;
if (Math.abs(mAngle - x) < 3.0f) {
break;
}
mAngle = Float.isNaN(x) ? 0 : x;
if (mMarker != null) {
mMarker.setRotateAngle(360 - mAngle);
}
lastTime = System.currentTimeMillis();
}
}
}
示例6: onSensorChanged
@SuppressWarnings("deprecation")
@Override
public void onSensorChanged(SensorEvent event)
{
if(m_useDeprecatedOrientationMethod)
{
if (event.sensor.getType() == Sensor.TYPE_ORIENTATION)
{
float smoothing = 0.6f;
float heading = event.values[0];
if (Float.isNaN(heading)) // Fix MPLY-4888
{
return;
}
float newAzimuth = adjustHeadingForDeviceOrientation(heading);
if(Math.abs(newAzimuth - m_azimuthDegrees) >= 180)
{
if(newAzimuth > m_azimuthDegrees)
{
m_azimuthDegrees += 360.0f;
}
else
{
newAzimuth += 360.0f;
}
}
m_azimuthDegrees = (float) ((newAzimuth * smoothing) + (m_azimuthDegrees * (1.0 - smoothing)));
m_azimuthDegrees %= 360.0f;
m_hasAzimuthAngle = true;
return;
}
}
else
{
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
{
m_gravity = event.values.clone();
}
if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
{
m_geomagnetic = event.values.clone();
}
if (m_gravity != null && m_geomagnetic != null)
{
float R[] = new float[9];
float I[] = new float[9];
boolean success = SensorManager.getRotationMatrix(R, I, m_gravity, m_geomagnetic);
if(success)
{
float remap[] = new float[9];
SensorManager.remapCoordinateSystem(R, SensorManager.AXIS_X, SensorManager.AXIS_Z, remap);
float orientation[] = new float[3];
SensorManager.getOrientation(remap, orientation);
m_hasAzimuthAngle = true;
addResultForFiltering(orientation[0]);
}
}
}
}
示例7: POrientation
public POrientation(AppRunner appRunner) {
super(appRunner);
type = Sensor.TYPE_ORIENTATION;
}