Search in sources :

Example 21 with ULocale

use of android.icu.util.ULocale in project android_frameworks_base by AOSPA.

the class StaticLayout_Delegate method nComputeLineBreaks.

@LayoutlibDelegate
static /*package*/
int nComputeLineBreaks(long nativeBuilder, LineBreaks recycle, int[] recycleBreaks, float[] recycleWidths, int[] recycleFlags, int recycleLength) {
    Builder builder = sBuilderManager.getDelegate(nativeBuilder);
    if (builder == null) {
        return 0;
    }
    // compute all possible breakpoints.
    int length = builder.mWidths.length;
    BreakIterator it = BreakIterator.getLineInstance(new ULocale(builder.mLocale));
    it.setText(new Segment(builder.mText, 0, length));
    // average word length in english is 5. So, initialize the possible breaks with a guess.
    List<Integer> breaks = new ArrayList<Integer>((int) Math.ceil(length / 5d));
    int loc;
    it.first();
    while ((loc = it.next()) != BreakIterator.DONE) {
        breaks.add(loc);
    }
    List<Primitive> primitives = computePrimitives(builder.mText, builder.mWidths, length, breaks);
    switch(builder.mBreakStrategy) {
        case Layout.BREAK_STRATEGY_SIMPLE:
            builder.mLineBreaker = new GreedyLineBreaker(primitives, builder.mLineWidth, builder.mTabStopCalculator);
            break;
        case Layout.BREAK_STRATEGY_HIGH_QUALITY:
        //                break;
        case Layout.BREAK_STRATEGY_BALANCED:
            builder.mLineBreaker = new OptimizingLineBreaker(primitives, builder.mLineWidth, builder.mTabStopCalculator);
            break;
        default:
            throw new AssertionError("Unknown break strategy: " + builder.mBreakStrategy);
    }
    builder.mLineBreaker.computeBreaks(recycle);
    return recycle.breaks.length;
}
Also used : ULocale(android.icu.util.ULocale) ArrayList(java.util.ArrayList) Paint(android.graphics.Paint) Segment(javax.swing.text.Segment) BreakIterator(android.icu.text.BreakIterator) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 22 with ULocale

use of android.icu.util.ULocale in project android_frameworks_base by ResurrectionRemix.

the class ZygoteInit method beginIcuCachePinning.

private static void beginIcuCachePinning() {
    // Pin ICU data in memory from this point that would normally be held by soft references.
    // Without this, any references created immediately below or during class preloading
    // would be collected when the Zygote GC runs in gcAndFinalize().
    Log.i(TAG, "Installing ICU cache reference pinning...");
    CacheValue.setStrength(CacheValue.Strength.STRONG);
    Log.i(TAG, "Preloading ICU data...");
    // Explicitly exercise code to cache data apps are likely to need.
    ULocale[] localesToPin = { ULocale.ROOT, ULocale.US, ULocale.getDefault() };
    for (ULocale uLocale : localesToPin) {
        new DecimalFormatSymbols(uLocale);
    }
}
Also used : ULocale(android.icu.util.ULocale) DecimalFormatSymbols(android.icu.text.DecimalFormatSymbols)

Example 23 with ULocale

use of android.icu.util.ULocale in project android_frameworks_base by crdroidandroid.

the class LocaleHelper method getDisplayName.

/**
     * Returns the locale localized for display in the provided locale.
     *
     * @param locale the locale whose name is to be displayed.
     * @param displayLocale the locale in which to display the name.
     * @param sentenceCase true if the result should be sentence-cased
     * @return the localized name of the locale.
     */
public static String getDisplayName(Locale locale, Locale displayLocale, boolean sentenceCase) {
    final ULocale displayULocale = ULocale.forLocale(displayLocale);
    String result = shouldUseDialectName(locale) ? ULocale.getDisplayNameWithDialect(locale.toLanguageTag(), displayULocale) : ULocale.getDisplayName(locale.toLanguageTag(), displayULocale);
    return sentenceCase ? toSentenceCase(result, displayLocale) : result;
}
Also used : ULocale(android.icu.util.ULocale)

Example 24 with ULocale

use of android.icu.util.ULocale in project android_frameworks_base by crdroidandroid.

the class LocaleUtils method calculateMatchingScore.

/**
     * Calculates a matching score for the desired locale list.
     *
     * <p>The supported locale gets a matching score of 3 if all language, script and country of the
     * supported locale matches with the desired locale.  The supported locale gets a matching
     * score of 2 if the language and script of the supported locale matches with the desired
     * locale. The supported locale gets a matching score of 1 if only language of the supported
     * locale matches with the desired locale.  The supported locale gets a matching score of 0 if
     * the language of the supported locale doesn't match with the desired locale.</p>
     *
     * @param supported The locale supported by IME subtyle.
     * @param desired The locale list preferred by user. Typically system locale list.
     * @param out The output buffer to be stored the individual score for the desired language list.
     * The length of {@code out} must be same as the length of {@code desired} language list.
     * @return {@code false} if supported locale doesn't match with any desired locale list.
     * Otherwise {@code true}.
     */
private static boolean calculateMatchingScore(@NonNull final ULocale supported, @NonNull final LocaleList desired, @NonNull byte[] out) {
    if (desired.isEmpty()) {
        return false;
    }
    boolean allZeros = true;
    final int N = desired.size();
    for (int i = 0; i < N; ++i) {
        final Locale locale = desired.get(i);
        if (!locale.getLanguage().equals(supported.getLanguage())) {
            // TODO: cache the result of addLikelySubtags if it is slow.
            out[i] = 0;
        } else {
            out[i] = calculateMatchingSubScore(supported, ULocale.addLikelySubtags(ULocale.forLocale(locale)));
            if (allZeros && out[i] != 0) {
                allZeros = false;
            }
        }
    }
    return !allZeros;
}
Also used : Locale(java.util.Locale) ULocale(android.icu.util.ULocale)

Example 25 with ULocale

use of android.icu.util.ULocale in project android_frameworks_base by crdroidandroid.

the class ZygoteInit method beginIcuCachePinning.

private static void beginIcuCachePinning() {
    // Pin ICU data in memory from this point that would normally be held by soft references.
    // Without this, any references created immediately below or during class preloading
    // would be collected when the Zygote GC runs in gcAndFinalize().
    Log.i(TAG, "Installing ICU cache reference pinning...");
    CacheValue.setStrength(CacheValue.Strength.STRONG);
    Log.i(TAG, "Preloading ICU data...");
    // Explicitly exercise code to cache data apps are likely to need.
    ULocale[] localesToPin = { ULocale.ROOT, ULocale.US, ULocale.getDefault() };
    for (ULocale uLocale : localesToPin) {
        new DecimalFormatSymbols(uLocale);
    }
}
Also used : ULocale(android.icu.util.ULocale) DecimalFormatSymbols(android.icu.text.DecimalFormatSymbols)

Aggregations

ULocale (android.icu.util.ULocale)25 Locale (java.util.Locale)10 Paint (android.graphics.Paint)5 BreakIterator (android.icu.text.BreakIterator)5 DecimalFormatSymbols (android.icu.text.DecimalFormatSymbols)5 VisibleForTesting (com.android.internal.annotations.VisibleForTesting)5 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 Segment (javax.swing.text.Segment)5