# tooltips **Repository Path**: chinasoft2_ohos/tooltips ## Basic Information - **Project Name**: tooltips - **Description**: Simple to use library for openharmony, enabling to add a tooltip near any view with ease - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2021-05-08 - **Last Updated**: 2024-06-16 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # tooltips #### 项目介绍 - 项目名称:tooltips - 所属系列:openharmony的第三方组件适配移植 - 功能:易于使用的ohos库,可轻松在任何视图附近添加工具提示 - 项目移植状态:主功能完成 - 调用差异:无 - 开发版本:sdk6,DevEco Studio 2.2 Beta1 - 基线版本:Release v1.1.0 #### 效果演示 #### 安装教程 1、在项目根目录下的build.gradle文件中 ```gradle allprojects { repositories { maven { url 'https://s01.oss.sonatype.org/content/repositories/releases/' } } } ``` 2.在app模块的build.gradle文件中 ```gradle dependencies { implementation('com.gitee.chinasoft_ohos:tooltips:1.0.0') ...... } ``` 在sdk6,DevEco Studio 2.2 Beta1下项目可直接运行, 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下 #### 使用说明 1.如何开始 创建一个ToolTipsManager对象 ``` ToolTipsManager mToolTipsManager; @Override public void onStart(Intent intent) { super.onStart(intent); getWindow().addFlags(WindowManager.LayoutConfig.MARK_TRANSLUCENT_STATUS); super.setUIContent(ResourceTable.Layout_ability_main); mToolTipsManager = new ToolTipsManager(MainAbilitySlice.this); ``` 2.使用mToolTipsManager 设置子类位置,大小,背景,文字等 ``` case ResourceTable.Id_button_above: tag = 1; builder = new ToolTip.Builder(this, mTextView); mToolTipsManager.show(tag,builder.build()); break; ``` 3.位置的实现ToolTipCoordinatesFinder类 根据点击的不同方向计算出位置 获取view上部位置 ``` float leftAbovey = textView.getContentPositionY() - idAboveImageview.getEstimatedHeight(); float leftAbovex = textView.getContentPositionX() + textView.getEstimatedWidth() / 2 - idAboveImageview.getEstimatedWidth() / 2; idAboveImageview.setContentPosition(leftAbovex, leftAbovey); ``` 获取view下部位置 ``` float leftBelowy = mTextView.getContentPositionY() + mTextView.getEstimatedHeight(); float leftBelowx = mTextView.getContentPositionX() + mTextView.getEstimatedWidth() / 2 - idBelowimageView.getEstimatedWidth() / 2; idBelowimageView.setContentPosition(leftBelowx, leftBelowy); ``` 4.加载动画DefaultToolTipAnimator类 动画加载调用方法 ``` public AnimatorProperty popup(Component view, long duration) { view.setVisibility(Component.VISIBLE); AnimatorProperty abovePopup = new AnimatorProperty(); abovePopup.alphaFrom(0).alpha(90).setCurveType(new Animator.CurveType().ANTICIPATE).setDuration(500); abovePopup.setTarget(view); return abovePopup; } ``` 动画消失调用方法 ``` public AnimatorProperty popout(final Component view, final long duration, final AnimatorProperty animatorListenerAdapter) { AnimatorProperty animatorValue = new AnimatorProperty(); animatorValue.alpha(0).scaleX(0).scaleY(0).setDuration(duration).setCurveType(3);...... ``` 5.设置背景类ToolTipBackgroundConstructor ``` 根据点击的不同方向设置加载不同的图片 static void setBackground(Text idAboveImageview, int imgResouse) { try { PixelMapElement pixelMapElement = new PixelMapElement(idAboveImageview.getResourceManager().getResource(imgResouse)); idAboveImageview.setBackground(pixelMapElement); } catch (IOException e) { e.printStackTrace(); } catch (NotExistException e) { e.printStackTrace(); } } ``` #### 测试信息 ``` CodeCheck代码测试无异常 CloudTest代码测试无异常 病毒安全检测通过 当前版本demo功能与原组件基本无差异 ``` #### 版本迭代 - 1.0.0 #### 版权和许可信息 ``` Copyright 2016 Tomer Goldstein 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. ```