Android Arabic Text Concatenation - android

in Android I would like to concatenate number with Arabic text. but if i concatenate the number then the arabic text direction changes.
Example: My Application reads each line of arabic text from file and adds the line number to each line and appended to string builder , After completion of reading final string will be displayed on text view.
Here is my code
SpannableStringBuilder styledString = new SpannableStringBuilder(TextUtils.concat(l,"("+sn+")"));
styledString.setSpan (new CustomTypefaceSpan("", type), 0, l.length()-1, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
// styledString.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_OPPOSITE),l.length()-1,l.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spannablestringbuilder.append(styledString);
Expected Output:
(3) ﺑِﺴْﻢِ ٱﻟﻠَّﻪِ ٱﻟﺮَّﺣْﻤَٰﻦِ ٱﻟﺮَّﺣِﻴِ(1)ٱﻟْﺤَﻤْﺪُ ﻟِﻠَّﻪِ ﺭَﺏِّ ٱﻟْﻌَٰﻠَﻤِﻴﻦَ (2) ٱﻟﺮَّﺣْﻤَٰﻦِ ٱﻟﺮَّﺣِﻴﻢِ
Actual Output
(1)ﺑِﺴْﻢِ ٱﻟﻠَّﻪِ ٱﻟﺮَّﺣْﻤَٰﻦِ ٱﻟﺮَّﺣِﻴﻢِ (2)ٱﻟْﺤَﻤْﺪُ ﻟِﻠَّﻪِ ﺭَﺏِّ ٱﻟْﻌَٰﻠَﻤِﻴﻦَ ٱﻟﺮَّﺣْﻤَٰﻦِ(3) ٱﻟﺮَّﺣِﻴﻢِ

Try
Removing spaces
Use hyphens - instead of spaces
Try finding a way to change the direction
By the way, this question is answerde here and might be a duplicate!
Thanks for posting!

Related

Android - Shortname to Unicode from Emojione doesn't work

First of all, I don't know whether I should ask this here or in the repo, but as I saw other questions for other libraries like.. Picasso, so here goes :
I'm trying to implement Emojione into my Android app. I've downloaded a small static class to convert all short name to unicode from Emojione Github Repo.
The problem is, when I try to use it to convert :smile: to unicode..
Emojione.shortnameToUnicode(postMessageText, true); // postMessageText is ":smile:"
It always return.. A square, as if it failed to convert. I tried other short names too like :smiley:, :grinning:, but they also failed. :(something): is really a short name right?
The answer is actually in front of my eyes all the time. It really did convert to unicode but, I might be wrong here, in a font unsupported by Android. So I tried using SpannableStringBuilder to span the emoji part to use emojione-android.ttf
Here's how :
int firstEq = sb.length();
Typeface font = FontCache.getTypeface("emojione-android.ttf", context);
String convertPart = Emojione.shortnameToUnicode(part, true);
sb.append(convertPart + " ");
int lastEq = sb.length();
sb.setSpan(new CustomTypefaceSpan("", font), firstEq, lastEq, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
And that's how I got the TextView to show emojis.. Just use the font!

Android EditText: cannot insert text between two emotion icons

I am using SpannableString to insert emotion icons into EditText.
The following four cases are all OK:
(1) append text or emotion icon at the end of EditText,
(2) insert emotion icon between text,
(3) insert emotion icon between existed emotion icons.
(4) insert text between existed text.
But the problem is I cannot insert text between those icons. Here is my code and logcat info.
(1) Add icon to EditText:
Drawable d = UiUtil.getCachedDrawable(mActivity, EmResource.findResIdByTag(value));
if (d != null) {
d.setBounds(0, 0, w, w);
String str = "<img src='" + value + "'/>";
SpannableString ss = new SpannableString(str);
ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BOTTOM);
ss.setSpan(span, 0, str.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
contentEt.getText().replace(contentEt.getSelectionStart(), contentEt.getSelectionEnd(), ss);
}
(2) After inputing some icons, it looks like this (I have moved the cursor manualy after typing):
I have added a TextWatcher for this EditText. Log info from TextWatcher:
<img src='115'/><img src='116'/><img src='117'/><img src='118'/>
(3) Then I press 'y' on the keyboard (in the position of previous screen shot). After that the cursor is moving but the text isn't shown. Like the following screen shot:
But the log info shows that the text is inserted to EditText successfully.
<img src='115'/><img src='116'/>y<img src='117'/><img src='118'/>
<img src='115'/><img src='116'/>yy<img src='117'/><img src='118'/>
<img src='115'/><img src='116'/>yyy<img src='117'/><img src='118'/>
Any suggestions? Thanks a lot.
Change Spannable.SPAN_INCLUSIVE_EXCLUSIVE to Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
Hope it helps.
As SpannableString content is immutable, it might not allow you to edit between two emojis, Instead of that try with SpannableStringBuilder whose content and markup can both be changed. Hope it will help

AutoLink link square brackets of URL in TextView

I have a url:
https://<site name>/pallavi/[Songs.PK]%2002%20.mp3
I have a text view, with property: android:autoLink="all"
If I simply set the text to the text view, my text view simply highlights the portion preceding the [. It looks something like this:
https://< site name >/pallavi/[Songs.PK]%2002%20.mp3
What i want is, the whole link should be highlighted like:
https://< site name >/pallavi/[Songs.PK]%2002%20.mp3
What I have tried till now:
Used the < pre > tag and Html.fromHtml, but it doesn't seem to work! (I don't even know if the < pre > is supported in android though.)
Used Jsoup.parser. But that too doesn't seem to work for me.
UPDATE
I have tried this answer too: https://stackoverflow.com/a/12376115/1320263
Please let me know if the issue is with android that the text view's linkAll property itself does not consider parenthesis as a valid character or not? If it is supported, how do i hyperlink that too?
Also NOTE:
The text(or link) I have written in the question is just a sample text. In reality, I am getting a block of text, from where it would be very difficult to identify where exactly the hyper link starts and where it ends. Also, the number of links present in the block would be un-known. Hence I cannot use the < a href = "" > thing...
If some one else happens to have the same issue, following is the solution which worked for me:
Pattern pattern = Pattern.compile("(?i)\\b((?:[a-z][\\w-]+:(?:/{1,3}|[a-z0-9%])|www\\d{0,3}[.]|[a-z0-9.\\-]+[.][a-z]{2,4}/)(?:[^\\s()<>]+|\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\))+(?:\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\)|[^\\s`!()\\[\\]{};:'\".,<>?«»“”‘’]))");
SpannableString spannable = new SpannableString(html);
Matcher matcher = pattern.matcher(spannable);
// Create ActivitySpans for each match
while (matcher.find())
spannable.setSpan(new ActivitySpan(matcher.group()), matcher.start(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
// Create a new TextView with these spans and enable the clickable links
mTxtEventDescription.setText(spannable);
You can try this:
((TextView) findViewById(R.id.your_text_view)).setMovementMethod(LinkMovementMethod.getInstance());
((TextView) findViewById(R.id.your_text_view)).setText(Html.fromHtml(getResources().getString(R.string.string_with_links)));`

Android edittext set Arbic and english text mix

i am going to set mix text on edittext like:Xyz Pvt Ltd فاتورة المبيعات مبيعات التسليم <0x09> Choclate Cake 10 x30.000 = 300.000
Acualy i had set text like this but arbic text chage it Xyz Pvt Ltd ف اتورة المبيعات مبيعات التسليم -Choclate Cake 10 x30.000 = 300.000
As you can see in first line after arbick text i had append <0X09> but it will append before arbick text that's proble
You can try to convert the unicode to arabic type with a convertor online and then setText the view with arabic font. For tamil I had used TAB font so I downloaded the tab font and had put it in my assets folder and then in setTypeFace I used the font. You can try the arabic encoded string and the font.
String EncodedString = "Üî¢î¤ò£òñ¢ : "; // Your arab encoded string
Typeface tfTab = Typeface.createFromAsset(getAssets(),"fonts/tabkovai.ttf"); // Replace with arab font
tab.setTypeface(tfTab);
TextView.setText(EncodedString);

Why 'ARABIC LETTER PEH' is not shown correctly on Android 3.x?

In Unicode characters the ARABIC LETTER PEH INITIAL FORM 'ﭘ' is 0xFB58. When I use the following code to show Unicode characters, everything is OK for every Unicode character in Android 2.2, 2.3. and 4.x But I have problem with ARABIC LETTER PEH 'ﭘ' on Android 3.x and in this case character '~' is shown.
Typeface tf = Typeface.createFromAsset(context.getAssets(),"TAHOMA.TTF");
strChars = "";
strChars += (char) 0xFB58;
tvChars.setTypeface(tf);
tvChars.setText(strChars);
I should mention that The problem is remained when I change the font or ignore using setTypeface(tf)
Why?
How can I find the code of ARABIC LETTER PEH in Unicode?
EDIT:
Please compare 0xFB58 (ﭘ) and 0xFB5E (ﭞ) with any font programmatically. you will find the problem. the first one is not shown but the second one is shown correctly.
Did you try adding your own fonts?
Get a Persian TTF font file that fits you and use it, this way you won't be OS dependent.
http://twigstechtips.blogspot.com/2012/01/android-how-to-use-true-type-fonts-ttf.html

Categories

Resources