Introduce a custom intent action to close software keyboard
am: fdfc55d3db
Change-Id: I1609eb35be94c3f52870f2ca47e30bd2c66100aa
main
commit
9f14e616ab
|
@ -35,6 +35,23 @@
|
||||||
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
|
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
|
||||||
<uses-permission android:name="android.permission.WRITE_USER_DICTIONARY" />
|
<uses-permission android:name="android.permission.WRITE_USER_DICTIONARY" />
|
||||||
|
|
||||||
|
<!-- A signature-protected permission to ask AOSP Keyboard to close the software keyboard.
|
||||||
|
To use this, add the following line into calling application's AndroidManifest.xml
|
||||||
|
<pre>
|
||||||
|
{@code
|
||||||
|
<uses-permission android:name="com.android.inputmethod.latin.HIDE_SOFT_INPUT"/>
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
|
then call {@link android.content.Context#sendBroadcast(Intent)} as follows:
|
||||||
|
<pre>
|
||||||
|
{@code
|
||||||
|
sendBroadcast(new Intent("com.android.inputmethod.latin.HIDE_SOFT_INPUT")
|
||||||
|
.setPackage("com.android.inputmethod.latin"));
|
||||||
|
}
|
||||||
|
</pre> -->
|
||||||
|
<permission android:name="com.android.inputmethod.latin.HIDE_SOFT_INPUT"
|
||||||
|
android:protectionLevel="signature" />
|
||||||
|
|
||||||
<application android:label="@string/english_ime_name"
|
<application android:label="@string/english_ime_name"
|
||||||
android:icon="@drawable/ic_launcher_keyboard"
|
android:icon="@drawable/ic_launcher_keyboard"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
|
|
|
@ -123,6 +123,18 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
static final long DELAY_WAIT_FOR_DICTIONARY_LOAD_MILLIS = TimeUnit.SECONDS.toMillis(2);
|
static final long DELAY_WAIT_FOR_DICTIONARY_LOAD_MILLIS = TimeUnit.SECONDS.toMillis(2);
|
||||||
static final long DELAY_DEALLOCATE_MEMORY_MILLIS = TimeUnit.SECONDS.toMillis(10);
|
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,
|
* The name of the scheme used by the Package Manager to warn of a new package installation,
|
||||||
* replacement or removal.
|
* replacement or removal.
|
||||||
|
@ -160,6 +172,25 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
private final BroadcastReceiver mDictionaryDumpBroadcastReceiver =
|
private final BroadcastReceiver mDictionaryDumpBroadcastReceiver =
|
||||||
new DictionaryDumpBroadcastReceiver(this);
|
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 AlertDialog mOptionsDialog;
|
||||||
|
|
||||||
private final boolean mIsHardwareAcceleratedDrawingEnabled;
|
private final boolean mIsHardwareAcceleratedDrawingEnabled;
|
||||||
|
@ -595,6 +626,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
dictDumpFilter.addAction(DictionaryDumpBroadcastReceiver.DICTIONARY_DUMP_INTENT_ACTION);
|
dictDumpFilter.addAction(DictionaryDumpBroadcastReceiver.DICTIONARY_DUMP_INTENT_ACTION);
|
||||||
registerReceiver(mDictionaryDumpBroadcastReceiver, dictDumpFilter);
|
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);
|
StatsUtils.onCreate(mSettings.getCurrent(), mRichImm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -699,6 +735,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
mDictionaryFacilitator.closeDictionaries();
|
mDictionaryFacilitator.closeDictionaries();
|
||||||
mSettings.onDestroy();
|
mSettings.onDestroy();
|
||||||
|
unregisterReceiver(mHideSoftInputReceiver);
|
||||||
unregisterReceiver(mRingerModeChangeReceiver);
|
unregisterReceiver(mRingerModeChangeReceiver);
|
||||||
unregisterReceiver(mDictionaryPackInstallReceiver);
|
unregisterReceiver(mDictionaryPackInstallReceiver);
|
||||||
unregisterReceiver(mDictionaryDumpBroadcastReceiver);
|
unregisterReceiver(mDictionaryDumpBroadcastReceiver);
|
||||||
|
|
Loading…
Reference in New Issue