7 package com.google.appinventor.components.runtime;
19 import android.content.Context;
20 import android.text.InputType;
21 import android.view.inputmethod.EditorInfo;
22 import android.view.inputmethod.InputMethodManager;
23 import android.widget.EditText;
53 @DesignerComponent(version = YaVersion.TEXTBOX_COMPONENT_VERSION,
54 description =
"<p>A box for the user to enter text. The initial or " +
55 "user-entered text value is in the <code>Text</code> property. If " +
56 "blank, the <code>Hint</code> property, which appears as faint text " +
57 "in the box, can provide the user with guidance as to what to type.</p>" +
58 "<p>The <code>MultiLine</code> property determines if the text can have" +
59 "more than one line. For a single line text box, the keyboard will close" +
60 "automatically when the user presses the Done key. To close the keyboard " +
61 "for multiline text boxes, the app should use the HideKeyboard method or " +
62 " rely on the user to press the Back key.</p>" +
63 "<p>The <code> NumbersOnly</code> property restricts the keyboard to accept" +
64 "numeric input only.</p>" +
65 "<p>Other properties affect the appearance of the text box " +
66 "(<code>TextAlignment</code>, <code>BackgroundColor</code>, etc.) and " +
67 "whether it can be used (<code>Enabled</code>).</p>" +
68 "<p>Text boxes are usually used with the <code>Button</code> " +
69 "component, with the user clicking on the button when text entry is " +
71 "<p>If the text entered by the user should not be displayed, use " +
72 "<code>PasswordTextBox</code> instead.</p>",
73 category = ComponentCategory.USERINTERFACE)
99 private boolean acceptsNumbersOnly;
102 private boolean multiLine;
105 private boolean readOnly;
126 view.setImeOptions(EditorInfo.IME_ACTION_DONE);
138 description =
"If true, then this text box accepts only numbers as keyboard input. " +
139 "Numbers can include a decimal point and an optional leading minus sign. " +
140 "This applies to keyboard input only. Even if NumbersOnly is true, you " +
141 "can use [set Text to] to enter any text at all.")
143 return acceptsNumbersOnly;
157 description =
"If true, then this text box accepts only numbers as keyboard input. " +
158 "Numbers can include a decimal point and an optional leading minus sign. " +
159 "This applies to keyboard input only. Even if NumbersOnly is true, you " +
160 "can use [set Text to] to enter any text at all.")
162 if (acceptsNumbersOnly) {
164 InputType.TYPE_CLASS_NUMBER |
165 InputType.TYPE_NUMBER_FLAG_SIGNED |
166 InputType.TYPE_NUMBER_FLAG_DECIMAL);
168 view.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
170 this.acceptsNumbersOnly = acceptsNumbersOnly;
178 description =
"Hide the keyboard. Only multiline text boxes need this. " +
179 "Single line text boxes close the keyboard when the users presses the Done key.")
181 InputMethodManager imm =
182 (InputMethodManager)
container.
$context().getSystemService(Context.INPUT_METHOD_SERVICE);
183 imm.hideSoftInputFromWindow(
view.getWindowToken(), 0);
194 description =
"If true, then this text box accepts multiple lines of input, which are " +
195 "entered using the return key. For single line text boxes there is a Done " +
196 "key instead of a return key, and pressing Done hides the keyboard. " +
197 "The app should call the HideKeyboard method to hide the keyboard for " +
198 "a mutiline text box.")
215 this.multiLine = multiLine;
216 view.setSingleLine(!multiLine);
221 description =
"Whether the %type% is read-only. By default, this is true."
233 defaultValue =
"False"
237 this.readOnly = readOnly;
238 view.setEnabled(!readOnly);