I have a view where a user enters a goal, a date to complete it by, and a confirmation checkbox. A user must enter all of this to move forwards. Thus, I have checks to see if any of the fields are empty. Here is the code for that. This code works.
private fun toggleInputRequiredError(
isErrorVisible: Boolean,
view: TextInputLayout,
errorText: String
) {
when (isErrorVisible) {
true -> {
view.error = errorText
}
else -> view.error = null
}
}
toggleInputRequiredError(
!state.isGoalChecked,
goalAffirmationCheckBoxErrorContainer,
getString(R.string.required_field)
).run {
if (!state.isGoalChecked) {
goalAffirmationCheckBox.isFocusable = true
goalAffirmationCheckBox.requestFocus()
goalAffirmationCheckBox.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED)
}
}
toggleInputRequiredError(
!state.isValidDateInput,
goalDateInputLayout,
getString(R.string.required_field)
).run {
if (!state.isValidDateInput) {
goalCompletionDateInput.isFocusable = true
goalCompletionDateInput.requestFocus()
goalCompletionDateInput.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED)
}
}
toggleInputRequiredError(
!state.isValidDescriptionInput,
goalDescriptionInputLayout,
getString(R.string.required_field)
).run {
if( !state.isValidDescriptionInput) {
goalDescriptionInput.isFocusable = true
goalDescriptionInput.requestFocus()
goalDescriptionInput.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED)
}
}
Now I have to enable accessibility for this view with also works, on most phones except for the latest Samsung phones. The desired behaviour are exemplified by the Pixel XL but also the Samsung S8. Here is an image to show this
On the newer Samsungs the sendAccessibilityEvent doesn't seem to actually focus on the view that needs to be addressed. Here is an image to show this behavior on the Samsung S10+ and Samsung Note 9.
I set the content description of these views in the XML. I noticed that the newer Samsung phones will read the "Required" text on the screen but not focus on it. This means that it ignores the content description in the XML. The last thing is that the view that needs to focusing seems not to experience the sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED) event
Let me know if you have any thoughts on how to address this or if you have any suggestions I can try
In the Samsung S10 device, I can't able set accessibility focus to the custom view. Then I have achieved based on the following code so can try this with your follow maybe it would be helpful.
val task = Runnable {
val mA11yManager = context.getSystemService(Context.ACCESSIBILITY_SERVICE) as AccessibilityManager
if (mA11yManager.isEnabled) {
// Equivalent to ACTION_ACCESSIBILITY_FOCUS
plus_chip_text?.performAccessibilityAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS, null);
// we fire selection events here not in View
plus_chip_text?.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED)
}
}
val worker: ScheduledExecutorService = newSingleThreadScheduledExecutor()
worker.schedule(task, 1, TimeUnit.SECONDS)
Sorry I know this is almost a year later, but we found a very similar issue on Samsung Talkback running Android 10. It would work fine on earlier versions of Android.
We found creating the following kotlin extension function seemed to work for all versions of Android, as well as working well for both Samsung Voice Assistant and Talkback.
Hope this is able to help anyone else facing a similar issue.
fun View?.requestAccessibilityFocus(): View? {
this?.performAccessibilityAction(ACTION_ACCESSIBILITY_FOCUS, null)
this?.sendAccessibilityEvent(TYPE_VIEW_SELECTED)
return this
}
Related
I have the following code to prevent the buttons to stay focused after they are clicked. It works perfectly for desktop but it doesn't work at all when testing on mobile devices (Both iOS & Android), I'm not sure if I'm missing something here (I already tried replacing click with touchstart and touchend).
this.renderer.listen('document', 'click', (event) => {
if (event.target.nodeName === 'BUTTON') {
event.target.blur();
} else if (event.target.parentNode.nodeName === 'BUTTON') {
event.target.parentNode.blur();
}
});
Ok so I figured it out, in case anyone ever comes across this situation:
It WAS actually working, but on mobile devices an "emulated" hover is also applied after pressing buttons, so what I was seeing was the hover state, not the focus one.
I fixed it by wrapping the hover style of my button inside this block, to make sure that the device supports ACTUAL hover (e.g. using a mouse):
#media (hover: hover) {
your-element:hover {
//hover style
}
}
I'm working on an app with intense usage of AccessibilityService. The app works great with other Android apps, I can use text selection properly.
The problem comes with multiline fields in browsers: when trying to perform the action AccessibilityNodeInfo.ACTION_SET_SELECTION, it results in a wrong selection.
Here's my example code snippet. It may not be functional, but it helps with stating the issue:
override fun onAccessibilityEvent(event: AccessibilityEvent) {
val nodeInfo = event.source
if (AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED == event.eventType
|| (AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED == event.eventType
&& event.contentChangeTypes and AccessibilityEvent.CONTENT_CHANGE_TYPE_TEXT == AccessibilityEvent.CONTENT_CHANGE_TYPE_TEXT)) {
nodeInfo?.text?.let {
val arguments = Bundle()
arguments.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_SELECTION_START_INT, 20)
arguments.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_SELECTION_END_INT, 20)
event.source.performAction(AccessibilityNodeInfo.ACTION_SET_SELECTION, arguments)
}
}
}
As an example of what is happening, when in https://translate.google.com/, if you write:
selection is
not
working
and after writing this text you run the code, after performing the action the caret should be placed somewhere here:
selection is
not
work|ing
but instead, it is placed here:
sel|ection is
not
working
The problem seems to be related to endlines. Everything works great if you just write and select in a single line, but when using multiline, it's not working properly.
Any clue??? Did someone experience the same issue?
Right now, I am calling this function before calling the fragment
fun toggleUIEventsListener(delay: Long = 1000) {
activity?.window?.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE)
Timer().schedule(delay) {
activity?.runOnUiThread {
activity?.window?.clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE)
}
}
}
I am sure it will happen in a real device as well. Check in other phones and try tapping as fast as you can (twice) and you will realise that its happening in some real devices as well.
The way you can fix this is... make a boolean say, isClicked, set it to true when its been clicked and then do not allow user to click it for atleast 3 seconds, after that the user should again be able to click that button.
I am facing an issue in Android which is like whenever I am using the maxlenth attribute on input e.g. ; After entering 20 characters on android tab, that page gets hang, I am unable to delete anything or add anything in any other input, other pages works fine but not this page where I entered the charcters upto max limit
I am using on KArbonn Smart Tab 8
Android JellyBean
It is a well known Android 4.1 issue.
Jelly Bean WebView not working well with HTML maxlength attribute for text box
http://code.google.com/p/android/issues/detail?id=35264
Unfortunately, no fix yet. You can follow the above stack-overflow post where they have a JS fix.
I have found the answer and it is working for me:
x$("#fieldWithMaxLength").on("keydown", function(e) {
if(e.keyCode != 8) {
maxlength = $(this).attr('maxlength');
if(this.value.length >= maxlength ) {
var curIndex = $(this).attr('tabindex');
$('[tabindex=' + curIndex + ']').focus();
return false;
}
}
});
I am trying to capture input events on a text input. Using jQuery I am handling the keyup event to populate a list of matches (an auto-complete list). This works fine on the stock browsers and others such as Maxthon, but in Firefox mobile nothing happens while the keyboard is shown--I have to either press enter or hide the keyboard for it work work.
I am using jQuery 1.7.2, Android 2.3 and the latest version of Firefox (10 I believe). I have also tried other events such as input and keydown without any luck.
Is it possible to handle key/input events in Firefox mobile while the keyboard is shown?
The problem is that when word suggestions are turned on in the Android keyboard, Firefox is not triggering the key events during the time the keyboard is "guessing" words, although the values are sent to the text field. I would say this is a bug in Firefox, but I guess they have chosen to do it this way because the result of the key pressed is not consistent with the value the field gets if the keyboard suggests something different than the exact thing you write.
I solved this by using a sniffer that checks on the value if it has changed or not.
var $searchField;
var _keypressWatchingTimer = 0;
var _previousTerm = '';
function keypressStartWatching() {
keypressStopWatching();
_keypressWatchingTimer = setInterval(executeAutocomplete, 100);
}
function keypressStopWatching() {
if (_keypressWatchingTimer != 0) {
clearInterval(_keypressWatchingTimer);
_keypressWatchingTimer = 0;
}
}
function executeAutocomplete() {
var searchTerm = $searchField.val() || '';
if (_previousTerm == searchTerm)
return false;
searchApi.autocomplete(searchTerm);
_previousTerm = searchTerm;
}
function init() {
$searchField = $('#searchField')
.focus(keypressStartWatching)
.blur(keypressStopWatching)
.keyup(executeAutocomplete);
}
init();