Last active
March 9, 2017 16:00
-
-
Save DanielJette/8f982de0d679e5e7cb1dce2716abeb81 to your computer and use it in GitHub Desktop.
OrientationEventListener to log orientation changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class OrientationLoggingActivity extends AppCompatActivity { | |
private OrientationEventListener orientationEventListener = null; | |
@Override | |
protected void onCreate(Bundle bundle) { | |
super.onCreate(bundle); | |
orientationEventListener = new OrientationEventListener(this) { | |
@Override | |
public void onOrientationChanged(int orientation) { | |
Log.v("OrientationLoggingActivity", "Orientation changed to " + orientation); | |
} | |
}; | |
if (orientationEventListener.canDetectOrientation()) { | |
orientationEventListener.enable(); | |
} | |
} | |
@Override | |
protected void onDestroy() { | |
orientationEventListener.disable(); | |
orientationEventListener = null; | |
super.onDestroy(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment