aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/dictionarypack
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/dictionarypack')
-rw-r--r--java/src/com/android/inputmethod/dictionarypack/ButtonSwitcher.java25
-rw-r--r--java/src/com/android/inputmethod/dictionarypack/DictionaryDownloadProgressBar.java2
-rw-r--r--java/src/com/android/inputmethod/dictionarypack/DictionaryListInterfaceState.java2
-rw-r--r--java/src/com/android/inputmethod/dictionarypack/DictionaryProvider.java36
-rw-r--r--java/src/com/android/inputmethod/dictionarypack/DictionaryService.java2
-rw-r--r--java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java155
-rw-r--r--java/src/com/android/inputmethod/dictionarypack/MetadataDbHelper.java4
-rw-r--r--java/src/com/android/inputmethod/dictionarypack/MetadataHandler.java3
-rw-r--r--java/src/com/android/inputmethod/dictionarypack/PrivateLog.java10
-rw-r--r--java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java19
-rw-r--r--java/src/com/android/inputmethod/dictionarypack/WordListPreference.java184
11 files changed, 219 insertions, 223 deletions
diff --git a/java/src/com/android/inputmethod/dictionarypack/ButtonSwitcher.java b/java/src/com/android/inputmethod/dictionarypack/ButtonSwitcher.java
index 6d6c8f5c6..0fa72c3fd 100644
--- a/java/src/com/android/inputmethod/dictionarypack/ButtonSwitcher.java
+++ b/java/src/com/android/inputmethod/dictionarypack/ButtonSwitcher.java
@@ -122,19 +122,23 @@ public class ButtonSwitcher extends FrameLayout {
mDeleteButton.setTranslationX(STATUS_DELETE == status ? 0 : width);
}
+ // The helper method for {@link AnimatorListenerAdapter}.
+ void animateButtonIfStatusIsEqual(final View newButton, final int newStatus) {
+ if (newStatus != mStatus) return;
+ animateButton(newButton, ANIMATION_IN);
+ }
+
private void animateButtonPosition(final int oldStatus, final int newStatus) {
final View oldButton = getButton(oldStatus);
final View newButton = getButton(newStatus);
if (null != oldButton && null != newButton) {
// Transition between two buttons : animate out, then in
- animateButton(oldButton, ANIMATION_OUT).setListener(
- new AnimatorListenerAdapter() {
- @Override
- public void onAnimationEnd(final Animator animation) {
- if (newStatus != mStatus) return;
- animateButton(newButton, ANIMATION_IN);
- }
- });
+ animateButton(oldButton, ANIMATION_OUT).setListener(new AnimatorListenerAdapter() {
+ @Override
+ public void onAnimationEnd(final Animator animation) {
+ animateButtonIfStatusIsEqual(newButton, newStatus);
+ }
+ });
} else if (null != oldButton) {
animateButton(oldButton, ANIMATION_OUT);
} else if (null != newButton) {
@@ -159,9 +163,8 @@ public class ButtonSwitcher extends FrameLayout {
if (ANIMATION_IN == direction) {
button.setClickable(true);
return button.animate().translationX(0);
- } else {
- button.setClickable(false);
- return button.animate().translationX(outerX - innerX);
}
+ button.setClickable(false);
+ return button.animate().translationX(outerX - innerX);
}
}
diff --git a/java/src/com/android/inputmethod/dictionarypack/DictionaryDownloadProgressBar.java b/java/src/com/android/inputmethod/dictionarypack/DictionaryDownloadProgressBar.java
index 1d84e5888..759852025 100644
--- a/java/src/com/android/inputmethod/dictionarypack/DictionaryDownloadProgressBar.java
+++ b/java/src/com/android/inputmethod/dictionarypack/DictionaryDownloadProgressBar.java
@@ -148,7 +148,7 @@ public class DictionaryDownloadProgressBar extends ProgressBar {
}
}
- private class UpdateHelper implements Runnable {
+ class UpdateHelper implements Runnable {
private int mProgress;
@Override
public void run() {
diff --git a/java/src/com/android/inputmethod/dictionarypack/DictionaryListInterfaceState.java b/java/src/com/android/inputmethod/dictionarypack/DictionaryListInterfaceState.java
index 8e026171d..836340a75 100644
--- a/java/src/com/android/inputmethod/dictionarypack/DictionaryListInterfaceState.java
+++ b/java/src/com/android/inputmethod/dictionarypack/DictionaryListInterfaceState.java
@@ -32,7 +32,7 @@ import java.util.HashMap;
* in case some dictionaries appeared, disappeared, changed states etc.
*/
public class DictionaryListInterfaceState {
- private static class State {
+ static class State {
public boolean mOpen = false;
public int mStatus = MetadataDbHelper.STATUS_UNKNOWN;
}
diff --git a/java/src/com/android/inputmethod/dictionarypack/DictionaryProvider.java b/java/src/com/android/inputmethod/dictionarypack/DictionaryProvider.java
index e748321e2..37fa76be7 100644
--- a/java/src/com/android/inputmethod/dictionarypack/DictionaryProvider.java
+++ b/java/src/com/android/inputmethod/dictionarypack/DictionaryProvider.java
@@ -255,10 +255,9 @@ public final class DictionaryProvider extends ContentProvider {
if (null != dictFiles && dictFiles.size() > 0) {
PrivateLog.log("Returned " + dictFiles.size() + " files");
return new ResourcePathCursor(dictFiles);
- } else {
- PrivateLog.log("No dictionary files for this URL");
- return new ResourcePathCursor(Collections.<WordListInfo>emptyList());
}
+ PrivateLog.log("No dictionary files for this URL");
+ return new ResourcePathCursor(Collections.<WordListInfo>emptyList());
// V2_METADATA and V2_DATAFILE are not supported for query()
default:
return null;
@@ -319,14 +318,13 @@ public final class DictionaryProvider extends ContentProvider {
final AssetFileDescriptor afd = getContext().getResources().openRawResourceFd(
R.raw.empty);
return afd;
- } else {
- final String localFilename =
- wordList.getAsString(MetadataDbHelper.LOCAL_FILENAME_COLUMN);
- final File f = getContext().getFileStreamPath(localFilename);
- final ParcelFileDescriptor pfd =
- ParcelFileDescriptor.open(f, ParcelFileDescriptor.MODE_READ_ONLY);
- return new AssetFileDescriptor(pfd, 0, pfd.getStatSize());
}
+ final String localFilename =
+ wordList.getAsString(MetadataDbHelper.LOCAL_FILENAME_COLUMN);
+ final File f = getContext().getFileStreamPath(localFilename);
+ final ParcelFileDescriptor pfd =
+ ParcelFileDescriptor.open(f, ParcelFileDescriptor.MODE_READ_ONLY);
+ return new AssetFileDescriptor(pfd, 0, pfd.getStatSize());
} catch (FileNotFoundException e) {
// No file : fall through and return null
}
@@ -461,13 +459,16 @@ public final class DictionaryProvider extends ContentProvider {
final String wordlistId = uri.getLastPathSegment();
final String clientId = getClientId(uri);
final ContentValues wordList = getWordlistMetadataForWordlistId(clientId, wordlistId);
- if (null == wordList) return 0;
+ if (null == wordList) {
+ return 0;
+ }
final int status = wordList.getAsInteger(MetadataDbHelper.STATUS_COLUMN);
final int version = wordList.getAsInteger(MetadataDbHelper.VERSION_COLUMN);
if (MetadataDbHelper.STATUS_DELETING == status) {
UpdateHandler.markAsDeleted(getContext(), clientId, wordlistId, version, status);
return 1;
- } else if (MetadataDbHelper.STATUS_INSTALLED == status) {
+ }
+ if (MetadataDbHelper.STATUS_INSTALLED == status) {
final String result = uri.getQueryParameter(QUERY_PARAMETER_DELETE_RESULT);
if (QUERY_PARAMETER_FAILURE.equals(result)) {
if (DEBUG) {
@@ -480,15 +481,10 @@ public final class DictionaryProvider extends ContentProvider {
wordList.getAsString(MetadataDbHelper.LOCAL_FILENAME_COLUMN);
final File f = getContext().getFileStreamPath(localFilename);
// f.delete() returns true if the file was successfully deleted, false otherwise
- if (f.delete()) {
- return 1;
- } else {
- return 0;
- }
- } else {
- Log.e(TAG, "Attempt to delete a file whose status is " + status);
- return 0;
+ return f.delete() ? 1 : 0;
}
+ Log.e(TAG, "Attempt to delete a file whose status is " + status);
+ return 0;
}
/**
diff --git a/java/src/com/android/inputmethod/dictionarypack/DictionaryService.java b/java/src/com/android/inputmethod/dictionarypack/DictionaryService.java
index 568c80abd..e9b634eec 100644
--- a/java/src/com/android/inputmethod/dictionarypack/DictionaryService.java
+++ b/java/src/com/android/inputmethod/dictionarypack/DictionaryService.java
@@ -179,7 +179,7 @@ public final class DictionaryService extends Service {
return Service.START_REDELIVER_INTENT;
}
- private static void dispatchBroadcast(final Context context, final Intent intent) {
+ static void dispatchBroadcast(final Context context, final Intent intent) {
if (DATE_CHANGED_INTENT_ACTION.equals(intent.getAction())) {
// This happens when the date of the device changes. This normally happens
// at midnight local time, but it may happen if the user changes the date
diff --git a/java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java b/java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java
index 11982fa65..c2dc87900 100644
--- a/java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java
+++ b/java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java
@@ -31,7 +31,6 @@ import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceGroup;
import android.text.TextUtils;
-import android.text.format.DateUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
@@ -203,25 +202,19 @@ public final class DictionarySettingsFragment extends PreferenceFragment
@Override
public void updateCycleCompleted() {}
- private void refreshNetworkState() {
+ void refreshNetworkState() {
NetworkInfo info = mConnectivityManager.getActiveNetworkInfo();
boolean isConnected = null == info ? false : info.isConnected();
if (null != mUpdateNowMenu) mUpdateNowMenu.setEnabled(isConnected);
}
- private void refreshInterface() {
+ void refreshInterface() {
final Activity activity = getActivity();
if (null == activity) return;
- final long lastUpdateDate =
- MetadataDbHelper.getLastUpdateDateForClient(getActivity(), mClientId);
final PreferenceGroup prefScreen = getPreferenceScreen();
final Collection<? extends Preference> prefList =
createInstalledDictSettingsCollection(mClientId);
- final String updateNowSummary = getString(R.string.last_update) + " "
- + DateUtils.formatDateTime(activity, lastUpdateDate,
- DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME);
-
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
@@ -239,14 +232,14 @@ public final class DictionarySettingsFragment extends PreferenceFragment
});
}
- private Preference createErrorMessage(final Activity activity, final int messageResource) {
+ private static Preference createErrorMessage(final Activity activity, final int messageResource) {
final Preference message = new Preference(activity);
message.setTitle(messageResource);
message.setEnabled(false);
return message;
}
- private void removeAnyDictSettings(final PreferenceGroup prefGroup) {
+ static void removeAnyDictSettings(final PreferenceGroup prefGroup) {
for (int i = prefGroup.getPreferenceCount() - 1; i >= 0; --i) {
prefGroup.removePreference(prefGroup.getPreference(i));
}
@@ -276,7 +269,7 @@ public final class DictionarySettingsFragment extends PreferenceFragment
.appendQueryParameter(DictionaryProvider.QUERY_PARAMETER_PROTOCOL_VERSION, "2")
.build();
final Activity activity = getActivity();
- final Cursor cursor = null == activity ? null
+ final Cursor cursor = (null == activity) ? null
: activity.getContentResolver().query(contentUri, null, null, null, null);
if (null == cursor) {
@@ -289,61 +282,57 @@ public final class DictionarySettingsFragment extends PreferenceFragment
final ArrayList<Preference> result = new ArrayList<>();
result.add(createErrorMessage(activity, R.string.no_dictionaries_available));
return result;
- } else {
- final String systemLocaleString = Locale.getDefault().toString();
- final TreeMap<String, WordListPreference> prefMap = new TreeMap<>();
- final int idIndex = cursor.getColumnIndex(MetadataDbHelper.WORDLISTID_COLUMN);
- final int versionIndex = cursor.getColumnIndex(MetadataDbHelper.VERSION_COLUMN);
- final int localeIndex = cursor.getColumnIndex(MetadataDbHelper.LOCALE_COLUMN);
- final int descriptionIndex =
- cursor.getColumnIndex(MetadataDbHelper.DESCRIPTION_COLUMN);
- final int statusIndex = cursor.getColumnIndex(MetadataDbHelper.STATUS_COLUMN);
- final int filesizeIndex = cursor.getColumnIndex(MetadataDbHelper.FILESIZE_COLUMN);
- do {
- final String wordlistId = cursor.getString(idIndex);
- final int version = cursor.getInt(versionIndex);
- final String localeString = cursor.getString(localeIndex);
- final Locale locale = new Locale(localeString);
- final String description = cursor.getString(descriptionIndex);
- final int status = cursor.getInt(statusIndex);
- final int matchLevel =
- LocaleUtils.getMatchLevel(systemLocaleString, localeString);
- final String matchLevelString =
- LocaleUtils.getMatchLevelSortedString(matchLevel);
- final int filesize = cursor.getInt(filesizeIndex);
- // The key is sorted in lexicographic order, according to the match level, then
- // the description.
- final String key = matchLevelString + "." + description + "." + wordlistId;
- final WordListPreference existingPref = prefMap.get(key);
- if (null == existingPref || existingPref.hasPriorityOver(status)) {
- final WordListPreference oldPreference = mCurrentPreferenceMap.get(key);
- final WordListPreference pref;
- if (null != oldPreference
- && oldPreference.mVersion == version
- && oldPreference.hasStatus(status)
- && oldPreference.mLocale.equals(locale)) {
- // If the old preference has all the new attributes, reuse it. Ideally,
- // we should reuse the old pref even if its status is different and call
- // setStatus here, but setStatus calls Preference#setSummary() which
- // needs to be done on the UI thread and we're not on the UI thread
- // here. We could do all this work on the UI thread, but in this case
- // it's probably lighter to stay on a background thread and throw this
- // old preference out.
- pref = oldPreference;
- } else {
- // Otherwise, discard it and create a new one instead.
- // TODO: when the status is different from the old one, we need to
- // animate the old one out before animating the new one in.
- pref = new WordListPreference(activity, mDictionaryListInterfaceState,
- mClientId, wordlistId, version, locale, description, status,
- filesize);
- }
- prefMap.put(key, pref);
- }
- } while (cursor.moveToNext());
- mCurrentPreferenceMap = prefMap;
- return prefMap.values();
}
+ final String systemLocaleString = Locale.getDefault().toString();
+ final TreeMap<String, WordListPreference> prefMap = new TreeMap<>();
+ final int idIndex = cursor.getColumnIndex(MetadataDbHelper.WORDLISTID_COLUMN);
+ final int versionIndex = cursor.getColumnIndex(MetadataDbHelper.VERSION_COLUMN);
+ final int localeIndex = cursor.getColumnIndex(MetadataDbHelper.LOCALE_COLUMN);
+ final int descriptionIndex = cursor.getColumnIndex(MetadataDbHelper.DESCRIPTION_COLUMN);
+ final int statusIndex = cursor.getColumnIndex(MetadataDbHelper.STATUS_COLUMN);
+ final int filesizeIndex = cursor.getColumnIndex(MetadataDbHelper.FILESIZE_COLUMN);
+ do {
+ final String wordlistId = cursor.getString(idIndex);
+ final int version = cursor.getInt(versionIndex);
+ final String localeString = cursor.getString(localeIndex);
+ final Locale locale = new Locale(localeString);
+ final String description = cursor.getString(descriptionIndex);
+ final int status = cursor.getInt(statusIndex);
+ final int matchLevel = LocaleUtils.getMatchLevel(systemLocaleString, localeString);
+ final String matchLevelString = LocaleUtils.getMatchLevelSortedString(matchLevel);
+ final int filesize = cursor.getInt(filesizeIndex);
+ // The key is sorted in lexicographic order, according to the match level, then
+ // the description.
+ final String key = matchLevelString + "." + description + "." + wordlistId;
+ final WordListPreference existingPref = prefMap.get(key);
+ if (null == existingPref || existingPref.hasPriorityOver(status)) {
+ final WordListPreference oldPreference = mCurrentPreferenceMap.get(key);
+ final WordListPreference pref;
+ if (null != oldPreference
+ && oldPreference.mVersion == version
+ && oldPreference.hasStatus(status)
+ && oldPreference.mLocale.equals(locale)) {
+ // If the old preference has all the new attributes, reuse it. Ideally,
+ // we should reuse the old pref even if its status is different and call
+ // setStatus here, but setStatus calls Preference#setSummary() which
+ // needs to be done on the UI thread and we're not on the UI thread
+ // here. We could do all this work on the UI thread, but in this case
+ // it's probably lighter to stay on a background thread and throw this
+ // old preference out.
+ pref = oldPreference;
+ } else {
+ // Otherwise, discard it and create a new one instead.
+ // TODO: when the status is different from the old one, we need to
+ // animate the old one out before animating the new one in.
+ pref = new WordListPreference(activity, mDictionaryListInterfaceState,
+ mClientId, wordlistId, version, locale, description, status,
+ filesize);
+ }
+ prefMap.put(key, pref);
+ }
+ } while (cursor.moveToNext());
+ mCurrentPreferenceMap = prefMap;
+ return prefMap.values();
} finally {
cursor.close();
}
@@ -396,26 +385,28 @@ public final class DictionarySettingsFragment extends PreferenceFragment
if (null != mUpdateNowMenu) mUpdateNowMenu.setTitle(R.string.cancel);
}
- private void stopLoadingAnimation() {
+ void stopLoadingAnimation() {
final View preferenceView = getView();
final Activity activity = getActivity();
if (null == activity) return;
+ final View loadingView = mLoadingView;
+ final MenuItem updateNowMenu = mUpdateNowMenu;
activity.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- mLoadingView.setVisibility(View.GONE);
- preferenceView.setVisibility(View.VISIBLE);
- mLoadingView.startAnimation(AnimationUtils.loadAnimation(
- getActivity(), android.R.anim.fade_out));
- preferenceView.startAnimation(AnimationUtils.loadAnimation(
- getActivity(), android.R.anim.fade_in));
- // The menu is created by the framework asynchronously after the activity,
- // which means it's possible to have the activity running but the menu not
- // created yet - hence the necessity for a null check here.
- if (null != mUpdateNowMenu) {
- mUpdateNowMenu.setTitle(R.string.check_for_updates_now);
- }
+ @Override
+ public void run() {
+ loadingView.setVisibility(View.GONE);
+ preferenceView.setVisibility(View.VISIBLE);
+ loadingView.startAnimation(AnimationUtils.loadAnimation(
+ activity, android.R.anim.fade_out));
+ preferenceView.startAnimation(AnimationUtils.loadAnimation(
+ activity, android.R.anim.fade_in));
+ // The menu is created by the framework asynchronously after the activity,
+ // which means it's possible to have the activity running but the menu not
+ // created yet - hence the necessity for a null check here.
+ if (null != updateNowMenu) {
+ updateNowMenu.setTitle(R.string.check_for_updates_now);
}
- });
+ }
+ });
}
}
diff --git a/java/src/com/android/inputmethod/dictionarypack/MetadataDbHelper.java b/java/src/com/android/inputmethod/dictionarypack/MetadataDbHelper.java
index c9e8f9118..db4315f8f 100644
--- a/java/src/com/android/inputmethod/dictionarypack/MetadataDbHelper.java
+++ b/java/src/com/android/inputmethod/dictionarypack/MetadataDbHelper.java
@@ -226,7 +226,7 @@ public class MetadataDbHelper extends SQLiteOpenHelper {
createClientTable(db);
}
- private void addRawChecksumColumnUnlessPresent(final SQLiteDatabase db) {
+ private static void addRawChecksumColumnUnlessPresent(final SQLiteDatabase db) {
try {
db.execSQL("SELECT " + RAW_CHECKSUM_COLUMN + " FROM "
+ METADATA_TABLE_NAME + " LIMIT 0;");
@@ -237,7 +237,7 @@ public class MetadataDbHelper extends SQLiteOpenHelper {
}
}
- private void addRetryCountColumnUnlessPresent(final SQLiteDatabase db) {
+ private static void addRetryCountColumnUnlessPresent(final SQLiteDatabase db) {
try {
db.execSQL("SELECT " + RETRY_COUNT_COLUMN + " FROM "
+ METADATA_TABLE_NAME + " LIMIT 0;");
diff --git a/java/src/com/android/inputmethod/dictionarypack/MetadataHandler.java b/java/src/com/android/inputmethod/dictionarypack/MetadataHandler.java
index 639d904a0..329b9f62e 100644
--- a/java/src/com/android/inputmethod/dictionarypack/MetadataHandler.java
+++ b/java/src/com/android/inputmethod/dictionarypack/MetadataHandler.java
@@ -30,9 +30,6 @@ import java.util.List;
* Helper class to easy up manipulation of dictionary pack metadata.
*/
public class MetadataHandler {
- @SuppressWarnings("unused")
- private static final String TAG = "DictionaryProvider:" + MetadataHandler.class.getSimpleName();
-
// The canonical file name for metadata. This is not the name of a real file on the
// device, but a symbolic name used in the database and in metadata handling. It is never
// tested against, only used for human-readability as the file name for the metadata.
diff --git a/java/src/com/android/inputmethod/dictionarypack/PrivateLog.java b/java/src/com/android/inputmethod/dictionarypack/PrivateLog.java
index 67dd7b9b7..bb64721d5 100644
--- a/java/src/com/android/inputmethod/dictionarypack/PrivateLog.java
+++ b/java/src/com/android/inputmethod/dictionarypack/PrivateLog.java
@@ -43,8 +43,8 @@ public class PrivateLog {
+ COLUMN_DATE + " TEXT,"
+ COLUMN_EVENT + " TEXT);";
- private static final SimpleDateFormat sDateFormat =
- new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.US);
+ static final SimpleDateFormat sDateFormat = new SimpleDateFormat(
+ "yyyy/MM/dd HH:mm:ss", Locale.ROOT);
private static PrivateLog sInstance = new PrivateLog();
private static DebugHelper sDebugHelper = null;
@@ -62,9 +62,9 @@ public class PrivateLog {
}
}
- private static class DebugHelper extends SQLiteOpenHelper {
+ static class DebugHelper extends SQLiteOpenHelper {
- private DebugHelper(final Context context) {
+ DebugHelper(final Context context) {
super(context, LOG_DATABASE_NAME, null, LOG_DATABASE_VERSION);
}
@@ -84,7 +84,7 @@ public class PrivateLog {
insert(db, "Upgrade finished");
}
- private static void insert(SQLiteDatabase db, String event) {
+ static void insert(SQLiteDatabase db, String event) {
if (!DEBUG) return;
final ContentValues c = new ContentValues(2);
c.put(COLUMN_DATE, sDateFormat.format(new Date(System.currentTimeMillis())));
diff --git a/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java b/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java
index 90a750493..d59b7a545 100644
--- a/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java
+++ b/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java
@@ -59,6 +59,8 @@ import java.util.Locale;
import java.util.Set;
import java.util.TreeSet;
+import javax.annotation.Nullable;
+
/**
* Handler for the update process.
*
@@ -750,19 +752,22 @@ public final class UpdateHandler {
* @return an ordered list of runnables to be called to upgrade.
*/
private static ActionBatch compareMetadataForUpgrade(final Context context,
- final String clientId, List<WordListMetadata> from, List<WordListMetadata> to) {
+ final String clientId, @Nullable final List<WordListMetadata> from,
+ @Nullable final List<WordListMetadata> to) {
final ActionBatch actions = new ActionBatch();
// Upgrade existing word lists
DebugLogUtils.l("Comparing dictionaries");
final Set<String> wordListIds = new TreeSet<>();
// TODO: Can these be null?
- if (null == from) from = new ArrayList<>();
- if (null == to) to = new ArrayList<>();
- for (WordListMetadata wlData : from) wordListIds.add(wlData.mId);
- for (WordListMetadata wlData : to) wordListIds.add(wlData.mId);
+ final List<WordListMetadata> fromList = (from == null) ? new ArrayList<WordListMetadata>()
+ : from;
+ final List<WordListMetadata> toList = (to == null) ? new ArrayList<WordListMetadata>()
+ : to;
+ for (WordListMetadata wlData : fromList) wordListIds.add(wlData.mId);
+ for (WordListMetadata wlData : toList) wordListIds.add(wlData.mId);
for (String id : wordListIds) {
- final WordListMetadata currentInfo = MetadataHandler.findWordListById(from, id);
- final WordListMetadata metadataInfo = MetadataHandler.findWordListById(to, id);
+ final WordListMetadata currentInfo = MetadataHandler.findWordListById(fromList, id);
+ final WordListMetadata metadataInfo = MetadataHandler.findWordListById(toList, id);
// TODO: Remove the following unnecessary check, since we are now doing the filtering
// inside findWordListById.
final WordListMetadata newInfo = null == metadataInfo
diff --git a/java/src/com/android/inputmethod/dictionarypack/WordListPreference.java b/java/src/com/android/inputmethod/dictionarypack/WordListPreference.java
index aea16af0d..500e39e0e 100644
--- a/java/src/com/android/inputmethod/dictionarypack/WordListPreference.java
+++ b/java/src/com/android/inputmethod/dictionarypack/WordListPreference.java
@@ -38,45 +38,39 @@ import java.util.Locale;
* enable or delete it as appropriate for the current state of the word list.
*/
public final class WordListPreference extends Preference {
- static final private String TAG = WordListPreference.class.getSimpleName();
+ private static final String TAG = WordListPreference.class.getSimpleName();
// What to display in the "status" field when we receive unknown data as a status from
// the content provider. Empty string sounds sensible.
- static final private String NO_STATUS_MESSAGE = "";
+ private static final String NO_STATUS_MESSAGE = "";
/// Actions
- static final private int ACTION_UNKNOWN = 0;
- static final private int ACTION_ENABLE_DICT = 1;
- static final private int ACTION_DISABLE_DICT = 2;
- static final private int ACTION_DELETE_DICT = 3;
+ private static final int ACTION_UNKNOWN = 0;
+ private static final int ACTION_ENABLE_DICT = 1;
+ private static final int ACTION_DISABLE_DICT = 2;
+ private static final int ACTION_DELETE_DICT = 3;
// Members
- // The context to get resources
- final Context mContext;
- // The id of the client for which this preference is.
- final String mClientId;
// The metadata word list id and version of this word list.
public final String mWordlistId;
public final int mVersion;
public final Locale mLocale;
public final String mDescription;
+
+ // The id of the client for which this preference is.
+ private final String mClientId;
// The status
private int mStatus;
// The size of the dictionary file
private final int mFilesize;
private final DictionaryListInterfaceState mInterfaceState;
- private final OnWordListPreferenceClick mPreferenceClickHandler =
- new OnWordListPreferenceClick();
- private final OnActionButtonClick mActionButtonClickHandler =
- new OnActionButtonClick();
public WordListPreference(final Context context,
final DictionaryListInterfaceState dictionaryListInterfaceState, final String clientId,
final String wordlistId, final int version, final Locale locale,
final String description, final int status, final int filesize) {
super(context, null);
- mContext = context;
mInterfaceState = dictionaryListInterfaceState;
mClientId = clientId;
mVersion = version;
@@ -116,22 +110,23 @@ public final class WordListPreference extends Preference {
}
private String getSummary(final int status) {
+ final Context context = getContext();
switch (status) {
- // If we are deleting the word list, for the user it's like it's already deleted.
- // It should be reinstallable. Exposing to the user the whole complexity of
- // the delayed deletion process between the dictionary pack and Android Keyboard
- // would only be confusing.
- case MetadataDbHelper.STATUS_DELETING:
- case MetadataDbHelper.STATUS_AVAILABLE:
- return mContext.getString(R.string.dictionary_available);
- case MetadataDbHelper.STATUS_DOWNLOADING:
- return mContext.getString(R.string.dictionary_downloading);
- case MetadataDbHelper.STATUS_INSTALLED:
- return mContext.getString(R.string.dictionary_installed);
- case MetadataDbHelper.STATUS_DISABLED:
- return mContext.getString(R.string.dictionary_disabled);
- default:
- return NO_STATUS_MESSAGE;
+ // If we are deleting the word list, for the user it's like it's already deleted.
+ // It should be reinstallable. Exposing to the user the whole complexity of
+ // the delayed deletion process between the dictionary pack and Android Keyboard
+ // would only be confusing.
+ case MetadataDbHelper.STATUS_DELETING:
+ case MetadataDbHelper.STATUS_AVAILABLE:
+ return context.getString(R.string.dictionary_available);
+ case MetadataDbHelper.STATUS_DOWNLOADING:
+ return context.getString(R.string.dictionary_downloading);
+ case MetadataDbHelper.STATUS_INSTALLED:
+ return context.getString(R.string.dictionary_installed);
+ case MetadataDbHelper.STATUS_DISABLED:
+ return context.getString(R.string.dictionary_disabled);
+ default:
+ return NO_STATUS_MESSAGE;
}
}
@@ -154,7 +149,7 @@ public final class WordListPreference extends Preference {
{ ButtonSwitcher.STATUS_INSTALL, ACTION_ENABLE_DICT }
};
- private int getButtonSwitcherStatus(final int status) {
+ static int getButtonSwitcherStatus(final int status) {
if (status >= sStatusActionList.length) {
Log.e(TAG, "Unknown status " + status);
return ButtonSwitcher.STATUS_NO_BUTTON;
@@ -162,7 +157,7 @@ public final class WordListPreference extends Preference {
return sStatusActionList[status][0];
}
- private static int getActionIdFromStatusAndMenuEntry(final int status) {
+ static int getActionIdFromStatusAndMenuEntry(final int status) {
if (status >= sStatusActionList.length) {
Log.e(TAG, "Unknown status " + status);
return ACTION_UNKNOWN;
@@ -171,9 +166,10 @@ public final class WordListPreference extends Preference {
}
private void disableDict() {
- SharedPreferences prefs = CommonPreferences.getCommonPreferences(mContext);
+ final Context context = getContext();
+ final SharedPreferences prefs = CommonPreferences.getCommonPreferences(context);
CommonPreferences.disable(prefs, mWordlistId);
- UpdateHandler.markAsUnused(mContext, mClientId, mWordlistId, mVersion, mStatus);
+ UpdateHandler.markAsUnused(context, mClientId, mWordlistId, mVersion, mStatus);
if (MetadataDbHelper.STATUS_DOWNLOADING == mStatus) {
setStatus(MetadataDbHelper.STATUS_AVAILABLE);
} else if (MetadataDbHelper.STATUS_INSTALLED == mStatus) {
@@ -184,11 +180,13 @@ public final class WordListPreference extends Preference {
Log.e(TAG, "Unexpected state of the word list for disabling " + mStatus);
}
}
+
private void enableDict() {
- SharedPreferences prefs = CommonPreferences.getCommonPreferences(mContext);
+ final Context context = getContext();
+ final SharedPreferences prefs = CommonPreferences.getCommonPreferences(context);
CommonPreferences.enable(prefs, mWordlistId);
// Explicit enabling by the user : allow downloading on metered data connection.
- UpdateHandler.markAsUsed(mContext, mClientId, mWordlistId, mVersion, mStatus, true);
+ UpdateHandler.markAsUsed(context, mClientId, mWordlistId, mVersion, mStatus, true);
if (MetadataDbHelper.STATUS_AVAILABLE == mStatus) {
setStatus(MetadataDbHelper.STATUS_DOWNLOADING);
} else if (MetadataDbHelper.STATUS_DISABLED == mStatus
@@ -203,11 +201,13 @@ public final class WordListPreference extends Preference {
Log.e(TAG, "Unexpected state of the word list for enabling " + mStatus);
}
}
+
private void deleteDict() {
- SharedPreferences prefs = CommonPreferences.getCommonPreferences(mContext);
+ final Context context = getContext();
+ final SharedPreferences prefs = CommonPreferences.getCommonPreferences(context);
CommonPreferences.disable(prefs, mWordlistId);
setStatus(MetadataDbHelper.STATUS_DELETING);
- UpdateHandler.markAsDeleting(mContext, mClientId, mWordlistId, mVersion, mStatus);
+ UpdateHandler.markAsDeleting(context, mClientId, mWordlistId, mVersion, mStatus);
}
@Override
@@ -225,8 +225,8 @@ public final class WordListPreference extends Preference {
status.setVisibility(showProgressBar ? View.INVISIBLE : View.VISIBLE);
progressBar.setVisibility(showProgressBar ? View.VISIBLE : View.INVISIBLE);
- final ButtonSwitcher buttonSwitcher =
- (ButtonSwitcher)view.findViewById(R.id.wordlist_button_switcher);
+ final ButtonSwitcher buttonSwitcher = (ButtonSwitcher)view.findViewById(
+ R.id.wordlist_button_switcher);
// We need to clear the state of the button switcher, because we reuse views; if we didn't
// reset it would animate from whatever its old state was.
buttonSwitcher.reset(mInterfaceState);
@@ -244,63 +244,67 @@ public final class WordListPreference extends Preference {
// The button is closed.
buttonSwitcher.setStatusAndUpdateVisuals(ButtonSwitcher.STATUS_NO_BUTTON);
}
- buttonSwitcher.setInternalOnClickListener(mActionButtonClickHandler);
- view.setOnClickListener(mPreferenceClickHandler);
+ buttonSwitcher.setInternalOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(final View v) {
+ onActionButtonClicked();
+ }
+ });
+ view.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(final View v) {
+ onWordListClicked(v);
+ }
+ });
}
- private class OnWordListPreferenceClick implements View.OnClickListener {
- @Override
- public void onClick(final View v) {
- // Note : v is the preference view
- final ViewParent parent = v.getParent();
- // Just in case something changed in the framework, test for the concrete class
- if (!(parent instanceof ListView)) return;
- final ListView listView = (ListView)parent;
- final int indexToOpen;
- // Close all first, we'll open back any item that needs to be open.
- final boolean wasOpen = mInterfaceState.isOpen(mWordlistId);
- mInterfaceState.closeAll();
- if (wasOpen) {
- // This button being shown. Take note that we don't want to open any button in the
- // loop below.
- indexToOpen = -1;
+ void onWordListClicked(final View v) {
+ // Note : v is the preference view
+ final ViewParent parent = v.getParent();
+ // Just in case something changed in the framework, test for the concrete class
+ if (!(parent instanceof ListView)) return;
+ final ListView listView = (ListView)parent;
+ final int indexToOpen;
+ // Close all first, we'll open back any item that needs to be open.
+ final boolean wasOpen = mInterfaceState.isOpen(mWordlistId);
+ mInterfaceState.closeAll();
+ if (wasOpen) {
+ // This button being shown. Take note that we don't want to open any button in the
+ // loop below.
+ indexToOpen = -1;
+ } else {
+ // This button was not being shown. Open it, and remember the index of this
+ // child as the one to open in the following loop.
+ mInterfaceState.setOpen(mWordlistId, mStatus);
+ indexToOpen = listView.indexOfChild(v);
+ }
+ final int lastDisplayedIndex =
+ listView.getLastVisiblePosition() - listView.getFirstVisiblePosition();
+ // The "lastDisplayedIndex" is actually displayed, hence the <=
+ for (int i = 0; i <= lastDisplayedIndex; ++i) {
+ final ButtonSwitcher buttonSwitcher = (ButtonSwitcher)listView.getChildAt(i)
+ .findViewById(R.id.wordlist_button_switcher);
+ if (i == indexToOpen) {
+ buttonSwitcher.setStatusAndUpdateVisuals(getButtonSwitcherStatus(mStatus));
} else {
- // This button was not being shown. Open it, and remember the index of this
- // child as the one to open in the following loop.
- mInterfaceState.setOpen(mWordlistId, mStatus);
- indexToOpen = listView.indexOfChild(v);
- }
- final int lastDisplayedIndex =
- listView.getLastVisiblePosition() - listView.getFirstVisiblePosition();
- // The "lastDisplayedIndex" is actually displayed, hence the <=
- for (int i = 0; i <= lastDisplayedIndex; ++i) {
- final ButtonSwitcher buttonSwitcher = (ButtonSwitcher)listView.getChildAt(i)
- .findViewById(R.id.wordlist_button_switcher);
- if (i == indexToOpen) {
- buttonSwitcher.setStatusAndUpdateVisuals(getButtonSwitcherStatus(mStatus));
- } else {
- buttonSwitcher.setStatusAndUpdateVisuals(ButtonSwitcher.STATUS_NO_BUTTON);
- }
+ buttonSwitcher.setStatusAndUpdateVisuals(ButtonSwitcher.STATUS_NO_BUTTON);
}
}
}
- private class OnActionButtonClick implements View.OnClickListener {
- @Override
- public void onClick(final View v) {
- switch (getActionIdFromStatusAndMenuEntry(mStatus)) {
- case ACTION_ENABLE_DICT:
- enableDict();
- break;
- case ACTION_DISABLE_DICT:
- disableDict();
- break;
- case ACTION_DELETE_DICT:
- deleteDict();
- break;
- default:
- Log.e(TAG, "Unknown menu item pressed");
- }
+ void onActionButtonClicked() {
+ switch (getActionIdFromStatusAndMenuEntry(mStatus)) {
+ case ACTION_ENABLE_DICT:
+ enableDict();
+ break;
+ case ACTION_DISABLE_DICT:
+ disableDict();
+ break;
+ case ACTION_DELETE_DICT:
+ deleteDict();
+ break;
+ default:
+ Log.e(TAG, "Unknown menu item pressed");
}
}
}