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

public static boolean isOrientationPortrait(Activity activity) {

    int orientation = activity.getResources().getConfiguration().orientation;

    switch (orientation) {
    case Configuration.ORIENTATION_LANDSCAPE:
        return false;
    case Configuration.ORIENTATION_PORTRAIT:
        return true;
    }//from w w w. j a  va2s.  c o  m
    return true;
}

From source file:Main.java

public static String getOrientation(Context context) {
    switch (context.getResources().getConfiguration().orientation) {
    case Configuration.ORIENTATION_LANDSCAPE:
        return "Landscape";
    case Configuration.ORIENTATION_PORTRAIT:
        return "Portrait";
    default://  w w w. j a v  a  2  s  .  co m
        return "";
    }
}

From source file:Main.java

public static int getOrientation(Context context) {
    int orientation = 0;
    if (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
        orientation = 2;/*  w  w w.  ja v  a 2 s .c om*/
    } else if (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
        orientation = 1;
    }
    return orientation;
}

From source file:Main.java

/**
 * <pre>/*from  w ww.  j  a v a  2 s.  c  o  m*/
 * Determine whether current orientation is portrait.
 * </pre>
 */
public static boolean isPortraitDisplay() {
    return getCurrentContext().getResources()
            .getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
}

From source file:Main.java

private static String getOrientation(Context ctx) {
    String orientation = "unknown";

    switch (ctx.getResources().getConfiguration().orientation) {
    case Configuration.ORIENTATION_LANDSCAPE:
        orientation = "landscape";
        break;/*from ww w .j av a 2s. c o  m*/
    case Configuration.ORIENTATION_PORTRAIT:
        orientation = "portrait";
        break;
    }

    return orientation;
}

From source file:Main.java

@SuppressLint("NewApi")
public static void lockScreenOrientation(Activity activity) {
    switch (activity.getResources().getConfiguration().orientation) {
    case Configuration.ORIENTATION_PORTRAIT:
        if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.FROYO) {
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        } else {//  ww  w .ja v a2s  .c  o m
            int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
            if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_180) {
                activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
            } else {
                activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            }
        }
        break;

    case Configuration.ORIENTATION_LANDSCAPE:
        if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.FROYO) {
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        } else {
            int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
            if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90) {
                activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            } else {
                activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
            }
        }
        break;
    }
}

From source file:Main.java

/**
 * Overall orientation of the screen./*w  ww  .  j a  va2s.  c o m*/
 * @param orientation "orientation"
 */
@SuppressWarnings("deprecation")
public static String getOrientationStr(int orientation) {
    switch (orientation) {
    case Configuration.ORIENTATION_UNDEFINED://0
        return "ORIENTATION_UNDEFINED";
    case Configuration.ORIENTATION_PORTRAIT://1
        return "ORIENTATION_PORTRAIT";
    case Configuration.ORIENTATION_LANDSCAPE://2
        return "ORIENTATION_LANDSCAPE";
    case Configuration.ORIENTATION_SQUARE://3
        return "ORIENTATION_SQUARE";
    default:
        return UNKNOWN;
    }
}

From source file:Main.java

public static int getScreenOrientation(Activity activity) {
    Display getOrient = activity.getWindowManager().getDefaultDisplay();
    int orientation = Configuration.ORIENTATION_UNDEFINED;
    if (getOrient.getWidth() == getOrient.getHeight()) {
        orientation = Configuration.ORIENTATION_SQUARE;
    } else {//from   w  w  w  .  j av  a  2  s  . c om
        if (getOrient.getWidth() < getOrient.getHeight()) {
            orientation = Configuration.ORIENTATION_PORTRAIT;
        } else {
            orientation = Configuration.ORIENTATION_LANDSCAPE;
        }
    }
    return orientation;
}

From source file:Main.java

/**
 * Untested, taken from stack-overflow.//w  w  w.  jav a  2s .  c o m
 *
 * @param activity
 */
public static void disableScreenOrientationChange(Activity activity) {
    final int orientation = activity.getResources().getConfiguration().orientation;
    final int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();

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

From source file:Main.java

public static int getScreenOrientation(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();

    int orientation = Configuration.ORIENTATION_UNDEFINED;
    if (display.getWidth() == display.getHeight()) {
        orientation = Configuration.ORIENTATION_SQUARE;
    } else {/*from w ww  . j a  va2  s  .  c  om*/
        if (display.getWidth() < display.getHeight()) {
            orientation = Configuration.ORIENTATION_PORTRAIT;
        } else {
            orientation = Configuration.ORIENTATION_LANDSCAPE;
        }
    }
    return orientation;
}