码迷,mamicode.com
首页 > 其他好文 > 详细

如何使用UserMetric发布消息到Welcome Screen

时间:2015-08-28 17:39:34      阅读:276      评论:0      收藏:0      [点我收藏+]

标签:

我们可以通过UserMetric的API发布消息到我们手机的欢迎页面(手机的锁屏界面)。在锁屏界面中,我们可以双击中间的圆圈,来循环播放我们手机发布的消息。如下图所示,

我们发布了“Useermetric messages received: 4”个消息。


技术分享


我们需要使用的模块是:

import UserMetrics 0.1

我们可以使用如下的方法得到它所有的API:


liuxg@liuxg:~$ qmlplugindump import UserMetrics 0.1
QQmlComponent: Component is not ready
liuxg@liuxg:~$ qmlplugindump  UserMetrics 0.1
import QtQuick.tooling 1.1

// This file describes the plugin-supplied types contained in the library.
// It is used for QML tooling purposes only.
//
// This file was auto-generated by:
// 'qmlplugindump UserMetrics 0.1'

Module {
    Component {
        name: "Metric"
        prototype: "QObject"
        exports: ["Metric 0.1"]
        exportMetaObjectRevisions: [0]
        Property { name: "name"; type: "string" }
        Property { name: "format"; type: "string" }
        Property { name: "emptyFormat"; type: "string" }
        Property { name: "domain"; type: "string" }
        Property { name: "minimum"; type: "double" }
        Property { name: "maximum"; type: "double" }
        Method {
            name: "increment"
            Parameter { name: "amount"; type: "double" }
        }
        Method { name: "increment" }
        Method {
            name: "update"
            Parameter { name: "value"; type: "double" }
        }
    }
}


我们的应用非常简单:


Main.qml


import QtQuick 2.0
import Ubuntu.Components 1.1
import UserMetrics 0.1

/*!
    \brief MainView with a Label and Button elements.
*/

MainView {
    // objectName for functional testing purposes (autopilot-qt5)
    objectName: "mainView"

    // Note! applicationName needs to match the "name" field of the click manifest
    applicationName: "usermetrics.liu-xiao-guo"

    /*
     This property enables the application to change orientation
     when the device is rotated. The default is false.
    */
    //automaticOrientation: true

    // Removes the old toolbar and enables new features of the new header.
    useDeprecatedToolbar: false

    width: units.gu(60)
    height: units.gu(85)

    Page {
        title: i18n.tr("usermetrics")

        Metric {
            id: incomingMessagesMetric
            name: "usermetric"
            format: i18n.tr("Usermetric messages received today: %1")
            emptyFormat: i18n.tr("No Usermetric messages received today.")
            domain: applicationName
        }

        Column {
            anchors.centerIn: parent
            spacing: units.gu(2)

            Button {
                text: i18n.tr("Increase")

                onClicked: {
                    console.log("Going to increase the metric!");
                    incomingMessagesMetric.increment()
                }
            }

            Button {
                text: i18n.tr("Decrease")

                onClicked: {
                    console.log("Going to increase the metric bye 2!");
                    incomingMessagesMetric.increment(-2)
                }
            }

            Button {
                text: i18n.tr("Decrease")

                onClicked: {
                    console.log("Going to update to 3 to the metric!");
                    incomingMessagesMetric.update(3)
                }
            }

        }
    }
}


为了使用UserMetric,我们必须在我们的应用中使用usermetrics security policy:

usermetrics.apparmor


{
    "policy_groups": [
        "networking",
        "webview",
        "usermetrics"
    ],
    "policy_version": 1.3
}<img src="http://img.blog.csdn.net/20150828164655239?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" width="200" height="300" alt="" />


运行我们的应用:


技术分享


每当我们点击increase按钮后,我们的欢迎界面数据将增加一个:


技术分享


整个应用的源码在:git clone https://gitcafe.com/ubuntu/usermetrics.git


版权声明:本文为博主原创文章,未经博主允许不得转载。

如何使用UserMetric发布消息到Welcome Screen

标签:

原文地址:http://blog.csdn.net/ubuntutouch/article/details/48054463

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!