PopupScreen with AnimatedGIFField

I am creating a screen using the AnimatedGIFField class and progression custom by extending PopupScreen figure in the Blackberry docs.  The problem is that my screen does not display when I call the method that is supposed to display.

Here is the code for the screen:

   RichTextField rtf;
    AnimatedGIFField agf;
   // GIFEncodedImage gei = (GIFEncodedImage) EncodedImage.getEncodedImageResource("ajaxloader.gif");
    String progress;

    // constructor for progressScreen
    progressScreen(String s)
    {
        super(new HorizontalFieldManager(), Field.NON_FOCUSABLE);
        int[] offset = new int[s.length()];
        byte[] attributes = new byte[s.length()-1];
        Font[] fonts = new Font[] {Font.getDefault().derive(Font.BOLD), Font.getDefault().derive(Font.PLAIN)};
        agf = new AnimatedGIFField(((GIFEncodedImage)GIFEncodedImage.getEncodedImageResource("resources/ajaxloader.gif")), Field.FIELD_RIGHT);
        rtf = new RichTextField(s, offset, attributes, fonts, Field.NON_FOCUSABLE);
        add(rtf);
        add(agf);
    }

Here is the code for the method display:

// behavior when displaying screen

    // method for displaying screen
    public void show()
    {
        UiApplication.getUiApplication().pushModalScreen(this);
    }

I'm sure that I forgot something... one object or a sublayout(), but I cannot know what.

I replaced the PopupScreen with a call to Status.show (String message, image bitmap Bitmap, int time) to check that it was a problem with my custom PopupScreen and not the surrounding code, and the Status.show () posted correctly.

Any help would be appreciated.

"You mean, like this?  Unfortunately, you're close, but still actually running on the event Thread.  'tril.run ();' executes the run method on the same Thread that you use.  What you wanted to write was:

Tril.Start ();

Give that a try, and you will start to notice the IllegalStateExceptions.

"Wouldn't be too big for a dialogue?

I don't know what you mean by that.

You might be interested in this review:

http://www.naviina.EU/WP/BlackBerry/loading-class-for-BlackBerry/#more-607

Tags: BlackBerry Developers

Similar Questions

  • Problem with fieldChanged() and custom button field

    Hello

    I created a custom button class by extending LabelField.  I chose LabelField over field because the LabelField contains desirable properties that are already being implemented.  The only problem I'm having has to do with the change listener.  It seems to 'steal' the event click on other areas in my application.

    For example, when I click on the custom button, a popupscreen with a listfield opens. When I click on an item in the listfield, then the fieldChanged() of custom button is called again...

    Can you see anything wrong with my code?

    package com.rantnetwork.fields;
    
    import com.rantnetwork.app.Constants;
    import net.rim.device.api.system.Display;
    import net.rim.device.api.ui.Color;
    import net.rim.device.api.ui.Field;
    import net.rim.device.api.ui.Font;
    import net.rim.device.api.ui.Graphics;
    import net.rim.device.api.ui.Ui;
    import net.rim.device.api.ui.XYEdges;
    import net.rim.device.api.ui.component.LabelField;
    import net.rim.device.api.ui.decor.BackgroundFactory;
    import net.rim.device.api.ui.decor.BorderFactory;
    
    public class CustomButtonField extends LabelField {
    
        private boolean highlighted = false;
    
        public CustomButtonField(String text, long style) {
            super(text, style | Field.FOCUSABLE | LabelField.ELLIPSIS);
    
            setPadding(10, 0, 10, 5);
    
            setFont(Font.getDefault().derive(Font.BOLD,
                    Constants.DEFAULT_FONT_SIZE, Ui.UNITS_pt));
    
            setBackground(BackgroundFactory.createLinearGradientBackground(
                    0x163d7c, 0x163d7c, 0x03162d, 0x03162d));
            setBorder(BorderFactory
                    .createBevelBorder(new XYEdges(1, 1, 1, 1), new XYEdges(
                            Color.BLACK, Color.BLACK, Color.BLACK, Color.BLACK),
                            new XYEdges(Color.BLACK, Color.BLACK, Color.BLACK,
                                    Color.BLACK)));
    
        }
    
        public int getPreferredWidth() {
            return Display.getWidth() / 3;
        }
    
        protected void paint(Graphics graphics) {
            graphics.setColor(Color.WHITE);
            super.paint(graphics);
        }
    
        protected void drawFocus(Graphics graphics, boolean on) {
            // Do nothing
        }
    
        protected boolean navigationClick(int status, int time) {
            fieldChangeNotify(1);
            return true;
        }
    
        protected void onFocus(int direction) {
            if (!highlighted) {
                setBackground(BackgroundFactory.createLinearGradientBackground(
                        0x4bb7df, 0x4bb7df, 0x1b96da, 0x1b96da));
                setBorder(BorderFactory.createBevelBorder(new XYEdges(1, 1, 1, 1),
                        new XYEdges(Color.BLACK, Color.BLACK, Color.BLACK,
                                Color.BLACK), new XYEdges(Color.BLACK, Color.BLACK,
                                Color.BLACK, Color.BLACK)));
            }
        }
    
        protected void onUnfocus() {
            if (!highlighted) {
                setBackground(BackgroundFactory.createLinearGradientBackground(
                        0x163d7c, 0x163d7c, 0x03162d, 0x03162d));
                setBorder(BorderFactory.createBevelBorder(new XYEdges(1, 1, 1, 1),
                        new XYEdges(Color.BLACK, Color.BLACK, Color.BLACK,
                                Color.BLACK), new XYEdges(Color.BLACK, Color.BLACK,
                                Color.BLACK, Color.BLACK)));
            }
        }
    
        public void showHighlighted(boolean focus) {
            if (focus) {
                highlighted = true;
                setBackground(BackgroundFactory.createLinearGradientBackground(
                        0x4bb7df, 0x4bb7df, 0x1b96da, 0x1b96da));
                setBorder(BorderFactory.createBevelBorder(new XYEdges(1, 1, 1, 1),
                        new XYEdges(Color.BLACK, Color.BLACK, Color.BLACK,
                                Color.BLACK), new XYEdges(Color.BLACK, Color.BLACK,
                                Color.BLACK, Color.BLACK)));
            } else {
                highlighted = false;
                setBackground(BackgroundFactory.createLinearGradientBackground(
                        0x163d7c, 0x163d7c, 0x03162d, 0x03162d));
                setBorder(BorderFactory.createBevelBorder(new XYEdges(1, 1, 1, 1),
                        new XYEdges(Color.BLACK, Color.BLACK, Color.BLACK,
                                Color.BLACK), new XYEdges(Color.BLACK, Color.BLACK,
                                Color.BLACK, Color.BLACK)));
            }
            invalidate();
        }
    
        public boolean isHighlighted() {
            return highlighted;
        }
    
    }
    

    behrk2 wrote:

    Now, I'm not sure why customButton.setText (calling) would trigger the fieldChanged().  Can anyone think of a reason why he can do?

    Thank you!

    Can you think of a reason why we can't do that? The field has changed, after all! Of course, the context (second argument to fieldChanged) will be PROGRAMMATIC in this case, that might be a pretty good indication for you. But not invoke fieldChanged at all would be wrong.

    This is why I don't like the idea of extending LabelField and not just the field for your custom badges - you have much less control over his behavior. If you want an example showing how to create abstract off-screen buttons, take a look at BaseButtonField and his descendants in managers, fields and advanced buttons.

  • Size PopupScreen

    I have a popupScreen with a label on the inside. I think that my looks too big popupScreen for the font size of labels, it looks like this:

    I want to adjust the size of the popupScreen as the label to look like this:

    I tried to do this:

    public class myPoupScreen extends PopupScreen {
        private static LabelField etiqueta;
        private static int totalWidth;
        private static int totalHeight;
    
        public myPoupScreen(String text) {
            super(new VerticalFieldManager());
            etiqueta =  new LabelField(text, Field.FIELD_HCENTER);
            Font fuente = Font.getDefault().derive(Font.PLAIN, 5, Ui.UNITS_pt);
            etiqueta.setFont(fuente);
            totalWidth = Font.getDefault().getAdvance(etiqueta.getText()) + 6;
            totalHeight = fuente.getHeight() + 2;
            this.add(etiqueta);
        }
    
        public void sublayout(int width, int height){
            super.sublayout(totalWidth, totalHeight);
        }
    
    }
    

    But the screen is too small as if text when it is empty, I have the label can't be seen.

    As I understand it there is only a border for popup screens which is related theme.  The screen will always try to put it in, and so if you forced in a space that is large enough to display this fact and your label, then you will not see the label.

    I wibder if this is what is happening here: you can find this Thread useful for the removal of the border:

    http://supportforums.BlackBerry.com/T5/Java-development/how-to-remove-border-PopupScreen/m-p/42809#M...

  • Transparent image on PopupScreen

    Hello guys '

    I want to change the cursor to the application. I did it by PopupScreen with BitmapField.

    Now, I need the transparent slider for my application. I have some ideas, but I do not know how to properly work.

    My idea is to place the transparent BitmapField on PopupScreen.

    So, if you have a certain idea, please share it with me.

    TNX'

    Hello guys '

    I found the solution. Is to use the paintBackground() method, when create PopupScreen object.

    protected void paintBackground(Graphics graphics) {
        graphics.setBackgroundColor(16777215); // 16777215 is transparent code.
    }
    
  • Selection of text in a PopupScreen

    Hello

    I have a PopupScreen with a RichTextField.
    Is it possible to let the user select the text inside the RichTextField (i.e. for copy and paste)?

    Thank you

    Can you make a button that does it for them by using the Clipboard?

  • How can I place a popupscreen against a field in the main screen

    I have a screen (a dialog box, in fact) with a field of inside edition.  I want to show a popupscreen just below the edit field (I put an AutoComplete feature implemented type).  Is it possible to know where in screen coords editing field is so I can call setPosition (in sublayout of the popupscreen) with the right values?

    -Morgan

    It was an interesting idea, and he was able to lead me to where I should be.  Field.getContentRect (), which looked kinda useless, turns out to have useful info when the field is a Manager or a screen. In particular, for the latter, the rect content seems to be in screen coordinates.

    So now I use the following to get the value y from the bottom of the text in my dialog box, which I use to place my pop-up screen:

    Gets the bottom of a field in the coords display to use setPosition appeal of a pop-up screen.

    private int getFieldBottom (field fld)
    {
    int cy = fld.getHeight () + fld.getContentTop ();
            
    Manager m = fld.getManager ();
    While (m! = null)
    {
    CY += m.getContentTop (); for screens, the rect content seems to be in screen coords
    If (m instanceof screen)
    break;
    m = m.getManager ();
    }
            
    Return cy;
    }

  • Problem with push the screen of an application

    Hello

    I developed an application with another point of entry. I have the main GUI application and an application that listens for push notifications. The background listener auto starts when the unit is turned on and tuned to push. When it receives the push message, it displays a popupscreen with the options 'launch' and 'Cancel '. By pressing 'start' should open the graphical application by pressing the main screen of the application. However, I get "ClassCastException" and I have no idea why.

    I looked around and the process is similar to what I did, but somehow, it does not work for me. Can someone explain or show me how to push a background application screen?

    See you soon!

    Welcome to the forums!

    I guess as you push a display context global [and maybe modal] 'launch' and 'Cancel' buttons. When you press 'start', then, you should not just push a screen - you should actually run the main application!

    To do this, you must create an application with the appropriate settings and say ApplicationManager descriptor to run it. Take a look at the documentation ApplicationManager, especially the section "running an application with different arguments. Make sure the arguments are according to the needs of your main application, not the bottom one.

    Only one problem: what happens if your application is already running but reduced? Don't worry - you try to run the same application with the same arguments will activate one already running!

    Good luck!

  • Problem With nested Manager in DialogFieldManager

    I display successfully a PopupScreen with an icon, title, two fields of line and two buttons to the right places.  I do this by calling the constructor of PopupScreen with DialogFieldManager

    The problem is fixed height BasicEditField as I am trying to add.  There is space for the BasicEditField, but the BasicEditField is not.

    Here is the code I use.  Note: I left the ButtonField and FieldChangeListener code to stay brief.  I also tried to use customManager.add () instead of delegateFieldManager.addCustomField ()... or work:

         eflink = new EditField("", link);
            efname = new EditField("", "");
            befd = new BasicEditField("", "")
            {
                public int getPreferredHeight()
                {
                    return 60;
                }
            };
            dsm = dfm.getCustomManager();
            hfm = new HorizontalFieldManager(Manager.FIELD_HCENTER);
            tvfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL)
            {
                protected void sublayout( int maxWidth, int maxHeight )
                {
                    int width = maxWidth;
                    int height = maxHeight;
                    width = dfm.getWidth();
                    height = dfm.getHeight() + befd.getPreferredHeight();
                    // super.sublayout( width, height);
                    setExtent( width, height);
                }
            };
            dfm.addCustomField(eflink);
            dfm.addCustomField(efname);
            //
            tvfm.add(befd);
            hfm.add(post);
            hfm.add(cancel);
            dfm.addCustomField(tvfm);
            dfm.addCustomField(hfm);
         }
    

    Can you see what I'm doing wrong?

    Solved!

    I took the code of this doc, deleted the reference EditField and adding a field to the constructor parameter.

    I then used the custom manager that results in place of the VerticalFieldManager in my previous code... using the fixed EditField as the field to the Manager constructor arg custom.

  • PopupScreen unusual behavior

    I am running with a storm of BB under JDE 4.7

    One area that concerns me is the behavior of the screens when alphablending participates.

    I have 2 problems now I am trying to solve with PopupScreens.

    First of all, I got a test application that I ran with a simple PopupScreen with a single ButtonField and I set the alpha value to 50 on the bottom. I used the call the PopupScreen itself setBackground (is derived from screen - Manager - field, and field a call to setBackground). Now with this call, the alpha is set to 50, and I see it very well in the Simulator.

    Now, the PopupScreens constructor requires a new VerticalFieldManager be sent in. If I use this Manager to its setBackground function call, I see a few alpha but much less... as he is set to 200 or something.

    Now there are several (lets call these areas for lack of a better term) in the PopupScreen. It is for the field of the screen itself and one for the Manager. I think what is happening here is that I put the alpha for the two "regions" and the result is that the whole 'widget' is defined on an alpha of 50, while the area inside the PopupScreen is as another area that is drawn with the same color and alpha is set to 50 too. The result is alpha to alpha, making it less transparent and I noticed that even the border has a few alpha and who is the alpha of the Manager.

    So my first question is... Exceeds my correct assessment? If so, I'll need to alpha using only the PopupScreen setBackground calls... it seems to work better.

    My second question is that I can't get either version of this application to run on the device itself. Now, this app has been changed from one that used a screen at the start (and it worked fine on the device), but when I changed to the PopupScreen and the PushGlobalScreen place in the UiApplication, it won't work. It gives me a message saying:

    "Error at startup test: 'test' may not contain the classes in com.rim, net.rim, net.blackberry.java or javax packages.

    I believe that this message is one that is normally given when proof is required. However, I don't see any warnings of certification in the Javadocs for the objects or calls I use.

    Any ideas?

    Here is the source code for a version... Sorry for all the commented code (I'm currently doing run :-)

    /**
     * test.java    Tests various features that this utility may use.
     *
     * Copyright (C) 2009, IPPUB. All rights reserved.
     */
    package com.rim.bbtools.source;
    
    import net.rim.device.api.ui.*;
    import net.rim.device.api.ui.component.*;
    import net.rim.device.api.ui.container.*;
    import net.rim.device.api.ui.decor.*;
    import net.rim.device.api.i18n.*;
    
    /*
     * BlackBerry applications that provide a user interface
     * must extend UiApplication.
     */
    public class test extends UiApplication
    {
            private Manager m_mgr;
    
            public static void main(String[] args)
            {
                    //create a new instance of the application
                    //and start the application on the event thread
                    test theApp = new test();
                    theApp.enterEventDispatcher();
            }
            public test()
            {
                    m_mgr = new VerticalFieldManager();
                    //display a new screen
                    pushGlobalScreen(new testScreen(m_mgr), Integer.MIN_VALUE + 1, 0);
                    //pushScreen(new testScreen());
            }
    }
    
    //create a new screen that extends MainScreen, which provides
    //default standard behavior for BlackBerry applications
    final class testScreen extends PopupScreen  // MainScreen
    {
            //private final static int TALPHAB    = 50;   // Set background of screen to almost Transparent
            //private final static int TALHPAF    = 200;  // Set background of Field to almost Opaque
    
            public testScreen(Manager mgr)
            {
    
                    //invoke the PopScreen constructor
                    super(mgr, Field.FOCUSABLE);
                    //super();
    
                    final Manager mymgr = mgr;
    
                    //add a title to the screen
                    //LabelField title = new LabelField("Feature test example", LabelField.ELLIPSIS
                    //                | LabelField.USE_ALL_WIDTH);
                    //setTitle(title);
    
                    // Get the HELLO string from the resources file
                    ResourceBundle resources = ResourceBundle.getBundle(testResource.BUNDLE_ID,
                            testResource.BUNDLE_NAME);
                    String hmessage = resources.getString(testResource.HELLO);
                    //add the text HELLO to the screen
                    add(new RichTextField(hmessage));
    
                    //add(new RichTextField("Hello World!"));
                    // First define button handler
                    FieldChangeListener bhandler = new FieldChangeListener()
                    {
                        public void fieldChanged(Field field, int context)
                        {
                            // First get the UiEngine
                            //UiEngine engine = getUiEngine();    // Screen function inherited
                            //int count = engine.getScreenCount();    // How many screens present now.
    
                            ButtonField buttonField = (ButtonField) field;
                            if (buttonField.getLabel() == "RED")
                            {
                                Background newback = BackgroundFactory.createSolidTransparentBackground(Color.RED,50);
                                mymgr.setBackground(newback);
                                buttonField.setLabel("BLUE");
                            }
                            else
                            {
                                Background newback = BackgroundFactory.createSolidTransparentBackground(Color.BLUE,50);
                                mymgr.setBackground(newback);
                                buttonField.setLabel("RED");
                            }
                        }
                     };
                     // Define button itself to use handler above, this one called RED
                     ButtonField buttonField = new ButtonField("RED",ButtonField.CONSUME_CLICK);     // Create RED button
                     buttonField.setChangeListener(bhandler);               // Set up button handler defined above
    
                     add(buttonField);      // Add the button to the screen.
    
            }
    
            //override the onClose() method to display a dialog box to the user
            //with "Goodbye!" when the application is closed
            public boolean onClose()
            {
                Dialog.alert("Goodbye!");
                System.exit(0);
                return true;
            }
    }
    

    Thank you

    -Donald

    I'm going to mark it as resolved because no one answered, and I guess that I am not mistaken, nothing makes sense. The only part that I haven't figured out is why it does not work on the device and I did more work to identify this problem and I suspect another problem (problem IDE), so I'll post a different question for this.

    Thank you

  • Adding symbols in the symbol menu

    Hi all

    Forgive my ignorance, but how do I add custom symbols menu items? Is this possible?

    Sincerely,

    MW

    If you are looking for in all applications, then no, it may not.

    This could be done for your own application.  You could create a custon PopupScreen with existing symbols, as well as your own that is displayed when the user press the symbol key.  You need capture when you press the symbol key and display your own PopupScreen by substituting the keyDown method that is found in the field classes or screen.

  • Directory selector

    Hi all

    I am wanting to set up a directory chooser. Essentially, I want to have a button 'Browse' which opens a directory browser and allows the user to select a directory.

    I saw this article:http://supportforums.blackberry.com/t5/Java-Development/Create-a-file-selection-popup-screen/ta-p/44...  But that takes a file I need to choose a directory.

    Y at - it something already built for the collection of directory? I briefly looked at LocationPicker, but I couldn't figure out how to make this selection work just a directory.

    Thank you!

    I took the code example in the link above for a file selector and the moditified be a directory chooser. If anyone has a better way to do it I'd love to see it. Here is my code updated to the:

    /*
     * FileSelectorPopupSample.java
     *
     * © , 2003-2008
     * Confidential and proprietary.
     */
    
    package mypackage;
    
    import net.rim.device.api.ui.UiApplication;
    import net.rim.device.api.ui.component.Dialog;
    import net.rim.device.api.ui.container.MainScreen;
    import net.rim.device.api.ui.MenuItem;
    import java.lang.String;
    
    /**
     * A sample application demonstrating the use of a custom FileSelectorPopupScreen.
     */
    
    public final class FileSelectorPopupSample extends UiApplication
    {
    
        public static void main(String[] args)
        {
                FileSelectorPopupSample theApp = new FileSelectorPopupSample();
                theApp.enterEventDispatcher();
        }
    
        public FileSelectorPopupSample()
        {
            MainScreen mainScreen = new MainScreen();
            mainScreen.setTitle("FileSelectorPopupScreen Example");
    
            MenuItem SelectDirectory = new MenuItem("Select a Directory", 40, 40)
            {
                public void run()
                {
                    FileSelectorPopupScreen fps = new FileSelectorPopupScreen();
                    fps.pickFile();
                    String theFile = fps.getFile();
    
                    if (theFile == null)
                    {
                        Dialog.alert("Screen was dismissed.  No file was selected.");
                    }
                    else
                    {
                        Dialog.alert("Directory selected: " + theFile);
                    }
                }
            };          
    
            mainScreen.addMenuItem(SelectDirectory);
    
            pushScreen(mainScreen);
        }
    }
    
    /*
     * FileSelectorPopupScreen.java
     *
     * © Research In Motion, 2003-2009
     * Confidential and proprietary.
     */
    
    package mypackage;
    
    import net.rim.device.api.ui.container.PopupScreen;
    import net.rim.device.api.ui.UiApplication;
    import net.rim.device.api.system.Bitmap;
    import net.rim.device.api.system.Characters;
    import net.rim.device.api.ui.component.*;
    import net.rim.device.api.ui.container.DialogFieldManager;
    import javax.microedition.io.Connector;
    import javax.microedition.io.file.*;
    import java.util.*;
    
    /**
     * A PopupScreen with a file browser allowing for file selection.
      */
    public class FileSelectorPopupScreen extends PopupScreen
    {
    
        String _currentPath;        //The current path;
        ObjectListField _olf;       //Lists fields and directories.
        protected final String selectHere = "[Select Here]";
    
        /**
         * Open the screen to the root folder and show all directories.
         */
        public FileSelectorPopupScreen()
        {
            super(new DialogFieldManager());
            prepScreen(null);
        }
    
        /**
         * Display the screen, prompting the user to pick a file.
         */
        public void pickFile()
        {
            UiApplication.getUiApplication().pushModalScreen(this);
        }
    
        /**
         * Retrieves the current directory if the user is still browsing for a file,
         * the selected file if the user has chosen one or null if the user dismissed the screen.
         * @return the current directory if the user is still browsing for a file,
         * the selected file if the user has chosen one or null if the user dismissed the screen.
         */
        public String getFile()
        {
            return _currentPath;
        }    
    
        //Prepare the DialogFieldManager.
        private void prepScreen(String path)
        {
            DialogFieldManager dfm = (DialogFieldManager)getDelegate();
            dfm.setIcon(new BitmapField(Bitmap.getPredefinedBitmap(Bitmap.QUESTION)));
            dfm.setMessage(new RichTextField("Select a file"));
    
            _olf = new ObjectListField();
            dfm.addCustomField(_olf);
    
            updateList(path);
        }
    
        //Reads all of the files and directories in a given path.
        private Vector readFiles(String path)
        {
            Enumeration fileEnum;
            Vector filesVector = new Vector();
    
            _currentPath = path;
    
            if (path == null)
            {
                //Read the file system roots.
                fileEnum = FileSystemRegistry.listRoots();
    
                while (fileEnum.hasMoreElements())
                {
                    filesVector.addElement((Object)fileEnum.nextElement());
                }
            }
            else
            {
                //Read the files and directories for the current path.
                try
                {
                    FileConnection fc = (FileConnection)Connector.open("file:///" + path);
                    fileEnum = fc.list();
                    String currentFile;
                    filesVector.addElement(selectHere);
                    while (fileEnum.hasMoreElements())
                    {
                        currentFile = ((String)fileEnum.nextElement());
                        if (currentFile.lastIndexOf('/') == (currentFile.length() - 1))
                        {
                            //Add all directories.
                            filesVector.addElement((Object)currentFile);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Dialog.alert("Unable to open folder. " + ex.toString());
                }
    
            }
            return filesVector;
        }
    
        //Handles a user picking an entry in the ObjectListField.
        private void doSelection()
        {
            //Determine the current path.
            String thePath = buildPath();
            java.lang.System.out.println("ThePath: "+thePath);
            if (thePath == null)
            {
                //Only update the screen if a directory was selected.
                updateList(thePath);
            }
            else if (!thePath.equals("*?*"))
            {
                //Only update the screen if a directory was selected.
                //A second check is required here to avoid a NullPointerException.
                updateList(thePath);
            }
            else
            {
                //The user has selected a file.
                //Close the screen.
                this.close();
            }
        }
    
        //Updates the entries in the ObjectListField.
        private void updateList(String path)
        {
            //Read all files and directories in the path.
            Vector fileList = readFiles(path);
    
            //Create an array from the Vector.
            Object fileArray[] = vectorToArray(fileList);
    
            //Update the field with the new files.
            _olf.set(fileArray);
        }
    
        //Build a String that contains the full path of the user's selection.
        //If a file has been selected, close this screen.
        //Returns *?* if the user has selected a file.
        private String buildPath()
        {
    
            String newPath = (String)_olf.get(_olf, _olf.getSelectedIndex());
            java.lang.System.out.println("newPath: "+newPath);
            if (newPath.equals(".."))
            {
                //Go up a directory.
                //Remove the trailing '/';
                newPath = _currentPath.substring(0, _currentPath.length() - 2);
                //Remove everything after the last '/' (the current directory).
                //If a '/' is not found, the user is opening the file system roots.
                //Return null to cause the screen to display the file system roots.
                int lastSlash = newPath.lastIndexOf('/');
    
                if (lastSlash == -1)
                {
                    newPath = null;
                }
                else
                {
                    newPath = newPath.substring(0, lastSlash + 1);
                }
            }
            else if (newPath.lastIndexOf('/') == (newPath.length() - 1))
            {
                //If the path ends with /, a directory was selected.
                //Prefix the _currentPath if it is not null (not in the root directory).
                if (_currentPath != null)
                {
                    newPath = _currentPath + newPath;
                }
            }
            else
            {
                java.lang.System.out.println("Directory has been chose");
                //A directory has been chosen
                _currentPath += newPath;
                java.lang.System.out.println("currentpath: "+_currentPath);
                if(_currentPath.indexOf(selectHere) != -1)
                {
                    _currentPath = _currentPath.substring(0, _currentPath.indexOf(selectHere));
                    java.lang.System.out.println("currentpath-after: "+_currentPath);
                }
                //Return *?* to stop the screen update process.
                newPath = "*?*";
            }
    
            return newPath;
        }
    
        //Saves the files and directories listed in vector format into an object array.
        private Object[] vectorToArray(Vector filesVector)
        {
            int filesCount = filesVector.size();
            int dotIncrementor;
            Object[] files;
    
            //If not in the root, add ".." to the top of the array.
            if (_currentPath == null)
            {
                dotIncrementor = 0;
                files = new Object[(filesCount)];
            }
            else
            {
                dotIncrementor = 1;
                files = new Object[(filesCount + dotIncrementor)];
    
                //Add .. at the top to go back a directory.
                files[0] = (Object)("..");
            }
    
            for (int count = 0; count < filesCount; ++count)
            {
                files[count + dotIncrementor] = (Object)filesVector.elementAt(count);
            }
    
            return files;
        }    
    
        //Handle trackball clicks.
        protected boolean navigationClick(int status, int time)
        {
            doSelection();
            return true;
        }
    
        protected boolean keyChar(char c, int status, int time)
        {
            //Close this screen if escape is selected.
            if (c == Characters.ESCAPE)
            {
                _currentPath = null;
                this.close();
                return true;
            }
            else if (c == Characters.ENTER)
            {
                doSelection();
                return true;
            }
    
            return super.keyChar(c, status, time);
        }
    }
    
  • Updade UI thread

    Hello

    I want to show a list of message on a scree. I have to get a web service messages, showing a popUpScreen with a message waiting, while the service is invocated.

    To do that I have created a RespuestaServicio interface and three classes, MyScreen where I want to display messages, it implements RespuestaServicio methods that are called after the Web service response is obtained, PleaseWaitPopupScreen extends from PopupScreen, which has a method that receives a thread to run while the popupscreen is showed and close itself when the thread end and finally

    LlamadaWSThread is passed to the PleaseWaitPopupScreen call and that the webservice to get the list of messages.

    It's code summarized:

    public class MyScreen extends MainScreen implements RespuestaServicio{
    
        private VerticalFieldManager listaMensajes;
    
        public MyScreen() {
            super(Manager.NO_VERTICAL_SCROLL);
            HorizonlatFieldManager fondo = new HorizonlatFieldManager();
            listaMensajes = new VerticalFieldManager();
            vertical.add(listaMensajes);
            fondo.add(vertical);
            this.add(fondo);
            buscarMensajes();
        }
    
        public void buscarMensajes(){
        // Here I get some parameters like url an xml to pass to LlamadaWSThread constructor
           LlamadaWSThread serviceCaller = new LlamadaWSThread(url, this, xml);
                  PleaseWaitPopupScreen.showScreenAndWait(serviceCaller);
        }
    
        private void llenarLista(String[] campos){
            LabelField campo;
            for(int i = 0; i < campos.length; i++){
                campo = new LabelField(campos[i]);
                campo.setMargin(0, 10, 0, 10);
                listaMensajes.add(campo);
            }
        }
    
        public void requestFailed(final String message) {
           UiApplication.getUiApplication().invokeLater(new Runnable() {
                     public void run() {
                    Dialog.alert("requestFailed: "+message);
                     }
                  });
        }
    
        public void requestSucceeded(Document result) {
            String[] mensajes;
            // Here I proccess result to get mesajes...;
            llenarLista(campos);
        }
    }
    
    public class PleaseWaitPopupScreen extends PopupScreen {
    
        private static LabelField _ourLabelField = null;
    
        private PleaseWaitPopupScreen() {
            super(new VerticalFieldManager());
            ourLabelField = new LabelField("Please wait");
            this.add(urLabelField);
        }
    
        public static void showScreenAndWait(final Runnable runThis) {
            final PleaseWaitPopupScreen thisScreen = new PleaseWaitPopupScreen(text);
            Thread threadToRun = new Thread() {
                public void run() {
    
                    UiApplication.getUiApplication().invokeLater(new Runnable() {
                        public void run() {
                            UiApplication.getUiApplication().pushScreen(thisScreen);
                        }
                    });
    
                    try {
                        runThis.run();
                    } catch (Exception t) {
    
                    }
    
                    UiApplication.getUiApplication().invokeLater(new Runnable() {
                        public void run() {
                            if(thisScreen != null){
                                try {
                   UiApplication.getUiApplication().popScreen(thisScreen);
                } catch (Exception e) {
                   Dialog.alert(e.getMessage());
                      }
                            }
                        }
                    });
                }
            };
            threadToRun.start();
        }
    }
    
    public class LlamadaWSThread extends Thread {
        private RespuestaServicio pantalla;
        private ConstructorXml xml;
        private String url;
    
        public LlamadaWSThread(String url, RespuestaServicio pantalla, ConstructorXml xml) {
            super();
            this.url = url;
            this.pantalla = pantalla;
            this.xml = xml;
        }
    
        public  void    run()
        {
            HttpConnection  conn = null;
            OutputStream    oStream = null;
            try
            {
                conn    =   (HttpConnection)Connector.open( url );
                conn.setRequestMethod( HttpConnection.POST );
                oStream =   conn.openOutputStream();
                oStream.write( xml.getXml().getBytes() );
                oStream.flush();
    
                      InputStream is = conn.openInputStream();
                byte [] response = IOUtilities.streamToBytes(is);
                is.close();
                ByteArrayOutputStream   baos  =  new ByteArrayOutputStream();
                baos.write( response );
                DocumentBuilderFactory  dbf =   DocumentBuilderFactory.newInstance();
                DocumentBuilder db  =   dbf.newDocumentBuilder();
                Document    doc =   db.parse( new ByteArrayInputStream( baos.toByteArray() ) );
                pantalla.requestSucceeded(doc);
            }
            catch (Exception except)
            {
                pantalla.requestFailed(except.toString());
            }
        }   
    
    }
    

    My problem is that I'm getting this exception:

    IllegalStateExeption: UI engine accesed without hoding the lock of the event

    When you call llenarLista (...)  of requestSucceeded (...) who is called to LlamadaWSThread

    Please reread what I proposed. You missed a part on the displacement of campo in the body of the loop for?

    What you see, it's quite normal - plan you a change in the user interface that will update the display with the contents of an object, once you're done. Then you quickly change the contents of this object before all your regular screen updates has a chance to be executed. No wonder that all of these updates are only the last value of this object.

    Compare your loop for:

    for (int i = 0; i < campos.length; ++i) {
      final String campo = campos[i];
      UiApplication.getUiApplication().invokeLater(new Runnable() {
        public void run() {
          listaMensajes.add(new LabelField(campo));
        }
      });
    }
    

    You see the difference?

  • Creating Popup screen without borders

    Hello everyone,

    I'm developing an application in which I use the pop-up screen.

    but the popup screen comes with white border by default.

    How do I remove the border pop-up screen white default.

    If possible can someone explain to me with the code snippet?

    Thanks in advance

    Hi Amit,

    I think this thread will be useful for you

    http://supportforums.BlackBerry.com/T5/Java-development/PopupScreen-with-transparent-background-and-...

  • How to hide the default hourglass in blackberry

    Hello

    In my application, I get the data from the server and analyze...

    It is process, shows a PopupScreen with a hour glass picture and a message added.

    But, the problem is when I run the application, I am able to see my hourglass and default BB hourglass.

    Is it possible to hide the default hourglass

    Thanks in advance

    Hah!

    I looked for this Hourglass.hide () myself, once or twice!

    Sometimes, you get a loop of analysis (or something) with only one problem, and you have 10,000 items create (forcing collection).  These can be hard to find.

    My best advice for the Po is to use the Profiler to see what objects are created/collected.

  • URL of the BB browser change the field number

    Hi guys.

    I'm looking the field as URL edit field.

    You know that the BB browser can show the navigation history.

    I want to make the same to her field.

    How to do?

    The field is used?

    Thank you.

    the browser does not use a single field.
    My first guess would be that it uses a popupscreen with a reminder to enter the selection in the url field. entered at the keyboard is also delegated to the url field and close the pop-up screen.
    (popupscreens did not stay in the Middle, with a border and an ok button)

Maybe you are looking for

  • Satellite P300 back recognize not connected camcorder

    Hello I have a camconrder samsung VP-D361 I try to connect to my Satellite P300-150 using a 1394 cable which is in the i.link on the P300 and the DV out on the camcorder but the laptop is not recognizing the presence of the camcorder. I downloaded al

  • C4580, buttons, not sensitive to touch

    OSX10.10 Upgrade to a router. Problems get router info new wireless printer (connection kept a fall). Suddenly, buttons no longer work. It is powered (as soon as I plug). Wireless light is on, if the printer connection is not seen in the available ne

  • How solve the OptionalComponents cannot be opened. Access is denied. Vista

    How solve the OptionalComponents cannot be opened. Access is denied. For Windows Vista 32 system, some Excel file cannot be opened, impossible to uninstall MS Office.

  • Cannot back up the DVD - RW disk

    Hello! Can you help me?-Windows Vista does not allow me to back up my files on a DVD - RW discIt is an intact and not a damaged disc. Here's what happens: Windows displays files are analyzed and prepared for backup; thenabout an hour later, a dialog

  • Java dropdown list 4.5

    Ho WTO to implement? Any suggestion is welcome. Thank you.