Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1167 from xamarin/bug/gh-1148-2
Browse files Browse the repository at this point in the history
GH-1148 - Check if 4th value is present in orientation sensor
  • Loading branch information
Redth authored Mar 25, 2020
2 parents a610b50 + b6fe59a commit c1e48ec
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions Xamarin.Essentials/OrientationSensor/OrientationSensor.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,21 @@ void ISensorEventListener.OnAccuracyChanged(Sensor sensor, [GeneratedEnum] Senso

void ISensorEventListener.OnSensorChanged(SensorEvent e)
{
if ((e?.Values?.Count ?? 0) < 4)
var count = e?.Values?.Count ?? 0;
if (count < 3)
return;

var data = new OrientationSensorData(e.Values[0], e.Values[1], e.Values[2], e.Values[3]);
OrientationSensor.OnChanged(data);
OrientationSensorData? data;

// Docs: https://developer.android.com/reference/android/hardware/SensorEvent#sensor.type_rotation_vector-:
// values[3], originally optional, will always be present from SDK Level 18 onwards. values[4] is a new value that has been added in SDK Level 18.

if (count < 4)
data = new OrientationSensorData(e.Values[0], e.Values[1], e.Values[2], -1);
else
data = new OrientationSensorData(e.Values[0], e.Values[1], e.Values[2], e.Values[3]);

OrientationSensor.OnChanged(data.Value);
}
}
}

0 comments on commit c1e48ec

Please sign in to comment.