Reputation: 8145
I'm developing an application adapted to people with visual disabilities
. If the device has an Android API
greater than 14 I want to enhance Talkback
a bit.
I have a ListView
filling the whole screen where each row has just one TextView
. Since the text might be quite long, I wanted to use marquee
and single line to scroll the text when the user clicks in it.
I tested it without Talkback
and it works:
So I decided to test it with Talkback active. In this case, I have two kind of problems:
1- Some rows doesn't scroll at all.
2- Some rows scroll, but I can't see more text than the one that is shown when the text isn't scrolled:
I don't know why some rows scroll and some doesn't, I use the same code for all of them.
To change the background color and start the marquee I'm adding an AccessibilityDelegate
to each row.
This is the layout for each row:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/rowTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
android:textSize="18dp" />
</LinearLayout>
And this is some of my adapter's code:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null){ // If the View is not cached
// Inflates the Common View from XML file
convertView = this.inflater.inflate(R.layout.list_simple_row, parent, false);
}
TextView tv = (TextView) convertView.findViewById(R.id.rowTextView);
tv.setText( list.get(position) );
convertView.setContentDescription( list.get(position) );
addAccessibilityDelegate(tv, position); // Add delegate to the TextView to detect touches
tv.setSingleLine(true);
if(position == selected){
// The user touched this row: Change background color to green.
convertView.setBackgroundColor(Color.GREEN);
tv.setTextColor(Color.BLACK);
tv.setSelected(true);
}
else{
convertView.setBackgroundColor(Color.TRANSPARENT);
tv.setTextColor(Color.WHITE);
tv.setSelected(false);
}
return convertView;
}
protected void addAccessibilityDelegate( View v, final int position ){
v.setAccessibilityDelegate(new AccessibilityDelegate(){
@Override
public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) {
super.onInitializeAccessibilityEvent(host, event);
}
@Override
public void onInitializeAccessibilityNodeInfo(View host,
AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(host, info);
}
@Override
public void onPopulateAccessibilityEvent(View host, AccessibilityEvent event) {
super.onPopulateAccessibilityEvent(host, event);
if(event.getEventType() == AccessibilityEvent.TYPE_VIEW_HOVER_ENTER){
focusBackground(position);
}
}
});
}
public void focusBackground(int position){
if(selected != position){
selected = position;
notifyDataSetInvalidated();
}
}
Anybody knows if I can use marquee with Talkback?
Thank you!
Upvotes: 0
Views: 803
Reputation: 3426
Check out this bug on the Android bug tracker, it looks like Accessibility services interfere with the ellipsize property on TextViews. I was having similar issues with android:ellipsize="start"
jumping to the start of the string until I disabled the LastPass Accessibility service. I verified that the Talkback service caused the same issue.
Upvotes: 1