Implement the "add word" screen according to new spec

This is only the interface. It doesn't do anything yet, so as to
avoid a too large change.

Bug: 6026080
Change-Id: I0c7f0c09f71e01b18fcb3566a3c6c4b0f0b2a0fc
This commit is contained in:
Jean Chalard
2012-05-08 16:35:53 +09:00
parent b9f837dd1d
commit be07e49a92
5 changed files with 155 additions and 5 deletions

View File

@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/user_dict_settings_add_dialog_top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="@string/user_dict_settings_add_screen_title"
style="?android:attr/listSeparatorTextViewStyle" />
<EditText android:id="@+id/user_dictionary_add_word_text"
android:maxLength="@integer/maximum_user_dictionary_word_length"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_gravity="fill_horizontal|center_vertical"
android:layout_marginLeft="8dip"
android:layout_marginBottom="8dip"
android:layout_marginTop="8dip"
android:inputType="textNoSuggestions"
android:imeOptions="flagNoFullscreen">
<requestFocus />
</EditText>
<GridLayout android:id="@+id/user_dictionary_add_word_grid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dip"
android:layout_marginRight="8dip"
android:columnCount="2">
<TextView android:id="@+id/user_dictionary_add_shortcut_label"
style="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:text="@string/user_dict_settings_add_shortcut_option_name" />
<EditText android:id="@+id/user_dictionary_settings_add_dialog_shortcut"
android:maxLength="@integer/maximum_user_dictionary_word_length"
android:layout_width="wrap_content"
android:layout_gravity="fill_horizontal|center_vertical"
android:layout_marginLeft="8dip"
android:layout_marginBottom="8dip"
android:layout_marginTop="8dip"
android:inputType="textNoSuggestions"
android:imeOptions="flagNoFullscreen" />
<TextView android:id="@+id/user_dictionary_add_locale_label"
style="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:text="@string/user_dict_settings_add_locale_option_name" />
<Spinner android:id="@+id/user_dictionary_settings_add_dialog_locale"
android:layout_marginLeft="8dip"
android:layout_marginBottom="8dip"
android:layout_marginTop="8dip"
android:layout_width="wrap_content"
android:layout_gravity="fill_horizontal|center_vertical" />
</GridLayout>
</LinearLayout>

View File

@@ -2664,6 +2664,8 @@
<string name="user_dict_settings_add_menu_title">Add</string>
<!-- User dictionary settings. The title of the dialog to add a new word to the user dictionary. [CHAR LIMIT=25] -->
<string name="user_dict_settings_add_dialog_title">Add to dictionary</string>
<!-- User dictionary settings. The title of the screen to add/edit a new word to the user dictionary; it describes the phrase that will be added to the user dictionary. [CHAR LIMIT=25] -->
<string name="user_dict_settings_add_screen_title">Phrase</string>
<!-- User dictionary settings. Text on the dialog button to pop more options for adding a word. [CHAR LIMIT=16] -->
<string name="user_dict_settings_add_dialog_more_options">More options</string>
<!-- User dictionary settings. Text on the dialog button mask advanced options. [CHAR LIMIT=15] -->

View File

@@ -183,13 +183,17 @@ public class UserDictionarySettings extends ListFragment {
* @param editingWord the word to edit, or null if it's an add.
*/
private void showAddOrEditDialog(final String editingWord) {
final Intent intent = new Intent(null == editingWord
final Bundle args = new Bundle();
args.putString(UserDictionaryAddWordActivity.EXTRA_MODE, null == editingWord
? UserDictionaryAddWordActivity.MODE_INSERT_ACTION
: UserDictionaryAddWordActivity.MODE_EDIT_ACTION);
// The following are fine if they are null
intent.putExtra(UserDictionaryAddWordActivity.EXTRA_WORD, editingWord);
intent.putExtra(UserDictionaryAddWordActivity.EXTRA_LOCALE, mLocale);
startActivity(intent);
args.putString(UserDictionaryAddWordActivity.EXTRA_WORD, editingWord);
args.putString(UserDictionaryAddWordActivity.EXTRA_LOCALE, mLocale);
android.preference.PreferenceActivity pa =
(android.preference.PreferenceActivity)getActivity();
pa.startPreferencePanel(
com.android.settings.inputmethod.UserDictionaryAddWordFragment.class.getName(),
args, R.string.details_title, null, null, 0);
}
private String getWord(int position) {

View File

@@ -41,6 +41,7 @@ import android.widget.Spinner;
public class UserDictionaryAddWordActivity extends Activity
implements AdapterView.OnItemSelectedListener {
public static final String EXTRA_MODE = "mode";
public static final String EXTRA_WORD = "word";
public static final String EXTRA_LOCALE = "locale";
private static final int FREQUENCY_FOR_USER_DICTIONARY_ADDS = 250;

View File

@@ -0,0 +1,69 @@
/*
* 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 android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import com.android.settings.R;
/**
* Fragment to add a word/shortcut to the user dictionary.
*
* As opposed to the UserDictionaryActivity, this is only invoked within Settings
* from the UserDictionarySettings.
*/
public class UserDictionaryAddWordFragment extends Fragment {
private static final int OPTIONS_MENU_DELETE = Menu.FIRST;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setHasOptionsMenu(true);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
return inflater.inflate(R.layout.user_dictionary_add_word_fullscreen, null);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
MenuItem actionItem = menu.add(0, OPTIONS_MENU_DELETE, 0, R.string.delete)
.setIcon(android.R.drawable.ic_menu_delete);
actionItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM |
MenuItem.SHOW_AS_ACTION_WITH_TEXT);
}
@Override
public void onResume() {
super.onResume();
// We are being shown: display the word
}
@Override
public void onPause() {
super.onPause();
// We are being hidden: commit changes to the user dictionary
}
}