Widget: Max out message count at 999+

Bug 3403158

Change-Id: I1daf0c62684bad83a69e19c39ffe1b8df899d077
This commit is contained in:
Andy Stadler 2011-01-30 11:45:33 -08:00
parent 1122e0f644
commit 0e3a03317b
4 changed files with 41 additions and 1 deletions

View File

@ -1018,4 +1018,8 @@ save attachment.</string>
<!-- Shown when no accounts are configured [CHAR LIMIT=35] -->
<string name="widget_touch_to_configure">Touch to configure</string>
<!-- Generic string shown instead of regular numbers, when a number is larger than 999.
This should not be altered if the original string ("999+") makes sense in the
target language. Typical alternatives include "+999" and ">999". [CHAR_LIMIT=4] -->
<string name="more_than_999">999+</string>
</resources>

View File

@ -1289,4 +1289,15 @@ public class Utility {
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
return i;
}
public static String getMessageCountForUi(Context context, int count,
boolean replaceZeroWithBlank) {
if (replaceZeroWithBlank && (count == 0)) {
return "";
} else if (count > 999) {
return context.getString(R.string.more_than_999);
} else {
return Integer.toString(count);
}
}
}

View File

@ -451,7 +451,7 @@ public class WidgetProvider extends AppWidgetProvider {
views.setTextViewText(R.id.widget_tap, sConfigureText);
String count = "";
if (mCursorCount != TOTAL_COUNT_UNKNOWN) {
count = Integer.toString(mCursor.getCount());
count = Utility.getMessageCountForUi(sContext, mCursor.getCount(), false);
}
views.setTextViewText(R.id.widget_count, count);
}

View File

@ -491,6 +491,31 @@ public class UtilityUnitTests extends AndroidTestCase {
// TODO check style -- but how?
}
public void testGetMessageCountForUi() {
final Context c = getContext();
// Negavive valeus not really expected, but at least shouldn't crash.
assertEquals("-1", Utility.getMessageCountForUi(c, -1, true));
assertEquals("-1", Utility.getMessageCountForUi(c, -1, false));
assertEquals("", Utility.getMessageCountForUi(c, 0, true));
assertEquals("0", Utility.getMessageCountForUi(c, 0, false));
assertEquals("1", Utility.getMessageCountForUi(c, 1, true));
assertEquals("1", Utility.getMessageCountForUi(c, 1, false));
assertEquals("999", Utility.getMessageCountForUi(c, 999, true));
assertEquals("999", Utility.getMessageCountForUi(c, 999, false));
final String moreThan999 = c.getString(R.string.more_than_999);
assertEquals(moreThan999, Utility.getMessageCountForUi(c, 1000, true));
assertEquals(moreThan999, Utility.getMessageCountForUi(c, 1000, false));
assertEquals(moreThan999, Utility.getMessageCountForUi(c, 1001, true));
assertEquals(moreThan999, Utility.getMessageCountForUi(c, 1001, false));
}
/**
* A {@link ListView} used by {@link #testListStateSaver}.
*/