Code example for Display

Methods: getHeightgetMetricsgetWidth

0
             
            WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
 
            Display d = wm.getDefaultDisplay();
 
            mScreenWidth = d.getWidth();
            mScreenHeight = d.getHeight();
 
            DisplayMetrics metrics = new DisplayMetrics();
            d.getMetrics(metrics);
 
            mScreenPpiX = metrics.xdpi;
            mScreenPpiY = metrics.ydpi;
             
            int orientation;
            orientation = context.getResources().getConfiguration().orientation;
            Logger.D(TAG, "Resources orientation: "+ orientation);
 
            if (orientation == Configuration.ORIENTATION_UNDEFINED)
            { 
                orientation = d.getOrientation();
                Logger.D(TAG, "DisplayMetrics orientation: "+ orientation);
 
                if (orientation == Configuration.ORIENTATION_UNDEFINED) {
                    if (d.getWidth() == d.getHeight())
                        orientation = Configuration.ORIENTATION_SQUARE;
                    else if(d.getWidth() < d.getHeight())
                        orientation = Configuration.ORIENTATION_PORTRAIT;
                    else 
                        orientation = Configuration.ORIENTATION_LANDSCAPE;
 
                    Logger.D(TAG, "Screen resolution orientation: " + orientation);
Stop searching for code, let great code find you!  Add Codota to your java IDE