|
1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- |
|
2 * This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 package org.mozilla.gecko; |
|
7 |
|
8 import org.mozilla.gecko.widget.ThemedEditText; |
|
9 |
|
10 import android.content.Context; |
|
11 import android.util.AttributeSet; |
|
12 import android.view.KeyEvent; |
|
13 import android.view.View; |
|
14 |
|
15 public class CustomEditText extends ThemedEditText { |
|
16 private OnKeyPreImeListener mOnKeyPreImeListener; |
|
17 private OnSelectionChangedListener mOnSelectionChangedListener; |
|
18 private OnWindowFocusChangeListener mOnWindowFocusChangeListener; |
|
19 |
|
20 public CustomEditText(Context context, AttributeSet attrs) { |
|
21 super(context, attrs); |
|
22 mOnKeyPreImeListener = null; |
|
23 } |
|
24 |
|
25 public interface OnKeyPreImeListener { |
|
26 public boolean onKeyPreIme(View v, int keyCode, KeyEvent event); |
|
27 } |
|
28 |
|
29 public void setOnKeyPreImeListener(OnKeyPreImeListener listener) { |
|
30 mOnKeyPreImeListener = listener; |
|
31 } |
|
32 |
|
33 @Override |
|
34 public boolean onKeyPreIme(int keyCode, KeyEvent event) { |
|
35 if (mOnKeyPreImeListener != null) |
|
36 return mOnKeyPreImeListener.onKeyPreIme(this, keyCode, event); |
|
37 |
|
38 return false; |
|
39 } |
|
40 |
|
41 public interface OnSelectionChangedListener { |
|
42 public void onSelectionChanged(int selStart, int selEnd); |
|
43 } |
|
44 |
|
45 public void setOnSelectionChangedListener(OnSelectionChangedListener listener) { |
|
46 mOnSelectionChangedListener = listener; |
|
47 } |
|
48 |
|
49 @Override |
|
50 protected void onSelectionChanged(int selStart, int selEnd) { |
|
51 if (mOnSelectionChangedListener != null) |
|
52 mOnSelectionChangedListener.onSelectionChanged(selStart, selEnd); |
|
53 |
|
54 super.onSelectionChanged(selStart, selEnd); |
|
55 } |
|
56 |
|
57 public interface OnWindowFocusChangeListener { |
|
58 public void onWindowFocusChanged(boolean hasFocus); |
|
59 } |
|
60 |
|
61 public void setOnWindowFocusChangeListener(OnWindowFocusChangeListener listener) { |
|
62 mOnWindowFocusChangeListener = listener; |
|
63 } |
|
64 |
|
65 @Override |
|
66 public void onWindowFocusChanged(boolean hasFocus) { |
|
67 super.onWindowFocusChanged(hasFocus); |
|
68 if (mOnWindowFocusChangeListener != null) |
|
69 mOnWindowFocusChangeListener.onWindowFocusChanged(hasFocus); |
|
70 } |
|
71 |
|
72 @Override |
|
73 public void setPrivateMode(boolean isPrivate) { |
|
74 super.setPrivateMode(isPrivate); |
|
75 |
|
76 // android:textColorHighlight cannot support a ColorStateList. |
|
77 int colorId = isPrivate ? R.color.url_bar_text_highlight_pb : R.color.url_bar_text_highlight; |
|
78 setHighlightColor(getContext().getResources().getColor(colorId)); |
|
79 } |
|
80 } |