Zero-width space with special characters - android

Interesting problem here, wondering if anyone has come across it.
I am building an Android app that has some special characters as text (mainly Japanese characters) and our designers want some soft returns strategically placed, incase the text needs to wrap due to width limitations on smaller devices.
The problem is that since the text is essentially Japanese, there are no spaces between words.
I know we can use \u200b as a zero-width space resulting in a string like this:
abcdef\u200bghijklmnop
appearing like this when there is enough room:
abcdefghijklmnop
and like this if it needs to wrap:
abcdef
ghijklmnop
The problem is that if instead of standard English characters, we use Japanese characters it doesn't seem to work. We don't get soft line breaks at all. It instead always breaks right where it runs out of space regardless of where we put the \u200b
ヘルプヘルプ\u200bヘルプヘルプ
results in:
ヘルプヘルプヘルプヘ
ルプ
Has anyone dealt with this before or have any ideas on how to solve this?

Related

Replacing Non-Breaking Space Android not working

I need to replace \u00A0, but it doesn't work with (found out which character it is by copying it to a text to unicode converter)
string.replace("\u00A0", " ");
It also doesn't work with copying the exakt character from the log into Android Studio. I unfortunately can't paste this character here, it gets converted to a normal white space.
I also tried many other solutions which should potentially remove this character, none of them actually worked.
My intention is to compare two phone numbers (looking like this: +49 176 34535...), one with non-breaking spaces and one with normal whitespaces from the keyboard. Non-breaking spaces result of reading the phone number from a notification.
Does someone have an idea how to solve my problem?

Android special characters converted to images in WebView?

Special characters such as
📂 ★ ✉
Are being replaced with images in the Android OS. As you can see, this seems to affect native TextViews (see screenshot).
My problem is they are also affecting the HTML I am loading through my app via WebView. The main problem is stars of different colors are all showing up as the same gray star. And other than that, you can imagine the visual inconsistency problems that arise.
If you load this page on Chrome for Android, the characters don't load at all. But if you copy the question and paste it into a plain text program such as ColorNote, you will see what I'm experiencing.
Is there a way to get my own WebView or even my entire app to use the font-family, rather than an image?
A wild guess, since I've only heard about this happening on iOS now.
How can I disable the unicode black telephone from being rendered as a red phone on iOS Mail app?
I need help getting a normal looking unicode down arrow in a UILabel like this ⬇
Unicode has this nifty thing that's called "Variation selectors", which can be used, among others, to select a variant shape of a letter, or to select whether a glyph is to be rendered as a black-and-white standard glyph, or as a colourful picture.
This variants are characters \uFE00 to \uFE0F. In case of emoji, \uFE0E means "render the previous character as a black-and-white glyph", and \uFE0F means "try to draw the previous character as a colourful picture".
So in your case, add \uFE0E after the character.

Letter Spacing in EditText for Android

I am trying to have a custom EditText based on the background that i am using for. The Background image has some spaces between the entry areas so i need to have some space between the characters(kerning) to fit them right in. So for example after every character the user enters, i need to put 4 whitespace after that.
I couldn't find any solution for this on the net so far, some people suggested TextWatcher, but i couldn't manage to make it work as i want it too.
Can someone help me about it?
Thanks
I have you considered using a custom font? Some font types are made to stretch out or shrink or have empty spaces. With so many different fonts available online, you can definitely find something. You can also make your own with a software. It might be time consuming if you start the lettering from scratch. I'm not 100% sure if it'll fit exactly to your background, but it's idea that you can consider.
If it doesn't fit, I supposed you can always customized the background to fix your font too. Here's the code for those who might want to use custom fonts in their app too.
Typeface myfont = Typeface.createFromAsset(getAssets(),
"fonts/Blocks2.ttf");
myeditText.setTypeface(myfont);
The font is in the asset folder under another folder called fonts.
This question is related to How to change letter spacing in a Textview?
As shown at this issue: android format edittext to display spaces after every 4 characters a solution might be to insert spaces with Java code...
You need to use TextWatcher to achieve visual purpose spaces.
And use any simply split string by space logic to join it back or loop
through the entire string per character wise and eliminate (char) 32
from the string
As far as i know actual character spacing is not possible, though i'd love to use that myself as well.
Another option might be to use a custom font with the character spacing included.

Android Hebrew (RTL) Integration

I'm working on a relatively simple Android app. I want it to have an English version as well as a Hebrew version. (RTL Right to Left Alignment)
I have manually change the alignment to right in layout xml file. When a sentence contains digits (in the middle of it), the digits appear in a mirror view:
29 appears as 92, 21:45 appears as 54:12 and 2,000 appears as 000,2.
Also, when a sentence starts with digits or English characters, they get thrown to the end of the sentence messing it all up.
I think for android version 4.0.3 it supports Hebrew. I have check that in emulator.
So for older versions is there correct way to implement Hebrew?
Please help.
I think that Android's bidi analysis algorithm has some flaws. Unicode has two invisible, strongly directional characters that might help with these problems:
U+200E - left-to-right mark
U+200F - right-to-left mark
For the digit order problem, try putting left-to-right marks (U+200E) on both sides of the digit sequence.
Unicode also has the following bidi formatting codes:
U+202A - left-to-right embedding
U+202B - right-to-left embedding
U+202C - pop directional formatting (cancels the previous embedding or override)
U+202D - left-to-right override
U+202E - right-to-left override
For the problem with English fragments in Hebrew text, it might be as simple as putting a right-to-left mark before the English. (Android's algorithm may be under the impression that the paragraph is left-to-right since the first characters are English.) If that doesn't work, perhaps try surrounding selected text with some combination of formatting codes. (I'd try left-to-right embedding followed by pop directional formatting. I'd also try right-to-left embedding around everything combined with selective explicit right-to-left embeddings.)
The way these are supposed to affect text layout are defined by the Unicode Bidirectional Algorithm Unicode Standard Annex #9. However, if Android's implementation is broken (and I suspect it is), the best you can do is trial-and-error until you get things looking right. Good luck.
EDIT
As far as code is concerned, here's an example of how it might be done in Java:
String text = "גרסה \u200e2.100\u200e זמינה";
In XML, it might be:
<string name="update_available">גרסה ‎2.100‎ זמינה</string>
here is an example from my hebrew string xml, Thanks to Ted Hopp's answer:
you need to add '\u200e' before the char that causes you the problem:
<string name="basic_text1">המר על תוצאת המשחק\u200e:</string>
and the result will be:
:המר על תוצאת המשחק

Android. Problem with arabic keyboard

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.

Categories

Resources