Im using Gluon to develop javafx applications to Android, Iphone (and to desktop). When I export a test application to my Android phone (Marshmallow 6.0) - I cannot hold down onto text to access the menu from where you can copy text (the context menu)
(Which is an example of what you can do with a context menu - and is not a question of how to copy text on long hold specifically in Android).
This was possible on iphone 6 when testing it there.
How can I detected wether the device/operating system has a default context menu or not in java?
On Desktop there is a default ContextMenu that is created and installed in TextFieldBehavior (private API). If you don't set your own custom context menu, that will be the one used when a ContextMenuEvent is fired (with a right click event for instance).
On mobile, both Android and iOS have a ContextMenu as well.
On iOS, it uses a native TextField (UITextField). When the long press event happens, it triggers the default context menu (on my iPad I can see a small magnifying glass, and after that the context menu shows up).
On Android, the JavaFX TextField has a custom skin, but shares the same private TextFieldBehavior as the desktop version. The problem in this case is the missing right click event that would trigger the ContextMenuEvent event.
That's why you have to fire manually a ContextMenuEvent event, as it was described in this question.
Conclusion: so far, this is basically required only on Android:
TextField textField = new TextField();
addPressAndHoldHandler(textField, Duration.seconds(1), event -> {
Bounds bounds = textField.localToScreen(textField.getBoundsInLocal());
textField.fireEvent(new ContextMenuEvent(ContextMenuEvent.CONTEXT_MENU_REQUESTED,
0, 0, bounds.getMinX() + 10, bounds.getMaxY() + 10, false, null));
});
Related
Goal: From a website having a lot of links, I will usually middle click the ones I want. Firefox will open them in background new tabs on the side. Now I want to do the same from my Android tablet where middle click is not available.
1) Best: Is there an easy way to middle click on a tablet ?
2) Otherwise something better than a long press to simulate right click then open in new tab ?
3) I'm currently trying a TamperMonkey solution based on other questions found here:
link.addEventListener('click', function(event){event.preventDefault();return newBackgroundTab(this);}, false);
function newBackgroundTab(node) {
var newWindow = window.open("about:blank", "_blank");
newWindow.blur();
window.focus();
newWindow.location.href = node.href;
return false;
}
It also need to set the dom.disable_window_flip option to false in Firefox.
This works on desktop, but not on Android, focus stays on the new tab even though the disable option was already on false by default.
I have created some custom radial menu buttons for my Android game. The radial menu displays when the game object with the menu is touched. I'm using mouse events to activate the menu, which works in Unity and also when built to Android. When the menu is active, you can mouse or slide over a menu item to select it. If you then release on that menu item, it will pass the selection to the radial menu, which then takes the appropriate action.
The following works in Unity:
public void OnPointerEnter (PointerEventData eventData)
{
myMenu.selected = this;
Debug.Log ("Menu selection is now: " + this.action.ToString ());
defaultColor = circle.color;
circle.color = Color.white;
}
public void OnPointerExit (PointerEventData eventData)
{
myMenu.selected = null;
Debug.Log ("Menu selection has been nulled out.");
circle.color = defaultColor;
}
However, it does not work correctly when built to Android. Via some debug testing, I've determined that in Unity, if I activate the menu and mouse over a menu item, then release the mouse, myMenu.selected is correctly assigned. However, on Android only, lifting my finger over the menu item processes a final OnPointerExit, which nulls it out, meaning that menu never gets a proper selection. The mouse does not behave this way--it doesn't treat the pointer as having exited when the mouse button is released.
I can "solve" this problem by switching everything to touch, but then I cannot test using the Unity player and my mouse. So far, everything via mouse also worked correctly via touch. This is the first issue I've run into. Is there any clean solution for this? Or is the best solution to use macros to determine if I'm in the editor and have separate mouse and touch code for each?
It depends on the behavior you trying to implement.
Touch input does not have the notion of "hover" so you should probably be using the IPointerClickHandler interface and/or the IPointerDownHandler and IPointerUpHandler interfaces instead.
I recommend separating the hover logic vs touch/click clearly by using the preprocessor directive #if UNITY_STANDALONE around your hover-code.
I want to create a mobile app (with possible desktop use) that uses a context menu and has as close to a native look and feel as possible for both Android and iOS. (This is my first foray into both Qt and QML.)
I figured out how to create a Menu and call myMenu.popup() to show the context menu. And in Android this context menu looks very similar to a native android context menu. This context menu also looks native on the desktop. The problem comes with iOS.
iOS has a similar concept to context menus called actionsheets. Examples. But the contextMenu looks like a windows context menu (right click menu) floating on the window.
tl;dr;
Is there a way to get the Menu in qml to look similar to iOS actionsheets when run on a iOS device? I have searched for hours today and can't find anything.
code:
The Menu code is mostly copied from the Qt docs just to see how things look and work
Menu
{
id: myContextMenu
title: "Edit"
MenuItem {
text: "Cut"
onTriggered: {console.log("cut")}
}
MenuItem {
text: "Copy"
onTriggered: {console.log("copy")}
}
MenuItem {
text: "Paste"
onTriggered: {console.log("paste")}
}
MenuSeparator { }
Menu {
title: "More Stuff"
MenuItem {
text: "Do Nothing"
}
}
}
MouseArea {
id: longPressArea
anchors.fill: text
onClicked: {
myContextMenu.popup()
}
}
Summarizing the comments above: No, not in the current version of Qt, unless you roll your own in QML.
Quick Controls uses one of [native, QWidget, QML] implementations, whichever is found first. You can read the source to see that there is no native implementation: grep for createPlatformMenu() in Qt/../Src/qtbase/src/plugins/platforms/ios. Thats where the adaptors to native widgets are.
Another answer is: you could contribute by creating the adaptor to the native widget for iOS (if you are an iOS and C++ programmer.) Also assuming that a UIActionSheet is the proper widget to adapt (it seems so.)
I suppose your concern is that a centered menu (instead of a native one that animatedly slides onto the screen like a drawer, the feel) doesn't meet the HIG (or that the style/look is wrong.) Thats a moving target. The iOS8 documentation under showInView seems to say a centered popup menu is an option (at least on iPad, its unclear whether it would work on a phone.) And its fuzzy what the store would reject.
Isn't that an intended benefit of QML: you could provide different skins for tablet and phone?
With Qt Labs, since Qt5.8, you can get native looking menus on macOS, iOS, Android and Linux (gtk+). Haven't tried it myself yet, but you can take a look:
https://doc.qt.io/qt-5.12/qml-qt-labs-platform-menu.html
You need to import Qt.labs.platform 1.1, link against widgets with QT += widgets and use a QApplication instead of QGuiApplication.
For comparison, here is also the stable menu from qml which does not try to look native.
https://doc.qt.io/qt-5.12/qml-qtquick-controls2-menu.html
I have set up a small mobile application and during tests I have stumbled upon a problem with older versions of mobile devices running Android version 2. Please note that iPhones, iPads and newer versions of Android, namely 4.xx display the pages well. The problem is as follows:
When page is called directly from the link:
Home
it is properly displayed.
However, when there is a click handler on a link, like here:
$(document).on('click', '#lstAddrList li', function ()
{
var anchor = $(this).find('a');
sessionStorage.SiteAddr = anchor.attr('id');
changePage();
});
the list line (in this case) stays selected and nothing happens. It is ONLY after the calling page is refreshed directly from the browser when the called page is displayed. I have a feeling that older Androids do not properly handle changePage() method.
Will you have some ideas?
I have an address search field in my app. When this field gets focus I want to open the keyboard as in the following image.
It works fine for iOS when the keyboard type is set to Titanium.UI.KEYBOARD_NUMBERS_PUNCTUATION as in the following code
var search = Titanium.UI.createSearchBar({
barColor:'#c8c8c8',
autocorrect:true,
hintText:'enter address',
height:'43dp',
top:'75dp',
autocapitalization: Titanium.UI.TEXT_AUTOCAPITALIZATION_WORDS,
keyboardType:Titanium.UI.KEYBOARD_NUMBERS_PUNCTUATION
});
However on Android it appears as in the following image.
I am using Titanium mobile SDK 1.7.5
You should probably add :
softKeyboardOnFocus : Titanium.UI.Android.SOFT_KEYBOARD_SHOW_ON_FOCUS
Unfortunately, it may be overridden by the system. Try it on another Android system (3.0 for example) if the problem persist.