문제

"로드"화면을 표시하는 방법이 있습니까? 애니메이션으로 Blackberry에서?

옵션 :

  • PME 애니메이션 컨텐츠
  • 멀티 스레딩 + 이미지 세트 + 타이머/카운터
  • 표준 림 API
  • 다른 방법

이거 하나?

감사!

도움이 되었습니까?

해결책

Fermin, Anthony +1. 모두 덕분에 대답의 일부를주었습니다.
나의 최종 해결책 :

1. 생성 또는 생성 (무료 Ajax 로딩 GIF 생성기) 애니메이션 및 프로젝트에 추가하십시오.

2. ResponseCallback 인터페이스를 생성합니다 (참조 Coderholic -BlackBerry WebBitMapfield) 스레드 실행 결과를 받으려면 :

public interface ResponseCallback {
    public void callback(String data);  
}

3. 배경 스레드 작업을 처리하기 위해 클래스를 만들어냅니다. 제 경우에는 HTTP 요청이있었습니다.

public class HttpConnector 
{
  static public void HttpGetStream(final String fileToGet,
    final ResponseCallback msgs) {
    Thread t = new Thread(new Runnable() {
      public void run() {
        HttpConnection hc = null;
    DataInputStream din = null;
    try {
      hc = (HttpConnection) Connector.open("http://" + fileToGet);
      hc.setRequestMethod(HttpsConnection.GET);
      din = hc.openDataInputStream();
      ByteVector bv = new ByteVector();
      int i = din.read();
      while (-1 != i) {
        bv.addElement((byte) i);
        i = din.read();
      }
      final String response = new String(bv.toArray(), "UTF-8");
      UiApplication.getUiApplication().invokeLater(
        new Runnable() {
          public void run() {
        msgs.callback(response);
              }
            });
    } 
        catch (final Exception e) {
          UiApplication.getUiApplication().invokeLater(
            new Runnable() {
              public void run() {
                msgs.callback("Exception (" + e.getClass() + "): " 
                  + e.getMessage());
              }
            });
        } 
        finally {
          try {
            din.close();
            din = null;
            hc.close();
            hc = null;
          }
          catch (Exception e) {
          }
        }
      }
    });
  t.start();
  }
}

4. Waitscreen (전체 화면의 하이브리드 및 애니메이션 기드 ResponseCallback 인터페이스) : :

public class WaitScreen extends FullScreen implements ResponseCallback 
{
    StartScreen startScreen;
    private GIFEncodedImage _image;
    private int _currentFrame;
    private int _width, _height, _xPos, _yPos;
    private AnimatorThread _animatorThread;
    public WaitScreen(StartScreen startScreen) {
        super(new VerticalFieldManager(), Field.NON_FOCUSABLE);
        setBackground(
            BackgroundFactory.createSolidTransparentBackground(
                Color.WHITE, 100));
        this.startScreen = startScreen;
        EncodedImage encImg = 
          GIFEncodedImage.getEncodedImageResource("ajax-loader.gif");
        GIFEncodedImage img = (GIFEncodedImage) encImg;

        // Store the image and it's dimensions.
        _image = img;
        _width = img.getWidth();
        _height = img.getHeight();
        _xPos = (Display.getWidth() - _width) >> 1;
        _yPos = (Display.getHeight() - _height) >> 1;
        // Start the animation thread.
        _animatorThread = new AnimatorThread(this);
        _animatorThread.start();
        UiApplication.getUiApplication().pushScreen(this);
    }

    protected void paint(Graphics graphics) {
        super.paint(graphics);
            // Draw the animation frame.
            graphics
              .drawImage(_xPos, _yPos, _image
                .getFrameWidth(_currentFrame), _image
                  .getFrameHeight(_currentFrame), _image,
                _currentFrame, 0, 0);
    }

    protected void onUndisplay() {
        _animatorThread.stop();
    }

    private class AnimatorThread extends Thread {
        private WaitScreen _theField;
        private boolean _keepGoing = true;
        private int _totalFrames, _loopCount, _totalLoops;
        public AnimatorThread(WaitScreen _theScreen) {
            _theField = _theScreen;
            _totalFrames = _image.getFrameCount();
            _totalLoops = _image.getIterations();

        }

        public synchronized void stop() {
            _keepGoing = false;
        }

        public void run() {
            while (_keepGoing) {
                // Invalidate the field so that it is redrawn.
                UiApplication.getUiApplication().invokeAndWait(
                  new Runnable() {
                    public void run() {
                        _theField.invalidate();
                    }
                });
                try {
                  // Sleep for the current frame delay before
                  // the next frame is drawn.
                  sleep(_image.getFrameDelay(_currentFrame) * 10);
                } catch (InterruptedException iex) {
                } // Couldn't sleep.
                // Increment the frame.
                ++_currentFrame;
                if (_currentFrame == _totalFrames) {
                  // Reset back to frame 0 
                  // if we have reached the end.
                  _currentFrame = 0;
                  ++_loopCount;
                  // Check if the animation should continue.
                  if (_loopCount == _totalLoops) {
                    _keepGoing = false;
                  }
                }
            }
        }

    }

    public void callback(String data) {
        startScreen.updateScreen(data);
        UiApplication.getUiApplication().popScreen(this);
    }
}

5. 끝에서 시작 화면을 만들어 httpconnector.httpgetStream을 호출하고 Waitscreen을 표시합니다.

public class StartScreen extends MainScreen
{
    public RichTextField text;
    WaitScreen msgs;
    public StartScreen() {       
        text = new RichTextField();
        this.add(text);
    }

    protected void makeMenu(Menu menu, int instance) {
        menu.add(runWait);
        super.makeMenu(menu, instance);
    }

    MenuItem runWait = new MenuItem("wait", 1, 1) {
        public void run() {
            UiApplication.getUiApplication().invokeLater(
                new Runnable() {
                    public void run() {
                        getFile();
                    }
            });             
        }
    };

    public void getFile() {
        msgs = new WaitScreen(this);
        HttpConnector.HttpGetStream(
            "stackoverflow.com/faq", msgs);                 
    }

    //you should implement this method to use callback data on the screen.
    public void updateScreen(String data)
    {
        text.setText(data);
    }
}

업데이트: 또 다른 해결책 Naviina.eu : 네이티브 블랙 베리 애플리케이션에서 웹 2.0/ajax 스타일 로딩 팝업

다른 팁

이런 종류의 기본 패턴은 다음과 같습니다.

변수 (예 : 애니메이션 이미지의 프레임 인덱스와 같은)를 업데이트하는 루프를 실행 한 다음 이미지를 그리는 필드에서 무효화 한 다음 시간 동안 잠을자는 스레드를 실행하십시오. 무효화는 필드의 리 페인트를 대기합니다.

필드의 페인트 방법에서 변수를 읽고 이미지의 적절한 프레임을 그립니다.

의사 코드 (완전히 완전하지는 않지만 아이디어를 제공하기 위해) :

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);
    }
  }

여기서도 비트 맵 배열을 사용했지만 인코딩을 사용하면 애니메이션 GIF를 하나의 객체로 취급 할 수 있으며 특정 프레임을 얻는 방법을 포함합니다.

편집 : 완전성 : Fermin의 답변에서와 같이 팝업 스크린에 추가하거나 화면을 직접 재정의하여 나만의 대화 상자를 만듭니다. RIM API가 스레드 안전하지 않기 때문에 별도의 스레드가 필요합니다. 이벤트 스레드와 관련된 모든 UI를 수행해야합니다 (또는 이벤트 잠금을 유지하는 동안 참조하십시오. BlackBerry UI 스레딩 - 기본 사항

이것은 화면로드를위한 간단한 코드입니다 ....

                HorizontalFieldManager popHF = new HorizontalFieldManager();
                popHF.add(new CustomLabelField("Pls wait..."));
                final PopupScreen waitScreen = new PopupScreen(popHF);
                new Thread()
                {
                    public void run() 
                    {

                        synchronized (UiApplication.getEventLock()) 
                        {
                            UiApplication.getUiApplication().pushScreen(waitScreen);
                        }
                       //Here Some Network Call 

                       synchronized (UiApplication.getEventLock()) 
                        {
                            UiApplication.getUiApplication().popScreen(waitScreen);
                        }
                     }
                 }.start();

단지 애니메이션이라면 애니메이션 GIF 팝업에서로드 작업이 완료 될 때 닫으세요?

가장 쉬운 방법은 아마도 표준 게이지 필드, 스타일 게이지 필드 설정을 사용하는 것입니다. 이것은 당신에게 진행 상황을 줄 것입니다. 이것을 팝업 화면에 추가하면 콘텐츠 위에 앉아 있습니다. .. 같은 ..

private GaugeField _gaugeField;
private PopupScreen _popup;

public ProgressBar() {    
    DialogFieldManager manager = new DialogFieldManager();
    _popup = new PopupScreen(manager);
    _gaugeField = new GaugeField(null, 0, 100, 0, GaugeField.PERCENT);    
    manager.addCustomField(_gaugeField);
}

그런 다음 _gaugefield.setValue (newValue)를 사용하는 업데이트 메소드가 있습니다. 진행률 표시 줄을 업데이트합니다.

나는 일반적으로 이것을 불러 일으켰습니다.

이 간단한 구현을 살펴 보는 것이 좋습니다. 나는 이것을 좋아했지만 결코 사용하지 않았습니다. 도움이 될 수 있습니다.

링크 텍스트

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top