diff options
author | Dianne Hackborn <hackbod@google.com> | 2013-04-19 14:09:37 -0700 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2013-04-19 14:50:27 -0700 |
commit | f1ae269c0665f266b904db7c9ef4511e11459f44 (patch) | |
tree | fd68efbc22282da227784fd0d42e1c5364069b14 /core | |
parent | 26a54ecaa556f72086790caa133e5a8d31652d8a (diff) | |
download | frameworks_base-f1ae269c0665f266b904db7c9ef4511e11459f44.zip frameworks_base-f1ae269c0665f266b904db7c9ef4511e11459f44.tar.gz frameworks_base-f1ae269c0665f266b904db7c9ef4511e11459f44.tar.bz2 |
Follow up on issue #8159072: Spinner widget should be RTL'ized
Only allow through changing direction configs for drawables.
Explicitly map layout direction values to an index in the
preload arrays.
Drawables that don't vary by configuration should go in to both
the rtl and ltr preloads.
Change-Id: Ib92dd11738082a795e02d1d4191adb54702d651c
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/content/res/Configuration.java | 8 | ||||
-rw-r--r-- | core/java/android/content/res/Resources.java | 57 |
2 files changed, 43 insertions, 22 deletions
diff --git a/core/java/android/content/res/Configuration.java b/core/java/android/content/res/Configuration.java index 86d6ee7..905ae0d 100644 --- a/core/java/android/content/res/Configuration.java +++ b/core/java/android/content/res/Configuration.java @@ -1219,12 +1219,12 @@ public final class Configuration implements Parcelable, Comparable<Configuration * Return the layout direction. Will be either {@link View#LAYOUT_DIRECTION_LTR} or * {@link View#LAYOUT_DIRECTION_RTL}. * - * @return the layout direction + * @return Returns {@link View#LAYOUT_DIRECTION_RTL} if the configuration + * is {@link #SCREENLAYOUT_LAYOUTDIR_RTL}, otherwise {@link View#LAYOUT_DIRECTION_LTR}. */ public int getLayoutDirection() { - // We need to substract one here as the configuration values are using "0" as undefined thus - // having LRT set to "1" and RTL set to "2" - return ((screenLayout&SCREENLAYOUT_LAYOUTDIR_MASK) >> SCREENLAYOUT_LAYOUTDIR_SHIFT) - 1; + return (screenLayout&SCREENLAYOUT_LAYOUTDIR_MASK) == SCREENLAYOUT_LAYOUTDIR_RTL + ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR; } /** diff --git a/core/java/android/content/res/Resources.java b/core/java/android/content/res/Resources.java index d8d5f2b..42f4faf 100644 --- a/core/java/android/content/res/Resources.java +++ b/core/java/android/content/res/Resources.java @@ -1985,13 +1985,14 @@ public class Resources { } } - static private final int VARYING_CONFIGS = ActivityInfo.activityInfoConfigToNative( - ActivityInfo.CONFIG_LAYOUT_DIRECTION); - - private boolean verifyPreloadConfig(int changingConfigurations, int resourceId, String name) { - // We dont want to preloadd a Drawable when there is both a LTR and RTL version of it + private boolean verifyPreloadConfig(int changingConfigurations, int allowVarying, + int resourceId, String name) { + // We allow preloading of resources even if they vary by font scale (which + // doesn't impact resource selection) or density (which we handle specially by + // simply turning off all preloading), as well as any other configs specified + // by the caller. if (((changingConfigurations&~(ActivityInfo.CONFIG_FONT_SCALE | - ActivityInfo.CONFIG_DENSITY)) & VARYING_CONFIGS) != 0) { + ActivityInfo.CONFIG_DENSITY)) & ~allowVarying) != 0) { String resName; try { resName = getResourceName(resourceId); @@ -2017,6 +2018,9 @@ public class Resources { return true; } + static private final int LAYOUT_DIR_CONFIG = ActivityInfo.activityInfoConfigToNative( + ActivityInfo.CONFIG_LAYOUT_DIRECTION); + /*package*/ Drawable loadDrawable(TypedValue value, int id) throws NotFoundException { @@ -2041,11 +2045,12 @@ public class Resources { if (dr != null) { return dr; } - final int layoutDirection = mConfiguration.getLayoutDirection(); - Drawable.ConstantState cs = isColorDrawable - ? sPreloadedColorDrawables.get(key) - : (sPreloadedDensity == mConfiguration.densityDpi - ? sPreloadedDrawables[layoutDirection].get(key) : null); + Drawable.ConstantState cs; + if (isColorDrawable) { + cs = sPreloadedColorDrawables.get(key); + } else { + cs = sPreloadedDrawables[mConfiguration.getLayoutDirection()].get(key); + } if (cs != null) { dr = cs.newDrawable(this); } else { @@ -2119,12 +2124,26 @@ public class Resources { cs = dr.getConstantState(); if (cs != null) { if (mPreloading) { - if (verifyPreloadConfig(cs.getChangingConfigurations(), value.resourceId, - "drawable")) { - if (isColorDrawable) { + final int changingConfigs = cs.getChangingConfigurations(); + if (isColorDrawable) { + if (verifyPreloadConfig(changingConfigs, 0, value.resourceId, + "drawable")) { sPreloadedColorDrawables.put(key, cs); - } else { - sPreloadedDrawables[layoutDirection].put(key, cs); + } + } else { + if (verifyPreloadConfig(changingConfigs, + LAYOUT_DIR_CONFIG, value.resourceId, "drawable")) { + if ((changingConfigs&LAYOUT_DIR_CONFIG) == 0) { + // If this resource does not vary based on layout direction, + // we can put it in all of the preload maps. + sPreloadedDrawables[0].put(key, cs); + sPreloadedDrawables[1].put(key, cs); + } else { + // Otherwise, only in the layout dir we loaded it for. + final LongSparseArray<Drawable.ConstantState> preloads + = sPreloadedDrawables[mConfiguration.getLayoutDirection()]; + preloads.put(key, cs); + } } } } else { @@ -2190,7 +2209,8 @@ public class Resources { csl = ColorStateList.valueOf(value.data); if (mPreloading) { - if (verifyPreloadConfig(value.changingConfigurations, value.resourceId, "color")) { + if (verifyPreloadConfig(value.changingConfigurations, 0, value.resourceId, + "color")) { sPreloadedColorStateLists.put(key, csl); } } @@ -2239,7 +2259,8 @@ public class Resources { if (csl != null) { if (mPreloading) { - if (verifyPreloadConfig(value.changingConfigurations, value.resourceId, "color")) { + if (verifyPreloadConfig(value.changingConfigurations, 0, value.resourceId, + "color")) { sPreloadedColorStateLists.put(key, csl); } } else { |