Merge "Show locale in region list even if suggested in language list" into nyc-dev
This commit is contained in:
@@ -180,14 +180,16 @@ public class LocaleHelper {
|
|||||||
*/
|
*/
|
||||||
public static final class LocaleInfoComparator implements Comparator<LocaleStore.LocaleInfo> {
|
public static final class LocaleInfoComparator implements Comparator<LocaleStore.LocaleInfo> {
|
||||||
private final Collator mCollator;
|
private final Collator mCollator;
|
||||||
|
private final boolean mCountryMode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param sortLocale the locale to be used for sorting.
|
* @param sortLocale the locale to be used for sorting.
|
||||||
*/
|
*/
|
||||||
public LocaleInfoComparator(Locale sortLocale) {
|
public LocaleInfoComparator(Locale sortLocale, boolean countryMode) {
|
||||||
mCollator = Collator.getInstance(sortLocale);
|
mCollator = Collator.getInstance(sortLocale);
|
||||||
|
mCountryMode = countryMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -202,9 +204,9 @@ public class LocaleHelper {
|
|||||||
public int compare(LocaleStore.LocaleInfo lhs, LocaleStore.LocaleInfo rhs) {
|
public int compare(LocaleStore.LocaleInfo lhs, LocaleStore.LocaleInfo rhs) {
|
||||||
// We don't care about the various suggestion types, just "suggested" (!= 0)
|
// We don't care about the various suggestion types, just "suggested" (!= 0)
|
||||||
// and "all others" (== 0)
|
// and "all others" (== 0)
|
||||||
if (lhs.isSuggested() == rhs.isSuggested()) {
|
if (mCountryMode || (lhs.isSuggested() == rhs.isSuggested())) {
|
||||||
// They are in the same "bucket" (suggested / others), so we compare the text
|
// They are in the same "bucket" (suggested / others), so we compare the text
|
||||||
return mCollator.compare(lhs.getLabel(), rhs.getLabel());
|
return mCollator.compare(lhs.getLabel(mCountryMode), rhs.getLabel(mCountryMode));
|
||||||
} else {
|
} else {
|
||||||
// One locale is suggested and one is not, so we put them in different "buckets"
|
// One locale is suggested and one is not, so we put them in different "buckets"
|
||||||
return lhs.isSuggested() ? -1 : 1;
|
return lhs.isSuggested() ? -1 : 1;
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ public class LocalePickerWithRegion extends ListFragment implements SearchView.O
|
|||||||
private Set<LocaleStore.LocaleInfo> mLocaleList;
|
private Set<LocaleStore.LocaleInfo> mLocaleList;
|
||||||
private LocaleStore.LocaleInfo mParentLocale;
|
private LocaleStore.LocaleInfo mParentLocale;
|
||||||
private boolean mTranslatedOnly = false;
|
private boolean mTranslatedOnly = false;
|
||||||
private boolean mCountryMode = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Other classes can register to be notified when a locale was selected.
|
* Other classes can register to be notified when a locale was selected.
|
||||||
@@ -70,15 +69,14 @@ public class LocalePickerWithRegion extends ListFragment implements SearchView.O
|
|||||||
boolean translatedOnly) {
|
boolean translatedOnly) {
|
||||||
LocalePickerWithRegion localePicker = new LocalePickerWithRegion();
|
LocalePickerWithRegion localePicker = new LocalePickerWithRegion();
|
||||||
boolean shouldShowTheList = localePicker.setListener(context, listener, parent,
|
boolean shouldShowTheList = localePicker.setListener(context, listener, parent,
|
||||||
true /* country mode */, translatedOnly);
|
translatedOnly);
|
||||||
return shouldShowTheList ? localePicker : null;
|
return shouldShowTheList ? localePicker : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LocalePickerWithRegion createLanguagePicker(Context context,
|
public static LocalePickerWithRegion createLanguagePicker(Context context,
|
||||||
LocaleSelectedListener listener, boolean translatedOnly) {
|
LocaleSelectedListener listener, boolean translatedOnly) {
|
||||||
LocalePickerWithRegion localePicker = new LocalePickerWithRegion();
|
LocalePickerWithRegion localePicker = new LocalePickerWithRegion();
|
||||||
localePicker.setListener(context, listener, null,
|
localePicker.setListener(context, listener, /* parent */ null, translatedOnly);
|
||||||
false /* language mode */, translatedOnly);
|
|
||||||
return localePicker;
|
return localePicker;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,14 +94,7 @@ public class LocalePickerWithRegion extends ListFragment implements SearchView.O
|
|||||||
* "pretending" it was selected, and return false.</p>
|
* "pretending" it was selected, and return false.</p>
|
||||||
*/
|
*/
|
||||||
private boolean setListener(Context context, LocaleSelectedListener listener,
|
private boolean setListener(Context context, LocaleSelectedListener listener,
|
||||||
LocaleStore.LocaleInfo parent, boolean countryMode, boolean translatedOnly) {
|
LocaleStore.LocaleInfo parent, boolean translatedOnly) {
|
||||||
if (countryMode && (parent == null || parent.getLocale() == null)) {
|
|
||||||
// The list of countries is determined as all the countries where the parent language
|
|
||||||
// is used.
|
|
||||||
throw new IllegalArgumentException("The country selection list needs a parent.");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.mCountryMode = countryMode;
|
|
||||||
this.mParentLocale = parent;
|
this.mParentLocale = parent;
|
||||||
this.mListener = listener;
|
this.mListener = listener;
|
||||||
this.mTranslatedOnly = translatedOnly;
|
this.mTranslatedOnly = translatedOnly;
|
||||||
@@ -116,7 +107,7 @@ public class LocalePickerWithRegion extends ListFragment implements SearchView.O
|
|||||||
Collections.addAll(langTagsToIgnore, langTags);
|
Collections.addAll(langTagsToIgnore, langTags);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (countryMode) {
|
if (parent != null) {
|
||||||
mLocaleList = LocaleStore.getLevelLocales(context,
|
mLocaleList = LocaleStore.getLevelLocales(context,
|
||||||
langTagsToIgnore, parent, translatedOnly);
|
langTagsToIgnore, parent, translatedOnly);
|
||||||
if (mLocaleList.size() <= 1) {
|
if (mLocaleList.size() <= 1) {
|
||||||
@@ -138,13 +129,11 @@ public class LocalePickerWithRegion extends ListFragment implements SearchView.O
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
|
|
||||||
final Locale sortingLocale = (mCountryMode && mParentLocale != null)
|
final boolean countryMode = mParentLocale != null;
|
||||||
? mParentLocale.getLocale()
|
final Locale sortingLocale = countryMode ? mParentLocale.getLocale() : Locale.getDefault();
|
||||||
: Locale.getDefault();
|
mAdapter = new SuggestedLocaleAdapter(mLocaleList, countryMode);
|
||||||
|
|
||||||
mAdapter = new SuggestedLocaleAdapter(mLocaleList, mCountryMode);
|
|
||||||
final LocaleHelper.LocaleInfoComparator comp =
|
final LocaleHelper.LocaleInfoComparator comp =
|
||||||
new LocaleHelper.LocaleInfoComparator(sortingLocale);
|
new LocaleHelper.LocaleInfoComparator(sortingLocale, countryMode);
|
||||||
mAdapter.sort(comp);
|
mAdapter.sort(comp);
|
||||||
setListAdapter(mAdapter);
|
setListAdapter(mAdapter);
|
||||||
}
|
}
|
||||||
@@ -164,12 +153,8 @@ public class LocalePickerWithRegion extends ListFragment implements SearchView.O
|
|||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
if (mCountryMode) {
|
if (mParentLocale != null) {
|
||||||
if (mParentLocale == null) {
|
this.getActivity().setTitle(mParentLocale.getFullNameNative());
|
||||||
this.getActivity().setTitle(R.string.country_selection_title);
|
|
||||||
} else {
|
|
||||||
this.getActivity().setTitle(mParentLocale.getFullNameNative());
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
this.getActivity().setTitle(R.string.language_selection_title);
|
this.getActivity().setTitle(R.string.language_selection_title);
|
||||||
}
|
}
|
||||||
@@ -182,7 +167,7 @@ public class LocalePickerWithRegion extends ListFragment implements SearchView.O
|
|||||||
final LocaleStore.LocaleInfo locale =
|
final LocaleStore.LocaleInfo locale =
|
||||||
(LocaleStore.LocaleInfo) getListAdapter().getItem(position);
|
(LocaleStore.LocaleInfo) getListAdapter().getItem(position);
|
||||||
|
|
||||||
if (mCountryMode || locale.getParent() != null) {
|
if (locale.getParent() != null) {
|
||||||
if (mListener != null) {
|
if (mListener != null) {
|
||||||
mListener.onLocaleSelected(locale);
|
mListener.onLocaleSelected(locale);
|
||||||
}
|
}
|
||||||
@@ -205,7 +190,7 @@ public class LocalePickerWithRegion extends ListFragment implements SearchView.O
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
if (!mCountryMode) {
|
if (mParentLocale == null) {
|
||||||
inflater.inflate(R.menu.language_selection_list, menu);
|
inflater.inflate(R.menu.language_selection_list, menu);
|
||||||
|
|
||||||
MenuItem mSearchMenuItem = menu.findItem(R.id.locale_search_menu);
|
MenuItem mSearchMenuItem = menu.findItem(R.id.locale_search_menu);
|
||||||
|
|||||||
@@ -145,11 +145,11 @@ public class LocaleStore {
|
|||||||
return mLangScriptKey;
|
return mLangScriptKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getLabel() {
|
String getLabel(boolean countryMode) {
|
||||||
if (getParent() == null || this.isSuggestionOfType(SUGGESTION_TYPE_SIM)) {
|
if (countryMode) {
|
||||||
return getFullNameNative();
|
|
||||||
} else {
|
|
||||||
return getFullCountryNameNative();
|
return getFullCountryNameNative();
|
||||||
|
} else {
|
||||||
|
return getFullNameNative();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,9 +311,7 @@ public class LocaleStore {
|
|||||||
if (level == 2) {
|
if (level == 2) {
|
||||||
if (parent != null) { // region selection
|
if (parent != null) { // region selection
|
||||||
if (parentId.equals(li.getParent().toLanguageTag())) {
|
if (parentId.equals(li.getParent().toLanguageTag())) {
|
||||||
if (!li.isSuggestionOfType(LocaleInfo.SUGGESTION_TYPE_SIM)) {
|
result.add(li);
|
||||||
result.add(li);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else { // language selection
|
} else { // language selection
|
||||||
if (li.isSuggestionOfType(LocaleInfo.SUGGESTION_TYPE_SIM)) {
|
if (li.isSuggestionOfType(LocaleInfo.SUGGESTION_TYPE_SIM)) {
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ public class SuggestedLocaleAdapter extends BaseAdapter implements Filterable {
|
|||||||
|
|
||||||
TextView text = (TextView) convertView.findViewById(R.id.locale);
|
TextView text = (TextView) convertView.findViewById(R.id.locale);
|
||||||
LocaleStore.LocaleInfo item = (LocaleStore.LocaleInfo) getItem(position);
|
LocaleStore.LocaleInfo item = (LocaleStore.LocaleInfo) getItem(position);
|
||||||
text.setText(item.getLabel());
|
text.setText(item.getLabel(mCountryMode));
|
||||||
text.setTextLocale(item.getLocale());
|
text.setTextLocale(item.getLocale());
|
||||||
if (mCountryMode) {
|
if (mCountryMode) {
|
||||||
int layoutDir = TextUtils.getLayoutDirectionFromLocale(item.getParent());
|
int layoutDir = TextUtils.getLayoutDirectionFromLocale(item.getParent());
|
||||||
@@ -171,6 +171,9 @@ public class SuggestedLocaleAdapter extends BaseAdapter implements Filterable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean showHeaders() {
|
private boolean showHeaders() {
|
||||||
|
if (mCountryMode) { // never show suggestions in country mode
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return mSuggestionCount != 0 && mSuggestionCount != mLocaleOptions.size();
|
return mSuggestionCount != 0 && mSuggestionCount != mLocaleOptions.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user