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

Commit f36740b2 authored by Bryan Mawhinney's avatar Bryan Mawhinney
Browse files

Recreate search dialog view each time it's shown.

This is slower, but less vulnerable to problems in TextField, for example.

Change-Id: I3bb6220f30d8231cedde97fc5e0c4db993660d27
parent b386a86c
Loading
Loading
Loading
Loading
+27 −20
Original line number Diff line number Diff line
@@ -127,8 +127,8 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
    private ArrayList<ComponentName> mPreviousComponents;

    // For voice searching
    private Intent mVoiceWebSearchIntent;
    private Intent mVoiceAppSearchIntent;
    private final Intent mVoiceWebSearchIntent;
    private final Intent mVoiceAppSearchIntent;

    // support for AutoCompleteTextView suggestions display
    private SuggestionsAdapter mSuggestionsAdapter;
@@ -156,18 +156,25 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
     */
    public SearchDialog(Context context) {
        super(context, com.android.internal.R.style.Theme_GlobalSearchBar);

        // Save voice intent for later queries/launching
        mVoiceWebSearchIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
        mVoiceWebSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mVoiceWebSearchIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);

        mVoiceAppSearchIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        mVoiceAppSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    }

    /**
     * We create the search dialog just once, and it stays around (hidden)
     * until activated by the user.
     * Create the search dialog and any resources that are used for the
     * entire lifetime of the dialog.
     */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(com.android.internal.R.layout.search_bar);

        Window theWindow = getWindow();
        WindowManager.LayoutParams lp = theWindow.getAttributes();
        lp.type = WindowManager.LayoutParams.TYPE_SEARCH_BAR;
@@ -180,6 +187,17 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
        lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
        theWindow.setAttributes(lp);

        // Touching outside of the search dialog will dismiss it
        setCanceledOnTouchOutside(true);        
    }

    /**
     * We recreate the dialog view each time it becomes visible so as to limit
     * the scope of any problems with the contained resources.
     */
    private void createContentView() {
        setContentView(com.android.internal.R.layout.search_bar);

        // get the view elements for local access
        SearchBar searchBar = (SearchBar) findViewById(com.android.internal.R.id.search_bar);
        searchBar.setSearchDialog(this);
@@ -211,19 +229,6 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
        mBadgeLabel.setVisibility(View.GONE);

        // Additional adjustments to make Dialog work for Search

        // Touching outside of the search dialog will dismiss it 
        setCanceledOnTouchOutside(true);

        // Save voice intent for later queries/launching
        mVoiceWebSearchIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
        mVoiceWebSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mVoiceWebSearchIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
        
        mVoiceAppSearchIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        mVoiceAppSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        mSearchAutoCompleteImeOptions = mSearchAutoComplete.getImeOptions();
    }

@@ -359,6 +364,8 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
        mGlobalSearchMode = globalSearch || searchManager.isDefaultSearchable(mSearchable);
        mActivityContext = mSearchable.getActivityContext(getContext());

        createContentView();

        // show the dialog. this will call onStart().
        if (!isShowing()) {            
            // The Dialog uses a ContextThemeWrapper for the context; use this to change the