الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

splash screen باستخدام canvas فى تطبيق LWUIT حتى لا يلاحظ المستخدم بطء التحميل

بدأه ahmed.awaad في 6 نوفمبر 2010 · 0 رد · 853 مشاهدة · في JavaME
مشاركة: واتساب X فيسبوك تيليجرام
#1

السلام عليكم ورحمة الله وبركاته

من الملاحظ فى أي تطبيق يستخدم فيه مكتبة LWUIT بطء التحميل، لذلك استخدمت ال Canvas لعمل splash screen يتم عرضها إلى أن تظهر أول LWUIT form فى التطبيق

وإليكم الكود التالي: " أرجو ألا يبخل علي أي زميل بتصحيح أو تعديل فى الكود"

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import com.sun.lwuit.Command;
import com.sun.lwuit.Display;
import com.sun.lwuit.Form;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.impl.midp.VKBImplementationFactory;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.midlet.*;

/**
 * @author Ahmed
 */
public class SplashScreenMidlet extends MIDlet
{

    private Form frmMainForm;

    public void startApp()
    {
        javax.microedition.lcdui.Display.getDisplay(this).setCurrent(new SplashScreen(frmMainForm, "/splash.png"));

        VKBImplementationFactory.init();
        Display.init(this);

        Display.getInstance().callSerially(new Runnable()
        {

            public void run()
            {
                // Uncomment follwing lines to test on emulator
                /*
                try
                {
                    Thread.sleep(3000);
                } catch (InterruptedException ex)
                {
                    ex.printStackTrace();
                }*/
                createMainScreen();
            }
        });

    }

    public void createMainScreen()
    {
        Form form = new Form("Main Form");
        form.addCommand(new Command("Exit")
        {
            public void actionPerformed(ActionEvent evt)
            {
                notifyDestroyed();
            }
        });

        frmMainForm = form;
        frmMainForm.show();
    }

    public void pauseApp()
    {
    }

    public void destroyApp(boolean unconditional)
    {
    }
}

class SplashScreen extends Canvas implements Runnable
{
    private Image mImage;
    private Form tmpForm;

    public SplashScreen(Form tmpForm, String mImagePath)
    {
        this.setFullScreenMode(true);
        this.tmpForm = tmpForm;

        try
        {
            System.out.println(mImagePath);
            this.mImage = Image.createImage(mImagePath);
            this.mImage = resizeImage(mImage);
            Thread t = new Thread(this);
            t.start();

        } catch (Throwable e)
        {
        }
    }

    public void paint(Graphics g)
    {
        if(mImage != null)
        g.drawImage(mImage, 0, 0, Graphics.TOP | Graphics.LEFT);

    }

    public void run()
    {
        try
        {
            while ((this.tmpForm == null) || (!(this.tmpForm.isVisible())))            
            {
                Thread.sleep(1000);//set for 1 seconds                
            }
        } catch (Throwable e)
        {
        }
    }

    private Image resizeImage(Image src)
    {
        int screenWidth = getWidth();
        int screenHeight = getHeight();
        int srcWidth = src.getWidth();
        int srcHeight = src.getHeight();
        Image tmp = Image.createImage(screenWidth, srcHeight);
        Graphics g = tmp.getGraphics();
        int ratio = (srcWidth << 16) / screenWidth;
        int pos = ratio / 2;

        for (int x = 0; x < screenWidth; x++)
        {
            g.setClip(x, 0, 1, srcHeight);
            g.drawImage(src, x - (pos >> 16), 0, Graphics.LEFT | Graphics.TOP);
            pos += ratio;
        }

        Image resizedImage = Image.createImage(screenWidth, screenHeight);
        g = resizedImage.getGraphics();
        ratio = (srcHeight << 16) / screenHeight;
        pos = ratio / 2;

        //Vertical resize

        for (int y = 0; y < screenHeight; y++)
        {
            g.setClip(0, y, screenWidth, 1);
            g.drawImage(tmp, 0, y - (pos >> 16), Graphics.LEFT | Graphics.TOP);
            pos += ratio;
        }
        return resizedImage;

    }//resize image
}
1
banner.jpg

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…