[Custom controls] Fix another crash

This commit is contained in:
khanhduytran0 2020-11-20 13:21:18 +07:00
parent 644af4eaaf
commit 29f14066bd

View File

@ -42,11 +42,44 @@ public class ActionPopupWindow extends PinnedPopupWindow implements OnClickListe
} }
private int getInternalId(String type, String name) { private int getInternalId(String type, String name) {
/*
int id = Resources.getSystem().getIdentifier(name, type, "com.android.internal"); int id = Resources.getSystem().getIdentifier(name, type, "com.android.internal");
if (id == 0) { if (id == 0) {
mHandleView.getContext().getResources().getIdentifier(name, type, "android"); mHandleView.getContext().getResources().getIdentifier(name, type, "android");
} }
return id; return id;
*/
try {
for (Class perType : Class.forName("com.android.internal.R").getDeclaredClasses()) {
if (perType.getSimpleName().equals(type)) {
try {
Field f = perType.getDeclaredField(name);
f.setAccessible(true);
return (int) f.get(null);
} catch (Throwable th) {
th.printStackTrace();
}
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
// If unable to find in com.android.internal.R, go find in android.R
for (Class perType : android.R.class.getDeclaredClasses()) {
if (perType.getSimpleName().equals(type)) {
try {
Field f = perType.getDeclaredField(name);
f.setAccessible(true);
return (int) f.get(null);
} catch (Throwable th) {
th.printStackTrace();
}
}
}
return -1;
} }
@Override @Override