Package net.rim.device.api.ui.component

Examples of net.rim.device.api.ui.component.Dialog


    private static class PopupDialogCommand extends AlwaysExecutableCommand {
        public void execute(final ReadOnlyCommandMetadata metadata,
                final Object context) {
            // This command merely demonstrates the adding of a command to the
            // screen's menu directly.
            final Dialog dialog =
                    new Dialog(Dialog.D_OK, "Popped up dialog", Dialog.D_OK,
                            null, 100);
            dialog.doModal();
        }
View Full Code Here


            // since we are modifying UI components (displaying a Dialog).
            _app.invokeLater(new Runnable() {
                public void run() {
                    final Event e = (Event) er; // It is an error if this cast
                                                // fails.
                    final Dialog d =
                            new Dialog(Dialog.D_OK,
                                    "Notification for event id: " + e._eventId,
                                    0, null, Screen.DEFAULT_CLOSE);
                    _dialogShowing = true;
                    _app.pushGlobalScreen(d, e._priority, UiEngine.GLOBAL_MODAL);
View Full Code Here

             *      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,
                    final Object context) {
                final Dialog tapDialog =
                        new Dialog(Dialog.D_OK_CANCEL, "Specify tap location",
                                Dialog.OK, null, Manager.NO_VERTICAL_SCROLL);

                final BasicEditField xPos1Input =
                        new BasicEditField("Tap position x1: ", "");
                final BasicEditField yPos1Input =
                        new BasicEditField("Tap position y1: ", "");
                final BasicEditField xPos2Input =
                        new BasicEditField("Tap position x2: ", "");
                final BasicEditField yPos2Input =
                        new BasicEditField("Tap position y2: ", "");
                final NumericChoiceField touchPointInput =
                        new NumericChoiceField("Touch point: ", 1, 2, 1);

                tapDialog.add(xPos1Input);
                tapDialog.add(yPos1Input);
                tapDialog.add(xPos2Input);
                tapDialog.add(yPos2Input);
                tapDialog.add(touchPointInput);

                // Display the dialog
                tapDialog.doModal();

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

                    try {
                        final int x1 = Integer.parseInt(xPos1Input.getText());
View Full Code Here

TOP

Related Classes of net.rim.device.api.ui.component.Dialog

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.