Example usage for android.content.res Configuration ORIENTATION_PORTRAIT

List of usage examples for android.content.res Configuration ORIENTATION_PORTRAIT

Introduction

In this page you can find the example usage for android.content.res Configuration ORIENTATION_PORTRAIT.

Prototype

int ORIENTATION_PORTRAIT

To view the source code for android.content.res Configuration ORIENTATION_PORTRAIT.

Click Source Link

Document

Constant for #orientation , value corresponding to the port resource qualifier.

Usage

From source file:Main.java

/**
 * Rotates the given activity.//from   w  ww  .  j  av  a 2s .  com
 * 
 * @param activity a given activity
 */
private static void rotateActivity(Activity activity) {
    activity.setRequestedOrientation(
            activity.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT
                    ? ORIENTATION_LANDSCAPE
                    : ORIENTATION_PORTRAIT);
}

From source file:Main.java

public static boolean isPortrait(Context context) {
    return (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT);
}

From source file:Main.java

private static int getNavBarHeight(Context context) {
    boolean hasMenuKey = Build.VERSION.SDK_INT >= 14 && ViewConfiguration.get(context).hasPermanentMenuKey();
    boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
    boolean hasNavBar = !hasMenuKey && !hasBackKey;

    if (hasNavBar) {
        boolean isPortrait = context.getResources()
                .getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;

        boolean isTablet = (context.getResources().getConfiguration().screenLayout
                & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;

        String key = isPortrait ? "navigation_bar_height"
                : (isTablet ? "navigation_bar_height_landscape" : null);

        return key == null ? 0 : getDimenSize(context, key);
    } else {/*ww w . ja va 2 s.  c om*/
        return 0;
    }
}

From source file:Main.java

public static int getSurfaceOrientation(Activity activity) {

    // Sanity check:
    if (activity == null) {
        return -1; // invalid value
    }/*  w  w w .j  a v a  2s.  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:Main.java

public static int getScreenOrientation(Context context) {
    Display display = getDefaultDisplay(context);
    int orientation = Configuration.ORIENTATION_UNDEFINED;
    if (display.getWidth() == display.getHeight())
        orientation = Configuration.ORIENTATION_SQUARE;
    else {/*from   w  w w  .j a va2s .c om*/
        if (display.getWidth() < display.getHeight())
            orientation = Configuration.ORIENTATION_PORTRAIT;
        else
            orientation = Configuration.ORIENTATION_LANDSCAPE;
    }

    return orientation;
}

From source file:Main.java

/**
 * Locks specified activity's orientation until it is unlocked or recreated.
 *
 * @param activity activity/*from  w w w .j a va2  s.co m*/
 */
public static void lockOrientation(Activity activity) {
    Configuration config = activity.getResources().getConfiguration();
    final int deviceOrientation = config.orientation;
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();

    int orientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
    if (deviceOrientation == Configuration.ORIENTATION_PORTRAIT) {
        orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
        if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_180)
            orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
    } else if (deviceOrientation == Configuration.ORIENTATION_LANDSCAPE) {
        orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
        if (rotation == Surface.ROTATION_180 || rotation == Surface.ROTATION_270)
            orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
    }

    activity.setRequestedOrientation(orientation);
}

From source file:MainActivity.java

public void checkOrientation(View view) {
    int orientation = getResources().getConfiguration().orientation;
    switch (orientation) {
    case Configuration.ORIENTATION_LANDSCAPE:
        Toast.makeText(MainActivity.this, "ORIENTATION_LANDSCAPE", Toast.LENGTH_SHORT).show();
        break;//from  ww  w.  jav  a 2 s.com
    case Configuration.ORIENTATION_PORTRAIT:
        Toast.makeText(MainActivity.this, "ORIENTATION_PORTRAIT", Toast.LENGTH_SHORT).show();
        break;
    case Configuration.ORIENTATION_UNDEFINED:
        Toast.makeText(MainActivity.this, "ORIENTATION_UNDEFINED", Toast.LENGTH_SHORT).show();
        break;
    }
}

From source file:Main.java

/**
 * Calculates the default orientation of the device.<br>
 * The default orientation of most phones is portrait, and the default orientation of most tablets is landscape.
 * /*  w w w .ja  va2s  .  c  o  m*/
 * @param activity Activity.
 * @return {@link Configuration#ORIENTATION_PORTRAIT} or {@link Configuration#ORIENTATION_LANDSCAPE}
 */
public static int getDefaultOrientationOfDevice(Activity activity) {
    Configuration configuration = activity.getResources().getConfiguration();
    boolean orientationLandscape = (configuration.orientation == Configuration.ORIENTATION_LANDSCAPE);

    Display display = activity.getWindowManager().getDefaultDisplay();
    int rotation = display.getRotation();
    boolean parallelToDefaultVerticalAxis = (rotation == Surface.ROTATION_0)
            || (rotation == Surface.ROTATION_180);

    boolean defaultOrientationLandscape = (parallelToDefaultVerticalAxis && orientationLandscape)
            || (!parallelToDefaultVerticalAxis && !orientationLandscape);

    if (defaultOrientationLandscape) {
        return Configuration.ORIENTATION_LANDSCAPE;
    }
    return Configuration.ORIENTATION_PORTRAIT;
}

From source file:Main.java

public static boolean inPortarit(Resources res) {
    return (res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT);
}

From source file:Main.java

private static String getHumanReadableOrientation(Context context) {
    switch (context.getResources().getConfiguration().orientation) {
    case Configuration.ORIENTATION_LANDSCAPE:
        return "Landscape";
    case Configuration.ORIENTATION_PORTRAIT:
        return "Portrait";
    default://from w  w w.jav a  2s  .  co m
        return "unknown";
    }
}