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

Commit b3ebc306 authored by Benjamin Poiesz's avatar Benjamin Poiesz Committed by Android Git Automerger
Browse files

am fc9f07dd: Merge "Adding LocalePicker support for the zz_ZZ pseudolocale" into jb-mr2-dev

* commit 'fc9f07dd':
  Adding LocalePicker support for the zz_ZZ pseudolocale
parents 63582a79 fc9f07dd
Loading
Loading
Loading
Loading
+40 −5
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import android.widget.TextView;
import java.text.Collator;
import java.util.Arrays;
import java.util.Locale;
import java.util.ArrayList;

public class LocalePicker extends ListFragment {
    private static final String TAG = "LocalePicker";
@@ -48,6 +49,10 @@ public class LocalePicker extends ListFragment {
        public void onLocaleSelected(Locale locale);
    }

    protected boolean isInDeveloperMode() {
        return false;
    }

    LocaleSelectionListener mListener;  // default to null

    public static class LocaleInfo implements Comparable<LocaleInfo> {
@@ -85,13 +90,39 @@ public class LocalePicker extends ListFragment {
     * {@link LocaleInfo#label}.
     */
    public static ArrayAdapter<LocaleInfo> constructAdapter(Context context) {
        return constructAdapter(context, R.layout.locale_picker_item, R.id.locale);
        return constructAdapter(context, false /* disable pesudolocales */);
    }

    public static ArrayAdapter<LocaleInfo> constructAdapter(Context context,
                                                            final boolean isInDeveloperMode) {
        return constructAdapter(context, R.layout.locale_picker_item, R.id.locale,
                isInDeveloperMode);
    }

    public static ArrayAdapter<LocaleInfo> constructAdapter(Context context,
            final int layoutId, final int fieldId) {
        return constructAdapter(context, layoutId, fieldId, false /* disable pseudolocales */);
    }

    public static ArrayAdapter<LocaleInfo> constructAdapter(Context context,
            final int layoutId, final int fieldId, final boolean isInDeveloperMode) {
        final Resources resources = context.getResources();
        final String[] locales = Resources.getSystem().getAssets().getLocales();

        ArrayList<String> localeList = new ArrayList<String>(Arrays.asList(
                Resources.getSystem().getAssets().getLocales()));
        if (isInDeveloperMode) {
            if (!localeList.contains("zz_ZZ")) {
                localeList.add("zz_ZZ");
            }
        /** - TODO: Enable when zz_ZY Pseudolocale is complete
         *  if (!localeList.contains("zz_ZY")) {
         *      localeList.add("zz_ZY");
         *	}
         */
        }
        String[] locales = new String[localeList.size()];
        locales = localeList.toArray(locales);

        final String[] specialLocaleCodes = resources.getStringArray(R.array.special_locale_codes);
        final String[] specialLocaleNames = resources.getStringArray(R.array.special_locale_names);
        Arrays.sort(locales);
@@ -118,7 +149,8 @@ public class LocalePicker extends ListFragment {
                    //    insert ours with full name
                    //  diff lang -> insert ours with lang-only name
                    if (preprocess[finalSize-1].locale.getLanguage().equals(
                            language)) {
                            language) &&
                            !preprocess[finalSize-1].locale.getLanguage().equals("zz")) {
                        if (DEBUG) {
                            Log.v(TAG, "backing up and fixing "+
                                    preprocess[finalSize-1].label+" to "+
@@ -139,7 +171,9 @@ public class LocalePicker extends ListFragment {
                    } else {
                        String displayName;
                        if (s.equals("zz_ZZ")) {
                            displayName = "Pseudo...";
                            displayName = "[Developer] Accented English";
                        } else if (s.equals("zz_ZY")) {
                            displayName = "[Developer] Fake Bi-Directional";
                        } else {
                            displayName = toTitleCase(l.getDisplayLanguage(l));
                        }
@@ -206,7 +240,8 @@ public class LocalePicker extends ListFragment {
    @Override
    public void onActivityCreated(final Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        final ArrayAdapter<LocaleInfo> adapter = constructAdapter(getActivity());
        final ArrayAdapter<LocaleInfo> adapter = constructAdapter(getActivity(),
                isInDeveloperMode());
        setListAdapter(adapter);
    }