<commit_before>/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.focus.search;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.preference.DialogPreference;
import android.util.AttributeSet;

import org.mozilla.focus.R;
import org.mozilla.focus.utils.Settings;

/**
 * Preference for setting the default search engine.
 */
public class SearchEnginePreference extends DialogPreference {
    @SuppressWarnings("unused") // Class referenced from XML
    public SearchEnginePreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init();
    }

    @SuppressWarnings("unused") // Class referenced from XML
    public SearchEnginePreference(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    @SuppressWarnings("unused") // Class referenced from XML
    public SearchEnginePreference(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    @SuppressWarnings("unused") // Class referenced from XML
    public SearchEnginePreference(Context context) {
        super(context);
        init();
    }

    private void init() {
        setTitle(SearchEngineManager.getInstance().getDefaultSearchEngine(getContext()).getName());
    }

    @Override
    protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
        final SearchEngineAdapter adapter = new SearchEngineAdapter(getContext());

        builder.setTitle(R.string.preference_dialog_title_search_engine);

        builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                persistSearchEngine(adapter.getItem(which));

                dialog.dismiss();
            }
        });<commit_msg>Only load SearchEnginePreference title when actually displaying on-screen (#405)<commit_after>/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.focus.search;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.preference.DialogPreference;
import android.util.AttributeSet;

import org.mozilla.focus.R;
import org.mozilla.focus.utils.Settings;

/**
 * Preference for setting the default search engine.
 */
public class SearchEnginePreference extends DialogPreference {
    public SearchEnginePreference(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public SearchEnginePreference(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onAttachedToActivity() {
        setTitle(SearchEngineManager.getInstance().getDefaultSearchEngine(getContext()).getName());
        super.onAttachedToActivity();
    }

    @Override
    protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
        final SearchEngineAdapter adapter = new SearchEngineAdapter(getContext());

        builder.setTitle(R.string.preference_dialog_title_search_engine);

        builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                persistSearchEngine(adapter.getItem(which));

                dialog.dismiss();
            }
        });
{'fraction_non_alphanumeric': 0.09744488977955912, 'fraction_numerical': 0.00375751503006012, 'mean_word_length': 3.486516853932584, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4155091', 'n_tokens_mistral': 1044, 'n_tokens_neox': 1024, 'n_words': 281}