Skip to content

Commit

Permalink
feat: support openharmony (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
zmtzawqlp committed Mar 13, 2024
1 parent f98ccae commit d8c3fb9
Show file tree
Hide file tree
Showing 44 changed files with 1,437 additions and 113 deletions.
45 changes: 28 additions & 17 deletions README.md
Expand Up @@ -7,10 +7,11 @@
[![Awesome Flutter](https://img.shields.io/badge/Awesome-Flutter-blue.svg?longCache=true&style=flat-square)](https://stackoverflow.com/questions/tagged/flutter?sort=votes)
[![FlutterCandies](https://pub.idqqimg.com/wpa/images/group.png)](https://jq.qq.com/?_wv=1027&k=5bcc0gy)

Compresses image as native plugin (Obj-C/Kotlin). This library works on Android and iOS.
Compresses image as native plugin (Obj-C/Kotlin). This library works on Android, iOS, macOS, Web, OpenHarmony.

- [flutter\_image\_compress](#flutter_image_compress)
- [Why don't you use dart to do it](#why-dont-you-use-dart-to-do-it)
- [Platform Features](#platform-features)
- [Usage](#usage)
- [About common params](#about-common-params)
- [minWidth and minHeight](#minwidth-and-minheight)
Expand All @@ -33,7 +34,7 @@ Compresses image as native plugin (Obj-C/Kotlin). This library works on Android
- [About EXIF information](#about-exif-information)
- [Web](#web)
- [About macOS](#about-macos)
- [Platform Features](#platform-features)
- [OpenHarmony](#openharmony)

## Why don't you use dart to do it

Expand All @@ -42,6 +43,25 @@ Q:Dart already has image compression libraries. Why use native?
A:For unknown reasons, image compression in Dart language is not efficient,
even in release version. Using isolate does not solve the problem.

## Platform Features

| Feature | Android | iOS | Web | macOS | OpenHarmony |
| :------------------------- | :-----: | :---: | :---------------------: | :---: | :-------: |
| method: compressWithList ||||||
| method: compressAssetImage ||||||
| method: compressWithFile ||||||
| method: compressAndGetFile ||||||
| format: jpeg ||||||
| format: png ||||||
| format: webp ||| [🌐][webp-compatibility] |||
| format: heic ||||||
| param: quality ||| [🌐][webp-compatibility] |||
| param: rotate ||||||
| param: keepExif ||||||

[webp-compatibility]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob#browser_compatibility "Browser support"


## Usage

See the [![pub](https://img.shields.io/pub/v/flutter_image_compress.svg)](https://pub.dev/packages/flutter_image_compress/versions) version.
Expand Down Expand Up @@ -368,20 +388,11 @@ Open xcode project, select Runner target, and change the value of `macOS Deploym
And, change the `Podfile`:
Change `platform` to `platform :osx, '10.15'`.

## Platform Features

| Feature | Android | iOS | Web | macOS |
| :------------------------- | :-----: | :---: | :---------------------: | :---: |
| method: compressWithList |||||
| method: compressAssetImage |||||
| method: compressWithFile |||||
| method: compressAndGetFile |||||
| format: jpeg |||||
| format: png |||||
| format: webp ||| [🌐][webp-compatibility] ||
| format: heic |||||
| param: quality ||| [🌐][webp-compatibility] ||
| param: rotate |||||
| param: keepExif |||||
## OpenHarmony

The currently supported image formats for parsing include JPEG, PNG, GIF, RAW, WebP, BMP, and SVG. However, the encoding output image formats are currently limited to JPEG, PNG, and WebP only.

当前支持的解析图片格式包括 JPEG、PNG、GIF、RAW、WebP、BMP、SVG . 编码输出图片格式当前仅支持 JPEG、PNG 和 WebP.


[webp-compatibility]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob#browser_compatibility "Browser support"
45 changes: 28 additions & 17 deletions packages/flutter_image_compress/README.md
Expand Up @@ -7,10 +7,11 @@
[![Awesome Flutter](https://img.shields.io/badge/Awesome-Flutter-blue.svg?longCache=true&style=flat-square)](https://stackoverflow.com/questions/tagged/flutter?sort=votes)
[![FlutterCandies](https://pub.idqqimg.com/wpa/images/group.png)](https://jq.qq.com/?_wv=1027&k=5bcc0gy)

Compresses image as native plugin (Obj-C/Kotlin). This library works on Android and iOS.
Compresses image as native plugin (Obj-C/Kotlin). This library works on Android, iOS, macOS, Web, OpenHarmony.

- [flutter\_image\_compress](#flutter_image_compress)
- [Why don't you use dart to do it](#why-dont-you-use-dart-to-do-it)
- [Platform Features](#platform-features)
- [Usage](#usage)
- [About common params](#about-common-params)
- [minWidth and minHeight](#minwidth-and-minheight)
Expand All @@ -33,7 +34,7 @@ Compresses image as native plugin (Obj-C/Kotlin). This library works on Android
- [About EXIF information](#about-exif-information)
- [Web](#web)
- [About macOS](#about-macos)
- [Platform Features](#platform-features)
- [OpenHarmony](#openharmony)

## Why don't you use dart to do it

Expand All @@ -42,6 +43,25 @@ Q:Dart already has image compression libraries. Why use native?
A:For unknown reasons, image compression in Dart language is not efficient,
even in release version. Using isolate does not solve the problem.

## Platform Features

| Feature | Android | iOS | Web | macOS | OpenHarmony |
| :------------------------- | :-----: | :---: | :---------------------: | :---: | :-------: |
| method: compressWithList ||||||
| method: compressAssetImage ||||||
| method: compressWithFile ||||||
| method: compressAndGetFile ||||||
| format: jpeg ||||||
| format: png ||||||
| format: webp ||| [🌐][webp-compatibility] |||
| format: heic ||||||
| param: quality ||| [🌐][webp-compatibility] |||
| param: rotate ||||||
| param: keepExif ||||||

[webp-compatibility]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob#browser_compatibility "Browser support"


## Usage

See the [![pub](https://img.shields.io/pub/v/flutter_image_compress.svg)](https://pub.dev/packages/flutter_image_compress/versions) version.
Expand Down Expand Up @@ -368,20 +388,11 @@ Open xcode project, select Runner target, and change the value of `macOS Deploym
And, change the `Podfile`:
Change `platform` to `platform :osx, '10.15'`.

## Platform Features

| Feature | Android | iOS | Web | macOS |
| :------------------------- | :-----: | :---: | :---------------------: | :---: |
| method: compressWithList |||||
| method: compressAssetImage |||||
| method: compressWithFile |||||
| method: compressAndGetFile |||||
| format: jpeg |||||
| format: png |||||
| format: webp ||| [🌐][webp-compatibility] ||
| format: heic |||||
| param: quality ||| [🌐][webp-compatibility] ||
| param: rotate |||||
| param: keepExif |||||
## OpenHarmony

The currently supported image formats for parsing include JPEG, PNG, GIF, RAW, WebP, BMP, and SVG. However, the encoding output image formats are currently limited to JPEG, PNG, and WebP only.

当前支持的解析图片格式包括 JPEG、PNG、GIF、RAW、WebP、BMP、SVG . 编码输出图片格式当前仅支持 JPEG、PNG 和 WebP.


[webp-compatibility]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob#browser_compatibility "Browser support"
18 changes: 18 additions & 0 deletions packages/flutter_image_compress/example/ohos/.gitignore
@@ -0,0 +1,18 @@
/node_modules
/oh_modules
/local.properties
/.idea
**/build
/.hvigor
.cxx
/.clangd
/.clang-format
/.clang-tidy
**/.test
entry/libs/arm64-v8a/libapp.so
entry/libs/arm64-v8a/libflutter.so
entry/libs/arm64-v8a/libvmservice_snapshot.so
entry/src/main/resources/rawfile/flutter_assets/
har/flutter.har
oh-package-lock.json5
dta
10 changes: 10 additions & 0 deletions packages/flutter_image_compress/example/ohos/AppScope/app.json5
@@ -0,0 +1,10 @@
{
"app": {
"bundleName": "com.fluttercandies.example",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name"
}
}
@@ -0,0 +1,8 @@
{
"string": [
{
"name": "app_name",
"value": "example"
}
]
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions packages/flutter_image_compress/example/ohos/build-profile.json5
@@ -0,0 +1,43 @@
/*
* 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.
*/

{
"app": {
"signingConfigs": [],
"products": [
{
"name": "default",
"signingConfig": "default",
"compileSdkVersion": "4.1.0(11)",
"compatibleSdkVersion": "4.1.0(11)",
"runtimeOS": "HarmonyOS",
}
]
},
"modules": [
{
"name": "entry",
"srcPath": "./entry",
"targets": [
{
"name": "default",
"applyToProducts": [
"default"
]
}
]
}
]
}
9 changes: 9 additions & 0 deletions packages/flutter_image_compress/example/ohos/entry/.gitignore
@@ -0,0 +1,9 @@

/node_modules
/oh_modules
/.preview
/build
/.cxx
/.test
/har
/libs
@@ -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",
}
]
}
17 changes: 17 additions & 0 deletions packages/flutter_image_compress/example/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';
@@ -0,0 +1,12 @@
{
name: 'entry',
version: '1.0.0',
description: 'Please describe the basic information.',
main: '',
author: '',
license: '',
dependencies: {
'@ohos/path_provider_ohos': 'file:./har/path_provider_ohos.har',
'@ohos/flutter_image_compress_ohos': 'file:./har/flutter_image_compress_ohos.har',
},
}
@@ -0,0 +1,30 @@
/*
* 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 } from '@ohos/flutter_ohos'
import { FlutterPlugin } from '@ohos/flutter_ohos/src/main/ets/embedding/engine/plugins/FlutterPlugin';
import { GeneratedPluginRegistrant } from '../plugins/GeneratedPluginRegistrant';
import List from '@ohos.util.List';
import FlutterEngine from '@ohos/flutter_ohos/src/main/ets/embedding/engine/FlutterEngine';

export default class EntryAbility extends FlutterAbility {
configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
let plugins = GeneratedPluginRegistrant.getPlugins() as List<FlutterPlugin>;
plugins.forEach((plugin) => {
this.addPlugin(plugin);
})
}
}
@@ -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
}
}
@@ -0,0 +1,18 @@
import { FlutterPlugin } from '@ohos/flutter_ohos/src/main/ets/embedding/engine/plugins/FlutterPlugin';
import List from '@ohos.util.List';
import FlutterImageCompressOhosPlugin from '@ohos/flutter_image_compress_ohos'
import PathProviderPlugin from '@ohos/path_provider_ohos'

/**
* Generated file. Do not edit.
* This file is generated by the Flutter tool based on the
* plugins that support the Ohos platform.
*/
export class GeneratedPluginRegistrant {
static getPlugins(): List<FlutterPlugin> {
let pluginList : List<FlutterPlugin> = new List();
pluginList.add(new FlutterImageCompressOhosPlugin());
pluginList.add(new PathProviderPlugin());
return pluginList;
}
}

0 comments on commit d8c3fb9

Please sign in to comment.