Example usage for android.view Surface ROTATION_90

List of usage examples for android.view Surface ROTATION_90

Introduction

In this page you can find the example usage for android.view Surface ROTATION_90.

Prototype

int ROTATION_90

To view the source code for android.view Surface ROTATION_90.

Click Source Link

Document

Rotation constant: 90 degree rotation.

Usage

From source file:org.telegram.ui.ChatActivity.java

@Override
public void onSizeChanged(int height) {
    Rect localRect = new Rect();
    parentActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(localRect);

    WindowManager manager = (WindowManager) ApplicationLoader.applicationContext
            .getSystemService(Activity.WINDOW_SERVICE);
    int rotation = manager.getDefaultDisplay().getRotation();

    if (height > Emoji.scale(50)) {
        if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) {
            keyboardHeightLand = height;
            parentActivity.getSharedPreferences("emoji", 0).edit()
                    .putInt("kbd_height_land3", keyboardHeightLand).commit();
        } else {//from w  ww  .jav a2s . c o  m
            keyboardHeight = height;
            parentActivity.getSharedPreferences("emoji", 0).edit().putInt("kbd_height", keyboardHeight)
                    .commit();
        }
    }

    if (emojiPopup != null && emojiPopup.isShowing()) {
        WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE);
        final WindowManager.LayoutParams layoutParams = (WindowManager.LayoutParams) emojiPopup.getContentView()
                .getLayoutParams();
        layoutParams.width = contentView.getWidth();
        if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) {
            layoutParams.height = keyboardHeightLand;
        } else {
            layoutParams.height = keyboardHeight;
        }
        wm.updateViewLayout(emojiPopup.getContentView(), layoutParams);
        if (!keyboardVisible) {
            contentView.post(new Runnable() {
                @Override
                public void run() {
                    contentView.setPadding(0, 0, 0, layoutParams.height);
                    contentView.requestLayout();
                }
            });
        }
    }

    boolean oldValue = keyboardVisible;
    keyboardVisible = height > 0;
    if (keyboardVisible && contentView.getPaddingBottom() > 0) {
        showEmojiPopup(false);
    } else if (!keyboardVisible && keyboardVisible != oldValue && emojiPopup != null
            && emojiPopup.isShowing()) {
        showEmojiPopup(false);
    }
}

From source file:com.almalence.opencam.ApplicationScreen.java

@Override
public void surfaceCreated(SurfaceHolder holder) {
    // ----- Find 'normal' orientation of the device

    Display display = ((WindowManager) this.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    int rotation = display.getRotation();
    if ((rotation == Surface.ROTATION_90) || (rotation == Surface.ROTATION_270))
        landscapeIsNormal = true; // false; - if landscape view orientation
    // set for ApplicationScreen
    else//  w ww .  j  av a 2s  .c o  m
        landscapeIsNormal = false;

    surfaceCreated = true;

    mCameraSurface = surfaceHolder.getSurface();
}

From source file:com.aujur.ebookreader.activity.ReadingFragment.java

@TargetApi(Build.VERSION_CODES.FROYO)
private boolean handleVolumeButtonEvent(KeyEvent event) {

    // Disable volume button handling during TTS
    if (!config.isVolumeKeyNavEnabled() || ttsIsRunning()) {
        return false;
    }/*from   www.  j  av a2s .  c o  m*/

    Activity activity = getActivity();

    if (activity == null) {
        return false;
    }

    boolean invert = false;

    int rotation = Surface.ROTATION_0;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
        Display display = activity.getWindowManager().getDefaultDisplay();
        rotation = display.getRotation();
    }

    switch (rotation) {
    case Surface.ROTATION_0:
    case Surface.ROTATION_90:
        invert = false;
        break;
    case Surface.ROTATION_180:
    case Surface.ROTATION_270:
        invert = true;
        break;
    }

    if (event.getAction() != KeyEvent.ACTION_DOWN) {
        return true;
    }

    if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) {
        if (invert) {
            pageDown(Orientation.HORIZONTAL);
        } else {
            pageUp(Orientation.HORIZONTAL);
        }
    } else if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN) {
        if (invert) {
            pageUp(Orientation.HORIZONTAL);
        } else {
            pageDown(Orientation.HORIZONTAL);
        }
    }

    return true;
}

From source file:net.zorgblub.typhon.fragment.ReadingFragment.java

@TargetApi(Build.VERSION_CODES.FROYO)
private boolean handleVolumeButtonEvent(KeyEvent event) {

    //Disable volume button handling during TTS
    if (!config.isVolumeKeyNavEnabled() || ttsIsRunning()) {
        return false;
    }// w  ww. j  a  v a 2 s  .c  om

    Activity activity = getActivity();

    if (activity == null) {
        return false;
    }

    boolean invert = false;

    int rotation = Surface.ROTATION_0;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
        Display display = activity.getWindowManager().getDefaultDisplay();
        rotation = display.getRotation();
    }

    switch (rotation) {
    case Surface.ROTATION_0:
    case Surface.ROTATION_90:
        invert = false;
        break;
    case Surface.ROTATION_180:
    case Surface.ROTATION_270:
        invert = true;
        break;
    }

    if (event.getAction() != KeyEvent.ACTION_DOWN) {
        return true;
    }

    if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) {
        if (config.isVolumeKeyNavChaptersEnabled()) {
            if (invert) {
                bookView.navigateForward();
            } else {
                bookView.navigateBack();
            }
        } else {
            if (invert) {
                pageDown(Orientation.HORIZONTAL);
            } else {
                pageUp(Orientation.HORIZONTAL);
            }
        }
    } else if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN) {
        if (config.isVolumeKeyNavChaptersEnabled()) {
            if (invert) {
                bookView.navigateBack();
            } else {
                bookView.navigateForward();
            }
        } else {
            if (invert) {
                pageUp(Orientation.HORIZONTAL);
            } else {
                pageDown(Orientation.HORIZONTAL);
            }
        }
    }

    return true;
}

From source file:com.aimfire.demo.CamcorderActivity.java

/**
 * get the default/natural device orientation. this should be PORTRAIT
 * for phones and LANDSCAPE for tablets// ww  w. j a  v  a 2s .  c om
 */
public int getDeviceDefaultOrientation() {
    WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);

    Configuration config = getResources().getConfiguration();

    int rotation = windowManager.getDefaultDisplay().getRotation();

    if (((rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180)
            && config.orientation == Configuration.ORIENTATION_LANDSCAPE)
            || ((rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270)
                    && config.orientation == Configuration.ORIENTATION_PORTRAIT)) {
        return Configuration.ORIENTATION_LANDSCAPE;
    } else {
        return Configuration.ORIENTATION_PORTRAIT;
    }
}

From source file:kr.wdream.ui.MediaActivity.java

private void fixLayoutInternal() {
    if (listView == null) {
        return;//from   ww  w .  j  av a2s .  co m
    }
    WindowManager manager = (WindowManager) ApplicationLoader.applicationContext
            .getSystemService(Activity.WINDOW_SERVICE);
    int rotation = manager.getDefaultDisplay().getRotation();

    if (!AndroidUtilities.isTablet() && ApplicationLoader.applicationContext.getResources()
            .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
        selectedMessagesCountTextView.setTextSize(18);
    } else {
        selectedMessagesCountTextView.setTextSize(20);
    }

    if (AndroidUtilities.isTablet()) {
        columnsCount = 4;
        emptyTextView.setPadding(AndroidUtilities.dp(40), 0, AndroidUtilities.dp(40), AndroidUtilities.dp(128));
    } else {
        if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) {
            columnsCount = 6;
            emptyTextView.setPadding(AndroidUtilities.dp(40), 0, AndroidUtilities.dp(40), 0);
        } else {
            columnsCount = 4;
            emptyTextView.setPadding(AndroidUtilities.dp(40), 0, AndroidUtilities.dp(40),
                    AndroidUtilities.dp(128));
        }
    }
    photoVideoAdapter.notifyDataSetChanged();

    if (dropDownContainer != null) {
        if (!AndroidUtilities.isTablet()) {
            FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) dropDownContainer
                    .getLayoutParams();
            layoutParams.topMargin = (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0);
            dropDownContainer.setLayoutParams(layoutParams);
        }

        if (!AndroidUtilities.isTablet() && ApplicationLoader.applicationContext.getResources()
                .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
            dropDown.setTextSize(18);
        } else {
            dropDown.setTextSize(20);
        }
    }
}

From source file:com.aimfire.demo.CamcorderActivity.java

/**
 * we fixed display to SCREEN_ORIENTATION_LANDSCAPE. but we don't know
 * how it is related to device's natural orientation. fortunately,
 * getDefaultDisplay().getRotation() tells us the information but with
 * a slight twist:// w ww. ja v  a 2s.  co m
 * 
 * Documentation for Display.getRotation: 
 *     Returns the rotation of the screen from its "natural" orientation. The 
 *     returned value may be Surface.ROTATION_0 (no rotation), 
 *     Surface.ROTATION_90, Surface.ROTATION_180, or Surface.ROTATION_270. 
 *     For example, if a device has a naturally tall screen, and the user has 
 *     turned it on its side to go into a landscape orientation, the value 
 *     returned here may be either Surface.ROTATION_90 or Surface.ROTATION_270 
 *     depending on the direction it was turned. The angle is the rotation of 
 *     the drawn graphics on the screen, which is the opposite direction of the 
 *     physical rotation of the device. For example, if the device is rotated 90 
 *     degrees counter-clockwise, to compensate rendering will be rotated by 90 
 *     degrees clockwise and thus the returned value here will be 
 *     Surface.ROTATION_90.
 * 
 * if we fix the display orientation, getRotation is going to tell us what the
 * fixed orientation is, relative to device natural orientation, regardless of
 * what the device's current, actual orientation is. and based on above, we need
 * to reverse the result from getRotation to get clockwise rotation
 */
public int getDeviceLandscapeOrientation() {
    int degrees = 0;
    int rotation = getWindowManager().getDefaultDisplay().getRotation();
    switch (rotation) {
    case Surface.ROTATION_0:
        degrees = 0;
        break;
    case Surface.ROTATION_90:
        degrees = 90;
        break;
    case Surface.ROTATION_180:
        degrees = 180;
        break; // this is not possible
    case Surface.ROTATION_270:
        degrees = 270;
        break;
    }
    // reverse the sign to get clockwise rotation
    return (360 - degrees) % 360;
}

From source file:com.aimfire.demo.CamcorderActivity.java

public void setCameraPreviewOrientation() {
    if (BuildConfig.DEBUG)
        Log.d(TAG, "setCameraPreviewOrientation");
    Camera.CameraInfo info = new Camera.CameraInfo();
    Camera.getCameraInfo(mCameraId, info);
    int rotation = getWindowManager().getDefaultDisplay().getRotation();
    int degrees = 0;
    switch (rotation) {
    case Surface.ROTATION_0:
        degrees = 0;//from   ww  w. j av a  2  s.  co m
        break;
    case Surface.ROTATION_90:
        degrees = 90;
        break;
    case Surface.ROTATION_180:
        degrees = 180;
        break;
    case Surface.ROTATION_270:
        degrees = 270;
        break;
    }

    int result;
    if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        // front-facing
        result = (info.orientation + degrees) % 360;
        result = (360 - result) % 360; // compensate the mirror
    } else {
        // back-facing
        result = (info.orientation - degrees + 360) % 360;
    }
    mCamera.setDisplayOrientation(result);
}

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

@TargetApi(Build.VERSION_CODES.GINGERBREAD)
private int getScreenOrientation() {
    switch (getScreenRotation()) {
    case Surface.ROTATION_0:
        return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
    case Surface.ROTATION_90:
        return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
    case Surface.ROTATION_180:
        // SCREEN_ORIENTATION_REVERSE_PORTRAIT only available since API Level 9+
        return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO
                ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT
                : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    case Surface.ROTATION_270:
        // SCREEN_ORIENTATION_REVERSE_LANDSCAPE only available since API Level 9+
        return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO
                ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
                : ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    default:/*from w  w  w  .j  ava  2s  .co  m*/
        return 0;
    }
}

From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java

public String GetRotationInfo() {
    WindowManager wMgr = (WindowManager) contextWrapper.getSystemService(Context.WINDOW_SERVICE);
    int nRotationDegrees = 0; // default
    switch (wMgr.getDefaultDisplay().getRotation()) {
    case Surface.ROTATION_90:
        nRotationDegrees = 90;//from  w  w w. j  ava2  s  .co  m
        break;
    case Surface.ROTATION_180:
        nRotationDegrees = 180;
        break;
    case Surface.ROTATION_270:
        nRotationDegrees = 270;
        break;
    }
    return "ROTATION:" + nRotationDegrees;
}