Package net.rim.device.api.ui

Examples of net.rim.device.api.ui.MenuItem


        final AddHeaderFieldAction addBccMenuItem =
                new AddHeaderFieldAction(Message.RecipientType.BCC,
                        "Add Bcc: ", "Bcc: ");

        // MenuItem to save a message
        final MenuItem saveMenuItem =
                new MenuItem(new StringProvider("Save Message"), 0x230020, 1);
        saveMenuItem.setCommand(new Command(new CommandHandler() {
            /**
             * @see net.rim.device.api.command.CommandHandler#execute(ReadOnlyCommandMetadata,
             *      Object)
             */
            public void execute(final ReadOnlyCommandMetadata metadata,
                    final Object context) { // If the save is completed, then
                                            // discard this screen
                if (onSave()) {
                    close();
                } else
                // If the message could not be saved, alert the user
                {
                    UiApplication.getUiApplication().invokeLater(
                            new Runnable() {
                                public void run() {
                                    Dialog.alert("Message could not be saved");
                                }
                            });
                }
            }
        }));

        // MenuItem to send a message
        final MenuItem sendMenuItem =
                new MenuItem(new StringProvider("Send Message"), 0x230010, 0);
        sendMenuItem.setCommand(new Command(new CommandHandler() {
            /**
             * @see net.rim.device.api.command.CommandHandler#execute(ReadOnlyCommandMetadata,
             *      Object)
             */
            public void execute(final ReadOnlyCommandMetadata metadata,
View Full Code Here


            // Initialize UI components
            setTitle("Notifications Demo");
            add(new RichTextField("Trigger notification from menu."));

            // A menu item to generate immediate and deferred events
            final MenuItem notifyItem =
                    new MenuItem(new StringProvider("Notify (ID1)"), 0x230010,
                            0);
            notifyItem.setCommand(new Command(new CommandHandler() {
                /**
                 * @see net.rim.device.api.command.CommandHandler#execute(ReadOnlyCommandMetadata,
                 *      Object)
                 */
                public void execute(final ReadOnlyCommandMetadata metadata,
View Full Code Here

                new LabelField(
                        "Select 'View Map' from the menu to see the default map view.");
        add(instructions);

        // Displays the default map
        final MenuItem viewMapItem =
                new MenuItem(new StringProvider("View Map"), 0x230010, 0);
        viewMapItem.setCommand(new Command(new CommandHandler() {
            /**
             * @see net.rim.device.api.command.CommandHandler#execute(ReadOnlyCommandMetadata,
             *      Object)
             */
            public void execute(final ReadOnlyCommandMetadata metadata,
View Full Code Here

                new RichTextField("Select an option from the menu.",
                        Field.NON_FOCUSABLE);
        add(rtf);

        // Displays an InvokeContactScreen
        final MenuItem invokeContactItem =
                new MenuItem(new StringProvider("Invoke Contact"), 0x230010, 0);
        invokeContactItem.setCommand(new Command(new CommandHandler() {
            /**
             * @see net.rim.device.api.command.CommandHandler#execute(ReadOnlyCommandMetadata,
             *      Object)
             */
            public void execute(final ReadOnlyCommandMetadata metadata,
                    final Object context) {
                final InvokeContactScreen invokeContactScreen =
                        new InvokeContactScreen();
                _app.pushScreen(invokeContactScreen);
            }
        }));

        // Displays an InvokeDefaultScreen
        final MenuItem invokeDefaultItem =
                new MenuItem(new StringProvider("Invoke Default"), 0x230020, 1);
        invokeDefaultItem.setCommand(new Command(new CommandHandler() {
            /**
             * @see net.rim.device.api.command.CommandHandler#execute(ReadOnlyCommandMetadata,
             *      Object)
             */
            public void execute(final ReadOnlyCommandMetadata metadata,
                    final Object context) {
                final InvokeDefaultScreen invokeDefaultScreen =
                        new InvokeDefaultScreen();
                _app.pushScreen(invokeDefaultScreen);
            }
        }));

        // Displays an InvokeLocationDocumentScreen
        final MenuItem invokeLocationDocumentItem =
                new MenuItem(new StringProvider("Invoke Location Document"),
                        0x230030, 2);
        invokeLocationDocumentItem.setCommand(new Command(new CommandHandler() {
            /**
             * @see net.rim.device.api.command.CommandHandler#execute(ReadOnlyCommandMetadata,
             *      Object)
             */
            public void execute(final ReadOnlyCommandMetadata metadata,
                    final Object context) {
                final InvokeLocationDocumentScreen invokeLocationDocumentScreen =
                        new InvokeLocationDocumentScreen();
                _app.pushScreen(invokeLocationDocumentScreen);
            }
        }));

        // Displays an InvokeMapViewScreen
        final MenuItem invokeMapViewItem =
                new MenuItem(new StringProvider("Invoke Map View"), 0x230040, 3);
        invokeMapViewItem.setCommand(new Command(new CommandHandler() {
            /**
             * @see net.rim.device.api.command.CommandHandler#execute(ReadOnlyCommandMetadata,
             *      Object)
             */
            public void execute(final ReadOnlyCommandMetadata metadata,
View Full Code Here

                new LabelField(
                        "Select 'View Map' from the menu.  The first Contact in the address book that has a valid address (at least a city and state/province defined) will be displayed.  If there are no valid addresses, map view will default to last view.");
        add(instructions);

        // Displays a map based on an address from the address book
        final MenuItem viewMapItem =
                new MenuItem(new StringProvider("View Map"), 0x230010, 0);
        viewMapItem.setCommand(new Command(new CommandHandler() {
            /**
             * @see net.rim.device.api.command.CommandHandler#execute(ReadOnlyCommandMetadata,
             *      Object)
             */
            public void execute(final ReadOnlyCommandMetadata metadata,
View Full Code Here

                        choices);
        _choiceField.setChangeListener(this);
        add(_choiceField);

        // Views the country's information
        final MenuItem viewItem =
                new MenuItem(_resources, MENUITEM_VIEW, 0x230010, 0);
        viewItem.setCommand(new Command(new CommandHandler() {
            /**
             * @see net.rim.device.api.command.CommandHandler#execute(ReadOnlyCommandMetadata,
             *      Object)
             */
            public void execute(final ReadOnlyCommandMetadata metadata,
View Full Code Here

                        "From the menu:\n\nSelect 'View Single Location' to invoke BlackBerry Maps using a single location tag.\n\nSelect 'View Multiple Locations' to invoke BlackBerry Maps using multiple location tags.",
                        Field.READONLY | Field.FOCUSABLE);
        add(instructions);

        // Displays a single location on a map
        final MenuItem viewSingleItem =
                new MenuItem(new StringProvider("View Single Location"),
                        0x230010, 0);
        viewSingleItem.setCommand(new Command(new CommandHandler() {
            /**
             * @see net.rim.device.api.command.CommandHandler#execute(ReadOnlyCommandMetadata,
             *      Object)
             */
            public void execute(final ReadOnlyCommandMetadata metadata,
                    final Object context) {
                final String document =
                        "<lbs clear='ALL'><location lon='-7938675' lat='4367022' label='Toronto, ON' description='Go Leafs Go!' zoom='10'/></lbs>";
                Invoke.invokeApplication(Invoke.APP_TYPE_MAPS,
                        new MapsArguments(MapsArguments.ARG_LOCATION_DOCUMENT,
                                document));
            }
        }));

        // Displays multiple locations on a map
        final MenuItem viewMultipleItem =
                new MenuItem(new StringProvider("View Multiple Locations"),
                        0x230020, 1);
        viewMultipleItem.setCommand(new Command(new CommandHandler() {
            /**
             * @see net.rim.device.api.command.CommandHandler#execute(ReadOnlyCommandMetadata,
             *      Object)
             */
            public void execute(final ReadOnlyCommandMetadata metadata,
View Full Code Here

        /*
         * A menu item to display a dialog that allows the user to specify where
         * to click the screen.
         */
        final MenuItem clickScreen =
                new MenuItem(new StringProvider("Click the screen"), 0x230030,
                        3);
        clickScreen.setCommand(new Command(new CommandHandler() {
            /**
             * @see net.rim.device.api.command.CommandHandler#execute(ReadOnlyCommandMetadata,
             *      Object)
             */
            public void execute(final ReadOnlyCommandMetadata metadata,
                    final Object context) {
                // Dialog containing input fields for x and y coordinates
                final Dialog clickDialog =
                        new Dialog(Dialog.D_OK_CANCEL,
                                "Specify click location", Dialog.OK, null,
                                Manager.BOTTOMMOST);

                final BasicEditField xPos1Input =
                        new BasicEditField("Click position x1: ", "");
                final BasicEditField yPos1Input =
                        new BasicEditField("Click position y1: ", "");
                final BasicEditField xPos2Input =
                        new BasicEditField("Click position x2: ", "");
                final BasicEditField yPos2Input =
                        new BasicEditField("Click position y2: ", "");

                clickDialog.add(xPos1Input);
                clickDialog.add(yPos1Input);
                clickDialog.add(xPos2Input);
                clickDialog.add(yPos2Input);

                // Display the dialog
                clickDialog.doModal();

                // Check if the user clicked OK
                if (clickDialog.getSelectedValue() == Dialog.OK) {
                    // Clear the output string
                    _output.delete(0, _output.length());

                    try {
                        // Clear the output string
                        _output.delete(0, _output.length());

                        // Check that integers were entered and that the
                        // coordinates are valid.
                        final int x1 = Integer.parseInt(xPos1Input.getText());
                        final int y1 = Integer.parseInt(yPos1Input.getText());
                        final int x2 = Integer.parseInt(xPos2Input.getText());
                        final int y2 = Integer.parseInt(yPos2Input.getText());

                        EventInjector.TouchEvent.invokeClickThrough(x1, y1, x2,
                                y2);

                        updateOutputText();
                    } catch (final NumberFormatException nfe) {
                        Dialog.alert("Invalid input: " + nfe.getMessage()
                                + "\n\nPlease enter a number.");
                    } catch (final IllegalArgumentException iae) {
                        Dialog.alert("Invalid coordinate. \n\nPlease try again.");
                    }
                }
            }
        }));

        /*
         * A menu item to invoke a TouchEvent which clicks the button field on
         * the screen.
         */
        final MenuItem clickButton =
                new MenuItem(new StringProvider("Click the button"), 0x230010,
                        1);
        clickButton.setCommand(new Command(new CommandHandler() {
            /**
             * @see net.rim.device.api.command.CommandHandler#execute(ReadOnlyCommandMetadata,
             *      Object)
             */
            public void execute(final ReadOnlyCommandMetadata metadata,
                    final Object context) {
                // Calculate button position
                final Manager manager = getMainManager();
                final XYRect managerExtent = manager.getExtent(); // Scrollable
                                                                  // section of
                                                                  // the screen
                final int titleHeight = managerExtent.y; // Top of the
                                                         // scrollable section
                final XYRect buttonExtent = _sampleButton.getExtent();
                final int buttonYCoordinate =
                        buttonExtent.y + titleHeight
                                + _sampleButton.getHeight() / 2; // Middle of
                                                                 // the button

                // Create the four touch events needed to click the button
                final EventInjector.TouchEvent downEvent =
                        new EventInjector.TouchEvent(TouchEvent.DOWN, 40,
                                buttonYCoordinate, -1, -1, -1);
                final EventInjector.TouchEvent clickEvent =
                        new EventInjector.TouchEvent(TouchEvent.CLICK, 40,
                                buttonYCoordinate, -1, -1, -1);
                final EventInjector.TouchEvent unclickEvent =
                        new EventInjector.TouchEvent(TouchEvent.UNCLICK, 40,
                                buttonYCoordinate, -1, -1, -1);
                final EventInjector.TouchEvent upEvent =
                        new EventInjector.TouchEvent(TouchEvent.UP, 40,
                                buttonYCoordinate, -1, -1, -1);

                // Clear the output string
                _output.delete(0, _output.length());

                // Invoke the touch events
                EventInjector.invokeEvent(downEvent);
                EventInjector.invokeEvent(clickEvent);
                EventInjector.invokeEvent(unclickEvent);
                EventInjector.invokeEvent(upEvent);

                updateOutputText();
            }
        }));

        // A menu item to swipe the screen
        final MenuItem swipe =
                new MenuItem(new StringProvider("Swipe the screen"), 0x230020,
                        2);
        swipe.setCommand(new Command(new CommandHandler() {
            /**
             * @see net.rim.device.api.command.CommandHandler#execute(ReadOnlyCommandMetadata,
             *      Object)
             */
            public void execute(final ReadOnlyCommandMetadata metadata,
                    final Object context) {
                /**
                 * Create a move event array to pass into injectSwipeGesture().
                 * This array contains move events for one touch point.
                 */
                final EventInjector.TouchEvent[] moveEvents =
                        new EventInjector.TouchEvent[3];
                moveEvents[0] =
                        new EventInjector.TouchEvent(TouchEvent.MOVE, 60, 60,
                                -1, -1, -1);
                moveEvents[1] =
                        new EventInjector.TouchEvent(TouchEvent.MOVE, 120, 120,
                                -1, -1, -1);
                moveEvents[2] =
                        new EventInjector.TouchEvent(TouchEvent.MOVE, 50, 50,
                                -1, -1, -1);

                // Clear the output string
                _output.delete(0, _output.length());

                // Inject a swipe gesture with origin coordinates of (0, 0)
                EventInjector.TouchEvent.injectSwipeGesture(0, 0, moveEvents);
                updateOutputText();
            }
        }));

        /*
         * A menu item to display a dialog that allows the user to specify
         * screen location for injecting a tap gesture.
         */
        final MenuItem tap =
                new MenuItem(new StringProvider("Tap the screen"), 0x230040, 4);
        tap.setCommand(new Command(new CommandHandler() {
            /**
             * @see net.rim.device.api.command.CommandHandler#execute(ReadOnlyCommandMetadata,
             *      Object)
             */
            public void execute(final ReadOnlyCommandMetadata metadata,
                    final Object context) {
                // Dialog containing the input fields for x and y coordinates
                // and
                // number of taps.
                final Dialog tapDialog =
                        new Dialog(Dialog.D_OK_CANCEL, "Specify tap location",
                                Dialog.OK, null, Manager.NO_VERTICAL_SCROLL);

                final BasicEditField xPosInput =
                        new BasicEditField("Tap position x: ", "");
                final BasicEditField yPosInput =
                        new BasicEditField("Tap position y: ", "");
                final BasicEditField tapCountInput =
                        new BasicEditField("Number of taps: ", "");

                tapDialog.add(xPosInput);
                tapDialog.add(yPosInput);
                tapDialog.add(tapCountInput);

                // Display the dialog
                tapDialog.doModal();

                if (tapDialog.getSelectedValue() == Dialog.OK) {

                    // Clear the output string
                    _output.delete(0, _output.length());

                    try {
                        // Check that integers were entered and that the
                        // coordinates
                        // and taps are valid.
                        final int x = Integer.parseInt(xPosInput.getText());
                        final int y = Integer.parseInt(yPosInput.getText());
                        final int taps =
                                Integer.parseInt(tapCountInput.getText());

                        EventInjector.TouchEvent.injectTapGesture(x, y, taps);

                        updateOutputText();
                    } catch (final NumberFormatException nfe) {
                        Dialog.alert("Invalid input: " + nfe.getMessage()
                                + "\n\nPlease enter a number.");
                    } catch (final IllegalArgumentException iae) {
                        Dialog.alert("Invalid coordinate or tap count. \n\nPlease try again.");
                    }
                }
            }
        }));

        /*
         * A menu item to display a dialog that allows the user to specify
         * screen location for injecting a two finger tap.
         */
        final MenuItem twoFingerTap =
                new MenuItem(new StringProvider("Two Finger Tap the screen"),
                        0x230050, 5);
        twoFingerTap.setCommand(new Command(new CommandHandler() {
            /**
             * @see net.rim.device.api.command.CommandHandler#execute(ReadOnlyCommandMetadata,
             *      Object)
             */
            public void execute(final ReadOnlyCommandMetadata metadata,
View Full Code Here

    /**
     * Initialize menu item objects
     */
    private void initializeMenuItems() {
        _composeMenuItem =
                new MenuItem(new StringProvider("Compose Email"), 0x230030, 2);
        _composeMenuItem.setCommand(new Command(new CommandHandler() {
            /**
             * @see net.rim.device.api.command.CommandHandler#execute(ReadOnlyCommandMetadata,
             *      Object)
             */
            public void execute(final ReadOnlyCommandMetadata metadata,
                    final Object context) {
                final ComposeScreen composeScreen =
                        new ComposeScreen(null, _store);
                UiApplication.getUiApplication().pushScreen(composeScreen);
                updateScreen();
            }
        }));

        _openMenuItem =
                new MenuItem(new StringProvider("Open Item"), 0x230010, 0);
        _openMenuItem.setCommand(new Command(new CommandHandler() {
            /**
             * @see net.rim.device.api.command.CommandHandler#execute(ReadOnlyCommandMetadata,
             *      Object)
             */
            public void execute(final ReadOnlyCommandMetadata metadata,
                    final Object context) {
                openAction();
            }
        }));

        _editMenuItem = new MenuItem(new StringProvider("Edit"), 0x230020, 1);
        _editMenuItem.setCommand(new Command(new CommandHandler() {
            /**
             * @see net.rim.device.api.command.CommandHandler#execute(ReadOnlyCommandMetadata,
             *      Object)
             */
 
View Full Code Here

     */
    public BlackBerryMailDemoScreen(final String title) {
        initializeMenuItems();

        _selectServiceMenuItem =
                new MenuItem(new StringProvider("Choose Message Service"),
                        0x230040, 3);
        _selectServiceMenuItem.setCommand(new Command(new CommandHandler() {
            /**
             * @see net.rim.device.api.command.CommandHandler#execute(ReadOnlyCommandMetadata,
             *      Object)
View Full Code Here

TOP

Related Classes of net.rim.device.api.ui.MenuItem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.