Example usage for android.app Activity setRequestedOrientation

List of usage examples for android.app Activity setRequestedOrientation

Introduction

In this page you can find the example usage for android.app Activity setRequestedOrientation.

Prototype

public void setRequestedOrientation(@ActivityInfo.ScreenOrientation int requestedOrientation) 

Source Link

Document

Change the desired orientation of this activity.

Usage

From source file:Main.java

/**
 * Rotates the given activity./* w  w  w .  j a  v a2s. 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 void restoreOrientation(Activity activity, int orientation) {
    if (activity != null) {
        activity.setRequestedOrientation(orientation);
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
    }/*w w w  . j  a  va  2s .  c o m*/
}

From source file:Main.java

public static void setPortraitOrientation(final Activity activity, final boolean portrait) {
    if (portrait) {
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    } else {//from  w w w.  j  a v a 2s.  c  om
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
    }
}

From source file:Main.java

/**
 * Sets the orientation enabled to true or false in this case true  if tablet false if mobile device
 * @param activity//from  www.j  a va2  s  .co  m
 */
public static void setProtraitOrientationEnabled(Activity activity) {
    if (!(isScreenXLarge(activity))) {

        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
}

From source file:Main.java

public static void unlockScreenOrientation(final Activity context) {
    boolean portrait = false;
    if (!portrait) {
        context.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
    }//  ww w.j  a  va  2  s  .co  m
}

From source file:Main.java

public static void setOrientation(Activity context, int mode) {
    // ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
    context.setRequestedOrientation(mode);
}

From source file:Main.java

public static void initialize(Activity activity, int layout) {
    // Do all sorts of common task for your activities here including:
    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
    activity.setContentView(layout);//from w  w  w . j  ava  2 s.c  om
    activity.getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);
    activity.getActionBar().setDisplayOptions(
            ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM);
    activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}

From source file:Main.java

public static void rotateScreen(Activity activity) {
    if (activity.getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    } else {/*from w  ww  .j  a  va2 s .  co m*/
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
}

From source file:Main.java

private static void changeOrientation(final Activity activity, Instrumentation instrumentation,
        final int orientation) {
    activity.setRequestedOrientation(orientation);
    if (instrumentation != null) {
        instrumentation.waitForIdleSync();
    }//from  ww  w.  j a va2 s  . c o m
}

From source file:Main.java

public static void OrientationFix(Activity context, boolean fixOrient) {
    if (fixOrient) {
        int ori = context.getResources().getConfiguration().orientation;
        if (ori == Configuration.ORIENTATION_LANDSCAPE) {
            context.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        } else {//from  w w w  .  j  a  v a  2s .c om
            context.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
    } else {
        context.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
    }
}