// Copyright 2015 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.widget;

import android.content.Context;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.AppCompatEditText;
import android.util.AttributeSet;
import android.view.ActionMode;
import android.view.Menu;
import android.view.MenuItem;

import org.chromium.chrome.R;

/**
 * EditText to use in AlertDialog needed due to b/20882793. This class should be removed
 * when we roll to AppCompat with a fix.
 */
public class AlertDialogEditText extends AppCompatEditText {

    public AlertDialogEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        setCustomSelectionActionModeCallback(new ActionMode.Callback() {
            @Override
            public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                return true;
            }

            @Override
            public void onDestroyActionMode(ActionMode mode) {}

            @Override
            public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                for (int i = 0; i < menu.size(); i++) {
                    MenuItem item = menu.getItem(i);
                    Drawable icon = item.getIcon();
                    icon.setColorFilter(getResources().getColor(R.color.light_normal_color),
                            PorterDuff.Mode.SRC_IN);
                    item.setIcon(icon);
                }
                return true;
            }

            @Override
            public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                return false;
            }
        });
    }

}

@@ -315,16 +315,41 @@
 awable;%0A
+import android.os.Build;%0A
 import a
@@ -388,24 +388,24 @@
 atEditText;%0A
-
 import andro
@@ -936,24 +936,99 @@
 hInflate();%0A
+        if (Build.VERSION.SDK_INT %3E= Build.VERSION_CODES.LOLLIPOP) return;%0A
         setC
@@ -1525,16 +1525,16 @@
 tem(i);%0A
-
         
@@ -1573,24 +1573,69 @@
 .getIcon();%0A
+                    if (icon == null) break;%0A
             

Fix a crash for EditText in alert dialogs.