summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Sandler <dsandler@android.com>2012-10-19 13:36:58 -0400
committerDaniel Sandler <dsandler@android.com>2012-10-19 13:38:11 -0400
commitb9d36649ca458cb5326a144fd88e26b92efba728 (patch)
tree8a03fb8bb423e595e37dc1d747541dcba0dc8711
parenta1f739ea83b6d770b8469ae1c2c4161f6fe96334 (diff)
downloadframeworks_base-b9d36649ca458cb5326a144fd88e26b92efba728.zip
frameworks_base-b9d36649ca458cb5326a144fd88e26b92efba728.tar.gz
frameworks_base-b9d36649ca458cb5326a144fd88e26b92efba728.tar.bz2
Properly show emoji in the notification ticker.
Add an emoji test to StatusBarTest (working around some difficulties in actually putting high-Unicode chars in the layout xml). Bug: 7378383 Change-Id: Ifce9844b26f67d2799521623e5161aa4dad69ed1
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/Ticker.java19
-rw-r--r--tests/StatusBar/res/layout/notification_builder_test.xml12
-rw-r--r--tests/StatusBar/src/com/android/statusbartest/NotificationBuilderTest.java42
3 files changed, 61 insertions, 12 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/Ticker.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/Ticker.java
index 67846a3..ecc70d6 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/Ticker.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/Ticker.java
@@ -53,6 +53,16 @@ public abstract class Ticker {
private TextSwitcher mTextSwitcher;
private float mIconScale;
+ public static boolean isGraphicOrEmoji(char c) {
+ int gc = Character.getType(c);
+ return gc != Character.CONTROL
+ && gc != Character.FORMAT
+ && gc != Character.UNASSIGNED
+ && gc != Character.LINE_SEPARATOR
+ && gc != Character.PARAGRAPH_SEPARATOR
+ && gc != Character.SPACE_SEPARATOR;
+ }
+
private final class Segment {
StatusBarNotification notification;
Drawable icon;
@@ -68,7 +78,7 @@ public abstract class Ticker {
}
CharSequence rtrim(CharSequence substr, int start, int end) {
- while (end > start && !TextUtils.isGraphic(substr.charAt(end-1))) {
+ while (end > start && !isGraphicOrEmoji(substr.charAt(end-1))) {
end--;
}
if (end > start) {
@@ -101,7 +111,7 @@ public abstract class Ticker {
this.first = false;
int index = this.next;
final int len = this.text.length();
- while (index < len && !TextUtils.isGraphic(this.text.charAt(index))) {
+ while (index < len && !isGraphicOrEmoji(this.text.charAt(index))) {
index++;
}
if (index >= len) {
@@ -136,7 +146,7 @@ public abstract class Ticker {
this.text = text;
int index = 0;
final int len = text.length();
- while (index < len && !TextUtils.isGraphic(text.charAt(index))) {
+ while (index < len && !isGraphicOrEmoji(text.charAt(index))) {
index++;
}
this.current = index;
@@ -194,7 +204,8 @@ public abstract class Ticker {
final Drawable icon = StatusBarIconView.getIcon(mContext,
new StatusBarIcon(n.pkg, n.user, n.notification.icon, n.notification.iconLevel, 0,
n.notification.tickerText));
- final Segment newSegment = new Segment(n, icon, n.notification.tickerText);
+ final CharSequence text = n.notification.tickerText;
+ final Segment newSegment = new Segment(n, icon, text);
// If there's already a notification schedule for this package and id, remove it.
for (int i=0; i<mSegments.size(); i++) {
diff --git a/tests/StatusBar/res/layout/notification_builder_test.xml b/tests/StatusBar/res/layout/notification_builder_test.xml
index 6c384f7..94fc089 100644
--- a/tests/StatusBar/res/layout/notification_builder_test.xml
+++ b/tests/StatusBar/res/layout/notification_builder_test.xml
@@ -371,6 +371,12 @@
android:tag="Oh my goodness. SOMETHING HAPPENED!!!!"
/>
<RadioButton
+ android:id="@+id/text_emoji"
+ style="@style/FieldContents"
+ android:text="emoji"
+ android:tag="_ Cactus _ Cactus _"
+ />
+ <RadioButton
android:id="@+id/text_haiku"
style="@style/FieldContents"
android:text="haiku"
@@ -572,6 +578,12 @@
android:tag="sholes final approach\nlanding gear punted to flan\nrunway foam glistens"
/>
<RadioButton
+ android:id="@+id/ticker_emoji"
+ style="@style/FieldContents"
+ android:text="emoji"
+ android:tag="_ Cactus _ Cactus _"
+ />
+ <RadioButton
android:id="@+id/ticker_custom"
style="@style/FieldContents.Disabled"
android:text="custom view"
diff --git a/tests/StatusBar/src/com/android/statusbartest/NotificationBuilderTest.java b/tests/StatusBar/src/com/android/statusbartest/NotificationBuilderTest.java
index fefd890..2f0c173 100644
--- a/tests/StatusBar/src/com/android/statusbartest/NotificationBuilderTest.java
+++ b/tests/StatusBar/src/com/android/statusbartest/NotificationBuilderTest.java
@@ -32,6 +32,7 @@ import android.os.Bundle;
import android.os.Environment;
import android.os.Vibrator;
import android.os.Handler;
+import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.util.Log;
import android.net.Uri;
@@ -187,6 +188,20 @@ public class NotificationBuilderTest extends Activity
mNM.notify(id, n);
}
+ private static CharSequence subst(CharSequence in, char ch, CharSequence sub) {
+ int i=0;
+ SpannableStringBuilder edit = new SpannableStringBuilder(in);
+ while (i<edit.length()) {
+ if (edit.charAt(i) == ch) {
+ edit.replace(i, i+1, sub);
+ i += sub.length();
+ } else {
+ i ++;
+ }
+ }
+ return edit;
+ }
+
private Notification buildNotification(int id) {
Notification.Builder b = new Notification.Builder(this);
@@ -223,19 +238,25 @@ public class NotificationBuilderTest extends Activity
}
// title
- final String title = getRadioTag(R.id.group_title);
+ final CharSequence title = getRadioTag(R.id.group_title);
if (!TextUtils.isEmpty(title)) {
b.setContentTitle(title);
}
// text
- final String text = getRadioTag(R.id.group_text);
+ final CharSequence text = getRadioTag(R.id.group_text);
if (!TextUtils.isEmpty(text)) {
- b.setContentText(text);
+ if (getRadioChecked(R.id.group_text) == R.id.text_emoji) {
+ // UTF-16 for +1F335
+ b.setContentText(subst(text,
+ '_', "\ud83c\udf35"));
+ } else {
+ b.setContentText(text);
+ }
}
// info
- final String info = getRadioTag(R.id.group_info);
+ final CharSequence info = getRadioTag(R.id.group_info);
if (!TextUtils.isEmpty(info)) {
b.setContentInfo(info);
}
@@ -272,6 +293,11 @@ public class NotificationBuilderTest extends Activity
case R.id.ticker_haiku:
b.setTicker(getRadioTag(R.id.group_ticker));
break;
+ case R.id.ticker_emoji:
+ // UTF-16 for +1F335
+ b.setTicker(subst(getRadioTag(R.id.group_ticker),
+ '_', "\ud83c\udf35"));
+ break;
case R.id.ticker_custom:
// TODO
break;
@@ -370,19 +396,19 @@ public class NotificationBuilderTest extends Activity
return g.getCheckedRadioButtonId();
}
- private String getRadioTag(int id) {
+ private CharSequence getRadioTag(int id) {
final RadioGroup g = (RadioGroup)findViewById(id);
final View v = findViewById(g.getCheckedRadioButtonId());
- return (String)v.getTag();
+ return (CharSequence) v.getTag();
}
private int getRadioInt(int id, int def) {
- String str = getRadioTag(id);
+ CharSequence str = getRadioTag(id);
if (TextUtils.isEmpty(str)) {
return def;
} else {
try {
- return Integer.parseInt(str);
+ return Integer.parseInt(str.toString());
} catch (NumberFormatException ex) {
return def;
}