• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Spannable String Builder problem

The following represents a code that I added to softkeyboard class (from Android SDK samples) the purpose of it is to print an image stored in the resouse

Code:
 public CharSequence addSmileySpans(CharSequence text) {

    Drawable bm = getResources().getDrawable(R.drawable.myimage); 
    bm.setBounds(0, 0, bm.getIntrinsicWidth(), bm.getIntrinsicHeight()); 
    SpannableStringBuilder builder = new SpannableStringBuilder(text);
    ImageSpan is = new ImageSpan(bm);
    builder.setSpan(is,1,3,Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
    return builder;
}

i Called it using the follwing sentence:
Code:
getCurrentInputConnection().commitText(addSmileySpans("abcde"),1);
The result after excuting is writing abcde without the image
when i create a textView in another activity ...
and call the function tv.setText("addSmileySpans("abcde"),1")
it works correctly and display the image
is the problem with commitText ???? (note : i should use commitText in softkeyboard)
 
yes ..
mmm I don't know what is the problem :S :S :S
sooo .. can I change the editText in the softkeyboard ???
by the way i took it in the samples and the XML layout of its view is not shown ..
Sorry for asking alot :)
 
help me please :( ...
can you try it .. on softkeyboard samples 2.3 ???
.. and try it again in another activity using editText et ... and et.setText :S :S
 
Sorry, I had only looked at that specific part of the question... are you sure sending the smiley like that is even valid? It doesn't really make any sense to me to commit an image as text... possible yes: the string could contain markup and a data url, but it's not how I would design such an API. Maybe these APIs only allow real text + built-in smileys... but I'd have to read up on that.
 
I looked on how to create true font (.ttf) and i downloaded creators for ttf font... but the problem was that the smiley would appear in black clolur ( as font ) .. I think its a bad idea :S
I don't want to use a built in emoticon .. i want to add my own one ..
I don't know what to do ...
Thaankssss Alot for helping :)
 
No problem... I just don't have any experience with this either. Problem is: since you're building an IME, you have to output something that the application receiving the input can understand and display... which also rules out using your own font, since you can't control what font the receiving application is using. I'm not sure if what you're trying to accomplish is at all possible. I mean, even if you somehow managed to put all this info into whatever the receiving application is using to display the text... the moment it writes out the content to a file, all the extra data will be lost.
 
Only devices that install the .apk of this softkeyboard are supposed to see the emoticons
I mean that the emoticons must appear in the recieving device if the used softkeyboard is the same ... :S
 
Even then every application displaying the text would have to know that your APK provides the icon and load it... it just doesn't look to me like it would work.

How about doing it the other way around: use your own markup... create text equivalents of your smileys... something like "
 
yes that was my idea .. when i commit the text using
getCurrentInputConnection().commitText(addSmileySpans("abcde"),1);
( the addsmileyspans add Imagespan to the text ) and return char sequence..
I don't know why it is ignoring the image .. and display abcde only
Thanks again :S
 
Because the image is not displayable in the context of the application (it doesn't have access to the resource)... that's assuming that it's even being sent... I'm a bit hazy on whether these APIs work with a plain string or one containing markup.
 
Ummm , Is there any solution for this problem .. :( :( ???
because I'v made a lotttttttt of searches about this .. but I did'nt find any thing related to this topic ..
 
I don't think so... only workarounds... I'd really stick with the my-own-markup solution... it may not be the cleanest one, but it will allow your smileys to work reasonably well no matter where they end up. Make your IME always work in "fullscreen" mode, where you should be able to display the image and encode the output once the input is committed.
 
Remember... I'm just extrapolating from general knowledge here, so I may very well be wrong on the specifics:

1. An IME can run in two modes; a) mixed, where it only occupies part of the screen and lets the running application display the text; b) fullscreen, where it takes up the whole screen and displays the text itself.
2. You can't get an IME to display custom content in mixed mode without hacks, so make sure it runs fullscreen.
 
It doesn't solve the problem .. I turned the keyboard into landscpase mode .. so that it would be displayed in full mode .. bs i got the same result ..
Thanks any way :)
 
I am having the exact same issue. However, I have taken a different approach and arrived at a different conclusion.

I am using Html.fromHtml() in order to create a Spannable object. Then I append that to the mComposing object. Afterwards I call getCurrentInputConnection().commitText(mComposing,1);

Here is where my implementation is at.

[HIGH] String sourceHtml = "<img src='hanging_small.png'/>";

ImageGetter imageGetter = new ImageGetter(){
@Override
public Drawable getDrawable(String source) {
Log.i("SOURCE", "SOURCE: " + source);
Drawable d = getResources().getDrawable(R.drawable.hanging_small);
d.setBounds(0, 0, 10, 10);
return d;
}
};

Spanned spannedString = Html.fromHtml(sourceHtml, imageGetter, null);
Log.i("SPANNED STRING", "SPANNED: " + spannedString);

mComposing.append(spannedString);
getCurrentInputConnection().setComposingText(mComposing, 1);[/HIGH]

this is currently still outputting the "null" drawable which looks like box with the word "obj" inside. I am in the process of debugging why ImageGetter is responding with the null behavior when it should be pointed at an existing drawable.
 
I am having the exact same issue. However, I have taken a different approach and arrived at a different conclusion.

I am using Html.fromHtml() in order to create a Spannable object. Then I append that to the mComposing object. Afterwards I call getCurrentInputConnection().commitText(mComposing,1);

Here is where my implementation is at.

[HIGH] String sourceHtml = "<img src='hanging_small.png'/>";

ImageGetter imageGetter = new ImageGetter(){
@Override
public Drawable getDrawable(String source) {
Log.i("SOURCE", "SOURCE: " + source);
Drawable d = getResources().getDrawable(R.drawable.hanging_small);
d.setBounds(0, 0, 10, 10);
return d;
}
};

Spanned spannedString = Html.fromHtml(sourceHtml, imageGetter, null);
Log.i("SPANNED STRING", "SPANNED: " + spannedString);

mComposing.append(spannedString);
getCurrentInputConnection().setComposingText(mComposing, 1);[/HIGH]

this is currently still outputting the "null" drawable which looks like box with the word "obj" inside. I am in the process of debugging why ImageGetter is responding with the null behavior when it should be pointed at an existing drawable.
Hi wapples,

I have facing the same problem for my softkeyboard.Can you find any solution for that problem.If you have any solution or suggestions then please help me about that problem.

I have bundle of thanks in advance for any solution to this problem.
Please help me.

Thanks and Regards.
Jawad Saleem(Snr Software Engineer).
Skype: live:jawadsaleem
Email : jdsahab202@gmail.com,
jawadsaleem@leadconcept.com
 
Back
Top Bottom