diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin/utils')
-rw-r--r-- | java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java | 37 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/latin/utils/ManagedProfileUtils.java | 82 |
2 files changed, 31 insertions, 88 deletions
diff --git a/java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java b/java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java index fd567f49d..d8e332370 100644 --- a/java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java @@ -22,11 +22,13 @@ import android.content.res.AssetManager; import android.content.res.Resources; import android.text.TextUtils; import android.util.Log; +import android.view.inputmethod.InputMethodSubtype; import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.latin.AssetFileAddress; import com.android.inputmethod.latin.BinaryDictionaryGetter; import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.RichInputMethodManager; import com.android.inputmethod.latin.common.LocaleUtils; import com.android.inputmethod.latin.define.DecoderSpecificConstants; import com.android.inputmethod.latin.makedict.DictionaryHeader; @@ -37,6 +39,7 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import java.util.Locale; import java.util.concurrent.TimeUnit; @@ -69,12 +72,11 @@ public class DictionaryInfoUtils { public final Locale mLocale; @Nullable public final String mDescription; - @Nonnull public final AssetFileAddress mFileAddress; public final int mVersion; public DictionaryInfo(@Nonnull final String id, @Nonnull final Locale locale, - @Nullable final String description, @Nonnull final AssetFileAddress fileAddress, + @Nullable final String description, @Nullable final AssetFileAddress fileAddress, final int version) { mId = id; mLocale = locale; @@ -88,10 +90,12 @@ public class DictionaryInfoUtils { values.put(WORDLISTID_COLUMN, mId); values.put(LOCALE_COLUMN, mLocale.toString()); values.put(DESCRIPTION_COLUMN, mDescription); - values.put(LOCAL_FILENAME_COLUMN, mFileAddress.mFilename); + values.put(LOCAL_FILENAME_COLUMN, + mFileAddress != null ? mFileAddress.mFilename : ""); values.put(DATE_COLUMN, TimeUnit.MILLISECONDS.toSeconds( - new File(mFileAddress.mFilename).lastModified())); - values.put(FILESIZE_COLUMN, mFileAddress.mLength); + mFileAddress != null ? new File(mFileAddress.mFilename).lastModified() : 0)); + values.put(FILESIZE_COLUMN, + mFileAddress != null ? mFileAddress.mLength : 0); values.put(VERSION_COLUMN, mVersion); return values; } @@ -360,7 +364,6 @@ public class DictionaryInfoUtils { * @param locale Locale for this file. * @return information of the specified dictionary. */ - @Nullable private static DictionaryInfo createDictionaryInfoFromFileAddress( final AssetFileAddress fileAddress, Locale locale) { final String id = getMainDictId(locale); @@ -370,6 +373,17 @@ public class DictionaryInfoUtils { return new DictionaryInfo(id, locale, description, fileAddress, version); } + /** + * Returns dictionary information for the given locale. + */ + private static DictionaryInfo createDictionaryInfoFromLocale(Locale locale) { + final String id = getMainDictId(locale); + final int version = -1; + final String description = SubtypeLocaleUtils + .getSubtypeLocaleDisplayName(locale.toString()); + return new DictionaryInfo(id, locale, description, null, version); + } + private static void addOrUpdateDictInfo(final ArrayList<DictionaryInfo> dictList, final DictionaryInfo newElement) { final Iterator<DictionaryInfo> iter = dictList.iterator(); @@ -441,6 +455,17 @@ public class DictionaryInfoUtils { addOrUpdateDictInfo(dictList, dictionaryInfo); } + // Generate the dictionary information from the enabled subtypes. This will not + // overwrite the real records. + RichInputMethodManager.init(context); + List<InputMethodSubtype> enabledSubtypes = RichInputMethodManager + .getInstance().getMyEnabledInputMethodSubtypeList(true); + for (InputMethodSubtype subtype : enabledSubtypes) { + Locale locale = LocaleUtils.constructLocaleFromString(subtype.getLocale()); + DictionaryInfo dictionaryInfo = createDictionaryInfoFromLocale(locale); + addOrUpdateDictInfo(dictList, dictionaryInfo); + } + return dictList; } diff --git a/java/src/com/android/inputmethod/latin/utils/ManagedProfileUtils.java b/java/src/com/android/inputmethod/latin/utils/ManagedProfileUtils.java deleted file mode 100644 index 1bd8f314c..000000000 --- a/java/src/com/android/inputmethod/latin/utils/ManagedProfileUtils.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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.annotation.TargetApi; -import android.content.Context; -import android.os.Build; -import android.os.UserHandle; -import android.os.UserManager; -import android.util.Log; - -import com.android.inputmethod.annotations.UsedForTesting; - -import java.util.List; - -/** - * Utility for determining if the device has managed profiles. - */ -public class ManagedProfileUtils { - private static final boolean DEBUG = false; - private static final String TAG = ManagedProfileUtils.class.getSimpleName(); - - private static ManagedProfileUtils INSTANCE = new ManagedProfileUtils(); - private static ManagedProfileUtils sTestInstance; - - private ManagedProfileUtils() { - // This utility class is not publicly instantiable. - } - - @UsedForTesting - public static void setTestInstance(final ManagedProfileUtils testInstance) { - sTestInstance = testInstance; - } - - public static ManagedProfileUtils getInstance() { - return sTestInstance == null ? INSTANCE : sTestInstance; - } - - /** - * Note that {@link UserManager#getUserProfiles} has been introduced - * in API level 21 (Build.VERSION_CODES.LOLLIPOP). - */ - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public boolean hasManagedWorkProfile(final Context context) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - return false; - } - - final UserManager userManagerService = - (UserManager) context.getSystemService(Context.USER_SERVICE); - if (userManagerService != null) { - if (DEBUG) { - Log.d(TAG, "Detecting managed profile..."); - } - final List<UserHandle> userProfiles = userManagerService.getUserProfiles(); - if (userProfiles.size() > 1) { - if (DEBUG) { - Log.d(TAG, "More than one user profile => Managed profile exists."); - } - return true; - } - } - if (DEBUG) { - Log.d(TAG, "Managed profile not detected."); - } - return false; - } -} |