Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for emotes in flairs #1054

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bharatknv
Copy link
Contributor

Adds #1042

@bharatknv
Copy link
Contributor Author

This is incomplete. I want to limit the emote height so it can't be taller than 2x the height of the text (or whatever multiple looks good).

Currently I'm just halving the emote and it mostly works with my device and font size but that's obviously an imperfect solution.

@QuantumBadger , Any thoughts on what the best way to do this would be?

@bharatknv
Copy link
Contributor Author

The best solution I came up with is this:

final int TEXT_SIZE = 11; // Text size in sp
final float MAX_IMAGE_HEIGHT_MULTIPLE = 2.0F; // emote can only be 2x the size of the text


final float maxHeight = TypedValue.applyDimension(
  TypedValue.COMPLEX_UNIT_SP, 
  PrefsUtility.appearance_fontscale_comment_headers() * 
    TEXT_SIZE * 
    MAX_IMAGE_HEIGHT_MULTIPLE, 
  activity.getBaseContext().getResources().getDisplayMetrics());

if (image.getHeight() > maxHeight) {
      final float imageAspectRatio = (float) image.getHeight() / image.getWidth();
      
      final float newImageWidth = maxHeight / imageAspectRatio;
      
      image = Bitmap.createScaledBitmap(image,
		      Math.round(newImageWidth),
		      Math.round(maxHeight),
		      true);
}

I got the text size from reddit_comment.xml. I'd like to get it programmatically instead of hard-coding it but I don't see an obvious way to do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants