Add showing suggestion only on portrait mode and fixing the state of suggestion strip

Change-Id: I7babd1400a3516c87506a3ea4bd46ddaf89e19b4
main
satok 2010-11-13 19:09:30 +09:00
parent 71c353aa87
commit 7599cfea4a
6 changed files with 107 additions and 31 deletions

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
**
** Copyright 2010, 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.
*/
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- Default value of the visibility of the suggestion strip -->
<string name="prefs_suggestion_visibility_default_value" translatable="false">1</string>
</resources>

View File

@ -32,4 +32,14 @@
<string name="settings_key_mode_always_show" translatable="false">1</string>
<!-- Always hide the settings key -->
<string name="settings_key_mode_always_hide" translatable="false">2</string>
<!-- Always show the suggestion strip -->
<string name="prefs_suggestion_visibility_show_value" translatable="false">0</string>
<!-- Show the suggestion strip only on portrait mode -->
<string name="prefs_suggestion_visibility_show_only_portrait_value" translatable="false">1</string>
<!-- Always hide the suggestion strip -->
<string name="prefs_suggestion_visibility_hide_value" translatable="false">2</string>
<!-- Default value of the visibility of the suggestion strip -->
<string name="prefs_suggestion_visibility_default_value" translatable="false">0</string>
</resources>

View File

@ -82,10 +82,24 @@
<string name="quick_fixes_summary">Corrects commonly typed mistakes</string>
<!-- Option to enable showing suggestions -->
<string name="show_suggestions">Show suggestions</string>
<string name="prefs_show_suggestions">Show suggestions</string>
<!-- Description for show suggestions -->
<string name="show_suggestions_summary">Display suggested words while typing</string>
<string name="prefs_show_suggestions_summary">Display suggested words while typing</string>
<!-- Option to show/hide the suggestion strip -->
<string-array name="prefs_suggestion_visibility_values" translatable="false">
<item>@string/prefs_suggestion_visibility_show_value</item>
<item>@string/prefs_suggestion_visibility_show_only_portrait_value</item>
<item>@string/prefs_suggestion_visibility_hide_value</item>
</string-array>
<string name="prefs_suggestion_visibility_show_name">Always show</string>
<string name="prefs_suggestion_visibility_show_only_portrait_name">Show on portrait mode</string>
<string name="prefs_suggestion_visibility_hide_name">Always hide</string>
<string-array name="prefs_suggestion_visibilities" translatable="false">
<item>@string/prefs_suggestion_visibility_show_name</item>
<item>@string/prefs_suggestion_visibility_show_only_portrait_name</item>
<item>@string/prefs_suggestion_visibility_hide_name</item>
</string-array>
<!-- Option to show/hide the settings key -->
<string name="prefs_settings_key">Show settings key</string>
<!-- Array of the settings key mode values -->

View File

@ -90,12 +90,14 @@
android:defaultValue="true"
/>
<CheckBoxPreference
android:key="show_suggestions"
android:title="@string/show_suggestions"
android:summary="@string/show_suggestions_summary"
<ListPreference
android:key="show_suggestions_setting"
android:summary="@string/prefs_show_suggestions_summary"
android:title="@string/prefs_show_suggestions"
android:persistent="true"
android:defaultValue="true"
android:entryValues="@array/prefs_suggestion_visibility_values"
android:entries="@array/prefs_suggestion_visibilities"
android:defaultValue="@string/prefs_suggestion_visibility_default_value"
/>
<ListPreference

View File

@ -95,7 +95,7 @@ public class LatinIME extends InputMethodService
private static final String PREF_POPUP_ON = "popup_on";
private static final String PREF_AUTO_CAP = "auto_cap";
private static final String PREF_QUICK_FIXES = "quick_fixes";
private static final String PREF_SHOW_SUGGESTIONS = "show_suggestions";
private static final String PREF_SHOW_SUGGESTIONS_SETTING = "show_suggestions_setting";
private static final String PREF_AUTO_COMPLETION_THRESHOLD = "auto_completion_threshold";
private static final String PREF_BIGRAM_SUGGESTIONS = "bigram_suggestion";
private static final String PREF_VOICE_MODE = "voice_mode";
@ -155,6 +155,20 @@ public class LatinIME extends InputMethodService
private static final int POS_METHOD = 0;
private static final int POS_SETTINGS = 1;
private int mSuggestionVisibility;
private static final int SUGGESTION_VISIBILILTY_SHOW_VALUE
= R.string.prefs_suggestion_visibility_show_value;
private static final int SUGGESTION_VISIBILILTY_SHOW_ONLY_PORTRAIT_VALUE
= R.string.prefs_suggestion_visibility_show_only_portrait_value;
private static final int SUGGESTION_VISIBILILTY_HIDE_VALUE
= R.string.prefs_suggestion_visibility_hide_value;
private static final int[] SUGGESTION_VISIBILITY_VALUE_ARRAY = new int[] {
SUGGESTION_VISIBILILTY_SHOW_VALUE,
SUGGESTION_VISIBILILTY_SHOW_ONLY_PORTRAIT_VALUE,
SUGGESTION_VISIBILILTY_HIDE_VALUE
};
private LinearLayout mCandidateViewContainer;
private CandidateView mCandidateView;
private Suggest mSuggest;
@ -206,7 +220,6 @@ public class LatinIME extends InputMethodService
private boolean mHasUsedVoiceInput;
private boolean mHasUsedVoiceInputUnsupportedLocale;
private boolean mLocaleSupportedForVoiceInput;
private boolean mShowSuggestions;
private boolean mIsShowingHint;
private int mCorrectionMode;
private boolean mVoiceButtonEnabled;
@ -674,7 +687,7 @@ public class LatinIME extends InputMethodService
inputView.setPreviewEnabled(mPopupOn);
inputView.setProximityCorrectionEnabled(true);
mPredictionOn = mPredictionOn && (mCorrectionMode > 0 || mShowSuggestions);
mPredictionOn = mPredictionOn && (mCorrectionMode > 0 || isSuggestionShown());
// If we just entered a text field, maybe it has some old text that requires correction
checkReCorrectionOnStart();
checkTutorial(attribute.privateImeOptions);
@ -819,9 +832,8 @@ public class LatinIME extends InputMethodService
abortCorrection(false);
// Show the punctuation suggestions list if the current one is not
// and if not showing "Touch again to save".
if (mCandidateView != null
&& !mSuggestPuncList.equals(mCandidateView.getSuggestions())
&& !mCandidateView.isShowingAddToDictionaryHint()) {
if (mCandidateView != null && !isShowingPunctuationList()
&& !mCandidateView.isShowingAddToDictionaryHint()) {
setPunctuationSuggestions();
}
}
@ -1574,9 +1586,21 @@ public class LatinIME extends InputMethodService
return mPredictionOn;
}
private boolean isShowingPunctuationList() {
return mSuggestPuncList.equals(mCandidateView.getSuggestions());
}
private boolean isSuggestionShown() {
return (mSuggestionVisibility == SUGGESTION_VISIBILILTY_SHOW_VALUE)
|| (mSuggestionVisibility == SUGGESTION_VISIBILILTY_SHOW_ONLY_PORTRAIT_VALUE
&& mOrientation == Configuration.ORIENTATION_PORTRAIT);
}
private boolean isCandidateStripVisible() {
return (isPredictionOn() && mShowSuggestions) || mCompletionOn
|| mCandidateView.isShowingAddToDictionaryHint() || TextEntryState.isCorrecting();
boolean forceVisible = mCandidateView.isShowingAddToDictionaryHint()
|| TextEntryState.isCorrecting();
return forceVisible || (isSuggestionShown()
&& (isPredictionOn() || mCompletionOn || isShowingPunctuationList()));
}
public void onCancelVoice() {
@ -2470,6 +2494,18 @@ public class LatinIME extends InputMethodService
mSuggest.setAutoTextEnabled(!different && mQuickFixes);
}
private void updateSuggestionVisibility(SharedPreferences prefs) {
final String suggestionVisiblityStr = prefs.getString(
PREF_SHOW_SUGGESTIONS_SETTING, mResources.getString(
R.string.prefs_suggestion_visibility_default_value));
for (int visibility : SUGGESTION_VISIBILITY_VALUE_ARRAY) {
if (suggestionVisiblityStr.equals(mResources.getString(visibility))) {
mSuggestionVisibility = visibility;
break;
}
}
}
protected void launchSettings() {
launchSettings(LatinIMESettings.class);
}
@ -2515,8 +2551,7 @@ public class LatinIME extends InputMethodService
mLocaleSupportedForVoiceInput = voiceInputSupportedLocales.contains(mInputLocale);
mShowSuggestions = sp.getBoolean(PREF_SHOW_SUGGESTIONS, true);
mAutoCorrectEnabled = mShowSuggestions && isAutoCorrectEnabled(sp);
mAutoCorrectEnabled = isAutoCorrectEnabled(sp);
mBigramSuggestionEnabled = mAutoCorrectEnabled && isBigramSuggestionEnabled(sp);
loadAndSetAutoCompletionThreshold(sp);
@ -2529,6 +2564,7 @@ public class LatinIME extends InputMethodService
}
updateCorrectionMode();
updateAutoTextEnabled(mResources.getConfiguration().locale);
updateSuggestionVisibility(sp);
mLanguageSwitcher.loadLocales(sp);
}

View File

@ -44,7 +44,6 @@ public class LatinIMESettings extends PreferenceActivity
private static final String QUICK_FIXES_KEY = "quick_fixes";
private static final String PREDICTION_SETTINGS_KEY = "prediction_settings";
private static final String VOICE_SETTINGS_KEY = "voice_mode";
private static final String PREF_SHOW_SUGGESTIONS = "show_suggestions";
private static final String PREF_AUTO_COMPLETION_THRESHOLD = "auto_completion_threshold";
private static final String PREF_BIGRAM_SUGGESTIONS = "bigram_suggestion";
/* package */ static final String PREF_SETTINGS_KEY = "settings_key";
@ -58,7 +57,6 @@ public class LatinIMESettings extends PreferenceActivity
private CheckBoxPreference mQuickFixes;
private ListPreference mVoicePreference;
private ListPreference mSettingsKeyPreference;
private CheckBoxPreference mShowSuggestions;
private ListPreference mAutoCompletionThreshold;
private CheckBoxPreference mBigramSuggestion;
private boolean mVoiceOn;
@ -69,16 +67,10 @@ public class LatinIMESettings extends PreferenceActivity
private String mVoiceModeOff;
private void ensureConsistencyOfAutoCompletionSettings() {
if (mShowSuggestions.isChecked()) {
mAutoCompletionThreshold.setEnabled(true);
final String autoCompletionOff = getResources().getString(
R.string.auto_completion_threshold_mode_value_off);
final String currentSetting = mAutoCompletionThreshold.getValue();
mBigramSuggestion.setEnabled(!currentSetting.equals(autoCompletionOff));
} else {
mAutoCompletionThreshold.setEnabled(false);
mBigramSuggestion.setEnabled(false);
}
final String autoCompletionOff = getResources().getString(
R.string.auto_completion_threshold_mode_value_off);
final String currentSetting = mAutoCompletionThreshold.getValue();
mBigramSuggestion.setEnabled(!currentSetting.equals(autoCompletionOff));
}
@Override
protected void onCreate(Bundle icicle) {
@ -94,7 +86,6 @@ public class LatinIMESettings extends PreferenceActivity
mVoiceOn = !(prefs.getString(VOICE_SETTINGS_KEY, mVoiceModeOff).equals(mVoiceModeOff));
mLogger = VoiceInputLogger.getLogger(this);
mShowSuggestions = (CheckBoxPreference) findPreference(PREF_SHOW_SUGGESTIONS);
mAutoCompletionThreshold = (ListPreference) findPreference(PREF_AUTO_COMPLETION_THRESHOLD);
mBigramSuggestion = (CheckBoxPreference) findPreference(PREF_BIGRAM_SUGGESTIONS);
ensureConsistencyOfAutoCompletionSettings();