diff --git a/.gitignore b/.gitignore index c2892a188e06ba15c0e0ef3ee3d8eb81f2d42dd9..9580e83deb86ccb377424dfa58c6a7cd13bdb3b3 100644 --- a/.gitignore +++ b/.gitignore @@ -2,12 +2,6 @@ .gradle .idea /local.properties -/.idea/caches -/.idea/libraries -/.idea/modules.xml -/.idea/workspace.xml -/.idea/navEditor.xml -/.idea/assetWizardSettings.xml .DS_Store /build /captures diff --git a/CHANGELOG.md b/CHANGELOG.md index a42dfb3935392189cacbc58c639fe9a7b3db9d39..6f89b180abcdec5ff2b7180a6c92705314e8b1b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ohos 第一个版本 - * 实现了原库的全部 api - * 因为使用了jsUI开发,没有library文件 + * 实现了原库的大部分 api + * 因为api限制无法设置背景颜色,点击关键字背景改变功能没有实现 diff --git a/README.OPENSOURCE b/README.OPENSOURCE index 477d8dc36454183c7496fac47d6838e420348f10..d793a3fa30c5df678eca0789cd45ca9ca2ee214d 100644 --- a/README.OPENSOURCE +++ b/README.OPENSOURCE @@ -11,7 +11,7 @@ "Upstream URL":"https://github.com/wangshaolei/AutoSpannableTextView", - "Description":"支持一些关键词可以用下划线文本视图单击" + "Description":"文字开头设置图片;关键字设置字体颜色,下划线,点击事件" } ] \ No newline at end of file diff --git a/README.md b/README.md index f0f834711fcc1c96248907f87e74e3811b68d2b0..9aae15f6d856a7036e66332cfcb5167dfb9baec0 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ - + # AutoSpannableTextView ## 项目介绍 * 项目名称: AutoSpannableTextView * 所属系列:openharmony的第三方组件适配移植 -* 功能:支持一些关键词可以用下划线文本视图单击 +* 功能:文字开头设置图片;关键字设置字体颜色,下划线,点击事件 * 项目移植状态:主功能完成 -* 调用差异:新库使用js UI框架开发实现,无library,调用请参考demo +* 调用差异:无 * 开发版本:sdk6,DevEco Studio 2.2 Beta1 * 基线版本:Release v1.0.1 @@ -15,32 +15,82 @@ ![cmd-markdown-logo](gif/1.gif) ## 安装教程 -在sdk6,DevEco Studio 2.2 Beta1下项目可直接运行。 - 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, - 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下 +在sdk6,DevEco Studio 2.2 Beta1下项目可直接运行。如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下 + +## 使用说明 + +java UI方式: + +1、在布局xml文件中声明 + +```xml + + + +``` + +2、在ability中调用 -#### 使用说明 -1. 在页面中引入组件 -`````` +```java + autoLinkStyleTextView.setOnClickCallBack(position -> { + if(position==0){ + ToastUtil.getInstance().showToast(this,"购买须知"); + }else{ + ToastUtil.getInstance().showToast(this,"用户条款"); + } + }); ``` - +
+ +
``` -2. 参数使用说明: - -**buy_info:** 购买须知文本 -**user_clause:** 用户条款文本 +2、参数说明 -**activity_title:** 活动介绍文本,渲染的方式与activity_type有关 +| 参数 | 说明 | +| -------------- | ------------------------------------------------- | +| buy_info | 购买须知文本 | +| user_clause | 用户条款文本 | +| activity_type | 样式类型:开头图片和文本样式:img;文本样式:text | +| activity_title | 图片路径 | -**activity_type:** 活动介绍类型,可取值img,text; -activity_type值为text时,activity_title传入的内容必须是字符串, -activity_type值为img时,activity_title传入的内容必须为图片路径 -#### 测试信息 +## 测试信息 CodeCheck代码测试无异常 diff --git a/entry/build.gradle b/entry/build.gradle index 90cf65991f2d360749bd804ce22ab43b70970787..881675cac3ddbbbb4422868d06e3ce89b49ea766 100644 --- a/entry/build.gradle +++ b/entry/build.gradle @@ -21,6 +21,8 @@ dependencies { implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) testImplementation 'junit:junit:4.13' ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100' + // 本地依赖 + implementation project(':library') } decc { supportType = ['html', 'xml'] diff --git a/entry/src/main/config.json b/entry/src/main/config.json index 69e96b53560b2b4c30bed9d0b613d10494b2f83e..baf95e0cbaffc8a0218e0bab2942703fbaa4c3e9 100644 --- a/entry/src/main/config.json +++ b/entry/src/main/config.json @@ -19,7 +19,7 @@ "customizeData": [ { "name": "hwc-theme", - "value": "androidhwext:style/Theme.Emui.NoTitleBar", + "value": "androidhwext:style/Theme.Emui.Dark.NoActionBar", "extra": "" } ] @@ -44,8 +44,17 @@ ], "name": "com.len.MainAbility", "icon": "$media:icon", - "description": "$string:mainability_description", - "label": "$string:entry_MainAbility", + "label": "$string:app_name", + "type": "page", + "launchType": "standard" + }, + { + "name": "com.len.JavaMainAbility", + "type": "page", + "launchType": "standard" + }, + { + "name": "com.len.JsMainAbility", "type": "page", "launchType": "standard" } diff --git a/entry/src/main/java/com/len/JavaMainAbility.java b/entry/src/main/java/com/len/JavaMainAbility.java new file mode 100644 index 0000000000000000000000000000000000000000..ec57f9a4054aca4153668cdc0127636f9616c232 --- /dev/null +++ b/entry/src/main/java/com/len/JavaMainAbility.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.len; + +import com.len.library.AutoLinkStyleTextView; +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; +import ohos.agp.utils.Color; + +/** + * MainAbility + * + * @since 2021-06-28 + */ +public class JavaMainAbility extends Ability { + @Override + public void onStart(Intent intent) { + getWindow().setStatusBarColor(Color.getIntColor("#2E409F")); + super.onStart(intent); + setUIContent(ResourceTable.Layout_ability_java_main); + + AutoLinkStyleTextView autoLinkStyleTextView = (AutoLinkStyleTextView) + findComponentById(ResourceTable.Id_autoLinkStyleText); + autoLinkStyleTextView.setOnClickCallBack(position -> { + if (position == 0) { + ToastUtil.getInstance().showToast(this,"购买须知"); + } else { + ToastUtil.getInstance().showToast(this,"用户条款"); + } + }); + } +} diff --git a/entry/src/main/java/com/len/JsMainAbility.java b/entry/src/main/java/com/len/JsMainAbility.java new file mode 100644 index 0000000000000000000000000000000000000000..d404220fe3c47714c81562aaf149f25bd8949c75 --- /dev/null +++ b/entry/src/main/java/com/len/JsMainAbility.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.len; + +import ohos.aafwk.content.Intent; +import ohos.ace.ability.AceAbility; +import ohos.agp.utils.Color; + +/** + * MainAbility + * + * @since 2021-06-28 + */ +public class JsMainAbility extends AceAbility { + @Override + public void onStart(Intent intent) { + getWindow().setStatusBarColor(Color.getIntColor("#2E409F")); + super.onStart(intent); + } +} diff --git a/entry/src/main/java/com/len/MainAbility.java b/entry/src/main/java/com/len/MainAbility.java index ccb88eb8a01e47b533ab0e38ab6ba52ec5230479..827220c6e0a3325a755c92648fea8c9b8336cdd7 100644 --- a/entry/src/main/java/com/len/MainAbility.java +++ b/entry/src/main/java/com/len/MainAbility.java @@ -15,23 +15,41 @@ package com.len; -import ohos.ace.ability.AceAbility; +import ohos.aafwk.ability.Ability; import ohos.aafwk.content.Intent; +import ohos.aafwk.content.Operation; +import ohos.agp.utils.Color; /** * MainAbility * - * @author:username * @since 2021-06-28 */ -public class MainAbility extends AceAbility { +public class MainAbility extends Ability { @Override public void onStart(Intent intent) { + getWindow().setStatusBarColor(Color.getIntColor("#2E409F")); super.onStart(intent); - } + setUIContent(ResourceTable.Layout_ability_main); - @Override - public void onStop() { - super.onStop(); + findComponentById(ResourceTable.Id_btn_main_skip_java).setClickedListener(component -> { + Intent mIntent = new Intent(); + Operation operation = new Intent.OperationBuilder() + .withBundleName(getBundleName()) + .withAbilityName(JavaMainAbility.class) + .build(); + mIntent.setOperation(operation); + startAbility(mIntent); + }); + + findComponentById(ResourceTable.Id_btn_main_skip_js).setClickedListener(component -> { + Intent mIntent = new Intent(); + Operation operation = new Intent.OperationBuilder() + .withBundleName(getBundleName()) + .withAbilityName(JsMainAbility.class) + .build(); + mIntent.setOperation(operation); + startAbility(mIntent); + }); } } diff --git a/entry/src/main/java/com/len/ToastUtil.java b/entry/src/main/java/com/len/ToastUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..b066ec67d52b729dc804847898c941ba6f99f756 --- /dev/null +++ b/entry/src/main/java/com/len/ToastUtil.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.len; + +import ohos.agp.components.Component; +import ohos.agp.components.LayoutScatter; +import ohos.agp.components.Text; +import ohos.agp.window.dialog.ToastDialog; +import ohos.app.Context; + +/** + * Toast工具类 + * + * @since 2021-08-09 + */ +public class ToastUtil { + private ToastDialog toastDialog; + + private ToastUtil() { + } + + /** + * 实例 + * + * @return 实例 + */ + public static ToastUtil getInstance() { + return ToastUtilInstance.INSTANCE; + } + + /** + * Toast实例内部类 + * + * @since 2021-07-14 + */ + private static class ToastUtilInstance { + private static final ToastUtil INSTANCE = new ToastUtil(); + } + + /** + * 显示Toast + * + * @param context 上下文 + * @param content 内容信息 + */ + public void showToast(Context context, String content) { + if (toastDialog != null && toastDialog.isShowing()) { + toastDialog.cancel(); + } + + Component toastLayout = LayoutScatter.getInstance(context) + .parse(ResourceTable.Layout_layout_toast, null, false); + Text toastText = (Text) toastLayout.findComponentById(ResourceTable.Id_text_msg_toast); + toastText.setText(content); + toastDialog = new ToastDialog(context); + toastDialog.setComponent(toastLayout); + toastDialog.setTransparent(true); + toastDialog.show(); + } +} diff --git a/entry/src/main/js/default/common/commpont/textView/textView.css b/entry/src/main/js/default/common/commpont/textView/textView.css index 3aee2750449d03a2e6e7164a5e61f5d3778c4a61..27052a4cc8805a25129461c4779d96d59c44c0ac 100644 --- a/entry/src/main/js/default/common/commpont/textView/textView.css +++ b/entry/src/main/js/default/common/commpont/textView/textView.css @@ -22,14 +22,14 @@ display: flex; align-items: center; width: 100%; - padding: 20px 15px; + padding: 15px 15px; background-color: #4050B5; } .header-text{ - font-size: 26px; + font-size: 20px; color: #ffffff; - font-weight: 700; + font-weight: 500; } .title { font-size: 18px; diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json index 0bae6bd40f7360d5d818998221b199d3ec0f69c0..8a10ba923cd6deb117f1393f3aa375e17b676d5c 100644 --- a/entry/src/main/resources/base/element/string.json +++ b/entry/src/main/resources/base/element/string.json @@ -1,8 +1,8 @@ { "string": [ { - "name": "entry_MainAbility", - "value": "entry_MainAbility" + "name": "app_name", + "value": "AutoSpannableTextView" }, { "name": "mainability_description", diff --git a/entry/src/main/resources/base/graphic/button_bg.xml b/entry/src/main/resources/base/graphic/button_bg.xml new file mode 100644 index 0000000000000000000000000000000000000000..0a1258488c1cd807f56cf48cc2641c76ea0217dc --- /dev/null +++ b/entry/src/main/resources/base/graphic/button_bg.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/graphic/shape_button_normal.xml b/entry/src/main/resources/base/graphic/shape_button_normal.xml new file mode 100644 index 0000000000000000000000000000000000000000..6481b9f8a5f0f691bf302844c84593389ed739e4 --- /dev/null +++ b/entry/src/main/resources/base/graphic/shape_button_normal.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/graphic/shape_button_pressed.xml b/entry/src/main/resources/base/graphic/shape_button_pressed.xml new file mode 100644 index 0000000000000000000000000000000000000000..5c6851afadacb7212b0ce29cdbb225be9336e6a8 --- /dev/null +++ b/entry/src/main/resources/base/graphic/shape_button_pressed.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/graphic/toast_bg.xml b/entry/src/main/resources/base/graphic/toast_bg.xml new file mode 100644 index 0000000000000000000000000000000000000000..d127f7350e2120a0281a002b2aaed7b6399ddf02 --- /dev/null +++ b/entry/src/main/resources/base/graphic/toast_bg.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/layout/ability_java_main.xml b/entry/src/main/resources/base/layout/ability_java_main.xml new file mode 100644 index 0000000000000000000000000000000000000000..a053b7aee8da21640376bab60bb2e1c79eecf255 --- /dev/null +++ b/entry/src/main/resources/base/layout/ability_java_main.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/layout/ability_main.xml b/entry/src/main/resources/base/layout/ability_main.xml new file mode 100644 index 0000000000000000000000000000000000000000..2bfa4999e6afddb5fb8249bfb38baf2359ced053 --- /dev/null +++ b/entry/src/main/resources/base/layout/ability_main.xml @@ -0,0 +1,41 @@ + + + + + + + +