From 5994d40d9a12826d857bb07dfeaf3d521d4baa05 Mon Sep 17 00:00:00 2001 From: hihope Date: Wed, 23 Jun 2021 20:22:56 +0800 Subject: [PATCH] update api --- LICENSE | 352 +++---- R.md | 8 +- README.md | 14 +- animation/Animator.md | 34 + animation/Keyframe.md | 49 + animation/ObjectAnimator.md | 37 + animation/PropertyValuesHolder.md | 37 + animation/TypeEvaluator.md | 24 + animation/ValueAnimator.md | 941 +++++++++--------- app/Activity.md | 58 +- app/ActivityManager.md | 36 +- app/AlarmManager.md | 34 + app/Application.md | 18 + app/Dialog.md | 9 + app/Fragment.md | 15 + app/PendingIntent.md | 9 + app/Service.md | 53 + bluetooth/AdvertiseData.md | 28 + bluetooth/BluetoothAdapter.md | 90 +- bluetooth/BluetoothGatt.md | 21 + content/BroadcastReceiver.md | 23 + content/ColorStateList.md | 96 +- content/ComponentName.md | 31 + content/ContentProvider.md | 218 ++-- content/ContentResolver.md | 84 +- content/ContentValues.md | 42 + content/Context.md | 76 +- content/ContextWrapper.md | 9 + content/ServiceConnection.md | 29 + content/SharedPreferences.md | 61 ++ content/res/AssetManager.md | 12 + content/res/Configuration.md | 9 + content/res/Resources.md | 10 + content/res/TypedArray.md | 128 +-- content/res/XmlResourceParser.md | 112 +-- .../NotificationCompat.md | 21 + database/Cursor.md | 226 ++--- database/DataSetObserver.md | 10 +- database/MatrixCursor.md | 72 +- database/sqlite/SQLiteDatabase.md | 120 +-- database/sqlite/SQLiteOpenHelper.md | 19 + fragment.app.Fragment/Fragment.md | 16 + graphics/Bitmap.md | 178 ++-- graphics/BitmapFactory.md | 106 +- graphics/BitmapRegionDecoder.md | 18 +- graphics/BitmapShader.md | 56 +- graphics/Canvas.md | 136 +-- graphics/Color.md | 23 + graphics/CornerPathEffect.md | 14 +- graphics/Matrix.md | 104 +- graphics/Paint.md | 43 +- graphics/Path.md | 90 +- graphics/PointF.md | 40 +- graphics/PorterDuffXfermode.md | 18 +- graphics/RectF.md | 140 +-- graphics/Typeface.md | 160 +-- graphics/Xfermode.md | 30 +- graphics/drawable/Drawable.md | 38 +- graphics/drawable/GradientDrawable.md | 86 +- graphics/drawable/StateListDrawable.md | 86 +- graphics/drawable/VectorDrawable.md | 50 +- hardware/Camera.md | 45 + os/AsyncTask.md | 10 + os/Handler.md | 92 +- os/Looper.md | 84 +- os/Message.md | 15 + os/Parcel.md | 9 + os/Parcelable.md | 10 + os/PowerManager.md | 9 + os/StatFs.md | 61 +- os/SystemClock.md | 82 +- provider/MediaStore.md | 10 + provider/Settings.md | 10 + support/v4/app/Fragment.md | 10 + support/v4/util/ArrayMap.md | 10 + support/v4/view/PagerAdapter.md | 9 + .../v4/view/ViewPager.OnPageChangeListener.md | 102 +- support/v4/widget/DrawerLayout.md | 102 +- support/v7/app/AppCompatActivity.md | 9 + support/v7/widget/RecyclerView.md | 25 + support/v7/widget/SimpleItemAnimator.md | 219 ++++ telephony/telephony.md | 66 ++ text/TextPaint.md | 9 + text/TextUtils.md | 50 +- util/AttributeSet.md | 35 + util/SparseArray.md | 118 +-- util/TypedValue.md | 32 +- util/encode.md | 38 + view/Display.md | 9 + view/Gravity.md | 10 + view/LayoutInflater.md | 8 +- view/Menu.md | 35 + view/MotionEvent.md | 24 +- view/SurfaceHolder.md | 10 + view/VelocityTracker.md | 138 +-- view/View.MeasureSpec.md | 106 +- view/View.md | 306 ++++-- view/ViewConfiguration.md | 61 ++ view/ViewPager.md | 24 +- view/ViewTreeObserver.md | 74 +- view/WindowManager.md | 61 +- view/animation/Animation.md | 20 +- view/animation/AnimationSet.md | 58 +- view/animation/Interpolator.md | 8 +- viewpager.widget.ViewPager/ViewPager.md | 264 +++++ webkit/WebView.md | 9 + widget/AbsListView.md | 20 + widget/AdapterView.md | 642 ++++++------ widget/ArrayAdapter.md | 237 +++++ widget/FrameLayout.md | 24 +- widget/GridView.md | 324 +++--- widget/ImageView.md | 32 +- widget/PopupWindow.md | 36 +- 113 files changed, 5375 insertions(+), 3143 deletions(-) create mode 100644 animation/Animator.md create mode 100644 animation/Keyframe.md create mode 100644 animation/ObjectAnimator.md create mode 100644 animation/PropertyValuesHolder.md create mode 100644 animation/TypeEvaluator.md create mode 100644 app/AlarmManager.md create mode 100644 app/Application.md create mode 100644 app/Dialog.md create mode 100644 app/Fragment.md create mode 100644 app/PendingIntent.md create mode 100644 app/Service.md create mode 100644 bluetooth/AdvertiseData.md create mode 100644 bluetooth/BluetoothGatt.md create mode 100644 content/BroadcastReceiver.md create mode 100644 content/ComponentName.md create mode 100644 content/ContentValues.md create mode 100644 content/ContextWrapper.md create mode 100644 content/ServiceConnection.md create mode 100644 content/SharedPreferences.md create mode 100644 content/res/AssetManager.md create mode 100644 content/res/Configuration.md create mode 100644 content/res/Resources.md create mode 100644 core.app.NotificationCompat/NotificationCompat.md create mode 100644 database/sqlite/SQLiteOpenHelper.md create mode 100644 fragment.app.Fragment/Fragment.md create mode 100644 graphics/Color.md create mode 100644 hardware/Camera.md create mode 100644 os/AsyncTask.md create mode 100644 os/Message.md create mode 100644 os/Parcel.md create mode 100644 os/Parcelable.md create mode 100644 os/PowerManager.md create mode 100644 provider/MediaStore.md create mode 100644 provider/Settings.md create mode 100644 support/v4/app/Fragment.md create mode 100644 support/v4/util/ArrayMap.md create mode 100644 support/v4/view/PagerAdapter.md create mode 100644 support/v7/app/AppCompatActivity.md create mode 100644 support/v7/widget/RecyclerView.md create mode 100644 support/v7/widget/SimpleItemAnimator.md create mode 100644 telephony/telephony.md create mode 100644 text/TextPaint.md create mode 100644 util/AttributeSet.md create mode 100644 util/encode.md create mode 100644 view/Display.md create mode 100644 view/Gravity.md create mode 100644 view/Menu.md create mode 100644 view/SurfaceHolder.md create mode 100644 view/ViewConfiguration.md create mode 100644 viewpager.widget.ViewPager/ViewPager.md create mode 100644 webkit/WebView.md create mode 100644 widget/AbsListView.md create mode 100644 widget/ArrayAdapter.md diff --git a/LICENSE b/LICENSE index 4947287..4a45986 100644 --- a/LICENSE +++ b/LICENSE @@ -1,177 +1,177 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + END OF TERMS AND CONDITIONS \ No newline at end of file diff --git a/R.md b/R.md index 9dc40fd..fdb7521 100644 --- a/R.md +++ b/R.md @@ -1,5 +1,5 @@ -### **R.id.content** ->+ openharmony API: 无 ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 +### **R.id.content** +>+ openharmony API: 无 +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 >+ 实现方案:R.id.content一般用于获取根布局,暂无对应的获取根布局的接口,可以通过暴露接口或增加构造参数让开发者传入布局作为根布局,然后调用根布局对象的getComponentParent()方法获取根容器。 \ No newline at end of file diff --git a/README.md b/README.md index 7406e7c..fe9d8dd 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -#三方库移植适配方案文档 -+ 此工程用于存放三方库移植过程中的解决方案,欢迎参与OpenHarmony的所有开发者与我们一起补充完善文档。 - -注意事项: -+ 修改方案请参照View.md的示例格式补充。 -+ 修改方案仅做为参考,具体代码需根据具体的业务场景进行修改。 - +#三方库移植适配方案文档 ++ 此工程用于存放三方库移植过程中的解决方案,欢迎参与OpenHarmony的所有开发者与我们一起补充完善文档。 + +注意事项: ++ 修改方案请参照View.md的示例格式补充。 ++ 修改方案仅做为参考,具体代码需根据具体的业务场景进行修改。 + # End \ No newline at end of file diff --git a/animation/Animator.md b/animation/Animator.md new file mode 100644 index 0000000..1a0d269 --- /dev/null +++ b/animation/Animator.md @@ -0,0 +1,34 @@ +### animation.Animator.setInterpolator + +>+ openharmony class: +> +> ohos.agp.animation.Animator.setCurveType +> +> ohos.agp.animation.AnimatorValue.ValueUpdateListener.onUpdate +> +>+ openharmony SDK版本:2.1.1.21 +> +>+ IDE版本:2.1.0.501 +> +>+ 实现方案: + +方案一: + +应用场景: setCurveType仅提一些预设的插值规则的枚举,无法自定义插值规则,也无法获取给定progress下的对应值。 + +可通过给AnimatorValue设置线性Curve Type,并设置ValueUpdateListener,在其onUpdate回调中对原始progress值进行自定义的插值计算求出所需新值 + +``` +@Override +public void onUpdate(AnimatorValue animation, float animatorValue) { + float newValue = interpolator.getInterpolation(animatorValue); + Point point = evaluator.evaluate(newValue, p0, p3); + target.mLeafRect.set((int) point.getPointX(), (int) point.getPointY(), + (int) (point.getPointX() + mLeafHolder.width), (int) (point.getPointY() + mLeafHolder.height)); + target.mLeafRotation = target.mMaxRotation * newValue; +} +``` + +方案二: + +通过AnimatorValue.setCurve(TimelineCurve curve)直接替换。 \ No newline at end of file diff --git a/animation/Keyframe.md b/animation/Keyframe.md new file mode 100644 index 0000000..69ffeab --- /dev/null +++ b/animation/Keyframe.md @@ -0,0 +1,49 @@ +### android.animation.Keyframe + +>+ openharmony class: +> +> 无 +> +>+ openharmony SDK版本:2.1.1.21 +> +>+ IDE版本:2.1.0.501 +> +>+ 实现方案: + +封装工具方法,根据参数构造Keyframe。 + +封装示例: + +``` +public static class Keyframe { + float progress; + float value; + + public Keyframe(float progress, float value) { + this.progress = progress; + this.value = value; + } + + public static Keyframe ofFloat(float progress, float value) { + return new Keyframe(progress, value); + } +} +``` + +使用示例: + +``` +Keyframe kf0, kf1, kf2; +float midwayPoint = 0.2f; +int duration = 500; + +kf0 = Keyframe.ofFloat(0f, 1); +kf1 = Keyframe.ofFloat(midwayPoint, mTransitionMidRadiusMultiplier); +kf2 = Keyframe.ofFloat(1f, mTransitionEndRadiusMultiplier); +PropertyValuesHolder radiusDisappear = PropertyValuesHolder.ofKeyframe( + "animationRadiusMultiplier", kf0, kf1, kf2); + +kf0 = Keyframe.ofFloat(0f, 1f); +kf1 = Keyframe.ofFloat(1f, 0f); +PropertyValuesHolder fadeOut = PropertyValuesHolder.ofKeyframe("alpha", kf0, kf1); +``` \ No newline at end of file diff --git a/animation/ObjectAnimator.md b/animation/ObjectAnimator.md new file mode 100644 index 0000000..0005c9e --- /dev/null +++ b/animation/ObjectAnimator.md @@ -0,0 +1,37 @@ +### android.animation.ObjectAnimator + +>+ openharmony class: ohos.agp.animation.AnimatorProperty +> +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景:属性动画alpha透明度渐变效果处理 +>+ 实现方案: + +创建alpha类 + +``` +import ohos.agp.animation.AnimatorProperty; + +public class AlphaAnimator extends AnimatorProperty { + private float mFromAlpha; + public AlphaAnimator(float fromAlpha, float toAlpha){ + super(); + mFromAlpha = fromAlpha; + alpha(toAlpha); + } + + @Override + public void start() { + getTarget().setAlpha(mFromAlpha); + super.start(); + } +} +``` + +使用 + +``` +AnimatorProperty loadingFadeOut = new AlphaAnimator(0f, 1f); +loadingFadeOut.setDuration(1200); +loadingFadeOut.setTarget(loadingView); +``` \ No newline at end of file diff --git a/animation/PropertyValuesHolder.md b/animation/PropertyValuesHolder.md new file mode 100644 index 0000000..fad0f81 --- /dev/null +++ b/animation/PropertyValuesHolder.md @@ -0,0 +1,37 @@ +### android.animation.PropertyValuesHolder + +>+ openharmony class: +> +> 无 +> +>+ openharmony SDK版本:2.1.1.21 +> +>+ IDE版本:2.1.0.501 +> +>+ 实现方案: + +封装工具方法,根据参数构造PropertyValuesHolder。 + +封装示例: + +``` +public static class PropertyValuesHolder { + String property; + Keyframe[] frames; + + public PropertyValuesHolder(String property, Keyframe... frames) { + this.property = property; + this.frames = frames; + } + + public static PropertyValuesHolder ofKeyframe(String property, Keyframe... frames) { + return new PropertyValuesHolder(property, frames); + } +} +``` + +使用示例 + +``` +PropertyValuesHolder fadeIn = PropertyValuesHolder.ofKeyframe("alpha", kf0, kf1, kf2); +``` \ No newline at end of file diff --git a/animation/TypeEvaluator.md b/animation/TypeEvaluator.md new file mode 100644 index 0000000..506ab05 --- /dev/null +++ b/animation/TypeEvaluator.md @@ -0,0 +1,24 @@ +### animation.TypeEvaluator.evaluate(float fraction, T startValue, T endValue) + +>+ openharmony class: +> +> 无 +> +>+ openharmony SDK版本:2.1.1.21 +> +>+ IDE版本:2.1.0.501 +> +>+ 应用场景: +> +> 此接口作用为将一些非数值类型按一定比例系数混合为新值,例如求取两个Color类型的中间值,或者求两个坐标点连线上某个比例的点的坐标等。TypeEvaluator对象可以与Animator对象绑定,使得动画更新时自动反馈当前系数下对应的新值。 +> +>+ 实现方案: + +与Interpolator类似,可以为AnimatorValue设置ValueUpdateListener,在其onUpdate回调中根据所需逻辑按照系数进行求值。 + +示例: + +``` +float v = startValue + fraction * (endValue = startValue) +``` + diff --git a/animation/ValueAnimator.md b/animation/ValueAnimator.md index 6eca569..d26a35d 100644 --- a/animation/ValueAnimator.md +++ b/animation/ValueAnimator.md @@ -1,464 +1,479 @@ -### **ofFloat,ofInt,setEvaluator** -## 方案一: ->+ openharmony class: ohos.agp.animation.Animator ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案: - -**对于ValueAnimator ofFloat(float... values)处理** -**原三方库:** -```java -final ValueAnimator valueAnimator = ValueAnimator.ofFloat(values); - valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(ValueAnimator animation) { - float value = (float) animation.getAnimatedValue(); - } - }); -``` -**openharmony :** -```java -final AnimatorValue animatorValue = new AnimatorValue(); - animatorValue.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() { - @Override - public void onUpdate(AnimatorValue animatorValue, float v) { - float value = AnimatorValueUtils.getAnimatedValue(v,values); - } - }); - -/** - * get the animated value with fraction and values - * - * @param fraction 0~1 - * @param values float array - * @return float animated value - */ -public static float getAnimatedValue(float fraction, float... values){ - if(values == null || values.length == 0){ - return 0; - } - if(values.length == 1){ - return values[0] * fraction; - }else{ - if(fraction == 1){ - return values[values.length-1]; - } - float oneFraction = 1f / (values.length - 1); - float offFraction = 0; - for (int i = 0; i < values.length - 1; i++) { - if (offFraction + oneFraction >= fraction) { - return values[i] + (fraction - offFraction) * (values.length - 1) * (values[i + 1] - values[i]); - } - offFraction += oneFraction; - } - } - return 0; - } -``` - -**对于ValueAnimator ofInt(int... values) + setEvaluator(new ArgbEvaluator())处理** -**原三方库:** -```java - final ValueAnimator valueAnimator = ValueAnimator.ofInt(color)); - valueAnimator.setEvaluator(new ArgbEvaluator()); - valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(ValueAnimator valueAnimator) { - int color = (int) valueAnimator.getAnimatedValue()); - } - }); -``` -**openharmony :** -```java -final AnimatorValue animatorValue = new AnimatorValue(); - animatorValue.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() { - @Override - public void onUpdate(AnimatorValue animatorValue, float v) { - int color = getAnimatedColor(v,color); - } - }); - - /** - * get the animated value with fraction and values - * - * @param fraction 0~1 - * @param colors color array - * @return int color - */ -public static int getAnimatedColor(float fraction, int... colors){ - if(colors == null || colors.length == 0){ - return 0; - } - if(colors.length == 1){ - return getAnimatedColor(0,colors[0],fraction); - }else{ - if(fraction == 1){ - return colors[colors.length-1]; - } - float oneFraction = 1f / (colors.length - 1); - float offFraction = 0; - for (int i = 0; i < colors.length - 1; i++) { - if (offFraction + oneFraction >= fraction) { - return getAnimatedColor(colors[i], colors[i + 1], (fraction - offFraction) * (colors.length -1)); - } - offFraction += oneFraction; - } - } - return 0; - } - - /** - * get the animated color with start color, end color and fraction - * - * @param fraction 0~1 - * @param from start color - * @param to end color - * @return int color - */ - public static int getAnimatedColor(int from, int to, float fraction) { - RgbColor colorFrom = RgbColor.fromArgbInt(from); - RgbColor colorTo = RgbColor.fromArgbInt(to); - int red = (int) (colorFrom.getRed() + (colorTo.getRed() - colorFrom.getRed()) * fraction); - int blue = (int) (colorFrom.getBlue() + (colorTo.getBlue() - colorFrom.getBlue()) * fraction); - int green = (int) (colorFrom.getGreen() + (colorTo.getGreen() - colorFrom.getGreen()) * fraction); - int alpha = (int) (colorFrom.getAlpha() + (colorTo.getAlpha() - colorFrom.getAlpha()) * fraction); - RgbColor mCurrentColorRgb = new RgbColor(red, green, blue, alpha); - return mCurrentColorRgb.asArgbInt(); - } -``` - -## 方案二: ->+ openharmony API: 无API替换 ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:对于设置自定义`float`初始值和`float`结束值的数值动画,可使用以下自定义类,同理可写出其他自定义初始值和结束值的数值动画类: -``` java - import ohos.agp.animation.AnimatorValue; - - /** - * 可以设置初始值和结束值的数值动画 - */ - public class MyValueAnimator extends AnimatorValue { - - private float start = 0; - private float end = 1; - private ValueUpdateListener myValueUpdateListener; - - /** - * 获取一个自定义初始值和结束值的数值动画对象 - * - * @param start 起始值 - * @param end 结束值 - * @return 自定义初始值和结束值的数值动画对象 - */ - public static MyValueAnimator ofFloat(float start, float end) { - MyValueAnimator myValueAnimator = new MyValueAnimator(); - myValueAnimator.start = start; - myValueAnimator.end = end; - return myValueAnimator; - } - - private MyValueAnimator() { - super.setValueUpdateListener(new ValueUpdateListener() { - @Override - public void onUpdate(AnimatorValue animatorValue, float value) { - value = value * (end - start) + start; - if (myValueUpdateListener != null) { - myValueUpdateListener.onUpdate(animatorValue, value); - } - } - }); - } - - /** - * 设置数值动画的起始值和结束值 - * - * @param start 起始值 - * @param end 结束值 - */ - public void setFloatValues(float start, float end) { - this.start = start; - this.end = end; - } - - @Override - public void setValueUpdateListener(ValueUpdateListener listener) { - this.myValueUpdateListener = listener; - } - - } -``` - - -### **setInterpolator** ->+ openharmony class: ohos.agp.animation.Animator ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:原三方库的ValueAnimator.setInterpolator(Interpolator interpolator)用ohos.agp.animation.AnimatorValue.setCurveType(int curveType)代替,其中curveType的int值是ohos.agp.animation.Animator.CurveType类的枚举常量. - -### **setRepeatMode** ->+ openharmony API: 无API替换 ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案: - + 1.定义两个状态常量值和一个Boolean值: -``` java -public final static int RESTART = 1;//正常模式 -public final static int REVERSE = 2;//倒序回放模式 -private int repeatMode = RESTART; -private boolean isBack = false; -``` - + 2.给数值动画设置重复执行时的监听,如下所示: -``` java -animatorValue.setLoopedListener(new Animator.LoopedListener() { - - @Override - public void onRepeat(Animator animator) { - isBack = !isBack; - } - }); -``` - + 3.在数值动画的`ValueUpdate`监听中做如下处理: -``` java -animatorValue.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() { - @Override - public void onUpdate(AnimatorValue animatorValue, float value) { - if (repeatMode == REVERSE && isBack) { - value = 1 - value; - } - //do yourself - } - }); -``` -### **ObjectAnimator ofFloat(Object target, String propertyName, float... values)(一种ohos替换方案)** ->+ openharmony class: ohos.agp.animation.AnimatorValue ->+ openharmony SDK版本:2.1.0.21 ->+ IDE版本:2.1.0.220 ->+ 实现方案: - -**对于ObjectAnimator ofFloat(Object target, String propertyName, float... values)处理** -**原三方库:** -```java - ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mTarget, "translationY", 0, dipToPixels(MyActivity.this, -(100))); - objectAnimator.setDuration(2000); - objectAnimator.start(); -``` -**openharmony :** -```java - // 数值动画 - AnimatorValue animator = new AnimatorValue(); - animator.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() { - @Override - public void onUpdate(AnimatorValue animatorValue, float v) { - mTarget.setTranslationY( - vpToPixels(getContext(), 100) * v); - } - }); - animator.setDuration(2000); - animator.start(); -``` - -### **ObjectAnimator ofFloat(Object target, String propertyName, float... values),setEvaluator(TypeEvaluator value)(一种ohos替换方案)** ->+ openharmony class: ohos.agp.animation.AnimatorValue ->+ openharmony SDK版本:2.1.0.21 ->+ IDE版本:2.1.0.220 ->+ 实现方案: - -**对于ObjectAnimator ofFloat(Object target, String propertyName, float... values),setEvaluator(TypeEvaluator value)处理** -**原三方库:** - -```java - Skill s = (Skill) view.getTag(); - AnimatorSet set = new AnimatorSet(); - mTarget.setTranslationX(0); - mTarget.setTranslationY(0); - ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mTarget, "translationY", 0, dipToPixels(MyActivity.this, -(157))); - set.playTogether( - Glider.glide(s, 1200, objectAnimator, new BaseEasingMethod.EasingListener() { - @Override - public void on(float time, float value, float start, float end, float duration) { - - mHistory.drawPoint(time, duration, value - dipToPixels(MyActivity.this, 60)); - } - }) - ); - set.setDuration(1200); - set.start(); - -``` - -```java -public abstract class BaseEasingMethod implements TypeEvaluator { - protected float mDuration; - - private ArrayList mListeners = new ArrayList(); - - public interface EasingListener { - public void on(float time, float value, float start, float end, float duration); - } - - public void addEasingListener(EasingListener l){ - mListeners.add(l); - } - - public void addEasingListeners(EasingListener ...ls){ - for(EasingListener l : ls){ - mListeners.add(l); - } - } - - public void removeEasingListener(EasingListener l){ - mListeners.remove(l); - } - - public void clearEasingListeners(){ - mListeners.clear(); - } - - public BaseEasingMethod(float duration){ - mDuration = duration; - } - - public void setDuration(float duration) { - mDuration = duration; - } - - @Override - public final Float evaluate(float fraction, Number startValue, Number endValue){ - float t = mDuration * fraction; - float b = startValue.floatValue(); - float c = endValue.floatValue() - startValue.floatValue(); - float d = mDuration; - float result = calculate(t,b,c,d); - for(EasingListener l : mListeners){ - l.on(t,result,b,c,d); - } - return result; - } - - public abstract Float calculate(float t, float b, float c, float d); - -} - - -``` - -```java -public class Glider { - - public static ValueAnimator glide(Skill skill, float duration, ValueAnimator animator) { - return Glider.glide(skill, duration, animator, (BaseEasingMethod.EasingListener[]) null); - } - - public static ValueAnimator glide(Skill skill, float duration, ValueAnimator animator, BaseEasingMethod.EasingListener... listeners) { - BaseEasingMethod t = skill.getMethod(duration); - - if (listeners != null) - t.addEasingListeners(listeners); - - animator.setEvaluator(t); - return animator; - } - - public static PropertyValuesHolder glide(Skill skill, float duration, PropertyValuesHolder propertyValuesHolder) { - propertyValuesHolder.setEvaluator(skill.getMethod(duration)); - return propertyValuesHolder; - } - - -} -``` -**openharmony :** -```java -public class MainAbility extends Ability { - - private Component mTarget; - private long mDuration = 2000; - - private DrawView mHistory; - - @Override - public void onStart(Intent intent) { - super.onStart(intent); - super.setUIContent(ResourceTable.Layout_ability_main); - - mTarget = findComponentById(ResourceTable.Id_target); - mHistory = (DrawView) findComponentById(ResourceTable.Id_history); - mHistory.clear(); - - // 动画集合 - AnimatorGroup set = new AnimatorGroup(); - mTarget.setTranslationX(0); - mTarget.setTranslationY(0); - // 数值动画 - AnimatorValue animator = new AnimatorValue(); - animator.setDuration(mDuration); - - // 画最开始的点 - mHistory.drawPoint(0, mDuration, 0 - vpToPixels(getContext(), 60)); - set.runSerially( - glide( animator,new AnimatorValue.ValueUpdateListener() { - @Override - public void onUpdate(AnimatorValue animatorValue, float value) { - - float start = 0; - float end = -vpToPixels(getContext(), 157) ; - float result = evaluate(value, start, end); - mTarget.setTranslationY(result); - mHistory.drawPoint(mDuration * value, mDuration, result - vpToPixels(getContext(), 60)); - } - })); - set.setDuration(mDuration); - set.start(); - - } - - /** - * vp转px - * - * @param context 上下文 - * @param vpValue vp数值 - * @return px - */ - public static float vpToPixels(Context context, float vpValue) { - return AttrHelper.fp2px(vpValue,context); - } - - public Float calculate(float t, float b, float c, float d) { - if ((t/=d) < (1/2.75f)) { - return c*(7.5625f*t*t) + b; - } else if (t < (2/2.75f)) { - return c*(7.5625f*(t-=(1.5f/2.75f))*t + .75f) + b; - } else if (t < (2.5/2.75)) { - return c*(7.5625f*(t-=(2.25f/2.75f))*t + .9375f) + b; - } else { - return c*(7.5625f*(t-=(2.625f/2.75f))*t + .984375f) + b; - } - } - - /** - * 获得动画结果 - * - * @param fraction 动画完成度 - * @param startValue 动画开始位置 - * @param endValue 动画结束位置 - * @return 动画结果 - */ - public final Float evaluate(float fraction, Float startValue, Float endValue){ - float t = mDuration * fraction; - float b = startValue; - float c = endValue- startValue; - float d = mDuration; - float result = calculate(t,b,c,d); - return result; - } - - public static AnimatorValue glide( - - AnimatorValue animator, - AnimatorValue.ValueUpdateListener valueUpdateListener) { - animator.setValueUpdateListener(valueUpdateListener); - return animator; - } -} - +### **ofFloat,ofInt,setEvaluator,setFloatValues** +## 方案一: +>+ openharmony class: ohos.agp.animation.Animator +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案: + +**对于ValueAnimator ofFloat(float... values)处理** +**原三方库:** + +```java +final ValueAnimator valueAnimator = ValueAnimator.ofFloat(values); + valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + @Override + public void onAnimationUpdate(ValueAnimator animation) { + float value = (float) animation.getAnimatedValue(); + } + }); +``` +**openharmony :** +```java +final AnimatorValue animatorValue = new AnimatorValue(); + animatorValue.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() { + @Override + public void onUpdate(AnimatorValue animatorValue, float v) { + float value = AnimatorValueUtils.getAnimatedValue(v,values); + } + }); + +/** + * get the animated value with fraction and values + * + * @param fraction 0~1 + * @param values float array + * @return float animated value + */ +public static float getAnimatedValue(float fraction, float... values){ + if(values == null || values.length == 0){ + return 0; + } + if(values.length == 1){ + return values[0] * fraction; + }else{ + if(fraction == 1){ + return values[values.length-1]; + } + float oneFraction = 1f / (values.length - 1); + float offFraction = 0; + for (int i = 0; i < values.length - 1; i++) { + if (offFraction + oneFraction >= fraction) { + return values[i] + (fraction - offFraction) * (values.length - 1) * (values[i + 1] - values[i]); + } + offFraction += oneFraction; + } + } + return 0; + } +``` + +**对于ValueAnimator ofInt(int... values) + setEvaluator(new ArgbEvaluator())处理** +**原三方库:** +```java + final ValueAnimator valueAnimator = ValueAnimator.ofInt(color)); + valueAnimator.setEvaluator(new ArgbEvaluator()); + valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + @Override + public void onAnimationUpdate(ValueAnimator valueAnimator) { + int color = (int) valueAnimator.getAnimatedValue()); + } + }); +``` +**openharmony :** +```java +final AnimatorValue animatorValue = new AnimatorValue(); + animatorValue.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() { + @Override + public void onUpdate(AnimatorValue animatorValue, float v) { + int color = getAnimatedColor(v,color); + } + }); + + /** + * get the animated value with fraction and values + * + * @param fraction 0~1 + * @param colors color array + * @return int color + */ +public static int getAnimatedColor(float fraction, int... colors){ + if(colors == null || colors.length == 0){ + return 0; + } + if(colors.length == 1){ + return getAnimatedColor(0,colors[0],fraction); + }else{ + if(fraction == 1){ + return colors[colors.length-1]; + } + float oneFraction = 1f / (colors.length - 1); + float offFraction = 0; + for (int i = 0; i < colors.length - 1; i++) { + if (offFraction + oneFraction >= fraction) { + return getAnimatedColor(colors[i], colors[i + 1], (fraction - offFraction) * (colors.length -1)); + } + offFraction += oneFraction; + } + } + return 0; + } + + /** + * get the animated color with start color, end color and fraction + * + * @param fraction 0~1 + * @param from start color + * @param to end color + * @return int color + */ + public static int getAnimatedColor(int from, int to, float fraction) { + RgbColor colorFrom = RgbColor.fromArgbInt(from); + RgbColor colorTo = RgbColor.fromArgbInt(to); + int red = (int) (colorFrom.getRed() + (colorTo.getRed() - colorFrom.getRed()) * fraction); + int blue = (int) (colorFrom.getBlue() + (colorTo.getBlue() - colorFrom.getBlue()) * fraction); + int green = (int) (colorFrom.getGreen() + (colorTo.getGreen() - colorFrom.getGreen()) * fraction); + int alpha = (int) (colorFrom.getAlpha() + (colorTo.getAlpha() - colorFrom.getAlpha()) * fraction); + RgbColor mCurrentColorRgb = new RgbColor(red, green, blue, alpha); + return mCurrentColorRgb.asArgbInt(); + } +``` + +## 方案二: +>+ openharmony API: 无API替换 +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:对于设置自定义`float`初始值和`float`结束值的数值动画,可使用以下自定义类,同理可写出其他自定义初始值和结束值的数值动画类: +``` java + import ohos.agp.animation.AnimatorValue; + + /** + * 可以设置初始值和结束值的数值动画 + */ + public class MyValueAnimator extends AnimatorValue { + + private float start = 0; + private float end = 1; + private ValueUpdateListener myValueUpdateListener; + + /** + * 获取一个自定义初始值和结束值的数值动画对象 + * + * @param start 起始值 + * @param end 结束值 + * @return 自定义初始值和结束值的数值动画对象 + */ + public static MyValueAnimator ofFloat(float start, float end) { + MyValueAnimator myValueAnimator = new MyValueAnimator(); + myValueAnimator.start = start; + myValueAnimator.end = end; + return myValueAnimator; + } + + private MyValueAnimator() { + super.setValueUpdateListener(new ValueUpdateListener() { + @Override + public void onUpdate(AnimatorValue animatorValue, float value) { + value = value * (end - start) + start; + if (myValueUpdateListener != null) { + myValueUpdateListener.onUpdate(animatorValue, value); + } + } + }); + } + + /** + * 设置数值动画的起始值和结束值 + * + * @param start 起始值 + * @param end 结束值 + */ + public void setFloatValues(float start, float end) { + this.start = start; + this.end = end; + } + + @Override + public void setValueUpdateListener(ValueUpdateListener listener) { + this.myValueUpdateListener = listener; + } + + } +``` + +### setFloatValues + +>+ openharmony API: 无API替换 +> +>+ openharmony SDK版本:2.1.1.21 +> +>+ IDE版本:2.1.0.501 +> +>+ 应用场景: +> +> 原三方库调用ValueAnimator.setFloatValues(1, 0),表示此数值动画的fraction将从1变化到0。AnimatorValue类暂时没有类似功能,而是固定从0变化到1,可以给AnimatorValue设置ValueUpdateListener,在其onUpdate(AnimatorValue animatorValue, float v)回调中对v进行处理 v = 1 - v; +> +> 假如所需的端点值为其他情况,例如需要从2到5,则可以将这两个值分别记录为mStartV, mEndV。在onUpdate回调中做如下处理: v = mStartV + v * (mEndV - mStartV) + +### **setInterpolator** + +>+ openharmony class: ohos.agp.animation.Animator +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:原三方库的ValueAnimator.setInterpolator(Interpolator interpolator)用ohos.agp.animation.AnimatorValue.setCurveType(int curveType)代替,其中curveType的int值是ohos.agp.animation.Animator.CurveType类的枚举常量. + +### **setRepeatMode** +>+ openharmony API: 无API替换 +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案: + + 1.定义两个状态常量值和一个Boolean值: +``` java +public final static int RESTART = 1;//正常模式 +public final static int REVERSE = 2;//倒序回放模式 +private int repeatMode = RESTART; +private boolean isBack = false; +``` + + 2.给数值动画设置重复执行时的监听,如下所示: +``` java +animatorValue.setLoopedListener(new Animator.LoopedListener() { + + @Override + public void onRepeat(Animator animator) { + isBack = !isBack; + } + }); +``` + + 3.在数值动画的`ValueUpdate`监听中做如下处理: +``` java +animatorValue.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() { + @Override + public void onUpdate(AnimatorValue animatorValue, float value) { + if (repeatMode == REVERSE && isBack) { + value = 1 - value; + } + //do yourself + } + }); +``` +### **ObjectAnimator ofFloat(Object target, String propertyName, float... values)(一种ohos替换方案)** +>+ openharmony class: ohos.agp.animation.AnimatorValue +>+ openharmony SDK版本:2.1.0.21 +>+ IDE版本:2.1.0.220 +>+ 实现方案: + +**对于ObjectAnimator ofFloat(Object target, String propertyName, float... values)处理** +**原三方库:** +```java + ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mTarget, "translationY", 0, dipToPixels(MyActivity.this, -(100))); + objectAnimator.setDuration(2000); + objectAnimator.start(); +``` +**openharmony :** +```java + // 数值动画 + AnimatorValue animator = new AnimatorValue(); + animator.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() { + @Override + public void onUpdate(AnimatorValue animatorValue, float v) { + mTarget.setTranslationY( - vpToPixels(getContext(), 100) * v); + } + }); + animator.setDuration(2000); + animator.start(); +``` + +### **ObjectAnimator ofFloat(Object target, String propertyName, float... values),setEvaluator(TypeEvaluator value)(一种ohos替换方案)** +>+ openharmony class: ohos.agp.animation.AnimatorValue +>+ openharmony SDK版本:2.1.0.21 +>+ IDE版本:2.1.0.220 +>+ 实现方案: + +**对于ObjectAnimator ofFloat(Object target, String propertyName, float... values),setEvaluator(TypeEvaluator value)处理** +**原三方库:** + +```java + Skill s = (Skill) view.getTag(); + AnimatorSet set = new AnimatorSet(); + mTarget.setTranslationX(0); + mTarget.setTranslationY(0); + ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mTarget, "translationY", 0, dipToPixels(MyActivity.this, -(157))); + set.playTogether( + Glider.glide(s, 1200, objectAnimator, new BaseEasingMethod.EasingListener() { + @Override + public void on(float time, float value, float start, float end, float duration) { + + mHistory.drawPoint(time, duration, value - dipToPixels(MyActivity.this, 60)); + } + }) + ); + set.setDuration(1200); + set.start(); + +``` + +```java +public abstract class BaseEasingMethod implements TypeEvaluator { + protected float mDuration; + + private ArrayList mListeners = new ArrayList(); + + public interface EasingListener { + public void on(float time, float value, float start, float end, float duration); + } + + public void addEasingListener(EasingListener l){ + mListeners.add(l); + } + + public void addEasingListeners(EasingListener ...ls){ + for(EasingListener l : ls){ + mListeners.add(l); + } + } + + public void removeEasingListener(EasingListener l){ + mListeners.remove(l); + } + + public void clearEasingListeners(){ + mListeners.clear(); + } + + public BaseEasingMethod(float duration){ + mDuration = duration; + } + + public void setDuration(float duration) { + mDuration = duration; + } + + @Override + public final Float evaluate(float fraction, Number startValue, Number endValue){ + float t = mDuration * fraction; + float b = startValue.floatValue(); + float c = endValue.floatValue() - startValue.floatValue(); + float d = mDuration; + float result = calculate(t,b,c,d); + for(EasingListener l : mListeners){ + l.on(t,result,b,c,d); + } + return result; + } + + public abstract Float calculate(float t, float b, float c, float d); + +} + + +``` + +```java +public class Glider { + + public static ValueAnimator glide(Skill skill, float duration, ValueAnimator animator) { + return Glider.glide(skill, duration, animator, (BaseEasingMethod.EasingListener[]) null); + } + + public static ValueAnimator glide(Skill skill, float duration, ValueAnimator animator, BaseEasingMethod.EasingListener... listeners) { + BaseEasingMethod t = skill.getMethod(duration); + + if (listeners != null) + t.addEasingListeners(listeners); + + animator.setEvaluator(t); + return animator; + } + + public static PropertyValuesHolder glide(Skill skill, float duration, PropertyValuesHolder propertyValuesHolder) { + propertyValuesHolder.setEvaluator(skill.getMethod(duration)); + return propertyValuesHolder; + } + + +} +``` +**openharmony :** +```java +public class MainAbility extends Ability { + + private Component mTarget; + private long mDuration = 2000; + + private DrawView mHistory; + + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_ability_main); + + mTarget = findComponentById(ResourceTable.Id_target); + mHistory = (DrawView) findComponentById(ResourceTable.Id_history); + mHistory.clear(); + + // 动画集合 + AnimatorGroup set = new AnimatorGroup(); + mTarget.setTranslationX(0); + mTarget.setTranslationY(0); + // 数值动画 + AnimatorValue animator = new AnimatorValue(); + animator.setDuration(mDuration); + + // 画最开始的点 + mHistory.drawPoint(0, mDuration, 0 - vpToPixels(getContext(), 60)); + set.runSerially( + glide( animator,new AnimatorValue.ValueUpdateListener() { + @Override + public void onUpdate(AnimatorValue animatorValue, float value) { + + float start = 0; + float end = -vpToPixels(getContext(), 157) ; + float result = evaluate(value, start, end); + mTarget.setTranslationY(result); + mHistory.drawPoint(mDuration * value, mDuration, result - vpToPixels(getContext(), 60)); + } + })); + set.setDuration(mDuration); + set.start(); + + } + + /** + * vp转px + * + * @param context 上下文 + * @param vpValue vp数值 + * @return px + */ + public static float vpToPixels(Context context, float vpValue) { + return AttrHelper.fp2px(vpValue,context); + } + + public Float calculate(float t, float b, float c, float d) { + if ((t/=d) < (1/2.75f)) { + return c*(7.5625f*t*t) + b; + } else if (t < (2/2.75f)) { + return c*(7.5625f*(t-=(1.5f/2.75f))*t + .75f) + b; + } else if (t < (2.5/2.75)) { + return c*(7.5625f*(t-=(2.25f/2.75f))*t + .9375f) + b; + } else { + return c*(7.5625f*(t-=(2.625f/2.75f))*t + .984375f) + b; + } + } + + /** + * 获得动画结果 + * + * @param fraction 动画完成度 + * @param startValue 动画开始位置 + * @param endValue 动画结束位置 + * @return 动画结果 + */ + public final Float evaluate(float fraction, Float startValue, Float endValue){ + float t = mDuration * fraction; + float b = startValue; + float c = endValue- startValue; + float d = mDuration; + float result = calculate(t,b,c,d); + return result; + } + + public static AnimatorValue glide( + + AnimatorValue animator, + AnimatorValue.ValueUpdateListener valueUpdateListener) { + animator.setValueUpdateListener(valueUpdateListener); + return animator; + } +} + ``` \ No newline at end of file diff --git a/app/Activity.md b/app/Activity.md index 5d7b9ce..b5b5fd1 100644 --- a/app/Activity.md +++ b/app/Activity.md @@ -1,29 +1,29 @@ -### **onConfigurationChanged 监听横竖屏切换** ->+ openharmony class:`ohos.aafwk.ability.Ability` ->+ openharmony SDK版本:2.1.1.21 ->+ IDE版本:2.1.0.501 ->+ 实现方案: - -步骤一:在 `config.json` 中对 ability 增加属性配置 -```json -"abilities": [ - { - "configChanges": [ - "orientation" - ], - } -``` - -步骤二: 监听方向切换 -```java - @Override -protected void onOrientationChanged(AbilityInfo.DisplayOrientation displayOrientation) { - super.onOrientationChanged(displayOrientation); - if (displayOrientation.name().equals("PORTRAIT")) { - // - } else if (displayOrientation.name().equals("LANDSCAPE")) { - // - } - } - -``` +### **onConfigurationChanged 监听横竖屏切换** +>+ openharmony class:`ohos.aafwk.ability.Ability` +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案: + +步骤一:在 `config.json` 中对 ability 增加属性配置 +```json +"abilities": [ + { + "configChanges": [ + "orientation" + ], + } +``` + +步骤二: 监听方向切换 +```java + @Override +protected void onOrientationChanged(AbilityInfo.DisplayOrientation displayOrientation) { + super.onOrientationChanged(displayOrientation); + if (displayOrientation.name().equals("PORTRAIT")) { + // + } else if (displayOrientation.name().equals("LANDSCAPE")) { + // + } + } + +``` diff --git a/app/ActivityManager.md b/app/ActivityManager.md index 4d3483b..1a8f0a9 100644 --- a/app/ActivityManager.md +++ b/app/ActivityManager.md @@ -1,18 +1,18 @@ - -### **MemoryInfo** ->+ openharmony class:`ohos.aafwk.ability.SystemMemoryInfo` ->+ openharmony SDK版本:2.1.1.21 ->+ IDE版本:2.1.0.501 ->+ 实现方案: - -* 原库实现 -```java -MemoryInfo memoryInfo = new MemoryInfo() ; -mActivityManager.getMemoryInfo(memoryInfo) ; -``` -* 替换实现 -```java -SystemMemoryInfo systemMemoryInfo = new SystemMemoryInfo(); -context.getAbilityManager().getSystemMemoryInfo(systemMemoryInfo); -``` - + +### **MemoryInfo** +>+ openharmony class:`ohos.aafwk.ability.SystemMemoryInfo` +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案: + +* 原库实现 +```java +MemoryInfo memoryInfo = new MemoryInfo() ; +mActivityManager.getMemoryInfo(memoryInfo) ; +``` +* 替换实现 +```java +SystemMemoryInfo systemMemoryInfo = new SystemMemoryInfo(); +context.getAbilityManager().getSystemMemoryInfo(systemMemoryInfo); +``` + diff --git a/app/AlarmManager.md b/app/AlarmManager.md new file mode 100644 index 0000000..3eccef9 --- /dev/null +++ b/app/AlarmManager.md @@ -0,0 +1,34 @@ +### setInexactRepeating + +>+ openharmony API:ohos.app.Context.getResourceManager() +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案: + +``` +// 注册消息 +MatchingSkills matchingSkills = new MatchingSkills(); +matchingSkills.addEvent(PING_ALARM_ACTION); +CommonEventSubscribeInfo subscribeInfo = new CommonEventSubscribeInfo(matchingSkills); +ALARM_BROADCAST_RECEIVER = new AlarmStateEventSubscriber(subscribeInfo); +try { + CommonEventManager.subscribeCommonEvent(ALARM_BROADCAST_RECEIVER); +} catch (RemoteException e) { + HiLog.info(label, "subscribeCommonEvent occur exception."); +} + +CommonEventPublishInfo publishInfo = new CommonEventPublishInfo(); +publishInfo.setOrdered(true); // 设置属性为有序公共事件 +Intent intentPermissions = new Intent(); +Operation operationPermissions = new Intent.OperationBuilder() + .withAction(PING_ALARM_ACTION) + .build(); +intentPermissions.setOperation(operationPermissions); +CommonEventData eventDataPermissions = new CommonEventData(intentPermissions); +try { + CommonEventManager.publishCommonEvent(eventDataPermissions, publishInfo); +} catch (RemoteException e) { + HiLog.info(label, "publishCommoneEvent occur exception."); +} +``` + diff --git a/app/Application.md b/app/Application.md new file mode 100644 index 0000000..a8f9e0b --- /dev/null +++ b/app/Application.md @@ -0,0 +1,18 @@ +### app.Application + +>+ openharmony class:ohos.aafwk.ability.AbilityPackage +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案: + +``` +public class MyApplication extends AbilityPackage { + + @Override + public void onInitialize() { + super.onInitialize(); + } + +} +``` + diff --git a/app/Dialog.md b/app/Dialog.md new file mode 100644 index 0000000..e8116dc --- /dev/null +++ b/app/Dialog.md @@ -0,0 +1,9 @@ +### app.Dialog + +>+ openharmony class:ohos.agp.window.dialog.CommonDialog +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 使用场景:弹框展示 +>+ 实现方案: + +直接替换 \ No newline at end of file diff --git a/app/Fragment.md b/app/Fragment.md new file mode 100644 index 0000000..e90aede --- /dev/null +++ b/app/Fragment.md @@ -0,0 +1,15 @@ +### app.Fragment + +>+ openharmony API:ohos.aafwk.ability.fraction.Fraction +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 页面以Fraction形式呈现 +>+ 实现方案: + +``` +stackContainer = (StackLayout) findComponentById(ResourceTable.Id_stackContainer); + ((FractionAbility) getAbility()).getFractionManager() + .startFractionScheduler() + .add(ResourceTable.Id_stackContainer, new RetainingCountriesFraction(this)) + .submit(); +``` \ No newline at end of file diff --git a/app/PendingIntent.md b/app/PendingIntent.md new file mode 100644 index 0000000..4c7d19f --- /dev/null +++ b/app/PendingIntent.md @@ -0,0 +1,9 @@ +### app.PendingIntent + +>+ openharmony API:ohos.event.intentagent.IntentAgent +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景:intent跳转 +>+ 实现方案: + +直接替换使用 \ No newline at end of file diff --git a/app/Service.md b/app/Service.md new file mode 100644 index 0000000..df3b086 --- /dev/null +++ b/app/Service.md @@ -0,0 +1,53 @@ +### app.Service + +>+ openharmony API:ohos.aafwk.ability.Ability +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景:开启后台服务执行任务,需要在后台监听AndSever服务运行状态 +>+ 实现方案: + +``` +public class ServiceAbility extends Ability { + + @Override + public void onStart(Intent intent) { + super.onStart(intent); + } + + @Override + public void onCommand(Intent intent, boolean restart, int startId) { + super.onCommand(intent, restart, startId); + + } + + @Override + public IRemoteObject onConnect(Intent intent) { + super.onConnect(intent); + return null; + } + + @Override + public void onDisconnect(Intent intent) { + super.onDisconnect(intent); + } + + @Override + public void onStop() { + super.onStop(); + } + + /** + * Start server. + */ + private void startServer() { + } + + /** + * Stop server. + */ + private void stopServer() { + } + +} +``` + diff --git a/bluetooth/AdvertiseData.md b/bluetooth/AdvertiseData.md new file mode 100644 index 0000000..3933cba --- /dev/null +++ b/bluetooth/AdvertiseData.md @@ -0,0 +1,28 @@ +### bluetooth.le.AdvertiseData + +>+ openharmony API : ohos.bluetooth.ble.BleAdvertiseData +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 获取蓝牙操作对象 +>+ 实现方案: + +``` +public void startAdvertising(final byte[] payload, final BleAdvertiseSettings advertiseSettings){ + + if (bluetoothAdapter.getBtState()==BluetoothHost.STATE_TURNING_ON){ + mHandler.removeTask(stopAvertiseRunnable); + if(mAdvertiser != null){ + ThreadUtils.asyn(new Runnable() { + @Override + public void run() { + mAdvertiser.stopAdvertising(); + myAdvertiseData = new BleAdvertiseData/*AdvertiseData*/.Builder() + .addManufacturerData(65520, payload) + .build(); + mAdvertiser.startAdvertising(advertiseSettings, myAdvertiseData,null); + } + }); + } + } +} +``` \ No newline at end of file diff --git a/bluetooth/BluetoothAdapter.md b/bluetooth/BluetoothAdapter.md index 3e01684..56a8154 100644 --- a/bluetooth/BluetoothAdapter.md +++ b/bluetooth/BluetoothAdapter.md @@ -1,45 +1,45 @@ -### **disable** ->+ openharmony API:ohos.bluetooth.BluetoothHost.disableBt ->+ openharmony SDK版本:2.1.1.21 ->+ IDE版本:2.1.0.501 ->+ 实现方案:BluetoothHost.disableBt() - -### **enable** ->+ openharmony API:ohos.bluetooth.BluetoothHost.enableBt ->+ openharmony SDK版本:2.1.1.21 ->+ IDE版本:2.1.0.501 ->+ 实现方案:BluetoothHost.enableBt() - ->+ 补充说明:调用enableBt()前需要判断蓝牙状态,直接调用hui会弹出蓝牙开关的对话框 - if (bluetoothHost.getBtState()== BluetoothHost.STATE_OFF){ - //此API会弹出蓝牙开关的对话框,需要配置"ohos.permission.DISCOVER_BLUETOOTH"权限 - bluetoothHost.enableBt(); - } - -### **cancelDiscovery** ->+ openharmony API:ohos.bluetooth.BluetoothHost.cancelBtDiscovery ->+ openharmony SDK版本:2.1.1.21 ->+ IDE版本:2.1.0.501 ->+ 实现方案:bluetoothHost.cancelBtDiscovery() - -### **checkBluetoothAddress** ->+ openharmony API:ohos.bluetooth.BluetoothHost.isValidBluetoothAddr ->+ openharmony SDK版本:2.1.1.21 ->+ IDE版本:2.1.0.501 ->+ 实现方案:bluetoothHost.isValidBluetoothAddr(String) - -### **isEnabled** ->+ openharmony API:ohos.bluetooth.BluetoothHost.getBtState ->+ openharmony SDK版本:2.1.1.21 ->+ IDE版本:2.1.0.501 ->+ 实现方案:使用bluetoothHost.getBtState()获取蓝牙状态,再调用enableBt()方法 - -### **getName** ->+ openharmony API:ohos.bluetooth.BluetoothHost.getLocalName ->+ openharmony SDK版本:2.1.1.21 ->+ IDE版本:2.1.0.501 ->+ 实现方案:bluetoothHost.getLocalName() - - - - +### **disable** +>+ openharmony API:ohos.bluetooth.BluetoothHost.disableBt +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案:BluetoothHost.disableBt() + +### **enable** +>+ openharmony API:ohos.bluetooth.BluetoothHost.enableBt +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案:BluetoothHost.enableBt() + +>+ 补充说明:调用enableBt()前需要判断蓝牙状态,直接调用hui会弹出蓝牙开关的对话框 + if (bluetoothHost.getBtState()== BluetoothHost.STATE_OFF){ + //此API会弹出蓝牙开关的对话框,需要配置"ohos.permission.DISCOVER_BLUETOOTH"权限 + bluetoothHost.enableBt(); + } + +### **cancelDiscovery** +>+ openharmony API:ohos.bluetooth.BluetoothHost.cancelBtDiscovery +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案:bluetoothHost.cancelBtDiscovery() + +### **checkBluetoothAddress** +>+ openharmony API:ohos.bluetooth.BluetoothHost.isValidBluetoothAddr +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案:bluetoothHost.isValidBluetoothAddr(String) + +### **isEnabled** +>+ openharmony API:ohos.bluetooth.BluetoothHost.getBtState +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案:使用bluetoothHost.getBtState()获取蓝牙状态,再调用enableBt()方法 + +### **getName** +>+ openharmony API:ohos.bluetooth.BluetoothHost.getLocalName +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案:bluetoothHost.getLocalName() + + + + diff --git a/bluetooth/BluetoothGatt.md b/bluetooth/BluetoothGatt.md new file mode 100644 index 0000000..0626ed0 --- /dev/null +++ b/bluetooth/BluetoothGatt.md @@ -0,0 +1,21 @@ +### bluetooth.BluetoothGatt + +>+ openharmony API:ohos.bluetooth.ble.BlePeripheralDevice +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 获取蓝牙操作对象 +>+ 实现方案: + +``` +@Override +public void connectionStateChangeEvent(BlePeripheralDevice device, int interval, int latency, int timeout, int status){ + + if (status == ProfileBase.STATE_CONNECTED) { + // 中心设备连接服务端成功 + deviceAddr = device.getDeviceAddr(); + gatt = device; + } + +} +``` + diff --git a/content/BroadcastReceiver.md b/content/BroadcastReceiver.md new file mode 100644 index 0000000..6de3f87 --- /dev/null +++ b/content/BroadcastReceiver.md @@ -0,0 +1,23 @@ +### content.BroadcastReceiver + +>+ openharmony API:ohos.event.commonevent.CommonEventSubscriber +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 通过广播订阅传递数据 +>+ 实现方案: + +``` +public class MyCommonEventSubscriber extends CommonEventSubscriber { + + public MyCommonEventSubscriber(CommonEventSubscribeInfo subscribeInfo) { + super(subscribeInfo); + + } + + @Override + public void onReceiveEvent(CommonEventData commonEventData) { + // do something + } +} +``` + diff --git a/content/ColorStateList.md b/content/ColorStateList.md index 20c62e6..c3c16a4 100644 --- a/content/ColorStateList.md +++ b/content/ColorStateList.md @@ -1,49 +1,49 @@ - -# ColorStateList -* openharmony API: ohos.agp.components.element.StateElement -* openharmony SDK版本:2.1.1.21 -* IDE版本:2.1.0.501 -* 实现方案: - - -原三方库: - -对TextView设置ColorStateList使其在Normal、Pressed、Focused、Unable四种状态下显示不同的颜色 -``` java - /** 对TextView设置不同状态时其文字颜色。 */ - private ColorStateList createColorStateList(int normal, int pressed, int focused, int unable) { - int[] colors = new int[] { pressed, focused, normal, focused, unable, normal }; - int[][] states = new int[6][]; - states[0] = new int[] { android.R.attr.state_pressed, android.R.attr.state_enabled }; - states[1] = new int[] { android.R.attr.state_enabled, android.R.attr.state_focused }; - states[2] = new int[] { android.R.attr.state_enabled }; - states[3] = new int[] { android.R.attr.state_focused }; - states[4] = new int[] { android.R.attr.state_window_focused }; - states[5] = new int[] {}; - ColorStateList colorList = new ColorStateList(states, colors); - return colorList; -``` - -openharmony: - -需要修改component组件交互效果/背景颜色 -``` java - public Text(Context context, AttrSet attrSet, String styleName) { - super(context, attrSet, styleName); - //通过属性值方式获取 - StateElement backgroudSelector = (StateElement)attrSet.getAttr(styleName).get().getElement(); - - //或者通过以下方式获取 - StateElement backgroudSelector1 = (StateElement)this.getBackgroundElement(); - - Element stateElement1 = backgroudSelector.getStateElement(0); - int[] states1 = backgroudSelector.getStateSet(0); - - Element stateElement2 = backgroudSelector.getStateElement(1); - int[] states2 = backgroudSelector.getStateSet(1); - - StateElement stateElement = new StateElement(); - stateElement.addState(states1,stateElement1); - stateElement.addState(states2,stateElement2); - } + +# ColorStateList +* openharmony API: ohos.agp.components.element.StateElement +* openharmony SDK版本:2.1.1.21 +* IDE版本:2.1.0.501 +* 实现方案: + + +原三方库: + +对TextView设置ColorStateList使其在Normal、Pressed、Focused、Unable四种状态下显示不同的颜色 +``` java + /** 对TextView设置不同状态时其文字颜色。 */ + private ColorStateList createColorStateList(int normal, int pressed, int focused, int unable) { + int[] colors = new int[] { pressed, focused, normal, focused, unable, normal }; + int[][] states = new int[6][]; + states[0] = new int[] { android.R.attr.state_pressed, android.R.attr.state_enabled }; + states[1] = new int[] { android.R.attr.state_enabled, android.R.attr.state_focused }; + states[2] = new int[] { android.R.attr.state_enabled }; + states[3] = new int[] { android.R.attr.state_focused }; + states[4] = new int[] { android.R.attr.state_window_focused }; + states[5] = new int[] {}; + ColorStateList colorList = new ColorStateList(states, colors); + return colorList; +``` + +openharmony: + +需要修改component组件交互效果/背景颜色 +``` java + public Text(Context context, AttrSet attrSet, String styleName) { + super(context, attrSet, styleName); + //通过属性值方式获取 + StateElement backgroudSelector = (StateElement)attrSet.getAttr(styleName).get().getElement(); + + //或者通过以下方式获取 + StateElement backgroudSelector1 = (StateElement)this.getBackgroundElement(); + + Element stateElement1 = backgroudSelector.getStateElement(0); + int[] states1 = backgroudSelector.getStateSet(0); + + Element stateElement2 = backgroudSelector.getStateElement(1); + int[] states2 = backgroudSelector.getStateSet(1); + + StateElement stateElement = new StateElement(); + stateElement.addState(states1,stateElement1); + stateElement.addState(states2,stateElement2); + } ``` \ No newline at end of file diff --git a/content/ComponentName.md b/content/ComponentName.md new file mode 100644 index 0000000..e656406 --- /dev/null +++ b/content/ComponentName.md @@ -0,0 +1,31 @@ +### content.ComponentName + +>+ openharmony API:ohos.bundle.IBundleManager +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 启动某应用或应用内服务时指定包名 +>+ 实现方案: + +直接替换: + +``` +private static String queryAuthority(Context context) { + BundleInfo packageInfos = null; + IBundleManager mgr = context.getBundleManager(); + if (mgr != null) { + try { + packageInfos = mgr.getBundleInfo(context.getBundleName(), 0x00000008); + } catch (RemoteException e) { + e.printStackTrace(); + } + } + if (packageInfos != null && packageInfos.getAbilityInfos() != null) { + for (AbilityInfo providerInfo : packageInfos.getAbilityInfos()) { + if (providerInfo.bundleName.equals(MultiProcessSharedPreferences.class.getName())) { + return providerInfo.label; + } + } + } + return MultiProcessSharedPreferences.class.getName(); +} +``` \ No newline at end of file diff --git a/content/ContentProvider.md b/content/ContentProvider.md index 6f0cc9c..5e5784e 100644 --- a/content/ContentProvider.md +++ b/content/ContentProvider.md @@ -1,109 +1,109 @@ -### **insert** ->+ openharmony API: ohos.aafwk.ability.DataAbilityHelper.insert ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java -DataAbilityHelper helper = DataAbilityHelper.creator(this); - -// 构造插入数据 -ValuesBucket valuesBucket = new ValuesBucket(); -valuesBucket.putString("name", "zhangsan"); -valuesBucket.putInteger("age", 18); -valuesBucket.putFloat("height", 172.0f); -helper.insert(uri, valuesBucket); - -``` - -### **query** ->+ openharmony API: ohos.aafwk.ability.DataAbilityHelper.query ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java -DataAbilityHelper helper = DataAbilityHelper.creator(this); - -// 构造查询条件 -DataAbilityPredicates predicates = new DataAbilityPredicates(); -predicates.between("id", 1, 10); - -// 进行查询 -ResultSet resultSet = helper.query(uri, columns, predicates); - -``` - -### **update** ->+ openharmony API: ohos.aafwk.ability.DataAbilityHelper.update ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java -DataAbilityHelper helper = DataAbilityHelper.creator(this); - -// 构造更新条件 -DataAbilityPredicates predicates = new DataAbilityPredicates(); -predicates.equalTo("id", 1); - -// 构造更新数据 -ValuesBucket valuesBucket = new ValuesBucket(); -valuesBucket.putString("name", "zhangsan"); -valuesBucket.putInteger("age", 18); -valuesBucket.putFloat("height", 172.0f); -helper.update(uri, valuesBucket, predicates); - -``` - -### **delete** ->+ openharmony API: ohos.aafwk.ability.DataAbilityHelper.delete ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java -DataAbilityHelper helper = DataAbilityHelper.creator(this); - -// 构造删除条件 -DataAbilityPredicates predicates = new DataAbilityPredicates(); -predicates.between("id", 1, 10); -helper.delete(uri, predicates); - -``` - -### **bulkInsert** ->+ openharmony API: ohos.aafwk.ability.DataAbilityHelper.batchInsert ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java -DataAbilityHelper helper = DataAbilityHelper.creator(this); - -// 构造插入数据 -ValuesBucket[] values = new ValuesBucket[2]; -values[0] = new ValuesBucket(); -values[0].putString("name", "zhangsan"); -values[0].putInteger("age", 18); -values[1] = new ValuesBucket(); -values[1].putString("name", "lisi"); -values[1].putInteger("age", 20); -helper.batchInsert(uri, values); - -``` - -### **applyBatch** ->+ openharmony API: ohos.aafwk.ability.DataAbilityHelper.executeBatch ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java -DataAbilityHelper helper = DataAbilityHelper.creator(context, insertUri); - -// 构造批量操作 -ValuesBucket value1 = new ValuesBucket(); -DataAbilityOperation opt1 = DataAbilityOperation.newInsertBuilder(insertUri).withValuesBucket(value1).build(); -ValuesBucket value2 = new ValuesBucket(); -DataAbilityOperation opt2 = DataAbilityOperation.newInsertBuilder(insertUri).withValuesBucket(value2).build(); -List operations = new ArrayList<>(); -operations.add(opt1); -operations.add(opt2); -DataAbilityResult[] result = helper.executeBatch(insertUri, operations); - -``` +### **insert** +>+ openharmony API: ohos.aafwk.ability.DataAbilityHelper.insert +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +DataAbilityHelper helper = DataAbilityHelper.creator(this); + +// 构造插入数据 +ValuesBucket valuesBucket = new ValuesBucket(); +valuesBucket.putString("name", "zhangsan"); +valuesBucket.putInteger("age", 18); +valuesBucket.putFloat("height", 172.0f); +helper.insert(uri, valuesBucket); + +``` + +### **query** +>+ openharmony API: ohos.aafwk.ability.DataAbilityHelper.query +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +DataAbilityHelper helper = DataAbilityHelper.creator(this); + +// 构造查询条件 +DataAbilityPredicates predicates = new DataAbilityPredicates(); +predicates.between("id", 1, 10); + +// 进行查询 +ResultSet resultSet = helper.query(uri, columns, predicates); + +``` + +### **update** +>+ openharmony API: ohos.aafwk.ability.DataAbilityHelper.update +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +DataAbilityHelper helper = DataAbilityHelper.creator(this); + +// 构造更新条件 +DataAbilityPredicates predicates = new DataAbilityPredicates(); +predicates.equalTo("id", 1); + +// 构造更新数据 +ValuesBucket valuesBucket = new ValuesBucket(); +valuesBucket.putString("name", "zhangsan"); +valuesBucket.putInteger("age", 18); +valuesBucket.putFloat("height", 172.0f); +helper.update(uri, valuesBucket, predicates); + +``` + +### **delete** +>+ openharmony API: ohos.aafwk.ability.DataAbilityHelper.delete +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +DataAbilityHelper helper = DataAbilityHelper.creator(this); + +// 构造删除条件 +DataAbilityPredicates predicates = new DataAbilityPredicates(); +predicates.between("id", 1, 10); +helper.delete(uri, predicates); + +``` + +### **bulkInsert** +>+ openharmony API: ohos.aafwk.ability.DataAbilityHelper.batchInsert +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +DataAbilityHelper helper = DataAbilityHelper.creator(this); + +// 构造插入数据 +ValuesBucket[] values = new ValuesBucket[2]; +values[0] = new ValuesBucket(); +values[0].putString("name", "zhangsan"); +values[0].putInteger("age", 18); +values[1] = new ValuesBucket(); +values[1].putString("name", "lisi"); +values[1].putInteger("age", 20); +helper.batchInsert(uri, values); + +``` + +### **applyBatch** +>+ openharmony API: ohos.aafwk.ability.DataAbilityHelper.executeBatch +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +DataAbilityHelper helper = DataAbilityHelper.creator(context, insertUri); + +// 构造批量操作 +ValuesBucket value1 = new ValuesBucket(); +DataAbilityOperation opt1 = DataAbilityOperation.newInsertBuilder(insertUri).withValuesBucket(value1).build(); +ValuesBucket value2 = new ValuesBucket(); +DataAbilityOperation opt2 = DataAbilityOperation.newInsertBuilder(insertUri).withValuesBucket(value2).build(); +List operations = new ArrayList<>(); +operations.add(opt1); +operations.add(opt2); +DataAbilityResult[] result = helper.executeBatch(insertUri, operations); + +``` diff --git a/content/ContentResolver.md b/content/ContentResolver.md index a8c75f6..bbeefcb 100644 --- a/content/ContentResolver.md +++ b/content/ContentResolver.md @@ -1,43 +1,43 @@ - -# ResourceManager -* openharmony API: ohos.global.resource.Resource -* openharmony SDK版本:2.1.1.21 -* IDE版本:2.1.0.501 -* 实现方案: -``` java - public static File readFontFile(Context context,String filePath) { - ResourceManager resManager = context.getResourceManager(); - RawFileEntry rawFileEntry = resManager.getRawFileEntry(filePath); - Resource resource = null; - try { - resource = rawFileEntry.openRawFile(); - } catch (IOException e) { - e.printStackTrace(); - } - StringBuffer fileName = new StringBuffer(filePath); - - File file = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), fileName.toString()); - OutputStream outputStream = null; - try { - outputStream = new FileOutputStream(file); - int index; - byte[] bytes = new byte[1024]; - while ((index = resource.read(bytes)) != -1) { - outputStream.write(bytes, 0, index); - outputStream.flush(); - } - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } finally { - try { - resource.close(); - outputStream.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - return file; - } + +# ResourceManager +* openharmony API: ohos.global.resource.Resource +* openharmony SDK版本:2.1.1.21 +* IDE版本:2.1.0.501 +* 实现方案: +``` java + public static File readFontFile(Context context,String filePath) { + ResourceManager resManager = context.getResourceManager(); + RawFileEntry rawFileEntry = resManager.getRawFileEntry(filePath); + Resource resource = null; + try { + resource = rawFileEntry.openRawFile(); + } catch (IOException e) { + e.printStackTrace(); + } + StringBuffer fileName = new StringBuffer(filePath); + + File file = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), fileName.toString()); + OutputStream outputStream = null; + try { + outputStream = new FileOutputStream(file); + int index; + byte[] bytes = new byte[1024]; + while ((index = resource.read(bytes)) != -1) { + outputStream.write(bytes, 0, index); + outputStream.flush(); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + resource.close(); + outputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + return file; + } ``` \ No newline at end of file diff --git a/content/ContentValues.md b/content/ContentValues.md new file mode 100644 index 0000000..8727596 --- /dev/null +++ b/content/ContentValues.md @@ -0,0 +1,42 @@ +### content.ContentValues + +>+ openharmony API:ohos.data.rdb.ValuesBucket +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 以键值对存储基本类型的数据 +>+ 实现方案: + +因为鸿蒙中该接口缺少参数为hashmap的构造需要进行以下处理: + +``` +private static class ValuesBucketHelper { + public static ValuesBucket from(HashMap map) { + ValuesBucket valuesBucket = new ValuesBucket(); + for (Object o : map.entrySet()) { + Map.Entry entry = (Map.Entry) o; + String key = (String) entry.getKey(); + Object value = entry.getValue(); + if (value instanceof String) { + valuesBucket.putString(key, (String) value); + } else if (value instanceof Integer) { + valuesBucket.putInteger(key, (Integer) value); + } else if (value instanceof Boolean) { + valuesBucket.putBoolean(key, (Boolean) value); + } else if (value instanceof Byte) { + valuesBucket.putByte(key, (Byte) value); + } else if (value instanceof byte[]) { + valuesBucket.putByteArray(key, (byte[]) value); + } else if (value instanceof Double) { + valuesBucket.putDouble(key, (Double) value); + } + } + return valuesBucket; + } +} + +private static class ReflectionUtil { + + public static ValuesBucket contentValuesNewInstance(HashMap values) { + return ValuesBucketHelper.from(values); + } +``` \ No newline at end of file diff --git a/content/Context.md b/content/Context.md index 9faa86d..5cf5fb4 100644 --- a/content/Context.md +++ b/content/Context.md @@ -1,12 +1,66 @@ - -# obtainStyledAttributes -* openharmony API:ohos.agp.components.AttrSet -* openharmony SDK版本:2.1.0.17 -* IDE版本:2.1.0.141 -* 实现方案: -``` java - int mCustomLength = 0; - if(attrSet.getAttr(customXmlName).isPresent()){ - mCustomLength = attrSet.getAttr(customXmlName).get().getDimensionValue(); - } + +## obtainStyledAttributes +* openharmony API:ohos.agp.components.AttrSet +* openharmony SDK版本:2.1.0.17 +* IDE版本:2.1.0.141 +* 实现方案: +``` java + int mCustomLength = 0; + if(attrSet.getAttr(customXmlName).isPresent()){ + mCustomLength = attrSet.getAttr(customXmlName).get().getDimensionValue(); + } +``` + + + +## getRawFile + +* openharmony API:ohos.app.Context.getResourceManager() +* openharmony SDK版本:2.1.1.21 +* IDE版本:2.1.0.501 +* 实现方案: + +``` +ResourceManager resManager = context.getResourceManager(); +RawFileEntry rawFileEntry = resManager.getRawFileEntry(***\*"resources/rawfile/"\****+fileName); +``` + + + +## startService + +* openharmony API:ohos.app.Context.getResourceManager() +* openharmony SDK版本:2.1.1.21 +* IDE版本:2.1.0.501 +* 实现方案: + +``` +Resource resource = null; +try { + resource = context.getResourceManager().getRawFileEntry(imageUri).openRawFile(); +} catch (IOException e) { + e.printStackTrace(); +} +``` + + + +## obtainStyledAttrbutes + +* openharmony API: setPanelLayoutId() +* openharmony SDK版本:2.1.1.21 +* IDE版本:2.1.0.501 +* 应用场景:初始化Panel的所引用的Component +* 实现方案: + +android使用xml的方式,将自定义数据源传入,现在因为数据源是在Library,layou.xml在entry中,没有办法访问到该layout资源。 + +``` +List PanelLayoutId = new ArrayList<>(); + +//构建Panel的LayoutComponent源 PanelLayoutId.add(LayoutScatter.getInstance(getContext()).parse(ResourceTable.Layout_panel_add_layout, null, false)); PanelLayoutId.add(LayoutScatter.getInstance(getContext()).parse(ResourceTable.Layout_panel_add_layout, null, false)); PanelLayoutId.add(LayoutScatter.getInstance(getContext()).parse(ResourceTable.Layout_panel_add_layout, null, false)); +mPanelSwitchLayout = (PanelSwitchLayout) findComponentById(ResourceTable.Id_panel_switch_layout); + +mPanelSwitchLayout.setPanelLayoutId(PanelLayoutId); +mPanelSwitchLayout.onFinishInflate(); ``` \ No newline at end of file diff --git a/content/ContextWrapper.md b/content/ContextWrapper.md new file mode 100644 index 0000000..16d3602 --- /dev/null +++ b/content/ContextWrapper.md @@ -0,0 +1,9 @@ +### content.ContextWrapper.getPackageName() + +>+ openharmony API:ohos.app.AbilityPackage.AbilityContext.getBundleName() +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 获取应用包名 +>+ 实现方案: + +直接替换 \ No newline at end of file diff --git a/content/ServiceConnection.md b/content/ServiceConnection.md new file mode 100644 index 0000000..52fbd22 --- /dev/null +++ b/content/ServiceConnection.md @@ -0,0 +1,29 @@ +### content.ServiceConnection + +>+ openharmony API:ohos.aafwk.ability.IAbilityConnection +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 创建Server实例 +>+ 实现方案: + +``` +// 创建连接回调实例 + private IAbilityConnection mConnection = new IAbilityConnection() { + // 连接到Service的回调 + @Override + public void onAbilityConnectDone(ElementName elementName, IRemoteObject iRemoteObject, int resultCode) { + // 在这里开发者可以拿到服务端传过来IRemoteObject对象,从中解析出服务端传过来的信息 + mBluetoothService = BluetoothServiceStub.asInterface(iRemoteObject); + BluetoothLog.i("onAbilityConnectDone"); + notifyBluetoothManagerReady(); + } + + // 断开与连接的回调 + @Override + public void onAbilityDisconnectDone(ElementName elementName, int resultCode) { + mBluetoothService = null; + } + + }; +``` + diff --git a/content/SharedPreferences.md b/content/SharedPreferences.md new file mode 100644 index 0000000..edba78a --- /dev/null +++ b/content/SharedPreferences.md @@ -0,0 +1,61 @@ +### content.SharedPreferences.PersistentCookieStore + +>+ openharmony API: ohos.data.preferences.Preferences +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景:数据状态保存 +>+ 实现方案: + +``` +public PersistentCookieStore(Context context) { + databaseHelper = new DatabaseHelper(context); + // fileName表示文件名,其取值不能为空,也不能包含路径,默认存储目录可以通过context.getPreferencesDir()获取。 + preferences = databaseHelper.getPreferences(COOKIE_PREFS); + cookies = new HashMap<>(); + + Map prefsMap = preferences.getAll(); + for (Map.Entry entry : prefsMap.entrySet()) { + String[] cookieNames = TextUtils.split((String) entry.getValue(), ","); + + for (String name : cookieNames) { + + String encodedCookie = preferences.getString(name, null); + + if (encodedCookie != null) { + Cookie decodedCookie = decodeCookie(encodedCookie); + if (decodedCookie != null) { + if (!cookies.containsKey(entry.getKey())) { + cookies.put(entry.getKey(), new ConcurrentHashMap()); + } + cookies.get(entry.getKey()).put(name, decodedCookie); + } + } + } + } + } + + public void add(HttpUrl url, Cookie cookie) { + String name = getCookieToken(cookie); + // 添加 host key. 否则有可能抛空. + if (!cookies.containsKey(url.host())) { + cookies.put(url.host(), new ConcurrentHashMap()); + } + // 删除已经有的. + if (cookies.containsKey(url.host())) { + cookies.get(url.host()).remove(name); + } + // 添加新的进去 + cookies.get(url.host()).put(name, cookie); + // 是否保存到 SP 中 + if (cookie.persistent()) { + preferences.putString(url.host(), TextUtils.join(",", cookies.get(url.host()).keySet())); + preferences.putString(name, encodeCookie(new SerializableOkHttpCookies(cookie))); + preferences.flushSync(); + } else { + preferences.delete(url.host()); + preferences.delete(name); + preferences.flushSync(); + } + } +``` + diff --git a/content/res/AssetManager.md b/content/res/AssetManager.md new file mode 100644 index 0000000..6aeb6ce --- /dev/null +++ b/content/res/AssetManager.md @@ -0,0 +1,12 @@ +### AssetManager + +>+ openharmony API:ohos.global.resource.RawFileEntry +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 获取rawfile中文件 +>+ 实现方案: + +``` +RawFileEntry fileEntry = getResourceManager().getRawFileEntry("resources/rawfile"); +``` + diff --git a/content/res/Configuration.md b/content/res/Configuration.md new file mode 100644 index 0000000..d677057 --- /dev/null +++ b/content/res/Configuration.md @@ -0,0 +1,9 @@ +### Configuration + +>+ openharmony API:ohos.global.configuration.Configuration +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 用于窗体配置 +>+ 实现方案: + +直接替换 \ No newline at end of file diff --git a/content/res/Resources.md b/content/res/Resources.md new file mode 100644 index 0000000..f20955a --- /dev/null +++ b/content/res/Resources.md @@ -0,0 +1,10 @@ +### content.res.Resources.getColor + +>+ openharmony API:ohos.global.resource.ResourceManager.getElement(resId).getColor() +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 资源id获取色彩资源 +>+ 实现方案: + +需要先getElement再按照Color类型get + diff --git a/content/res/TypedArray.md b/content/res/TypedArray.md index 8110e62..35278a0 100644 --- a/content/res/TypedArray.md +++ b/content/res/TypedArray.md @@ -1,65 +1,65 @@ -# TypedArray -* openharmony API: ohos.agp.components.AttrSet -* openharmony SDK版本:2.0.1.93及以上 -* IDE版本:2.0.12.131 -* 实现方案:自定义Component时添加自定义属性 -## 新建一个java文件,配置需要的属性key -```java -public class AttrSetString { - /** 幅值的大小,默认为100dp */ - public static String SIDEBAR_A = "SideBar_a"; - - /** 文本滚动时字体大小,defaultalut :1 */ - public static String SIDEBAR_FONTSCALE = "SideBar_fontScale"; - - /** 大文本大小,默认是文本大小的3倍 */ - public static String SIDEBAR_BIGTEXTSIZE = "SideBar_bigTextSize"; - - /** BigText到峰值的距离,默认50dp */ - public static String SIDEBAR_GAPBETWEENTEXT = "SideBar_gapBetweenText"; - - /** 抛物线开度大小,defaultalut 13 */ - public static String SIDEBAR_OPENCOUNT = "SideBar_openCount"; -} - ``` -## 在xml中设置参数 -```java - - ``` -## 在自定义控件中使用 -```java -public class SideBar extends Text { - private float amplitude = dp(100); - private float fontScale = 1; - private int gapBetweenText = dp(50); - private int openCount = 13; - private float bigTextSize; - - public SideBar(Context context, AttrSet attrs) { - super(context, attrs); - mContext = context; - init(attrs); - } - - private void init(AttrSet attrs) { - amplitude = attrs.getAttr(SIDEBAR_A).isPresent() ? attrs.getAttr(SIDEBAR_A).get().getFloatValue() : 100.0f; - fontScale = attrs.getAttr(SIDEBAR_FONTSCALE).isPresent() ? attrs.getAttr(SIDEBAR_FONTSCALE).get().getFloatValue() : 1; - bigTextSize = attrs.getAttr(SIDEBAR_BIGTEXTSIZE).isPresent() ? attrs.getAttr(SIDEBAR_BIGTEXTSIZE).get().getFloatValue() : getTextSize() * 3; - gapBetweenText = attrs.getAttr(SIDEBAR_GAPBETWEENTEXT).isPresent() ? attrs.getAttr(SIDEBAR_GAPBETWEENTEXT).get().getIntegerValue() : dp(50); - openCount = attrs.getAttr(SIDEBAR_OPENCOUNT).isPresent() ? attrs.getAttr(SIDEBAR_OPENCOUNT).get().getIntegerValue() : 13; - } - -} - - - +# TypedArray +* openharmony API: ohos.agp.components.AttrSet +* openharmony SDK版本:2.0.1.93及以上 +* IDE版本:2.0.12.131 +* 实现方案:自定义Component时添加自定义属性 +## 新建一个java文件,配置需要的属性key +```java +public class AttrSetString { + /** 幅值的大小,默认为100dp */ + public static String SIDEBAR_A = "SideBar_a"; + + /** 文本滚动时字体大小,defaultalut :1 */ + public static String SIDEBAR_FONTSCALE = "SideBar_fontScale"; + + /** 大文本大小,默认是文本大小的3倍 */ + public static String SIDEBAR_BIGTEXTSIZE = "SideBar_bigTextSize"; + + /** BigText到峰值的距离,默认50dp */ + public static String SIDEBAR_GAPBETWEENTEXT = "SideBar_gapBetweenText"; + + /** 抛物线开度大小,defaultalut 13 */ + public static String SIDEBAR_OPENCOUNT = "SideBar_openCount"; +} + ``` +## 在xml中设置参数 +```java + + ``` +## 在自定义控件中使用 +```java +public class SideBar extends Text { + private float amplitude = dp(100); + private float fontScale = 1; + private int gapBetweenText = dp(50); + private int openCount = 13; + private float bigTextSize; + + public SideBar(Context context, AttrSet attrs) { + super(context, attrs); + mContext = context; + init(attrs); + } + + private void init(AttrSet attrs) { + amplitude = attrs.getAttr(SIDEBAR_A).isPresent() ? attrs.getAttr(SIDEBAR_A).get().getFloatValue() : 100.0f; + fontScale = attrs.getAttr(SIDEBAR_FONTSCALE).isPresent() ? attrs.getAttr(SIDEBAR_FONTSCALE).get().getFloatValue() : 1; + bigTextSize = attrs.getAttr(SIDEBAR_BIGTEXTSIZE).isPresent() ? attrs.getAttr(SIDEBAR_BIGTEXTSIZE).get().getFloatValue() : getTextSize() * 3; + gapBetweenText = attrs.getAttr(SIDEBAR_GAPBETWEENTEXT).isPresent() ? attrs.getAttr(SIDEBAR_GAPBETWEENTEXT).get().getIntegerValue() : dp(50); + openCount = attrs.getAttr(SIDEBAR_OPENCOUNT).isPresent() ? attrs.getAttr(SIDEBAR_OPENCOUNT).get().getIntegerValue() : 13; + } + +} + + + ``` \ No newline at end of file diff --git a/content/res/XmlResourceParser.md b/content/res/XmlResourceParser.md index f1dc988..66a2bea 100644 --- a/content/res/XmlResourceParser.md +++ b/content/res/XmlResourceParser.md @@ -1,57 +1,57 @@ -### **getAttributeResourceValue** ->+ openharmony API: ohos.javax.xml.stream.XMLStreamReader.getAttributeValue ->+ openharmony SDK版本:2.1.0.17 以上 ->+ IDE版本:2.1.0.141 ->+ 实现方案:由于ohos.javax.xml.stream.XMLInputFactory只能解析xml得到基础的文本string,所以如果xml文件中的value使用的是型如$media:icon的引用型时,需要进行特殊的处理。 - -android assets/xml -```xml - - - -``` -harmony rawfile/xml -```xml - - - -``` -此时通过XMLStreamReader.getAttributeValue能得到的是一个String值"$media:i0",而我们需要的是icon图标的resId,此时我们可以通过icon的名字去反射entry/ResourceTable中的icon的resId,代码如下: -```java - /** - * invoke the resId of app bundle - * - * @param context for get package name - * @param referenceStr for example {$media:i0_selected} - * @return resource id - */ - public static int invokeResId(Context context, String referenceStr) { - String[] split = referenceStr.split(":"); - String type = split[0].substring(1); - String fieldName = type.substring(0, 1).toUpperCase(Locale.ROOT) + type.substring(1) + "_" + split[1]; - try { - Class aClass = Class.forName(context.getBundleName() + ".ResourceTable"); - Field field = aClass.getDeclaredField(fieldName); - return field.getInt(null); - } catch (Exception e) { - logger.log(Level.INFO, e.getMessage()); - } - return -1; - } -``` -其他引用类型的value如"$color:myred"同样可以通过以上方式获取到resId进而拿到myred具体的颜色值 - -### **getAttributeBooleanValue** ->+ openharmony API: ohos.javax.xml.stream.XMLStreamReader.getAttributeValue ->+ openharmony SDK版本:2.1.0.17 以上 ->+ IDE版本:2.1.0.141 ->+ 实现方案: -```java -Boolean.parseBoolean(xMLStreamReader.getAttributeValue(i)); +### **getAttributeResourceValue** +>+ openharmony API: ohos.javax.xml.stream.XMLStreamReader.getAttributeValue +>+ openharmony SDK版本:2.1.0.17 以上 +>+ IDE版本:2.1.0.141 +>+ 实现方案:由于ohos.javax.xml.stream.XMLInputFactory只能解析xml得到基础的文本string,所以如果xml文件中的value使用的是型如$media:icon的引用型时,需要进行特殊的处理。 + +android assets/xml +```xml + + + +``` +harmony rawfile/xml +```xml + + + +``` +此时通过XMLStreamReader.getAttributeValue能得到的是一个String值"$media:i0",而我们需要的是icon图标的resId,此时我们可以通过icon的名字去反射entry/ResourceTable中的icon的resId,代码如下: +```java + /** + * invoke the resId of app bundle + * + * @param context for get package name + * @param referenceStr for example {$media:i0_selected} + * @return resource id + */ + public static int invokeResId(Context context, String referenceStr) { + String[] split = referenceStr.split(":"); + String type = split[0].substring(1); + String fieldName = type.substring(0, 1).toUpperCase(Locale.ROOT) + type.substring(1) + "_" + split[1]; + try { + Class aClass = Class.forName(context.getBundleName() + ".ResourceTable"); + Field field = aClass.getDeclaredField(fieldName); + return field.getInt(null); + } catch (Exception e) { + logger.log(Level.INFO, e.getMessage()); + } + return -1; + } +``` +其他引用类型的value如"$color:myred"同样可以通过以上方式获取到resId进而拿到myred具体的颜色值 + +### **getAttributeBooleanValue** +>+ openharmony API: ohos.javax.xml.stream.XMLStreamReader.getAttributeValue +>+ openharmony SDK版本:2.1.0.17 以上 +>+ IDE版本:2.1.0.141 +>+ 实现方案: +```java +Boolean.parseBoolean(xMLStreamReader.getAttributeValue(i)); ``` \ No newline at end of file diff --git a/core.app.NotificationCompat/NotificationCompat.md b/core.app.NotificationCompat/NotificationCompat.md new file mode 100644 index 0000000..6159c77 --- /dev/null +++ b/core.app.NotificationCompat/NotificationCompat.md @@ -0,0 +1,21 @@ +### fragment.app.DialogFragment + +>+ openharmony API : 无 +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: base对话框 +>+ 实现方案: + +``` +public abstract class BaseDialogFragment extends CommonDialog { + + protected int mRequestCode; + protected boolean mCancelableOnTouchOutside; + protected PacMap mPacMap; + protected Context mContext; + + public BaseDialogFragment(Context context) { + super(context); + this.mContext = context; + } +``` \ No newline at end of file diff --git a/database/Cursor.md b/database/Cursor.md index b82d331..6e9f23e 100644 --- a/database/Cursor.md +++ b/database/Cursor.md @@ -1,114 +1,114 @@ -### **getCount()** ->+ openharmony API: `ohos.data.resultset.ResultSet` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:使用`getRowCount()`方法 - -### **getPosition()** ->+ openharmony API: `ohos.data.resultset.ResultSet` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:使用`getRowIndex()`方法 - -### **move(int)** ->+ openharmony API: `ohos.data.resultset.ResultSet` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:使用`goTo(int)`方法 - -### **moveToPosition(int)** ->+ openharmony API: `ohos.data.resultset.ResultSet` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:使用`goToRow(int)`方法 - -### **moveToFirst()** ->+ openharmony API: `ohos.data.resultset.ResultSet` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:使用`goToFirstRow()`方法 - - -### **moveToLast()** ->+ openharmony API: `ohos.data.resultset.ResultSet` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:使用`goToLastRow()`方法 - -### **moveToNext()** ->+ openharmony API: `ohos.data.resultset.ResultSet` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:使用`goToNextRow()`方法 - -### **moveToPrevious()** ->+ openharmony API: `ohos.data.resultset.ResultSet` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:使用`goToPreviousRow()`方法 - -### **getColumnIndex(String)** ->+ openharmony API: `ohos.data.resultset.ResultSet` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:使用`getColumnIndexForName(String)`方法 - -### **getColumnIndexOrThrow(String)** ->+ openharmony API: `ohos.data.resultset.ResultSet` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:使用`getColumnIndexForName(String)`方法 - -### **getColumnName(int)** ->+ openharmony API: `ohos.data.resultset.ResultSet` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:使用`getColumnNameForIndex(int)`方法 - -### **getColumnCount()** ->+ openharmony API: `ohos.data.resultset.ResultSet` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:使用`getColumnCount()`方法 - -### **getColumnNames()** ->+ openharmony API: `ohos.data.resultset.ResultSet` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:使用`getAllColumnNames()`方法 - -### **registerDataSetObserver(DataSetObserver)** ->+ openharmony API: `ohos.data.resultset.ResultSet` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:使用`registerObserver(DataObserver)`方法 - -### **unregisterDataSetObserver(DataSetObserver)** ->+ openharmony API: `ohos.data.resultset.ResultSet` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:使用`unregisterObserver(DataObserver)`方法 - -### **setNotificationUris(ContentResolver,List)** ->+ openharmony API: `ohos.data.resultset.ResultSet` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:使用`setAffectedByUris(Object,List)`方法 - -### **setExtras(Bundle)** ->+ openharmony API: `ohos.data.resultset.ResultSet` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:使用`setExtensions(PacMap)`方法 - -### **getExtras()** ->+ openharmony API: `ohos.data.resultset.ResultSet` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:使用`getExtensions()`方法 - -### **close()** ->+ openharmony API: `ohos.data.resultset.ResultSet` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 +### **getCount()** +>+ openharmony API: `ohos.data.resultset.ResultSet` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:使用`getRowCount()`方法 + +### **getPosition()** +>+ openharmony API: `ohos.data.resultset.ResultSet` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:使用`getRowIndex()`方法 + +### **move(int)** +>+ openharmony API: `ohos.data.resultset.ResultSet` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:使用`goTo(int)`方法 + +### **moveToPosition(int)** +>+ openharmony API: `ohos.data.resultset.ResultSet` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:使用`goToRow(int)`方法 + +### **moveToFirst()** +>+ openharmony API: `ohos.data.resultset.ResultSet` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:使用`goToFirstRow()`方法 + + +### **moveToLast()** +>+ openharmony API: `ohos.data.resultset.ResultSet` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:使用`goToLastRow()`方法 + +### **moveToNext()** +>+ openharmony API: `ohos.data.resultset.ResultSet` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:使用`goToNextRow()`方法 + +### **moveToPrevious()** +>+ openharmony API: `ohos.data.resultset.ResultSet` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:使用`goToPreviousRow()`方法 + +### **getColumnIndex(String)** +>+ openharmony API: `ohos.data.resultset.ResultSet` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:使用`getColumnIndexForName(String)`方法 + +### **getColumnIndexOrThrow(String)** +>+ openharmony API: `ohos.data.resultset.ResultSet` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:使用`getColumnIndexForName(String)`方法 + +### **getColumnName(int)** +>+ openharmony API: `ohos.data.resultset.ResultSet` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:使用`getColumnNameForIndex(int)`方法 + +### **getColumnCount()** +>+ openharmony API: `ohos.data.resultset.ResultSet` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:使用`getColumnCount()`方法 + +### **getColumnNames()** +>+ openharmony API: `ohos.data.resultset.ResultSet` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:使用`getAllColumnNames()`方法 + +### **registerDataSetObserver(DataSetObserver)** +>+ openharmony API: `ohos.data.resultset.ResultSet` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:使用`registerObserver(DataObserver)`方法 + +### **unregisterDataSetObserver(DataSetObserver)** +>+ openharmony API: `ohos.data.resultset.ResultSet` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:使用`unregisterObserver(DataObserver)`方法 + +### **setNotificationUris(ContentResolver,List)** +>+ openharmony API: `ohos.data.resultset.ResultSet` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:使用`setAffectedByUris(Object,List)`方法 + +### **setExtras(Bundle)** +>+ openharmony API: `ohos.data.resultset.ResultSet` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:使用`setExtensions(PacMap)`方法 + +### **getExtras()** +>+ openharmony API: `ohos.data.resultset.ResultSet` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:使用`getExtensions()`方法 + +### **close()** +>+ openharmony API: `ohos.data.resultset.ResultSet` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 >+ 实现方案:使用`close()`方法 \ No newline at end of file diff --git a/database/DataSetObserver.md b/database/DataSetObserver.md index 817f563..986a2bb 100644 --- a/database/DataSetObserver.md +++ b/database/DataSetObserver.md @@ -1,6 +1,6 @@ - -### **onChanged()** ->+ openharmony API: `ohos.data.rdb.DataObserver` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 + +### **onChanged()** +>+ openharmony API: `ohos.data.rdb.DataObserver` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 >+ 实现方案:使用`onChanged()`方法 \ No newline at end of file diff --git a/database/MatrixCursor.md b/database/MatrixCursor.md index 5c223d3..47a4a43 100644 --- a/database/MatrixCursor.md +++ b/database/MatrixCursor.md @@ -1,37 +1,37 @@ - -### **getCount()** ->+ openharmony API: `ohos.data.resultset.TableResultSet` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:使用`getRowCount()`方法 - - -### **getInt()** ->+ openharmony API: `ohos.data.resultset.TableResultSet` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:使用`getInt(int)`方法 - -### **getLong()** ->+ openharmony API: `ohos.data.resultset.TableResultSet` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:使用`getLong(int)`方法 - -### **getString()** ->+ openharmony API: `ohos.data.resultset.TableResultSet` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:使用`getString(int)`方法 - -### **getColumnNames()** ->+ openharmony API: `ohos.data.resultset.TableResultSet` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:使用`getAllColumnNames()`方法 - -### **isNull()** ->+ openharmony API: `ohos.data.resultset.TableResultSet` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 + +### **getCount()** +>+ openharmony API: `ohos.data.resultset.TableResultSet` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:使用`getRowCount()`方法 + + +### **getInt()** +>+ openharmony API: `ohos.data.resultset.TableResultSet` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:使用`getInt(int)`方法 + +### **getLong()** +>+ openharmony API: `ohos.data.resultset.TableResultSet` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:使用`getLong(int)`方法 + +### **getString()** +>+ openharmony API: `ohos.data.resultset.TableResultSet` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:使用`getString(int)`方法 + +### **getColumnNames()** +>+ openharmony API: `ohos.data.resultset.TableResultSet` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:使用`getAllColumnNames()`方法 + +### **isNull()** +>+ openharmony API: `ohos.data.resultset.TableResultSet` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 >+ 实现方案:使用`isColumnNull(int)`方法 \ No newline at end of file diff --git a/database/sqlite/SQLiteDatabase.md b/database/sqlite/SQLiteDatabase.md index 72bfaf2..c6df7f9 100644 --- a/database/sqlite/SQLiteDatabase.md +++ b/database/sqlite/SQLiteDatabase.md @@ -1,60 +1,60 @@ -#### **query()** ->+ openharmony API: `ohos.data.rdb.RdbStore.query()` ->+ openharmony SDK版本:2.1.0.17 以上 ->+ IDE版本:2.1.0.141 ->+ 实现方案和步骤:使用`query(AbsRdbPredicates var1, String[] var2)`方法 - -``` java -RawRdbPredicates rawRdbPredicates = new RawRdbPredicates(getTableName()); - rawRdbPredicates.setWhereClause(selection); - if (selectionArgs == null || selectionArgs.length == 0) { - rawRdbPredicates.setWhereArgs(null); - } else { - rawRdbPredicates.setWhereArgs(Arrays.asList(selectionArgs)); - } - cursor = database.query(rawRdbPredicates, columns); - while (!cursor.isClosed() && cursor.goToNextRow()) { - list.add(parseCursorToBean(cursor)); - } - database.markAsCommit(); -``` - - - - - -#### **update()** ->+ openharmony API: `ohos.data.rdb.RdbStore.update()` ->+ openharmony SDK版本:2.1.0.17 以上 ->+ IDE版本:2.1.0.141 ->+ 实现方案和步骤:使用`update(ValuesBucket var1, AbsRdbPredicates var2)`方法 -``` java - database.beginTransaction(); - RawRdbPredicates rawRdbPredicates = new RawRdbPredicates(getTableName()); - rawRdbPredicates.setWhereClause(whereClause); - if (whereArgs == null || whereArgs.length == 0) { - rawRdbPredicates.setWhereArgs(null); - } else { - rawRdbPredicates.setWhereArgs(Arrays.asList(whereArgs)); - } - database.update(contentValues, rawRdbPredicates); - database.markAsCommit(); -``` - -#### **delete()** ->+ openharmony API: `ohos.data.rdb.RdbStore.delete()` ->+ openharmony SDK版本:2.1.0.17 以上 ->+ IDE版本:2.1.0.141 ->+ 实现方案和步骤:使用` delete(String whereClause, String[] whereArgs) `方法 -``` java - database.beginTransaction(); - RawRdbPredicates rdbPredicates = new RawRdbPredicates(getTableName()); - rdbPredicates.setWhereClause(whereClause); - if (whereArgs == null || whereArgs.length == 0) { - rdbPredicates.setWhereArgs(null); - } else { - rdbPredicates.setWhereArgs(Arrays.asList(whereArgs)); - } - database.delete(rdbPredicates); - database.markAsCommit(); -``` +#### **query()** +>+ openharmony API: `ohos.data.rdb.RdbStore.query()` +>+ openharmony SDK版本:2.1.0.17 以上 +>+ IDE版本:2.1.0.141 +>+ 实现方案和步骤:使用`query(AbsRdbPredicates var1, String[] var2)`方法 + +``` java +RawRdbPredicates rawRdbPredicates = new RawRdbPredicates(getTableName()); + rawRdbPredicates.setWhereClause(selection); + if (selectionArgs == null || selectionArgs.length == 0) { + rawRdbPredicates.setWhereArgs(null); + } else { + rawRdbPredicates.setWhereArgs(Arrays.asList(selectionArgs)); + } + cursor = database.query(rawRdbPredicates, columns); + while (!cursor.isClosed() && cursor.goToNextRow()) { + list.add(parseCursorToBean(cursor)); + } + database.markAsCommit(); +``` + + + + + +#### **update()** +>+ openharmony API: `ohos.data.rdb.RdbStore.update()` +>+ openharmony SDK版本:2.1.0.17 以上 +>+ IDE版本:2.1.0.141 +>+ 实现方案和步骤:使用`update(ValuesBucket var1, AbsRdbPredicates var2)`方法 +``` java + database.beginTransaction(); + RawRdbPredicates rawRdbPredicates = new RawRdbPredicates(getTableName()); + rawRdbPredicates.setWhereClause(whereClause); + if (whereArgs == null || whereArgs.length == 0) { + rawRdbPredicates.setWhereArgs(null); + } else { + rawRdbPredicates.setWhereArgs(Arrays.asList(whereArgs)); + } + database.update(contentValues, rawRdbPredicates); + database.markAsCommit(); +``` + +#### **delete()** +>+ openharmony API: `ohos.data.rdb.RdbStore.delete()` +>+ openharmony SDK版本:2.1.0.17 以上 +>+ IDE版本:2.1.0.141 +>+ 实现方案和步骤:使用` delete(String whereClause, String[] whereArgs) `方法 +``` java + database.beginTransaction(); + RawRdbPredicates rdbPredicates = new RawRdbPredicates(getTableName()); + rdbPredicates.setWhereClause(whereClause); + if (whereArgs == null || whereArgs.length == 0) { + rdbPredicates.setWhereArgs(null); + } else { + rdbPredicates.setWhereArgs(Arrays.asList(whereArgs)); + } + database.delete(rdbPredicates); + database.markAsCommit(); +``` diff --git a/database/sqlite/SQLiteOpenHelper.md b/database/sqlite/SQLiteOpenHelper.md new file mode 100644 index 0000000..42df846 --- /dev/null +++ b/database/sqlite/SQLiteOpenHelper.md @@ -0,0 +1,19 @@ +### getWritableDatabase + +>+ openharmony API: ohos.data. DatabaseHelper +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 创建Server实例 +>+ 实现方案: + +getRdbStore()替换getWritableDatabase(),由空参变为3个入参,并添加回调 + +``` +@override +public void onContentScrolled(Component component,int i,int i1,int i2,int i3) { + if(externalListener != null) { + externalListener.onContentScrolled(component,i,i1,i2,i3); + } +} +``` + diff --git a/fragment.app.Fragment/Fragment.md b/fragment.app.Fragment/Fragment.md new file mode 100644 index 0000000..3bc8b1c --- /dev/null +++ b/fragment.app.Fragment/Fragment.md @@ -0,0 +1,16 @@ +### fragment.app.Fragment.instantiate + +>+ openharmony API : 无 +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 根据Class实例化一个对象 +>+ 实现方案: + +``` +BaseDialogFragment fragment = null; +try { + fragment = mClass.getDeclaredConstructor(Context.class).newInstance(mContext); +} catch (Exception e) { + e.printStackTrace(); +} +``` \ No newline at end of file diff --git a/graphics/Bitmap.md b/graphics/Bitmap.md index 55b8631..621d8d6 100644 --- a/graphics/Bitmap.md +++ b/graphics/Bitmap.md @@ -1,90 +1,90 @@ -openharmony 替换类`ohos.media.image.PixelMap` - -根据来源创建`PixelMap` -```java -ImageSource.SourceOptions options = new ImageSource.SourceOptions(); -ImageSource source = ImageSource.create(data, options); -ImageSource.DecodingOptions decodingOptions = new ImageSource.DecodingOptions(); -PixelMap pixelMap = source.createPixelmap(decodingOptions); -``` -直接创建初始选项的图片 -```java -PixelMap.InitializationOptions opts = new PixelMap.InitializationOptions(); -opts.size = new Size(100,100); -opts.pixelFormat = PixelFormat.ARGB_8888; -PixelMap pixelMap = PixelMap.create(opts); -``` - -### **createBitmap(source,x, y, width, height,matrix,filter)** ->+ openharmony API: ohos.media.image.PixelMap ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:暂无直接替换,需要自己去写,使用方法如下: -```java -public static PixelMap createPixelMap(PixelMap source, int x, int y, int width, int height, - Matrix matrix, boolean filter){ -PixelMap.InitializationOptions initializationOptions = new PixelMap.InitializationOptions(); - -RectFloat srcR = new RectFloat(x, y, x + width,y + height); -RectFloat dstR = new RectFloat(0, 0, width, height); -RectFloat deviceR = new RectFloat(); -Paint paint = new Paint(); -paint.setFilterBitmap(filter); -final boolean transformed = !matrix.rectStaysRect(); -if (transformed) { - paint.setAntiAlias(true); -} -matrix.mapRect(deviceR, dstR); - -int neww = Math.round(deviceR.getWidth()); -int newh = Math.round(deviceR.getHeight()); -initializationOptions.size = new Size(neww,newh); -initializationOptions.scaleMode = ScaleMode.CENTER_CROP; -initializationOptions.alphaType = AlphaType.OPAQUE; -PixelMap srcPixelMap = PixelMap.create(initializationOptions); -Texture texture = new Texture(srcPixelMap); -Canvas canvas = new Canvas(texture); - -canvas.translate(-deviceR.left, -deviceR.top); -canvas.concat(matrix); -canvas.drawPixelMapHolderRect(new PixelMapHolder(source), srcR, dstR, paint); -return srcPixelMap/texture.getPixelMap(); -} - -``` - - -### **getWidth()** ->+ openharmony API: ohos.media.image.common.Size ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:替换使用,使用方法如下: -```java -int width = pixelMap.getImageInfo().size.width; -``` - -### **getHeight()** ->+ openharmony API: ohos.media.image.common.Size ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:替换使用,使用方法如下: -```java -int height = pixelMap.getImageInfo().size.height; -``` -### **getByteCount()** ->+ openharmony API: ohos.media.image.PixelMap.getPixelBytesCapacity(); ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:替换使用 - -### **getDensity()** ->+ openharmony API: ohos.media.image.PixelMap.getBaseDensity(); ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:替换使用 - -### **recycle()** ->+ openharmony API: ohos.media.image.PixelMap.release() ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 +openharmony 替换类`ohos.media.image.PixelMap` + +根据来源创建`PixelMap` +```java +ImageSource.SourceOptions options = new ImageSource.SourceOptions(); +ImageSource source = ImageSource.create(data, options); +ImageSource.DecodingOptions decodingOptions = new ImageSource.DecodingOptions(); +PixelMap pixelMap = source.createPixelmap(decodingOptions); +``` +直接创建初始选项的图片 +```java +PixelMap.InitializationOptions opts = new PixelMap.InitializationOptions(); +opts.size = new Size(100,100); +opts.pixelFormat = PixelFormat.ARGB_8888; +PixelMap pixelMap = PixelMap.create(opts); +``` + +### **createBitmap(source,x, y, width, height,matrix,filter)** +>+ openharmony API: ohos.media.image.PixelMap +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:暂无直接替换,需要自己去写,使用方法如下: +```java +public static PixelMap createPixelMap(PixelMap source, int x, int y, int width, int height, + Matrix matrix, boolean filter){ +PixelMap.InitializationOptions initializationOptions = new PixelMap.InitializationOptions(); + +RectFloat srcR = new RectFloat(x, y, x + width,y + height); +RectFloat dstR = new RectFloat(0, 0, width, height); +RectFloat deviceR = new RectFloat(); +Paint paint = new Paint(); +paint.setFilterBitmap(filter); +final boolean transformed = !matrix.rectStaysRect(); +if (transformed) { + paint.setAntiAlias(true); +} +matrix.mapRect(deviceR, dstR); + +int neww = Math.round(deviceR.getWidth()); +int newh = Math.round(deviceR.getHeight()); +initializationOptions.size = new Size(neww,newh); +initializationOptions.scaleMode = ScaleMode.CENTER_CROP; +initializationOptions.alphaType = AlphaType.OPAQUE; +PixelMap srcPixelMap = PixelMap.create(initializationOptions); +Texture texture = new Texture(srcPixelMap); +Canvas canvas = new Canvas(texture); + +canvas.translate(-deviceR.left, -deviceR.top); +canvas.concat(matrix); +canvas.drawPixelMapHolderRect(new PixelMapHolder(source), srcR, dstR, paint); +return srcPixelMap/texture.getPixelMap(); +} + +``` + + +### **getWidth()** +>+ openharmony API: ohos.media.image.common.Size +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用,使用方法如下: +```java +int width = pixelMap.getImageInfo().size.width; +``` + +### **getHeight()** +>+ openharmony API: ohos.media.image.common.Size +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用,使用方法如下: +```java +int height = pixelMap.getImageInfo().size.height; +``` +### **getByteCount()** +>+ openharmony API: ohos.media.image.PixelMap.getPixelBytesCapacity(); +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用 + +### **getDensity()** +>+ openharmony API: ohos.media.image.PixelMap.getBaseDensity(); +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用 + +### **recycle()** +>+ openharmony API: ohos.media.image.PixelMap.release() +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 >+ 实现方案:替换使用 \ No newline at end of file diff --git a/graphics/BitmapFactory.md b/graphics/BitmapFactory.md index 2c6dbf9..4bb36dd 100644 --- a/graphics/BitmapFactory.md +++ b/graphics/BitmapFactory.md @@ -1,54 +1,54 @@ -### **decodeResource** ->+ openharmony API: 无 ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案: -``` java -public static PixelMap decodeResource(Context context, int id) { - try { - String path = context.getResourceManager().getMediaPath(id); - if (path.isEmpty()) { - return null; - } - RawFileEntry assetManager = context.getResourceManager().getRawFileEntry(path); - ImageSource.SourceOptions options = new ImageSource.SourceOptions(); - options.formatHint = "image/png"; - ImageSource.DecodingOptions decodingOptions = new ImageSource.DecodingOptions(); - Resource asset = assetManager.openRawFile(); - ImageSource source = ImageSource.create(asset, options); - return Optional.ofNullable(source.createPixelmap(decodingOptions)).get(); - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } -``` - -### **decodeStream** ->+ openharmony API: `ohos.media.image.ImageSource`> ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:自定义 -``` java -public static PixelMap decodeStream(InputStream is) { - ImageSource.SourceOptions options = new ImageSource.SourceOptions(); - ImageSource source = ImageSource.create(is,options);//options可为null - ImageSource.DecodingOptions decodingOptions = new ImageSource.DecodingOptions(); - return source.createPixelmap(decodingOptions);//decodingOptions可为null -} -``` - - -### **decodeFileDescriptor** ->+ openharmony API: `ohos.media.image.ImageSource` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:自定义 -``` java -public static PixelMap decodeStream(FileDescriptor fd) { - ImageSource.SourceOptions options = new ImageSource.SourceOptions(); - ImageSource source = ImageSource.create(fd,options);//options可为null - ImageSource.DecodingOptions decodingOptions = new ImageSource.DecodingOptions(); - return source.createPixelmap(decodingOptions);//decodingOptions可为null -} +### **decodeResource** +>+ openharmony API: 无 +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案: +``` java +public static PixelMap decodeResource(Context context, int id) { + try { + String path = context.getResourceManager().getMediaPath(id); + if (path.isEmpty()) { + return null; + } + RawFileEntry assetManager = context.getResourceManager().getRawFileEntry(path); + ImageSource.SourceOptions options = new ImageSource.SourceOptions(); + options.formatHint = "image/png"; + ImageSource.DecodingOptions decodingOptions = new ImageSource.DecodingOptions(); + Resource asset = assetManager.openRawFile(); + ImageSource source = ImageSource.create(asset, options); + return Optional.ofNullable(source.createPixelmap(decodingOptions)).get(); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } +``` + +### **decodeStream** +>+ openharmony API: `ohos.media.image.ImageSource`> +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:自定义 +``` java +public static PixelMap decodeStream(InputStream is) { + ImageSource.SourceOptions options = new ImageSource.SourceOptions(); + ImageSource source = ImageSource.create(is,options);//options可为null + ImageSource.DecodingOptions decodingOptions = new ImageSource.DecodingOptions(); + return source.createPixelmap(decodingOptions);//decodingOptions可为null +} +``` + + +### **decodeFileDescriptor** +>+ openharmony API: `ohos.media.image.ImageSource` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:自定义 +``` java +public static PixelMap decodeStream(FileDescriptor fd) { + ImageSource.SourceOptions options = new ImageSource.SourceOptions(); + ImageSource source = ImageSource.create(fd,options);//options可为null + ImageSource.DecodingOptions decodingOptions = new ImageSource.DecodingOptions(); + return source.createPixelmap(decodingOptions);//decodingOptions可为null +} ``` \ No newline at end of file diff --git a/graphics/BitmapRegionDecoder.md b/graphics/BitmapRegionDecoder.md index d82e8ff..792ff87 100644 --- a/graphics/BitmapRegionDecoder.md +++ b/graphics/BitmapRegionDecoder.md @@ -1,10 +1,10 @@ -### **decodeRegion** ->+ openharmony API: `ohos.media.image.PixelMap` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案和步骤:使用`PixelMap.create()`方法 -``` java -public static PixelMap decodeRegion(PixelMap source,Rect srcRegion,PixelMap.InitializationOptions opts){ - return PixelMap.create(source,srcRegion,opts); -} +### **decodeRegion** +>+ openharmony API: `ohos.media.image.PixelMap` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案和步骤:使用`PixelMap.create()`方法 +``` java +public static PixelMap decodeRegion(PixelMap source,Rect srcRegion,PixelMap.InitializationOptions opts){ + return PixelMap.create(source,srcRegion,opts); +} ``` \ No newline at end of file diff --git a/graphics/BitmapShader.md b/graphics/BitmapShader.md index 8ac2302..d99cf8f 100644 --- a/graphics/BitmapShader.md +++ b/graphics/BitmapShader.md @@ -1,29 +1,29 @@ - -# PixelMapShader -* openharmony API: ohos.agp.render.PixelMapShader -* openharmony SDK版本:2.1.1.21 -* IDE版本:2.1.0.501 -* 实现方案: - - -原三方库: - -BitmapShader通过设置给mPaint,然后用这个mPaint绘图时,就会根据你设置的TileMode,对绘制区域进行着色 -``` java - // 渲染图像,使用图像为绘制图形着色 - private BitmapShader mBitmapShader; - // 将bmp作为着色器,就是在指定区域内绘制bmp - mBitmapShader = new BitmapShader(bmp, TileMode.CLAMP, TileMode.CLAMP); - // 设置变换矩阵 - mBitmapShader.setLocalMatrix(mMatrix); - // 设置shader - mBitmapPaint.setShader(mBitmapShader); -``` - -openharmony: - -当您需要绘制的对象大于像素图着色器定义的着色区域时,您可以为像素图指定平铺模式以绘制重复或镜像的像素图。 -``` java - PixelMapShader mShadel; - mShadel = new PixelMapShader(new PixelMapHolder(pixelMap), Shader.TileMode.CLAMP_TILEMODE,Shader.TileMode.CLAMP_TILEMODE); + +# PixelMapShader +* openharmony API: ohos.agp.render.PixelMapShader +* openharmony SDK版本:2.1.1.21 +* IDE版本:2.1.0.501 +* 实现方案: + + +原三方库: + +BitmapShader通过设置给mPaint,然后用这个mPaint绘图时,就会根据你设置的TileMode,对绘制区域进行着色 +``` java + // 渲染图像,使用图像为绘制图形着色 + private BitmapShader mBitmapShader; + // 将bmp作为着色器,就是在指定区域内绘制bmp + mBitmapShader = new BitmapShader(bmp, TileMode.CLAMP, TileMode.CLAMP); + // 设置变换矩阵 + mBitmapShader.setLocalMatrix(mMatrix); + // 设置shader + mBitmapPaint.setShader(mBitmapShader); +``` + +openharmony: + +当您需要绘制的对象大于像素图着色器定义的着色区域时,您可以为像素图指定平铺模式以绘制重复或镜像的像素图。 +``` java + PixelMapShader mShadel; + mShadel = new PixelMapShader(new PixelMapHolder(pixelMap), Shader.TileMode.CLAMP_TILEMODE,Shader.TileMode.CLAMP_TILEMODE); ``` \ No newline at end of file diff --git a/graphics/Canvas.md b/graphics/Canvas.md index 11246dd..8d81745 100644 --- a/graphics/Canvas.md +++ b/graphics/Canvas.md @@ -1,69 +1,69 @@ - -### **Canvas(Bitmap)** ->+ openharmony API: `ohos.agp.render.Canvas` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:使用`Canvas(Texture)`方法 -``` java -Canvas canvas = new Canvas(new Texture(pixelMap)); -``` - -### **drawBitmap(Bitmap,Rect, RectF, Paint)** ->+ openharmony API: `ohos.agp.render.Canvas` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:使用`drawPixelMapHolderRect(PixelMapHolder, RectFloat, RectFloat , Paint )`方法 - -### **quickReject()** ->+ openharmony API: `ohos.agp.render.Canvas` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:使用`quickRejectRect(RectFloat)` , `quickRejectPath(Path)`方法 - -### **clipPath()** ->+ openharmony API: `ohos.agp.render.Canvas` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:使用`clipPath(Path, Canvas.ClipOp)`方法 - -### **clipRect()** ->+ openharmony API: `ohos.agp.render.Canvas` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:使用`clipRect(RectFloat, Canvas.ClipOp)` , `clipRect(float, float, float, float)` , `clipRect(RectFloat, Canvas.ClipOp)` , `clipRect(int, int, int, float)`方法 - -### **concat()** ->+ openharmony API: `ohos.agp.render.Canvas` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:使用`concat(Matrix)`方法 - -### **drawArc()** ->+ openharmony API: `ohos.agp.render.Canvas` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:使用`drawArc(RectFloat, Arc, Paint)`方法 - -### **drawARGB()** ->+ openharmony API: `ohos.agp.render.Canvas` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案和步骤:使用`drawColor(int, Canvas.PorterDuffMode)`方法 - -### **getDensity()** ->+ openharmony API: `ohos.agp.render.Canvas` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:使用`getDeviceDensity(Context)`方法 - -### **getSaveCount()** ->+ openharmony API: `ohos.agp.render.Canvas` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:使用`getSaveCount()`方法 - -### **drawLine(float startX, float startY, float stopX, float stopY,Paint paint)** ->+ openharmony API: `ohos.agp.render.Canvas` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 + +### **Canvas(Bitmap)** +>+ openharmony API: `ohos.agp.render.Canvas` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:使用`Canvas(Texture)`方法 +``` java +Canvas canvas = new Canvas(new Texture(pixelMap)); +``` + +### **drawBitmap(Bitmap,Rect, RectF, Paint)** +>+ openharmony API: `ohos.agp.render.Canvas` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:使用`drawPixelMapHolderRect(PixelMapHolder, RectFloat, RectFloat , Paint )`方法 + +### **quickReject()** +>+ openharmony API: `ohos.agp.render.Canvas` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:使用`quickRejectRect(RectFloat)` , `quickRejectPath(Path)`方法 + +### **clipPath()** +>+ openharmony API: `ohos.agp.render.Canvas` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:使用`clipPath(Path, Canvas.ClipOp)`方法 + +### **clipRect()** +>+ openharmony API: `ohos.agp.render.Canvas` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:使用`clipRect(RectFloat, Canvas.ClipOp)` , `clipRect(float, float, float, float)` , `clipRect(RectFloat, Canvas.ClipOp)` , `clipRect(int, int, int, float)`方法 + +### **concat()** +>+ openharmony API: `ohos.agp.render.Canvas` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:使用`concat(Matrix)`方法 + +### **drawArc()** +>+ openharmony API: `ohos.agp.render.Canvas` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:使用`drawArc(RectFloat, Arc, Paint)`方法 + +### **drawARGB()** +>+ openharmony API: `ohos.agp.render.Canvas` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案和步骤:使用`drawColor(int, Canvas.PorterDuffMode)`方法 + +### **getDensity()** +>+ openharmony API: `ohos.agp.render.Canvas` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:使用`getDeviceDensity(Context)`方法 + +### **getSaveCount()** +>+ openharmony API: `ohos.agp.render.Canvas` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:使用`getSaveCount()`方法 + +### **drawLine(float startX, float startY, float stopX, float stopY,Paint paint)** +>+ openharmony API: `ohos.agp.render.Canvas` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 >+ 实现方案:使用`drawLine(Point point1 ,Point point2,Paint)`方法 \ No newline at end of file diff --git a/graphics/Color.md b/graphics/Color.md new file mode 100644 index 0000000..6c54567 --- /dev/null +++ b/graphics/Color.md @@ -0,0 +1,23 @@ +### graphics.Color + +>+ openharmony API:ohos.agp.utils.Color +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 设置色值 +>+ 实现方案: + +``` +divView.addComponent(generateView("hello world", Color.GREEN), params); +``` + + + +### graphics.Color.colorToHSV(int color, float[] array) + +>+ openharmony API:ohos.agp.colors.HsvColor.toHSV(int Value) +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 将RGB色彩空间转化为HSV色彩空间 +>+ 实现方案: + +Android是把hsv色彩空间的各分量写进array数组,OHOS则是返回一个HsvColor对象,其各个分量可以通过getHue(), getSaturation(), getValue()这几个方法获取 \ No newline at end of file diff --git a/graphics/CornerPathEffect.md b/graphics/CornerPathEffect.md index 5839a0f..6563496 100644 --- a/graphics/CornerPathEffect.md +++ b/graphics/CornerPathEffect.md @@ -1,8 +1,8 @@ -### **CornerPathEffect(float)** ->+ openharmony API: `ohos.agp.render.PathEffect` ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java -paint.setPathEffect(new PathEffect(10f)); +### **CornerPathEffect(float)** +>+ openharmony API: `ohos.agp.render.PathEffect` +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +paint.setPathEffect(new PathEffect(10f)); ``` \ No newline at end of file diff --git a/graphics/Matrix.md b/graphics/Matrix.md index 6746e12..997cd00 100644 --- a/graphics/Matrix.md +++ b/graphics/Matrix.md @@ -1,52 +1,52 @@ -### **setScale** ->+ openharmony API: ohos.agp.utils.Matrix.setScale ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java -Matrix matrix = new Matrix(); -// 默认以左上角的点进行缩放矩阵 -matrix.setScale(0.5f, 0.5f); -// 以坐标点(100,100)为枢轴点进行缩放矩阵 -matrix.setScale(0.5f, 0.5f, 100f, 100f); - -``` - -### **setTranslate** ->+ openharmony API: ohos.agp.utils.Matrix.setTranslate ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java -Matrix matrix = new Matrix(); -// 平移指定的距离 -matrix.setTranslate(100f, 100f); - -``` - -### **setSkew** ->+ openharmony API: ohos.agp.utils.Matrix.setSkew ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java -Matrix matrix = new Matrix(); -// 设置水平错切和垂直错切的值为 0.3 -matrix.setSkew(0.3f, 0.3f); - -``` - -### **setRotate** ->+ openharmony API: ohos.agp.utils.Matrix.setRotate ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java -Matrix matrix = new Matrix(); -// 默认以左上角为锚点进行旋转90度 -matrix.setRotate(90); -// 以指定坐标点进行旋转90度 -matrix.setRotate(90, 100f, 100f); - -``` - +### **setScale** +>+ openharmony API: ohos.agp.utils.Matrix.setScale +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +Matrix matrix = new Matrix(); +// 默认以左上角的点进行缩放矩阵 +matrix.setScale(0.5f, 0.5f); +// 以坐标点(100,100)为枢轴点进行缩放矩阵 +matrix.setScale(0.5f, 0.5f, 100f, 100f); + +``` + +### **setTranslate** +>+ openharmony API: ohos.agp.utils.Matrix.setTranslate +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +Matrix matrix = new Matrix(); +// 平移指定的距离 +matrix.setTranslate(100f, 100f); + +``` + +### **setSkew** +>+ openharmony API: ohos.agp.utils.Matrix.setSkew +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +Matrix matrix = new Matrix(); +// 设置水平错切和垂直错切的值为 0.3 +matrix.setSkew(0.3f, 0.3f); + +``` + +### **setRotate** +>+ openharmony API: ohos.agp.utils.Matrix.setRotate +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +Matrix matrix = new Matrix(); +// 默认以左上角为锚点进行旋转90度 +matrix.setRotate(90); +// 以指定坐标点进行旋转90度 +matrix.setRotate(90, 100f, 100f); + +``` + diff --git a/graphics/Paint.md b/graphics/Paint.md index c850e0d..368c4fb 100644 --- a/graphics/Paint.md +++ b/graphics/Paint.md @@ -1,15 +1,28 @@ -### **setShadowLayer** ->+ openharmony class: ohos.agp.render.Paint ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:替代对比如下 - -原三方库: -```java -paint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor) -``` -openharmony : -```java -BlurDrawLooper textBlurDrawLooper = new BlurDrawLooper(shadowRadius, shadowDx, shadowDy, new Color(shadowColor)); - paint.setBlurDrawLooper(textBlurDrawLooper); -``` \ No newline at end of file +### **setShadowLayer** +>+ openharmony class: ohos.agp.render.Paint +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替代对比如下 + +原三方库: +```java +paint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor) +``` +openharmony : +```java +BlurDrawLooper textBlurDrawLooper = new BlurDrawLooper(shadowRadius, shadowDx, shadowDy, new Color(shadowColor)); + paint.setBlurDrawLooper(textBlurDrawLooper); +``` + + + +### setAlpha + +>+ openharmony class: ohos.agp.render.setAlpha(float alpha) +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案: + +接口本身并不难找,需要注意的是这里存在一个隐藏的陷阱:Android版本alpha参数为int类型,范围为0-255,OHOS版本参数为float型,范围为0-1。由于float兼容int型,直接从android移植代码到OHOS上在编译阶段完全不会检查出问题。实际上却潜在alpha效果不对应的问题,需要注意适配。 + +例如:如果android上传入的是一个大于1的数值,那么直接移植到OHOS上将会使参数超过OHOS的alpha值的上限,此时会丢失透明度而一律按不透明处理。另一方面,假设android上采用类似写法:mPaint.setAlpha((int)(factor * MAX_ALPHA)),若仅仅将MAX_ALPHA由255改为1,而没有去掉int强转则会导致alpha值在不足1的情况下被向下取整为0,使得绘制内容变为全透明。因此要根据具体场景注意适配,在上一例中,直接改为mPaint.setAlpha(factor)即可 \ No newline at end of file diff --git a/graphics/Path.md b/graphics/Path.md index 7b803e7..9a81394 100644 --- a/graphics/Path.md +++ b/graphics/Path.md @@ -1,45 +1,45 @@ -### **moveTo** ->+ openharmony API: ohos.agp.render.Path.moveTo ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java -Path path = new Path(); -path.moveTo(100f, 100f); - -``` - -### **lineTo** ->+ openharmony API: ohos.agp.render.Path.lineTo ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java -Path path = new Path(); -path.lineTo(200f, 200f); - -``` - -### **setLastPoint** ->+ openharmony API: ohos.agp.render.Path.setLastPoint ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java -Path path = new Path(); -path.setLastPoint(100f, 100f); -// 或者 -path.setLastPoint(new Point(100f, 100f)); - -``` - -### **addRect** ->+ openharmony API: ohos.agp.render.Path.addRect ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java -Path path = new Path(); -path.addRect(new RectFloat(0f, 0f, 100f, 100f), Path.Direction.CLOCK_WISE); - -``` +### **moveTo** +>+ openharmony API: ohos.agp.render.Path.moveTo +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +Path path = new Path(); +path.moveTo(100f, 100f); + +``` + +### **lineTo** +>+ openharmony API: ohos.agp.render.Path.lineTo +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +Path path = new Path(); +path.lineTo(200f, 200f); + +``` + +### **setLastPoint** +>+ openharmony API: ohos.agp.render.Path.setLastPoint +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +Path path = new Path(); +path.setLastPoint(100f, 100f); +// 或者 +path.setLastPoint(new Point(100f, 100f)); + +``` + +### **addRect** +>+ openharmony API: ohos.agp.render.Path.addRect +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +Path path = new Path(); +path.addRect(new RectFloat(0f, 0f, 100f, 100f), Path.Direction.CLOCK_WISE); + +``` diff --git a/graphics/PointF.md b/graphics/PointF.md index 67f3951..c878bc7 100644 --- a/graphics/PointF.md +++ b/graphics/PointF.md @@ -1,20 +1,20 @@ -### **PointF(float, float)** ->+ openharmony API: ohos.agp.utils.Point(float, float) ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java -// 直接构建 -Point point = new Point(100f, 100f); -``` - -### **set** ->+ openharmony API: ohos.agp.utils.Point.modify ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java -Point point = new Point(); -// 重新修改坐标点 -point.modify(100f, 100f); -``` +### **PointF(float, float)** +>+ openharmony API: ohos.agp.utils.Point(float, float) +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +// 直接构建 +Point point = new Point(100f, 100f); +``` + +### **set** +>+ openharmony API: ohos.agp.utils.Point.modify +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +Point point = new Point(); +// 重新修改坐标点 +point.modify(100f, 100f); +``` diff --git a/graphics/PorterDuffXfermode.md b/graphics/PorterDuffXfermode.md index c20a3dd..e135ef7 100644 --- a/graphics/PorterDuffXfermode.md +++ b/graphics/PorterDuffXfermode.md @@ -1,10 +1,10 @@ -### **PorterDuffXfermode(PorterDuff.Mode)** ->+ openharmony API: ohos.agp.render.Canvas.PorterDuffMode ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java -Canvas canvas = new Canvas(); -// 根据指定的混合模式画指定颜色 -canvas.drawColor(Color.BLUE.getValue(), Canvas.PorterDuffMode.SRC_OVER); +### **PorterDuffXfermode(PorterDuff.Mode)** +>+ openharmony API: ohos.agp.render.Canvas.PorterDuffMode +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +Canvas canvas = new Canvas(); +// 根据指定的混合模式画指定颜色 +canvas.drawColor(Color.BLUE.getValue(), Canvas.PorterDuffMode.SRC_OVER); ``` \ No newline at end of file diff --git a/graphics/RectF.md b/graphics/RectF.md index 2390def..1681f90 100644 --- a/graphics/RectF.md +++ b/graphics/RectF.md @@ -1,70 +1,70 @@ -### **RectF** ->+ openharmony API: ohos.agp.utils.RectFloat ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java -// 通过坐标点直接构建 -RectFloat rectFloat = new RectFloat(0f, 0f, 100f, 100f); - -// 通过传入一个RectFloat进行构建 -RectFloat rectFloat2 = new RectFloat(new RectFloat(0f, 0f, 100f, 100f)); -``` - -### **width** ->+ openharmony API: ohos.agp.utils.RectFloat.getWidth ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java -RectFloat rectFloat = new RectFloat(0f, 0f, 100f, 100f); -rectFloat.getWidth(); -``` - -### **height** ->+ openharmony API: ohos.agp.utils.RectFloat.getHeight ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java -RectFloat rectFloat = new RectFloat(0f, 0f, 100f, 100f); -rectFloat.getHeight(); -``` - -### **centerX** ->+ openharmony API: ohos.agp.utils.RectFloat.getHorizontalCenter ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java -RectFloat rectFloat = new RectFloat(0f, 0f, 100f, 100f); -rectFloat.getHorizontalCenter(); -``` - -### **centerY** ->+ openharmony API: ohos.agp.utils.RectFloat.getVerticalCenter ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java -RectFloat rectFloat = new RectFloat(0f, 0f, 100f, 100f); -rectFloat.getVerticalCenter(); -``` - -### **contains** ->+ openharmony API: ohos.agp.utils.RectFloat.isInclude ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java -RectFloat rectFloat = new RectFloat(0f, 0f, 100f, 100f); -// 方式一 -rectFloat.isInclude(50f, 50f); -// 方式二 -rectFloat.isInclude(new Point(50f, 50f)); -// 方式三 -rectFloat.isInclude(new RectFloat(0f, 0f, 50f, 50f)); -// 方式四 -rectFloat.isInclude(0f, 0f, 50f, 50f); -``` - +### **RectF** +>+ openharmony API: ohos.agp.utils.RectFloat +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +// 通过坐标点直接构建 +RectFloat rectFloat = new RectFloat(0f, 0f, 100f, 100f); + +// 通过传入一个RectFloat进行构建 +RectFloat rectFloat2 = new RectFloat(new RectFloat(0f, 0f, 100f, 100f)); +``` + +### **width** +>+ openharmony API: ohos.agp.utils.RectFloat.getWidth +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +RectFloat rectFloat = new RectFloat(0f, 0f, 100f, 100f); +rectFloat.getWidth(); +``` + +### **height** +>+ openharmony API: ohos.agp.utils.RectFloat.getHeight +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +RectFloat rectFloat = new RectFloat(0f, 0f, 100f, 100f); +rectFloat.getHeight(); +``` + +### **centerX** +>+ openharmony API: ohos.agp.utils.RectFloat.getHorizontalCenter +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +RectFloat rectFloat = new RectFloat(0f, 0f, 100f, 100f); +rectFloat.getHorizontalCenter(); +``` + +### **centerY** +>+ openharmony API: ohos.agp.utils.RectFloat.getVerticalCenter +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +RectFloat rectFloat = new RectFloat(0f, 0f, 100f, 100f); +rectFloat.getVerticalCenter(); +``` + +### **contains** +>+ openharmony API: ohos.agp.utils.RectFloat.isInclude +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +RectFloat rectFloat = new RectFloat(0f, 0f, 100f, 100f); +// 方式一 +rectFloat.isInclude(50f, 50f); +// 方式二 +rectFloat.isInclude(new Point(50f, 50f)); +// 方式三 +rectFloat.isInclude(new RectFloat(0f, 0f, 50f, 50f)); +// 方式四 +rectFloat.isInclude(0f, 0f, 50f, 50f); +``` + diff --git a/graphics/Typeface.md b/graphics/Typeface.md index 7eae621..bc710e4 100644 --- a/graphics/Typeface.md +++ b/graphics/Typeface.md @@ -1,81 +1,81 @@ -### **createFromAsset** ->+ openharmony class: ohos.agp.text.Font ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:替代对比如下 - -原三方库: -```java -mTypeface = Typeface.createFromAsset(context.getResources().getAssets(), typeface); -``` -openharmony : -```java -Font createFontBuild(Context context, String name) { - ResourceManager resManager = context.getResourceManager(); - RawFileEntry rawFileEntry = resManager.getRawFileEntry("resources/rawfile/" + name); - Resource resource = null; - try { - resource = rawFileEntry.openRawFile(); - } catch (IOException e) { - e.printStackTrace(); - } - StringBuffer fileName = new StringBuffer(name); - File file = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), fileName.toString()); - OutputStream outputStream = null; - try { - outputStream = new FileOutputStream(file); - int index; - byte[] bytes = new byte[1024]; - while ((index = resource.read(bytes)) != -1) { - outputStream.write(bytes, 0, index); - outputStream.flush(); - } - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } finally { - try { - resource.close(); - outputStream.close(); - } catch (IOException e) { - e.printStackTrace(); - } - - } - Font.Builder builder = new Font.Builder(file); - return builder.build(); - } -``` - -### **create** ->+ openharmony class: ohos.agp.text.Font.Build ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:替代对比如下 - -原三方库: -```java -Typeface.create(mTypeface, mTextStyle) -``` -openharmony : -```java -switch (mTextStyle) { - case NORMAL: - mTypeface.setWeight(Font.REGULAR); - mTypeface.makeItalic(false); - break; - case BOLD: - mTypeface.setWeight(Font.BOLD); - mTypeface.makeItalic(false); - break; - case ITALIC: - mTypeface.setWeight(Font.REGULAR); - mTypeface.makeItalic(true); - break; - case BOLD_ITALIC: - mTypeface.setWeight(Font.BOLD); - mTypeface.makeItalic(true); - break; -} +### **createFromAsset** +>+ openharmony class: ohos.agp.text.Font +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替代对比如下 + +原三方库: +```java +mTypeface = Typeface.createFromAsset(context.getResources().getAssets(), typeface); +``` +openharmony : +```java +Font createFontBuild(Context context, String name) { + ResourceManager resManager = context.getResourceManager(); + RawFileEntry rawFileEntry = resManager.getRawFileEntry("resources/rawfile/" + name); + Resource resource = null; + try { + resource = rawFileEntry.openRawFile(); + } catch (IOException e) { + e.printStackTrace(); + } + StringBuffer fileName = new StringBuffer(name); + File file = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), fileName.toString()); + OutputStream outputStream = null; + try { + outputStream = new FileOutputStream(file); + int index; + byte[] bytes = new byte[1024]; + while ((index = resource.read(bytes)) != -1) { + outputStream.write(bytes, 0, index); + outputStream.flush(); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + resource.close(); + outputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + } + Font.Builder builder = new Font.Builder(file); + return builder.build(); + } +``` + +### **create** +>+ openharmony class: ohos.agp.text.Font.Build +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替代对比如下 + +原三方库: +```java +Typeface.create(mTypeface, mTextStyle) +``` +openharmony : +```java +switch (mTextStyle) { + case NORMAL: + mTypeface.setWeight(Font.REGULAR); + mTypeface.makeItalic(false); + break; + case BOLD: + mTypeface.setWeight(Font.BOLD); + mTypeface.makeItalic(false); + break; + case ITALIC: + mTypeface.setWeight(Font.REGULAR); + mTypeface.makeItalic(true); + break; + case BOLD_ITALIC: + mTypeface.setWeight(Font.BOLD); + mTypeface.makeItalic(true); + break; +} ``` \ No newline at end of file diff --git a/graphics/Xfermode.md b/graphics/Xfermode.md index 3aa0a7f..32c5bef 100644 --- a/graphics/Xfermode.md +++ b/graphics/Xfermode.md @@ -1,16 +1,16 @@ -### **setXfermode** ->+ openharmony API:ohos.agp.render.BlendMode ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案,替代对比如下 - -原三方库 : -```java -paint.setXfermode(xfermode); -``` -openharmony : -```java -paint.setBlendMode(BlendMode.SRC_OUT); -``` - +### **setXfermode** +>+ openharmony API:ohos.agp.render.BlendMode +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案,替代对比如下 + +原三方库 : +```java +paint.setXfermode(xfermode); +``` +openharmony : +```java +paint.setBlendMode(BlendMode.SRC_OUT); +``` + 具体枚举解释查看API文档 \ No newline at end of file diff --git a/graphics/drawable/Drawable.md b/graphics/drawable/Drawable.md index f787825..8279951 100644 --- a/graphics/drawable/Drawable.md +++ b/graphics/drawable/Drawable.md @@ -1,20 +1,20 @@ -### **draw(Canvas canvas)** ->+ openharmony API: ohos.agp.components.element.Element.drawToCanvas ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案: - -```java - 1:继承ShapeElemen,并重写drawToCanvas - 2:外部通过addDrawTask来手动触发drawToCanvas的回调。 - Component.addDrawTask(new Component.DrawTask() { - @Override - public void onDraw(Component component, Canvas canvas) { - customDrawable = new CustomDrawable(); - customDrawable.drawToCanvas(canvas); - } - }); -``` ->+ 补充说明:目前直接继承Element会报错,请继承其子类。 -原三方库中构造自定义Drawable后会自动调用draw()方法,但是drawToCanvas无法自动调用, +### **draw(Canvas canvas)** +>+ openharmony API: ohos.agp.components.element.Element.drawToCanvas +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案: + +```java + 1:继承ShapeElemen,并重写drawToCanvas + 2:外部通过addDrawTask来手动触发drawToCanvas的回调。 + Component.addDrawTask(new Component.DrawTask() { + @Override + public void onDraw(Component component, Canvas canvas) { + customDrawable = new CustomDrawable(); + customDrawable.drawToCanvas(canvas); + } + }); +``` +>+ 补充说明:目前直接继承Element会报错,请继承其子类。 +原三方库中构造自定义Drawable后会自动调用draw()方法,但是drawToCanvas无法自动调用, 需要在外部主动调用才执行,目前验证可行的方案是在自定义Component的addDrawTask中手动调用,在其他的非自定义控件场景中暂时未找到触发回调的办法,自定义element后续会支持并完善。 \ No newline at end of file diff --git a/graphics/drawable/GradientDrawable.md b/graphics/drawable/GradientDrawable.md index 6771386..2458660 100644 --- a/graphics/drawable/GradientDrawable.md +++ b/graphics/drawable/GradientDrawable.md @@ -1,44 +1,44 @@ -### **GradientDrawable()** ->+ openharmony API: `ohos.agp.components.element.ShapeElement` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:替换使用,使用方法如下: - ```java - ShapeElement shapeElement = new ShapeElement(); - ``` -### **setCornerRadius(float radius)** ->+ openharmony API: `ohos.agp.components.element.ShapeElement` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:替换使用,使用方法如下: - ```java - shapeElement.setShape(ShapeElement.RECTANGLE);//根据不同的形状传不同的参数 - shapeElement.setCornerRadius(raduis); - ``` -### **setStroke(int width, int color)** ->+ openharmony API: `ohos.agp.components.element.ShapeElement` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:替换使用,使用方法如下: - ```java - shapeElement.setStroke(strokeWidth, new RgbColor(strokeColor)); - ``` -### **setColor(int argb)** ->+ openharmony API: `ohos.agp.components.element.ShapeElement` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:替换使用,使用方法如下: - ```java - shapeElement.setRgbColor(new RgbColor(color)); - shapeElement.setAlpha(alpha); - ``` - -### **setCornerRadii** ->+ openharmony API: `ohos.agp.components.element.ShapeElement` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:替换使用,使用方法如下: - ```java - ShapeElement leftItemPressedDrawable = new ShapeElement(); - leftItemPressedDrawable.setCornerRadiiArray(new float[]{}); +### **GradientDrawable()** +>+ openharmony API: `ohos.agp.components.element.ShapeElement` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用,使用方法如下: + ```java + ShapeElement shapeElement = new ShapeElement(); + ``` +### **setCornerRadius(float radius)** +>+ openharmony API: `ohos.agp.components.element.ShapeElement` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用,使用方法如下: + ```java + shapeElement.setShape(ShapeElement.RECTANGLE);//根据不同的形状传不同的参数 + shapeElement.setCornerRadius(raduis); + ``` +### **setStroke(int width, int color)** +>+ openharmony API: `ohos.agp.components.element.ShapeElement` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用,使用方法如下: + ```java + shapeElement.setStroke(strokeWidth, new RgbColor(strokeColor)); + ``` +### **setColor(int argb)** +>+ openharmony API: `ohos.agp.components.element.ShapeElement` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用,使用方法如下: + ```java + shapeElement.setRgbColor(new RgbColor(color)); + shapeElement.setAlpha(alpha); + ``` + +### **setCornerRadii** +>+ openharmony API: `ohos.agp.components.element.ShapeElement` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用,使用方法如下: + ```java + ShapeElement leftItemPressedDrawable = new ShapeElement(); + leftItemPressedDrawable.setCornerRadiiArray(new float[]{}); ``` \ No newline at end of file diff --git a/graphics/drawable/StateListDrawable.md b/graphics/drawable/StateListDrawable.md index 86952d8..1ce5b83 100644 --- a/graphics/drawable/StateListDrawable.md +++ b/graphics/drawable/StateListDrawable.md @@ -1,44 +1,44 @@ -### **GradientDrawable()** ->+ openharmony API: `ohos.agp.components.element.ShapeElement` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:替换使用,使用方法如下: - ```java - ShapeElement shapeElement = new ShapeElement(); - ``` -### **setCornerRadius(float radius)** ->+ openharmony API: `ohos.agp.components.element.ShapeElement` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:替换使用,使用方法如下: - ```java - shapeElement.setShape(ShapeElement.RECTANGLE);//根据不同的形状传不同的参数 - shapeElement.setCornerRadius(raduis); - ``` -### **setStroke(int width, int color)** ->+ openharmony API: `ohos.agp.components.element.ShapeElement` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:替换使用,使用方法如下: - ```java - shapeElement.setStroke(strokeWidth, new RgbColor(strokeColor)); - ``` -### **setColor(int argb)** ->+ openharmony API: `ohos.agp.components.element.ShapeElement` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:替换使用,使用方法如下: - ```java - shapeElement.setRgbColor(new RgbColor(color)); - shapeElement.setAlpha(alpha); - ``` - -### **setCornerRadii** ->+ openharmony API: `ohos.agp.components.element.ShapeElement` ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:替换使用,使用方法如下: - ```java - ShapeElement leftItemPressedDrawable = new ShapeElement(); - leftItemPressedDrawable.setCornerRadiiArray(new float[]{}); +### **GradientDrawable()** +>+ openharmony API: `ohos.agp.components.element.ShapeElement` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用,使用方法如下: + ```java + ShapeElement shapeElement = new ShapeElement(); + ``` +### **setCornerRadius(float radius)** +>+ openharmony API: `ohos.agp.components.element.ShapeElement` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用,使用方法如下: + ```java + shapeElement.setShape(ShapeElement.RECTANGLE);//根据不同的形状传不同的参数 + shapeElement.setCornerRadius(raduis); + ``` +### **setStroke(int width, int color)** +>+ openharmony API: `ohos.agp.components.element.ShapeElement` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用,使用方法如下: + ```java + shapeElement.setStroke(strokeWidth, new RgbColor(strokeColor)); + ``` +### **setColor(int argb)** +>+ openharmony API: `ohos.agp.components.element.ShapeElement` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用,使用方法如下: + ```java + shapeElement.setRgbColor(new RgbColor(color)); + shapeElement.setAlpha(alpha); + ``` + +### **setCornerRadii** +>+ openharmony API: `ohos.agp.components.element.ShapeElement` +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用,使用方法如下: + ```java + ShapeElement leftItemPressedDrawable = new ShapeElement(); + leftItemPressedDrawable.setCornerRadiiArray(new float[]{}); ``` \ No newline at end of file diff --git a/graphics/drawable/VectorDrawable.md b/graphics/drawable/VectorDrawable.md index dd859a7..52caffc 100644 --- a/graphics/drawable/VectorDrawable.md +++ b/graphics/drawable/VectorDrawable.md @@ -1,26 +1,26 @@ -### vector.xml转换VectorElement -+ openharmony API: `ohos.agp.components.element.VectorElement` -+ openharmony SDK版本:2.0.1.93 以上 -+ IDE版本:2.0.12.141 -+ 实现方案: - + 1.定义一个xml文件: `vector_test.xml` - ```java - - - - ``` - + 2.在java代码中使用已经定义好的xml文件: - ```java - Image image ; - VectorElement vectorElement = new VectorElement(this, Graphic_vector_test); - image.setImageElement(vectorElement); - or - image.setBackground(vectorElement); +### vector.xml转换VectorElement ++ openharmony API: `ohos.agp.components.element.VectorElement` ++ openharmony SDK版本:2.0.1.93 以上 ++ IDE版本:2.0.12.141 ++ 实现方案: + + 1.定义一个xml文件: `vector_test.xml` + ```java + + + + ``` + + 2.在java代码中使用已经定义好的xml文件: + ```java + Image image ; + VectorElement vectorElement = new VectorElement(this, Graphic_vector_test); + image.setImageElement(vectorElement); + or + image.setBackground(vectorElement); ``` \ No newline at end of file diff --git a/hardware/Camera.md b/hardware/Camera.md new file mode 100644 index 0000000..1a95169 --- /dev/null +++ b/hardware/Camera.md @@ -0,0 +1,45 @@ +### hardware.Camera + +>+ openharmony API:ohos.media.camera.device.Camera +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 使用相机功能 +>+ 实现方案: + +直接替换 + + + +### hardware.Camera.Parameters + +>+ openharmony API:ohos.media.camera.device.CameraAbility +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 相机静态能力 +>+ 实现方案: + +直接替换 + + + +### hardware.Camera.Size + +>+ openharmony API:ohos.media.image.common.Size +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 相机大小尺寸 +>+ 实现方案: + +直接替换 + + + +### hardware.Camera.PreviewCallback + +>+ openharmony API: ohos.media.camera.device. CameraStateCallback +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 相机预览回调 +>+ 实现方案: + +直接替换 \ No newline at end of file diff --git a/os/AsyncTask.md b/os/AsyncTask.md new file mode 100644 index 0000000..60a1b2e --- /dev/null +++ b/os/AsyncTask.md @@ -0,0 +1,10 @@ +### os.AsyncTask + +>+ openharmony API : ohos.eventhandler.EventHandler +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 执行异步任务 +>+ 实现方案: + +直接替换 + diff --git a/os/Handler.md b/os/Handler.md index b11e111..7359c51 100644 --- a/os/Handler.md +++ b/os/Handler.md @@ -1,16 +1,78 @@ -## handleMessage(Message msg) ->+ openharmony API:ohos.eventhandler.EventHandler ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:新建类继承EventHandler,重写processEvent方法 -``` java -public class MyHandler extends EventHandler { - - @Override - protected void processEvent(InnerEvent event) { - if(MSG_ID==event.eventId){ - //dosomething - } - } -} +## handleMessage(Message msg) +>+ openharmony API:ohos.eventhandler.EventHandler +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:新建类继承EventHandler,重写processEvent方法 +``` java +public class MyHandler extends EventHandler { + + @Override + protected void processEvent(InnerEvent event) { + if(MSG_ID==event.eventId){ + //dosomething + } + } +} +``` + + + +## sendMessage(Message mMsg) + +>+ openharmony API:ohos.eventhandler.EventHandler.sendEvent(InnerEvent event) +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案: + +``` +public class Handler extends EventHandler { + + private Callback mCallback; + + public Handler(Looper looper,Callback mCallback){ + super(looper.getEventRunner()); + this.mCallback = mCallback; + } + public Handler(Callback mCallback) { + this(Looper.myLooper(),mCallback); + } + + public Handler(Looper looper) { + this(looper,null); + } + + public static Handler getMainLooperHandler(){ + return new Handler(Looper.getMainLooper()); + } + + public Looper getLooper() { + return Looper.myLooper(); + } + + @Override + protected void processEvent(InnerEvent event) { + super.processEvent(event); + if(mCallback != null){ + mCallback.handleMessage((Message) event.object); + } + } + + public boolean postDelayed(Runnable runnable, long delayTime) { + super.postTask(runnable,delayTime); + return true; + } + + public boolean post(Runnable runnable) { + super.postTask(runnable); + return true; + } + + public void sendMessage(Message mMsg) { + sendEvent(InnerEvent.get(mMsg.what, mMsg)); + } + + public boolean postAtTime(Runnable runnable, long millis) { + postTimingTask(runnable, millis); + return true; + } ``` \ No newline at end of file diff --git a/os/Looper.md b/os/Looper.md index 4fad022..aceed70 100644 --- a/os/Looper.md +++ b/os/Looper.md @@ -1,42 +1,42 @@ -### **prepare** ->+ openharmony API:ohos.eventhandler.EventRunner.create ->+ openharmony SDK版本:2.1.1.21 ->+ IDE版本:2.1.0.501 ->+ 实现方案:直接替换 - -### **prepareMainLooper** ->+ openharmony API:ohos.eventhandler.EventRunner.create ->+ openharmony SDK版本:2.1.1.21 ->+ IDE版本:2.1.0.501 ->+ 实现方案:直接替换 - -### **myLooper** ->+ openharmony API:ohos.eventhandler.EventRunner.current ->+ openharmony SDK版本:2.1.1.21 ->+ IDE版本:2.1.0.501 ->+ 实现方案:直接替换 - -### **isCurrentThread** ->+ openharmony API:ohos.eventhandler.EventRunner.isCurrentRunnerThread ->+ openharmony SDK版本:2.1.1.21 ->+ IDE版本:2.1.0.501 ->+ 实现方案:直接替换 - -### **getMainLooper** ->+ openharmony API:ohos.eventhandler.EventRunner.getMainEventRunner ->+ openharmony SDK版本:2.1.1.21 ->+ IDE版本:2.1.0.501 ->+ 实现方案:直接替换 - -### **loop** ->+ openharmony API:ohos.eventhandler.EventRunner.run ->+ openharmony SDK版本:2.1.1.21 ->+ IDE版本:2.1.0.501 ->+ 实现方案:直接替换 - -### **quit** ->+ openharmony API:ohos.eventhandler.EventRunner.stop ->+ openharmony SDK版本:2.1.1.21 ->+ IDE版本:2.1.0.501 ->+ 实现方案:直接替换 - +### **prepare** +>+ openharmony API:ohos.eventhandler.EventRunner.create +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案:直接替换 + +### **prepareMainLooper** +>+ openharmony API:ohos.eventhandler.EventRunner.create +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案:直接替换 + +### **myLooper** +>+ openharmony API:ohos.eventhandler.EventRunner.current +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案:直接替换 + +### **isCurrentThread** +>+ openharmony API:ohos.eventhandler.EventRunner.isCurrentRunnerThread +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案:直接替换 + +### **getMainLooper** +>+ openharmony API:ohos.eventhandler.EventRunner.getMainEventRunner +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案:直接替换 + +### **loop** +>+ openharmony API:ohos.eventhandler.EventRunner.run +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案:直接替换 + +### **quit** +>+ openharmony API:ohos.eventhandler.EventRunner.stop +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案:直接替换 + diff --git a/os/Message.md b/os/Message.md new file mode 100644 index 0000000..8daaf3b --- /dev/null +++ b/os/Message.md @@ -0,0 +1,15 @@ +### os.Message + +>+ openharmony API: ohos.eventhandler.InnerEvent +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 消息对象 +>+ 实现方案: + +替换使用 + +``` +InnerEvent event2 = InnerEvent.get(RESPONSE_UPDATE, 0L, new ProgressModel(bytesWritten, contentLength, done)); +mHandler.sendEvent(event2); +``` + diff --git a/os/Parcel.md b/os/Parcel.md new file mode 100644 index 0000000..d7fbc1e --- /dev/null +++ b/os/Parcel.md @@ -0,0 +1,9 @@ +### os.Parcel + +>+ openharmony API: ohos.utils. Parcel +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 序列化 +>+ 实现方案: + +直接替换 \ No newline at end of file diff --git a/os/Parcelable.md b/os/Parcelable.md new file mode 100644 index 0000000..fb28be2 --- /dev/null +++ b/os/Parcelable.md @@ -0,0 +1,10 @@ +### os.Parcelable + +>+ openharmony API: ohos.utils.Sequenceable +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 序列化 +>+ 实现方案: + +直接替换使用 + diff --git a/os/PowerManager.md b/os/PowerManager.md new file mode 100644 index 0000000..51abb4b --- /dev/null +++ b/os/PowerManager.md @@ -0,0 +1,9 @@ +### os.PowerManager + +>+ openharmony API : ohos.powermanager.PowerManager +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 电源管理 +>+ 实现方案: + +直接替换 \ No newline at end of file diff --git a/os/StatFs.md b/os/StatFs.md index 237b97e..81672a6 100644 --- a/os/StatFs.md +++ b/os/StatFs.md @@ -1,19 +1,42 @@ - -### **StatFs** ->+ openharmony class:`ohos.data.usage.StatVfs` ->+ openharmony SDK版本:2.1.1.21 ->+ IDE版本:2.1.0.501 ->+ 实现方案:查询外置存储器的剩余空间 - -* 原库实现 -```java - File sdcardDir = Environment.getExternalStorageDirectory(); - StatFs sf = new StatFs(sdcardDir.getPath()); - return sf.getAvailableBlocks() * sf.getBlockSize(); -``` - -* 替换实现 -```java - StatVfs statVfs = new StatVfs(context.getExternalCacheDir().getAbsolutePath()); - return statVfs.getAvailableSpace(); -``` \ No newline at end of file + +### **StatFs** +>+ openharmony class:`ohos.data.usage.StatVfs` +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案:查询外置存储器的剩余空间 + +* 原库实现 +```java + File sdcardDir = Environment.getExternalStorageDirectory(); + StatFs sf = new StatFs(sdcardDir.getPath()); + return sf.getAvailableBlocks() * sf.getBlockSize(); +``` + +* 替换实现 +```java + StatVfs statVfs = new StatVfs(context.getExternalCacheDir().getAbsolutePath()); + return statVfs.getAvailableSpace(); +``` + + + +### **StatFs.calculateDiskCacheSize** + +>+ openharmony API : ohos.data.usage.StatVfs +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案: + +``` +private static long calculateDiskCacheSize(File dir) { + long size = 0; + try { + StatVfs statFs = new StatVfs(dir.getAbsolutePath()); + long available = (long) statFs.getAvailableSpace(); + size = available / 50; + } catch (IllegalArgumentException ignored) { + } + return Math.max(Math.min(size, MAX_DISK_CACHE_SIZE), MIN_DISK_CACHE_SIZE); +} +``` + diff --git a/os/SystemClock.md b/os/SystemClock.md index d029db6..6300532 100644 --- a/os/SystemClock.md +++ b/os/SystemClock.md @@ -1,42 +1,42 @@ -### **elapsedRealtime** ->+ openharmony API:ohos.miscservices.timeutility.Time.getRealTime ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案 使用 getRealTime()方法 - -```java -long time = Time.getRealTime(); -``` - -### **currentThreadTimeMillis** ->+ openharmony API:ohos.miscservices.timeutility.Time.getCurrentThreadTime ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案: 使用 getCurrentThreadTime()方法 -```java -long time = Time.getCurrentThreadTime(); -``` - - -### **setCurrentTimeMillis** ->+ openharmony API:ohos.miscservices.timeutility.Time.setTime ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案: 使用 setTime(Context context,Date date)方法 - -```java -long time = Time.setTime(context , date); -``` - -### **sleep** ->+ openharmony API:ohos.miscservices.timeutility.Time.sleep ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案: 使用 sleep(Long ms)方法 - -```java -Time.sleep(milliSecond); -``` - - +### **elapsedRealtime** +>+ openharmony API:ohos.miscservices.timeutility.Time.getRealTime +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案 使用 getRealTime()方法 + +```java +long time = Time.getRealTime(); +``` + +### **currentThreadTimeMillis** +>+ openharmony API:ohos.miscservices.timeutility.Time.getCurrentThreadTime +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案: 使用 getCurrentThreadTime()方法 +```java +long time = Time.getCurrentThreadTime(); +``` + + +### **setCurrentTimeMillis** +>+ openharmony API:ohos.miscservices.timeutility.Time.setTime +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案: 使用 setTime(Context context,Date date)方法 + +```java +long time = Time.setTime(context , date); +``` + +### **sleep** +>+ openharmony API:ohos.miscservices.timeutility.Time.sleep +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案: 使用 sleep(Long ms)方法 + +```java +Time.sleep(milliSecond); +``` + + \ No newline at end of file diff --git a/provider/MediaStore.md b/provider/MediaStore.md new file mode 100644 index 0000000..d1f6d16 --- /dev/null +++ b/provider/MediaStore.md @@ -0,0 +1,10 @@ +### provider.MediaStore + +>+ openharmony API : ohos.media.photokit.metadata.AVStorage +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 操作媒体图片、视频属性 +>+ 实现方案: + +直接替换 + diff --git a/provider/Settings.md b/provider/Settings.md new file mode 100644 index 0000000..7841f43 --- /dev/null +++ b/provider/Settings.md @@ -0,0 +1,10 @@ +### provider.Settings + +>+ openharmony API : ohos.sysappcomponents.settings.SystemSettings +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 设置提供者包含全局系统级设备首选项 +>+ 实现方案: + +直接替换使用 + diff --git a/support/v4/app/Fragment.md b/support/v4/app/Fragment.md new file mode 100644 index 0000000..fa7a3a1 --- /dev/null +++ b/support/v4/app/Fragment.md @@ -0,0 +1,10 @@ +### support.v4.app.Fragment + +>+ openharmony API: ohos.aafwk.ability.fraction.Fraction +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 页面展示 +>+ 实现方案: + +直接替换使用 + diff --git a/support/v4/util/ArrayMap.md b/support/v4/util/ArrayMap.md new file mode 100644 index 0000000..cec4fc2 --- /dev/null +++ b/support/v4/util/ArrayMap.md @@ -0,0 +1,10 @@ +### support.v4.util.ArrayMap + +>+ openharmony API: ohos.utils.LightweightMap +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 存储Map对象 +>+ 实现方案: + +直接替换使用 + diff --git a/support/v4/view/PagerAdapter.md b/support/v4/view/PagerAdapter.md new file mode 100644 index 0000000..8472c96 --- /dev/null +++ b/support/v4/view/PagerAdapter.md @@ -0,0 +1,9 @@ +### support.v4.view.PagerAdapter + +>+ openharmony API : ohos.agp.components. PageSliderProvider +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 加载数据 +>+ 实现方案: + +直接替换使用 \ No newline at end of file diff --git a/support/v4/view/ViewPager.OnPageChangeListener.md b/support/v4/view/ViewPager.OnPageChangeListener.md index c05890b..822f4c1 100644 --- a/support/v4/view/ViewPager.OnPageChangeListener.md +++ b/support/v4/view/ViewPager.OnPageChangeListener.md @@ -1,52 +1,52 @@ -### **onPageScrolled** -+ openharmony API: `ohos.agp.components.PageSlider.PageChangedListener.onPageSliding(int position, float positionOffset, int positionOffsetPixels)` -+ openharmony SDK版本:2.1.0.17 -+ IDE版本:2.1.0.141 -+ 实现方案:采用上面的API,但是当滑动到终点和往左滑动时,参数不一样,需要修正 - + 1.定义两个变量: -``` java - private float downTouchX = 0; - private boolean isScrollBack = false; -``` - + 2.在PageSlider的触摸事件中做处理,用来判断用户是否是往左滑动: -``` java - @Override - public boolean onTouchEvent(Component component, TouchEvent touchEvent) { - switch (touchEvent.getAction()) { - case TouchEvent.PRIMARY_POINT_DOWN: - downTouchX = touchEvent.getPointerScreenPosition(0).getX(); - break; - case TouchEvent.POINT_MOVE: - float newTouchX = touchEvent.getPointerScreenPosition(0).getX(); - isScrollBack = newTouchX > downTouchX; - break; - default: - break; - } - return false; - } -``` - + 3.在onPageSliding监听中先对值进行修正,然后再做要做的逻辑: -``` java - @Override - public void onPageSliding(int position, float positionOffset, int positionOffsetPixels) { - /** - * position:当前View的位置 - * positionOffset:当前View的偏移量比例.[0,1) - */ - positionOffset = positionOffset == 1 ? 0 : positionOffset; - if (isScrollBack) { - position = position - 1; - positionOffset = 1 - positionOffset; - } else { - if (position == pageSlider.getProvider().getCount() - 1 && positionOffset > 0.99) { - position = 0; - positionOffset = 0; - } - } - if (positionOffset == 0) { - isScrollBack = false; - } - //do yourself - } +### **onPageScrolled** ++ openharmony API: `ohos.agp.components.PageSlider.PageChangedListener.onPageSliding(int position, float positionOffset, int positionOffsetPixels)` ++ openharmony SDK版本:2.1.0.17 ++ IDE版本:2.1.0.141 ++ 实现方案:采用上面的API,但是当滑动到终点和往左滑动时,参数不一样,需要修正 + + 1.定义两个变量: +``` java + private float downTouchX = 0; + private boolean isScrollBack = false; +``` + + 2.在PageSlider的触摸事件中做处理,用来判断用户是否是往左滑动: +``` java + @Override + public boolean onTouchEvent(Component component, TouchEvent touchEvent) { + switch (touchEvent.getAction()) { + case TouchEvent.PRIMARY_POINT_DOWN: + downTouchX = touchEvent.getPointerScreenPosition(0).getX(); + break; + case TouchEvent.POINT_MOVE: + float newTouchX = touchEvent.getPointerScreenPosition(0).getX(); + isScrollBack = newTouchX > downTouchX; + break; + default: + break; + } + return false; + } +``` + + 3.在onPageSliding监听中先对值进行修正,然后再做要做的逻辑: +``` java + @Override + public void onPageSliding(int position, float positionOffset, int positionOffsetPixels) { + /** + * position:当前View的位置 + * positionOffset:当前View的偏移量比例.[0,1) + */ + positionOffset = positionOffset == 1 ? 0 : positionOffset; + if (isScrollBack) { + position = position - 1; + positionOffset = 1 - positionOffset; + } else { + if (position == pageSlider.getProvider().getCount() - 1 && positionOffset > 0.99) { + position = 0; + positionOffset = 0; + } + } + if (positionOffset == 0) { + isScrollBack = false; + } + //do yourself + } ``` \ No newline at end of file diff --git a/support/v4/widget/DrawerLayout.md b/support/v4/widget/DrawerLayout.md index f03bf90..6dd20fa 100644 --- a/support/v4/widget/DrawerLayout.md +++ b/support/v4/widget/DrawerLayout.md @@ -1,51 +1,51 @@ -### **closeDrawer** ->+ openharmony API: ohos.agp.components.SlideDrawer.close(closeSmoothly) ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java -// 不带动画直接关闭 -slideDrawer.close(); - -// 不带动画向指定方向关闭 -slideDrawer.close(SlideDrawer.SlideDirection.START); - -// 带动画效果的关闭方式 -slideDrawer.closeSmoothly(); - -// 带动画(指定动画时间)效果的关闭方式 -slideDrawer.closeSmoothly(350); - -// 带动画向指定方向关闭 -slideDrawer.closeSmoothly(SlideDrawer.SlideDirection.START); - -// 带动画(指定动画时间)向指定方向关闭 -slideDrawer.closeSmoothly(SlideDrawer.SlideDirection.START, 350); -``` - -### **openDrawer** ->+ openharmony API: ohos.agp.components.SlideDrawer.open(openSmoothly) ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java -// 不带动画直接打开 -slideDrawer.open(); - -// 不带动画向指定方向打开 -slideDrawer.open(SlideDrawer.SlideDirection.START); - -// 带动画效果的打开方式 -slideDrawer.openSmoothly(); - -// 带动画(指定动画时间)效果的打开方式 -slideDrawer.openSmoothly(350); - -// 带动画向指定方向打开 -slideDrawer.openSmoothly(SlideDrawer.SlideDirection.START); - -// 带动画(指定动画时间)向指定方向打开 -slideDrawer.openSmoothly(SlideDrawer.SlideDirection.START, 350); -``` - - +### **closeDrawer** +>+ openharmony API: ohos.agp.components.SlideDrawer.close(closeSmoothly) +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +// 不带动画直接关闭 +slideDrawer.close(); + +// 不带动画向指定方向关闭 +slideDrawer.close(SlideDrawer.SlideDirection.START); + +// 带动画效果的关闭方式 +slideDrawer.closeSmoothly(); + +// 带动画(指定动画时间)效果的关闭方式 +slideDrawer.closeSmoothly(350); + +// 带动画向指定方向关闭 +slideDrawer.closeSmoothly(SlideDrawer.SlideDirection.START); + +// 带动画(指定动画时间)向指定方向关闭 +slideDrawer.closeSmoothly(SlideDrawer.SlideDirection.START, 350); +``` + +### **openDrawer** +>+ openharmony API: ohos.agp.components.SlideDrawer.open(openSmoothly) +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +// 不带动画直接打开 +slideDrawer.open(); + +// 不带动画向指定方向打开 +slideDrawer.open(SlideDrawer.SlideDirection.START); + +// 带动画效果的打开方式 +slideDrawer.openSmoothly(); + +// 带动画(指定动画时间)效果的打开方式 +slideDrawer.openSmoothly(350); + +// 带动画向指定方向打开 +slideDrawer.openSmoothly(SlideDrawer.SlideDirection.START); + +// 带动画(指定动画时间)向指定方向打开 +slideDrawer.openSmoothly(SlideDrawer.SlideDirection.START, 350); +``` + + diff --git a/support/v7/app/AppCompatActivity.md b/support/v7/app/AppCompatActivity.md new file mode 100644 index 0000000..274ebfa --- /dev/null +++ b/support/v7/app/AppCompatActivity.md @@ -0,0 +1,9 @@ +### support.v7.app.AppCompatActivity + +>+ openharmony API : ohos.aafwk.ability.Ability +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: app的呈现页面 +>+ 实现方案: + +直接替换使用 \ No newline at end of file diff --git a/support/v7/widget/RecyclerView.md b/support/v7/widget/RecyclerView.md new file mode 100644 index 0000000..38ad1c7 --- /dev/null +++ b/support/v7/widget/RecyclerView.md @@ -0,0 +1,25 @@ +### support.v7.widget.RecyclerView + +>+ openharmony API : ohos.agp.components.ListContainer +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 更换控件 +>+ 实现方案: + +``` + +``` + +``` +listView = (ListContainer) findComponentById(ResourceTable.Id_lv_slide_delete); +listView.setBoundaryColor(Color.BLUE); +listView.setBoundaryThickness(2); +listView.setBoundarySwitch(true); +mProvider = new MyItemProvider( data,this); +listView.setItemProvider(mProvider); +``` \ No newline at end of file diff --git a/support/v7/widget/SimpleItemAnimator.md b/support/v7/widget/SimpleItemAnimator.md new file mode 100644 index 0000000..1bcdfc3 --- /dev/null +++ b/support/v7/widget/SimpleItemAnimator.md @@ -0,0 +1,219 @@ +### support.v7.widget.SimpleItemAnimator + +>+ openharmony API : ohos.agp.components.ListContainer +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 自定义ItemLayout实现Component的TouchEventListener及BindStateChangedListener +>+ 实现方案: + +参考实现: + +``` +import ohos.agp.animation.Animator; +import ohos.agp.animation.AnimatorValue; +import ohos.agp.components.AttrSet; +import ohos.agp.components.Component; +import ohos.agp.components.DirectionalLayout; +import ohos.app.Context; +import ohos.hiviewdfx.HiLog; +import ohos.hiviewdfx.HiLogLabel; +import ohos.multimodalinput.event.MmiPoint; +import ohos.multimodalinput.event.TouchEvent; + +public class ItemLayout extends DirectionalLayout implements Component.TouchEventListener , Component.BindStateChangedListener { + + static final HiLogLabel label = new HiLogLabel(HiLog.LOG_APP, 0x00201, "LAYOUT"); + private int downX; + private int downY; + private int slideX; + private boolean isSlide; + private int touchSlop; + private CallBack callBack; + + public ItemLayout(Context context) { + super(context); + init(); + } + + public ItemLayout(Context context, AttrSet attrSet) { + super(context, attrSet); + init(); + } + + public ItemLayout(Context context, AttrSet attrSet, String styleName) { + super(context, attrSet, styleName); + init(); + + } + public void init(){ + touchSlop = 8; + isSlide = false; + setTouchEventListener(this); + setBindStateChangedListener(this); + } + + public boolean ifSlideLeft(Component component, TouchEvent ev) { + switch (ev.getAction()) { + case TouchEvent.PRIMARY_POINT_DOWN: + MmiPoint point = ev.getPointerPosition(ev.getIndex()); + downX = (int) point.getX(); + downY = (int) point.getY(); + break; + case TouchEvent.POINT_MOVE: + MmiPoint point1 = ev.getPointerPosition(ev.getIndex()); + int deltaX = (int) point1.getX() - downX; + int deltaY = (int) point1.getY() - downY; + if (Math.abs(deltaX) > Math.abs(deltaY) && Math.abs(deltaX) > touchSlop) + { + isSlide = true; + } else { + isSlide = false; + } + } + return isSlide; + } + + @Override + public boolean onTouchEvent(Component component, TouchEvent ev) { + if (ifSlideLeft(component,ev)) { + MmiPoint point = ev.getPointerPosition(ev.getIndex()); + downX = (int) point.getX(); + downY = (int) point.getY(); + switch (ev.getAction()) { + case TouchEvent.PRIMARY_POINT_DOWN: + break; + case TouchEvent.POINT_MOVE: + slideX = component.getWidth() - downX; + component.setContentPosition(-slideX, component.getContentPositionY()); + break; + case TouchEvent.PRIMARY_POINT_UP: + + if (slideX >= (component.getWidth()) / 2) { + HiLog.info(label,"bbbb---slideX="+slideX); + HiLog.info(label,"bbbb--getWidth="+component.getWidth()); + component.setContentPosition(-getWidth(), getContentPositionY()); + //调用删除方法 + callBack.call(mPosition); + } else { + component.setContentPosition(0, component.getContentPositionY()); + callBack.refresh(); + } + isSlide = false; + break; + } + return true; + } else { + switch (ev.getAction()) { + case TouchEvent.PRIMARY_POINT_DOWN: + break; + case TouchEvent.PRIMARY_POINT_UP: + setScale(1.3f,1.3f); + //判断是否选中 + if(callBack.isCheck(mPosition) == 1){ + float y= callBack.move(mPosition); + AnimatorValue value=new AnimatorValue(); + value.setCurveType(Animator.CurveType.LINEAR); + value.setDuration(500); + value.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() { + @Override + public void onUpdate(AnimatorValue animatorValue, float v) { + + if(y*v>=getContentPositionY()){ + setContentPositionY(y*v); + } + if(v==1){ + setScale(1,1); + callBack.moveToButtom(); + } + } + }); + value.start(); + + }else if(callBack.isCheck(mPosition) == 2){ + setScale(1.3f,1.3f); + float y= callBack.moveTop(mPosition); + AnimatorValue value=new AnimatorValue(); + value.setCurveType(Animator.CurveType.LINEAR); + value.setDuration(500); + value.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() { + @Override + public void onUpdate(AnimatorValue animatorValue, float v) { + if(-y*v<=getContentPositionY()){ + setContentPositionY(-y*v); + } + if(v==1){ + setScale(1,1); + callBack.moveToFront(mPosition); + } + } + }); + value.start(); + + }else { + setScale(1f,1f); + AnimatorValue value=new AnimatorValue(); + value.setCurveType(Animator.CurveType.LINEAR); + callBack.showTips(mPosition); + value.setDuration(100); + value.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() { + @Override + public void onUpdate(AnimatorValue animatorValue, float v) { + setScale(1,1); + } + }); + value.start(); + } + break; + } + return false; + } + } + + public void setCallBack(CallBack callBack) { + this.callBack = callBack; + } + + + + private int mPosition; + + + public void setPosition(int position) { + mPosition = position; + } + + @Override + public void onComponentBoundToWindow(Component component) { + AnimatorValue value=new AnimatorValue(); + value.setCurveType(Animator.CurveType.LINEAR); + value.setDuration(1000); + value.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() { + @Override + public void onUpdate(AnimatorValue animatorValue, float v) { + //setScale(1,1); + } + }); + value.start(); + } + + @Override + public void onComponentUnboundFromWindow(Component component) { + + } + + + public interface CallBack{ + void call(int position); + void refresh(); + void moveToButtom(); + float move(int position); + float moveTop(int position); + void moveToFront(int position); + int isCheck(int position); + void showTips(int position); + + } + +} +``` + diff --git a/telephony/telephony.md b/telephony/telephony.md new file mode 100644 index 0000000..12083a6 --- /dev/null +++ b/telephony/telephony.md @@ -0,0 +1,66 @@ +### os.Parcelable + +>+ openharmony API : ohos.telephony.RadioInfoManager +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 电话服务 +>+ 实现方案: + +参考实现: + +``` +private void getTelephonyData() { + //卡1 : 0 ;卡2 :1 卡槽索引号,取值范围为0〜设备支持的最大卡槽索引号 + int slotld = 0; + // 获取RadioInfoManager对象。 + RadioInfoManager radioInfoManager = RadioInfoManager.getInstance(this); + + //获取注册网络中CS域的RAT。 + RadioInfoManagerUtils managerUtils = new RadioInfoManagerUtils(this); + String phoneType = managerUtils.getPhoneType(slotld); + text_gs.setText("手机类型: " + phoneType); + + text_imei.setText("IMEI: " + radioInfoManager.getImei(slotld)); + //软件版本 + text_ril.setText("RIL 版本: " + radioInfoManager.getImeiSv(slotld)); + + //获取部署注册网络所在国家/地区的ISO定义的国家/地区代码。 + text_country.setText("国家: " + radioInfoManager.getIsoCountryCodeForNetwork(slotld)); + + //运营商ID + text_id.setText("运营商ID: " + radioInfoManager.getUniqueDeviceId(slotld)); + + //获取注册网络的运营商名称。 + text_name.setText("运营商名称: " + radioInfoManager.getOperatorName(slotld)); + + //IMSI + text_imsi.setText("IMSI: " + radioInfoManager.getPrimarySlotId()); + + //序列号 + text_xil.setText("序列号: " + radioInfoManager.getPlmnNumeric(slotld)); + + + //获取设备指定卡槽的制造商代码。 + text_gys.setText("供应商名称: " + radioInfoManager.getOperatorName(slotld)); + + //供应商代码 + text_gysdm.setText("供应商代码: " + radioInfoManager.getPlmnNumeric(slotld)); + + //检查设备是否在漫游网络中注册。 + text_roa.setText("漫游状态: " + radioInfoManager.isRoaming(slotld)); + + //获取指定槽位SIM卡的网络搜索模式。 + text_mode.setText("网络模式: " + radioInfoManager.getNetworkSelectionMode(slotld)); + + //获取注册网络的网络状态。 + String networkState = managerUtils.getNetworkState(slotld); + text_data.setText("数据状态: " + networkState); + + // 获取对应于指定SIM卡的注册网络的信号强度信息列表。 + List signalList = radioInfoManager.getSignalInfoList(1); + + // 检查信号信息列表大小。 + new ToastDialog(this).setText("网络信号:" + signalList.size()).show(); + +} +``` \ No newline at end of file diff --git a/text/TextPaint.md b/text/TextPaint.md new file mode 100644 index 0000000..b192f8d --- /dev/null +++ b/text/TextPaint.md @@ -0,0 +1,9 @@ +### text.TextPaint + +>+ openharmony API : ohos.agp.reder.Paint +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 画布 +>+ 实现方案: + +直接替换使用 \ No newline at end of file diff --git a/text/TextUtils.md b/text/TextUtils.md index 614eaff..6e870ee 100644 --- a/text/TextUtils.md +++ b/text/TextUtils.md @@ -1,25 +1,25 @@ -### **isEmpty** ->+ openharmony API: ohos.agp.utils.TextTool.isNullOrEmpty ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java -String str = ""; -// 判断是否为空或者为null -TextTool.isNullOrEmpty(str); - -``` - -### **equals** ->+ openharmony API: ohos.agp.utils.TextTool.isEqual ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java -String strA = "TestA"; -String strB = "TestB"; -// 判断是否相等 -TextTool.isEqual(strA, strB); - -``` - +### **isEmpty** +>+ openharmony API: ohos.agp.utils.TextTool.isNullOrEmpty +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +String str = ""; +// 判断是否为空或者为null +TextTool.isNullOrEmpty(str); + +``` + +### **equals** +>+ openharmony API: ohos.agp.utils.TextTool.isEqual +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +String strA = "TestA"; +String strB = "TestB"; +// 判断是否相等 +TextTool.isEqual(strA, strB); + +``` + diff --git a/util/AttributeSet.md b/util/AttributeSet.md new file mode 100644 index 0000000..b999ba8 --- /dev/null +++ b/util/AttributeSet.md @@ -0,0 +1,35 @@ +### util.AttributeSet + +>+ openharmony API : ohos.agp.components.AttrSet +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 自定义视图的自定义属性 +>+ 实现方案: + +``` + + + + + +``` + +``` +private void getAttrs(AttrSet attrs) { + isDropDownStyle = getBooleanValue(attrs, "isDropDownStyle", true); + isOnBottomStyle = getBooleanValue(attrs, "isOnBottomStyle", true); + isAutoLoadOnBottom = getBooleanValue(attrs, "isAutoLoadOnBottom", true); +} +``` \ No newline at end of file diff --git a/util/SparseArray.md b/util/SparseArray.md index 4ad24a2..ab6db34 100644 --- a/util/SparseArray.md +++ b/util/SparseArray.md @@ -1,59 +1,59 @@ -### **put** ->+ openharmony API: ohos.utils.PlainArray.put ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java -PlainArray plainArray = new PlainArray<>(); -plainArray.put(1, "A"); -``` - -### **append** ->+ openharmony API: ohos.utils.PlainArray.append ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java -PlainArray plainArray = new PlainArray<>(); -plainArray.append(2,"B"); -``` - -### **remove** ->+ openharmony API: ohos.utils.PlainArray.remove ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java -PlainArray plainArray = new PlainArray<>(); -plainArray.remove(1); -``` - -### **removeAt** ->+ openharmony API: ohos.utils.PlainArray.removeAt ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java -PlainArray plainArray = new PlainArray<>(); -plainArray.removeAt(0); -``` - -### **contains** ->+ openharmony API: ohos.utils.PlainArray.contains ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java -PlainArray plainArray = new PlainArray<>(); -plainArray.contains(1); -``` - -### **clear** ->+ openharmony API: ohos.utils.PlainArray.clear ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java -PlainArray plainArray = new PlainArray<>(); -plainArray.clear(); -``` +### **put** +>+ openharmony API: ohos.utils.PlainArray.put +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +PlainArray plainArray = new PlainArray<>(); +plainArray.put(1, "A"); +``` + +### **append** +>+ openharmony API: ohos.utils.PlainArray.append +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +PlainArray plainArray = new PlainArray<>(); +plainArray.append(2,"B"); +``` + +### **remove** +>+ openharmony API: ohos.utils.PlainArray.remove +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +PlainArray plainArray = new PlainArray<>(); +plainArray.remove(1); +``` + +### **removeAt** +>+ openharmony API: ohos.utils.PlainArray.removeAt +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +PlainArray plainArray = new PlainArray<>(); +plainArray.removeAt(0); +``` + +### **contains** +>+ openharmony API: ohos.utils.PlainArray.contains +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +PlainArray plainArray = new PlainArray<>(); +plainArray.contains(1); +``` + +### **clear** +>+ openharmony API: ohos.utils.PlainArray.clear +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +PlainArray plainArray = new PlainArray<>(); +plainArray.clear(); +``` diff --git a/util/TypedValue.md b/util/TypedValue.md index 794293c..4ea2e63 100644 --- a/util/TypedValue.md +++ b/util/TypedValue.md @@ -1,17 +1,17 @@ -# TypedValue -* openharmony API: ohos.agp.components.AttrHelper -* openharmony SDK版本:2.0.1.93及以上 -* IDE版本:2.0.12.131 -* 实现方案: -## fp转px -```java - public static float fpToPixels(Context context, float value) { - return AttrHelper.fp2px(value,context); - } - ``` -## vp转px -```java - public static float vpToPixels(Context context, float value) { - return AttrHelper.vp2px(value,context); - } +# TypedValue +* openharmony API: ohos.agp.components.AttrHelper +* openharmony SDK版本:2.0.1.93及以上 +* IDE版本:2.0.12.131 +* 实现方案: +## fp转px +```java + public static float fpToPixels(Context context, float value) { + return AttrHelper.fp2px(value,context); + } + ``` +## vp转px +```java + public static float vpToPixels(Context context, float value) { + return AttrHelper.vp2px(value,context); + } ``` \ No newline at end of file diff --git a/util/encode.md b/util/encode.md new file mode 100644 index 0000000..4ae7eca --- /dev/null +++ b/util/encode.md @@ -0,0 +1,38 @@ +### util.encode + +>+ openharmony API : 无,使用java.util.Base64替换 +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案: + +``` +public byte[] encode(byte[] input) { + return Base64.getEncoder().encode(input); +} +``` + +### util.decode + +>+ openharmony API: 无,使用java.util.Base64替换 +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案: + +``` +public String decode(String string) { + return Base32.decode(string); +} +``` + +### util.encodeToString + +>+ openharmony API: 无,使用java.util.Base64替换 +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案: + +``` +public String encodeToString(byte[] input) { + return Base64.encodeToString(input, BASE64_ENCODER_FLAGS); +} +``` \ No newline at end of file diff --git a/view/Display.md b/view/Display.md new file mode 100644 index 0000000..afe6ef9 --- /dev/null +++ b/view/Display.md @@ -0,0 +1,9 @@ +### view.Display + +>+ openharmony API : ohos.agp.window.service.DisplayManager +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 提供设备大小密度等信息 +>+ 实现方案: + +直接替换使用 \ No newline at end of file diff --git a/view/Gravity.md b/view/Gravity.md new file mode 100644 index 0000000..cfeb238 --- /dev/null +++ b/view/Gravity.md @@ -0,0 +1,10 @@ +### view.Gravity + +>+ openharmony API : ohos.agp.utils.LayoutAlignment +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 布局排放位置 +>+ 实现方案: + +直接替换使用 + diff --git a/view/LayoutInflater.md b/view/LayoutInflater.md index e283e06..28084ec 100644 --- a/view/LayoutInflater.md +++ b/view/LayoutInflater.md @@ -1,5 +1,5 @@ -### **inflate** ->+ openharmony API:ohos.agp.components.LayoutScatter.parse ->+ openharmony SDK版本:2.1.1.21 ->+ IDE版本:2.1.0.501 +### **inflate** +>+ openharmony API:ohos.agp.components.LayoutScatter.parse +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 >+ 实现方案:直接替换 \ No newline at end of file diff --git a/view/Menu.md b/view/Menu.md new file mode 100644 index 0000000..f2981c6 --- /dev/null +++ b/view/Menu.md @@ -0,0 +1,35 @@ +### view.Menu + +>+ openharmony API: 无 +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 显示菜单栏 +>+ 实现方案: + +参考实现: + +``` +private void createMenuComponent() { + Component menu = LayoutScatter.getInstance(getContext()).parse(ResourceTable.Layout_menu, null, false); + textThemeChange = (Text) menu.findComponentById(ResourceTable.Id_theme_change); + textAbout = (Text) menu.findComponentById(ResourceTable.Id_about); + textThemeChange.setClickedListener(clickedListener); + if (isDarkTheme()) { + textThemeChange.setText("Use Light Theme"); + } else { + textThemeChange.setText("Use Dark Theme"); + } + textAbout.setClickedListener(clickedListener); + + mMenuDialog = new PopupDialog(MainAbilitySlice.this, mImageRightTitle); + mMenuDialog.setCustomComponent(menu); + mMenuDialog.setDialogListener(new BaseDialog.DialogListener() { + @Override + public boolean isTouchOutside() { + mMenuDialog.remove(); + return false; + } + }); + mMenuDialog.show(); +} +``` \ No newline at end of file diff --git a/view/MotionEvent.md b/view/MotionEvent.md index c86fe75..ddfcc88 100644 --- a/view/MotionEvent.md +++ b/view/MotionEvent.md @@ -1,12 +1,12 @@ -### **getActionIndex** ->+ openharmony API: ohos.multimodalinput.event.TouchEvent.getIndex ->+ openharmony SDK版本:2.1.1.21 ->+ IDE版本:2.1.0.501 ->+ 实现方案:直接替换 - -### **getActionMasked** ->+ openharmony API: ohos.multimodalinput.event.TouchEvent.getAction ->+ openharmony SDK版本:2.1.1.21 ->+ IDE版本:2.1.0.501 ->+ 实现方案:直接替换 - +### **getActionIndex** +>+ openharmony API: ohos.multimodalinput.event.TouchEvent.getIndex +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案:直接替换 + +### **getActionMasked** +>+ openharmony API: ohos.multimodalinput.event.TouchEvent.getAction +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案:直接替换 + diff --git a/view/SurfaceHolder.md b/view/SurfaceHolder.md new file mode 100644 index 0000000..1dae615 --- /dev/null +++ b/view/SurfaceHolder.md @@ -0,0 +1,10 @@ +### view.SurfaceHolder + +>+ openharmony API: ohos.agp.graphics.SurfaceOps +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 相机使用 +>+ 实现方案: + +直接替换使用 + diff --git a/view/VelocityTracker.md b/view/VelocityTracker.md index 637ee65..7fa03d6 100644 --- a/view/VelocityTracker.md +++ b/view/VelocityTracker.md @@ -1,70 +1,70 @@ - -### **obtain** ->+ openharmony API: ohos.agp.components.VelocityDetector.obtainInstance ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:直接替换 - - -### **addMovement** ->+ openharmony API: ohos.agp.components.VelocityDetector.addEvent ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:替换使用,使用方法如下: -```java -VelocityDetector detector = VelocityDetector.obtainInstance(); -detector.addEvent(touchEvent); -``` - -### **computeCurrentVelocity** ->+ openharmony API: ohos.agp.components.VelocityDetector.calculateCurrentVelocity ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:替换使用,使用方法如下: -```java -VelocityDetector detector = VelocityDetector.obtainInstance(); -detector.calculateCurrentVelocity(units, maxVxVelocity, maxVyVelocity); -``` ->+ 注意事项:给TouchEvent事件添加惯性(VelocityDetector)的时候必须要按如下顺序才可以正常获取到VelocityDetector的数值,否则数值会一直是0 -顺序如下: -VelocityDetector detector = VelocityDetector.obtainInstance(); -detector.addEvent(touchEvent); -detector.calculateCurrentVelocity(1000, 10000, 10000); -float velocity = detector.getVerticalVelocity(); - - -### **getXVelocity** ->+ openharmony API: ohos.agp.components.VelocityDetector.getHorizontalVelocity ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:替换使用,使用方法如下: - -```java -VelocityDetector detector = VelocityDetector.obtainInstance(); -// 必须先调用computeCurrentVelocity方法 -detector.getHorizontalVelocity(); -``` - - -### **getYVelocity** ->+ openharmony API: ohos.agp.components.VelocityDetector.getVerticalVelocity ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:替换使用,使用方法如下: - -```java -VelocityDetector detector = VelocityDetector.obtainInstance(); -// 必须先调用computeCurrentVelocity方法 -detector.getVerticalVelocity(); -``` - -### **clear** ->+ openharmony API: ohos.agp.components.VelocityDetector.clear ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:替换使用,使用方法如下: - -```java -VelocityDetector detector = VelocityDetector.obtainInstance(); -detector.clear(); + +### **obtain** +>+ openharmony API: ohos.agp.components.VelocityDetector.obtainInstance +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:直接替换 + + +### **addMovement** +>+ openharmony API: ohos.agp.components.VelocityDetector.addEvent +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用,使用方法如下: +```java +VelocityDetector detector = VelocityDetector.obtainInstance(); +detector.addEvent(touchEvent); +``` + +### **computeCurrentVelocity** +>+ openharmony API: ohos.agp.components.VelocityDetector.calculateCurrentVelocity +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用,使用方法如下: +```java +VelocityDetector detector = VelocityDetector.obtainInstance(); +detector.calculateCurrentVelocity(units, maxVxVelocity, maxVyVelocity); +``` +>+ 注意事项:给TouchEvent事件添加惯性(VelocityDetector)的时候必须要按如下顺序才可以正常获取到VelocityDetector的数值,否则数值会一直是0 +顺序如下: +VelocityDetector detector = VelocityDetector.obtainInstance(); +detector.addEvent(touchEvent); +detector.calculateCurrentVelocity(1000, 10000, 10000); +float velocity = detector.getVerticalVelocity(); + + +### **getXVelocity** +>+ openharmony API: ohos.agp.components.VelocityDetector.getHorizontalVelocity +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用,使用方法如下: + +```java +VelocityDetector detector = VelocityDetector.obtainInstance(); +// 必须先调用computeCurrentVelocity方法 +detector.getHorizontalVelocity(); +``` + + +### **getYVelocity** +>+ openharmony API: ohos.agp.components.VelocityDetector.getVerticalVelocity +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用,使用方法如下: + +```java +VelocityDetector detector = VelocityDetector.obtainInstance(); +// 必须先调用computeCurrentVelocity方法 +detector.getVerticalVelocity(); +``` + +### **clear** +>+ openharmony API: ohos.agp.components.VelocityDetector.clear +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用,使用方法如下: + +```java +VelocityDetector detector = VelocityDetector.obtainInstance(); +detector.clear(); ``` \ No newline at end of file diff --git a/view/View.MeasureSpec.md b/view/View.MeasureSpec.md index c731e75..32deec3 100644 --- a/view/View.MeasureSpec.md +++ b/view/View.MeasureSpec.md @@ -1,53 +1,53 @@ -### **UNSPECIFIED** ->+ openharmony API: ohos.agp.components.Component$EstimateSpec.UNCONSTRAINT ->+ openharmony SDK版本:2.1.1.21 ->+ IDE版本:2.1.0.501 ->+ 实现方案:直接替换 - - -### **EXACTLY** ->+ openharmony API: ohos.agp.components.Component$EstimateSpec.PRECISE ->+ openharmony SDK版本:2.1.1.21 ->+ IDE版本:2.1.0.501 ->+ 实现方案:直接替换 - - -### **AT_MOST** ->+ openharmony API: ohos.agp.components.Component$EstimateSpec.NOT_EXCEED ->+ openharmony SDK版本:2.1.1.21 ->+ IDE版本:2.1.0.501 ->+ 实现方案:直接替换 - - -### **MODE_MASK** ->+ openharmony API: ohos.agp.components.Component$EstimateSpec.ESTIMATED_STATE_BIT_MASK ->+ openharmony SDK版本:2.1.1.21 ->+ IDE版本:2.1.0.501 ->+ 实现方案:直接替换 - - -### **makeMeasureSpec** ->+ openharmony API: 暂无 ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:暂无相关替换,可以自行实现。 - -```java -public static int makeEstimateSpec(int size, int mode) { - return (size & ~EstimateSpec.ESTIMATED_STATE_BIT_MASK) | (mode & EstimateSpec.ESTIMATED_STATE_BIT_MASK); -} -``` - - -### **getMode** ->+ openharmony API: ohos.agp.components.Component$EstimateSpec.getMode ->+ openharmony SDK版本:2.1.1.21 ->+ IDE版本:2.1.0.501 ->+ 实现方案:直接替换 - - -### **getSize** ->+ openharmony API: ohos.agp.components.Component$EstimateSpec.getSize ->+ openharmony SDK版本:2.1.1.21 ->+ IDE版本:2.1.0.501 ->+ 实现方案:直接替换 +### **UNSPECIFIED** +>+ openharmony API: ohos.agp.components.Component$EstimateSpec.UNCONSTRAINT +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案:直接替换 + + +### **EXACTLY** +>+ openharmony API: ohos.agp.components.Component$EstimateSpec.PRECISE +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案:直接替换 + + +### **AT_MOST** +>+ openharmony API: ohos.agp.components.Component$EstimateSpec.NOT_EXCEED +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案:直接替换 + + +### **MODE_MASK** +>+ openharmony API: ohos.agp.components.Component$EstimateSpec.ESTIMATED_STATE_BIT_MASK +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案:直接替换 + + +### **makeMeasureSpec** +>+ openharmony API: 暂无 +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:暂无相关替换,可以自行实现。 + +```java +public static int makeEstimateSpec(int size, int mode) { + return (size & ~EstimateSpec.ESTIMATED_STATE_BIT_MASK) | (mode & EstimateSpec.ESTIMATED_STATE_BIT_MASK); +} +``` + + +### **getMode** +>+ openharmony API: ohos.agp.components.Component$EstimateSpec.getMode +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案:直接替换 + + +### **getSize** +>+ openharmony API: ohos.agp.components.Component$EstimateSpec.getSize +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案:直接替换 diff --git a/view/View.md b/view/View.md index 48127a9..7679105 100644 --- a/view/View.md +++ b/view/View.md @@ -1,72 +1,234 @@ -### **onMeasure** ->+ openharmony API: ohos.agp.components.Component.onEstimateSize ->+ openharmony SDK版本:2.1.0.17 以上 ->+ IDE版本:2.1.0.141 ->+ 实现方案:实现接口 implements Component.EstimateSizeListener,设置监听 setEstimateSizeListener(this) - - @Override - public boolean onEstimateSize(int widthEstimatedConfig, int heightEstimatedConfig) { - return true; - } - ->+ 补充说明:onEstimateSize在sdk 2.1.0.17以前未实现,临时方案可以通过在构造函数中调用setLayoutRefreshedListener或者addDrawTask中去获取宽高信息 - - - -### **onLayout** ->+ openharmony API: ohos.agp.components.Component.onArrange ->+ openharmony SDK版本:2.1.0.17 以上 ->+ IDE版本:2.1.0.141 ->+ 实现方案:实现接口 implements ComponentContainer.ArrangeListener,设置监听 setArrangeListener(this) - - @Override - public boolean onArrange(int l, int t, int r, int b) { - return true; - } - ->+ 补充说明:onArrange在sdk 2.1.0.17以前未实现,临时方案为,如果不涉及到View.layout()操作可以直接将逻辑放到onDraw里面,否则可以通过component.setComponentPosition()对子控件重新布局; - - -### **onDraw** ->+ openharmony API: ohos.agp.components.Component.addDrawTask ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:在构造函数调用addDrawTask(this),自定义Component实现Component.DrawTask接口,重写onDraw(Component component, Canvas canvas)方法。 - -### **onSizeChanged** ->+ openharmony API: ohos.agp.components.Component.LayoutRefreshedListener ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:可以在构造函数或者其他地方主动调用。 - -### **onAttachedToWindow** ->+ openharmony API: ohos.agp.components.Component.BindStateChangedListener ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:可以在构造函数或者其他地方主动调用。 - -### **onDetachedFromWindow** ->+ openharmony API: ohos.agp.components.Component.BindStateChangedListener ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:可以在构造函数或者其他地方主动调用。 - -### **onTouchEvent** ->+ openharmony API: ohos.agp.components.Component.setTouchEventListener ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:在构造函数调用setTouchEventListener(Component.TouchEventListener listener),自定义Component实现Component.TouchEventListener接口,重写onTouchEvent(MotionEvent event)方法。 - -### **onScrollChanged** - ->+ openharmony API: ohos.agp.components.ComponentTreeObserver.addScrolledListener ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:在构造函数调用getComponentTreeObserver().addScrolledListener(ComponentTreeObserver.ScrollChangedListener listener),自定义Component实现ComponentTreeObserver.ScrollChangedListener接口,onScrolled()方法。 - -### **invalidate** - ->+ openharmony API: ohos.agp.components.Component.invalidate ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:在onDraw()方法中调用直接invalidate()方法无效,需在asyncDispatch方法中调用,如下:getContext().getUITaskDispatcher().asyncDispatch(this::invalidate)。 \ No newline at end of file +### **onMeasure** +>+ openharmony API: ohos.agp.components.Component.onEstimateSize +>+ openharmony SDK版本:2.1.0.17 以上 +>+ IDE版本:2.1.0.141 +>+ 实现方案:实现接口 implements Component.EstimateSizeListener,设置监听 setEstimateSizeListener(this) + + @Override + public boolean onEstimateSize(int widthEstimatedConfig, int heightEstimatedConfig) { + return true; + } + +>+ 补充说明:onEstimateSize在sdk 2.1.0.17以前未实现,临时方案可以通过在构造函数中调用setLayoutRefreshedListener或者addDrawTask中去获取宽高信息 + + + +### **onLayout** +>+ openharmony API: ohos.agp.components.Component.onArrange +>+ openharmony SDK版本:2.1.0.17 以上 +>+ IDE版本:2.1.0.141 +>+ 实现方案:实现接口 implements ComponentContainer.ArrangeListener,设置监听 setArrangeListener(this) + + @Override + public boolean onArrange(int l, int t, int r, int b) { + return true; + } + +>+ 补充说明:onArrange在sdk 2.1.0.17以前未实现,临时方案为,如果不涉及到View.layout()操作可以直接将逻辑放到onDraw里面,否则可以通过component.setComponentPosition()对子控件重新布局; + + +### **onDraw** +>+ openharmony API: ohos.agp.components.Component.addDrawTask +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:在构造函数调用addDrawTask(this),自定义Component实现Component.DrawTask接口,重写onDraw(Component component, Canvas canvas)方法。 + +### **onSizeChanged** +>+ openharmony API: ohos.agp.components.Component.LayoutRefreshedListener +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:可以在构造函数或者其他地方主动调用。 + +### **onAttachedToWindow** +>+ openharmony API: ohos.agp.components.Component.BindStateChangedListener +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:可以在构造函数或者其他地方主动调用。 + +### **onDetachedFromWindow** +>+ openharmony API: ohos.agp.components.Component.BindStateChangedListener +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:可以在构造函数或者其他地方主动调用。 + +### **onTouchEvent** +>+ openharmony API: ohos.agp.components.Component.setTouchEventListener +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:在构造函数调用setTouchEventListener(Component.TouchEventListener listener),自定义Component实现Component.TouchEventListener接口,重写onTouchEvent(MotionEvent event)方法。 + +### **onScrollChanged** + +>+ openharmony API: ohos.agp.components.ComponentTreeObserver.addScrolledListener +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:在构造函数调用getComponentTreeObserver().addScrolledListener(ComponentTreeObserver.ScrollChangedListener listener),自定义Component实现ComponentTreeObserver.ScrollChangedListener接口,onScrolled()方法。 + +### **invalidate** + +>+ openharmony API: ohos.agp.components.Component.invalidate +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:在onDraw()方法中调用直接invalidate()方法无效,需在asyncDispatch方法中调用,如下:getContext().getUITaskDispatcher().asyncDispatch(this::invalidate)。 + +### computeScroll + +>+ openharmony API: 无 +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 在绘制时调用此接口,计算滑动状态并判断滑动是否完成,如果未完成需要postInvalidate事件触发下个滑动状态的绘制 +>+ 实现方案: + +OHOS由于没有此回调,可以通过添加一个DrawTask,在其onDraw回调中调用相关逻辑 + +``` +addDrawTask(new DrawTask() { + @Override + public void onDraw(Component component, Canvas canvas) { + computeScroll(); + } +}); +``` + +``` +private void computeScroll() { + if (mDragHelper.continueSettling(true)) { + this.getContext().getUITaskDispatcher().asyncDispatch(this::invalidate); + } +} +``` + +### offsetLeftAndRight + +>+ openharmony API: +> +> ohos.agp.components.Component.setComponentPosition(Rect position) +> +> ohos.agp.components.Component.translateX(float dx) +> +>+ openharmony SDK版本:2.1.1.21 +> +>+ 应用场景: 将控件水平方向平移 +> +>+ IDE版本:2.1.0.501 +> +>+ 实现方案: + +OHOS平移控件有两种方式,一种为修改控件left、right值,一种为添加translation,最终的显示位置为二者叠加的结果,即区间[left+translateX, right + translateX]。从android源码来看,offsetLeftAndRight修改的是left、right值,因此方案一更接近原本逻辑 + +方案一: + +``` +//修改控件left、right值 + +Rect position = component.getComponentPosition(); + +position.translate(dx, 0); + +component.setComponentPosition(position); +``` + +方案二: + +``` +//对控件添加平移操作transitionX + +component.setTranslationX(component.getTranslationX() + dx) +``` + +### onWindowFocusChanged + +>+ openharmony API: +> +> ohos.agp.components.Component.LayoutRefreshedListener.onRefreshed(Component component) +> +>+ openharmony SDK版本:2.1.1.21 +> +>+ IDE版本:2.1.0.501 +> +>+ 实现方案: + +直接替换使用 + +除此之外还有可考虑 + +ohos.agp.components.Component.BindStateChangedListener.onComponentBoundToWindow(Component var1) + +ohos.agp.components.Component.FocusChangedListener.onFocusChange(Component var1, boolean var2) + +根据具体场景实验、选择 + +### onFinishInflate + +>+ openharmony API : onFinishflate() +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景: 序列化 +>+ 实现方案: + +在AbilitySlice()中的onStart()必须调onFinishFlate()初始化ContentContainerImpl(),必须项。 + +注:因为该方法需要初始化面板信息,OHOS中没有对应的api,故是个暂时的办法,后面出现对应api在进行更改。 + +``` +public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_ability_api_auto_reset_enable_layout); + mPanelSwitchLayout =(PanelSwitchLayout)findComponentById(ResourceTable.Id_panel_view); + RelativeContentContainer container =(RelativeContentContainer) findComponentById(ResourceTable.Id_recc_pageview); + PanelContainer panelContainer=(PanelContainer)findComponentById(ResourceTable.Id_panelc_container); + int count= mPanelSwitchLayout.getChildCount(); + + HiLog.info(LABEL,"获取的当前view的子类数量 : "+count); + HiLog.info(LABEL,"获取的当前view的id : "+mPanelSwitchLayout.getComponentAt(0).getId()+", mPanelSwitchLayout id is "+mPanelSwitchLayout.getId()); + + HiLog.info(LABEL,"获取的当前view的子类id PanelContainer : "+panelContainer.getId()); + + container.onFinishFlate(); + mPanelSwitchLayout.onFinishInflate(); + addbt=(Image)findComponentById(ResourceTable.Id_add_btn); + emotion_btn=(Image)findComponentById(ResourceTable.Id_emotion_btn); + HiLog.info(LABEL, "mPanelSwitchLayout的ResourceTable.Id_panel_view editTextid:" + ResourceTable.Id_panel_view); + init(); + } +``` + +### setBackground + +>+ openharmony API: ohos.agp.components.Component.setBackground(Element element) +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案: + +参考示例: + +``` +public static void setBackground(Component v, int drawableRes) { + + ImageSource.SourceOptions srcOpts = new ImageSource.SourceOptions(); + ImageSource imageSource = null; + try { + imageSource = ImageSource.create(v.getContext().getResourceManager().getResource(drawableRes), srcOpts); + } catch (IOException e) { + e.printStackTrace(); + } catch (NotExistException e) { + e.printStackTrace(); + } + ImageSource.DecodingOptions decodingOpts = new ImageSource.DecodingOptions(); + PixelMap pixelMap = imageSource.createPixelmap(decodingOpts); + v.setBackground(new PixelMapElement(pixelMap)); +} +``` + +### setBackgroundColor + +>+ openharmony API : ohos.agp.components.Component.setBackground(Element element) +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案: + +``` +shapeElement.setRgbColor(RgbColor.fromArgbInt(mColorInt)); +view.setBackground(shapeElement); +``` + diff --git a/view/ViewConfiguration.md b/view/ViewConfiguration.md new file mode 100644 index 0000000..c795393 --- /dev/null +++ b/view/ViewConfiguration.md @@ -0,0 +1,61 @@ +### view.ViewConfiguration + +>+ openharmony API : 无 +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案: + +提供view滑动常量值 + +``` +public class ViewConfiguration { + + private static final int DEFAULT_LONG_PRESS_TIMEOUT = 500; + + private static final int TAP_TIMEOUT = 100; + + private static final int DOUBLE_TAP_TIMEOUT = 300; + + private static final int DOUBLE_TAP_MIN_TIME = 40; + + private static final int TOUCH_SLOP = 8; + + private static final int DOUBLE_TAP_SLOP = 100; + + private static final int MINIMUM_FLING_VELOCITY = 200; + + private static final int MAXIMUM_FLING_VELOCITY = 8000; + + public static int getLongPressTimeout() { + return DEFAULT_LONG_PRESS_TIMEOUT; + } + + public static int getTapTimeout() { + return TAP_TIMEOUT; + } + + public static int getDoubleTapTimeout() { + return DOUBLE_TAP_TIMEOUT; + } + + public static int getDoubleTapMinTime() { + return DOUBLE_TAP_MIN_TIME; + } + + public static int getTouchSlop() { + return TOUCH_SLOP; + } + + public static int getDoubleTapSlop() { + return DOUBLE_TAP_SLOP; + } + + public static int getMinimumFlingVelocity() { + return MINIMUM_FLING_VELOCITY; + } + + public static int getMaximumFlingVelocity() { + return MAXIMUM_FLING_VELOCITY; + } +} +``` \ No newline at end of file diff --git a/view/ViewPager.md b/view/ViewPager.md index 0255410..07440fa 100644 --- a/view/ViewPager.md +++ b/view/ViewPager.md @@ -1,13 +1,13 @@ - -# PageSlider -* openharmony API: ohos.agp.components.PageSlider -* openharmony SDK版本:2.1.1.21 -* IDE版本:2.1.0.501 -* 实现方案: - -openharmony: - -``` java - bannerView = (PageSlider)findComponentById(ResourceTable.Id_page_slider); - bannerView.setProvider(new TabPagerProvider(this, titles)) + +# PageSlider +* openharmony API: ohos.agp.components.PageSlider +* openharmony SDK版本:2.1.1.21 +* IDE版本:2.1.0.501 +* 实现方案: + +openharmony: + +``` java + bannerView = (PageSlider)findComponentById(ResourceTable.Id_page_slider); + bannerView.setProvider(new TabPagerProvider(this, titles)) ``` \ No newline at end of file diff --git a/view/ViewTreeObserver.md b/view/ViewTreeObserver.md index fe142bf..4412258 100644 --- a/view/ViewTreeObserver.md +++ b/view/ViewTreeObserver.md @@ -1,28 +1,46 @@ -### **OnGlobalLayoutListener** ->+ openharmony API: ohos.agp.components.ComponentTreeObserver.WindowBoundListener ->+ openharmony SDK版本:2.1.1.21 ->+ IDE版本:2.1.0.501 ->+ 实现方案: -使用addTreeLayoutChangedListener调用,监听没有回调,故使用addWindowBoundListener来进行替换,需要注意,该替换只会在首次Window添加Components后调用,不会像原库一样,Layout变化后,每次都会调用,需要自己具体情况自行考虑,手动触发监听。手动调用如下: ComponentTreeObserver.WindowBoundListener.onWindowBound(); - -``` -componentView.getComponentTreeObserver().addWindowBoundListener( - new ComponentTreeObserver.WindowBoundListener() { - - @Override - public void onWindowBound() { - componentView.this.layout.onWindowBound(); - } - - @Override - public void onWindowUnbound() { - try { - componentView.getComponentTreeObserver().removeWindowBoundListener(this); - }catch (Exception e){ - e.printStackTrace(); - } - } - - }); - -``` \ No newline at end of file +### **OnGlobalLayoutListener** +>+ openharmony API: ohos.agp.components.ComponentTreeObserver.WindowBoundListener +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案: +使用addTreeLayoutChangedListener调用,监听没有回调,故使用addWindowBoundListener来进行替换,需要注意,该替换只会在首次Window添加Components后调用,不会像原库一样,Layout变化后,每次都会调用,需要自己具体情况自行考虑,手动触发监听。手动调用如下: ComponentTreeObserver.WindowBoundListener.onWindowBound(); + +``` +componentView.getComponentTreeObserver().addWindowBoundListener( + new ComponentTreeObserver.WindowBoundListener() { + + @Override + public void onWindowBound() { + componentView.this.layout.onWindowBound(); + } + + @Override + public void onWindowUnbound() { + try { + componentView.getComponentTreeObserver().removeWindowBoundListener(this); + }catch (Exception e){ + e.printStackTrace(); + } + } + + }); + +``` + +### view.ViewTreeObserver.OnGlobalLayoutListener.onGlobalLayout() + +>+ openharmony API: +> +> ohos.agp.components.ComponentTreeObserver.GlobalLayoutListener.onGlobalLayoutUpdated() +> +> ohos.agp.components.Component.LayoutRefreshedListener.onRefreshed(Component component) +> +>+ openharmony SDK版本:2.1.1.21 +> +>+ IDE版本:2.1.0.501 +> +>+ 使用场景:可用来监听布局事件 +> +>+ 实现方案: + +从接口名称上看,应该是GlobalLayoutListener更接近,但是,OHOS已将GlobalLayoutListener标为废弃,而推荐使用LayoutRefreshedListener \ No newline at end of file diff --git a/view/WindowManager.md b/view/WindowManager.md index a1a5d88..e8779f8 100644 --- a/view/WindowManager.md +++ b/view/WindowManager.md @@ -1,26 +1,35 @@ -### **addView** ->+ openharmony API: ohos.agp.window.dialog.PopupDialog.show ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:可以利用PopupDialog类,在特定场景中可以代替Android中WindowManager.addView()的效果。这里只是一种方案,并不是说明两者基于各自系统是同一类型的控件。下面是PopupDialog显示的代码片段,有更好的方法大家也可以分享。 - -```java -component = new Component(context); -component.setLayoutConfig(new ComponentContainer.LayoutConfig(ComponentContainer.LayoutConfig.MATCH_PARENT, ComponentContainer.LayoutConfig.MATCH_PARENT)); -component.addDrawTask(new Component.DrawTask() { - @Override - public void onDraw(Component component, Canvas canvas) { - - } - }); -popupDialog = new PopupDialog(context, component, - context.getResourceManager().getDeviceCapability().screenDensity / 160 * context.getResourceManager().getDeviceCapability().width, - context.getResourceManager().getDeviceCapability().screenDensity / 160 * context.getResourceManager().getDeviceCapability().height - ); -popupDialog.setCustomComponent(component); -popupDialog.setTransparent(true); -popupDialog.setBackColor(new Color(0x00000000)); -popupDialog.show(); -``` - ->+ 补充说明:当前SDK版本:2.1.0.17不生效,后续支持。 \ No newline at end of file +### **addView** +>+ openharmony API: ohos.agp.window.dialog.PopupDialog.show +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:可以利用PopupDialog类,在特定场景中可以代替Android中WindowManager.addView()的效果。这里只是一种方案,并不是说明两者基于各自系统是同一类型的控件。下面是PopupDialog显示的代码片段,有更好的方法大家也可以分享。 + +```java +component = new Component(context); +component.setLayoutConfig(new ComponentContainer.LayoutConfig(ComponentContainer.LayoutConfig.MATCH_PARENT, ComponentContainer.LayoutConfig.MATCH_PARENT)); +component.addDrawTask(new Component.DrawTask() { + @Override + public void onDraw(Component component, Canvas canvas) { + + } + }); +popupDialog = new PopupDialog(context, component, + context.getResourceManager().getDeviceCapability().screenDensity / 160 * context.getResourceManager().getDeviceCapability().width, + context.getResourceManager().getDeviceCapability().screenDensity / 160 * context.getResourceManager().getDeviceCapability().height + ); +popupDialog.setCustomComponent(component); +popupDialog.setTransparent(true); +popupDialog.setBackColor(new Color(0x00000000)); +popupDialog.show(); +``` + +>+ 补充说明:当前SDK版本:2.1.0.17不生效,后续支持。 + +### LayoutParams + +>+ openharmony API : ohos.agp.window.service.WindowManager. LayoutConfig +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案: + +直接替换使用 \ No newline at end of file diff --git a/view/animation/Animation.md b/view/animation/Animation.md index 9f0e3e4..bbfa01a 100644 --- a/view/animation/Animation.md +++ b/view/animation/Animation.md @@ -1,11 +1,11 @@ -### **Animation** ->+ openharmony class: ohos.agp.animation.AnimatorProperty ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 -实现方案:使用AnimatorProperty类对应 -原三方库: -view.startAnimation(animation) - -openharmony : -AnimatorProperty animatorProperty = new AnimatorProperty(component); +### **Animation** +>+ openharmony class: ohos.agp.animation.AnimatorProperty +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +实现方案:使用AnimatorProperty类对应 +原三方库: +view.startAnimation(animation) + +openharmony : +AnimatorProperty animatorProperty = new AnimatorProperty(component); animatorProperty.start(); \ No newline at end of file diff --git a/view/animation/AnimationSet.md b/view/animation/AnimationSet.md index 6c9533e..c96c6f6 100644 --- a/view/animation/AnimationSet.md +++ b/view/animation/AnimationSet.md @@ -1,30 +1,30 @@ -### **AnimationSet** ->+ openharmony API: ohos.agp.animation.AnimatorGroup ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:使用AnimatorGroup类对应 - -```java -原三方库: -Animation animation = new Animation(); -AnimationSet.add(Animation); -view.startAnimation(AnimationSet) - -openharmony : -Animation animation = new Animation(component); -AnimatorGroup animatorGroup = new AnimatorGroup(); -animatorGroup.build().addAnimators(animation); -animatorProperty.start(); -``` - - -### **addAnimation** ->+ openharmony API: ohos.agp.animation.AnimatorGroup.build().addAnimators ->+ 实现方案:使用AnimatorGroup类对应 - -```java -Animation animation = new Animation(component); -AnimatorGroup animatorGroup = new AnimatorGroup(); -animatorGroup.build().addAnimators(animation); -animatorProperty.start(); +### **AnimationSet** +>+ openharmony API: ohos.agp.animation.AnimatorGroup +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:使用AnimatorGroup类对应 + +```java +原三方库: +Animation animation = new Animation(); +AnimationSet.add(Animation); +view.startAnimation(AnimationSet) + +openharmony : +Animation animation = new Animation(component); +AnimatorGroup animatorGroup = new AnimatorGroup(); +animatorGroup.build().addAnimators(animation); +animatorProperty.start(); +``` + + +### **addAnimation** +>+ openharmony API: ohos.agp.animation.AnimatorGroup.build().addAnimators +>+ 实现方案:使用AnimatorGroup类对应 + +```java +Animation animation = new Animation(component); +AnimatorGroup animatorGroup = new AnimatorGroup(); +animatorGroup.build().addAnimators(animation); +animatorProperty.start(); ``` \ No newline at end of file diff --git a/view/animation/Interpolator.md b/view/animation/Interpolator.md index 35726ee..1827821 100644 --- a/view/animation/Interpolator.md +++ b/view/animation/Interpolator.md @@ -1,5 +1,5 @@ -### **Interpolator** ->+ openharmony class: ohos.agp.animation.Animator.CurveType ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 +### **Interpolator** +>+ openharmony class: ohos.agp.animation.Animator.CurveType +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 >+ 实现方案:原三方库的ValueAnimator.setInterpolator(Interpolator interpolator)用ohos.agp.animation.AnimatorValue.setCurveType(int curveType)代替,其中curveType的int值是ohos.agp.animation.Animator.CurveType类的枚举常量. \ No newline at end of file diff --git a/viewpager.widget.ViewPager/ViewPager.md b/viewpager.widget.ViewPager/ViewPager.md new file mode 100644 index 0000000..bfd014f --- /dev/null +++ b/viewpager.widget.ViewPager/ViewPager.md @@ -0,0 +1,264 @@ +### viewpager.widget.ViewPager.setPageTransformer(boolean reverseDrawingOrder, PageTransformer transformer) + +>+ openharmony API : 无 +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案: + +OHOS的PageSlider没有对应方法,目前对OHOS的PageSlidler进行封装,利用PageChangedListener实现相似功能 + + * ``` + import ohos.agp.components.AttrSet; +import ohos.agp.components.Component; + import ohos.agp.components.ComponentContainer; + import ohos.agp.components.DirectionalLayout; + import ohos.agp.components.PageSlider; + import ohos.agp.components.PageSliderProvider; + import ohos.agp.components.StackLayout; + import ohos.app.Context; + + import java.util.ArrayList; + import java.util.Comparator; + import java.util.List; + + /** + + * Subclass of {@link PageSlider}. Provides a PageTransformer interface, it can apply a property + + * transformation to the given page while sliding. And use {@link #setPageTransformer} method to set it. + */ + public class TransformPageSlider extends PageSlider { + /** + + * A PageTransformer is invoked whenever a visible/attached page is scrolled. + * This offers an opportunity for the application to apply a custom transformation + * to the page views using animation properties. + */ + public interface PageTransformer { + /** + * Apply a property transformation to the given page. + * + * @param page Apply the transformation to this page + * @param position Position of page relative to the current front-and-center + * position of the pager. 0 is front and center. 1 is one full + * page position to the right, and -1 is one page position to the left. + */ + void transformPage(Component page, float position); + } + + private PageSliderProviderWrapper pageSliderProviderWrapper = null; + private PageChangedListenerWrapper pageChangedListenerWrapper = new PageChangedListenerWrapper(); + private boolean reverse = false; + private PageTransformer pageTransformer; + + public TransformPageSlider(Context context) { + super(context); + init(); + } + + public TransformPageSlider(Context context, AttrSet attrSet) { + super(context, attrSet); + init(); + } + + public TransformPageSlider(Context context, AttrSet attrSet, String styleName) { + super(context, attrSet, styleName); + init(); + } + + private void init() { + super.addPageChangedListener(pageChangedListenerWrapper); + } + + /** + + * Sets a {@link PageTransformer} that will be called for each attached page whenever + * the scroll position is changed. This allows the application to apply custom property + * transformations to each page, overriding the default sliding behavior. + * + * @param reverse true if the supplied PageTransformer requires page views + * to be drawn from last to first instead of first to last. + * @param pageTransformer PageTransformer that will modify each page's animation properties + */ + public final void setPageTransformer(boolean reverse, PageTransformer pageTransformer) { + clearTransformEffects(); + this.reverse = reverse; + this.pageTransformer = pageTransformer; + } + + @Override + public final void setProvider(PageSliderProvider provider) { + if (pageSliderProviderWrapper == null) { + pageSliderProviderWrapper = new PageSliderProviderWrapper(provider); + } else { + pageSliderProviderWrapper.setPageSliderProvider(provider); + } + super.setProvider(pageSliderProviderWrapper); + } + + @Override + public final void addPageChangedListener(PageChangedListener listener) { + pageChangedListenerWrapper.addPageChangedListener(listener); + } + + @Override + public final void removePageChangedListener(PageChangedListener listener) { + pageChangedListenerWrapper.removePageChangedListener(listener); + } + + public final void clearPageChangedListeners() { + pageChangedListenerWrapper.clearPageChangedListeners(); + } + + private class PageChangedListenerWrapper implements PageChangedListener { + private List pageChangedListeners = new ArrayList<>(); + + public void addPageChangedListener(PageChangedListener pageChangedListener) { + if (!pageChangedListeners.contains(pageChangedListener)) { + pageChangedListeners.add(pageChangedListener); + } + } + + public void removePageChangedListener(PageChangedListener pageChangedListener) { + pageChangedListeners.remove(pageChangedListener); + } + + public void clearPageChangedListeners() { + pageChangedListeners.clear(); + } + + @Override + public void onPageSliding(int itemPos, + float itemPosOffset, + int itemPosOffsetPixels) { + float offset = itemPosOffsetPixels > 0 ? -itemPosOffset : itemPosOffset; + for (int i = pageChangedListeners.size() - 1; i >= 0; i--) { + pageChangedListeners.get(i).onPageSliding(itemPos, itemPosOffset,itemPosOffsetPixels); + } + transformPages(itemPos, offset); + } + + @Override + public void onPageSlideStateChanged(int state) { + if (state == 0) { + transformPages(getCurrentPage(), 0); + } + for (int i = pageChangedListeners.size() - 1; i >= 0; i--) { + pageChangedListeners.get(i).onPageSlideStateChanged(state); + } + } + + @Override + public void onPageChosen(int itemPos) { + for (int i = pageChangedListeners.size() - 1; i >= 0; i--) { + pageChangedListeners.get(i).onPageChosen(itemPos); + } + } + + } + + private class PageSliderProviderWrapper extends PageSliderProvider { + private PageSliderProvider userPageSliderProvider; + + public PageSliderProviderWrapper(PageSliderProvider userPageSliderProvider) { + this.userPageSliderProvider = userPageSliderProvider; + } + + public void setPageSliderProvider(PageSliderProvider userPageSliderProvider) { + this.userPageSliderProvider = userPageSliderProvider; + } + + @Override + public int getCount() { + return userPageSliderProvider == null ? 0 : userPageSliderProvider.getCount(); + } + + @Override + public Object createPageInContainer(ComponentContainer componentContainer, int i) { + if (userPageSliderProvider == null) { + return null; + } + Object newPage = userPageSliderProvider.createPageInContainer(componentContainer, i); + componentContainer.setTag(i); + return newPage; + } + + @Override + public void destroyPageFromContainer(ComponentContainer componentContainer, int i, Object o) { + if (userPageSliderProvider == null) { + return; + } + Component page = componentContainer.getComponentAt(0); + if (page !=null && pageTransformer != null) { + removeTransition(page); + } + userPageSliderProvider.destroyPageFromContainer(componentContainer, i, o); + componentContainer.setTag(null); + } + + @Override + public boolean isPageMatchToObject(Component component, Object o) { + return userPageSliderProvider == null ? false : userPageSliderProvider.isPageMatchToObject(component, o); + } + + } + + private void transformPages(int baseIndex, float baseOffset) { + if (pageTransformer == null) { + return; + } + Component directionalLayout = getComponentAt(0); + if (!(directionalLayout instanceof DirectionalLayout)) { + // null or other component, it means ohos changes implementation of PageSlider. + return; + } + List components = getPagesToTransformByOrder((DirectionalLayout) directionalLayout, reverse); + for (Component component : components) { + if (component instanceof StackLayout && component.getTag() instanceof Integer) { + pageTransformer.transformPage(((StackLayout) component).getComponentAt(0), + baseOffset + ((Integer) component.getTag()) - baseIndex); + } + } + } + + private void clearTransformEffects() { + long startTime = System.currentTimeMillis(); + Component directionalLayout = getComponentAt(0); + if (!(directionalLayout instanceof DirectionalLayout)) { + // null or other component, it means ohos changes implementation of PageSlider. + return; + } + List components = getPagesToTransformByOrder((DirectionalLayout) directionalLayout, reverse); + for (Component component : components) { + if (component instanceof StackLayout && component.getTag() instanceof Integer) { + removeTransition(((StackLayout) component).getComponentAt(0)); + } + } + } + + private List getPagesToTransformByOrder(ComponentContainer container, boolean reverse) { + List components = new ArrayList(); + for (int i = 0; i < container.getChildCount(); i++) { + Component component = container.getComponentAt(i); + if (component.getTag() != null) { + components.add(component); + } + } + if (reverse) { + components.sort(Comparator.comparing(c -> (Integer) (c.getTag()), Comparator.reverseOrder())); + } else { + components.sort(Comparator.comparing(c -> (Integer) (c.getTag()), Comparator.naturalOrder())); + } + return components; + } + + private void removeTransition(Component component) { + component.setAlpha(1); + component.setScale(1, 1); + component.setTranslation(0, 0); + component.setRotation(0); + } + } + ``` + + \ No newline at end of file diff --git a/webkit/WebView.md b/webkit/WebView.md new file mode 100644 index 0000000..b2680e5 --- /dev/null +++ b/webkit/WebView.md @@ -0,0 +1,9 @@ +### webkit.WebView + +>+ openharmony API : ohos.agp.components.webengine.WebView +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景:加载url +>+ 实现方案: + +直接替换使用 \ No newline at end of file diff --git a/widget/AbsListView.md b/widget/AbsListView.md new file mode 100644 index 0000000..ca3c5d3 --- /dev/null +++ b/widget/AbsListView.md @@ -0,0 +1,20 @@ +### widget.AbsListView.OnScrollListener + +>+ openharmony API : ohos.agp.components.Component. onContentScrolled () +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案: + +``` +@Override +public void onContentScrolled(Component component, int scrollX, int scrollY, int oldScrollX, int oldScrollY) { + + if (lastVisibleItemPosition < listContainer.getLastVisibleItemPosition()) { + mProvider.scrollAnimator(listContainer.getLastVisibleItemPosition()); + } + lastVisibleItemPosition = listContainer.getLastVisibleItemPosition(); + int itemPosByVisibleIndex = listContainer.getItemPosByVisibleIndex(0); + int visibleItemCount = listContainer.getVisibleIndexCount(); + mProvider.refreshVisibleItem(itemPosByVisibleIndex + visibleItemCount - 1); +} +``` \ No newline at end of file diff --git a/widget/AdapterView.md b/widget/AdapterView.md index 041d525..10f15f0 100644 --- a/widget/AdapterView.md +++ b/widget/AdapterView.md @@ -1,322 +1,322 @@ -+ openharmony API: 无 -+ openharmony SDK版本:2.1.0.17 -+ IDE版本:2.1.0.141 -+ 实现方案: - + 1.自己编码实现类似AdapterView,这里只给出实现AdapterView最基本的功能 -``` java -public abstract class ProviderComponent extends ComponentContainer - implements Component.LayoutRefreshedListener, Component.BindStateChangedListener, Component.DrawTask { - /** - * item最大显示数 - */ - public static final int DEFAULT_MAX_VISIBLE = 4; - - private static final String MAX_VISIBLE_NUM = "maxVisibleNum"; - - private int mMaxVisible; - - private final List mChildComponents = new ArrayList<>(); - - private BaseItemProvider mProvider; - - private boolean mIsRegistered; - - /** - * 构造方法 - * - * @param context 上下文 - */ - public ProviderComponent(Context context) { - this(context, null); - } - - /** - * 构造方法 - * - * @param context 上下文 - * @param attrSet 自定义属性 - */ - public ProviderComponent(Context context, AttrSet attrSet) { - this(context, attrSet, null); - } - - /** - * 构造方法 - * - * @param context 上下文 - * @param attrSet 自定义属性 - * @param styleName 风格样式 - */ - public ProviderComponent(Context context, AttrSet attrSet, String styleName) { - super(context, attrSet, styleName); - mMaxVisible = AttrUtils.getIntFromAttr(attrSet, MAX_VISIBLE_NUM, DEFAULT_MAX_VISIBLE); - setBindStateChangedListener(this); - setLayoutRefreshedListener(this); - addDrawTask(this); - } - - @Override - public void onComponentBoundToWindow(Component component) { - if (mProvider != null && !mIsRegistered) { - mIsRegistered = true; - mProvider.addDataSubscriber(subscriber); - } - } - - @Override - public void onComponentUnboundFromWindow(Component component) { - if (mProvider != null && mIsRegistered) { - mIsRegistered = false; - mProvider.removeDataSubscriber(subscriber); - } - } - - @Override - public Component getComponentAt(int index) { - if (index < 0 || index >= mChildComponents.size()) { - return null; - } - return mChildComponents.get(index); - } - - @Override - public void onRefreshed(Component component) { - for (int i = 0; i < getChildCount(); i++) { - Component childComponent = getComponentAt(i); - if (childComponent != null) { - childComponent.setContentPositionX((getWidth() - childComponent.getWidth()) / 2f); - childComponent.setContentPositionY((getHeight() - childComponent.getHeight()) / 2f); - } - } - } - - /** - * 获取当前被选中的item组件 - * - * @return 被选中的组件 - */ - public abstract Component getSelectedComponent(); - - /** - * 获取适配器 - * - * @return 适配器 - */ - public BaseItemProvider getItemProvider() { - return mProvider; - } - - /** - * 获取最大显示child component数 - * - * @return child component - */ - public int getMaxVisible() { - return mMaxVisible; - } - - /** - * 设置最大显示child component数 - * - * @param maxVisible 最大显示child component数 - */ - public void setMaxVisible(int maxVisible) { - this.mMaxVisible = maxVisible; - } - - /** - * 设置适配器 - * - * @param itemProvider 适配器 - */ - public void setItemProvider(BaseItemProvider itemProvider) { - mProvider = itemProvider; - if (mProvider != null && !mIsRegistered) { - mIsRegistered = true; - mProvider.addDataSubscriber(subscriber); - } - mChildComponents.clear(); - if (getChildCount() > 0) { - removeAllComponents(); - } - addAllItem(); - } - - private void addAllItem() { - if (mProvider == null) { - return; - } - for (int i = 0; i < mProvider.getCount(); i++) { - boolean isAddToParent = false; - Component childComponent = null; - if (i < getChildCount()) { - childComponent = getComponentAt(i); - } - if (childComponent == null) { - isAddToParent = true; - } - childComponent = mProvider.getComponent(i, childComponent, this); - if (isAddToParent) { - mChildComponents.add(childComponent); - if (getChildCount() < mMaxVisible) { - addComponent(childComponent, 0); - } - } - } - } - - private void insertItem(int position) { - Component addComponent = mProvider.getComponent(position, null, this); - mChildComponents.add(addComponent); - for (int i = 0; i < mChildComponents.size(); i++) { - mProvider.getComponent(i, mChildComponents.get(i), this); - } - } - - private void removeItem(int position) { - if (position >= 0 && position < mChildComponents.size()) { - Component removeComponent = mChildComponents.get(position); - mChildComponents.remove(removeComponent); - int childIndex = getChildIndex(removeComponent); - if (childIndex >= 0) { - removeComponentAt(childIndex); - } - int childCount = getChildCount(); - if (childCount < mMaxVisible && childCount < mChildComponents.size()) { - addComponent(mChildComponents.get(getChildCount()), 0); - } - } - } - - private DataSetSubscriber subscriber = - new DataSetSubscriber() { - @Override - public void onChanged() {} - - @Override - public void onItemInserted(int position) { - insertItem(position); - } - - @Override - public void onItemRemoved(int position) { - removeItem(position); - } - - @Override - public void onItemRangeChanged(int positionStart, int itemCount) {} - - @Override - public void onItemRangeInserted(int positionStart, int itemCount) {} - - @Override - public void onItemRangeRemoved(int positionStart, int itemCount) {} - }; -} -``` - - + 2.使用: - - 1、xml布局加入: -``` java - -``` - - 2、写ProviderComponent的适配器: -``` java -public class BaseAdapter extends BaseItemProvider { - private Context mContext; - - private List mDataList; - - /** - * constructor - * - * @param context context - */ - public BaseAdapter(Context context) { - mContext = context; - } - - /** - * set data in the list - * - * @param dataList data source - */ - public void setData(List dataList) { - this.mDataList = dataList; - super.notifyDataChanged(); - } - - @Override - public int getCount() { - return mDataList == null ? 0 : mDataList.size(); - } - - @Override - public String getItem(int position) { - return mDataList.get(position); - } - - @Override - public long getItemId(int position) { - return position; - } - - @Override - public Component getComponent(int position, Component convertView, ComponentContainer container) { - MyComponentHolder holder; - if (convertView == null) { - convertView = LayoutScatter.getInstance(mContext).parse(ResourceTable.Layout_item, container, false); - holder = new MyComponentHolder(convertView); - convertView.setTag(holder); - } else { - holder = (MyComponentHolder) convertView.getTag(); - } - Text text = (Text) holder.getItemView().findComponentById(ResourceTable.Id_helloText); - text.setText(mDataList.get(position)); - return convertView; - } - - /** - * item component holder - */ - public static class MyComponentHolder { - private final Component itemView; - - public MyComponentHolder(Component itemView) { - if (itemView == null) { - throw new IllegalArgumentException("itemView may not be null"); - } else { - this.itemView = itemView; - } - } - - public Component getItemView() { - return itemView; - } - } -} -``` - - 3、与适配器绑定: -``` java - BaseAdapter provider = new BaseAdapter(this); - provider.setData(al); - ProviderComponent container = (ProviderComponent) findComponentById(ResourceTable.Id_frame); - container.setItemProvider(provider); -``` - - 4、刷新数据接口 -``` java - 插入数据: - al.add("XML ".concat(String.valueOf(mCount))); - provider.notifyDataSetItemInserted(al.size() - 1); - - 删除数据: - al.remove(0); - provider.notifyDataSetItemRemoved(0); ++ openharmony API: 无 ++ openharmony SDK版本:2.1.0.17 ++ IDE版本:2.1.0.141 ++ 实现方案: + + 1.自己编码实现类似AdapterView,这里只给出实现AdapterView最基本的功能 +``` java +public abstract class ProviderComponent extends ComponentContainer + implements Component.LayoutRefreshedListener, Component.BindStateChangedListener, Component.DrawTask { + /** + * item最大显示数 + */ + public static final int DEFAULT_MAX_VISIBLE = 4; + + private static final String MAX_VISIBLE_NUM = "maxVisibleNum"; + + private int mMaxVisible; + + private final List mChildComponents = new ArrayList<>(); + + private BaseItemProvider mProvider; + + private boolean mIsRegistered; + + /** + * 构造方法 + * + * @param context 上下文 + */ + public ProviderComponent(Context context) { + this(context, null); + } + + /** + * 构造方法 + * + * @param context 上下文 + * @param attrSet 自定义属性 + */ + public ProviderComponent(Context context, AttrSet attrSet) { + this(context, attrSet, null); + } + + /** + * 构造方法 + * + * @param context 上下文 + * @param attrSet 自定义属性 + * @param styleName 风格样式 + */ + public ProviderComponent(Context context, AttrSet attrSet, String styleName) { + super(context, attrSet, styleName); + mMaxVisible = AttrUtils.getIntFromAttr(attrSet, MAX_VISIBLE_NUM, DEFAULT_MAX_VISIBLE); + setBindStateChangedListener(this); + setLayoutRefreshedListener(this); + addDrawTask(this); + } + + @Override + public void onComponentBoundToWindow(Component component) { + if (mProvider != null && !mIsRegistered) { + mIsRegistered = true; + mProvider.addDataSubscriber(subscriber); + } + } + + @Override + public void onComponentUnboundFromWindow(Component component) { + if (mProvider != null && mIsRegistered) { + mIsRegistered = false; + mProvider.removeDataSubscriber(subscriber); + } + } + + @Override + public Component getComponentAt(int index) { + if (index < 0 || index >= mChildComponents.size()) { + return null; + } + return mChildComponents.get(index); + } + + @Override + public void onRefreshed(Component component) { + for (int i = 0; i < getChildCount(); i++) { + Component childComponent = getComponentAt(i); + if (childComponent != null) { + childComponent.setContentPositionX((getWidth() - childComponent.getWidth()) / 2f); + childComponent.setContentPositionY((getHeight() - childComponent.getHeight()) / 2f); + } + } + } + + /** + * 获取当前被选中的item组件 + * + * @return 被选中的组件 + */ + public abstract Component getSelectedComponent(); + + /** + * 获取适配器 + * + * @return 适配器 + */ + public BaseItemProvider getItemProvider() { + return mProvider; + } + + /** + * 获取最大显示child component数 + * + * @return child component + */ + public int getMaxVisible() { + return mMaxVisible; + } + + /** + * 设置最大显示child component数 + * + * @param maxVisible 最大显示child component数 + */ + public void setMaxVisible(int maxVisible) { + this.mMaxVisible = maxVisible; + } + + /** + * 设置适配器 + * + * @param itemProvider 适配器 + */ + public void setItemProvider(BaseItemProvider itemProvider) { + mProvider = itemProvider; + if (mProvider != null && !mIsRegistered) { + mIsRegistered = true; + mProvider.addDataSubscriber(subscriber); + } + mChildComponents.clear(); + if (getChildCount() > 0) { + removeAllComponents(); + } + addAllItem(); + } + + private void addAllItem() { + if (mProvider == null) { + return; + } + for (int i = 0; i < mProvider.getCount(); i++) { + boolean isAddToParent = false; + Component childComponent = null; + if (i < getChildCount()) { + childComponent = getComponentAt(i); + } + if (childComponent == null) { + isAddToParent = true; + } + childComponent = mProvider.getComponent(i, childComponent, this); + if (isAddToParent) { + mChildComponents.add(childComponent); + if (getChildCount() < mMaxVisible) { + addComponent(childComponent, 0); + } + } + } + } + + private void insertItem(int position) { + Component addComponent = mProvider.getComponent(position, null, this); + mChildComponents.add(addComponent); + for (int i = 0; i < mChildComponents.size(); i++) { + mProvider.getComponent(i, mChildComponents.get(i), this); + } + } + + private void removeItem(int position) { + if (position >= 0 && position < mChildComponents.size()) { + Component removeComponent = mChildComponents.get(position); + mChildComponents.remove(removeComponent); + int childIndex = getChildIndex(removeComponent); + if (childIndex >= 0) { + removeComponentAt(childIndex); + } + int childCount = getChildCount(); + if (childCount < mMaxVisible && childCount < mChildComponents.size()) { + addComponent(mChildComponents.get(getChildCount()), 0); + } + } + } + + private DataSetSubscriber subscriber = + new DataSetSubscriber() { + @Override + public void onChanged() {} + + @Override + public void onItemInserted(int position) { + insertItem(position); + } + + @Override + public void onItemRemoved(int position) { + removeItem(position); + } + + @Override + public void onItemRangeChanged(int positionStart, int itemCount) {} + + @Override + public void onItemRangeInserted(int positionStart, int itemCount) {} + + @Override + public void onItemRangeRemoved(int positionStart, int itemCount) {} + }; +} +``` + + + 2.使用: + + 1、xml布局加入: +``` java + +``` + + 2、写ProviderComponent的适配器: +``` java +public class BaseAdapter extends BaseItemProvider { + private Context mContext; + + private List mDataList; + + /** + * constructor + * + * @param context context + */ + public BaseAdapter(Context context) { + mContext = context; + } + + /** + * set data in the list + * + * @param dataList data source + */ + public void setData(List dataList) { + this.mDataList = dataList; + super.notifyDataChanged(); + } + + @Override + public int getCount() { + return mDataList == null ? 0 : mDataList.size(); + } + + @Override + public String getItem(int position) { + return mDataList.get(position); + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public Component getComponent(int position, Component convertView, ComponentContainer container) { + MyComponentHolder holder; + if (convertView == null) { + convertView = LayoutScatter.getInstance(mContext).parse(ResourceTable.Layout_item, container, false); + holder = new MyComponentHolder(convertView); + convertView.setTag(holder); + } else { + holder = (MyComponentHolder) convertView.getTag(); + } + Text text = (Text) holder.getItemView().findComponentById(ResourceTable.Id_helloText); + text.setText(mDataList.get(position)); + return convertView; + } + + /** + * item component holder + */ + public static class MyComponentHolder { + private final Component itemView; + + public MyComponentHolder(Component itemView) { + if (itemView == null) { + throw new IllegalArgumentException("itemView may not be null"); + } else { + this.itemView = itemView; + } + } + + public Component getItemView() { + return itemView; + } + } +} +``` + + 3、与适配器绑定: +``` java + BaseAdapter provider = new BaseAdapter(this); + provider.setData(al); + ProviderComponent container = (ProviderComponent) findComponentById(ResourceTable.Id_frame); + container.setItemProvider(provider); +``` + + 4、刷新数据接口 +``` java + 插入数据: + al.add("XML ".concat(String.valueOf(mCount))); + provider.notifyDataSetItemInserted(al.size() - 1); + + 删除数据: + al.remove(0); + provider.notifyDataSetItemRemoved(0); ``` \ No newline at end of file diff --git a/widget/ArrayAdapter.md b/widget/ArrayAdapter.md new file mode 100644 index 0000000..6484b7e --- /dev/null +++ b/widget/ArrayAdapter.md @@ -0,0 +1,237 @@ +### widget.ArrayAdapter + +>+ openharmony API : ohos.agp.components.Component.setBackground(Element element) +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 应用场景:数组适配器 +>+ 实现方案: + +``` +private RecycleItemProvider prepareAdapter(final int itemLayoutId) { + switch (getMode()) { + case ConstantUtils.CHOICE_MODE_NONE: + itemProvider = new NormalBaseListDialogProvider(mContext, itemLayoutId, getItems()); + break; + case ConstantUtils.CHOICE_MODE_SINGLE: + itemProvider = new SingleBaseListDialogProvider(mContext, itemLayoutId, getItems(), getSelectedItem()); + break; + case ConstantUtils.CHOICE_MODE_MULTIPLE: + itemProvider = new MultipleBaseListDialogProvider(mContext, itemLayoutId, getItems(), getCheckedItems()); + break; + } + return itemProvider; +} +``` + +实现4个类: + +第一个:BaseListDialogProvider + +``` +import ohos.agp.components.Component; +import ohos.agp.components.ComponentContainer; +import ohos.agp.components.LayoutScatter; +import ohos.agp.components.RecycleItemProvider; +import ohos.app.Context; + +public abstract class BaseListDialogProvider extends RecycleItemProvider { + + public Context mContext = null; + public LayoutScatter mLayoutScatter = null; + public int mItemLayoutId; + public CharSequence[] mCharSequences = null; + + public BaseListDialogProvider(Context context, int itemLayoutId, CharSequence[] charSequences) { + mContext = context; + mLayoutScatter = LayoutScatter.getInstance(context); + mItemLayoutId = itemLayoutId; + mCharSequences = charSequences; + } + + @Override + public int getCount() { + return mCharSequences.length; + } + + @Override + public Object getItem(int i) { + return mCharSequences[i]; + } + + @Override + public long getItemId(int i) { + return i; + } + + @Override + public Component getComponent(int i, Component component, ComponentContainer componentContainer) { + return initView(i, component, componentContainer); + } + + protected abstract Component initView(int i, Component component, ComponentContainer componentContainer); +} +``` + +第二个:MultipleBaseListDialogProvider + +``` +import ohos.agp.components.Checkbox; +import ohos.agp.components.Component; +import ohos.agp.components.ComponentContainer; +import ohos.app.Context; + +import com.avast.ohos.dialogs.ResourceTable; + +import java.util.ArrayList; +import java.util.Arrays; + +public class MultipleBaseListDialogProvider extends BaseListDialogProvider { + private ArrayList mCheckedItems = new ArrayList<>(); + + public MultipleBaseListDialogProvider(Context context, int itemLayoutId, CharSequence[] charSequences, int[] checkedItems) { + super(context, itemLayoutId, charSequences); + for (int i = 0; i < checkedItems.length; i++) { + mCheckedItems.add(checkedItems[i]); + } + } + + @Override + protected Component initView(int i, Component component, ComponentContainer componentContainer) { + ViewHolder viewHolder; + if (component == null) { + viewHolder = new ViewHolder(); + component = mLayoutScatter.parse(mItemLayoutId, null, false); + viewHolder.checkbox = (Checkbox) component.findComponentById(ResourceTable.Id_sdl_text); + component.setTag(viewHolder); + } else { + viewHolder = (ViewHolder) component.getTag(); + } + viewHolder.checkbox.setText((String) getItem(i)); + if (mCheckedItems.contains(i)) { + viewHolder.checkbox.setChecked(true); + } else { + viewHolder.checkbox.setChecked(false); + } + return component; + } + + private static class ViewHolder { + private Checkbox checkbox; + } + + public void setCheckedItem(int position) { + if (mCheckedItems.contains(position)) { + for (int i = 0; i < mCheckedItems.size(); i++) { + if (mCheckedItems.get(i) == position) { + mCheckedItems.remove(i); + } + } + } else { + mCheckedItems.add(position); + } + notifyDataChanged(); + } + + public int[] getCheckedItem() { + int[] array = new int[mCheckedItems.size()]; + for (int i = 0; i < mCheckedItems.size(); i++) { + array[i] = mCheckedItems.get(i); + } + Arrays.sort(array); + return array; + } +} +``` + +第三个:NormalBaseListDialogProvider + +``` +import ohos.agp.components.Component; +import ohos.agp.components.ComponentContainer; +import ohos.agp.components.Text; +import ohos.app.Context; + +import com.avast.ohos.dialogs.ResourceTable; + +public class NormalBaseListDialogProvider extends BaseListDialogProvider { + + public NormalBaseListDialogProvider(Context context, int itemLayoutId, CharSequence[] charSequences) { + super(context, itemLayoutId, charSequences); + } + + @Override + protected Component initView(int i, Component component, ComponentContainer componentContainer) { + ViewHolder viewHolder; + if (component == null) { + viewHolder = new ViewHolder(); + component = mLayoutScatter.parse(mItemLayoutId, componentContainer, false); + viewHolder.text = (Text) component.findComponentById(ResourceTable.Id_sdl_text); + component.setTag(viewHolder); + } else { + viewHolder = (ViewHolder) component.getTag(); + } + viewHolder.text.setText((String) getItem(i)); + return component; + } + + private static class ViewHolder { + private Text text; + } + + +} +``` + +第四个:SingleBaseListDialogProvider + +``` +import ohos.agp.components.Component; +import ohos.agp.components.ComponentContainer; +import ohos.agp.components.RadioButton; +import ohos.app.Context; + +import com.avast.ohos.dialogs.ResourceTable; + +public class SingleBaseListDialogProvider extends BaseListDialogProvider { + private int mSelectedItem; + + public SingleBaseListDialogProvider(Context context, int itemLayoutId, CharSequence[] charSequences, int selectedItem) { + super(context, itemLayoutId, charSequences); + this.mSelectedItem = selectedItem; + } + + @Override + protected Component initView(int i, Component component, ComponentContainer componentContainer) { + ViewHolder viewHolder; + if (component == null) { + viewHolder = new ViewHolder(); + component = mLayoutScatter.parse(mItemLayoutId, null, false); + viewHolder.radioButton = (RadioButton) component.findComponentById(ResourceTable.Id_sdl_text); + component.setTag(viewHolder); + } else { + viewHolder = (ViewHolder) component.getTag(); + } + viewHolder.radioButton.setText((String) getItem(i)); + if (i == mSelectedItem) { + viewHolder.radioButton.setChecked(true); + } else { + viewHolder.radioButton.setChecked(false); + } + return component; + } + + private static class ViewHolder { + private RadioButton radioButton; + } + + public void setSelectedItem(int position) { + this.mSelectedItem = position; + notifyDataChanged(); + } + + public int getSelectedItem() { + return mSelectedItem; + } + +} +``` \ No newline at end of file diff --git a/widget/FrameLayout.md b/widget/FrameLayout.md index 6717f08..7ae64de 100644 --- a/widget/FrameLayout.md +++ b/widget/FrameLayout.md @@ -1,13 +1,13 @@ -### **LayoutParams** ->+ openharmony API:ohos.agp.components.StackLayout.LayoutConfig ->+ openharmony SDK版本:2.1.1.21 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java - StackLayout.LayoutConfig layoutParams = new StackLayout.LayoutConfig(ComponentContainer.LayoutConfig.MATCH_PARENT, ComponentContainer.LayoutConfig.MATCH_PARENT); - layoutParams.setMarginLeft(borderMargin); - layoutParams.setMarginTop(topMargin); - layoutParams.setMarginRight(borderMargin); - layoutParams.setMarginBottom(bottomMargin); - view.setLayoutConfig(layoutParams); +### **LayoutParams** +>+ openharmony API:ohos.agp.components.StackLayout.LayoutConfig +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java + StackLayout.LayoutConfig layoutParams = new StackLayout.LayoutConfig(ComponentContainer.LayoutConfig.MATCH_PARENT, ComponentContainer.LayoutConfig.MATCH_PARENT); + layoutParams.setMarginLeft(borderMargin); + layoutParams.setMarginTop(topMargin); + layoutParams.setMarginRight(borderMargin); + layoutParams.setMarginBottom(bottomMargin); + view.setLayoutConfig(layoutParams); ``` \ No newline at end of file diff --git a/widget/GridView.md b/widget/GridView.md index 2f75d5f..fed7dd1 100644 --- a/widget/GridView.md +++ b/widget/GridView.md @@ -1,163 +1,163 @@ -+ openharmony API: 无 -+ openharmony SDK版本:2.1.0.17 -+ IDE版本:2.1.0.141 -+ 实现方案: - + 1.先复制下面这个自定义Provider到你的目录下: -``` java -public abstract class EasyGridProvider extends RecycleItemProvider { - - private Context context; - private List data; - private int mLayoutId; - private int numColumns = 1; - private OnItemClickListener onItemClickListener; - - /** - * @param context 上下文 - * @param data 数据源 - * @param mLayoutId 条目的资源文件id - * @return - */ - public EasyGridProvider(Context context, int mLayoutId, List data) { - this.context = context; - this.data = data; - this.mLayoutId = mLayoutId; - } - - public void setNumColumns(int numColumns) { - this.numColumns = numColumns; - } - - public void setData(List data) { - this.data = data; - notifyDataChanged(); - } - - public List getData() { - return data; - } - - @Override - public int getCount() { - if (data != null) { - return data.size() % numColumns == 0 ? data.size() / numColumns : data.size() / numColumns + 1; - } else { - return 0; - } - } - - @Override - public T getItem(int position) { - if (data != null) { - return data.get(position); - } else { - return null; - } - } - - @Override - public long getItemId(int position) { - return position; - } - - @Override - public Component getComponent(int position, Component convertComponent, ComponentContainer parent) { - ViewHolder viewHolder; - convertComponent = new DirectionalLayout(context); - ((DirectionalLayout) convertComponent).setOrientation(Component.HORIZONTAL); - ComponentContainer.LayoutConfig layoutConfig = convertComponent.getLayoutConfig(); - layoutConfig.width = DependentLayout.LayoutConfig.MATCH_PARENT; - layoutConfig.height = DependentLayout.LayoutConfig.MATCH_CONTENT; - convertComponent.setLayoutConfig(layoutConfig); - for (int i = 0; i < numColumns; i++) { - if (position * numColumns + i < data.size()) { - DirectionalLayout dlItemParent = new DirectionalLayout(context); - dlItemParent.setLayoutConfig(new DirectionalLayout.LayoutConfig(0, DirectionalLayout.LayoutConfig.MATCH_CONTENT, LayoutAlignment.TOP, 1)); - Component childConvertComponent = LayoutScatter.getInstance(context).parse(mLayoutId, null, false); - int finalI = i; - childConvertComponent.setClickedListener(new Component.ClickedListener() { - @Override - public void onClick(Component component) { - if (onItemClickListener != null) { - onItemClickListener.onItemClick(component, position * numColumns + finalI); - } - } - }); - dlItemParent.addComponent(childConvertComponent); - ((ComponentContainer) convertComponent).addComponent(dlItemParent); - viewHolder = new ViewHolder(childConvertComponent); - bind(viewHolder, getItem(position * numColumns + i), position * numColumns + i); - } else { - //用Component占位会导致高度为MATCH_PARENT,所以此处用DirectionalLayout占位 - DirectionalLayout childConvertComponent = new DirectionalLayout(context); - childConvertComponent.setLayoutConfig(new DirectionalLayout.LayoutConfig(0, DirectionalLayout.LayoutConfig.MATCH_CONTENT, LayoutAlignment.TOP, 1)); - ((ComponentContainer) convertComponent).addComponent(childConvertComponent); - } - } - return convertComponent; - } - - public void setOnItemClickListener(OnItemClickListener onItemClickListener) { - this.onItemClickListener = onItemClickListener; - } - - protected abstract void bind(ViewHolder holder, T s, int position); - - protected static class ViewHolder { - HashMap mViews = new HashMap<>(); - public Component itemView; - - ViewHolder(Component component) { - this.itemView = component; - } - - public ViewHolder setText(int viewId, String text) { - ((Text) getView(viewId)).setText(text); - return this; - } - - public E getView(int viewId) { - E view = (E) mViews.get(viewId); - if (view == null) { - view = (E) itemView.findComponentById(viewId); - mViews.put(viewId, view); - } - return view; - } - - } - - public static abstract class OnItemClickListener { - public abstract void onItemClick(Component component, int position); - } -} -``` - + 2.用法如下所示: -``` java -//找到ListContainer控件 -ListContainer listContainer = (ListContainer) findComponentById(ResourceTable.Id_list_container); -//创建适配器 -EasyGridProvider easyGridProvider = new EasyGridProvider(getContext(), ResourceTable.Layout_item_list, data1) { - @Override - protected void bind(ViewHolder holder, String s, int position) { - //在这里做你想给每一个条目做的逻辑 - //设置文本的两种方式,目前只有Text支持第一种方式 - holder.setText(ResourceTable.Id_text, s); - holder.getView(ResourceTable.Id_text).setText(s); - } -}; -//设置列数 -easyGridProvider.setNumColumns(3); -//设置条目点击事件 -easyGridProvider.setOnItemClickListener(new EasyGridProvider.OnItemClickListener() { - @Override - public void onItemClick(Component component, int position) { - - } -}); -//把适配器设置给ListContainer控件 -listContainer.setItemProvider(easyGridProvider); -//变更数据 -easyGridProvider.setData(data2); -``` ++ openharmony API: 无 ++ openharmony SDK版本:2.1.0.17 ++ IDE版本:2.1.0.141 ++ 实现方案: + + 1.先复制下面这个自定义Provider到你的目录下: +``` java +public abstract class EasyGridProvider extends RecycleItemProvider { + + private Context context; + private List data; + private int mLayoutId; + private int numColumns = 1; + private OnItemClickListener onItemClickListener; + + /** + * @param context 上下文 + * @param data 数据源 + * @param mLayoutId 条目的资源文件id + * @return + */ + public EasyGridProvider(Context context, int mLayoutId, List data) { + this.context = context; + this.data = data; + this.mLayoutId = mLayoutId; + } + + public void setNumColumns(int numColumns) { + this.numColumns = numColumns; + } + + public void setData(List data) { + this.data = data; + notifyDataChanged(); + } + + public List getData() { + return data; + } + + @Override + public int getCount() { + if (data != null) { + return data.size() % numColumns == 0 ? data.size() / numColumns : data.size() / numColumns + 1; + } else { + return 0; + } + } + + @Override + public T getItem(int position) { + if (data != null) { + return data.get(position); + } else { + return null; + } + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public Component getComponent(int position, Component convertComponent, ComponentContainer parent) { + ViewHolder viewHolder; + convertComponent = new DirectionalLayout(context); + ((DirectionalLayout) convertComponent).setOrientation(Component.HORIZONTAL); + ComponentContainer.LayoutConfig layoutConfig = convertComponent.getLayoutConfig(); + layoutConfig.width = DependentLayout.LayoutConfig.MATCH_PARENT; + layoutConfig.height = DependentLayout.LayoutConfig.MATCH_CONTENT; + convertComponent.setLayoutConfig(layoutConfig); + for (int i = 0; i < numColumns; i++) { + if (position * numColumns + i < data.size()) { + DirectionalLayout dlItemParent = new DirectionalLayout(context); + dlItemParent.setLayoutConfig(new DirectionalLayout.LayoutConfig(0, DirectionalLayout.LayoutConfig.MATCH_CONTENT, LayoutAlignment.TOP, 1)); + Component childConvertComponent = LayoutScatter.getInstance(context).parse(mLayoutId, null, false); + int finalI = i; + childConvertComponent.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + if (onItemClickListener != null) { + onItemClickListener.onItemClick(component, position * numColumns + finalI); + } + } + }); + dlItemParent.addComponent(childConvertComponent); + ((ComponentContainer) convertComponent).addComponent(dlItemParent); + viewHolder = new ViewHolder(childConvertComponent); + bind(viewHolder, getItem(position * numColumns + i), position * numColumns + i); + } else { + //用Component占位会导致高度为MATCH_PARENT,所以此处用DirectionalLayout占位 + DirectionalLayout childConvertComponent = new DirectionalLayout(context); + childConvertComponent.setLayoutConfig(new DirectionalLayout.LayoutConfig(0, DirectionalLayout.LayoutConfig.MATCH_CONTENT, LayoutAlignment.TOP, 1)); + ((ComponentContainer) convertComponent).addComponent(childConvertComponent); + } + } + return convertComponent; + } + + public void setOnItemClickListener(OnItemClickListener onItemClickListener) { + this.onItemClickListener = onItemClickListener; + } + + protected abstract void bind(ViewHolder holder, T s, int position); + + protected static class ViewHolder { + HashMap mViews = new HashMap<>(); + public Component itemView; + + ViewHolder(Component component) { + this.itemView = component; + } + + public ViewHolder setText(int viewId, String text) { + ((Text) getView(viewId)).setText(text); + return this; + } + + public E getView(int viewId) { + E view = (E) mViews.get(viewId); + if (view == null) { + view = (E) itemView.findComponentById(viewId); + mViews.put(viewId, view); + } + return view; + } + + } + + public static abstract class OnItemClickListener { + public abstract void onItemClick(Component component, int position); + } +} +``` + + 2.用法如下所示: +``` java +//找到ListContainer控件 +ListContainer listContainer = (ListContainer) findComponentById(ResourceTable.Id_list_container); +//创建适配器 +EasyGridProvider easyGridProvider = new EasyGridProvider(getContext(), ResourceTable.Layout_item_list, data1) { + @Override + protected void bind(ViewHolder holder, String s, int position) { + //在这里做你想给每一个条目做的逻辑 + //设置文本的两种方式,目前只有Text支持第一种方式 + holder.setText(ResourceTable.Id_text, s); + holder.getView(ResourceTable.Id_text).setText(s); + } +}; +//设置列数 +easyGridProvider.setNumColumns(3); +//设置条目点击事件 +easyGridProvider.setOnItemClickListener(new EasyGridProvider.OnItemClickListener() { + @Override + public void onItemClick(Component component, int position) { + + } +}); +//把适配器设置给ListContainer控件 +listContainer.setItemProvider(easyGridProvider); +//变更数据 +easyGridProvider.setData(data2); +``` + **注意:使用此方案后,ListContainer的条目点击事件将失效,替换成EasyGridProvider的条目点击事件即可** \ No newline at end of file diff --git a/widget/ImageView.md b/widget/ImageView.md index ac6cb10..8d92b9e 100644 --- a/widget/ImageView.md +++ b/widget/ImageView.md @@ -1,17 +1,17 @@ -### **setColorFilter** ->+ openharmony API:暂无 ->+ openharmony SDK版本:2.1.1.21 ->+ IDE版本:2.1.0.501 ->+ 实现方案:自行实现,使用方法如下: -```java -public static void setImageTint(Element element, int intColor, BlendMode mode, Image image) { - int[] colors = new int[]{intColor, intColor}; - int[][] states = new int[2][]; - states[0] = new int[]{0}; - states[1] = new int[]{0}; - element.setStateColorList(states, colors); - element.setStateColorMode(mode); - image.setImageElement(element); - } - +### **setColorFilter** +>+ openharmony API:暂无 +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.1.0.501 +>+ 实现方案:自行实现,使用方法如下: +```java +public static void setImageTint(Element element, int intColor, BlendMode mode, Image image) { + int[] colors = new int[]{intColor, intColor}; + int[][] states = new int[2][]; + states[0] = new int[]{0}; + states[1] = new int[]{0}; + element.setStateColorList(states, colors); + element.setStateColorMode(mode); + image.setImageElement(element); + } + ``` \ No newline at end of file diff --git a/widget/PopupWindow.md b/widget/PopupWindow.md index ad10bdf..732a8e4 100644 --- a/widget/PopupWindow.md +++ b/widget/PopupWindow.md @@ -1,19 +1,19 @@ - -# PopupDialog -* openharmony API: ohos.agp.window.dialog.PopupDialog; -* openharmony SDK版本:2.1.1.21 -* IDE版本:2.1.0.501 -* 实现方案: - -openharmony: - -``` java - PopupDialog popupDialog = new PopupDialog(context,null); - popupDialog.setCustomComponent(listView); - popupDialog.setDialogListener(new BaseDialog.DialogListener() { - @Override - public boolean isTouchOutside() { - return true; - } - }); + +# PopupDialog +* openharmony API: ohos.agp.window.dialog.PopupDialog; +* openharmony SDK版本:2.1.1.21 +* IDE版本:2.1.0.501 +* 实现方案: + +openharmony: + +``` java + PopupDialog popupDialog = new PopupDialog(context,null); + popupDialog.setCustomComponent(listView); + popupDialog.setDialogListener(new BaseDialog.DialogListener() { + @Override + public boolean isTouchOutside() { + return true; + } + }); ``` \ No newline at end of file -- Gitee