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:com.jasompeter.openalpr.CameraActivity.java

public void setCorrectOrientation(Camera camera) {
    int displayRotation = getWindowManager().getDefaultDisplay().getRotation();

    int degrees = 0;
    switch (displayRotation) {
    case Surface.ROTATION_0:
        degrees = 0;/*  w ww  . j  ava 2s. co m*/
        break;
    case Surface.ROTATION_90:
        degrees = 90;
        break;
    case Surface.ROTATION_180:
        degrees = 180;
        break;
    case Surface.ROTATION_270:
        degrees = 270;
        break;
    }

    Camera.CameraInfo cameraInfo = getCurrentCameraInfo();
    int resultDegrees;
    if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        resultDegrees = (cameraInfo.orientation + degrees) % 360;
        resultDegrees = (360 - resultDegrees) % 360;
    } else {
        resultDegrees = (cameraInfo.orientation - degrees + 360) % 360;
    }

    camera.setDisplayOrientation(resultDegrees);

    Camera.Parameters parameters = camera.getParameters();
    parameters.setRotation(resultDegrees);
    camera.setParameters(parameters);
}

From source file:com.almalence.util.Util.java

public static int getDisplayRotation(Activity activity) {
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    switch (rotation) {
    case Surface.ROTATION_0:
        return 0;
    case Surface.ROTATION_90:
        return 90;
    case Surface.ROTATION_180:
        return 180;
    case Surface.ROTATION_270:
        return 270;
    default:/*w  w  w . j  a  v  a 2  s . c om*/
        break;
    }
    return 0;
}

From source file:com.nextgis.maplibui.util.ControlHelper.java

@TargetApi(Build.VERSION_CODES.GINGERBREAD)
public static void lockScreenOrientation(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:
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            break;
        case Surface.ROTATION_90:
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
            break;
        case Surface.ROTATION_180:
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
            break;
        case Surface.ROTATION_270:
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            break;
        }//from w w  w.  ja  v a 2s  .  c  om
    } else {
        // Natural position is Portrait
        switch (rotation) {
        case Surface.ROTATION_0:
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            break;
        case Surface.ROTATION_90:
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            break;
        case Surface.ROTATION_180:
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
            break;
        case Surface.ROTATION_270:
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
            break;
        }
    }
}

From source file:com.metinkale.prayerapp.compass.Main.java

@Override
public void onRotationUpdate(float[] newMatrix) {
    if (mMode == Mode.Map) {
        return;// w w  w.  ja v a2s  .  com
    }
    // remap matrix values according to display rotation, as in
    // SensorManager documentation.
    switch (mDisplayRotation) {
    case Surface.ROTATION_0:
    case Surface.ROTATION_180:
        break;
    case Surface.ROTATION_90:
        SensorManager.remapCoordinateSystem(newMatrix, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X,
                newMatrix);
        break;
    case Surface.ROTATION_270:
        SensorManager.remapCoordinateSystem(newMatrix, SensorManager.AXIS_MINUS_Y, SensorManager.AXIS_X,
                newMatrix);
        break;
    default:
        break;
    }
    mRotationMatrix.set(newMatrix);
    mOrientationCalculator.getOrientation(mRotationMatrix, mDisplayRotation, mDerivedDeviceOrientation);

    updateFrag((mDerivedDeviceOrientation[1] > -55f) ? Mode.ThreeDim : Mode.TwoDim);

    mList.onUpdateSensors(mDerivedDeviceOrientation);
}

From source file:com.tritop.androsense2.fragments.GpsFragment.java

@Override
public void onSensorChanged(SensorEvent event) {
    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        mAccel = event.values;/*from   w ww  .j  ava2 s. co  m*/
    }
    if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
        mMag = event.values;
    }
    if ((mAccel != null) && (mMag != null)) {
        float R[] = new float[9];
        float I[] = new float[9];
        float Rot[] = new float[9];
        if (SensorManager.getRotationMatrix(R, I, mAccel, mMag)) {
            float orientation[] = new float[3];
            int axisX = 0, axisY = 0;
            switch (display.getRotation()) {
            case Surface.ROTATION_0:
                axisX = SensorManager.AXIS_X;
                axisY = SensorManager.AXIS_Y;
                break;
            case Surface.ROTATION_90:
                axisX = SensorManager.AXIS_Y;
                axisY = SensorManager.AXIS_MINUS_X;
                break;
            case Surface.ROTATION_180:
                axisX = SensorManager.AXIS_MINUS_X;
                axisY = SensorManager.AXIS_MINUS_Y;
                break;
            case Surface.ROTATION_270:
                axisX = SensorManager.AXIS_MINUS_Y;
                axisY = SensorManager.AXIS_X;
                break;
            default:
                break;
            }

            SensorManager.remapCoordinateSystem(R, axisX, axisY, Rot);
            SensorManager.getOrientation(Rot, orientation);
            aRotation = orientation[0];
            aRotation = (int) Math.toDegrees(aRotation);
            satView.setAzimutRotation(-aRotation);
            satView.invalidate();
        }
    }
}

From source file:com.google.android.testing.nativedriver.server.AndroidNativeDriver.java

@Override
public ScreenOrientation getOrientation() {
    int orientation = context.getOnMainSyncRunner().run(doGetOrientation());

    if ((orientation == Surface.ROTATION_0) || (orientation == Surface.ROTATION_180)) {
        return ScreenOrientation.PORTRAIT;
    } else { // Surface.ROTATION_90 or Surface.ROTATION_270
        return ScreenOrientation.LANDSCAPE;
    }//  www . ja  va2 s.  co  m
}

From source file:com.nextgis.mobile.forms.CompassFragment.java

public int getDeviceRotation() {

    Display display = getActivity().getWindowManager().getDefaultDisplay();

    final int rotation = display.getRotation();

    if (rotation == Surface.ROTATION_90) {
        return 90;
    } else if (rotation == Surface.ROTATION_180) {
        return 180;
    } else if (rotation == Surface.ROTATION_270) {
        return 270;
    }/*from   w w  w .j a  v  a2 s  .co  m*/

    return 0;
}

From source file:uk.ac.horizon.artcodes.camera.CameraView.java

private int getDeviceRotation() {
    WindowManager manager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    int rotation = manager.getDefaultDisplay().getRotation();
    switch (rotation) {
    case Surface.ROTATION_0:
        return 0;
    case Surface.ROTATION_90:
        return 90;
    case Surface.ROTATION_180:
        return 180;
    case Surface.ROTATION_270:
        return 270;
    }//  w  w w.j a  v a 2s .  co m
    return 0;
}

From source file:co.taqat.call.LinphoneActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    //This must be done before calling super.onCreate().
    super.onCreate(savedInstanceState);

    if (getResources().getBoolean(R.bool.orientation_portrait_only)) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }//  ww  w  .j a va  2 s  .  c o  m

    boolean useFirstLoginActivity = getResources().getBoolean(R.bool.display_account_assistant_at_first_start);
    if (LinphonePreferences.instance().isProvisioningLoginViewEnabled()) {
        Intent wizard = new Intent();
        wizard.setClass(this, RemoteProvisioningLoginActivity.class);
        wizard.putExtra("Domain", LinphoneManager.getInstance().wizardLoginViewDomain);
        startActivity(wizard);
        finish();
        return;
    } else if (savedInstanceState == null
            && (useFirstLoginActivity && LinphonePreferences.instance().isFirstLaunch())) {
        if (LinphonePreferences.instance().getAccountCount() > 0) {
            LinphonePreferences.instance().firstLaunchSuccessful();
        } else {
            startActivity(new Intent().setClass(this, AssistantActivity.class));
            finish();
            return;
        }
    }

    if (getIntent() != null && getIntent().getExtras() != null) {
        newProxyConfig = getIntent().getExtras().getBoolean("isNewProxyConfig");
    }

    if (getResources().getBoolean(R.bool.use_linphone_tag)) {
        if (getPackageManager().checkPermission(Manifest.permission.WRITE_SYNC_SETTINGS,
                getPackageName()) != PackageManager.PERMISSION_GRANTED) {
            checkSyncPermission();
        } else {
            ContactsManager.getInstance().initializeSyncAccount(getApplicationContext(), getContentResolver());
        }
    } else {
        ContactsManager.getInstance().initializeContactManager(getApplicationContext(), getContentResolver());
    }

    setContentView(R.layout.main);
    instance = this;
    fragmentsHistory = new ArrayList<FragmentsAvailable>();
    pendingFragmentTransaction = FragmentsAvailable.UNKNOW;

    initButtons();
    initSideMenu();

    currentFragment = FragmentsAvailable.EMPTY;
    if (savedInstanceState == null) {
        changeCurrentFragment(FragmentsAvailable.DIALER, getIntent().getExtras());
    } else {
        currentFragment = (FragmentsAvailable) savedInstanceState.getSerializable("currentFragment");
    }

    mListener = new LinphoneCoreListenerBase() {
        @Override
        public void messageReceived(LinphoneCore lc, LinphoneChatRoom cr, LinphoneChatMessage message) {
            displayMissedChats(getUnreadMessageCount());
        }

        @Override
        public void registrationState(LinphoneCore lc, LinphoneProxyConfig proxy,
                LinphoneCore.RegistrationState state, String smessage) {
            if (state.equals(RegistrationState.RegistrationCleared)) {
                if (lc != null) {
                    LinphoneAuthInfo authInfo = lc.findAuthInfo(proxy.getIdentity(), proxy.getRealm(),
                            proxy.getDomain());
                    if (authInfo != null)
                        lc.removeAuthInfo(authInfo);
                }
            }

            refreshAccounts();

            if (getResources().getBoolean(R.bool.use_phone_number_validation)) {
                if (state.equals(RegistrationState.RegistrationOk)) {
                    LinphoneManager.getInstance().isAccountWithAlias();
                }
            }

            if (state.equals(RegistrationState.RegistrationFailed) && newProxyConfig) {
                newProxyConfig = false;
                if (proxy.getError() == Reason.BadCredentials) {
                    //displayCustomToast(getString(R.string.error_bad_credentials), Toast.LENGTH_LONG);
                }
                if (proxy.getError() == Reason.Unauthorized) {
                    displayCustomToast(getString(R.string.error_unauthorized), Toast.LENGTH_LONG);
                }
                if (proxy.getError() == Reason.IOError) {
                    displayCustomToast(getString(R.string.error_io_error), Toast.LENGTH_LONG);
                }
            }
        }

        @Override
        public void callState(LinphoneCore lc, LinphoneCall call, LinphoneCall.State state, String message) {
            if (state == State.IncomingReceived) {
                startActivity(new Intent(LinphoneActivity.instance(), CallIncomingActivity.class));
            } else if (state == State.OutgoingInit || state == State.OutgoingProgress) {
                startActivity(new Intent(LinphoneActivity.instance(), CallOutgoingActivity.class));
            } else if (state == State.CallEnd || state == State.Error || state == State.CallReleased) {
                resetClassicMenuLayoutAndGoBackToCallIfStillRunning();
            }

            int missedCalls = LinphoneManager.getLc().getMissedCallsCount();
            displayMissedCalls(missedCalls);
        }
    };

    int missedCalls = LinphoneManager.getLc().getMissedCallsCount();
    displayMissedCalls(missedCalls);

    int rotation = getWindowManager().getDefaultDisplay().getRotation();
    switch (rotation) {
    case Surface.ROTATION_0:
        rotation = 0;
        break;
    case Surface.ROTATION_90:
        rotation = 90;
        break;
    case Surface.ROTATION_180:
        rotation = 180;
        break;
    case Surface.ROTATION_270:
        rotation = 270;
        break;
    }

    LinphoneManager.getLc().setDeviceRotation(rotation);
    mAlwaysChangingPhoneAngle = rotation;
}

From source file:com.nextgis.maplibui.fragment.CompassFragment.java

public int getDeviceRotation() {
    Display display = getActivity().getWindowManager().getDefaultDisplay();
    final int rotation = display.getRotation();

    if (rotation == Surface.ROTATION_90) {
        return 90;
    } else if (rotation == Surface.ROTATION_180) {
        return 180;
    } else if (rotation == Surface.ROTATION_270) {
        return 270;
    }//from   ww w.j  a  va2 s . com

    return 0;
}