forked from upstream-mirrors/quik
Merge pull request #202 from danielchristopher1/master
Small refactoring
This commit is contained in:
@@ -38,28 +38,29 @@ public class EmojiRegistry {
|
|||||||
public static String parseEmojis(String body) {
|
public static String parseEmojis(String body) {
|
||||||
if (TextUtils.isEmpty(body)) {
|
if (TextUtils.isEmpty(body)) {
|
||||||
return body;
|
return body;
|
||||||
} else {
|
|
||||||
// whitespace and punctuation characters
|
|
||||||
String ACCEPTED_CHARS = "[\\s.,?:;'\"!]";
|
|
||||||
|
|
||||||
// explanation: we want to match:
|
|
||||||
// 1) either an accepted char or the beginning of the text (i.e. ^)
|
|
||||||
// 2) the actual emoji code (to be inserted in the loop)
|
|
||||||
// 3) either an accepted char or the end of the text (i.e. $)
|
|
||||||
String REGEX_TEMPLATE = String.format("(^|%s)%s(%s|$)", ACCEPTED_CHARS, "%s", ACCEPTED_CHARS);
|
|
||||||
|
|
||||||
// iterate over all the entries
|
|
||||||
for (Map.Entry<String, String> entry : EmojiRegistry.EMOJIS_MAP.entrySet()) {
|
|
||||||
// quote the emoji code because some characters like ) are protected in regex land
|
|
||||||
String quoted = Pattern.quote(entry.getKey());
|
|
||||||
String regex = String.format(REGEX_TEMPLATE, quoted);
|
|
||||||
|
|
||||||
// the $1 and $2 represent the character* that came before the emoji and the
|
|
||||||
// character* that came after the emoji
|
|
||||||
// * - or beginning / end of text
|
|
||||||
body = body.replaceAll(regex, "$1:" + entry.getValue() + ":$2");
|
|
||||||
}
|
|
||||||
return EmojiParser.parseToUnicode(body);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// whitespace and punctuation characters
|
||||||
|
String ACCEPTED_CHARS = "[\\s.,?:;'\"!]";
|
||||||
|
|
||||||
|
// explanation: we want to match:
|
||||||
|
// 1) either an accepted char or the beginning of the text (i.e. ^)
|
||||||
|
// 2) the actual emoji code (to be inserted in the loop)
|
||||||
|
// 3) either an accepted char or the end of the text (i.e. $)
|
||||||
|
String REGEX_TEMPLATE = String.format("(^|%s)%s(%s|$)", ACCEPTED_CHARS, "%s", ACCEPTED_CHARS);
|
||||||
|
|
||||||
|
// iterate over all the entries
|
||||||
|
for (Map.Entry<String, String> entry : EmojiRegistry.EMOJIS_MAP.entrySet()) {
|
||||||
|
// quote the emoji code because some characters like ) are protected in regex land
|
||||||
|
String quoted = Pattern.quote(entry.getKey());
|
||||||
|
String regex = String.format(REGEX_TEMPLATE, quoted);
|
||||||
|
|
||||||
|
// the $1 and $2 represent the character* that came before the emoji and the
|
||||||
|
// character* that came after the emoji
|
||||||
|
// * - or beginning / end of text
|
||||||
|
body = body.replaceAll(regex, "$1:" + entry.getValue() + ":$2");
|
||||||
|
}
|
||||||
|
|
||||||
|
return EmojiParser.parseToUnicode(body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package com.moez.QKSMS.common.emoji;
|
package com.moez.QKSMS.common.emoji;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines all supported emojis
|
||||||
|
*/
|
||||||
public class Emojis {
|
public class Emojis {
|
||||||
public static final String SMILE = "smile";
|
public static final String SMILE = "smile";
|
||||||
public static final String SMILEY = "smiley";
|
public static final String SMILEY = "smiley";
|
||||||
|
|||||||
@@ -122,6 +122,7 @@ public class Contact {
|
|||||||
mIsStale = true;
|
mIsStale = true;
|
||||||
mSendToVoicemail = false;
|
mSendToVoicemail = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("{ number=%s, name=%s, nameAndNumber=%s, label=%s, person_id=%d, hash=%d method_id=%d }",
|
return String.format("{ number=%s, name=%s, nameAndNumber=%s, label=%s, person_id=%d, hash=%d method_id=%d }",
|
||||||
|
|||||||
@@ -189,10 +189,9 @@ public class ContactHelper {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Bitmap blankContact(Context context, String name) {
|
public static Bitmap blankContact(Context context, String name) {
|
||||||
String text = name == null || PhoneNumberUtils.isWellFormedSmsAddress(PhoneNumberUtils.stripSeparators(name)) || name.length() == 0 ? "#" : "" + name.toUpperCase().charAt(0);
|
String text = name == null || PhoneNumberUtils.isWellFormedSmsAddress(PhoneNumberUtils.stripSeparators(name)) || name.length() == 0 ? "#" : "" + name.toUpperCase().charAt(0);
|
||||||
|
|
||||||
|
|||||||
@@ -82,12 +82,12 @@ public class Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isMms() {
|
public boolean isMms() {
|
||||||
boolean bool = false;
|
boolean isMms = false;
|
||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
try {
|
try {
|
||||||
cursor = context.getContentResolver().query(MMS_SMS_CONTENT_PROVIDER, new String[]{SmsHelper.COLUMN_MMS}, "_id=" + id, null, null);
|
cursor = context.getContentResolver().query(MMS_SMS_CONTENT_PROVIDER, new String[]{SmsHelper.COLUMN_MMS}, "_id=" + id, null, null);
|
||||||
cursor.moveToFirst();
|
cursor.moveToFirst();
|
||||||
bool = "application/vnd.wap.multipart.related".equals(cursor.getString(cursor.getColumnIndex(SmsHelper.COLUMN_MMS)));
|
isMms = "application/vnd.wap.multipart.related".equals(cursor.getString(cursor.getColumnIndex(SmsHelper.COLUMN_MMS)));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
@@ -95,7 +95,7 @@ public class Message {
|
|||||||
cursor.close();
|
cursor.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return bool;
|
return isMms;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAddress() {
|
public String getAddress() {
|
||||||
|
|||||||
Reference in New Issue
Block a user