diff options
author | Christian Schneppe <christian@pix-art.de> | 2017-03-04 18:18:34 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2017-03-04 18:18:34 +0100 |
commit | 8eff9bd35c8c2011cc92d8ccb722483f79b612a9 (patch) | |
tree | 0a65862031c3b52510a341b3d9bf49c46b73bc67 /src | |
parent | 2ab35f4c9302371240184b90905d81f3238a9a46 (diff) |
show icons in pop menu with reflection. imagespan was not centred ver…
…tically
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/ConversationActivity.java | 23 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/utils/UIHelper.java | 18 |
2 files changed, 19 insertions, 22 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java index 8175d10bc..e8d61d1df 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java @@ -18,7 +18,6 @@ import android.content.pm.PackageManager; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Typeface; -import android.graphics.drawable.Drawable; import android.media.ExifInterface; import android.net.Uri; import android.os.Build; @@ -29,8 +28,6 @@ import android.provider.MediaStore; import android.provider.Settings; import android.support.v4.widget.SlidingPaneLayout; import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener; -import android.text.SpannableStringBuilder; -import android.text.style.ImageSpan; import android.util.Log; import android.util.Pair; import android.view.Gravity; @@ -914,24 +911,6 @@ public class ConversationActivity extends XmppActivity builder.create().show(); } - /** - * Moves icons from the PopupMenu's MenuItems' icon fields into the menu title as a Spannable with the icon and title text. - */ - public static void insertMenuItemIcons(Context context, PopupMenu popupMenu) { - Menu menu = popupMenu.getMenu(); - for (int i = 0; i < menu.size(); i++) { - MenuItem menuItem = menu.getItem(i); - Drawable icon = menuItem.getIcon(); - int iconSize = context.getResources().getDimensionPixelSize(R.dimen.menu_item_icon_size); - icon.setBounds(0, 0, iconSize, iconSize); - ImageSpan imageSpan = new ImageSpan(icon); - SpannableStringBuilder ssb = new SpannableStringBuilder(" " + menuItem.getTitle()); - ssb.setSpan(imageSpan, 0, 1, 0); - menuItem.setTitle(ssb); - menuItem.setIcon(null); - } - } - protected void attachFileDialog() { View menuAttachFile = findViewById(R.id.action_attach_file); if (menuAttachFile == null) { @@ -972,7 +951,7 @@ public class ConversationActivity extends XmppActivity return false; } }); - insertMenuItemIcons(getApplicationContext(), attachFilePopup); + UIHelper.showIconsInPopup(attachFilePopup); attachFilePopup.show(); } diff --git a/src/main/java/de/pixart/messenger/utils/UIHelper.java b/src/main/java/de/pixart/messenger/utils/UIHelper.java index 12cd708f1..caa466b04 100644 --- a/src/main/java/de/pixart/messenger/utils/UIHelper.java +++ b/src/main/java/de/pixart/messenger/utils/UIHelper.java @@ -4,7 +4,10 @@ import android.content.Context; import android.text.format.DateFormat; import android.text.format.DateUtils; import android.util.Pair; +import android.widget.PopupMenu; +import java.lang.reflect.Field; +import java.lang.reflect.Method; import java.util.Arrays; import java.util.Calendar; import java.util.Date; @@ -371,4 +374,19 @@ public class UIHelper { return type; } } + + public static boolean showIconsInPopup(PopupMenu attachFilePopup) { + try { + Field field = attachFilePopup.getClass().getDeclaredField("mPopup"); + field.setAccessible(true); + Object menuPopupHelper = field.get(attachFilePopup); + Class<?> cls = Class.forName("com.android.internal.view.menu.MenuPopupHelper"); + Method method = cls.getDeclaredMethod("setForceShowIcon", new Class[]{boolean.class}); + method.setAccessible(true); + method.invoke(menuPopupHelper, new Object[]{true}); + return true; + } catch (Exception e) { + return false; + } + } } |