Example usage for android.view Surface ROTATION_0

List of usage examples for android.view Surface ROTATION_0

Introduction

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

Prototype

int ROTATION_0

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

Click Source Link

Document

Rotation constant: 0 degree rotation (natural orientation)

Usage

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:// w  w  w .ja va  2s.co m
        return String.valueOf(rotation);
    }
}

From source file:piuk.blockchain.android.ui.zxing.CaptureActivity.java

private int getCurrentOrientation() {
    int rotation = getWindowManager().getDefaultDisplay().getRotation();
    switch (rotation) {
    case Surface.ROTATION_0:
    case Surface.ROTATION_270:
        return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
    default:/*from   ww  w.j a v a 2 s.c  o  m*/
        return ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;//reverse-mounted cameras on devices like the Nexus 5X
    }
}

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 va 2s  .  c o  m
        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.cocos2dx.lib.Cocos2dxAccelerometer.java

@Override
public void onSensorChanged(SensorEvent event) {

    if (event.sensor.getType() != Sensor.TYPE_ACCELEROMETER) {
        return;//from  ww w  .  j a  v  a  2  s . c  o  m
    }

    float x = event.values[0];
    float y = event.values[1];
    float z = event.values[2];

    /*
     * Because the axes are not swapped when the device's screen orientation changes. 
     * So we should swap it here.
     * In tablets such as Motorola Xoom, the default orientation is landscape, so should
     * consider this.
     */
    int orientation = mContext.getResources().getConfiguration().orientation;
    if ((orientation == Configuration.ORIENTATION_LANDSCAPE) && (mNaturalOrientation != Surface.ROTATION_0)) {
        float tmp = x;
        x = -y;
        y = tmp;
    } else if ((orientation == Configuration.ORIENTATION_PORTRAIT)
            && (mNaturalOrientation != Surface.ROTATION_0)) {
        float tmp = x;
        x = y;
        y = -tmp;
    }

    onSensorChanged(x, y, z, event.timestamp);
    // Log.d(TAG, "x = " + event.values[0] + " y = " + event.values[1] + " z = " + event.values[2]);
}

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

/**
 * Returns the correct screen orientation based on the supposedly preferred
 * position of the device.//w  w w. j a  v  a2s  . 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:io.github.msc42.masterthemaze.SearchDeviceActivity.java

private void lockScreenOrientation() {
    int orientation = getResources().getConfiguration().orientation;
    int rotation = getWindowManager().getDefaultDisplay().getRotation();

    if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
        if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        } else {/* w  w w.  j  a  va  2s .  c om*/
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
        }
    } else if (orientation == Configuration.ORIENTATION_PORTRAIT) {
        if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        } else {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
        }
    } else {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
}

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;
    }//ww  w .  ja va2s.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  www  .  j av a 2s  .c  om*/
    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:com.blueverdi.rosietheriveter.SitesFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    thisFragment = this;
    setRetainInstance(false);// w w  w  .  ja  v  a2  s . c om
    myTour = new MySqliteHelperMyTour(getActivity());
    networkAvailable = Utils.isNetworkAvailable(getActivity());
    buildSitesList();
    view = inflater.inflate(R.layout.sites_fragment, container, false);
    viewContainer = (LinearLayout) view.findViewById(R.id.view_container);
    RadioGroup radioGroup = (RadioGroup) view.findViewById(R.id.radioGroup1);
    // implementation without nested fragments
    // first initialize the gallery view
    // ---------------------------------
    listLayout = (LinearLayout) inflater.inflate(R.layout.site_gallery_view, viewContainer, false);
    Display display = ((WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE))
            .getDefaultDisplay();
    int rotation = display.getRotation();
    switch (rotation) {
    case Surface.ROTATION_0:
    case Surface.ROTATION_180:
        portrait = true;
        arrayLayout = R.layout.site_portrait;
        break;
    case Surface.ROTATION_90:
    case Surface.ROTATION_270:
        portrait = false;
        arrayLayout = R.layout.site_landscape;
        break;
    }

    // now initialize the map view 
    // --------------------------
    mapLayout = (LinearLayout) inflater.inflate(R.layout.site_map_view, viewContainer, false);
    try {
        MapsInitializer.initialize(this.getActivity());
    } catch (Exception e) {
        e.printStackTrace();

    }
    mapView = (MapView) mapLayout.findViewById(R.id.siteMap);
    mapView.onCreate(savedInstanceState);
    mapView.getMapAsync(new OnMapReadyCallback() {
        @Override
        public void onMapReady(GoogleMap googleMap) {
            map = googleMap;
            map.getUiSettings().setMyLocationButtonEnabled(false);
            if (!networkAvailable) {
                Toast.makeText(thisFragment.getActivity(),
                        thisFragment.getActivity().getString(R.string.internet_required), Toast.LENGTH_LONG)
                        .show();
            }

            //      map.setMyLocationEnabled(true);
            //                 CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(SITES, 0);
            //                 map.animateCamera(cameraUpdate);

            CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(SITES, 0);
            if (networkAvailable) {
                map.animateCamera(cameraUpdate);
            } else {
                map.moveCamera(cameraUpdate);

            }
            markers = new HashMap<String, Site>();
            for (Site s : sites) {
                LatLng ll = new LatLng(Double.parseDouble(s.getString(Site.LATITUDE)),
                        Double.parseDouble(s.getString(Site.LONGITUDE)));
                Marker marker = map.addMarker(new MarkerOptions().position(ll).title(s.getString(Site.NAME)));
                markers.put(marker.getId(), s);
            }
            map.setOnMarkerClickListener(new OnMarkerClickListener() {
                @Override
                public boolean onMarkerClick(Marker marker) {
                    Site s = markers.get(marker.getId());
                    Intent i = new Intent(getActivity(), SiteActivity.class);
                    i.putExtra(Site.PARCEL_NAME, s);
                    SiteDetails sd = s.getDetails();
                    if (sd != null) {
                        i.putExtra(SiteDetails.PARCEL_NAME, sd);
                    }
                    startActivity(i);
                    getActivity().overridePendingTransition(R.anim.zoom_in, 0);
                    return true;
                }
            });
        }
    });
    try {
        container.removeAllViews();
    } catch (Exception e) {
        MyLog.d(TAG, "container evaporated inside onCreateView");
        return view;
    }
    if (startInMapView) {
        RadioButton rb = (RadioButton) view.findViewById(R.id.radioMapView);
        rb.setChecked(true);
        setMap();
    } else {
        setGallery();
    }
    radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            if (checkedId == R.id.radioListView) {
                setGallery();
            } else {
                Toast.makeText(getActivity(), getString(R.string.getting_map), Toast.LENGTH_LONG).show();
                setMap();
            }
        }
    });
    return view;
}