• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006 The Android Open Source Project
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 
17 package android.widget;
18 
19 import android.text.*;
20 import android.text.method.*;
21 import android.content.Context;
22 import android.util.AttributeSet;
23 
24 
25 /*
26  * This is supposed to be a *very* thin veneer over TextView.
27  * Do not make any changes here that do anything that a TextView
28  * with a key listener and a movement method wouldn't do!
29  */
30 
31 /**
32  * EditText is a thin veneer over TextView that configures itself
33  * to be editable.
34  * <p>
35  * <b>XML attributes</b>
36  * <p>
37  * See {@link android.R.styleable#EditText EditText Attributes},
38  * {@link android.R.styleable#TextView TextView Attributes},
39  * {@link android.R.styleable#View View Attributes}
40  */
41 public class EditText extends TextView {
EditText(Context context)42     public EditText(Context context) {
43         this(context, null);
44     }
45 
EditText(Context context, AttributeSet attrs)46     public EditText(Context context, AttributeSet attrs) {
47         this(context, attrs, com.android.internal.R.attr.editTextStyle);
48     }
49 
EditText(Context context, AttributeSet attrs, int defStyle)50     public EditText(Context context, AttributeSet attrs, int defStyle) {
51         super(context, attrs, defStyle);
52     }
53 
54     @Override
getDefaultEditable()55     protected boolean getDefaultEditable() {
56         return true;
57     }
58 
59     @Override
getDefaultMovementMethod()60     protected MovementMethod getDefaultMovementMethod() {
61         return ArrowKeyMovementMethod.getInstance();
62     }
63 
64     @Override
getText()65     public Editable getText() {
66         return (Editable) super.getText();
67     }
68 
69     @Override
setText(CharSequence text, BufferType type)70     public void setText(CharSequence text, BufferType type) {
71         super.setText(text, BufferType.EDITABLE);
72     }
73 
74     /**
75      * Convenience for {@link Selection#setSelection(Spannable, int, int)}.
76      */
setSelection(int start, int stop)77     public void setSelection(int start, int stop) {
78         Selection.setSelection(getText(), start, stop);
79     }
80 
81     /**
82      * Convenience for {@link Selection#setSelection(Spannable, int)}.
83      */
setSelection(int index)84     public void setSelection(int index) {
85         Selection.setSelection(getText(), index);
86     }
87 
88     /**
89      * Convenience for {@link Selection#selectAll}.
90      */
selectAll()91     public void selectAll() {
92         Selection.selectAll(getText());
93     }
94 
95     /**
96      * Convenience for {@link Selection#extendSelection}.
97      */
extendSelection(int index)98     public void extendSelection(int index) {
99         Selection.extendSelection(getText(), index);
100     }
101 
102     @Override
setEllipsize(TextUtils.TruncateAt ellipsis)103     public void setEllipsize(TextUtils.TruncateAt ellipsis) {
104         if (ellipsis == TextUtils.TruncateAt.MARQUEE) {
105             throw new IllegalArgumentException("EditText cannot use the ellipsize mode "
106                     + "TextUtils.TruncateAt.MARQUEE");
107         }
108         super.setEllipsize(ellipsis);
109     }
110 }
111