SoftKeyboard does not allow keyOutputText and keyIcon on same Key - android

I am trying to modify the SoftKeyboard example (Andriod 3.1 on Moto Xoom) so that I can use an icon on the key and have it output a unicode character when that key is pressed. Specifically I am trying to have it output a beamed eighth note (musical symbol) which is unicode \u266B. Unfortunately I cannot use keyOutputText and keyIcon on the same key in the symbols.xml file which lays out the keys. I need keyIcon because I could not find a way to change the Typeface on the Keyboard Keys to one with that character. I found where I would do it, but its a call to a private method (.setTypeFace) buried in android.jar (KeyboardView if I recall) so I can't.
So I just use an icon to put on the key. This works fine in combination with android:codes, however android:codes will not output my unicode character when I feed it android:codes="\\u266B" which documentation says it should accept. I need android:keyOutputText="\u266B" to get the character to actually output into my EditText. So I can make the key display an icon of my character and the EditText display the character itself, but not the two together. When I try to use the 2 together it compiles and runs just fine, then I hit the shift button on the keyboard to display the symbols and only the numbers 0-9 show up, the rest of the keyboard is just gone. Now error messages or anything, just gone. Nowhere does it say these two things are exclusive that I could find, nor does it make any logical sense for them to be. If this is a bug, I just want to know so I can accept it and stop banging my head against it (a planned fix date would be nice too). If not, how can I get both the key on the keyboard and the EditText box to show my beamed eighth note. I am open to any suggestion or work arounds. Thanks.

Use a HashMap to map the android:codes to your unicode character.
In XML :
<Key android:codes="719" android:keyIcon="#drawable/zo"/> //use your icon and required code here
In java code:
HashMap<String, String> keyCodeMap = new HashMap<String, String>();
keyCodeMap.put("719", ""+'\u0986');
Then, in the onKey(int primaryCode, int[] keyCodes) method get the corresponding character using using following code:
String c = keyCodeMap.get(String.valueOf(primaryCode));
Use the value of c where you need.

Not sure if this is really going to help, since it's for AnySoftKeyboard, but the problem is the same, so maybe the solution is too?
What solved the problem (for me, creating a layout for ASK) was this:
supply both keyIcon and keyOutputText AS WELL as android:codes, but NO keyLabel!
keyLabel gets filled (by ASK?) with the first letter of android:codes, but you still see the image and it outputs multi-letter text.
Hope it helps, might be worth a try in any case, I guess.
(Please note: I just found this out and although I could reproduce it, I can't guarantee if it really was this that solved the problem. I honestly think so, though.)

Instead of using \u266B in android:codes try the int value of the unicode: 0x266B.
Then from onKey you can convert it back to String using:
Character.toString((char)primaryCode)

Related

Skip suggestion string value from Android EditText

I have an Android EditText with suggestions enabled. My goal is not to disable suggestion (since i'm able to do that), but to skip some string values from them.
For example, suppose that i'd like to skip 'hello' word.
If i write 'he' in the EditText, my suggestions list shouldn't contain 'hello' since it's a string that has to be skipped. Is it possible?
Hope i explained myself, thanks

Copy "Text" column content only from logcat view

Does anybody know of a way, or something that could ease the process of manually removing the extra strings, to get only the content of the "Text" column in the logcat view when copying the logcat content?
Seems not possible, but I've drawn an attention to it through android issues portal:
https://code.google.com/p/android/issues/detail?id=77883&thanks=77883&ts=1413891569
Hopefully it will be implemented soon enough, as it woudl be really helpful.
There are two ways to achieve that:
The First Way, if you have multiple lines:
copy your text to Notepad++ or any editor that uses Regex.
press ctrl+f and choose Replace tab.
use a Regex format in order to remove all the unnecessary tags info, for example in the case of System.out messages, the Regex formula will be:
\d*-\d* \d*:\d*:\d*\.\d*: I\/System\.out\(\d*\):
if the messages are like:
03-14 14:44:17.557: I/System.out(18293):
finaly, use this formula in [find what] field and use a white space in the [Replace with] field, and don't forget to choose Regular Expression choice in the (search mode) field.
The second way, if you have a single line of log: as described here:
Right click on the line in Logcat which you wish to copy text from
Click “find similar messages”
In the window that pops up the text is contained in the field “by Log Message:”
This text can now be copied via Ctrl+C

inputType="textMultiLine" not working with imeOptions="actionSend"?

As topic says, is it not possible to use inputType="textMultiLine" with a EditText which uses imeOptions="actionSend" ? Why must it be set to only inputType="text" ? Is there any work-around to solve this? Never used this before so I am kinda new to it. /Thx!
when you use imeOptions="actionsSend", it converts the enter key into send key and hence there is no enter key in the keypad. So it is not possible to use multi line text.

Android Replace "..." with ellipsis character

Since AVD tools 16 I'm getting this warning:
Replace "..." with ellipsis character (..., …) ?
in my strings.xml
at this line
<string name="searching">Searching...</string>
How do I replace ...? Is it just literally …?
Could someone explain this encoding?
… is the unicode for "…" so just replace it. It's better to have it as one char/symbol than three dots.
To make thing short just put … in place ...
Link to XML character Entities List
Look at Unicode column of HTML for row named hellip
If you're using Eclipse then you can always do the following:
Right click on the warning
Select "Quick Fix" (shortcut is Ctrl + 1 by default)
Select "Replace with suggested characters"
This should replace your three dots with the proper Unicode character for ellipsis.
Just a note: The latest version of ADT (21.1) sometimes won't do the replace operation properly, but earlier versions had no problem doing this.
This is the character: …
The solution to your problem is:
Go to Window -> Preferences -> Android -> Lint Error Checking
And search for "ellipsis". Change the warning level to "Info" or "Ignore".
This answer is indirectly related to this question:
In my case textView1.setTextView("done&#8230"); was showing some box/chinese character. Later, I checked into fileformat.info for what the value represents and I found this is a Han character.
So, what to do? I searched for "fileformat.info ellipse character" and then everything became clear to me once I saw its values are;
UTF-16 (hex) 0x2026 (2026)
UTF-16 (decimal) 8,230
So, you have several encoding available to represent a character (e.g. 10 in Decimal is represented as A in hexa) so it is very important to know when you are writing an unicode character, how receiving function decodes it. If it decodes as decimal value then you have to provide decimal value, if it accept hexadecimal then you have to provide hexadecimal.
In my case, setTextView() function accepts decimal encoded value but I was providing hexadecimal values so I was getting wrong character.
The quick fix shortcut in Android Studio is Alt + Enter by default.
Best not to ignore it as suggested by some, it seems to me. Use Android Studio to correct it (rather than actually typing in the character code), and the tool will replace the three dots with the three-dot unicode character. Won't be confusing to translators etc.

Android: converting between Strings, SpannedStrings and Spannablestrings

I have a string resource called "foo". It may be a simple string... or it may contain HTML. This may change over time: I should be able to box it up as at least a SpannableString immediately upon reading whether it's HTML or not (but how??)
I want to get that raw CharSequence and first be able to display it as-is (the exact characters, not Android's "interpretation" of it). Right now I can't do that... toString() decides to rip out the parts it doesn't think I want to see.
I'd then like to be able to create a SpannableString from this and other Strings or SpannableStrings via concatenation using some method (none of the normal ones work). I'd like to then use that SpannableString to display the HTML-formatted text in a TextView.
This shouldn't be difficult, but clearly I'm not doing it right (there's very little info out there about this that I've found so far). Surely there is a way to accurately interconvert between between Strings, SpannedStrings and even Spannablestrings, without losing the markups along the way?
Note that I've already played with the somewhat broken Linkify, but I want better control over the process (no dangling unformatted "/"s, proper hrefs, etc.) I can get this all to work IF I stay in HTML at all steps, though I can't concatenate anything.
Edit 1: I've learned I can use the following to always ensure I get my raw string (instead of whatever Android decides it thinks the CharSequence really is). Nice... now, how to coax this into a SpannableString?
<string name="foo"><![CDATA[
<b>Some bold</b>
]]>
</string>
Edit 2: Not sure why this didn't work earlier, but... if foo1 and foo2 are strings marked up as above (as CDATA), then one can apparently do this:
String foo1 = (String)getResources().getText(R.string.foo1);
String foo2 = (String)getResources().getText(R.string.foo2);
SpannedString bar = new SpannedString(Html.fromHtml(foo1+foo2));
Curious: is there a more straightforward solution than this? Is this CDATA business actually necessary? It seems convoluted (but not as convoluted as never quite knowing what the resource type will be... String, Spannable, etc.)
I had the same problem. There are two solutions according to Google API Guides.
First is to escape < mark with < in the string resource. Unfortunately, String conversion removes the tag in the background.
Second is to use Format Strings instead of XML/HTML tags. It seems simpler, faster, and evades hidden conversion problems. getString(resource, ...) works like a printf(string, ...) here.
Both work and require some code to replace given part of the string anyway (handle tags or format strings). Enjoy! =)
It appears there isn't a more straightforward way to accomplish this.

Categories

Resources