/** {@inheritDoc} */
@Override
public
long
interceptKeyBeforeDispatching(WindowState win, KeyEvent event,
int
policyFlags) {
:
:
}
else
if
(keyCode == KeyEvent.KEYCODE_ASSIST) {
if
(down) {
if
(repeatCount ==
0
) {
mAssistKeyLongPressed =
false
;
}
else
if
(repeatCount ==
1
) {
mAssistKeyLongPressed =
true
;
if
(!keyguardOn) {
launchAssistLongPressAction();
}
}
}
else
{
if
(mAssistKeyLongPressed) {
mAssistKeyLongPressed =
false
;
}
else
{
if
(!keyguardOn) {
launchAssistAction();
}
}
}
return
-
1
;
}
:
:
}
private
void
launchAssistLongPressAction() {
performHapticFeedbackLw(
null
, HapticFeedbackConstants.LONG_PRESS,
false
);
sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Intent intent =
new
Intent(Intent.ACTION_SEARCH_LONG_PRESS);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try
{
SearchManager searchManager = getSearchManager();
if
(searchManager !=
null
) {
searchManager.stopSearch();
}
mContext.startActivity(intent);
}
catch
(ActivityNotFoundException e) {
Slog.w(TAG,
"No activity to handle assist long press action."
, e);
}
}
private
void
launchAssistAction() {
sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Intent intent = SearchManager.getAssistIntent(mContext);
if
(intent !=
null
) {
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_SINGLE_TOP
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
try
{
mContext.startActivity(intent);
}
catch
(ActivityNotFoundException e) {
Slog.w(TAG,
"No activity to handle assist action."
, e);
}
}
}