Example usage for android.view Display getOrientation

List of usage examples for android.view Display getOrientation

Introduction

In this page you can find the example usage for android.view Display getOrientation.

Prototype

@Deprecated
@Surface.Rotation
public int getOrientation() 

Source Link

Usage

From source file:Main.java

public static int getSurfaceOrientation(Activity activity) {

    // Sanity check:
    if (activity == null) {
        return -1; // invalid value
    }/*from ww w.  j av  a 2  s. c om*/

    Configuration config = activity.getResources().getConfiguration();
    Display display = ((WindowManager) activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();

    int displayRotation;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
        displayRotation = display.getRotation(); // only available from Froyo
    } else {
        displayRotation = display.getOrientation();
    }

    int activityOrientation = SCREEN_ORIENTATION_UNKNOWN;

    switch (config.orientation) {
    case Configuration.ORIENTATION_PORTRAIT:
    case Configuration.ORIENTATION_SQUARE:
        activityOrientation = ((displayRotation == Surface.ROTATION_0
                || displayRotation == Surface.ROTATION_270) ? SCREEN_ORIENTATION_PORTRAIT
                        : SCREEN_ORIENTATION_PORTRAITUPSIDEDOWN);
        break;

    case Configuration.ORIENTATION_LANDSCAPE:
        activityOrientation = ((displayRotation == Surface.ROTATION_0 || displayRotation == Surface.ROTATION_90)
                ? SCREEN_ORIENTATION_LANDSCAPELEFT
                : SCREEN_ORIENTATION_LANDSCAPERIGHT);
        break;

    case Configuration.ORIENTATION_UNDEFINED:
    default:
        break;
    }

    return activityOrientation;
}

From source file:org.cocos2dx.lib.Cocos2dxAccelerometer.java

public Cocos2dxAccelerometer(Context context) {
    mContext = context;/*from w w  w  . j ava  2 s.co  m*/

    //Get an instance of the SensorManager
    mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
    mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);

    Display display = ((WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    mNaturalOrientation = display.getOrientation();
}

From source file:de.akquinet.android.androlog.reporter.Report.java

/**
 * Adds the device data to the report.//from w ww  .  j  a  v  a 2  s .  co  m
 * @param context 
 * @throws JSONException if the device data cannot be added
 */
private void buildDeviceData(Context context) throws JSONException {
    device = new JSONObject();
    device.put("device", Build.DEVICE);
    device.put("brand", Build.BRAND);

    Object windowService = context.getSystemService(Context.WINDOW_SERVICE);
    if (windowService instanceof WindowManager) {
        Display display = ((WindowManager) windowService).getDefaultDisplay();
        device.put("resolution", display.getWidth() + "x" + display.getHeight());
        device.put("orientation", display.getOrientation());
    }
    device.put("display", Build.DISPLAY);
    device.put("manufacturer", Build.MANUFACTURER);
    device.put("model", Build.MODEL);
    device.put("product", Build.PRODUCT);
    device.put("build.type", Build.TYPE);
    device.put("android.version", Build.VERSION.SDK_INT);
}

From source file:com.scm.reader.livescanner.sdk.recognizers.KooabaRecognizer.java

private Bitmap fixRotation(Bitmap img) throws IOException {
    //get WINDOW_SERVICE
    Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();

    if (isDebugLog()) {
        logDebug("Display orientation is " + display.getOrientation());
    }/*  w  w w  . j  av  a 2  s. c om*/

    Matrix m = new Matrix();

    int angle = 0;

    //TODO: refactor
    if (img.getWidth() > img.getHeight()) {
        if (display.getOrientation() == ROTATION_0) {
            angle = 90;
        } else if (display.getOrientation() == ROTATION_270) {
            angle = 180;
        }
    } else {
        if (display.getOrientation() == ROTATION_90) {
            angle = -90;
        } else if (display.getOrientation() == ROTATION_270) {
            angle = 90;
        }
    }

    if (isDebugLog()) {
        logDebug("Preview image will be rotated by " + angle + " degrees");
    }

    m.postRotate(angle);
    return Bitmap.createBitmap(img, 0, 0, img.getWidth(), img.getHeight(), m, true);
}

From source file:com.google.android.testing.nativedriver.server.AndroidNativeDriver.java

/**
 * Creates a {@code Function} to get screen rotation information. This
 * {@code Function} should always be run on the main application thread.
 *///from   ww w .  j a v  a2s .  c  o m
private Function<Void, Integer> doGetOrientation() {
    return new Function<Void, Integer>() {
        @Override
        public Integer apply(Void ignoredArgument) {
            Display display = checkHasCurrentActivity().getWindowManager().getDefaultDisplay();

            // Display.getOrientation() is marked as deprecated starting from
            // Android 2.3. Display.getRotation() should be used in newer versions.
            return display.getOrientation();
        }
    };
}

From source file:org.openremote.android.console.GroupActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

    Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
    Log.i("OpenRemote-ORIENTATION", "onCreate:" + display.getOrientation());
    if (display != null && display.getOrientation() == 1) {
        isLandscape = true;//www  .j a v a 2  s . c o m
        lastConfigurationOrientation = Configuration.ORIENTATION_LANDSCAPE;
    } else {
        isLandscape = false;
        lastConfigurationOrientation = Configuration.ORIENTATION_PORTRAIT;
    }

    this.gestureScanner = new GestureDetector(this);

    if (groupViews == null) {
        groupViews = new HashMap<Integer, GroupView>();
    }
    if (navigationHistory == null) {
        navigationHistory = new ArrayList<Navigate>();
    }

    recoverLastGroupScreen();
    addControllerRefreshEventListener();

    initOrientationListener();

}

From source file:info.alni.comete.android.Comete.java

private void getPrefs() {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

    throttleArr = sharedPreferences.getString("throttleKey", getString(R.string.prop_throttle)).split("$d");

    mixtureArr = sharedPreferences.getString("mixtureKey", getString(R.string.prop_mixture)).split("$d");
    propellerArr = sharedPreferences.getString("propellerKey", getString(R.string.prop_propeller)).split("$d");
    magnetosArr = sharedPreferences.getString("magnetosKey", getString(R.string.prop_magnetos)).split("$d");
    starterArr = sharedPreferences.getString("starterKey", getString(R.string.prop_starter)).split("$d");
    startSwitchsArr = sharedPreferences.getString("starterSwitchKey", getString(R.string.prop_starter_switch))
            .split("$d");
    setReverserArr(sharedPreferences.getString("reverserKey", getString(R.string.prop_reverser)).split("$d"));

    flapPropKey = sharedPreferences.getString("flapKey", getString(R.string.prop_flap));
    rudderPropKey = sharedPreferences.getString("rudderKey", getString(R.string.prop_rudder));
    aileronPropKey = sharedPreferences.getString("aileronKey", getString(R.string.prop_aileron));
    elevatorPropKey = sharedPreferences.getString("elevatorKey", getString(R.string.prop_elevator));
    setBrakeLeftPropKey(sharedPreferences.getString("brakeLeftKey", getString(R.string.prop_brakeLeft)));
    setBrakeRightPropKey(sharedPreferences.getString("brakeRightKey", getString(R.string.prop_brakeRight)));
    starter2PropKey = sharedPreferences.getString("starter2Key", getString(R.string.prop_starter2));
    nav1FreqPropKey = sharedPreferences.getString("nav1FreqKey", getString(R.string.prop_nav1Freq));
    setNav1RadPropKey(sharedPreferences.getString("nav1RadKey", getString(R.string.prop_nav1Rad)));
    nav2FreqPropKey = sharedPreferences.getString("nav2FreqKey", getString(R.string.prop_nav2Freq));
    setNav2RadPropKey(sharedPreferences.getString("nav2RadKey", getString(R.string.prop_nav2Rad)));
    adf1FreqPropKey = sharedPreferences.getString("adf1FreqKey", getString(R.string.prop_adf1Freq));
    com1FreqPropKey = sharedPreferences.getString("com1FreqKey", getString(R.string.prop_com1Freq));
    fgViewPropKey = sharedPreferences.getString("fgViewKey", getString(R.string.prop_fgView));

    ((FGToggleButton) findViewById(R.id.gear2))
            .setFgProp(sharedPreferences.getString("gearDownKey", getString(R.string.prop_gearDown)));
    ((FGToggleButton) findViewById(R.id.autoCoordination)).setFgProp(
            sharedPreferences.getString("autoCoordinationKey", getString(R.string.prop_autoCoordination)));
    ((FGToggleButton) findViewById(R.id.parking_brake))
            .setFgProp(sharedPreferences.getString("parkingBrakeKey", getString(R.string.prop_parkingBrake)));
    // this will be (0 or 1) not (true or false)
    ((FGToggleButton) findViewById(R.id.parking_brake)).setBoolean(false);

    try {/*from   ww  w  .j  av a2  s.c  om*/
        aileronMoltDefault = sharedPreferences.getFloat("aileronMoltDefaultKey",
                Float.parseFloat(getString(R.string.aileronMoltDefault)));
        elevatorMoltDefault = sharedPreferences.getFloat("elevatorMoltDefaultKey",
                Float.parseFloat(getString(R.string.elevatorMoltDefault)));
        elevatorSubDefault = sharedPreferences.getFloat("elevatorSubDefaultKey",
                Float.parseFloat(getString(R.string.elevatorSubDefault)));
        rudderMoltDefault = sharedPreferences.getFloat("rudderMoltDefaultKey",
                Float.parseFloat(getString(R.string.rudderMoltDefault)));
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (sharedPreferences.getBoolean("orientationLandscape", false)) {

        /* First, get the Display from the WindowManager */
        Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();

        /* Now we can retrieve all display-related infos */
        // int width = display.getWidth();
        // int height = display.getHeight();
        int orientation = display.getOrientation();

        if (orientation != Configuration.ORIENTATION_LANDSCAPE) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        }
    } else {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
    }

    thrGetAirspeed.getProp().clear();
    thrGetAirspeed.addProp(sharedPreferences.getString("airspeedKey", getString(R.string.prop_airspeed)),
            getString(R.string.prop_airspeed_format));
    thrGetAirspeed.addProp(sharedPreferences.getString("directionKey", getString(R.string.prop_direction)),
            getString(R.string.prop_direction_format));

    thrGetAirspeed.addProp(sharedPreferences.getString("nav1FreqKey", getString(R.string.prop_nav1Freq)),
            getString(R.string.prop_nav1Freq_format), true);
    thrGetAirspeed.addProp(sharedPreferences.getString("nav1RadKey", getString(R.string.prop_nav1Rad)),
            getString(R.string.prop_nav1Rad_format), true);
    thrGetAirspeed.addProp(sharedPreferences.getString("nav2FreqKey", getString(R.string.prop_nav2Freq)),
            getString(R.string.prop_nav2Freq_format), true);
    thrGetAirspeed.addProp(sharedPreferences.getString("nav2RadKey", getString(R.string.prop_nav2Rad)),
            getString(R.string.prop_nav2Rad_format), true);
    thrGetAirspeed.addProp(sharedPreferences.getString("adf1FreqKey", getString(R.string.prop_adf1Freq)),
            getString(R.string.prop_adf1Freq_format), true);
    thrGetAirspeed.addProp(sharedPreferences.getString("com1FreqKey", getString(R.string.prop_com1Freq)),
            getString(R.string.prop_com1Freq_format), true);

    thrGetAirspeed.setEnabled(sharedPreferences.getBoolean("enableGetting", true));

    // }

}

From source file:tw.com.sti.store.api.android.AndroidApiService.java

private AndroidApiService(Context context, Configuration config) {
    this.config = config;
    this.apiUrl = new ApiUrl(config);
    if (Logger.DEBUG)
        L.d("new ApiService()");

    sdkVer = Build.VERSION.SDK;//from  w ww .ja  v a 2  s. co  m
    sdkRel = Build.VERSION.RELEASE;
    try {
        PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(),
                PackageManager.GET_ACTIVITIES);
        storeId = pi.packageName;
        clientVer = "" + pi.versionCode;
    } catch (NameNotFoundException e) {
    }
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    deviceId = tm.getDeviceId() == null ? "0" : tm.getDeviceId();
    macAddress = NetworkUtils.getDeviceMacAddress(context);
    subscriberId = tm.getSubscriberId() == null ? "0" : tm.getSubscriberId();
    simSerialNumber = tm.getSimSerialNumber() == null ? "0" : tm.getSimSerialNumber();

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    try {
        Class<Display> cls = Display.class;
        Method method = cls.getMethod("getRotation");
        Object retobj = method.invoke(display);
        int rotation = Integer.parseInt(retobj.toString());
        if (Surface.ROTATION_0 == rotation || Surface.ROTATION_180 == rotation) {
            wpx = "" + display.getWidth();
            hpx = "" + display.getHeight();
        } else {
            wpx = "" + display.getHeight();
            hpx = "" + display.getWidth();
        }
    } catch (Exception e) {
        if (display.getOrientation() == 1) {
            wpx = "" + display.getHeight();
            hpx = "" + display.getWidth();
        } else {
            wpx = "" + display.getWidth();
            hpx = "" + display.getHeight();
        }
    }

    SharedPreferences pref = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
    //      token = pref.getString(PREF_KEY_TOKEN, "");
    //      uid = pref.getString(PREF_KEY_UID, "");
    //      userId = pref.getString(PREF_KEY_USER_ID, "");
    appFilter = pref.getInt(PREF_KEY_APP_FILTER, 0);
    // ipLoginEnable = pref.getBoolean(PREF_KEY_IP_LOGIN_ENABLE, true);

    // ??SIM?
    String pref_subscriberId = pref.getString(PREF_KEY_SUBSCRIBER_ID, "0");
    String pref_simSerialNumber = pref.getString(PREF_KEY_SIM_SERIAL_NUMBER, "0");
    if (!subscriberId.equals(pref_subscriberId) || !simSerialNumber.equals(pref_simSerialNumber)) {
        if (Logger.DEBUG)
            L.d("Change SIM card.");
        cleanCredential(context);
    }
    this.getCredential(context);
}

From source file:org.cryptsecure.Utility.java

/**
 * Checks if is orientation landscape./* w  w w. ja va 2  s . c  o m*/
 * 
 * @param context
 *            the context
 * @return true, if is orientation landscape
 */
@SuppressWarnings("deprecation")
public static boolean isOrientationLandscape(Context context) {
    Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    // int rotation = display.getRotation();
    int rotation = display.getOrientation();
    return (rotation != 0 && rotation != 180);
}

From source file:org.videolan.vlc.gui.video.VideoPlayerActivity.java

@SuppressWarnings("deprecation")
private int getScreenRotation() {
    WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO /* Android 2.2 has getRotation */) {
        try {/* w  w  w .  j a  va2  s. co  m*/
            Method m = display.getClass().getDeclaredMethod("getRotation");
            return (Integer) m.invoke(display);
        } catch (Exception e) {
            return Surface.ROTATION_0;
        }
    } else {
        return display.getOrientation();
    }
}