1
0
mirror of https://github.com/moparisthebest/k-9 synced 2025-01-13 06:38:05 -05:00

Simplify code and beautify pre-jellybean notifications by using bold

sender span for those.
This commit is contained in:
Danny Baumann 2013-01-02 17:02:57 +01:00
parent be68a6cbe6
commit 42605a7ea9
2 changed files with 27 additions and 28 deletions

View File

@ -19,6 +19,7 @@
</style> </style>
<style name="TextAppearance.StatusBar.EventContent.Emphasized" parent="@android:style/TextAppearance.StatusBar.EventContent"> <style name="TextAppearance.StatusBar.EventContent.Emphasized" parent="@android:style/TextAppearance.StatusBar.EventContent">
<item name="android:textStyle">bold</item>
</style> </style>
</resources> </resources>

View File

@ -4458,7 +4458,15 @@ public class MessagingController implements Runnable {
return context.getString(R.string.general_no_subject); return context.getString(R.string.general_no_subject);
} }
private CharSequence getMessagePreview(Context context, Message message, boolean useSpans) { private static TextAppearanceSpan sEmphasizedSpan;
private void ensureEmphasizedSpan(Context context) {
if (sEmphasizedSpan == null) {
sEmphasizedSpan = new TextAppearanceSpan(context,
R.style.TextAppearance_StatusBar_EventContent_Emphasized);
}
}
private CharSequence getMessagePreview(Context context, Message message) {
CharSequence subject = getMessageSubject(context, message); CharSequence subject = getMessageSubject(context, message);
String snippet = null; String snippet = null;
@ -4497,38 +4505,27 @@ public class MessagingController implements Runnable {
preview.append('\n'); preview.append('\n');
preview.append(snippet); preview.append(snippet);
if (useSpans) { ensureEmphasizedSpan(context);
final TextAppearanceSpan subjectSpan = new TextAppearanceSpan(context, preview.setSpan(sEmphasizedSpan, 0, subject.length(), 0);
R.style.TextAppearance_StatusBar_EventContent_Emphasized);
preview.setSpan(subjectSpan, 0, subject.length(), 0);
}
return preview; return preview;
} }
private CharSequence buildMessageSummary(Context context, CharSequence sender, private CharSequence buildMessageSummary(Context context, CharSequence sender, CharSequence subject) {
CharSequence subject, boolean useSpans) {
if (sender == null) { if (sender == null) {
return subject; return subject;
} }
if (useSpans) {
SpannableStringBuilder summary = new SpannableStringBuilder(); SpannableStringBuilder summary = new SpannableStringBuilder();
final TextAppearanceSpan senderSpan = new TextAppearanceSpan(context,
R.style.TextAppearance_StatusBar_EventContent_Emphasized);
summary.append(sender); summary.append(sender);
summary.append(" "); summary.append(" ");
summary.append(subject); summary.append(subject);
summary.setSpan(senderSpan, 0, sender.length(), 0);
ensureEmphasizedSpan(context);
summary.setSpan(sEmphasizedSpan, 0, sender.length(), 0);
return summary; return summary;
} else {
StringBuilder summary = new StringBuilder();
summary.append(sender);
summary.append(": ");
summary.append(subject);
return summary.toString();
}
} }
private static boolean platformShowsNumberInNotification() { private static boolean platformShowsNumberInNotification() {
@ -4552,7 +4549,7 @@ public class MessagingController implements Runnable {
final KeyguardManager keyguardService = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); final KeyguardManager keyguardService = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
final CharSequence sender = getMessageSender(context, account, message); final CharSequence sender = getMessageSender(context, account, message);
final CharSequence subject = getMessageSubject(context, message); final CharSequence subject = getMessageSubject(context, message);
CharSequence summary = buildMessageSummary(context, sender, subject, false); CharSequence summary = buildMessageSummary(context, sender, subject);
// If privacy mode active and keyguard active // If privacy mode active and keyguard active
// OR // OR
@ -4593,8 +4590,9 @@ public class MessagingController implements Runnable {
// multiple messages pending, show inbox style // multiple messages pending, show inbox style
NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle(builder); NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle(builder);
for (Message m : data.messages) { for (Message m : data.messages) {
style.addLine(buildMessageSummary(context, getMessageSender(context, account, m), style.addLine(buildMessageSummary(context,
getMessageSubject(context, m), true)); getMessageSender(context, account, m),
getMessageSubject(context, m)));
} }
if (data.droppedMessages > 0) { if (data.droppedMessages > 0) {
style.setSummaryText(context.getString( style.setSummaryText(context.getString(
@ -4608,7 +4606,7 @@ public class MessagingController implements Runnable {
} else { } else {
// single message pending, show big text // single message pending, show big text
NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle(builder); NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle(builder);
CharSequence preview = getMessagePreview(context, message, true); CharSequence preview = getMessagePreview(context, message);
if (preview != null) { if (preview != null) {
style.bigText(preview); style.bigText(preview);
} }