am 76f01118: Merge change 25362 into eclair
Merge commit '76f0111845f0886f522cfe1eb5ec1dee34181f7c' into eclair-plus-aosp * commit '76f0111845f0886f522cfe1eb5ec1dee34181f7c': Handle BACK key with focus in search ACTV correctly
This commit is contained in:
@@ -739,11 +739,6 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle back key to go back to previous searchable, etc.
|
|
||||||
if (handleBackKey(keyCode, event)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (keyCode == KeyEvent.KEYCODE_SEARCH) {
|
if (keyCode == KeyEvent.KEYCODE_SEARCH) {
|
||||||
// Consume search key for later use.
|
// Consume search key for later use.
|
||||||
return true;
|
return true;
|
||||||
@@ -756,8 +751,8 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
|
|||||||
launchQuerySearch(keyCode, actionKey.getQueryActionMsg());
|
launchQuerySearch(keyCode, actionKey.getQueryActionMsg());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return super.onKeyDown(keyCode, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -767,11 +762,6 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle back key to go back to previous searchable, etc.
|
|
||||||
if (handleBackKey(keyCode, event)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (keyCode == KeyEvent.KEYCODE_SEARCH && event.isTracking()
|
if (keyCode == KeyEvent.KEYCODE_SEARCH && event.isTracking()
|
||||||
&& !event.isCanceled()) {
|
&& !event.isCanceled()) {
|
||||||
// If the search key is pressed, toggle between global and in-app search. If we are
|
// If the search key is pressed, toggle between global and in-app search. If we are
|
||||||
@@ -779,8 +769,8 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
|
|||||||
// just don't do anything.
|
// just don't do anything.
|
||||||
return toggleGlobalSearch();
|
return toggleGlobalSearch();
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return super.onKeyUp(keyCode, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1487,6 +1477,13 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
|
|||||||
mSearchAutoComplete.setListSelection(index);
|
mSearchAutoComplete.setListSelection(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if there are any previous searchable components in the history stack.
|
||||||
|
*/
|
||||||
|
private boolean hasPreviousComponent() {
|
||||||
|
return mPreviousComponents != null && !mPreviousComponents.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the previous component that was searched, so that we can go
|
* Saves the previous component that was searched, so that we can go
|
||||||
* back to it.
|
* back to it.
|
||||||
@@ -1505,14 +1502,10 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
|
|||||||
* no previous component.
|
* no previous component.
|
||||||
*/
|
*/
|
||||||
private ComponentName popPreviousComponent() {
|
private ComponentName popPreviousComponent() {
|
||||||
if (mPreviousComponents == null) {
|
if (!hasPreviousComponent()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
int size = mPreviousComponents.size();
|
return mPreviousComponents.remove(mPreviousComponents.size() - 1);
|
||||||
if (size == 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return mPreviousComponents.remove(size - 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1520,25 +1513,22 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
|
|||||||
*
|
*
|
||||||
* @return <code>true</code> if there was a previous component that we could go back to.
|
* @return <code>true</code> if there was a previous component that we could go back to.
|
||||||
*/
|
*/
|
||||||
private boolean backToPreviousComponent(boolean doIt) {
|
private boolean backToPreviousComponent() {
|
||||||
ComponentName previous = popPreviousComponent();
|
ComponentName previous = popPreviousComponent();
|
||||||
if (previous == null) {
|
if (previous == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (doIt) {
|
if (!show(previous, mAppSearchData, false)) {
|
||||||
if (!show(previous, mAppSearchData, false)) {
|
Log.w(LOG_TAG, "Failed to switch to source " + previous);
|
||||||
Log.w(LOG_TAG, "Failed to switch to source " + previous);
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// must touch text to trigger suggestions
|
|
||||||
// TODO: should this be the text as it was when the user left
|
|
||||||
// the source that we are now going back to?
|
|
||||||
String query = mSearchAutoComplete.getText().toString();
|
|
||||||
setUserQuery(query);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// must touch text to trigger suggestions
|
||||||
|
// TODO: should this be the text as it was when the user left
|
||||||
|
// the source that we are now going back to?
|
||||||
|
String query = mSearchAutoComplete.getText().toString();
|
||||||
|
setUserQuery(query);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1763,74 +1753,49 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
|
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
|
||||||
|
if (DBG) Log.d(LOG_TAG, "onKeyPreIme(" + keyCode + "," + event + ")");
|
||||||
if (mSearchDialog.mSearchable == null) {
|
if (mSearchDialog.mSearchable == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||||
if (event.getAction() == KeyEvent.ACTION_DOWN
|
if (event.getAction() == KeyEvent.ACTION_DOWN
|
||||||
&& event.getRepeatCount() == 0) {
|
&& event.getRepeatCount() == 0) {
|
||||||
// We release the back key, might we want to do
|
if (mSearchDialog.hasPreviousComponent() || isDismissingKeyboardPointless()) {
|
||||||
// something before the IME?
|
|
||||||
if (mSearchDialog.backToPreviousComponent(false)) {
|
|
||||||
getKeyDispatcherState().startTracking(event, this);
|
getKeyDispatcherState().startTracking(event, this);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (isInputMethodNotNeeded() ||
|
|
||||||
(isEmpty() && getDropDownChildCount() >= getAdapterCount())) {
|
|
||||||
getKeyDispatcherState().startTracking(event, this);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false; // will dismiss soft keyboard if necessary
|
|
||||||
} else if (event.getAction() == KeyEvent.ACTION_UP
|
} else if (event.getAction() == KeyEvent.ACTION_UP
|
||||||
&& event.isTracking() && !event.isCanceled()) {
|
&& event.isTracking() && !event.isCanceled()) {
|
||||||
if (mSearchDialog.backToPreviousComponent(true)) {
|
if (mSearchDialog.backToPreviousComponent()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
} else if (isDismissingKeyboardPointless()) {
|
||||||
// If the drop-down obscures the keyboard, the user wouldn't see anything
|
|
||||||
// happening when pressing back, so we dismiss the entire dialog instead.
|
|
||||||
//
|
|
||||||
// also: if there is no text entered, we also want to dismiss the whole dialog,
|
|
||||||
// not just the soft keyboard. the exception to this is if there are shortcuts
|
|
||||||
// that aren't displayed (e.g are being obscured by the soft keyboard); in that
|
|
||||||
// case we want to dismiss the soft keyboard so the user can see the rest of the
|
|
||||||
// shortcuts.
|
|
||||||
if (isInputMethodNotNeeded() ||
|
|
||||||
(isEmpty() && getDropDownChildCount() >= getAdapterCount())) {
|
|
||||||
mSearchDialog.cancel();
|
mSearchDialog.cancel();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false; // will dismiss soft keyboard if necessary
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the drop-down obscures the keyboard, or if the drop-down shows all suggestions,
|
||||||
|
// dismissing the keyboard is pointless, so we dismiss the entire dialog instead.
|
||||||
|
private boolean isDismissingKeyboardPointless() {
|
||||||
|
return (isInputMethodNotNeeded() || getDropDownChildCount() >= getAdapterCount());
|
||||||
|
}
|
||||||
|
|
||||||
private int getAdapterCount() {
|
private int getAdapterCount() {
|
||||||
final ListAdapter adapter = getAdapter();
|
final ListAdapter adapter = getAdapter();
|
||||||
return adapter == null ? 0 : adapter.getCount();
|
return adapter == null ? 0 : adapter.getCount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean handleBackKey(int keyCode, KeyEvent event) {
|
@Override
|
||||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
public void onBackPressed() {
|
||||||
if (event.getAction() == KeyEvent.ACTION_DOWN
|
if (!backToPreviousComponent()) {
|
||||||
&& event.getRepeatCount() == 0) {
|
cancel();
|
||||||
// Consume the event, to get an up at which point we execute.
|
|
||||||
event.startTracking();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (event.getAction() == KeyEvent.ACTION_UP && event.isTracking()
|
|
||||||
&& !event.isCanceled()) {
|
|
||||||
if (backToPreviousComponent(true)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
cancel();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements OnItemClickListener
|
* Implements OnItemClickListener
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user