Blackberry - Loading/Wait screen with animation

后端 未结 7 1026
被撕碎了的回忆
被撕碎了的回忆 2020-11-27 13:21

Is there a way to show \"Loading\" screen with animation in blackberry?

Options:

  • PME animation content
  • multithreading + set of
相关标签:
7条回答
  • 2020-11-27 13:56

    The basic pattern for this kind of thing is:

    Have a thread running a loop that updates a variable (such as the frame index of the animated image) and then calls invalidate on a Field which draws the image (and then sleeps for a period of time). The invalidate will queue a repaint of the field.

    In the field's paint method, read the variable and draw the appropriate frame of the image.

    Pseudo code (not totally complete, but to give you the idea):

    public class AnimatedImageField extends Field implements Runnable {
    
       private int currentFrame;
       private Bitmap[] animationFrames;
    
       public void run() {
         while(true) {
           currentFrame = (currentFrame + 1) % animationFrames.length;
           invalidate();
           Thread.sleep(100);
          }
        }
    
       protected void paint(Graphics g) {
          g.drawBitmap(0, 0, imageWidth, imageHeight, animationFrames[currentFrame], 0, 0);
        }
      }
    

    Note also here I used an array of Bitmaps, but EncodedImage lets you treat an animated gif as one object, and includes methods to get specific frames.

    EDIT: For completeness: Add this to a PopupScreen (as in Fermin's answer) or create your own dialog by overriding Screen directly. The separate thread is necessary because the RIM API is not thread-safe: you need to do everything UI related on the event thread (or while holding the event lock, see BlackBerry UI Threading - The Very Basics

    0 讨论(0)
提交回复
热议问题