/ime/latinime/src/com/googlecode/eyesfree/inputmethod/latin/tutorial/SelectionEditText.java
Java | 67 lines | 34 code | 12 blank | 21 comment | 2 complexity | e86c86400078f0ad29fda55bd9f1e01f MD5 | raw file
1/* 2 * Copyright (C) 2011 Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.googlecode.eyesfree.inputmethod.latin.tutorial; 18 19import android.content.Context; 20import android.util.AttributeSet; 21import android.widget.EditText; 22 23/** 24 * This class extends the {@link EditText} widget by providing a listener 25 * interface for selection changes. See {@link SelectionListener}. 26 * 27 * @author alanv@google.com (Alan Viverette) 28 */ 29public class SelectionEditText extends EditText { 30 private SelectionListener mSelectionListener = null; 31 32 private int mOldSelStart = 0; 33 private int mOldSelEnd = 0; 34 35 public SelectionEditText(Context context) { 36 super(context); 37 } 38 39 public SelectionEditText(Context context, AttributeSet attrs) { 40 super(context, attrs); 41 } 42 43 public SelectionEditText(Context context, AttributeSet attrs, int defStyle) { 44 super(context, attrs, defStyle); 45 } 46 47 public void setSelectionListener(SelectionListener selectionListener) { 48 mSelectionListener = selectionListener; 49 } 50 51 @Override 52 protected void onSelectionChanged(int selStart, int selEnd) { 53 super.onSelectionChanged(selStart, selEnd); 54 55 if (mSelectionListener != null) { 56 mSelectionListener.onSelectionChanged(this, mOldSelStart, mOldSelEnd, selStart, selEnd); 57 } 58 59 mOldSelStart = selStart; 60 mOldSelEnd = selEnd; 61 } 62 63 public static interface SelectionListener { 64 public void onSelectionChanged(SelectionEditText editText, int oldSelStart, int oldSelEnd, 65 int selStart, int selEnd); 66 } 67}