Merge "Cherry-pick system theme rebase to fix square UI on round watches" into cw-e-dev

This commit is contained in:
Alexander Hills
2015-09-14 18:34:32 +00:00
committed by Android (Google) Code Review
3 changed files with 96 additions and 122 deletions

View File

@@ -4235,6 +4235,11 @@ public final class ActivityThread {
configDiff = mConfiguration.updateFrom(config); configDiff = mConfiguration.updateFrom(config);
config = applyCompatConfiguration(mCurDefaultDisplayDpi); config = applyCompatConfiguration(mCurDefaultDisplayDpi);
final Theme systemTheme = getSystemContext().getTheme();
if ((systemTheme.getChangingConfigurations() & configDiff) != 0) {
systemTheme.rebase();
}
} }
ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(false, config); ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(false, config);

View File

@@ -1438,11 +1438,13 @@ public class Resources {
* if not already defined in the theme. * if not already defined in the theme.
*/ */
public void applyStyle(int resId, boolean force) { public void applyStyle(int resId, boolean force) {
synchronized (mKey) {
AssetManager.applyThemeStyle(mTheme, resId, force); AssetManager.applyThemeStyle(mTheme, resId, force);
mThemeResId = resId; mThemeResId = resId;
mKey.append(resId, force); mKey.append(resId, force);
} }
}
/** /**
* Set this theme to hold the same contents as the theme * Set this theme to hold the same contents as the theme
@@ -1454,11 +1456,15 @@ public class Resources {
* @param other The existing Theme to copy from. * @param other The existing Theme to copy from.
*/ */
public void setTo(Theme other) { public void setTo(Theme other) {
synchronized (mKey) {
synchronized (other.mKey) {
AssetManager.copyTheme(mTheme, other.mTheme); AssetManager.copyTheme(mTheme, other.mTheme);
mThemeResId = other.mThemeResId; mThemeResId = other.mThemeResId;
mKey.setTo(other.getKey()); mKey.setTo(other.getKey());
} }
}
}
/** /**
* Return a TypedArray holding the values defined by * Return a TypedArray holding the values defined by
@@ -1480,12 +1486,14 @@ public class Resources {
* @see #obtainStyledAttributes(AttributeSet, int[], int, int) * @see #obtainStyledAttributes(AttributeSet, int[], int, int)
*/ */
public TypedArray obtainStyledAttributes(@StyleableRes int[] attrs) { public TypedArray obtainStyledAttributes(@StyleableRes int[] attrs) {
synchronized (mKey) {
final int len = attrs.length; final int len = attrs.length;
final TypedArray array = TypedArray.obtain(Resources.this, len); final TypedArray array = TypedArray.obtain(Resources.this, len);
array.mTheme = this; array.mTheme = this;
AssetManager.applyStyle(mTheme, 0, 0, 0, attrs, array.mData, array.mIndices); AssetManager.applyStyle(mTheme, 0, 0, 0, attrs, array.mData, array.mIndices);
return array; return array;
} }
}
/** /**
* Return a TypedArray holding the values defined by the style * Return a TypedArray holding the values defined by the style
@@ -1494,7 +1502,7 @@ public class Resources {
* <p>Be sure to call {@link TypedArray#recycle() TypedArray.recycle()} when you are done * <p>Be sure to call {@link TypedArray#recycle() TypedArray.recycle()} when you are done
* with the array. * with the array.
* *
* @param resid The desired style resource. * @param resId The desired style resource.
* @param attrs The desired attributes in the style. * @param attrs The desired attributes in the style.
* *
* @throws NotFoundException Throws NotFoundException if the given ID does not exist. * @throws NotFoundException Throws NotFoundException if the given ID does not exist.
@@ -1507,40 +1515,16 @@ public class Resources {
* @see #obtainStyledAttributes(int[]) * @see #obtainStyledAttributes(int[])
* @see #obtainStyledAttributes(AttributeSet, int[], int, int) * @see #obtainStyledAttributes(AttributeSet, int[], int, int)
*/ */
public TypedArray obtainStyledAttributes(@StyleRes int resid, @StyleableRes int[] attrs) public TypedArray obtainStyledAttributes(@StyleRes int resId, @StyleableRes int[] attrs)
throws NotFoundException { throws NotFoundException {
synchronized (mKey) {
final int len = attrs.length; final int len = attrs.length;
final TypedArray array = TypedArray.obtain(Resources.this, len); final TypedArray array = TypedArray.obtain(Resources.this, len);
array.mTheme = this; array.mTheme = this;
if (false) { AssetManager.applyStyle(mTheme, 0, resId, 0, attrs, array.mData, array.mIndices);
int[] data = array.mData;
System.out.println("**********************************************************");
System.out.println("**********************************************************");
System.out.println("**********************************************************");
System.out.println("Attributes:");
String s = " Attrs:";
int i;
for (i=0; i<attrs.length; i++) {
s = s + " 0x" + Integer.toHexString(attrs[i]);
}
System.out.println(s);
s = " Found:";
TypedValue value = new TypedValue();
for (i=0; i<attrs.length; i++) {
int d = i*AssetManager.STYLE_NUM_ENTRIES;
value.type = data[d+AssetManager.STYLE_TYPE];
value.data = data[d+AssetManager.STYLE_DATA];
value.assetCookie = data[d+AssetManager.STYLE_ASSET_COOKIE];
value.resourceId = data[d+AssetManager.STYLE_RESOURCE_ID];
s = s + " 0x" + Integer.toHexString(attrs[i])
+ "=" + value;
}
System.out.println(s);
}
AssetManager.applyStyle(mTheme, 0, resid, 0, attrs, array.mData, array.mIndices);
return array; return array;
} }
}
/** /**
* Return a TypedArray holding the attribute values in * Return a TypedArray holding the attribute values in
@@ -1592,6 +1576,7 @@ public class Resources {
*/ */
public TypedArray obtainStyledAttributes(AttributeSet set, public TypedArray obtainStyledAttributes(AttributeSet set,
@StyleableRes int[] attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) { @StyleableRes int[] attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
synchronized (mKey) {
final int len = attrs.length; final int len = attrs.length;
final TypedArray array = TypedArray.obtain(Resources.this, len); final TypedArray array = TypedArray.obtain(Resources.this, len);
@@ -1601,42 +1586,14 @@ public class Resources {
// contained in the resources and such). // contained in the resources and such).
final XmlBlock.Parser parser = (XmlBlock.Parser) set; final XmlBlock.Parser parser = (XmlBlock.Parser) set;
AssetManager.applyStyle(mTheme, defStyleAttr, defStyleRes, AssetManager.applyStyle(mTheme, defStyleAttr, defStyleRes,
parser != null ? parser.mParseState : 0, attrs, array.mData, array.mIndices); parser != null ? parser.mParseState : 0,
attrs, array.mData, array.mIndices);
array.mTheme = this; array.mTheme = this;
array.mXml = parser; array.mXml = parser;
if (false) {
int[] data = array.mData;
System.out.println("Attributes:");
String s = " Attrs:";
int i;
for (i=0; i<set.getAttributeCount(); i++) {
s = s + " " + set.getAttributeName(i);
int id = set.getAttributeNameResource(i);
if (id != 0) {
s = s + "(0x" + Integer.toHexString(id) + ")";
}
s = s + "=" + set.getAttributeValue(i);
}
System.out.println(s);
s = " Found:";
TypedValue value = new TypedValue();
for (i=0; i<attrs.length; i++) {
int d = i*AssetManager.STYLE_NUM_ENTRIES;
value.type = data[d+AssetManager.STYLE_TYPE];
value.data = data[d+AssetManager.STYLE_DATA];
value.assetCookie = data[d+AssetManager.STYLE_ASSET_COOKIE];
value.resourceId = data[d+AssetManager.STYLE_RESOURCE_ID];
s = s + " 0x" + Integer.toHexString(attrs[i])
+ "=" + value;
}
System.out.println(s);
}
return array; return array;
} }
}
/** /**
* Retrieve the values for a set of attributes in the Theme. The * Retrieve the values for a set of attributes in the Theme. The
@@ -1654,6 +1611,7 @@ public class Resources {
*/ */
@NonNull @NonNull
public TypedArray resolveAttributes(@NonNull int[] values, @NonNull int[] attrs) { public TypedArray resolveAttributes(@NonNull int[] values, @NonNull int[] attrs) {
synchronized (mKey) {
final int len = attrs.length; final int len = attrs.length;
if (values == null || len != values.length) { if (values == null || len != values.length) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
@@ -1667,6 +1625,7 @@ public class Resources {
return array; return array;
} }
}
/** /**
* Retrieve the value of an attribute in the Theme. The contents of * Retrieve the value of an attribute in the Theme. The contents of
@@ -1686,14 +1645,9 @@ public class Resources {
* <var>outValue</var> is valid, else false. * <var>outValue</var> is valid, else false.
*/ */
public boolean resolveAttribute(int resid, TypedValue outValue, boolean resolveRefs) { public boolean resolveAttribute(int resid, TypedValue outValue, boolean resolveRefs) {
boolean got = mAssets.getThemeValue(mTheme, resid, outValue, resolveRefs); synchronized (mKey) {
if (false) { return mAssets.getThemeValue(mTheme, resid, outValue, resolveRefs);
System.out.println(
"resolveAttribute #" + Integer.toHexString(resid)
+ " got=" + got + ", type=0x" + Integer.toHexString(outValue.type)
+ ", data=0x" + Integer.toHexString(outValue.data));
} }
return got;
} }
/** /**
@@ -1739,9 +1693,12 @@ public class Resources {
* @see ActivityInfo * @see ActivityInfo
*/ */
public int getChangingConfigurations() { public int getChangingConfigurations() {
final int nativeChangingConfig = AssetManager.getThemeChangingConfigurations(mTheme); synchronized (mKey) {
final int nativeChangingConfig =
AssetManager.getThemeChangingConfigurations(mTheme);
return ActivityInfo.activityInfoConfigNativeToJava(nativeChangingConfig); return ActivityInfo.activityInfoConfigNativeToJava(nativeChangingConfig);
} }
}
/** /**
* Print contents of this theme out to the log. For debugging only. * Print contents of this theme out to the log. For debugging only.
@@ -1751,8 +1708,10 @@ public class Resources {
* @param prefix Text to prefix each line printed. * @param prefix Text to prefix each line printed.
*/ */
public void dump(int priority, String tag, String prefix) { public void dump(int priority, String tag, String prefix) {
synchronized (mKey) {
AssetManager.dumpTheme(mTheme, priority, tag, prefix); AssetManager.dumpTheme(mTheme, priority, tag, prefix);
} }
}
@Override @Override
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
@@ -1801,6 +1760,7 @@ public class Resources {
*/ */
@ViewDebug.ExportedProperty(category = "theme", hasAdjacentMapping = true) @ViewDebug.ExportedProperty(category = "theme", hasAdjacentMapping = true)
public String[] getTheme() { public String[] getTheme() {
synchronized (mKey) {
final int N = mKey.mCount; final int N = mKey.mCount;
final String[] themes = new String[N * 2]; final String[] themes = new String[N * 2];
for (int i = 0, j = N - 1; i < themes.length; i += 2, --j) { for (int i = 0, j = N - 1; i < themes.length; i += 2, --j) {
@@ -1815,6 +1775,7 @@ public class Resources {
} }
return themes; return themes;
} }
}
/** @hide */ /** @hide */
public void encode(@NonNull ViewHierarchyEncoder encoder) { public void encode(@NonNull ViewHierarchyEncoder encoder) {
@@ -1834,6 +1795,7 @@ public class Resources {
* @hide * @hide
*/ */
public void rebase() { public void rebase() {
synchronized (mKey) {
AssetManager.clearTheme(mTheme); AssetManager.clearTheme(mTheme);
// Reapply the same styles in the same order. // Reapply the same styles in the same order.
@@ -1844,6 +1806,7 @@ public class Resources {
} }
} }
} }
}
static class ThemeKey implements Cloneable { static class ThemeKey implements Cloneable {
int[] mResId; int[] mResId;

View File

@@ -1047,6 +1047,12 @@ public final class SystemServer {
w.getDefaultDisplay().getMetrics(metrics); w.getDefaultDisplay().getMetrics(metrics);
context.getResources().updateConfiguration(config, metrics); context.getResources().updateConfiguration(config, metrics);
// The system context's theme may be configuration-dependent.
final Theme systemTheme = context.getTheme();
if (systemTheme.getChangingConfigurations() != 0) {
systemTheme.rebase();
}
try { try {
// TODO: use boot phase // TODO: use boot phase
mPowerManagerService.systemReady(mActivityManagerService.getAppOpsService()); mPowerManagerService.systemReady(mActivityManagerService.getAppOpsService());