Implement the "more locales" feature.
Bug: 6026080 Change-Id: I051a734321793e9130dc2cc77d4e7f670d2ce93d
This commit is contained in:
@@ -155,6 +155,10 @@ public class UserDictionaryAddWordContents {
|
|||||||
public String getLocaleString() {
|
public String getLocaleString() {
|
||||||
return mLocaleString;
|
return mLocaleString;
|
||||||
}
|
}
|
||||||
|
// "More languages..." is null ; "All languages" is the empty string.
|
||||||
|
public boolean isMoreLanguages() {
|
||||||
|
return null == mLocaleString;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addLocaleDisplayNameToList(final Context context,
|
private static void addLocaleDisplayNameToList(final Context context,
|
||||||
|
@@ -17,6 +17,7 @@ package com.android.settings.inputmethod;
|
|||||||
|
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.preference.PreferenceActivity;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
@@ -31,6 +32,7 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.inputmethod.UserDictionaryAddWordContents.LocaleRenderer;
|
import com.android.settings.inputmethod.UserDictionaryAddWordContents.LocaleRenderer;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fragment to add a word/shortcut to the user dictionary.
|
* Fragment to add a word/shortcut to the user dictionary.
|
||||||
@@ -39,7 +41,8 @@ import java.util.ArrayList;
|
|||||||
* from the UserDictionarySettings.
|
* from the UserDictionarySettings.
|
||||||
*/
|
*/
|
||||||
public class UserDictionaryAddWordFragment extends Fragment
|
public class UserDictionaryAddWordFragment extends Fragment
|
||||||
implements AdapterView.OnItemSelectedListener {
|
implements AdapterView.OnItemSelectedListener,
|
||||||
|
com.android.internal.app.LocalePicker.LocaleSelectionListener {
|
||||||
|
|
||||||
private static final int OPTIONS_MENU_DELETE = Menu.FIRST;
|
private static final int OPTIONS_MENU_DELETE = Menu.FIRST;
|
||||||
|
|
||||||
@@ -57,6 +60,9 @@ public class UserDictionaryAddWordFragment extends Fragment
|
|||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
|
||||||
mRootView = inflater.inflate(R.layout.user_dictionary_add_word_fullscreen, null);
|
mRootView = inflater.inflate(R.layout.user_dictionary_add_word_fullscreen, null);
|
||||||
mIsDeleting = false;
|
mIsDeleting = false;
|
||||||
|
if (null == mContents) {
|
||||||
|
mContents = new UserDictionaryAddWordContents(mRootView, getArguments());
|
||||||
|
}
|
||||||
return mRootView;
|
return mRootView;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +86,7 @@ public class UserDictionaryAddWordFragment extends Fragment
|
|||||||
if (item.getItemId() == OPTIONS_MENU_DELETE) {
|
if (item.getItemId() == OPTIONS_MENU_DELETE) {
|
||||||
mContents.delete(getActivity());
|
mContents.delete(getActivity());
|
||||||
mIsDeleting = true;
|
mIsDeleting = true;
|
||||||
getFragmentManager().popBackStack();
|
getActivity().onBackPressed();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -90,7 +96,10 @@ public class UserDictionaryAddWordFragment extends Fragment
|
|||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
// We are being shown: display the word
|
// We are being shown: display the word
|
||||||
mContents = new UserDictionaryAddWordContents(mRootView, getArguments());
|
updateSpinner();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateSpinner() {
|
||||||
final ArrayList<LocaleRenderer> localesList = mContents.getLocalesList(getActivity());
|
final ArrayList<LocaleRenderer> localesList = mContents.getLocalesList(getActivity());
|
||||||
|
|
||||||
final Spinner localeSpinner =
|
final Spinner localeSpinner =
|
||||||
@@ -115,7 +124,12 @@ public class UserDictionaryAddWordFragment extends Fragment
|
|||||||
public void onItemSelected(final AdapterView<?> parent, final View view, final int pos,
|
public void onItemSelected(final AdapterView<?> parent, final View view, final int pos,
|
||||||
final long id) {
|
final long id) {
|
||||||
final LocaleRenderer locale = (LocaleRenderer)parent.getItemAtPosition(pos);
|
final LocaleRenderer locale = (LocaleRenderer)parent.getItemAtPosition(pos);
|
||||||
mContents.updateLocale(locale.getLocaleString());
|
if (locale.isMoreLanguages()) {
|
||||||
|
PreferenceActivity preferenceActivity = (PreferenceActivity)getActivity();
|
||||||
|
preferenceActivity.startPreferenceFragment(new UserDictionaryLocalePicker(this), true);
|
||||||
|
} else {
|
||||||
|
mContents.updateLocale(locale.getLocaleString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -124,4 +138,11 @@ public class UserDictionaryAddWordFragment extends Fragment
|
|||||||
final Bundle args = getArguments();
|
final Bundle args = getArguments();
|
||||||
mContents.updateLocale(args.getString(UserDictionaryAddWordContents.EXTRA_LOCALE));
|
mContents.updateLocale(args.getString(UserDictionaryAddWordContents.EXTRA_LOCALE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Called by the locale picker
|
||||||
|
@Override
|
||||||
|
public void onLocaleSelected(final Locale locale) {
|
||||||
|
mContents.updateLocale(locale.toString());
|
||||||
|
getActivity().onBackPressed();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.inputmethod;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
public class UserDictionaryLocalePicker extends com.android.internal.app.LocalePicker {
|
||||||
|
public UserDictionaryLocalePicker(final UserDictionaryAddWordFragment parent) {
|
||||||
|
super();
|
||||||
|
setLocaleSelectionListener(parent);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user