Java源码示例:org.chromium.chrome.browser.util.KeyNavigationUtil
示例1
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (KeyNavigationUtil.isGoDown(event)
&& mSuggestionList != null
&& mSuggestionList.isShown()) {
int suggestionCount = mSuggestionListAdapter.getCount();
if (mSuggestionList.getSelectedItemPosition() < suggestionCount - 1) {
if (suggestionCount > 0) mIgnoreOmniboxItemSelection = false;
} else {
// Do not pass down events when the last item is already selected as it will
// dismiss the suggestion list.
return true;
}
if (mSuggestionList.getSelectedItemPosition()
== ListView.INVALID_POSITION) {
// When clearing the selection after a text change, state is not reset
// correctly so hitting down again will cause it to start from the previous
// selection point. We still have to send the key down event to let the list
// view items take focus, but then we select the first item explicitly.
boolean result = mSuggestionList.onKeyDown(keyCode, event);
mSuggestionList.setSelection(0);
return result;
} else {
return mSuggestionList.onKeyDown(keyCode, event);
}
} else if (KeyNavigationUtil.isGoUp(event)
&& mSuggestionList != null
&& mSuggestionList.isShown()) {
if (mSuggestionList.getSelectedItemPosition() != 0
&& mSuggestionListAdapter.getCount() > 0) {
mIgnoreOmniboxItemSelection = false;
}
return mSuggestionList.onKeyDown(keyCode, event);
} else if (KeyNavigationUtil.isGoRight(event)
&& mSuggestionList != null
&& mSuggestionList.isShown()
&& mSuggestionList.getSelectedItemPosition()
!= ListView.INVALID_POSITION) {
OmniboxResultItem selectedItem =
(OmniboxResultItem) mSuggestionListAdapter.getItem(
mSuggestionList.getSelectedItemPosition());
// Set the UrlBar text to empty, so that it will trigger a text change when we
// set the text to the suggestion again.
setUrlBarText("", null);
mUrlBar.setText(selectedItem.getSuggestion().getFillIntoEdit());
mSuggestionList.setSelection(0);
mUrlBar.setSelection(mUrlBar.getText().length());
return true;
} else if (KeyNavigationUtil.isEnter(event)
&& LocationBarLayout.this.getVisibility() == VISIBLE) {
UiUtils.hideKeyboard(mUrlBar);
mSuggestionSelectionInProgress = true;
final String urlText = mUrlBar.getQueryText();
if (mNativeInitialized) {
findMatchAndLoadUrl(urlText);
} else {
mDeferredNativeRunnables.add(new Runnable() {
@Override
public void run() {
findMatchAndLoadUrl(urlText);
}
});
}
return true;
}
return false;
}
示例2
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (KeyNavigationUtil.isGoDown(event)
&& mSuggestionList != null
&& mSuggestionList.isShown()) {
int suggestionCount = mSuggestionListAdapter.getCount();
if (mSuggestionList.getSelectedItemPosition() < suggestionCount - 1) {
if (suggestionCount > 0) mIgnoreOmniboxItemSelection = false;
} else {
// Do not pass down events when the last item is already selected as it will
// dismiss the suggestion list.
return true;
}
if (mSuggestionList.getSelectedItemPosition()
== ListView.INVALID_POSITION) {
// When clearing the selection after a text change, state is not reset
// correctly so hitting down again will cause it to start from the previous
// selection point. We still have to send the key down event to let the list
// view items take focus, but then we select the first item explicitly.
boolean result = mSuggestionList.onKeyDown(keyCode, event);
mSuggestionList.setSelection(0);
return result;
} else {
return mSuggestionList.onKeyDown(keyCode, event);
}
} else if (KeyNavigationUtil.isGoUp(event)
&& mSuggestionList != null
&& mSuggestionList.isShown()) {
if (mSuggestionList.getSelectedItemPosition() != 0
&& mSuggestionListAdapter.getCount() > 0) {
mIgnoreOmniboxItemSelection = false;
}
return mSuggestionList.onKeyDown(keyCode, event);
} else if (KeyNavigationUtil.isGoRight(event)
&& mSuggestionList != null
&& mSuggestionList.isShown()
&& mSuggestionList.getSelectedItemPosition()
!= ListView.INVALID_POSITION) {
OmniboxResultItem selectedItem =
(OmniboxResultItem) mSuggestionListAdapter.getItem(
mSuggestionList.getSelectedItemPosition());
// Set the UrlBar text to empty, so that it will trigger a text change when we
// set the text to the suggestion again.
setUrlBarText("", null);
mUrlBar.setText(selectedItem.getSuggestion().getFillIntoEdit());
mSuggestionList.setSelection(0);
mUrlBar.setSelection(mUrlBar.getText().length());
return true;
} else if (KeyNavigationUtil.isEnter(event)
&& LocationBarLayout.this.getVisibility() == VISIBLE) {
UiUtils.hideKeyboard(mUrlBar);
mSuggestionSelectionInProgress = true;
final String urlText = mUrlBar.getQueryText();
if (mNativeInitialized) {
findMatchAndLoadUrl(urlText);
} else {
mDeferredNativeRunnables.add(new Runnable() {
@Override
public void run() {
findMatchAndLoadUrl(urlText);
}
});
}
return true;
} else if (keyCode == KeyEvent.KEYCODE_BACK) {
if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
// Tell the framework to start tracking this event.
getKeyDispatcherState().startTracking(event, this);
return true;
} else if (event.getAction() == KeyEvent.ACTION_UP) {
getKeyDispatcherState().handleUpEvent(event);
if (event.isTracking() && !event.isCanceled()) {
backKeyPressed();
return true;
}
}
} else if (keyCode == KeyEvent.KEYCODE_ESCAPE) {
if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
revertChanges();
return true;
}
}
return false;
}
示例3
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (KeyNavigationUtil.isGoDown(event)
&& mSuggestionList != null
&& mSuggestionList.isShown()) {
int suggestionCount = mSuggestionListAdapter.getCount();
if (mSuggestionList.getSelectedItemPosition() < suggestionCount - 1) {
if (suggestionCount > 0) mIgnoreOmniboxItemSelection = false;
} else {
// Do not pass down events when the last item is already selected as it will
// dismiss the suggestion list.
return true;
}
if (mSuggestionList.getSelectedItemPosition()
== ListView.INVALID_POSITION) {
// When clearing the selection after a text change, state is not reset
// correctly so hitting down again will cause it to start from the previous
// selection point. We still have to send the key down event to let the list
// view items take focus, but then we select the first item explicitly.
boolean result = mSuggestionList.onKeyDown(keyCode, event);
mSuggestionList.setSelection(0);
return result;
} else {
return mSuggestionList.onKeyDown(keyCode, event);
}
} else if (KeyNavigationUtil.isGoUp(event)
&& mSuggestionList != null
&& mSuggestionList.isShown()) {
if (mSuggestionList.getSelectedItemPosition() != 0
&& mSuggestionListAdapter.getCount() > 0) {
mIgnoreOmniboxItemSelection = false;
}
return mSuggestionList.onKeyDown(keyCode, event);
} else if (KeyNavigationUtil.isGoRight(event)
&& mSuggestionList != null
&& mSuggestionList.isShown()
&& mSuggestionList.getSelectedItemPosition()
!= ListView.INVALID_POSITION) {
OmniboxResultItem selectedItem =
(OmniboxResultItem) mSuggestionListAdapter.getItem(
mSuggestionList.getSelectedItemPosition());
// Set the UrlBar text to empty, so that it will trigger a text change when we
// set the text to the suggestion again.
setUrlBarText("", null);
mUrlBar.setText(selectedItem.getSuggestion().getFillIntoEdit());
mSuggestionList.setSelection(0);
mUrlBar.setSelection(mUrlBar.getText().length());
return true;
} else if (KeyNavigationUtil.isEnter(event)
&& LocationBarLayout.this.getVisibility() == VISIBLE) {
UiUtils.hideKeyboard(mUrlBar);
mSuggestionSelectionInProgress = true;
final String urlText = mUrlBar.getTextWithAutocomplete();
if (mNativeInitialized) {
findMatchAndLoadUrl(urlText);
} else {
mDeferredNativeRunnables.add(new Runnable() {
@Override
public void run() {
findMatchAndLoadUrl(urlText);
}
});
}
return true;
} else if (keyCode == KeyEvent.KEYCODE_BACK) {
if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
// Tell the framework to start tracking this event.
getKeyDispatcherState().startTracking(event, this);
return true;
} else if (event.getAction() == KeyEvent.ACTION_UP) {
getKeyDispatcherState().handleUpEvent(event);
if (event.isTracking() && !event.isCanceled()) {
backKeyPressed();
return true;
}
}
} else if (keyCode == KeyEvent.KEYCODE_ESCAPE) {
if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
revertChanges();
return true;
}
}
return false;
}