Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 063b2e8d authored by Tadashi G. Takaoka's avatar Tadashi G. Takaoka Committed by Android (Google) Code Review
Browse files

Merge "Make LocaleUtils.constructLocaleFromString as @Nonnull"

parents 032bac3e ebe5b42f
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -104,7 +104,8 @@ public final class LocaleUtils {
     * @param testedLocale the locale to test.
     * @return a constant that measures how well the tested locale matches the reference locale.
     */
    public static int getMatchLevel(final String referenceLocale, final String testedLocale) {
    public static int getMatchLevel(@Nullable final String referenceLocale,
            @Nullable final String testedLocale) {
        if (StringUtils.isEmpty(referenceLocale)) {
            return StringUtils.isEmpty(testedLocale) ? LOCALE_FULL_MATCH : LOCALE_ANY_MATCH;
        }
@@ -167,11 +168,8 @@ public final class LocaleUtils {
     * @param localeString a string specification of a locale, in a format of "ll_cc_variant" where
     * "ll" is a language code, "cc" is a country code.
     */
    @Nullable
    public static Locale constructLocaleFromString(@Nullable final String localeString) {
        if (localeString == null) {
            return null;
        }
    @Nonnull
    public static Locale constructLocaleFromString(@Nonnull final String localeString) {
        synchronized (sLocaleCache) {
            if (sLocaleCache.containsKey(localeString)) {
                return sLocaleCache.get(localeString);
+1 −5
Original line number Diff line number Diff line
@@ -118,11 +118,7 @@ public final class SuggestionSpanUtils {
            if (TextUtils.isEmpty(localeString)) {
                continue;
            }
            final Locale locale = LocaleUtils.constructLocaleFromString(localeString);
            if (locale == null) {
                continue;
            }
            return locale;
            return LocaleUtils.constructLocaleFromString(localeString);
        }
        return null;
    }
+15 −4
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;

import com.android.inputmethod.latin.R;
@@ -33,6 +34,8 @@ import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import javax.annotation.Nonnull;

/**
 * Service that handles background tasks for the dictionary provider.
 *
@@ -51,6 +54,8 @@ import java.util.concurrent.TimeUnit;
 *     to access, and mark the current state as such.
 */
public final class DictionaryService extends Service {
    private static final String TAG = DictionaryService.class.getSimpleName();

    /**
     * The package name, to use in the intent actions.
     */
@@ -156,9 +161,14 @@ public final class DictionaryService extends Service {
            final int startId) {
        final DictionaryService self = this;
        if (SHOW_DOWNLOAD_TOAST_INTENT_ACTION.equals(intent.getAction())) {
            final String localeString = intent.getStringExtra(LOCALE_INTENT_ARGUMENT);
            if (localeString == null) {
                Log.e(TAG, "Received " + intent.getAction() + " without locale; skipped");
            } else {
                // This is a UI action, it can't be run in another thread
            showStartDownloadingToast(this, LocaleUtils.constructLocaleFromString(
                    intent.getStringExtra(LOCALE_INTENT_ARGUMENT)));
                showStartDownloadingToast(
                        this, LocaleUtils.constructLocaleFromString(localeString));
            }
        } else {
            // If it's a command that does not require UI, arrange for the work to be done on a
            // separate thread, so that we can return right away. The executor will spawn a thread
@@ -245,7 +255,8 @@ public final class DictionaryService extends Service {
    /**
     * Shows a toast informing the user that an automatic dictionary download is starting.
     */
    private static void showStartDownloadingToast(final Context context, final Locale locale) {
    private static void showStartDownloadingToast(final Context context,
            @Nonnull final Locale locale) {
        final String toastText = String.format(
                context.getString(R.string.toast_downloading_suggestions),
                locale.getDisplayName());
+4 −4
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ import com.android.inputmethod.annotations.ExternallyReferenced;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.common.LocaleUtils;

import java.util.Locale;
import javax.annotation.Nullable;

/**
 * This implements the dialog for asking the user whether it's okay to download dictionaries over
@@ -54,11 +54,11 @@ public final class DownloadOverMeteredDialog extends Activity {
        setTexts(localeString, size);
    }

    private void setTexts(final String localeString, final long size) {
    private void setTexts(@Nullable final String localeString, final long size) {
        final String promptFormat = getString(R.string.should_download_over_metered_prompt);
        final String allowButtonFormat = getString(R.string.download_over_metered);
        final Locale locale = LocaleUtils.constructLocaleFromString(localeString);
        final String language = (null == locale ? "" : locale.getDisplayLanguage());
        final String language = (null == localeString) ? ""
                : LocaleUtils.constructLocaleFromString(localeString).getDisplayLanguage();
        final TextView prompt = (TextView)findViewById(R.id.download_over_metered_prompt);
        prompt.setText(Html.fromHtml(String.format(promptFormat, language)));
        final Button allowButton = (Button)findViewById(R.id.allow_button);
+2 −3
Original line number Diff line number Diff line
@@ -57,7 +57,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.TreeSet;

@@ -880,8 +879,8 @@ public final class UpdateHandler {
        // None of those are expected to happen, but just in case...
        if (null == notificationIntent || null == notificationManager) return;

        final Locale locale = LocaleUtils.constructLocaleFromString(localeString);
        final String language = (null == locale ? "" : locale.getDisplayLanguage());
        final String language = (null == localeString) ? ""
                : LocaleUtils.constructLocaleFromString(localeString).getDisplayLanguage();
        final String titleFormat = context.getString(R.string.dict_available_notification_title);
        final String notificationTitle = String.format(titleFormat, language);
        final Notification.Builder builder = new Notification.Builder(context)
Loading