Java Code Examples for android.view.Display#getOrientation()

The following examples show how to use android.view.Display#getOrientation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Engine.java    From 30-android-libraries-in-30-days with Apache License 2.0 6 votes vote down vote up
/**
 * @return <code>true</code> when the sensor was successfully enabled, <code>false</code> otherwise.
 */
public boolean enableAccelerationSensor(final Context pContext, final IAccelerationListener pAccelerationListener, final AccelerationSensorOptions pAccelerationSensorOptions) {
	final SensorManager sensorManager = (SensorManager) pContext.getSystemService(Context.SENSOR_SERVICE);
	if(Engine.isSensorSupported(sensorManager, Sensor.TYPE_ACCELEROMETER)) {
		this.mAccelerationListener = pAccelerationListener;

		if(this.mAccelerationData == null) {
			final Display display = ((WindowManager) pContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
			final int displayRotation = display.getOrientation();
			this.mAccelerationData = new AccelerationData(displayRotation);
		}

		this.registerSelfAsSensorListener(sensorManager, Sensor.TYPE_ACCELEROMETER, pAccelerationSensorOptions.getSensorDelay());

		return true;
	} else {
		return false;
	}
}
 
Example 2
Source File: Engine.java    From 30-android-libraries-in-30-days with Apache License 2.0 6 votes vote down vote up
/**
 * @return <code>true</code> when the sensor was successfully enabled, <code>false</code> otherwise.
 */
public boolean enableOrientationSensor(final Context pContext, final IOrientationListener pOrientationListener, final OrientationSensorOptions pOrientationSensorOptions) {
	final SensorManager sensorManager = (SensorManager) pContext.getSystemService(Context.SENSOR_SERVICE);
	if(Engine.isSensorSupported(sensorManager, Sensor.TYPE_ACCELEROMETER) && Engine.isSensorSupported(sensorManager, Sensor.TYPE_MAGNETIC_FIELD)) {
		this.mOrientationListener = pOrientationListener;

		if(this.mOrientationData == null) {
			final Display display = ((WindowManager) pContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
			final int displayRotation = display.getOrientation();
			this.mOrientationData = new OrientationData(displayRotation);
		}

		this.registerSelfAsSensorListener(sensorManager, Sensor.TYPE_ACCELEROMETER, pOrientationSensorOptions.getSensorDelay());
		this.registerSelfAsSensorListener(sensorManager, Sensor.TYPE_MAGNETIC_FIELD, pOrientationSensorOptions.getSensorDelay());

		return true;
	} else {
		return false;
	}
}
 
Example 3
Source File: OrientationSensor.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
private int getScreenRotation() {
  Display display =
      ((WindowManager) form.getSystemService(Context.WINDOW_SERVICE)).
      getDefaultDisplay();
  if (SdkLevel.getLevel() >= SdkLevel.LEVEL_FROYO) {
    return FroyoUtil.getRotation(display);
  } else {
    return display.getOrientation();
  }
}
 
Example 4
Source File: VideoPlayerActivity.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
private int getScreenRotation(){
    WindowManager wm = (WindowManager) VLCApplication.getAppContext().getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO /* Android 2.2 has getRotation */) {
        try {
            Method m = display.getClass().getDeclaredMethod("getRotation");
            return (Integer) m.invoke(display);
        } catch (Exception e) {
            return Surface.ROTATION_0;
        }
    } else {
        return display.getOrientation();
    }
}
 
Example 5
Source File: PopupWindowManager.java    From Noyze with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("depecation")
protected static int getRotation(Display mDisplay) {		
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO)
		return mDisplay.getRotation();
	else
		return mDisplay.getOrientation();
}
 
Example 6
Source File: PopupWindowManager.java    From Noyze with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("depecation")
protected static int getRotation(Display mDisplay) {		
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO)
		return mDisplay.getRotation();
	else
		return mDisplay.getOrientation();
}