diff --git a/ClockFACardDemo/LICENSE b/ClockFACardDemo/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..80576ef141485b36eea4aebf25af97020bc2de44 --- /dev/null +++ b/ClockFACardDemo/LICENSE @@ -0,0 +1,78 @@ + Copyright (c) 2021 Huawei Device Co., Ltd. All rights reserved. + + 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. + +Apache License, Version 2.0 +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: +1.You must give any other recipients of the Work or Derivative Works a copy of this License; and +2.You must cause any modified files to carry prominent notices stating that You changed the files; and +3.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 +4.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/ClockFACardDemo/README.md b/ClockFACardDemo/README.md new file mode 100644 index 0000000000000000000000000000000000000000..28abd016cc4debd3869fa438a32bae36632aee96 --- /dev/null +++ b/ClockFACardDemo/README.md @@ -0,0 +1,47 @@ +# ClockFACardDemo +简介 +• 本cookbook旨在使开发人员了解HarmonyOS中JAVA卡片的开发,包含卡片的创建、更新、删除功能,实现了时分秒,年月日,星期的实时刷新效果。 + +安装要求 +• 安装DevEco Studio +• 设置DevEco Studio开发环境。DevEco Studio开发环境需要连接到网络,以确保该正常使用。可以根据以下两种情况配置开发环境: + 1.如果您可以直接访问Internet,则只需下载HarmonyOS SDK + 2.如果网络无法直接访问Internet,则可以通过代理服务器进行访问 +• 生成密钥并申请证书 + +用户指南 +• 下载此项目 +• 打开HUAWEI DevEco Studio,单击File> Open选择此ComponentCodelab +• 单击Build> Build App(s)/Hap(s)>Build Debug Hap(s)以编译hap软件包 +• 单击Run> Run 'entry'以运行hap包 + +注意 +• 您可以选择在模拟器或真机上运行hap软件包。 +• 如果在真机上运行它,则需要在项目的File> Project Structure> Modules> Signing Configs中配置签名和证书信息。 + +许可 +请参阅LICENSE文件以获得更多信息。 + +What is it? +This cookbook is designed to enable developers to understand the development of Java cards in HarmonyOS, including the creation, update, and deletion of cards, and the real-time refresh effect of hour, second, year, month, day, and week. + +Installation requirements +• Install DevEco Studio +• Set up the DevEco Studio development environment.The DevEco Studio development environment needs to depend on the network environment. It needs to be connected to the network to ensure the normal use of the tool.The development environment can be configured according to the following two situations + 1.If you can directly access the Internet, just download the HarmonyOS SDK + 2.If the network cannot access the Internet directly, it can be accessed through a proxy server +• Generate secret key and apply for certificate + +User guide +• Download this Project +• Open HUAWEI DevEco Studio, click File> Open> Then select and open this Project +• Click Build> Build App(s)/Hap(s)>Build Debug Hap(s) to compile the hap package +• Click Run> Run 'entry' to run the hap package + +Note +• You can choose to run the hap package on the simulator or the phone. +• If you run it on the phone, you need to configure the signature and certificate information in the project's File> Project Structure> Modules> Signing Configs. + +Licensing +Please see LICENSE for more info. + diff --git a/ClockFACardDemo/RELEASE-NOTES.md b/ClockFACardDemo/RELEASE-NOTES.md new file mode 100644 index 0000000000000000000000000000000000000000..ea23a13e3d4407d06cba3aa7155a23e5081b50b4 --- /dev/null +++ b/ClockFACardDemo/RELEASE-NOTES.md @@ -0,0 +1,2 @@ +1.0.0 +1.Initial version \ No newline at end of file diff --git a/ClockFACardDemo/build.gradle b/ClockFACardDemo/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..1ce01d8202dede3a761267d58bd910197a647d83 --- /dev/null +++ b/ClockFACardDemo/build.gradle @@ -0,0 +1,36 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +apply plugin: 'com.huawei.ohos.app' + +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 4 + } +} + +buildscript { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + jcenter() + } + dependencies { + classpath 'com.huawei.ohos:hap:2.4.4.2' + } +} + +allprojects { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + jcenter() + } +} diff --git a/ClockFACardDemo/entry/.gitignore b/ClockFACardDemo/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..796b96d1c402326528b4ba3c12ee9d92d0e212e9 --- /dev/null +++ b/ClockFACardDemo/entry/.gitignore @@ -0,0 +1 @@ +/build diff --git a/ClockFACardDemo/entry/build.gradle b/ClockFACardDemo/entry/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..90d8c89d8096320385b29451a9e804b30d7cf853 --- /dev/null +++ b/ClockFACardDemo/entry/build.gradle @@ -0,0 +1,23 @@ +apply plugin: 'com.huawei.ohos.hap' +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 4 + } + buildTypes { + release { + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } + } + } + compileOptions { annotationEnabled true } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) + implementation 'android.arch.persistence.room:runtime:1.1.1' + testCompile 'junit:junit:4.12' +} + diff --git a/ClockFACardDemo/entry/proguard-rules.pro b/ClockFACardDemo/entry/proguard-rules.pro new file mode 100644 index 0000000000000000000000000000000000000000..f7666e47561d514b2a76d5a7dfbb43ede86da92a --- /dev/null +++ b/ClockFACardDemo/entry/proguard-rules.pro @@ -0,0 +1 @@ +# config module specific ProGuard rules here. \ No newline at end of file diff --git a/ClockFACardDemo/entry/src/main/config.json b/ClockFACardDemo/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..a57e096e0b9f33a3c03fb60f932430fe36e32666 --- /dev/null +++ b/ClockFACardDemo/entry/src/main/config.json @@ -0,0 +1,84 @@ +{ + "app": { + "bundleName": "com.huawei.cookbook", + "vendor": "huawei", + "version": { + "code": 1000000, + "name": "1.0" + } + }, + "deviceConfig": { + "default": { + "keepAlive": true + } + }, + "module": { + "package": "com.huawei.cookbooks", + "name": ".MyApplication", + "mainAbility": "com.huawei.cookbooks.MainAbility", + "deviceType": [ + "default" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "name": "com.huawei.cookbooks.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "singleton", + "formsEnabled": true, + "visible": true, + "forms": [ + { + "landscapeLayouts": [ + "$layout:form_image_with_info_date_card_2_2", + "$layout:form_image_with_info_date_card_2_4" + ], + "isDefault": true, + "scheduledUpdateTime": "10:30", + "defaultDimension": "2*2", + "name": "DateCard", + "description": "This is a form card", + "colorMode": "auto", + "type": "Java", + "supportDimensions": [ + "2*2", + "2*4" + ], + "portraitLayouts": [ + "$layout:form_image_with_info_date_card_2_2", + "$layout:form_image_with_info_date_card_2_4" + ], + "updateEnabled": true, + "updateDuration": 1, + "formVisibleNotify": true + } + ] + }, + { + "name": "com.huawei.cookbooks.TimerAbility", + "icon": "$media:icon", + "description": "$string:TimeAbility_description", + "type": "service", + "visible": false + } + ] + } +} \ No newline at end of file diff --git a/ClockFACardDemo/entry/src/main/java/com/huawei/cookbooks/MainAbility.java b/ClockFACardDemo/entry/src/main/java/com/huawei/cookbooks/MainAbility.java new file mode 100644 index 0000000000000000000000000000000000000000..cdfa9f286a7b14510733e001281e20a478e70901 --- /dev/null +++ b/ClockFACardDemo/entry/src/main/java/com/huawei/cookbooks/MainAbility.java @@ -0,0 +1,115 @@ +/* + * 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.huawei.cookbooks; + +import com.huawei.cookbooks.database.Form; +import com.huawei.cookbooks.database.FormDatabase; +import com.huawei.cookbooks.slice.ClockCardSlice; +import com.huawei.cookbooks.utils.ComponentProviderUtils; +import com.huawei.cookbooks.utils.DatabaseUtils; + +import ohos.aafwk.ability.Ability; +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.ability.ProviderFormInfo; +import ohos.aafwk.content.Intent; +import ohos.aafwk.content.Operation; +import ohos.agp.components.ComponentProvider; +import ohos.data.DatabaseHelper; +import ohos.data.orm.OrmContext; +import ohos.hiviewdfx.HiLog; +import ohos.hiviewdfx.HiLogLabel; + +/** + * Card Main Ability + */ +public class MainAbility extends Ability { + private static final HiLogLabel LABEL_LOG = new HiLogLabel(0, 0, "com.huawei.cookbooks.MainAbility"); + private static final int DEFAULT_DIMENSION_2X2 = 2; + private static final int DEFAULT_DIMENSION_2X4 = 3; + private static final String EMPTY_STRING = ""; + private static final int INVALID_FORM_ID = -1; + private long formId; + private ProviderFormInfo formInfo; + private DatabaseHelper helper = new DatabaseHelper(this); + private OrmContext connect; + + @Override + public void onStart(Intent intent) { + super.onStart(intent); + connect = helper.getOrmContext("FormDatabase", "FormDatabase.db", FormDatabase.class); + // 启动TimerAbility + Intent intentService = new Intent(); + Operation operation = + new Intent.OperationBuilder() + .withDeviceId("") + .withBundleName(getBundleName()) + .withAbilityName(TimerAbility.class.getName()) + .build(); + intentService.setOperation(operation); + startAbility(intentService); + super.setMainRoute(ClockCardSlice.class.getName()); + } + + @Override + protected ProviderFormInfo onCreateForm(Intent intent) { + if (intent == null) { + return new ProviderFormInfo(); + } + // 获取卡片id + formId = INVALID_FORM_ID; + if (intent.hasParameter(AbilitySlice.PARAM_FORM_IDENTITY_KEY)) { + formId = intent.getLongParam(AbilitySlice.PARAM_FORM_IDENTITY_KEY, INVALID_FORM_ID); + } else { + return new ProviderFormInfo(); + } + // 获取卡片名称 + String formName = EMPTY_STRING; + if (intent.hasParameter(AbilitySlice.PARAM_FORM_NAME_KEY)) { + formName = intent.getStringParam(AbilitySlice.PARAM_FORM_NAME_KEY); + } + // 获取卡片规格 + int dimension = DEFAULT_DIMENSION_2X2; + if (intent.hasParameter(AbilitySlice.PARAM_FORM_DIMENSION_KEY)) { + dimension = intent.getIntParam(AbilitySlice.PARAM_FORM_DIMENSION_KEY, DEFAULT_DIMENSION_2X2); + } + int layoutId = ResourceTable.Layout_form_image_with_info_date_card_2_2; + if (dimension == DEFAULT_DIMENSION_2X4) { + layoutId = ResourceTable.Layout_form_image_with_info_date_card_2_4; + } + formInfo = new ProviderFormInfo(layoutId, this); + // 存储卡片信息 + Form form = new Form(formId, formName, dimension); + ComponentProvider componentProvider = ComponentProviderUtils.getComponentProvider(form, this); + formInfo.mergeActions(componentProvider); + if (connect == null) { + connect = + helper.getOrmContext("FormDatabase", "FormDatabase.db", FormDatabase.class); + } + try { + DatabaseUtils.insertForm(form, connect); + } catch (Exception e) { + DatabaseUtils.deleteFormData(form.getFormId(), connect); + } + return formInfo; + } + + @Override + protected void onDeleteForm(long formId) { + super.onDeleteForm(formId); + // 删除数据库中的卡片信息 + DatabaseUtils.deleteFormData(formId, connect); + } +} diff --git a/ClockFACardDemo/entry/src/main/java/com/huawei/cookbooks/MyApplication.java b/ClockFACardDemo/entry/src/main/java/com/huawei/cookbooks/MyApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..f85d694ae60537b43c057d0bbd14690f95a6c228 --- /dev/null +++ b/ClockFACardDemo/entry/src/main/java/com/huawei/cookbooks/MyApplication.java @@ -0,0 +1,28 @@ +/* + * 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.huawei.cookbooks; + +import ohos.aafwk.ability.AbilityPackage; + +/** + * MyApplication + */ +public class MyApplication extends AbilityPackage { + @Override + public void onInitialize() { + super.onInitialize(); + } +} diff --git a/ClockFACardDemo/entry/src/main/java/com/huawei/cookbooks/TimerAbility.java b/ClockFACardDemo/entry/src/main/java/com/huawei/cookbooks/TimerAbility.java new file mode 100644 index 0000000000000000000000000000000000000000..22a00dbc9640d24723b691c45e8539e0bbbc00d9 --- /dev/null +++ b/ClockFACardDemo/entry/src/main/java/com/huawei/cookbooks/TimerAbility.java @@ -0,0 +1,102 @@ +/* + * 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.huawei.cookbooks; + +import com.huawei.cookbooks.database.Form; +import com.huawei.cookbooks.database.FormDatabase; +import com.huawei.cookbooks.utils.ComponentProviderUtils; +import com.huawei.cookbooks.utils.DatabaseUtils; + +import ohos.aafwk.ability.Ability; +import ohos.aafwk.ability.FormException; +import ohos.aafwk.content.Intent; +import ohos.agp.components.ComponentProvider; +import ohos.data.DatabaseHelper; +import ohos.data.orm.OrmContext; +import ohos.data.orm.OrmPredicates; +import ohos.hiviewdfx.HiLog; +import ohos.hiviewdfx.HiLogLabel; +import ohos.rpc.IRemoteObject; + +import java.util.List; +import java.util.Timer; +import java.util.TimerTask; + +/** + * Time PA + */ +public class TimerAbility extends Ability { + private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, 0xD001100, "Demo"); + private static final long SEND_PERIOD = 1000L; + private DatabaseHelper helper = new DatabaseHelper(this); + private OrmContext connect; + + @Override + public void onStart(Intent intent) { + HiLog.info(LABEL_LOG, "TimerAbility::onStart"); + connect = helper.getOrmContext("FormDatabase", "FormDatabase.db", FormDatabase.class); + startTimer(); + super.onStart(intent); + } + + // 卡片更新定时器,每秒更新一次 + private void startTimer() { + Timer timer = new Timer(); + timer.schedule( + new TimerTask() { + @Override + public void run() { + updateForms(); + } + }, + 0, + SEND_PERIOD); + } + + private void updateForms() { + // 从数据库中获取卡片信息 + OrmPredicates ormPredicates = new OrmPredicates(Form.class); + List
formList = connect.query(ormPredicates); + // 更新时分秒 + if (formList.size() <= 0) { + return; + } + for (Form form : formList) { + // 遍历卡片列表更新卡片 + ComponentProvider componentProvider = ComponentProviderUtils.getComponentProvider(form, this); + try { + Long updateFormId = form.getFormId(); + updateForm(updateFormId, componentProvider); + } catch (FormException e) { + // 删除不存在的卡片 + DatabaseUtils.deleteFormData(form.getFormId(), connect); + HiLog.error(LABEL_LOG, "onUpdateForm updateForm error"); + } + } + } + + @Override + public void onBackground() { + super.onBackground(); + HiLog.info(LABEL_LOG, "TimerAbility::onBackground"); + } + + @Override + public void onStop() { + super.onStop(); + HiLog.info(LABEL_LOG, "TimerAbility::onStop"); + } +} diff --git a/ClockFACardDemo/entry/src/main/java/com/huawei/cookbooks/database/Form.java b/ClockFACardDemo/entry/src/main/java/com/huawei/cookbooks/database/Form.java new file mode 100644 index 0000000000000000000000000000000000000000..64c77fb6355ee6dbe4e8dc5eb5c7ec830e9707de --- /dev/null +++ b/ClockFACardDemo/entry/src/main/java/com/huawei/cookbooks/database/Form.java @@ -0,0 +1,63 @@ +/* + * 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.huawei.cookbooks.database; + +import ohos.data.orm.OrmObject; +import ohos.data.orm.annotation.Entity; +import ohos.data.orm.annotation.PrimaryKey; + +/** + * Card Table + */ +@Entity(tableName = "form") +public class Form extends OrmObject { + @PrimaryKey() + private Long formId; + private String formName; + private Integer dimension; + + public Form(Long formId, String formName, Integer dimension) { + this.formId = formId; + this.formName = formName; + this.dimension = dimension; + } + + public Form() { } + + public Integer getDimension() { + return dimension; + } + + public void setDimension(Integer dimension) { + this.dimension = dimension; + } + + public Long getFormId() { + return formId; + } + + public void setFormId(Long formId) { + this.formId = formId; + } + + public String getFormName() { + return formName; + } + + public void setFormName(String formName) { + this.formName = formName; + } +} diff --git a/ClockFACardDemo/entry/src/main/java/com/huawei/cookbooks/database/FormDatabase.java b/ClockFACardDemo/entry/src/main/java/com/huawei/cookbooks/database/FormDatabase.java new file mode 100644 index 0000000000000000000000000000000000000000..b69fc36bb032861467031fb052681ef9f7788a7b --- /dev/null +++ b/ClockFACardDemo/entry/src/main/java/com/huawei/cookbooks/database/FormDatabase.java @@ -0,0 +1,27 @@ +/* + * 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.huawei.cookbooks.database; + +import ohos.data.orm.OrmDatabase; +import ohos.data.orm.annotation.Database; + +/** + * Card Database + */ +@Database( + entities = {Form.class}, + version = 1) +public abstract class FormDatabase extends OrmDatabase { } diff --git a/ClockFACardDemo/entry/src/main/java/com/huawei/cookbooks/slice/ClockCardSlice.java b/ClockFACardDemo/entry/src/main/java/com/huawei/cookbooks/slice/ClockCardSlice.java new file mode 100644 index 0000000000000000000000000000000000000000..26a1d8d91d64f1681c0dc05c965e2b3c729c0788 --- /dev/null +++ b/ClockFACardDemo/entry/src/main/java/com/huawei/cookbooks/slice/ClockCardSlice.java @@ -0,0 +1,172 @@ +/* + * 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.huawei.cookbooks.slice; + +import com.huawei.cookbooks.ResourceTable; +import com.huawei.cookbooks.utils.ComponentProviderUtils; +import com.huawei.cookbooks.utils.DateUtils; +import com.huawei.cookbooks.utils.LogUtils; + +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import ohos.agp.components.Component; +import ohos.agp.components.Text; +import ohos.agp.utils.Color; +import ohos.eventhandler.EventHandler; +import ohos.eventhandler.EventRunner; +import ohos.eventhandler.InnerEvent; +import ohos.hiviewdfx.HiLogLabel; + +import java.util.Calendar; +import java.util.Timer; +import java.util.TimerTask; + +/** + * Clock Card Slice + */ +public class ClockCardSlice extends AbilitySlice { + private static final HiLogLabel LABEL_LOG = new HiLogLabel(0, 0, ClockCardSlice.class.getName()); + private static final long SEND_PERIOD = 1000L; + private static final int COLOR_RGB = 192; + private static final int TIME_LENGTH = 2; + private Text dateText; + private Text hourText; + private Text minText; + private Text secondText; + private EventRunner runner; + private MyEventHandle myEventHandle; + private AbilitySlice slice = this; + private Timer timer; + private Runnable runnable = new Runnable() { + private void initHandler() { + runner = EventRunner.getMainEventRunner(); + if (runner == null) { + return; + } + myEventHandle = new MyEventHandle(runner); + } + + @Override + public void run() { + // 初始化认证对象 + initHandler(); + } + }; + + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_form_image_with_info_date_card_2_2); + initComponent(); + startTimer(); + } + + private void startTimer() { + timer = new Timer(); + timer.schedule( + new TimerTask() { + @Override + public void run() { + runnable.run(); + myEventHandle.sendEvent(1); + } + }, + 0, + SEND_PERIOD); + } + + /** + * Init Component + */ + private void initComponent() { + Calendar now = Calendar.getInstance(); + Component dateComponent = slice.findComponentById(ResourceTable.Id_date); + if (dateComponent != null && dateComponent instanceof Text) { + dateText = (Text) dateComponent; + dateText.setText(DateUtils.getCurrentDate("yyyy-MM-dd")); + } + Component hourComponent = slice.findComponentById(ResourceTable.Id_hour); + if (hourComponent != null && hourComponent instanceof Text) { + hourText = (Text) hourComponent; + int hour = now.get(Calendar.HOUR_OF_DAY); + setTextValue(hour, hourText); + } + Component minComponent = findComponentById(ResourceTable.Id_min); + if (minComponent != null && minComponent instanceof Text) { + minText = (Text) minComponent; + int min = now.get(Calendar.MINUTE); + setTextValue(min, minText); + } + Component secComponent = findComponentById(ResourceTable.Id_sec); + if (secComponent != null && secComponent instanceof Text) { + secondText = (Text) secComponent; + int second = now.get(Calendar.SECOND); + setTextValue(second, secondText); + } + int weekId = ComponentProviderUtils.getWeekDayId(); + Component weekComponent = slice.findComponentById(weekId); + if (weekComponent != null && weekComponent instanceof Text) { + Text week = (Text) weekComponent; + week.setTextColor(new Color(Color.rgb(0, 0, 0))); + } + int lastWeekDayId = ComponentProviderUtils.getLastWeekDayId(); + Component lastWeekComponent = slice.findComponentById(lastWeekDayId); + if (weekComponent != null && lastWeekComponent instanceof Text) { + Text lastWeek = (Text) lastWeekComponent; + lastWeek.setTextColor(new Color(Color.rgb(COLOR_RGB, COLOR_RGB, COLOR_RGB))); + } + } + + private void setTextValue(int now, Text text) { + if (String.valueOf(now).length() < TIME_LENGTH) { + text.setText("0" + now); + } else { + text.setText(now + ""); + } + } + + @Override + public void onActive() { + super.onActive(); + } + + @Override + public void onForeground(Intent intent) { + super.onForeground(intent); + } + + private class MyEventHandle extends EventHandler { + MyEventHandle(EventRunner runner) throws IllegalArgumentException { + super(runner); + } + + @Override + protected void processEvent(InnerEvent event) { + super.processEvent(event); + int eventId = event.eventId; + if (eventId == 1) { + // 更新页面 + initComponent(); + } + } + } + + @Override + protected void onStop() { + LogUtils.info("onStop", " start to destroy slice"); + timer.cancel(); + } +} diff --git a/ClockFACardDemo/entry/src/main/java/com/huawei/cookbooks/utils/ComponentProviderUtils.java b/ClockFACardDemo/entry/src/main/java/com/huawei/cookbooks/utils/ComponentProviderUtils.java new file mode 100644 index 0000000000000000000000000000000000000000..3ae843ac0aa37b9f01aff9d445fcaf480c600122 --- /dev/null +++ b/ClockFACardDemo/entry/src/main/java/com/huawei/cookbooks/utils/ComponentProviderUtils.java @@ -0,0 +1,173 @@ +/* + * 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.huawei.cookbooks.utils; + +import com.huawei.cookbooks.ResourceTable; +import com.huawei.cookbooks.database.Form; + +import ohos.agp.components.ComponentProvider; +import ohos.agp.utils.Color; +import ohos.app.Context; + +import java.util.Calendar; + +/** + * Component ProviderUtils + */ +public class ComponentProviderUtils { + // 当前星期颜色 + private static Color nowWeekColor = new Color(Color.rgb(255, 245, 238)); + + // 原色星期 + private static Color primaryWeekColor = new Color(Color.rgb(192, 192, 192)); + + private static final int WEEK_DAYS = 7; + private static final int STRING_LENGTH = 2; + private static final int DIM_VERSION = 3; + private static final int SUNDAY = 1; + private static final int MONDAY = 2; + private static final int TUESDAY = 3; + private static final int WEDNESDAY = 4; + private static final int THURSDAY = 5; + private static final int FRIDAY = 6; + private static final int SATURDAY = 7; + + /** + * Obtain the day of the week + * + * @return week + */ + public static int getWeekDayId() { + Calendar calendar = Calendar.getInstance(); + int week = calendar.get(Calendar.DAY_OF_WEEK); + int result = getWeekIdResult(week); + return result; + } + + /** + * get week component id + * + * @param week week + * @return component id + */ + private static int getWeekIdResult(int week) { + int result = ResourceTable.Id_mon; + switch (week) { + case SUNDAY: + result = ResourceTable.Id_sun; + break; + case MONDAY: + result = ResourceTable.Id_mon; + break; + case TUESDAY: + result = ResourceTable.Id_tue; + break; + case WEDNESDAY: + result = ResourceTable.Id_wed; + break; + case THURSDAY: + result = ResourceTable.Id_thu; + break; + case FRIDAY: + result = ResourceTable.Id_fri; + break; + case SATURDAY: + result = ResourceTable.Id_sat; + break; + default: + result = ResourceTable.Id_sun; + break; + } + return result; + } + + /** + * Obtains the ComponentProvider object + * + * @param form form info + * @param context context + * @return component provider + */ + public static ComponentProvider getComponentProvider(Form form, Context context) { + int layoutId = ResourceTable.Layout_form_image_with_info_date_card_2_2; + if (form.getDimension() == DIM_VERSION) { + layoutId = ResourceTable.Layout_form_image_with_info_date_card_2_4; + } + ComponentProvider componentProvider = new ComponentProvider(layoutId, context); + setComponentProviderValue(componentProvider); + return componentProvider; + } + + /** + * Time converted to string + * + * @param time time + * @return time string + */ + private static String int2String(int time) { + String timeString; + if (String.valueOf(time).length() < STRING_LENGTH) { + timeString = "0" + time; + } else { + timeString = time + ""; + } + return timeString; + } + + /** + * Set the value of componentProvider + * + * @param componentProvider component provider + */ + private static void setComponentProviderValue(ComponentProvider componentProvider) { + Calendar now = Calendar.getInstance(); + int hour = now.get(Calendar.HOUR_OF_DAY); + int min = now.get(Calendar.MINUTE); + int second = now.get(Calendar.SECOND); + String hourString = int2String(hour); + String minString = int2String(min); + String secondString = int2String(second); + componentProvider.setText(ResourceTable.Id_date, DateUtils.getCurrentDate("yyyy-MM-dd")); + componentProvider.setText(ResourceTable.Id_hour, hourString); + componentProvider.setText(ResourceTable.Id_min, minString); + componentProvider.setText(ResourceTable.Id_sec, secondString); + + // 获取当前星期 + int weekDayId = getWeekDayId(); + componentProvider.setTextColor(weekDayId, nowWeekColor); + + // 将前一天的星期改回原色 + int lastWeekId = getLastWeekDayId(); + componentProvider.setTextColor(lastWeekId, primaryWeekColor); + } + + /** + * obtain previous day of the week + * + * @return previous day of the week + */ + public static int getLastWeekDayId() { + Calendar calendar = Calendar.getInstance(); + int week = calendar.get(Calendar.DAY_OF_WEEK); + int lastWeek; + if (week == 1) { + lastWeek = WEEK_DAYS; + } else { + lastWeek = week - 1; + } + return getWeekIdResult(lastWeek); + } +} diff --git a/ClockFACardDemo/entry/src/main/java/com/huawei/cookbooks/utils/DatabaseUtils.java b/ClockFACardDemo/entry/src/main/java/com/huawei/cookbooks/utils/DatabaseUtils.java new file mode 100644 index 0000000000000000000000000000000000000000..1c1d5238b74fac54d300d29b657b25b2261d6973 --- /dev/null +++ b/ClockFACardDemo/entry/src/main/java/com/huawei/cookbooks/utils/DatabaseUtils.java @@ -0,0 +1,55 @@ +/* + * 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.huawei.cookbooks.utils; + +import com.huawei.cookbooks.database.Form; + +import ohos.data.orm.OrmContext; +import ohos.data.orm.OrmPredicates; + +import java.util.List; + +/** + * Card Database Operations + */ +public class DatabaseUtils { + /** + * delete data + * + * @param formId form id + * @param connect data connection + */ + public static void deleteFormData(long formId, OrmContext connect) { + OrmPredicates where = connect.where(Form.class); + where.equalTo("formId", formId); + List query = connect.query(where); + if (!query.isEmpty()) { + connect.delete(query.get(0)); + connect.flush(); + } + } + + /** + * add card info + * + * @param form card object + * @param connect data connection + */ + public static void insertForm(Form form, OrmContext connect) { + connect.insert(form); + connect.flush(); + } +} diff --git a/ClockFACardDemo/entry/src/main/java/com/huawei/cookbooks/utils/DateUtils.java b/ClockFACardDemo/entry/src/main/java/com/huawei/cookbooks/utils/DateUtils.java new file mode 100644 index 0000000000000000000000000000000000000000..b333f12fc4edd8d6ba932d618841d3d5e65cf08d --- /dev/null +++ b/ClockFACardDemo/entry/src/main/java/com/huawei/cookbooks/utils/DateUtils.java @@ -0,0 +1,38 @@ +/* + * 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.huawei.cookbooks.utils; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * Date time util + */ +public class DateUtils { + /** + * current time + * + * @param format format + * @return corresponding format string + */ + public static String getCurrentDate(String format) { + DateFormat dateFormat = new SimpleDateFormat(format); + Date date = new Date(); + String formatDate = dateFormat.format(date); + return formatDate; + } +} diff --git a/ClockFACardDemo/entry/src/main/java/com/huawei/cookbooks/utils/LogUtils.java b/ClockFACardDemo/entry/src/main/java/com/huawei/cookbooks/utils/LogUtils.java new file mode 100644 index 0000000000000000000000000000000000000000..baaea54df5ecde61a3fa998d43942c4d67eb236f --- /dev/null +++ b/ClockFACardDemo/entry/src/main/java/com/huawei/cookbooks/utils/LogUtils.java @@ -0,0 +1,72 @@ +/* + * 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.huawei.cookbooks.utils; + +import ohos.hiviewdfx.HiLog; +import ohos.hiviewdfx.HiLogLabel; + +/** + * LogUtils + */ +public class LogUtils { + private static final String TAG_LOG = "LogUtil"; + + private static final HiLogLabel LABEL_LOG = new HiLogLabel(0, 0, LogUtils.TAG_LOG); + + private static final String LOG_FORMAT = "%{public}s: %{public}s"; + + private LogUtils() { } + + /** + * Print debug log + * + * @param tag log tag + * @param msg log message + */ + public static void debug(String tag, String msg) { + HiLog.debug(LABEL_LOG, LOG_FORMAT, tag, msg); + } + + /** + * Print info log + * + * @param tag log tag + * @param msg log message + */ + public static void info(String tag, String msg) { + HiLog.info(LABEL_LOG, LOG_FORMAT, tag, msg); + } + + /** + * Print warn log + * + * @param tag log tag + * @param msg log message + */ + public static void warn(String tag, String msg) { + HiLog.warn(LABEL_LOG, LOG_FORMAT, tag, msg); + } + + /** + * Print error log + * + * @param tag log tag + * @param msg log message + */ + public static void error(String tag, String msg) { + HiLog.error(LABEL_LOG, LOG_FORMAT, tag, msg); + } +} diff --git a/ClockFACardDemo/entry/src/main/resources/base/element/string.json b/ClockFACardDemo/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..de56bc1fc8ca81fb9e3e584a4646d6b3e482c7a2 --- /dev/null +++ b/ClockFACardDemo/entry/src/main/resources/base/element/string.json @@ -0,0 +1,20 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ClockCard" + }, + { + "name": "mainability_description", + "value": "Java_Phone_Empty Feature Ability" + }, + { + "name": "HelloWorld", + "value": "Hello World" + }, + { + "name": "TimeAbility_description", + "value": "hap sample empty service" + } + ] +} \ No newline at end of file diff --git a/ClockFACardDemo/entry/src/main/resources/base/graphic/background_ability_main.xml b/ClockFACardDemo/entry/src/main/resources/base/graphic/background_ability_main.xml new file mode 100644 index 0000000000000000000000000000000000000000..c0c0a3df480fa387a452b9c40ca191cc918a3fc0 --- /dev/null +++ b/ClockFACardDemo/entry/src/main/resources/base/graphic/background_ability_main.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/ClockFACardDemo/entry/src/main/resources/base/layout/ability_main.xml b/ClockFACardDemo/entry/src/main/resources/base/layout/ability_main.xml new file mode 100644 index 0000000000000000000000000000000000000000..adab58cdd70238cd3f4f9a6a8fbe81755a036172 --- /dev/null +++ b/ClockFACardDemo/entry/src/main/resources/base/layout/ability_main.xml @@ -0,0 +1,17 @@ + + + + + \ No newline at end of file diff --git a/ClockFACardDemo/entry/src/main/resources/base/layout/form_image_with_info_date_card_2_2.xml b/ClockFACardDemo/entry/src/main/resources/base/layout/form_image_with_info_date_card_2_2.xml new file mode 100644 index 0000000000000000000000000000000000000000..679a3a2d074ccd866e824e7d3d70a90964faab14 --- /dev/null +++ b/ClockFACardDemo/entry/src/main/resources/base/layout/form_image_with_info_date_card_2_2.xml @@ -0,0 +1,203 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ClockFACardDemo/entry/src/main/resources/base/layout/form_image_with_info_date_card_2_4.xml b/ClockFACardDemo/entry/src/main/resources/base/layout/form_image_with_info_date_card_2_4.xml new file mode 100644 index 0000000000000000000000000000000000000000..c97b3f31e87863f9a65b70ae2524fbe8e7bba17c --- /dev/null +++ b/ClockFACardDemo/entry/src/main/resources/base/layout/form_image_with_info_date_card_2_4.xml @@ -0,0 +1,216 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ClockFACardDemo/entry/src/main/resources/base/media/form_image_with_info_datecard_default_image_2.png b/ClockFACardDemo/entry/src/main/resources/base/media/form_image_with_info_datecard_default_image_2.png new file mode 100644 index 0000000000000000000000000000000000000000..64d3f425041c3dc993e82b45f1f5e7c56804db70 Binary files /dev/null and b/ClockFACardDemo/entry/src/main/resources/base/media/form_image_with_info_datecard_default_image_2.png differ diff --git a/ClockFACardDemo/entry/src/main/resources/base/media/form_image_with_info_form_card_default_image_2.png b/ClockFACardDemo/entry/src/main/resources/base/media/form_image_with_info_form_card_default_image_2.png new file mode 100644 index 0000000000000000000000000000000000000000..64d3f425041c3dc993e82b45f1f5e7c56804db70 Binary files /dev/null and b/ClockFACardDemo/entry/src/main/resources/base/media/form_image_with_info_form_card_default_image_2.png differ diff --git a/ClockFACardDemo/entry/src/main/resources/base/media/icon.png b/ClockFACardDemo/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ClockFACardDemo/entry/src/main/resources/base/media/icon.png differ diff --git a/ClockFACardDemo/entry/src/ohosTest/config.json b/ClockFACardDemo/entry/src/ohosTest/config.json new file mode 100644 index 0000000000000000000000000000000000000000..a5df38c4a0039b030393cea561c6568fc0866430 --- /dev/null +++ b/ClockFACardDemo/entry/src/ohosTest/config.json @@ -0,0 +1,39 @@ +{ + "app": { + "bundleName": "com.huawei.cookbooks", + "vendor": "huawei", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5 + } + }, + "deviceConfig": {}, + "module": { + "package": "com.huawei.cookbooks", + "name": "testModule", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry_test", + "moduleType": "feature" + }, + "abilities": [ + { + "name": "decc.testkit.runner.EntryAbility", + "description": "Test Entry Ability", + "icon": "$media:icon", + "label": "TestAbility", + "launchType": "standard", + "orientation": "landscape", + "visible": true, + "type": "page" + } + ] + } +} \ No newline at end of file diff --git a/ClockFACardDemo/entry/src/ohosTest/java/com/huawei/cookbooks/ExampleOhosTest.java b/ClockFACardDemo/entry/src/ohosTest/java/com/huawei/cookbooks/ExampleOhosTest.java new file mode 100644 index 0000000000000000000000000000000000000000..b88edd22bdf50501a3c190d1a2edb809141d8646 --- /dev/null +++ b/ClockFACardDemo/entry/src/ohosTest/java/com/huawei/cookbooks/ExampleOhosTest.java @@ -0,0 +1,12 @@ +package com.huawei.cookbooks; + +import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry; + + +public class ExampleOhosTest { + @Test + public void testBundleName() { + final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName(); + assertEquals("com.huawei.clockcard", actualBundleName); + } +} \ No newline at end of file diff --git a/ClockFACardDemo/entry/src/test/java/com/huawei/cookbooks/ExampleTest.java b/ClockFACardDemo/entry/src/test/java/com/huawei/cookbooks/ExampleTest.java new file mode 100644 index 0000000000000000000000000000000000000000..790846344f6fdfb7eb978df65a7712f030cf2056 --- /dev/null +++ b/ClockFACardDemo/entry/src/test/java/com/huawei/cookbooks/ExampleTest.java @@ -0,0 +1,9 @@ +package com.huawei.cookbooks; + +import org.junit.Test; + +public class ExampleTest { + @Test + public void onStart() { + } +} diff --git a/ClockFACardDemo/gradle/wrapper/gradle-wrapper.jar b/ClockFACardDemo/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000000000000000000000000000000000..490fda8577df6c95960ba7077c43220e5bb2c0d9 Binary files /dev/null and b/ClockFACardDemo/gradle/wrapper/gradle-wrapper.jar differ diff --git a/ClockFACardDemo/gradle/wrapper/gradle-wrapper.properties b/ClockFACardDemo/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000000000000000000000000000000000..f59159e865d4b59feb1b8c44b001f62fc5d58df4 --- /dev/null +++ b/ClockFACardDemo/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://repo.huaweicloud.com/gradle/gradle-6.3-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/ClockFACardDemo/settings.gradle b/ClockFACardDemo/settings.gradle new file mode 100644 index 0000000000000000000000000000000000000000..4773db73233a570c2d0c01a22e75321acfbf7a07 --- /dev/null +++ b/ClockFACardDemo/settings.gradle @@ -0,0 +1 @@ +include ':entry' diff --git a/ComponentCodelab/LICENSE b/ComponentCodelab/LICENSE index 7c357dc828cf7d8c783f10ed6bb1bac8a1e903c1..80576ef141485b36eea4aebf25af97020bc2de44 100644 --- a/ComponentCodelab/LICENSE +++ b/ComponentCodelab/LICENSE @@ -1,10 +1,10 @@ - Copyright (c) 2021 Huawei Device Co., Ltd. + Copyright (c) 2021 Huawei Device Co., Ltd. All rights reserved. - Licensed under the Apache License,Version 2.0 (the "License"); + 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 + 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, diff --git a/ComponentCodelab/build.gradle b/ComponentCodelab/build.gradle index 0cdb1590ae7440ce7a35f6a3f6d2e970542c718e..1cad0050dc02f19207e7df37fa4ec4cd44101b41 100644 --- a/ComponentCodelab/build.gradle +++ b/ComponentCodelab/build.gradle @@ -19,7 +19,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.huawei.ohos:hap:2.4.2.7' + classpath 'com.huawei.ohos:hap:2.4.4.2' classpath 'com.huawei.ohos:decctest:1.0.0.7' } } diff --git a/ComponentCodelab/checkbox/build.gradle b/ComponentCodelab/checkbox/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..66c5259e68ee219a7d0d65202c9543e0c36b6fc7 --- /dev/null +++ b/ComponentCodelab/checkbox/build.gradle @@ -0,0 +1,28 @@ +apply plugin: 'com.huawei.ohos.hap' +apply plugin: 'com.huawei.ohos.decctest' +//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#ZH-CN_TOPIC_0000001154985555__section1112183053510 +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 5 + } + buildTypes { + release { + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } + } + } + entryModules "entry" +} + +dependencies { + entryImplementation project(':entry') + implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) + testImplementation 'junit:junit:4.13' + ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100' +} +decc { + supportType = ['html', 'xml'] +} diff --git a/ComponentCodelab/checkbox/src/main/config.json b/ComponentCodelab/checkbox/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..d1f52641332195b0e5061b2c26b53ff93d8ca8fd --- /dev/null +++ b/ComponentCodelab/checkbox/src/main/config.json @@ -0,0 +1,37 @@ +{ + "app": { + "bundleName": "com.huawei.cookbook", + "vendor": "huawei", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.huawei.checkbox", + "name": ".MyApplication", + "mainAbility": "com.huawei.checkbox.MainAbility", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "checkbox", + "moduleType": "feature", + "installationFree": false + }, + "abilities": [ + { + "orientation": "unspecified", + "visible": true, + "name": "com.huawei.checkbox.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:checkbox_MainAbility", + "type": "page", + "launchType": "standard" + } + ] + } +} \ No newline at end of file diff --git a/ComponentCodelab/checkbox/src/main/java/com/huawei/checkbox/MainAbility.java b/ComponentCodelab/checkbox/src/main/java/com/huawei/checkbox/MainAbility.java new file mode 100644 index 0000000000000000000000000000000000000000..c57f73e654022b47a20511d42f91a33fb9afc270 --- /dev/null +++ b/ComponentCodelab/checkbox/src/main/java/com/huawei/checkbox/MainAbility.java @@ -0,0 +1,32 @@ +/* + * 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.huawei.checkbox; + +import com.huawei.checkbox.slice.MainAbilitySlice; + +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; + +/** + * MainAbility + */ +public class MainAbility extends Ability { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setMainRoute(MainAbilitySlice.class.getName()); + } +} diff --git a/ComponentCodelab/checkbox/src/main/java/com/huawei/checkbox/MyApplication.java b/ComponentCodelab/checkbox/src/main/java/com/huawei/checkbox/MyApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..0a6676c5c761821ad32a59d0d7c9f3d6a53efc4e --- /dev/null +++ b/ComponentCodelab/checkbox/src/main/java/com/huawei/checkbox/MyApplication.java @@ -0,0 +1,28 @@ +/* + * 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.huawei.checkbox; + +import ohos.aafwk.ability.AbilityPackage; + +/** + * MyApplication + */ +public class MyApplication extends AbilityPackage { + @Override + public void onInitialize() { + super.onInitialize(); + } +} diff --git a/ComponentCodelab/checkbox/src/main/java/com/huawei/checkbox/slice/MainAbilitySlice.java b/ComponentCodelab/checkbox/src/main/java/com/huawei/checkbox/slice/MainAbilitySlice.java new file mode 100644 index 0000000000000000000000000000000000000000..756ef1b41c3a979c9710d31450d4576e21402ef7 --- /dev/null +++ b/ComponentCodelab/checkbox/src/main/java/com/huawei/checkbox/slice/MainAbilitySlice.java @@ -0,0 +1,120 @@ +/* + * 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.huawei.checkbox.slice; + +import com.huawei.checkbox.ResourceTable; + +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import ohos.agp.colors.RgbPalette; +import ohos.agp.components.Checkbox; +import ohos.agp.components.ComponentState; +import ohos.agp.components.Text; +import ohos.agp.components.element.ShapeElement; +import ohos.agp.components.element.StateElement; + +import java.util.HashSet; +import java.util.Set; + +/** + * MainAbilitySlice + */ +public class MainAbilitySlice extends AbilitySlice { + private Text answer; + private Set selectedSet = new HashSet<>(); + + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_checkbox); + answer = (Text) findComponentById(ResourceTable.Id_text_answer); + initCheckbox(); + } + + // 获取Checkbox的背景 + private StateElement getStateElement() { + ShapeElement elementButtonOn = new ShapeElement(); + elementButtonOn.setRgbColor(RgbPalette.RED); + elementButtonOn.setShape(ShapeElement.OVAL); + + ShapeElement elementButtonOff = new ShapeElement(); + elementButtonOff.setRgbColor(RgbPalette.WHITE); + elementButtonOff.setShape(ShapeElement.OVAL); + + StateElement checkElement = new StateElement(); + checkElement.addState(new int[]{ComponentState.COMPONENT_STATE_CHECKED}, elementButtonOn); + checkElement.addState(new int[]{ComponentState.COMPONENT_STATE_EMPTY}, elementButtonOff); + return checkElement; + } + + // 订阅Checkbox状态变化 + private void setCheckedStateChangedListener(Checkbox checkbox, String checkValue) { + checkbox.setCheckedStateChangedListener((view, state) -> { + if (state) { + selectedSet.add(checkValue); + } else { + selectedSet.remove(checkValue); + } + showAnswer(); + }); + } + + // 初始化Checkbox并设置订阅事件 + private void initCheckbox() { + Checkbox checkbox1 = (Checkbox) findComponentById(ResourceTable.Id_checkbox_1); + checkbox1.setButtonElement(getStateElement()); + setCheckedStateChangedListener(checkbox1, "A"); + if (checkbox1.isChecked()) { + selectedSet.add("A"); + } + + Checkbox checkbox2 = (Checkbox) findComponentById(ResourceTable.Id_checkbox_2); + checkbox2.setButtonElement(getStateElement()); + setCheckedStateChangedListener(checkbox2, "B"); + if (checkbox2.isChecked()) { + selectedSet.add("B"); + } + + Checkbox checkbox3 = (Checkbox) findComponentById(ResourceTable.Id_checkbox_3); + checkbox3.setButtonElement(getStateElement()); + setCheckedStateChangedListener(checkbox3, "C"); + if (checkbox3.isChecked()) { + selectedSet.add("C"); + } + + Checkbox checkbox4 = (Checkbox) findComponentById(ResourceTable.Id_checkbox_4); + checkbox4.setButtonElement(getStateElement()); + setCheckedStateChangedListener(checkbox4, "D"); + if (checkbox4.isChecked()) { + selectedSet.add("D"); + } + } + + private void showAnswer() { + String select = selectedSet.toString(); + answer.setText(select); + } + + @Override + public void onActive() { + super.onActive(); + } + + @Override + public void onForeground(Intent intent) { + super.onForeground(intent); + } +} diff --git a/ComponentCodelab/checkbox/src/main/resources/base/element/string.json b/ComponentCodelab/checkbox/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f4542ca0ef5b2c60502686b11d594009fc85ad68 --- /dev/null +++ b/ComponentCodelab/checkbox/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "checkbox_MainAbility", + "value": "checkbox_MainAbility" + }, + { + "name": "mainability_description", + "value": "Java_Empty Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "Hello World" + } + ] +} \ No newline at end of file diff --git a/ComponentCodelab/checkbox/src/main/resources/base/graphic/background_checkbox.xml b/ComponentCodelab/checkbox/src/main/resources/base/graphic/background_checkbox.xml new file mode 100644 index 0000000000000000000000000000000000000000..c0c0a3df480fa387a452b9c40ca191cc918a3fc0 --- /dev/null +++ b/ComponentCodelab/checkbox/src/main/resources/base/graphic/background_checkbox.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/ComponentCodelab/checkbox/src/main/resources/base/layout/checkbox.xml b/ComponentCodelab/checkbox/src/main/resources/base/layout/checkbox.xml new file mode 100644 index 0000000000000000000000000000000000000000..45ff7f9f11a71d55a53209e7e6cdb5c3a2977430 --- /dev/null +++ b/ComponentCodelab/checkbox/src/main/resources/base/layout/checkbox.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/ComponentCodelab/checkbox/src/main/resources/base/media/icon.png b/ComponentCodelab/checkbox/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ComponentCodelab/checkbox/src/main/resources/base/media/icon.png differ diff --git a/ComponentCodelab/checkbox/src/main/resources/en/element/string.json b/ComponentCodelab/checkbox/src/main/resources/en/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..fe97eab06aa7c534bace1184dfa98c8144222d51 --- /dev/null +++ b/ComponentCodelab/checkbox/src/main/resources/en/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "checkbox_MainAbility", + "value": "checkbox_MainAbility" + }, + { + "name": "mainability_description", + "value": "Java_Empty Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "Hello World" + } + ] +} diff --git a/ComponentCodelab/checkbox/src/main/resources/zh/element/string.json b/ComponentCodelab/checkbox/src/main/resources/zh/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..fa147eedb86d21bf7c29d698ed91973531ea6b16 --- /dev/null +++ b/ComponentCodelab/checkbox/src/main/resources/zh/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "checkbox_MainAbility", + "value": "checkbox_MainAbility" + }, + { + "name": "mainability_description", + "value": "Java_Empty Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "你好,世界" + } + ] +} \ No newline at end of file diff --git a/ComponentCodelab/checkbox/src/ohosTest/java/com/huawei/checkbox/ExampleOhosTest.java b/ComponentCodelab/checkbox/src/ohosTest/java/com/huawei/checkbox/ExampleOhosTest.java new file mode 100644 index 0000000000000000000000000000000000000000..ab47c2879b37ff00ced7d3768dc05de22c5af3e1 --- /dev/null +++ b/ComponentCodelab/checkbox/src/ohosTest/java/com/huawei/checkbox/ExampleOhosTest.java @@ -0,0 +1,14 @@ +package com.huawei.checkbox; + +import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class ExampleOhosTest { + @Test + public void testBundleName() { + final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName(); + assertEquals("com.huawei.cookbook", actualBundleName); + } +} \ No newline at end of file diff --git a/ComponentCodelab/checkbox/src/test/java/com/huawei/checkbox/ExampleTest.java b/ComponentCodelab/checkbox/src/test/java/com/huawei/checkbox/ExampleTest.java new file mode 100644 index 0000000000000000000000000000000000000000..4f12b33f6e686a70c9ae7f67a9b85f61d91c6295 --- /dev/null +++ b/ComponentCodelab/checkbox/src/test/java/com/huawei/checkbox/ExampleTest.java @@ -0,0 +1,9 @@ +package com.huawei.checkbox; + +import org.junit.Test; + +public class ExampleTest { + @Test + public void onStart() { + } +} diff --git a/ComponentCodelab/datepicker/build.gradle b/ComponentCodelab/datepicker/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..66c5259e68ee219a7d0d65202c9543e0c36b6fc7 --- /dev/null +++ b/ComponentCodelab/datepicker/build.gradle @@ -0,0 +1,28 @@ +apply plugin: 'com.huawei.ohos.hap' +apply plugin: 'com.huawei.ohos.decctest' +//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#ZH-CN_TOPIC_0000001154985555__section1112183053510 +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 5 + } + buildTypes { + release { + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } + } + } + entryModules "entry" +} + +dependencies { + entryImplementation project(':entry') + implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) + testImplementation 'junit:junit:4.13' + ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100' +} +decc { + supportType = ['html', 'xml'] +} diff --git a/ComponentCodelab/datepicker/src/main/config.json b/ComponentCodelab/datepicker/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..bc0113ac3bc67e1d52f5c428399262c3b1fa1d45 --- /dev/null +++ b/ComponentCodelab/datepicker/src/main/config.json @@ -0,0 +1,37 @@ +{ + "app": { + "bundleName": "com.huawei.cookbook", + "vendor": "huawei", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.huawei.datepicker", + "name": ".MyApplication", + "mainAbility": "com.huawei.datepicker.MainAbility", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "datepicker", + "moduleType": "feature", + "installationFree": false + }, + "abilities": [ + { + "orientation": "unspecified", + "visible": true, + "name": "com.huawei.datepicker.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:datepicker_MainAbility", + "type": "page", + "launchType": "standard" + } + ] + } +} \ No newline at end of file diff --git a/ComponentCodelab/datepicker/src/main/java/com/huawei/datepicker/MainAbility.java b/ComponentCodelab/datepicker/src/main/java/com/huawei/datepicker/MainAbility.java new file mode 100644 index 0000000000000000000000000000000000000000..7e39468f76d55d3612f00837490ee3a341cbb49f --- /dev/null +++ b/ComponentCodelab/datepicker/src/main/java/com/huawei/datepicker/MainAbility.java @@ -0,0 +1,32 @@ +/* + * 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.huawei.datepicker; + +import com.huawei.datepicker.slice.MainAbilitySlice; + +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; + +/** + * MainAbility + */ +public class MainAbility extends Ability { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setMainRoute(MainAbilitySlice.class.getName()); + } +} diff --git a/ComponentCodelab/datepicker/src/main/java/com/huawei/datepicker/MyApplication.java b/ComponentCodelab/datepicker/src/main/java/com/huawei/datepicker/MyApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..a92005aa813b1d5234d519c66a546582615be89f --- /dev/null +++ b/ComponentCodelab/datepicker/src/main/java/com/huawei/datepicker/MyApplication.java @@ -0,0 +1,28 @@ +/* + * 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.huawei.datepicker; + +import ohos.aafwk.ability.AbilityPackage; + +/** + * MyApplication + */ +public class MyApplication extends AbilityPackage { + @Override + public void onInitialize() { + super.onInitialize(); + } +} diff --git a/ComponentCodelab/datepicker/src/main/java/com/huawei/datepicker/slice/MainAbilitySlice.java b/ComponentCodelab/datepicker/src/main/java/com/huawei/datepicker/slice/MainAbilitySlice.java new file mode 100644 index 0000000000000000000000000000000000000000..558ff3c446bfdc43c02c1db9f22b621447ca5ddd --- /dev/null +++ b/ComponentCodelab/datepicker/src/main/java/com/huawei/datepicker/slice/MainAbilitySlice.java @@ -0,0 +1,84 @@ +/* + * 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.huawei.datepicker.slice; + +import com.huawei.datepicker.ResourceTable; + +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import ohos.agp.components.DatePicker; +import ohos.agp.components.Text; + +import java.util.Locale; + +/** + * MainAbilitySlice + */ +public class MainAbilitySlice extends AbilitySlice { + private DatePicker datePicker; + private Text textDate; + + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_data_picker); + initComponent(); + initDate(); + setValueChangedListener(); + } + + /** + * 初始化组件 + */ + private void initComponent() { + datePicker = (DatePicker) findComponentById(ResourceTable.Id_date_pick); + textDate = (Text) findComponentById(ResourceTable.Id_text_date); + } + + /** + * 显示初始日期 + */ + private void initDate() { + int day = datePicker.getDayOfMonth(); + int month = datePicker.getMonth(); + int year = datePicker.getYear(); + textDate.setText(String.format(Locale.ROOT,"%02d/%02d/%4d", day, month, year)); + } + + /** + * 为DatePicker设置订阅事件 + */ + private void setValueChangedListener() { + datePicker.setValueChangedListener( + new DatePicker.ValueChangedListener() { + @Override + public void onValueChanged(DatePicker picker, int year, int monthOfYear, int dayOfMonth) { + textDate.setText(String.format(Locale.ROOT,"%02d/%02d/%4d", dayOfMonth, monthOfYear, year)); + } + } + ); + } + + @Override + public void onActive() { + super.onActive(); + } + + @Override + public void onForeground(Intent intent) { + super.onForeground(intent); + } +} diff --git a/ComponentCodelab/datepicker/src/main/resources/base/element/string.json b/ComponentCodelab/datepicker/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3b99fca8adc9686957358aafd93686084ad1edde --- /dev/null +++ b/ComponentCodelab/datepicker/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "datepicker_MainAbility", + "value": "datepicker_MainAbility" + }, + { + "name": "mainability_description", + "value": "Java_Empty Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "Hello World" + } + ] +} \ No newline at end of file diff --git a/ComponentCodelab/datepicker/src/main/resources/base/graphic/background_data_picker.xml b/ComponentCodelab/datepicker/src/main/resources/base/graphic/background_data_picker.xml new file mode 100644 index 0000000000000000000000000000000000000000..c0c0a3df480fa387a452b9c40ca191cc918a3fc0 --- /dev/null +++ b/ComponentCodelab/datepicker/src/main/resources/base/graphic/background_data_picker.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/ComponentCodelab/datepicker/src/main/resources/base/graphic/button_element.xml b/ComponentCodelab/datepicker/src/main/resources/base/graphic/button_element.xml new file mode 100644 index 0000000000000000000000000000000000000000..ba40e3d579b3ac51c820f26b13308cb50f04baca --- /dev/null +++ b/ComponentCodelab/datepicker/src/main/resources/base/graphic/button_element.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/ComponentCodelab/datepicker/src/main/resources/base/layout/data_picker.xml b/ComponentCodelab/datepicker/src/main/resources/base/layout/data_picker.xml new file mode 100644 index 0000000000000000000000000000000000000000..40026333351d3bcb49de242cb76f0bd6e128bf1b --- /dev/null +++ b/ComponentCodelab/datepicker/src/main/resources/base/layout/data_picker.xml @@ -0,0 +1,46 @@ + + + + + + + + + + \ No newline at end of file diff --git a/ComponentCodelab/datepicker/src/main/resources/base/media/icon.png b/ComponentCodelab/datepicker/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ComponentCodelab/datepicker/src/main/resources/base/media/icon.png differ diff --git a/ComponentCodelab/datepicker/src/main/resources/en/element/string.json b/ComponentCodelab/datepicker/src/main/resources/en/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..64a277db99b079970fbe0ba88da29aeb6cc2c438 --- /dev/null +++ b/ComponentCodelab/datepicker/src/main/resources/en/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "datepicker_MainAbility", + "value": "datepicker_MainAbility" + }, + { + "name": "mainability_description", + "value": "Java_Empty Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "Hello World" + } + ] +} diff --git a/ComponentCodelab/datepicker/src/main/resources/zh/element/string.json b/ComponentCodelab/datepicker/src/main/resources/zh/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..fb4cd1c6d973bd1a49a6ef98508165da548b7a5a --- /dev/null +++ b/ComponentCodelab/datepicker/src/main/resources/zh/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "datepicker_MainAbility", + "value": "datepicker_MainAbility" + }, + { + "name": "mainability_description", + "value": "Java_Empty Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "你好,世界" + } + ] +} \ No newline at end of file diff --git a/ComponentCodelab/datepicker/src/ohosTest/java/com/huawei/datepicker/ExampleOhosTest.java b/ComponentCodelab/datepicker/src/ohosTest/java/com/huawei/datepicker/ExampleOhosTest.java new file mode 100644 index 0000000000000000000000000000000000000000..d8585fb45da459f10a638bf9e2f151878fb1a470 --- /dev/null +++ b/ComponentCodelab/datepicker/src/ohosTest/java/com/huawei/datepicker/ExampleOhosTest.java @@ -0,0 +1,14 @@ +package com.huawei.datepicker; + +import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class ExampleOhosTest { + @Test + public void testBundleName() { + final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName(); + assertEquals("com.huawei.cookbook", actualBundleName); + } +} \ No newline at end of file diff --git a/ComponentCodelab/datepicker/src/test/java/com/huawei/datepicker/ExampleTest.java b/ComponentCodelab/datepicker/src/test/java/com/huawei/datepicker/ExampleTest.java new file mode 100644 index 0000000000000000000000000000000000000000..de0aaa73075899282b7d197e42eebb3fe6b09868 --- /dev/null +++ b/ComponentCodelab/datepicker/src/test/java/com/huawei/datepicker/ExampleTest.java @@ -0,0 +1,9 @@ +package com.huawei.datepicker; + +import org.junit.Test; + +public class ExampleTest { + @Test + public void onStart() { + } +} diff --git a/ComponentCodelab/dependentlayout/build.gradle b/ComponentCodelab/dependentlayout/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..66c5259e68ee219a7d0d65202c9543e0c36b6fc7 --- /dev/null +++ b/ComponentCodelab/dependentlayout/build.gradle @@ -0,0 +1,28 @@ +apply plugin: 'com.huawei.ohos.hap' +apply plugin: 'com.huawei.ohos.decctest' +//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#ZH-CN_TOPIC_0000001154985555__section1112183053510 +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 5 + } + buildTypes { + release { + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } + } + } + entryModules "entry" +} + +dependencies { + entryImplementation project(':entry') + implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) + testImplementation 'junit:junit:4.13' + ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100' +} +decc { + supportType = ['html', 'xml'] +} diff --git a/ComponentCodelab/dependentlayout/src/main/config.json b/ComponentCodelab/dependentlayout/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..f19d4927d5b6b99bf0b00838e6b322a9afaaedb5 --- /dev/null +++ b/ComponentCodelab/dependentlayout/src/main/config.json @@ -0,0 +1,37 @@ +{ + "app": { + "bundleName": "com.huawei.cookbook", + "vendor": "huawei", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.huawei.dependentlayout", + "name": ".MyApplication", + "mainAbility": "com.huawei.dependentlayout.MainAbility", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "dependentlayout", + "moduleType": "feature", + "installationFree": false + }, + "abilities": [ + { + "orientation": "unspecified", + "visible": true, + "name": "com.huawei.dependentlayout.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:dependentlayout_MainAbility", + "type": "page", + "launchType": "standard" + } + ] + } +} \ No newline at end of file diff --git a/ComponentCodelab/dependentlayout/src/main/java/com/huawei/dependentlayout/MainAbility.java b/ComponentCodelab/dependentlayout/src/main/java/com/huawei/dependentlayout/MainAbility.java new file mode 100644 index 0000000000000000000000000000000000000000..7bc4b663f8515efc4ce8416b866c4fceb31a3356 --- /dev/null +++ b/ComponentCodelab/dependentlayout/src/main/java/com/huawei/dependentlayout/MainAbility.java @@ -0,0 +1,32 @@ +/* + * 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.huawei.dependentlayout; + +import com.huawei.dependentlayout.slice.MainAbilitySlice; + +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; + +/** + * MainAbility + */ +public class MainAbility extends Ability { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setMainRoute(MainAbilitySlice.class.getName()); + } +} diff --git a/ComponentCodelab/dependentlayout/src/main/java/com/huawei/dependentlayout/MyApplication.java b/ComponentCodelab/dependentlayout/src/main/java/com/huawei/dependentlayout/MyApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..21916e6f9fde29deed6339f596ca566b8db97593 --- /dev/null +++ b/ComponentCodelab/dependentlayout/src/main/java/com/huawei/dependentlayout/MyApplication.java @@ -0,0 +1,28 @@ +/* + * 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.huawei.dependentlayout; + +import ohos.aafwk.ability.AbilityPackage; + +/** + * MainAbility + */ +public class MyApplication extends AbilityPackage { + @Override + public void onInitialize() { + super.onInitialize(); + } +} diff --git a/ComponentCodelab/dependentlayout/src/main/java/com/huawei/dependentlayout/slice/MainAbilitySlice.java b/ComponentCodelab/dependentlayout/src/main/java/com/huawei/dependentlayout/slice/MainAbilitySlice.java new file mode 100644 index 0000000000000000000000000000000000000000..ee1018b59410a5797d5d6805f949d5f58d94cfc1 --- /dev/null +++ b/ComponentCodelab/dependentlayout/src/main/java/com/huawei/dependentlayout/slice/MainAbilitySlice.java @@ -0,0 +1,42 @@ +/* + * 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.huawei.dependentlayout.slice; + +import com.huawei.dependentlayout.ResourceTable; + +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; + +/** + * MainAbilitySlice + */ +public class MainAbilitySlice extends AbilitySlice { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_dependent_layout); + } + + @Override + public void onActive() { + super.onActive(); + } + + @Override + public void onForeground(Intent intent) { + super.onForeground(intent); + } +} diff --git a/ComponentCodelab/dependentlayout/src/main/resources/base/element/string.json b/ComponentCodelab/dependentlayout/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..b0db557cd14605e5373d2c748af577de648f9a16 --- /dev/null +++ b/ComponentCodelab/dependentlayout/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "dependentlayout_MainAbility", + "value": "dependentlayout_MainAbility" + }, + { + "name": "mainability_description", + "value": "Java_Empty Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "Hello World" + } + ] +} \ No newline at end of file diff --git a/ComponentCodelab/dependentlayout/src/main/resources/base/graphic/background_dependent_layout.xml b/ComponentCodelab/dependentlayout/src/main/resources/base/graphic/background_dependent_layout.xml new file mode 100644 index 0000000000000000000000000000000000000000..c0c0a3df480fa387a452b9c40ca191cc918a3fc0 --- /dev/null +++ b/ComponentCodelab/dependentlayout/src/main/resources/base/graphic/background_dependent_layout.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/ComponentCodelab/dependentlayout/src/main/resources/base/graphic/corner_bg_comment.xml b/ComponentCodelab/dependentlayout/src/main/resources/base/graphic/corner_bg_comment.xml new file mode 100644 index 0000000000000000000000000000000000000000..149c407f0e705a4b7e0814d5cd2b0030c419da09 --- /dev/null +++ b/ComponentCodelab/dependentlayout/src/main/resources/base/graphic/corner_bg_comment.xml @@ -0,0 +1,8 @@ + + + + + diff --git a/ComponentCodelab/dependentlayout/src/main/resources/base/layout/dependent_layout.xml b/ComponentCodelab/dependentlayout/src/main/resources/base/layout/dependent_layout.xml new file mode 100644 index 0000000000000000000000000000000000000000..791341b0ee5faca6af1475a6291f567c2823d472 --- /dev/null +++ b/ComponentCodelab/dependentlayout/src/main/resources/base/layout/dependent_layout.xml @@ -0,0 +1,154 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ComponentCodelab/dependentlayout/src/main/resources/base/media/collect_icon.jpg b/ComponentCodelab/dependentlayout/src/main/resources/base/media/collect_icon.jpg new file mode 100644 index 0000000000000000000000000000000000000000..cb4f79918a73b6510056d372ee296a160140234d Binary files /dev/null and b/ComponentCodelab/dependentlayout/src/main/resources/base/media/collect_icon.jpg differ diff --git a/ComponentCodelab/dependentlayout/src/main/resources/base/media/icon.png b/ComponentCodelab/dependentlayout/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ComponentCodelab/dependentlayout/src/main/resources/base/media/icon.png differ diff --git a/ComponentCodelab/dependentlayout/src/main/resources/base/media/like_icon.jpg b/ComponentCodelab/dependentlayout/src/main/resources/base/media/like_icon.jpg new file mode 100644 index 0000000000000000000000000000000000000000..2e996085da24a1f59ad80ea8375c36caf1a5bfe3 Binary files /dev/null and b/ComponentCodelab/dependentlayout/src/main/resources/base/media/like_icon.jpg differ diff --git a/ComponentCodelab/dependentlayout/src/main/resources/base/media/message_icon.jpg b/ComponentCodelab/dependentlayout/src/main/resources/base/media/message_icon.jpg new file mode 100644 index 0000000000000000000000000000000000000000..2ce75607ff5fb9754b3536c0d7bb8212bc19379f Binary files /dev/null and b/ComponentCodelab/dependentlayout/src/main/resources/base/media/message_icon.jpg differ diff --git a/ComponentCodelab/dependentlayout/src/main/resources/base/media/news_image.jpg b/ComponentCodelab/dependentlayout/src/main/resources/base/media/news_image.jpg new file mode 100644 index 0000000000000000000000000000000000000000..e58a289f7d136043766f33f168a87af367c370f3 Binary files /dev/null and b/ComponentCodelab/dependentlayout/src/main/resources/base/media/news_image.jpg differ diff --git a/ComponentCodelab/dependentlayout/src/main/resources/base/media/news_image_left.jpg b/ComponentCodelab/dependentlayout/src/main/resources/base/media/news_image_left.jpg new file mode 100644 index 0000000000000000000000000000000000000000..b349d81e1dce2d2a553baaf26a5b7fde58d8beac Binary files /dev/null and b/ComponentCodelab/dependentlayout/src/main/resources/base/media/news_image_left.jpg differ diff --git a/ComponentCodelab/dependentlayout/src/main/resources/base/media/news_image_right.jpg b/ComponentCodelab/dependentlayout/src/main/resources/base/media/news_image_right.jpg new file mode 100644 index 0000000000000000000000000000000000000000..e3d1ca269b529e890a3e154ac081e93487f5743b Binary files /dev/null and b/ComponentCodelab/dependentlayout/src/main/resources/base/media/news_image_right.jpg differ diff --git a/ComponentCodelab/dependentlayout/src/main/resources/base/media/share_icon.jpg b/ComponentCodelab/dependentlayout/src/main/resources/base/media/share_icon.jpg new file mode 100644 index 0000000000000000000000000000000000000000..f16c17cfe8f38bf5b947b61299fbec3c2405de8d Binary files /dev/null and b/ComponentCodelab/dependentlayout/src/main/resources/base/media/share_icon.jpg differ diff --git a/ComponentCodelab/dependentlayout/src/main/resources/en/element/string.json b/ComponentCodelab/dependentlayout/src/main/resources/en/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..162653497f3a1dfa196d67fcb16d0a3b797e4486 --- /dev/null +++ b/ComponentCodelab/dependentlayout/src/main/resources/en/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "dependentlayout_MainAbility", + "value": "dependentlayout_MainAbility" + }, + { + "name": "mainability_description", + "value": "Java_Empty Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "Hello World" + } + ] +} diff --git a/ComponentCodelab/dependentlayout/src/main/resources/zh/element/string.json b/ComponentCodelab/dependentlayout/src/main/resources/zh/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..698146d40955f5b10c4474b2b31bfba929c1e30d --- /dev/null +++ b/ComponentCodelab/dependentlayout/src/main/resources/zh/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "dependentlayout_MainAbility", + "value": "dependentlayout_MainAbility" + }, + { + "name": "mainability_description", + "value": "Java_Empty Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "你好,世界" + } + ] +} \ No newline at end of file diff --git a/ComponentCodelab/dependentlayout/src/ohosTest/java/com/huawei/dependentlayout/ExampleOhosTest.java b/ComponentCodelab/dependentlayout/src/ohosTest/java/com/huawei/dependentlayout/ExampleOhosTest.java new file mode 100644 index 0000000000000000000000000000000000000000..435a3a73cfb2bfe357b98a10b9bcf0cf49c75a12 --- /dev/null +++ b/ComponentCodelab/dependentlayout/src/ohosTest/java/com/huawei/dependentlayout/ExampleOhosTest.java @@ -0,0 +1,14 @@ +package com.huawei.dependentlayout; + +import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class ExampleOhosTest { + @Test + public void testBundleName() { + final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName(); + assertEquals("com.huawei.cookbook", actualBundleName); + } +} \ No newline at end of file diff --git a/ComponentCodelab/dependentlayout/src/test/java/com/huawei/dependentlayout/ExampleTest.java b/ComponentCodelab/dependentlayout/src/test/java/com/huawei/dependentlayout/ExampleTest.java new file mode 100644 index 0000000000000000000000000000000000000000..1368d9ec8fa808aae6bd242f4defa9624618641d --- /dev/null +++ b/ComponentCodelab/dependentlayout/src/test/java/com/huawei/dependentlayout/ExampleTest.java @@ -0,0 +1,9 @@ +package com.huawei.dependentlayout; + +import org.junit.Test; + +public class ExampleTest { + @Test + public void onStart() { + } +} diff --git a/ComponentCodelab/directionallayout/build.gradle b/ComponentCodelab/directionallayout/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..66c5259e68ee219a7d0d65202c9543e0c36b6fc7 --- /dev/null +++ b/ComponentCodelab/directionallayout/build.gradle @@ -0,0 +1,28 @@ +apply plugin: 'com.huawei.ohos.hap' +apply plugin: 'com.huawei.ohos.decctest' +//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#ZH-CN_TOPIC_0000001154985555__section1112183053510 +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 5 + } + buildTypes { + release { + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } + } + } + entryModules "entry" +} + +dependencies { + entryImplementation project(':entry') + implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) + testImplementation 'junit:junit:4.13' + ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100' +} +decc { + supportType = ['html', 'xml'] +} diff --git a/ComponentCodelab/directionallayout/src/main/config.json b/ComponentCodelab/directionallayout/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..31b6ce4a42af7b95915d22e40b9d2e448dffe526 --- /dev/null +++ b/ComponentCodelab/directionallayout/src/main/config.json @@ -0,0 +1,37 @@ +{ + "app": { + "bundleName": "com.huawei.cookbook", + "vendor": "huawei", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.huawei.directionallayout", + "name": ".MyApplication", + "mainAbility": "com.huawei.directionallayout.MainAbility", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "directionallayout", + "moduleType": "feature", + "installationFree": false + }, + "abilities": [ + { + "orientation": "unspecified", + "visible": true, + "name": "com.huawei.directionallayout.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:directionallayout_MainAbility", + "type": "page", + "launchType": "standard" + } + ] + } +} \ No newline at end of file diff --git a/ComponentCodelab/directionallayout/src/main/java/com/huawei/directionallayout/MainAbility.java b/ComponentCodelab/directionallayout/src/main/java/com/huawei/directionallayout/MainAbility.java new file mode 100644 index 0000000000000000000000000000000000000000..79134d24908ffccaadf11dda56439ba006d287ef --- /dev/null +++ b/ComponentCodelab/directionallayout/src/main/java/com/huawei/directionallayout/MainAbility.java @@ -0,0 +1,32 @@ +/* + * 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.huawei.directionallayout; + +import com.huawei.directionallayout.slice.MainAbilitySlice; + +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; + +/** + * MainAbility + */ +public class MainAbility extends Ability { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setMainRoute(MainAbilitySlice.class.getName()); + } +} diff --git a/ComponentCodelab/directionallayout/src/main/java/com/huawei/directionallayout/MyApplication.java b/ComponentCodelab/directionallayout/src/main/java/com/huawei/directionallayout/MyApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..540c56bf5041d103cc81f7e2df85cb47972f6feb --- /dev/null +++ b/ComponentCodelab/directionallayout/src/main/java/com/huawei/directionallayout/MyApplication.java @@ -0,0 +1,28 @@ +/* + * 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.huawei.directionallayout; + +import ohos.aafwk.ability.AbilityPackage; + +/** + * MyApplication + */ +public class MyApplication extends AbilityPackage { + @Override + public void onInitialize() { + super.onInitialize(); + } +} diff --git a/ComponentCodelab/directionallayout/src/main/java/com/huawei/directionallayout/slice/MainAbilitySlice.java b/ComponentCodelab/directionallayout/src/main/java/com/huawei/directionallayout/slice/MainAbilitySlice.java new file mode 100644 index 0000000000000000000000000000000000000000..79492fcb21790a79ebd60e892402dd7beb63c1a8 --- /dev/null +++ b/ComponentCodelab/directionallayout/src/main/java/com/huawei/directionallayout/slice/MainAbilitySlice.java @@ -0,0 +1,42 @@ +/* + * 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.huawei.directionallayout.slice; + +import com.huawei.directionallayout.ResourceTable; + +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; + +/** + * MainAbilitySlice + */ +public class MainAbilitySlice extends AbilitySlice { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_directional_layout); + } + + @Override + public void onActive() { + super.onActive(); + } + + @Override + public void onForeground(Intent intent) { + super.onForeground(intent); + } +} diff --git a/ComponentCodelab/directionallayout/src/main/resources/base/element/string.json b/ComponentCodelab/directionallayout/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..045a58f52468354d6fc0fc8bbc270d056b4a274c --- /dev/null +++ b/ComponentCodelab/directionallayout/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "directionallayout_MainAbility", + "value": "directionallayout_MainAbility" + }, + { + "name": "mainability_description", + "value": "Java_Empty Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "Hello World" + } + ] +} \ No newline at end of file diff --git a/ComponentCodelab/directionallayout/src/main/resources/base/graphic/background_directional_layout.xml b/ComponentCodelab/directionallayout/src/main/resources/base/graphic/background_directional_layout.xml new file mode 100644 index 0000000000000000000000000000000000000000..c0c0a3df480fa387a452b9c40ca191cc918a3fc0 --- /dev/null +++ b/ComponentCodelab/directionallayout/src/main/resources/base/graphic/background_directional_layout.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/ComponentCodelab/directionallayout/src/main/resources/base/layout/directional_layout.xml b/ComponentCodelab/directionallayout/src/main/resources/base/layout/directional_layout.xml new file mode 100644 index 0000000000000000000000000000000000000000..c6193961a6aad4559d8be53554116e8f3e9a11a9 --- /dev/null +++ b/ComponentCodelab/directionallayout/src/main/resources/base/layout/directional_layout.xml @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ComponentCodelab/directionallayout/src/main/resources/base/media/icon.png b/ComponentCodelab/directionallayout/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ComponentCodelab/directionallayout/src/main/resources/base/media/icon.png differ diff --git a/ComponentCodelab/directionallayout/src/main/resources/en/element/string.json b/ComponentCodelab/directionallayout/src/main/resources/en/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..20cce785d158a96bbe6cef0e1e11e1b5339afb86 --- /dev/null +++ b/ComponentCodelab/directionallayout/src/main/resources/en/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "directionallayout_MainAbility", + "value": "directionallayout_MainAbility" + }, + { + "name": "mainability_description", + "value": "Java_Empty Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "Hello World" + } + ] +} diff --git a/ComponentCodelab/directionallayout/src/main/resources/zh/element/string.json b/ComponentCodelab/directionallayout/src/main/resources/zh/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f08a5c2a80ae68f2b453d885cfe61ac6e6ca47bf --- /dev/null +++ b/ComponentCodelab/directionallayout/src/main/resources/zh/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "directionallayout_MainAbility", + "value": "directionallayout_MainAbility" + }, + { + "name": "mainability_description", + "value": "Java_Empty Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "你好,世界" + } + ] +} \ No newline at end of file diff --git a/ComponentCodelab/directionallayout/src/ohosTest/java/com/huawei/directionallayout/ExampleOhosTest.java b/ComponentCodelab/directionallayout/src/ohosTest/java/com/huawei/directionallayout/ExampleOhosTest.java new file mode 100644 index 0000000000000000000000000000000000000000..ae57c4590071fb8ba305d3f1f31fd551da26d3d3 --- /dev/null +++ b/ComponentCodelab/directionallayout/src/ohosTest/java/com/huawei/directionallayout/ExampleOhosTest.java @@ -0,0 +1,14 @@ +package com.huawei.directionallayout; + +import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class ExampleOhosTest { + @Test + public void testBundleName() { + final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName(); + assertEquals("com.huawei.cookbook", actualBundleName); + } +} \ No newline at end of file diff --git a/ComponentCodelab/directionallayout/src/test/java/com/huawei/directionallayout/ExampleTest.java b/ComponentCodelab/directionallayout/src/test/java/com/huawei/directionallayout/ExampleTest.java new file mode 100644 index 0000000000000000000000000000000000000000..cb05dc7f86c813e4e310230cc47b03620ee7bd0d --- /dev/null +++ b/ComponentCodelab/directionallayout/src/test/java/com/huawei/directionallayout/ExampleTest.java @@ -0,0 +1,9 @@ +package com.huawei.directionallayout; + +import org.junit.Test; + +public class ExampleTest { + @Test + public void onStart() { + } +} diff --git a/ComponentCodelab/entry/build.gradle b/ComponentCodelab/entry/build.gradle index 95059698209dd4e70219f28daef063de0a9cde67..3de012e16603dcf2842c83db5963598cb4b98ccf 100644 --- a/ComponentCodelab/entry/build.gradle +++ b/ComponentCodelab/entry/build.gradle @@ -21,5 +21,5 @@ dependencies { ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100' } decc { - supportType = ['html','xml'] + supportType = ['html', 'xml'] } diff --git a/ComponentCodelab/entry/src/main/config.json b/ComponentCodelab/entry/src/main/config.json index d1bb29108aec2e5a86f814e26ce20321b3ddeefe..3637208a18436fb4e56296e93477650eba8f7570 100644 --- a/ComponentCodelab/entry/src/main/config.json +++ b/ComponentCodelab/entry/src/main/config.json @@ -1,10 +1,10 @@ { "app": { - "bundleName": "com.huawei.codelab", + "bundleName": "com.huawei.cookbook", "vendor": "huawei", "version": { - "code": 1, - "name": "1.0" + "code": 1000000, + "name": "1.0.0" }, "apiVersion": { "compatible": 4, diff --git a/ComponentCodelab/listcontainer/build.gradle b/ComponentCodelab/listcontainer/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..66c5259e68ee219a7d0d65202c9543e0c36b6fc7 --- /dev/null +++ b/ComponentCodelab/listcontainer/build.gradle @@ -0,0 +1,28 @@ +apply plugin: 'com.huawei.ohos.hap' +apply plugin: 'com.huawei.ohos.decctest' +//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#ZH-CN_TOPIC_0000001154985555__section1112183053510 +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 5 + } + buildTypes { + release { + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } + } + } + entryModules "entry" +} + +dependencies { + entryImplementation project(':entry') + implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) + testImplementation 'junit:junit:4.13' + ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100' +} +decc { + supportType = ['html', 'xml'] +} diff --git a/ComponentCodelab/listcontainer/src/main/config.json b/ComponentCodelab/listcontainer/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..8e5f1a44c0cc1fe35853857a97c248d5a77b5bf6 --- /dev/null +++ b/ComponentCodelab/listcontainer/src/main/config.json @@ -0,0 +1,37 @@ +{ + "app": { + "bundleName": "com.huawei.cookbook", + "vendor": "huawei", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.huawei.cookbook", + "name": ".MyApplication", + "mainAbility": "com.huawei.cookbook.MainAbility", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "listcontainer", + "moduleType": "feature", + "installationFree": false + }, + "abilities": [ + { + "orientation": "unspecified", + "visible": true, + "name": "com.huawei.cookbook.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:listcontainer_MainAbility", + "type": "page", + "launchType": "standard" + } + ] + } +} \ No newline at end of file diff --git a/ComponentCodelab/listcontainer/src/main/java/com/huawei/cookbook/MainAbility.java b/ComponentCodelab/listcontainer/src/main/java/com/huawei/cookbook/MainAbility.java new file mode 100644 index 0000000000000000000000000000000000000000..3477ad424ff324ea1ef1d1c63ddbb5608dd0edd0 --- /dev/null +++ b/ComponentCodelab/listcontainer/src/main/java/com/huawei/cookbook/MainAbility.java @@ -0,0 +1,32 @@ +/* + * 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.huawei.cookbook; + +import com.huawei.cookbook.slice.MainAbilitySlice; + +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; + +/** + * MainAbility + */ +public class MainAbility extends Ability { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setMainRoute(MainAbilitySlice.class.getName()); + } +} diff --git a/ComponentCodelab/listcontainer/src/main/java/com/huawei/cookbook/MyApplication.java b/ComponentCodelab/listcontainer/src/main/java/com/huawei/cookbook/MyApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..aa0b392778678cba23371d003255bb05c1d64931 --- /dev/null +++ b/ComponentCodelab/listcontainer/src/main/java/com/huawei/cookbook/MyApplication.java @@ -0,0 +1,28 @@ +/* + * 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.huawei.cookbook; + +import ohos.aafwk.ability.AbilityPackage; + +/** + * MyApplication + */ +public class MyApplication extends AbilityPackage { + @Override + public void onInitialize() { + super.onInitialize(); + } +} diff --git a/ComponentCodelab/listcontainer/src/main/java/com/huawei/cookbook/provider/NewsInfo.java b/ComponentCodelab/listcontainer/src/main/java/com/huawei/cookbook/provider/NewsInfo.java new file mode 100644 index 0000000000000000000000000000000000000000..82d629b3acf51fa857b3cfc3e31801a46fa0be4c --- /dev/null +++ b/ComponentCodelab/listcontainer/src/main/java/com/huawei/cookbook/provider/NewsInfo.java @@ -0,0 +1,40 @@ +/* + * 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.huawei.cookbook.provider; + +/** + * NewsInfo 新闻实体 + */ +public class NewsInfo { + private String title; + private String type; + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } +} diff --git a/ComponentCodelab/listcontainer/src/main/java/com/huawei/cookbook/provider/NewsListProvider.java b/ComponentCodelab/listcontainer/src/main/java/com/huawei/cookbook/provider/NewsListProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..8226c2142ba50b26148ee26d1ea5411cdfe5fbe6 --- /dev/null +++ b/ComponentCodelab/listcontainer/src/main/java/com/huawei/cookbook/provider/NewsListProvider.java @@ -0,0 +1,98 @@ +/* + * 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.huawei.cookbook.provider; + +import com.huawei.cookbook.ResourceTable; + +import ohos.agp.components.BaseItemProvider; +import ohos.agp.components.Component; +import ohos.agp.components.ComponentContainer; +import ohos.agp.components.Image; +import ohos.agp.components.LayoutScatter; +import ohos.agp.components.Text; +import ohos.app.Context; + +import java.util.List; +import java.util.Optional; + +/** + * NewsListProvider + */ +public class NewsListProvider extends BaseItemProvider { + private List newsInfoList; + private Context context; + + /** + * 有参构造 + * @param listBasicInfo 新闻信息集合 + * @param context context + */ + public NewsListProvider(List listBasicInfo, Context context) { + this.newsInfoList = listBasicInfo; + this.context = context; + } + + @Override + public int getCount() { + return newsInfoList == null ? 0 : newsInfoList.size(); + } + + @Override + public Object getItem(int position) { + return Optional.of(this.newsInfoList.get(position)); + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public Component getComponent(int position, Component componentP, ComponentContainer componentContainer) { + ViewHolder viewHolder = null; + Component component = componentP; + if (component == null) { + component = LayoutScatter.getInstance(context).parse(ResourceTable.Layout_item_news_layout, null, false); + viewHolder = new ViewHolder(); + Component componentTitle = component.findComponentById(ResourceTable.Id_item_news_title); + Component componentImage = component.findComponentById(ResourceTable.Id_item_news_image); + if (componentTitle instanceof Text) { + viewHolder.title = (Text) componentTitle; + } + if (componentImage instanceof Image) { + viewHolder.image = (Image) componentImage; + } + component.setTag(viewHolder); + } else { + if (component.getTag() instanceof ViewHolder) { + viewHolder = (ViewHolder) component.getTag(); + } + } + if (viewHolder != null) { + viewHolder.title.setText(newsInfoList.get(position).getTitle()); + viewHolder.image.setScaleMode(Image.ScaleMode.STRETCH); + } + return component; + } + + /** + * 显示内容 + */ + private static class ViewHolder { + Text title; + Image image; + } +} diff --git a/ComponentCodelab/listcontainer/src/main/java/com/huawei/cookbook/provider/NewsTypeProvider.java b/ComponentCodelab/listcontainer/src/main/java/com/huawei/cookbook/provider/NewsTypeProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..2bc745cf059299b0632fbb781be71dd9ecfa59c6 --- /dev/null +++ b/ComponentCodelab/listcontainer/src/main/java/com/huawei/cookbook/provider/NewsTypeProvider.java @@ -0,0 +1,91 @@ +/* + * 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.huawei.cookbook.provider; + +import com.huawei.cookbook.ResourceTable; + +import ohos.agp.components.BaseItemProvider; +import ohos.agp.components.Component; +import ohos.agp.components.ComponentContainer; +import ohos.agp.components.LayoutScatter; +import ohos.agp.components.Text; +import ohos.app.Context; + +import java.util.Optional; + +/** + * NewsTypeProvider + */ +public class NewsTypeProvider extends BaseItemProvider { + private String[] newsTypeLists; + private Context context; + + /** + * 有参构造 + * @param listBasicInfo 新闻类型集合 + * @param context context + */ + public NewsTypeProvider(String[] listBasicInfo, Context context) { + this.newsTypeLists = listBasicInfo; + this.context = context; + } + + @Override + public int getCount() { + return newsTypeLists == null ? 0 : newsTypeLists.length; + } + + @Override + public Object getItem(int position) { + return Optional.of(this.newsTypeLists[position]); + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public Component getComponent(int position, Component componentP, ComponentContainer componentContainer) { + ViewHolder viewHolder = null; + Component component = componentP; + if (component == null) { + component = LayoutScatter.getInstance(context).parse(ResourceTable.Layout_item_news_type_layout, + null, false); + viewHolder = new ViewHolder(); + Component componentText = component.findComponentById(ResourceTable.Id_news_type_text); + if (componentText instanceof Text) { + viewHolder.title = (Text) componentText; + } + component.setTag(viewHolder); + } else { + if (component.getTag() instanceof ViewHolder) { + viewHolder = (ViewHolder) component.getTag(); + } + } + if (viewHolder != null) { + viewHolder.title.setText(newsTypeLists[position]); + } + return component; + } + + /** + * 显示内容 + */ + private static class ViewHolder { + Text title; + } +} diff --git a/ComponentCodelab/listcontainer/src/main/java/com/huawei/cookbook/slice/MainAbilitySlice.java b/ComponentCodelab/listcontainer/src/main/java/com/huawei/cookbook/slice/MainAbilitySlice.java new file mode 100644 index 0000000000000000000000000000000000000000..25b7d78a00544adba64d639528691155ced9981b --- /dev/null +++ b/ComponentCodelab/listcontainer/src/main/java/com/huawei/cookbook/slice/MainAbilitySlice.java @@ -0,0 +1,168 @@ +/* + * 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.huawei.cookbook.slice; + +import com.huawei.cookbook.ResourceTable; +import com.huawei.cookbook.provider.NewsInfo; +import com.huawei.cookbook.provider.NewsListProvider; +import com.huawei.cookbook.provider.NewsTypeProvider; + +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import ohos.agp.components.Component; +import ohos.agp.components.ListContainer; +import ohos.agp.components.Text; +import ohos.agp.utils.Color; + +import java.util.ArrayList; +import java.util.List; + +/** + * MainAbilitySlice + */ +public class MainAbilitySlice extends AbilitySlice { + private static final float FOCUS_TEXT_SIZE = 1.2f; + private static final float UNFOCUS_TEXT_SIZE = 1.0f; + private Text selectText; + private ListContainer newsListContainer; + private ListContainer selectorListContainer; + private List totalNews; + private List selectNews; + private NewsTypeProvider newsTypeProvider; + private NewsListProvider newsListProvider; + + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_news_list_layout); + initView(); + initProvider(); + setListContainer(); + initListener(); + } + + private void initView() { + selectorListContainer = (ListContainer) findComponentById(ResourceTable.Id_selector_list); + newsListContainer = (ListContainer) findComponentById(ResourceTable.Id_news_container); + } + + /** + * 初始化Provider + */ + private void initProvider() { + String[] listNames = new String[]{"All", "Health", "Finance", "Technology", "Sport", "Internet", "Game"}; + newsTypeProvider = new NewsTypeProvider(listNames, this); + newsTypeProvider.notifyDataChanged(); + + String[] newsTypes = new String[]{"Health", "Finance", "Finance", "Technology", "Sport", + "Health", "Internet", "Game", "Game", "Internet"}; + String[] newsTitles = new String[]{ + "Best Enterprise Wi-Fi Network Award of the Wireless Broadband Alliance 2020", + "Openness and Cooperation Facilitate Industry Upgrade", + "High-voltage super-fast charging is an inevitable trend", + "Ten Future Trends of Digital Energy", + "Ascend Helps Industry, Learning, and Research Promote AI Industry " + + "Development in the National AI Contest", + "Enterprise data centers are moving towards autonomous driving network", + "One optical fiber lights up a green smart room", + "Trust technology, embrace openness, and share the world prosperity brought by technology", + "Intelligent Twins Won the Leading Technology Achievement Award at the 7th World Internet Conference", + "Maximizing the Value of Wireless Networks and Ushering in the Golden Decade of 5G" + }; + totalNews = new ArrayList<>(); + selectNews = new ArrayList<>(); + for (int i = 0; i < newsTypes.length; i++) { + NewsInfo newsInfo = new NewsInfo(); + newsInfo.setTitle(newsTitles[i]); + newsInfo.setType(newsTypes[i]); + totalNews.add(newsInfo); + } + selectNews.addAll(totalNews); + newsListProvider = new NewsListProvider(selectNews, this); + newsListProvider.notifyDataChanged(); + } + + /** + * 将Provider应用到ListContainer + */ + private void setListContainer() { + selectorListContainer.setItemProvider(newsTypeProvider); + newsListContainer.setItemProvider(newsListProvider); + } + + /** + * 为ListContainer绑定点击事件 + */ + private void initListener() { + selectorListContainer.setItemClickedListener((listContainer, component, position, listener) -> { + setCategorizationFocus(false); + Component newsTypeText = component.findComponentById(ResourceTable.Id_news_type_text); + if (newsTypeText instanceof Text) { + selectText = (Text) newsTypeText; + } + setCategorizationFocus(true); + selectNews.clear(); + if (position == 0) { + selectNews.addAll(totalNews); + } else { + setNewsData(); + } + updateListView(); + }); + selectorListContainer.setSelected(true); + selectorListContainer.setSelectedItemIndex(0); + } + + private void setNewsData() { + String newsType = selectText.getText(); + for (NewsInfo newsData : totalNews) { + if (newsType.equals(newsData.getType())) { + selectNews.add(newsData); + } + } + } + + private void setCategorizationFocus(boolean isFocus) { + if (selectText == null) { + return; + } + if (isFocus) { + selectText.setTextColor(new Color(Color.getIntColor("#afaafa"))); + selectText.setScaleX(FOCUS_TEXT_SIZE); + selectText.setScaleY(FOCUS_TEXT_SIZE); + } else { + selectText.setTextColor(new Color(Color.getIntColor("#999999"))); + selectText.setScaleX(UNFOCUS_TEXT_SIZE); + selectText.setScaleY(UNFOCUS_TEXT_SIZE); + } + } + + private void updateListView() { + newsListProvider.notifyDataChanged(); + newsListContainer.invalidate(); + newsListContainer.scrollToCenter(0); + } + + @Override + public void onActive() { + super.onActive(); + } + + @Override + public void onForeground(Intent intent) { + super.onForeground(intent); + } +} diff --git a/ComponentCodelab/listcontainer/src/main/resources/base/element/string.json b/ComponentCodelab/listcontainer/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..4e9487fa5db75398e0140f8cba1554a3444d3072 --- /dev/null +++ b/ComponentCodelab/listcontainer/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "listcontainer_MainAbility", + "value": "listcontainer_MainAbility" + }, + { + "name": "mainability_description", + "value": "Java_Empty Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "Hello World" + } + ] +} \ No newline at end of file diff --git a/ComponentCodelab/listcontainer/src/main/resources/base/graphic/background_ability_main.xml b/ComponentCodelab/listcontainer/src/main/resources/base/graphic/background_ability_main.xml new file mode 100644 index 0000000000000000000000000000000000000000..c0c0a3df480fa387a452b9c40ca191cc918a3fc0 --- /dev/null +++ b/ComponentCodelab/listcontainer/src/main/resources/base/graphic/background_ability_main.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/ComponentCodelab/listcontainer/src/main/resources/base/layout/item_news_layout.xml b/ComponentCodelab/listcontainer/src/main/resources/base/layout/item_news_layout.xml new file mode 100644 index 0000000000000000000000000000000000000000..f7205704f3de0d1498c165d7d2e7493851201d93 --- /dev/null +++ b/ComponentCodelab/listcontainer/src/main/resources/base/layout/item_news_layout.xml @@ -0,0 +1,32 @@ + + + + + + + + \ No newline at end of file diff --git a/ComponentCodelab/listcontainer/src/main/resources/base/layout/item_news_type_layout.xml b/ComponentCodelab/listcontainer/src/main/resources/base/layout/item_news_type_layout.xml new file mode 100644 index 0000000000000000000000000000000000000000..350b339dbb7efc80093d87128f86be4cfa07fb90 --- /dev/null +++ b/ComponentCodelab/listcontainer/src/main/resources/base/layout/item_news_type_layout.xml @@ -0,0 +1,15 @@ + + + + \ No newline at end of file diff --git a/ComponentCodelab/listcontainer/src/main/resources/base/layout/news_list_layout.xml b/ComponentCodelab/listcontainer/src/main/resources/base/layout/news_list_layout.xml new file mode 100644 index 0000000000000000000000000000000000000000..928af1d001f9d8b55227ec003b513b316a6addb3 --- /dev/null +++ b/ComponentCodelab/listcontainer/src/main/resources/base/layout/news_list_layout.xml @@ -0,0 +1,21 @@ + + + + + + \ No newline at end of file diff --git a/ComponentCodelab/listcontainer/src/main/resources/base/media/icon.png b/ComponentCodelab/listcontainer/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ComponentCodelab/listcontainer/src/main/resources/base/media/icon.png differ diff --git a/ComponentCodelab/listcontainer/src/main/resources/base/media/news_image.jpg b/ComponentCodelab/listcontainer/src/main/resources/base/media/news_image.jpg new file mode 100644 index 0000000000000000000000000000000000000000..e58a289f7d136043766f33f168a87af367c370f3 Binary files /dev/null and b/ComponentCodelab/listcontainer/src/main/resources/base/media/news_image.jpg differ diff --git a/ComponentCodelab/listcontainer/src/main/resources/base/media/news_image_left.jpg b/ComponentCodelab/listcontainer/src/main/resources/base/media/news_image_left.jpg new file mode 100644 index 0000000000000000000000000000000000000000..b349d81e1dce2d2a553baaf26a5b7fde58d8beac Binary files /dev/null and b/ComponentCodelab/listcontainer/src/main/resources/base/media/news_image_left.jpg differ diff --git a/ComponentCodelab/listcontainer/src/main/resources/base/media/news_image_right.jpg b/ComponentCodelab/listcontainer/src/main/resources/base/media/news_image_right.jpg new file mode 100644 index 0000000000000000000000000000000000000000..e3d1ca269b529e890a3e154ac081e93487f5743b Binary files /dev/null and b/ComponentCodelab/listcontainer/src/main/resources/base/media/news_image_right.jpg differ diff --git a/ComponentCodelab/listcontainer/src/main/resources/en/element/string.json b/ComponentCodelab/listcontainer/src/main/resources/en/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..d176a22b64fd09e892cb72e8187c71939cbeef77 --- /dev/null +++ b/ComponentCodelab/listcontainer/src/main/resources/en/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "listcontainer_MainAbility", + "value": "listcontainer_MainAbility" + }, + { + "name": "mainability_description", + "value": "Java_Empty Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "Hello World" + } + ] +} diff --git a/ComponentCodelab/listcontainer/src/main/resources/zh/element/string.json b/ComponentCodelab/listcontainer/src/main/resources/zh/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..278ff0d145d535b1241ec284da2e47e064affe4d --- /dev/null +++ b/ComponentCodelab/listcontainer/src/main/resources/zh/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "listcontainer_MainAbility", + "value": "listcontainer_MainAbility" + }, + { + "name": "mainability_description", + "value": "Java_Empty Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "你好,世界" + } + ] +} \ No newline at end of file diff --git a/ComponentCodelab/listcontainer/src/ohosTest/java/com/huawei/cookbook/ExampleOhosTest.java b/ComponentCodelab/listcontainer/src/ohosTest/java/com/huawei/cookbook/ExampleOhosTest.java new file mode 100644 index 0000000000000000000000000000000000000000..bf27899ae844b18c931cc6c9841267cbdb2c717c --- /dev/null +++ b/ComponentCodelab/listcontainer/src/ohosTest/java/com/huawei/cookbook/ExampleOhosTest.java @@ -0,0 +1,14 @@ +package com.huawei.cookbook; + +import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class ExampleOhosTest { + @Test + public void testBundleName() { + final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName(); + assertEquals("com.huawei.cookbook", actualBundleName); + } +} \ No newline at end of file diff --git a/ComponentCodelab/listcontainer/src/test/java/com/huawei/cookbook/ExampleTest.java b/ComponentCodelab/listcontainer/src/test/java/com/huawei/cookbook/ExampleTest.java new file mode 100644 index 0000000000000000000000000000000000000000..2a3bdc236408c9e4374d4c0c77aee7404ece1789 --- /dev/null +++ b/ComponentCodelab/listcontainer/src/test/java/com/huawei/cookbook/ExampleTest.java @@ -0,0 +1,9 @@ +package com.huawei.cookbook; + +import org.junit.Test; + +public class ExampleTest { + @Test + public void onStart() { + } +} diff --git a/ComponentCodelab/radiocontainer/build.gradle b/ComponentCodelab/radiocontainer/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..66c5259e68ee219a7d0d65202c9543e0c36b6fc7 --- /dev/null +++ b/ComponentCodelab/radiocontainer/build.gradle @@ -0,0 +1,28 @@ +apply plugin: 'com.huawei.ohos.hap' +apply plugin: 'com.huawei.ohos.decctest' +//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#ZH-CN_TOPIC_0000001154985555__section1112183053510 +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 5 + } + buildTypes { + release { + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } + } + } + entryModules "entry" +} + +dependencies { + entryImplementation project(':entry') + implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) + testImplementation 'junit:junit:4.13' + ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100' +} +decc { + supportType = ['html', 'xml'] +} diff --git a/ComponentCodelab/radiocontainer/src/main/config.json b/ComponentCodelab/radiocontainer/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..37a76c1dad8c410083c561b4020b50dee7a0aaa9 --- /dev/null +++ b/ComponentCodelab/radiocontainer/src/main/config.json @@ -0,0 +1,37 @@ +{ + "app": { + "bundleName": "com.huawei.cookbook", + "vendor": "huawei", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.huawei.radiocontainer", + "name": ".MyApplication", + "mainAbility": "com.huawei.radiocontainer.MainAbility", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "radiocontainer", + "moduleType": "feature", + "installationFree": false + }, + "abilities": [ + { + "orientation": "unspecified", + "visible": true, + "name": "com.huawei.radiocontainer.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:radiocontainer_MainAbility", + "type": "page", + "launchType": "standard" + } + ] + } +} \ No newline at end of file diff --git a/ComponentCodelab/radiocontainer/src/main/java/com/huawei/radiocontainer/MainAbility.java b/ComponentCodelab/radiocontainer/src/main/java/com/huawei/radiocontainer/MainAbility.java new file mode 100644 index 0000000000000000000000000000000000000000..1698bb83bcb785c95f0c1560d1b5064dac5f8008 --- /dev/null +++ b/ComponentCodelab/radiocontainer/src/main/java/com/huawei/radiocontainer/MainAbility.java @@ -0,0 +1,32 @@ +/* + * 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.huawei.radiocontainer; + +import com.huawei.radiocontainer.slice.MainAbilitySlice; + +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; + +/** + * MainAbility + */ +public class MainAbility extends Ability { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setMainRoute(MainAbilitySlice.class.getName()); + } +} diff --git a/ComponentCodelab/radiocontainer/src/main/java/com/huawei/radiocontainer/MyApplication.java b/ComponentCodelab/radiocontainer/src/main/java/com/huawei/radiocontainer/MyApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..e16a86c8dcb255a7bed4804c9c970c4b3fd630f9 --- /dev/null +++ b/ComponentCodelab/radiocontainer/src/main/java/com/huawei/radiocontainer/MyApplication.java @@ -0,0 +1,28 @@ +/* + * 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.huawei.radiocontainer; + +import ohos.aafwk.ability.AbilityPackage; + +/** + * MyApplication + */ +public class MyApplication extends AbilityPackage { + @Override + public void onInitialize() { + super.onInitialize(); + } +} diff --git a/ComponentCodelab/radiocontainer/src/main/java/com/huawei/radiocontainer/slice/MainAbilitySlice.java b/ComponentCodelab/radiocontainer/src/main/java/com/huawei/radiocontainer/slice/MainAbilitySlice.java new file mode 100644 index 0000000000000000000000000000000000000000..f1aea7b1c71ed4223db0c4a752967f5f3e66fe75 --- /dev/null +++ b/ComponentCodelab/radiocontainer/src/main/java/com/huawei/radiocontainer/slice/MainAbilitySlice.java @@ -0,0 +1,86 @@ +/* + * 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.huawei.radiocontainer.slice; + +import com.huawei.radiocontainer.ResourceTable; + +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import ohos.agp.colors.RgbPalette; +import ohos.agp.components.ComponentState; +import ohos.agp.components.RadioButton; +import ohos.agp.components.RadioContainer; +import ohos.agp.components.Text; +import ohos.agp.components.element.ShapeElement; +import ohos.agp.components.element.StateElement; + +import java.util.Locale; + +/** + * MainAbilitySlice + */ +public class MainAbilitySlice extends AbilitySlice { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_radio_container); + initComponent(); + } + + /** + * 定义RadioButton的背景 + * @return 背景样式 + */ + private StateElement getStateElement() { + ShapeElement elementButtonOn = new ShapeElement(); + elementButtonOn.setRgbColor(RgbPalette.RED); + elementButtonOn.setShape(ShapeElement.OVAL); + + ShapeElement elementButtonOff = new ShapeElement(); + elementButtonOff.setRgbColor(RgbPalette.DARK_GRAY); + elementButtonOff.setShape(ShapeElement.OVAL); + + StateElement checkElement = new StateElement(); + checkElement.addState(new int[]{ComponentState.COMPONENT_STATE_CHECKED}, elementButtonOn); + checkElement.addState(new int[]{ComponentState.COMPONENT_STATE_EMPTY}, elementButtonOff); + return checkElement; + } + + /** + * 初始化组件并设置响应RadioContainer状态改变的事件,显示单选结果 + */ + private void initComponent() { + Text answer = (Text) findComponentById(ResourceTable.Id_answer); + RadioContainer container = (RadioContainer) findComponentById(ResourceTable.Id_radio_container); + int count = container.getChildCount(); + for (int i = 0; i < count; i++) { + ((RadioButton) container.getComponentAt(i)).setButtonElement(getStateElement()); + } + container.setMarkChangedListener((radioContainer1, index) -> { + answer.setText(String.format(Locale.ROOT,"[%c]", (char) ('A' + index))); + }); + } + + @Override + public void onActive() { + super.onActive(); + } + + @Override + public void onForeground(Intent intent) { + super.onForeground(intent); + } +} diff --git a/ComponentCodelab/radiocontainer/src/main/resources/base/element/string.json b/ComponentCodelab/radiocontainer/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..b71cb94780e841d7dc57200dc3e6e186bd80899e --- /dev/null +++ b/ComponentCodelab/radiocontainer/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "radiocontainer_MainAbility", + "value": "radiocontainer_MainAbility" + }, + { + "name": "mainability_description", + "value": "Java_Empty Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "Hello World" + } + ] +} \ No newline at end of file diff --git a/ComponentCodelab/radiocontainer/src/main/resources/base/graphic/background_radio_container.xml b/ComponentCodelab/radiocontainer/src/main/resources/base/graphic/background_radio_container.xml new file mode 100644 index 0000000000000000000000000000000000000000..c0c0a3df480fa387a452b9c40ca191cc918a3fc0 --- /dev/null +++ b/ComponentCodelab/radiocontainer/src/main/resources/base/graphic/background_radio_container.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/ComponentCodelab/radiocontainer/src/main/resources/base/layout/radio_container.xml b/ComponentCodelab/radiocontainer/src/main/resources/base/layout/radio_container.xml new file mode 100644 index 0000000000000000000000000000000000000000..6b2a0b0783c3051c8c8f566a50f9936e664678f2 --- /dev/null +++ b/ComponentCodelab/radiocontainer/src/main/resources/base/layout/radio_container.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ComponentCodelab/radiocontainer/src/main/resources/base/media/icon.png b/ComponentCodelab/radiocontainer/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ComponentCodelab/radiocontainer/src/main/resources/base/media/icon.png differ diff --git a/ComponentCodelab/radiocontainer/src/main/resources/en/element/string.json b/ComponentCodelab/radiocontainer/src/main/resources/en/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..dfc37f5a8ce98eb180a97d798ee1623d7fd89d05 --- /dev/null +++ b/ComponentCodelab/radiocontainer/src/main/resources/en/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "radiocontainer_MainAbility", + "value": "radiocontainer_MainAbility" + }, + { + "name": "mainability_description", + "value": "Java_Empty Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "Hello World" + } + ] +} diff --git a/ComponentCodelab/radiocontainer/src/main/resources/zh/element/string.json b/ComponentCodelab/radiocontainer/src/main/resources/zh/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..e0685d5e0e0d03e45af14defe7c868479c3ef714 --- /dev/null +++ b/ComponentCodelab/radiocontainer/src/main/resources/zh/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "radiocontainer_MainAbility", + "value": "radiocontainer_MainAbility" + }, + { + "name": "mainability_description", + "value": "Java_Empty Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "你好,世界" + } + ] +} \ No newline at end of file diff --git a/ComponentCodelab/radiocontainer/src/ohosTest/java/com/huawei/radiocontainer/ExampleOhosTest.java b/ComponentCodelab/radiocontainer/src/ohosTest/java/com/huawei/radiocontainer/ExampleOhosTest.java new file mode 100644 index 0000000000000000000000000000000000000000..126cbbfc3f0a5c3c747e8f64096515029e9c9883 --- /dev/null +++ b/ComponentCodelab/radiocontainer/src/ohosTest/java/com/huawei/radiocontainer/ExampleOhosTest.java @@ -0,0 +1,14 @@ +package com.huawei.radiocontainer; + +import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class ExampleOhosTest { + @Test + public void testBundleName() { + final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName(); + assertEquals("com.huawei.cookbook", actualBundleName); + } +} \ No newline at end of file diff --git a/ComponentCodelab/radiocontainer/src/test/java/com/huawei/radiocontainer/ExampleTest.java b/ComponentCodelab/radiocontainer/src/test/java/com/huawei/radiocontainer/ExampleTest.java new file mode 100644 index 0000000000000000000000000000000000000000..e44cc7bf5c7c275243dda5e0737fc20a0572e4b5 --- /dev/null +++ b/ComponentCodelab/radiocontainer/src/test/java/com/huawei/radiocontainer/ExampleTest.java @@ -0,0 +1,9 @@ +package com.huawei.radiocontainer; + +import org.junit.Test; + +public class ExampleTest { + @Test + public void onStart() { + } +} diff --git a/ComponentCodelab/settings.gradle b/ComponentCodelab/settings.gradle index 4773db73233a570c2d0c01a22e75321acfbf7a07..bc414431ef249887dbf0b3c5a031295519791573 100644 --- a/ComponentCodelab/settings.gradle +++ b/ComponentCodelab/settings.gradle @@ -1 +1 @@ -include ':entry' +include ':entry', ':tablist', ':listcontainer', ':radiocontainer', ':checkbox', ':datepicker', ':directionallayout', ':dependentlayout', ':stacklayout', ':tablelayout' diff --git a/ComponentCodelab/stacklayout/build.gradle b/ComponentCodelab/stacklayout/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..66c5259e68ee219a7d0d65202c9543e0c36b6fc7 --- /dev/null +++ b/ComponentCodelab/stacklayout/build.gradle @@ -0,0 +1,28 @@ +apply plugin: 'com.huawei.ohos.hap' +apply plugin: 'com.huawei.ohos.decctest' +//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#ZH-CN_TOPIC_0000001154985555__section1112183053510 +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 5 + } + buildTypes { + release { + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } + } + } + entryModules "entry" +} + +dependencies { + entryImplementation project(':entry') + implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) + testImplementation 'junit:junit:4.13' + ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100' +} +decc { + supportType = ['html', 'xml'] +} diff --git a/ComponentCodelab/stacklayout/src/main/config.json b/ComponentCodelab/stacklayout/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..e94da0bc6df340053fa1d78126db5f4089a0d75d --- /dev/null +++ b/ComponentCodelab/stacklayout/src/main/config.json @@ -0,0 +1,37 @@ +{ + "app": { + "bundleName": "com.huawei.cookbook", + "vendor": "huawei", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.huawei.stacklayout", + "name": ".MyApplication", + "mainAbility": "com.huawei.stacklayout.MainAbility", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "stacklayout", + "moduleType": "feature", + "installationFree": false + }, + "abilities": [ + { + "orientation": "unspecified", + "visible": true, + "name": "com.huawei.stacklayout.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:stacklayout_MainAbility", + "type": "page", + "launchType": "standard" + } + ] + } +} \ No newline at end of file diff --git a/ComponentCodelab/stacklayout/src/main/java/com/huawei/stacklayout/MainAbility.java b/ComponentCodelab/stacklayout/src/main/java/com/huawei/stacklayout/MainAbility.java new file mode 100644 index 0000000000000000000000000000000000000000..be205ba40a7cb62bb3ef1e326097c77f458e659f --- /dev/null +++ b/ComponentCodelab/stacklayout/src/main/java/com/huawei/stacklayout/MainAbility.java @@ -0,0 +1,32 @@ +/* + * 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.huawei.stacklayout; + +import com.huawei.stacklayout.slice.MainAbilitySlice; + +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; + +/** + * MainAbility + */ +public class MainAbility extends Ability { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setMainRoute(MainAbilitySlice.class.getName()); + } +} diff --git a/ComponentCodelab/stacklayout/src/main/java/com/huawei/stacklayout/MyApplication.java b/ComponentCodelab/stacklayout/src/main/java/com/huawei/stacklayout/MyApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..a02c9ceeb8f5758ade8d5ab01fc7079b631e0fda --- /dev/null +++ b/ComponentCodelab/stacklayout/src/main/java/com/huawei/stacklayout/MyApplication.java @@ -0,0 +1,28 @@ +/* + * 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.huawei.stacklayout; + +import ohos.aafwk.ability.AbilityPackage; + +/** + * MyApplication + */ +public class MyApplication extends AbilityPackage { + @Override + public void onInitialize() { + super.onInitialize(); + } +} diff --git a/ComponentCodelab/stacklayout/src/main/java/com/huawei/stacklayout/slice/MainAbilitySlice.java b/ComponentCodelab/stacklayout/src/main/java/com/huawei/stacklayout/slice/MainAbilitySlice.java new file mode 100644 index 0000000000000000000000000000000000000000..e898c0317a96ccbfc82ad036e6b81ccd4813e18c --- /dev/null +++ b/ComponentCodelab/stacklayout/src/main/java/com/huawei/stacklayout/slice/MainAbilitySlice.java @@ -0,0 +1,42 @@ +/* + * 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.huawei.stacklayout.slice; + +import com.huawei.stacklayout.ResourceTable; + +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; + +/** + * MainAbilitySlice + */ +public class MainAbilitySlice extends AbilitySlice { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_stack_layout); + } + + @Override + public void onActive() { + super.onActive(); + } + + @Override + public void onForeground(Intent intent) { + super.onForeground(intent); + } +} diff --git a/ComponentCodelab/stacklayout/src/main/resources/base/element/string.json b/ComponentCodelab/stacklayout/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..8094ae4c7fa760f80643fb323c78ded3467a3297 --- /dev/null +++ b/ComponentCodelab/stacklayout/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "stacklayout_MainAbility", + "value": "stacklayout_MainAbility" + }, + { + "name": "mainability_description", + "value": "Java_Empty Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "Hello World" + } + ] +} \ No newline at end of file diff --git a/ComponentCodelab/stacklayout/src/main/resources/base/graphic/background_stack_layout.xml b/ComponentCodelab/stacklayout/src/main/resources/base/graphic/background_stack_layout.xml new file mode 100644 index 0000000000000000000000000000000000000000..a002c2353e78af3a15235e00738328ff566bc085 --- /dev/null +++ b/ComponentCodelab/stacklayout/src/main/resources/base/graphic/background_stack_layout.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/ComponentCodelab/stacklayout/src/main/resources/base/layout/stack_layout.xml b/ComponentCodelab/stacklayout/src/main/resources/base/layout/stack_layout.xml new file mode 100644 index 0000000000000000000000000000000000000000..756f6f2eb4593a1acabef17f829a8ec297ae1233 --- /dev/null +++ b/ComponentCodelab/stacklayout/src/main/resources/base/layout/stack_layout.xml @@ -0,0 +1,31 @@ + + + + + + \ No newline at end of file diff --git a/ComponentCodelab/stacklayout/src/main/resources/base/media/icon.png b/ComponentCodelab/stacklayout/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ComponentCodelab/stacklayout/src/main/resources/base/media/icon.png differ diff --git a/ComponentCodelab/stacklayout/src/main/resources/en/element/string.json b/ComponentCodelab/stacklayout/src/main/resources/en/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..2020752594eba04d90a9909968beecf4393536b3 --- /dev/null +++ b/ComponentCodelab/stacklayout/src/main/resources/en/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "stacklayout_MainAbility", + "value": "stacklayout_MainAbility" + }, + { + "name": "mainability_description", + "value": "Java_Empty Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "Hello World" + } + ] +} diff --git a/ComponentCodelab/stacklayout/src/main/resources/zh/element/string.json b/ComponentCodelab/stacklayout/src/main/resources/zh/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..1dbdc2e3d9e111d72bfcd7f592bb167d9b1c5822 --- /dev/null +++ b/ComponentCodelab/stacklayout/src/main/resources/zh/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "stacklayout_MainAbility", + "value": "stacklayout_MainAbility" + }, + { + "name": "mainability_description", + "value": "Java_Empty Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "你好,世界" + } + ] +} \ No newline at end of file diff --git a/ComponentCodelab/stacklayout/src/ohosTest/java/com/huawei/stacklayout/ExampleOhosTest.java b/ComponentCodelab/stacklayout/src/ohosTest/java/com/huawei/stacklayout/ExampleOhosTest.java new file mode 100644 index 0000000000000000000000000000000000000000..044aa46f3b322c77c6cf384298c232092e1c43d7 --- /dev/null +++ b/ComponentCodelab/stacklayout/src/ohosTest/java/com/huawei/stacklayout/ExampleOhosTest.java @@ -0,0 +1,14 @@ +package com.huawei.stacklayout; + +import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class ExampleOhosTest { + @Test + public void testBundleName() { + final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName(); + assertEquals("com.huawei.cookbook", actualBundleName); + } +} \ No newline at end of file diff --git a/ComponentCodelab/stacklayout/src/test/java/com/huawei/stacklayout/ExampleTest.java b/ComponentCodelab/stacklayout/src/test/java/com/huawei/stacklayout/ExampleTest.java new file mode 100644 index 0000000000000000000000000000000000000000..f45ee8fe7e62cbe18fb6007fbdb460917742e53b --- /dev/null +++ b/ComponentCodelab/stacklayout/src/test/java/com/huawei/stacklayout/ExampleTest.java @@ -0,0 +1,9 @@ +package com.huawei.stacklayout; + +import org.junit.Test; + +public class ExampleTest { + @Test + public void onStart() { + } +} diff --git a/ComponentCodelab/tablelayout/build.gradle b/ComponentCodelab/tablelayout/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..66c5259e68ee219a7d0d65202c9543e0c36b6fc7 --- /dev/null +++ b/ComponentCodelab/tablelayout/build.gradle @@ -0,0 +1,28 @@ +apply plugin: 'com.huawei.ohos.hap' +apply plugin: 'com.huawei.ohos.decctest' +//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#ZH-CN_TOPIC_0000001154985555__section1112183053510 +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 5 + } + buildTypes { + release { + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } + } + } + entryModules "entry" +} + +dependencies { + entryImplementation project(':entry') + implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) + testImplementation 'junit:junit:4.13' + ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100' +} +decc { + supportType = ['html', 'xml'] +} diff --git a/ComponentCodelab/tablelayout/src/main/config.json b/ComponentCodelab/tablelayout/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..591fab1bb2ebf16c57cf226896028ebece4e2b0b --- /dev/null +++ b/ComponentCodelab/tablelayout/src/main/config.json @@ -0,0 +1,37 @@ +{ + "app": { + "bundleName": "com.huawei.cookbook", + "vendor": "huawei", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.huawei.tablelayout", + "name": ".MyApplication", + "mainAbility": "com.huawei.tablelayout.MainAbility", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "tablelayout", + "moduleType": "feature", + "installationFree": false + }, + "abilities": [ + { + "orientation": "unspecified", + "visible": true, + "name": "com.huawei.tablelayout.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:tablelayout_MainAbility", + "type": "page", + "launchType": "standard" + } + ] + } +} \ No newline at end of file diff --git a/ComponentCodelab/tablelayout/src/main/java/com/huawei/tablelayout/MainAbility.java b/ComponentCodelab/tablelayout/src/main/java/com/huawei/tablelayout/MainAbility.java new file mode 100644 index 0000000000000000000000000000000000000000..23077bfb5263f6a3f2e6d89196e3037f25251e71 --- /dev/null +++ b/ComponentCodelab/tablelayout/src/main/java/com/huawei/tablelayout/MainAbility.java @@ -0,0 +1,32 @@ +/* + * 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.huawei.tablelayout; + +import com.huawei.tablelayout.slice.MainAbilitySlice; + +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; + +/** + * MainAbility + */ +public class MainAbility extends Ability { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setMainRoute(MainAbilitySlice.class.getName()); + } +} diff --git a/ComponentCodelab/tablelayout/src/main/java/com/huawei/tablelayout/MyApplication.java b/ComponentCodelab/tablelayout/src/main/java/com/huawei/tablelayout/MyApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..238aad7807681236ba734bd6dd3f179dcb47da90 --- /dev/null +++ b/ComponentCodelab/tablelayout/src/main/java/com/huawei/tablelayout/MyApplication.java @@ -0,0 +1,28 @@ +/* + * 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.huawei.tablelayout; + +import ohos.aafwk.ability.AbilityPackage; + +/** + * MyApplication + */ +public class MyApplication extends AbilityPackage { + @Override + public void onInitialize() { + super.onInitialize(); + } +} diff --git a/ComponentCodelab/tablelayout/src/main/java/com/huawei/tablelayout/slice/MainAbilitySlice.java b/ComponentCodelab/tablelayout/src/main/java/com/huawei/tablelayout/slice/MainAbilitySlice.java new file mode 100644 index 0000000000000000000000000000000000000000..b9d05751a4b58a5bdd1487afc9e592e71d937848 --- /dev/null +++ b/ComponentCodelab/tablelayout/src/main/java/com/huawei/tablelayout/slice/MainAbilitySlice.java @@ -0,0 +1,117 @@ +/* + * 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.huawei.tablelayout.slice; + +import com.huawei.tablelayout.ResourceTable; + +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import ohos.agp.components.Button; +import ohos.agp.components.Component; +import ohos.agp.components.TableLayout; +import ohos.agp.components.Text; +import ohos.agp.utils.LayoutAlignment; +import ohos.agp.window.dialog.ToastDialog; + +/** + * MainAbilitySlice + */ +public class MainAbilitySlice extends AbilitySlice { + private static final int TIALOG_OFFSET_X = 0; + private static final int TIALOG_OFFSET_Y = 180; + private Text info; + private Button call; + private Button clear; + + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_table_layout); + initComponent(); + setClickedListener(); + } + + /** + * 初始化组件 + */ + private void initComponent() { + info = (Text)findComponentById(ResourceTable.Id_info); + call = (Button)findComponentById(ResourceTable.Id_call); + clear = (Button)findComponentById(ResourceTable.Id_clear); + } + + /** + * 设置点击事件 + */ + private void setClickedListener() { + call.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + showTips(); + } + }); + + clear.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + info.setText(""); + } + }); + + TableLayout table = (TableLayout)findComponentById(ResourceTable.Id_table); + int childNum = table.getChildCount(); + for (int index = 0; index < childNum; index++) { + setClickListener(table, index); + } + } + + private void setClickListener(TableLayout table, int index) { + Button child = (Button)(table.getComponentAt(index)); + child.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + if (component instanceof Button) { + Button button = (Button)component; + info.setText(info.getText() + button.getText()); + } + } + }); + } + + private void showTips() { + String toastInfo = info.getText(); + if (toastInfo == null || toastInfo.isEmpty()) { + toastInfo = "Please enter the number!"; + } else { + toastInfo = "Call " + info.getText(); + } + new ToastDialog(getContext()) + .setText(toastInfo) + .setAlignment(LayoutAlignment.CENTER) + .setOffset(TIALOG_OFFSET_X, TIALOG_OFFSET_Y) + .show(); + } + + @Override + public void onActive() { + super.onActive(); + } + + @Override + public void onForeground(Intent intent) { + super.onForeground(intent); + } +} diff --git a/ComponentCodelab/tablelayout/src/main/resources/base/element/string.json b/ComponentCodelab/tablelayout/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..eea1e564e67a61dcfad3a08f12b130713c9b4fd8 --- /dev/null +++ b/ComponentCodelab/tablelayout/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "tablelayout_MainAbility", + "value": "tablelayout_MainAbility" + }, + { + "name": "mainability_description", + "value": "Java_Empty Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "Hello World" + } + ] +} \ No newline at end of file diff --git a/ComponentCodelab/tablelayout/src/main/resources/base/graphic/background_table_layout.xml b/ComponentCodelab/tablelayout/src/main/resources/base/graphic/background_table_layout.xml new file mode 100644 index 0000000000000000000000000000000000000000..a002c2353e78af3a15235e00738328ff566bc085 --- /dev/null +++ b/ComponentCodelab/tablelayout/src/main/resources/base/graphic/background_table_layout.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/ComponentCodelab/tablelayout/src/main/resources/base/graphic/button_element.xml b/ComponentCodelab/tablelayout/src/main/resources/base/graphic/button_element.xml new file mode 100644 index 0000000000000000000000000000000000000000..ba40e3d579b3ac51c820f26b13308cb50f04baca --- /dev/null +++ b/ComponentCodelab/tablelayout/src/main/resources/base/graphic/button_element.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/ComponentCodelab/tablelayout/src/main/resources/base/graphic/circle_button_element.xml b/ComponentCodelab/tablelayout/src/main/resources/base/graphic/circle_button_element.xml new file mode 100644 index 0000000000000000000000000000000000000000..a5fffc1625ee412c50c9b0328626420b57d876f5 --- /dev/null +++ b/ComponentCodelab/tablelayout/src/main/resources/base/graphic/circle_button_element.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/ComponentCodelab/tablelayout/src/main/resources/base/layout/table_layout.xml b/ComponentCodelab/tablelayout/src/main/resources/base/layout/table_layout.xml new file mode 100644 index 0000000000000000000000000000000000000000..4570632a5a366d835f0503011edd87d21f47e632 --- /dev/null +++ b/ComponentCodelab/tablelayout/src/main/resources/base/layout/table_layout.xml @@ -0,0 +1,159 @@ + + + + +