forked from sk22/megalodon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix menu item icons being display improperly
After the March 2024 security patch, icons in popup menus would be very small and misaligned. I couldn't figure out the cause or how to fix this within the existing system, so all icons are now shown using a custom image span in the title instead of using the built in system
- Loading branch information
1 parent
bce9f10
commit 725b1d8
Showing
7 changed files
with
128 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
mastodon/src/main/java/org/joinmastodon/android/ui/text/CenteredImageSpan.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.joinmastodon.android.ui.text; | ||
|
||
import android.graphics.Canvas; | ||
import android.graphics.Paint; | ||
import android.graphics.Rect; | ||
import android.graphics.drawable.Drawable; | ||
import android.text.style.ImageSpan; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
public class CenteredImageSpan extends ImageSpan{ | ||
public CenteredImageSpan(@NonNull Drawable d){ | ||
super(d, ImageSpan.ALIGN_BOTTOM); | ||
} | ||
|
||
@Override | ||
public int getSize(@NonNull Paint paint, CharSequence text, int start, int end, @Nullable Paint.FontMetricsInt fm){ | ||
Drawable drawable=getDrawable(); | ||
if (fm!=null) { | ||
Paint.FontMetricsInt paintFm=paint.getFontMetricsInt(); | ||
int fontHeight=paintFm.descent-paintFm.ascent; | ||
int verticalCenter=paintFm.ascent+(fontHeight/2); | ||
int imgHeight=drawable.getIntrinsicHeight(); | ||
|
||
fm.ascent=fm.top=verticalCenter-imgHeight/2; | ||
fm.descent=fm.bottom=verticalCenter+imgHeight/2; | ||
} | ||
return drawable.getIntrinsicWidth(); | ||
} | ||
|
||
@Override | ||
public void draw(@NonNull Canvas canvas, CharSequence text, | ||
int start, int end, float x, int top, int y, int bottom, | ||
@NonNull Paint paint){ | ||
Drawable drawable=getDrawable(); | ||
canvas.save(); | ||
|
||
int translateY=bottom-drawable.getIntrinsicHeight(); | ||
canvas.translate(x, translateY); | ||
|
||
drawable.draw(canvas); | ||
canvas.restore(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters