Merge pull request 'Adding more reliable calculation of label width.' (#393) from opyale/GitNex:label-width-calc into master
Reviewed-on: https://gitea.com/gitnex/GitNex/pulls/393 Reviewed-by: M M Arif <mmarif@swatian.com>
This commit is contained in:
commit
14bca1f4c4
@ -59,6 +59,7 @@ import org.mian.gitnex.clients.RetrofitClient;
|
||||
import org.mian.gitnex.fragments.BottomSheetSingleIssueFragment;
|
||||
import org.mian.gitnex.helpers.AlertDialogs;
|
||||
import org.mian.gitnex.helpers.Authorization;
|
||||
import org.mian.gitnex.helpers.LabelWidthCalculator;
|
||||
import org.mian.gitnex.helpers.TimeHelper;
|
||||
import org.mian.gitnex.helpers.UserMentions;
|
||||
import org.mian.gitnex.models.IssueComments;
|
||||
@ -451,7 +452,7 @@ public class IssueDetailActivity extends BaseActivity {
|
||||
.useFont(Typeface.DEFAULT)
|
||||
.textColor(new ColorInverter().getContrastColor(color))
|
||||
.fontSize(30)
|
||||
.width((width * labelName.length()) - ((width / 4) * labelName.length()))
|
||||
.width(LabelWidthCalculator.calculateLabelWidth(labelName, Typeface.DEFAULT, 30, 15))
|
||||
.height(50)
|
||||
.endConfig()
|
||||
.buildRoundRect(labelName, color, 10);
|
||||
|
@ -1,11 +1,28 @@
|
||||
package org.mian.gitnex.helpers;
|
||||
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.Typeface;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class LabelWidthCalculator {
|
||||
|
||||
public static int calculateLabelWidth(String text, Typeface typeface, int textSize, int paddingLeftRight) {
|
||||
|
||||
Paint paint = new Paint();
|
||||
Rect rect = new Rect();
|
||||
|
||||
paint.setTextSize(textSize);
|
||||
paint.setTypeface(typeface);
|
||||
paint.getTextBounds(text, 0, text.length(), rect);
|
||||
|
||||
return rect.width() + (paddingLeftRight * 2);
|
||||
|
||||
}
|
||||
|
||||
public static int customWidth(int labelLength) {
|
||||
|
||||
int width = 33;
|
||||
|
Loading…
x
Reference in New Issue
Block a user