1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/CustomEditText.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,80 @@ 1.4 +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +package org.mozilla.gecko; 1.10 + 1.11 +import org.mozilla.gecko.widget.ThemedEditText; 1.12 + 1.13 +import android.content.Context; 1.14 +import android.util.AttributeSet; 1.15 +import android.view.KeyEvent; 1.16 +import android.view.View; 1.17 + 1.18 +public class CustomEditText extends ThemedEditText { 1.19 + private OnKeyPreImeListener mOnKeyPreImeListener; 1.20 + private OnSelectionChangedListener mOnSelectionChangedListener; 1.21 + private OnWindowFocusChangeListener mOnWindowFocusChangeListener; 1.22 + 1.23 + public CustomEditText(Context context, AttributeSet attrs) { 1.24 + super(context, attrs); 1.25 + mOnKeyPreImeListener = null; 1.26 + } 1.27 + 1.28 + public interface OnKeyPreImeListener { 1.29 + public boolean onKeyPreIme(View v, int keyCode, KeyEvent event); 1.30 + } 1.31 + 1.32 + public void setOnKeyPreImeListener(OnKeyPreImeListener listener) { 1.33 + mOnKeyPreImeListener = listener; 1.34 + } 1.35 + 1.36 + @Override 1.37 + public boolean onKeyPreIme(int keyCode, KeyEvent event) { 1.38 + if (mOnKeyPreImeListener != null) 1.39 + return mOnKeyPreImeListener.onKeyPreIme(this, keyCode, event); 1.40 + 1.41 + return false; 1.42 + } 1.43 + 1.44 + public interface OnSelectionChangedListener { 1.45 + public void onSelectionChanged(int selStart, int selEnd); 1.46 + } 1.47 + 1.48 + public void setOnSelectionChangedListener(OnSelectionChangedListener listener) { 1.49 + mOnSelectionChangedListener = listener; 1.50 + } 1.51 + 1.52 + @Override 1.53 + protected void onSelectionChanged(int selStart, int selEnd) { 1.54 + if (mOnSelectionChangedListener != null) 1.55 + mOnSelectionChangedListener.onSelectionChanged(selStart, selEnd); 1.56 + 1.57 + super.onSelectionChanged(selStart, selEnd); 1.58 + } 1.59 + 1.60 + public interface OnWindowFocusChangeListener { 1.61 + public void onWindowFocusChanged(boolean hasFocus); 1.62 + } 1.63 + 1.64 + public void setOnWindowFocusChangeListener(OnWindowFocusChangeListener listener) { 1.65 + mOnWindowFocusChangeListener = listener; 1.66 + } 1.67 + 1.68 + @Override 1.69 + public void onWindowFocusChanged(boolean hasFocus) { 1.70 + super.onWindowFocusChanged(hasFocus); 1.71 + if (mOnWindowFocusChangeListener != null) 1.72 + mOnWindowFocusChangeListener.onWindowFocusChanged(hasFocus); 1.73 + } 1.74 + 1.75 + @Override 1.76 + public void setPrivateMode(boolean isPrivate) { 1.77 + super.setPrivateMode(isPrivate); 1.78 + 1.79 + // android:textColorHighlight cannot support a ColorStateList. 1.80 + int colorId = isPrivate ? R.color.url_bar_text_highlight_pb : R.color.url_bar_text_highlight; 1.81 + setHighlightColor(getContext().getResources().getColor(colorId)); 1.82 + } 1.83 +}