Example usage for android.view Display getRotation

List of usage examples for android.view Display getRotation

Introduction

In this page you can find the example usage for android.view Display getRotation.

Prototype

@Surface.Rotation
public int getRotation() 

Source Link

Document

Returns the rotation of the screen from its "natural" orientation.

Usage

From source file:com.projecttango.examples.java.augmentedreality.AugmentedRealityActivity.java

/**
 * Set the color camera background texture rotation and save the camera to display rotation.
 *///  w  ww  . j a va 2  s.c  o m
private void setDisplayRotation() {
    Display display = getWindowManager().getDefaultDisplay();
    mDisplayRotation = display.getRotation();

    // We also need to update the camera texture UV coordinates. This must be run in the OpenGL
    // thread.
    mSurfaceView.queueEvent(new Runnable() {
        @Override
        public void run() {
            if (mIsConnected) {
                mRenderer.updateColorCameraTextureUvGlThread(mDisplayRotation);
            }
        }
    });
}

From source file:org.acra.collector.DisplayManagerCollector.java

@NonNull
private Object collectDisplayData(@NonNull Display display) {
    final DisplayMetrics metrics = new DisplayMetrics();
    display.getMetrics(metrics);//from  ww  w  . ja v  a  2s. c  o  m

    //noinspection deprecation
    return collectCurrentSizeRange(display) + collectFlags(display) + display.getDisplayId() + ".height="
            + display.getHeight() + '\n' + collectMetrics(display) + collectName(display)
            + display.getDisplayId() + ".orientation=" + display.getRotation() + '\n' + display.getDisplayId()
            + ".pixelFormat=" + display.getPixelFormat() + '\n' + collectRealMetrics(display)
            + collectRealSize(display) + collectRectSize(display) + display.getDisplayId() + ".refreshRate="
            + display.getRefreshRate() + '\n' + collectRotation(display) + collectSize(display)
            + display.getDisplayId() + ".width=" + display.getWidth() + '\n' + collectIsValid(display);
}

From source file:com.blueverdi.rosietheriveter.MoreFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    setRetainInstance(false);//from   w  w  w  .  ja v a 2 s . c  om
    thisFragment = this;
    myTour = new MySqliteHelperMyTour(getActivity());
    networkAvailable = Utils.isNetworkAvailable(getActivity());
    buildSitesList();
    view = inflater.inflate(R.layout.more_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;
    }
    ListView listview = (ListView) listLayout.findViewById(R.id.siteListView);

    // 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) {
                thisFragment.getActivity().runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        Toast.makeText(getActivity(), getString(R.string.internet_required), Toast.LENGTH_LONG)
                                .show();

                    }
                });
            }

            map.setOnCameraChangeListener(new OnCameraChangeListener() {

                @Override
                public void onCameraChange(CameraPosition arg0) {
                    map.setOnCameraChangeListener(null);
                    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);
                    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;
}

From source file:com.playhaven.android.req.PlayHavenRequest.java

@SuppressWarnings("deprecation")
protected UriComponentsBuilder createUrl(Context context) throws PlayHavenException {
    try {/*from   w  w  w . j  a v a2  s  .co m*/
        SharedPreferences pref = PlayHaven.getPreferences(context);

        UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(getString(pref, APIServer));
        builder.path(context.getResources().getString(getApiPath(context)));
        builder.queryParam("app", getString(pref, AppPkg));
        builder.queryParam("opt_out", getString(pref, OptOut, "0"));
        builder.queryParam("app_version", getString(pref, AppVersion));
        builder.queryParam("os", getInt(pref, OSVersion, 0));
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        builder.queryParam("orientation", display.getRotation());
        builder.queryParam("hardware", getString(pref, DeviceModel));
        PlayHaven.ConnectionType connectionType = getConnectionType(context);
        builder.queryParam("connection", connectionType.ordinal());
        builder.queryParam("idiom",
                context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK);

        /**
         * For height/width we will use getSize(Point) not getRealSize(Point) as this will allow us to automatically
         * account for rotation and screen decorations like the status bar. We only want to know available space.
         *
         * @playhaven.apihack for SDK_INT < 13, have to use getHeight and getWidth!
         */
        Point size = new Point();
        if (Build.VERSION.SDK_INT >= 13) {
            display.getSize(size);
        } else {
            size.x = display.getWidth();
            size.y = display.getHeight();
        }
        builder.queryParam("width", size.x);
        builder.queryParam("height", size.y);

        /**
         * SDK Version needs to be reported as a dotted numeric value
         * So, if it is a -SNAPSHOT build, we will replace -SNAPSHOT with the date of the build
         * IE: 2.0.0.20130201
         * as opposed to an actual released build, which would be like 2.0.0
         */
        String sdkVersion = getString(pref, SDKVersion);
        String[] date = Version.PLUGIN_BUILD_TIME.split("[\\s]");
        sdkVersion = sdkVersion.replace("-SNAPSHOT", "." + date[0].replaceAll("-", ""));
        builder.queryParam("sdk_version", sdkVersion);

        builder.queryParam("plugin", getString(pref, PluginIdentifer));

        Locale locale = context.getResources().getConfiguration().locale;
        builder.queryParam("languages", String.format("%s,%s", locale.toString(), locale.getLanguage()));
        builder.queryParam("token", getString(pref, Token));

        builder.queryParam("device", getString(pref, DeviceId));
        DisplayMetrics metrics = new DisplayMetrics();
        display.getMetrics(metrics);
        builder.queryParam("dpi", metrics.densityDpi);

        String uuid = UUID.randomUUID().toString();
        String nonce = base64Digest(uuid);
        builder.queryParam("nonce", nonce);

        ktsid = KontagentUtil.getSenderId(context);
        if (ktsid != null)
            builder.queryParam("sid", ktsid);

        addSignature(builder, pref, nonce);

        // Setup for signature verification
        String secret = getString(pref, Secret);
        SecretKeySpec key = new SecretKeySpec(secret.getBytes(UTF8), HMAC);
        sigMac = Mac.getInstance(HMAC);
        sigMac.init(key);
        sigMac.update(nonce.getBytes(UTF8));

        return builder;
    } catch (Exception e) {
        throw new PlayHavenException(e);
    }
}

From source file:com.projecttango.examples.java.greenscreen.GreenScreenActivity.java

/**
 * Set the color camera background texture rotation and save the camera to display rotation.
 *///from ww w . j  a v a  2 s .  com
private void setDisplayRotation() {
    Display display = getWindowManager().getDefaultDisplay();
    mDisplayRotation = display.getRotation();

    // We also need to update the camera texture UV coordinates. This must be run in the OpenGL
    // thread.
    mSurfaceView.queueEvent(new Runnable() {
        @Override
        public void run() {
            if (mIsConnected) {
                mRenderer.updateColorCameraTextureUv(mDisplayRotation);
            }
        }
    });
}

From source file:org.artoolkit.ar.samples.ARMovie.ARMovieActivity.java

private void updateNativeDisplayParameters() {
    Display d = getWindowManager().getDefaultDisplay();
    int orientation = d.getRotation();
    DisplayMetrics dm = new DisplayMetrics();
    d.getMetrics(dm);//www. j a  va2s .  c  o m
    int w = dm.widthPixels;
    int h = dm.heightPixels;
    int dpi = dm.densityDpi;
    nativeDisplayParametersChanged(orientation, w, h, dpi);
}

From source file:de.uulm.graphicalpasswords.openmiba.MIBACreatePasswordActivity.java

private void setViews() {
    tblLayout = (TableLayout) findViewById(R.id.tableLayout);
    btnBack = (Button) findViewById(R.id.miba_btnBack);
    btnBack.setOnClickListener(new View.OnClickListener() {

        @Override/*from   w  ww .  ja  v  a2  s  .  co  m*/
        public void onClick(View v) {
            back();
        }
    });
    btnDone = (Button) findViewById(R.id.miba_btnCreateMasterKey);

    tvRound = (TextView) this.findViewById(R.id.tvRound);
    tvRound.setText(getString(R.string.label_round) + " 1");

    linlGrid = new LinearLayout[2][4];
    linlGrid[0][0] = (LinearLayout) this.findViewById(R.id.square1);
    linlGrid[1][0] = (LinearLayout) this.findViewById(R.id.square2);
    linlGrid[0][1] = (LinearLayout) this.findViewById(R.id.square3);
    linlGrid[1][1] = (LinearLayout) this.findViewById(R.id.square4);
    linlGrid[0][2] = (LinearLayout) this.findViewById(R.id.square5);
    linlGrid[1][2] = (LinearLayout) this.findViewById(R.id.square6);
    linlGrid[0][3] = (LinearLayout) this.findViewById(R.id.square7);
    linlGrid[1][3] = (LinearLayout) this.findViewById(R.id.square8);

    for (int y = 0; y < 4; y++) {
        for (int x = 0; x < 2; x++) {
            linlGrid[x][y].setBackgroundColor(colors_off[x][y]);
        }

    }

    // get width and height from mainpanel
    // can not use display width/height because of notification bar
    ViewTreeObserver vto = tblLayout.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {

            // get values of portrait mode

            Display display = getWindowManager().getDefaultDisplay();

            if (display.getRotation() == Surface.ROTATION_0) {
                width = tblLayout.getWidth();
                height = tblLayout.getHeight();
            } else {
                height = tblLayout.getWidth();
                width = tblLayout.getHeight();
            }

            Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.ccp000);
            bmp = Bitmap.createScaledBitmap(bmp, width, height, true);
            Drawable d = new BitmapDrawable(getResources(), bmp);
            tblLayout.setBackgroundDrawable(d);

            touchlistener = new TouchListener(linlGrid, width, height, handler);
            tblLayout.setOnTouchListener(touchlistener);
            // remove listener again otherwise it gets called twice
            tblLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
        }
    });

    btnDone.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            DialogFragment dialog = new RememberPasswordDialogFragment();
            dialog.show(getFragmentManager(), "remember");
        }
    });
    btnDone.setVisibility(View.VISIBLE);
}

From source file:com.blueverdi.rosietheriveter.SitesFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    thisFragment = this;
    setRetainInstance(false);//from   w  ww  . j a v  a 2s  .c  o  m
    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;
}

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

@NonNull
private JSONObject collectDisplayData(@NonNull Display display) throws JSONException {
    final DisplayMetrics metrics = new DisplayMetrics();
    display.getMetrics(metrics);/* w ww .ja v  a2 s.c o  m*/

    final JSONObject result = new JSONObject();
    collectCurrentSizeRange(display, result);
    collectFlags(display, result);
    collectMetrics(display, result);
    collectRealMetrics(display, result);
    collectName(display, result);
    collectRealSize(display, result);
    collectRectSize(display, result);
    collectSize(display, result);
    collectRotation(display, result);
    collectIsValid(display, result);
    result.put("orientation", display.getRotation()).put("refreshRate", display.getRefreshRate());
    //noinspection deprecation
    result.put("height", display.getHeight()).put("width", display.getWidth()).put("pixelFormat",
            display.getPixelFormat());
    return result;
}

From source file:hr.foicore.varazdinlandmarksdemo.POIMapActivity.java

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
private void lockOrientation() {
    Display display = POIMapActivity.this.getWindowManager().getDefaultDisplay();
    int rotation = display.getRotation();
    int height;/* w  ww .jav a2s  . co  m*/
    int width;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2) {
        height = display.getHeight();
        width = display.getWidth();
    } else {
        Point size = new Point();
        display.getSize(size);
        height = size.y;
        width = size.x;
    }
    switch (rotation) {
    case Surface.ROTATION_90:
        if (width > height)
            POIMapActivity.this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        else
            POIMapActivity.this.setRequestedOrientation(9/* reversePortait */);
        break;
    case Surface.ROTATION_180:
        if (height > width)
            POIMapActivity.this.setRequestedOrientation(9/* reversePortait */);
        else
            POIMapActivity.this.setRequestedOrientation(8/* reverseLandscape */);
        break;
    case Surface.ROTATION_270:
        if (width > height)
            POIMapActivity.this.setRequestedOrientation(8/* reverseLandscape */);
        else
            POIMapActivity.this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        break;
    default:
        if (height > width)
            POIMapActivity.this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        else
            POIMapActivity.this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }
}