diff --git a/java/src/com/android/inputmethod/latin/ImportantNoticeDialog.java b/java/src/com/android/inputmethod/latin/ImportantNoticeDialog.java index be54b669b..567087c81 100644 --- a/java/src/com/android/inputmethod/latin/ImportantNoticeDialog.java +++ b/java/src/com/android/inputmethod/latin/ImportantNoticeDialog.java @@ -20,8 +20,6 @@ import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; -import android.content.DialogInterface.OnDismissListener; -import android.content.DialogInterface.OnShowListener; import com.android.inputmethod.latin.utils.DialogUtils; import com.android.inputmethod.latin.utils.ImportantNoticeUtils; @@ -29,11 +27,10 @@ import com.android.inputmethod.latin.utils.ImportantNoticeUtils; /** * The dialog box that shows the important notice contents. */ -public final class ImportantNoticeDialog extends AlertDialog implements OnShowListener, - OnClickListener, OnDismissListener { +public final class ImportantNoticeDialog extends AlertDialog implements OnClickListener { public interface ImportantNoticeDialogListener { + public void onUserAcknowledgmentOfImportantNoticeDialog(final int nextVersion); public void onClickSettingsOfImportantNoticeDialog(final int nextVersion); - public void onDismissImportantNoticeDialog(final int nextVersion); } private final ImportantNoticeDialogListener mListener; @@ -50,9 +47,9 @@ public final class ImportantNoticeDialog extends AlertDialog implements OnShowLi if (shouldHaveSettingsButton()) { setButton(BUTTON_NEGATIVE, context.getString(R.string.go_to_settings), this); } - // Set listeners. - setOnShowListener(this); - setOnDismissListener(this); + // This dialog is cancelable by pressing back key. See {@link #onBackPress()}. + setCancelable(true /* cancelable */); + setCanceledOnTouchOutside(false /* cancelable */); } private boolean shouldHaveSettingsButton() { @@ -60,9 +57,9 @@ public final class ImportantNoticeDialog extends AlertDialog implements OnShowLi == ImportantNoticeUtils.VERSION_TO_ENABLE_PERSONALIZED_SUGGESTIONS; } - @Override - public void onShow(final DialogInterface dialog) { + private void userAcknowledged() { ImportantNoticeUtils.updateLastImportantNoticeVersion(getContext()); + mListener.onUserAcknowledgmentOfImportantNoticeDialog(mNextImportantNoticeVersion); } @Override @@ -70,10 +67,12 @@ public final class ImportantNoticeDialog extends AlertDialog implements OnShowLi if (shouldHaveSettingsButton() && which == BUTTON_NEGATIVE) { mListener.onClickSettingsOfImportantNoticeDialog(mNextImportantNoticeVersion); } + userAcknowledged(); } @Override - public void onDismiss(final DialogInterface dialog) { - mListener.onDismissImportantNoticeDialog(mNextImportantNoticeVersion); + public void onBackPressed() { + super.onBackPressed(); + userAcknowledged(); } } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 059f36288..84558ca24 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -657,9 +657,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mInputLogic.commitTyped(mSettings.getCurrent(), LastComposedWord.NOT_A_SEPARATOR); mInputLogic.mConnection.finishComposingText(); mInputLogic.mConnection.endBatchEdit(); - if (isShowingOptionDialog()) { - mOptionsDialog.dismiss(); - } } PersonalizationDictionarySessionRegistrar.onConfigurationChanged(this, conf, mInputLogic.mSuggest.mDictionaryFacilitator); @@ -990,7 +987,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } if (TRACE) Debug.stopMethodTracing(); - if (mOptionsDialog != null && mOptionsDialog.isShowing()) { + if (isShowingOptionDialog()) { mOptionsDialog.dismiss(); mOptionsDialog = null; } @@ -1186,7 +1183,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // Implement {@link ImportantNoticeDialog.ImportantNoticeDialogListener} @Override - public void onDismissImportantNoticeDialog(final int nextVersion) { + public void onUserAcknowledgmentOfImportantNoticeDialog(final int nextVersion) { setNeutralSuggestionStrip(); } @@ -1694,7 +1691,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen final AlertDialog.Builder builder = new AlertDialog.Builder( DialogUtils.getPlatformDialogThemeContext(this)); builder.setItems(items, listener).setTitle(title); - showOptionDialog(builder.create()); + final AlertDialog dialog = builder.create(); + dialog.setCancelable(true /* cancelable */); + dialog.setCanceledOnTouchOutside(true /* cancelable */); + showOptionDialog(dialog); } // TODO: Move this method out of {@link LatinIME}. @@ -1704,9 +1704,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen return; } - dialog.setCancelable(true /* cancelable */); - dialog.setCanceledOnTouchOutside(true /* cancelable */); - final Window window = dialog.getWindow(); final WindowManager.LayoutParams lp = window.getAttributes(); lp.token = windowToken;