Merge "Fix 6414061: Add new ACTION_ASSIST intent." into jb-dev

This commit is contained in:
Jim Miller
2012-05-04 14:12:41 -07:00
committed by Android (Google) Code Review
5 changed files with 60 additions and 24 deletions

View File

@@ -5661,6 +5661,7 @@ package android.content {
field public static final java.lang.String ACTION_ALL_APPS = "android.intent.action.ALL_APPS";
field public static final java.lang.String ACTION_ANSWER = "android.intent.action.ANSWER";
field public static final java.lang.String ACTION_APP_ERROR = "android.intent.action.APP_ERROR";
field public static final java.lang.String ACTION_ASSIST = "android.intent.action.ASSIST";
field public static final java.lang.String ACTION_ATTACH_DATA = "android.intent.action.ATTACH_DATA";
field public static final java.lang.String ACTION_BATTERY_CHANGED = "android.intent.action.BATTERY_CHANGED";
field public static final java.lang.String ACTION_BATTERY_LOW = "android.intent.action.BATTERY_LOW";

View File

@@ -1098,6 +1098,14 @@ public class Intent implements Parcelable, Cloneable {
*/
@SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
public static final String ACTION_WEB_SEARCH = "android.intent.action.WEB_SEARCH";
/**
* Activity Action: Perform assist action.
* <p>
* Input: nothing
* Output: nothing.
*/
@SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
public static final String ACTION_ASSIST = "android.intent.action.ASSIST";
/**
* Activity Action: List all available applications
* <p>Input: Nothing.

View File

@@ -52,7 +52,6 @@ public class SearchPanelView extends FrameLayout implements
private boolean mShowing;
private View mSearchTargetsContainer;
private MultiWaveView mMultiWaveView;
private SearchManager mSearchManager;
public SearchPanelView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
@@ -67,10 +66,30 @@ public class SearchPanelView extends FrameLayout implements
}
}
public boolean isSearchAvailable() {
private SearchManager mSearchManager;
public boolean isAssistantAvailable() {
return mSearchManager != null && mSearchManager.getGlobalSearchActivity() != null;
}
private void startAssistActivity() {
if (mSearchManager != null) {
ComponentName globalSearchActivity = mSearchManager.getGlobalSearchActivity();
if (globalSearchActivity != null) {
Intent intent = new Intent(Intent.ACTION_ASSIST);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setPackage(globalSearchActivity.getPackageName());
try {
mContext.startActivity(intent);
} catch (ActivityNotFoundException e) {
Slog.w(TAG, "Activity not found for " + intent.getAction());
}
} else {
Slog.w(TAG, "No global search activity");
}
}
}
final MultiWaveView.OnTriggerListener mMultiWaveViewListener
= new MultiWaveView.OnTriggerListener() {
@@ -90,29 +109,11 @@ public class SearchPanelView extends FrameLayout implements
final int resId = mMultiWaveView.getResourceIdForTarget(target);
switch (resId) {
case com.android.internal.R.drawable.ic_lockscreen_search:
startGlobalSearch();
startAssistActivity();
break;
}
mBar.hideSearchPanel();
}
private void startGlobalSearch() {
if (mSearchManager != null) {
ComponentName globalSearchActivity = mSearchManager.getGlobalSearchActivity();
if (globalSearchActivity != null) {
Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setComponent(globalSearchActivity);
try {
mContext.startActivity(intent);
} catch (ActivityNotFoundException e) {
Slog.w(TAG, "Application not found for action " + intent.getAction());
}
} else {
Slog.w(TAG, "No global search activity");
}
}
}
};
@Override

View File

@@ -397,7 +397,7 @@ public abstract class BaseStatusBar extends SystemUI implements
break;
case MSG_OPEN_SEARCH_PANEL:
if (DEBUG) Slog.d(TAG, "opening search panel");
if (mSearchPanelView != null && mSearchPanelView.isSearchAvailable()) {
if (mSearchPanelView != null && mSearchPanelView.isAssistantAvailable()) {
mSearchPanelView.show(true, true);
}
break;

View File

@@ -29,6 +29,7 @@ import android.app.ActivityManager;
import android.app.ActivityManagerNative;
import android.app.SearchManager;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
@@ -38,8 +39,8 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import android.speech.RecognizerIntent;
import android.util.Log;
import android.util.Slog;
import android.media.AudioManager;
import android.os.RemoteException;
import android.provider.MediaStore;
@@ -80,6 +81,7 @@ class LockScreen extends LinearLayout implements KeyguardScreen {
private View mUnlockWidget;
private boolean mCameraDisabled;
private boolean mSearchDisabled;
private SearchManager mSearchManager;
InfoCallbackImpl mInfoCallback = new InfoCallbackImpl() {
@@ -237,6 +239,25 @@ class LockScreen extends LinearLayout implements KeyguardScreen {
}
}
private Intent getAssistIntent() {
Intent intent = null;
if (mSearchManager == null) {
mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
}
if (mSearchManager != null) {
ComponentName globalSearchActivity = mSearchManager.getGlobalSearchActivity();
if (globalSearchActivity != null) {
intent = new Intent(Intent.ACTION_ASSIST);
intent.setPackage(globalSearchActivity.getPackageName());
} else {
Slog.w(TAG, "No global search activity");
}
} else {
Slog.w(TAG, "No SearchManager");
}
return intent;
}
class MultiWaveViewMethods implements MultiWaveView.OnTriggerListener,
UnlockWidgetCommonMethods {
private final MultiWaveView mMultiWaveView;
@@ -279,7 +300,12 @@ class LockScreen extends LinearLayout implements KeyguardScreen {
final int resId = mMultiWaveView.getResourceIdForTarget(target);
switch (resId) {
case com.android.internal.R.drawable.ic_lockscreen_search:
launchActivity(new Intent(RecognizerIntent.ACTION_WEB_SEARCH));
Intent assistIntent = getAssistIntent();
if (assistIntent != null) {
launchActivity(assistIntent);
} else {
Log.w(TAG, "Failed to get intent for assist activity");
}
mCallback.pokeWakelock();
break;