Example usage for android.view Display getHeight

List of usage examples for android.view Display getHeight

Introduction

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

Prototype

@Deprecated
public int getHeight() 

Source Link

Usage

From source file:Main.java

public static int getFullScreenSizeHeight(Context context) {
    int realWidth;
    int realHeight;

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();

    Point point = new Point();

    if (Build.VERSION.SDK_INT >= 17) {
        //new pleasant way to get real metrics
        DisplayMetrics realMetrics = new DisplayMetrics();
        display.getRealMetrics(realMetrics);
        realWidth = realMetrics.widthPixels;
        realHeight = realMetrics.heightPixels;

    } else if (Build.VERSION.SDK_INT >= 14) {
        //reflection for this weird in-between time
        try {/*from  w w w .ja v a2 s  .com*/
            Method mGetRawH = Display.class.getMethod("getRawHeight");
            Method mGetRawW = Display.class.getMethod("getRawWidth");
            realWidth = (Integer) mGetRawW.invoke(display);
            realHeight = (Integer) mGetRawH.invoke(display);
        } catch (Exception e) {
            //this may not be 100% accurate, but it's all we've got
            realWidth = display.getWidth();
            realHeight = display.getHeight();
            Log.e("Display Info", "Couldn't use reflection to get the real display metrics.");
        }

    } else {
        //This should be close, as lower API devices should not have window navigation bars
        realWidth = display.getWidth();
        realHeight = display.getHeight();
    }
    return realHeight;
}

From source file:Main.java

public static int getFullScreenSizeWidth(Context context) {
    int realWidth;
    int realHeight;

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();

    Point point = new Point();

    if (Build.VERSION.SDK_INT >= 17) {
        //new pleasant way to get real metrics
        DisplayMetrics realMetrics = new DisplayMetrics();
        display.getRealMetrics(realMetrics);
        realWidth = realMetrics.widthPixels;
        realHeight = realMetrics.heightPixels;

    } else if (Build.VERSION.SDK_INT >= 14) {
        //reflection for this weird in-between time
        try {//w  w  w. jav a 2  s.co  m
            Method mGetRawH = Display.class.getMethod("getRawHeight");
            Method mGetRawW = Display.class.getMethod("getRawWidth");
            realWidth = (Integer) mGetRawW.invoke(display);
            realHeight = (Integer) mGetRawH.invoke(display);
        } catch (Exception e) {
            //this may not be 100% accurate, but it's all we've got
            realWidth = display.getWidth();
            realHeight = display.getHeight();
            Log.e("Display Info", "Couldn't use reflection to get the real display metrics.");
        }

    } else {
        //This should be close, as lower API devices should not have window navigation bars
        realWidth = display.getWidth();
        realHeight = display.getHeight();
    }
    return realWidth;
}

From source file:com.pdftron.pdf.utils.Utils.java

/**
 * Gets the size of the display, in pixels.
 *
 * @param context the Context/*from w  w  w.jav  a 2 s .c o  m*/
 * @param outSize A Point object to receive the size information
 */
public static void getDisplaySize(Context context, Point outSize) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    if (outSize == null) {
        outSize = new Point();
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        display.getSize(outSize);
    } else {
        outSize.set(display.getWidth(), display.getHeight());
    }
}

From source file:com.gm.goldencity.util.Utils.java

/**
 * Get display height/* w  w  w.ja  v  a 2s.c om*/
 *
 * @param context Application context
 * @return
 */
@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
public static int getDisplayHeight(Context context) {
    Activity activity = (Activity) context;
    if (Integer.valueOf(Build.VERSION.SDK_INT) < 13) {
        Display display = activity.getWindowManager().getDefaultDisplay();
        return display.getHeight();
    } else {
        Display display = activity.getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        return size.y;
    }
}

From source file:com.mobicage.rogerthat.util.ui.UIUtils.java

public static Point getDisplaySize(Context ctx) {
    Display display = ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    Point size = new Point();
    size.x = display.getWidth();/* w w  w.  ja v  a 2 s. c  o  m*/
    size.y = display.getHeight();
    return size;
}

From source file:com.manning.androidhacks.hack007.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Display display = getWindowManager().getDefaultDisplay();
    mDrawView = new DrawView(this);
    mDrawView.height = display.getHeight();
    mDrawView.width = display.getWidth();

    setContentView(mDrawView);/*from   ww w  .ja  va  2s  .  c  om*/
}

From source file:com.pickr.tasks.PhotoLoader.java

@Override
protected Bitmap doInBackground() {
    try {//from  w w  w  . j ava  2  s . c o m
        WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();

        int resolution = display.getWidth() * display.getHeight();

        Flickr flickr = FlickrHandler.getFlickr();
        List<PhotoSize> sizes = flickr.getPhotosService().getSizes(mPhoto);

        return loadBitmap(PhotoSizeWeight.getOptimalPhotoSize(sizes, resolution), display);

    } catch (Throwable ex) {
        ex.printStackTrace();
        LOGGER.e("Error loading photo", ex);
    }
    return null;
}

From source file:org.kaaproject.kaa.demo.smarthousedemo.device.QrcodeFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_qrcode, container, false);

    Bundle args = this.getArguments();
    String contents = args.getString(QR_CONTENTS);
    String contentsDesc = args.getString(QR_CONTENTS_DESCRIPTION);

    WindowManager manager = (WindowManager) getActivity().getSystemService(Activity.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    int width = display.getWidth();
    int height = display.getHeight();
    int smallerDimension = width < height ? width : height;
    smallerDimension = smallerDimension * 7 / 8;

    qrCodeEncoder = new QRCodeEncoder(contents, smallerDimension);
    try {/*  w ww  .  j av  a  2  s . c o  m*/
        Bitmap bitmap = qrCodeEncoder.encodeAsBitmap();
        if (bitmap == null) {
            Log.w(TAG, "Could not encode barcode");
            showErrorMessage(R.string.msg_encode_contents_failed);
            qrCodeEncoder = null;
            return rootView;
        }
        ImageView view = (ImageView) rootView.findViewById(R.id.image_view);
        view.setImageBitmap(bitmap);
        TextView contentsView = (TextView) rootView.findViewById(R.id.contents_text_view);
        contentsView.setText(contentsDesc);
    } catch (WriterException e) {
        Log.w(TAG, "Could not encode barcode", e);
        showErrorMessage(R.string.msg_encode_contents_failed);
        qrCodeEncoder = null;
    }
    return rootView;
}

From source file:com.appsimobile.appsii.AbstractHotspotHelper.java

@SuppressWarnings("deprecation")
protected WindowManager.LayoutParams createHotspotParams(HotspotItem conf, SharedPreferences prefs) {

    Display display = mWindowManager.getDefaultDisplay();
    mHeight = display.getHeight();

    float pct = conf.mHeightRelativeToViewHeight;
    int realHeight = (int) (mHeight * pct);
    if (realHeight < mDp56)
        realHeight = mDp56;//www. j  av a  2 s .c o m

    int y = (int) (conf.mYPosRelativeToView * mHeight);

    int hotspotWidth = prefs.getInt("pref_hotspot_width", 22);

    int width = (int) (hotspotWidth * AppsiApplication.getDensity(mContext));

    int xOffset = 0;

    if (conf.mLeft) {
        WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
                WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
                        | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
                        | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                        | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
                PixelFormat.TRANSLUCENT);
        params.gravity = Gravity.LEFT | Gravity.TOP;
        params.x = xOffset;
        params.y = y;
        params.width = width;
        params.height = realHeight;
        return params;
    } else {
        WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
                WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
                        | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
                        | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                        | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
                PixelFormat.TRANSLUCENT);
        params.gravity = Gravity.RIGHT | Gravity.TOP;
        params.x = xOffset;
        params.y = y;
        params.width = width;
        params.height = realHeight;
        return params;
    }
}

From source file:com.figo.campaignhelper.GenerateActivity.java

Bitmap encodeAsBitmap(String contents) throws WriterException {
    String contentsToEncode = contents;
    if (contentsToEncode == null) {
        return null;
    }/*from w w  w .  j a  v a  2  s . c o  m*/
    Map<EncodeHintType, Object> hints = null;
    String encoding = guessAppropriateEncoding(contentsToEncode);
    if (encoding != null) {
        hints = new EnumMap<EncodeHintType, Object>(EncodeHintType.class);
        hints.put(EncodeHintType.CHARACTER_SET, encoding);
    }
    MultiFormatWriter writer = new MultiFormatWriter();

    WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    int widthD = display.getWidth();
    int heightD = display.getHeight();
    int dimension = widthD < heightD ? widthD : heightD;
    dimension = dimension * 7 / 8;

    BitMatrix result = writer.encode(contentsToEncode, BarcodeFormat.QR_CODE, dimension, dimension, hints);
    int width = result.getWidth();
    int height = result.getHeight();
    int[] pixels = new int[width * height];
    for (int y = 0; y < height; y++) {
        int offset = y * width;
        for (int x = 0; x < width; x++) {
            pixels[offset + x] = result.get(x, y) ? Color.BLACK : Color.WHITE;
        }
    }

    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return bitmap;
}