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

Commit e5fb3288 authored by Mitsuru Oshima's avatar Mitsuru Oshima
Browse files

resolution support fix/improvement

    * adding compatibility menu
    * backup gravity
    * set expanable=true if the screen size is hvga * density.
    * added "supports any density" mode. I'll add sdk check later.
    * disallow to catch orientation change event if the app is not expandable. This
      was causing layout problem under non-expandable mode. I discussed this with Mike C
      and we agreed to do this approach for now. We'll revisit if this causes problem to
      a lot of applications.
parent ca436e24
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -144,6 +144,13 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
     */
    public static final int FLAG_ALLOW_BACKUP = 1<<10;
    
    /**
     * Indicates that the application supports any densities;
     * {@hide}
     */
    public static final int ANY_DENSITY = -1;
    private static final int[] ANY_DENSITIES_ARRAY = { ANY_DENSITY };

    /**
     * Flags associated with the application.  Any combination of
     * {@link #FLAG_SYSTEM}, {@link #FLAG_DEBUGGABLE}, {@link #FLAG_HAS_CODE},
@@ -369,4 +376,14 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
        }
        return null;
    }

    /**
     * Disable compatibility mode
     * 
     * @hide
     */
    public void disableCompatibilityMode() {
        expandable = true;
        supportsDensities = ANY_DENSITIES_ARRAY;
    }
}
+16 −6
Original line number Diff line number Diff line
@@ -51,10 +51,17 @@ public class CompatibilityInfo {
    public final float mApplicationInvertedScale;
    
    /**
     * 
     * A boolean flag to indicates that the application can expand over the original size.
     * The flag is set to true if
     * 1) Application declares its expandable in manifest file using <expandable /> or
     * 2) The screen size is same as (320 x 480) * density. 
     */
    public boolean mExpandable;

    /**
     * A expandable flag in the configuration.
     */
    public final boolean mExpandable;
    public final boolean mConfiguredExpandable;
    
    /**
     * A boolean flag to tell if the application needs scaling (when mApplicationScale != 1.0f)
@@ -62,13 +69,16 @@ public class CompatibilityInfo {
    public final boolean mScalingRequired;

    public CompatibilityInfo(ApplicationInfo appInfo) {
        // A temp workaround to fix rotation issue.
        // mExpandable = appInfo.expandable;
        mExpandable = true;
        mExpandable = mConfiguredExpandable = appInfo.expandable;
        
        float packageDensityScale = -1.0f;
        if (appInfo.supportsDensities != null) {
            int minDiff = Integer.MAX_VALUE;
            for (int density : appInfo.supportsDensities) {
                if (density == ApplicationInfo.ANY_DENSITY) { 
                    packageDensityScale = 1.0f;
                    break;
                }
                int tmpDiff = Math.abs(DisplayMetrics.DEVICE_DENSITY - density);
                if (tmpDiff == 0) {
                    packageDensityScale = 1.0f;
@@ -92,7 +102,7 @@ public class CompatibilityInfo {

    private CompatibilityInfo() {
        mApplicationScale = mApplicationInvertedScale = 1.0f;
        mExpandable = true;
        mExpandable = mConfiguredExpandable = true;
        mScalingRequired = false;
    }

+3 −3
Original line number Diff line number Diff line
@@ -1268,7 +1268,7 @@ public class Resources {
            }
            if (metrics != null) {
                mMetrics.setTo(metrics);
                mMetrics.updateMetrics(mCompatibilityInfo, mConfiguration);
                mMetrics.updateMetrics(mCompatibilityInfo, mConfiguration.orientation);
            }
            mMetrics.scaledDensity = mMetrics.density * mConfiguration.fontScale;

+8 −0
Original line number Diff line number Diff line
@@ -1024,6 +1024,14 @@ public final class Settings {
         */
        public static final String SCREEN_OFF_TIMEOUT = "screen_off_timeout";

        /**
         * If 0, the compatibility mode is off for all applications.
         * If 1, older applications run under compatibility mode.
         * TODO: remove this settings before code freeze (bug/1907571)
         * @hide
         */
        public static final String COMPATIBILITY_MODE = "compatibility_mode";

        /**
         * The screen backlight brightness between 0 and 255.
         */
+22 −11
Original line number Diff line number Diff line
@@ -103,10 +103,10 @@ public class DisplayMetrics {
    }

    /**
     * Update the display metrics based on the compatibility info and configuration.
     * Update the display metrics based on the compatibility info and orientation
     * {@hide}
     */
    public void updateMetrics(CompatibilityInfo compatibilityInfo, Configuration configuration) {
    public void updateMetrics(CompatibilityInfo compatibilityInfo, int orientation) {
        if (compatibilityInfo.mScalingRequired) {
            float invertedRatio = compatibilityInfo.mApplicationInvertedScale;
            density *= invertedRatio;
@@ -116,25 +116,35 @@ public class DisplayMetrics {
            widthPixels *= invertedRatio;
            heightPixels *= invertedRatio;
        }
        if (!compatibilityInfo.mExpandable) {
        if (!compatibilityInfo.mConfiguredExpandable) {
            // Note: this assume that configuration is updated before calling
            // updateMetrics method.
            int defaultWidth;
            int defaultHeight;
            switch (configuration.orientation) {
            switch (orientation) {
                case Configuration.ORIENTATION_LANDSCAPE: {
                    defaultWidth = (int)(CompatibilityInfo.DEFAULT_PORTRAIT_HEIGHT * density);
                    defaultHeight = (int)(CompatibilityInfo.DEFAULT_PORTRAIT_WIDTH * density);
                    break;
                }
                case Configuration.ORIENTATION_UNDEFINED:
                case Configuration.ORIENTATION_PORTRAIT:
                case Configuration.ORIENTATION_SQUARE:
                default: {
                    defaultWidth = (int)(CompatibilityInfo.DEFAULT_PORTRAIT_WIDTH * density);
                    defaultHeight = (int)(CompatibilityInfo.DEFAULT_PORTRAIT_HEIGHT * density);
                    break;
                }
                case Configuration.ORIENTATION_UNDEFINED: {
                    // don't change
                    return;
                }
            }
            
            if (defaultWidth == widthPixels && defaultHeight == heightPixels) {
                // the screen size is same as expected size. make it expandable
                compatibilityInfo.mExpandable = true;
            } else {
                compatibilityInfo.mExpandable = false;
                // adjust the size only when the device's screen is bigger.
                if (defaultWidth < widthPixels) {
                    widthPixels = defaultWidth;
@@ -144,6 +154,7 @@ public class DisplayMetrics {
                }
            }
        }
    }

    public String toString() {
        return "DisplayMetrics{density=" + density + ", width=" + widthPixels +
Loading