code:
/*
    Copyright (c) 2009-2011, BogDan Vatra <bog_dan_ro@yahoo.com>
    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are met:
        * Redistributions of source code must retain the above copyright
        notice, this list of conditions and the following disclaimer.
        * Redistributions in binary form must reproduce the above copyright
        notice, this list of conditions and the following disclaimer in the
        documentation and/or other materials provided with the distribution.
        * Neither the name of the  BogDan Vatra <bog_dan_ro@yahoo.com> nor the
        names of its contributors may be used to endorse or promote products
        derived from this software without specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY BogDan Vatra <bog_dan_ro@yahoo.com> ''AS IS'' AND ANY
    EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    DISCLAIMED. IN NO EVENT SHALL BogDan Vatra <bog_dan_ro@yahoo.com> BE LIABLE FOR ANY
    DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package eu.licentia.necessitas.industrius;

import java.io.File;
import java.util.ArrayList;

import android.app.Application;
import android.util.Log;
import android.view.MotionEvent;

public class QtApplication extends Application
{
    private static QtActivity m_mainActivity = null;
    private static QtSurface m_mainView = null;
    public static Object m_mainActivityMutex = new Object(); // mutex used to synchronize runnable operations

    public static final String QtTAG = "Qt JAVA"; // string used for Log.x
    private static ArrayList<Runnable> m_lostActions = new ArrayList<Runnable>(); // a list containing all actions which could not be performed (e.g. the main activity is destroyed, etc.)
    private static boolean m_started = false;
    private static int m_displayMetricsScreenWidthPixels = 0;
    private static int m_displayMetricsScreenHeightPixels = 0;
    private static int m_displayMetricsDesktopWidthPixels = 0;
    private static int m_displayMetricsDesktopHeightPixels = 0;
    private static double m_displayMetricsXDpi = .0;
    private static double m_displayMetricsYDpi = .0;
    private static int m_oldx, m_oldy;
    private static final int m_moveThreshold = 0;

    public static QtActivity mainActivity()
    {
        return m_mainActivity;
    }

    public static QtSurface mainView()
    {
        return m_mainView;
    }

    // this method loads full path libs
    public static void loadQtLibraries(String[] libraries)
    {
        if (libraries == null)
            return;

        for (int i = 0; i < libraries.length; i++)
        {
            try
            {
                File f = new File(libraries[i]);
                if (f.exists())
                    System.load(libraries[i]);
            }
            catch (SecurityException e)
            {
                Log.i(QtTAG, "Can't load '" + libraries[i] + "'", e);
            }
            catch (Exception e)
            {
                Log.i(QtTAG, "Can't load '" + libraries[i] + "'", e);
            }
        }
    }

        // this method loads bundled libs by name.
    public static void loadBundledLibraries(String[] libraries)
    {
        for (int i = 0; i < libraries.length; i++)
        {
            try
            {
                System.loadLibrary(libraries[i]);
            }
            catch (UnsatisfiedLinkError e)
            {
                Log.i(QtTAG, "Can't load '" + libraries[i] + "'", e);
            }
            catch (SecurityException e)
            {
                Log.i(QtTAG, "Can't load '" + libraries[i] + "'", e);
            }
            catch (Exception e)
            {
                Log.i(QtTAG, "Can't load '" + libraries[i] + "'", e);
            }
        }
    }

    public static void setMainActivity(QtActivity qtMainActivity)
    {
        synchronized (m_mainActivityMutex)
        {
            m_mainActivity = qtMainActivity;
        }
    }
    public static void setMainView(QtSurface qtSurface)
    {
        synchronized (m_mainActivityMutex)
        {
            m_mainView = qtSurface;
        }
    }

    static public ArrayList<Runnable> getLostActions()
    {
        return m_lostActions;
    }

    static public void clearLostActions()
    {
        m_lostActions.clear();
    }

    private static boolean runAction(Runnable action)
    {
        synchronized (m_mainActivityMutex)
        {
            if (m_mainActivity == null)
                m_lostActions.add(action);
            else
                m_mainActivity.runOnUiThread(action);
            return m_mainActivity != null;
        }
    }

    public static void startApplication(String params, String environment)
    {
        if (params == null)
            params = "-platform\tandroid";

        synchronized (m_mainActivityMutex)
        {
            startQtAndroidPlugin();
            setDisplayMetrics(m_displayMetricsScreenWidthPixels,
                            m_displayMetricsScreenHeightPixels,
                            m_displayMetricsDesktopWidthPixels,
                            m_displayMetricsDesktopHeightPixels,
                            m_displayMetricsXDpi,
                            m_displayMetricsYDpi);
            if (params.length()>0)
                params="\t"+params;
            startQtApp("QtApp"+params, environment);
            m_started=true;
        }
    }

    public static void setApplicationDisplayMetrics(int screenWidthPixels,
            int screenHeightPixels, int desktopWidthPixels,
            int desktopHeightPixels, double XDpi, double YDpi)
    {
        /* Fix buggy dpi report */
        if (XDpi<android.util.DisplayMetrics.DENSITY_LOW)
            XDpi=android.util.DisplayMetrics.DENSITY_LOW;
        if (YDpi<android.util.DisplayMetrics.DENSITY_LOW)
            YDpi=android.util.DisplayMetrics.DENSITY_LOW;

        synchronized (m_mainActivityMutex)
        {
            if (m_started)
                setDisplayMetrics(screenWidthPixels, screenHeightPixels, desktopWidthPixels, desktopHeightPixels, XDpi, YDpi);
            else
            {
                m_displayMetricsScreenWidthPixels = screenWidthPixels;
                m_displayMetricsScreenHeightPixels = screenHeightPixels;
                m_displayMetricsDesktopWidthPixels = desktopWidthPixels;
                m_displayMetricsDesktopHeightPixels = desktopHeightPixels;
                m_displayMetricsXDpi = XDpi;
                m_displayMetricsYDpi = YDpi;
            }
        }
    }

    public static void pauseApplication()
    {
        synchronized (m_mainActivityMutex)
        {
            if (m_started)
                pauseQtApp();
        }
    }

    public static void resumeApplication()
    {
        synchronized (m_mainActivityMutex)
        {
            if (m_started)
            {
                resumeQtApp();
                updateWindow();
            }
        }
    }
    // application methods
    public static native void startQtApp(String params,String env);
    public static native void pauseQtApp();
    public static native void resumeQtApp();
    public static native void startQtAndroidPlugin();
    public static native void quitQtAndroidPlugin();
    public static native void terminateQt();
    // application methods

    private static void quitApp()
    {
        m_mainActivity.finish();
    }

    private static void redrawSurface(final int left, final int top, final int right, final int bottom )
    {
        runAction(new Runnable() {
            @Override
            public void run() {
                m_mainActivity.redrawWindow(left, top, right, bottom);
            }
        });
    }

    @Override
    public void onTerminate() {
        if (m_started)
            terminateQt();
        super.onTerminate();
    }

    //@ANDROID-5
//QtCreator     static private int getAction(int index, MotionEvent event)
//QtCreator     {
//QtCreator         int action=event.getAction();
//QtCreator         if (action == MotionEvent.ACTION_MOVE)
//QtCreator         {
//QtCreator             int hsz=event.getHistorySize();
//QtCreator             if (hsz>0)
//QtCreator             {
//QtCreator                 if (Math.abs(event.getX(index)-event.getHistoricalX(index, hsz-1))>1||
//QtCreator                                 Math.abs(event.getY(index)-event.getHistoricalY(index, hsz-1))>1)
//QtCreator                     return 1;
//QtCreator                 else
//QtCreator                     return 2;
//QtCreator             }
//QtCreator             return 1;
//QtCreator         }
//QtCreator
//QtCreator         switch(index)
//QtCreator         {
//QtCreator             case 0:
//QtCreator                 if (action == MotionEvent.ACTION_DOWN ||
//QtCreator                         action == MotionEvent.ACTION_POINTER_1_DOWN)
//QtCreator                     return 0;
//QtCreator                 if (action == MotionEvent.ACTION_UP ||
//QtCreator                         action == MotionEvent.ACTION_POINTER_1_UP)
//QtCreator                     return 3;
//QtCreator                 break;
//QtCreator
//QtCreator             case 1:
//QtCreator                 if (action == MotionEvent.ACTION_POINTER_2_DOWN ||
//QtCreator                         action == MotionEvent.ACTION_POINTER_DOWN)
//QtCreator                     return 0;
//QtCreator                 if (action == MotionEvent.ACTION_POINTER_2_UP ||
//QtCreator                         action == MotionEvent.ACTION_POINTER_UP)
//QtCreator                     return 3;
//QtCreator                 break;
//QtCreator
//QtCreator             case 2:
//QtCreator                 if (action == MotionEvent.ACTION_POINTER_3_DOWN ||
//QtCreator                         action == MotionEvent.ACTION_POINTER_DOWN)
//QtCreator                     return 0;
//QtCreator                 if (action == MotionEvent.ACTION_POINTER_3_UP ||
//QtCreator                         action == MotionEvent.ACTION_POINTER_UP)
//QtCreator                     return 3;
//QtCreator                 break;
//QtCreator         }
//QtCreator         return 2;
//QtCreator     }
    //@ANDROID-5

    static public void sendTouchEvent(MotionEvent event, int id)
    {
        //@ANDROID-5
//QtCreator         touchBegin(id);
//QtCreator         for (int i=0;i<event.getPointerCount();i++)
//QtCreator                 touchAdd(id,event.getPointerId(i), getAction(i, event), i==0,
//QtCreator                                 (int)event.getX(i), (int)event.getY(i), event.getSize(i),
//QtCreator                                 event.getPressure(i));
//QtCreator
//QtCreator         switch(event.getAction())
//QtCreator         {
//QtCreator             case MotionEvent.ACTION_DOWN:
//QtCreator                 touchEnd(id,0);
//QtCreator                 break;
//QtCreator
//QtCreator             case MotionEvent.ACTION_UP:
//QtCreator                 touchEnd(id,2);
//QtCreator                 break;
//QtCreator
//QtCreator             default:
//QtCreator                 touchEnd(id,1);
//QtCreator         }
        //@ANDROID-5

        switch (event.getAction())
        {
            case MotionEvent.ACTION_UP:
                mouseUp(id,(int) event.getX(), (int) event.getY());
                break;

            case MotionEvent.ACTION_DOWN:
                mouseDown(id,(int) event.getX(), (int) event.getY());
                m_oldx = (int) event.getX();
                m_oldy = (int) event.getY();
                break;

            case MotionEvent.ACTION_MOVE:
                int dx = (int) (event.getX() - m_oldx);
                int dy = (int) (event.getY() - m_oldy);
                if (Math.abs(dx) > m_moveThreshold || Math.abs(dy) > m_moveThreshold)
                {
                    mouseMove(id,(int) event.getX(), (int) event.getY());
                    m_oldx = (int) event.getX();
                    m_oldy = (int) event.getY();
                }
                break;
        }
    }

    static public void sendTrackballEvent(MotionEvent event, int id)
    {
        switch (event.getAction())
        {
            case MotionEvent.ACTION_UP:
                mouseUp(id, (int) event.getX(), (int) event.getY());
                break;

            case MotionEvent.ACTION_DOWN:
                mouseDown(id, (int) event.getX(), (int) event.getY());
                m_oldx = (int) event.getX();
                m_oldy = (int) event.getY();
                break;

            case MotionEvent.ACTION_MOVE:
                int dx = (int) (event.getX() - m_oldx);
                int dy = (int) (event.getY() - m_oldy);
                if (Math.abs(dx) > 5 || Math.abs(dy) > 5)
                {
                        mouseMove(id, (int) event.getX(), (int) event.getY());
                        m_oldx = (int) event.getX();
                        m_oldy = (int) event.getY();
                }
                break;
        }
    }

    private static void showSoftwareKeyboard()
    {
        runAction(new Runnable() {
            @Override
            public void run() {
                m_mainActivity.showSoftwareKeyboard();
            }
        });
    }

    private static void hideSoftwareKeyboard()
    {
        runAction(new Runnable() {
            @Override
            public void run() {
                m_mainActivity.hideSoftwareKeyboard();
            }
        });
    }

    private static void setFullScreen(final boolean fullScreen)
    {
        runAction(new Runnable() {
            @Override
            public void run() {
                m_mainActivity.setFullScreen(fullScreen);
                updateWindow();
            }
        });
    }

    public static native void setEglObject(Object eglObject);

    // screen methods
    public static native void setDisplayMetrics(int screenWidthPixels,
                    int screenHeightPixels, int desktopWidthPixels,
                    int desktopHeightPixels, double XDpi, double YDpi);
    // screen methods

    // pointer methods
    public static native void mouseDown(int winId, int x, int y);
    public static native void mouseUp(int winId, int x, int y);
    public static native void mouseMove(int winId, int x, int y);
    public static native void touchBegin(int winId);
    public static native void touchAdd(int winId, int pointerId, int action, boolean primary, int x, int y, float size, float pressure);
    public static native void touchEnd(int winId, int action);
    // pointer methods

    // keyboard methods
    public static native void keyDown(int key, int unicode, int modifier);
    public static native void keyUp(int key, int unicode, int modifier);
    // keyboard methods

    // surface methods
    public static native void destroySurface();
    public static native void setSurface(Object surface);
    public static native void lockSurface();
    public static native void unlockSurface();
    // surface methods

    // window methods
    public static native void updateWindow();
    // window methods
}


code:
/*
    Copyright (c) 2009-2011, BogDan Vatra <bog_dan_ro@yahoo.com>
    Copyright (c) 2011 Elektrobit (EB), All rights reserved.
    Contact: oss-devel@elektrobit.com
    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are met:
        * Redistributions of source code must retain the above copyright
        notice, this list of conditions and the following disclaimer.
        * Redistributions in binary form must reproduce the above copyright
        notice, this list of conditions and the following disclaimer in the
        documentation and/or other materials provided with the distribution.
        * Neither the name of the  BogDan Vatra <bog_dan_ro@yahoo.com> nor the
        names of its contributors may be used to endorse or promote products
        derived from this software without specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY BogDan Vatra <bog_dan_ro@yahoo.com> ''AS IS'' AND ANY
    EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    DISCLAIMED. IN NO EVENT SHALL BogDan Vatra <bog_dan_ro@yahoo.com> BE LIABLE FOR ANY
    DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package eu.licentia.necessitas.industrius;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;

public class QtLayout extends ViewGroup{
    public QtLayout(Context context) {
        super(context);
    }

    public QtLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public QtLayout(Context context, AttributeSet attrs,
            int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int count = getChildCount();

        int maxHeight = 0;
        int maxWidth = 0;

        // Find out how big everyone wants to be
        measureChildren(widthMeasureSpec, heightMeasureSpec);

        // Find rightmost and bottom-most child
        for (int i = 0; i < count; i++) {
            View child = getChildAt(i);
            if (child.getVisibility() != GONE) {
                int childRight;
                int childBottom;

                QtLayout.LayoutParams lp
                        = (QtLayout.LayoutParams) child.getLayoutParams();

                childRight = lp.x + child.getMeasuredWidth();
                childBottom = lp.y + child.getMeasuredHeight();

                maxWidth = Math.max(maxWidth, childRight);
                maxHeight = Math.max(maxHeight, childBottom);
            }
        }

        // Check against minimum height and width
        maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight());
        maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth());

        setMeasuredDimension(resolveSize(maxWidth, widthMeasureSpec),
                resolveSize(maxHeight, heightMeasureSpec));
    }

    /**
    * Returns a set of layout parameters with a width of
    * {@link android.view.ViewGroup.LayoutParams#WRAP_CONTENT},
    * a height of {@link android.view.ViewGroup.LayoutParams#WRAP_CONTENT}
    * and with the coordinates (0, 0).
    */
    @Override
    protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
        return new LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 0, 0);
    }

    @Override
    protected void onLayout(boolean changed, int l, int t,
            int r, int b) {
        int count = getChildCount();

        for (int i = 0; i < count; i++) {
            View child = getChildAt(i);
            if (child.getVisibility() != GONE) {

                QtLayout.LayoutParams lp =
                        (QtLayout.LayoutParams) child.getLayoutParams();

                int childLeft = lp.x;
                int childTop = lp.y;
                child.layout(childLeft, childTop,
                        childLeft + child.getMeasuredWidth(),
                        childTop + child.getMeasuredHeight());

            }
        }
    }

    // Override to allow type-checking of LayoutParams.
    @Override
    protected boolean checkLayoutParams(ViewGroup.LayoutParams p) {
        return p instanceof QtLayout.LayoutParams;
    }

    @Override
    protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {
        return new LayoutParams(p);
    }

    /**
    * Per-child layout information associated with AbsoluteLayout.
    * See
    * {@link android.R.styleable#AbsoluteLayout_Layout Absolute Layout Attributes}
    * for a list of all child view attributes that this class supports.
    */
    public static class LayoutParams extends ViewGroup.LayoutParams {
        /**
        * The horizontal, or X, location of the child within the view group.
        */
        public int x;
        /**
        * The vertical, or Y, location of the child within the view group.
        */
        public int y;

        /**
        * Creates a new set of layout parameters with the specified width,
        * height and location.
        *
        * @param width the width, either {@link #FILL_PARENT},
                {@link #WRAP_CONTENT} or a fixed size in pixels
        * @param height the height, either {@link #FILL_PARENT},
                {@link #WRAP_CONTENT} or a fixed size in pixels
        * @param x the X location of the child
        * @param y the Y location of the child
        */
        public LayoutParams(int width, int height, int x, int y) {
            super(width, height);
            this.x = x;
            this.y = y;
        }

        /**
        * {@inheritDoc}
        */
        public LayoutParams(ViewGroup.LayoutParams source) {
            super(source);
        }
    }

    public void bringChildFront(int child)
    {
        bringChildToFront(getChildAt(child));
    }
}

repo_name: snapshot/uds

license: mit


code:
/*
    Copyright (c) 2009-2011, BogDan Vatra <bog_dan_ro@yahoo.com>
    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are met:
        * Redistributions of source code must retain the above copyright
        notice, this list of conditions and the following disclaimer.
        * Redistributions in binary form must reproduce the above copyright
        notice, this list of conditions and the following disclaimer in the
        documentation and/or other materials provided with the distribution.
        * Neither the name of the  BogDan Vatra <bog_dan_ro@yahoo.com> nor the
        names of its contributors may be used to endorse or promote products
        derived from this software without specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY BogDan Vatra <bog_dan_ro@yahoo.com> ''AS IS'' AND ANY
    EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    DISCLAIMED. IN NO EVENT SHALL BogDan Vatra <bog_dan_ro@yahoo.com> BE LIABLE FOR ANY
    DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package eu.licentia.necessitas.industrius;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class QtSurface extends SurfaceView implements SurfaceHolder.Callback
{
    private Bitmap m_bitmap=null;
    private boolean m_started = false;
    public QtSurface(Context context, int id)
    {
        super(context);
        setFocusable(true);
        getHolder().addCallback(this);
        getHolder().setType(SurfaceHolder.SURFACE_TYPE_GPU);
        setId(id);
    }

    public void applicationStared()
    {
        m_started = true;
        if (getWidth() < 1 ||  getHeight() < 1)
            return;
        QtApplication.lockSurface();
        QtApplication.setSurface(null);
        m_bitmap=Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.RGB_565);
        QtApplication.setSurface(m_bitmap);
        QtApplication.unlockSurface();
    }

    @Override
    public void surfaceCreated(SurfaceHolder holder)
    {
        DisplayMetrics metrics = new DisplayMetrics();
        ((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(metrics);
        QtApplication.setApplicationDisplayMetrics(metrics.widthPixels,
            metrics.heightPixels, getWidth(), getHeight(), metrics.xdpi, metrics.ydpi);

        if (!m_started)
            return;

        QtApplication.lockSurface();
        QtApplication.setSurface(null);
        m_bitmap=Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.RGB_565);
        QtApplication.setSurface(m_bitmap);
        QtApplication.unlockSurface();

    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
    {
        Log.i(QtApplication.QtTAG,"surfaceChanged: "+width+","+height);
        if (width<1 || height<1)
                return;

        DisplayMetrics metrics = new DisplayMetrics();
        ((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(metrics);
        QtApplication.setApplicationDisplayMetrics(metrics.widthPixels,
            metrics.heightPixels, width, height, metrics.xdpi, metrics.ydpi);

        if (!m_started)
            return;
        QtApplication.lockSurface();
        QtApplication.setSurface(null);
        m_bitmap=Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
        QtApplication.setSurface(m_bitmap);
        QtApplication.unlockSurface();
        QtApplication.updateWindow();
    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder)
    {
        if (!m_started)
            return;
        Log.i(QtApplication.QtTAG,"surfaceDestroyed ");
        QtApplication.lockSurface();
        QtApplication.setSurface(null);
        QtApplication.unlockSurface();
    }

    public void drawBitmap(Rect rect)
    {
        if (!m_started)
            return;
        QtApplication.lockSurface();
        if (null!=m_bitmap)
        {
            try
            {
                Canvas cv=getHolder().lockCanvas(rect);
                cv.drawBitmap(m_bitmap, rect, rect, null);
                getHolder().unlockCanvasAndPost(cv);
            }
            catch (Exception e)
            {
                Log.e(QtApplication.QtTAG, "Can't create main activity", e);
            }
        }
        QtApplication.unlockSurface();
    }

    @Override
    public boolean onTouchEvent(MotionEvent event)
    {
        if (!m_started)
            return false;
        QtApplication.sendTouchEvent(event, getId());
        return true;
    }

    @Override
    public boolean onTrackballEvent(MotionEvent event)
    {
        if (!m_started)
            return false;
        QtApplication.sendTrackballEvent(event, getId());
        return true;
    }
}


code:
/*
    Copyright (c) 2009-2011, BogDan Vatra <bog_dan_ro@yahoo.com>
    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are met:
        * Redistributions of source code must retain the above copyright
        notice, this list of conditions and the following disclaimer.
        * Redistributions in binary form must reproduce the above copyright
        notice, this list of conditions and the following disclaimer in the
        documentation and/or other materials provided with the distribution.
        * Neither the name of the  BogDan Vatra <bog_dan_ro@yahoo.com> nor the
        names of its contributors may be used to endorse or promote products
        derived from this software without specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY BogDan Vatra <bog_dan_ro@yahoo.com> ''AS IS'' AND ANY
    EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    DISCLAIMED. IN NO EVENT SHALL BogDan Vatra <bog_dan_ro@yahoo.com> BE LIABLE FOR ANY
    DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package eu.licentia.necessitas.ministro;

import eu.licentia.necessitas.ministro.IMinistroCallback;

interface IMinistro
{
    /**
    * Check/download required libs to run the application
    *
    * param callback              - interface used by the service to notify the client when it has the libs
    * param modules               - Qt modules you want to check
    * param appName               - Application name, used to show more informations to user
    * param ministroApiLevel      - Ministro api level, used to check ministro service compatibility.
    *                               Current API Level is 1 !!!
    * param mecessitasApiLevel    - Necessitas api level, used to download the right platform plugin.
    *                               Current API Level is 1 !!!
    */

    void checkModules(in IMinistroCallback callback, in String[] modules, in String appName, in int ministroApiLevel, in int necessitasApiLevel);
}


code:
/*
    Copyright (c) 2009-2011, BogDan Vatra <bog_dan_ro@yahoo.com>
    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are met:
        * Redistributions of source code must retain the above copyright
        notice, this list of conditions and the following disclaimer.
        * Redistributions in binary form must reproduce the above copyright
        notice, this list of conditions and the following disclaimer in the
        documentation and/or other materials provided with the distribution.
        * Neither the name of the  BogDan Vatra <bog_dan_ro@yahoo.com> nor the
        names of its contributors may be used to endorse or promote products
        derived from this software without specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY BogDan Vatra <bog_dan_ro@yahoo.com> ''AS IS'' AND ANY
    EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    DISCLAIMED. IN NO EVENT SHALL BogDan Vatra <bog_dan_ro@yahoo.com> BE LIABLE FOR ANY
    DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package eu.licentia.necessitas.ministro;

oneway interface IMinistroCallback {
    /**
    * This method is called back by the Ministro service
    *
    * param in - libs, you have to load before load the application
    * param in - evnVars, tab separated environment variables
    * param in - params, tab separated paras which should be passed to the application
    * param in - errorCode, the error number, the application should check the error code before starts
    *             - 0 no error
    *             - 1 no qt libs found
    *             - xxx
    * param in - errorMessage, the error message (where available, translated into phone language).
    */

    void libs(in String[] libs,in String environmentVariables, in String applicationParams, in int errorCode, in String errorMessage);
}