// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package org.chromium.chrome.browser.preferences;

import android.content.Context;
import android.preference.ListPreference;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;

/**
 * Contains the basic functionality that should be shared by all ListPreference in Chrome.
 */
public class ChromeBaseListPreference extends ListPreference {

    private ManagedPreferenceDelegate mManagedPrefDelegate;

    /**
     * Constructor for inflating from XML.
     */
    public ChromeBaseListPreference(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    /**
     * Sets the ManagedPreferenceDelegate which will determine whether this preference is managed.
     */
    public void setManagedPreferenceDelegate(ManagedPreferenceDelegate delegate) {
        mManagedPrefDelegate = delegate;
        if (mManagedPrefDelegate != null) mManagedPrefDelegate.initPreference(this);
    }

    @Override
    protected void onBindView(View view) {
        super.onBindView(view);
        ((TextView) view.findViewById(android.R.id.title)).setSingleLine(false);
        if (mManagedPrefDelegate != null) mManagedPrefDelegate.onBindViewToPreference(this, view);
    }

    @Override
    protected void onClick() {
        if (mManagedPrefDelegate != null && mManagedPrefDelegate.onClickPreference(this)) return;
        super.onClick();
    }
}

@@ -260,33 +260,89 @@
 oid.
-preference.ListPreference
+os.Build;%0Aimport android.preference.ListPreference;%0Aimport android.text.TextUtils
 ;%0Aim
@@ -1608,11 +1608,540 @@
 );%0A    %7D
+%0A%0A    @Override%0A    public void setValue(String value) %7B%0A        if (Build.VERSION.SDK_INT %3E= Build.VERSION_CODES.KITKAT) %7B%0A            super.setValue(value);%0A            return;%0A        %7D%0A%0A        // Work around an Android bug where notifyChanged() wasn't called on pre-KitKat devices,%0A        // causing the summary text not to be updated. http://crbug.com/446137%0A        String original = getValue();%0A        super.setValue(value);%0A        if (!TextUtils.equals(original, value)) %7B%0A            notifyChanged();%0A        %7D%0A    %7D
 %0A%7D%0A

Fix bug where Settings showed the wrong search engine.