[Interest] Android launch screens?

Nuno Santos nunosantos at imaginando.pt
Wed Aug 5 18:21:57 CEST 2015


Jason,

In order to avoid multiple images to handle different screen resolutions I decided to implement my launch image using Qml only. For that reason I have omitted launch images for both iOS and Android.

The only disadvantage is that it looks a bit black on the beginning compared with other apps opening, but I have a consistent behaviour across platforms. One of the most interesting advantages is that you can have a dynamic splash screen. This is how my main qml file looks like:

import QtQuick 2.4
import QtQuick.Window 2.2
import Imaginando 1.0

Window {
    id: window
    visible: true
    color: "black"
    width: 1024
    height: 768
    onWidthChanged: deviceScreenSize()
    onHeightChanged: deviceScreenSize()
    Component.onCompleted: {
        if (!controller.loaded)
        {
            splash.state="start"
            deviceScreenSize()
        }
    }

    property string prefix: ""
    property real scaleFactor: 1
    property alias style: styleLoader.item
    property var storeModel
    property real currentWidth: 0
    property real currentHeight: 0

    signal styleLoaded

    function deviceScreenSize()
    {
        if (currentWidth==width)
            return

        if (currentHeight==height)
            return

        currentWidth=width
        currentHeight=height

        var size = Math.round(Math.sqrt(width*width+height*height)/Screen.pixelDensity/25.4)

        var screenSizeMin
        var screenSizeMax
        var scaleFactorMin
        var scaleFactorMax

        if (size>=7)
        {
            screenSizeMin=7
            screenSizeMax=12.2
            scaleFactorMin=0.75
            scaleFactorMax=1.25
            styleLoader.source="qrc:/styles/"+window.prefix+"TabletStyle.qml"
            console.log("Device is tablet")
        }
        else
        {
            screenSizeMin=4
            screenSizeMax=7
            scaleFactorMin=0.75
            scaleFactorMax=1.25
            styleLoader.source="qrc:/styles/"+window.prefix+"PhoneStyle.qml"
            console.log("Device is phone")
        }

        scaleFactor = scaleFactorMin+((size-screenSizeMin)/(screenSizeMax-screenSizeMin))*(scaleFactorMax-scaleFactorMin)
    }

    function mmToPx(measure)
    {
        return Math.round(Screen.pixelDensity)*measure*scaleFactor
    }

    Loader {
        id: styleLoader
        onStatusChanged:{
            if (styleLoader.status== Loader.Ready)
                window.styleLoaded()
        }
    }

    FontLoader {
        id: mainFont
        source: "qrc:/fonts/OpenSans-Regular.ttf"
    }

    Timer {
        id: timer
        interval: 250; repeat: false
        onTriggered: splash.state = "start"
    }

    SplashView {
        id: splash
        width: window.width
        height: window.height
        onReady: loader.source = Qt.resolvedUrl("MainView.qml")
    }

    Loader {
        id: loader
        anchors.fill: parent
        asynchronous: true
        visible: status == Loader.Ready
        onLoaded: {
            splash.visible = false
            splash.destroy()
            controller.loaded=true
        }
    }
}


Nuno Santos
Founder / CEO / CTO
www.imaginando.pt
+351 91 621 69 62

> On 05 Aug 2015, at 16:03, Jason H <jhihn at gmx.com> wrote:
> 
> This question is 50% Qt and 50% Android. Now that I have a launch screen working in iOS, I'd like the same thing in Android.
> 
> Now, iOS lists the launch screen separately from the rest of the application, so it can be loaded without having to load the whole app. I'm not sure this is the case in Android. Most android tutorials just create a Activity subclass with a timeout.
> 
> I was wondering if:
> 1) There is a true launch screen for android (not just faking it with a timeout - I want it to only be displayed for as long as the app is loading),
> 2) How I can accomplish it in Qt? I *think* some people may have done something with a Loader Element to create a stub, then dynamically load the screens, but I'm not sure of what all that entails, and if there are any caveats. 
> 2a) Also, do I need to provide an Activity, or can I do it all in Qt/QML? 
> 2b) Is there any actual perceived benefit? The iOS makes the app seem more responsive in a way, and the loading time is not significantly increased.
> 
> Many thanks in advance.
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150805/c8dc4002/attachment.html>


More information about the Interest mailing list