/TalkBack/src/com/google/android/marvin/talkback/speechrules/RuleEditText.java
Java | 73 lines | 34 code | 11 blank | 28 comment | 4 complexity | 62b6d9d0cc2130fcd1722d8b5df4d197 MD5 | raw file
1/* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 * use this file except in compliance with the License. You may obtain a copy of 6 * 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, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations under 14 * the License. 15 */ 16 17package com.google.android.marvin.talkback.speechrules; 18 19import android.content.Context; 20import android.text.TextUtils; 21import android.view.accessibility.AccessibilityEvent; 22import android.view.accessibility.AccessibilityNodeInfo; 23 24import com.google.android.marvin.talkback.AccessibilityNodeInfoUtils; 25import com.google.android.marvin.talkback.R; 26 27/** 28 * Processes editable text fields. 29 * 30 * @author alanv@google.com (Alan Viverette) 31 */ 32class RuleEditText implements NodeSpeechRule { 33 @Override 34 public boolean accept(AccessibilityNodeInfo node) { 35 return AccessibilityNodeInfoUtils.nodeMatchesClassByType(node, 36 android.widget.EditText.class); 37 } 38 39 @Override 40 public CharSequence 41 format(Context context, AccessibilityNodeInfo node, AccessibilityEvent event) { 42 final CharSequence text = getText(context, node); 43 return context.getString(R.string.template_edit_box, text); 44 } 45 46 /** 47 * Inverts the default priorities of text and content description. If the 48 * field is a password, only returns the content description or "password". 49 * 50 * @param context 51 * @param node 52 * @return A text description of the editable text area. 53 */ 54 private CharSequence getText(Context context, AccessibilityNodeInfo node) { 55 final CharSequence text = node.getText(); 56 57 if (!TextUtils.isEmpty(text) && !node.isPassword()) { 58 return text; 59 } 60 61 final CharSequence contentDescription = node.getContentDescription(); 62 63 if (!TextUtils.isEmpty(contentDescription)) { 64 return contentDescription; 65 } 66 67 if (node.isPassword()) { 68 return context.getString(R.string.value_password); 69 } 70 71 return ""; 72 } 73}