Search in sources :

Example 1 with IllegalFormatException

use of java.util.IllegalFormatException in project android_frameworks_base by ParanoidAndroid.

the class Chronometer method updateText.

private synchronized void updateText(long now) {
    long seconds = now - mBase;
    seconds /= 1000;
    String text = DateUtils.formatElapsedTime(mRecycle, seconds);
    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);
}
Also used : Locale(java.util.Locale) Formatter(java.util.Formatter) IllegalFormatException(java.util.IllegalFormatException)

Example 2 with IllegalFormatException

use of java.util.IllegalFormatException in project platform_frameworks_base by android.

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);
}
Also used : Locale(java.util.Locale) Formatter(java.util.Formatter) IllegalFormatException(java.util.IllegalFormatException)

Example 3 with IllegalFormatException

use of java.util.IllegalFormatException in project XobotOS by xamarin.

the class Chronometer method updateText.

private synchronized void updateText(long now) {
    long seconds = now - mBase;
    seconds /= 1000;
    String text = DateUtils.formatElapsedTime(mRecycle, seconds);
    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);
}
Also used : Locale(java.util.Locale) Formatter(java.util.Formatter) IllegalFormatException(java.util.IllegalFormatException)

Example 4 with IllegalFormatException

use of java.util.IllegalFormatException in project android_frameworks_base by DirtyUnicorns.

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 "";
    }
}
Also used : DisplayContext(android.icu.text.DisplayContext) IllegalFormatException(java.util.IllegalFormatException) NonNull(android.annotation.NonNull)

Example 5 with IllegalFormatException

use of java.util.IllegalFormatException in project android_frameworks_base by AOSPA.

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 "";
    }
}
Also used : DisplayContext(android.icu.text.DisplayContext) IllegalFormatException(java.util.IllegalFormatException) NonNull(android.annotation.NonNull)

Aggregations

IllegalFormatException (java.util.IllegalFormatException)15 Locale (java.util.Locale)9 Formatter (java.util.Formatter)7 NonNull (android.annotation.NonNull)5 DisplayContext (android.icu.text.DisplayContext)5 StringWriter (java.io.StringWriter)1 Test (org.junit.Test)1