Skip to content
Permalink
Browse files

Improve app resizing on Chromebooks

Change-Id: I58de7133e0eb76d13353ed152c38137bbdb31a3d
  • Loading branch information
ewpatton authored and jisqyv committed Jan 16, 2020
1 parent ec35256 commit 4da346ef3bdc26d610c274a3a4c41f04ea414776
@@ -1,6 +1,6 @@
// -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2009-2011 Google, All Rights reserved
// Copyright 2011-2019 MIT, All rights reserved
// Copyright 2011-2020 MIT, All rights reserved
// Released under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0

@@ -984,7 +984,8 @@ private boolean writeAndroidManifest(File manifestFile) {

// The keyboard option prevents the app from stopping when a external (bluetooth)
// keyboard is attached.
out.write("android:configChanges=\"orientation|screenSize|keyboardHidden|keyboard\">\n");
out.write("android:configChanges=\"orientation|screenSize|keyboardHidden|keyboard|"
+ "screenLayout|smallestScreenSize\">\n");

out.write(" <intent-filter>\n");
out.write(" <action android:name=\"android.intent.action.MAIN\" />\n");
@@ -1,6 +1,6 @@
// -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2009-2015 Google, All Rights reserved
// Copyright 2011-2015 MIT, All rights reserved
// Copyright 2011-2020 MIT, All rights reserved
// Released under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0

@@ -13,7 +13,6 @@
import android.view.Display;
import android.view.WindowManager;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

@@ -75,12 +74,8 @@ public static float computeCompatibleScaling(Context context) {

float sw = width/(float)newWidth;
float sh = height/(float)newHeight;
float scale = sw < sh ? sw : sh;
if (scale < 1) {
scale = 1;
}

return scale;
return Math.max(1, Math.min(Math.min(sw, sh), MAXIMUM_ASPECT_RATIO));
}

/**
@@ -90,14 +85,19 @@ public static float computeCompatibleScaling(Context context) {
* @param context context to get screen size of.
* @param outSize Set to the real size of the display.
*/
public static void getRawScreenDim(Context context, Point outSize) {
private static void getRawScreenDim(Context context, Point outSize) {

final DisplayMetrics metrics = new DisplayMetrics();
final WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();

int sdkLevel = SdkLevel.getLevel();
if (sdkLevel >= SdkLevel.LEVEL_JELLYBEAN_MR1) {
if (sdkLevel >= SdkLevel.LEVEL_NOUGAT) {
// Needed for multi-window support
display.getMetrics(metrics);
outSize.x = metrics.widthPixels;
outSize.y = metrics.heightPixels;
} else if (sdkLevel >= SdkLevel.LEVEL_JELLYBEAN_MR1) {
// On API level 17, a public method was added to get the actual sizes
JellybeanUtil.getRealSize(display, outSize);
} else if ( sdkLevel > SdkLevel.LEVEL_GINGERBREAD_MR1){
@@ -1,6 +1,6 @@
// -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2009-2011 Google, All Rights reserved
// Copyright 2011-2012 MIT, All rights reserved
// Copyright 2011-2020 MIT, All rights reserved
// Released under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0

@@ -34,6 +34,7 @@
public static final int LEVEL_KITKAT = 19; // a.k.a. 4.4
public static final int LEVEL_LOLLIPOP = 21; // a.k.a. 5.0
public static final int LEVEL_MARSHMALLOW = 23; // a.k.a. 6.0
public static final int LEVEL_NOUGAT = 24; // a.k.a. 7.0

private SdkLevel() {
}

0 comments on commit 4da346e

Please sign in to comment.
You can’t perform that action at this time.