Android Emoticons Implementation - java

Hello everyone ,
I am developing an application which required implementation of emoticons ( smiley). I can replace specific strings with drawable but it would be very time consuming. Is there any we to use system built in emoticons or some library to shorten my work? What I want is when I send text like this :) , the receiver get emoticon. Or when I send an emoticon he will get the same. Getting android system emoticons can help me too much.Your help would be great favor for me. Thanks

Emoji is a list of unicode emoticons which has a github that can implement emoticons into code (Found here).
From there you could use regex(\ue415\ue056\ue057) to find them or build them by char array (below).
Example:
StringBuilder sb = new StringBuilder();
for (char curr : str.toCharArray()) {
sb.append((SUPPORTED_EMOJI_SET.contains(curr)) ? convertCharToImgTag(curr) : curr);
}
where SUPPORTED_EMOJI_SET is just a set of chars, for example:
new HashSet<Character>() {{
add('\ue415');
add('\ue056');
...
}}
For more ideas: go here!

Related

Why are complex emojis not merged but split up when drawn on Android canvas?

I want to implement an emoji selector for my keyboard app Keyboard Designer. To do so I want to draw emojis based on unicodes in hexadecimal format. The emoji "\u1F636\u200D\u1F32B\uFE0F" is shown correctly when I write it in the text field (two eyes behind a cloud), but when I draw it on my canvas, it looks like two separate emojis (left top corner of the keyboard):
Hint: The hearts do nothing have to do with the question, they only mark favourite emojis
My source is nested in objects and methods, but to show you how it works, I change it to linear commands:
ArrayList<char[]> utf16Chars = new ArrayList<>();
String hexCode = "\\u1F636\\u200D\\u1F32B\\uFE0F";
int distance;
if (hexCode.startsWith("\\")) {
for (int i = 0; i < hexCode.length(); i += distance) {
distance = hexCode.indexOf("\\", i + 1) - i;
if (distance < 0)
distance = hexCode.length() - i;
String utf16Code = hexCode.substring(i, i + distance);
int decimalCode = Integer.parseInt(utf16Code.length() >= 6 ? utf16Code.substring(2) : utf16Code, 16);
char[] utf8Chars = Character.toChars(decimalCode);
utf16Chars.add(utf8Chars);
}
}
StringBuilder stringBuilder = new StringBuilder();
for(char[] utf8Chars : utf16Chars)
for(char character : utf8Chars)
stringBuilder.append(character);
String emoji = stringBuilder.toString();
canvas.drawText(emoji, 0, emoji.length(), x, y, paint);
Does anyone have an idea what I do wrong?
Update
Also see this bug report.
The Face in Clouds Emoji was added in Emoji Version 13.1 and will probably be generally available in later versions of Android. My answer, below, works for API 31 but not for API 30 or before. There is a backward compatibility issue with that solution.
There is a class EmojiCompat that can supply compatibility that will display the "Face in Clouds" emoji on Android version before API 31.
I have put together a EmojiCompat project based on the EmojiCompat app in Google's user-interface-samples. A couple of notes on this demo:
The EmojiCompatApplication class has some important setup.
The dependency on version 1.1.0 of androidx.emoji:emoji-bundled was updated to version 1.2.0-alpha03. Without this update, the "Face in Clouds" emoji displays as two emojis and not one. As new emojis are released (yearly, I think), this library will need to be updated. I believe an alternative is to use downloadable emoji fonts, but I do not address downloadable fonts here.
In MainActivity, I left everything as it was in the Google project except that I added processing for "MyView" which creates a StaticLayout and displays the content using Layout.draw(canvas) as specified in my previous solution which is what the OP was requesting. Canvas.drawText() is still discouraged.
Here is the output of the demo app on an emulator running API 24:
This was more involved than I thought at first and I could not find a good tutorial online. Maybe someone knows of one and can suggest it.
I used the following simple code to create the combined emoji.
// val cloudy = "\u1F636\u200D\u1F32B\uFE0F"
val cloudyFace = intArrayOf(0x1F636, 0x200D, 0x1F32B, 0xFE0F)
val sb = StringBuilder()
for (i in 0 until cloudyFace.size) {
sb.append(getUtf16FromInt(cloudyFace[i]))
}
binding.textView.text = sb.toString()
fun getUtf16FromInt(unicode: Int) = String(Character.toChars(unicode))
Instead of using Canvas.drawText() use layout.draw(canvas) where layout is a StaticLayout. From the documentation:
This is used by widgets to control text layout. You should not need to use this class directly unless you are implementing your own widget or custom display object, or would be tempted to call Canvas.drawText() directly.
Bottom line: Don't use Canvas.drawText().
You may also use the BoringLayout class if that better suits your needs.

Java equals() seemingly returns wrong bool value

So my app is saving the names of Bluetooth devices the user has connected to previously in SharedPreferences which is than compared to all of the names of currently paired devices so on opening the app can instantly connect to the said device. This is done by this piece of code:
sharedPreferences = getApplicationContext().getSharedPreferences("BtNames", MODE_PRIVATE);
keys = sharedPreferences.getAll();
for(BluetoothDevice device : pairedDevices) {
try {
for (Map.Entry<String, ?> entry : keys.entrySet()) {...}
This loops through the paired devices and the entries of SharedPreferences whose value than is accessed by this code:
String device_name = device.getName();
String name = entry.getValue().toString();
Now both of these work well and entry.getValue()... returns the exact names of the previously connected devices. The problem occurs when trying to compare the two Strings by:
device_name.equals(name)
This returns false even though both of the Strings appear to be exact same when logged:
E/FaceTracker: EV3LO
E/FaceTracker: EV3LO
I have already tried to replace all spaces with nothing but that didn't work either. Maybe I overlooked something but at the moment I don't really have a clue what's going wrong.
Thanks in advance for answers.
The problem is a non printable and non ASCII character at the end or the beginning of the string. Please try the following script:
name.replaceAll("\\P{Print}","");
I hope it helpem and good luck if it didn't

Android Compare Lockscreen pattern captured from 2 sources

I am working on an android app where I am saving the a lock pattern.
While the user enters a pattern while powering on the screen, I am checking if it is the same as the saved pattern.
I am saving the pattern in the application using: https://github.com/haibison/android-lockpattern/
The problem is that both are in different formats:
1) lockpattern Object captured while powering on the screen:
[(row=1,clmn=0), (row=0,clmn=1), (row=1,clmn=1), (row=2,clmn=1), (row=1,clmn=2)]
2) And this one i am capturing using haibison's method:
char[] pattern = data.getCharArrayExtra(LockPatternActivity.EXTRA_PATTERN);
String lockpattern = new String(pattern);
Can you please provide some examples/links.
Should I not use haibison's method?
You have to set an Encrypter before starting the Lockpattern-Intent in order to get a proper representation from haibison's char-array , e.g. LPEncrypter (https://bitbucket.org/haibison/android-lockpattern/wiki/Encryption):
AlpSettings.Security.setEncrypterClass(context, LPEncrypter.class);
E.g. a simple representation for this pattern:
Simple Pattern
Habisons char array without the Encrypter is like this:
[3,9,7,7,c,9,3,7,e,c,e,a,5,6,2,4,0,e,a,7,3,9,3,4,b,8,e,9,a,c,9,7,6,6,e,8,e,8,d,0]
using the Example-Encrypter with
String[] ids = new String(pattern).split("[^0-9]");
you'll get [1,-,2,-,3,-,6] which should be easy to convert into your lockpattern-representation.

About Emoticons in android 2.3.7

I'm trying to make a chat app in android, I wanna add emotions in my app..
I used unicode in android 4.4.2 and it worked fine..
But when I try to use it in android 2.3.7 it doesn't work.. So how can i use emoticons in android 2.3.7 and in android 2.3.7 there is emoticons panel in Messaging (Insert Smiley) does that use unicode ? And if it uses it how can I get characters unicode ? I googled for it but found nothing.
I want it to be like this in my code :
array.add(new Emoticon(unicode, ":D")): // Emoticon class is a custom class with constructor (String unicode, String Shortcut)
Thanks :)
If you want to implement in your app emoticons keyboard you can use in this great library:
https://github.com/ankushsachdeva/emojicon
This shows a popup window with emojicons over the soft keyboard.
in this library you can find EmojiconHandler class and there you can see this code that generate the emoticons:
sEmojisMap.put(0x1f604, R.drawable.emoji_1f604);
sEmojisMap.put(0x1f603, R.drawable.emoji_1f603);
sEmojisMap.put(0x1f600, R.drawable.emoji_1f600);
sEmojisMap.put(0x1f60a, R.drawable.emoji_1f60a);
sEmojisMap.put(0x263a, R.drawable.emoji_263a);
sEmojisMap.put(0x1f609, R.drawable.emoji_1f609);....
more of that , in this site :
http://www.fileformat.info/info/unicode/char/search.htm
you can convert emoticons from UTF-16 to java source code like this example:
UTF-16 ---> 0x1f604 in java source code equls to ---> "\uD83D\uDE03"

Sample DevicePolicyManager codes from Android 2.2 work?

Im looking for some sample codes to start with thanks, although i can read the api ,this will be a big help for others to help with a simple code.
Taken from the API Demo:
// Password quality spinner choices
// This list must match the list found in
// samples/ApiDemos/res/values/arrays.xml
final static int mPasswordQualityValues[] = new int[] {
DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED,
DevicePolicyManager.PASSWORD_QUALITY_SOMETHING,
DevicePolicyManager.PASSWORD_QUALITY_NUMERIC,
DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC,
DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC
};
Ref: DeviceAdminSample.java

Categories