您的位置:首页 > 其它

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

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

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



我们需要使用的模块是:

import UserMetrics 0.1


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

liuxg@liuxg:~$ qmlplugindump import UserMetrics 0.1QQmlComponent: 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
}


运行我们的应用:



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



整个应用的源码在:https://github.com/liu-xiao-guo/usermetrics
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: