Talk Back annoucing spinner content description even when editText has focus - android

I have a Layout,
that has a form .. about five items down in the form is a spinner, and everytime my activity loads Talkback seems to read this spinners content description even though the focus and flashing cursor are on the first edittext view.
I can't seem to stop it.. any ideas?

Accessibility Focus and Input Focus are tracked separately in Android. I would need more details about your specific scenario to provide a 100% answer. However, my guess is that your EditText field is requesting input focus when the view loads, so the cursor is being moved there, and potentially the keyboard is popped up (depending on Android version). However, due to tab ordering, or some other mechanism, the spinner is the first item on the page to get Accessibility Focus.
There are two solutions to this, depending on the behavior that you want.
Solution 1 (recommended): Don't have your EditText box request input focus. Allow the user to force input focus into the box on interaction. For capable users, this is just a simple tap into the EditText box.
Solution 2 (less accessibile, but perhaps more usable): Shift accessibility focus to the EditText in your onResume method (or onCreate, or wherever you deem most appropriate). A method like this would be best:
public void resetFocus() {
editTextControl.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
editTextControl.requestFocus();
}
I would recommend calling the above method in onResume, so that every time this particular view loads input and accessibility focus will be in a predictable place. Otherwise, you've created additional accessibility issues.

I solved it simply like this:
/*
This custom Spinner has the purpose of making sure that there are no accessibility events fired after
a selection is made
*/
public class SilentSpinner<T> extends SimpleSpinner<T> {
//region constructors
...
//endregion
//region public methods
#Override
public void sendAccessibilityEvent(int eventType) {
if (eventType != AccessibilityEvent.TYPE_VIEW_SELECTED) {
super.sendAccessibilityEvent(eventType);
}
}
//endregion
}

Related

Which event can I handle when an EditText is completelly filled?

I am developing an Android application.
I implemented a View Pager with Tabs, as described in this link, with a FragmentStatePagerAdapter, and adding the tabs to the ActionBar on the OnCreate method of the Activity.
On my onCreateView event of my frament, I am inflating a layout that contains an EditText View, so each generated Tab has its own EditText for the user to enter data.
The thing is, I currently need to locally store the content of each textbox once its been fully filled with the input the user is writing in each EditText control. For example, I can know that the user is finished entering data, when they change the tab, or unfocus the control.
SCENARIO 1:
I tried attaching a TextWatcher to the EditText control in my onCreateView event of the fragment, but it didn't work for me because I don't need it to be called every time a letter is inserted in my control, so I discarded that option
SCENARIO 2:
I tried attaching a OnEditorActionListener to the EditText control in my onCreateView event of the fragment, but it's never called (like this link explains)
SCENARIO 3:
I was thinking of handling the onTabUnselected event of the TabListener, but I don't know how to access the PREVIOUS EditText control value. Besides, that will only work when the user selects the tab by pressing its header, but not on the swipe event. In that case I am attanching a SimpleOnPageChangeListener to the ViewPager, but again, in that context, I can't know which was the previous Tab, nor can I access its EditText control.
What can I do?
Thank you very much!
When the EditText lose focus, you simply need to add focusChangedListener to the EditText:
OnFocusChangeListener focus = new OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
// TODO Auto-generated method stub
}
};
Every time the edit text lose focus just add the data to a singleton class that holds all of the data, from all of the TextEdits, check this out
android get value from all fragment tab

Why android InputMethodManager.showSoftInput() returns false?

Recently while developing an app, I faced an issue. I have searched a lot on google but couldn't find any solution. In the end I came across this Android issue tracker
To explain my issue, I have made a sample App.
Basic Working of my Sample App
I have a screen, which has an EditText, a Button and a RelativeLayout.
Width and Height of RelativeLayout is 0px. It is just a view to move focus away from EditText.
When App is launched focus is on RelativeLayout, not on EditText(so that there is not blinking cursor in it.)
When a user clicks on Button I just move focus to RelativeLayout using requestFocus() call on RelativeLayout.
When user taps on EditText, keyboard comes up. I can enter text in that.
What I want to achieve
If I change orientation of phone when keyboard is visible then after orienation changes, keyboard should stay.
If keyboard is visible and some other activity comes on top of it for e.g. alarm, facebook chat heads, opening something from notification area, locking unlocking device, etc.. then on returning back to sample app keyboard should be visible.
How I am achieving this
In onSaveInstanceState(), I check if focus is on EditText then put a boolean variable in Bundle.
In onStop(), I am setting a one boolean flag wasEditing = true.
In onRestoreInstanceState(), I checked if Bundle has flag value set in onSaveInstanceState(). If yes then I am make wasEditing = true.
In onResume(), I check this wasEditing and if it is true, I request focus for EditText.
After that I call imm.showSoftInput(mEditText, InputMethodManager.SHOW_IMPLICIT,resultRec)
Where I am getting problem
Sometimes after executing this call, Keyboard is not visible in few cases, like during orientation change.
When I put logs I have found this function is returning false
But if I make this showSoftInput() call with some delay of 100ms using mEditText.postDelayed() in onResume() everything works fine.
Question
In what cases this function returns false and why delay is working?
Note
Although I have solved my problem using delay, but I still want to know why it is behaving like that.
This is a problem I ran into today as well. Of my 8 android devices only 1 has the problem and it's running Android 4.0.4.
The problem was fixed by adding
mEditText.requestFocus();
mEditText.requestFocusFromTouch();
before calling
mEditText.showSoftInput(...)
You'll see the resultcode from showSoftInput is now true. I noticed that after the mEditText.requestFocus() the isFocused() was still false. Probably a bug in Android 4.0 and perhaps 4.1.
Please call showKeyboard after your mEditText is attached to window.
Please make sure the time you make the call.
PROBLEM:
I faced with this keyboard not showing up problem. I found the following solution inspired by this answer but not their solution! In short the reason for this mess is that the request focus and the IMM provided service can only run on a view that is created and active. When you do all these on the creation phase onCreate(Bundle savedInstance).. or onCreateView(LayoutInflater inflater... and the view is still in initializing state, you won't get an active view to act on! I have seen many solutions using delays and checks to wait for that view to get active then do the show keyboard but here is my solution based on the android frame work design:
SOLUTION:
in your activity or fragment override the following make sure your view has the access (define it in the top of the activity/fragment):
#Override
public void onStart() {
yourView.requestFocus();
showSoftKeyboard(yourView);
super.onStart();
}
public void showSoftKeyboard(View view) {
if(view.requestFocus()){
InputMethodManager imm = (InputMethodManager)
mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
}
}

Trouble doing searchView within main activity (NOT actionbar)

I have a main activity that, among other elements, has a search view on screen. When a client clicks on the search box (and makes an entry) I need to invoke an activity that will provide results to populate other places on that activity screen.
I've looked at a ton of StackOverflow (and other) threads about implementing search view (am using the widget) - most either refer to using the action bar or a separate search activity window. Neither are options in this case.
Without lectures on why I should use the action bar, does anyone have the very basics on using search? In effect, when they enter info in it and click the search icon (magnifying glass) I want to listen for a click/search on that item, call a function to get the contents of that (as in intent.getStringExtra(SearchManager.QUERY);), do some work and go from there. However, I'm not successful in hooking in to when the search icon on the keyboard is pressed and getting the user's search line. Any ideas?
Thanks
Okay, finally figured it out. Oh so often I'll look at something for hours, finally post a question, then figure it out 20 minutes later. Oh, well. Hopefully this helps someone else:
What I've got is an embedded search view in another activity and I just want to hook into it like I would a button. I found lots of stuff regarding action bars and xml intents and all that crap, but what I really wanted turned out to be this:
Make sure to import the listener:
import android.widget.SearchView.OnQueryTextListener;
Say that you implement it:
public class MainActivity extends Activity implements OnQueryTextListener {
Then just stick in the functions:
#Override
public boolean onQueryTextSubmit(String myQuery) {
// "myQuery" represents query as submitted. Go ahead
// and do your searchy stuff here
return (false);
} /* on query text submit */
#Override
public boolean onQueryTextChange(String change)
{
// "change" represents current text string as being typed
return(false);
} /* on query text change */
That's all I wanted :)

Which method handles the changing appearance of a Fragment UI?

Basically, I have a list of detail fragments and each one represents a list of peers of that phone. When one of these DeviceDetails is tapped on, a selection of buttons and text appears. Which of these buttons and text appears depends on the status of the phone; it is either connected to the phone being used, or it is available for connection.
I currently use the fragment's onCreateView to make 3 buttons appear. 1 of these buttons should appear every time, and the other 2 alternate depending on the connected/available state.
I am trying to figure out which overridden fragment method should handle the changing UI's. It should just be a case of if statements (or maybe switch statements?) but I am not sure where to place these?
Well if let's say you have an Activity and it is hosting all these Fragments.
I assume there is some event that triggers this state to happen, maybe in that Activity
public void onSomeEventThatICareAbout(EventDetails deets) {
Fragment fragment = getFragmentManager().findFragmentById(R.id.my_fragment_with_buttons);
if (fragment != null) {
((MyButtonsFragment)).disableButtons(deets);
}
}
Basically just treat the fragment like any other component and call methods on it based on events like normal, whether it is an onClick(), a AsyncTask callback, or whatever. Just call the function right on the fragment.
Define your own way for your fragment to do what you want,
public void disableButtons(EventDetails deets) {
View view = getView();
view.findViewById(R.id.button1).setEnabled(false);
view.findViewById(R.id.button2).setEnabled(false);
}

In Accessibility Mode, I Want To Override The TalkBack For A TextView

I currently have a ListView and each element of that list consists of at least two TextViews. I'm adding accessibility to my app, so whenever I focus on a certain list element, it reads out the text in each TextView.
Right now, I'm sending it a TalkBack event, but right after it completes it, it reads out the TextViews again. I want it to only complete my TalkBack event and nothing else.
Anyone have a clue how to do this?
Thanks in advance!
Sure, just override View.dispatchPopulateAccessibilityEvent.
From the doc (emphasis mine):
A typical implementation will call onPopulateAccessibilityEvent(AccessibilityEvent) on the this view and then call the dispatchPopulateAccessibilityEvent(AccessibilityEvent) on each child. Override this method if custom population of the event text content is required.
Within that method, you can add any text you want to the event in the following manner:
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
event.getText().add("Hey look!");
return true;
}

Categories

Resources