Example usage for android.view Surface ROTATION_180

List of usage examples for android.view Surface ROTATION_180

Introduction

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

Prototype

int ROTATION_180

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

Click Source Link

Document

Rotation constant: 180 degree rotation.

Usage

From source file:Main.java

/**
 * Calculates the clockwise rotation applied to the camera such that the picture will be aligned with the screen
 * orientation./*from   ww  w.  ja v  a2 s  . c  o m*/
 *
 * @param activity the {@link Activity}.
 * @param cameraId id of the camera.
 * @return the clockwise rotation in degrees.
 */
public static int getCameraScreenOrientation(Activity activity, int cameraId) {
    int cameraScreenOrientation = CAMERA_SCREEN_ORIENTATION_0;

    // Get camera info.
    CameraInfo info = new CameraInfo();
    Camera.getCameraInfo(cameraId, info);

    // Get screen orientation.
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    int degrees = SCREEN_ROTATION_0;
    switch (rotation) {
    case Surface.ROTATION_0:
        degrees = SCREEN_ROTATION_0;
        break;
    case Surface.ROTATION_90:
        degrees = SCREEN_ROTATION_90;
        break;
    case Surface.ROTATION_180:
        degrees = SCREEN_ROTATION_180;
        break;
    case Surface.ROTATION_270:
        degrees = SCREEN_ROTATION_270;
        break;
    }

    /*
     * Calculate result based on camera and screen orientation.
     */
    if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        // Calculate relative rotation between camera and screen.
        cameraScreenOrientation = (info.orientation + degrees) % 360;

        // Account for mirroring.
        cameraScreenOrientation = (360 - cameraScreenOrientation) % 360;
    } else {
        // Calculate relative rotation between camera and screen.
        cameraScreenOrientation = (info.orientation - degrees + 360) % 360;
    }

    return cameraScreenOrientation;
}

From source file:org.chromium.ChromeSystemDisplay.java

private int getRotation(final Display display) {
    final int rotation = display.getRotation();
    final int DEFAULT_ROTATION = 0;

    if (rotation == Surface.ROTATION_0) {
        return 0;
    } else if (rotation == Surface.ROTATION_90) {
        return 90;
    } else if (rotation == Surface.ROTATION_180) {
        return 180;
    } else if (rotation == Surface.ROTATION_270) {
        return 270;
    }//  ww  w  . j a  v a2  s . c om
    return DEFAULT_ROTATION;
}

From source file:com.mruddy.devdataviewer.DevDataListFragment.java

@SuppressLint("InlinedApi")
private static void initMaps() {
    DevDataListFragment.DENSITY_BUCKETS.append(DisplayMetrics.DENSITY_LOW, "LDPI");
    DevDataListFragment.DENSITY_BUCKETS.append(DisplayMetrics.DENSITY_MEDIUM, "MDPI");
    DevDataListFragment.DENSITY_BUCKETS.append(DisplayMetrics.DENSITY_HIGH, "HDPI");
    DevDataListFragment.DENSITY_BUCKETS.append(DisplayMetrics.DENSITY_XHIGH, "XHDPI");
    DevDataListFragment.DENSITY_BUCKETS.append(DisplayMetrics.DENSITY_XXHIGH, "XXHDPI");
    DevDataListFragment.DENSITY_BUCKETS.append(DisplayMetrics.DENSITY_XXXHIGH, "XXXHDPI");
    DevDataListFragment.ROTATION.append(Surface.ROTATION_0, "0");
    DevDataListFragment.ROTATION.append(Surface.ROTATION_90, "90");
    DevDataListFragment.ROTATION.append(Surface.ROTATION_180, "180");
    DevDataListFragment.ROTATION.append(Surface.ROTATION_270, "270");
    DevDataListFragment.ORIENTATION.append(Configuration.ORIENTATION_UNDEFINED, "undefined");
    DevDataListFragment.ORIENTATION.append(Configuration.ORIENTATION_PORTRAIT, "portrait");
    DevDataListFragment.ORIENTATION.append(Configuration.ORIENTATION_LANDSCAPE, "landscape");
    DevDataListFragment.SCREEN_SIZE_BUCKETS.append(Configuration.SCREENLAYOUT_SIZE_UNDEFINED, "undefined");
    DevDataListFragment.SCREEN_SIZE_BUCKETS.append(Configuration.SCREENLAYOUT_SIZE_SMALL, "small");
    DevDataListFragment.SCREEN_SIZE_BUCKETS.append(Configuration.SCREENLAYOUT_SIZE_NORMAL, "normal");
    DevDataListFragment.SCREEN_SIZE_BUCKETS.append(Configuration.SCREENLAYOUT_SIZE_LARGE, "large");
    DevDataListFragment.SCREEN_SIZE_BUCKETS.append(Configuration.SCREENLAYOUT_SIZE_XLARGE, "xlarge");
}

From source file:me.wimanacra.collector.DisplayManagerCollector.java

@NonNull
private static String rotationToString(int rotation) {
    switch (rotation) {
    case Surface.ROTATION_0:
        return "ROTATION_0";
    case Surface.ROTATION_90:
        return "ROTATION_90";
    case Surface.ROTATION_180:
        return "ROTATION_180";
    case Surface.ROTATION_270:
        return "ROTATION_270";
    default:/*from w  ww  . ja  v  a  2 s  . c o m*/
        return String.valueOf(rotation);
    }
}

From source file:com.jwork.spycamera.SpyCamActivity.java

private void getDefaultOrientation() {
    int rotation = getWindowManager().getDefaultDisplay().getRotation();
    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    //If Naturally landscape (tablets)
    log.v(this, "Display pixels: " + dm.widthPixels + "x" + dm.heightPixels + "|Rotation:" + rotation);
    if (((rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180)
            && dm.widthPixels > dm.heightPixels)
            || ((rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270)
                    && dm.widthPixels < dm.heightPixels)) {
        rotation += 1;//from   w w w  .  ja  v  a2s.com
        if (rotation > 3) {
            rotation = 0;
        }
    }
    switch (rotation) {
    case Surface.ROTATION_0:
        defaultOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
        break;
    case Surface.ROTATION_90:
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO) {
            defaultOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE;
        } else {
            defaultOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
            setRequestedOrientation(defaultOrientation);
        }
        break;
    case Surface.ROTATION_180:
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO) {
            defaultOrientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
        } else {
            defaultOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
            setRequestedOrientation(defaultOrientation);
        }
        break;
    case Surface.ROTATION_270:
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO) {
            defaultOrientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
        } else {
            defaultOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
            setRequestedOrientation(defaultOrientation);
        }
        break;
    }
}

From source file:org.kontalk.util.SystemUtils.java

/**
 * Returns the correct screen orientation based on the supposedly preferred
 * position of the device.//  www.ja va  2 s  .com
 * http://stackoverflow.com/a/16585072/1045199
 */
public static int getScreenOrientation(Activity activity) {
    WindowManager windowManager = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
    Configuration configuration = activity.getResources().getConfiguration();
    int rotation = windowManager.getDefaultDisplay().getRotation();

    // Search for the natural position of the device
    if (configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
            && (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180)
            || configuration.orientation == Configuration.ORIENTATION_PORTRAIT
                    && (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270)) {
        // Natural position is Landscape
        switch (rotation) {
        case Surface.ROTATION_0:
            return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
        case Surface.ROTATION_90:
            return ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
        case Surface.ROTATION_180:
            return ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
        case Surface.ROTATION_270:
            return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
        }
    } else {
        // Natural position is Portrait
        switch (rotation) {
        case Surface.ROTATION_0:
            return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
        case Surface.ROTATION_90:
            return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
        case Surface.ROTATION_180:
            return ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
        case Surface.ROTATION_270:
            return ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
        }
    }

    return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
}

From source file:mobi.cangol.mobile.navigation.DrawerMenuLayout.java

private void fitDecorChild(View view) {
    ViewGroup contentView = (ViewGroup) view.findViewById(R.id.actionbar_content_view);
    if (contentView != null) {
        ViewGroup decorChild = (ViewGroup) contentView.getChildAt(0);
        if (decorChild != null) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                WindowManager manager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
                FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) decorChild.getLayoutParams();
                switch (manager.getDefaultDisplay().getRotation()) {
                case Surface.ROTATION_90:
                    layoutParams.rightMargin = 0;
                    break;
                case Surface.ROTATION_180:
                    layoutParams.topMargin = 0;
                    break;
                case Surface.ROTATION_270:
                    layoutParams.leftMargin = 0;
                    break;
                default:
                    layoutParams.bottomMargin = 0;
                }/*  w  w w .  ja va  2 s  . c  om*/
                decorChild.setLayoutParams(layoutParams);
            }
        }
    }
}

From source file:com.google.android.apps.santatracker.games.SplashActivity.java

@Override
protected void onStart() {
    super.onStart();

    // Orientation
    boolean gameIsLandscape = getIntent().getBooleanExtra(EXTRA_LANDSCAPE, false);
    boolean isLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
    Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    int rotation = display.getRotation();

    // Figure out how many degrees to rotate
    // Landscape always wants to be at 90degrees, portrait always wants to be at 0degrees
    float degreesToRotate = 0f;
    if (rotation == Surface.ROTATION_0) {
        degreesToRotate = gameIsLandscape && !isLandscape ? 90.0f : 0.0f;
    } else if (rotation == Surface.ROTATION_90) {
        degreesToRotate = gameIsLandscape && isLandscape ? 0f : -90f;
    } else if (rotation == Surface.ROTATION_180) {
        degreesToRotate = gameIsLandscape && !isLandscape ? -90f : -180f;
    } else if (rotation == Surface.ROTATION_270) {
        degreesToRotate = gameIsLandscape && isLandscape ? -180f : -270f;
    }/*from   ww  w  . ja v  a  2 s . c om*/

    // On a TV, should always be 0
    if (isRunningOnTV()) {
        degreesToRotate = 0f;
    }

    // Rotate, if necessary
    if (degreesToRotate != 0) {
        Point size = new Point();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            display.getRealSize(size);
        } else {
            display.getSize(size);
        }
        int w = size.x;
        int h = size.y;

        View mainLayout = findViewById(R.id.splash_layout);
        mainLayout.setRotation(degreesToRotate);
        mainLayout.setTranslationX((w - h) / 2);
        mainLayout.setTranslationY((h - w) / 2);

        ViewGroup.LayoutParams lp = mainLayout.getLayoutParams();
        lp.height = w;
        lp.width = h;

        mainLayout.requestLayout();
    }
}

From source file:tw.com.sti.store.api.android.AndroidApiService.java

private AndroidApiService(Context context, Configuration config) {
    this.config = config;
    this.apiUrl = new ApiUrl(config);
    if (Logger.DEBUG)
        L.d("new ApiService()");

    sdkVer = Build.VERSION.SDK;//from w w  w. j a  va2 s. c o m
    sdkRel = Build.VERSION.RELEASE;
    try {
        PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(),
                PackageManager.GET_ACTIVITIES);
        storeId = pi.packageName;
        clientVer = "" + pi.versionCode;
    } catch (NameNotFoundException e) {
    }
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    deviceId = tm.getDeviceId() == null ? "0" : tm.getDeviceId();
    macAddress = NetworkUtils.getDeviceMacAddress(context);
    subscriberId = tm.getSubscriberId() == null ? "0" : tm.getSubscriberId();
    simSerialNumber = tm.getSimSerialNumber() == null ? "0" : tm.getSimSerialNumber();

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    try {
        Class<Display> cls = Display.class;
        Method method = cls.getMethod("getRotation");
        Object retobj = method.invoke(display);
        int rotation = Integer.parseInt(retobj.toString());
        if (Surface.ROTATION_0 == rotation || Surface.ROTATION_180 == rotation) {
            wpx = "" + display.getWidth();
            hpx = "" + display.getHeight();
        } else {
            wpx = "" + display.getHeight();
            hpx = "" + display.getWidth();
        }
    } catch (Exception e) {
        if (display.getOrientation() == 1) {
            wpx = "" + display.getHeight();
            hpx = "" + display.getWidth();
        } else {
            wpx = "" + display.getWidth();
            hpx = "" + display.getHeight();
        }
    }

    SharedPreferences pref = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
    //      token = pref.getString(PREF_KEY_TOKEN, "");
    //      uid = pref.getString(PREF_KEY_UID, "");
    //      userId = pref.getString(PREF_KEY_USER_ID, "");
    appFilter = pref.getInt(PREF_KEY_APP_FILTER, 0);
    // ipLoginEnable = pref.getBoolean(PREF_KEY_IP_LOGIN_ENABLE, true);

    // ??SIM?
    String pref_subscriberId = pref.getString(PREF_KEY_SUBSCRIBER_ID, "0");
    String pref_simSerialNumber = pref.getString(PREF_KEY_SIM_SERIAL_NUMBER, "0");
    if (!subscriberId.equals(pref_subscriberId) || !simSerialNumber.equals(pref_simSerialNumber)) {
        if (Logger.DEBUG)
            L.d("Change SIM card.");
        cleanCredential(context);
    }
    this.getCredential(context);
}

From source file:mobi.cangol.mobile.navigation.SlidingMenuLayout.java

private void fitPadding(Rect rect) {
    boolean hasNavigationBar = checkDeviceHasNavigationBar();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && hasNavigationBar) {
        WindowManager manager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
        switch (manager.getDefaultDisplay().getRotation()) {
        case Surface.ROTATION_90:
            rect.right += getNavBarWidth();
            break;
        case Surface.ROTATION_180:
            rect.top += getNavBarHeight();
            break;
        case Surface.ROTATION_270:
            rect.left += getNavBarWidth();
            break;
        default://www . ja  va 2  s  .c om
            rect.bottom += getNavBarHeight();
        }
    }
    mContentView.setPadding(rect.left, rect.top, rect.right, rect.bottom);
    mMenuView.setPadding(rect.left, rect.top, rect.right, rect.bottom);
}