HarmonyOS之时钟FA卡片开发样例实践

想了解更多内容,请访问:

为玄武等地区用户提供了全套网页设计制作服务,及玄武网站建设行业解决方案。主营业务为成都网站设计、成都做网站、玄武网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

和华为官方合作共建的鸿蒙技术社区

https://harmonyos.

时钟FA卡片开发样例

介绍

服务卡片是FA的一种主要信息呈现形式,开发者可以在卡片中展示用户最关心的FA数据,并可以通过点击卡片内容直接打开FA。例如,天气类FA,可以在服务卡片中展示当前的基本天气信息,点击卡片启动天气FA,展示详细的天气数据。

同时,服务卡片支持不同的规格尺寸,开发者可以根据展示的不同内容和布局效果,选用不同的卡片尺寸,支持的尺寸包括:1x2、2x2、2x4 和 4x4。

知识点:

1.对象关系型数据库的使用,如何查询、创建卡片、删除卡片

2.如何更新卡片数据

搭建环境

安装DevEco Studio,详情请参考DevEco Studio下载。

设置DevEco Studio开发环境,DevEco Studio开发环境需要依赖于网络环境,需要连接上网络才能确保工具的正常使用,可以根据如下两种情况来配置开发环境:

如果可以直接访问Internet,只需进行下载HarmonyOS SDK操作。

如果网络不能直接访问Internet,需要通过代理服务器才可以访问,请参考配置开发环境。

代码结构解读

 
 
 
 
  1. ├─config.json #项目配置文件
  2. ├─java
  3. │  └─com
  4. │      └─huawei
  5. │          └─learnharmony
  6. │              │  MainAbility.java
  7. │              │  MyApplication.java
  8. │              │  TimerAbility.java  #用于定时更新卡片的服务
  9. │              │
  10. │              ├─database
  11. │              │      Form.java #卡片表,extends OrmObject 
  12. │              │      FormDatabase.java #卡片数据库,extends OrmDatabase
  13. │              │
  14. │              ├─slice
  15. │              │      ClockCardSlice.java #时钟卡片主能力页,extends AbilitySlice
  16. │              │
  17. │              └─utils
  18. │                      ComponentProviderUtils.java #ComponentProvider工具类
  19. │                      DatabaseUtils.java #数据库工具类,实现Form的添加和删除
  20. │                      DateUtils.java  #日期工具类
  21. │                      LogUtils.java #日志工具类
  22. └─resources
  23.     └─base
  24.         ├─element
  25.         │      string.json
  26.         │
  27.         ├─graphic
  28.         │      background_ability_main.xml
  29.         │      background_week.xml
  30.         │
  31.         ├─layout
  32.         │      ability_main.xml #主能力页,默认
  33.         │      form_image_with_info_date_card_1_2.xml #1x2规格的卡片
  34.         │      form_image_with_info_date_card_2_2.xml #2x2规格的卡片
  35.         │      form_image_with_info_date_card_2_4.xml #2x4规格的卡片
  36.         │
  37.         └─media
  38.                 form_image_with_info_datecard_default_image_2.png
  39.                 form_image_with_info_form_card_default_image_2.png
  40.                 icon.png

卡片布局

form_image_with_info_date_card_1_2.xml #1x2规格的卡片

 
 
 
 
  1.     xmlns:ohos="http://schemas.huawei.com/res/ohos"
  2.     ohos:height="match_parent"
  3.     ohos:width="match_parent"
  4.     ohos:background_element="#FFFFFFFF"
  5.     ohos:remote="true">
  6.     
  7.         ohos:height="match_content"
  8.         ohos:width="match_parent"
  9.         ohos:orientation="vertical"
  10.         ohos:vertical_center="true"
  11.         >
  12.         
  13.             ohos:id="$+id:date"
  14.             ohos:height="match_content"
  15.             ohos:width="match_content"
  16.             ohos:center_in_parent="true"
  17.             ohos:text="2021-03-24"
  18.             ohos:text_alignment="vertical_center"
  19.             ohos:text_font="sans-serif-medium"
  20.             ohos:text_size="20fp"
  21.             />
  22.     

form_image_with_info_date_card_2_2.xml #2x2规格的卡片

 
 
 
 
  1.     xmlns:ohos="http://schemas.huawei.com/res/ohos"
  2.     ohos:height="match_parent"
  3.     ohos:width="match_parent"
  4.     ohos:background_element="#FFFFFFFF"
  5.     ohos:remote="true">
  6.     
  7.         ohos:height="match_content"
  8.         ohos:width="match_parent"
  9.         ohos:orientation="vertical"
  10.         >
  11.         
  12.             ohos:id="$+id:date"
  13.             ohos:height="match_content"
  14.             ohos:width="match_parent"
  15.             ohos:text_alignment="horizontal_center"
  16.             ohos:margin="12fp"
  17.             ohos:text="2021-03-24"
  18.             ohos:text_font="sans-serif-medium"
  19.             ohos:text_size="10fp"
  20.             />
  21.     
  22.     
  23.         ohos:id="$+id:title"
  24.         ohos:height="match_content"
  25.         ohos:width="match_parent"
  26.         ohos:alignment="horizontal_center"
  27.         ohos:orientation="horizontal"
  28.         ohos:top_margin="35fp"
  29.         >
  30.         
  31.             ohos:height="match_content"
  32.             ohos:width="match_content"
  33.             ohos:margin="8vp"
  34.             ohos:text="HOUR"
  35.             ohos:text_size="10fp"
  36.             />
  37.         
  38.             ohos:height="match_content"
  39.             ohos:width="match_content"
  40.             ohos:margin="8vp"
  41.             ohos:text="MIN"
  42.             ohos:text_size="10fp"
  43.             />
  44.         
  45.             ohos:height="match_content"
  46.             ohos:width="match_content"
  47.             ohos:margin="8vp"
  48.             ohos:text="SEC"
  49.             ohos:text_size="10fp"
  50.             />
  51.     
  52.     
  53.         ohos:id="$+id:time"
  54.         ohos:height="match_content"
  55.         ohos:width="match_parent"
  56.         ohos:alignment="horizontal_center"
  57.         ohos:below="$id:title"
  58.         ohos:orientation="horizontal"
  59.         ohos:top_margin="0.5fp"
  60.         >
  61.         
  62.             ohos:id="$+id:hour"
  63.             ohos:height="match_content"
  64.             ohos:width="match_content"
  65.             ohos:left_margin="10vp"
  66.             ohos:right_margin="5vp"
  67.             ohos:text="00"
  68.             ohos:text_font="HwChinese-medium"
  69.             ohos:text_size="20fp"
  70.             ohos:top_margin="2vp"
  71.             />
  72.         
  73.             ohos:height="match_content"
  74.             ohos:width="match_content"
  75.             ohos:text=":"
  76.             ohos:text_font="bold"
  77.             ohos:text_size="20fp"
  78.             ohos:top_margin="2vp"
  79.             />
  80.         
  81.             ohos:id="$+id:min"
  82.             ohos:height="match_content"
  83.             ohos:width="match_content"
  84.             ohos:left_margin="5vp"
  85.             ohos:right_margin="5vp"
  86.             ohos:text="00"
  87.             ohos:text_font="HwChinese-medium"
  88.             ohos:text_size="20fp"
  89.             ohos:top_margin="2vp"
  90.             />
  91.         
  92.             ohos:height="match_content"
  93.             ohos:width="match_content"
  94.             ohos:text=":"
  95.             ohos:text_font="bold"
  96.             ohos:text_size="20fp"
  97.             ohos:top_margin="2vp"
  98.             />
  99.         
  100.             ohos:id="$+id:sec"
  101.             ohos:height="match_content"
  102.             ohos:width="match_content"
  103.             ohos:left_margin="5vp"
  104.             ohos:right_margin="10vp"
  105.             ohos:text="00"
  106.             ohos:text_font="HwChinese-medium"
  107.             ohos:text_size="20fp"
  108.             ohos:top_margin="2vp"
  109.             />
  110.     
  111.     
  112.         ohos:height="match_content"
  113.         ohos:width="match_parent"
  114.         ohos:alignment="center"
  115.         ohos:below="$id:time"
  116.         ohos:margin="16fp"
  117.         ohos:orientation="horizontal"
  118.         >
  119.         
  120.             ohos:id="$+id:sun"
  121.             ohos:height="match_content"
  122.             ohos:width="match_content"
  123.             ohos:text="日"
  124.             ohos:text_color="#C0C0C0"
  125.             ohos:text_size="10fp"
  126.             ohos:weight="1"
  127.             />
  128.         
  129.             ohos:id="$+id:mon"
  130.             ohos:height="match_content"
  131.             ohos:width="match_content"
  132.             ohos:text="一"
  133.             ohos:text_color="#C0C0C0"
  134.             ohos:text_size="10fp"
  135.             ohos:weight="1"
  136.             />
  137.         
  138.             ohos:id="$+id:tue"
  139.             ohos:height="match_content"
  140.             ohos:width="match_content"
  141.             ohos:text="二"
  142.             ohos:text_color="#C0C0C0"
  143.             ohos:text_size="10fp"
  144.             ohos:weight="1"
  145.             />
  146.         
  147.             ohos:id="$+id:wed"
  148.             ohos:height="match_content"
  149.             ohos:width="match_content"
  150.             ohos:text="三"
  151.             ohos:text_color="#C0C0C0"
  152.             ohos:text_size="10fp"
  153.             ohos:weight="1"
  154.             />
  155.         
  156.             ohos:id="$+id:thu"
  157.             ohos:height="match_content"
  158.             ohos:width="match_content"
  159.             ohos:text="四"
  160.             ohos:text_color="#C0C0C0"
  161.             ohos:text_size="10fp"
  162.             ohos:weight="1"
  163.             />
  164.         
  165.             ohos:id="$+id:fri"
  166.             ohos:height="match_content"
  167.             ohos:width="match_content"
  168.             ohos:text="五"
  169.             ohos:text_color="#C0C0C0"
  170.             ohos:text_size="10fp"
  171.             ohos:weight="1"
  172.             />
  173.         
  174.             ohos:id="$+id:sat"
  175.             ohos:height="match_content"
  176.             ohos:width="match_content"
  177.             ohos:text="六"
  178.             ohos:text_color="#C0C0C0"
  179.             ohos:text_size="10fp"
  180.             ohos:weight="1"
  181.             />
  182.     

form_image_with_info_date_card_2_4.xml #2x4规格的卡片

 
 
 
 
  1.     xmlns:ohos="http://schemas.huawei.com/res/ohos"
  2.     ohos:height="match_parent"
  3.     ohos:width="match_parent"
  4.     ohos:background_element="#FFFFFFFF"
  5.     ohos:remote="true">
  6.     
  7.         ohos:height="match_content"
  8.         ohos:width="match_parent"
  9.         ohos:orientation="horizontal"
  10.         >
  11.         
  12.             ohos:id="$+id:date"
  13.             ohos:height="match_content"
  14.             ohos:width="match_content"
  15.             ohos:align_parent_left="true"
  16.             ohos:margin="10fp"
  17.             ohos:text="2021-03-24"
  18.             ohos:text_font="sans-serif-medium"
  19.             ohos:text_size="20fp"
  20.             />
  21.         
  22.             ohos:height="match_content"
  23.             ohos:width="match_content"
  24.             ohos:align_parent_right="true"
  25.             ohos:orientation="horizontal"
  26.             ohos:top_margin="10fp"
  27.             >
  28.             
  29.                 ohos:id="$+id:sun"
  30.                 ohos:height="match_content"
  31.                 ohos:width="match_content"
  32.                 ohos:text="日"
  33.                 ohos:text_color="#C0C0C0"
  34.                 ohos:text_size="20fp"
  35.                 ohos:weight="1"
  36.                 />
  37.             
  38.                 ohos:id="$+id:mon"
  39.                 ohos:height="match_content"
  40.                 ohos:width="match_content"
  41.                 ohos:text="一"
  42.                 ohos:text_color="#C0C0C0"
  43.                 ohos:text_size="20fp"
  44.                 ohos:weight="1"
  45.                 />
  46.             
  47.                 ohos:id="$+id:tue"
  48.                 ohos:height="match_content"
  49.                 ohos:width="match_content"
  50.                 ohos:text="二"
  51.                 ohos:text_color="#C0C0C0"
  52.                 ohos:text_size="20fp"
  53.                 ohos:weight="1"
  54.                 />
  55.             
  56.                 ohos:id="$+id:wed"
  57.                 ohos:height="match_content"
  58.                 ohos:width="match_content"
  59.                 ohos:text="三"
  60.                 ohos:text_color="#C0C0C0"
  61.                 ohos:text_size="20fp"
  62.                 ohos:weight="1"
  63.                 />
  64.             
  65.                 ohos:id="$+id:thu"
  66.                 ohos:height="match_content"
  67.                 ohos:width="match_content"
  68.                 ohos:text="四"
  69.                 ohos:text_color="#C0C0C0"
  70.                 ohos:text_size="20fp"
  71.                 ohos:weight="1"
  72.                 />
  73.             
  74.                 ohos:id="$+id:fri"
  75.                 ohos:height="match_content"
  76.                 ohos:width="match_content"
  77.                 ohos:text="五"
  78.                 ohos:text_color="#C0C0C0"
  79.                 ohos:text_size="20fp"
  80.                 ohos:weight="1"
  81.                 />
  82.             
  83.                 ohos:id="$+id:sat"
  84.                 ohos:height="match_content"
  85.                 ohos:width="match_content"
  86.                 ohos:text="六"
  87.                 ohos:text_color="#C0C0C0"
  88.                 ohos:text_size="20fp"
  89.                 ohos:weight="1"
  90.                 ohos:right_margin="10fp"
  91.                 />
  92.         
  93.     
  94.     
  95.         ohos:id="$+id:title"
  96.         ohos:height="match_content"
  97.         ohos:width="match_parent"
  98.         ohos:alignment="horizontal_center"
  99.         ohos:orientation="horizontal"
  100.         ohos:top_margin="35fp"
  101.         >
  102.         
  103.             ohos:height="match_content"
  104.             ohos:width="match_content"
  105.             ohos:top_margin="20vp"
  106.             ohos:left_margin="20vp"
  107.             ohos:right_margin="20vp"
  108.             ohos:text="HOUR"
  109.             ohos:text_size="20fp"
  110.             />
  111.         
  112.             ohos:height="match_content"
  113.             ohos:width="match_content"
  114.             ohos:top_margin="20vp"
  115.             ohos:left_margin="20vp"
  116.             ohos:right_margin="20vp"
  117.             ohos:text="MIN"
  118.             ohos:text_size="20fp"
  119.             />
  120.         
  121.             ohos:height="match_content"
  122.             ohos:width="match_content"
  123.             ohos:top_margin="20vp"
  124.             ohos:left_margin="20vp"
  125.             ohos:right_margin="20vp"
  126.             ohos:text="SEC"
  127.             ohos:text_size="20fp"
  128.             />
  129.     
  130.     
  131.         ohos:id="$+id:time"
  132.         ohos:height="match_content"
  133.         ohos:width="match_parent"
  134.         ohos:alignment="horizontal_center"
  135.         ohos:below="$id:title"
  136.         ohos:orientation="horizontal"
  137.         >
  138.         
  139.             ohos:id="$+id:hour"
  140.             ohos:height="match_content"
  141.             ohos:width="match_content"
  142.             ohos:left_margin="20vp"
  143.             ohos:right_margin="10vp"
  144.             ohos:text="00"
  145.             ohos:text_font="HwChinese-medium"
  146.             ohos:text_size="40fp"
  147.             ohos:top_margin="2vp"
  148.             />
  149.         
  150.             ohos:height="match_content"
  151.             ohos:width="match_content"
  152.             ohos:text=":"
  153.             ohos:text_font="bold"
  154.             ohos:text_size="40fp"
  155.             ohos:top_margin="2vp"
  156.             />
  157.         
  158.             ohos:id="$+id:min"
  159.             ohos:height="match_content"
  160.             ohos:width="match_content"
  161.             ohos:left_margin="10vp"
  162.             ohos:right_margin="10vp"
  163.             ohos:text="00"
  164.             ohos:text_font="HwChinese-medium"
  165.             ohos:text_size="40fp"
  166.             ohos:top_margin="2vp"
  167.             />
  168.         
  169.             ohos:height="match_content"
  170.             ohos:width="match_content"
  171.             ohos:text=":"
  172.             ohos:text_font="bold"  当前标题:HarmonyOS之时钟FA卡片开发样例实践
    地址分享:http://www.shufengxianlan.com/qtweb/news27/528227.html

    网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

    广告

    声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联