Guest User

Untitled

a guest
Aug 19th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.67 KB | None | 0 0
  1. public class MyAct extends Activity {
  2.  
  3.     private OrientationEventListener listener;
  4.  
  5.     @Override
  6.     public void onCreate(Bundle savedInstanceState) {
  7.         listener = new OrientationEventListener(this,
  8.                 SensorManager.SENSOR_DELAY_UI) {
  9.             @Override
  10.             public void onOrientationChanged(int orientation) {
  11.                 Log.d("test", "orientation = " + orientation);
  12.                 if ((orientation >= 350 && orientation <= 360)
  13.                         || (orientation >= 0 && orientation <= 10)) {
  14.                     listener.disable();
  15.                     //Do what you need with the above conditions
  16.                     //Disable is optional, it "pauses" the listener
  17.                 }
  18.             }
  19.         };
  20.         listener.enable();
  21.         super.onCreate(savedInstanceState);
  22.     }
  23. }
Add Comment
Please, Sign In to add comment