use of java.util.IllegalFormatException in project platform_frameworks_base by android.
the class InputMethodSubtype method getDisplayName.
/**
* Returns a display name for this subtype.
*
* <p>If {@code subtypeNameResId} is specified (!= 0) text generated from that resource will
* be returned. The localized string resource of the label should be capitalized for inclusion
* in UI lists. The string resource may contain at most one {@code %s}. If present, the
* {@code %s} will be replaced with the display name of the subtype locale in the user's locale.
*
* <p>If {@code subtypeNameResId} is not specified (== 0) the framework returns the display name
* of the subtype locale, as capitalized for use in UI lists, in the user's locale.
*
* @param context {@link Context} will be used for getting {@link Locale} and
* {@link android.content.pm.PackageManager}.
* @param packageName The package name of the input method.
* @param appInfo The {@link ApplicationInfo} of the input method.
* @return a display name for this subtype.
*/
@NonNull
public CharSequence getDisplayName(Context context, String packageName, ApplicationInfo appInfo) {
if (mSubtypeNameResId == 0) {
return getLocaleDisplayName(getLocaleFromContext(context), getLocaleObject(), DisplayContext.CAPITALIZATION_FOR_UI_LIST_OR_MENU);
}
final CharSequence subtypeName = context.getPackageManager().getText(packageName, mSubtypeNameResId, appInfo);
if (TextUtils.isEmpty(subtypeName)) {
return "";
}
final String subtypeNameString = subtypeName.toString();
String replacementString;
if (containsExtraValueKey(EXTRA_KEY_UNTRANSLATABLE_STRING_IN_SUBTYPE_NAME)) {
replacementString = getExtraValueOf(EXTRA_KEY_UNTRANSLATABLE_STRING_IN_SUBTYPE_NAME);
} else {
final DisplayContext displayContext;
if (TextUtils.equals(subtypeNameString, "%s")) {
displayContext = DisplayContext.CAPITALIZATION_FOR_UI_LIST_OR_MENU;
} else if (subtypeNameString.startsWith("%s")) {
displayContext = DisplayContext.CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE;
} else {
displayContext = DisplayContext.CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE;
}
replacementString = getLocaleDisplayName(getLocaleFromContext(context), getLocaleObject(), displayContext);
}
if (replacementString == null) {
replacementString = "";
}
try {
return String.format(subtypeNameString, replacementString);
} catch (IllegalFormatException e) {
Slog.w(TAG, "Found illegal format in subtype name(" + subtypeName + "): " + e);
return "";
}
}
use of java.util.IllegalFormatException in project neo4j by neo4j.
the class FormattedLogTest method logShouldFailAndWriteNothingForInvalidParametersArray.
@Test
public void logShouldFailAndWriteNothingForInvalidParametersArray() {
// Given
StringWriter writer = new StringWriter();
Log log = newFormattedLog(writer);
try {
// When
log.info("%s like me. A T-%d, advanced prototype.", "Not", "1000", 1000);
fail("Should have thrown " + IllegalFormatException.class);
} catch (IllegalFormatException ife) {
// Then
assertThat(writer.toString(), equalTo(""));
}
}
use of java.util.IllegalFormatException in project android_frameworks_base by AOSPA.
the class Chronometer method updateText.
private synchronized void updateText(long now) {
mNow = now;
long seconds = mCountDown ? mBase - now : now - mBase;
seconds /= 1000;
boolean negative = false;
if (seconds < 0) {
seconds = -seconds;
negative = true;
}
String text = DateUtils.formatElapsedTime(mRecycle, seconds);
if (negative) {
text = getResources().getString(R.string.negative_duration, text);
}
if (mFormat != null) {
Locale loc = Locale.getDefault();
if (mFormatter == null || !loc.equals(mFormatterLocale)) {
mFormatterLocale = loc;
mFormatter = new Formatter(mFormatBuilder, loc);
}
mFormatBuilder.setLength(0);
mFormatterArgs[0] = text;
try {
mFormatter.format(mFormat, mFormatterArgs);
text = mFormatBuilder.toString();
} catch (IllegalFormatException ex) {
if (!mLogged) {
Log.w(TAG, "Illegal format string: " + mFormat);
mLogged = true;
}
}
}
setText(text);
}
use of java.util.IllegalFormatException in project android_frameworks_base by DirtyUnicorns.
the class Chronometer method updateText.
private synchronized void updateText(long now) {
mNow = now;
long seconds = mCountDown ? mBase - now : now - mBase;
seconds /= 1000;
boolean negative = false;
if (seconds < 0) {
seconds = -seconds;
negative = true;
}
String text = DateUtils.formatElapsedTime(mRecycle, seconds);
if (negative) {
text = getResources().getString(R.string.negative_duration, text);
}
if (mFormat != null) {
Locale loc = Locale.getDefault();
if (mFormatter == null || !loc.equals(mFormatterLocale)) {
mFormatterLocale = loc;
mFormatter = new Formatter(mFormatBuilder, loc);
}
mFormatBuilder.setLength(0);
mFormatterArgs[0] = text;
try {
mFormatter.format(mFormat, mFormatterArgs);
text = mFormatBuilder.toString();
} catch (IllegalFormatException ex) {
if (!mLogged) {
Log.w(TAG, "Illegal format string: " + mFormat);
mLogged = true;
}
}
}
setText(text);
}
use of java.util.IllegalFormatException in project android_frameworks_base by ResurrectionRemix.
the class Chronometer method updateText.
private synchronized void updateText(long now) {
mNow = now;
long seconds = mCountDown ? mBase - now : now - mBase;
seconds /= 1000;
boolean negative = false;
if (seconds < 0) {
seconds = -seconds;
negative = true;
}
String text = DateUtils.formatElapsedTime(mRecycle, seconds);
if (negative) {
text = getResources().getString(R.string.negative_duration, text);
}
if (mFormat != null) {
Locale loc = Locale.getDefault();
if (mFormatter == null || !loc.equals(mFormatterLocale)) {
mFormatterLocale = loc;
mFormatter = new Formatter(mFormatBuilder, loc);
}
mFormatBuilder.setLength(0);
mFormatterArgs[0] = text;
try {
mFormatter.format(mFormat, mFormatterArgs);
text = mFormatBuilder.toString();
} catch (IllegalFormatException ex) {
if (!mLogged) {
Log.w(TAG, "Illegal format string: " + mFormat);
mLogged = true;
}
}
}
setText(text);
}
Aggregations