AI2 Component  (Version nb184)
PasswordTextBox.java
Go to the documentation of this file.
1 // -*- mode: java; c-basic-offset: 2; -*-
2 // Copyright 2009-2011 Google, All Rights reserved
3 // Copyright 2011-2012 MIT, All rights reserved
4 // Released under the Apache License, Version 2.0
5 // http://www.apache.org/licenses/LICENSE-2.0
6 
7 package com.google.appinventor.components.runtime;
8 
14 
15 import android.text.InputType;
16 import android.text.method.PasswordTransformationMethod;
17 import android.view.inputmethod.EditorInfo;
18 import android.widget.EditText;
19 
35 @DesignerComponent(version = YaVersion.PASSWORDTEXTBOX_COMPONENT_VERSION,
36  description = "<p>A box for entering passwords. This is the same as " +
37  "the ordinary <code>TextBox</code> component except this does not " +
38  "display the characters typed by the user.</p><p>The value of the text " +
39  "in the box can be found or set through the <code>Text</code> property. " +
40  "If blank, the <code>Hint</code> property, which appears as faint text " +
41  "in the box, can provide the user with guidance as to what to type.</p> " +
42  "<p>Text boxes are usually used with the <code>Button</code> " +
43  "component, with the user clicking on the button when text entry is " +
44  "complete.</p>",
45  category = ComponentCategory.USERINTERFACE)
46 @SimpleObject
47 public final class PasswordTextBox extends TextBoxBase {
48 
49  private boolean passwordVisible;
50 
57  super(container, new EditText(container.$context()));
58 
59  // make the box single line
60  view.setSingleLine(true);
61  // Add a transformation method to hide password text. This must
62  // be done after the SingleLine command
63  view.setTransformationMethod(new PasswordTransformationMethod());
64 
65  // make sure the done action is Done and not Next. See comment in Textbox.java
66  view.setImeOptions(EditorInfo.IME_ACTION_DONE);
67 
68  PasswordVisible(false);
69 
70  }
71 
72  @SimpleProperty(description = "Visibility of password.")
73  public void PasswordVisible(boolean visible){
74  passwordVisible=visible;
75  if(visible){
76  view.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
77  }else{
78  view.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_PASSWORD);
79  }
80  }
81 
87  @SimpleProperty(description = "Visibility of password.")
88  public boolean PasswordVisible(){
89  return passwordVisible;
90  }
91 
92 }
com.google.appinventor.components.runtime.TextBoxBase.view
final EditText view
Definition: TextBoxBase.java:40
com.google.appinventor.components.common.YaVersion
Definition: YaVersion.java:14
com.google.appinventor.components
com.google.appinventor.components.annotations.DesignerComponent
Definition: DesignerComponent.java:22
com.google.appinventor.components.runtime.TextBoxBase
Definition: TextBoxBase.java:37
com.google.appinventor.components.runtime.PasswordTextBox
Definition: PasswordTextBox.java:47
com.google.appinventor.components.annotations.SimpleProperty
Definition: SimpleProperty.java:23
com.google.appinventor.components.runtime.ComponentContainer
Definition: ComponentContainer.java:16
com.google.appinventor.components.common
Definition: ComponentCategory.java:7
com.google.appinventor.components.common.ComponentCategory
Definition: ComponentCategory.java:48
com.google.appinventor.components.runtime.PasswordTextBox.PasswordTextBox
PasswordTextBox(ComponentContainer container)
Definition: PasswordTextBox.java:56
com.google.appinventor.components.runtime.PasswordTextBox.PasswordVisible
boolean PasswordVisible()
Definition: PasswordTextBox.java:88
com.google.appinventor.components.annotations.SimpleObject
Definition: SimpleObject.java:23
com.google.appinventor.components.runtime.AndroidViewComponent.container
final ComponentContainer container
Definition: AndroidViewComponent.java:29
com.google
com
com.google.appinventor.components.runtime.ComponentContainer.$context
Activity $context()
com.google.appinventor.components.annotations
com.google.appinventor