I have created a custom soft Keyboard(IME) where we can add custom emoji.
Whenever i try to add my emoticons to it. it override the last text entered. i mean it dont append the emoticons unless it override it. how can i add emoji to currentInputConnection
for example
i image write hello image abcimage ///where image represents emoji
it becomes
i image write hello image image
// and i can add image after space easily or i can repeatedly add images easily .
when i add text it appends to emoji but when i add emoji after entering some text it remove the text and then add it self(emoji image).
Just for testing purpose i put emoji code to shift key
Problem code
else if (primaryCode == Keyboard.KEYCODE_SHIFT)
{
// this.handleShift();
//this.mComposing.append(getSmiledText(getApplicationContext(), ":)"));
ImageGetter imageGetter = new ImageGetter()
{
public Drawable getDrawable(String source) {
Drawable d = getResources().getDrawable(R.drawable.e041);
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
return d;
}
};
Spanned cs = Html.fromHtml("<img src='" + getResources().getDrawable(R.drawable.e041) + "'/>", imageGetter, null);
// getCurrentInputConnection().commitText(cs, 1);
// this.mComposing.append(cs);
//getCurrentInputConnection().commitText(getSmiledText(getApplicationContext(), ":)"), 1);
getCurrentInputConnection().beginBatchEdit();
getCurrentInputConnection().commitText(cs, 1);
getCurrentInputConnection().endBatchEdit();
//getCurrentInputConnection().setComposingText(cs, 1); // it is giving wrong
}
And tried multiple ways to solve it ,some tried codes are shown in comments
Simple Words : I want to append emoji image to text, but when i add image to text, it remove the written text, how can i solve. full source can't be shown it is lengthy. Ask me if you need any method in my class
Related link :
add custom image as Emoji in android
https://stackoverflow.com/questions/24100615/cannot-add-an-image-to-my-keyboard-service
Implementations of Emoji (Emoticon) View/Keyboard Layouts
Thanks in Advance.
I also tried for the same but always got "obj".Atlast I found a solution try this.
Instead of adding drawables just add emoticons by their uniCodes like this..
getCurrentInputConnection().commitText((CharSequence)"\ud83c\udfb5", 1);
Its working for me perfectly.and also remove beginBatchEdit and endBatchEdit from your code.
Thanks
Related
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();
}
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!
Excuse me, I have a question how can l write the code when i click on image button send it on edit view with the same pic inside the button
like the emojicon chat
note :
the same idea of emojicons but with my special icons like this picture
like this picture :
Are you looking for Spannable's? They can be used to insert images into a field that contains plain text in Android. You can view the Google documentation for Spannable's here.
I wrote a code example below that might give you a head start:
public CharSequence addImageSpan(CharSequence text){
SpannableStringBuilder builder=new SpannableStringBuilder(text);
int resId = R.drawable.emoticonImgResource;
builder.setSpan(new ImageSpan(mContext,resId),
text.start(), text.length()-1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
return builder;
}
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)));`
How to Add Smiley/Emojis in Edittext?
Any Source code is Available on Internet, if yes Please Give me Link.
Thanks in Advance.
I am using below code for add Smiley/Emojis in edittext.
ImageGetter imageGetter = new ImageGetter() {
public Drawable getDrawable(String source) {
Drawable d = getResources().getDrawable(R.drawable.happy);
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
return d;
}
};
cs = Html.fromHtml("<img src='" + getResources().getDrawable(R.drawable.happy) + "'/>", imageGetter, null);
edttxtemoji.setText(cs);
Android may not support some special characters, but here is the tutorial anyways:
On a PC, I believe either Alt + 1 or Alt + 2 makes a smiley face.
This website provides an excellent tutorial for how to do alt codes, along with what alt code combination does what.
For a Mac, you can hold "Option + Command + T" down to open a list of special characters. From there, open the category "Miscellaneous." Your smiley is in there.
Is this what you are looking for? If not, just let me know :).
When all else fails, you could just use an image of a smiley-face.
EDIT: I'm using a Mac. I opened TextEdit, followed my above tutorial for the Mac, generated a smiley face, cut the smiley face, and pasted it into the Java code. It worked for me. If it's not working for you, try copying this:
EditText mEditText = null;
mEditText.setText("☺");
EDIT 2: I thought Martin was looking for just a smiley, not a window of Emoji's. Currently, there is no source code to open this window - only a separate app that does this, which can be found at this link or this link.