gpt4 book ai didi

user-interface - Blackberry - 带动画的加载/等待屏幕

转载 作者:行者123 更新时间:2023-12-03 22:48:28 25 4
gpt4 key购买 nike

有没有办法在黑莓中显示带有动画的“加载”屏幕?

选项:

  • PME动画内容
  • 多线程 + 图像集 + 定时器/计数器
  • 标准轮辋 API
  • 其他方式

  • 有这些吗?

    谢谢!

    最佳答案

    费尔明,安东尼+1。谢谢大家,你给了我答案的一部分。
    我的最终解决方案:

    1.创建或生成(free Ajax loading gif generator)动画并将其添加到项目中。

    2.创建ResponseCallback接口(interface)(见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(FullScreen和 AnimatedGIFField的混合体,带有ResponseCallback接口(interface)):
    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: A Web2.0/Ajax-style loading popup in a native BlackBerry application

    关于user-interface - Blackberry - 带动画的加载/等待屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/801161/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com