From 382b741adfa29104223dfed32799b5883db9110a Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Sat, 4 Mar 2017 18:05:37 +0100 Subject: Added icons for the attach options according to material design guidlines --- .../pixart/messenger/ui/ConversationActivity.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/main/java/de/pixart/messenger') diff --git a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java index a1e2a344b..7864c9e12 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java @@ -18,6 +18,7 @@ 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; @@ -28,6 +29,8 @@ 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; @@ -911,6 +914,24 @@ 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) { @@ -951,6 +972,7 @@ public class ConversationActivity extends XmppActivity return false; } }); + insertMenuItemIcons(getApplicationContext(), attachFilePopup); attachFilePopup.show(); } -- cgit v1.2.3