Java Code Examples for android.view.Display#getHeight()

The following examples show how to use android.view.Display#getHeight() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CameraConfigurationManager.java    From QrCodeLib with MIT License 6 votes vote down vote up
/**
 * Reads, one time, values from the camera that are needed by the app.
 */
void initFromCameraParameters(Camera camera) {
    Camera.Parameters parameters = camera.getParameters();
    previewFormat = parameters.getPreviewFormat();
    previewFormatString = parameters.get("preview-format");
    Log.d(TAG, "Default preview format: " + previewFormat + '/' + previewFormatString);
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    screenResolution = new Point(display.getWidth(), display.getHeight());
    Log.d(TAG, "Screen resolution: " + screenResolution);

    //图片拉伸
    Point screenResolutionForCamera = new Point();
    screenResolutionForCamera.x = screenResolution.x;
    screenResolutionForCamera.y = screenResolution.y;
    // preview size is always something like 480*320, other 320*480
    if (screenResolution.x < screenResolution.y) {
        screenResolutionForCamera.x = screenResolution.y;
        screenResolutionForCamera.y = screenResolution.x;
    }

    cameraResolution = getCameraResolution(parameters, screenResolutionForCamera);
    Log.d(TAG, "Camera resolution: " + screenResolution);

}
 
Example 2
Source File: DeviceUtils.java    From AndroidWear-OpenWear with MIT License 6 votes vote down vote up
@TargetApi(13)
@SuppressWarnings("deprecation")
public static int[] getScreenSize(Context cx) {
    WindowManager wm = (WindowManager) cx.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();

    int[] size = new int[2];

    if (Build.VERSION.SDK_INT >= 13) {
        Point point = new Point();
        display.getSize(point);
        size[0] = point.x;
        size[1] = point.y;
    } else {
        size[0] = display.getWidth();
        size[1] = display.getHeight();
    }
    return size;
}
 
Example 3
Source File: AnimateDialog.java    From phphub-android with Apache License 2.0 6 votes vote down vote up
public void windowDeploy() {
        window = getWindow();

        window.setWindowAnimations(R.style.dialogWindow);
        window.setBackgroundDrawableResource(R.drawable.bg_dialog); //设置对话框背景为透明
        WindowManager.LayoutParams wl = window.getAttributes();
        //根据x,y坐标设置窗口需要显示的位置
        wl.x = 0; //x小于0左移,大于0右移
        wl.y = 0; //y小于0上移,大于0下移
//            wl.alpha = 0.6f; //设置透明度
//            wl.gravity = Gravity.BOTTOM; //设置重力

        window.setAttributes(wl);

        WindowManager m = window.getWindowManager();
        Display d = m.getDefaultDisplay();

        WindowManager.LayoutParams params = window.getAttributes();

        params.width = (int) (d.getWidth() * this.widthProportion);
        params.height = (int) (d.getHeight() * this.heightProportion);

        window.setAttributes(params);
    }
 
Example 4
Source File: DensityUtils.java    From StickerView with MIT License 5 votes vote down vote up
public static int getScreenHeight(Context context) {
    Display display = ((WindowManager) context
            .getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    // Point p = new Point();
    // display.getSize(p);//need api13
    int height = display.getHeight();
    return height;
}
 
Example 5
Source File: ScreenUtil.java    From SnackbarUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 获取屏幕的高度
 * @param context
 * @return
 */
public static int getScreenHeight(Context context) {
    WindowManager manager = (WindowManager) context
            .getSystemService(Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    return display.getHeight();
}
 
Example 6
Source File: HomeActivity.java    From CameraV with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public int[] getDimensions()
{
	Display display = getWindowManager().getDefaultDisplay();
	return new int[] { display.getWidth(), display.getHeight() };
}
 
Example 7
Source File: PluginImageAD.java    From SimplifyReader with Apache License 2.0 5 votes vote down vote up
private boolean isLand() {
	if (mActivity != null) {
		Display getOrient = mActivity.getWindowManager()
				.getDefaultDisplay();
		return getOrient.getWidth() > getOrient.getHeight();
	}
	return false;
}
 
Example 8
Source File: DeviceUtils.java    From ZxingSupport with Apache License 2.0 5 votes vote down vote up
/**
 * 获取屏幕的尺寸
 * @param context
 * @return
 */
public static Point getScreenSize(Context context){
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    Point screenResolution = new Point(display.getWidth(), display.getHeight());
    return screenResolution;
}
 
Example 9
Source File: SDKUtils.java    From letv with Apache License 2.0 5 votes vote down vote up
public static Point getScreenHeightWidth(WindowManager mWindowManager) {
    Point point = new Point();
    try {
        Display display = mWindowManager.getDefaultDisplay();
        if (VERSION.SDK_INT >= 17) {
            display.getRealSize(point);
        } else {
            point.y = display.getHeight();
            point.x = display.getWidth();
        }
    } catch (Throwable e) {
        LOG.w(TAG, "getScreenHeightWidth failed(Throwable): " + e.getMessage());
    }
    return point;
}
 
Example 10
Source File: Utils.java    From cast-videos-android with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
/**
 * Returns the screen/display size
 *
 */
public static Point getDisplaySize(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    int width = display.getWidth();
    int height = display.getHeight();
    return new Point(width, height);
}
 
Example 11
Source File: EntityViewTile.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
/**
 * Compute what the width and height of a single tile should be, based upon the available
 * screen space, how many columns there should be, and how many rows we want to show at a time.
 * Round up to the nearest integer since the GridView's width and height will ultimately be
 * computed indirectly from these values, and those values need to be integers, and we don't
 * want to end up cutting things off
 */
private Pair<Integer, Integer> computeTileWidthAndHeight(Context context) {
    double screenWidth, screenHeight;
    Display display = ((Activity)context).getWindowManager().getDefaultDisplay();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        Point size = new Point();
        display.getSize(size);
        screenWidth = size.x;
        screenHeight = size.y;
    } else {
        screenWidth = display.getWidth();
        screenHeight = display.getHeight();
    }

    if (!tileBeingShownInGridView()) {
        // If we added padding, subtract that space since we can't use it
        screenWidth = screenWidth - DEFAULT_TILE_PADDING_HORIZONTAL * 2;
    }

    int tileHeight;
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
        if (beingDisplayedInAwesomeMode) {
            // if in awesome mode, split available width in half
            screenWidth = screenWidth / 2;
        }
        tileHeight = (int)Math.ceil(screenHeight / computeNumTilesPerScreen(false, screenHeight));
    } else {
        tileHeight = (int)Math.ceil(screenHeight / computeNumTilesPerScreen(true, screenHeight));
    }

    int tileWidth = (int)Math.ceil(screenWidth / numTilesPerRow);

    return new Pair<>(tileWidth, tileHeight);
}
 
Example 12
Source File: CameraConfigurationManager.java    From myapplication with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
private Point getDisplaySize(final Display display) {
    final Point point = new Point();
    try {
        display.getSize(point);
    } catch (NoSuchMethodError ignore) {
        point.x = display.getWidth();
        point.y = display.getHeight();
    }
    return point;
}
 
Example 13
Source File: ImageWebViewActivity.java    From matrix-android-console with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
private Point getDisplaySize() {
    Point size = new Point();
    WindowManager w = getWindowManager();

    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)    {
        w.getDefaultDisplay().getSize(size);
    }else{
        Display d = w.getDefaultDisplay();
        size.x = d.getWidth();
        size.y = d.getHeight();
    }

    return size;
}
 
Example 14
Source File: PEWImageView.java    From ParallaxEverywhere with MIT License 5 votes vote down vote up
private void initSizeScreen() {
    WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        Point size = new Point();
        display.getSize(size);
        screenHeight = size.y;
        screenWidth = size.x;
    } else {
        screenHeight = display.getHeight();
        screenWidth = display.getWidth();
    }
}
 
Example 15
Source File: CameraConfigurationManager.java    From QrModule with Apache License 2.0 5 votes vote down vote up
/**
     * Reads, one time, values from the camera that are needed by the app.
     */
    @SuppressWarnings("SuspiciousNameCombination")
    void initFromCameraParameters(Camera camera) {
        Camera.Parameters parameters = camera.getParameters();
        previewFormat = parameters.getPreviewFormat();
        previewFormatString = parameters.get("preview-format");
        Log.d(TAG, "Default preview format: " + previewFormat + '/' + previewFormatString);
        WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = manager.getDefaultDisplay();
        screenResolution = new Point(display.getWidth(), display.getHeight());
//        display.getSize(screenResolution);//api > 13
        Log.d(TAG, "Screen resolution: " + screenResolution);

        //-- modify by ydcool at 2015-11-18 16:12:15 --
        Point screenResolutionForCamera = new Point();
        screenResolutionForCamera.x = screenResolution.x;
        screenResolutionForCamera.y = screenResolution.y;
        // preview size is always something like 480*320, other 320*480
        if (screenResolution.x < screenResolution.y) {
            screenResolutionForCamera.x = screenResolution.y;
            screenResolutionForCamera.y = screenResolution.x;
        }

//        cameraResolution = getCameraResolution(parameters, screenResolution);
        cameraResolution = getCameraResolution(parameters, screenResolutionForCamera);
        //-- end modify --

        Log.d(TAG, "Camera resolution: " + screenResolution);
    }
 
Example 16
Source File: FaceTrackActivity.java    From FaceDetect with Apache License 2.0 4 votes vote down vote up
@Override
    public void surfaceCreated(SurfaceHolder holder) {
        mCamera = Camera.open(1);
        mCamera.setDisplayOrientation(90);
        Camera.Parameters para = mCamera.getParameters();

     /* List<Camera.Size> sizes =   para.getSupportedPreviewSizes();
        int count = sizes.size();
        for (int i = 0; i< count; i++){
            Camera.Size size = sizes.get(i);
            if (size.width > 800 && size.width < 1000){
                width = size.width;
                height = size.height;
                break;
            }
            Log.e("size","size w:"+size.width + "--h:"+size.height);

        }


*/
        Point showingArea = new Point();
        WindowManager wm = (WindowManager) getSystemService(
                Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
       int screenWidth = display.getWidth();
       int  screenHeight = display.getHeight();

       int topHeight = dip2px(activity,25+44);//状态栏+titlebar
        showingArea.set(screenWidth,screenHeight-topHeight);


        Point point = getBestCameraResolution(para,showingArea);

        width = point.x;
        height= point.y;
        //todo 预览变形的问题
        Log.e("size","size w:"+width + "--h:"+height);
        /*:1920--h:1080
09-19 15:30:11.068 19768-19768/com.hss01248.facedemo E/size: size w:1440--h:1080
09-19 15:30:11.068 19768-19768/com.hss01248.facedemo E/size: size w:1280--h:720
09-19 15:30:11.068 19768-19768/com.hss01248.facedemo E/size: size w:1056--h:864
09-19 15:30:11.068 19768-19768/com.hss01248.facedemo E/size: size w:960--h:720
09-19 15:30:11.068 19768-19768/com.hss01248.facedemo E/size: size w:720--h:480
09-19 15:30:11.068 19768-19768/com.hss01248.facedemo E/size: size w:640--h:480
09-19 15:30:11.068 19768-19768/com.hss01248.facedemo E/size: size w:352--h:288
09-19 15:30:11.068 19768-19768/com.hss01248.facedemo E/size: size w:320--h:240*/

        para.setPreviewSize(width, height);
        mCamera.setParameters(para);
    }
 
Example 17
Source File: VideoPlayerActivity.java    From VCL-Android with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
private int getScreenOrientation(){
    WindowManager wm = (WindowManager) VLCApplication.getAppContext().getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    int rot = getScreenRotation();
    /*
     * Since getRotation() returns the screen's "natural" orientation,
     * which is not guaranteed to be SCREEN_ORIENTATION_PORTRAIT,
     * we have to invert the SCREEN_ORIENTATION value if it is "naturally"
     * landscape.
     */
    @SuppressWarnings("deprecation")
    boolean defaultWide = display.getWidth() > display.getHeight();
    if(rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270)
        defaultWide = !defaultWide;
    if(defaultWide) {
        switch (rot) {
        case Surface.ROTATION_0:
            return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
        case Surface.ROTATION_90:
            return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
        case Surface.ROTATION_180:
            // SCREEN_ORIENTATION_REVERSE_PORTRAIT only available since API
            // Level 9+
            return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
                    : ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        case Surface.ROTATION_270:
            // SCREEN_ORIENTATION_REVERSE_LANDSCAPE only available since API
            // Level 9+
            return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT
                    : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        default:
            return 0;
        }
    } else {
        switch (rot) {
        case Surface.ROTATION_0:
            return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
        case Surface.ROTATION_90:
            return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
        case Surface.ROTATION_180:
            // SCREEN_ORIENTATION_REVERSE_PORTRAIT only available since API
            // Level 9+
            return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT
                    : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        case Surface.ROTATION_270:
            // SCREEN_ORIENTATION_REVERSE_LANDSCAPE only available since API
            // Level 9+
            return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
                    : ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        default:
            return 0;
        }
    }
}
 
Example 18
Source File: DeviceUtils.java    From VideoRecord with MIT License 4 votes vote down vote up
@SuppressWarnings("deprecation")
public static int getScreenHeight(Context context) {
    Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    return display.getHeight();
}
 
Example 19
Source File: ThemeableActivity.java    From zom-android-matrix with Apache License 2.0 4 votes vote down vote up
public static boolean setBackgroundImage (Activity activity)
{
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(activity);
    boolean themeDark = settings.getBoolean("themeDark", false);
    String themebg = settings.getString("pref_background", "");

    if (themeDark)
    {

        if (activity != null)
            activity.setTheme(R.style.AppThemeDark);
    }
    else
    {

        if (activity != null)
            activity.setTheme(R.style.AppTheme);
    }


    if (themebg != null && themebg.length() > 0)
    {


        File fileThemeBg = new File(themebg);
        if (!fileThemeBg.exists())
            return false;

        if (mThemeBg == null || (!mThemeBg.equals(themebg)))
        {
            mThemeBg = themebg;

            Display display = activity.getWindowManager().getDefaultDisplay();
            int width = display.getWidth();  // deprecated
            int height = display.getHeight();  // deprecated

            final BitmapFactory.Options options = new BitmapFactory.Options();
            // Calculate inSampleSize
            options.inSampleSize = 4;

            Bitmap b = BitmapFactory.decodeFile(themebg, options);

            float ratio = ((float)width)/((float)height);
            int bgHeight = b.getHeight();
            int bgWidth = (int)(((float)b.getHeight()) * ratio);

            b = Bitmap.createBitmap(b, 0, 0,Math.min(b.getWidth(),bgWidth),bgHeight);

            mThemeDrawable = new BitmapDrawable(b);


        }

        activity.getWindow().setBackgroundDrawable(mThemeDrawable);
        return true;
    }
    
    return false;

}
 
Example 20
Source File: EncodeActivity.java    From android-apps with MIT License 4 votes vote down vote up
@Override
protected void onResume() {
  super.onResume();
  // This assumes the view is full screen, which is a good assumption
  WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE);
  Display display = manager.getDefaultDisplay();
  int width = display.getWidth();
  int height = display.getHeight();
  int smallerDimension = width < height ? width : height;
  smallerDimension = smallerDimension * 7 / 8;

  Intent intent = getIntent();
  if (intent == null) {
    return;
  }

  try {
    boolean useVCard = intent.getBooleanExtra(USE_VCARD_KEY, false);
    qrCodeEncoder = new QRCodeEncoder(this, intent, smallerDimension, useVCard);
    Bitmap bitmap = qrCodeEncoder.encodeAsBitmap();
    if (bitmap == null) {
      Log.w(TAG, "Could not encode barcode");
      showErrorMessage(R.string.msg_encode_contents_failed);
      qrCodeEncoder = null;
      return;
    }

    ImageView view = (ImageView) findViewById(R.id.image_view);
    view.setImageBitmap(bitmap);

    TextView contents = (TextView) findViewById(R.id.contents_text_view);
    if (intent.getBooleanExtra(Intents.Encode.SHOW_CONTENTS, true)) {
      contents.setText(qrCodeEncoder.getDisplayContents());
      setTitle(getString(R.string.app_name) + " - " + qrCodeEncoder.getTitle());
    } else {
      contents.setText("");
      setTitle(getString(R.string.app_name));
    }
  } catch (WriterException e) {
    Log.w(TAG, "Could not encode barcode", e);
    showErrorMessage(R.string.msg_encode_contents_failed);
    qrCodeEncoder = null;
  }
}