aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorYohei Yukawa <yukawa@google.com>2017-09-01 19:56:14 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-09-01 19:56:14 +0000
commit9f14e616abb361e7c5d5e03a4a0e5ae03c04b422 (patch)
tree242d86f25e78005df7d28df3433ce50c9491aec7 /java/src
parent28faa6be017d11492cb03c65148d9508754217c0 (diff)
parentfdfc55d3db4c999c1510de20367bdd7ddbf497f8 (diff)
downloadlatinime-9f14e616abb361e7c5d5e03a4a0e5ae03c04b422.tar.gz
latinime-9f14e616abb361e7c5d5e03a4a0e5ae03c04b422.tar.xz
latinime-9f14e616abb361e7c5d5e03a4a0e5ae03c04b422.zip
Introduce a custom intent action to close software keyboard
am: fdfc55d3db Change-Id: I1609eb35be94c3f52870f2ca47e30bd2c66100aa
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java37
1 files changed, 37 insertions, 0 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 1764ded8c..00ed52cad 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -124,6 +124,18 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
static final long DELAY_DEALLOCATE_MEMORY_MILLIS = TimeUnit.SECONDS.toMillis(10);
/**
+ * A broadcast intent action to hide the software keyboard.
+ */
+ static final String ACTION_HIDE_SOFT_INPUT =
+ "com.android.inputmethod.latin.HIDE_SOFT_INPUT";
+
+ /**
+ * A custom permission for external apps to send {@link #ACTION_HIDE_SOFT_INPUT}.
+ */
+ static final String PERMISSION_HIDE_SOFT_INPUT =
+ "com.android.inputmethod.latin.HIDE_SOFT_INPUT";
+
+ /**
* The name of the scheme used by the Package Manager to warn of a new package installation,
* replacement or removal.
*/
@@ -160,6 +172,25 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private final BroadcastReceiver mDictionaryDumpBroadcastReceiver =
new DictionaryDumpBroadcastReceiver(this);
+ final static class HideSoftInputReceiver extends BroadcastReceiver {
+ private final InputMethodService mIms;
+
+ public HideSoftInputReceiver(InputMethodService ims) {
+ mIms = ims;
+ }
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ final String action = intent.getAction();
+ if (ACTION_HIDE_SOFT_INPUT.equals(action)) {
+ mIms.requestHideSelf(0 /* flags */);
+ } else {
+ Log.e(TAG, "Unexpected intent " + intent);
+ }
+ }
+ }
+ final HideSoftInputReceiver mHideSoftInputReceiver = new HideSoftInputReceiver(this);
+
private AlertDialog mOptionsDialog;
private final boolean mIsHardwareAcceleratedDrawingEnabled;
@@ -595,6 +626,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
dictDumpFilter.addAction(DictionaryDumpBroadcastReceiver.DICTIONARY_DUMP_INTENT_ACTION);
registerReceiver(mDictionaryDumpBroadcastReceiver, dictDumpFilter);
+ final IntentFilter hideSoftInputFilter = new IntentFilter();
+ hideSoftInputFilter.addAction(ACTION_HIDE_SOFT_INPUT);
+ registerReceiver(mHideSoftInputReceiver, hideSoftInputFilter, PERMISSION_HIDE_SOFT_INPUT,
+ null /* scheduler */);
+
StatsUtils.onCreate(mSettings.getCurrent(), mRichImm);
}
@@ -699,6 +735,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
public void onDestroy() {
mDictionaryFacilitator.closeDictionaries();
mSettings.onDestroy();
+ unregisterReceiver(mHideSoftInputReceiver);
unregisterReceiver(mRingerModeChangeReceiver);
unregisterReceiver(mDictionaryPackInstallReceiver);
unregisterReceiver(mDictionaryDumpBroadcastReceiver);