Android Accessibility, how to remove all Button Actions? - java

On Android, TalkBack announces "Double tap to activate, double tap and hold to long press".
How can I remove all these default actions and just have it say nothing?
While ignoring whether that is a good idea or not for now.
Update the below code seems to not do anything:
private class NoActionsAccessibilityDelegate : View.AccessibilityDelegate
{
public override void OnInitializeAccessibilityNodeInfo(View host, Android.Views.Accessibility.AccessibilityNodeInfo info)
{
base.OnInitializeAccessibilityNodeInfo(host, info);
foreach (var action in info.ActionList.ToList()) //to list ensures we are not iterating while modifying the readonly ActionList property
{
info.RemoveAction(action);
}
}
}

If your 'view' does not have a click action but for some reason the system detects it as clickable, use the following, (I am using Xamarin for my implementation and the code to disable actions is as follows):
myView.Clickable = false;
myView.LongClickable = false;
Yes that will disable interaction with the view, but in my case the view is not meant to be interactable to begin with. For some reason the system thinks it has an action though it does not.

Related

Validate CTabFolder before switching tabs

In a CTabFolder, I'd like to check the content for unsaved data before the user can switch from one tab to another. SWT does not provide a PreSelection event, as stated here.
I found a workaround, suggesting to switch back to the old tab when a selection is triggered, validate the data and then perform the desired switch again, if data is valid.
I do understand the general idea of this workaround, however, it is not working for me. oldPageIndex and newPageIndex do always have the same value, though I did not click on the same tab.
this.tabContainer.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent event) {
int oldPageIndex = tabContainer.getSelectionIndex();
int newPageIndex = tabContainer.indexOf((CTabItem)event.item);
// Here: oldPageIndex == newPageIndex
...
}
});
Is this workaround still working or is there anything I could possibly be doing wrong? Or maybe, has there been any fix for a real PreSelection event in the meantime? I tried using event.doit, but the SelectionEvent is fired, when the tabs have been switched already.
You can use the selection listener but as you have found the getSelectionIndex() does not give you the old tab. So you will have to maintain the old tab index yourself.
This is the technique used by the Eclipse FormEditor.

how to get rid of visual effect when disabling buttons in java

When I'm setting the button to be disabled using this:
jButton.setEnabled(false);
then there is this visual effect visible on the second element ->
How can I disable the button, but keep the the look of the first element?
how to get rid of visual effect when disabling buttons
Companies spend millions of dollars to develop a UI can is common and can be used by all users.
How is the user suppose to know that the button is disabled if there is no visual indication?
Anyway, (rant finished) you can manually set the disabled icon:
button.setDisabledIcon( button.getIcon());
If you also happen to have text on the button the text will still be disabled so instead of a disabled icon you can use a custom ButtonModel:
button.setModel( new DefaultButtonModel()
{
#Override
public boolean isArmed()
{
return false;
}
#Override
public boolean isPressed()
{
return false;
}
});

GWT event prevent default not working in Java

I'm new to GWT and I need to get a right click working. The doco I've read suggests that I need to override the onBrowserEvent() method. I'm just experimenting at this stage. the event is processed and my pop-up appears. However, as soon as I close the pop-up, the usual browser drop down menu appears (with options like "Bookmark this page" and such).
I'm using IceWeasel 24.5.0 (FireFox clone for Debian) and, obviously, Debian (wheezy).
Here's the relevant code:
public ActivityTextCell() {
super(BrowserEvents.MOUSEDOWN, BrowserEvents.MOUSEUP);
}
#Override
public void onBrowserEvent(
com.google.gwt.cell.client.Cell.Context context,
Element parent,
ActivityDTO value,
NativeEvent event,
ValueUpdater<ActivityDTO> valueUpdater) {
super.onBrowserEvent(context, parent, value, event, valueUpdater);
event.preventDefault();
event.stopPropagation();
if (event.getType().equals(BrowserEvents.MOUSEUP)) {
Window.alert("mouse up event");
}
else {
switch ( event.getButton()){
case NativeEvent.BUTTON_RIGHT:
Window.alert("right mouseclick");
break;
case NativeEvent.BUTTON_LEFT:
Window.alert("left mouseclick");
break;
case NativeEvent.BUTTON_MIDDLE:
default:
break; // Do nothing
}
}
The class ActivityTextCell extends AbstractCell.
So what am I missing? How do I stop the browser from reaticng to the mouse click?
Well it certainly wasn't a matter of a few minutes (as can be seen by the fact that it has taken me a week to get back to this), but I have a solution. I tried reversing the order of the the event.preventDefault() and super.onBrowserEvent() but it didn't really help.
I tried a little experiment on a normal web page. It turns out, that the MOUSEDOWN event doesn't do anything in that context and the usual browser selection menu appears on the MOUSEUP. So the if/else logic sort of fell by the wayside.
What did the trick is to include the following in the top level GUI class immediately after adding the main page:
RootLayoutPanel.get().addDomHandler(new ContextMenuHandler() {
#Override
public void onContextMenu(ContextMenuEvent event) {
event.preventDefault();
event.stopPropagation();
}
}, ContextMenuEvent.getType());
This has the additional benefit (for my purposes, at least) of preventing the Browser from reacting to a right click anywhere in the application view.
As an aside: The purpose of preventing the default action is to stop the Browser doing its own thing Stopping propagation is possibly not required, but I left it in anyway (propagation goes fro the node up to the root, not the other way around). The purpose of overridinging onBrowserEvent() is to enable your own application to handel that event. The use of super.onBrowserEvent() is to allow the event to be handled by your code in the first place. I've given the relevant reference in my previous comment. The book "GWT in Action" is well worth a read if you're likely to be doing a lot of GWT coding.
You call super.onBrowserEvent() which triggers the standard browser response.
You should move event.preventDefault() to the if part of your code, and super.onBrowserEvent() to the else part. You want one of them executed depending on a browser event, but not both.

Hide Mouse Pointer on Android

I'm writing a game for OUYA and Android and I'm using the trackpad on the OUYA controller. When ever you touch it a mouse pointer comes up and I can't find a way to hide it. I image this would be a problem for games on an Android netbook as well.
Has anyone found a way to interact with the cursor instead of just listening for events?
This won't hide the mouse, but it will at least help prevent touch events from interfering with your joystick processing code -- not a proper solution I know, but still might help people who land on this page:
public boolean onGenericMotionEvent(MotionEvent event) {
if ( (event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) {
//handle the event
return true;
}
else {
return false;
}
}
Android currently does not expose any functionality to hide the mouse cursor. Whenever you have an external pointing device (ie. usb/bluetooth mouse, trackpad, etc) a mouse pointer will appear on the screen whenever you interact with the device.
Unfortunately (as of JB 4.2.2) this means it is impossible without a modified ROM.
It is possible to request pointer capture now. You need to explicitly request capture:
fun onClick(view: View) {
view.requestPointerCapture()
}
As documented:
Android delivers pointer events from sources other than the mouse normally, but the mouse pointer is not visible anymore.
You can either handle pointer events by overriding onCapturedPointerEvent:
override fun onCapturedPointerEvent(motionEvent: MotionEvent): Boolean {
// Get the coordinates required by your app
val verticalOffset: Float = motionEvent.y
// Use the coordinates to update your view and return true if the event was
// successfully processed
return true
}
or registering an event handler for OnCapturedPointerListener:
myView.setOnCapturedPointerListener { view, motionEvent ->
// Get the coordinates required by your app
val horizontalOffset: Float = motionEvent.x
// Use the coordinates to update your view and return true if the event was
// successfully processed
true
}
And it's up to you to release the pointer when you're done:
override fun onClick(view: View) {
view.releasePointerCapture()
}
I know that the context of this question overall may not apply (ie: Ouya development), but this was the first search result when I looked into how to do this myself. So I figured that I'd update the answer!

Selecing an item in a Blackberry ListField

I've been using this book as reference to creating my Blackberry application. So far I have a list of items and when I select one I get the side menu but next to my list item:
Just looking through my methods, I'm not sure which one causes this as I can remove the custom item (GetValue) from the Menu and it will still appear here when I select the list item!
I guess my question is, how can I stop this menu appearing and have a method fire instead? I can provide code if necessary but I don't know where to start with this one!
Thanks
Can you show your code when invoking the method.
When I override the navigationClick method of the ListField class like in the code below it works properly. (no menu pops)
protected boolean navigationClick(int status, int time){
return true;
}
#ing0
You can override default menu by using OnMenu() method
public boolean onMenu(int i)
{
return false;
}

Categories

Resources