diff --git a/.gitignore b/.gitignore index 6e4612064e1cf0b80faa8e39377a4354a51fa0f0..37a4eb8b43d978ea05b2c6e3fb934f9b40dddd4d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,40 +1,15 @@ -# Eclipse -.project -.classpath -.settings -.checkstyle - -# IntelliJ IDEA -.idea *.iml -*.ipr -*.iws -classes -gen-external-apklibs - -# Gradle -gradle/ .gradle -build -gradlew -gradlew.bat -# Gradle -gradle.properties - -# Maven -target -release.properties -pom.xml.* - -# Ant -bin -gen -build.xml -ant.properties -local.properties -proguard.cfg -proguard-project.txt - -# Other +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml .DS_Store -tmp +/build +/captures +.externalNativeBuild +/entry/.preview +.cxx diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000000000000000000000000000000000000..6f013c6093503024be42020828c9c6da7994bca6 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,11 @@ +## 0.0.1-SHAOSHOT + +ohos第一个版本 + +* 实现了原库基本功能 + +部分效果未实现 + +​ 1.TextField密码掩码为*,原项目为●,该效果为原项目系统自带特性,openharmony无该特性 + +​ 2.TextField被选中时无复制、粘贴等弹窗,此效果为原项目系统自带特性,openharmony暂无该特性 \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..26356eb6944355fba89e81d70145fc076c921816 --- /dev/null +++ b/LICENSE @@ -0,0 +1,6 @@ +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. \ No newline at end of file diff --git a/README.OPENSOURCE b/README.OPENSOURCE new file mode 100644 index 0000000000000000000000000000000000000000..e74c5af3bef6c74e3fed9a325bbf3cc3d2390505 --- /dev/null +++ b/README.OPENSOURCE @@ -0,0 +1,19 @@ +[ + + { + + "Name":"floatlabelededittext" + + "License":"Apache License" + + "License File":"LICENSE" + + "Version Number":"master" + + "Upstream URL":"https://github.com/wrapp-archive/floatlabelededittext" + + "Description":"Simple implementation of a Float Labeled EditText: An Android ViewGroup which uses a child EditText and puts the hint on top of the EditText when it is populated with text." + + } + +] \ No newline at end of file diff --git a/README.md b/README.md index 90b4d495e115aec7d00e81bb8c1510f0988c3bb3..129b4d9b8e874918a7f4b8a58a887b3bc8db3ee1 100644 --- a/README.md +++ b/README.md @@ -1,119 +1,96 @@ -Float Labeled EditText -============== +# floatlabelededittext -Simple implementation of a Float Labeled EditText: An Android ViewGroup which uses a child EditText and puts the hint on top of the EditText when it is populated with text. +#### 项目介绍 -iOS implementation by [@jverdi](http://www.twitter.com/jverdi): [JVFloatLabeledTextField](https://github.com/jverdi/JVFloatLabeledTextField) +* 项目名称:floatlabelededittext +* 所属系列:openharmony +* 功能:使用一个子TextField,当TextField被填充时,提示将浮现在上方 +* 项目移植状态:主功能完成 +* 调用差异:无 +* 开发版本:sdk6,DevEco Studio 2.2 Beta1 +* 基线版本:master分支 -Credits for the concept to Matt D. Smith ([@mds](http://www.twitter.com/mds)). +#### 效果演示 -![Android Version](http://i.imgur.com/ucRd1jm.gif) +![](https://images.gitee.com/uploads/images/2021/0817/102010_8419a852_7648707.gif "floatlabelededittext.gif") -http://dribbble.com/shots/1254439--GIF-Mobile-Form-Interaction?list=users +#### 按照教程 -Notice -============== - -The usage has significantly changed in version 0.0.5 inspired by [chrisbanes](https://github.com/chrisbanes) [implementation](https://gist.github.com/chrisbanes/11247418) which makes styling easier. If you want to use the old style, use version 0.0.4. +1.在项目根目录下的build.gradle文件中 +```txt +allprojects { + repositories { + maven { + url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' + } + } +} +``` -Usage -===== +2.在entry模块下的build.gradle文件中 -Add the library project or grab to build.gradle: -```groovy -compile 'com.wrapp.floatlabelededittext:library:0.0.6' -``` -or plain maven: -```maven - - com.wrapp.floatlabelededittext - library - 0.0.6 - aar - +```txt +dependencies { + implementation('com.gitee.chinasoft_ohos:floatlabelededittext:0.0.1-SNAPSHOT') + ...... + } ``` -and then insert the view in XML: -```xml - +在sdk6,DevEco Studio 2.2 Beta1下项目可直接运行 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下 - - +#### 使用说明 - - +在布局中引入floatlabelededittext,内部需添加一个TextField节点 - - +```txt + - - - - - - - - - - + ``` -Developed By -============ -* Henrik Sandström [@heinrisch](https://twitter.com/Heinrisch) +下面是一些自定义属性的设置 + +| 属性名 | 作用域 | 例如 | +| :----------------: | :--------------------: | :---------: | +| fletPadding | 左上右下内边距 | 16vp | +| fletPaddingRight | 右侧内边距 | 16vp | +| fletPaddingLeft | 左侧内边距 | 16vp | +| fletPaddingTop | 上方内边距 | 16vp | +| fletPaddingBottom | 下方内边距 | 16vp | +| fletIsBold | 浮动提示信息是否加粗 | true | +| fletisIncline | 浮动提示信息是否倾斜 | false | +| fletBackground | 浮动提示信息的背景 | $media:icon | +| fletTextAppearance | 浮动提示信息的文字颜色 | #FF0000 | + +#### 测试信息 + +CodeCheck代码测试无异常 + +CloudTest代码测试无异常 -Styled By -========= +病毒安全检测通过 -* Marcus Gellemark [Dribbble](http://dribbble.com/Gellermark) +当前版本demo功能与原组件基本无差异 -Additional Credit -================= +#### 版本迭代 -* Chris Banes [chrisbanes](https://github.com/chrisbanes) -* Quentin DOMMERC [dommerq](https://github.com/dommerq) -* Aaron Rietschlin [@AaronRietschlin](https://twitter.com/AaronRietschlin) -* Guillaume Imbert [HozakaN](https://github.com/HozakaN) +* 0.0.1-SHAPSHOT +#### 版权和许可信息 +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 -License -======= -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at -http://www.apache.org/licenses/LICENSE-2.0 +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. -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. diff --git a/build.gradle b/build.gradle index 38a094c193dfdbc0db221d5f5d2e348d2216d584..ffb7d0b2406a4957aad77fd38996e79c00dccab6 100644 --- a/build.gradle +++ b/build.gradle @@ -1,16 +1,36 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +apply plugin: 'com.huawei.ohos.app' + +//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#section1112183053510 +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 5 + } +} + buildscript { repositories { - mavenCentral() + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } } dependencies { - classpath 'com.android.tools.build:gradle:1.0.0' + classpath 'com.huawei.ohos:hap:2.4.5.0' + classpath 'com.huawei.ohos:decctest:1.2.4.1' } } allprojects { - group = 'com.wrapp.floatlabelededittext' - - repositories { - mavenCentral() - } + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + } } diff --git a/example/.gitignore b/entry/.gitignore similarity index 100% rename from example/.gitignore rename to entry/.gitignore diff --git a/entry/build.gradle b/entry/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..f5b00e8242ab4faa2787633b619a8b16ff498e9d --- /dev/null +++ b/entry/build.gradle @@ -0,0 +1,28 @@ +apply plugin: 'com.huawei.ohos.hap' +apply plugin: 'com.huawei.ohos.decctest' +//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#section1112183053510 +ohos { + compileSdkVersion 5 + 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.200' + implementation project(':library') +} +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..cf9b5f7d736f3c3f989c67aa0cb28b79713b94b7 --- /dev/null +++ b/entry/src/main/config.json @@ -0,0 +1,55 @@ +{ + "app": { + "bundleName": "com.wrapp.example.floatlabelededittext", + "vendor": "wrapp", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.wrapp.example.floatlabelededittext", + "name": ".MyApplication", + "mainAbility": "com.wrapp.example.floatlabelededittext.MainAbility", + "metaData": { + "customizeData": [ + { + "name": "hwc-theme", + "value": "androidhwext:style/Theme.Emui.NoTitleBar", + "extra": "" + } + ] + }, + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": false + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "name": "com.wrapp.example.floatlabelededittext.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:entry_MainAbility", + "type": "page", + "launchType": "standard" + } + ] + } +} \ No newline at end of file diff --git a/entry/src/main/java/com/wrapp/example/floatlabelededittext/MainAbility.java b/entry/src/main/java/com/wrapp/example/floatlabelededittext/MainAbility.java new file mode 100644 index 0000000000000000000000000000000000000000..f130dbeea623878fcb89985849a4dcabb33291f2 --- /dev/null +++ b/entry/src/main/java/com/wrapp/example/floatlabelededittext/MainAbility.java @@ -0,0 +1,13 @@ +package com.wrapp.example.floatlabelededittext; + +import com.wrapp.example.floatlabelededittext.slice.MainAbilitySlice; +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; + +public class MainAbility extends Ability { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setMainRoute(MainAbilitySlice.class.getName()); + } +} diff --git a/entry/src/main/java/com/wrapp/example/floatlabelededittext/MyApplication.java b/entry/src/main/java/com/wrapp/example/floatlabelededittext/MyApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..7e6e0d4fc01ef0f567a87349e7b87545c3e0ad17 --- /dev/null +++ b/entry/src/main/java/com/wrapp/example/floatlabelededittext/MyApplication.java @@ -0,0 +1,10 @@ +package com.wrapp.example.floatlabelededittext; + +import ohos.aafwk.ability.AbilityPackage; + +public class MyApplication extends AbilityPackage { + @Override + public void onInitialize() { + super.onInitialize(); + } +} diff --git a/entry/src/main/java/com/wrapp/example/floatlabelededittext/slice/MainAbilitySlice.java b/entry/src/main/java/com/wrapp/example/floatlabelededittext/slice/MainAbilitySlice.java new file mode 100644 index 0000000000000000000000000000000000000000..cf319bfb87d20509fcead3530d457be5419eb265 --- /dev/null +++ b/entry/src/main/java/com/wrapp/example/floatlabelededittext/slice/MainAbilitySlice.java @@ -0,0 +1,131 @@ +package com.wrapp.example.floatlabelededittext.slice; + +import com.wrapp.example.floatlabelededittext.ResourceTable; +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import ohos.agp.colors.RgbColor; +import ohos.agp.components.AttrHelper; +import ohos.agp.components.Component; +import ohos.agp.components.LayoutScatter; +import ohos.agp.components.TextField; +import ohos.agp.components.element.ShapeElement; +import ohos.agp.utils.Color; +import ohos.agp.utils.LayoutAlignment; +import ohos.agp.window.dialog.PopupDialog; +import ohos.agp.window.service.WindowManager; +import ohos.multimodalinput.event.KeyEvent; +import ohos.multimodalinput.event.TouchEvent; + +public class MainAbilitySlice extends AbilitySlice implements Component.DoubleClickedListener { + private TextField textField1; + private TextField textField2; + private TextField textField3; + private TextField textField4; + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_ability_main); + WindowManager.getInstance().getTopWindow().get().setStatusBarColor(Color.getIntColor("#757575")); + + Component component = findComponentById(ResourceTable.Id_more); + + ShapeElement grayElement = new ShapeElement(); + grayElement.setRgbColor(new RgbColor(220, 220, 220)); + + ShapeElement whiteElement = new ShapeElement(); + whiteElement.setRgbColor(new RgbColor(250, 250, 250)); + + textField1 = (TextField) findComponentById(ResourceTable.Id_text1); + textField2 = (TextField) findComponentById(ResourceTable.Id_text2); + textField3 = (TextField) findComponentById(ResourceTable.Id_text3); + textField4 = (TextField) findComponentById(ResourceTable.Id_text4); + + textField1.setDoubleClickedListener(this::onDoubleClick); + textField2.setDoubleClickedListener(this::onDoubleClick); + textField3.setDoubleClickedListener(this::onDoubleClick); + textField4.setDoubleClickedListener(this::onDoubleClick); + + // 设置光标颜色 + ShapeElement shapeElement = new ShapeElement(); + shapeElement.setShape(ShapeElement.LINE); + RgbColor rgbColor = new RgbColor(0, 154, 134); + shapeElement.setRgbColors(new RgbColor[]{rgbColor, rgbColor}); + shapeElement.setStroke(AttrHelper.vp2px(28, this), rgbColor); + textField1.setCursorElement(shapeElement); + textField2.setCursorElement(shapeElement); + textField3.setCursorElement(shapeElement); + textField4.setCursorElement(shapeElement); + + textField3.setKeyEventListener(new Component.KeyEventListener() { + @Override + public boolean onKeyEvent(Component component, KeyEvent keyEvent) { + if (keyEvent.getKeyCode() != KeyEvent.KEY_ENTER) { + return false; + } + textField3.setText(textField3.getText().replaceAll("\n", "")); + return false; + } + }); + + textField4.setKeyEventListener(new Component.KeyEventListener() { + @Override + public boolean onKeyEvent(Component component, KeyEvent keyEvent) { + if (keyEvent.getKeyCode() == KeyEvent.KEY_ENTER) { + textField4.setText(textField4.getText().replaceAll("\n", "")); + } + return false; + } + }); + + component.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + PopupDialog dialog = new PopupDialog(MainAbilitySlice.this, null); + Component parse = LayoutScatter.getInstance(MainAbilitySlice.this).parse(ResourceTable.Layout_dialog_layout, null, false); + dialog.setCustomComponent(parse); + dialog.setAutoClosable(true); + dialog.showOnCertainPosition(LayoutAlignment.RIGHT | LayoutAlignment.TOP, 20, 100); + dialog.show(); + parse.setTouchEventListener(new Component.TouchEventListener() { + @Override + public boolean onTouchEvent(Component component, TouchEvent touchEvent) { + switch (touchEvent.getAction()) { + case TouchEvent.PRIMARY_POINT_DOWN: + parse.setBackground(grayElement); + break; + case TouchEvent.PRIMARY_POINT_UP: + parse.setBackground(whiteElement); + break; + } + return false; + } + }); + Component settings = parse.findComponentById(ResourceTable.Id_btn); + settings.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + dialog.remove(); + } + }); + } + }); + } + + @Override + public void onDoubleClick(Component component) { + switch (component.getId()) { + case ResourceTable.Id_text1: + textField1.executeLongClick(); + break; + case ResourceTable.Id_text2: + textField2.executeLongClick(); + break; + case ResourceTable.Id_text3: + textField3.executeLongClick(); + break; + case ResourceTable.Id_text4: + textField4.executeLongClick(); + break; + } + } +} \ 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..270cb02bdcf87907d67c0c3bfa43cc3ebcfab45e --- /dev/null +++ b/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "floatlabelededittext" + }, + { + "name": "mainability_description", + "value": "Java_Empty Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "Hello World" + } + ] +} \ 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..c0c0a3df480fa387a452b9c40ca191cc918a3fc0 --- /dev/null +++ b/entry/src/main/resources/base/graphic/background_ability_main.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/graphic/border.xml b/entry/src/main/resources/base/graphic/border.xml new file mode 100644 index 0000000000000000000000000000000000000000..71864ceb900b1a007a29542e8eb5ce871ddaae61 --- /dev/null +++ b/entry/src/main/resources/base/graphic/border.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..3743717ac05824eccd11d7caa5aaea5480234123 --- /dev/null +++ b/entry/src/main/resources/base/layout/ability_main.xml @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/layout/dialog_layout.xml b/entry/src/main/resources/base/layout/dialog_layout.xml new file mode 100644 index 0000000000000000000000000000000000000000..bad4d3e906620458c84326b6ee5e9d43443bd23a --- /dev/null +++ b/entry/src/main/resources/base/layout/dialog_layout.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/media/bubble.png b/entry/src/main/resources/base/media/bubble.png new file mode 100644 index 0000000000000000000000000000000000000000..cb47238ed15ef4c9e9093d926fdb4cdde98aad93 Binary files /dev/null and b/entry/src/main/resources/base/media/bubble.png differ diff --git a/entry/src/main/resources/base/media/bubble_left.png b/entry/src/main/resources/base/media/bubble_left.png new file mode 100644 index 0000000000000000000000000000000000000000..ecb16316f15ea512c48d43575ecd18f3872769b5 Binary files /dev/null and b/entry/src/main/resources/base/media/bubble_left.png differ diff --git a/entry/src/main/resources/base/media/bubble_right.png b/entry/src/main/resources/base/media/bubble_right.png new file mode 100644 index 0000000000000000000000000000000000000000..4dd28596a6e22ca5917af79a49f246d43314d0f0 Binary files /dev/null and b/entry/src/main/resources/base/media/bubble_right.png differ 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/main/resources/base/media/more.png b/entry/src/main/resources/base/media/more.png new file mode 100644 index 0000000000000000000000000000000000000000..1328e4ff0d68e8d4accabf97d0d4213e99865733 Binary files /dev/null and b/entry/src/main/resources/base/media/more.png differ diff --git a/entry/src/main/resources/en/element/string.json b/entry/src/main/resources/en/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f3cf8b5498539030fcf359e38ac021d47a4bef23 --- /dev/null +++ b/entry/src/main/resources/en/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "floatlabelededittext" + }, + { + "name": "mainability_description", + "value": "Java_Empty Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "Hello World" + } + ] +} diff --git a/entry/src/main/resources/zh/element/string.json b/entry/src/main/resources/zh/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..c423a55b8e429e6e99f44180c268177c40ab4335 --- /dev/null +++ b/entry/src/main/resources/zh/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "floatlabelededittext" + }, + { + "name": "mainability_description", + "value": "Java_Empty Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "你好,世界" + } + ] +} \ No newline at end of file diff --git a/entry/src/ohosTest/java/com/wrapp/example/floatlabelededittext/ExampleOhosTest.java b/entry/src/ohosTest/java/com/wrapp/example/floatlabelededittext/ExampleOhosTest.java new file mode 100644 index 0000000000000000000000000000000000000000..b641008c19719fe88eb67cda1970aebefb691603 --- /dev/null +++ b/entry/src/ohosTest/java/com/wrapp/example/floatlabelededittext/ExampleOhosTest.java @@ -0,0 +1,14 @@ +package com.wrapp.example.floatlabelededittext; + +import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class ExampleOhosTest { + @Test + public void testBundleName() { + final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName(); + assertEquals("com.wrapp.example.floatlabelededittext", actualBundleName); + } +} \ No newline at end of file diff --git a/entry/src/test/java/com/wrapp/example/floatlabelededittext/ExampleTest.java b/entry/src/test/java/com/wrapp/example/floatlabelededittext/ExampleTest.java new file mode 100644 index 0000000000000000000000000000000000000000..20f63e798822803dd68c537f7c4202f71d1d1b6a --- /dev/null +++ b/entry/src/test/java/com/wrapp/example/floatlabelededittext/ExampleTest.java @@ -0,0 +1,9 @@ +package com.wrapp.example.floatlabelededittext; + +import org.junit.Test; + +public class ExampleTest { + @Test + public void onStart() { + } +} diff --git a/example/build.gradle b/example/build.gradle deleted file mode 100644 index 4faca436278af738626f5825a9b0792ad9e62a3a..0000000000000000000000000000000000000000 --- a/example/build.gradle +++ /dev/null @@ -1,26 +0,0 @@ -apply plugin: 'android' - -android { - compileSdkVersion 19 - buildToolsVersion '19.1.0' - - defaultConfig { - minSdkVersion 7 - targetSdkVersion 19 - versionCode 1 - versionName "1.0" - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' - } - } -} - -dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:appcompat-v7:19.+' - //compile 'com.wrapp.floatlabelededittext:library:0.0.6' - compile project(":library") -} diff --git a/example/proguard-rules.txt b/example/proguard-rules.txt deleted file mode 100644 index d110c1e1b162557fe260dfd35ee1b97dd30c2a52..0000000000000000000000000000000000000000 --- a/example/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 /Users/henrik/Android-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/example/src/main/AndroidManifest.xml b/example/src/main/AndroidManifest.xml deleted file mode 100644 index 1d4adccd7212e12c6529186df957ee625db9f7c0..0000000000000000000000000000000000000000 --- a/example/src/main/AndroidManifest.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - diff --git a/example/src/main/java/com/wrapp/example/floatlabelededittext/MainActivity.java b/example/src/main/java/com/wrapp/example/floatlabelededittext/MainActivity.java deleted file mode 100644 index 6c2de49d08b68cea6035acb3ffae5fccf8ca358f..0000000000000000000000000000000000000000 --- a/example/src/main/java/com/wrapp/example/floatlabelededittext/MainActivity.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.wrapp.example.floatlabelededittext; - -import android.support.v7.app.ActionBarActivity; -import android.os.Bundle; -import android.view.Menu; -import android.view.MenuItem; - - -public class MainActivity extends ActionBarActivity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - } - - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - // Inflate the menu; this adds items to the action bar if it is present. - getMenuInflater().inflate(R.menu.main, 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); - } -} diff --git a/example/src/main/res/drawable-hdpi/ic_launcher.png b/example/src/main/res/drawable-hdpi/ic_launcher.png deleted file mode 100644 index 96a442e5b8e9394ccf50bab9988cb2316026245d..0000000000000000000000000000000000000000 Binary files a/example/src/main/res/drawable-hdpi/ic_launcher.png and /dev/null differ diff --git a/example/src/main/res/drawable-mdpi/ic_launcher.png b/example/src/main/res/drawable-mdpi/ic_launcher.png deleted file mode 100644 index 359047dfa4ed206e41e2354f9c6b307e713efe32..0000000000000000000000000000000000000000 Binary files a/example/src/main/res/drawable-mdpi/ic_launcher.png and /dev/null differ diff --git a/example/src/main/res/drawable-xhdpi/ic_launcher.png b/example/src/main/res/drawable-xhdpi/ic_launcher.png deleted file mode 100644 index 71c6d760f05183ef8a47c614d8d13380c8528499..0000000000000000000000000000000000000000 Binary files a/example/src/main/res/drawable-xhdpi/ic_launcher.png and /dev/null differ diff --git a/example/src/main/res/drawable-xxhdpi/ic_launcher.png b/example/src/main/res/drawable-xxhdpi/ic_launcher.png deleted file mode 100644 index 4df18946442ed763bd52cf3adca31617848656fa..0000000000000000000000000000000000000000 Binary files a/example/src/main/res/drawable-xxhdpi/ic_launcher.png and /dev/null differ diff --git a/example/src/main/res/layout/activity_main.xml b/example/src/main/res/layout/activity_main.xml deleted file mode 100644 index fc68963b1caba566d4f8fedc473292c0738ccae8..0000000000000000000000000000000000000000 --- a/example/src/main/res/layout/activity_main.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/example/src/main/res/menu/main.xml b/example/src/main/res/menu/main.xml deleted file mode 100644 index 7ff2c49cd83a9d472ee86e441be85681b4326db6..0000000000000000000000000000000000000000 --- a/example/src/main/res/menu/main.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/example/src/main/res/values-w820dp/dimens.xml b/example/src/main/res/values-w820dp/dimens.xml deleted file mode 100644 index 63fc816444614bd64f68a372d1f93211628ee51d..0000000000000000000000000000000000000000 --- a/example/src/main/res/values-w820dp/dimens.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - 64dp - diff --git a/example/src/main/res/values/dimens.xml b/example/src/main/res/values/dimens.xml deleted file mode 100644 index 47c82246738c4d056e8030d3a259206f42e8e15d..0000000000000000000000000000000000000000 --- a/example/src/main/res/values/dimens.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - 16dp - 16dp - diff --git a/example/src/main/res/values/strings.xml b/example/src/main/res/values/strings.xml deleted file mode 100644 index 516a7e30a9bd8962aae756d1651f17cfecc73032..0000000000000000000000000000000000000000 --- a/example/src/main/res/values/strings.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - Float Labeled Edittext Example - Hello world! - Settings - - diff --git a/example/src/main/res/values/styles.xml b/example/src/main/res/values/styles.xml deleted file mode 100644 index ac0952b1303662790c2373f60fa12d7d8fb46420..0000000000000000000000000000000000000000 --- a/example/src/main/res/values/styles.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - diff --git a/gradle.properties b/gradle.properties deleted file mode 100644 index a7826ca1e216ceff3a03dd22591dbe7a9ea6e894..0000000000000000000000000000000000000000 --- a/gradle.properties +++ /dev/null @@ -1,14 +0,0 @@ -VERSION_NAME=0.0.6 -VERSION_CODE=6 -GROUP=com.wrapp.floatlabelededittext - -POM_DESCRIPTION=Float Label Edittext for Android -POM_URL=https://github.com/wrapp/floatlabelededittext -POM_SCM_URL=https://github.com/wrapp/floatlabelededittext -POM_SCM_CONNECTION=scm:git@github.com:wrapp/floatlabelededittext.git -POM_SCM_DEV_CONNECTION=scm:git@github.com:wrapp/floatlabelededittext.git -POM_LICENCE_NAME=MIT License, Version 2.0 -POM_LICENCE_URL=http://opensource.org/licenses/MIT -POM_LICENCE_DIST=repo -POM_DEVELOPER_ID=heinrisch -POM_DEVELOPER_NAME=Henrik Sandström diff --git a/img/floatlabelededittext.gif b/img/floatlabelededittext.gif new file mode 100644 index 0000000000000000000000000000000000000000..f68a3173e58535ef97d4af767c252da4047db054 Binary files /dev/null and b/img/floatlabelededittext.gif differ diff --git a/library/.gitignore b/library/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..796b96d1c402326528b4ba3c12ee9d92d0e212e9 --- /dev/null +++ b/library/.gitignore @@ -0,0 +1 @@ +/build diff --git a/library/AndroidManifest.xml b/library/AndroidManifest.xml deleted file mode 100644 index fef014b68e65eeaad97145f94f4b4127cac5d18a..0000000000000000000000000000000000000000 --- a/library/AndroidManifest.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/library/build.gradle b/library/build.gradle index a1f175ddbea73735680b0b53e7ac439fc6fb849d..41ccbc47eeacae3270066ead4578951dfa63b058 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,27 +1,22 @@ -apply plugin: 'com.android.library' - -dependencies { - compile 'com.nineoldandroids:library:2.4.0' -} - -android { - compileSdkVersion 19 - buildToolsVersion '19.1.0' - - defaultConfig { - versionCode 6 - versionName "0.0.6" - minSdkVersion 7 - targetSdkVersion 19 - } - - sourceSets { - main { - manifest.srcFile 'AndroidManifest.xml' - java.srcDirs = ['src'] - res.srcDirs = ['res'] +apply plugin: 'com.huawei.ohos.library' +//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#section1112183053510 +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 5 + } + buildTypes { + release { + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } + } } - } + } -apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle' +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + testImplementation 'junit:junit:4.13' +} diff --git a/library/consumer-rules.pro b/library/consumer-rules.pro new file mode 100644 index 0000000000000000000000000000000000000000..9dccc613bc71b04b83531f550bdab2fb667ecfc9 --- /dev/null +++ b/library/consumer-rules.pro @@ -0,0 +1 @@ +# Add har specific ProGuard rules for consumer here. \ No newline at end of file diff --git a/library/proguard-rules.pro b/library/proguard-rules.pro new file mode 100644 index 0000000000000000000000000000000000000000..f7666e47561d514b2a76d5a7dfbb43ede86da92a --- /dev/null +++ b/library/proguard-rules.pro @@ -0,0 +1 @@ +# config module specific ProGuard rules here. \ No newline at end of file diff --git a/library/res/values/attrs.xml b/library/res/values/attrs.xml deleted file mode 100644 index 5815d092b3df6c1524619181b994fdbbb5ddba15..0000000000000000000000000000000000000000 --- a/library/res/values/attrs.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - diff --git a/library/src/com/wrapp/floatlabelededittext/FloatLabeledEditText.java b/library/src/com/wrapp/floatlabelededittext/FloatLabeledEditText.java deleted file mode 100644 index bbe777a62496434b6fd96a286dab5b0408d3facb..0000000000000000000000000000000000000000 --- a/library/src/com/wrapp/floatlabelededittext/FloatLabeledEditText.java +++ /dev/null @@ -1,209 +0,0 @@ -package com.wrapp.floatlabelededittext; - -import android.annotation.SuppressLint; -import android.annotation.TargetApi; -import android.content.Context; -import android.content.res.TypedArray; -import android.graphics.drawable.Drawable; -import android.os.Build; -import android.text.Editable; -import android.text.TextUtils; -import android.text.TextWatcher; -import android.util.AttributeSet; -import android.util.TypedValue; -import android.view.Gravity; -import android.view.View; -import android.view.ViewGroup; -import android.widget.EditText; -import android.widget.FrameLayout; -import android.widget.TextView; - -import com.nineoldandroids.animation.Animator; -import com.nineoldandroids.animation.AnimatorListenerAdapter; -import com.nineoldandroids.animation.AnimatorSet; -import com.nineoldandroids.animation.ObjectAnimator; -import com.nineoldandroids.view.animation.AnimatorProxy; - -public class FloatLabeledEditText extends FrameLayout { - - private static final int DEFAULT_PADDING_LEFT= 2; - - private TextView mHintTextView; - private EditText mEditText; - - private Context mContext; - - public FloatLabeledEditText(Context context) { - super(context); - mContext = context; - } - - public FloatLabeledEditText(Context context, AttributeSet attrs) { - super(context, attrs); - mContext = context; - setAttributes(attrs); - } - - @TargetApi(Build.VERSION_CODES.HONEYCOMB) - public FloatLabeledEditText(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - mContext = context; - setAttributes(attrs); - } - - private void setAttributes(AttributeSet attrs) { - mHintTextView = new TextView(mContext); - - final TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.FloatLabeledEditText); - - final int padding = a.getDimensionPixelSize(R.styleable.FloatLabeledEditText_fletPadding, 0); - final int defaultPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_PADDING_LEFT, getResources().getDisplayMetrics()); - final int paddingLeft = a.getDimensionPixelSize(R.styleable.FloatLabeledEditText_fletPaddingLeft, defaultPadding); - final int paddingTop = a.getDimensionPixelSize(R.styleable.FloatLabeledEditText_fletPaddingTop, 0); - final int paddingRight = a.getDimensionPixelSize(R.styleable.FloatLabeledEditText_fletPaddingRight, 0); - final int paddingBottom = a.getDimensionPixelSize(R.styleable.FloatLabeledEditText_fletPaddingBottom, 0); - Drawable background = a.getDrawable(R.styleable.FloatLabeledEditText_fletBackground); - - if (padding != 0) { - mHintTextView.setPadding(padding, padding, padding, padding); - } else { - mHintTextView.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); - } - - if (background != null) { - setHintBackground(background); - } - - mHintTextView.setTextAppearance(mContext, a.getResourceId(R.styleable.FloatLabeledEditText_fletTextAppearance, android.R.style.TextAppearance_Small)); - - //Start hidden - mHintTextView.setVisibility(INVISIBLE); - AnimatorProxy.wrap(mHintTextView).setAlpha(0); - - addView(mHintTextView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); - - a.recycle(); - } - - @SuppressLint("NewApi") - private void setHintBackground(Drawable background) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { - mHintTextView.setBackground(background); - } else { - mHintTextView.setBackgroundDrawable(background); - } - } - - @Override - public final void addView(View child, int index, ViewGroup.LayoutParams params) { - if (child instanceof EditText) { - if (mEditText != null) { - throw new IllegalArgumentException("Can only have one Edittext subview"); - } - - final LayoutParams lp = new LayoutParams(params); - lp.gravity = Gravity.BOTTOM; - lp.topMargin = (int) (mHintTextView.getTextSize() + mHintTextView.getPaddingBottom() + mHintTextView.getPaddingTop()); - params = lp; - - setEditText((EditText) child); - } - - super.addView(child, index, params); - } - - private void setEditText(EditText editText) { - mEditText = editText; - - mEditText.addTextChangedListener(new TextWatcher() { - - @Override - public void afterTextChanged(Editable s) { - setShowHint(!TextUtils.isEmpty(s)); - } - - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - } - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - } - - }); - - mEditText.setOnFocusChangeListener(new OnFocusChangeListener() { - @Override - public void onFocusChange(View view, boolean gotFocus) { - onFocusChanged(gotFocus); - } - }); - - mHintTextView.setText(mEditText.getHint()); - - if(!TextUtils.isEmpty(mEditText.getText())){ - mHintTextView.setVisibility(VISIBLE); - } - } - - private void onFocusChanged(boolean gotFocus) { - if (gotFocus && mHintTextView.getVisibility() == VISIBLE) { - ObjectAnimator.ofFloat(mHintTextView, "alpha", 0.33f, 1f).start(); - } else if (mHintTextView.getVisibility() == VISIBLE) { - AnimatorProxy.wrap(mHintTextView).setAlpha(1f); //Need this for compat reasons - ObjectAnimator.ofFloat(mHintTextView, "alpha", 1f, 0.33f).start(); - } - } - - private void setShowHint(final boolean show) { - AnimatorSet animation = null; - if ((mHintTextView.getVisibility() == VISIBLE) && !show) { - animation = new AnimatorSet(); - ObjectAnimator move = ObjectAnimator.ofFloat(mHintTextView, "translationY", 0, mHintTextView.getHeight() / 8); - ObjectAnimator fade = ObjectAnimator.ofFloat(mHintTextView, "alpha", 1, 0); - animation.playTogether(move, fade); - } else if ((mHintTextView.getVisibility() != VISIBLE) && show) { - animation = new AnimatorSet(); - ObjectAnimator move = ObjectAnimator.ofFloat(mHintTextView, "translationY", mHintTextView.getHeight() / 8, 0); - ObjectAnimator fade; - if (mEditText.isFocused()) { - fade = ObjectAnimator.ofFloat(mHintTextView, "alpha", 0, 1); - } else { - fade = ObjectAnimator.ofFloat(mHintTextView, "alpha", 0, 0.33f); - } - animation.playTogether(move, fade); - } - - if (animation != null) { - animation.addListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationStart(Animator animation) { - super.onAnimationStart(animation); - mHintTextView.setVisibility(VISIBLE); - } - - @Override - public void onAnimationEnd(Animator animation) { - super.onAnimationEnd(animation); - mHintTextView.setVisibility(show ? VISIBLE : INVISIBLE); - AnimatorProxy.wrap(mHintTextView).setAlpha(show ? 1 : 0); - } - }); - animation.start(); - } - } - - public EditText getEditText() { - return mEditText; - } - - public void setHint(String hint) { - mEditText.setHint(hint); - mHintTextView.setText(hint); - } - - public CharSequence getHint() { - return mHintTextView.getHint(); - } - -} diff --git a/library/src/com/wrapp/floatlabelededittext/Utils.java b/library/src/com/wrapp/floatlabelededittext/Utils.java deleted file mode 100644 index 86da0f07689fce03ed60044a8b83cd49ae25ada3..0000000000000000000000000000000000000000 --- a/library/src/com/wrapp/floatlabelededittext/Utils.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.wrapp.floatlabelededittext; - -import java.util.concurrent.atomic.AtomicInteger; - -import android.annotation.SuppressLint; -import android.os.Build; -import android.view.View; - -public class Utils { - - private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1); - - /** - * Generate a value suitable for use in {@link #setId(int)}. - * This value will not collide with ID values generated at build time by aapt for R.id. - * - * @return a generated ID value - */ - private static int generateViewId() { - for (;;) { - final int result = sNextGeneratedId.get(); - // aapt-generated IDs have the high byte nonzero; clamp to the range under that. - int newValue = result + 1; - if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0. - if (sNextGeneratedId.compareAndSet(result, newValue)) { - return result; - } - } - } - - @SuppressLint("NewApi") - public static int generateId() { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { - - return generateViewId(); - } else { - - return View.generateViewId(); - } - } - -} diff --git a/library/src/main/config.json b/library/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..525036ceb3195bdde5c93bf8312347dbadd9f705 --- /dev/null +++ b/library/src/main/config.json @@ -0,0 +1,23 @@ +{ + "app": { + "bundleName": "com.wrapp.example.floatlabelededittext", + "vendor": "wrapp", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": { + }, + "module": { + "package": "com.wrapp.floatlabelededittext", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "library", + "moduleType": "har" + } + } +} \ No newline at end of file diff --git a/library/src/main/java/com/wrapp/floatlabelededittext/FloatLabeledEditText.java b/library/src/main/java/com/wrapp/floatlabelededittext/FloatLabeledEditText.java new file mode 100644 index 0000000000000000000000000000000000000000..43f3f467224656fa815c2f13eeb525ef9dd60403 --- /dev/null +++ b/library/src/main/java/com/wrapp/floatlabelededittext/FloatLabeledEditText.java @@ -0,0 +1,280 @@ +package com.wrapp.floatlabelededittext; + +import ohos.agp.animation.Animator; +import ohos.agp.animation.AnimatorGroup; +import ohos.agp.animation.AnimatorProperty; +import ohos.agp.colors.RgbColor; +import ohos.agp.components.*; +import ohos.agp.components.element.Element; +import ohos.agp.components.element.ShapeElement; +import ohos.agp.text.Font; +import ohos.agp.utils.Color; +import ohos.app.Context; + +/** + * 浮动TextField + * + * @since 2021-08-04 + */ +public class FloatLabeledEditText extends StackLayout { + private static final int DEFAULT_PADDING_LEFT = 2; + + private Text mHintTextView; + private TextField mEditText; + private ShapeElement getFocusElement = new ShapeElement(); + private ShapeElement loseFocusElement = new ShapeElement(); + + private Context mContext; + + /** + * 构造方法 + * + * @param context + */ + public FloatLabeledEditText(Context context) { + super(context); + mContext = context; + } + + /** + * 构造方法 + * + * @param context + * @param attrSet + */ + public FloatLabeledEditText(Context context, AttrSet attrSet) { + super(context, attrSet); + mContext = context; + setAttributes(attrSet); + } + + /** + * 构造方法 + * + * @param context + * @param attrSet + * @param styleName + */ + public FloatLabeledEditText(Context context, AttrSet attrSet, String styleName) { + super(context, attrSet, styleName); + mContext = context; + setAttributes(attrSet); + } + + private void setAttributes(AttrSet attrSet) { + mHintTextView = new Text(mContext); + mHintTextView.setTextSize(39); + TypedArray a = new TypedArray(attrSet); + + final int defaultPadding = 5; + final int padding = a.getDimensionValue("fletPadding", 0); + final int paddingLeft = a.getDimensionValue("fletPaddingLeft", defaultPadding); + final int paddingTop = a.getDimensionValue("fletPaddingTop", 0); + final int paddingRight = a.getDimensionValue("fletPaddingRight", 0); + final int paddingBottom = a.getDimensionValue("fletPaddingBottom", 0); + final boolean isBold = a.getBoolean("fletIsBold", false); + final boolean isIncline = a.getBoolean("fletisIncline", false); + Element background = a.getElement("fletBackground"); + + if (padding != 0) { + mHintTextView.setPadding(padding, padding, padding, padding); + } else { + mHintTextView.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); + } + + if (background != null) { + setHintBackground(background); + } + + if (isBold) { + mHintTextView.setFont(Font.DEFAULT_BOLD); + } + + if (isIncline) { + mHintTextView.setFont(Font.SANS_SERIF); + } + + mHintTextView.setTextColor(a.getColor("fletTextAppearance", Color.getIntColor("#7F7F7F"))); + + mHintTextView.setVisibility(Component.INVISIBLE); + mHintTextView.setAlpha(0); + + getFocusElement.setRgbColor(new RgbColor(66, 171, 160)); + loseFocusElement.setRgbColor(new RgbColor(131, 131, 131)); + + addComponent(mHintTextView, LayoutConfig.MATCH_PARENT, LayoutConfig.MATCH_CONTENT); + } + + @SuppressLint("NewApi") + private void setHintBackground(Element background) { + mHintTextView.setBackground(background); + } + + @Override + public final void addComponent(Component child) { + if (child instanceof TextField) { + if (mEditText != null) { + throw new IllegalArgumentException("Can only have one Edittext subview"); + } + + LayoutConfig lp = new LayoutConfig(); + lp.width = DependentLayout.LayoutConfig.MATCH_PARENT; + int i = mHintTextView.getTextSize() + mHintTextView.getPaddingBottom() + mHintTextView.getPaddingTop(); + lp.setMarginTop(i); + child.setLayoutConfig(lp); + setTextField((TextField)child); + } + super.addComponent(child); + } + + private void setTextField(TextField editText) { + mEditText = editText; + + mEditText.addTextObserver(new Text.TextObserver() { + @Override + public void onTextUpdated(String s, int i, int i1, int i2) { + if (!s.equals("\n")) { + setShowHint(!s.isEmpty()); + } + } + }); + + mEditText.setFocusChangedListener(new FocusChangedListener() { + @Override + public void onFocusChange(Component component, boolean gotFocus) { + onFocusChanged(gotFocus); + } + }); + + mHintTextView.setText(mEditText.getHint()); + + if (!mEditText.getText().isEmpty()) { + mHintTextView.setVisibility(VISIBLE); + } + } + + private void onFocusChanged(boolean gotFocus) { + if (gotFocus) { + mEditText.setBasement(getFocusElement); + } else { + mEditText.setBasement(loseFocusElement); + } + if (gotFocus && mHintTextView.getVisibility() == VISIBLE) { + mHintTextView.createAnimatorProperty().alphaFrom(0.33f).alpha(1).start(); + } else if (mHintTextView.getVisibility() == VISIBLE) { + mHintTextView.createAnimatorProperty().alphaFrom(1f).alpha(0.33f).start(); + } + } + + private void setShowHint(boolean show) { + AnimatorGroup animation = new AnimatorGroup(); + AnimatorGroup.Builder build = animation.build(); + if ((mHintTextView.getVisibility() == VISIBLE) && !show) { + AnimatorProperty move = mHintTextView.createAnimatorProperty() + .moveFromY(0).moveToY(mHintTextView.getHeight() / 8); + AnimatorProperty fade = mHintTextView.createAnimatorProperty().alphaFrom(1).alpha(0); + build.addAnimators(move, fade); + } else if ((mHintTextView.getVisibility() != VISIBLE) && show) { + AnimatorProperty move = mHintTextView.createAnimatorProperty() + .moveFromY(mHintTextView.getHeight() / 8).moveToY(0); + AnimatorProperty fade; + if (mEditText.isFocused()) { + fade = mHintTextView.createAnimatorProperty().alphaFrom(0).alpha(1); + } else { + fade = mHintTextView.createAnimatorProperty().alphaFrom(0).alpha(0.33f); + } + build.addAnimators(move, fade); + } + + if (animation != null) { + animation.setStateChangedListener(new Animator.StateChangedListener() { + @Override + public void onStart(Animator animator) { + mHintTextView.setVisibility(VISIBLE); + } + + @Override + public void onStop(Animator animator) { + } + + @Override + public void onCancel(Animator animator) { + } + + @Override + public void onEnd(Animator animator) { + mHintTextView.setVisibility(show ? VISIBLE : INVISIBLE); + if (show) { + mHintTextView.createAnimatorProperty().alpha(1).start(); + } else { + mHintTextView.createAnimatorProperty().alpha(0).start(); + } + } + + @Override + public void onPause(Animator animator) { + } + + @Override + public void onResume(Animator animator) { + } + }); + animation.start(); + } + } + + /** + * 获取内部TextField + * + * @return TextField + */ + public TextField getEditText() { + return mEditText; + } + + /** + * 设置Hint + * + * @param hint + */ + public void setHint(String hint) { + mEditText.setHint(hint); + mHintTextView.setText(hint); + } + + /** + * 获取Hint + * + * @return CharSequence + */ + public CharSequence getHint() { + return mHintTextView.getHint(); + } + + /** + * 设置浮动文字大小 + * + * @param size + */ + public void setHintTextSize(int size) { + mHintTextView.setTextSize(size); + } + + /** + * 设置子TextField获取到焦点时的下方Basement颜色 + * + * @param rgbColor + */ + public void setGetFocusElement(RgbColor rgbColor) { + getFocusElement.setRgbColor(rgbColor); + } + + /** + * 设置子TextField失去焦点后下方Basement颜色 + * + * @param rgbColor + */ + public void setLoseFocusElement(RgbColor rgbColor) { + loseFocusElement.setRgbColor(rgbColor); + } +} \ No newline at end of file diff --git a/library/src/main/java/com/wrapp/floatlabelededittext/SuppressLint.java b/library/src/main/java/com/wrapp/floatlabelededittext/SuppressLint.java new file mode 100644 index 0000000000000000000000000000000000000000..f1a2ffc278e043e6b98cccab834a3f1137f213f4 --- /dev/null +++ b/library/src/main/java/com/wrapp/floatlabelededittext/SuppressLint.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.wrapp.floatlabelededittext; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.*; + +/** Indicates that Lint should ignore the specified warnings for the annotated element. */ +@Target({TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE}) +@Retention(RetentionPolicy.CLASS) +public @interface SuppressLint { + /** + * The set of warnings (identified by the lint issue id) that should be + * ignored by lint. It is not an error to specify an unrecognized name. + */ + String[] value(); +} \ No newline at end of file diff --git a/library/src/main/java/com/wrapp/floatlabelededittext/TypedArray.java b/library/src/main/java/com/wrapp/floatlabelededittext/TypedArray.java new file mode 100644 index 0000000000000000000000000000000000000000..8f73338377d24b14d0c61b0a957516862e198ea6 --- /dev/null +++ b/library/src/main/java/com/wrapp/floatlabelededittext/TypedArray.java @@ -0,0 +1,155 @@ +/* + * 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.wrapp.floatlabelededittext; + +import ohos.agp.components.AttrSet; +import ohos.agp.components.element.Element; +import ohos.agp.utils.Color; + +/** + * 获取自定义属性类 + * + * @since 2021-08-04 + */ +public class TypedArray { + private AttrSet attrSet; + + /** + * 构造方法 + * + * @param attrSet + */ + public TypedArray(AttrSet attrSet) { + this.attrSet = attrSet; + } + + /** + * 获取vp fp属性 + * + * @param value + * @param defaultValue + * @return int + */ + public int getDimensionValue(String value, int defaultValue) { + if (attrSet.getAttr(value).isPresent()) { + return attrSet.getAttr(value).get().getDimensionValue(); + } else { + return defaultValue; + } + } + + /** + * 获取颜色属性 + * + * @param value + * @param defaultValue + * @return Color + */ + public Color getColor(String value, int defaultValue) { + if (attrSet.getAttr(value).isPresent()) { + return attrSet.getAttr(value).get().getColorValue(); + } else { + return new Color(defaultValue); + } + } + + /** + * 获取float属性 + * + * @param value + * @param defaultValue + * @return float + */ + public float getFloat(String value, float defaultValue) { + if (attrSet.getAttr(value).isPresent()) { + return attrSet.getAttr(value).get().getFloatValue(); + } else { + return defaultValue; + } + } + + /** + * 获取int属性 + * + * @param value + * @param defaultValue + * @return int + */ + public int getInt(String value, int defaultValue) { + if (attrSet.getAttr(value).isPresent()) { + return attrSet.getAttr(value).get().getIntegerValue(); + } else { + return defaultValue; + } + } + + /** + * 获取Boolean属性 + * + * @param value + * @param defaultValue + * @return boolean + */ + public boolean getBoolean(String value, boolean defaultValue) { + if (attrSet.getAttr(value).isPresent()) { + return attrSet.getAttr(value).get().getBoolValue(); + } else { + return defaultValue; + } + } + + /** + * 获取String属性 + * + * @param value + * @return String + */ + public String getString(String value) { + if (attrSet.getAttr(value).isPresent()) { + return attrSet.getAttr(value).get().getStringValue(); + } else { + return null; + } + } + + /** + * 判断是否声明当前属性 + * + * @param value + * @return boolean + */ + public boolean hasValue(String value) { + if (attrSet.getAttr(value).isPresent()) { + return true; + } else { + return false; + } + } + + /** + * 获取Element值 + * + * @param value + * @return Element + */ + public Element getElement(String value) { + if (attrSet.getAttr(value).isPresent()) { + return attrSet.getAttr(value).get().getElement(); + } else { + return null; + } + } +} diff --git a/library/src/main/java/com/wrapp/floatlabelededittext/Untils.java b/library/src/main/java/com/wrapp/floatlabelededittext/Untils.java new file mode 100644 index 0000000000000000000000000000000000000000..c388c41018ad326107f99be1bec412d657d3b34a --- /dev/null +++ b/library/src/main/java/com/wrapp/floatlabelededittext/Untils.java @@ -0,0 +1,40 @@ +package com.wrapp.floatlabelededittext; + +import ohos.agp.components.Component; + +import java.util.concurrent.atomic.AtomicInteger; + +public class Untils { + private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1); + + /** + * Generate a value suitable for use in {@link #setId(int)}. + * This value will not collide with ID values generated at build time by aapt for R.id. + * + * @return a generated ID value + */ + private static int generateViewId() { + for (;;) { + final int result = sNextGeneratedId.get(); + + // aapt-generated IDs have the high byte nonzero; clamp to the range under that. + int newValue = result + 1; + if (newValue > 0x00FFFFFF) { + newValue = 1; + } + if (sNextGeneratedId.compareAndSet(result, newValue)) { + return result; + } + } + } + + /** + * generateId + * + * @return int + */ + @SuppressLint("NewApi") + public static int generateId() { + return generateViewId(); + } +} diff --git a/library/src/main/resources/base/element/string.json b/library/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..211a936b6a562815c346636393376e8f1a72a08e --- /dev/null +++ b/library/src/main/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "library_library", + "value": "library_library" + } + ] +} diff --git a/library/src/test/java/com/wrapp/floatlabelededittext/ExampleTest.java b/library/src/test/java/com/wrapp/floatlabelededittext/ExampleTest.java new file mode 100644 index 0000000000000000000000000000000000000000..a817381ba4924b2a4adf905808cf5edfdef952d7 --- /dev/null +++ b/library/src/test/java/com/wrapp/floatlabelededittext/ExampleTest.java @@ -0,0 +1,9 @@ +package com.wrapp.floatlabelededittext; + +import org.junit.Test; + +public class ExampleTest { + @Test + public void onStart() { + } +} diff --git a/settings.gradle b/settings.gradle index 7294b5837e9fe73624dc8bef5ae81b4a5d7668e2..d0c7ee8440156d4a9324ac5357770747425fef57 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':library', ':example' +include ':entry', ':library'