Small DrawableSpan fix (alig_center)
This commit is contained in:
		
							parent
							
								
									6ed978b7a2
								
							
						
					
					
						commit
						3e3a213a1b
					
				| @ -1,8 +1,11 @@ | ||||
| package ru.noties.markwon; | ||||
| 
 | ||||
| import android.app.Activity; | ||||
| import android.graphics.drawable.Drawable; | ||||
| import android.os.Bundle; | ||||
| import android.os.SystemClock; | ||||
| import android.text.SpannableStringBuilder; | ||||
| import android.text.Spanned; | ||||
| import android.text.method.LinkMovementMethod; | ||||
| import android.widget.TextView; | ||||
| 
 | ||||
| @ -18,6 +21,7 @@ import java.util.Scanner; | ||||
| import ru.noties.debug.AndroidLogDebugOutput; | ||||
| import ru.noties.debug.Debug; | ||||
| import ru.noties.markwon.renderer.*; | ||||
| import ru.noties.markwon.spans.DrawableSpan; | ||||
| import ru.noties.markwon.spans.DrawableSpanUtils; | ||||
| 
 | ||||
| public class MainActivity extends Activity { | ||||
| @ -33,6 +37,21 @@ public class MainActivity extends Activity { | ||||
| 
 | ||||
|         final TextView textView = (TextView) findViewById(R.id.activity_main); | ||||
| 
 | ||||
| //        final Drawable drawable = getDrawable(R.mipmap.ic_launcher); | ||||
| ////        drawable.setBounds(0, 0, 16, 16); | ||||
| //        final SpannableStringBuilder builder = new SpannableStringBuilder(); | ||||
| //        for (int i = 0; i < 10; i++) { | ||||
| //            builder.append("text here and icon: \u00a0"); | ||||
| //            //noinspection WrongConstant | ||||
| //            builder.setSpan(new DrawableSpan(drawable, i % 3), builder.length() - 1, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); | ||||
| //            builder.append('\n'); | ||||
| //        } | ||||
| //        textView.setText(builder); | ||||
| // | ||||
| //        if (true) { | ||||
| //            return; | ||||
| //        } | ||||
| 
 | ||||
|         new Thread(new Runnable() { | ||||
|             @Override | ||||
|             public void run() { | ||||
|  | ||||
| @ -107,6 +107,7 @@ public class SpannableConfiguration { | ||||
| 
 | ||||
|         // todo, change to something more reliable | ||||
|         // todo, must mention that bullet/ordered/quote must have the same margin (or maybe we can just enforce it?) | ||||
|         // actually it does make sense to have `blockQuote` & `list` margins (if they are different) | ||||
|         public SpannableConfiguration build() { | ||||
|             if (blockQuoteConfig == null) { | ||||
|                 blockQuoteConfig = new BlockQuoteSpan.Config( | ||||
|  | ||||
| @ -18,7 +18,7 @@ public class DrawableSpan extends ReplacementSpan { | ||||
| 
 | ||||
|     public static final int ALIGN_BOTTOM = 0; | ||||
|     public static final int ALIGN_BASELINE = 1; | ||||
|     public static final int ALIGN_CENTER = 2; | ||||
|     public static final int ALIGN_CENTER = 2; // will only center if drawable height is less than text line height | ||||
| 
 | ||||
|     private final Drawable drawable; | ||||
|     private final int alignment; | ||||
| @ -79,7 +79,7 @@ public class DrawableSpan extends ReplacementSpan { | ||||
|         try { | ||||
|             final int translationY; | ||||
|             if (ALIGN_CENTER == alignment) { | ||||
|                 translationY = (int) (b / 2.F + .5F); | ||||
|                 translationY = b - ((bottom - top - drawable.getBounds().height()) / 2); | ||||
|             } else if (ALIGN_BASELINE == alignment) { | ||||
|                 translationY = b - paint.getFontMetricsInt().descent; | ||||
|             } else { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Dimitry Ivanov
						Dimitry Ivanov