|
@@ -1,71 +0,0 @@
|
|
|
-/*
|
|
|
- * Nextcloud Talk application
|
|
|
- *
|
|
|
- * @author Mario Danic
|
|
|
- * Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
|
|
|
- *
|
|
|
- * This program is free software: you can redistribute it and/or modify
|
|
|
- * it under the terms of the GNU General Public License as published by
|
|
|
- * the Free Software Foundation, either version 3 of the License, or
|
|
|
- * at your option) any later version.
|
|
|
- *
|
|
|
- * This program is distributed in the hope that it will be useful,
|
|
|
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
- * GNU General Public License for more details.
|
|
|
- *
|
|
|
- * You should have received a copy of the GNU General Public License
|
|
|
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
- *
|
|
|
- * Taken and adapter from
|
|
|
- */
|
|
|
-
|
|
|
-package com.nextcloud.talk.utils.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;
|
|
|
-
|
|
|
-public class TextAlignedImageSpan extends ImageSpan {
|
|
|
- public TextAlignedImageSpan(@NonNull Drawable drawable, int verticalAlignment) {
|
|
|
- super(drawable, verticalAlignment);
|
|
|
- }
|
|
|
-
|
|
|
- public int getSize(@NonNull Paint paint, CharSequence text, int start, int end,
|
|
|
- Paint.FontMetricsInt fontMetricsInt) {
|
|
|
- Drawable drawable = getDrawable();
|
|
|
- Rect drawableBounds = drawable.getBounds();
|
|
|
-
|
|
|
- if (fontMetricsInt != null) {
|
|
|
- Paint.FontMetricsInt fmPaint = paint.getFontMetricsInt();
|
|
|
- int fontHeight = fmPaint.bottom - fmPaint.top;
|
|
|
- int drHeight = drawableBounds.bottom - drawableBounds.top;
|
|
|
-
|
|
|
- int top = drHeight / 2 - fontHeight / 4;
|
|
|
- int bottom = drHeight / 2 + fontHeight / 4;
|
|
|
-
|
|
|
- fontMetricsInt.ascent = -bottom;
|
|
|
- fontMetricsInt.top = -bottom;
|
|
|
- fontMetricsInt.bottom = top;
|
|
|
- fontMetricsInt.descent = top;
|
|
|
- }
|
|
|
-
|
|
|
- return drawableBounds.right;
|
|
|
- }
|
|
|
-
|
|
|
- @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 transY;
|
|
|
- transY = ((bottom - top) - drawable.getBounds().bottom) / 2 + top;
|
|
|
- canvas.translate(x, transY);
|
|
|
- drawable.draw(canvas);
|
|
|
- canvas.restore();
|
|
|
- }
|
|
|
-
|
|
|
-}
|