|
32 | 32 | import android.os.Environment; |
33 | 33 | import android.os.Vibrator; |
34 | 34 | import android.os.Handler; |
| 35 | +import android.text.SpannableStringBuilder; |
35 | 36 | import android.text.TextUtils; |
36 | 37 | import android.util.Log; |
37 | 38 | import android.net.Uri; |
@@ -187,6 +188,20 @@ private void sendNotification(int id) { |
187 | 188 | mNM.notify(id, n); |
188 | 189 | } |
189 | 190 |
|
| 191 | + private static CharSequence subst(CharSequence in, char ch, CharSequence sub) { |
| 192 | + int i=0; |
| 193 | + SpannableStringBuilder edit = new SpannableStringBuilder(in); |
| 194 | + while (i<edit.length()) { |
| 195 | + if (edit.charAt(i) == ch) { |
| 196 | + edit.replace(i, i+1, sub); |
| 197 | + i += sub.length(); |
| 198 | + } else { |
| 199 | + i ++; |
| 200 | + } |
| 201 | + } |
| 202 | + return edit; |
| 203 | + } |
| 204 | + |
190 | 205 | private Notification buildNotification(int id) { |
191 | 206 | Notification.Builder b = new Notification.Builder(this); |
192 | 207 |
|
@@ -223,19 +238,25 @@ private Notification buildNotification(int id) { |
223 | 238 | } |
224 | 239 |
|
225 | 240 | // title |
226 | | - final String title = getRadioTag(R.id.group_title); |
| 241 | + final CharSequence title = getRadioTag(R.id.group_title); |
227 | 242 | if (!TextUtils.isEmpty(title)) { |
228 | 243 | b.setContentTitle(title); |
229 | 244 | } |
230 | 245 |
|
231 | 246 | // text |
232 | | - final String text = getRadioTag(R.id.group_text); |
| 247 | + final CharSequence text = getRadioTag(R.id.group_text); |
233 | 248 | if (!TextUtils.isEmpty(text)) { |
234 | | - b.setContentText(text); |
| 249 | + if (getRadioChecked(R.id.group_text) == R.id.text_emoji) { |
| 250 | + // UTF-16 for +1F335 |
| 251 | + b.setContentText(subst(text, |
| 252 | + '_', "\ud83c\udf35")); |
| 253 | + } else { |
| 254 | + b.setContentText(text); |
| 255 | + } |
235 | 256 | } |
236 | 257 |
|
237 | 258 | // info |
238 | | - final String info = getRadioTag(R.id.group_info); |
| 259 | + final CharSequence info = getRadioTag(R.id.group_info); |
239 | 260 | if (!TextUtils.isEmpty(info)) { |
240 | 261 | b.setContentInfo(info); |
241 | 262 | } |
@@ -272,6 +293,11 @@ private Notification buildNotification(int id) { |
272 | 293 | case R.id.ticker_haiku: |
273 | 294 | b.setTicker(getRadioTag(R.id.group_ticker)); |
274 | 295 | break; |
| 296 | + case R.id.ticker_emoji: |
| 297 | + // UTF-16 for +1F335 |
| 298 | + b.setTicker(subst(getRadioTag(R.id.group_ticker), |
| 299 | + '_', "\ud83c\udf35")); |
| 300 | + break; |
275 | 301 | case R.id.ticker_custom: |
276 | 302 | // TODO |
277 | 303 | break; |
@@ -370,19 +396,19 @@ private int getRadioChecked(int id) { |
370 | 396 | return g.getCheckedRadioButtonId(); |
371 | 397 | } |
372 | 398 |
|
373 | | - private String getRadioTag(int id) { |
| 399 | + private CharSequence getRadioTag(int id) { |
374 | 400 | final RadioGroup g = (RadioGroup)findViewById(id); |
375 | 401 | final View v = findViewById(g.getCheckedRadioButtonId()); |
376 | | - return (String)v.getTag(); |
| 402 | + return (CharSequence) v.getTag(); |
377 | 403 | } |
378 | 404 |
|
379 | 405 | private int getRadioInt(int id, int def) { |
380 | | - String str = getRadioTag(id); |
| 406 | + CharSequence str = getRadioTag(id); |
381 | 407 | if (TextUtils.isEmpty(str)) { |
382 | 408 | return def; |
383 | 409 | } else { |
384 | 410 | try { |
385 | | - return Integer.parseInt(str); |
| 411 | + return Integer.parseInt(str.toString()); |
386 | 412 | } catch (NumberFormatException ex) { |
387 | 413 | return def; |
388 | 414 | } |
|
0 commit comments