Example usage for android.app SearchManager QUERY

List of usage examples for android.app SearchManager QUERY

Introduction

In this page you can find the example usage for android.app SearchManager QUERY.

Prototype

String QUERY

To view the source code for android.app SearchManager QUERY.

Click Source Link

Document

Intent extra data key: Use this key with android.content.Intent#getStringExtra content.Intent.getStringExtra() to obtain the query string from Intent.ACTION_SEARCH.

Usage

From source file:com.gelakinetic.mtgfam.FamiliarActivity.java

private boolean processIntent(Intent intent) {
    boolean isDeepLink = false;

    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        /* Do a search by name, launched from the quick search */
        String query = intent.getStringExtra(SearchManager.QUERY);
        Bundle args = new Bundle();
        SearchCriteria sc = new SearchCriteria();
        sc.name = query;/*from ww  w .ja v a  2s . co  m*/
        args.putSerializable(SearchViewFragment.CRITERIA, sc);
        selectItem(R.string.main_card_search, args, false,
                true); /* Don't clear backstack, do force the intent */

    } else if (Intent.ACTION_VIEW.equals(intent.getAction())) {

        boolean shouldSelectItem = true;

        Uri data = intent.getData();
        Bundle args = new Bundle();
        assert data != null;

        boolean shouldClearFragmentStack = true; /* Clear backstack for deep links */
        if (data.getAuthority().toLowerCase().contains("gatherer.wizards")) {
            SQLiteDatabase database = DatabaseManager.getInstance(this, false).openDatabase(false);
            try {
                String queryParam;
                if ((queryParam = data.getQueryParameter("multiverseid")) != null) {
                    Cursor cursor = CardDbAdapter.fetchCardByMultiverseId(Long.parseLong(queryParam),
                            new String[] { CardDbAdapter.DATABASE_TABLE_CARDS + "." + CardDbAdapter.KEY_ID },
                            database);
                    if (cursor.getCount() != 0) {
                        isDeepLink = true;
                        args.putLongArray(CardViewPagerFragment.CARD_ID_ARRAY,
                                new long[] { cursor.getInt(cursor.getColumnIndex(CardDbAdapter.KEY_ID)) });
                    }
                    cursor.close();
                    if (args.size() == 0) {
                        throw new Exception("Not Found");
                    }
                } else if ((queryParam = data.getQueryParameter("name")) != null) {
                    Cursor cursor = CardDbAdapter.fetchCardByName(queryParam,
                            new String[] { CardDbAdapter.DATABASE_TABLE_CARDS + "." + CardDbAdapter.KEY_ID },
                            true, database);
                    if (cursor.getCount() != 0) {
                        isDeepLink = true;
                        args.putLongArray(CardViewPagerFragment.CARD_ID_ARRAY,
                                new long[] { cursor.getInt(cursor.getColumnIndex(CardDbAdapter.KEY_ID)) });
                    }
                    cursor.close();
                    if (args.size() == 0) {
                        throw new Exception("Not Found");
                    }
                } else {
                    throw new Exception("Not Found");
                }
            } catch (Exception e) {
                /* empty cursor, just return */
                ToastWrapper.makeText(this, R.string.no_results_found, ToastWrapper.LENGTH_LONG).show();
                this.finish();
                shouldSelectItem = false;
            } finally {
                DatabaseManager.getInstance(this, false).closeDatabase(false);
            }
        } else if (data.getAuthority().contains("CardSearchProvider")) {
            /* User clicked a card in the quick search autocomplete, jump right to it */
            args.putLongArray(CardViewPagerFragment.CARD_ID_ARRAY,
                    new long[] { Long.parseLong(data.getLastPathSegment()) });
            shouldClearFragmentStack = false; /* Don't clear backstack for search intents */
        } else {
            /* User clicked a deep link, jump to the card(s) */
            isDeepLink = true;

            SQLiteDatabase database = DatabaseManager.getInstance(this, false).openDatabase(false);
            try {
                Cursor cursor = null;
                boolean screenLaunched = false;
                if (data.getScheme().toLowerCase().equals("card")
                        && data.getAuthority().toLowerCase().equals("multiverseid")) {
                    if (data.getLastPathSegment() == null) {
                        /* Home screen deep link */
                        launchHomeScreen();
                        screenLaunched = true;
                        shouldSelectItem = false;
                    } else {
                        try {
                            /* Don't clear the fragment stack for internal links (thanks Meld cards) */
                            if (data.getPathSegments().contains("internal")) {
                                shouldClearFragmentStack = false;
                            }
                            cursor = CardDbAdapter.fetchCardByMultiverseId(
                                    Long.parseLong(data.getLastPathSegment()),
                                    new String[] {
                                            CardDbAdapter.DATABASE_TABLE_CARDS + "." + CardDbAdapter.KEY_ID },
                                    database);
                        } catch (NumberFormatException e) {
                            cursor = null;
                        }
                    }
                }

                if (cursor != null) {
                    if (cursor.getCount() != 0) {
                        args.putLongArray(CardViewPagerFragment.CARD_ID_ARRAY,
                                new long[] { cursor.getInt(cursor.getColumnIndex(CardDbAdapter.KEY_ID)) });
                    } else {
                        /* empty cursor, just return */
                        ToastWrapper.makeText(this, R.string.no_results_found, ToastWrapper.LENGTH_LONG).show();
                        this.finish();
                        shouldSelectItem = false;
                    }
                    cursor.close();
                } else if (!screenLaunched) {
                    /* null cursor, just return */
                    ToastWrapper.makeText(this, R.string.no_results_found, ToastWrapper.LENGTH_LONG).show();
                    this.finish();
                    shouldSelectItem = false;
                }
            } catch (FamiliarDbException e) {
                e.printStackTrace();
            }
            DatabaseManager.getInstance(this, false).closeDatabase(false);
        }
        args.putInt(CardViewPagerFragment.STARTING_CARD_POSITION, 0);
        if (shouldSelectItem) {
            selectItem(R.string.main_card_search, args, shouldClearFragmentStack, true);
        }
    } else if (ACTION_ROUND_TIMER.equals(intent.getAction())) {
        selectItem(R.string.main_timer, null, true, false);
    } else if (ACTION_CARD_SEARCH.equals(intent.getAction())) {
        selectItem(R.string.main_card_search, null, true, false);
    } else if (ACTION_LIFE.equals(intent.getAction())) {
        selectItem(R.string.main_life_counter, null, true, false);
    } else if (ACTION_DICE.equals(intent.getAction())) {
        selectItem(R.string.main_dice, null, true, false);
    } else if (ACTION_TRADE.equals(intent.getAction())) {
        selectItem(R.string.main_trade, null, true, false);
    } else if (ACTION_MANA.equals(intent.getAction())) {
        selectItem(R.string.main_mana_pool, null, true, false);
    } else if (ACTION_WISH.equals(intent.getAction())) {
        selectItem(R.string.main_wishlist, null, true, false);
    } else if (ACTION_RULES.equals(intent.getAction())) {
        selectItem(R.string.main_rules, null, true, false);
    } else if (ACTION_JUDGE.equals(intent.getAction())) {
        selectItem(R.string.main_judges_corner, null, true, false);
    } else if (ACTION_MOJHOSTO.equals(intent.getAction())) {
        selectItem(R.string.main_mojhosto, null, true, false);
    } else if (ACTION_PROFILE.equals(intent.getAction())) {
        selectItem(R.string.main_profile, null, true, false);
    } else if (ACTION_DECKLIST.equals(intent.getAction())) {
        selectItem(R.string.main_decklist, null, true, false);
    } else if (Intent.ACTION_MAIN.equals(intent.getAction())) {
        /* App launched as regular, show the default fragment if there isn't one already */
        if (getSupportFragmentManager().getFragments() == null) {
            launchHomeScreen();
        }
    } else {
        /* Some unknown intent, just finish */
        finish();
    }

    mDrawerList.setItemChecked(mCurrentFrag, true);
    return isDeepLink;
}

From source file:com.lgallardo.youtorrentcontroller.RefreshListener.java

private void handleIntent(Intent intent) {

    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        // Use the query to search your data somehow
        searchField = intent.getStringExtra(SearchManager.QUERY);

        // Autorefresh
        refreshCurrent();/*from   w ww .j  a  v a  2 s . c o  m*/
    }

    if (Intent.ACTION_VIEW.equals(intent.getAction())) {

        if (token == null || cookie == null) {
            // Get token and cookie and then
            // get intent from the intent filter and Add URL torrent
            //            Log.d("Debug", "MainActivity - 2");
            new torrentTokenByIntent().execute(getIntent());

        } else {

            // Add torrent (file, url or magnet)
            addTorrentByIntent(intent);
        }
        // // Activity is visble
        activityIsVisible = true;

        // Autorefresh
        refreshCurrent();

    }

    try {
        if (intent.getStringExtra("from").equals("NotifierService")) {

            //                drawerList.setItemChecked(2, true);
            mRecyclerView.findViewHolderForAdapterPosition(3).itemView.performClick();
            setTitle(navigationDrawerItemTitles[2]);
            refresh("completed");

        }

        if (intent.getStringExtra("from").equals("RSSItemActivity")) {

            // Add torrent (file, url or magnet)
            addTorrentByIntent(intent);

            // // Activity is visble
            activityIsVisible = true;

            // Autorefresh
            refreshCurrent();
        }

    } catch (NullPointerException npe) {

    }
}

From source file:com.dycody.android.idealnote.ListFragment.java

/**
 * Notes list adapter initialization and association to view
 *//*  w  ww .j a va2  s. c  o m*/
void initNotesList(Intent intent) {
    Log.d(Constants.TAG, "initNotesList intent: " + intent.getAction());

    progress_wheel.setAlpha(1);
    list.setAlpha(0);

    // Search for a tag
    // A workaround to simplify it's to simulate normal search
    if (Intent.ACTION_VIEW.equals(intent.getAction()) && intent.getCategories() != null
            && intent.getCategories().contains(Intent.CATEGORY_BROWSABLE)) {
        searchTags = intent.getDataString().replace(UrlCompleter.HASHTAG_SCHEME, "");
        goBackOnToggleSearchLabel = true;
    }

    // Searching
    searchQuery = searchQueryInstant;
    searchQueryInstant = null;
    if (searchTags != null || searchQuery != null || Intent.ACTION_SEARCH.equals(intent.getAction())) {

        // Using tags
        if (searchTags != null && intent.getStringExtra(SearchManager.QUERY) == null) {
            searchQuery = searchTags;
            NoteLoaderTask.getInstance().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, "getNotesByTag",
                    searchQuery);
        } else {
            // Get the intent, verify the action and get the query
            if (intent.getStringExtra(SearchManager.QUERY) != null) {
                searchQuery = intent.getStringExtra(SearchManager.QUERY);
                searchTags = null;
            }
            NoteLoaderTask.getInstance().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, "getNotesByPattern",
                    searchQuery);
        }

        toggleSearchLabel(true);

    } else {
        // Check if is launched from a widget with categories
        if ((Constants.ACTION_WIDGET_SHOW_LIST.equals(intent.getAction())
                && intent.hasExtra(Constants.INTENT_WIDGET))
                || !TextUtils.isEmpty(mainActivity.navigationTmp)) {
            String widgetId = intent.hasExtra(Constants.INTENT_WIDGET)
                    ? intent.getExtras().get(Constants.INTENT_WIDGET).toString()
                    : null;
            if (widgetId != null) {
                String sqlCondition = prefs.getString(Constants.PREF_WIDGET_PREFIX + widgetId, "");
                String categoryId = TextHelper.checkIntentCategory(sqlCondition);
                mainActivity.navigationTmp = !TextUtils.isEmpty(categoryId) ? categoryId : null;
            }
            intent.removeExtra(Constants.INTENT_WIDGET);
            if (mainActivity.navigationTmp != null) {
                Long categoryId = Long.parseLong(mainActivity.navigationTmp);
                NoteLoaderTask.getInstance().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
                        "getNotesByCategory", categoryId);
            } else {
                NoteLoaderTask.getInstance().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, "getAllNotes",
                        true);
            }

        } else {
            NoteLoaderTask.getInstance().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, "getAllNotes", true);
        }
    }
}

From source file:org.brandroid.openmanager.activities.OpenExplorer.java

/**
 * Returns true if the Intent was "Handled"
 * @param intent Input Intent/*ww w.ja v a 2  s .  c o m*/
 */
public boolean handleIntent(Intent intent) {
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        OpenPath searchIn = new OpenFile("/");
        Bundle bundle = intent.getBundleExtra(SearchManager.APP_DATA);
        if (bundle != null && bundle.containsKey("path"))
            try {
                searchIn = FileManager.getOpenCache(bundle.getString("path"), false, null);
            } catch (IOException e) {
                searchIn = new OpenFile(bundle.getString("path"));
            }
        String query = intent.getStringExtra(SearchManager.QUERY);
        Logger.LogDebug("ACTION_SEARCH for \"" + query + "\" in " + searchIn);
        SearchResultsFragment srf = SearchResultsFragment.getInstance(searchIn, query);
        if (mViewPagerEnabled && mViewPagerAdapter != null) {
            mViewPagerAdapter.add(srf);
            setViewPageAdapter(mViewPagerAdapter, true);
            setCurrentItem(mViewPagerAdapter.getCount() - 1, true);
        } else {
            getSupportFragmentManager().beginTransaction().replace(R.id.content_frag, srf).commit();
        }
    } else if ((Intent.ACTION_VIEW.equals(intent.getAction()) || Intent.ACTION_EDIT.equals(intent.getAction()))
            && intent.getData() != null) {
        OpenPath path = FileManager.getOpenCache(intent.getDataString(), this);
        if (editFile(path))
            return true;
    } else if (intent.hasExtra("state")) {
        Bundle state = intent.getBundleExtra("state");
        onRestoreInstanceState(state);
    }
    return false;
}

From source file:com.lgallardo.qbittorrentclient.RefreshListener.java

private void handleIntent(Intent intent) {

    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {

        // Use the query to search your data somehow
        searchField = intent.getStringExtra(SearchManager.QUERY);

        //            Log.d("Debug", "Search for..." + searchField);

        // Autorefresh
        refreshSwipeLayout();// w ww .ja va2s  .  c om
        refreshCurrent();
    }

    if (Intent.ACTION_VIEW.equals(intent.getAction())) {

        // Add torrent (file, url or magnet)
        addTorrentByIntent(intent);

        // // Activity is visible
        activityIsVisible = true;

        // Autorefresh
        refreshCurrent();

    }

    try {

        if (intent.getStringExtra("from").equals("NotifierService")) {

            saveLastState("completed");
            setSelectionAndTitle("completed");
            refresh("completed", currentLabel);
        }

        if (intent.getStringExtra("from").equals("RSSItemActivity")) {

            // Add torrent (file, url or magnet)
            addTorrentByIntent(intent);

            // // Activity is visble
            activityIsVisible = true;

            // Autorefresh
            refreshCurrent();
        }

        //            Log.d("Debug", "lastState (handle intent):End " );
    } catch (Exception e) {

        //            Log.e("Debug", "Handle intent: " + e.toString() );

    }
}

From source file:android.support.v7.widget.SearchView.java

/**
 * Constructs an intent from the given information and the search dialog state.
 *
 * @param action Intent action.//from   www .j a  v  a2 s .c  o m
 * @param data Intent data, or <code>null</code>.
 * @param extraData Data for {@link SearchManager#EXTRA_DATA_KEY} or <code>null</code>.
 * @param query Intent query, or <code>null</code>.
 * @param actionKey The key code of the action key that was pressed,
 *        or {@link KeyEvent#KEYCODE_UNKNOWN} if none.
 * @param actionMsg The message for the action key that was pressed,
 *        or <code>null</code> if none.
 * @return The intent.
 */
private Intent createIntent(String action, Uri data, String extraData, String query, int actionKey,
        String actionMsg) {
    // Now build the Intent
    Intent intent = new Intent(action);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    // We need CLEAR_TOP to avoid reusing an old task that has other activities
    // on top of the one we want. We don't want to do this in in-app search though,
    // as it can be destructive to the activity stack.
    if (data != null) {
        intent.setData(data);
    }
    intent.putExtra(SearchManager.USER_QUERY, mUserQuery);
    if (query != null) {
        intent.putExtra(SearchManager.QUERY, query);
    }
    if (extraData != null) {
        intent.putExtra(SearchManager.EXTRA_DATA_KEY, extraData);
    }
    if (mAppSearchData != null) {
        intent.putExtra(SearchManager.APP_DATA, mAppSearchData);
    }
    if (actionKey != KeyEvent.KEYCODE_UNKNOWN) {
        intent.putExtra(SearchManager.ACTION_KEY, actionKey);
        intent.putExtra(SearchManager.ACTION_MSG, actionMsg);
    }
    if (IS_AT_LEAST_FROYO) {
        intent.setComponent(mSearchable.getSearchActivity());
    }
    return intent;
}

From source file:cm.aptoide.com.actionbarsherlock.widget.SearchView.java

/**
 * Constructs an intent from the given information and the search dialog state.
 *
 * @param action Intent action./*from   ww  w.  j  ava 2 s.  c o  m*/
 * @param data Intent data, or <code>null</code>.
 * @param extraData Data for {@link SearchManager#EXTRA_DATA_KEY} or <code>null</code>.
 * @param query Intent query, or <code>null</code>.
 * @param actionKey The key code of the action key that was pressed,
 *        or {@link KeyEvent#KEYCODE_UNKNOWN} if none.
 * @param actionMsg The message for the action key that was pressed,
 *        or <code>null</code> if none.
 * @return The intent.
 */
private Intent createIntent(String action, Uri data, String extraData, String query, int actionKey,
        String actionMsg) {
    // Now build the Intent
    Intent intent = new Intent(action);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    // We need CLEAR_TOP to avoid reusing an old task that has other activities
    // on top of the one we want. We don't want to do this in in-app search though,
    // as it can be destructive to the activity stack.
    if (data != null) {
        intent.setData(data);
    }
    intent.putExtra(SearchManager.USER_QUERY, mUserQuery);
    if (query != null) {
        intent.putExtra(SearchManager.QUERY, query);
    }
    if (extraData != null) {
        intent.putExtra(SearchManager.EXTRA_DATA_KEY, extraData);
    }
    if (mAppSearchData != null) {
        intent.putExtra(SearchManager.APP_DATA, mAppSearchData);
    }
    if (actionKey != KeyEvent.KEYCODE_UNKNOWN) {
        intent.putExtra(SearchManager.ACTION_KEY, actionKey);
        intent.putExtra(SearchManager.ACTION_MSG, actionMsg);
    }
    intent.setComponent(mSearchable.getSearchActivity());
    return intent;
}

From source file:com.tct.mail.ui.AbstractActivityController.java

@Override
public void onFolderChanged(Folder folder, final boolean force) {
    if (isDrawerEnabled()) {
        /** If the folder doesn't exist, or its parent URI is empty,
         * this is not a child folder */
        final boolean isTopLevel = Folder.isRoot(folder);
        final int mode = mViewMode.getMode();
        mDrawerToggle.setDrawerIndicatorEnabled(getShouldShowDrawerIndicator(mode, isTopLevel));
        mDrawerContainer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);

        mDrawerContainer.closeDrawers();
    }/*  w w  w.j  a  v  a2s. c  o m*/

    if (mFolder == null || !mFolder.equals(folder)) {
        // We are actually changing the folder, so exit cab mode
        exitCabMode();
    }

    final String query;
    //TS: zheng.zou 2015-03-24 EMAIL BUGFIX-942796 MOD_S
    //keep search word after go back from view conversation
    //        if (folder != null && folder.isType(FolderType.SEARCH)) {
    //            query = mConvListContext.searchQuery;
    //        } else {
    //            query = null;
    //        }
    if (mConvListContext != null) {
        query = mConvListContext.searchQuery;
    } else {
        query = null;
    }
    //TS: zheng.zou 2015-03-24 EMAIL BUGFIX-942796 MOD_E

    changeFolder(folder, query, force);
    /** TCT: For global search, enter local search mode and search the text @{ */
    if (mGlobalSearch) {
        LogUtils.logFeature(LogTag.SEARCH_TAG, "[Global Search]Enter and execute local search");
        mActionBarController.expandSearch(mActivity.getIntent().getStringExtra(SearchManager.QUERY), null);
    }
    /** @{ */
}

From source file:com.example.navigationsearchview.NavigationSearchView.java

/**
 * Constructs an intent from the given information and the search dialog
 * state.//from   w w  w  .  java2  s . com
 *
 * @param action
 *            Intent action.
 * @param data
 *            Intent data, or <code>null</code>.
 * @param extraData
 *            Data for {@link SearchManager#EXTRA_DATA_KEY} or
 *            <code>null</code>.
 * @param query
 *            Intent query, or <code>null</code>.
 * @param actionKey
 *            The key code of the action key that was pressed, or
 *            {@link KeyEvent#KEYCODE_UNKNOWN} if none.
 * @param actionMsg
 *            The message for the action key that was pressed, or
 *            <code>null</code> if none.
 * @return The intent.
 */
private Intent createIntent(String action, Uri data, String extraData, String query, int actionKey,
        String actionMsg) {
    // Now build the Intent
    Intent intent = new Intent(action);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    // We need CLEAR_TOP to avoid reusing an old task that has other
    // activities
    // on top of the one we want. We don't want to do this in in-app search
    // though,
    // as it can be destructive to the activity stack.
    if (data != null) {
        intent.setData(data);
    }
    intent.putExtra(SearchManager.USER_QUERY, mUserQuery);
    if (query != null) {
        intent.putExtra(SearchManager.QUERY, query);
    }
    if (extraData != null) {
        intent.putExtra(SearchManager.EXTRA_DATA_KEY, extraData);
    }
    if (mAppSearchData != null) {
        intent.putExtra(SearchManager.APP_DATA, mAppSearchData);
    }
    if (actionKey != KeyEvent.KEYCODE_UNKNOWN) {
        intent.putExtra(SearchManager.ACTION_KEY, actionKey);
        intent.putExtra(SearchManager.ACTION_MSG, actionMsg);
    }
    if (IS_AT_LEAST_FROYO) {
        intent.setComponent(mSearchable.getSearchActivity());
    }
    return intent;
}

From source file:de.azapps.mirakel.main_activity.MainActivity.java

private void handleIntent(final Intent intent) {
    if ((intent == null) || (intent.getAction() == null)) {
        Log.d(MainActivity.TAG, "action null");
    } else if (DefinitionsHelper.SHOW_TASK.equals(intent.getAction())
            || DefinitionsHelper.SHOW_TASK_REMINDER.equals(intent.getAction())
            || DefinitionsHelper.SHOW_TASK_FROM_WIDGET.equals(intent.getAction())) {
        final Optional<Task> task = TaskHelper.getTaskFromIntent(intent);
        if (task.isPresent()) {
            this.currentList = task.get().getList();
            if (this.mDrawerLayout != null) {
                this.mDrawerLayout.postDelayed(new Runnable() {
                    @Override/*from  w  w w .  j  a v a  2 s  .  c o  m*/
                    public void run() {
                        setCurrentTask(task.get(), true);
                    }
                }, 10L);
            }
        } else {
            Log.d(MainActivity.TAG, "task null");
        }
        if (intent.getAction().equals(DefinitionsHelper.SHOW_TASK_FROM_WIDGET)) {
            this.closeOnBack = true;
        }
    } else if (intent.getAction().equals(Intent.ACTION_SEND)
            || intent.getAction().equals(Intent.ACTION_SEND_MULTIPLE)) {
        this.closeOnBack = true;
        this.newTaskContent = intent.getStringExtra(Intent.EXTRA_TEXT);
        this.newTaskSubject = intent.getStringExtra(Intent.EXTRA_SUBJECT);
        // If from google now, the content is the subject
        if ((intent.getCategories() != null)
                && intent.getCategories().contains("com.google.android.voicesearch.SELF_NOTE")
                && !this.newTaskContent.isEmpty()) {
            this.newTaskSubject = this.newTaskContent;
            this.newTaskContent = "";
        }
        if (!"text/plain".equals(intent.getType()) && (this.newTaskSubject == null)) {
            this.newTaskSubject = MirakelCommonPreferences.getImportFileTitle();
        }
        final Optional<ListMirakel> listFromSharing = MirakelModelPreferences.getImportDefaultList();
        if (listFromSharing.isPresent()) {
            addTaskFromSharing(listFromSharing.get(), intent);
        } else {
            final AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle(R.string.import_to);
            final List<CharSequence> items = new ArrayList<>();
            final List<Long> list_ids = new ArrayList<>();
            final int currentItem = 0;
            for (final ListMirakel list : ListMirakel.all()) {
                if (list.getId() > 0) {
                    items.add(list.getName());
                    list_ids.add(list.getId());
                }
            }
            builder.setSingleChoiceItems(items.toArray(new CharSequence[items.size()]), currentItem,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(final DialogInterface dialog, final int which) {
                            final Optional<ListMirakel> listMirakelOptional = ListMirakel
                                    .get(list_ids.get(which));
                            withOptional(listMirakelOptional, new OptionalUtils.Procedure<ListMirakel>() {
                                @Override
                                public void apply(final ListMirakel input) {
                                    addTaskFromSharing(input, intent);
                                    dialog.dismiss();
                                }
                            });
                        }
                    });
            builder.create().show();
        }
    } else if (intent.getAction().equals(DefinitionsHelper.SHOW_LIST)
            || intent.getAction().contains(DefinitionsHelper.SHOW_LIST_FROM_WIDGET)) {
        final Optional<ListMirakel> listMirakelOptional = ListHelper.getListMirakelFromIntent(intent);
        if (listMirakelOptional.isPresent()) {
            final ListMirakel list = listMirakelOptional.get();
            setCurrentList(list);
            final Optional<Task> taskOptional = list.getFirstTask();
            if (taskOptional.isPresent()) {
                this.currentTask = taskOptional.get();
            }
            if (getTaskFragment() != null) {
                getTaskFragment().update(this.currentTask);
            }
        } else {
            Log.d(TAG, "show_list does not pass list, so ignore this");
        }
    } else if (intent.getAction().equals(DefinitionsHelper.SHOW_LISTS)) {
        this.mDrawerLayout.openDrawer(DefinitionsHelper.GRAVITY_LEFT);
    } else if (intent.getAction().equals(Intent.ACTION_SEARCH)) {
        final String query = intent.getStringExtra(SearchManager.QUERY);
        search(query);
    } else if (intent.getAction().contains(DefinitionsHelper.ADD_TASK_FROM_WIDGET)) {
        final int listId = Integer
                .parseInt(intent.getAction().replace(DefinitionsHelper.ADD_TASK_FROM_WIDGET, ""));
        final Optional<ListMirakel> listMirakelOptional = ListMirakel.get(listId);
        if (listMirakelOptional.isPresent()) {
            setCurrentList(listMirakelOptional.get());
        } else {
            setCurrentList(ListMirakel.safeFirst());
        }
        this.mDrawerLayout.postDelayed(new Runnable() {
            @Override
            public void run() {
                if ((getTasksFragment() != null) && getTasksFragment().isReady()) {
                    getTasksFragment().focusNew(true);
                } else if (!MirakelCommonPreferences.isTablet()) {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            if (getTasksFragment() != null) {
                                getTasksFragment().focusNew(true);
                            } else {
                                Log.wtf(MainActivity.TAG, "Tasksfragment null");
                            }
                        }
                    });
                }
            }
        }, 10);
    } else if (intent.getAction().equals(DefinitionsHelper.SHOW_MESSAGE)) {
        final String message = intent.getStringExtra(Intent.EXTRA_TEXT);
        String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT);
        if (message != null) {
            if (subject == null) {
                subject = getString(R.string.message_notification);
            }
            final TextView msg = (TextView) getLayoutInflater().inflate(R.layout.alertdialog_textview, null);
            msg.setText(Html.fromHtml(message));
            msg.setMovementMethod(LinkMovementMethod.getInstance());
            msg.setClickable(true);
            new AlertDialog.Builder(this).setTitle(subject).setView(msg).show();
        }
    } else {
        setCurrentItem(getTaskFragmentPosition());
    }
    if (((intent == null) || (intent.getAction() == null)
            || !intent.getAction().contains(DefinitionsHelper.ADD_TASK_FROM_WIDGET))
            && (getTasksFragment() != null)) {
        getTasksFragment().clearFocus();
    }
    setIntent(null);
    if (this.currentList == null) {
        setCurrentList(SpecialList.firstSpecialSafe());
    }
}