HarmonyOS NEXT 实战之元服务:静态案例效果--- 手机一键加速、手机垃圾清理

news/2024/12/26 21:31:46 标签: harmonyos, 华为

背景:

前几篇学习了元服务,后面几期就让我们开发简单的元服务吧,里面丰富的内容大家自己加,本期案例 仅供参考

先上本期效果图 ,里面图片自行替换

在这里插入图片描述
在这里插入图片描述

效果图1完整代码案例如下:

import { authentication } from '@kit.AccountKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

@Entry
@Component
struct Index {
  @State message: string = 'Hello World';

  build() {
    Column() {

      Text($r('app.string.EntryAbility_label')).fontWeight(FontWeight.Bold).fontSize(29).fontColor("#222222").margin({ top: 20, bottom: 20 })

      Row() {
        Stack() {
          Progress({
            value: 6800,
            total: 10000,
            type: ProgressType.Ring
          })
            .width(84)
            .color("#1B80FA")
            .style({ strokeWidth: 10 })
            .backgroundColor('#EDF3FD')

          Text('68%').fontSize(14).fontColor("#222222").fontWeight(FontWeight.Bold)

        }.margin({ left: 16 })

        Column({ space: 6 }) {
          Text('请放心使用').fontColor('#383838').fontSize(25)
          Text('本周自动清理 1.13 GB').fontColor('#9E9E9E').fontSize(15)
          Text('已使用 52.91 GB/256 GB >').fontColor('#9E9E9E').fontSize(15)
        }.alignItems(HorizontalAlign.Start).margin({ left: 8 })

      }.width('100%').height(150).backgroundColor(Color.White)
      .borderRadius(10)

      Text('推荐压缩').fontSize(24).fontColor("#222222").margin({ top: 20, bottom: 20 })
      Row() {
        Text().backgroundColor('#EB6F20').width(40).height(40).borderRadius(20)

        Column({ space: 6 }) {
          Text('113 组文件可压缩').fontColor('#383838').fontSize(20)
          Text('491MB').fontColor('#A5A5A5').fontSize(15)
        }.alignItems(HorizontalAlign.Start).margin({ left: 8 }).layoutWeight(1)

        Button("无损压缩").height(40).fontSize(16).margin({ left: 4 })
      }
      .width('100%')
      .height(100)
      .backgroundColor(Color.White)
      .borderRadius(10)
      .padding(16)


      Row() {
        Text().backgroundColor('#F8A52B').width(40).height(40).borderRadius(20)

        Column({ space: 6 }) {
          Text('垃圾文件').fontColor('#383838').fontSize(20)
          Text('2.36 GB').fontColor('#A5A5A5').fontSize(15)
        }.alignItems(HorizontalAlign.Start).margin({ left: 8 }).layoutWeight(1)

        Button("立即清理").height(40).fontSize(16).margin({ left: 4 }).backgroundColor('#F8A52B')
      }
      .width('100%')
      .height(80)
      .backgroundColor(Color.White)
      .borderRadius(10)
      .padding(16)
      .margin({ top: 16 })

    }
    .height('100%')
    .width('100%')
    .padding(16)
    .backgroundColor('#F2F3F5')
    .margin({ top: 60 })
    .alignItems(HorizontalAlign.Start)
  }

  aboutToAppear() {
    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
    this.loginWithHuaweiID();
  }

  /**
   * Sample code for using HUAWEI ID to log in to atomic service.
   * According to the Atomic Service Review Guide, when a atomic service has an account system,
   * the option to log in with a HUAWEI ID must be provided.
   * The following presets the atomic service to use the HUAWEI ID silent login function.
   * To enable the atomic service to log in successfully using the HUAWEI ID, please refer
   * to the HarmonyOS HUAWEI ID Access Guide to configure the client ID and fingerprint certificate.
   */
  private loginWithHuaweiID() {
    // Create a login request and set parameters
    let loginRequest = new authentication.HuaweiIDProvider().createLoginWithHuaweiIDRequest();
    // Whether to forcibly launch the HUAWEI ID login page when the user is not logged in with the HUAWEI ID
    loginRequest.forceLogin = false;
    // Execute login request
    let controller = new authentication.AuthenticationController();
    controller.executeRequest(loginRequest).then((data) => {
      let loginWithHuaweiIDResponse = data as authentication.LoginWithHuaweiIDResponse;
      let authCode = loginWithHuaweiIDResponse.data?.authorizationCode;
      // Send authCode to the backend in exchange for unionID, session

    }).catch((error: BusinessError) => {
      hilog.error(0x0000, 'testTag', 'error: %{public}s', JSON.stringify(error));
      if (error.code == authentication.AuthenticationErrorCode.ACCOUNT_NOT_LOGGED_IN) {
        // HUAWEI ID is not logged in, it is recommended to jump to the login guide page

      }
    });
  }
}

效果图2完整代码案例如下:

import { authentication } from '@kit.AccountKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

@Entry
@ComponentV2
struct Index {
  @Local c1: number = 535;
  @Local c2: number = 348;

  build() {
    Column({ space: 8 }) {
      Text($r('app.string.EntryAbility_label'))
        .fontWeight(FontWeight.Bold)
        .fontSize(29)
        .fontColor("#222222")
        .margin({ top: 20, bottom: 20 })
      Row() {
        Checkbox()
          .select(true).onChange(value => {
          console.log('xxxxxxxxxxxx' + value)
        })

        Column({ space: 6 }) {
          Text('内存垃圾').fontColor('#383838').fontSize(20)
          Text('已选2项').fontColor('#6A6A6A').fontSize(15)
        }.alignItems(HorizontalAlign.Start).margin({ left: 8 }).layoutWeight(1)

        Text('2 项 >').fontColor('#6A6A6A').fontSize(20)
      }
      .width('100%')
      .height(100)
      .backgroundColor(Color.White)
      .borderRadius(10)
      .padding(16)

      // 缓存垃圾
      // 已选 535 KB
      // 系统垃圾
      //
      // 2 项
      // 535 KB2
      // 348 KB
      Row() {
        Checkbox()
          .select(true).onChange(value => {
          this.c1 = value ? 535 : 0
        })

        Column({ space: 6 }) {
          Text('缓存垃圾').fontColor('#383838').fontSize(20)
          Text('已选 535 KB').fontColor('#6A6A6A').fontSize(15)
        }.alignItems(HorizontalAlign.Start).margin({ left: 8 }).layoutWeight(1)

        Text('535 KB').fontColor('#6A6A6A').fontSize(20)
      }
      .width('100%')
      .height(100)
      .backgroundColor(Color.White)
      .borderRadius(10)
      .padding(16)

      Row() {
        Checkbox()
          .select(true).onChange(value => {
          this.c2 = value ? 348 : 0
        })

        Column({ space: 6 }) {
          Text('系统垃圾').fontColor('#383838').fontSize(20)
          Text('已选 348 KB').fontColor('#6A6A6A').fontSize(15)
        }.alignItems(HorizontalAlign.Start).margin({ left: 8 }).layoutWeight(1)

        Text('348 KB >').fontColor('#6A6A6A').fontSize(20)
      }
      .width('100%')
      .height(100)
      .backgroundColor(Color.White)
      .borderRadius(10)
      .padding(16)


      Button(`删除(已选 ${this.c1 + this.c2} KB)`)
        .width('70%')
        .margin({ top: 40, left: 50 })
        .backgroundColor('#E7E8EA')
        .fontColor('#E65A5B')

    }
    .height('100%')
    .width('100%')
    .alignItems(HorizontalAlign.Start)
    .padding(16)
    .backgroundColor('#F2F3F5')
    .margin({ top: 50 })
  }

  aboutToAppear() {
    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
    this.loginWithHuaweiID();
  }

  /**
   * Sample code for using HUAWEI ID to log in to atomic service.
   * According to the Atomic Service Review Guide, when a atomic service has an account system,
   * the option to log in with a HUAWEI ID must be provided.
   * The following presets the atomic service to use the HUAWEI ID silent login function.
   * To enable the atomic service to log in successfully using the HUAWEI ID, please refer
   * to the HarmonyOS HUAWEI ID Access Guide to configure the client ID and fingerprint certificate.
   */
  private loginWithHuaweiID() {
    // Create a login request and set parameters
    let loginRequest = new authentication.HuaweiIDProvider().createLoginWithHuaweiIDRequest();
    // Whether to forcibly launch the HUAWEI ID login page when the user is not logged in with the HUAWEI ID
    loginRequest.forceLogin = false;
    // Execute login request
    let controller = new authentication.AuthenticationController();
    controller.executeRequest(loginRequest).then((data) => {
      let loginWithHuaweiIDResponse = data as authentication.LoginWithHuaweiIDResponse;
      let authCode = loginWithHuaweiIDResponse.data?.authorizationCode;
      // Send authCode to the backend in exchange for unionID, session

    }).catch((error: BusinessError) => {
      hilog.error(0x0000, 'testTag', 'error: %{public}s', JSON.stringify(error));
      if (error.code == authentication.AuthenticationErrorCode.ACCOUNT_NOT_LOGGED_IN) {
        // HUAWEI ID is not logged in, it is recommended to jump to the login guide page

      }
    });
  }
}

最近文章>>>>>>>>>>>

HarmonyOS NEXT实战:元服务与应用 APP 发布应用市场的详细步骤与流程

若本文对您稍有帮助,诚望您不吝点赞,多谢。

有兴趣的同学可以点击查看源码

  • gitee:https://gitee.com/jiaojiaoone/explore-harmony-next/tree/case%2Fwanandroid/
  • github:https://github.com/JasonYinH/ExploreHarmonyNext.git

http://www.niftyadmin.cn/n/5800982.html

相关文章

前端案例---自定义鼠标右键菜单

之前右击出现默认的选项菜单&#xff0c;使用evt.preventDefault()把默认的去掉&#xff0c;然后自定义右击的样式 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta http-equiv"X-UA-Compatible"…

Verilog中initial的用法

在 Verilog 语言中&#xff0c;initial 语句用于在仿真开始时执行一次性初始化操作。它是顺序执行的&#xff0c;用来描述在仿真启动时立即运行的代码块&#xff0c;通常用于赋初值、生成波形或控制信号行为。 语法 initial begin // 语句1 // 语句2 ... end特点 只…

Linux 多命令执行

‌1、顺序执行‌&#xff1a;使用分号分隔的多个命令会按照顺序依次执行&#xff0c;前一个命令执行完后&#xff0c;才会执行下一个命令。 在Linux中&#xff0c;使用分号&#xff08;;&#xff09;可以执行多个指令。‌ 分号用于分隔多个命令&#xff0c;系统会依次执行这些命…

物联网网络中的设备认证方法

论文标题&#xff1a;DEVICE AUTHENTICATION METHOD IN INTERNET OF THINGS NETWORKS&#xff08;物联网网络中的设备认证方法&#xff09; 作者信息&#xff1a; A.Ya. Davletova&#xff0c;West Ukrainian National University, 11, Lvivska Str. Ternopil, 46009, Ukraine…

HTML、CSS页面资料库

(以下代码全非本人原创&#xff0c;纯分享个人收集的其他博主的好用、有趣的东西鸭&#xff5e;)&#xff08;若侵权&#xff0c;私信&#xff0c;立删&#xff09; 1.动态自做电脑 展示效果&#xff1a; 源码&#xff1a; <!DOCTYPE html> <html lang"en&quo…

[ThinkPHP]5.0.23-Rce 1

[ThinkPHP]5.0.23-Rce 1 根据题目知道这是一个5.0.23的PHP RCE&#xff0c;话不多说直接上扫描器 检测出Payload url地址&#xff1a; ?scaptcha&test-1 Post表单参数: _method__construct&filter[]phpinfo&methodget&server[REQUEST_METHOD]1HackBar构造p…

散户应该持有哪些代币?

山寨币春天正式来临 对于散户来说&#xff0c;跟着特朗普贝莱德马斯克买就可以了&#xff0c;这轮牛市能跑赢大部分到处乱冲的人。 $aave $link $ena $ondo $crv $apt $DOGE 如何安全优惠的参与比特币&#xff1f;遇到困难参考教程:http://www.btcwbo.com/94.html **本文仅代…

代码随想录算法训练营第十一天-150.逆波兰表达式求值

队列栈 #include <iostream> #include <vector> #include <stack>class Solution { public:int evalRPN(std::vector<std::string>& tokens) {std::stack<long long> stack_number;for (auto it tokens.begin(); it ! tokens.end(); it) {…