diff options
Diffstat (limited to 'java/src')
7 files changed, 84 insertions, 28 deletions
diff --git a/java/src/com/android/inputmethod/dictionarypack/ButtonSwitcher.java b/java/src/com/android/inputmethod/dictionarypack/ButtonSwitcher.java index 5ab94a429..c5aca174a 100644 --- a/java/src/com/android/inputmethod/dictionarypack/ButtonSwitcher.java +++ b/java/src/com/android/inputmethod/dictionarypack/ButtonSwitcher.java @@ -57,6 +57,11 @@ public class ButtonSwitcher extends FrameLayout { super(context, attrs, defStyle); } + public void reset() { + mStatus = NOT_INITIALIZED; + mAnimateToStatus = NOT_INITIALIZED; + } + @Override protected void onLayout(final boolean changed, final int left, final int top, final int right, final int bottom) { @@ -64,9 +69,7 @@ public class ButtonSwitcher extends FrameLayout { mInstallButton = (Button)findViewById(R.id.dict_install_button); mCancelButton = (Button)findViewById(R.id.dict_cancel_button); mDeleteButton = (Button)findViewById(R.id.dict_delete_button); - mInstallButton.setOnClickListener(mOnClickListener); - mCancelButton.setOnClickListener(mOnClickListener); - mDeleteButton.setOnClickListener(mOnClickListener); + setInternalOnClickListener(mOnClickListener); setButtonPositionWithoutAnimation(mStatus); if (mAnimateToStatus != NOT_INITIALIZED) { // We have been asked to animate before we were ready, so we took a note of it. @@ -139,6 +142,12 @@ public class ButtonSwitcher extends FrameLayout { public void setInternalOnClickListener(final OnClickListener listener) { mOnClickListener = listener; + if (null != mInstallButton) { + // Already laid out : do it now + mInstallButton.setOnClickListener(mOnClickListener); + mCancelButton.setOnClickListener(mOnClickListener); + mDeleteButton.setOnClickListener(mOnClickListener); + } } private ViewPropertyAnimator animateButton(final View button, final int direction) { diff --git a/java/src/com/android/inputmethod/dictionarypack/DictionaryListInterfaceState.java b/java/src/com/android/inputmethod/dictionarypack/DictionaryListInterfaceState.java index de3711c27..5ad5900d4 100644 --- a/java/src/com/android/inputmethod/dictionarypack/DictionaryListInterfaceState.java +++ b/java/src/com/android/inputmethod/dictionarypack/DictionaryListInterfaceState.java @@ -16,8 +16,11 @@ package com.android.inputmethod.dictionarypack; +import android.view.View; + import com.android.inputmethod.latin.CollectionUtils; +import java.util.ArrayList; import java.util.HashMap; /** @@ -37,6 +40,7 @@ public class DictionaryListInterfaceState { } private HashMap<String, State> mWordlistToState = CollectionUtils.newHashMap(); + private ArrayList<View> mViewCache = CollectionUtils.newArrayList(); public boolean isOpen(final String wordlistId) { final State state = mWordlistToState.get(wordlistId); @@ -64,4 +68,16 @@ public class DictionaryListInterfaceState { state.mOpen = false; } } + + public View findFirstOrphanedView() { + for (final View v : mViewCache) { + if (null == v.getParent()) return v; + } + return null; + } + + public View addToCacheAndReturnView(final View view) { + mViewCache.add(view); + return view; + } } diff --git a/java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java b/java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java index 618322357..1e93e7e7a 100644 --- a/java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java +++ b/java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java @@ -222,7 +222,9 @@ public final class DictionarySettingsFragment extends PreferenceFragment refreshNetworkState(); removeAnyDictSettings(prefScreen); + int i = 0; for (Preference preference : prefList) { + preference.setOrder(i++); prefScreen.addPreference(preference); } } diff --git a/java/src/com/android/inputmethod/dictionarypack/MetadataDbHelper.java b/java/src/com/android/inputmethod/dictionarypack/MetadataDbHelper.java index 03ed267c3..1511dbcfe 100644 --- a/java/src/com/android/inputmethod/dictionarypack/MetadataDbHelper.java +++ b/java/src/com/android/inputmethod/dictionarypack/MetadataDbHelper.java @@ -572,7 +572,8 @@ public class MetadataDbHelper extends SQLiteOpenHelper { * If several clients use the same metadata URL, we know to only download it once, and * dispatch the update process across all relevant clients when the download ends. This means * several clients may share a single download ID if they share a metadata URI. - * The dispatching is done in {@link UpdateHandler#downloadFinished(Context, Intent)}, which + * The dispatching is done in + * {@link UpdateHandler#downloadFinished(Context, android.content.Intent)}, which * finds out about the list of relevant clients by calling this method. * * @param context a context instance to open the databases @@ -863,17 +864,20 @@ public class MetadataDbHelper extends SQLiteOpenHelper { r.getAsString(WORDLISTID_COLUMN), Integer.toString(STATUS_INSTALLED) }, null, null, null); - if (c.moveToFirst()) { - // There should never be more than one file, but if there are, it's a bug - // and we should remove them all. I think it might happen if the power of the - // phone is suddenly cut during an update. - final int filenameIndex = c.getColumnIndex(LOCAL_FILENAME_COLUMN); - do { - Utils.l("Setting for removal", c.getString(filenameIndex)); - filenames.add(c.getString(filenameIndex)); - } while (c.moveToNext()); + try { + if (c.moveToFirst()) { + // There should never be more than one file, but if there are, it's a bug + // and we should remove them all. I think it might happen if the power of + // the phone is suddenly cut during an update. + final int filenameIndex = c.getColumnIndex(LOCAL_FILENAME_COLUMN); + do { + Utils.l("Setting for removal", c.getString(filenameIndex)); + filenames.add(c.getString(filenameIndex)); + } while (c.moveToNext()); + } + } finally { + c.close(); } - r.put(STATUS_COLUMN, STATUS_INSTALLED); db.beginTransactionNonExclusive(); // Delete all old entries. There should never be any stalled entries, but if diff --git a/java/src/com/android/inputmethod/dictionarypack/WordListPreference.java b/java/src/com/android/inputmethod/dictionarypack/WordListPreference.java index 451a0fb82..a1031c2ca 100644 --- a/java/src/com/android/inputmethod/dictionarypack/WordListPreference.java +++ b/java/src/com/android/inputmethod/dictionarypack/WordListPreference.java @@ -98,6 +98,14 @@ public final class WordListPreference extends Preference { setSummary(getSummary(status)); } + @Override + public View onCreateView(final ViewGroup parent) { + final View orphanedView = mInterfaceState.findFirstOrphanedView(); + if (null != orphanedView) return orphanedView; // Will be sent to onBindView + final View newView = super.onCreateView(parent); + return mInterfaceState.addToCacheAndReturnView(newView); + } + private String getSummary(final int status) { switch (status) { // If we are deleting the word list, for the user it's like it's already deleted. @@ -209,6 +217,9 @@ public final class WordListPreference extends Preference { 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(); if (mInterfaceState.isOpen(mWordlistId)) { // The button is open. final int previousStatus = mInterfaceState.getStatus(mWordlistId); diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java index a9b58de44..603e8d30d 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java @@ -32,6 +32,7 @@ import com.android.inputmethod.latin.DictionaryInfoUtils.DictionaryInfo; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; +import java.io.Closeable; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -319,20 +320,12 @@ public final class BinaryDictionaryFileDumper { // Try the next method. } finally { // Ignore exceptions while closing files. - try { - if (null != afd) afd.close(); - if (null != inputStream) inputStream.close(); - if (null != uncompressedStream) uncompressedStream.close(); - if (null != decryptedStream) decryptedStream.close(); - if (null != bufferedInputStream) bufferedInputStream.close(); - } catch (Exception e) { - Log.e(TAG, "Exception while closing a file descriptor", e); - } - try { - if (null != bufferedOutputStream) bufferedOutputStream.close(); - } catch (Exception e) { - Log.e(TAG, "Exception while closing a file", e); - } + closeAssetFileDescriptorAndReportAnyException(afd); + closeCloseableAndReportAnyException(inputStream); + closeCloseableAndReportAnyException(uncompressedStream); + closeCloseableAndReportAnyException(decryptedStream); + closeCloseableAndReportAnyException(bufferedInputStream); + closeCloseableAndReportAnyException(bufferedOutputStream); } } @@ -352,6 +345,26 @@ public final class BinaryDictionaryFileDumper { } } + // Ideally the two following methods should be merged, but AssetFileDescriptor does not + // implement Closeable although it does implement #close(), and Java does not have + // structural typing. + private static void closeAssetFileDescriptorAndReportAnyException( + final AssetFileDescriptor file) { + try { + if (null != file) file.close(); + } catch (Exception e) { + Log.e(TAG, "Exception while closing a file", e); + } + } + + private static void closeCloseableAndReportAnyException(final Closeable file) { + try { + if (null != file) file.close(); + } catch (Exception e) { + Log.e(TAG, "Exception while closing a file", e); + } + } + /** * Queries a content provider for word list data for some locale and cache the returned files * diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index cebc93c18..c9a42a3a4 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -855,6 +855,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } // Remove pending messages related to update suggestions mHandler.cancelUpdateSuggestionStrip(); + if (mWordComposer.isComposingWord()) mConnection.finishComposingText(); resetComposingState(true /* alsoResetLastComposedWord */); // Notify ResearchLogger if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { |