Bug 41304 - ILeadingMarginSpanLeadingMarginSpan2 () GetLeadingMargin never called
Summary: ILeadingMarginSpanLeadingMarginSpan2 () GetLeadingMargin never called
Alias: None
Product: Android
Classification: Xamarin
Component: Mono runtime / AOT Compiler ()
Version: 6.0.99
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jonathan Pryor
Depends on:
Reported: 2016-05-25 04:50 UTC by joeperkins
Modified: 2016-11-03 00:11 UTC (History)
1 user (show)

Is this bug a regression?: ---
Last known good build:

Scratch.Bxc41304.zip (4.29 KB, application/zip)
2016-05-27 19:15 UTC, Jonathan Pryor
Confirmed working (112.29 KB, image/png)
2016-05-27 19:32 UTC, joeperkins

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description joeperkins 2016-05-25 04:50:56 UTC
public class LeadingMarginSpanner : Java.Lang.Object, ILeadingMarginSpanLeadingMarginSpan2
        private readonly int _margin;
        private int _lines;
        public LeadingMarginSpanner() { }

        public LeadingMarginSpanner(int lines, int margin)
            this._margin = margin;
            this._lines = lines;
        public void DrawLeadingMargin(Canvas c, Paint p, int x, int dir, int top, int baseline, int bottom, ICharSequence text,
                                      int start, int end, bool first, Layout layout)
        public int GetLeadingMargin(bool first)
            if (first)
                 /* *This * indentation is applied to the number of          rows returned *getLeadingMarginLineCount() */
                 return _margin;
                //Offset for all other Layout layout ) { }  
                /*Returns * the number of rows which should be applied *     indent returned by getLeadingMargin (true)   
                * Note:* Indent only applies to N lines of the first paragraph.*/
                return 0;

        public int LeadingMarginLineCount
                return _lines;
Comment 1 Jonathan Pryor 2016-05-25 15:27:07 UTC
Please provide a complete test case.

There's nothing in the provided code which would cause GetLeadingMargin() to be invoked. Presumably you're passing an instance of LeadingMarginSpanner into Java code, but *what* Java code? Is that Java code supposed to use the LeadingMarginSpanLeadingMarginSpan2 interface? Which API level? Etc., etc.
Comment 2 joeperkins 2016-05-27 06:53:03 UTC
Android.Text.Style.ILeadingMarginSpanLeadingMarginSpan2, API 21, Xamarin Visual Studio 2015 

var spannable = new SpannableString (someText); spannable.SetSpan(new LeadingMarginSpanner(1, 100), 0, spannable.Length(), 0);
((TextView) textViewObject).TextFormatted = spannable;

In Android Studio (java) API 21, works fine and the overridden methods are called when the spannable text is rendered. 

(java) 	LeadingMarginSpanner implements LeadingMarginSpan2 
(mono)	LeadingMarginSpanner : Java.Lang.Object, ILeadingMarginSpanLeadingMarginSpan2
Comment 3 Jonathan Pryor 2016-05-27 19:15:15 UTC
Created attachment 16125 [details]
Comment 4 Jonathan Pryor 2016-05-27 19:17:19 UTC
Please attach a complete test case which demonstrates the error.

Attachment #16125 [details] is my effort at creating such a repro based on Comment #0 and Comment #2, and it works, with the following messages printed to `adb logcat`:

> # jonp: GetLeadingMargin: first=True
> # jonp: GetLeadingMargin: first=False
> # jonp: LeadingMarginLineCount: _lines=1
> # jonp: LeadingMarginLineCount: _lines=1
> # jonp: DrawLeadingMargin
> # jonp: GetLeadingMargin: first=True

GetLeadingMargin() is called three times when displaying my app.
Comment 5 joeperkins 2016-05-27 19:32:13 UTC
Created attachment 16126 [details]
Confirmed working

I'll need to dig deeper why its not working in my solution, could be SDK version. Thank you for checking into this.
Comment 6 joeperkins 2016-11-03 00:11:22 UTC
possible target API level issue