Bug 1057390: Clear focus when keyboard is dismissed. r=margaret

This commit is contained in:
Eric Edens 2014-08-27 14:10:16 -05:00
parent 87d44388d2
commit 633f23c334
3 changed files with 38 additions and 1 deletions

View File

@ -0,0 +1,36 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.search.ui;
import android.content.Context;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.widget.EditText;
/**
* An EditText subclass that loses focus when the keyboard
* is dismissed.
*/
public class BackCaptureEditText extends EditText {
public BackCaptureEditText(Context context) {
super(context);
}
public BackCaptureEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}
public BackCaptureEditText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
clearFocus();
}
return super.onKeyPreIme(keyCode, event);
}
}

View File

@ -4,7 +4,7 @@
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<EditText
<org.mozilla.search.ui.BackCaptureEditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"

View File

@ -17,4 +17,5 @@ search_activity_sources = [
'java/org/mozilla/search/providers/SearchEngineManager.java',
'java/org/mozilla/search/SearchPreferenceActivity.java',
'java/org/mozilla/search/SearchWidget.java',
'java/org/mozilla/search/ui/BackCaptureEditText.java',
]