Search in sources :

Example 6 with SearchManager

use of android.app.SearchManager in project android_frameworks_base by ParanoidAndroid.

the class SearchManagerTest method testSearchManagerInvocations.

/**
     * The goal of this test is to confirm that we can start and then
     * stop a simple search.
     */
public void testSearchManagerInvocations() throws Exception {
    SearchManager searchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
    assertNotNull(searchManager);
    // These tests should simply run to completion w/o exceptions
    searchManager.startSearch(null, false, SEARCHABLE_ACTIVITY, null, false);
    searchManager.stopSearch();
    searchManager.startSearch("", false, SEARCHABLE_ACTIVITY, null, false);
    searchManager.stopSearch();
    searchManager.startSearch("test search string", false, SEARCHABLE_ACTIVITY, null, false);
    searchManager.stopSearch();
    searchManager.startSearch("test search string", true, SEARCHABLE_ACTIVITY, null, false);
    searchManager.stopSearch();
}
Also used : ISearchManager(android.app.ISearchManager) SearchManager(android.app.SearchManager)

Example 7 with SearchManager

use of android.app.SearchManager in project android_frameworks_base by ParanoidAndroid.

the class SearchPanelView method startAssistActivity.

private void startAssistActivity() {
    if (!mBar.isDeviceProvisioned())
        return;
    // Close Recent Apps if needed
    mBar.animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_SEARCH_PANEL);
    boolean isKeyguardShowing = false;
    try {
        isKeyguardShowing = mWm.isKeyguardLocked();
    } catch (RemoteException e) {
    }
    if (isKeyguardShowing) {
        // Have keyguard show the bouncer and launch the activity if the user succeeds.
        try {
            mWm.showAssistant();
        } catch (RemoteException e) {
        // too bad, so sad...
        }
        onAnimationStarted();
    } else {
        // Otherwise, keyguard isn't showing so launch it from here.
        Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE)).getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
        if (intent == null)
            return;
        try {
            ActivityManagerNative.getDefault().dismissKeyguardOnNextActivity();
        } catch (RemoteException e) {
        // too bad, so sad...
        }
        try {
            ActivityOptions opts = ActivityOptions.makeCustomAnimation(mContext, R.anim.search_launch_enter, R.anim.search_launch_exit, getHandler(), this);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            mContext.startActivityAsUser(intent, opts.toBundle(), new UserHandle(UserHandle.USER_CURRENT));
        } catch (ActivityNotFoundException e) {
            Slog.w(TAG, "Activity not found for " + intent.getAction());
            onAnimationStarted();
        }
    }
}
Also used : SearchManager(android.app.SearchManager) ActivityNotFoundException(android.content.ActivityNotFoundException) UserHandle(android.os.UserHandle) Intent(android.content.Intent) RemoteException(android.os.RemoteException) ActivityOptions(android.app.ActivityOptions)

Example 8 with SearchManager

use of android.app.SearchManager in project android_frameworks_base by ParanoidAndroid.

the class KeyguardSelectorView method updateResources.

public void updateResources() {
    // Update the search icon with drawable from the search .apk
    if (!mSearchDisabled) {
        Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE)).getAssistIntent(mContext, false, UserHandle.USER_CURRENT);
        if (intent != null) {
            // XXX Hack. We need to substitute the icon here but haven't formalized
            // the public API. The "_google" metadata will be going away, so
            // DON'T USE IT!
            ComponentName component = intent.getComponent();
            boolean replaced = mGlowPadView.replaceTargetDrawablesIfPresent(component, ASSIST_ICON_METADATA_NAME + "_google", com.android.internal.R.drawable.ic_action_assist_generic);
            if (!replaced && !mGlowPadView.replaceTargetDrawablesIfPresent(component, ASSIST_ICON_METADATA_NAME, com.android.internal.R.drawable.ic_action_assist_generic)) {
                Slog.w(TAG, "Couldn't grab icon from package " + component);
            }
        }
    }
    mGlowPadView.setEnableTarget(com.android.internal.R.drawable.ic_lockscreen_camera, !mCameraDisabled);
    mGlowPadView.setEnableTarget(com.android.internal.R.drawable.ic_action_assist_generic, !mSearchDisabled);
}
Also used : SearchManager(android.app.SearchManager) Intent(android.content.Intent) ComponentName(android.content.ComponentName)

Example 9 with SearchManager

use of android.app.SearchManager in project Fairphone by Kwamecorp.

the class LauncherTransitionable method updateVoiceSearchIcon.

private boolean updateVoiceSearchIcon(boolean searchVisible) {
    final View voiceButtonContainer = findViewById(R.id.voice_button_container);
    final View voiceButton = findViewById(R.id.voice_button);
    // We only show/update the voice search icon if the search icon is
    // enabled as well
    final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
    ComponentName activityName = null;
    if (globalSearchActivity != null) {
        // Check if the global search activity handles voice search
        Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
        intent.setPackage(globalSearchActivity.getPackageName());
        activityName = intent.resolveActivity(getPackageManager());
    }
    if (activityName == null) {
        // Fallback: check if an activity other than the global search
        // activity
        // resolves this
        Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
        activityName = intent.resolveActivity(getPackageManager());
    }
    if (searchVisible && activityName != null) {
        int coi = getCurrentOrientationIndexForGlobalIcons();
        sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo, TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
        if (sVoiceSearchIcon[coi] == null) {
            sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo, TOOLBAR_ICON_METADATA_NAME);
        }
        if (voiceButtonContainer != null)
            voiceButtonContainer.setVisibility(View.VISIBLE);
        voiceButton.setVisibility(View.VISIBLE);
        invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
        return true;
    } else {
        if (voiceButtonContainer != null)
            voiceButtonContainer.setVisibility(View.GONE);
        voiceButton.setVisibility(View.GONE);
        return false;
    }
}
Also used : SearchManager(android.app.SearchManager) ComponentName(android.content.ComponentName) Intent(android.content.Intent) RecognizerIntent(android.speech.RecognizerIntent) ImageView(android.widget.ImageView) AppWidgetHostView(android.appwidget.AppWidgetHostView) View(android.view.View) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint)

Example 10 with SearchManager

use of android.app.SearchManager in project Fairphone by Kwamecorp.

the class LauncherTransitionable method onClickVoiceButton.

/**
	 * Event handler for the voice button
	 * 
	 * @param v
	 *            The view that was clicked.
	 */
public void onClickVoiceButton(View v) {
    v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
    try {
        final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        ComponentName activityName = searchManager.getGlobalSearchActivity();
        Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (activityName != null) {
            intent.setPackage(activityName.getPackageName());
        }
        startActivity(null, intent, "onClickVoiceButton");
    } catch (ActivityNotFoundException e) {
        Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivitySafely(null, intent, "onClickVoiceButton");
    }
}
Also used : SearchManager(android.app.SearchManager) ActivityNotFoundException(android.content.ActivityNotFoundException) ComponentName(android.content.ComponentName) Intent(android.content.Intent) RecognizerIntent(android.speech.RecognizerIntent)

Aggregations

SearchManager (android.app.SearchManager)99 Intent (android.content.Intent)31 ISearchManager (android.app.ISearchManager)26 ActivityNotFoundException (android.content.ActivityNotFoundException)20 ComponentName (android.content.ComponentName)20 Bundle (android.os.Bundle)14 RecognizerIntent (android.speech.RecognizerIntent)12 SearchView (android.support.v7.widget.SearchView)12 MenuItem (android.view.MenuItem)12 UserHandle (android.os.UserHandle)10 View (android.view.View)9 ImageView (android.widget.ImageView)8 SearchView (android.widget.SearchView)8 TextView (android.widget.TextView)8 ActivityOptions (android.app.ActivityOptions)7 LargeTest (android.test.suitebuilder.annotation.LargeTest)6 AppWidgetHostView (android.appwidget.AppWidgetHostView)5 PackageManager (android.content.pm.PackageManager)5 ResolveInfo (android.content.pm.ResolveInfo)5 MenuInflater (android.view.MenuInflater)5