Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 99f4cdc8 authored by Daniel Sandler's avatar Daniel Sandler Committed by Android Git Automerger
Browse files

am d1ccf94b: am 694722da: am cc0106cd: Merge "Properly show emoji in the...

am d1ccf94b: am 694722da: am cc0106cd: Merge "Properly show emoji in the notification ticker." into jb-mr1-dev

* commit 'd1ccf94b':
  Properly show emoji in the notification ticker.
parents bea80c0d d1ccf94b
Loading
Loading
Loading
Loading
+15 −4
Original line number Diff line number Diff line
@@ -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++) {
+12 −0
Original line number Diff line number Diff line
@@ -370,6 +370,12 @@
                        android:text="long"
                        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"
@@ -571,6 +577,12 @@
                        android:text="haiku"
                        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"
+34 −8
Original line number Diff line number Diff line
@@ -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)) {
            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;
            }