Using bitmap font for displaying and editing texts - android

One of the problems i'm facing now, is displaying complex texts (English + Persian/Arabic).
The texts which have both English and Persian/Arabic letters, not display in correct order.
For solving this issue, I created a Bitmap Font library that draws these complex texts correctly. Now i want to convert all the texts in all of my program's widgets to their bitmap equivalent. For example, if i have a TextView in my program, i want to get it's text, convert it to a bitmap with my bitmap font library and finally replace it in the TextView. The problem is finding a general solution which can be applied to any widget that can display text, like ListView, EditText, Menus, ...

You can try looking at the source code for TextView and modify it to suite your needs (ie, whenever a user enters a character using the IME, capture the event and insert the correct bitmap character to your custom view...)

Have you seen Arabic Reshaper from all what I've understood it can be used to display correctly texts that contain both RTL (arabic) and LTR symbols.

You can use font library in c++ and render the correct font
though bit lengthy

Related

How to get system Android emoji drawable by unicode character?

I want to implement an android emoji keyboard just using emoji unicode array, without any extra res.
So for the emoji unicode character, I need to get the drawable from android system, if the system doesn't support the charactor, I just ignore this character.
After some basic research,
emojicon, https://github.com/rockerhieu/emojicon
emojicon, https://github.com/ankushsachdeva/emojicon
These implements all use self made resources.
use TextView setText, tv.setText("\u263A"); TextView can show the resource, but how can I get the resource?
Here's the problem- the system doesn't determine what characters can be displayed. The font does. The font needs to define how to draw every character it will display. That's why you'll see boxes or ? for missing characters- that's the font's default render. There is no method on Android to test if a character will display in a given font (although it would be really nice). And since there's no way to know what font the EditText is using, there's no way to know if a given character is supported. Your best bet is to limit yourself to characters defined in the default Android System font. But even then you're assuming the OEM didn't use a different default font, the user hasn't overridden it, and the app hasn't overridden it. Basically, you're forced to guess and hope.

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.

Reader app - use WebView or Canvas?

I'm writing one of those reader applications. I would like to know if you have opinions and arguments for and against using WebView and Canvas (with drawText()) to achieve it.
What are the requirements:
format text according to a few html tags: <p>, <strong>, <h3>, <br/>, <a>,
display images within the text (they are in <img> tags),
display the text in two columns on tablet devices,
paging the text (Google currents style)
The ones in bold are absolutely required. The latter are strongly desired, but I can drop them.
So as far as my knowledge goes:
WebView will be great when it comes to displaying the html formatted text. I also don't have to take care of loading images, tey will be loaded automatically with <img> tags (will they, even if I use loadData() instead of loadUrl()?). The problems begin if I try to page the text. Is there a possibility to count the size of the text in a WebView and reflow it into multiple pages (using ViewPager)?
Canvas is great when it comes to counting the size of the text, putting it into columns and pages. But I will have to handle all the HTML tags myself, format the text myself. What is even worse, I will have to extract images' urls, handle the downloading and putting them back to the text (reflowing the whole text every time they load). Am I right?
Can you point some other advantages and disadvantages of using them? Which would you choose? Or maybe something else? Or is there some lib which does at least some of the work for me?
Why not use the Textview combined with spanned text and viewpagers for the paging.

Android. Image in EditText

I wanna create a simple calculator. One from my goals its place in EditText field images with special math chars as like square root, pi... F.e. :
2/34*sqrt(121)
Here I want to place images instead of divide, multiply chars, sqrt string.
how I can do it?
Some more questions:
Does it actually need to be Editable i.e. user can type directly into it? If so how will it work? when they type '*' it will realize it and replace it with your png? Would it be acceptable if it didn't interrupt as they type but instead all at once when they are finished entering the entire line?
Best answer I have for now:
EditText doesn't support that by default. You'll likely have to create your own view that is some kind of mashup of EditText and LinearLayout that can hold ImageViews with your pngs. If it doesn't need to be editable by the user it is going to be easier because you can make your custom view a LinearLayout and add TextView's and ImageViews with the proper text and images set in them. If it does need to be editable it is going to a bigger challenge. You'll have to use a TextChangedListener to pull out each character as it is typed and replace it with an ImageView if need be. Seems to me like the hard part is going to be knowing where to position the ImageView and having the EditText know that you want it to pick back up with text on the other side of the Image. Im not sure how you'd go about that. Maybe the best solution is you have an EditText that they type into and then seperately you have your custom view as a display view. That way you don't have to worry about positioning images over the top of an EditText and correctly moving the cursor to right side of the image.
What I would suggest is looking into a freely available font that includes mathematical symbols (some quick searching turned up the StixFont project), then just add that font to your assets, and set it as your typeface. You'll still probably need a TextWatcher/TextChangedListener as Tim suggested (unless you're using your own keyboard to input the symbols) but this would get around the problem of trying to insert images into a text field, and would also keep the vector quality provided by fonts versus a raster image embedded into a text field.

How to set numbers as images on TextView?

I made a display, that will show the sum of purchase. It's a TextView with background image. I have a designed digits too. How can I set those digit images to that TextView or do I have to create some layout instead of simple TextView? If I need to create layout, can you add some code sample, how can I do it?
Here's an example what I want to achieve.
Regards,
evilone
As far as I know, your two options would be to create your own True/OpenTypeFont (setting the color of the text to yellow in xml most likely) or to code your own custom ViewGroup which will take a String and convert each character to the appropriate image.
If you're able to construct your own font, you can add a font folder inside your assets project folder, and put your font in it. It can then be loaded like this:
Typeface tf = Typeface.createFromAsset(myContext.getAssets(), "fonts/MyFont.ttf");
myTextView.setTypeface(tf);
This site has free fonts even for commercial use, http://www.fontsquirrel.com and I searched for led and found a font called radioland that looks good, though the numbers are at an angle. If you do use that site, I've found it's good to verify the font is indeed free to use with it's included license or a software and can open the font and view it's headers.
Install and use the National Instruments 7 Segment LED font. For the Pound symbol, you can make a tabular layout and put it in a corner.

Categories

Resources