Fix JLatexMathPlugin (backgroundProvider null)
This commit is contained in:
		
							parent
							
								
									24151dff7d
								
							
						
					
					
						commit
						c68aeabcf9
					
				| @ -6,6 +6,7 @@ import android.os.Handler; | ||||
| import android.os.Looper; | ||||
| import android.os.SystemClock; | ||||
| import android.text.Spanned; | ||||
| import android.util.Log; | ||||
| import android.widget.TextView; | ||||
| 
 | ||||
| import androidx.annotation.NonNull; | ||||
| @ -262,12 +263,28 @@ public class JLatexMathPlugin extends AbstractMarkwonPlugin { | ||||
|                 cache.put(drawable, config.executorService.submit(new Runnable() { | ||||
|                     @Override | ||||
|                     public void run() { | ||||
|                         // @since 4.0.1 wrap in try-catch block and add error logging | ||||
|                         try { | ||||
|                             execute(); | ||||
|                         } catch (Throwable t) { | ||||
|                             Log.e( | ||||
|                                     "JLatexMathPlugin", | ||||
|                                     "Error displaying latex: `" + drawable.getDestination() + "`", | ||||
|                                     t); | ||||
|                         } | ||||
|                     } | ||||
| 
 | ||||
|                     private void execute() { | ||||
| 
 | ||||
|                         // @since 4.0.1 (background provider can be null) | ||||
|                         final BackgroundProvider backgroundProvider = config.backgroundProvider; | ||||
| 
 | ||||
|                         // create JLatexMathDrawable | ||||
|                         //noinspection ConstantConditions | ||||
|                         final JLatexMathDrawable jLatexMathDrawable = | ||||
|                                 JLatexMathDrawable.builder(drawable.getDestination()) | ||||
|                                         .textSize(config.textSize) | ||||
|                                         .background(config.backgroundProvider.provide()) | ||||
|                                         .background(backgroundProvider != null ? backgroundProvider.provide() : null) | ||||
|                                         .align(config.align) | ||||
|                                         .fitCanvas(config.fitCanvas) | ||||
|                                         .padding( | ||||
|  | ||||
| @ -47,24 +47,24 @@ public class LatexActivity extends Activity { | ||||
|                 + latex + "$$\n\n something like **this**"; | ||||
| 
 | ||||
|         final Markwon markwon = Markwon.builder(this) | ||||
| //                .usePlugin(ImagesPlugin.create(this)) | ||||
|                 .usePlugin(JLatexMathPlugin.create(textView.getTextSize(), new JLatexMathPlugin.BuilderConfigure() { | ||||
|                     @Override | ||||
|                     public void configureBuilder(@NonNull JLatexMathPlugin.Builder builder) { | ||||
|                         builder | ||||
|                                 .backgroundProvider(new JLatexMathPlugin.BackgroundProvider() { | ||||
|                                     @NonNull | ||||
|                                     @Override | ||||
|                                     public Drawable provide() { | ||||
|                                         return new ColorDrawable(0x40ff0000); | ||||
|                                     } | ||||
|                                 }) | ||||
|                                 .fitCanvas(true) | ||||
|                                 .align(JLatexMathDrawable.ALIGN_LEFT) | ||||
|                                 .padding(48) | ||||
|                         ; | ||||
|                     } | ||||
|                 })) | ||||
| //                .usePlugin(JLatexMathPlugin.create(textView.getTextSize(), new JLatexMathPlugin.BuilderConfigure() { | ||||
| //                    @Override | ||||
| //                    public void configureBuilder(@NonNull JLatexMathPlugin.Builder builder) { | ||||
| //                        builder | ||||
| //                                .backgroundProvider(new JLatexMathPlugin.BackgroundProvider() { | ||||
| //                                    @NonNull | ||||
| //                                    @Override | ||||
| //                                    public Drawable provide() { | ||||
| //                                        return new ColorDrawable(0x40ff0000); | ||||
| //                                    } | ||||
| //                                }) | ||||
| //                                .fitCanvas(true) | ||||
| //                                .align(JLatexMathDrawable.ALIGN_LEFT) | ||||
| //                                .padding(48) | ||||
| //                        ; | ||||
| //                    } | ||||
| //                })) | ||||
|                 .usePlugin(JLatexMathPlugin.create(textView.getTextSize())) | ||||
|                 .build(); | ||||
| 
 | ||||
|         if (true) { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Dimitry Ivanov
						Dimitry Ivanov