diff --git a/.gitignore b/.gitignore index d861a7e5acbef00d181a9fc5c28cd5970bce6a43..e4ea5a1ebdc69399ec8e72608d8d1e9cd86fc22d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,18 +1,17 @@ -local.properties - -# Gradle -.gradle -build/ - -# Android Studio *.iml -!.idea/runConfigurations/* -.idea/*.xml -.idea/.name -.idea/copyright/ -.idea/libraries/ -.idea/scopes/ -.idea/inspectionProfiles/ - -# Other -.DS_Store \ No newline at end of file +.gradle +.idea +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +/entry/.preview +.cxx +upload.gradle diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000000000000000000000000000000000000..8c6f58999029544b3beb3ee6ca846f7ea8df1200 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +## 0.0.2-SNAPSHOT +ohos 第二个版本,修复了findbugs问题,更新SDK6 + +## 0.0.1-SNAPSHOT +ohos第一个版本,完整实现了原库的全部api diff --git a/README.OPENSOURCE b/README.OPENSOURCE new file mode 100644 index 0000000000000000000000000000000000000000..f43e8ccc7a28a59b34f444c47220577af52b0a4a --- /dev/null +++ b/README.OPENSOURCE @@ -0,0 +1,10 @@ +[ + { + "Name": " ExpandableTextView ", + "License": " Apache License ", + "License File": " LICENSE ", + "Version Number": " v0.1.3 ", + "Upstream URL": " https://github.com/Manabu-GT/ExpandableTextView ", + "Description": " ExpandableTextView is an library that allows developers to easily create an TextView which can expand/collapse just like the Google Play's app description. Feel free to use it all you want in your apps provided that you cite this project. " + } +] diff --git a/README.md b/README.md index 14b4530c26fe876d5014db1baf93e66700d35ae2..96822b635b3e9d40373a2f8aac896db78e1675b7 100644 --- a/README.md +++ b/README.md @@ -1,109 +1,132 @@ -ExpandableTextView [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-ExpandableTextView-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/1203) -=================== +# ExpandableTextView + +#### 项目介绍 +- 项目名称:可以展开/折叠的Text +- 所属系列:openharmony的第三方组件适配移植 +- 功能:实现可以展开/折叠的Text控件 +- 项目移植状态:主功能完成 +- 调用差异:无 +- 开发版本:sdk6,DevEco Studio2.2 Bate1 +- 基线版本:Release v0.1.3 + +#### 效果演示 + + +#### 安装教程 + +1.在项目根目录下的build.gradle文件中, + ```gradle +allprojects { + repositories { + maven { + url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' + } + } +} + ``` +2.在entry模块的build.gradle文件中, + ```gradle + dependencies { + implementation('com.gitee.chinasoft_ohos:ExpandableTextView:0.0.2-SNAPSHOT') + ...... + } +``` -ExpandableTextView is an Android library that allows developers to easily create an TextView -which can expand/collapse just like the Google Play's app description. -Feel free to use it all you want in your Android apps provided that you cite this project. +在sdk6,DevEco Studio2.2 Bate1下项目可直接运行 +如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, +并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下 + +#### 使用说明 + +使用该库非常简单,只需查看提供的示例的源代码。(查看ViewCreateHelper.java中在ScrollView和ListContainer中的使用) +```示例XML + + + + + + +``` -Quick Demo +```java +ExpandableTextView expandableTextView = (ExpandableTextView) + component.findComponentById(ResourceTable.Id_expandable); +expandableTextView.setText(slice.getString(ResourceTable.String_dummy_text2)); +``` +另外,您可以选择在布局xml文件中设置以下属性,以自定义ExpandableTextView的行为。 +1. maxCollapsedLines (默认为8)当TextView折叠时允许显示的最大文本行数 -Requirements -------------- -API Level 8 (Froyo) and above. +2. animDuration (默认为300毫秒)扩展/折叠动画的持续时间 -Setup ------- -The library is pushed to Maven Central as an AAR, -so you just need to add the followings to your ***build.gradle*** file: +3. animAlphaStart (默认值为0.7f)动画开始时TextView的Alpha值(注意)如果要禁用Alpha动画,请将此值设置为1。 -```groovy +4. expandDrawable 自定义一个可绘制的设置为ImageButton以展开TextView -dependencies { - compile 'com.ms-square:expandableTextView:0.1.4' -} +5. collapseDrawable 自定义一个可绘制的设置为ImageButton以折叠TextView -``` +#### 测试信息 -Usage ------- -Using the library is really simple, just look at the source code of the [provided sample][1]. -(Look at the SampleTextListAdapter.java for the use within a ListView) - -The important thing to note is that the view Ids for TextView and ImageButton must be set to -"@id/expandable_text" and "@id/expand_collapse" respectively for this library to work. - -Also, you can optionally set the following attributes in your layout xml file to customize the behavior -of the ExpandableTextView. - - * `maxCollapsedLines` (defaults to 8) - The maximum number of text lines allowed to be shown when the TextView gets collapsed - - * `animDuration` (defaults to 300ms) - Duration of the Animation for the expansion/collapse - - * `animAlphaStart` (defaults to 0.7f) - Alpha value of the TextView when the animation starts - (NOTE) - Set this value to 1 if you want to disable the alpha animation. - - * `expandDrawable` - Customize a drawable set to ImageButton to expand the TextView - - * `collapseDrawable` - Customize a drawable set to ImageButton to collapse the TextView - -```xml - - - - - -``` +CodeCheck代码测试无异常 -```java -// sample code snippet to set the text content on the ExpandableTextView -ExpandableTextView expTv1 = (ExpandableTextView) rootView.findViewById(R.id.sample1) - .findViewById(R.id.expand_text_view); - -// IMPORTANT - call setText on the ExpandableTextView to set the text content to display -expTv1.setText(getString(R.string.dummy_text1)); -``` +CloudTest代码测试无异常 -License ----------- +病毒安全检测通过 - Copyright 2014 Manabu Shimobe +当前版本demo功能与原组件基本无差异 + +#### 版本迭代 + +- 0.0.2-SNAPSHOT + +#### 版权和许可信息 + Copyright 2014 Manabu Shimobe + 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. - -[1]: https://github.com/Manabu-GT/ExpandableTextView/tree/master/sample diff --git a/art/readme_demo.gif b/art/readme_demo.gif deleted file mode 100644 index eb99788e430b0b09682c2960b245089666e633be..0000000000000000000000000000000000000000 Binary files a/art/readme_demo.gif and /dev/null differ diff --git a/build.gradle b/build.gradle index 2c7ad6cab36d28cefff376b8ec4a76f7f84cc691..58e1cd2b1242734387f7c7bd9624744b8f2ed57e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,28 +1,41 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. +apply plugin: 'com.huawei.ohos.app' + +ohos { + compileSdkVersion 6 + defaultConfig { + compatibleSdkVersion 5 + } +} buildscript { repositories { - mavenCentral() + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.1.0' + classpath 'com.huawei.ohos:hap:2.4.5.0' + classpath 'com.huawei.ohos:decctest:1.2.4.1' } } allprojects { repositories { - mavenCentral() - } -} - -// http://www.gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html -project.ext { - ANDROID_COMPILE_SDK_VERSION = 23 - ANDROID_BUILD_TOOLS_VERSION = "23.0.3" + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + maven { + url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' + } - ANDROID_MIN_SDK_VERSION = 8 - ANDROID_TARGET_SDK_VERSION = 23 - - // Google Stuffs - supportPackageVersion = "23.1.1" + jcenter() + } } diff --git a/sample/.gitignore b/entry/.gitignore similarity index 100% rename from sample/.gitignore rename to entry/.gitignore diff --git a/entry/build.gradle b/entry/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..f66785e7e18e2843c407617ea1ee0953516e3b50 --- /dev/null +++ b/entry/build.gradle @@ -0,0 +1,27 @@ +apply plugin: 'com.huawei.ohos.hap' +apply plugin: 'com.huawei.ohos.decctest' +ohos { + compileSdkVersion 6 + defaultConfig { + compatibleSdkVersion 5 + } + buildTypes { + release { + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } + } + } + +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) + testImplementation 'junit:junit:4.13' + ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100' + implementation project(path: ':lib') +} +decc { + supportType = ['html', 'xml'] +} diff --git a/entry/proguard-rules.pro b/entry/proguard-rules.pro new file mode 100644 index 0000000000000000000000000000000000000000..f7666e47561d514b2a76d5a7dfbb43ede86da92a --- /dev/null +++ b/entry/proguard-rules.pro @@ -0,0 +1 @@ +# config module specific ProGuard rules here. \ No newline at end of file diff --git a/entry/src/main/config.json b/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..11c38f6b725ec875ae671edc65319bb5091e509f --- /dev/null +++ b/entry/src/main/config.json @@ -0,0 +1,64 @@ +{ + "app": { + "bundleName": "com.ms.square.ohos.expandabletextview.sample", + "vendor": "hos", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.ms.square.ohos.expandabletextview.sample", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "metaData": { + "customizeData": [ + { + "name": "hwc-theme", + "value": "androidhwext:style/Theme.Emui.NoTitleBar", + "extra": "" + } + ] + }, + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "name": "com.ms.square.ohos.expandabletextview.sample.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard", + "configChanges": [ + "orientation" + ] + } + ], + "reqPermissions": [ + { + "name": "ohos.permission.INTERNET" + }, + { + "name": "ohos.permission.READ_USER_STORAGE" + } + ] + } +} \ No newline at end of file diff --git a/entry/src/main/java/com/ms/square/ohos/expandabletextview/sample/MainAbility.java b/entry/src/main/java/com/ms/square/ohos/expandabletextview/sample/MainAbility.java new file mode 100644 index 0000000000000000000000000000000000000000..e9495dec71d52b8d788a5b8523aef4cc22e53d00 --- /dev/null +++ b/entry/src/main/java/com/ms/square/ohos/expandabletextview/sample/MainAbility.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.ms.square.ohos.expandabletextview.sample; + +import com.ms.square.ohos.expandabletextview.sample.slice.MainAbilitySlice; +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; +import ohos.agp.components.ComponentContainer; + +public class MainAbility extends Ability { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setMainRoute(MainAbilitySlice.class.getName()); + } + + @Override + public void setUIContent(ComponentContainer componentContainer) { + super.setUIContent(componentContainer); + } +} diff --git a/entry/src/main/java/com/ms/square/ohos/expandabletextview/sample/MyApplication.java b/entry/src/main/java/com/ms/square/ohos/expandabletextview/sample/MyApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..50c1ced3c6c8e7cee74f83f8ea8a2f2644e65c94 --- /dev/null +++ b/entry/src/main/java/com/ms/square/ohos/expandabletextview/sample/MyApplication.java @@ -0,0 +1,24 @@ +/* + * 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.ms.square.ohos.expandabletextview.sample; + +import ohos.aafwk.ability.AbilityPackage; + +public class MyApplication extends AbilityPackage { + @Override + public void onInitialize() { + super.onInitialize(); + } +} diff --git a/entry/src/main/java/com/ms/square/ohos/expandabletextview/sample/adapter/ListAdapter.java b/entry/src/main/java/com/ms/square/ohos/expandabletextview/sample/adapter/ListAdapter.java new file mode 100644 index 0000000000000000000000000000000000000000..7f76d08e3a50bd7d73b78e27a8995938c92c8b98 --- /dev/null +++ b/entry/src/main/java/com/ms/square/ohos/expandabletextview/sample/adapter/ListAdapter.java @@ -0,0 +1,68 @@ +/* + * 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.ms.square.ohos.expandabletextview.sample.adapter; + +import ohos.agp.components.BaseItemProvider; +import ohos.agp.components.Component; +import ohos.agp.components.ComponentContainer; +import ohos.agp.components.LayoutScatter; +import ohos.app.Context; + +import java.util.List; + +/** + * Version 1.0 + * ModifiedBy + * date 2021-03-15 10:13 + * description 列表数据适配器 + */ +public abstract class ListAdapter extends BaseItemProvider { + private List data; + private Context ct; + private int itemId; + + public ListAdapter(Context ct, int itemId, List data) { + this.data = data; + this.ct = ct; + this.itemId = itemId; + } + + public abstract void convert(ViewHolder viewHolder, T item, int position); + + @Override + public int getCount() { + return data == null ? 0 : data.size(); + } + + @Override + public T getItem(int i) { + return data.get(i); + } + + @Override + public long getItemId(int i) { + return i; + } + + @Override + public Component getComponent(int i, Component component, ComponentContainer componentContainer) { + ViewHolder viewHolder; + Component itemView = LayoutScatter.getInstance(ct).parse(itemId, componentContainer, false); + viewHolder = new ViewHolder(itemView); + convert(viewHolder, getItem(i), i); + return itemView; + } +} diff --git a/entry/src/main/java/com/ms/square/ohos/expandabletextview/sample/adapter/MainPagerAdapter.java b/entry/src/main/java/com/ms/square/ohos/expandabletextview/sample/adapter/MainPagerAdapter.java new file mode 100644 index 0000000000000000000000000000000000000000..303f085ccb6f9529b5b8008388d674d564311a06 --- /dev/null +++ b/entry/src/main/java/com/ms/square/ohos/expandabletextview/sample/adapter/MainPagerAdapter.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.ms.square.ohos.expandabletextview.sample.adapter; + +import ohos.agp.components.Component; +import ohos.agp.components.ComponentContainer; +import ohos.agp.components.PageSliderProvider; + +import java.util.ArrayList; +import java.util.List; + +/** + * Version 1.0 + * ModifiedBy + * date 2021-03-15 10:13 + * description PageSlider适配器 + */ +public class MainPagerAdapter extends PageSliderProvider { + private List pages; + + /** + * 构造函数 + * + * @param pages 页面 + */ + public MainPagerAdapter(ArrayList pages) { + this.pages = pages; + } + + @Override + public int getCount() { + return pages == null ? 0 : pages.size(); + } + + @Override + public Object createPageInContainer(ComponentContainer componentContainer, int i) { + componentContainer.addComponent(pages.get(i)); + return componentContainer; + } + + @Override + public void destroyPageFromContainer(ComponentContainer componentContainer, int i, Object o) { + componentContainer.removeComponent(pages.get(i)); + } + + @Override + public boolean isPageMatchToObject(Component component, Object object) { + return component == object; + } +} diff --git a/entry/src/main/java/com/ms/square/ohos/expandabletextview/sample/adapter/ViewHolder.java b/entry/src/main/java/com/ms/square/ohos/expandabletextview/sample/adapter/ViewHolder.java new file mode 100644 index 0000000000000000000000000000000000000000..502a406d3a4b7fdc794a597772fb4b894c1ba1fd --- /dev/null +++ b/entry/src/main/java/com/ms/square/ohos/expandabletextview/sample/adapter/ViewHolder.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.ms.square.ohos.expandabletextview.sample.adapter; + +import ohos.agp.components.Component; + +import java.util.HashMap; + +/** + * Version 1.0 + * ModifiedBy + * date 2021-03-15 10:13 + * description ViewHolder + */ +public class ViewHolder { + private Component component; + private HashMap views; + + ViewHolder(Component itemView) { + this.component = itemView; + views = new HashMap<>(0); + component.setTag(this); + } + + public T getView(int viewId) { + Component view = views.get(viewId); + if (view == null) { + view = component.findComponentById(viewId); + views.put(viewId, view); + } + return (T) view; + } +} diff --git a/entry/src/main/java/com/ms/square/ohos/expandabletextview/sample/slice/MainAbilitySlice.java b/entry/src/main/java/com/ms/square/ohos/expandabletextview/sample/slice/MainAbilitySlice.java new file mode 100644 index 0000000000000000000000000000000000000000..87b598669869f9190b74c5762ca74732ab926f56 --- /dev/null +++ b/entry/src/main/java/com/ms/square/ohos/expandabletextview/sample/slice/MainAbilitySlice.java @@ -0,0 +1,161 @@ +/* + * 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.ms.square.ohos.expandabletextview.sample.slice; + +import com.ms.square.ohos.expandabletextview.sample.ResourceTable; +import com.ms.square.ohos.expandabletextview.sample.adapter.MainPagerAdapter; +import com.ms.square.ohos.expandabletextview.sample.utils.ViewCreateHelper; +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import ohos.agp.colors.RgbColor; +import ohos.agp.components.Component; +import ohos.agp.components.DirectionalLayout; +import ohos.agp.components.PageSlider; +import ohos.agp.components.TabList; +import ohos.agp.components.element.ShapeElement; +import ohos.agp.window.service.WindowManager; +import ohos.global.resource.NotExistException; +import ohos.global.resource.WrongTypeException; +import ohos.hiviewdfx.HiLog; +import ohos.hiviewdfx.HiLogLabel; + +import java.io.IOException; +import java.util.ArrayList; + +/** + * Version 1.0 + * ModifiedBy + * date 2021-03-15 10:13 + * description 主界面 + */ +public class MainAbilitySlice extends AbilitySlice implements TabList.TabSelectedListener, + PageSlider.PageChangedListener { + private static final HiLogLabel HI_LOG_LABEL = new HiLogLabel(HiLog.LOG_APP, 0xFFFFF, "MainAbilitySlice"); + private static final int GRAY_COLOR = 211; + private static final int WHITE_COLOR = 0; + private TabList tabList; + private PageSlider pageSlider; + private DirectionalLayout rootLayout; + + @Override + public void onStart(Intent intent) { + // 设置状态栏颜色 + WindowManager.getInstance().getTopWindow().get().setStatusBarColor(getColor(ResourceTable.Color_purple_700)); + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_ability_main); + initView(); + initData(); + } + + private void initView() { + tabList = (TabList) findComponentById(ResourceTable.Id_tab_list); + pageSlider = (PageSlider) findComponentById(ResourceTable.Id_pager); + tabList.addTabSelectedListener(this); + pageSlider.addPageChangedListener(this); + tabList.setFixedMode(true); + rootLayout = (DirectionalLayout) findComponentById(ResourceTable.Id_root); + } + + /** + * 设置tabList + */ + private void initData() { + try { + String[] tabsTitle = getResourceManager().getElement(ResourceTable.Strarray_tab_title).getStringArray(); + for (String title : tabsTitle) { + TabList.Tab tab = tabList.new Tab(getContext()); + tab.setText(title); + ShapeElement shapeElement = new ShapeElement(); + shapeElement.setRgbColor(new RgbColor(0, 0, 0, 0)); + tab.setBackground(shapeElement); + tabList.addTab(tab); + } + tabList.selectTabAt(0); + pageSlider.setProvider(new MainPagerAdapter(initPageSliderViewData())); + pageSlider.setCurrentPage(0); + pageSlider.setReboundEffect(true); + pageSlider.setCentralScrollMode(true); + } catch (IOException | NotExistException | WrongTypeException e) { + HiLog.debug(HI_LOG_LABEL, e.getMessage()); + } + } + + private ArrayList initPageSliderViewData() { + if (tabList == null) { + HiLog.debug(HI_LOG_LABEL, "initPageSliderViewData tabList is null"); + return null; + } + ArrayList pages = new ArrayList<>(); + int pageSize = tabList.getTabCount(); + if (pageSize < 1) { + return pages; + } + ViewCreateHelper viewCreateHelper = new ViewCreateHelper(getContext()); + for (int tabIndex = 0; tabIndex < pageSize; tabIndex++) { + pages.add(viewCreateHelper.createView(tabList.getTabAt(tabIndex).getText(), tabIndex)); + } + return pages; + } + + @Override + public void onActive() { + super.onActive(); + } + + @Override + public void onForeground(Intent intent) { + super.onForeground(intent); + } + + @Override + public void onPageSliding(int i, float v, int i1) { + } + + @Override + public void onPageSlideStateChanged(int i) { + } + + @Override + public void onPageChosen(int i) { + if (tabList.getSelectedTab().getPosition() != i) { + tabList.selectTabAt(i); + } + if (i == 0) { + ShapeElement shapeElement = new ShapeElement(); + shapeElement.setRgbColor(new RgbColor(GRAY_COLOR, GRAY_COLOR, GRAY_COLOR, GRAY_COLOR)); + rootLayout.setBackground(shapeElement); + } else { + ShapeElement shapeElement = new ShapeElement(); + shapeElement.setRgbColor(new RgbColor(WHITE_COLOR, WHITE_COLOR, WHITE_COLOR, WHITE_COLOR)); + rootLayout.setBackground(shapeElement); + } + } + + @Override + public void onSelected(TabList.Tab tab) { + if (pageSlider.getCurrentPage() != tab.getPosition()) { + pageSlider.setCurrentPage(tab.getPosition()); + } + } + + @Override + public void onUnselected(TabList.Tab tab) { + } + + @Override + public void onReselected(TabList.Tab tab) { + } +} diff --git a/entry/src/main/java/com/ms/square/ohos/expandabletextview/sample/utils/MyToast.java b/entry/src/main/java/com/ms/square/ohos/expandabletextview/sample/utils/MyToast.java new file mode 100644 index 0000000000000000000000000000000000000000..bfc84dd1da09db0ef17628e85ffbe59daccbb36f --- /dev/null +++ b/entry/src/main/java/com/ms/square/ohos/expandabletextview/sample/utils/MyToast.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.ms.square.ohos.expandabletextview.sample.utils; + +import ohos.agp.colors.RgbColor; +import ohos.agp.components.DirectionalLayout; +import ohos.agp.components.Text; +import ohos.agp.components.element.ShapeElement; +import ohos.agp.utils.Color; +import ohos.agp.utils.LayoutAlignment; +import ohos.agp.window.dialog.ToastDialog; +import ohos.agp.window.service.DisplayAttributes; +import ohos.agp.window.service.DisplayManager; +import ohos.app.Context; + +/** + * Version 1.0 + * ModifiedBy + * date 2021-03-05 14:46 + * description 自定义Toast + */ +public class MyToast { + public static final int LENGTH_SHORT = 2000; + private static ToastDialog toastDialog; + + public enum ToastLayout { + CENTER, + TOP, + BOTTOM, + } + + public static void show(Context mContext, String content, ToastLayout layout) { + createTost(mContext, content, LENGTH_SHORT, layout); + } + + private static void createTost(Context mContext, String content, int duration, ToastLayout layout) { + DirectionalLayout toastLayout = new DirectionalLayout(mContext); + DirectionalLayout.LayoutConfig textConfig = new DirectionalLayout.LayoutConfig(DirectionalLayout.LayoutConfig.MATCH_CONTENT, DirectionalLayout.LayoutConfig.MATCH_CONTENT); + Text text = new Text(mContext); + text.setText(content); + text.setTextColor(new Color(Color.getIntColor("#ffffff"))); + text.setPadding(vp2px(mContext, 16), vp2px(mContext, 10), vp2px(mContext, 16), vp2px(mContext, 10)); + text.setTextSize(vp2px(mContext, 12)); + text.setBackground(buildDrawableByColorRadius(Color.getIntColor("#70000000"), vp2px(mContext, 20))); + text.setLayoutConfig(textConfig); + text.setMarginBottom(20); + toastLayout.addComponent(text); + int mLayout = LayoutAlignment.CENTER; + switch (layout) { + case TOP: + mLayout = LayoutAlignment.TOP; + break; + case BOTTOM: + mLayout = LayoutAlignment.BOTTOM; + break; + case CENTER: + mLayout = LayoutAlignment.CENTER; + break; + } + if (toastDialog != null) { + toastDialog.cancel(); + toastDialog = null; + } + toastDialog = new ToastDialog(mContext); + toastDialog.setComponent(toastLayout); + toastDialog.setSize(DirectionalLayout.LayoutConfig.MATCH_CONTENT, DirectionalLayout.LayoutConfig.MATCH_CONTENT); + toastDialog.setAlignment(mLayout); + toastDialog.setTransparent(true); + toastDialog.setDuration(duration); + toastDialog.show(); + } + + + private static ohos.agp.components.element.Element buildDrawableByColorRadius(int color, float radius) { + ShapeElement drawable = new ShapeElement(); + drawable.setShape(0); + drawable.setRgbColor(RgbColor.fromArgbInt(color)); + drawable.setCornerRadius(radius); + return drawable; + } + + private static int vp2px(Context context, float vp) { + DisplayAttributes attributes = DisplayManager.getInstance().getDefaultDisplay(context).get().getAttributes(); + return (int) (attributes.densityPixels * vp); + } +} diff --git a/entry/src/main/java/com/ms/square/ohos/expandabletextview/sample/utils/ViewCreateHelper.java b/entry/src/main/java/com/ms/square/ohos/expandabletextview/sample/utils/ViewCreateHelper.java new file mode 100644 index 0000000000000000000000000000000000000000..92e395c2879470353c667f0d23e255186d1f2721 --- /dev/null +++ b/entry/src/main/java/com/ms/square/ohos/expandabletextview/sample/utils/ViewCreateHelper.java @@ -0,0 +1,174 @@ +/* + * 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.ms.square.ohos.expandabletextview.sample.utils; + +import com.ms.square.ohos.expandabletextview.ExpandableTextView; +import com.ms.square.ohos.expandabletextview.sample.ResourceTable; +import com.ms.square.ohos.expandabletextview.sample.adapter.ListAdapter; +import com.ms.square.ohos.expandabletextview.sample.adapter.ViewHolder; +import ohos.agp.components.*; +import ohos.agp.render.Paint; +import ohos.app.Context; +import ohos.hiviewdfx.HiLog; +import ohos.hiviewdfx.HiLogLabel; + +import java.util.ArrayList; +import java.util.List; + +/** + * Version 1.0 + * ModifiedBy + * date 2021-03-15 10:13 + * description ViewCreateHelper + */ +public final class ViewCreateHelper { + private static final HiLogLabel HI_LOG_LABEL = new HiLogLabel(HiLog.LOG_APP, 0xFFFFF, "ViewCreateHelper"); + /** + * 列表长度 + */ + private static final int ITEM_LEN = 10; + private static final int MAX_COLLAPSED_LINES = 4; + private static final int DEFAULT = 2; + private Context slice; + + /** + * 构造函数 + * + * @param abilitySlice Context + */ + public ViewCreateHelper(Context abilitySlice) { + slice = abilitySlice; + } + + /** + * 创建view + * + * @param title 标题 + * @param position 位置 + * @return Component + */ + public Component createView(String title, int position) { + HiLog.debug(HI_LOG_LABEL, "createView position =" + position); + Component mainComponent; + if (position == 0) { + mainComponent = + LayoutScatter.getInstance(slice).parse(ResourceTable.Layout_pager_srcoll_item, null, false); + if (!(mainComponent instanceof ComponentContainer)) { + return mainComponent; + } + ScrollView scrollView = (ScrollView) mainComponent.findComponentById(ResourceTable.Id_scroll); + scrollView.enableScrollBar(1, true); + ComponentContainer rootLayout = (ComponentContainer) mainComponent; + DirectionalLayout root = (DirectionalLayout) rootLayout.findComponentById(ResourceTable.Id_root); + if (null == root){ + return rootLayout; + } + int itemCount = root.getChildCount(); + if (itemCount > 0) { + for (int index = 0; index < itemCount; index++) { + Component component = root.getComponentAt(index); + Text titleText = (Text) component.findComponentById(ResourceTable.Id_title); + titleText.setText("Sample " + (index + 1)); + ExpandableTextView expandableTextView = (ExpandableTextView) + component.findComponentById(ResourceTable.Id_expandable); + expandableTextView.setText(slice.getString(ResourceTable.String_dummy_text2)); + expandableTextView.setOnExpandStateChangeListener(new ExpandableTextView.OnExpandStateChangeListener() { + @Override + public void onExpandStateChanged(Text textView) { + + } + + @Override + public void expandStateChangedToast(boolean isExpanded) { + MyToast.show(slice, isExpanded ? "Expanded" : "Collapsed", MyToast.ToastLayout.BOTTOM); + } + }); + } + } + return rootLayout; + } else { + mainComponent = + LayoutScatter.getInstance(slice).parse(ResourceTable.Layout_pager_item, null, false); + if (!(mainComponent instanceof ComponentContainer)) { + return mainComponent; + } + ComponentContainer rootLayout = (ComponentContainer) mainComponent; + initView(mainComponent, title); + return rootLayout; + } + } + + private float getFontHeight(int fontSize) { + Paint paint = new Paint(); + paint.setTextSize(fontSize); + Paint.FontMetrics fm = paint.getFontMetrics(); + + return (float) ((Math.ceil((double) fm.descent - (double) fm.top) + DEFAULT) * MAX_COLLAPSED_LINES); + } + + ListAdapter listAdapter = null; + + private void initView(Component mainComponent, String title) { + // 列表 + ListContainer listContainer = (ListContainer) mainComponent.findComponentById(ResourceTable.Id_list_main); + listContainer.enableScrollBar(1, true); + listAdapter = new ListAdapter(slice, ResourceTable.Layout_text_item, getData()) { + @Override + public void convert(ViewHolder viewHolder, String item, int position) { + Text text = viewHolder.getView(ResourceTable.Id_expandable_text); + text.setTag(position + ""); + text.setHeight((int) getFontHeight(text.getTextSize())); + ExpandableTextView expandableTextView = viewHolder.getView(ResourceTable.Id_expandable); + expandableTextView.setText(slice.getString(ResourceTable.String_dummy_text2)); + expandableTextView.setOnExpandStateChangeListener(new ExpandableTextView.OnExpandStateChangeListener() { + @Override + public void onExpandStateChanged(Text textView) { + int position = Integer.valueOf(textView.getTag().toString()).intValue(); + listAdapter.notifyDataSetItemChanged(position + 1); + } + + @Override + public void expandStateChangedToast(boolean isExpanded) { + MyToast.show(slice, isExpanded ? "Expanded" : "Collapsed", MyToast.ToastLayout.BOTTOM); + } + }); + } + }; + listContainer.setLayoutRefreshedListener(new Component.LayoutRefreshedListener() { + @Override + public void onRefreshed(Component component) { + if (listContainer.getHeight() < ((ComponentContainer) (component.getComponentParent())).getHeight()) { + listContainer.setEnabled(false); + } else { + listContainer.setEnabled(true); + } + } + }); + listContainer.setItemProvider(listAdapter); + listContainer.setItemClickedListener(new ListContainer.ItemClickedListener() { + @Override + public void onItemClicked(ListContainer listContainer, Component component, int position, long l) { + } + }); + } + + private List getData() { + List curData = new ArrayList<>(); + for (int index = 0; index < ITEM_LEN; index++) { + curData.add("测试"); + } + return curData; + } +} diff --git a/entry/src/main/resources/base/element/color.json b/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..b97ca3eb1732b351ab554fef1ec7728fded6d38e --- /dev/null +++ b/entry/src/main/resources/base/element/color.json @@ -0,0 +1,40 @@ +{ + "color": [ + { + "name": "advertise", + "value": "#FFFFFF" + }, + { + "name": "skip", + "value": "#FFFFFF" + }, + { + "name": "copyright_text_color", + "value": "#99000000" + }, + { + "name": "app_title_text_color", + "value": "#E6000000" + }, + { + "name": "purple_200", + "value": "#FFBB86FC" + }, + { + "name": "purple_500", + "value": "#FF6200EE" + }, + { + "name": "purple_700", + "value": "#FF3700B3" + }, + { + "name": "teal_200", + "value": "#FF03DAC5" + }, + { + "name": "teal_700", + "value": "#FF018786" + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/base/element/float.json b/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..c077a3ce8ec268d2f6bb1b5bef2eb92236330f0f --- /dev/null +++ b/entry/src/main/resources/base/element/float.json @@ -0,0 +1,84 @@ +{ + "float": [ + { + "name": "advertise_bottom_margin", + "value": "10vp" + }, + { + "name": "advertise_left_margin", + "value": "10vp" + }, + { + "name": "advertise_width", + "value": "40vp" + }, + { + "name": "advertise_height", + "value": "17vp" + }, + { + "name": "advertise_text_size", + "value": "8fp" + }, + { + "name": "skip_height", + "value": "29vp" + }, + { + "name": "skip_width", + "value": "56vp" + }, + { + "name": "skip_button_right_margin", + "value": "20vp" + }, + { + "name": "skip_button_top_margin", + "value": "20vp" + }, + { + "name": "skip_left_margin", + "value": "9vp" + }, + { + "name": "skip_right_margin", + "value": "10vp" + }, + { + "name": "skip_text_size", + "value": "12fp" + }, + { + "name": "copyright_text_size", + "value": "8fp" + }, + { + "name": "copyright_top_margin", + "value": "12vp" + }, + { + "name": "app_title_text_size", + "value": "21fp" + }, + { + "name": "app_icon_height", + "value": "36vp" + }, + { + "name": "app_icon_width", + "value": "36vp" + }, + { + "name": "app_icon_right_margin", + "value": "12vp" + }, + { + "name": "bottom_bar_height", + "value": "92vp" + }, + { + "name": "app_title_top_margin", + "value": "12vp" + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/base/element/integer.json b/entry/src/main/resources/base/element/integer.json new file mode 100644 index 0000000000000000000000000000000000000000..11a0b6feadec7803b1d0c7c6d2e53074f68bc6ff --- /dev/null +++ b/entry/src/main/resources/base/element/integer.json @@ -0,0 +1,12 @@ +{ + "integer": [ + { + "name": "ImageButton", + "value": 0 + }, + { + "name": "TextView", + "value": 1 + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/base/element/strarray.json b/entry/src/main/resources/base/element/strarray.json new file mode 100644 index 0000000000000000000000000000000000000000..71752b0d7fdf931b31377679148575c069d07a5c --- /dev/null +++ b/entry/src/main/resources/base/element/strarray.json @@ -0,0 +1,15 @@ +{ + "strarray": [ + { + "name": "tab_title", + "value": [ + { + "value": "IN SCROLLVIEW" + }, + { + "value": "IN LISTVIEW" + } + ] + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..b60ae8e9024704754e6b7a24db4cf552bc21a619 --- /dev/null +++ b/entry/src/main/resources/base/element/string.json @@ -0,0 +1,44 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ExpandableTextView Demo" + }, + { + "name": "mainability_description", + "value": "Java_Phone_Empty Feature Ability" + }, + { + "name": "textId", + "value": "expandable_text" + }, + { + "name": "imageId", + "value": "expand_collapse" + }, + { + "name": "expand_less", + "value": "收缩" + }, + { + "name": "expand_more", + "value": "展开" + }, + { + "name": "ExpandableTextId", + "value": "expandable_text" + }, + { + "name": "ExpandCollapseToggleId", + "value": "expand_collapse" + }, + { + "name": "dummy_text1", + "value": "Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar." + }, + { + "name": "dummy_text2", + "value": "Lorem, ipsum dolor sit amett aante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc, quis gravida magna mi a libero. Fusce vulputate eleifend sapien." + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/base/graphic/background_ability_main.xml b/entry/src/main/resources/base/graphic/background_ability_main.xml new file mode 100644 index 0000000000000000000000000000000000000000..05e7b6be04e01877279b69ad26866e30c7ecfc4e --- /dev/null +++ b/entry/src/main/resources/base/graphic/background_ability_main.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/graphic/button_skip.xml b/entry/src/main/resources/base/graphic/button_skip.xml new file mode 100644 index 0000000000000000000000000000000000000000..4a5d15383436de0f9fbfdfa44a6121a36994a518 --- /dev/null +++ b/entry/src/main/resources/base/graphic/button_skip.xml @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/graphic/icon_app.xml b/entry/src/main/resources/base/graphic/icon_app.xml new file mode 100644 index 0000000000000000000000000000000000000000..f37c0fddbda88b3a9ecec0c9835e85c2a28ff618 --- /dev/null +++ b/entry/src/main/resources/base/graphic/icon_app.xml @@ -0,0 +1,15 @@ + + + + + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/graphic/mark_advertise.xml b/entry/src/main/resources/base/graphic/mark_advertise.xml new file mode 100644 index 0000000000000000000000000000000000000000..757d0b1bc77f1aea4bc9da7115843513b881fc13 --- /dev/null +++ b/entry/src/main/resources/base/graphic/mark_advertise.xml @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/graphic/title_bg.xml b/entry/src/main/resources/base/graphic/title_bg.xml new file mode 100644 index 0000000000000000000000000000000000000000..6c1be6294c1b65b7e3d67f864a03f568b294f2f2 --- /dev/null +++ b/entry/src/main/resources/base/graphic/title_bg.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/layout/ability_main.xml b/entry/src/main/resources/base/layout/ability_main.xml new file mode 100644 index 0000000000000000000000000000000000000000..93de30464ff7008a3cc67f8f4538e030b8cf0700 --- /dev/null +++ b/entry/src/main/resources/base/layout/ability_main.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/layout/pager_item.xml b/entry/src/main/resources/base/layout/pager_item.xml new file mode 100644 index 0000000000000000000000000000000000000000..8b3a56a95b061a20bf8e12683da4bb0042dfc31e --- /dev/null +++ b/entry/src/main/resources/base/layout/pager_item.xml @@ -0,0 +1,19 @@ + + + + + + diff --git a/entry/src/main/resources/base/layout/pager_srcoll_item.xml b/entry/src/main/resources/base/layout/pager_srcoll_item.xml new file mode 100644 index 0000000000000000000000000000000000000000..ed0d01657c9ecb254b137b52dc2b5c689be7abec --- /dev/null +++ b/entry/src/main/resources/base/layout/pager_srcoll_item.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/entry/src/main/resources/base/layout/text_item.xml b/entry/src/main/resources/base/layout/text_item.xml new file mode 100644 index 0000000000000000000000000000000000000000..3ad58a10c0afc6333091d30955abdb41a628a254 --- /dev/null +++ b/entry/src/main/resources/base/layout/text_item.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + diff --git a/entry/src/main/resources/base/layout/text_item_scroll.xml b/entry/src/main/resources/base/layout/text_item_scroll.xml new file mode 100644 index 0000000000000000000000000000000000000000..714cdc96ce7339a66b2ec0b74af2b2cc66233ecb --- /dev/null +++ b/entry/src/main/resources/base/layout/text_item_scroll.xml @@ -0,0 +1,25 @@ + + + + + + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/layout/text_item_scroll_test.xml b/entry/src/main/resources/base/layout/text_item_scroll_test.xml new file mode 100644 index 0000000000000000000000000000000000000000..0b53569b83c1d45d62891d1ce3b96c07f674c058 --- /dev/null +++ b/entry/src/main/resources/base/layout/text_item_scroll_test.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/src/main/res/drawable-xxxhdpi/ic_expand_less_black_12dp.png b/entry/src/main/resources/base/media/ic_expand_less_black_12dp.png similarity index 100% rename from lib/src/main/res/drawable-xxxhdpi/ic_expand_less_black_12dp.png rename to entry/src/main/resources/base/media/ic_expand_less_black_12dp.png diff --git a/lib/src/main/res/drawable-xxxhdpi/ic_expand_less_black_16dp.png b/entry/src/main/resources/base/media/ic_expand_less_black_16dp.png similarity index 100% rename from lib/src/main/res/drawable-xxxhdpi/ic_expand_less_black_16dp.png rename to entry/src/main/resources/base/media/ic_expand_less_black_16dp.png diff --git a/lib/src/main/res/drawable-xxxhdpi/ic_expand_more_black_12dp.png b/entry/src/main/resources/base/media/ic_expand_more_black_12dp.png similarity index 100% rename from lib/src/main/res/drawable-xxxhdpi/ic_expand_more_black_12dp.png rename to entry/src/main/resources/base/media/ic_expand_more_black_12dp.png diff --git a/lib/src/main/res/drawable-xxxhdpi/ic_expand_more_black_16dp.png b/entry/src/main/resources/base/media/ic_expand_more_black_16dp.png similarity index 100% rename from lib/src/main/res/drawable-xxxhdpi/ic_expand_more_black_16dp.png rename to entry/src/main/resources/base/media/ic_expand_more_black_16dp.png diff --git a/entry/src/main/resources/base/media/icon.png b/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/entry/src/main/resources/base/media/icon.png differ diff --git a/entry/src/ohosTest/config.json b/entry/src/ohosTest/config.json new file mode 100644 index 0000000000000000000000000000000000000000..7ce86206d8fecc333510045bcd7ec2201771cecb --- /dev/null +++ b/entry/src/ohosTest/config.json @@ -0,0 +1,41 @@ +{ + "app": { + "bundleName": "com.hos.expandabletextview", + "vendor": "hos", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 5, + "target": 5, + "releaseType": "Release" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.hos.expandabletextview", + "name": "testModule", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry_test", + "moduleType": "feature", + "installationFree": true + }, + "abilities": [ + { + "name": "decc.testkit.runner.EntryAbility", + "description": "Test Entry Ability", + "icon": "$media:icon", + "label": "$string:app_name", + "launchType": "standard", + "orientation": "landscape", + "visible": true, + "type": "page" + } + ] + } +} \ No newline at end of file diff --git a/entry/src/ohosTest/java/com/hos/expandabletextview/ExampleOhosTest.java b/entry/src/ohosTest/java/com/hos/expandabletextview/ExampleOhosTest.java new file mode 100644 index 0000000000000000000000000000000000000000..5a391233b51b8c05270f8566a045ca99e99e083d --- /dev/null +++ b/entry/src/ohosTest/java/com/hos/expandabletextview/ExampleOhosTest.java @@ -0,0 +1,17 @@ +package com.hos.expandabletextview; + +import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class ExampleOhosTest { + /** + * 全UI应用、不支持Context,不支持单元测试 + */ + @Test + public void testBundleName() { + final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName(); + assertEquals("com.hos.expandabletext", actualBundleName); + } +} \ No newline at end of file diff --git a/entry/src/test/java/com/hos/expandabletextview/ExampleTest.java b/entry/src/test/java/com/hos/expandabletextview/ExampleTest.java new file mode 100644 index 0000000000000000000000000000000000000000..7adf7dabc1b1be4cc15bce137f21b0e0660b51a1 --- /dev/null +++ b/entry/src/test/java/com/hos/expandabletextview/ExampleTest.java @@ -0,0 +1,9 @@ +package com.hos.expandabletextview; + +import org.junit.Test; + +public class ExampleTest { + @Test + public void onStart() { + } +} diff --git a/gradle.properties b/gradle.properties index 1bf02e37c9838dec2e4a13772560a0e2ce6aecba..0daf1830fbdef07e50a44d74210c8c82f1b66278 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,34 +1,10 @@ # Project-wide Gradle settings. - -# IDE (e.g. Android Studio) users: -# Settings specified in this file will override any Gradle settings -# configured through the IDE. - +# IDE (e.g. DevEco Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. # For more details on how to configure your build environment visit # http://www.gradle.org/docs/current/userguide/build_environment.html - # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. -# Default value: -Xmx10248m -XX:MaxPermSize=256m -# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 - -# When configured, Gradle will run in incubating parallel mode. -# This option should only be used with decoupled projects. More details, visit -# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true - -# For maven central -VERSION_NAME=0.1.4 -VERSION_CODE=4 -GROUP=com.ms-square - -POM_DESCRIPTION=Android library that allows developers to easily create an TextView which can expand/collapse just like the Google Play's app description. -POM_URL=https://github.com/Manabu-GT/ExpandableTextView -POM_SCM_URL=https://github.com/Manabu-GT/ExpandableTextView -POM_SCM_CONNECTION=scm:git@github.com:Manabu-GT/ExpandableTextView.git -POM_SCM_DEV_CONNECTION=scm:git@github.com:Manabu-GT/ExpandableTextView.git -POM_LICENCE_NAME=The Apache Software License, Version 2.0 -POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt -POM_LICENCE_DIST=repo -POM_DEVELOPER_ID=Manabu-GT -POM_DEVELOPER_NAME=Manabu Shimobe \ No newline at end of file +# If the Chinese output is garbled, please configure the following parameter. +# org.gradle.jvmargs=-Dfile.encoding=GBK diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 8c0fb64a8698b08ecc4158d828ca593c4928e9dd..490fda8577df6c95960ba7077c43220e5bb2c0d9 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 04807e144962a7cc4c76ada9b78d4ad57cf9c777..f59159e865d4b59feb1b8c44b001f62fc5d58df4 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Sat Jun 04 15:13:19 IST 2016 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 -distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip diff --git a/gradlew b/gradlew index 91a7e269e19dfc62e27137a0b57ef3e430cee4fd..2fe81a7d95e4f9ad2c9b2a046707d36ceb3980b3 100755 --- a/gradlew +++ b/gradlew @@ -1,4 +1,20 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# 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 +# +# https://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. +# ############################################################################## ## @@ -6,20 +22,38 @@ ## ############################################################################## -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" -warn ( ) { +warn () { echo "$*" } -die ( ) { +die () { echo echo "$*" echo @@ -30,6 +64,7 @@ die ( ) { cygwin=false msys=false darwin=false +nonstop=false case "`uname`" in CYGWIN* ) cygwin=true @@ -40,31 +75,11 @@ case "`uname`" in MINGW* ) msys=true ;; + NONSTOP* ) + nonstop=true + ;; esac -# For Cygwin, ensure paths are in UNIX format before anything is touched. -if $cygwin ; then - [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` -fi - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >&- -APP_HOME="`pwd -P`" -cd "$SAVED" >&- - CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. @@ -90,7 +105,7 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then MAX_FD_LIMIT=`ulimit -H -n` if [ $? -eq 0 ] ; then if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then @@ -110,10 +125,11 @@ if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` @@ -138,27 +154,30 @@ if $cygwin ; then else eval `echo args$i`="\"$arg\"" fi - i=$((i+1)) + i=`expr $i + 1` done case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; esac fi -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " } -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index aec99730b4e8fcd90b57a0e8e01544fea7c31a89..62bd9b9ccefea2b65ae41e5d9a545e2021b90a1d 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,90 +1,103 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windowz variants - -if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/img/demo.gif b/img/demo.gif new file mode 100644 index 0000000000000000000000000000000000000000..b7f2fbd451ba172a33e131b67f6aed92d7e77df2 Binary files /dev/null and b/img/demo.gif differ diff --git a/lib/build.gradle b/lib/build.gradle index 63c643bebca50b95b6650ec9cbab86bde6643c84..d5ee65bbf9bcfb996297049bb0c93314c583d56c 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -1,27 +1,14 @@ -apply plugin: 'android-library' - -android { - - compileSdkVersion project.ANDROID_COMPILE_SDK_VERSION - buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION +apply plugin: 'com.huawei.ohos.library' +ohos { + compileSdkVersion 6 defaultConfig { - minSdkVersion project.ANDROID_MIN_SDK_VERSION - targetSdkVersion project.ANDROID_TARGET_SDK_VERSION - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' - } + compatibleSdkVersion 5 } + } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - // to support annotations such as @NonNull - compile "com.android.support:support-annotations:${supportPackageVersion}" + implementation fileTree(dir: 'libs', include: ['*.jar']) + testCompile 'junit:junit:4.12' } - -// for maven central deployment -apply from: 'https://raw.githubusercontent.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle' \ No newline at end of file diff --git a/lib/gradle.properties b/lib/gradle.properties deleted file mode 100644 index dd79e8c757764ebfb22a0dca2289176dfafb2610..0000000000000000000000000000000000000000 --- a/lib/gradle.properties +++ /dev/null @@ -1,4 +0,0 @@ -# For maven central -POM_NAME=ExpandableTextView Library -POM_ARTIFACT_ID=expandableTextView -POM_PACKAGING=aar \ No newline at end of file diff --git a/lib/proguard-rules.txt b/lib/proguard-rules.txt deleted file mode 100644 index cb8998dd02e6e21616d855056c1ab35143efba29..0000000000000000000000000000000000000000 --- a/lib/proguard-rules.txt +++ /dev/null @@ -1,17 +0,0 @@ -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in /Applications/Android Studio.app/sdk/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the ProGuard -# include property in project.properties. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} \ No newline at end of file diff --git a/lib/src/main/AndroidManifest.xml b/lib/src/main/AndroidManifest.xml deleted file mode 100644 index 83d192bced128876d1265847f5cf58c58f01abeb..0000000000000000000000000000000000000000 --- a/lib/src/main/AndroidManifest.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/lib/src/main/config.json b/lib/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..c1564b6ae997eef6102fc228f9a016c2c3e16624 --- /dev/null +++ b/lib/src/main/config.json @@ -0,0 +1,22 @@ +{ + "app": { + "bundleName": "com.ms.square.ohos.expandabletextview", + "vendor": "loopj", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.ms.square.ohos.expandabletextview", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "lib", + "moduleType": "har" + } + } +} \ No newline at end of file diff --git a/lib/src/main/java/com/ms/square/android/expandabletextview/ExpandableTextView.java b/lib/src/main/java/com/ms/square/android/expandabletextview/ExpandableTextView.java deleted file mode 100644 index fb1b867fa97d6f8084942b0b790d4942bebfd82c..0000000000000000000000000000000000000000 --- a/lib/src/main/java/com/ms/square/android/expandabletextview/ExpandableTextView.java +++ /dev/null @@ -1,460 +0,0 @@ -/* - * Copyright (C) 2011 The Android Open Source Project - * Copyright 2014 Manabu Shimobe - * - * 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.ms.square.android.expandabletextview; - -import android.annotation.TargetApi; -import android.content.Context; -import android.content.res.Resources; -import android.content.res.TypedArray; -import android.graphics.drawable.Drawable; -import android.os.Build; -import android.support.annotation.DrawableRes; -import android.support.annotation.IdRes; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.text.TextUtils; -import android.util.AttributeSet; -import android.util.SparseBooleanArray; -import android.view.MotionEvent; -import android.view.View; -import android.view.ViewGroup; -import android.view.animation.AlphaAnimation; -import android.view.animation.Animation; -import android.view.animation.Transformation; -import android.widget.ImageButton; -import android.widget.LinearLayout; -import android.widget.TextView; - - -public class ExpandableTextView extends LinearLayout implements View.OnClickListener { - - private static final String TAG = ExpandableTextView.class.getSimpleName(); - - private static final int EXPAND_INDICATOR_IMAGE_BUTTON = 0; - - private static final int EXPAND_INDICATOR_TEXT_VIEW = 1; - - private static final int DEFAULT_TOGGLE_TYPE = EXPAND_INDICATOR_IMAGE_BUTTON; - - /* The default number of lines */ - private static final int MAX_COLLAPSED_LINES = 8; - - /* The default animation duration */ - private static final int DEFAULT_ANIM_DURATION = 300; - - /* The default alpha value when the animation starts */ - private static final float DEFAULT_ANIM_ALPHA_START = 0.7f; - - protected TextView mTv; - - protected View mToggleView; // View to expand/collapse - - private boolean mRelayout; - - private boolean mCollapsed = true; // Show short version as default. - - private int mCollapsedHeight; - - private int mTextHeightWithMaxLines; - - private int mMaxCollapsedLines; - - private int mMarginBetweenTxtAndBottom; - - private ExpandIndicatorController mExpandIndicatorController; - - private int mAnimationDuration; - - private float mAnimAlphaStart; - - private boolean mAnimating; - - @IdRes - private int mExpandableTextId = R.id.expandable_text; - - @IdRes - private int mExpandCollapseToggleId = R.id.expand_collapse; - - private boolean mExpandToggleOnTextClick; - - /* Listener for callback */ - private OnExpandStateChangeListener mListener; - - /* For saving collapsed status when used in ListView */ - private SparseBooleanArray mCollapsedStatus; - private int mPosition; - - public ExpandableTextView(Context context) { - this(context, null); - } - - public ExpandableTextView(Context context, AttributeSet attrs) { - super(context, attrs); - init(attrs); - } - - @TargetApi(Build.VERSION_CODES.HONEYCOMB) - public ExpandableTextView(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - init(attrs); - } - - @Override - public void setOrientation(int orientation){ - if(LinearLayout.HORIZONTAL == orientation){ - throw new IllegalArgumentException("ExpandableTextView only supports Vertical Orientation."); - } - super.setOrientation(orientation); - } - - @Override - public void onClick(View view) { - if (mToggleView.getVisibility() != View.VISIBLE) { - return; - } - - mCollapsed = !mCollapsed; - mExpandIndicatorController.changeState(mCollapsed); - - if (mCollapsedStatus != null) { - mCollapsedStatus.put(mPosition, mCollapsed); - } - - // mark that the animation is in progress - mAnimating = true; - - Animation animation; - if (mCollapsed) { - animation = new ExpandCollapseAnimation(this, getHeight(), mCollapsedHeight); - } else { - animation = new ExpandCollapseAnimation(this, getHeight(), getHeight() + - mTextHeightWithMaxLines - mTv.getHeight()); - } - - animation.setFillAfter(true); - animation.setAnimationListener(new Animation.AnimationListener() { - @Override - public void onAnimationStart(Animation animation) { - applyAlphaAnimation(mTv, mAnimAlphaStart); - } - @Override - public void onAnimationEnd(Animation animation) { - // clear animation here to avoid repeated applyTransformation() calls - clearAnimation(); - // clear the animation flag - mAnimating = false; - - // notify the listener - if (mListener != null) { - mListener.onExpandStateChanged(mTv, !mCollapsed); - } - } - @Override - public void onAnimationRepeat(Animation animation) { } - }); - - clearAnimation(); - startAnimation(animation); - } - - @Override - public boolean onInterceptTouchEvent(MotionEvent ev) { - // while an animation is in progress, intercept all the touch events to children to - // prevent extra clicks during the animation - return mAnimating; - } - - @Override - protected void onFinishInflate() { - super.onFinishInflate(); - findViews(); - } - - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - // If no change, measure and return - if (!mRelayout || getVisibility() == View.GONE) { - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - return; - } - mRelayout = false; - - // Setup with optimistic case - // i.e. Everything fits. No button needed - mToggleView.setVisibility(View.GONE); - mTv.setMaxLines(Integer.MAX_VALUE); - - // Measure - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - - // If the text fits in collapsed mode, we are done. - if (mTv.getLineCount() <= mMaxCollapsedLines) { - return; - } - - // Saves the text height w/ max lines - mTextHeightWithMaxLines = getRealTextViewHeight(mTv); - - // Doesn't fit in collapsed mode. Collapse text view as needed. Show - // button. - if (mCollapsed) { - mTv.setMaxLines(mMaxCollapsedLines); - } - mToggleView.setVisibility(View.VISIBLE); - - // Re-measure with new setup - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - - if (mCollapsed) { - // Gets the margin between the TextView's bottom and the ViewGroup's bottom - mTv.post(new Runnable() { - @Override - public void run() { - mMarginBetweenTxtAndBottom = getHeight() - mTv.getHeight(); - } - }); - // Saves the collapsed height of this ViewGroup - mCollapsedHeight = getMeasuredHeight(); - } - } - - public void setOnExpandStateChangeListener(@Nullable OnExpandStateChangeListener listener) { - mListener = listener; - } - - public void setText(@Nullable CharSequence text) { - mRelayout = true; - mTv.setText(text); - setVisibility(TextUtils.isEmpty(text) ? View.GONE : View.VISIBLE); - clearAnimation(); - getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT; - requestLayout(); - } - - public void setText(@Nullable CharSequence text, @NonNull SparseBooleanArray collapsedStatus, int position) { - mCollapsedStatus = collapsedStatus; - mPosition = position; - boolean isCollapsed = collapsedStatus.get(position, true); - clearAnimation(); - mCollapsed = isCollapsed; - mExpandIndicatorController.changeState(mCollapsed); - setText(text); - } - - @Nullable - public CharSequence getText() { - if (mTv == null) { - return ""; - } - return mTv.getText(); - } - - private void init(AttributeSet attrs) { - TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ExpandableTextView); - mMaxCollapsedLines = typedArray.getInt(R.styleable.ExpandableTextView_maxCollapsedLines, MAX_COLLAPSED_LINES); - mAnimationDuration = typedArray.getInt(R.styleable.ExpandableTextView_animDuration, DEFAULT_ANIM_DURATION); - mAnimAlphaStart = typedArray.getFloat(R.styleable.ExpandableTextView_animAlphaStart, DEFAULT_ANIM_ALPHA_START); - mExpandableTextId = typedArray.getResourceId(R.styleable.ExpandableTextView_expandableTextId, R.id.expandable_text); - mExpandCollapseToggleId = typedArray.getResourceId(R.styleable.ExpandableTextView_expandCollapseToggleId, R.id.expand_collapse); - mExpandToggleOnTextClick = typedArray.getBoolean(R.styleable.ExpandableTextView_expandToggleOnTextClick, true); - - mExpandIndicatorController = setupExpandToggleController(getContext(), typedArray); - - typedArray.recycle(); - - // enforces vertical orientation - setOrientation(LinearLayout.VERTICAL); - - // default visibility is gone - setVisibility(GONE); - } - - private void findViews() { - mTv = (TextView) findViewById(mExpandableTextId); - if (mExpandToggleOnTextClick) { - mTv.setOnClickListener(this); - } else { - mTv.setOnClickListener(null); - } - mToggleView = findViewById(mExpandCollapseToggleId); - mExpandIndicatorController.setView(mToggleView); - mExpandIndicatorController.changeState(mCollapsed); - mToggleView.setOnClickListener(this); - } - - private static boolean isPostHoneycomb() { - return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB; - } - - private static boolean isPostLolipop() { - return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP; - } - - @TargetApi(Build.VERSION_CODES.HONEYCOMB) - private static void applyAlphaAnimation(View view, float alpha) { - if (isPostHoneycomb()) { - view.setAlpha(alpha); - } else { - AlphaAnimation alphaAnimation = new AlphaAnimation(alpha, alpha); - // make it instant - alphaAnimation.setDuration(0); - alphaAnimation.setFillAfter(true); - view.startAnimation(alphaAnimation); - } - } - - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - private static Drawable getDrawable(@NonNull Context context, @DrawableRes int resId) { - Resources resources = context.getResources(); - if (isPostLolipop()) { - return resources.getDrawable(resId, context.getTheme()); - } else { - return resources.getDrawable(resId); - } - } - - private static int getRealTextViewHeight(@NonNull TextView textView) { - int textHeight = textView.getLayout().getLineTop(textView.getLineCount()); - int padding = textView.getCompoundPaddingTop() + textView.getCompoundPaddingBottom(); - return textHeight + padding; - } - - private static ExpandIndicatorController setupExpandToggleController(@NonNull Context context, TypedArray typedArray) { - final int expandToggleType = typedArray.getInt(R.styleable.ExpandableTextView_expandToggleType, DEFAULT_TOGGLE_TYPE); - final ExpandIndicatorController expandIndicatorController; - switch (expandToggleType) { - case EXPAND_INDICATOR_IMAGE_BUTTON: - Drawable expandDrawable = typedArray.getDrawable(R.styleable.ExpandableTextView_expandIndicator); - Drawable collapseDrawable = typedArray.getDrawable(R.styleable.ExpandableTextView_collapseIndicator); - - if (expandDrawable == null) { - expandDrawable = getDrawable(context, R.drawable.ic_expand_more_black_12dp); - } - if (collapseDrawable == null) { - collapseDrawable = getDrawable(context, R.drawable.ic_expand_less_black_12dp); - } - expandIndicatorController = new ImageButtonExpandController(expandDrawable, collapseDrawable); - break; - case EXPAND_INDICATOR_TEXT_VIEW: - String expandText = typedArray.getString(R.styleable.ExpandableTextView_expandIndicator); - String collapseText = typedArray.getString(R.styleable.ExpandableTextView_collapseIndicator); - expandIndicatorController = new TextViewExpandController(expandText, collapseText); - break; - default: - throw new IllegalStateException("Must be of enum: ExpandableTextView_expandToggleType, one of EXPAND_INDICATOR_IMAGE_BUTTON or EXPAND_INDICATOR_TEXT_VIEW."); - } - - return expandIndicatorController; - } - - class ExpandCollapseAnimation extends Animation { - private final View mTargetView; - private final int mStartHeight; - private final int mEndHeight; - - public ExpandCollapseAnimation(View view, int startHeight, int endHeight) { - mTargetView = view; - mStartHeight = startHeight; - mEndHeight = endHeight; - setDuration(mAnimationDuration); - } - - @Override - protected void applyTransformation(float interpolatedTime, Transformation t) { - final int newHeight = (int)((mEndHeight - mStartHeight) * interpolatedTime + mStartHeight); - mTv.setMaxHeight(newHeight - mMarginBetweenTxtAndBottom); - if (Float.compare(mAnimAlphaStart, 1.0f) != 0) { - applyAlphaAnimation(mTv, mAnimAlphaStart + interpolatedTime * (1.0f - mAnimAlphaStart)); - } - mTargetView.getLayoutParams().height = newHeight; - mTargetView.requestLayout(); - } - - @Override - public void initialize( int width, int height, int parentWidth, int parentHeight ) { - super.initialize(width, height, parentWidth, parentHeight); - } - - @Override - public boolean willChangeBounds( ) { - return true; - } - } - - public interface OnExpandStateChangeListener { - /** - * Called when the expand/collapse animation has been finished - * - * @param textView - TextView being expanded/collapsed - * @param isExpanded - true if the TextView has been expanded - */ - void onExpandStateChanged(TextView textView, boolean isExpanded); - } - - interface ExpandIndicatorController { - void changeState(boolean collapsed); - - void setView(View toggleView); - } - - static class ImageButtonExpandController implements ExpandIndicatorController { - - private final Drawable mExpandDrawable; - private final Drawable mCollapseDrawable; - - private ImageButton mImageButton; - - public ImageButtonExpandController(Drawable expandDrawable, Drawable collapseDrawable) { - mExpandDrawable = expandDrawable; - mCollapseDrawable = collapseDrawable; - } - - @Override - public void changeState(boolean collapsed) { - mImageButton.setImageDrawable(collapsed ? mExpandDrawable : mCollapseDrawable); - } - - @Override - public void setView(View toggleView) { - mImageButton = (ImageButton) toggleView; - } - } - - static class TextViewExpandController implements ExpandIndicatorController { - - private final String mExpandText; - private final String mCollapseText; - - private TextView mTextView; - - public TextViewExpandController(String expandText, String collapseText) { - mExpandText = expandText; - mCollapseText = collapseText; - } - - @Override - public void changeState(boolean collapsed) { - mTextView.setText(collapsed ? mExpandText : mCollapseText); - } - - @Override - public void setView(View toggleView) { - mTextView = (TextView) toggleView; - } - } -} \ No newline at end of file diff --git a/lib/src/main/java/com/ms/square/ohos/expandabletextview/ExpandableTextView.java b/lib/src/main/java/com/ms/square/ohos/expandabletextview/ExpandableTextView.java new file mode 100644 index 0000000000000000000000000000000000000000..76c368a1d1ea8e3a4b793d3ed3aabcceff045c54 --- /dev/null +++ b/lib/src/main/java/com/ms/square/ohos/expandabletextview/ExpandableTextView.java @@ -0,0 +1,528 @@ +/* + * Copyright (C) 2011 The Open Source Project + * Copyright 2014 Manabu Shimobe + * + * 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.ms.square.ohos.expandabletextview; + +import ohos.agp.animation.Animator; +import ohos.agp.animation.AnimatorValue; +import ohos.agp.components.*; +import ohos.agp.components.element.PixelMapElement; +import ohos.agp.render.Canvas; +import ohos.agp.render.Paint; +import ohos.app.Context; +import ohos.hiviewdfx.HiLog; +import ohos.hiviewdfx.HiLogLabel; +import ohos.media.image.ImageSource; +import ohos.media.image.PixelMap; +import ohos.media.image.common.PixelFormat; +import ohos.media.image.common.Rect; +import ohos.media.image.common.Size; + +import java.io.InputStream; +import java.util.Map; + +public class ExpandableTextView extends DirectionalLayout implements + Component.EstimateSizeListener, Component.ClickedListener, ComponentContainer.ArrangeListener { + private static final HiLogLabel logLabel = new HiLogLabel(HiLog.LOG_APP, 0x00101, "ExpandableTextView"); + + private static final int EXPAND_INDICATOR_IMAGE_BUTTON = 0; + + private static final int EXPAND_INDICATOR_TEXT_VIEW = 1; + + private static final int DEFAULT_TOGGLE_TYPE = EXPAND_INDICATOR_IMAGE_BUTTON; + + /* The default number of lines */ + private static final int MAX_COLLAPSED_LINES = 4; + + /* The default animation duration */ + private static final int DEFAULT_ANIM_DURATION = 300; + + /* The default alpha value when the animation starts */ + private static final float DEFAULT_ANIM_ALPHA_START = 0.7f; + + private boolean mRelayout = true; + + // Show short version as default. + private boolean mCollapsed = true; + + private int mCollapsedHeight; + + private double singleTextHeight; + /** + * 内容展示Text + */ + private Text expandText; + + /** + * 展开,收缩图标 + * View to expand/collapse + */ + private Component expandCollapse; + + /** + * 最大展示行数 + */ + private int maxCollapsedLines; + + private int mMarginBetweenTxtAndBottom; + + /** + * 文本是否可以被点击 + */ + private boolean expandToggleOnTextClick; + + + private ExpandIndicatorController mExpandIndicatorController; + + /** + * 动画展示时长 + */ + private int animationDuration; + + /** + * 起始透明度 + */ + private float animAlphaStart = 0.7f; + + private OnExpandStateChangeListener mListener; + + /** + * 收缩状态 + */ + private Map collapsedStatus; + + private int mPosition; + private int mStartHeight; + private int expendTextHeight; + + /** + * 构造函数 + * + * @param context Context + */ + public ExpandableTextView(Context context) { + super(context); + } + + /** + * 构造函数 + * + * @param context Context + * @param attrSet AttrSet + */ + public ExpandableTextView(Context context, AttrSet attrSet) { + super(context, attrSet); + init(attrSet); + } + + /** + * 构造函数 + * + * @param context Context + * @param attrSet AttrSet + * @param styleName styleName + */ + public ExpandableTextView(Context context, AttrSet attrSet, String styleName) { + super(context, attrSet, styleName); + init(attrSet); + } + + /** + * 设置布局方向(只支持竖向) + * + * @param orientation 布局方向 + */ + @Override + public void setOrientation(int orientation) { + if (Component.HORIZONTAL == orientation) { + throw new IllegalArgumentException("ExpandableTextView only supports Vertical Orientation."); + } + super.setOrientation(orientation); + } + + AnimatorValue animation = new AnimatorValue(); + + @Override + public void onClick(Component component) { + if (animation.isRunning()) { + return; + } + if (expandCollapse.getVisibility() != Component.VISIBLE) { + return; + } + + mCollapsed = !mCollapsed; + mExpandIndicatorController.changeState(mCollapsed); + + // 记录伸缩状态 + if (collapsedStatus != null) { + collapsedStatus.put(mPosition, mCollapsed); + } + + if (mStartHeight == 0) { + mStartHeight = getHeight(); + expendTextHeight = expandText.getHeight(); + expandText.setHeight(expendTextHeight); + expandText.setMaxTextLines(Integer.MAX_VALUE); + } + + // 动效 + animation.setDuration(animationDuration); + animation.setStateChangedListener(new Animator.StateChangedListener() { + @Override + public void onStart(Animator animator) { + applyAlphaAnimation(expandText, animAlphaStart); + } + + @Override + public void onStop(Animator animator) { + + } + + @Override + public void onCancel(Animator animator) { + + } + + @Override + public void onEnd(Animator animator) { + // notify the listener + mListener.expandStateChangedToast(!mCollapsed); + } + + @Override + public void onPause(Animator animator) { + + } + + @Override + public void onResume(Animator animator) { + + } + }); + animation.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() { + + @Override + public void onUpdate(AnimatorValue animatorValue, float interpolatedTime) { + final int newHeight; + if (mCollapsed) { + newHeight = (mCollapsedHeight - getHeight()) * (int) interpolatedTime + getHeight(); + } else { + double mEndHeight = mStartHeight + singleTextHeight * 7 - expendTextHeight; + newHeight = ((int) mEndHeight - mStartHeight) * (int) interpolatedTime + mStartHeight; + } + expandText.setHeight(newHeight - mMarginBetweenTxtAndBottom); + if (Float.compare(animAlphaStart, 1.0f) != 0) { + double result = (double) interpolatedTime * ((double)1 - (double)animAlphaStart); + double alphaResult = animAlphaStart + result; + applyAlphaAnimation(expandText, (float) alphaResult); + } + + getContext().getUITaskDispatcher().delayDispatch(new Runnable() { + @Override + public void run() { + if (mListener != null) { + mListener.onExpandStateChanged(expandText); + } + } + }, 10); + } + }); + + animation.start(); + } + + @Override + public boolean onEstimateSize(int widthEstimateConfig, int heightEstimateConfig) { + HiLog.debug(logLabel, "onEstimateSize"); + singleTextHeight = getFontHeight(expandText.getTextSize()); + // If no change, measure and return + if (!mRelayout || getVisibility() == Component.HIDE) { + return false; + } + mRelayout = false; + + // Setup with optimistic case + // i.e. Everything fits. No button needed + expandCollapse.setVisibility(Component.HIDE); + expandText.setMaxTextLines(Integer.MAX_VALUE); + + // Measure + super.estimateSize(widthEstimateConfig, heightEstimateConfig); + // If the text fits in collapsed mode, we are done. + if (expandText.getMaxTextLines() <= maxCollapsedLines) { + return false; + } + // Doesn't fit in collapsed mode. Collapse text view as needed. Show + // button. + if (mCollapsed) { + expandText.setMaxTextLines(maxCollapsedLines); + } + expandCollapse.setVisibility(Component.VISIBLE); + + // Re-measure with new setup + super.estimateSize(widthEstimateConfig, heightEstimateConfig); + + if (mCollapsed) { + mMarginBetweenTxtAndBottom = getHeight() - expandText.getHeight(); + // Saves the collapsed height of this ViewGroup + mCollapsedHeight = getEstimatedHeight(); + } + return false; + } + + + /** + * 获取一行的字体高度 + * + * @param fontSize 字体大小 + * @return 行高 + */ + private double getFontHeight(int fontSize) { + Paint paint = new Paint(); + paint.setTextSize(fontSize); + Paint.FontMetrics fm = paint.getFontMetrics(); + return Math.ceil((double) fm.descent - (double) fm.top) + 2; + } + + + private void init(AttrSet attrs) { + initAttrs(attrs); + // enforces vertical orientation + setOrientation(Component.VERTICAL); + //add绘制的回调 + addDrawTask(mDrawTask); + + } + + //绘制的回调 + final private DrawTask mDrawTask = new DrawTask() { + @Override + public void onDraw(Component component, Canvas canvas) { + //add测量的回调 + setEstimateSizeListener(ExpandableTextView.this); + //add布局的回调 + setArrangeListener(ExpandableTextView.this); + findViews(); + + } + }; + + + /** + * 初始化属性 + * + * @param attrSet 属性 + */ + private void initAttrs(AttrSet attrSet) { + maxCollapsedLines = TypedAttrUtils.getInteger(attrSet, "maxCollapsedLines", MAX_COLLAPSED_LINES); + animationDuration = TypedAttrUtils.getInteger(attrSet, "animDuration", DEFAULT_ANIM_DURATION); + animAlphaStart = TypedAttrUtils.getFloat(attrSet, "animAlphaStart", DEFAULT_ANIM_ALPHA_START); + expandToggleOnTextClick = TypedAttrUtils.getBoolean(attrSet, "expandToggleOnTextClick", true); + mExpandIndicatorController = setupExpandToggleController(getContext(), attrSet); + } + + private void findViews() { + int count = getChildCount(); + if (count < 1) { + return; + } + for (int i = 0; i < count; i++) { + Component component = getComponentAt(i); + if (component.getComponentDescription().toString().equals("expandable_text")) { + expandText = (Text) component; + } else if (component.getComponentDescription().toString().equals("expand_collapse")) { + expandCollapse = component; + } + } + if (expandToggleOnTextClick) { + expandText.setClickedListener(this); + } else { + expandText.setClickedListener(null); + } + expandCollapse.setClickedListener(this); + mExpandIndicatorController.setView(expandCollapse); + mExpandIndicatorController.changeState(mCollapsed); + + // enforces vertical orientation + setOrientation(Component.VERTICAL); + } + + /** + * 设置监听 + * + * @param listener 监听器 + */ + public void setOnExpandStateChangeListener(OnExpandStateChangeListener listener) { + mListener = listener; + } + + @Override + public boolean onArrange(int i, int i1, int i2, int i3) { + return false; + } + + public interface OnExpandStateChangeListener { + /** + * Called when the expand/collapse animation has been finished + * + * @param textView - TextView being expanded/collapsed + */ + void onExpandStateChanged(Text textView); + + /** + * 状态改变时的提示语 + * + * @param isExpanded 是否是展开状态 + */ + void expandStateChangedToast(boolean isExpanded); + } + + interface ExpandIndicatorController { + void changeState(boolean collapsed); + + void setView(Component toggleView); + } + + private static void applyAlphaAnimation(Component view, float alpha) { + view.setAlpha(alpha); + } + + /** + * Image图标控制器 + */ + private static class ImageButtonExpandController implements ExpandIndicatorController { + + private final PixelMap mExpandDrawable; + private final PixelMap mCollapseDrawable; + + private Image mImageButton; + + public ImageButtonExpandController(PixelMap expandDrawable, PixelMap collapseDrawable) { + mExpandDrawable = expandDrawable; + mCollapseDrawable = collapseDrawable; + } + + @Override + public void changeState(boolean collapsed) { + mImageButton.setPixelMap(collapsed ? mExpandDrawable : mCollapseDrawable); + } + + @Override + public void setView(Component toggleView) { + mImageButton = (Image) toggleView; + } + } + + /** + * Text图标控制器 + */ + static class TextViewExpandController implements ExpandIndicatorController { + + private final int mExpandText; + private final int mCollapseText; + + private Text mTextView; + + public TextViewExpandController(int expandText, int collapseText) { + mExpandText = expandText; + mCollapseText = collapseText; + } + + @Override + public void changeState(boolean collapsed) { + mTextView.setText(collapsed ? mExpandText : mCollapseText); + } + + @Override + public void setView(Component toggleView) { + mTextView = (Text) toggleView; + } + } + + private static PixelMap getPixelMap(int resId, Context context) { + InputStream drawableInputStream = null; + try { + drawableInputStream = context.getResourceManager().getResource(resId); + ImageSource.SourceOptions sourceOptions = new ImageSource.SourceOptions(); + sourceOptions.formatHint = "image/png"; + ImageSource imageSource = ImageSource.create(drawableInputStream, null); + ImageSource.DecodingOptions decodingOptions = new ImageSource.DecodingOptions(); + decodingOptions.desiredSize = new Size(0, 0); + decodingOptions.desiredRegion = new Rect(0, 0, 0, 0); + decodingOptions.desiredPixelFormat = PixelFormat.ARGB_8888; + PixelMap pixelMap = imageSource.createPixelmap(decodingOptions); + return pixelMap; + } catch (Exception e) { + HiLog.debug(logLabel, "getPixelMap" + e.getMessage()); + } finally { + try { + if (drawableInputStream != null) { + drawableInputStream.close(); + } + } catch (Exception e) { + HiLog.debug(logLabel, "getPixelMap" + e.getMessage()); + } + } + return null; + } + + private static ExpandIndicatorController setupExpandToggleController(Context context, AttrSet attrSet) { + final int expandToggleType = TypedAttrUtils.getInteger(attrSet, "expandToggleType", DEFAULT_TOGGLE_TYPE); + final ExpandIndicatorController expandIndicatorController; + switch (expandToggleType) { + case EXPAND_INDICATOR_IMAGE_BUTTON: + PixelMap expandDrawable = null; + PixelMap collapseDrawable = null; + boolean expandPresent = attrSet.getAttr("expandIndicator").isPresent(); + if (expandPresent) { + expandDrawable = ((PixelMapElement) (attrSet.getAttr("expandIndicator").get().getElement())).getPixelMap(); + } + boolean collapsePresent = attrSet.getAttr("collapseIndicator").isPresent(); + if (collapsePresent) { + collapseDrawable = ((PixelMapElement) (attrSet.getAttr("collapseIndicator").get().getElement())).getPixelMap(); + } + if (expandDrawable == null) { + expandDrawable = getPixelMap(ResourceTable.Media_ic_expand_more_black_12dp, context); + } + if (collapseDrawable == null) { + collapseDrawable = getPixelMap(ResourceTable.Media_ic_expand_less_black_12dp, context); + } + expandIndicatorController = new ImageButtonExpandController(expandDrawable, collapseDrawable); + break; + case EXPAND_INDICATOR_TEXT_VIEW: + expandIndicatorController = new TextViewExpandController(ResourceTable.String_expand_more, ResourceTable.String_expand_less); + break; + default: + throw new IllegalStateException("Must be of enum: ExpandableTextView_expandToggleType, one of EXPAND_INDICATOR_IMAGE_BUTTON or EXPAND_INDICATOR_TEXT_VIEW."); + } + + return expandIndicatorController; + } + + /** + * 设置文案 + * + * @param text 文案内容 + */ + public void setText(String text) { + mRelayout = true; + findViews(); + expandText.setText(text); + setVisibility(null == text ? Component.HIDE : Component.VISIBLE); + postLayout(); + } +} diff --git a/lib/src/main/java/com/ms/square/ohos/expandabletextview/TypedAttrUtils.java b/lib/src/main/java/com/ms/square/ohos/expandabletextview/TypedAttrUtils.java new file mode 100644 index 0000000000000000000000000000000000000000..29dff4331c60a15bd370e0ce1868543495dc630f --- /dev/null +++ b/lib/src/main/java/com/ms/square/ohos/expandabletextview/TypedAttrUtils.java @@ -0,0 +1,111 @@ +/* + * 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.ms.square.ohos.expandabletextview; + + +import ohos.agp.components.Attr; +import ohos.agp.components.AttrSet; +import ohos.agp.utils.Color; +import ohos.hiviewdfx.HiLog; +import ohos.hiviewdfx.HiLogLabel; + +import java.util.NoSuchElementException; + +public final class TypedAttrUtils { + static final HiLogLabel label = new HiLogLabel(HiLog.LOG_APP, 0x00201, "jiangbenfu"); + + public static int getIntColor(AttrSet attrs, String attrName, int defValue) { + Attr attr = attrNoSuchElement(attrs, attrName); + if (attr == null) { + return defValue; + } else { + return attr.getColorValue().getValue(); + } + } + + public static Color getColor(AttrSet attrs, String attrName, Color defValue) { + Attr attr = attrNoSuchElement(attrs, attrName); + if (attr == null) { + return defValue; + } else { + return attr.getColorValue(); + } + } + + public static boolean getBoolean(AttrSet attrs, String attrName, boolean defValue) { + Attr attr = attrNoSuchElement(attrs, attrName); + if (attr == null) { + return defValue; + } else { + return attr.getBoolValue(); + } + } + + + public static int getInteger(AttrSet attrs, String attrName, int defValue) { + Attr attr = attrNoSuchElement(attrs, attrName); + if (attr == null) { + return defValue; + } else { + return attr.getIntegerValue(); + } + } + + public static float getFloat(AttrSet attrs, String attrName, float defValue) { + Attr attr = attrNoSuchElement(attrs, attrName); + if (attr == null) { + return defValue; + } else { + return attr.getFloatValue(); + } + } + + public static String getString(AttrSet attrs, String attrName, String defValue) { + Attr attr = attrNoSuchElement(attrs, attrName); + if (attr == null) { + return defValue; + } else { + return attr.getStringValue(); + } + } + + public static int getDimensionPixelSize(AttrSet attrs, String attrName, int defValue) { + Attr attr = attrNoSuchElement(attrs, attrName); + if (attr == null) { + return defValue; + } else { + return attr.getIntegerValue(); + } + } + + public static int getLayoutDimension(AttrSet attrs, String attrName, int defValue) { + Attr attr = attrNoSuchElement(attrs, attrName); + if (attr == null) { + return defValue; + } else { + return attr.getDimensionValue(); + } + } + + private static Attr attrNoSuchElement(AttrSet attrs, String attrName) { + Attr attr = null; + try { + attr = attrs.getAttr(attrName).get(); + } catch (NoSuchElementException e) { + HiLog.info(label, "Exception = " + e.toString()); + } + return attr; + } +} diff --git a/lib/src/main/res/drawable-hdpi/ic_expand_less_black_12dp.png b/lib/src/main/res/drawable-hdpi/ic_expand_less_black_12dp.png deleted file mode 100644 index 2298ef5c83343c97029d45084b1cc63eb76bab9e..0000000000000000000000000000000000000000 Binary files a/lib/src/main/res/drawable-hdpi/ic_expand_less_black_12dp.png and /dev/null differ diff --git a/lib/src/main/res/drawable-hdpi/ic_expand_less_black_16dp.png b/lib/src/main/res/drawable-hdpi/ic_expand_less_black_16dp.png deleted file mode 100644 index 4513b255a4a254c17a735083649a7e7ea89b2919..0000000000000000000000000000000000000000 Binary files a/lib/src/main/res/drawable-hdpi/ic_expand_less_black_16dp.png and /dev/null differ diff --git a/lib/src/main/res/drawable-hdpi/ic_expand_more_black_12dp.png b/lib/src/main/res/drawable-hdpi/ic_expand_more_black_12dp.png deleted file mode 100644 index 5cf7dadc555991841d3201aea67e2e58777e80a5..0000000000000000000000000000000000000000 Binary files a/lib/src/main/res/drawable-hdpi/ic_expand_more_black_12dp.png and /dev/null differ diff --git a/lib/src/main/res/drawable-hdpi/ic_expand_more_black_16dp.png b/lib/src/main/res/drawable-hdpi/ic_expand_more_black_16dp.png deleted file mode 100644 index c239df4f13e820ba2baf03ceb46f48c463188574..0000000000000000000000000000000000000000 Binary files a/lib/src/main/res/drawable-hdpi/ic_expand_more_black_16dp.png and /dev/null differ diff --git a/lib/src/main/res/drawable-mdpi/ic_expand_less_black_12dp.png b/lib/src/main/res/drawable-mdpi/ic_expand_less_black_12dp.png deleted file mode 100644 index 3a51f7368662f14461ec0f742bba16eb42ed7dd0..0000000000000000000000000000000000000000 Binary files a/lib/src/main/res/drawable-mdpi/ic_expand_less_black_12dp.png and /dev/null differ diff --git a/lib/src/main/res/drawable-mdpi/ic_expand_less_black_16dp.png b/lib/src/main/res/drawable-mdpi/ic_expand_less_black_16dp.png deleted file mode 100644 index ee7e2a1ec80de7064f8f41aacfbba039f6301ac9..0000000000000000000000000000000000000000 Binary files a/lib/src/main/res/drawable-mdpi/ic_expand_less_black_16dp.png and /dev/null differ diff --git a/lib/src/main/res/drawable-mdpi/ic_expand_more_black_12dp.png b/lib/src/main/res/drawable-mdpi/ic_expand_more_black_12dp.png deleted file mode 100644 index cc2f73d165178301933c71d309abff4ed8b70242..0000000000000000000000000000000000000000 Binary files a/lib/src/main/res/drawable-mdpi/ic_expand_more_black_12dp.png and /dev/null differ diff --git a/lib/src/main/res/drawable-mdpi/ic_expand_more_black_16dp.png b/lib/src/main/res/drawable-mdpi/ic_expand_more_black_16dp.png deleted file mode 100644 index 7e25edb3fd5bc276e1c94bf6e3d3bea65fa1fd6f..0000000000000000000000000000000000000000 Binary files a/lib/src/main/res/drawable-mdpi/ic_expand_more_black_16dp.png and /dev/null differ diff --git a/lib/src/main/res/drawable-sw600dp/ic_expand_less.xml b/lib/src/main/res/drawable-sw600dp/ic_expand_less.xml deleted file mode 100644 index 25b311f91775ca5c186e4a2f7ee317e7050198fc..0000000000000000000000000000000000000000 --- a/lib/src/main/res/drawable-sw600dp/ic_expand_less.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - diff --git a/lib/src/main/res/drawable-sw600dp/ic_expand_more.xml b/lib/src/main/res/drawable-sw600dp/ic_expand_more.xml deleted file mode 100644 index aba9de78a7293a68995c458bb43dad0b2c47879f..0000000000000000000000000000000000000000 --- a/lib/src/main/res/drawable-sw600dp/ic_expand_more.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - diff --git a/lib/src/main/res/drawable-xhdpi/ic_expand_less_black_12dp.png b/lib/src/main/res/drawable-xhdpi/ic_expand_less_black_12dp.png deleted file mode 100644 index e5a7076779c2abdd1770988cba475ff6d30a4452..0000000000000000000000000000000000000000 Binary files a/lib/src/main/res/drawable-xhdpi/ic_expand_less_black_12dp.png and /dev/null differ diff --git a/lib/src/main/res/drawable-xhdpi/ic_expand_less_black_16dp.png b/lib/src/main/res/drawable-xhdpi/ic_expand_less_black_16dp.png deleted file mode 100644 index c6c20241bdf3e4eef01202cb1697a71a673df258..0000000000000000000000000000000000000000 Binary files a/lib/src/main/res/drawable-xhdpi/ic_expand_less_black_16dp.png and /dev/null differ diff --git a/lib/src/main/res/drawable-xhdpi/ic_expand_more_black_12dp.png b/lib/src/main/res/drawable-xhdpi/ic_expand_more_black_12dp.png deleted file mode 100644 index b9e88d457d0a991ec0789524fe84d1b7e96aca5e..0000000000000000000000000000000000000000 Binary files a/lib/src/main/res/drawable-xhdpi/ic_expand_more_black_12dp.png and /dev/null differ diff --git a/lib/src/main/res/drawable-xhdpi/ic_expand_more_black_16dp.png b/lib/src/main/res/drawable-xhdpi/ic_expand_more_black_16dp.png deleted file mode 100644 index 319d0374418701693017d8e97c895e7b1e26886a..0000000000000000000000000000000000000000 Binary files a/lib/src/main/res/drawable-xhdpi/ic_expand_more_black_16dp.png and /dev/null differ diff --git a/lib/src/main/res/drawable-xxhdpi/ic_expand_less_black_12dp.png b/lib/src/main/res/drawable-xxhdpi/ic_expand_less_black_12dp.png deleted file mode 100644 index 71321e99cc2b43bbb2a584643c64867e51c57a94..0000000000000000000000000000000000000000 Binary files a/lib/src/main/res/drawable-xxhdpi/ic_expand_less_black_12dp.png and /dev/null differ diff --git a/lib/src/main/res/drawable-xxhdpi/ic_expand_less_black_16dp.png b/lib/src/main/res/drawable-xxhdpi/ic_expand_less_black_16dp.png deleted file mode 100644 index e49b9e9916c3a15e59ce8aac654924c19640834b..0000000000000000000000000000000000000000 Binary files a/lib/src/main/res/drawable-xxhdpi/ic_expand_less_black_16dp.png and /dev/null differ diff --git a/lib/src/main/res/drawable-xxhdpi/ic_expand_more_black_12dp.png b/lib/src/main/res/drawable-xxhdpi/ic_expand_more_black_12dp.png deleted file mode 100644 index 2d543777ea0f44ebf3ba910caeadcb89a71ed826..0000000000000000000000000000000000000000 Binary files a/lib/src/main/res/drawable-xxhdpi/ic_expand_more_black_12dp.png and /dev/null differ diff --git a/lib/src/main/res/drawable-xxhdpi/ic_expand_more_black_16dp.png b/lib/src/main/res/drawable-xxhdpi/ic_expand_more_black_16dp.png deleted file mode 100644 index 07818d2e9afcffaff0aa2fb274b1e593e3415722..0000000000000000000000000000000000000000 Binary files a/lib/src/main/res/drawable-xxhdpi/ic_expand_more_black_16dp.png and /dev/null differ diff --git a/lib/src/main/res/drawable/ic_expand_less.xml b/lib/src/main/res/drawable/ic_expand_less.xml deleted file mode 100644 index 71a53422517aef65a4c2c30a1ab3f7be1e607ce1..0000000000000000000000000000000000000000 --- a/lib/src/main/res/drawable/ic_expand_less.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - \ No newline at end of file diff --git a/lib/src/main/res/drawable/ic_expand_more.xml b/lib/src/main/res/drawable/ic_expand_more.xml deleted file mode 100644 index f7dd4b10629ecd60641c7a62661b5ecd989d73ae..0000000000000000000000000000000000000000 --- a/lib/src/main/res/drawable/ic_expand_more.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - \ No newline at end of file diff --git a/lib/src/main/res/values/attrs.xml b/lib/src/main/res/values/attrs.xml deleted file mode 100644 index 8bcd68da8fda32c0da6aab6a4fc65f1622441e22..0000000000000000000000000000000000000000 --- a/lib/src/main/res/values/attrs.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/lib/src/main/res/values/ids.xml b/lib/src/main/res/values/ids.xml deleted file mode 100644 index 4f399f460318be2fba64bc9e502f026664d7bac0..0000000000000000000000000000000000000000 --- a/lib/src/main/res/values/ids.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/lib/src/main/resources/base/element/string.json b/lib/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..0fec1f2cc2ae95977073133b56b4bb56e48eb6e6 --- /dev/null +++ b/lib/src/main/resources/base/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "app_name", + "value": "Library" + }, + { + "name": "expand_less", + "value": "收缩" + }, + { + "name": "expand_more", + "value": "展开" + }, + { + "name": "ExpandableTextId", + "value": "expandable_text" + }, + { + "name": "ExpandCollapseToggleId", + "value": "expand_collapse" + } + ] +} diff --git a/lib/src/main/resources/base/media/ic_expand_less_black_12dp.png b/lib/src/main/resources/base/media/ic_expand_less_black_12dp.png new file mode 100644 index 0000000000000000000000000000000000000000..4893bfcbf68efbe8932ea8d9435ef0270818be20 Binary files /dev/null and b/lib/src/main/resources/base/media/ic_expand_less_black_12dp.png differ diff --git a/lib/src/main/resources/base/media/ic_expand_less_black_16dp.png b/lib/src/main/resources/base/media/ic_expand_less_black_16dp.png new file mode 100644 index 0000000000000000000000000000000000000000..0aa7c572413c0cf0a60d60e86f7c3104931cbab3 Binary files /dev/null and b/lib/src/main/resources/base/media/ic_expand_less_black_16dp.png differ diff --git a/lib/src/main/resources/base/media/ic_expand_more_black_12dp.png b/lib/src/main/resources/base/media/ic_expand_more_black_12dp.png new file mode 100644 index 0000000000000000000000000000000000000000..4f6d8ff27567d0d94b4a631d948754108c2a43be Binary files /dev/null and b/lib/src/main/resources/base/media/ic_expand_more_black_12dp.png differ diff --git a/lib/src/main/resources/base/media/ic_expand_more_black_16dp.png b/lib/src/main/resources/base/media/ic_expand_more_black_16dp.png new file mode 100644 index 0000000000000000000000000000000000000000..cb5fbc1185838e8f156eeef5ebc2bdab2ce52e4a Binary files /dev/null and b/lib/src/main/resources/base/media/ic_expand_more_black_16dp.png differ diff --git a/sample/build.gradle b/sample/build.gradle deleted file mode 100644 index 84be5eac288c18e9ffa1ce4bc104f0c361737116..0000000000000000000000000000000000000000 --- a/sample/build.gradle +++ /dev/null @@ -1,28 +0,0 @@ -apply plugin: 'android' - -android { - - compileSdkVersion project.ANDROID_COMPILE_SDK_VERSION - buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION - - defaultConfig { - minSdkVersion project.ANDROID_MIN_SDK_VERSION - targetSdkVersion project.ANDROID_TARGET_SDK_VERSION - versionCode 1 - versionName "1.0.0" - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' - } - } -} - -dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - compile project(':lib') - compile "com.android.support:appcompat-v7:${supportPackageVersion}" - compile "com.android.support:design:${supportPackageVersion}" -} diff --git a/sample/proguard-rules.txt b/sample/proguard-rules.txt deleted file mode 100644 index cb8998dd02e6e21616d855056c1ab35143efba29..0000000000000000000000000000000000000000 --- a/sample/proguard-rules.txt +++ /dev/null @@ -1,17 +0,0 @@ -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in /Applications/Android Studio.app/sdk/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the ProGuard -# include property in project.properties. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} \ No newline at end of file diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml deleted file mode 100644 index 3356fc1e84b09d6b2a4d3b5d6faeb3c00a8fd119..0000000000000000000000000000000000000000 --- a/sample/src/main/AndroidManifest.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - - diff --git a/sample/src/main/ic_launcher-web.png b/sample/src/main/ic_launcher-web.png deleted file mode 100644 index a3e84937d0a91dd6b724f3d57f1e1a591399f8bb..0000000000000000000000000000000000000000 Binary files a/sample/src/main/ic_launcher-web.png and /dev/null differ diff --git a/sample/src/main/java/com/ms/square/android/expandabletextview/sample/DemoActivity.java b/sample/src/main/java/com/ms/square/android/expandabletextview/sample/DemoActivity.java deleted file mode 100644 index 03078c23ee2cc7aef1f9ceaebaa6b0898e8af7f9..0000000000000000000000000000000000000000 --- a/sample/src/main/java/com/ms/square/android/expandabletextview/sample/DemoActivity.java +++ /dev/null @@ -1,176 +0,0 @@ -package com.ms.square.android.expandabletextview.sample; - -import android.os.Bundle; -import android.support.design.widget.TabLayout; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentPagerAdapter; -import android.support.v4.app.ListFragment; -import android.support.v4.view.ViewPager; -import android.support.v7.app.AppCompatActivity; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; -import android.widget.Toast; - -import com.ms.square.android.expandabletextview.ExpandableTextView; -import com.ms.square.android.mymodule.app.R; - -/** - * Demo Activity which demos the features of the ExpandableTextView. - * - * @author Manabu-GT - */ -public class DemoActivity extends AppCompatActivity { - - private static final String POSITION = "POSITION"; - - /** - * The {@link android.support.v4.view.PagerAdapter} that will provide - * fragments for each of the sections. We use a - * {@link FragmentPagerAdapter} derivative, which will keep every - * loaded fragment in memory. If this becomes too memory intensive, it - * may be best to switch to a - * {@link android.support.v4.app.FragmentStatePagerAdapter}. - */ - private SectionsPagerAdapter mSectionsPagerAdapter; - - /** - * The {@link ViewPager} that will host the section contents. - */ - private ViewPager mViewPager; - - private TabLayout mTabLayout; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_demo); - - // Create the adapter that will return a fragment for each of the three - // primary sections of the activity. - mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); - - // Set up the ViewPager with the sections adapter. - mViewPager = (ViewPager) findViewById(R.id.container); - mViewPager.setAdapter(mSectionsPagerAdapter); - - mTabLayout = (TabLayout) findViewById(R.id.tabs); - mTabLayout.setupWithViewPager(mViewPager); - setupTabLayout(mTabLayout); - } - - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - // Inflate the menu; this adds items to the action bar if it is present. - getMenuInflater().inflate(R.menu.demo, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - // Handle action bar item clicks here. The action bar will - // automatically handle clicks on the Home/Up button, so long - // as you specify a parent activity in AndroidManifest.xml. - int id = item.getItemId(); - if (id == R.id.action_settings) { - return true; - } - return super.onOptionsItemSelected(item); - } - - private void setupTabLayout(TabLayout tabLayout) { - tabLayout.setTabMode(TabLayout.MODE_FIXED); - tabLayout.setTabGravity(TabLayout.GRAVITY_FILL); - tabLayout.setupWithViewPager(mViewPager); - } - - @Override - public void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - outState.putInt(POSITION, mTabLayout.getSelectedTabPosition()); - } - - @Override - protected void onRestoreInstanceState(Bundle savedInstanceState) { - super.onRestoreInstanceState(savedInstanceState); - mViewPager.setCurrentItem(savedInstanceState.getInt(POSITION)); - } - - /** - * A {@link FragmentPagerAdapter} that returns a fragment corresponding to - * one of the sections/tabs/pages. - */ - class SectionsPagerAdapter extends FragmentPagerAdapter { - - public SectionsPagerAdapter(FragmentManager fm) { - super(fm); - } - - @Override - public Fragment getItem(int position) { - if (position == 0) { - return new Demo1Fragment(); - } else { - return new Demo2Fragment(); - } - } - - @Override - public int getCount() { - return 2; - } - - @Override - public CharSequence getPageTitle(int position) { - switch (position) { - case 0: - return getString(R.string.title_demo1); - case 1: - return getString(R.string.title_demo2); - } - return null; - } - } - - public static class Demo1Fragment extends Fragment { - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View rootView = inflater.inflate(R.layout.fragment_demo1, container, false); - - ((TextView) rootView.findViewById(R.id.sample1).findViewById(R.id.title)).setText("Sample 1"); - ((TextView) rootView.findViewById(R.id.sample2).findViewById(R.id.title)).setText("Sample 2"); - - ExpandableTextView expTv1 = (ExpandableTextView) rootView.findViewById(R.id.sample1) - .findViewById(R.id.expand_text_view); - ExpandableTextView expTv2 = (ExpandableTextView) rootView.findViewById(R.id.sample2) - .findViewById(R.id.expand_text_view); - - expTv1.setOnExpandStateChangeListener(new ExpandableTextView.OnExpandStateChangeListener() { - @Override - public void onExpandStateChanged(TextView textView, boolean isExpanded) { - Toast.makeText(getActivity(), isExpanded ? "Expanded" : "Collapsed", Toast.LENGTH_SHORT).show(); - } - }); - - expTv1.setText(getString(R.string.dummy_text1)); - expTv2.setText(getString(R.string.dummy_text2)); - - return rootView; - } - } - - public static class Demo2Fragment extends ListFragment { - @Override - public void onViewCreated(View view, Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - SampleTextListAdapter adapter = new SampleTextListAdapter(getActivity()); - setListAdapter(adapter); - } - } -} diff --git a/sample/src/main/java/com/ms/square/android/expandabletextview/sample/SampleTextListAdapter.java b/sample/src/main/java/com/ms/square/android/expandabletextview/sample/SampleTextListAdapter.java deleted file mode 100644 index 8c02f5117346b4dc394fe102ce75fca483cd8868..0000000000000000000000000000000000000000 --- a/sample/src/main/java/com/ms/square/android/expandabletextview/sample/SampleTextListAdapter.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.ms.square.android.expandabletextview.sample; - -import android.content.Context; -import android.util.SparseBooleanArray; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.BaseAdapter; - -import com.ms.square.android.expandabletextview.ExpandableTextView; -import com.ms.square.android.mymodule.app.R; - -public class SampleTextListAdapter extends BaseAdapter { - - private final Context mContext; - private final SparseBooleanArray mCollapsedStatus; - private final String[] sampleStrings; - - public SampleTextListAdapter(Context context) { - mContext = context; - mCollapsedStatus = new SparseBooleanArray(); - sampleStrings = mContext.getResources().getStringArray(R.array.sampleStrings); - } - - @Override - public int getCount() { - return sampleStrings.length; - } - - @Override - public Object getItem(int position) { - return null; - } - - @Override - public long getItemId(int position) { - return 0; - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - final ViewHolder viewHolder; - if (convertView == null) { - convertView = LayoutInflater.from(mContext).inflate(R.layout.list_item, parent, false); - viewHolder = new ViewHolder(); - viewHolder.expandableTextView = (ExpandableTextView) convertView.findViewById(R.id.expand_text_view); - convertView.setTag(viewHolder); - } else { - viewHolder = (ViewHolder) convertView.getTag(); - } - - viewHolder.expandableTextView.setText(sampleStrings[position], mCollapsedStatus, position); - - return convertView; - } - - - private static class ViewHolder{ - ExpandableTextView expandableTextView; - } -} \ No newline at end of file diff --git a/sample/src/main/res/layout/activity_demo.xml b/sample/src/main/res/layout/activity_demo.xml deleted file mode 100644 index bbb1ffa20e26f912873f718f1f79ae6e59f3e6d4..0000000000000000000000000000000000000000 --- a/sample/src/main/res/layout/activity_demo.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/sample/src/main/res/layout/fragment_demo1.xml b/sample/src/main/res/layout/fragment_demo1.xml deleted file mode 100644 index 2351a9d78469b1419b88feae62750aa4e132c71e..0000000000000000000000000000000000000000 --- a/sample/src/main/res/layout/fragment_demo1.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/sample/src/main/res/layout/fragment_demo2.xml b/sample/src/main/res/layout/fragment_demo2.xml deleted file mode 100644 index 39422b1b183ada5ce217c5677ff97c7b7284f67b..0000000000000000000000000000000000000000 --- a/sample/src/main/res/layout/fragment_demo2.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - \ No newline at end of file diff --git a/sample/src/main/res/layout/list_item.xml b/sample/src/main/res/layout/list_item.xml deleted file mode 100644 index 9e3bac03935ed20ade6c47d1bfe6c9c9ca006db2..0000000000000000000000000000000000000000 --- a/sample/src/main/res/layout/list_item.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - diff --git a/sample/src/main/res/layout/text_item.xml b/sample/src/main/res/layout/text_item.xml deleted file mode 100644 index b00218865118f0552a2662f523ba946de8c78ebe..0000000000000000000000000000000000000000 --- a/sample/src/main/res/layout/text_item.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/sample/src/main/res/menu/demo.xml b/sample/src/main/res/menu/demo.xml deleted file mode 100644 index b47da08b56dc22b6b1b97b2289aca7385f74a78e..0000000000000000000000000000000000000000 --- a/sample/src/main/res/menu/demo.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/sample/src/main/res/mipmap-hdpi/ic_launcher.png b/sample/src/main/res/mipmap-hdpi/ic_launcher.png deleted file mode 100644 index 4c561f2207beb5d425791c41f52cacce6426938b..0000000000000000000000000000000000000000 Binary files a/sample/src/main/res/mipmap-hdpi/ic_launcher.png and /dev/null differ diff --git a/sample/src/main/res/mipmap-mdpi/ic_launcher.png b/sample/src/main/res/mipmap-mdpi/ic_launcher.png deleted file mode 100644 index df810258513f0d1ee9f56605752f08df5bfe5d96..0000000000000000000000000000000000000000 Binary files a/sample/src/main/res/mipmap-mdpi/ic_launcher.png and /dev/null differ diff --git a/sample/src/main/res/mipmap-xhdpi/ic_launcher.png b/sample/src/main/res/mipmap-xhdpi/ic_launcher.png deleted file mode 100644 index 5df4b872b049e25a69429576ddaeaa23d5e559a2..0000000000000000000000000000000000000000 Binary files a/sample/src/main/res/mipmap-xhdpi/ic_launcher.png and /dev/null differ diff --git a/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png b/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png deleted file mode 100644 index 012691a683b5c8a168d1bfa3e6256dd9664ed7f0..0000000000000000000000000000000000000000 Binary files a/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png and /dev/null differ diff --git a/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png deleted file mode 100644 index d9cad20899f839f60e60bd7055924093c6f24813..0000000000000000000000000000000000000000 Binary files a/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png and /dev/null differ diff --git a/sample/src/main/res/values-w820dp/dimens.xml b/sample/src/main/res/values-w820dp/dimens.xml deleted file mode 100644 index 63fc816444614bd64f68a372d1f93211628ee51d..0000000000000000000000000000000000000000 --- a/sample/src/main/res/values-w820dp/dimens.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - 64dp - diff --git a/sample/src/main/res/values/arrays.xml b/sample/src/main/res/values/arrays.xml deleted file mode 100644 index 9b3c2ae21f91f634c68dfceb5c0e803dff4887c8..0000000000000000000000000000000000000000 --- a/sample/src/main/res/values/arrays.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - "Android provides a rich application framework that allows you to build innovative apps and games for mobile devices in a Java language environment. The documents listed in the left navigation provide details about how to build apps using Android's various APIs." - "Android apps are built as a combination of distinct components that can be invoked individually. For instance, an individual activity provides a single screen for a user interface, and a service independently performs work in the background." - "From one component you can start another component using an intent. You can even start a component in a different app, such an activity in a maps app to show an address. This model provides multiple entry points for a single app and allows any app to behave as a user's "default" for an action that other apps may invoke." - "You can query the availability of device features at runtime if any app features require specific hardware such as a camera. If necessary, you can also declare features your app requires so app markets such as Google Play Store do not allow installation on devices that do not support that feature." - "Android provides an adaptive app framework that allows you to provide unique resources for different device configurations. For example, you can create different XML layout files for different screen sizes and the system determines which layout to apply based on the current device's screen size." - "Android provides a rich application framework that allows you to build innovative apps and games for mobile devices in a Java language environment. The documents listed in the left navigation provide details about how to build apps using Android's various APIs." - "Android provides a rich application framework that allows you to build innovative apps and games for mobile devices in a Java language environment. The documents listed in the left navigation provide details about how to build apps using Android's various APIs." - "Android provides a rich application framework that allows you to build innovative apps and games for mobile devices in a Java language environment. The documents listed in the left navigation provide details about how to build apps using Android's various APIs." - "Android provides a rich application framework that allows you to build innovative apps and games for mobile devices in a Java language environment. The documents listed in the left navigation provide details about how to build apps using Android's various APIs." - "Android provides a rich application framework that allows you to build innovative apps and games for mobile devices in a Java language environment. The documents listed in the left navigation provide details about how to build apps using Android's various APIs." - "test" - - \ No newline at end of file diff --git a/sample/src/main/res/values/dimens.xml b/sample/src/main/res/values/dimens.xml deleted file mode 100644 index 8928f5d3e8d8641dadd9b472e3cb4b5818734538..0000000000000000000000000000000000000000 --- a/sample/src/main/res/values/dimens.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - 16dp - 16dp - 8dp - diff --git a/sample/src/main/res/values/strings.xml b/sample/src/main/res/values/strings.xml deleted file mode 100644 index 23a8771725935e2c96364e43e24e6d6c6a441bc5..0000000000000000000000000000000000000000 --- a/sample/src/main/res/values/strings.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - ExpandableTextView Demo - Settings - Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. - Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt.\\n\\nCras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc, quis gravida magna mi a libero. Fusce vulputate eleifend sapien. - Demo - In ScrollView - In ListView - - \ No newline at end of file diff --git a/sample/src/main/res/values/styles.xml b/sample/src/main/res/values/styles.xml deleted file mode 100644 index 766ab9930487aebdf634594950b22d39b44d8125..0000000000000000000000000000000000000000 --- a/sample/src/main/res/values/styles.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - diff --git a/settings.gradle b/settings.gradle index 191917058f4f87f1dfe6aa2be41dbae63ce6a624..4f47b2b6cbbdaa9aade56ce8e57eaf9fafcb8e6e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':lib', 'sample' +include ':entry',':lib'