diff --git "a/ohos/docs/05_performance/\346\200\247\350\203\275\350\260\203\344\274\230.md" "b/ohos/docs/05_performance/\346\200\247\350\203\275\350\260\203\344\274\230.md" new file mode 100644 index 0000000000000000000000000000000000000000..79648feb05dcbe4874dbbf0a4ac77e721ec827d5 --- /dev/null +++ "b/ohos/docs/05_performance/\346\200\247\350\203\275\350\260\203\344\274\230.md" @@ -0,0 +1,17 @@ +# 性能调优 + +## 图片预加载 + +请参考:[官方图片预加载文档](https://api.flutter.dev/flutter/widgets/precacheImage.html) + +## 图片加载内存优化 + +参考下列的优化策略: + +- 使用 `ListView.builder` 或 `GridView.builder` 可以确保只加载当前可见的图片,同时,根据业务情况可以把`ListView.builder` 或 `GridView.builder`中的`addAutomaticKeepAlives`属性值置为false,减少内存占用。 +- 使用 `ResizeImage `类,`ResizeImage` 类可以在图片加载时自动调整图片尺寸,减少内存占用。 +- 使用 `ImageProvider `自定义图片加载, 通过自定义 `ImageProvider`,可以完全控制图片的加载和解码过程,从而实现更高效的内存管理。也可以通过 `ResizeImage` 或自定义解码逻辑,在加载图片时调整其分辨率,从而减少内存占用。 +- 使用`cached_network_image` 第三方插件,该插件提供了图片缓存和加载功能,支持占位符、错误处理和内存优化。 +- 使用 `keframe`第三方插件,`keframe` 通过分帧渲染减少主线程的负担,从而提升应用的流畅性。 +- 使用外接纹理方式加载图片,原生平台能很好地管理大图片或大量图片的内存,及时释放不再使用的资源,减少内存占用。 +- 图片资源优化、压缩。 \ No newline at end of file diff --git "a/ohos/docs/08_FAQ/ohos\344\273\243\347\240\201\345\274\200\345\217\221\347\233\270\345\205\263\351\227\256\351\242\230.md" "b/ohos/docs/08_FAQ/ohos\344\273\243\347\240\201\345\274\200\345\217\221\347\233\270\345\205\263\351\227\256\351\242\230.md" index eaadca62023e4c326eeba7ad42807013b4a2aec3..9da54dcc71ea3c8a4eda816068538a4180e7ee4e 100644 --- "a/ohos/docs/08_FAQ/ohos\344\273\243\347\240\201\345\274\200\345\217\221\347\233\270\345\205\263\351\227\256\351\242\230.md" +++ "b/ohos/docs/08_FAQ/ohos\344\273\243\347\240\201\345\274\200\345\217\221\347\233\270\345\205\263\351\227\256\351\242\230.md" @@ -101,3 +101,37 @@ class _MyHomePageState extends State { Widget build(BuildContext context) { ... ``` + +## Flutter项目里集成华为账号一键登录 +Flutter项目里集成华为账号一键登录,如何使用一键登录的相关组件,请参考: +[demo](https://gitee.com/openharmony-sig/flutter_samples/tree/master/ohos/flutter_huawei_login ) + +## Flutter项目如何适配折叠屏 +- 手机和折叠屏折叠态,应用需要适配竖屏布局。仅部分特殊场景例如横屏游戏、长视频需要适配横屏布局。当设备尺寸比例接近1:1时,建议横竖屏使用相同或相近的布局;当设备尺寸比例差异大时,横竖屏可以使用不同的布局,从而提供更好的使用体验。 +- 对于挖孔区的适配,需要考虑核心内容或重要交互不要被挖孔区遮挡。如果被遮挡,则应进行局部内容等避让;可滚动内容无需专门避让挖孔区。要避免因为避让挖孔导致左右侧留白不一致。 +- 在多端设备上,长视频、直播、会议、通话等场景下支持画中画功能。卡片广告在宽屏设备上建议使用延伸布局和形变进行响应式适配。 +- 针对折叠屏悬停态(即用户可以将产品半折后立在桌面上),中间弯折区域难以操作且显示内容会变形,因此建议页面内容进行折痕区避让适配。建议上半屏内容由中线向上避让16vp(3毫米)、下半屏内容由中线向下避让40vp(7毫米)。这些是折叠屏设计的主要方案概述。 + +可参考: + +- [多设备响应式设计](https://developer.huawei.com/consumer/cn/doc/design-guides/responsive-design-overview-0000001746498066#section1531711918247) +- [折叠屏UX体验](https://developer.huawei.com/consumer/cn/doc/design-guides/ux-guidelines-foldable-screen-0000001807866557) +- [判断折叠状态](https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-display-V5#foldstatus10) +- [一多开发](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/foreword-V5) +- [通过windowSizeChange来监听高度](https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-V5#onwindowsizechange7) +- [折叠屏悬停](https://developer.huawei.com/consumer/cn/doc/design-guides/responsive-design-overview-0000001746498066#section127711650854) +- [FolderStack](https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-container-folderstack-V5) + +## Flutter项目启动闪退 +请开发者在crash的栈顶日志中查看是有如下相关信息,如有,可能是因为编译hap文件模式与编译出来的engine模式不匹配,如:编译hap文件release包,但用的是debug模式的engine引起。 +相关信息: + +``` +Reason:Signal:SIGABRT(SI_TKILL)............................. +........................................................ +#01 pc 000000000014710c /system/lib/ld-musl-aarch64.so.1(abort+20)............. +........................................................ +........................................................ +........................................................ +``` + diff --git a/ohos/load_native_resource_demo/.gitignore b/ohos/load_native_resource_demo/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..24476c5d1eb55824c76d8b01a3965f94abad1ef8 --- /dev/null +++ b/ohos/load_native_resource_demo/.gitignore @@ -0,0 +1,44 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +**/doc/api/ +**/ios/Flutter/.last_build_id +.dart_tool/ +.flutter-plugins +.flutter-plugins-dependencies +.packages +.pub-cache/ +.pub/ +/build/ + +# Symbolication related +app.*.symbols + +# Obfuscation related +app.*.map.json + +# Android Studio will place build artifacts here +/android/app/debug +/android/app/profile +/android/app/release diff --git a/ohos/load_native_resource_demo/README.md b/ohos/load_native_resource_demo/README.md new file mode 100644 index 0000000000000000000000000000000000000000..f1a57992d8efec163c4758dd492790d5b1295015 --- /dev/null +++ b/ohos/load_native_resource_demo/README.md @@ -0,0 +1,16 @@ +# load_native_resource_demo + +A new Flutter project. + +## Getting Started + +This project is a starting point for a Flutter application. + +A few resources to get you started if this is your first Flutter project: + +- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab) +- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook) + +For help getting started with Flutter development, view the +[online documentation](https://docs.flutter.dev/), which offers tutorials, +samples, guidance on mobile development, and a full API reference. diff --git a/ohos/load_native_resource_demo/analysis_options.yaml b/ohos/load_native_resource_demo/analysis_options.yaml new file mode 100644 index 0000000000000000000000000000000000000000..61b6c4de17c96863d24279f06b85e01b6ebbdb34 --- /dev/null +++ b/ohos/load_native_resource_demo/analysis_options.yaml @@ -0,0 +1,29 @@ +# This file configures the analyzer, which statically analyzes Dart code to +# check for errors, warnings, and lints. +# +# The issues identified by the analyzer are surfaced in the UI of Dart-enabled +# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be +# invoked from the command line by running `flutter analyze`. + +# The following line activates a set of recommended lints for Flutter apps, +# packages, and plugins designed to encourage good coding practices. +include: package:flutter_lints/flutter.yaml + +linter: + # The lint rules applied to this project can be customized in the + # section below to disable rules from the `package:flutter_lints/flutter.yaml` + # included above or to enable additional rules. A list of all available lints + # and their documentation is published at + # https://dart-lang.github.io/linter/lints/index.html. + # + # Instead of disabling a lint rule for the entire project in the + # section below, it can also be suppressed for a single line of code + # or a specific dart file by using the `// ignore: name_of_lint` and + # `// ignore_for_file: name_of_lint` syntax on the line or in the file + # producing the lint. + rules: + # avoid_print: false # Uncomment to disable the `avoid_print` rule + # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/ohos/load_native_resource_demo/lib/load_native_media_image.dart b/ohos/load_native_resource_demo/lib/load_native_media_image.dart new file mode 100644 index 0000000000000000000000000000000000000000..e70112da3e1b092c9d3560a8fa3a886f1a5e8288 --- /dev/null +++ b/ohos/load_native_resource_demo/lib/load_native_media_image.dart @@ -0,0 +1,65 @@ +import 'dart:io'; + +import 'package:flutter/material.dart'; +import 'package:image_picker/image_picker.dart'; +import 'package:permission_handler/permission_handler.dart'; + +class LoadNativeMediaImage extends StatefulWidget { + const LoadNativeMediaImage({super.key}); + + @override + _LoadNativeMediaImageState createState() => _LoadNativeMediaImageState(); +} + +class _LoadNativeMediaImageState extends State { + XFile? _image; // 用来保存选择的图片 + + // 请求权限的方法 + Future _requestPermission() async { + final status = await Permission.photos.request(); + if (status.isGranted) { + _pickImage(); // 权限被允许后,继续选择图片 + } else { + // 权限被拒绝 + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar(content: Text('权限被拒绝,无法访问相册')), + ); + } + } + + // 选择图片的方法 + Future _pickImage() async { + final ImagePicker picker = ImagePicker(); + // 从相册选择图片 + final XFile? pickedFile = await picker.pickImage(source: ImageSource.gallery); + + if (pickedFile != null) { + setState(() { + _image = pickedFile; // 更新状态,显示图片 + }); + } + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar(title: const Text('Load Photo Album Image')), + body: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + // 如果有图片,则显示图片,否则显示提示文字 + _image == null + ? const Text('请选择一张图片') + : Image.file(File(_image!.path)), + const SizedBox(height: 20), + ElevatedButton( + onPressed: _requestPermission, + child: const Text('从相册选择图片'), + ), + ], + ), + ), + ); + } +} \ No newline at end of file diff --git a/ohos/load_native_resource_demo/lib/load_native_media_video.dart b/ohos/load_native_resource_demo/lib/load_native_media_video.dart new file mode 100644 index 0000000000000000000000000000000000000000..673cf511674f09d0df15f386c7a7dfb5c2e38263 --- /dev/null +++ b/ohos/load_native_resource_demo/lib/load_native_media_video.dart @@ -0,0 +1,82 @@ +import 'dart:io'; +import 'package:flutter/material.dart'; +import 'package:image_picker/image_picker.dart'; +import 'package:permission_handler/permission_handler.dart'; +import 'package:video_player/video_player.dart'; + +class LoadNativeMediaVideo extends StatefulWidget { + const LoadNativeMediaVideo({super.key}); + + @override + _LoadNativeMediaVideoState createState() => _LoadNativeMediaVideoState(); +} + +class _LoadNativeMediaVideoState extends State { + VideoPlayerController? _controller; + XFile? _video; + + // 请求权限的方法 + Future _requestPermission() async { + final status = await Permission.photos.request(); + if (status.isGranted) { + _pickVideo(); // 权限被允许后,继续选择视频 + } else { + // 权限被拒绝 + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar(content: Text('权限被拒绝,无法访问相册')), + ); + } + } + + // 选择视频的方法 + Future _pickVideo() async { + final ImagePicker picker = ImagePicker(); + final XFile? pickedFile = await picker.pickVideo(source: ImageSource.gallery); + + if (pickedFile != null) { + setState(() { + _video = pickedFile; + }); + + // 创建视频播放器 + _controller = VideoPlayerController.file(File(_video!.path)) + ..initialize().then((_) { + setState(() {}); + _controller!.play(); // 视频初始化完成后播放 + }); + } + } + + @override + void dispose() { + super.dispose(); + _controller?.dispose(); // 释放播放器资源 + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar(title: const Text('Load Photo Album Video')), + body: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + _video == null + ? const Text('请选择一个视频') + : _controller!.value.isInitialized + ? Expanded(child: AspectRatio( + aspectRatio: _controller!.value.aspectRatio, + child: VideoPlayer(_controller!)), + ) + : const CircularProgressIndicator(), + const SizedBox(height: 20), + ElevatedButton( + onPressed: _requestPermission, + child: const Text('从相册选择视频'), + ), + ], + ), + ), + ); + } +} \ No newline at end of file diff --git a/ohos/load_native_resource_demo/lib/load_native_rawfile_image.dart b/ohos/load_native_resource_demo/lib/load_native_rawfile_image.dart new file mode 100644 index 0000000000000000000000000000000000000000..5781f26a44cc1e24741617c65abbcc371e24ec72 --- /dev/null +++ b/ohos/load_native_resource_demo/lib/load_native_rawfile_image.dart @@ -0,0 +1,28 @@ +import 'package:flutter/material.dart'; +import 'method_channel_tools.dart'; + +class LoadNativeRawfileImage extends StatelessWidget { + const LoadNativeRawfileImage({super.key}); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar(title: const Text("Native Rawfile Image Loader")), + body: Center( + child: Image.asset('landscape.jpg'), + // child: FutureBuilder( + // future: MethodChannelTools.loadImage('landscape.jpg'), // 请求图片资源 + // builder: (context, snapshot) { + // if (snapshot.connectionState == ConnectionState.waiting) { + // return const CircularProgressIndicator(); + // } else if (snapshot.hasError) { + // return Text('Error: ${snapshot.error}'); + // } else { + // return Image.asset(snapshot.data!); + // } + // }, + // ), + ), + ); + } +} diff --git a/ohos/load_native_resource_demo/lib/load_native_rawfile_video.dart b/ohos/load_native_resource_demo/lib/load_native_rawfile_video.dart new file mode 100644 index 0000000000000000000000000000000000000000..cf23eac7013e141d5d3fe40aab1c7505d70007da --- /dev/null +++ b/ohos/load_native_resource_demo/lib/load_native_rawfile_video.dart @@ -0,0 +1,69 @@ +import 'dart:io'; + +import 'package:flutter/material.dart'; +import 'package:video_player/video_player.dart'; +import 'method_channel_tools.dart'; + +class LoadNativeRawfileVideo extends StatelessWidget { + const LoadNativeRawfileVideo({super.key}); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar(title: const Text("Native Rawfile Video Loader")), + body: Center( + child: FutureBuilder( + future: MethodChannelTools.loadVideo('trailer.mp4'), // 请求视频资源 + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return const CircularProgressIndicator(); + } else if (snapshot.hasError) { + return Text('Error: ${snapshot.error}'); + } else { + return VideoPlayerScreen(videoPath: snapshot.data!); + } + }, + ), + ), + ); + } +} + +class VideoPlayerScreen extends StatefulWidget { + final String videoPath; + + const VideoPlayerScreen({super.key, required this.videoPath}); + + @override + _VideoPlayerScreenState createState() => _VideoPlayerScreenState(); +} + +class _VideoPlayerScreenState extends State { + late VideoPlayerController _controller; + + @override + void initState() { + super.initState(); + _controller = VideoPlayerController.file(File(widget.videoPath)) // 使用 file 加载本地资源 + ..initialize().then((_) { + setState(() {}); + _controller.play(); + }); + } + + @override + Widget build(BuildContext context) { + return _controller.value.isInitialized + ? AspectRatio( + aspectRatio: _controller.value.aspectRatio, + child: VideoPlayer(_controller), + ) + : const CircularProgressIndicator(); + } + + @override + void dispose() { + super.dispose(); + _controller.dispose(); + } +} \ No newline at end of file diff --git a/ohos/load_native_resource_demo/lib/main.dart b/ohos/load_native_resource_demo/lib/main.dart new file mode 100644 index 0000000000000000000000000000000000000000..d688ed4f7b14779c4fdc891cb4212ab9ddd4820a --- /dev/null +++ b/ohos/load_native_resource_demo/lib/main.dart @@ -0,0 +1,74 @@ +import 'package:flutter/material.dart'; + +import 'load_native_rawfile_image.dart'; +import 'load_native_media_image.dart'; +import 'load_native_media_video.dart'; +import 'load_native_rawfile_video.dart'; + +void main() { + runApp(const MyApp()); +} + +class MyApp extends StatelessWidget { + const MyApp({super.key}); + @override + Widget build(BuildContext context) { + return MaterialApp( + title: 'Flutter Load Native Resource Demo', + theme: ThemeData( + primarySwatch: Colors.blue, + ), + home: const MyHomePage(title: 'Flutter Load Native Resource'), + ); + } +} + +class MyHomePage extends StatefulWidget { + const MyHomePage({super.key, required this.title}); + final String title; + + @override + State createState() => _MyHomePageState(); +} + +class _MyHomePageState extends State { + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text(widget.title), + ), + body: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + TextButton(onPressed: () { + Navigator.push(context, MaterialPageRoute(builder: (context) { + return const LoadNativeRawfileImage(); + })); + }, child: const Text('LoadNativeRawfileImage')), + const SizedBox(height: 30), + TextButton(onPressed: () { + Navigator.push(context, MaterialPageRoute(builder: (context) { + return const LoadNativeRawfileVideo(); + })); + }, child: const Text('LoadNativeRawfileVideo')), + const SizedBox(height: 30), + TextButton(onPressed: () { + Navigator.push(context, MaterialPageRoute(builder: (context) { + return const LoadNativeMediaImage(); + })); + }, child: const Text('LoadNativeMediaImage')), + const SizedBox(height: 30), + TextButton(onPressed: () { + Navigator.push(context, MaterialPageRoute(builder: (context) { + return const LoadNativeMediaVideo(); + })); + }, child: const Text('LoadNativeMediaVideo')), + ], + ), + ), // This trailing comma makes auto-formatting nicer for build methods. + ); + } +} diff --git a/ohos/load_native_resource_demo/lib/method_channel_tools.dart b/ohos/load_native_resource_demo/lib/method_channel_tools.dart new file mode 100644 index 0000000000000000000000000000000000000000..b13845765716486dd8e49933a9370022cbd5deb4 --- /dev/null +++ b/ohos/load_native_resource_demo/lib/method_channel_tools.dart @@ -0,0 +1,15 @@ +import 'package:flutter/services.dart'; + +class MethodChannelTools { + static const _platform = MethodChannel("com.example.dev/loadNativeResource"); + + ///通过视频名称获取该视频在原生资源中的路径 + static Future loadVideo(String videoName) async { + try { + final String videoPath = await _platform.invokeMethod("getVideo", {"resourceName": videoName}); + return videoPath; + } on PlatformException catch (e) { + return "Failed to load video:'${e.message}'"; + } + } +} \ No newline at end of file diff --git a/ohos/load_native_resource_demo/ohos/.gitignore b/ohos/load_native_resource_demo/ohos/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..6ca13b3170eec5dd5ac5ad7f1c4dd0118845f473 --- /dev/null +++ b/ohos/load_native_resource_demo/ohos/.gitignore @@ -0,0 +1,19 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +*.har +**/BuildProfile.ets +**/oh-package-lock.json5 + +**/src/main/resources/rawfile/flutter_assets/ +**/libs/arm64-v8a/libapp.so +**/libs/arm64-v8a/libflutter.so +**/libs/arm64-v8a/libvmservice_snapshot.so diff --git a/ohos/load_native_resource_demo/ohos/AppScope/app.json5 b/ohos/load_native_resource_demo/ohos/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b07bbe553e7c1771e1164d081df397aa06594738 --- /dev/null +++ b/ohos/load_native_resource_demo/ohos/AppScope/app.json5 @@ -0,0 +1,10 @@ +{ + "app": { + "bundleName": "com.example.load_native_resource_demo", + "vendor": "example", + "versionCode": 1, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} \ No newline at end of file diff --git a/ohos/load_native_resource_demo/ohos/AppScope/resources/base/element/string.json b/ohos/load_native_resource_demo/ohos/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..5a2adef96d080ad7be6522721709b38c574defc8 --- /dev/null +++ b/ohos/load_native_resource_demo/ohos/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "load_native_resource_demo" + } + ] +} diff --git a/ohos/load_native_resource_demo/ohos/AppScope/resources/base/media/app_icon.png b/ohos/load_native_resource_demo/ohos/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ohos/load_native_resource_demo/ohos/AppScope/resources/base/media/app_icon.png differ diff --git a/ohos/load_native_resource_demo/ohos/build-profile.json5 b/ohos/load_native_resource_demo/ohos/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1d12140d202702d7c73d64f1b291fe5c45a660ce --- /dev/null +++ b/ohos/load_native_resource_demo/ohos/build-profile.json5 @@ -0,0 +1,27 @@ +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "5.0.0(12)", + "runtimeOS": "HarmonyOS" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/ohos/load_native_resource_demo/ohos/entry/.gitignore b/ohos/load_native_resource_demo/ohos/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..2795a1c5b1fe53659dd1b71d90ba0592eaf7e043 --- /dev/null +++ b/ohos/load_native_resource_demo/ohos/entry/.gitignore @@ -0,0 +1,7 @@ + +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ohos/load_native_resource_demo/ohos/entry/build-profile.json5 b/ohos/load_native_resource_demo/ohos/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..633d360fbc91a3186a23b66ab71b27e5618944cb --- /dev/null +++ b/ohos/load_native_resource_demo/ohos/entry/build-profile.json5 @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +{ + "apiType": 'stageMode', + "buildOption": { + }, + "targets": [ + { + "name": "default", + "runtimeOS": "HarmonyOS" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/ohos/load_native_resource_demo/ohos/entry/hvigorfile.ts b/ohos/load_native_resource_demo/ohos/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..894fc15c6b793f085e6c8506e43d719af658e8ff --- /dev/null +++ b/ohos/load_native_resource_demo/ohos/entry/hvigorfile.ts @@ -0,0 +1,17 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +export { hapTasks } from '@ohos/hvigor-ohos-plugin'; diff --git a/ohos/load_native_resource_demo/ohos/entry/oh-package.json5 b/ohos/load_native_resource_demo/ohos/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..33e5376790a5c19d94913fcb95631b99ae1d48fc --- /dev/null +++ b/ohos/load_native_resource_demo/ohos/entry/oh-package.json5 @@ -0,0 +1,13 @@ +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "video_player_ohos": "file:../har/video_player_ohos.har", + "image_picker_ohos": "file:../har/image_picker_ohos.har", + "permission_handler_ohos": "file:../har/permission_handler_ohos.har" + } +} \ No newline at end of file diff --git a/ohos/load_native_resource_demo/ohos/entry/src/main/ets/entryability/EntryAbility.ets b/ohos/load_native_resource_demo/ohos/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..37352913c30c3e828b0360c9e06ea297d0ab8ca8 --- /dev/null +++ b/ohos/load_native_resource_demo/ohos/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import { FlutterAbility, FlutterEngine } from '@ohos/flutter_ohos'; +import { GeneratedPluginRegistrant } from '../plugins/GeneratedPluginRegistrant'; +import { LoadNativeResourcePlugin } from '../plugins/LoadNativeResourcePlugin'; + +export default class EntryAbility extends FlutterAbility { + configureFlutterEngine(flutterEngine: FlutterEngine) { + super.configureFlutterEngine(flutterEngine) + GeneratedPluginRegistrant.registerWith(flutterEngine) + flutterEngine.getPlugins()?.add(new LoadNativeResourcePlugin()); + } +} diff --git a/ohos/load_native_resource_demo/ohos/entry/src/main/ets/pages/Index.ets b/ohos/load_native_resource_demo/ohos/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..1125f9fdd95f4310a182c1c9e3680f37f73686c9 --- /dev/null +++ b/ohos/load_native_resource_demo/ohos/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import common from '@ohos.app.ability.common'; +import { FlutterPage } from '@ohos/flutter_ohos' + +let storage = LocalStorage.getShared() +const EVENT_BACK_PRESS = 'EVENT_BACK_PRESS' + +@Entry(storage) +@Component +struct Index { + private context = getContext(this) as common.UIAbilityContext + @LocalStorageLink('viewId') viewId: string = ""; + + build() { + Column() { + FlutterPage({ viewId: this.viewId }) + } + } + + onBackPress(): boolean { + this.context.eventHub.emit(EVENT_BACK_PRESS) + return true + } +} \ No newline at end of file diff --git a/ohos/load_native_resource_demo/ohos/entry/src/main/ets/plugins/GeneratedPluginRegistrant.ets b/ohos/load_native_resource_demo/ohos/entry/src/main/ets/plugins/GeneratedPluginRegistrant.ets new file mode 100644 index 0000000000000000000000000000000000000000..18d9545f3af882f601a0ddd73c261fd9a92995db --- /dev/null +++ b/ohos/load_native_resource_demo/ohos/entry/src/main/ets/plugins/GeneratedPluginRegistrant.ets @@ -0,0 +1,30 @@ +import { FlutterEngine, Log } from '@ohos/flutter_ohos'; +import ImagePickerPlugin from 'image_picker_ohos'; +import PermissionHandlerPlugin from 'permission_handler_ohos'; +import VideoPlayerPlugin from 'video_player_ohos'; + +/** + * Generated file. Do not edit. + * This file is generated by the Flutter tool based on the + * plugins that support the Ohos platform. + */ + +const TAG = "GeneratedPluginRegistrant"; + +export class GeneratedPluginRegistrant { + + static registerWith(flutterEngine: FlutterEngine) { + try { + flutterEngine.getPlugins()?.add(new ImagePickerPlugin()); + flutterEngine.getPlugins()?.add(new PermissionHandlerPlugin()); + flutterEngine.getPlugins()?.add(new VideoPlayerPlugin()); + } catch (e) { + Log.e( + TAG, + "Tried to register plugins with FlutterEngine (" + + flutterEngine + + ") failed."); + Log.e(TAG, "Received exception while registering", e); + } + } +} diff --git a/ohos/load_native_resource_demo/ohos/entry/src/main/ets/plugins/LoadNativeResourcePlugin.ets b/ohos/load_native_resource_demo/ohos/entry/src/main/ets/plugins/LoadNativeResourcePlugin.ets new file mode 100644 index 0000000000000000000000000000000000000000..4bf16b21d101aae98c5dd86ac658467167ffaf70 --- /dev/null +++ b/ohos/load_native_resource_demo/ohos/entry/src/main/ets/plugins/LoadNativeResourcePlugin.ets @@ -0,0 +1,49 @@ +import { FlutterPlugin, Log, MethodCall, MethodChannel, MethodResult } from "@ohos/flutter_ohos"; +import { FlutterPluginBinding } from "@ohos/flutter_ohos/src/main/ets/embedding/engine/plugins/FlutterPlugin"; +import { common } from "@kit.AbilityKit"; +import { fileIo as fs } from '@kit.CoreFileKit'; +import { resourceManager } from "@kit.LocalizationKit"; + +export class LoadNativeResourcePlugin implements FlutterPlugin{ + private channel?: MethodChannel; + private context: common.Context | null = null; + + getUniqueClassName(): string { + return "LoadNativeResourcePlugin"; + } + + onAttachedToEngine(binding: FlutterPluginBinding): void { + Log.d("EntryAbility", "EntryAbility come in"); + this.context = binding.getApplicationContext(); + this.channel = new MethodChannel(binding.getBinaryMessenger(), "com.example.dev/loadNativeResource"); + this.channel.setMethodCallHandler(this) + } + + onDetachedFromEngine(binding: FlutterPluginBinding): void { + } + + onMethodCall(call: MethodCall, result: MethodResult): void { + switch (call.method) { + case 'getVideo': + const resourceMgr : resourceManager.ResourceManager = this.context!.resourceManager; + let videoName: string = call.argument('resourceName'); + resourceMgr.getRawFileContent(videoName, (err, value) => { + if (value) { + let myBuffer: ArrayBufferLike = value.buffer; + let context = getContext(this); //沙箱路径 + let filePath = context.filesDir + '/' + videoName; + let file = fs.openSync(filePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); + fs.writeSync(file.fd, myBuffer); + fs.closeSync(file); + result.success(filePath); + }else { + result.error(err.code.toString(), 'Failed to load video', err.message); + } + }); + break; + default: + result.notImplemented(); + break; + } + } +} \ No newline at end of file diff --git a/ohos/load_native_resource_demo/ohos/entry/src/main/module.json5 b/ohos/load_native_resource_demo/ohos/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fa09f0985d776d1c309d5f0f55838f6f8df4927e --- /dev/null +++ b/ohos/load_native_resource_demo/ohos/entry/src/main/module.json5 @@ -0,0 +1,73 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + {"name" : "ohos.permission.INTERNET"}, + { + "name": "ohos.permission.READ_MEDIA", + "reason": "$string:app_name", + "usedScene": { + "abilities": [ + "FormAbility" + ], + "when": "always" + } + }, + { + "name": "ohos.permission.READ_IMAGEVIDEO", + "reason": "$string:app_name", + "usedScene": { + "abilities": [ + "FormAbility" + ], + "when": "always" + } + } + ] + } +} \ No newline at end of file diff --git a/ohos/load_native_resource_demo/ohos/entry/src/main/resources/base/element/color.json b/ohos/load_native_resource_demo/ohos/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ohos/load_native_resource_demo/ohos/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ohos/load_native_resource_demo/ohos/entry/src/main/resources/base/element/string.json b/ohos/load_native_resource_demo/ohos/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..c1a620b3d4318c7c2a6e31f132d0ccf7cf7c6cc4 --- /dev/null +++ b/ohos/load_native_resource_demo/ohos/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "load_native_resource_demo" + } + ] +} \ No newline at end of file diff --git a/ohos/load_native_resource_demo/ohos/entry/src/main/resources/base/media/icon.png b/ohos/load_native_resource_demo/ohos/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ohos/load_native_resource_demo/ohos/entry/src/main/resources/base/media/icon.png differ diff --git a/ohos/load_native_resource_demo/ohos/entry/src/main/resources/base/profile/main_pages.json b/ohos/load_native_resource_demo/ohos/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/ohos/load_native_resource_demo/ohos/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/ohos/load_native_resource_demo/ohos/entry/src/main/resources/en_US/element/string.json b/ohos/load_native_resource_demo/ohos/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..c1a620b3d4318c7c2a6e31f132d0ccf7cf7c6cc4 --- /dev/null +++ b/ohos/load_native_resource_demo/ohos/entry/src/main/resources/en_US/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "load_native_resource_demo" + } + ] +} \ No newline at end of file diff --git a/ohos/load_native_resource_demo/ohos/entry/src/main/resources/rawfile/landscape.jpg b/ohos/load_native_resource_demo/ohos/entry/src/main/resources/rawfile/landscape.jpg new file mode 100644 index 0000000000000000000000000000000000000000..809a1085ed4974d3ea8c136350c7b55b10261fec Binary files /dev/null and b/ohos/load_native_resource_demo/ohos/entry/src/main/resources/rawfile/landscape.jpg differ diff --git a/ohos/load_native_resource_demo/ohos/entry/src/main/resources/rawfile/trailer.mp4 b/ohos/load_native_resource_demo/ohos/entry/src/main/resources/rawfile/trailer.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..c9620136c83da293273addaa3cb65833e3c9f195 Binary files /dev/null and b/ohos/load_native_resource_demo/ohos/entry/src/main/resources/rawfile/trailer.mp4 differ diff --git a/ohos/load_native_resource_demo/ohos/entry/src/main/resources/zh_CN/element/string.json b/ohos/load_native_resource_demo/ohos/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..0ce597097594d528eef3722473556a8c48a348ec --- /dev/null +++ b/ohos/load_native_resource_demo/ohos/entry/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "load_native_resource_demo" + } + ] +} \ No newline at end of file diff --git a/ohos/load_native_resource_demo/ohos/entry/src/ohosTest/ets/test/Ability.test.ets b/ohos/load_native_resource_demo/ohos/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..25d4c71ff3cd584f5d64f6f8c0ac864928c234c4 --- /dev/null +++ b/ohos/load_native_resource_demo/ohos/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import hilog from '@ohos.hilog'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' + +export default function abilityTest() { + describe('ActsAbilityTest', function () { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(function () { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(function () { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(function () { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(function () { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('assertContain',0, function () { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc' + let b = 'b' + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b) + expect(a).assertEqual(a) + }) + }) +} \ No newline at end of file diff --git a/ohos/load_native_resource_demo/ohos/entry/src/ohosTest/ets/test/List.test.ets b/ohos/load_native_resource_demo/ohos/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f4140030e65d20df6af30a6bf51e464dea8f8aa6 --- /dev/null +++ b/ohos/load_native_resource_demo/ohos/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import abilityTest from './Ability.test' + +export default function testsuite() { + abilityTest() +} \ No newline at end of file diff --git a/ohos/load_native_resource_demo/ohos/entry/src/ohosTest/ets/testability/TestAbility.ets b/ohos/load_native_resource_demo/ohos/entry/src/ohosTest/ets/testability/TestAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..4ca645e6013cfce8e7dbb728313cb8840c4da660 --- /dev/null +++ b/ohos/load_native_resource_demo/ohos/entry/src/ohosTest/ets/testability/TestAbility.ets @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import UIAbility from '@ohos.app.ability.UIAbility'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; +import hilog from '@ohos.hilog'; +import { Hypium } from '@ohos/hypium'; +import testsuite from '../test/List.test'; +import window from '@ohos.window'; + +export default class TestAbility extends UIAbility { + onCreate(want, launchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate'); + hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? ''); + hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:'+ JSON.stringify(launchParam) ?? ''); + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!'); + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate'); + windowStage.loadContent('testability/pages/Index', (err, data) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', + JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy'); + } + + onForeground() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground'); + } + + onBackground() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground'); + } +} \ No newline at end of file diff --git a/ohos/load_native_resource_demo/ohos/entry/src/ohosTest/ets/testability/pages/Index.ets b/ohos/load_native_resource_demo/ohos/entry/src/ohosTest/ets/testability/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..cef0447cd2f137ef82d223ead2e156808878ab90 --- /dev/null +++ b/ohos/load_native_resource_demo/ohos/entry/src/ohosTest/ets/testability/pages/Index.ets @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import hilog from '@ohos.hilog'; + +@Entry +@Component +struct Index { + aboutToAppear() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear'); + } + @State message: string = 'Hello World' + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(()=>{ + }) + } + .width('100%') + } + .height('100%') + } + } \ No newline at end of file diff --git a/ohos/load_native_resource_demo/ohos/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts b/ohos/load_native_resource_demo/ohos/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..1def08f2e9dcbfa3454a07b7a3b82b173bb90d02 --- /dev/null +++ b/ohos/load_native_resource_demo/ohos/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import hilog from '@ohos.hilog'; +import TestRunner from '@ohos.application.testRunner'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +var abilityDelegator = undefined +var abilityDelegatorArguments = undefined + +async function onAbilityCreateCallback() { + hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback'); +} + +async function addAbilityMonitorCallback(err: any) { + hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? ''); +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare '); + } + + async onRun() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run'); + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility' + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName + var debug = abilityDelegatorArguments.parameters['-D'] + if (debug == 'true') + { + cmd += ' -D' + } + hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd); + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? ''); + }) + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end'); + } +} \ No newline at end of file diff --git a/ohos/load_native_resource_demo/ohos/entry/src/ohosTest/module.json5 b/ohos/load_native_resource_demo/ohos/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fab77ce2e0c61e3ad010bab5b27ccbd15f9a8c96 --- /dev/null +++ b/ohos/load_native_resource_demo/ohos/entry/src/ohosTest/module.json5 @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/ohos/load_native_resource_demo/ohos/entry/src/ohosTest/resources/base/element/color.json b/ohos/load_native_resource_demo/ohos/entry/src/ohosTest/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ohos/load_native_resource_demo/ohos/entry/src/ohosTest/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ohos/load_native_resource_demo/ohos/entry/src/ohosTest/resources/base/element/string.json b/ohos/load_native_resource_demo/ohos/entry/src/ohosTest/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..65d8fa5a7cf54aa3943dcd0214f58d1771bc1f6c --- /dev/null +++ b/ohos/load_native_resource_demo/ohos/entry/src/ohosTest/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_test_desc", + "value": "test ability description" + }, + { + "name": "TestAbility_desc", + "value": "the test ability" + }, + { + "name": "TestAbility_label", + "value": "test label" + } + ] +} \ No newline at end of file diff --git a/ohos/load_native_resource_demo/ohos/entry/src/ohosTest/resources/base/media/icon.png b/ohos/load_native_resource_demo/ohos/entry/src/ohosTest/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ohos/load_native_resource_demo/ohos/entry/src/ohosTest/resources/base/media/icon.png differ diff --git a/ohos/load_native_resource_demo/ohos/entry/src/ohosTest/resources/base/profile/test_pages.json b/ohos/load_native_resource_demo/ohos/entry/src/ohosTest/resources/base/profile/test_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..b7e7343cacb32ce982a45e76daad86e435e054fe --- /dev/null +++ b/ohos/load_native_resource_demo/ohos/entry/src/ohosTest/resources/base/profile/test_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "testability/pages/Index" + ] +} diff --git a/ohos/load_native_resource_demo/ohos/hvigor/hvigor-config.json5 b/ohos/load_native_resource_demo/ohos/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..541ba35711b75986f9295410ee38fdb8f2572878 --- /dev/null +++ b/ohos/load_native_resource_demo/ohos/hvigor/hvigor-config.json5 @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +{ + "modelVersion": "5.0.0", + "dependencies": { + } +} \ No newline at end of file diff --git a/ohos/load_native_resource_demo/ohos/hvigorfile.ts b/ohos/load_native_resource_demo/ohos/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..8f2d2aafe6d6a3a71a9944ebd0c91fbc308ac9d1 --- /dev/null +++ b/ohos/load_native_resource_demo/ohos/hvigorfile.ts @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/ohos/load_native_resource_demo/ohos/oh-package.json5 b/ohos/load_native_resource_demo/ohos/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..13cb1ccbcf51f3bdb74900f0a6980ce26cd306bb --- /dev/null +++ b/ohos/load_native_resource_demo/ohos/oh-package.json5 @@ -0,0 +1,22 @@ +{ + "modelVersion": "5.0.0", + "name": "load_native_resource_demo", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "@ohos/flutter_ohos": "file:./har/flutter.har" + }, + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "overrides": { + "@ohos/flutter_ohos": "file:./har/flutter.har", + "video_player_ohos": "file:./har/video_player_ohos.har", + "@ohos/flutter_module": "file:./entry", + "image_picker_ohos": "file:./har/image_picker_ohos.har", + "permission_handler_ohos": "file:./har/permission_handler_ohos.har" + } +} \ No newline at end of file diff --git a/ohos/load_native_resource_demo/pubspec.yaml b/ohos/load_native_resource_demo/pubspec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..fba573effd032b5ad23520b247210defff566ec9 --- /dev/null +++ b/ohos/load_native_resource_demo/pubspec.yaml @@ -0,0 +1,104 @@ +name: load_native_resource_demo +description: A new Flutter project. +# The following line prevents the package from being accidentally published to +# pub.dev using `flutter pub publish`. This is preferred for private packages. +publish_to: 'none' # Remove this line if you wish to publish to pub.dev + +# The following defines the version and build number for your application. +# A version number is three numbers separated by dots, like 1.2.43 +# followed by an optional build number separated by a +. +# Both the version and the builder number may be overridden in flutter +# build by specifying --build-name and --build-number, respectively. +# In Android, build-name is used as versionName while build-number used as versionCode. +# Read more about Android versioning at https://developer.android.com/studio/publish/versioning +# In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion. +# Read more about iOS versioning at +# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html +# In Windows, build-name is used as the major, minor, and patch parts +# of the product and file versions while build-number is used as the build suffix. +version: 1.0.0+1 + +environment: + sdk: '>=2.19.6 <3.0.0' + +# Dependencies specify other packages that your package needs in order to work. +# To automatically upgrade your package dependencies to the latest versions +# consider running `flutter pub upgrade --major-versions`. Alternatively, +# dependencies can be manually updated by changing the version numbers below to +# the latest version available on pub.dev. To see which dependencies have newer +# versions available, run `flutter pub outdated`. +dependencies: + flutter: + sdk: flutter + + + # The following adds the Cupertino Icons font to your application. + # Use with the CupertinoIcons class for iOS style icons. + cupertino_icons: ^1.0.2 + video_player: + git: + url: https://gitee.com/openharmony-sig/flutter_packages.git + path: packages/video_player/video_player + + image_picker: + git: + url: https://gitee.com/openharmony-sig/flutter_packages.git + path: packages/image_picker/image_picker + + permission_handler: + git: + url: https://gitee.com/openharmony-sig/flutter_permission_handler.git + path: permission_handler + +dev_dependencies: + flutter_test: + sdk: flutter + + # The "flutter_lints" package below contains a set of recommended lints to + # encourage good coding practices. The lint set provided by the package is + # activated in the `analysis_options.yaml` file located at the root of your + # package. See that file for information about deactivating specific lint + # rules and activating additional ones. + flutter_lints: ^2.0.0 + +# For information on the generic Dart part of this file, see the +# following page: https://dart.dev/tools/pub/pubspec + +# The following section is specific to Flutter packages. +flutter: + + # The following line ensures that the Material Icons font is + # included with your application, so that you can use the icons in + # the material Icons class. + uses-material-design: true + + # To add assets to your application, add an assets section, like this: + # assets: + # - images/a_dot_burr.jpeg + # - images/a_dot_ham.jpeg + + # An image asset can refer to one or more resolution-specific "variants", see + # https://flutter.dev/assets-and-images/#resolution-aware + + # For details regarding adding assets from package dependencies, see + # https://flutter.dev/assets-and-images/#from-packages + + # To add custom fonts to your application, add a fonts section here, + # in this "flutter" section. Each entry in this list should have a + # "family" key with the font family name, and a "fonts" key with a + # list giving the asset and other descriptors for the font. For + # example: + # fonts: + # - family: Schyler + # fonts: + # - asset: fonts/Schyler-Regular.ttf + # - asset: fonts/Schyler-Italic.ttf + # style: italic + # - family: Trajan Pro + # fonts: + # - asset: fonts/TrajanPro.ttf + # - asset: fonts/TrajanPro_Bold.ttf + # weight: 700 + # + # For details regarding fonts from package dependencies, + # see https://flutter.dev/custom-fonts/#from-packages