From f4365ed1631c51a72fec275af972cc2f6b66eb46 Mon Sep 17 00:00:00 2001 From: sk Date: Mon, 20 Mar 2023 19:17:22 +0100 Subject: [PATCH] fix context menu resizing closes sk22#467 --- .../account_list/BaseAccountListFragment.java | 3 +- .../displayitems/HeaderStatusDisplayItem.java | 59 +++++++++++++++++-- mastodon/src/main/res/menu/post.xml | 4 +- mastodon/src/main/res/menu/profile.xml | 6 +- 4 files changed, 59 insertions(+), 13 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/BaseAccountListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/BaseAccountListFragment.java index c70e83129..6a7fb48b6 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/BaseAccountListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/BaseAccountListFragment.java @@ -295,7 +295,6 @@ public abstract class BaseAccountListFragment extends BaseRecyclerFragment largestWidth) largestWidth = width; + } + for (String str : otherStrings) { + float width = paint.measureText(str); + if (width > largestWidth) largestWidth = width; + } + float textWidth = paint.measureText(openInBrowserText); + float missingWidth = Math.max(0, largestWidth - textWidth); + float singleSpaceWidth = paint.measureText(" "); + int howManySpaces = (int) Math.ceil(missingWidth / singleSpaceWidth); + String enlargedText = openInBrowserText + " ".repeat(howManySpaces); + menu.findItem(R.id.open_in_browser).setTitle(enlargedText); + } else { + menu.findItem(R.id.open_in_browser).setTitle(openInBrowserText); + } } } } diff --git a/mastodon/src/main/res/menu/post.xml b/mastodon/src/main/res/menu/post.xml index 9fe389962..ad1e2209c 100644 --- a/mastodon/src/main/res/menu/post.xml +++ b/mastodon/src/main/res/menu/post.xml @@ -8,11 +8,11 @@ + + - - diff --git a/mastodon/src/main/res/menu/profile.xml b/mastodon/src/main/res/menu/profile.xml index e3cc847d1..3a0e39c43 100644 --- a/mastodon/src/main/res/menu/profile.xml +++ b/mastodon/src/main/res/menu/profile.xml @@ -1,15 +1,15 @@ - + + - + - \ No newline at end of file