aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
Diffstat (limited to 'java')
-rw-r--r--java/res/layout/suggestions_strip.xml1
-rw-r--r--java/res/xml/keys_comma_period_symbols.xml3
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java3
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java54
-rw-r--r--java/src/com/android/inputmethod/latin/SuggestedWords.java25
-rw-r--r--java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java20
-rw-r--r--java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java11
-rw-r--r--java/src/com/android/inputmethod/latin/settings/SettingsValues.java2
-rw-r--r--java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java13
-rw-r--r--java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java4
-rw-r--r--java/src/com/android/inputmethod/latin/utils/ImportantNoticeUtils.java75
-rw-r--r--java/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtils.java7
12 files changed, 143 insertions, 75 deletions
diff --git a/java/res/layout/suggestions_strip.xml b/java/res/layout/suggestions_strip.xml
index d8a65f6e5..9c83542a6 100644
--- a/java/res/layout/suggestions_strip.xml
+++ b/java/res/layout/suggestions_strip.xml
@@ -42,6 +42,7 @@
android:id="@+id/hint_add_to_dictionary"
android:layout_width="match_parent"
android:layout_height="match_parent"
+ android:textAlignment="viewStart"
style="?attr/suggestionWordStyle" />
</LinearLayout>
</merge>
diff --git a/java/res/xml/keys_comma_period_symbols.xml b/java/res/xml/keys_comma_period_symbols.xml
index cbdbe2ea2..880fe40d9 100644
--- a/java/res/xml/keys_comma_period_symbols.xml
+++ b/java/res/xml/keys_comma_period_symbols.xml
@@ -22,7 +22,8 @@
xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
>
<Key
- latin:keyLabel="," />
+ latin:keyLabel="!text/keylabel_for_comma"
+ latin:moreKeys="!text/more_keys_for_comma" />
<!-- U+2026: "…" HORIZONTAL ELLIPSIS -->
<Key
latin:keyLabel="."
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java
index 9f33fcc0a..4e8eb3ea7 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java
@@ -1512,7 +1512,8 @@ public final class KeyboardTextsSet {
/* 104 */ "\u061F",
/* 105 */ "!fixedColumnOrder!4,:,!,\u061F,\u061B,-,/,\u00AB|\u00BB,\u00BB|\u00AB",
/* 106 */ null,
- /* 107 */ "\u061F",
+ // U+064B: "ً" ARABIC FATHATAN
+ /* 107 */ "\u064B",
/* 108 */ "!text/more_keys_for_arabic_diacritics",
/* 109 */ null,
/* 110 */ "\u064B",
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index e8ea5e39d..8f4b2d67e 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -42,7 +42,6 @@ import android.preference.PreferenceManager;
import android.text.InputType;
import android.text.TextUtils;
import android.util.Log;
-import android.util.Pair;
import android.util.PrintWriterPrinter;
import android.util.Printer;
import android.view.KeyEvent;
@@ -154,8 +153,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private static final int ARG1_NOT_GESTURE_INPUT = 0;
private static final int ARG1_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT = 1;
private static final int ARG1_SHOW_GESTURE_FLOATING_PREVIEW_TEXT = 2;
- private static final int ARG2_WITHOUT_TYPED_WORD = 0;
- private static final int ARG2_WITH_TYPED_WORD = 1;
+ private static final int ARG2_UNUSED = 0;
private int mDelayUpdateSuggestions;
private int mDelayUpdateShiftState;
@@ -190,16 +188,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
break;
case MSG_SHOW_GESTURE_PREVIEW_AND_SUGGESTION_STRIP:
if (msg.arg1 == ARG1_NOT_GESTURE_INPUT) {
- if (msg.arg2 == ARG2_WITH_TYPED_WORD) {
- final Pair<SuggestedWords, String> p =
- (Pair<SuggestedWords, String>) msg.obj;
- // [IL]: this is the only place where the second arg is not
- // suggestedWords.mTypedWord.
- latinIme.showSuggestionStrip(p.first, p.second);
- } else {
- final SuggestedWords suggestedWords = (SuggestedWords) msg.obj;
- latinIme.showSuggestionStrip(suggestedWords, suggestedWords.mTypedWord);
- }
+ final SuggestedWords suggestedWords = (SuggestedWords) msg.obj;
+ latinIme.showSuggestionStrip(suggestedWords);
} else {
latinIme.showGesturePreviewAndSuggestionStrip((SuggestedWords) msg.obj,
msg.arg1 == ARG1_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT);
@@ -292,22 +282,13 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
? ARG1_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT
: ARG1_SHOW_GESTURE_FLOATING_PREVIEW_TEXT;
obtainMessage(MSG_SHOW_GESTURE_PREVIEW_AND_SUGGESTION_STRIP, arg1,
- ARG2_WITHOUT_TYPED_WORD, suggestedWords).sendToTarget();
+ ARG2_UNUSED, suggestedWords).sendToTarget();
}
public void showSuggestionStrip(final SuggestedWords suggestedWords) {
removeMessages(MSG_SHOW_GESTURE_PREVIEW_AND_SUGGESTION_STRIP);
obtainMessage(MSG_SHOW_GESTURE_PREVIEW_AND_SUGGESTION_STRIP,
- ARG1_NOT_GESTURE_INPUT, ARG2_WITHOUT_TYPED_WORD, suggestedWords).sendToTarget();
- }
-
- // TODO: Remove this method.
- public void showSuggestionStripWithTypedWord(final SuggestedWords suggestedWords,
- final String typedWord) {
- removeMessages(MSG_SHOW_GESTURE_PREVIEW_AND_SUGGESTION_STRIP);
- obtainMessage(MSG_SHOW_GESTURE_PREVIEW_AND_SUGGESTION_STRIP, ARG1_NOT_GESTURE_INPUT,
- ARG2_WITH_TYPED_WORD,
- new Pair<SuggestedWords, String>(suggestedWords, typedWord)).sendToTarget();
+ ARG1_NOT_GESTURE_INPUT, ARG2_UNUSED, suggestedWords).sendToTarget();
}
public void onEndBatchInput(final SuggestedWords suggestedWords) {
@@ -1273,7 +1254,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// This method must run on the UI Thread.
private void showGesturePreviewAndSuggestionStrip(final SuggestedWords suggestedWords,
final boolean dismissGestureFloatingPreviewText) {
- showSuggestionStrip(suggestedWords, suggestedWords.mTypedWord);
+ showSuggestionStrip(suggestedWords);
final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
mainKeyboardView.showGestureFloatingPreviewText(suggestedWords);
if (dismissGestureFloatingPreviewText) {
@@ -1409,8 +1390,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
// TODO[IL]: Define a clean interface for this
- public void showSuggestionStrip(final SuggestedWords sourceSuggestedWords,
- final String typedWord) {
+ public void showSuggestionStrip(final SuggestedWords sourceSuggestedWords) {
final SuggestedWords suggestedWords =
sourceSuggestedWords.isEmpty() ? SuggestedWords.EMPTY : sourceSuggestedWords;
final String autoCorrection;
@@ -1419,7 +1399,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} else {
// We can't use suggestedWords.getWord(SuggestedWords.INDEX_OF_TYPED_WORD)
// because it may differ from mWordComposer.mTypedWord.
- autoCorrection = typedWord;
+ autoCorrection = sourceSuggestedWords.mTypedWord;
}
if (SuggestedWords.EMPTY != suggestedWords) {
mInputLogic.mWordComposer.setAutoCorrection(autoCorrection);
@@ -1427,7 +1407,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
setSuggestedWords(suggestedWords, isSuggestionsStripVisible());
// Cache the auto-correction in accessibility code so we can speak it if the user
// touches a key that will insert it.
- AccessibilityUtils.getInstance().setAutoCorrection(suggestedWords, typedWord);
+ AccessibilityUtils.getInstance().setAutoCorrection(suggestedWords,
+ sourceSuggestedWords.mTypedWord);
}
// Called from {@link SuggestionStripView} through the {@link SuggestionStripView#Listener}
@@ -1517,8 +1498,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
if (showingAddToDictionaryHint
&& suggest.mDictionaryFacilitator.isUserDictionaryEnabled()) {
- mSuggestionStripView.showAddToDictionaryHint(
- suggestion, currentSettings.mHintToSaveText);
+ mSuggestionStripView.showAddToDictionaryHint(suggestion);
} else {
// If we're not showing the "Touch again to save", then update the suggestion strip.
mHandler.postUpdateSuggestionStrip();
@@ -1538,18 +1518,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
}
- public void unsetIsAutoCorrectionIndicatorOnAndCallShowSuggestionStrip(
- final SuggestedWords suggestedWords, final String typedWord) {
- // Note that it's very important here that suggestedWords.mWillAutoCorrect is false.
- // We never want to auto-correct on a resumed suggestion. Please refer to the three places
- // above in restartSuggestionsOnWordTouchedByCursor() where suggestedWords is affected.
- // We also need to unset mIsAutoCorrectionIndicatorOn to avoid showSuggestionStrip touching
- // the text to adapt it.
- // TODO: remove mIsAutoCorrectionIndicatorOn (see comment on definition)
- mInputLogic.mIsAutoCorrectionIndicatorOn = false;
- mHandler.showSuggestionStripWithTypedWord(suggestedWords, typedWord);
- }
-
// TODO: Make this private
// Outside LatinIME, only used by the {@link InputTestsBase} test suite.
@UsedForTesting
diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java
index 982a97a5e..dbaf822e4 100644
--- a/java/src/com/android/inputmethod/latin/SuggestedWords.java
+++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java
@@ -68,6 +68,21 @@ public final class SuggestedWords {
final boolean isObsoleteSuggestions,
final boolean isPrediction,
final int sequenceNumber) {
+ this(suggestedWordInfoList,
+ suggestedWordInfoList.isEmpty() ? null
+ : suggestedWordInfoList.get(INDEX_OF_TYPED_WORD).mWord,
+ typedWordValid, willAutoCorrect, isPunctuationSuggestions,
+ isObsoleteSuggestions, isPrediction, sequenceNumber);
+ }
+
+ public SuggestedWords(final ArrayList<SuggestedWordInfo> suggestedWordInfoList,
+ final String typedWord,
+ final boolean typedWordValid,
+ final boolean willAutoCorrect,
+ final boolean isPunctuationSuggestions,
+ final boolean isObsoleteSuggestions,
+ final boolean isPrediction,
+ final int sequenceNumber) {
mSuggestedWordInfoList = suggestedWordInfoList;
mTypedWordValid = typedWordValid;
mWillAutoCorrect = willAutoCorrect;
@@ -75,7 +90,7 @@ public final class SuggestedWords {
mIsObsoleteSuggestions = isObsoleteSuggestions;
mIsPrediction = isPrediction;
mSequenceNumber = sequenceNumber;
- mTypedWord = suggestedWordInfoList.isEmpty() ? null : getWord(INDEX_OF_TYPED_WORD);
+ mTypedWord = typedWord;
}
public boolean isEmpty() {
@@ -279,17 +294,21 @@ public final class SuggestedWords {
// words from the member ArrayList as some other parties may expect the object to never change.
public SuggestedWords getSuggestedWordsExcludingTypedWord() {
final ArrayList<SuggestedWordInfo> newSuggestions = CollectionUtils.newArrayList();
+ String typedWord = null;
for (int i = 0; i < mSuggestedWordInfoList.size(); ++i) {
final SuggestedWordInfo info = mSuggestedWordInfoList.get(i);
if (SuggestedWordInfo.KIND_TYPED != info.mKind) {
newSuggestions.add(info);
+ } else {
+ assert(null == typedWord);
+ typedWord = info.mWord;
}
}
// We should never autocorrect, so we say the typed word is valid. Also, in this case,
// no auto-correction should take place hence willAutoCorrect = false.
- return new SuggestedWords(newSuggestions, true /* typedWordValid */,
+ return new SuggestedWords(newSuggestions, typedWord, true /* typedWordValid */,
false /* willAutoCorrect */, mIsPunctuationSuggestions, mIsObsoleteSuggestions,
- mIsPrediction);
+ mIsPrediction, NOT_A_SEQUENCE_NUMBER);
}
// Creates a new SuggestedWordInfo from the currently suggested words that removes all but the
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
index ce3ef5374..1bc67b2a0 100644
--- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
+++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
@@ -1120,7 +1120,7 @@ public final class InputLogic {
final SuggestedWords suggestedWords = holder.get(null,
Constants.GET_SUGGESTED_WORDS_TIMEOUT);
if (suggestedWords != null) {
- mLatinIME.showSuggestionStrip(suggestedWords, suggestedWords.mTypedWord);
+ mLatinIME.showSuggestionStrip(suggestedWords);
}
}
@@ -1217,21 +1217,18 @@ public final class InputLogic {
// Since there is only one word, willAutoCorrect is false.
suggestedWords = suggestedWordsIncludingTypedWord;
}
- // We need to pass typedWord because mWordComposer.mTypedWord may
- // differ from typedWord.
- mLatinIME.unsetIsAutoCorrectionIndicatorOnAndCallShowSuggestionStrip(
- suggestedWords, typedWord);
+ mIsAutoCorrectionIndicatorOn = false;
+ mLatinIME.mHandler.showSuggestionStrip(suggestedWords);
}});
} else {
// We found suggestion spans in the word. We'll create the SuggestedWords out of
// them, and make willAutoCorrect false.
- final SuggestedWords suggestedWords = new SuggestedWords(suggestions,
+ final SuggestedWords suggestedWords = new SuggestedWords(suggestions, typedWord,
true /* typedWordValid */, false /* willAutoCorrect */,
false /* isPunctuationSuggestions */, false /* isObsoleteSuggestions */,
- false /* isPrediction */);
- // We need to pass typedWord because mWordComposer.mTypedWord may differ from typedWord.
- mLatinIME.unsetIsAutoCorrectionIndicatorOnAndCallShowSuggestionStrip(suggestedWords,
- typedWord);
+ false /* isPrediction */, SuggestedWords.NOT_A_SEQUENCE_NUMBER);
+ mIsAutoCorrectionIndicatorOn = false;
+ mLatinIME.mHandler.showSuggestionStrip(suggestedWords);
}
}
@@ -1624,8 +1621,7 @@ public final class InputLogic {
mConnection.commitText(batchInputText.substring(0, indexOfLastSpace), 1);
final SuggestedWords suggestedWordsForLastWordOfPhraseGesture =
suggestedWords.getSuggestedWordsForLastWordOfPhraseGesture();
- mLatinIME.showSuggestionStrip(suggestedWordsForLastWordOfPhraseGesture,
- suggestedWordsForLastWordOfPhraseGesture.mTypedWord);
+ mLatinIME.showSuggestionStrip(suggestedWordsForLastWordOfPhraseGesture);
}
final String lastWord = batchInputText.substring(indexOfLastSpace);
mWordComposer.setBatchInputWord(lastWord);
diff --git a/java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java b/java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java
index f23022992..e459e4861 100644
--- a/java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java
+++ b/java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java
@@ -215,11 +215,12 @@ public class Ver4DictDecoder extends AbstractDictDecoder {
if (options.mHasTimestamp) {
probability = buffer.readUnsignedByte();
- final int pos = buffer.position();
- // Skip historical info.
- buffer.position(pos + FormatSpec.BIGRAM_TIMESTAMP_SIZE
- + FormatSpec.BIGRAM_LEVEL_SIZE
- + FormatSpec.BIGRAM_COUNTER_SIZE);
+ // Skip timestamp
+ buffer.readInt();
+ // Skip level
+ buffer.readUnsignedByte();
+ // Skip count
+ buffer.readUnsignedByte();
} else {
probability = bigramFlags
& FormatSpec.FLAG_BIGRAM_SHORTCUT_ATTR_FREQUENCY;
diff --git a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
index e4ae64fdc..2979544ae 100644
--- a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
+++ b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
@@ -49,7 +49,6 @@ public final class SettingsValues {
// From resources:
public final SpacingAndPunctuations mSpacingAndPunctuations;
public final int mDelayUpdateOldSuggestions;
- public final CharSequence mHintToSaveText;
// From preferences, in the same order as xml/prefs.xml:
public final boolean mAutoCap;
@@ -101,7 +100,6 @@ public final class SettingsValues {
// Get the resources
mDelayUpdateOldSuggestions = res.getInteger(R.integer.config_delay_update_old_suggestions);
mSpacingAndPunctuations = new SpacingAndPunctuations(res);
- mHintToSaveText = res.getText(R.string.hint_add_to_dictionary);
// Store the input attributes
if (null == inputAttributes) {
diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java
index 3cd9d9555..5ed42ab00 100644
--- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java
+++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java
@@ -50,6 +50,7 @@ import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.SuggestedWords;
import com.android.inputmethod.latin.utils.AutoCorrectionUtils;
import com.android.inputmethod.latin.utils.ResourceUtils;
+import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
import com.android.inputmethod.latin.utils.ViewLayoutUtils;
import java.util.ArrayList;
@@ -459,7 +460,7 @@ final class SuggestionStripLayoutHelper {
}
public void layoutAddToDictionaryHint(final String word, final ViewGroup addToDictionaryStrip,
- final int stripWidth, final CharSequence hintText) {
+ final int stripWidth) {
final int width = stripWidth - mDividerWidth - mPadding * 2;
final TextView wordView = (TextView)addToDictionaryStrip.findViewById(R.id.word_to_save);
@@ -473,13 +474,17 @@ final class SuggestionStripLayoutHelper {
final TextView hintView = (TextView)addToDictionaryStrip.findViewById(
R.id.hint_add_to_dictionary);
- hintView.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL | GravityCompat.START);
hintView.setTextColor(mColorAutoCorrect);
final boolean isRtlLanguage = (ViewCompat.getLayoutDirection(addToDictionaryStrip)
== ViewCompat.LAYOUT_DIRECTION_RTL);
- final String hintWithArrow = (isRtlLanguage ? RIGHTWARDS_ARROW : LEFTWARDS_ARROW)
- + hintText;
+ final String arrow = isRtlLanguage ? RIGHTWARDS_ARROW : LEFTWARDS_ARROW;
+ final Resources res = addToDictionaryStrip.getResources();
+ final boolean isRtlSystem = SubtypeLocaleUtils.isRtlLanguage(res.getConfiguration().locale);
+ final CharSequence hintText = res.getText(R.string.hint_add_to_dictionary);
+ final String hintWithArrow = (isRtlLanguage == isRtlSystem)
+ ? (arrow + hintText) : (hintText + arrow);
final int hintWidth = width - wordWidth;
+ hintView.setTextScaleX(1.0f); // Reset textScaleX.
final float hintScaleX = getTextScaleX(hintWithArrow, hintWidth, hintView.getPaint());
hintView.setText(hintWithArrow);
hintView.setTextScaleX(hintScaleX);
diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java
index 5469ced7a..22804fce1 100644
--- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java
+++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java
@@ -186,8 +186,8 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
return mStripVisibilityGroup.isShowingAddToDictionaryStrip();
}
- public void showAddToDictionaryHint(final String word, final CharSequence hintText) {
- mLayoutHelper.layoutAddToDictionaryHint(word, mAddToDictionaryStrip, getWidth(), hintText);
+ public void showAddToDictionaryHint(final String word) {
+ mLayoutHelper.layoutAddToDictionaryHint(word, mAddToDictionaryStrip, getWidth());
// {@link TextView#setTag()} is used to hold the word to be added to dictionary. The word
// will be extracted at {@link #onClick(View)}.
mAddToDictionaryStrip.setTag(word);
diff --git a/java/src/com/android/inputmethod/latin/utils/ImportantNoticeUtils.java b/java/src/com/android/inputmethod/latin/utils/ImportantNoticeUtils.java
new file mode 100644
index 000000000..8eff2e6e7
--- /dev/null
+++ b/java/src/com/android/inputmethod/latin/utils/ImportantNoticeUtils.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2014 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.inputmethod.latin.utils;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.provider.Settings;
+import android.provider.Settings.SettingNotFoundException;
+import android.util.Log;
+
+public final class ImportantNoticeUtils {
+ private static final String TAG = ImportantNoticeUtils.class.getSimpleName();
+
+ // The current version number of an important notice.
+ // This number must be incremented whenever users should see a new important notice.
+ private static final int CURRENT_IMPORTANT_NOTICE_VERSION = 0;
+
+ // {@link SharedPreferences} name to save the last important notice version that has been
+ // displayed to users.
+ private static final String PREFERENCE_NAME = "important_notice";
+ private static final String KEY_IMPORTANT_NOTICE_VERSION = "important_notice_version";
+
+ // Copy of the hidden {@link Settings.Secure#USER_SETUP_COMPLETE} settings key.
+ // The value is zero until each multiuser completes system setup wizard.
+ // Caveat: This is a hidden API.
+ private static final String Settings_Secure_USER_SETUP_COMPLETE = "user_setup_complete";
+ private static final int USER_SETUP_IS_NOT_COMPLETE = 0;
+
+ private ImportantNoticeUtils() {
+ // This utility class is not publicly instantiable.
+ }
+
+ public static boolean isInSystemSetupWizard(final Context context) {
+ try {
+ final int userSetupComplete = Settings.Secure.getInt(
+ context.getContentResolver(), Settings_Secure_USER_SETUP_COMPLETE);
+ return userSetupComplete == USER_SETUP_IS_NOT_COMPLETE;
+ } catch (final SettingNotFoundException e) {
+ Log.w(TAG, "Can't find settings in Settings.Secure: key="
+ + Settings_Secure_USER_SETUP_COMPLETE);
+ return false;
+ }
+ }
+
+ private static SharedPreferences getImportantNoticePreferences(final Context context) {
+ return context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
+ }
+
+ public static boolean hasNewImportantNotice(final Context context) {
+ final SharedPreferences prefs = getImportantNoticePreferences(context);
+ final int lastVersion = prefs.getInt(KEY_IMPORTANT_NOTICE_VERSION, 0);
+ return CURRENT_IMPORTANT_NOTICE_VERSION > lastVersion;
+ }
+
+ public static void updateLastImportantNoticeVersion(final Context context) {
+ final SharedPreferences prefs = getImportantNoticePreferences(context);
+ prefs.edit()
+ .putInt(KEY_IMPORTANT_NOTICE_VERSION, CURRENT_IMPORTANT_NOTICE_VERSION)
+ .apply();
+ }
+}
diff --git a/java/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtils.java b/java/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtils.java
index 0d0288923..b3871bfb4 100644
--- a/java/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtils.java
+++ b/java/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtils.java
@@ -347,9 +347,12 @@ public final class SubtypeLocaleUtils {
Arrays.sort(SORTED_RTL_LANGUAGES);
}
- public static boolean isRtlLanguage(final InputMethodSubtype subtype) {
- final Locale locale = getSubtypeLocale(subtype);
+ public static boolean isRtlLanguage(final Locale locale) {
final String language = locale.getLanguage();
return Arrays.binarySearch(SORTED_RTL_LANGUAGES, language) >= 0;
}
+
+ public static boolean isRtlLanguage(final InputMethodSubtype subtype) {
+ return isRtlLanguage(getSubtypeLocale(subtype));
+ }
}