React Native Custom Text Selection Menu - java

We are making a reading book application with React Native, but we have a problem about context menu. As you know many reading applications have a customized menu when user long press on text. There is a different menu instead of standart Android context menu (Copy-Paste-Select All)
For example: https://prnt.sc/w14pap (App XODO - https://play.google.com/store/apps/details?id=com.xodo.pdf.reader&hl=tr)
We want to show a menu like that.
We tried both in javascript side and react native plugin (https://github.com/Astrocoders/react-native-selectable-text), but we couldn't succeed.
Plugin supports only text, but we want to show icons only.
Could you help me please how can I make a context menu like this?
What we need?
When user long press on text, a customized menu must be shown
When user extend selection, the customized menu mustn't be lost or should be shown again.
When user long press or extend selection, we must get start and end indexes of selection.
We are using Text component because of we can colorize/underline some words of text. (TextInput doesn't support partial styling)
If it is not possible to do it without native bridge, is there any ready plugins in native side to bridge?

Related

How can I create a popup menu that allows user to choose a certain elements from a list on Java?

I am writing a Java program to record some events and their status, i.e., done or not. I have implemented the recording and calculations, but I also want to have a button that will open another window that will list the events with a checkbox corresponding to each of them, so I can pick which ones' statuses I will change to done. I have only used Swing libraries so far.
I want this window to contain one event per line, with a checkbox next to the event. Each checkbox should determine whether the status of the even should be changed or not. I had trouble even making such a window open and list the items, let alone put the checkbox.
Note: The design is not too important. This won't be a published project, I will mostly use it for personal work. I can do with buttons instead of checkboxes, where any click changes the status of the event next to it.
Thank you in advance for your valuable responses.

java swing GUI. Allow user to rearrange buttons

Many programs allow to freely rearrange buttons on gui. For instance Firefox and Chrome have "customize" option. How to do it in Java? Sure, I can bring GUI constrains to settings file and let user edit it, but this isn't user friendly.
Is there a better way to do this?
How to do it in Java?
There is no built in support, so you need to provide this yourself.
You might start with a configuration dialog. It could display a JList with the text of all the buttons in the order in which you want the buttons displayed.
Then the user would be able to drag each item in the list to a new location
When the user is finished they would click "Save" and you would store the order in a user properties file.
Then you would iterate through the list and change the order of each button on your panel.
Every time you start your application you would need to read the user properties file and perform step 4.
Check out the Drop Demo Project from the Swing tutorial on Drag and Drop. It will show you how to implement the JList so items can be dragged to a new location.
So basically you need to write the code yourself.
You can try creating a preference menu like you find in Chrome etc. This will provide for a familiar and user friendly method to do so. You can also go ahead and allow the use to change icon or size if you want to.
Another way could be that you allow the buttons to be dragable and resizable across a container and using events based on movements of the mouse to reorder the buttons in question.

How do I toggle the menu button icon and tooltip text for an Eclipse plugin?

I'm developing an Eclipse plugin that has a toolbar menu item that will be enabling/disabling a feature. I know how to set the icon and tooltip text for it using the plugin.xml file, but I want to be able to change the icon and especially the tooltip text for it depending on the state of the project being worked on. I.e., if the feature is not enabled, I want an icon that shows turning the feature on along with tooltip text that says "enable feature", but if the feature is enabled, I want an icon that shows turning the feature off along with tooltip text that says "disable feature". Right now, the only option I can see is a generic icon and tooltip text that says "enable/disable feature", but that feels clumsy to me.
Edit to add: In response to indigomonkey's answer, which is a good one based on what I originally wrote, I would like to clarify that the behavior that is being enabled by the toolbar button is one that we really discourage ever disabling once it has been enabled (and a dialog pops up both to when enabling it to verify that they want to enable it because it should not be started lightly as well as to discourage them from disabling it once it is enabled). Because of this, I would like the icon to change to one that suggests "don't click on me".
If your command Handler implements IElementUpdater the updateElement method will be called whenever the command is run.
The UIElement parameter of updateElement has setIcon and setTooltip methods.
I would suggest that you choose to create your toolbar contribution as a 'checkbox' type, rather than the standard 'push'. This will mean that the button will toggle between a selected and unselected state, allowing you to equate this behaviour to the enabled and disabled state of your feature.
If you're using org.eclipse.ui.commands and org.eclipse.ui.handlers along with the org.eclipse.ui.menus extension point to contribute your button with a <command> element, you'll need to set its style attribute to check. You can then read and toggle the command's selection from inside the handler.
For more information, see http://blog.eclipse-tips.com/2009/03/commands-part-6-toggle-radio-menu.html.
In rcp E4 the solution seems to be a bit different. Since I first stumbled accross this question, I want to summerize/link the solution for future developers.
The relevant questions, where I found the answer are Switch Image of a Handler in a e4 rcp and RCP 4 Toggle a button in the toolbar.
Basically you need to add the argument MToolItem to your Execute-method like this:
#Execute
public void execute(final MToolItem item)
{
item.setIconURI("platform:/plugin/......");
//additional changes e.g. to the tooltip are also possible.
}
If you additionally give your toolbarbutton type checked
<elements xsi:type="menu:HandledToolItem" type="Check" ...
the item will automatically toggle between selected/unselected with each click. You can get the current state with
item.isSelected(). As a side effect, the toolbar icon will be highlighed in the selected-state. If you don't want that, you need to keep track of the state yourself.

J2ME: How to press keypad programmatically?

Is it possible to press keypad programmatically so that number for the key pressed shows on the screen? See the screenshot below for more explanation please:
Details:
Nokia N70
CLDC 1.1
MIDP 2.0
How you approach it will depend on what you want to achieve.
You can quite easily simulate pressing keys on a Canvas, by calling your Canvas's keyPressed(), keyReleased() and keyRepeated() methods directly.
This could be good for testing a canvas-based game, ensuring a given state is entered when certain keys are pressed on the canvas.
However, this won't allow you to control any form-based interaction, or native prompts. So you can't start the MIDlet, navigate through a LCDUI Form or List, accept a native security prompt, or edit a native TextBox. You'd need to use an emulator and some form of test scripting framework which simulates keypresses, such as Eggplant.
if you want to mimicking the keypressed process, just call the keypressed with the int of key as argument, for example keyPressed(-8);
Or are you trying to display the key number in the screen ?

Java Menu issue

I have a menu with a few JCheckBoxMnuItems. How do I ensure that the Menu stays open until I have done all my selections (i.e. checked the menuitems) and does not close on just clicking one of them?
I'd rather not try to change the normal menu behavior for an application or for a part of the menu tree. A User expects that the menu closes automatically after a menu item is clicked. And, if you kept the menu expanded, what kind of action would you invent to close it manually after you've done your last selection?
If there's a requirement to change more then one setting within one use case, then you should consider to provide a small dialog where the use can apply the changes and confirm them at once. I believe, that's more consistent with typical behaviors of UIs.
And it declutters the menu bar, you'll have just one 'setup' menu item instead of a dozen (?) check box actions :)
I guess menu's aren't supposed to allow multi-selection.
But you may offer keyboard shortcuts to set the menuitems without using the menu at all.
If the set-operation of your flags is a central aspect in your application, I would tend to use a dialog here. These are all suggestions which do not require to change the internal implementation of the existing controls, even though I know, that it would be possible in swing.
I agree that it is better to do this with standard UI. However, if do you want to add checkboxes that do not close the menu it is surprisingly easy:
JCheckBox checkBox = new JCheckBox("Text");
checkBox.setOpaque(false);
checkBox.setRequestFocusEnabled(false);
menu.add(checkBox);
This may not work on every look and feel and the check boxes will not line up with menu items in the same manner as JMenuItems but it seems to be a reasonable place to start.

Categories

Resources