Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3fc982f4 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Add new resource configurations for screen width/height in "dp".

You can now specify resource configuration variants "wNNNdp"
and "hNNNdp".  These are the minimum screen width/height in "dp"
units.  This allows you to do things like have your app adjust
its layout based only on the about of horizontal space available.

This introduces a new configuration change flag for screen size.
Note that this configuration change happens each time the orientation
changes.  Applications often say they handle the orientation change
to avoid being restarted at a screen rotation, and this will now
cause them to be restarted.  To address this, we assume the app can
handle this new config change if its target SDK version is < ICS.

Change-Id: I22f8afa136b4f274423978c570fa7c9855040496
parent fb84ce0d
Loading
Loading
Loading
Loading
+65 −1
Original line number Diff line number Diff line
@@ -57955,6 +57955,17 @@
 visibility="public"
>
</field>
<field name="CONFIG_SCREEN_SIZE"
 type="int"
 transient="false"
 volatile="false"
 value="1024"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="CONFIG_TOUCHSCREEN"
 type="int"
 transient="false"
@@ -64017,6 +64028,28 @@
 visibility="public"
>
</field>
<field name="SCREEN_HEIGHT_DP_UNDEFINED"
 type="int"
 transient="false"
 volatile="false"
 value="0"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="SCREEN_WIDTH_DP_UNDEFINED"
 type="int"
 transient="false"
 volatile="false"
 value="0"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="TOUCHSCREEN_FINGER"
 type="int"
 transient="false"
@@ -64260,6 +64293,16 @@
 visibility="public"
>
</field>
<field name="screenHeightDp"
 type="int"
 transient="false"
 volatile="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="screenLayout"
 type="int"
 transient="false"
@@ -64270,6 +64313,16 @@
 visibility="public"
>
</field>
<field name="screenWidthDp"
 type="int"
 transient="false"
 volatile="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="touchscreen"
 type="int"
 transient="false"
@@ -144074,6 +144127,17 @@
 visibility="public"
>
</field>
<field name="ICE_CREAM_SANDWICH"
 type="int"
 transient="false"
 volatile="false"
 value="10000"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
</class>
<class name="Bundle"
 extends="java.lang.Object"
@@ -267777,7 +267841,7 @@
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="t" type="T">
<parameter name="arg0" type="T">
</parameter>
</method>
</interface>
+37 −0
Original line number Diff line number Diff line
@@ -332,6 +332,12 @@ public class ActivityInfo extends ComponentInfo
     * {@link android.R.attr#configChanges} attribute.
     */
    public static final int CONFIG_UI_MODE = 0x0200;
    /**
     * Bit in {@link #configChanges} that indicates that the activity
     * can itself handle the screen size. Set from the
     * {@link android.R.attr#configChanges} attribute.
     */
    public static final int CONFIG_SCREEN_SIZE = 0x0400;
    /**
     * Bit in {@link #configChanges} that indicates that the activity
     * can itself handle changes to the font scaling factor.  Set from the
@@ -341,6 +347,37 @@ public class ActivityInfo extends ComponentInfo
     */
    public static final int CONFIG_FONT_SCALE = 0x40000000;
    
    /** @hide
     * Unfortunately the constants for config changes in native code are
     * different from ActivityInfo. :(  Here are the values we should use for the
     * native side given the bit we have assigned in ActivityInfo.
     */
    public static int[] CONFIG_NATIVE_BITS = new int[] {
        0x0001, // MNC
        0x0002, // MCC
        0x0004, // LOCALE
        0x0008, // TOUCH SCREEN
        0x0010, // KEYBOARD
        0x0020, // KEYBOARD HIDDEN
        0x0040, // NAVIGATION
        0x0080, // ORIENTATION
        0x0800, // SCREEN LAYOUT
        0x1000, // UI MODE
        0x0200, // SCREEN SIZE
    };
    /** @hide
     * Convert Java change bits to native.
     */
    public static int activityInfoConfigToNative(int input) {
        int output = 0;
        for (int i=0; i<CONFIG_NATIVE_BITS.length; i++) {
            if ((input&(1<<i)) != 0) {
                output |= CONFIG_NATIVE_BITS[i];
            }
        }
        return output;
    }

    /**
     * Bit mask of kinds of configuration changes that this activity
     * can handle itself (without being restarted by the system).
+6 −2
Original line number Diff line number Diff line
@@ -396,7 +396,7 @@ public class PackageParser {
            int cookie = assmgr.addAssetPath(mArchiveSourcePath);
            if (cookie != 0) {
                res = new Resources(assmgr, metrics, null);
                assmgr.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                assmgr.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                        Build.VERSION.RESOURCES_SDK_INT);
                parser = assmgr.openXmlResourceParser(cookie, "AndroidManifest.xml");
                assetError = false;
@@ -596,7 +596,7 @@ public class PackageParser {
        AssetManager assmgr = null;
        try {
            assmgr = new AssetManager();
            assmgr.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            assmgr.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    Build.VERSION.RESOURCES_SDK_INT);
            int cookie = assmgr.addAssetPath(packageFilePath);
            parser = assmgr.openXmlResourceParser(cookie, "AndroidManifest.xml");
@@ -1931,6 +1931,10 @@ public class PackageParser {
            a.info.configChanges = sa.getInt(
                    com.android.internal.R.styleable.AndroidManifestActivity_configChanges,
                    0);
            if (owner.applicationInfo.targetSdkVersion
                        < android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                a.info.configChanges |= ActivityInfo.CONFIG_SCREEN_SIZE;
            }
            a.info.softInputMode = sa.getInt(
                    com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode,
                    0);
+2 −1
Original line number Diff line number Diff line
@@ -652,7 +652,8 @@ public final class AssetManager {
    public native final void setConfiguration(int mcc, int mnc, String locale,
            int orientation, int touchscreen, int density, int keyboard,
            int keyboardHidden, int navigation, int screenWidth, int screenHeight,
            int screenLayout, int uiMode, int majorVersion);
            int screenWidthDp, int screenHeightDp, int screenLayout, int uiMode,
            int majorVersion);

    /**
     * Retrieve the resource identifier for the given resource name.
+54 −3
Original line number Diff line number Diff line
@@ -241,6 +241,20 @@ public final class Configuration implements Parcelable, Comparable<Configuration
     */
    public int uiMode;

    public static final int SCREEN_WIDTH_DP_UNDEFINED = 0;

    /**
     * The current width of the available screen space, in dp units.
     */
    public int screenWidthDp;

    public static final int SCREEN_HEIGHT_DP_UNDEFINED = 0;

    /**
     * The current height of the available screen space, in dp units.
     */
    public int screenHeightDp;

    /**
     * @hide Internal book-keeping.
     */
@@ -278,6 +292,8 @@ public final class Configuration implements Parcelable, Comparable<Configuration
        orientation = o.orientation;
        screenLayout = o.screenLayout;
        uiMode = o.uiMode;
        screenWidthDp = o.screenWidthDp;
        screenHeightDp = o.screenHeightDp;
        seq = o.seq;
    }
    
@@ -316,6 +332,10 @@ public final class Configuration implements Parcelable, Comparable<Configuration
        sb.append(java.lang.Integer.toHexString(screenLayout));
        sb.append(" uiMode=0x");
        sb.append(java.lang.Integer.toHexString(uiMode));
        sb.append(" wdp=");
        sb.append(screenWidthDp);
        sb.append(" hdp=");
        sb.append(screenHeightDp);
        if (seq != 0) {
            sb.append(" seq=");
            sb.append(seq);
@@ -341,6 +361,8 @@ public final class Configuration implements Parcelable, Comparable<Configuration
        orientation = ORIENTATION_UNDEFINED;
        screenLayout = SCREENLAYOUT_SIZE_UNDEFINED;
        uiMode = UI_MODE_TYPE_UNDEFINED;
        screenWidthDp = SCREEN_WIDTH_DP_UNDEFINED;
        screenHeightDp = SCREEN_HEIGHT_DP_UNDEFINED;
        seq = 0;
    }

@@ -434,6 +456,16 @@ public final class Configuration implements Parcelable, Comparable<Configuration
                        | (delta.uiMode&UI_MODE_NIGHT_MASK);
            }
        }
        if (delta.screenWidthDp != SCREEN_WIDTH_DP_UNDEFINED
                && screenWidthDp != delta.screenWidthDp) {
            changed |= ActivityInfo.CONFIG_SCREEN_SIZE;
            screenWidthDp = delta.screenWidthDp;
        }
        if (delta.screenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED
                && screenHeightDp != delta.screenHeightDp) {
            changed |= ActivityInfo.CONFIG_SCREEN_SIZE;
            screenHeightDp = delta.screenHeightDp;
        }
        
        if (delta.seq != 0) {
            seq = delta.seq;
@@ -463,9 +495,11 @@ public final class Configuration implements Parcelable, Comparable<Configuration
     * {@link android.content.pm.ActivityInfo#CONFIG_NAVIGATION
     * PackageManager.ActivityInfo.CONFIG_NAVIGATION},
     * {@link android.content.pm.ActivityInfo#CONFIG_ORIENTATION
     * PackageManager.ActivityInfo.CONFIG_ORIENTATION}, or
     * PackageManager.ActivityInfo.CONFIG_ORIENTATION},
     * {@link android.content.pm.ActivityInfo#CONFIG_SCREEN_LAYOUT
     * PackageManager.ActivityInfo.CONFIG_SCREEN_LAYOUT}.
     * PackageManager.ActivityInfo.CONFIG_SCREEN_LAYOUT}, or
     * {@link android.content.pm.ActivityInfo#CONFIG_SCREEN_SIZE
     * PackageManager.ActivityInfo.CONFIG_SCREEN_SIZE}.
     */
    public int diff(Configuration delta) {
        int changed = 0;
@@ -518,6 +552,14 @@ public final class Configuration implements Parcelable, Comparable<Configuration
                && uiMode != delta.uiMode) {
            changed |= ActivityInfo.CONFIG_UI_MODE;
        }
        if (delta.screenWidthDp != SCREEN_WIDTH_DP_UNDEFINED
                && screenWidthDp != delta.screenWidthDp) {
            changed |= ActivityInfo.CONFIG_SCREEN_SIZE;
        }
        if (delta.screenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED
                && screenHeightDp != delta.screenHeightDp) {
            changed |= ActivityInfo.CONFIG_SCREEN_SIZE;
        }
        
        return changed;
    }
@@ -599,6 +641,8 @@ public final class Configuration implements Parcelable, Comparable<Configuration
        dest.writeInt(orientation);
        dest.writeInt(screenLayout);
        dest.writeInt(uiMode);
        dest.writeInt(screenWidthDp);
        dest.writeInt(screenHeightDp);
        dest.writeInt(seq);
    }

@@ -620,6 +664,8 @@ public final class Configuration implements Parcelable, Comparable<Configuration
        orientation = source.readInt();
        screenLayout = source.readInt();
        uiMode = source.readInt();
        screenWidthDp = source.readInt();
        screenHeightDp = source.readInt();
        seq = source.readInt();
    }
    
@@ -680,6 +726,10 @@ public final class Configuration implements Parcelable, Comparable<Configuration
        n = this.screenLayout - that.screenLayout;
        if (n != 0) return n;
        n = this.uiMode - that.uiMode;
        if (n != 0) return n;
        n = this.screenWidthDp - that.screenWidthDp;
        if (n != 0) return n;
        n = this.screenHeightDp - that.screenHeightDp;
        //if (n != 0) return n;
        return n;
    }
@@ -704,6 +754,7 @@ public final class Configuration implements Parcelable, Comparable<Configuration
                + this.touchscreen
                + this.keyboard + this.keyboardHidden + this.hardKeyboardHidden
                + this.navigation + this.navigationHidden
                + this.orientation + this.screenLayout + this.uiMode;
                + this.orientation + this.screenLayout + this.uiMode
                + this.screenWidthDp + this.screenHeightDp;
    }
}
Loading