/ime/latinime/src/com/googlecode/eyesfree/inputmethod/latin/tutorial/SelectionEditText.java

http://eyes-free.googlecode.com/ · 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. package com.googlecode.eyesfree.inputmethod.latin.tutorial;
  17. import android.content.Context;
  18. import android.util.AttributeSet;
  19. import android.widget.EditText;
  20. /**
  21. * This class extends the {@link EditText} widget by providing a listener
  22. * interface for selection changes. See {@link SelectionListener}.
  23. *
  24. * @author alanv@google.com (Alan Viverette)
  25. */
  26. public class SelectionEditText extends EditText {
  27. private SelectionListener mSelectionListener = null;
  28. private int mOldSelStart = 0;
  29. private int mOldSelEnd = 0;
  30. public SelectionEditText(Context context) {
  31. super(context);
  32. }
  33. public SelectionEditText(Context context, AttributeSet attrs) {
  34. super(context, attrs);
  35. }
  36. public SelectionEditText(Context context, AttributeSet attrs, int defStyle) {
  37. super(context, attrs, defStyle);
  38. }
  39. public void setSelectionListener(SelectionListener selectionListener) {
  40. mSelectionListener = selectionListener;
  41. }
  42. @Override
  43. protected void onSelectionChanged(int selStart, int selEnd) {
  44. super.onSelectionChanged(selStart, selEnd);
  45. if (mSelectionListener != null) {
  46. mSelectionListener.onSelectionChanged(this, mOldSelStart, mOldSelEnd, selStart, selEnd);
  47. }
  48. mOldSelStart = selStart;
  49. mOldSelEnd = selEnd;
  50. }
  51. public static interface SelectionListener {
  52. public void onSelectionChanged(SelectionEditText editText, int oldSelStart, int oldSelEnd,
  53. int selStart, int selEnd);
  54. }
  55. }