I am unable to align text in a table format in my dashclock extension's body. Following is the format I want (first column left aligned, rest columns right aligned):
A 2 3
BC 5 10
DEF 22 3
In the code I try aligning the following way
String.format("%-10s %10s %10s\n", val1, val2, val3);
When I log the result of the above formatting it prints in the correct and intended way in logcat. But when I deploy the app and run it as part of the dashclock application, the alignment is completely off. The alignment when displayed in dashclock extension looks like:
A 2 3
BC 5 10
DEF 22 3
I tried searching and looking into the DashClockExtension class to see if something is possible but couldn't. Also the expandedBody method in ExtensionData does not take SpannedString as argument, only String.
Any ideas as how to get the alignment right in the device?
There isn't currently a way to do this because the font used for displaying expanded body content isn't a monospace font, meaning each character has a different width. Feel free to file a feature request for representing tabular data though! http://dashclock.com/issues
Related
In an android app I'm using PdfDocument to save a report to a pdf file. On a customer's device I'm getting a strange result with the text of the report.
The following is image of header with the following text rendered in DroidSansMono:
Baus Demo Company
4727 4TH AVE SW STE 202
Seatle, WA 9816
Tel: 206-932-986
Fax: 206-932-986
I this same process renders well on most devices. I checked the pdf file and it has the correct font.
here is the full PDF file:
PDF File
Can anyone help me figure out why the text is rendered so?
The reason for this weird look is that this is exactly the formatting the PDF describes.
Horizontal scaling
The content stream of the page consists of three sections:
The top section, all text above the image of a signature, contains at the beginning the instruction
2000 Tz
Inside the section after some text a 1000 Tz follows, then again a 2000 Tz and yet again a 1000 Tz.
The Tz operator sets the horizontal scaling to the preceding number as a percentage value. Thus, these instruction cause all following text (until the end of the section where the graphics state is reset) to be horizontally stretched by a factor of either 10 or 20!
This explains why the glyphs are so wide but not why they overlap so much.
Glyph widths and positioning
The reason why they overlap so much is that each glyph is individually positioned at a distance appropriate for a layout without horizontal scaling.
First of all, the DroidSansMono font information in the PDF declare that virtually all glyphs in the font have a width of 0. Thus, whenever a glyph is drawn, the text insertion point does not wander along to the glyph's end but remains at its start.
Furthermore, each glyph is drawn using an individual operation and between two such single glyph drawing operations the text insertion point is advanced by a separate instruction. But the distance parameter of this instruction is appropriate for the glyphs without horizontal scaling!
This causes all the overlaps.
If this very PDF is rendered "well" (i.e. incorrectly ignoring the Tz operations) on most devices, the PDF renderer used on those devices clearly does a lousy job of PDF rendering.
I have a scenario where I have to show a huge report which consists of about 16 fields, and the last field consists of a radio group. I've taken a Table layout for this. But the problem is, I don't know the size of each field. I mean, there could be 50 characters in one, and 2 in another, and I have to adjust the width and height basing on that without loosing the look and feel criteria. For example,the first column is a Serial No which may contain 4 digits max, the second column contains an ID which may be a 20 digit number and so on. I can use Wrap Content, but its making the page clumsy! So, my question is, is there any possibility that my fields can automatically set their width and height basing on the length of the characters.Thanks in advance! Any help will be appreciated!
I have a TextView that displays 13 labels by using '\n'. I chose to use only one View, since android-layouting tends to get very slow if you have more than a couple of TextViews.
I set line-spacing-multiplier to 1.3x and have the problem that between the first and the second line there's about 5 to 10 px more space than between the others. There are no special characters like Ö in the labels, everyone of them consists of capital letters only.
Is this a known bug?
I have items with a lot of text, mostly around 8500 to 9500 characters.
I want to display that in a scrollable textview, but when put the text in a TextView, it seems to be truncated to a max of 9000 characters, while a (the original) String object can hold more. Is there a way to extend this number? Absolutely no parameters on restricting the size of the TextView has been set.
Thanks in advance.
Here is a link which basically says:
The answer is "how much memory can you allocate?" Of course the
system needs to allocate resources to measure and typeset and render
all of that text. If it's too long, consider showing the text in
pages or chunks.
So if your string has 50000 characters, show it in 9000 character chunks.
Use this on your EditText or TextView:
android:maxLength="1000000"
Some phones have an hard limit of 9000 chars by default.
For anyone looking at this in 2018, I don't think there's a hard limit. I have a pretty cheap Android phone with 1 GB of RAM and was able to both edit and display over 40,000 characters of text. There is a slight initial pause when pasting into the edit box and when rendering into a text view but otherwise it works just fine.
I make arabic virtual keyboard, and I have a problem.
If you write only arabic characters - all works (written right to left). But the numbers and punctuation marks are written to the right of the previous word. Although should be written to the left of the word. For example:
You write:
word_2011 where '_' is space
Must be:
'2011_drow' (look right to left, numbers read left to right)
but is:
'_drow2011'
Now more interesting. If you write 'NOW' you get
'_drow201WON1' (must be 'WON2011_drow')
This is Android problem? Or is it possible to solve it?
This is due to the way Android mis-implements bidi (bi-directional) logic.
You will also have issues with arabic letters not displaying the mid and start letters correctly.
To work around the space problem you could try to insert a direction character between them see: http://en.wikipedia.org/wiki/Unicode_control_characters. This will work, but will get a square displayed instead of a space in some phones.