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