Skip to content

Commit

Permalink
Support password fields on Android (flutter#4781)
Browse files Browse the repository at this point in the history
  • Loading branch information
goderbauer authored Mar 19, 2018
1 parent 8e1da69 commit cc6b450
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lib/ui/semantics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ class SemanticsFlag {
static const int _kIsEnabledIndex = 1 << 7;
static const int _kIsInMutuallyExclusiveGroupIndex = 1 << 8;
static const int _kIsHeaderIndex = 1 << 9;
static const int _kIsPasswordIndex = 1 << 10;

const SemanticsFlag._(this.index);

Expand Down Expand Up @@ -300,6 +301,12 @@ class SemanticsFlag {
/// address book applications.
static const SemanticsFlag isHeader = const SemanticsFlag._(_kIsHeaderIndex);

/// Whether the semantics node represents a password.
///
/// This is usually used for text fields to indicate that the content should
/// be obscured.
static const SemanticsFlag isPassword = const SemanticsFlag._(_kIsPasswordIndex);

/// The possible semantics flags.
///
/// The map's key is the [index] of the flag and the value is the flag itself.
Expand All @@ -314,6 +321,7 @@ class SemanticsFlag {
_kIsEnabledIndex: isEnabled,
_kIsInMutuallyExclusiveGroupIndex: isInMutuallyExclusiveGroup,
_kIsHeaderIndex: isHeader,
_kIsPasswordIndex: isPassword,
};

@override
Expand All @@ -339,6 +347,8 @@ class SemanticsFlag {
return 'SemanticsFlag.isInMutuallyExclusiveGroup';
case _kIsHeaderIndex:
return 'SemanticsFlag.isHeader';
case _kIsPasswordIndex:
return 'SemanticsFlag.isPassword';
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ enum Flag {
HAS_ENABLED_STATE(1 << 6),
IS_ENABLED(1 << 7),
IS_IN_MUTUALLY_EXCLUSIVE_GROUP(1 << 8),
IS_HEADER(1 << 9);
IS_HEADER(1 << 9),
IS_PASSWORD(1 << 10);

Flag(int value) {
this.value = value;
Expand Down Expand Up @@ -137,6 +138,7 @@ public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) {
result.setAccessibilityFocused(mA11yFocusedObject.id == virtualViewId);

if (object.hasFlag(Flag.IS_TEXT_FIELD)) {
result.setPassword(object.hasFlag(Flag.IS_PASSWORD);
result.setClassName("android.widget.EditText");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
result.setEditable(true);
Expand Down

0 comments on commit cc6b450

Please sign in to comment.