I'm trying to make AccessibilityService get notified about clipboard copy event.
So far I've tried to make work around, so the service would be notified after "copy" button is clicked in popup, but no event is thrown in that situation, I checked all basic events (text selection, type view click etc.)
Is there any possibility to achieve that?
Accessibility services don't receive this event. What you could do is check the content of the clipboard after some subset of Accessibility Events.
#Override
public void onAccessibilityEvent(AccessibilityEvent e) {
switch (e.getEventType()) {
//This event alone may be enough!
case AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED:
// If not fall through for these events as well, which would detect things like a "Copy" button activated.
case AccessibilityEvent.TYPE_VIEW_CLICKED:
case AccessibilityEvent.TYPE_VIEW_CONTEXT_CLICKED:
checkContentsOfClipboard();
}
}
Sadly not possible, as the other answer has written (and from Android 10 you can't even check what's on the clipboard without having an Activity of your own in the foreground), so I've requested to add this API here:
https://issuetracker.google.com/issues/207842550
Please consider starring.
Related
I have a SWT GUI, containing different elements (Text, Buttons, Labels...) which are themselves in different Composites.
I would like to make the navigation easier using some keybindings such as "Alt+c" to call the Cancel Button, "Alt+f" to call the finish button etc... When using a KeyListener on a specific component, the listener is triggered, but it implies that the component has the focus (and this is not very convenient !).
So I tried to register the listener on the shell itself, but the result is the same and nothing is triggered.
How should I proceed in order to get my listener triggered no matters what element is currently focused ?
Any hint would be appreciated.
Thanks for reading.
Edit
Regarding the comments, I tried to add the keylistener recursively to all the composites of the GUI, and it's working. However, I guess there is probably a "clever" way to do it.
You can use the Display addFilter or addListener methods to add a listener which is always called.
Display.getDefault().addListener(SWT.KeyDown, new Listener() {
#Override
public void handleEvent(final Event event) {
// TODO handle event
}
});
These listeners use the lower level Listener interface rather than KeyListener.
addFilter is similar to addListener but is called earlier and can change the event.
The easiest way is to add a event filter to the display:
Here is an example I use to activate a search field when a user types command-F in our main application window.
Display.getCurrent().addFilter(SWT.KeyDown, event -> {
// Only respond to key events for our shell.
if (getShell().equals(Display.getCurrent().getActiveShell())) {
// Activate the focus for our search widget when user types 'f'
// (control-f, command-f, or just f)
if (event.keyCode == 'f') {
if (!searchField.isFocusControl()) {
searchField.setFocus();
}
}
}
});
I have a issue with Vaadin. It seems as the layout click event listener consumes my right clicks as well as left clicks.
I have a layout with some components inside, and when I try to right click for inspecting my elements, nothing happens in the browser since the event is consumed by the code.
Is there a way to prevent it from capturing the right mouse click? Thanks! Checking what was pushed inside the event does not affect the behaviour.. My listener;
this.addLayoutClickListener(new LayoutEvents.LayoutClickListener() {
public void layoutClick(LayoutEvents.LayoutClickEvent event) {
System.out.println("clicked.." + getSuit());
}});
Seems the answer is you can't. See: https://vaadin.com/forum/#!/thread/696409/701753
Now admittedly that is an old answer, but I just tried with vaadin7 and seems to me the behaviour hasn't changed. So you are left with extending the client side if you want to change the behaviour: https://vaadin.com/book/-/page/gwt.html
If you want to inspect specific element you can do:
In Google Chrome:
open Developer Tools (F12),
click on button "Select an element in the page to inspect it." (Magnifier icon on top left),
inspect your element.
How can I check if currently any mouse button is pressed and if so, which one it is?
The thing is that I need to use this kind of information in MouseListener.mouseEntered(). I checked MouseEvent but I could not find the method which would help me.
The getButton() method seems to only return value if there has been change in buttons' state.
Is there a way to find this out without manually keeping track of this somehow vie MouseListener.mousePressed()/mouseReleased() methods.
How can I check if currently any mouse button is pressed and if so, which one it is?
Presumably you want to invoke specific code depending on the button pressed so you can do something like:
if (SwingUtilities.isLeftMouseButton(...))
// do something
You could start by looking at How to write a Mouse Listener and the JavaDocs for MouseEvent in particular, the getButton method.
However, there are cross platform considerations that need to taken into consideration, which are overed by SwingUtilities.isLeftMouseButton and equivalent methods...
This will solve your problem
long eventMask = AWTEvent.MOUSE_MOTION_EVENT_MASK + AWTEvent.MOUSE_EVENT_MASK;
Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
public void eventDispatched(AWTEvent e) {
System.out.println(e.paramString()+"-"+e.getSource());
}
}, eventMask);
This is a Global Event Listeners.
Get the source and button from AWTEvent and do whatever you want to perform.
I regularly see the following code in blackberry development. It registers a listener on a field and when the listener is fired(in below example when focus is on a field) some code is executed. Is this part of a design pattern? How is focusChanged actually called ?
FocusChangeListener focusListener = new FocusChangeListener() {
public void focusChanged(Field field, int eventType) {
// TODO Auto-generated method stub
}
}
field.setFocusListener(focusListener);
Focus change is called by the OS, or some BB APIs that sit close to the OS. Whenever someone scrolls through, or touches a field the focus changes. Think of it kind of like tabbing through a window in a desktop app.
As you move through the controls, your app gets notified of the focus change, which notifies your base manager, and it bubbles up until it gets handled.
Similarly for ButtonClickListener etc. They're basically events that get fired (to think of it in the Windows parlance) and the ChangeListeners that subscribe to those events get called.
I have an application in which you can do a right mouse button press and drag (as well as a left press and drag for different operations). However, when running this on linux, it seems that popup menus are triggered by a mousePressed and not a mouseReleased. This is resulting in every time I press the right mouse button to perform a drag, the popup menus are triggered (unlike windows, where it is mouseReleased).
Any thoughts on how to work around this?
thanks.
EDIT: Posting code
Code for popup menu
// this is called from mousePressed and mouseReleased
if (e.isPopupTrigger() && !e.isConsumed()) {
// show the popup menu
}
This code is what is called on the right mouse press/drag (this is 3rd party code, but it is open source so I can change as needed)
// this is called on all mouse events
if (buttonAction.mouseButton != 0)
{
// handle the event
}
Yes, use isPopupTrigger(), as shown here.
Addendum:
it appears isPopupTrigger is triggered on mousePressed in linux.
Yes, it's the same on Mac OS X. You have to call isPopupTrigger() from both mousePressed() and mouseReleased(). There's a related example in GraphPanel.
MouseEvent.isPopupTrigger(). Returns whether or not this mouse event is the popup menu trigger event for the platform.
edit - : You need to make the check in both mousePressed for linux, and mouseReleased for windows.
I think the correct procedure in your case should be to unify where and when to show the popup. As a drag event, if exist, follows a press event you should avoid writting logic for showing the popup in the press event (and then also write logic in the press event for showing the popup). Some users feel good navigating the popup while holding the popup button, and some other users just don't care or don't know. But in your case, you won't be able to navigate the popup menu while dragging without adding extra code.
My way would we to manage the logic to always show the popup on the release event. Entering a release event after a drag should be enough information to know that the popup shouldn't be visible. And of course, always if you can change and modify the source.