0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

OpenHarmony DaYu200开发板示例 鸿蒙智联汽车【1.0】

ArkUI详解 来源:鸿蒙实验室 作者:鸿蒙实验室 2022-07-13 09:22 次阅读

应用场景:

智慧出行。

智能汽车是集环境感知、规划决策、多等级辅助驾驶等功能于一体的智能网联综合系统,它集中运用了计算机、现代传感、信息融合、通讯、人工智能及自动控制等技术,是典型的高新技术综合体。简单的说,智能汽车的出现将逐步放松车、手、眼,让开车,用车变得简单。这样的产品对有本儿不敢上路的人来说或许是大大的福音。

在北方冬天有点冷,这个时候,去车里,温度很低,给人一种不舒服的感觉,那么有没有一种可能,就是可以通过手机App,实现对车内的一些情况的监测,答案是有的,今天做的这个App,就是这样一个App。

我要实现的功能主要有

用户可以解锁任何车门,

检查电池状态,

控制空调温度,

检查轮胎的气压。

在开始之前大家可以先预览一下我完成之后的效果。如下图所示:

智联汽车演示_

是不是很炫酷呢?

搭建OpenHarmony环境

完成本篇Codelab我们首先要完成开发环境的搭建,本示例以DaYu200开发板为例,参照以下步骤进行:

获取OpenHarmony系统版本:标准系统解决方案(二进制)

以3.0版本为例:

img

搭建烧录环境

完成DevEco Device Tool的安装

完成Dayu200开发板的烧录

搭建开发环境

开始前请参考工具准备 ,完成DevEco Studio的安装和开发环境配置。

开发环境配置完成后,请参考使用工程向导 创建工程(模板选择“Empty Ability”),选择eTS语言开发。

工程创建完成后,选择使用真机进行调测 。

相关概念

容器组件

Column

Row

Stack

基础组件

Text

Button

Image

Navigation

通用

边框设置

尺寸设置

点击控制

布局约束

背景设置

点击事件

TS语法糖

好的接下来我将详细讲解如何制作

开发教学

创建好的 eTS工程目录

新建工程的ETS目录如下图所示。

img

各个文件夹和文件的作用:

index.ets:用于描述UI布局、样式、事件交互和页面逻辑。

app.ets:用于全局应用逻辑和应用生命周期管理。

pages:用于存放所有组件页面。

resources:用于存放资源配置文件。

接下来开始正文。

我们的主要操作都是在在pages目录中,然后我将用不到10分钟的时间,带大家实现这个功能。

拆解

image-20220706083825022

根据设计图,我们可以分为内容展示区和菜单。

针对这一点,我们可以用Navigation组件作为Page页面的根容器,通过属性设置来展示页面的标题、工具栏、菜单。

Navigation

() {

Column

({

space

:

20

}) {

if

(

this

.

index

==

0

)

DoorLook

()

else

if

(

this

.

index

==

1

)

Battery

()

else

if

(

this

.

index

==

2

)

Temp

()

else

if

(

this

.

index

==

3

)

Tyre

()

}

.

backgroundColor

(

Color

.

Black

)

.

justifyContent

(

FlexAlign

.

SpaceAround

)

.

alignItems

(

HorizontalAlign

.

Center

)

.

justifyContent

(

FlexAlign

.

Center

)

.

size

({

width

:

'100%'

,

height

:

'100%'

})

} .

size

({

width

:

'100%'

,

height

:

'100%'

})

.

toolBar

(

this

.

toolbarWidget

())

.

hideToolBar

(

this

.

hideToolBar

)

.

hideTitleBar

(

this

.

hideTitleBar

)

具体布局

具体布局设计到一些细节的地方,例如间隔,边框,当前组件尺寸设置等一些特殊情况,基本上就是嵌套,一层一层去实现。

代码结构

image-20220706084830625

编码

Index.ets

import

Tyre

from

'./tyre_page'

;

import

Temp

from

'./temp_page'

;

import

Battery

from

'./battery_page'

;

import

DoorLook

from

'./door_lock_page'

;

@

Entry

@

Component

struct

ComponentTest

{

@

State

index

:

number

=

0

;

// 选项卡下标,默认为第一个

@

State

hideToolBar

:

boolean

=

false

;

@

State

hideTitleBar

:

boolean

=

true

;

private

imageArray

:

string

[]

=

[

'app.media.Lock'

,

'app.media.Charge'

,

'app.media.Temp'

,

'app.media.Tyre'

,];

// 数据源

@

Builder

toolbarWidget

() {

// 通过builder自定义toolbar

Row

() {

Column

() {

Image

(

this

.

index

==

0

?

$r

(

'app.media.lock'

):

$r

(

'app.media.lock0'

) )

.

size

({

width

:

36

,

height

:

36

}).

margin

({

bottom

:

4

,

top

:

12

})

}

.

alignItems

(

HorizontalAlign

.

Center

)

.

height

(

'100%'

)

.

layoutWeight

(

1

)

.

onClick

(()

=>

{

this

.

index

=

0

;

})

Column

() {

Image

(

this

.

index

==

1

?

$r

(

'app.media.battery'

):

$r

(

"app.media.battery0"

))

.

size

({

width

:

36

,

height

:

36

}).

margin

({

bottom

:

4

,

top

:

12

})

}

.

alignItems

(

HorizontalAlign

.

Center

)

.

height

(

'100%'

)

.

layoutWeight

(

1

)

.

onClick

(()

=>

{

this

.

index

=

1

;

})

Column

() {

Image

(

this

.

index

==

2

?

$r

(

'app.media.yytemp'

):

$r

(

'app.media.yytem0'

))

.

size

({

width

:

36

,

height

:

36

}).

margin

({

bottom

:

4

,

top

:

12

})

}

.

alignItems

(

HorizontalAlign

.

Center

)

.

height

(

'100%'

)

.

layoutWeight

(

1

)

.

onClick

(()

=>

{

this

.

index

=

2

;

})

Column

() {

Image

(

this

.

index

==

3

?

$r

(

'app.media.tyre'

):

$r

(

'app.media.tyre0'

))

.

size

({

width

:

36

,

height

:

36

}).

margin

({

bottom

:

4

,

top

:

12

})

}

.

alignItems

(

HorizontalAlign

.

Center

)

.

height

(

'100%'

)

.

layoutWeight

(

1

)

.

onClick

(()

=>

{

this

.

index

=

3

;

})

}.

backgroundColor

(

Color

.

Black

)

.

width

(

'100%'

)

.

height

(

66

)

}

build

() {

Navigation

() {

Column

({

space

:

20

}) {

//根据索引展示对应内容å

if

(

this

.

index

==

0

)

DoorLook

()

else

if

(

this

.

index

==

1

)

Battery

()

else

if

(

this

.

index

==

2

)

Temp

()

else

if

(

this

.

index

==

3

)

Tyre

()

}

.

backgroundColor

(

Color

.

Black

)

.

justifyContent

(

FlexAlign

.

SpaceAround

)

.

alignItems

(

HorizontalAlign

.

Center

)

.

justifyContent

(

FlexAlign

.

Center

)

.

size

({

width

:

'100%'

,

height

:

'100%'

})

}

.

size

({

width

:

'100%'

,

height

:

'100%'

})

.

title

(

"跟着坚果学OpenHarmony"

)

.

toolBar

(

this

.

toolbarWidget

())

//自定义底部菜单栏

.

hideToolBar

(

this

.

hideToolBar

)

.

hideTitleBar

(

this

.

hideTitleBar

)

.

menus

([

{

value

:

"关"

,

icon

:

'common/images/door_lock.svg'

,

action

: ()

=>

{

console

.

log

(

"工具栏"

)

}

},

{

value

:

"开"

,

icon

:

'common/images/door_unlock.svg'

,

action

: ()

=>

{

}

}

])

}

}

效果演示:

车锁页

@

Entry

@

Component

export

default

struct

DoorLook

{

//车锁页

@

State

isRightDoorLock

:

boolean

=

false

;

@

State

isLeftDoorLock

:

boolean

=

false

;

@

State

isBonnetLock

:

boolean

=

false

;

@

State

isTrunkLock

:

boolean

=

false

;

build

() {

Column

() {

Stack

() {

Image

(

$r

(

"app.media.Car"

))

.

width

(

"100%"

)

.

height

(

"100%"

)

.

objectFit

(

ImageFit

.

Contain

)

.

margin

({

left

:

20

})

Image

(

$r

(

"app.media.door_lock"

))

.

width

(

60

).

height

(

60

).

position

({

x

:

340

,

y

:

50

})

.

onClick

(()

=>

{

})

Image

(

$r

(

"app.media.door_unlock"

)).

width

(

60

).

height

(

60

).

position

({

x

:

50

,

y

:

600

})

Image

(

$r

(

"app.media.door_unlock"

)).

width

(

60

).

height

(

60

).

position

({

x

:

640

,

y

:

600

})

Image

(

$r

(

"app.media.door_unlock"

)).

width

(

60

).

height

(

60

).

position

({

x

:

340

,

y

:

920

})

}

.

backgroundColor

(

Color

.

Black

)

.

width

(

"100%"

)

.

height

(

"100%"

)

}

}

}

效果演示:

image-20220706085446034

电池页

@

Entry

@

Component

export

default

struct

Battery

{

//电池页

build

() {

Column

() {

Stack

() {

Image

(

$r

(

"app.media.Car"

))

.

width

(

"100%"

)

.

height

(

"80%"

)

.

objectFit

(

ImageFit

.

Contain

)

.

margin

({

left

:

20

,

top

:

150

,

bottom

:

300

})

Text

(

"220 mi"

).

fontColor

(

Color

.

White

).

fontWeight

(

FontWeight

.

Bold

).

fontSize

(

79

).

position

({

x

:

260

,

y

:

20

})

Text

(

"62 %"

).

fontColor

(

Color

.

White

).

fontWeight

(

FontWeight

.

Bold

).

fontSize

(

60

).

position

({

x

:

320

,

y

:

90

})

Text

(

"22 mi /hr"

).

fontColor

(

Color

.

White

).

fontWeight

(

FontWeight

.

Bold

).

fontSize

(

45

).

position

({

x

:

20

,

y

:

1000

})

Text

(

"232 v"

).

fontColor

(

Color

.

White

).

fontWeight

(

FontWeight

.

Bold

).

fontSize

(

45

).

position

({

x

:

550

,

y

:

1000

})

}

.

backgroundColor

(

Color

.

Black

)

.

width

(

"100%"

)

.

height

(

"100%"

)

}

}

}

效果演示:

image-20220706085508024

空调页

@

Entry

@

Component

export

default

struct

Temp

{

//空调页

build

() {

Column

() {

Stack

() {

Image

(

$r

(

"app.media.Car"

))

.

width

(

"100%"

)

.

height

(

"100%"

)

.

objectFit

(

ImageFit

.

Contain

)

.

position

({

x

:

268

,

y

:

90

})

.

margin

({

left

:

20

})

Image

(

$r

(

"app.media.Hot_glow_4"

))

.

width

(

"90%"

)

.

height

(

"90%"

)

.

objectFit

(

ImageFit

.

Contain

)

.

position

({

x

:

220

,

y

:

90

})

.

margin

({

left

:

20

})

Text

(

"29"

+

"\u2103"

,).

fontSize

(

90

).

fontColor

(

Color

.

Orange

).

position

({

x

:

90

,

y

:

400

})

Image

(

$r

(

"app.media.arrow_drop_up"

))

.

width

(

60

)

.

height

(

60

)

.

position

({

x

:

120

,

y

:

360

})

Image

(

$r

(

"app.media.arrow_drop_down"

))

.

width

(

60

)

.

height

(

60

)

.

position

({

x

:

120

,

y

:

480

})

Image

(

$r

(

"app.media.cool"

)).

width

(

60

).

height

(

60

).

position

({

x

:

20

,

y

:

40

})

Image

(

$r

(

"app.media.heating"

))

.

width

(

60

)

.

height

(

60

)

.

position

({

x

:

80

,

y

:

90

})

.

borderRadius

(

7

)

.

margin

({

right

:

40

})

Column

() {

Text

(

"当前温度"

).

fontSize

(

32

).

fontColor

(

Color

.

White

).

margin

({

bottom

:

20

})

Row

({

space

:

30

}) {

Column

() {

Text

(

"里面"

).

fontSize

(

32

).

fontColor

(

Color

.

Orange

)

Text

(

"20"

+

"\u2103"

,).

fontSize

(

32

).

fontColor

(

Color

.

White

)

}

Column

() {

Text

(

"外边"

).

fontSize

(

32

).

fontColor

(

Color

.

Yellow

)

Text

(

"35"

+

"\u2103"

,).

fontSize

(

32

).

fontColor

(

Color

.

White

)

}

}

}.

position

({

x

:

20

,

y

:

800

})

}

.

backgroundColor

(

Color

.

Black

)

.

offset

({

y

:

-

20

})

.

width

(

"100%"

)

.

height

(

"100%"

)

}

}

}

效果演示:

image-20220706085527772

轮胎页

import

{

TyrePsiCard

}

from

'./tyre_psi_card'

@

Entry

@

Component

export

default

struct

Tyre

{

//轮胎页

build

() {

Column

() {

Stack

() {

Image

(

$r

(

"app.media.Car"

))

.

width

(

"100%"

)

.

height

(

"80%"

)

.

objectFit

(

ImageFit

.

Contain

)

.

margin

({

left

:

20

})

Image

(

$r

(

"app.media.FL_Tyre"

))

.

width

(

"10%"

)

.

height

(

"10%"

)

.

objectFit

(

ImageFit

.

Contain

)

.

position

({

x

:

180

,

y

:

700

})

Image

(

$r

(

"app.media.FL_Tyre"

))

.

width

(

"10%"

)

.

height

(

"10%"

)

.

objectFit

(

ImageFit

.

Contain

)

.

position

({

x

:

500

,

y

:

700

})

Image

(

$r

(

"app.media.FL_Tyre"

))

.

width

(

"10%"

)

.

height

(

"10%"

)

.

objectFit

(

ImageFit

.

Contain

)

.

position

({

x

:

500

,

y

:

260

})

Image

(

$r

(

"app.media.FL_Tyre"

))

.

width

(

"10%"

)

.

height

(

"10%"

)

.

objectFit

(

ImageFit

.

Contain

)

.

position

({

x

:

180

,

y

:

260

})

TyrePsiCard

({

x

:

60

,

y

:

60

,

boardColor

:

Color

.

Blue

})

TyrePsiCard

({

x

:

380

,

y

:

60

,

boardColor

:

Color

.

Blue

})

TyrePsiCard

({

x

:

60

,

y

:

500

,

boardColor

:

Color

.

Blue

,

isBottomTwoTyre

:

false

})

TyrePsiCard

({

x

:

380

,

y

:

500

,

isBottomTwoTyre

:

false

})

}

.

backgroundColor

(

Color

.

Black

)

.

width

(

"100%"

)

.

height

(

"100%"

)

}

}

}

效果演示:

image-20220706085547727

轮胎参数

/**

* 轮胎详细信息

*/

@

Entry

@

Component

export

struct

TyrePsiCard

{

private

text

:

string

=

''

private

x

:

number

=

0

private

y

:

number

=

0

private

boardColor

:

Color

=

Color

.

Red

private

isBottomTwoTyre

:

boolean

=

true

;

build

() {

Column

() {

if

(

this

.

isBottomTwoTyre

) {

Text

(

"23.6psi"

,).

fontSize

(

60

)

.

fontColor

(

Color

.

White

).

margin

({

right

:

60

})

Text

(

"56.0\u2103"

).

fontSize

(

36

)

.

fontColor

(

Color

.

Orange

).

margin

({

bottom

:

70

})

Text

(

"Low"

).

fontSize

(

60

)

.

fontColor

(

Color

.

White

)

Text

(

"Pressure"

).

fontSize

(

36

)

.

fontColor

(

Color

.

White

)

}

else

{

Text

(

"Low"

).

fontSize

(

60

).

margin

({

right

:

60

})

.

fontColor

(

Color

.

White

)

Text

(

"Pressure"

).

fontSize

(

36

)

.

fontColor

(

Color

.

White

).

margin

({

bottom

:

70

})

Text

(

"23.6psi"

,).

fontSize

(

60

)

.

fontColor

(

Color

.

White

)

Text

(

"56.0\u2103"

).

fontSize

(

36

)

.

fontColor

(

Color

.

Orange

)

}

}

.

border

({

width

:

3

,

color

:

this

.

boardColor

})

.

width

(

280

)

.

justifyContent

(

FlexAlign

.

Start

)

.

alignItems

(

HorizontalAlign

.

Start

)

// .padding({ left: 10, bottom: 20, top: 20 })

.

position

({

x

:

this

.

x

,

y

:

this

.

y

})

}

}

效果演示:

image-20220706085603380

恭喜你

在本文中,通过实现智联汽车App示例,我主要为大家讲解了如下ArkUI(基于TS扩展的类Web开发范式)组件

容器组件

Column

Row

Stack

基础组件

Text

TextInput

Button

Image

Navigation

通用

边框设置

尺寸设置

点击控制

布局约束

背景设置

点击事件

TS语法糖

希望通过本教程,各位开发者可以对以上基础组件具有更深刻的认识。

后面的计划:

一键启动

硬件交互

动画交互

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • 开发板
    +关注

    关注

    25

    文章

    4422

    浏览量

    93938
  • 智能汽车
    +关注

    关注

    30

    文章

    2612

    浏览量

    106385
  • 智慧出行
    +关注

    关注

    0

    文章

    89

    浏览量

    7427
  • HarmonyOS
    +关注

    关注

    79

    文章

    1807

    浏览量

    29255
  • OpenHarmony
    +关注

    关注

    23

    文章

    3261

    浏览量

    15159
  • 鸿蒙智联
    +关注

    关注

    0

    文章

    28

    浏览量

    377
收藏 人收藏

    评论

    相关推荐

    如何实现DAYU200开发板使能Panfrost驱动并且支持OpenHarmony

    如何实现DAYU200开发板使能Panfrost驱动并且支持OpenHarmony呢?
    发表于 03-02 10:26

    基于润和DAYU200开发套件的OpenHarmony分布式音乐播放器

    :参考DevEco Studio(OpenHarmony)使用指南搭建OpenHarmony应用开发环境、并导入本工程进行编译、运行。运行结果截图:【分布式流转体验】硬件准备:准备两台润和DA
    发表于 03-14 09:07

    【每日精选】开源鸿蒙系统DAYU200教程及Tina Wi-Fi模组移植

    ] 支持开源鸿蒙系统 DAYU200 镜像烧录教程【问答】请问下HiHope_DAYU200 如何搭建编译开发环境?[经验]作品分享-基于RT-Thread系统和N32G457
    发表于 03-15 15:32

    OpenHarmony 3.1 Release初体验 润和DAYU200开发套件

    固件下载手里刚好有一块DAYU200开发板,官方刚好有发布编译的固件,下载链接:https://gitee.com/openharmony/docs/blob/master/zh-cn
    发表于 03-31 18:10

    润和DAYU200领跑OpenHarmony富设备产业化!

    等)提供性能优越、稳定可靠的智能硬件底座,在国产化替代方面具有标杆意义。润和大禹系列HH-SCDAYU200是润和软件推出的在社区内首款支持OpenHarmony富设备的开发板,基于瑞芯微64位处
    发表于 04-21 20:06

    【润和软件DAYU200开发板体验】润和软件DAYU200开发板开箱篇

    开发板靓图: 首先谈谈润和软件DAYU名字由来,DAYU 即是“大禹”,大禹治水精神是中华民族精神的源头和象征。润和软件新款OpenHarmony高性能
    发表于 09-21 20:25

    【润和软件DAYU200开发板体验】终于Helloworld!!

    hello world!是开发者跟开发板的第一个交互,今天在DAYU200上实现了。用了差不多两天的学习,入门的时间还算好吧。如何实现,很多的教程了,我这菜鸟就不做讲解,大家可以按我下面的教程慢慢
    发表于 09-23 21:54

    【润和软件DAYU200开发板体验】移植speexdsp到OpenHarmony标准系统功能演示

    该视频已经同步上传至硬声app,账号名称离北况归移植speexdsp到OpenHarmony标准系统系列文章:【润和软件DAYU200开发板体验】移植speexdsp到OpenHarmony
    发表于 11-06 22:35

    OpenHarmony 润和DAYU200开发板,全新未开封(出)

    润和DAYU200开发板,全新未使用,多买了一块,现在想出,有朋友要吗
    发表于 09-04 15:41

    DAYU200开发版升级openHarmony3.1 release版本

    今天收到了来自润和的DAYU200开发板,我们在开机之后,查看关于手机,这一栏,发现openharmony的版本是3.1的beta版,于是我们先做个升级,然后进行更多的体验,
    的头像 发表于 04-16 09:37 1724次阅读
    <b class='flag-5'>DAYU200</b><b class='flag-5'>开发</b>版升级<b class='flag-5'>openHarmony</b>3.1 release版本

    润和软件开发板DAYU200 支持富设备开发 OpenHarmony开发者都选它

      智能硬件开放生态已经进入富设备产业化的时代,作为OpenHarmony标准系统的先驱者,润和软件推出了首款支持OpenHarmony富设备的开发板DAYU200
    的头像 发表于 10-09 17:48 2279次阅读

    【润和软件DAYU200开发板体验】润和软件DAYU200开发板开箱篇

    创新为内涵的大禹治水精神,寓意着DAYU秉承OpenHarmony“以开发者为本”的开源治理宗旨和积极担当国产化历史使命的责任定位。      润和软件DAYU200
    的头像 发表于 10-12 11:38 3777次阅读
    【润和软件<b class='flag-5'>DAYU200</b><b class='flag-5'>开发板</b>体验】润和软件<b class='flag-5'>DAYU200</b><b class='flag-5'>开发板</b>开箱篇

    OpenHarmony知识赋能No.29-DAYU200分布式应用开发

      5月4日      基于OpenHarmony3.2Release最新版本,详细讲述基于润开鸿DAYU200北向应用开发,包括开发板个绍、固件升级,到应用
    的头像 发表于 05-04 09:57 627次阅读
    <b class='flag-5'>OpenHarmony</b>知识赋能No.29-<b class='flag-5'>DAYU200</b>分布式应用<b class='flag-5'>开发</b>

    喜大普奔!DAYU200能打电话了—OpenHarmony 3.1新特性!

    扫码:淘宝生态市场DAYU200开发套件润和大禹系列HH-SCDAYU200是润和软件推出的社区内首款支持OpenHarmony富设备的开发板
    的头像 发表于 04-22 11:43 773次阅读
    喜大普奔!<b class='flag-5'>DAYU200</b>能打电话了—<b class='flag-5'>OpenHarmony</b> 3.1新特性!

    润和软件DAYU200OpenHarmony赋能之旅

    2021年,润和软件推出了OpenHarmony高性能设备平台大禹系列,其中DAYU200作为首款支持OpenHarmony富设备的开发板,是广大
    的头像 发表于 11-18 09:49 960次阅读
    润和软件<b class='flag-5'>DAYU200</b>的<b class='flag-5'>OpenHarmony</b>赋能之旅