From bcb118b7172149d76e0edf6a25fb831c08dc153d Mon Sep 17 00:00:00 2001 From: cuizhaofei Date: Fri, 16 Jul 2021 14:46:21 +0800 Subject: [PATCH] =?UTF-8?q?CheckStyle=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- entry/build.gradle | 1 + .../example/expandableview/MainAbility.java | 20 ++++ .../example/expandableview/MyApplication.java | 20 ++++ .../slice/MainAbilitySlice.java | 113 ++++++++++-------- .../java/com/expandable/view/HmCheckbox.java | 4 +- 6 files changed, 105 insertions(+), 55 deletions(-) diff --git a/README.md b/README.md index b752946..0c8703a 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,8 @@ - 功能:实现可折叠ListContainer - 项目移植状态:主功能完成 - 调用差异:无 -- 基线版本: master分支 - 开发版本:sdk6,DevEco Studio2.2 Beta1 +- 基线版本: Release 1.0 #### 效果演示 diff --git a/entry/build.gradle b/entry/build.gradle index ba3b3df..ade61a0 100644 --- a/entry/build.gradle +++ b/entry/build.gradle @@ -21,6 +21,7 @@ dependencies { testImplementation 'junit:junit:4.13' ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100' implementation('com.gitee.chinasoft_ohos:ohos-expandableview:0.0.2-SNAPSHOT') +// implementation project(path: ':expandableview') } decc { supportType = ['html', 'xml'] diff --git a/entry/src/main/java/com/example/expandableview/MainAbility.java b/entry/src/main/java/com/example/expandableview/MainAbility.java index e0dd165..01decb9 100644 --- a/entry/src/main/java/com/example/expandableview/MainAbility.java +++ b/entry/src/main/java/com/example/expandableview/MainAbility.java @@ -1,9 +1,29 @@ +/* + * 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.example.expandableview; import com.example.expandableview.slice.MainAbilitySlice; import ohos.aafwk.ability.Ability; import ohos.aafwk.content.Intent; +/** + * MainAbility + * + * @since 2021-06-07 + */ public class MainAbility extends Ability { @Override public void onStart(Intent intent) { diff --git a/entry/src/main/java/com/example/expandableview/MyApplication.java b/entry/src/main/java/com/example/expandableview/MyApplication.java index d29d7f8..05aef7a 100644 --- a/entry/src/main/java/com/example/expandableview/MyApplication.java +++ b/entry/src/main/java/com/example/expandableview/MyApplication.java @@ -1,7 +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.example.expandableview; import ohos.aafwk.ability.AbilityPackage; +/** + * MyApplication + * + * @since 2021-06-07 + */ public class MyApplication extends AbilityPackage { @Override public void onInitialize() { diff --git a/entry/src/main/java/com/example/expandableview/slice/MainAbilitySlice.java b/entry/src/main/java/com/example/expandableview/slice/MainAbilitySlice.java index 690d078..9735fed 100644 --- a/entry/src/main/java/com/example/expandableview/slice/MainAbilitySlice.java +++ b/entry/src/main/java/com/example/expandableview/slice/MainAbilitySlice.java @@ -1,3 +1,18 @@ +/* + * 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.example.expandableview.slice; import com.example.expandableview.ExpandedListItemView; @@ -9,12 +24,21 @@ import ohos.agp.colors.RgbColor; import ohos.agp.components.element.ShapeElement; import ohos.global.resource.NotExistException; import ohos.global.resource.WrongTypeException; +import ohos.hiviewdfx.HiLog; +import ohos.hiviewdfx.HiLogLabel; import java.io.IOException; +/** + * MainAbilitySlice + * + * @since 2021-06-07 + */ public class MainAbilitySlice extends AbilitySlice { - - private static final String TAG = "MainAbilitySlice:"; + private static final HiLogLabel LABEL = new HiLogLabel(HiLog.LOG_APP, 0x00201, "MY_TAG"); + private static final int VISIBLELAYOUTHEIGHT = 100; + private static final int HOLOBLUELIGHT = 0xff33b5e5; + private static final int HOLOGREENLIGHT = 0xff99cc00; private ExpandableView topExpandableView; private ExpandableView middleExpandableView; private ExpandableView expandableViewLevel1; @@ -29,8 +53,10 @@ public class MainAbilitySlice extends AbilitySlice { } private void initView() { - topExpandableView = (ExpandableView) findComponentById(ResourceTable.Id_activity_main_top_expandable_view); - middleExpandableView = (ExpandableView) findComponentById(ResourceTable.Id_activity_main_middle_expandable_view); + topExpandableView = (ExpandableView) findComponentById( + ResourceTable.Id_activity_main_top_expandable_view); + middleExpandableView = (ExpandableView) findComponentById( + ResourceTable.Id_activity_main_middle_expandable_view); expandableViewLevel1 = new ExpandableView(this); expandableViewLevel2 = new ExpandableView(this); @@ -47,101 +73,84 @@ public class MainAbilitySlice extends AbilitySlice { createInnerExpandableViewLevel3(); expandableViewLevel1.setOutsideContentLayout(topExpandableView.getContentLayout()); - expandableViewLevel2.setOutsideContentLayout(topExpandableView.getContentLayout(), expandableViewLevel1.getContentLayout()); - expandableViewLevel3.setOutsideContentLayout(topExpandableView.getContentLayout(), expandableViewLevel1.getContentLayout(), expandableViewLevel2.getContentLayout()); + expandableViewLevel2.setOutsideContentLayout(topExpandableView. + getContentLayout(), expandableViewLevel1.getContentLayout()); + expandableViewLevel3.setOutsideContentLayout(topExpandableView. + getContentLayout(), expandableViewLevel1.getContentLayout(), expandableViewLevel2.getContentLayout()); } - private void createTopExpandableView() { try { - String[] ohosVersionNameList = this.getResourceManager().getElement(ResourceTable.Strarray_ohos_version_names).getStringArray(); + String[] ohosVersionNameList = this.getResourceManager(). + getElement(ResourceTable.Strarray_ohos_version_names).getStringArray(); topExpandableView.fillData(ResourceTable.Media_icon, getString(ResourceTable.String_ohos_names), true); addContentView(topExpandableView, ohosVersionNameList, true); topExpandableView.addContentView(expandableViewLevel1); - } catch (IOException e) { - e.printStackTrace(); - } catch (NotExistException e) { - e.printStackTrace(); - } catch (WrongTypeException e) { - e.printStackTrace(); + } catch (IOException | NotExistException | WrongTypeException e) { + HiLog.error(LABEL, e.getMessage()); } } private void createMiddleExpandableView() { try { - String[] ohosVersionNameList = this.getResourceManager().getElement(ResourceTable.Strarray_ohos_version_names).getStringArray(); + String[] ohosVersionNameList = this.getResourceManager(). + getElement(ResourceTable.Strarray_ohos_version_names).getStringArray(); middleExpandableView.fillData(ResourceTable.Media_icon, getString(ResourceTable.String_ohos_names), false); - middleExpandableView.setVisibleLayoutHeight(100); + middleExpandableView.setVisibleLayoutHeight(VISIBLELAYOUTHEIGHT); addContentView(middleExpandableView, ohosVersionNameList, false); - } catch (IOException e) { - e.printStackTrace(); - } catch (NotExistException e) { - e.printStackTrace(); - } catch (WrongTypeException e) { - e.printStackTrace(); + } catch (IOException | NotExistException | WrongTypeException e) { + HiLog.error(LABEL, e.getMessage()); } } private void createInnerExpandableViewLevel1() { try { - String[] ohosVersionNumberList = this.getResourceManager().getElement(ResourceTable.Strarray_ohos_version_time).getStringArray(); ShapeElement element = new ShapeElement(); - int holo_blue_light = 0xff33b5e5; - element.setRgbColor(RgbColor.fromArgbInt(holo_blue_light)); + element.setRgbColor(RgbColor.fromArgbInt(HOLOBLUELIGHT)); expandableViewLevel1.setBackground(element); expandableViewLevel1.fillData(ResourceTable.Media_icon, getString(ResourceTable.String_ohos_codes), false); + String[] ohosVersionNumberList = this.getResourceManager(). + getElement(ResourceTable.Strarray_ohos_version_time).getStringArray(); addContentView(expandableViewLevel1, ohosVersionNumberList, false); expandableViewLevel1.addContentView(expandableViewLevel2); - } catch (IOException e) { - e.printStackTrace(); - } catch (NotExistException e) { - e.printStackTrace(); - } catch (WrongTypeException e) { - e.printStackTrace(); + } catch (IOException | NotExistException | WrongTypeException e) { + HiLog.error(LABEL, e.getMessage()); } } private void createInnerExpandableViewLevel2() { try { - String[] ohosVersionNameList = this.getResourceManager().getElement(ResourceTable.Strarray_ohos_version_names).getStringArray(); ShapeElement element = new ShapeElement(); - int holo_green_light = 0xff99cc00; - element.setRgbColor(RgbColor.fromArgbInt(holo_green_light)); + element.setRgbColor(RgbColor.fromArgbInt(HOLOGREENLIGHT)); expandableViewLevel2.setBackground(element); expandableViewLevel2.fillData(ResourceTable.Media_icon, getString(ResourceTable.String_ohos_names), false); + String[] ohosVersionNameList = this.getResourceManager(). + getElement(ResourceTable.Strarray_ohos_version_names).getStringArray(); addContentView(expandableViewLevel2, ohosVersionNameList, false); expandableViewLevel2.addContentView(expandableViewLevel3); - } catch (IOException e) { - e.printStackTrace(); - } catch (NotExistException e) { - e.printStackTrace(); - } catch (WrongTypeException e) { - e.printStackTrace(); + } catch (IOException | NotExistException | WrongTypeException e) { + HiLog.error(LABEL, e.getMessage()); } } private void createInnerExpandableViewLevel3() { try { - String[] ohosVersionNameList = this.getResourceManager().getElement(ResourceTable.Strarray_ohos_version_time).getStringArray(); ShapeElement element = new ShapeElement(); - int holo_blue_light = 0xff33b5e5; - element.setRgbColor(RgbColor.fromArgbInt(holo_blue_light)); + element.setRgbColor(RgbColor.fromArgbInt(HOLOBLUELIGHT)); expandableViewLevel3.setBackground(element); expandableViewLevel3.fillData(ResourceTable.Media_icon, getString(ResourceTable.String_ohos_codes), false); + String[] ohosVersionNameList = this.getResourceManager(). + getElement(ResourceTable.Strarray_ohos_version_time).getStringArray(); addContentView(expandableViewLevel3, ohosVersionNameList, false); - } catch (IOException e) { - e.printStackTrace(); - } catch (NotExistException e) { - e.printStackTrace(); - } catch (WrongTypeException e) { - e.printStackTrace(); + } catch (IOException | NotExistException | WrongTypeException e) { + HiLog.error(LABEL, e.getMessage()); } } - public void addContentView(ExpandableView view, String[] stringList, boolean showCheckbox) { - for (int i = 0; i < stringList.length; i++) { + private void addContentView(ExpandableView view, String[] stringList, boolean isShowCheckbox) { + for (String ss : stringList) { ExpandedListItemView itemView = new ExpandedListItemView(this); - itemView.setText(stringList[i], showCheckbox); + itemView.setText(ss, isShowCheckbox); view.addContentView(itemView); } } diff --git a/expandableview/src/main/java/com/expandable/view/HmCheckbox.java b/expandableview/src/main/java/com/expandable/view/HmCheckbox.java index bf666f3..4e1aaa0 100644 --- a/expandableview/src/main/java/com/expandable/view/HmCheckbox.java +++ b/expandableview/src/main/java/com/expandable/view/HmCheckbox.java @@ -113,8 +113,8 @@ public class HmCheckbox extends Checkbox implements Component.DrawTask, Checkbox } @Override - public void onCheckedChanged(AbsButton absButton, boolean b) { - this.setChecked(b); + public void onCheckedChanged(AbsButton absButton, boolean isBoolean) { + this.setChecked(isBoolean); invalidate(); } } -- Gitee