parent
fe39d576dc
commit
d73044a249
|
@ -0,0 +1,78 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
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.ImportantNoticeUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The dialog box that shows the important notice contents.
|
||||||
|
*/
|
||||||
|
public final class ImportantNoticeDialog extends AlertDialog implements OnShowListener,
|
||||||
|
OnClickListener, OnDismissListener {
|
||||||
|
public interface ImportantNoticeDialogListener {
|
||||||
|
public void onClickSettingsOfImportantNoticeDialog(final int nextVersion);
|
||||||
|
public void onDismissImportantNoticeDialog(final int nextVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final ImportantNoticeDialogListener mListener;
|
||||||
|
private final int mNextImportantNoticeVersion;
|
||||||
|
|
||||||
|
public ImportantNoticeDialog(
|
||||||
|
final Context context, final ImportantNoticeDialogListener listener) {
|
||||||
|
super(context, THEME_HOLO_DARK);
|
||||||
|
mListener = listener;
|
||||||
|
mNextImportantNoticeVersion = ImportantNoticeUtils.getNextImportantNoticeVersion(context);
|
||||||
|
setMessage(ImportantNoticeUtils.getNextImportantNoticeContents(context));
|
||||||
|
// Create buttons and set listeners.
|
||||||
|
setButton(BUTTON_POSITIVE, context.getString(android.R.string.ok), this);
|
||||||
|
if (shouldHaveSettingsButton()) {
|
||||||
|
setButton(BUTTON_NEGATIVE, context.getString(R.string.go_to_settings), this);
|
||||||
|
}
|
||||||
|
// Set listeners.
|
||||||
|
setOnShowListener(this);
|
||||||
|
setOnDismissListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean shouldHaveSettingsButton() {
|
||||||
|
return mNextImportantNoticeVersion
|
||||||
|
== ImportantNoticeUtils.VERSION_TO_ENABLE_PERSONALIZED_SUGGESTIONS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onShow(final DialogInterface dialog) {
|
||||||
|
ImportantNoticeUtils.updateLastImportantNoticeVersion(getContext());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(final DialogInterface dialog, final int which) {
|
||||||
|
if (shouldHaveSettingsButton() && which == BUTTON_NEGATIVE) {
|
||||||
|
mListener.onClickSettingsOfImportantNoticeDialog(mNextImportantNoticeVersion);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDismiss(final DialogInterface dialog) {
|
||||||
|
mListener.onDismissImportantNoticeDialog(mNextImportantNoticeVersion);
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,8 +26,6 @@ import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.DialogInterface.OnClickListener;
|
import android.content.DialogInterface.OnClickListener;
|
||||||
import android.content.DialogInterface.OnDismissListener;
|
|
||||||
import android.content.DialogInterface.OnShowListener;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
@ -100,7 +98,8 @@ import java.util.concurrent.TimeUnit;
|
||||||
*/
|
*/
|
||||||
public class LatinIME extends InputMethodService implements KeyboardActionListener,
|
public class LatinIME extends InputMethodService implements KeyboardActionListener,
|
||||||
SuggestionStripView.Listener, SuggestionStripViewAccessor,
|
SuggestionStripView.Listener, SuggestionStripViewAccessor,
|
||||||
DictionaryFacilitatorForSuggest.DictionaryInitializationListener {
|
DictionaryFacilitatorForSuggest.DictionaryInitializationListener,
|
||||||
|
ImportantNoticeDialog.ImportantNoticeDialogListener {
|
||||||
private static final String TAG = LatinIME.class.getSimpleName();
|
private static final String TAG = LatinIME.class.getSimpleName();
|
||||||
private static final boolean TRACE = false;
|
private static final boolean TRACE = false;
|
||||||
private static boolean DEBUG = false;
|
private static boolean DEBUG = false;
|
||||||
|
@ -1180,53 +1179,24 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
mInputLogic.mSuggest.mDictionaryFacilitator.addWordToUserDictionary(wordToEdit);
|
mInputLogic.mSuggest.mDictionaryFacilitator.addWordToUserDictionary(wordToEdit);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Move this method out of {@link LatinIME}.
|
|
||||||
// Callback for the {@link SuggestionStripView}, to call when the important notice strip is
|
// Callback for the {@link SuggestionStripView}, to call when the important notice strip is
|
||||||
// pressed.
|
// pressed.
|
||||||
@Override
|
@Override
|
||||||
public void showImportantNoticeContents() {
|
public void showImportantNoticeContents() {
|
||||||
final Context context = this;
|
showOptionDialog(new ImportantNoticeDialog(this /* context */, this /* listener */));
|
||||||
final AlertDialog.Builder builder =
|
}
|
||||||
new AlertDialog.Builder(context, AlertDialog.THEME_HOLO_DARK);
|
|
||||||
builder.setMessage(ImportantNoticeUtils.getNextImportantNoticeContents(context));
|
// Implement {@link ImportantNoticeDialog.ImportantNoticeDialogListener}
|
||||||
builder.setPositiveButton(android.R.string.ok, null /* listener */);
|
|
||||||
final int nextVersion = ImportantNoticeUtils.getNextImportantNoticeVersion(context);
|
|
||||||
final OnClickListener onClickListener = new OnClickListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(final DialogInterface dialog, final int position) {
|
public void onClickSettingsOfImportantNoticeDialog(final int nextVersion) {
|
||||||
switch (nextVersion) {
|
|
||||||
case ImportantNoticeUtils.VERSION_TO_ENABLE_PERSONALIZED_SUGGESTIONS:
|
|
||||||
if (position == DialogInterface.BUTTON_NEGATIVE) {
|
|
||||||
launchSettings();
|
launchSettings();
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
default:
|
// Implement {@link ImportantNoticeDialog.ImportantNoticeDialogListener}
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
switch (nextVersion) {
|
|
||||||
case ImportantNoticeUtils.VERSION_TO_ENABLE_PERSONALIZED_SUGGESTIONS:
|
|
||||||
builder.setNegativeButton(R.string.go_to_settings, onClickListener);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
final AlertDialog importantNoticeDialog = builder.create();
|
|
||||||
importantNoticeDialog.setOnShowListener(new OnShowListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onShow(final DialogInterface dialog) {
|
public void onDismissImportantNoticeDialog(final int nextVersion) {
|
||||||
ImportantNoticeUtils.updateLastImportantNoticeVersion(context);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
importantNoticeDialog.setOnDismissListener(new OnDismissListener() {
|
|
||||||
@Override
|
|
||||||
public void onDismiss(final DialogInterface dialog) {
|
|
||||||
setNeutralSuggestionStrip();
|
setNeutralSuggestionStrip();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
showOptionDialog(importantNoticeDialog);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void displaySettingsDialog() {
|
public void displaySettingsDialog() {
|
||||||
if (isShowingOptionDialog()) {
|
if (isShowingOptionDialog()) {
|
||||||
|
|
Loading…
Reference in New Issue