Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f944adbf authored by Daisuke Miyakawa's avatar Daisuke Miyakawa
Browse files

Suppress IME show-up on search mode.

- call SearchView#clearFocus()
- prepare the search view on onCreate()

Though SearchView itself tries to suppress IME on its clearFocus(),
ondemand SearchView creation forces IME show-up for some reason
(attaching it to ActionBar might be the cause of the harm).

Just creating the view every time on onCreate() avoids the problem.
It doesn't hurt performance or any other app capability much.

This change also removes some stale code for showing up IME, which
is needless anyway.

Bug: 5104943
Change-Id: I4c542b3d0cdc5287c9285493e8e5ed0ce25cb204
parent 8feafa54
Loading
Loading
Loading
Loading
+25 −40
Original line number Diff line number Diff line
@@ -358,6 +358,8 @@ public class DialtactsActivity extends Activity {
        mViewPager.setAdapter(new ViewPagerAdapter(getFragmentManager()));
        mViewPager.setOnPageChangeListener(mPageChangeListener);

        prepareSearchView();

        // Setup the ActionBar tabs (the order matches the tab-index contants TAB_INDEX_*)
        setupDialer();
        setupCallLog();
@@ -383,6 +385,25 @@ public class DialtactsActivity extends Activity {
        }
    }

    private void prepareSearchView() {
        final View searchViewLayout =
                getLayoutInflater().inflate(R.layout.custom_action_bar, null);
        mSearchView = (SearchView) searchViewLayout.findViewById(R.id.search_view);
        mSearchView.setOnQueryTextListener(mPhoneSearchQueryTextListener);
        mSearchView.setOnCloseListener(mPhoneSearchCloseListener);
        // Since we're using a custom layout for showing SearchView instead of letting the
        // search menu icon do that job, we need to manually configure the View so it looks
        // "shown via search menu".
        // - it should be iconified by default
        // - it should not be iconified at this time
        // See also comments for onActionViewExpanded()/onActionViewCollapsed()
        mSearchView.setIconifiedByDefault(true);
        mSearchView.setQueryHint(getString(R.string.hint_findContacts));
        mSearchView.setIconified(false);
        getActionBar().setCustomView(searchViewLayout,
                new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    }

    @Override
    public void onAttachFragment(Fragment fragment) {
        // This method can be called before onCreate(), at which point we cannot rely on ViewPager.
@@ -690,46 +711,7 @@ public class DialtactsActivity extends Activity {
            mLastManuallySelectedFragment = tab.getPosition();
        }

        // Instantiate or reset SearchView in ActionBar.
        if (mSearchView == null) {
            final View searchViewLayout =
                    getLayoutInflater().inflate(R.layout.custom_action_bar, null);
            mSearchView = (SearchView) searchViewLayout.findViewById(R.id.search_view);
            mSearchView.setOnQueryTextListener(mPhoneSearchQueryTextListener);
            mSearchView.setOnCloseListener(mPhoneSearchCloseListener);
            // Since we're using a custom layout for showing SearchView instead of letting the
            // search menu icon do that job, we need to manually configure the View so it looks
            // "shown via search menu".
            // - it should be iconified by default
            // - it should not be iconified at this time
            // See also comments for onActionViewExpanded()/onActionViewCollapsed()
            mSearchView.setIconifiedByDefault(true);
            mSearchView.setQueryHint(getString(R.string.hint_findContacts));
            mSearchView.setIconified(false);
            mSearchView.requestFocus();
            // Show soft keyboard when SearchView has a focus. Need to delay the request in order
            // to let InputMethodManager handle it correctly.
            mSearchView.addOnAttachStateChangeListener(new OnAttachStateChangeListener() {
                @Override
                public void onViewDetachedFromWindow(View v) {
                }

                @Override
                public void onViewAttachedToWindow(View v) {
                    if (mSearchView.hasFocus()) {
                        mSearchView.postDelayed(new Runnable() {
                            public void run() {
                                showInputMethod(mSearchView.findFocus());
                            }
                        }, 0);
                    }
                }
            });
            actionBar.setCustomView(searchViewLayout,
                    new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        } else {
        mSearchView.setQuery(null, true);
        }

        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
@@ -748,6 +730,9 @@ public class DialtactsActivity extends Activity {
        // layout instead of asking the search menu item to take care of SearchView.
        mSearchView.onActionViewExpanded();
        mInSearchUi = true;

        // Clear focus and suppress keyboard show-up.
        mSearchView.clearFocus();
    }

    private void showInputMethod(View view) {