Merge "Update DisplayMetrics when resizing" into nyc-mr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
038084e61c
@@ -149,17 +149,17 @@ public class ResourcesManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DisplayMetrics getDisplayMetrics() {
|
DisplayMetrics getDisplayMetrics() {
|
||||||
return getDisplayMetrics(Display.DEFAULT_DISPLAY);
|
return getDisplayMetrics(Display.DEFAULT_DISPLAY,
|
||||||
|
DisplayAdjustments.DEFAULT_DISPLAY_ADJUSTMENTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Protected so that tests can override and returns something a fixed value.
|
* Protected so that tests can override and returns something a fixed value.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected @NonNull DisplayMetrics getDisplayMetrics(int displayId) {
|
protected @NonNull DisplayMetrics getDisplayMetrics(int displayId, DisplayAdjustments da) {
|
||||||
DisplayMetrics dm = new DisplayMetrics();
|
DisplayMetrics dm = new DisplayMetrics();
|
||||||
final Display display =
|
final Display display = getAdjustedDisplay(displayId, da);
|
||||||
getAdjustedDisplay(displayId, DisplayAdjustments.DEFAULT_DISPLAY_ADJUSTMENTS);
|
|
||||||
if (display != null) {
|
if (display != null) {
|
||||||
display.getMetrics(dm);
|
display.getMetrics(dm);
|
||||||
} else {
|
} else {
|
||||||
@@ -304,11 +304,13 @@ public class ResourcesManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private @NonNull ResourcesImpl createResourcesImpl(@NonNull ResourcesKey key) {
|
private @NonNull ResourcesImpl createResourcesImpl(@NonNull ResourcesKey key) {
|
||||||
|
final DisplayAdjustments daj = new DisplayAdjustments(key.mOverrideConfiguration);
|
||||||
|
daj.setCompatibilityInfo(key.mCompatInfo);
|
||||||
|
|
||||||
final AssetManager assets = createAssetManager(key);
|
final AssetManager assets = createAssetManager(key);
|
||||||
final DisplayMetrics dm = getDisplayMetrics(key.mDisplayId);
|
final DisplayMetrics dm = getDisplayMetrics(key.mDisplayId, daj);
|
||||||
final Configuration config = generateConfig(key, dm);
|
final Configuration config = generateConfig(key, dm);
|
||||||
final ResourcesImpl impl = new ResourcesImpl(assets, dm, config, key.mCompatInfo,
|
final ResourcesImpl impl = new ResourcesImpl(assets, dm, config, daj);
|
||||||
key.mOverrideConfiguration);
|
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Slog.d(TAG, "- creating impl=" + impl + " with key: " + key);
|
Slog.d(TAG, "- creating impl=" + impl + " with key: " + key);
|
||||||
}
|
}
|
||||||
@@ -805,7 +807,16 @@ public class ResourcesManager {
|
|||||||
}
|
}
|
||||||
tmpConfig.setTo(config);
|
tmpConfig.setTo(config);
|
||||||
if (!isDefaultDisplay) {
|
if (!isDefaultDisplay) {
|
||||||
dm = getDisplayMetrics(displayId);
|
// Get new DisplayMetrics based on the DisplayAdjustments given
|
||||||
|
// to the ResourcesImpl. Udate a copy if the CompatibilityInfo
|
||||||
|
// changed, because the ResourcesImpl object will handle the
|
||||||
|
// update internally.
|
||||||
|
DisplayAdjustments daj = r.getDisplayAdjustments();
|
||||||
|
if (compat != null) {
|
||||||
|
daj = new DisplayAdjustments(daj);
|
||||||
|
daj.setCompatibilityInfo(compat);
|
||||||
|
}
|
||||||
|
dm = getDisplayMetrics(displayId, daj);
|
||||||
applyNonDefaultDisplayMetricsToConfiguration(dm, tmpConfig);
|
applyNonDefaultDisplayMetricsToConfiguration(dm, tmpConfig);
|
||||||
}
|
}
|
||||||
if (hasOverrideConfiguration) {
|
if (hasOverrideConfiguration) {
|
||||||
|
|||||||
@@ -209,8 +209,7 @@ public class Resources {
|
|||||||
*/
|
*/
|
||||||
public Resources(AssetManager assets, DisplayMetrics metrics, Configuration config) {
|
public Resources(AssetManager assets, DisplayMetrics metrics, Configuration config) {
|
||||||
this(null);
|
this(null);
|
||||||
mResourcesImpl = new ResourcesImpl(assets, metrics, config,
|
mResourcesImpl = new ResourcesImpl(assets, metrics, config, new DisplayAdjustments());
|
||||||
CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -238,7 +237,7 @@ public class Resources {
|
|||||||
config.setToDefaults();
|
config.setToDefaults();
|
||||||
|
|
||||||
mResourcesImpl = new ResourcesImpl(AssetManager.getSystem(), metrics, config,
|
mResourcesImpl = new ResourcesImpl(AssetManager.getSystem(), metrics, config,
|
||||||
CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO);
|
new DisplayAdjustments());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -114,12 +114,11 @@ public class ResourcesImpl {
|
|||||||
|
|
||||||
final AssetManager mAssets;
|
final AssetManager mAssets;
|
||||||
private final DisplayMetrics mMetrics = new DisplayMetrics();
|
private final DisplayMetrics mMetrics = new DisplayMetrics();
|
||||||
private final DisplayAdjustments mDisplayAdjustments = new DisplayAdjustments();
|
private final DisplayAdjustments mDisplayAdjustments;
|
||||||
|
|
||||||
private PluralRules mPluralRule;
|
private PluralRules mPluralRule;
|
||||||
|
|
||||||
private final Configuration mConfiguration = new Configuration();
|
private final Configuration mConfiguration = new Configuration();
|
||||||
private CompatibilityInfo mCompatibilityInfo = CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO;
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
sPreloadedDrawables = new LongSparseArray[2];
|
sPreloadedDrawables = new LongSparseArray[2];
|
||||||
@@ -135,37 +134,15 @@ public class ResourcesImpl {
|
|||||||
* selecting/computing resource values.
|
* selecting/computing resource values.
|
||||||
* @param config Desired device configuration to consider when
|
* @param config Desired device configuration to consider when
|
||||||
* selecting/computing resource values (optional).
|
* selecting/computing resource values (optional).
|
||||||
* @param compatInfo this resource's compatibility info. Must not be null.
|
* @param displayAdjustments this resource's Display override and compatibility info.
|
||||||
|
* Must not be null.
|
||||||
*/
|
*/
|
||||||
public ResourcesImpl(@NonNull AssetManager assets, @Nullable DisplayMetrics metrics,
|
public ResourcesImpl(@NonNull AssetManager assets, @Nullable DisplayMetrics metrics,
|
||||||
@Nullable Configuration config, @NonNull CompatibilityInfo compatInfo) {
|
@Nullable Configuration config, @NonNull DisplayAdjustments displayAdjustments) {
|
||||||
this(assets, metrics, config, compatInfo, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new ResourcesImpl object with CompatibilityInfo and assigns a static overrideConfig
|
|
||||||
* that is reported with getDisplayAdjustments(). This is used for updating the Display
|
|
||||||
* when a new ResourcesImpl is created due to multi-window configuration changes.
|
|
||||||
*
|
|
||||||
* @param assets Previously created AssetManager.
|
|
||||||
* @param metrics Current display metrics to consider when selecting/computing resource values.
|
|
||||||
* @param fullConfig Desired device configuration to consider when selecting/computing
|
|
||||||
* resource values.
|
|
||||||
* @param compatInfo this resource's compatibility info. Must not be null.
|
|
||||||
* @param overrideConfig the overrides specific to this ResourcesImpl object. They must already
|
|
||||||
* be applied to the fullConfig and are mainly maintained in order to return a valid
|
|
||||||
* DisplayAdjustments object during configuration changes.
|
|
||||||
*/
|
|
||||||
public ResourcesImpl(@NonNull AssetManager assets, @Nullable DisplayMetrics metrics,
|
|
||||||
@Nullable Configuration fullConfig, @NonNull CompatibilityInfo compatInfo,
|
|
||||||
@Nullable Configuration overrideConfig) {
|
|
||||||
mAssets = assets;
|
mAssets = assets;
|
||||||
mMetrics.setToDefaults();
|
mMetrics.setToDefaults();
|
||||||
mDisplayAdjustments.setCompatibilityInfo(compatInfo);
|
mDisplayAdjustments = displayAdjustments;
|
||||||
if (overrideConfig != null) {
|
updateConfiguration(config, metrics, displayAdjustments.getCompatibilityInfo());
|
||||||
mDisplayAdjustments.setConfiguration(overrideConfig);
|
|
||||||
}
|
|
||||||
updateConfiguration(fullConfig, metrics, compatInfo);
|
|
||||||
mAssets.ensureStringBlocks();
|
mAssets.ensureStringBlocks();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,7 +169,7 @@ public class ResourcesImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CompatibilityInfo getCompatibilityInfo() {
|
CompatibilityInfo getCompatibilityInfo() {
|
||||||
return mCompatibilityInfo;
|
return mDisplayAdjustments.getCompatibilityInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
private PluralRules getPluralRule() {
|
private PluralRules getPluralRule() {
|
||||||
@@ -347,12 +324,13 @@ public class ResourcesImpl {
|
|||||||
synchronized (mAccessLock) {
|
synchronized (mAccessLock) {
|
||||||
if (false) {
|
if (false) {
|
||||||
Slog.i(TAG, "**** Updating config of " + this + ": old config is "
|
Slog.i(TAG, "**** Updating config of " + this + ": old config is "
|
||||||
+ mConfiguration + " old compat is " + mCompatibilityInfo);
|
+ mConfiguration + " old compat is "
|
||||||
|
+ mDisplayAdjustments.getCompatibilityInfo());
|
||||||
Slog.i(TAG, "**** Updating config of " + this + ": new config is "
|
Slog.i(TAG, "**** Updating config of " + this + ": new config is "
|
||||||
+ config + " new compat is " + compat);
|
+ config + " new compat is " + compat);
|
||||||
}
|
}
|
||||||
if (compat != null) {
|
if (compat != null) {
|
||||||
mCompatibilityInfo = compat;
|
mDisplayAdjustments.setCompatibilityInfo(compat);
|
||||||
}
|
}
|
||||||
if (metrics != null) {
|
if (metrics != null) {
|
||||||
mMetrics.setTo(metrics);
|
mMetrics.setTo(metrics);
|
||||||
@@ -366,7 +344,7 @@ public class ResourcesImpl {
|
|||||||
// it would be cleaner and more maintainable to just be
|
// it would be cleaner and more maintainable to just be
|
||||||
// consistently dealing with a compatible display everywhere in
|
// consistently dealing with a compatible display everywhere in
|
||||||
// the framework.
|
// the framework.
|
||||||
mCompatibilityInfo.applyToDisplayMetrics(mMetrics);
|
mDisplayAdjustments.getCompatibilityInfo().applyToDisplayMetrics(mMetrics);
|
||||||
|
|
||||||
final @Config int configChanges = calcConfigChanges(config);
|
final @Config int configChanges = calcConfigChanges(config);
|
||||||
|
|
||||||
@@ -440,7 +418,8 @@ public class ResourcesImpl {
|
|||||||
|
|
||||||
if (DEBUG_CONFIG) {
|
if (DEBUG_CONFIG) {
|
||||||
Slog.i(TAG, "**** Updating config of " + this + ": final config is "
|
Slog.i(TAG, "**** Updating config of " + this + ": final config is "
|
||||||
+ mConfiguration + " final compat is " + mCompatibilityInfo);
|
+ mConfiguration + " final compat is "
|
||||||
|
+ mDisplayAdjustments.getCompatibilityInfo());
|
||||||
}
|
}
|
||||||
|
|
||||||
mDrawableCache.onConfigurationChange(configChanges);
|
mDrawableCache.onConfigurationChange(configChanges);
|
||||||
@@ -480,7 +459,7 @@ public class ResourcesImpl {
|
|||||||
density = mMetrics.noncompatDensityDpi;
|
density = mMetrics.noncompatDensityDpi;
|
||||||
}
|
}
|
||||||
|
|
||||||
mCompatibilityInfo.applyToConfiguration(density, mTmpConfig);
|
mDisplayAdjustments.getCompatibilityInfo().applyToConfiguration(density, mTmpConfig);
|
||||||
|
|
||||||
if (mTmpConfig.getLocales().isEmpty()) {
|
if (mTmpConfig.getLocales().isEmpty()) {
|
||||||
mTmpConfig.setLocales(LocaleList.getDefault());
|
mTmpConfig.setLocales(LocaleList.getDefault());
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ public class DisplayAdjustments {
|
|||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"setConfiguration: Cannot modify DEFAULT_DISPLAY_ADJUSTMENTS");
|
"setConfiguration: Cannot modify DEFAULT_DISPLAY_ADJUSTMENTS");
|
||||||
}
|
}
|
||||||
mConfiguration = configuration;
|
mConfiguration = configuration != null ? configuration : Configuration.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Configuration getConfiguration() {
|
public Configuration getConfiguration() {
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ import android.support.test.filters.SmallTest;
|
|||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.Display;
|
import android.view.Display;
|
||||||
|
import android.view.DisplayAdjustments;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
public class ResourcesManagerTest extends TestCase {
|
public class ResourcesManagerTest extends TestCase {
|
||||||
@@ -58,7 +60,7 @@ public class ResourcesManagerTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected DisplayMetrics getDisplayMetrics(int displayId) {
|
protected DisplayMetrics getDisplayMetrics(int displayId, DisplayAdjustments daj) {
|
||||||
return mDisplayMetrics;
|
return mDisplayMetrics;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user