OrientationDetector is a well-documented android library, a high-level library that makes detecting the orientation of the device easy and still leaving you with the flexibility to use it where needed.
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.MoustafaElsaghier:OrientationDetector:0.2.1'
}
1- Create a new Instance of OrientationDetector
OrientationDetector detector;
2- in onCreate() method init it :
detector = new OrientationDetector(this) {
@Override
protected void onRotateChanged(int startDeg, int endDeg) {
// action to added here
}
};
3- in onStart() method enable the listner :
@Override
protected void onStart() {
super.onStart();
detector.enable();
}
4- in onStop() method disable the listner :
@Override
protected void onStop() {
super.onStop();
detector.disable();
}
// true if portraits, false in landscape
boolean isPortraite = detector.isPortrait();
/* 0 for portrait
* 180 for reverse-portrait
* 90 for landscape
* 270 for reverse-landscape
*/
int rotateValue = detector.getRotateValue();Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.