From 29f14066bdb970b99e86387e8b870823d4607ec0 Mon Sep 17 00:00:00 2001 From: khanhduytran0 Date: Fri, 20 Nov 2020 13:21:18 +0700 Subject: [PATCH] [Custom controls] Fix another crash --- .../com/kdt/handleview/ActionPopupWindow.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/app/src/main/java/com/kdt/handleview/ActionPopupWindow.java b/app/src/main/java/com/kdt/handleview/ActionPopupWindow.java index 3982e9bda..fe5bf43f5 100644 --- a/app/src/main/java/com/kdt/handleview/ActionPopupWindow.java +++ b/app/src/main/java/com/kdt/handleview/ActionPopupWindow.java @@ -42,11 +42,44 @@ public class ActionPopupWindow extends PinnedPopupWindow implements OnClickListe } private int getInternalId(String type, String name) { +/* int id = Resources.getSystem().getIdentifier(name, type, "com.android.internal"); if (id == 0) { mHandleView.getContext().getResources().getIdentifier(name, type, "android"); } 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