Example usage for android.view Surface ROTATION_270

List of usage examples for android.view Surface ROTATION_270

Introduction

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

Prototype

int ROTATION_270

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

Click Source Link

Document

Rotation constant: 270 degree rotation.

Usage

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

private void fixLayoutInternal() {
    if (listView == null) {
        return;//  w w w .  j a  v  a 2s .  c o  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

/**
 * get the default/natural device orientation. this should be PORTRAIT
 * for phones and LANDSCAPE for tablets//from  w  w  w  .  j av  a 2 s  .com
 */
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: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:/*from w w w.jav a 2  s  . 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  w w w  .j  a  v a2s .  c  om*/
        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  ww.  j  a  v  a2 s . c o 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;/* ww w.j  a  v  a 2 s .  c o m*/
        break;
    case Surface.ROTATION_180:
        nRotationDegrees = 180;
        break;
    case Surface.ROTATION_270:
        nRotationDegrees = 270;
        break;
    }
    return "ROTATION:" + nRotationDegrees;
}

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

private void showEmojiPopup(boolean show) {
    if (parentActivity == null) {
        return;// w ww . j a  va2s  .c o m
    }
    InputMethodManager localInputMethodManager = (InputMethodManager) parentActivity
            .getSystemService("input_method");
    if (show) {
        if (emojiPopup == null) {
            createEmojiPopup();
        }
        int currentHeight;
        WindowManager manager = (WindowManager) ApplicationLoader.applicationContext
                .getSystemService(Activity.WINDOW_SERVICE);
        int rotation = manager.getDefaultDisplay().getRotation();
        if (keyboardHeight <= 0) {
            keyboardHeight = parentActivity.getSharedPreferences("emoji", 0).getInt("kbd_height",
                    Emoji.scale(200.0f));
        }
        if (keyboardHeightLand <= 0) {
            keyboardHeightLand = parentActivity.getSharedPreferences("emoji", 0).getInt("kbd_height_land3",
                    Emoji.scale(200.0f));
        }
        if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) {
            currentHeight = keyboardHeightLand;
        } else {
            currentHeight = keyboardHeight;
        }
        emojiPopup.setHeight(View.MeasureSpec.makeMeasureSpec(currentHeight, View.MeasureSpec.EXACTLY));
        emojiPopup.setWidth(View.MeasureSpec.makeMeasureSpec(contentView.getWidth(), View.MeasureSpec.EXACTLY));

        emojiPopup.showAtLocation(parentActivity.getWindow().getDecorView(), 83, 0, 0);
        if (!keyboardVisible) {
            contentView.setPadding(0, 0, 0, currentHeight);
            emojiButton.setImageResource(R.drawable.ic_msg_panel_hide);
            return;
        }
        emojiButton.setImageResource(R.drawable.ic_msg_panel_kb);
        return;
    }
    if (emojiButton != null) {
        emojiButton.setImageResource(R.drawable.ic_msg_panel_smiles);
    }
    if (emojiPopup != null) {
        emojiPopup.dismiss();
    }
    if (contentView != null) {
        contentView.post(new Runnable() {
            public void run() {
                if (contentView != null) {
                    contentView.setPadding(0, 0, 0, 0);
                }
            }
        });
    }
}

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

private void fixLayout() {
    if (chatListView != null) {
        ViewTreeObserver obs = chatListView.getViewTreeObserver();
        obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
            @Override// w w  w  .  j a va 2  s .  c  o  m
            public boolean onPreDraw() {
                if (parentActivity == null) {
                    chatListView.getViewTreeObserver().removeOnPreDrawListener(this);
                    return false;
                }
                WindowManager manager = (WindowManager) ApplicationLoader.applicationContext
                        .getSystemService(Activity.WINDOW_SERVICE);
                Display display = manager.getDefaultDisplay();
                int rotation = display.getRotation();
                int height;
                int currentActionBarHeight = parentActivity.getSupportActionBar().getHeight();

                if (currentActionBarHeight != Utilities.dp(48) && currentActionBarHeight != Utilities.dp(40)) {
                    height = currentActionBarHeight;
                } else {
                    height = Utilities.dp(48);
                    if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) {
                        height = Utilities.dp(40);
                    }
                }

                if (avatarImageView != null) {
                    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) avatarImageView
                            .getLayoutParams();
                    params.width = height;
                    params.height = height;
                    avatarImageView.setLayoutParams(params);
                }

                chatListView.getViewTreeObserver().removeOnPreDrawListener(this);

                if (currentEncryptedChat != null) {
                    TextView title = (TextView) parentActivity.findViewById(R.id.action_bar_title);
                    if (title == null) {
                        final int subtitleId = parentActivity.getResources().getIdentifier("action_bar_title",
                                "id", "android");
                        title = (TextView) parentActivity.findViewById(subtitleId);
                    }
                    if (title != null) {
                        title.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_lock_white, 0, 0, 0);
                        title.setCompoundDrawablePadding(Utilities.dp(4));
                    }
                }

                return false;
            }
        });
    }
}

From source file:com.android.launcher2.Launcher.java

private int mapConfigurationOriActivityInfoOri(int configOri) {
    final Display d = getWindowManager().getDefaultDisplay();
    int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
    switch (d.getRotation()) {
    case Surface.ROTATION_0:
    case Surface.ROTATION_180:
        // We are currently in the same basic orientation as the natural orientation
        naturalOri = configOri;//from www  . j  a v  a  2s . c  om
        break;
    case Surface.ROTATION_90:
    case Surface.ROTATION_270:
        // We are currently in the other basic orientation to the natural orientation
        naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ? Configuration.ORIENTATION_PORTRAIT
                : Configuration.ORIENTATION_LANDSCAPE;
        break;
    }

    int[] oriMap = { ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
            ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
            ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE };
    // Since the map starts at portrait, we need to offset if this device's natural orientation
    // is landscape.
    int indexOffset = 0;
    if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
        indexOffset = 1;
    }
    return oriMap[(d.getRotation() + indexOffset) % 4];
}