Displaying Unicode string in Users control in Xamarin (Android) - android

Basically, i have a list of Nepali Unicode strings something like {"युनिकोड १ ","युनिकोड २","युनिकोड ३"}.
Now, Firstly, I have a text view in Xamarin (Android) and tried to set the text property using couple of methods:
UnicodeTextView.Text="युनिकोड १"; //direct method
var font = Typeface.CreateFromAsset(_activity.Assets, "kantiput.TTF");//kantiput.TTF Is a Nepali font.
UnicodeTextView.Typeface = font;
var font = Typeface.CreateFromAsset(_activity.Assets, "kantiput.TTF");
UnicodeTextView.SetTypeface(font, TypefaceStyle.BoldItalic);
and none of them worked.
When using the first option nothing was displayed, and on working with last two
and there were some BOX character visible.
For first case when i directly tried to set the value:
Before setting value:
After setting value:
Samething with the ListAdapter.
Can anyone suggest me how can we display unicode sentences in TextView, EditText, Toast ?
I want result something like this :
with TextView :
and here is the weird behavior :
and i tried all those code that are in comment too. Still didn't find any luck.

I am working in android.
In toast I checked like the following:
Toast.makeText (this, "\u0c05 \u0c06", Toast.LENGTH_SHORT).Show();
For first two letters of Telugu alphabet s. It worked.
If you have the font file you can obtain unicode codes for the various glyphs in the online software available at
https://opentype.js.org/index.html
Under page glyph inspector.

I tested your code, the first direct method UnicodeTextView.Text="युनिकोड १"; works fine by my side both with single TextView or TextView in ListView.
Or you may try this code:
if (Android.OS.Build.VERSION.SdkInt >= Android.OS.Build.VERSION_CODES.N)
{
UnicodeTextView.Text = Android.Text.Html.FromHtml("युनिकोड १", Android.Text.FromHtmlOptions.ModeLegacy).ToString();
}
else
{
UnicodeTextView.Text = Android.Text.Html.FromHtml("युनिकोड १").ToString();
}

Related

Characters UTF-16LE not showing on my Android Nougat

I am developing an Android Application and I need to display on a TextView special UTF-16LE characters like æ or Œ, or the one in the picture I posted.
I can't understand why everything is displayed correctly on Nougat Emulator and also on an Lollipop and Marshmallow Smartphone while on my Personal Android Nougat I can't see those characters, I can only see ": :" characters instead of the right ones.
(Careful, In the left picture, that ' character is not a normal accent and that I is not a normal I)
Why can't I display those special characters on my Smartphone? How should I proceed with that?
I debugged my application and characters are properly set on my TextView; but still, I can't read them correctly.
It seems that my Smartphone (OnePlus3 on latest Software Updates) can't read UTF-16LE characters, but still, It's really strange for me to face something like that.
Any help would be very appreciated,
Have a nice day.
UPDATE: I downloaded https://play.google.com/store/apps/details?id=org.madore.android.unicodeMap on my Smartphone and it seems that I don't have many of those unicode characters on my Smartphone, is there a way to fix it? Do I just need to install a better font?
I solved my issue, that's what I did. (As usual, thanks also to #Claffolo, my teammate)
I imported a free copyrighted font like Gentium in my android assets.
/assets/fonts/
On my project, I imported the new font and init a variable like that
Typeface plain = Typeface.createFromAsset(getActivity().getAssets(), "fonts/GentiumPlus-I.ttf");
final TextView text_view = (TextView)view.findViewById(R.id.text_view);
text_view.setTypeface(plain);
text_view.setText("[String with special characters]");
When I loaded my ArrayList with all the special characters, let's say my wordlist.
I did it in the following way:
//Loading my Wordlist
BufferedReader line_reader = new BufferedReader(new InputStreamReader(activity.getResources().openRawResource(R.raw.ipautf16le), Charset.forName("UTF-16LE")));
String line;
try {
while ((line = line_reader.readLine()) != null) {
WordList.add(line);
}
} catch (IOException e) {
e.printStackTrace();
}
Collections.sort(WordList);
That's all.

Adobe Air Android / Arabic text issue

i'm using Adobe Flash Air for IOS & Android problem now is the Arabic RTL i can't write arabic.
My
Input Text is Classic not " TLF Text "
The TLF problem is the keyboard not showing up in android..
Example
1) Did you try doing some research? I googled as3 "android" keyboard not showing.
What's wrong with solutions suggested on first page results of the above link?
2) Consider using Stage text and there's an introduction article about it.
3) Try something like below (untested) as a starting point. Hard to fix your code since none shown.
Also read this guide first. Might be useful.
var testInput : TextField = new TextField();
testInput.needsSoftKeyboard = true;
testInput.type = "input";
testInput.addEventListener(FocusEvent.FOCUS_IN, onFocusText);
stage.addChild(testInput);
function onFocusText( e:FocusEvent ):void
{
testInput.requestSoftKeyboard();
}

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)));`

Punjabi Text not shown properly on Mobile

i have used many punjabi fonts as like bulara_f.ttf , anmollipi , Akaash and many more but every time prolem with one word of punjabi "sihari"
Sihari : Sihari is equivalent to i in pin or thin. Hence forth in this module we will denote sihari vowel with /i/.
in my application only this one word is not shown properly as like in following snapshot... please help...
EDIT
i am using this method
Typeface myfont;
myfont=Typeface.createFromAsset(getAssets(),"font.ttf");
TextView textview = (TextView)findViewById(R.id.TextView01);
//textview.setText("punjabi Text");
textview.setTypeface(myfont);
}
Use bulara_5.ttf and run the code on device it will show correct punjabi words
mTvAbout = (TextView) findViewById(R.id.tv_about);
font = Typeface.createFromAsset(this.getAssets(), "bulara_5.ttf");
mTvAbout.setTypeface(font);
mTvAbout.setText(" ਜਾਣਕਾਰੀ");

Highlight Text feature like google play book

I want my android application to have text highlighting within a WebView. Similar to the functionality found in Google play book. Does any one have an idea how to achieve this?
I'm using a WebView because my content is in html form.
basically talking about this effect:
Starting from API level 11, you can use TextView's textIsSelectable flag.
Edit: Even though the question has now been edited to specifically mention WebView, OP #Suhail's comment "my content is in html form" does not fully disqualify TextView as it can also render some basic HTML.
The blue selection you see is part of the standard android environment when selecting text. So that should work on your standard webview without need of any custom code. => I'm no longer convinced this is true. Looks like it's not.
The green (yellow, orange, red, ...) selection however is custom.
You could read out the selected text from your selection event and use that information to update the html content, wrap the text in a span with a background color set.
Alternative approach is using javascript and enabling javascript in your webview. Not sure however how to get that done.
Some sources to check for that approach are https://github.com/btate/BTAndroidWebViewSelection and Android: How to select text from WebView, and highlight it onclick
Text selection from WebView details
To get the text selection working on a WebView you can use the following snippet (from this question). Trigger this on a button click (or other event) from your (context) menu.
private void emulateShiftHeld(WebView view)
{
try
{
KeyEvent shiftPressEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN,
KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0);
shiftPressEvent.dispatch(view);
Toast.makeText(this, "select_text_now", Toast.LENGTH_SHORT).show();
}
catch (Exception e)
{
Log.e("dd", "Exception in emulateShiftHeld()", e);
}
}
If your using WebView Try to integrate Mozilla PDF.JS where you can render PDF . which can contain Images also .

Categories

Resources