From b62005d17819112c8354d49a0cf61dcff1598bd8 Mon Sep 17 00:00:00 2001 From: chenjianpeng Date: Wed, 26 May 2021 09:52:05 +0800 Subject: [PATCH] =?UTF-8?q?1=EF=BC=8C=E4=BF=AE=E6=94=B9CHANGELOG,=E4=BF=AE?= =?UTF-8?q?=E6=94=B9readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 + README.OPENSOURCE | 10 +++ README.md | 4 - changelog.md | 18 ----- entry/src/main/config.json | 2 +- entry/src/ohosTest/config.json | 4 +- .../imageselector/ExampleOhosTest.java | 14 ---- .../imageselector/MainAbilityTest.java | 74 +++++++++++++++++++ .../com/lzy/imagepicker/util/BitmapUtil.java | 1 + .../yalantis/ucrop/task/BitmapCropTask.java | 4 +- .../yalantis/ucrop/task/BitmapLoadTask.java | 12 +-- .../yalantis/ucrop/util/BitmapLoadUtils.java | 14 ++-- .../ucrop/view/GestureCropImageView.java | 2 +- .../ucrop/view/TransformImageView.java | 6 +- 14 files changed, 109 insertions(+), 58 deletions(-) create mode 100644 CHANGELOG.md create mode 100644 README.OPENSOURCE delete mode 100644 changelog.md delete mode 100644 entry/src/ohosTest/java/com/donkingliang/imageselector/ExampleOhosTest.java create mode 100644 entry/src/ohosTest/java/com/donkingliang/imageselector/MainAbilityTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..e02d0e9 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,2 @@ +## 0.0.1-SNAPSHOT +ohos 第一个版本,完整实现了原库的全部 api \ No newline at end of file diff --git a/README.OPENSOURCE b/README.OPENSOURCE new file mode 100644 index 0000000..68babb5 --- /dev/null +++ b/README.OPENSOURCE @@ -0,0 +1,10 @@ +[ + { + "Name": "ImageSelector", + "License": "Apache License 2.0", + "License File": "LICENSE", + "Version Number": "v1.9.3", + "Upstream URL": "https://github.com/donkingliang/ImageSelector", + "Description": "Android图片选择器,仿微信的图片选择器的样式和效果。支持图片的单选、限数量的多选和不限数量的多选。支持图片预览和图片文件夹的切换。支持在选择图片时调用相机拍照,也支持不用打开相册直接调用相机拍照。" + } +] \ No newline at end of file diff --git a/README.md b/README.md index 468d64c..5ac3ed5 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,5 @@ # ImageSelector -**本项目基于开源项目ImageSelector -进行OpenHarmony化的移植和开发,可以通过项目标签以及github地址( https://github.com/donkingliang/ImageSelector )追踪到原项目版本** - #### 项目介绍 - 项目名称:ImageSelector - 所属系列:OpenHarmony的第三方组件适配移植 @@ -11,7 +8,6 @@ - 项目移植状态:主功能完成 - 调用差异:无 - 开发版本:sdk5,DevEco Studio2.1 beta4 -- 原项目Doc地址:https://github.com/donkingliang/ImageSelector #### 效果演示 diff --git a/changelog.md b/changelog.md deleted file mode 100644 index 32ff53b..0000000 --- a/changelog.md +++ /dev/null @@ -1,18 +0,0 @@ -# 基本功能: - - 一个功能强大的图片选择器。支持图片的单选、限数量的多选和不限数量的多选。支持图片预览和图片文件夹的切换。支持在选择图片时调用相机拍照,也支持不用打开相册直接调用相机拍照。 - -# 修改点: - -1、采用harmony的方式实现 拍照,图库查询,图片裁剪,图片预览。 - -2、目前功能开发是自研,所有功能都是采用harmony的方式实现。 - -# 遗留问题(暂不支持的功能): - -1、目前使用三方库,图片加载缓慢,内存占用高。 - -2、目前模拟器无法拍照 - - - diff --git a/entry/src/main/config.json b/entry/src/main/config.json index 6731a5c..d0cc2a3 100644 --- a/entry/src/main/config.json +++ b/entry/src/main/config.json @@ -9,7 +9,7 @@ "apiVersion": { "compatible": 5, "target": 5, - "releaseType": "Beta1" + "releaseType": "Release" } }, "deviceConfig": {}, diff --git a/entry/src/ohosTest/config.json b/entry/src/ohosTest/config.json index d5f4fb1..3c61119 100644 --- a/entry/src/ohosTest/config.json +++ b/entry/src/ohosTest/config.json @@ -9,7 +9,7 @@ "apiVersion": { "compatible": 5, "target": 5, - "releaseType": "Beta1" + "releaseType": "Release" } }, "deviceConfig": {}, @@ -30,7 +30,7 @@ "name": "decc.testkit.runner.EntryAbility", "description": "Test Entry Ability", "icon": "$media:icon", - "label": "$string:app_name", + "label": "ImageSelector", "launchType": "standard", "orientation": "landscape", "visible": true, diff --git a/entry/src/ohosTest/java/com/donkingliang/imageselector/ExampleOhosTest.java b/entry/src/ohosTest/java/com/donkingliang/imageselector/ExampleOhosTest.java deleted file mode 100644 index a69cdb1..0000000 --- a/entry/src/ohosTest/java/com/donkingliang/imageselector/ExampleOhosTest.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.donkingliang.imageselector; - -import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class ExampleOhosTest { - @Test - public void testBundleName() { - final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName(); - assertEquals("com.donkingliang.imageselector", actualBundleName); - } -} \ No newline at end of file diff --git a/entry/src/ohosTest/java/com/donkingliang/imageselector/MainAbilityTest.java b/entry/src/ohosTest/java/com/donkingliang/imageselector/MainAbilityTest.java new file mode 100644 index 0000000..62eca2e --- /dev/null +++ b/entry/src/ohosTest/java/com/donkingliang/imageselector/MainAbilityTest.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2021 Huawei Device 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 an 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. + */ + +package com.donkingliang.imageselector; + +import com.donkingliang.imageselector.util.HeLog; +import com.flask.colorpicker.cameralibrary.util.AngleUtil; +import com.flask.colorpicker.cameralibrary.util.ScreenUtils; +import ohos.aafwk.ability.Ability; +import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry; +import org.junit.Assert; +import org.junit.Test; + +/** + * 测试类 + * + * @author ImageSelector + * @since 2021-05-25 + */ +public class MainAbilityTest { + Ability ability = AbilityDelegatorRegistry.getAbilityDelegator().getCurrentTopAbility(); + + /** + * 测试类 + */ + @Test + public void onStart() { + HeLog.d("HiLog","单元测试"); + int senSer = AngleUtil.getSensorAngle(10.0f,20.0f); + Assert.assertEquals(0, senSer); + ScreenUtils.getScreenHeight(ability.getApplicationContext()); + ScreenUtils.getScreenWidth(ability.getApplicationContext()); + } + + /** + * 测试类 + */ + @Test + public void enterPage() { + } + + /** + * 测试类 + */ + @Test + public void onRequestPermissionsFromUserResult() { + } + + /** + * 测试类 + */ + @Test + public void onAbilityResult() { + } + + /** + * 测试类 + */ + @Test + public void cropImg() { + } +} \ No newline at end of file diff --git a/imagepicker/src/main/java/com/lzy/imagepicker/util/BitmapUtil.java b/imagepicker/src/main/java/com/lzy/imagepicker/util/BitmapUtil.java index 27baa83..d578e94 100644 --- a/imagepicker/src/main/java/com/lzy/imagepicker/util/BitmapUtil.java +++ b/imagepicker/src/main/java/com/lzy/imagepicker/util/BitmapUtil.java @@ -30,6 +30,7 @@ public class BitmapUtil { DataAbilityHelper helper = DataAbilityHelper.creator(ability); ImageSource.SourceOptions options = new ImageSource.SourceOptions(); ImageSource source = ImageSource.create(helper.openFile(Uri.parse(uriScheme), "r"), options); + degree = source.getImagePropertyInt(PropertyKey.Exif.ORIENTATION, 0); } catch (DataAbilityRemoteException | FileNotFoundException e) { return degree; diff --git a/ucrop/src/main/java/com/yalantis/ucrop/task/BitmapCropTask.java b/ucrop/src/main/java/com/yalantis/ucrop/task/BitmapCropTask.java index 8ea3cee..2ea135d 100644 --- a/ucrop/src/main/java/com/yalantis/ucrop/task/BitmapCropTask.java +++ b/ucrop/src/main/java/com/yalantis/ucrop/task/BitmapCropTask.java @@ -129,8 +129,8 @@ public class BitmapCropTask implements CropResult{ // Rotate if needed if (mCurrentAngle != 0) { - //安卓逻辑:将Bitmap缩放、旋转 - //鸿蒙逻辑:将PixelMap保存,再读取,读取时缩放并旋转.保存需要路径,所以需要Ability传进来Context + //逻辑:将Bitmap缩放、旋转 + //逻辑:将PixelMap保存,再读取,读取时缩放并旋转.保存需要路径,所以需要Ability传进来Context //获取缩放和旋转参数 Matrix tempMatrix = new Matrix(); diff --git a/ucrop/src/main/java/com/yalantis/ucrop/task/BitmapLoadTask.java b/ucrop/src/main/java/com/yalantis/ucrop/task/BitmapLoadTask.java index ccfcf4f..9bbbc81 100644 --- a/ucrop/src/main/java/com/yalantis/ucrop/task/BitmapLoadTask.java +++ b/ucrop/src/main/java/com/yalantis/ucrop/task/BitmapLoadTask.java @@ -89,9 +89,9 @@ public class BitmapLoadTask { boolean decodeAttemptSuccess = false; while (!decodeAttemptSuccess) { try { - //安卓通过InputUri获取InputStream + //通过InputUri获取InputStream //InputStream stream = mContext.getContentResolver().openInputStream(mInputUri); - //鸿蒙通过InputUri获取InputStream + //通过InputUri获取InputStream InputStream stream; DataAbilityHelper helper = DataAbilityHelper.creator(mContext); FileDescriptor fd = helper.openFile(mInputUri, "r"); @@ -227,9 +227,9 @@ public class BitmapLoadTask { InputStream inputStream; OutputStream outputStream; try { - //安卓通过InputUri获取InputStream + //通过InputUri获取InputStream //inputStream = mContext.getContentResolver().openInputStream(inputUri); - //鸿蒙通过InputUri获取InputStream + //通过InputUri获取InputStream DataAbilityHelper helper = DataAbilityHelper.creator(mContext); FileDescriptor fd_i = helper.openFile(mInputUri, "r"); inputStream = new FileInputStream(fd_i); @@ -273,9 +273,9 @@ public class BitmapLoadTask { assert response.body() != null; source = response.body().source(); - //安卓通过OutputUri获取OutputStream + //通过OutputUri获取OutputStream //OutputStream outputStream = mContext.getContentResolver().openOutputStream(outputUri); - //鸿蒙通过OutputUri获取OutputStream + //通过OutputUri获取OutputStream OutputStream outputStream; DataAbilityHelper helper = DataAbilityHelper.creator(mContext); FileDescriptor fd = helper.openFile(outputUri,"w"); diff --git a/ucrop/src/main/java/com/yalantis/ucrop/util/BitmapLoadUtils.java b/ucrop/src/main/java/com/yalantis/ucrop/util/BitmapLoadUtils.java index a58109b..1be3611 100644 --- a/ucrop/src/main/java/com/yalantis/ucrop/util/BitmapLoadUtils.java +++ b/ucrop/src/main/java/com/yalantis/ucrop/util/BitmapLoadUtils.java @@ -36,18 +36,18 @@ public class BitmapLoadUtils { Uri uri, Uri outputUri, int requiredWidth, int requiredHeight, BitmapLoadCallback loadCallback) { -//原安卓接口 +//原接口 // new BitmapLoadTask(context, uri, outputUri, requiredWidth, requiredHeight, loadCallback) // .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); -//鸿蒙版 +//版 new BitmapLoadTask(context, uri, outputUri, requiredWidth, requiredHeight, loadCallback).doInBackground(); } public PixelMap transformBitmap(PixelMap bitmap, float degrees, float scale_X, Context context) { try { - //安卓逻辑:对位图使用矩阵进行先旋转再缩放、平移 + //逻辑:对位图使用矩阵进行先旋转再缩放、平移 // PixelMap converted = PixelMap.create(bitmap, 0, 0, bitmap.getImageInfo().getWidth(), bitmap.getHeight(), transformMatrix, true); - //鸿蒙逻辑:先保存位图,再读取,读取时旋转和缩放、平移 + //逻辑:先保存位图,再读取,读取时旋转和缩放、平移 File file_path = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES); File temp_file = new File(file_path + "/temp.jpg"); _saveImage(temp_file, bitmap); @@ -125,9 +125,9 @@ public class BitmapLoadUtils { System.out.println(context); int orientation = 0; try { - //安卓通过InputUri获取InputStream + //通过InputUri获取InputStream //InputStream stream = context.getContentResolver().openInputStream(imageUri); - //鸿蒙通过InputUri获取InputStream + //通过InputUri获取InputStream InputStream stream = null; HttpURLConnection connection = null; URL url = new URL(String.valueOf(imageUri)); @@ -214,7 +214,7 @@ public class BitmapLoadUtils { int maxBitmapSize = (int) Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2)); // Check for max texture size via Canvas - //鸿蒙无此参数,故预设一个大数 + //无此参数,故预设一个大数 //final int maxCanvasSize = Math.min(canvas.getMaximumBitmapWidth(), canvas.getMaximumBitmapHeight()); final int maxCanvasSize = 10000000; if (maxCanvasSize > 0) { diff --git a/ucrop/src/main/java/com/yalantis/ucrop/view/GestureCropImageView.java b/ucrop/src/main/java/com/yalantis/ucrop/view/GestureCropImageView.java index a18bed7..47ea4d0 100644 --- a/ucrop/src/main/java/com/yalantis/ucrop/view/GestureCropImageView.java +++ b/ucrop/src/main/java/com/yalantis/ucrop/view/GestureCropImageView.java @@ -40,7 +40,7 @@ public class GestureCropImageView extends CropImageView implements Component.Tou mScaledListener = new ScaleListener(); setScaledListener(mScaledListener); } - //由于鸿蒙滑动监听缺陷,所以滑动操作整合在触摸监听里 + //由于滑动监听缺陷,所以滑动操作整合在触摸监听里 @Override public boolean onTouchEvent(Component component, TouchEvent event) { if ((event.getAction() ) == TouchEvent.PRIMARY_POINT_DOWN) { diff --git a/ucrop/src/main/java/com/yalantis/ucrop/view/TransformImageView.java b/ucrop/src/main/java/com/yalantis/ucrop/view/TransformImageView.java index 542c6c4..67a7485 100644 --- a/ucrop/src/main/java/com/yalantis/ucrop/view/TransformImageView.java +++ b/ucrop/src/main/java/com/yalantis/ucrop/view/TransformImageView.java @@ -63,7 +63,7 @@ public class TransformImageView extends PositionLayout implements Component.Layo public static final int MSKEW_X = 1; //!< use with getValues/setValues public static final int MSKEW_Y = 3; //!< use with getValues/setValues - //添加一个全局变量PixelMapHolder用于传递图片,解决鸿蒙操作canvas时图像不变换的问题 + //添加一个全局变量PixelMapHolder用于传递图片,解决openharmony操作canvas时图像不变换的问题 public PixelMapHolder mBitmapHolder; @Override @@ -128,9 +128,9 @@ public class TransformImageView extends PositionLayout implements Component.Layo // @Override public void setPixelMap(final PixelMap bitmap) { - //原安卓:FastBitmapDrawable是一个Drawable,Drawbale可以被画在View里,所以直接set一个FastBitmapDrawable即可完成对图像的绘制 + //原:FastBitmapDrawable是一个Drawable,Drawbale可以被画在View里,所以直接set一个FastBitmapDrawable即可完成对图像的绘制 //setImageElement(new FastBitmapDrawable(mContext, bitmap)); - //鸿蒙:Drawable对标的是Element,但是由于功能缺陷,Element不支持自定义绘制,如果将FastBitmapDrawable继承Element则不能完成绘制任务 + //Drawable对标的是Element,但是由于功能缺陷,Element不支持自定义绘制,如果将FastBitmapDrawable继承Element则不能完成绘制任务 //所以FastBitmapDrawable需要是一个Image,然而TransformImageView不能支持内置另一个Image,所以有必要将TransformImageView继承一个ComponentContainer //此处选择PositionLayout Component fastBitmapDrawable = new FastBitmapDrawable(mContext, bitmap); -- Gitee