BaseActivity: invalidate icon cache on Android P

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2018-06-04 16:42:38 +02:00
parent e5f6c24174
commit 8aab35a70d
2 changed files with 15 additions and 15 deletions

View File

@ -121,21 +121,20 @@ public abstract class BaseActivity extends AppCompatActivity implements Topic.Su
@Override
public void onTopicPublished(Topic topic) {
try {
Field f = getResources().getClass().getDeclaredField("mResourcesImpl");
f.setAccessible(true);
Object o = f.get(getResources());
f = o.getClass().getDeclaredField("mDrawableCache");
f.setAccessible(true);
o = f.get(o);
f = o.getClass().getSuperclass().getDeclaredField("mThemedEntries");
f.setAccessible(true);
o = f.get(o);
o.getClass().getMethod("clear").invoke(o);
} catch (Exception e) {
Log.e(TAG, "Failed to flush icon cache", e);
if (topic == Application.getComponent().getThemeChangeTopic()) {
try {
Field f = getResources().getClass().getDeclaredField("mResourcesImpl");
f.setAccessible(true);
Object o = f.get(getResources());
f = o.getClass().getDeclaredField("mDrawableCache");
f.setAccessible(true);
o = f.get(o);
o.getClass().getMethod("onConfigurationChange", int.class).invoke(o, -1);
} catch (Exception e) {
Log.e(TAG, "Failed to flush icon cache", e);
}
recreate();
}
recreate();
}
@Override

View File

@ -101,7 +101,8 @@ public class SettingsActivity extends AppCompatActivity implements Topic.Subscri
@Override
public void onTopicPublished(final Topic topic) {
recreate();
if (topic == Application.getComponent().getThemeChangeTopic())
recreate();
}
@Override