Search in sources :

Example 96 with SearchManager

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

the class PhoneWindow method launchDefaultSearch.

/**
     * Helper method for adding launch-search to most applications. Opens the
     * search window using default settings.
     *
     * @return true if search window opened
     */
private boolean launchDefaultSearch(KeyEvent event) {
    boolean result;
    final Callback cb = getCallback();
    if (cb == null || isDestroyed()) {
        result = false;
    } else {
        sendCloseSystemWindows("search");
        int deviceId = event.getDeviceId();
        SearchEvent searchEvent = null;
        if (deviceId != 0) {
            searchEvent = new SearchEvent(InputDevice.getDevice(deviceId));
        }
        try {
            result = cb.onSearchRequested(searchEvent);
        } catch (AbstractMethodError e) {
            Log.e(TAG, "WindowCallback " + cb.getClass().getName() + " does not implement" + " method onSearchRequested(SearchEvent); fa", e);
            result = cb.onSearchRequested();
        }
    }
    if (!result && (getContext().getResources().getConfiguration().uiMode & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) {
        // On TVs, if the app doesn't implement search, we want to launch assist.
        Bundle args = new Bundle();
        args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, event.getDeviceId());
        return ((SearchManager) getContext().getSystemService(Context.SEARCH_SERVICE)).launchLegacyAssist(null, UserHandle.myUserId(), args);
    }
    return result;
}
Also used : SearchManager(android.app.SearchManager) Bundle(android.os.Bundle) SearchEvent(android.view.SearchEvent)

Example 97 with SearchManager

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

the class Action method processActionWithOptions.

public static void processActionWithOptions(Context context, String action, boolean isLongpress, boolean collapseShade) {
    if (action == null || action.equals(ActionConstants.ACTION_NULL)) {
        return;
    }
    boolean isKeyguardShowing = false;
    try {
        isKeyguardShowing = WindowManagerGlobal.getWindowManagerService().isKeyguardLocked();
    } catch (RemoteException e) {
        Log.w("Action", "Error getting window manager service", e);
    }
    // process the actions
    if (action.equals(ActionConstants.ACTION_HOME)) {
        triggerVirtualKeypress(KeyEvent.KEYCODE_HOME, isLongpress);
        return;
    } else if (action.equals(ActionConstants.ACTION_BACK)) {
        triggerVirtualKeypress(KeyEvent.KEYCODE_BACK, isLongpress);
        return;
    } else if (action.equals(ActionConstants.ACTION_SEARCH)) {
        triggerVirtualKeypress(KeyEvent.KEYCODE_SEARCH, isLongpress);
        return;
    } else if (action.equals(ActionConstants.ACTION_MENU) || action.equals(ActionConstants.ACTION_MENU_BIG)) {
        triggerVirtualKeypress(KeyEvent.KEYCODE_MENU, isLongpress);
        return;
    } else if (action.equals(ActionConstants.ACTION_IME_NAVIGATION_LEFT)) {
        triggerVirtualKeypress(KeyEvent.KEYCODE_DPAD_LEFT, isLongpress);
        return;
    } else if (action.equals(ActionConstants.ACTION_IME_NAVIGATION_RIGHT)) {
        triggerVirtualKeypress(KeyEvent.KEYCODE_DPAD_RIGHT, isLongpress);
        return;
    } else if (action.equals(ActionConstants.ACTION_IME_NAVIGATION_UP)) {
        triggerVirtualKeypress(KeyEvent.KEYCODE_DPAD_UP, isLongpress);
        return;
    } else if (action.equals(ActionConstants.ACTION_IME_NAVIGATION_DOWN)) {
        triggerVirtualKeypress(KeyEvent.KEYCODE_DPAD_DOWN, isLongpress);
        return;
    } else if (action.equals(ActionConstants.ACTION_POWER)) {
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        pm.goToSleep(SystemClock.uptimeMillis());
        return;
    } else if (action.equals(ActionConstants.ACTION_IME)) {
        if (isKeyguardShowing) {
            return;
        }
        context.sendBroadcastAsUser(new Intent("android.settings.SHOW_INPUT_METHOD_PICKER"), new UserHandle(UserHandle.USER_CURRENT));
        return;
    } else if (action.equals(ActionConstants.ACTION_VOICE_SEARCH)) {
        // launch the search activity
        Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        try {
            // TODO: This only stops the factory-installed search manager.
            // Need to formalize an API to handle others
            SearchManager searchManager = (SearchManager) context.getSystemService(Context.SEARCH_SERVICE);
            if (searchManager != null) {
                searchManager.stopSearch();
            }
            startActivity(context, intent);
        } catch (ActivityNotFoundException e) {
            Log.e("Actions:", "No activity to handle assist long press action.", e);
        }
        return;
    } else if (action.equals(ActionConstants.ACTION_VIB)) {
        AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        if (am != null && ActivityManagerNative.isSystemReady()) {
            if (am.getRingerMode() != AudioManager.RINGER_MODE_VIBRATE) {
                am.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
                Vibrator vib = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
                if (vib != null) {
                    vib.vibrate(50);
                }
            } else {
                am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
                ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, (int) (ToneGenerator.MAX_VOLUME * 0.85));
                if (tg != null) {
                    tg.startTone(ToneGenerator.TONE_PROP_BEEP);
                }
            }
        }
        return;
    } else if (action.equals(ActionConstants.ACTION_SILENT)) {
        AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        if (am != null && ActivityManagerNative.isSystemReady()) {
            if (am.getRingerMode() != AudioManager.RINGER_MODE_SILENT) {
                am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
            } else {
                am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
                ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, (int) (ToneGenerator.MAX_VOLUME * 0.85));
                if (tg != null) {
                    tg.startTone(ToneGenerator.TONE_PROP_BEEP);
                }
            }
        }
        return;
    } else if (action.equals(ActionConstants.ACTION_VIB_SILENT)) {
        AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        if (am != null && ActivityManagerNative.isSystemReady()) {
            if (am.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) {
                am.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
                Vibrator vib = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
                if (vib != null) {
                    vib.vibrate(50);
                }
            } else if (am.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE) {
                am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
            } else {
                am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
                ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, (int) (ToneGenerator.MAX_VOLUME * 0.85));
                if (tg != null) {
                    tg.startTone(ToneGenerator.TONE_PROP_BEEP);
                }
            }
        }
        return;
    } else if (action.equals(ActionConstants.ACTION_CAMERA)) {
        // ToDo: Send for secure keyguard secure camera intent.
        // We need to add support for it first.
        Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA, null);
        startActivity(context, intent);
        return;
    } else if (action.equals(ActionConstants.ACTION_MEDIA_PREVIOUS)) {
        dispatchMediaKeyWithWakeLock(KeyEvent.KEYCODE_MEDIA_PREVIOUS, context);
        return;
    } else if (action.equals(ActionConstants.ACTION_MEDIA_NEXT)) {
        dispatchMediaKeyWithWakeLock(KeyEvent.KEYCODE_MEDIA_NEXT, context);
        return;
    } else if (action.equals(ActionConstants.ACTION_MEDIA_PLAY_PAUSE)) {
        dispatchMediaKeyWithWakeLock(KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE, context);
        return;
    } else if (action.equals(ActionConstants.ACTION_WAKE_DEVICE)) {
        PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        if (!powerManager.isScreenOn()) {
            powerManager.wakeUp(SystemClock.uptimeMillis());
        }
        return;
    } else {
        // we must have a custom uri
        Intent intent = null;
        try {
            intent = Intent.parseUri(action, 0);
        } catch (URISyntaxException e) {
            Log.e("Actions:", "URISyntaxException: [" + action + "]");
            return;
        }
        startActivity(context, intent);
        return;
    }
}
Also used : PowerManager(android.os.PowerManager) AudioManager(android.media.AudioManager) ToneGenerator(android.media.ToneGenerator) SearchManager(android.app.SearchManager) ActivityNotFoundException(android.content.ActivityNotFoundException) UserHandle(android.os.UserHandle) Intent(android.content.Intent) Vibrator(android.os.Vibrator) URISyntaxException(java.net.URISyntaxException) RemoteException(android.os.RemoteException)

Example 98 with SearchManager

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

the class SearchManagerTest method testSearchManagerAvailable.

/**
     * The goal of this test is to confirm that we can obtain
     * a search manager at any time, and that for any given context,
     * it is a singleton.
     */
@LargeTest
public void testSearchManagerAvailable() {
    SearchManager searchManager1 = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
    assertNotNull(searchManager1);
    SearchManager searchManager2 = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
    assertNotNull(searchManager2);
    assertSame(searchManager1, searchManager2);
}
Also used : ISearchManager(android.app.ISearchManager) SearchManager(android.app.SearchManager) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 99 with SearchManager

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

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)

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