Search in sources :

Example 1 with VerticalFieldManager

use of net.rim.device.api.ui.container.VerticalFieldManager in project Samples-for-Java by blackberry.

the class TestScreen method fieldChanged.

public void fieldChanged(Field field, int context) {
    if (simpleProvider == null) {
        try {
            simpleProvider = new SimpleLocationProvider(getMode(modeField.getSelectedIndex()));
        } catch (final Exception le) {
            UiApplication.getUiApplication().invokeLater(new Runnable() {

                public void run() {
                    Dialog.alert(le.getMessage());
                }
            });
        }
        if (simpleProvider != null) {
            simpleProvider.setGeolocationTimeout(geoTimeoutField.getSelectedValue());
            simpleProvider.setGPSTimeout(gpsTimeoutField.getSelectedValue());
            simpleProvider.setRetryFactor(retryFactorField.getSelectedValue());
            simpleProvider.setTrackignInterval(trackingIntervalField.getSelectedValue());
            simpleProvider.setMaxRetryDelay(maxRetryDelayField.getSelectedValue());
        }
    }
    if (field == startTrackingField) {
        if (simpleProvider != null) {
            simpleProvider.addSimpleLocationListener(this, trackingIntervalField.getSelectedValue());
        }
    } else if (field == stopTrackingField) {
        if (simpleProvider != null) {
            simpleProvider.removeSimpleLocationListener();
        }
    } else if (field == restartField) {
        if (simpleProvider != null) {
            try {
                simpleProvider.restart();
            } catch (IllegalStateException ise) {
                UiApplication.getUiApplication().invokeLater(new Runnable() {

                    public void run() {
                        Dialog.alert("Tracking session must be in progress. Please select Start Tracking.");
                    }
                });
            }
        }
    } else if (field == modeField) {
        if (simpleProvider != null) {
            try {
                simpleProvider.setMode(getMode(modeField.getSelectedIndex()));
            } catch (final LocationException le) {
                UiApplication.getUiApplication().invokeLater(new Runnable() {

                    public void run() {
                        Dialog.alert(le.toString());
                    }
                });
            }
        }
    } else if (field == trackingIntervalField) {
        if (simpleProvider != null) {
            simpleProvider.setTrackignInterval(trackingIntervalField.getSelectedValue());
        }
    } else if (field == gpsTimeoutField) {
        if (simpleProvider != null) {
            simpleProvider.setGPSTimeout(gpsTimeoutField.getSelectedValue());
        }
    } else if (field == geoTimeoutField) {
        if (simpleProvider != null) {
            simpleProvider.setGPSTimeout(geoTimeoutField.getSelectedValue());
        }
    } else if (field == retryFactorField) {
        if (simpleProvider != null) {
            simpleProvider.setRetryFactor(retryFactorField.getSelectedValue());
        }
    } else if (field == maxRetryDelayField) {
        if (simpleProvider != null) {
            simpleProvider.setMaxRetryDelay(maxRetryDelayField.getSelectedValue());
        }
    } else if (field == getSingleLocationField) {
        new Thread() {

            public void run() {
                location = simpleProvider.getLocation(30);
                if (location != null && location.isValid()) {
                    locationField.setText(location.getQualifiedCoordinates().getLatitude() + ", " + location.getQualifiedCoordinates().getLongitude());
                    statusField.setText("Obtained single location.");
                } else {
                    statusField.setText("Failed to obtain location!");
                }
            }
        }.start();
    } else if (field == getLastLocationField) {
        if (simpleProvider != null) {
            location = simpleProvider.getLastKnownLocation();
            if (location != null && location.isValid()) {
                locationField.setText(location.getQualifiedCoordinates().getLatitude() + ", " + location.getQualifiedCoordinates().getLongitude());
                statusField.setText("Obtained last known location.");
            } else {
                statusField.setText("Last known location not available! Please acquire a single location or start a tracking session first.");
            }
        } else {
            statusField.setText("Last known location not available! Please acquire a single location or a tracking session first.");
        }
    } else if (field == satellitesField) {
        if (location != null) {
            final PopupScreen satPopup = new PopupScreen(new VerticalFieldManager()) {

                protected boolean keyDown(int keycode, int time) {
                    int key = Keypad.key(keycode);
                    if (key == Keypad.KEY_ESCAPE) {
                        Screen screen = getScreen();
                        UiApplication.getUiApplication().popScreen(screen);
                    }
                    return true;
                }
            };
            EditField satField = new EditField("", "");
            satPopup.add(satField);
            StringBuffer buffer = new StringBuffer();
            Enumeration satEnum = location.getSatelliteInfo();
            if (satEnum != null && satEnum.hasMoreElements()) {
                buffer.append("ID\tAzimuth\tElevation\tSignal\n");
                while (satEnum.hasMoreElements()) {
                    SatelliteInfo satInfo = (SatelliteInfo) satEnum.nextElement();
                    if (satInfo != null && satInfo.isValid()) {
                        buffer.append(satInfo.getId() + "\t" + satInfo.getAzimuth() + "\t" + satInfo.getElevation() + "\t" + satInfo.getSignalQuality() + "\n");
                    }
                }
                satField.setText(buffer.toString());
            } else {
                buffer.append("No satellite information available for current location fix");
                satField.setText(buffer.toString());
            }
            UiApplication.getUiApplication().invokeLater(new Runnable() {

                public void run() {
                    UiApplication.getUiApplication().pushScreen(satPopup);
                }
            });
        } else {
            UiApplication.getUiApplication().invokeLater(new Runnable() {

                public void run() {
                    Dialog.inform("No location fix available..");
                }
            });
        }
    }
}
Also used : EditField(net.rim.device.api.ui.component.EditField) Enumeration(java.util.Enumeration) Screen(net.rim.device.api.ui.Screen) PopupScreen(net.rim.device.api.ui.container.PopupScreen) MainScreen(net.rim.device.api.ui.container.MainScreen) LocationException(javax.microedition.location.LocationException) PopupScreen(net.rim.device.api.ui.container.PopupScreen) SimpleLocationProvider(rimx.location.simplelocation.SimpleLocationProvider) LocationException(javax.microedition.location.LocationException) SatelliteInfo(net.rim.device.api.gps.SatelliteInfo) VerticalFieldManager(net.rim.device.api.ui.container.VerticalFieldManager)

Example 2 with VerticalFieldManager

use of net.rim.device.api.ui.container.VerticalFieldManager in project Samples-for-Java by blackberry.

the class StartScreen method searchResponse.

// ResponseListener Implementation
public void searchResponse(Vector results) {
    if (results != null && results.size() > 0) {
        // Create the list of videos
        GridFieldManager resultsList = new GridFieldManager(results.size() * 2, 2, GridFieldManager.USE_ALL_WIDTH | GridFieldManager.USE_ALL_HEIGHT);
        resultsList.setColumnProperty(0, GridFieldManager.PREFERRED_SIZE, 0);
        resultsList.setColumnProperty(1, GridFieldManager.AUTO_SIZE, 0);
        resultsList.setColumnPadding(1);
        resultsList.setCellPadding(0);
        for (int i = 0; i < results.size(); i++) {
            VideoData data = (VideoData) results.elementAt(i);
            // Thumbnail
            BitmapFieldButton image = new BitmapFieldButton(_clock, BitmapField.FOCUSABLE);
            image.setSpace(2, 2);
            image.setCommandAction(new ThumbnailClick(data));
            data.setBitmapField(image);
            resultsList.add(image);
            // Text column
            VerticalFieldManager vfm = new VerticalFieldManager();
            vfm.add(new LabelField(data.getTitle(), LabelField.NON_FOCUSABLE));
            vfm.add(new LabelField(data.getDescription(), LabelField.USE_ALL_HEIGHT | LabelField.NON_FOCUSABLE | LabelField.ELLIPSIS));
            resultsList.add(vfm);
            // Break
            resultsList.add(new NullField(NullField.NON_FOCUSABLE));
            resultsList.add(new SeparatorField());
        }
        UiApplication.getUiApplication().invokeLater(new ResultsUpdater(resultsList));
    }
}
Also used : VideoData(com.blackberry.toolkit.sample.youtube.internal.VideoData) NullField(net.rim.device.api.ui.component.NullField) GridFieldManager(net.rim.device.api.ui.container.GridFieldManager) SeparatorField(net.rim.device.api.ui.component.SeparatorField) VerticalFieldManager(net.rim.device.api.ui.container.VerticalFieldManager) LabelField(net.rim.device.api.ui.component.LabelField)

Aggregations

VerticalFieldManager (net.rim.device.api.ui.container.VerticalFieldManager)2 VideoData (com.blackberry.toolkit.sample.youtube.internal.VideoData)1 Enumeration (java.util.Enumeration)1 LocationException (javax.microedition.location.LocationException)1 SatelliteInfo (net.rim.device.api.gps.SatelliteInfo)1 Screen (net.rim.device.api.ui.Screen)1 EditField (net.rim.device.api.ui.component.EditField)1 LabelField (net.rim.device.api.ui.component.LabelField)1 NullField (net.rim.device.api.ui.component.NullField)1 SeparatorField (net.rim.device.api.ui.component.SeparatorField)1 GridFieldManager (net.rim.device.api.ui.container.GridFieldManager)1 MainScreen (net.rim.device.api.ui.container.MainScreen)1 PopupScreen (net.rim.device.api.ui.container.PopupScreen)1 SimpleLocationProvider (rimx.location.simplelocation.SimpleLocationProvider)1