Skip to content

Instantly share code, notes, and snippets.

@CarlaTeo
Last active August 1, 2018 20:42
Show Gist options
  • Save CarlaTeo/8743f3bee4adc8cc09fc3e9897f5fd89 to your computer and use it in GitHub Desktop.
Save CarlaTeo/8743f3bee4adc8cc09fc3e9897f5fd89 to your computer and use it in GitHub Desktop.
package com.example.gk.np;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.Spannable;
import android.text.style.ImageSpan;
import android.util.Base64;
import android.util.Log;
import android.view.ActionMode;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import org.xml.sax.Attributes;
import org.xml.sax.XMLReader;
import java.util.HashMap;
import java.util.Map;
class VerticalImageSpan extends ImageSpan {
private int baseline;
public VerticalImageSpan(Drawable drawable, int baseline) {
super(drawable);
this.baseline = baseline;
}
/**
* update the text line height
*/
@Override
public int getSize(Paint paint, CharSequence text, int start, int end,
Paint.FontMetricsInt fontMetricsInt) {
Drawable drawable = getDrawable();
Rect rect = drawable.getBounds();
if (fontMetricsInt != null) {
Paint.FontMetricsInt fmPaint = paint.getFontMetricsInt();
int fontHeight = fmPaint.descent - fmPaint.ascent;
int drHeight = rect.bottom - rect.top;
int centerY = fmPaint.ascent + fontHeight / 2;
fontMetricsInt.ascent = centerY - drHeight / 2;
fontMetricsInt.top = fontMetricsInt.ascent;
fontMetricsInt.bottom = centerY + drHeight / 2;
fontMetricsInt.descent = fontMetricsInt.bottom;
}
return rect.right;
}
/**
* see detail message in android.text.TextLine
*
* @param canvas the canvas, can be null if not rendering
* @param text the text to be draw
* @param start the text start position
* @param end the text end position
* @param x the edge of the replacement closest to the leading margin
* @param top the top of the line
* @param y the baseline
* @param bottom the bottom of the line
* @param paint the work paint
*/
@Override
public void draw(Canvas canvas, CharSequence text, int start, int end,
float x, int top, int y, int bottom, Paint paint) {
Drawable drawable = getDrawable();
canvas.save();
Paint.FontMetricsInt fmPaint = paint.getFontMetricsInt();
int fontHeight = fmPaint.descent - fmPaint.ascent;
int centerY = y + fmPaint.descent - fontHeight / 2;
int transY = centerY - (drawable.getBounds().bottom - drawable.getBounds().top) / 2;
canvas.translate(x, transY);
drawable.draw(canvas);
canvas.restore();
}
}
public class MainActivity extends AppCompatActivity {
String getHTML() {
return "<p>Este texto precisa estar espaçadinho também. Sejam<strong> a</strong> e <strong>b</strong> números reais para os quais a igualdade " +
"<img style=\"width: 118px; height: 33px; vertical-align: -15px; margin: 3px;\" src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAO0AAABCCAQAAAARDpk/AAAJJGlDQ1BpY2MAAHjalZVnUJNZF8fv8zzphUASQodQQ5EqJYCUEFoo0quoQOidUEVsiLgCK4qINEUQUUDBVSmyVkSxsCgoYkE3yCKgrBtXERWUF/Sd0Xnf2Q/7n7n3/OY/Z+4995wPFwCCOFgSvLQnJqULvJ3smIFBwUzwg8L4aSkcT0838I96Pwyg5XhvBfj3IkREpvGX4sLSyuWnCNIBgLKXWDMrPWWZDy8xPTz+K59dZsFSgUt8Y5mjv/Ho15xvLPqa4+vNXXoVCgAcKfoHDv+B/3vvslQ4gvTYqMhspk9yVHpWmCCSmbbcCR6Xy/QUJEfFJkT+UPC/Sv4HpUdmpy9HbnLKBkFsdEw68/8ONTIwNATfZ/HW62uPIUb//85nWd+95HoA2LMAIHu+e+GVAHTuAED68XdPbamvlHwAOu7wMwSZ3zzU8oYGBEABdCADFIEq0AS6wAiYAUtgCxyAC/AAviAIrAN8EAMSgQBkgVywDRSAIrAH7AdVoBY0gCbQCk6DTnAeXAHXwW1wFwyDJ0AIJsArIALvwTwEQViIDN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YILW+6rtc4qGfpaBGSgBVqgPY8kGCHDa4EWaIFWFFjtvzTQSoJ6L4TUj6fu2H5AG1prwx9tPKnOWGkq5NyVMqHYfaKX/nqVha8FFVEquntzNp2FrO/FWhvGYas9QqqTo93+mhzWK21R/nq55KJl4OWb0A5AC7RAC7SC0dJ4NclemiPQ+k1gp6g0lQAtzS4nod1M87itjfHREtapLFrqSlMp0HZqVpHpyFpTB6BdbK32aQydE1o7h3lkrakD0C7WeqTdR58CbaWaUJEEgWiTVr/YqATveZ9b+6HPrY6tNfVRqnUrqexatGlr1iTwWp9xNTR4cqm/i2SvTVtpKkVAdr7R5BCQM/PaeWGT5bPiz3DR18ZF+7fSlJ7QWnFo8xohP6GtRKE1C6NNWmkqfDG41mbHgGxmIeviVif47ROR7XuLVF+irR+JU3qaSVtp6lnxdprY9P643l0FJSngOmaRi7GUmI0J1hfzeEzX7DdP+0Ku30pTZsyPJ640teON0goST0F833yvGwmtCsNXLpE40IBWdPsB6Mzekm4R1/sAAAAldEVYdGRhdGU6Y3JlYXRlADIwMTctMTEtMTdUMDE6MTY6NTcrMDA6MDBLO69PAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE3LTExLTE3VDAxOjE2OjU3KzAwOjAwOmYX8wAAABR0RVh0cGRmOlZlcnNpb24AUERGLTEuNSAFXAs5AAAAAElFTkSuQmCC\" data-math=\"XGZyYWN7YX17MSthfSArIFxmcmFje2J9ezErYn0gPSAx\" " +
"data-original-size=\"baseline: 24px; height: 66px; width: 237px;\" data-mathrm=\"true\" /> " +
"tenha solução. Determine o valor do produto " +
"<img style=\"width: 27px; height: 11px; vertical-align: -3px; margin: 3px;\" src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADcAAAAXCAQAAAAFfh/7AAAJJGlDQ1BpY2MAAHjalZVnUJNZF8fv8zzphUASQodQQ5EqJYCUEFoo0quoQOidUEVsiLgCK4qINEUQUUDBVSmyVkSxsCgoYkE3yCKgrBtXERWUF/Sd0Xnf2Q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hnmGVwLTkjzEC66/ON+GAeGjrJKoadUlvdxEM5f4S3CejD/3GDCuLYulrII3hj50qHlbx0ZFQZIMv0N3Ji1GzI6x9ninBJhDeYbOFX09GRkLmYHURluFWdbibPaDRuZSQvnLmGOs4ufwPFVrbRTuqBKtAer03bwfirt4Ewupt3JeY2Ybjg7JWa5OieffI/dlQqsiJ09o9IZB5z+CG5YY72Jo/jNt3BTcQqGKk7FVOH1kpvcZuklnCT5WPA2xy0jfiRoydqBlN/U9BWYLWqv0LJnDmnJPPxr9AL/LqhdrBhflgAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAxNy0xMS0xN1QwMToxNzoxNyswMDowMCCzyosAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMTctMTEtMTdUMDE6MTc6MTcrMDA6MDBR7nI3AAAAFHRFWHRwZGY6VmVyc2lvbgBQREYtMS41IAVcCzkAAAAASUVORK5CYII=\" " +
"data-math=\"YSBcY2RvdCBi\" data-original-size=\"baseline: 0px; height: 23px; width: 55px;\" data-mathrm=\"true\" />.</p>";
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
TextView textView = (TextView)findViewById(R.id.textView);
textView.setText(Html.fromHtml(this.getHTML(), 0, new Html.ImageGetter() {
@Override
public Drawable getDrawable(String source, Attributes attributes) {
if (source.startsWith("data:image/png;base64,")) {
Log.e("MyComponent", source);
float latexScale = getApplication().getResources().getDisplayMetrics().density;
Map<String, Integer> styleProperties = new HashMap<>();
String style = attributes.getValue("", "style");
Log.e("MyComponent", style);
for (String part: style.split(";")) {
String trimmedPart = part.replace("px", "").trim();
String[] subParts = trimmedPart.split(":");
styleProperties.put(subParts[0].trim(), Integer.valueOf(subParts[1].trim()));
}
byte[] data = Base64.decode(source.substring(22), Base64.DEFAULT);
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
BitmapDrawable bitmapDrawable = new BitmapDrawable(getApplication().getResources(), bitmap);
bitmapDrawable.setBounds(0, 0, (int)(latexScale * styleProperties.get("width")),(int)(latexScale * styleProperties.get("height")));
return bitmapDrawable;
}
return null;
}
@Override
public ImageSpan getImageSpan(Drawable drawable, String source, Attributes attributes) {
if (source.startsWith("data:image/png;base64,")) {
float latexScale = getApplication().getResources().getDisplayMetrics().density;
Map<String, Integer> styleProperties = new HashMap<>();
String style = attributes.getValue("", "style");
for (String part: style.split(";")) {
String trimmedPart = part.replace("px", "").trim();
String[] subParts = trimmedPart.split(":");
styleProperties.put(subParts[0].trim(), Integer.valueOf(subParts[1].trim()));
}
return new VerticalImageSpan(drawable, (int)(latexScale * styleProperties.get("vertical-align")));
}
return new ImageSpan(drawable, source);
}
}, new Html.TagHandler() {
@Override
public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) { }
}));
// textView.setLineSpacing( (float)50, 0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment