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:com.waz.zclient.pages.main.conversation.SingleImageFragment.java

@SuppressWarnings("WrongConstant")
private void restoreRotation() {
    Activity activity = getActivity();
    if (activity != null) {
        activity.setRequestedOrientation(activityOrientation);
    }/*from  ww w  .  ja v  a  2s.co  m*/
}

From source file:com.ferdi2005.secondgram.AndroidUtilities.java

public static void unlockOrientation(Activity activity) {
    if (activity == null) {
        return;//from   www.  ja  v  a  2s. co m
    }
    try {
        if (prevOrientation != -10) {
            activity.setRequestedOrientation(prevOrientation);
            prevOrientation = -10;
        }
    } catch (Exception e) {
        FileLog.e(e);
    }
}

From source file:org.apache.cordova.screenorientation.ScreenOrientation.java

/**
 * Executes the request and returns whether the action was valid.
 *
 * @param action                 The action to execute.
 * @param args                 JSONArray of arguments for the plugin.
 * @param callbackContext        The callback context used when calling back into JavaScript.
 * @return                         True if the action was valid, false otherwise.
 *//*from ww w .jav a  2 s .co  m*/
public boolean execute(String action, final JSONArray args, final CallbackContext callbackContext)
        throws JSONException {
    final String orientation = args.optString(0);
    final Activity activity = this.cordova.getActivity();
    final View view = this.webView;

    if (action.equals("setOrientation")) {
        LOG.w("ScreenOrientation", "Change orientation");
        final int androidOrientation = getOrientation(orientation);
        if (lastOrientation == -1) {
            lastOrientation = androidOrientation;
        }

        if (lastOrientation != androidOrientation) {
            activity.runOnUiThread(new Runnable() {
                public void run() {
                    LOG.v("ScreenOrientation", "Set orientation");
                    view.setVisibility(View.INVISIBLE);
                    activity.setRequestedOrientation(androidOrientation);

                    final Handler handler = new Handler();
                    handler.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            view.setVisibility(View.VISIBLE);
                        }
                    }, 1300);
                }
            });
            lastOrientation = androidOrientation;
        }

        callbackContext.success();
        return true;
    } else {
        return false;
    }
}

From source file:com.waz.zclient.pages.main.conversation.SingleImageFragment.java

@Override
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
protected void onPostAttach(Activity activity) {
    super.onPostAttach(activity);
    activityOrientation = activity.getRequestedOrientation();
    activity.setRequestedOrientation(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2
            ? ActivityInfo.SCREEN_ORIENTATION_FULL_USER
            : ActivityInfo.SCREEN_ORIENTATION_USER);
}

From source file:com.android.purenexussettings.TinkerActivity.java

public static void lockCurrentOrientation(Activity activity) {
    int currentRotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    int orientation = activity.getResources().getConfiguration().orientation;
    int frozenRotation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
    switch (currentRotation) {
    case Surface.ROTATION_0:
        frozenRotation = orientation == Configuration.ORIENTATION_LANDSCAPE
                ? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
                : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
        break;/*from  w ww. j a v  a2s.  c om*/
    case Surface.ROTATION_90:
        frozenRotation = orientation == Configuration.ORIENTATION_PORTRAIT
                ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT
                : ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
        break;
    case Surface.ROTATION_180:
        frozenRotation = orientation == Configuration.ORIENTATION_LANDSCAPE
                ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
                : ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
        break;
    case Surface.ROTATION_270:
        frozenRotation = orientation == Configuration.ORIENTATION_PORTRAIT
                ? ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
                : ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
        break;
    }
    activity.setRequestedOrientation(frozenRotation);
}

From source file:io.selendroid.server.model.DefaultSelendroidDriver.java

public void rotate(final ScreenOrientation orientation) {
    final Activity activity = serverInstrumentation.getCurrentActivity();
    if (activity == null) {
        return;// w  w w  . j  a  v  a2 s  .  c om
    }
    final int screenOrientation = getAndroidScreenOrientation(orientation);
    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            activity.setRequestedOrientation(screenOrientation);
        }
    });
    serverInstrumentation.waitForIdleSync();
}

From source file:kr.wdream.storyshop.AndroidUtilities.java

public static void lockOrientation(Activity activity) {
    if (activity == null || prevOrientation != -10) {
        return;//from  w ww. java 2s.c o  m
    }
    try {
        prevOrientation = activity.getRequestedOrientation();
        WindowManager manager = (WindowManager) activity.getSystemService(Activity.WINDOW_SERVICE);
        if (manager != null && manager.getDefaultDisplay() != null) {
            int rotation = manager.getDefaultDisplay().getRotation();
            int orientation = activity.getResources().getConfiguration().orientation;

            if (rotation == Surface.ROTATION_270) {
                if (orientation == Configuration.ORIENTATION_PORTRAIT) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
                }
            } else if (rotation == Surface.ROTATION_90) {
                if (orientation == Configuration.ORIENTATION_PORTRAIT) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                }
            } else if (rotation == Surface.ROTATION_0) {
                if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                }
            } else {
                if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
                }
            }
        }
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
}

From source file:im.ene.lab.toro.ext.layeredvideo.PlaybackControlLayer.java

/**
 * Fullscreen mode will rotate to landscape mode, hide the action bar, hide the navigation bar,
 * hide the system tray, and make the video player take up the full size of the display.
 * The developer who is using this function must ensure the following:
 *
 * <p>1) Inside the android manifest, the activity that uses the video player has the attribute
 * android:configChanges="orientation"./*from   ww  w .  j av  a2 s .  c o  m*/
 *
 * <p>2) Other views in the activity (or fragment) are
 * hidden (or made visible) when this method is called.
 */
public void doToggleFullscreen() {
    // If there is no callback for handling fullscreen, don't do anything.
    if (fullscreenCallback == null) {
        return;
    }

    ObservablePlayerControl playerControl = layerManager.getControl();
    if (playerControl == null) {
        return;
    }

    Activity activity = layerManager.getActivity();
    FrameLayout container = layerManager.getContainer();

    if (isFullscreen) {
        activity.setRequestedOrientation(savedOrientation);

        // Make the status bar and navigation bar visible again.
        activity.getWindow().getDecorView().setSystemUiVisibility(0);

        container.setLayoutParams(originalContainerLayoutParams);

        fullscreenButton.setImageResource(R.drawable.toro_ext_ic_fullscreen_enter);

        fullscreenCallback.onReturnFromFullscreen();
        isFullscreen = false;
    } else {
        savedOrientation = activity.getResources().getConfiguration().orientation;
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

        activity.getWindow().getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

        container.setLayoutParams(PlayerUtil.getLayoutParamsBasedOnParent(container,
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

        fullscreenButton.setImageResource(R.drawable.toro_ext_ic_fullscreen_exit);
        fullscreenCallback.onGoToFullscreen();
        isFullscreen = true;
    }
}

From source file:com.ferdi2005.secondgram.AndroidUtilities.java

public static void lockOrientation(Activity activity) {
    if (activity == null || prevOrientation != -10) {
        return;//from   w ww .  j av a2s  .  co  m
    }
    try {
        prevOrientation = activity.getRequestedOrientation();
        WindowManager manager = (WindowManager) activity.getSystemService(Activity.WINDOW_SERVICE);
        if (manager != null && manager.getDefaultDisplay() != null) {
            int rotation = manager.getDefaultDisplay().getRotation();
            int orientation = activity.getResources().getConfiguration().orientation;

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

From source file:jmri.enginedriver.threaded_application.java

public boolean setActivityOrientation(Activity activity, Boolean webPref) {
    String to;/*from   w  w w. j  a v a 2 s.  c o m*/
    to = prefs.getString("ThrottleOrientation", activity.getApplicationContext().getResources()
            .getString(R.string.prefThrottleOrientationDefaultValue));
    if (to.equals("Auto-Web")) {
        int orient = activity.getResources().getConfiguration().orientation;
        if ((webPref && orient == Configuration.ORIENTATION_PORTRAIT)
                || (!webPref && orient == Configuration.ORIENTATION_LANDSCAPE))
            return (false);
    } else if (webPref) {
        to = prefs.getString("WebOrientation", activity.getApplicationContext().getResources()
                .getString(R.string.prefWebOrientationDefaultValue));
    }

    int co = activity.getRequestedOrientation();
    if (to.equals("Landscape") && (co != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE))
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    else if (to.equals("Auto-Rotate") && (co != ActivityInfo.SCREEN_ORIENTATION_SENSOR))
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
    else if (to.equals("Portrait") && (co != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT))
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    return true;
}