michael@0: /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko; michael@0: michael@0: import org.mozilla.gecko.widget.ThemedEditText; michael@0: michael@0: import android.content.Context; michael@0: import android.util.AttributeSet; michael@0: import android.view.KeyEvent; michael@0: import android.view.View; michael@0: michael@0: public class CustomEditText extends ThemedEditText { michael@0: private OnKeyPreImeListener mOnKeyPreImeListener; michael@0: private OnSelectionChangedListener mOnSelectionChangedListener; michael@0: private OnWindowFocusChangeListener mOnWindowFocusChangeListener; michael@0: michael@0: public CustomEditText(Context context, AttributeSet attrs) { michael@0: super(context, attrs); michael@0: mOnKeyPreImeListener = null; michael@0: } michael@0: michael@0: public interface OnKeyPreImeListener { michael@0: public boolean onKeyPreIme(View v, int keyCode, KeyEvent event); michael@0: } michael@0: michael@0: public void setOnKeyPreImeListener(OnKeyPreImeListener listener) { michael@0: mOnKeyPreImeListener = listener; michael@0: } michael@0: michael@0: @Override michael@0: public boolean onKeyPreIme(int keyCode, KeyEvent event) { michael@0: if (mOnKeyPreImeListener != null) michael@0: return mOnKeyPreImeListener.onKeyPreIme(this, keyCode, event); michael@0: michael@0: return false; michael@0: } michael@0: michael@0: public interface OnSelectionChangedListener { michael@0: public void onSelectionChanged(int selStart, int selEnd); michael@0: } michael@0: michael@0: public void setOnSelectionChangedListener(OnSelectionChangedListener listener) { michael@0: mOnSelectionChangedListener = listener; michael@0: } michael@0: michael@0: @Override michael@0: protected void onSelectionChanged(int selStart, int selEnd) { michael@0: if (mOnSelectionChangedListener != null) michael@0: mOnSelectionChangedListener.onSelectionChanged(selStart, selEnd); michael@0: michael@0: super.onSelectionChanged(selStart, selEnd); michael@0: } michael@0: michael@0: public interface OnWindowFocusChangeListener { michael@0: public void onWindowFocusChanged(boolean hasFocus); michael@0: } michael@0: michael@0: public void setOnWindowFocusChangeListener(OnWindowFocusChangeListener listener) { michael@0: mOnWindowFocusChangeListener = listener; michael@0: } michael@0: michael@0: @Override michael@0: public void onWindowFocusChanged(boolean hasFocus) { michael@0: super.onWindowFocusChanged(hasFocus); michael@0: if (mOnWindowFocusChangeListener != null) michael@0: mOnWindowFocusChangeListener.onWindowFocusChanged(hasFocus); michael@0: } michael@0: michael@0: @Override michael@0: public void setPrivateMode(boolean isPrivate) { michael@0: super.setPrivateMode(isPrivate); michael@0: michael@0: // android:textColorHighlight cannot support a ColorStateList. michael@0: int colorId = isPrivate ? R.color.url_bar_text_highlight_pb : R.color.url_bar_text_highlight; michael@0: setHighlightColor(getContext().getResources().getColor(colorId)); michael@0: } michael@0: }