summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorBryce Lee <brycelee@google.com>2017-04-03 14:30:42 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2017-04-03 14:30:49 +0000
commit7efe56b779d4c44399513c4c92142df2bb8cc51f (patch)
tree81ba716b8e166a344b1c8d893fddd3459b84c289 /core/java
parentef3a28cb92039c198ed8e78a69d00bd9c8322dab (diff)
parent7566d76c618a48b8dcc981dac3cab1e42f864063 (diff)
Merge "Add app bounds to configuration." into oc-dev
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/content/res/Configuration.java68
-rw-r--r--core/java/android/view/DisplayInfo.java10
2 files changed, 72 insertions, 6 deletions
diff --git a/core/java/android/content/res/Configuration.java b/core/java/android/content/res/Configuration.java
index 99fbee1ea3cc..c8353c9bffb9 100644
--- a/core/java/android/content/res/Configuration.java
+++ b/core/java/android/content/res/Configuration.java
@@ -16,6 +16,11 @@
package android.content.res;
+import android.graphics.Point;
+import android.graphics.Rect;
+import android.util.DisplayMetrics;
+import android.view.Display;
+import android.view.DisplayInfo;
import com.android.internal.util.XmlUtils;
import org.xmlpull.v1.XmlPullParser;
@@ -293,6 +298,16 @@ public final class Configuration implements Parcelable, Comparable<Configuration
*/
public int screenLayout;
+ /**
+ * @hide
+ * {@link android.graphics.Rect} defining app bounds. The dimensions override usages of
+ * {@link DisplayInfo#appHeight} and {@link DisplayInfo#appWidth} and mirrors these values at
+ * the display level. Lower levels can override these values to provide custom bounds to enforce
+ * features such as a max aspect ratio.
+ * TODO(b/36812336): Move appBounds out of {@link Configuration}.
+ */
+ public Rect appBounds;
+
/** @hide */
static public int resetScreenLayout(int curLayout) {
return (curLayout&~(SCREENLAYOUT_LONG_MASK | SCREENLAYOUT_SIZE_MASK
@@ -882,6 +897,7 @@ public final class Configuration implements Parcelable, Comparable<Configuration
compatScreenWidthDp = o.compatScreenWidthDp;
compatScreenHeightDp = o.compatScreenHeightDp;
compatSmallestScreenWidthDp = o.compatSmallestScreenWidthDp;
+ setAppBounds(o.appBounds);
assetsSeq = o.assetsSeq;
seq = o.seq;
}
@@ -1032,6 +1048,9 @@ public final class Configuration implements Parcelable, Comparable<Configuration
case NAVIGATIONHIDDEN_YES: sb.append("/h"); break;
default: sb.append("/"); sb.append(navigationHidden); break;
}
+ if (appBounds != null) {
+ sb.append(" appBounds="); sb.append(appBounds);
+ }
if (assetsSeq != 0) {
sb.append(" as.").append(assetsSeq);
}
@@ -1066,6 +1085,7 @@ public final class Configuration implements Parcelable, Comparable<Configuration
smallestScreenWidthDp = compatSmallestScreenWidthDp = SMALLEST_SCREEN_WIDTH_DP_UNDEFINED;
densityDpi = DENSITY_DPI_UNDEFINED;
assetsSeq = ASSETS_SEQ_UNDEFINED;
+ appBounds = null;
seq = 0;
}
@@ -1253,6 +1273,10 @@ public final class Configuration implements Parcelable, Comparable<Configuration
if (delta.compatSmallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) {
compatSmallestScreenWidthDp = delta.compatSmallestScreenWidthDp;
}
+ if (delta.appBounds != null && !delta.appBounds.equals(appBounds)) {
+ changed |= ActivityInfo.CONFIG_SCREEN_SIZE;
+ setAppBounds(delta.appBounds);
+ }
if (delta.assetsSeq != ASSETS_SEQ_UNDEFINED) {
changed |= ActivityInfo.CONFIG_ASSETS_PATHS;
assetsSeq = delta.assetsSeq;
@@ -1399,6 +1423,13 @@ public final class Configuration implements Parcelable, Comparable<Configuration
changed |= ActivityInfo.CONFIG_ASSETS_PATHS;
}
+ // Make sure that one of the values is not null and that they are not equal.
+ if ((compareUndefined || delta.appBounds != null)
+ && appBounds != delta.appBounds
+ && (appBounds == null || !appBounds.equals(delta.appBounds))) {
+ changed |= ActivityInfo.CONFIG_SCREEN_SIZE;
+ }
+
return changed;
}
@@ -1494,6 +1525,7 @@ public final class Configuration implements Parcelable, Comparable<Configuration
dest.writeInt(compatScreenWidthDp);
dest.writeInt(compatScreenHeightDp);
dest.writeInt(compatSmallestScreenWidthDp);
+ dest.writeValue(appBounds);
dest.writeInt(assetsSeq);
dest.writeInt(seq);
}
@@ -1529,6 +1561,7 @@ public final class Configuration implements Parcelable, Comparable<Configuration
compatScreenWidthDp = source.readInt();
compatScreenHeightDp = source.readInt();
compatSmallestScreenWidthDp = source.readInt();
+ appBounds = (Rect) source.readValue(null);
assetsSeq = source.readInt();
seq = source.readInt();
}
@@ -1706,6 +1739,33 @@ public final class Configuration implements Parcelable, Comparable<Configuration
/**
* @hide
*
+ * Helper method for setting the app bounds.
+ */
+ public void setAppBounds(Rect rect) {
+ if (rect == null) {
+ appBounds = null;
+ return;
+ }
+
+ setAppBounds(rect.left, rect.top, rect.right, rect.bottom);
+ }
+
+ /**
+ * @hide
+ *
+ * Helper method for setting the app bounds.
+ */
+ public void setAppBounds(int left, int top, int right, int bottom) {
+ if (appBounds == null) {
+ appBounds = new Rect();
+ }
+
+ appBounds.set(left, top, right, bottom);
+ }
+
+ /**
+ * @hide
+ *
* Clears the locale without changing layout direction.
*/
public void clearLocales() {
@@ -2212,6 +2272,7 @@ public final class Configuration implements Parcelable, Comparable<Configuration
private static final String XML_ATTR_SCREEN_HEIGHT = "height";
private static final String XML_ATTR_SMALLEST_WIDTH = "sw";
private static final String XML_ATTR_DENSITY = "density";
+ private static final String XML_ATTR_APP_BOUNDS = "app_bounds";
/**
* Reads the attributes corresponding to Configuration member fields from the Xml parser.
@@ -2261,6 +2322,8 @@ public final class Configuration implements Parcelable, Comparable<Configuration
SMALLEST_SCREEN_WIDTH_DP_UNDEFINED);
configOut.densityDpi = XmlUtils.readIntAttribute(parser, XML_ATTR_DENSITY,
DENSITY_DPI_UNDEFINED);
+ configOut.appBounds =
+ Rect.unflattenFromString(XmlUtils.readStringAttribute(parser, XML_ATTR_APP_BOUNDS));
// For persistence, we don't care about assetsSeq, so do not read it out.
}
@@ -2332,6 +2395,11 @@ public final class Configuration implements Parcelable, Comparable<Configuration
XmlUtils.writeIntAttribute(xml, XML_ATTR_DENSITY, config.densityDpi);
}
+ if (config.appBounds != null) {
+ XmlUtils.writeStringAttribute(xml, XML_ATTR_APP_BOUNDS,
+ config.appBounds.flattenToString());
+ }
+
// For persistence, we do not care about assetsSeq, so do not write it out.
}
}
diff --git a/core/java/android/view/DisplayInfo.java b/core/java/android/view/DisplayInfo.java
index 3d11dcbf14bf..0cec496fa264 100644
--- a/core/java/android/view/DisplayInfo.java
+++ b/core/java/android/view/DisplayInfo.java
@@ -562,12 +562,10 @@ public final class DisplayInfo implements Parcelable {
outMetrics.xdpi = outMetrics.noncompatXdpi = physicalXDpi;
outMetrics.ydpi = outMetrics.noncompatYdpi = physicalYDpi;
- width = (configuration != null
- && configuration.screenWidthDp != Configuration.SCREEN_WIDTH_DP_UNDEFINED)
- ? (int)((configuration.screenWidthDp * outMetrics.density) + 0.5f) : width;
- height = (configuration != null
- && configuration.screenHeightDp != Configuration.SCREEN_HEIGHT_DP_UNDEFINED)
- ? (int)((configuration.screenHeightDp * outMetrics.density) + 0.5f) : height;
+ width = configuration != null && configuration.appBounds != null
+ ? configuration.appBounds.width() : width;
+ height = configuration != null && configuration.appBounds != null
+ ? configuration.appBounds.height() : height;
outMetrics.noncompatWidthPixels = outMetrics.widthPixels = width;
outMetrics.noncompatHeightPixels = outMetrics.heightPixels = height;