├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── zhy │ │ └── highlight │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── zhy │ │ └── highlight │ │ ├── LeakCanaryApplication.java │ │ └── MainActivity.java │ └── res │ ├── drawable-xxhdpi │ ├── info_text.png │ ├── jt_down.png │ ├── jt_known.png │ └── jt_up.png │ ├── layout │ ├── activity_main.xml │ ├── info_down.xml │ ├── info_gravity_left_down.xml │ ├── info_gravity_right_up.xml │ ├── info_known.xml │ └── info_up.xml │ ├── menu │ └── menu_main.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── arrays.xml │ ├── attr.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gif ├── high_light_demo.gif ├── highlight.gif ├── highlight2.gif ├── highlight3.png └── light03.gif ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── highlight ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── zhy │ │ └── com │ │ └── highlight │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── zhy │ │ └── com │ │ └── highlight │ │ ├── HighLight.java │ │ ├── interfaces │ │ └── HighLightInterface.java │ │ ├── position │ │ ├── OnBaseCallback.java │ │ ├── OnBottomPosCallback.java │ │ ├── OnLeftPosCallback.java │ │ ├── OnRightPosCallback.java │ │ └── OnTopPosCallback.java │ │ ├── shape │ │ ├── BaseLightShape.java │ │ ├── CircleLightShape.java │ │ ├── OvalLightShape.java │ │ └── RectLightShape.java │ │ ├── util │ │ ├── L.java │ │ └── ViewUtils.java │ │ └── view │ │ └── HightLightView.java │ └── res │ └── values │ ├── ids.xml │ └── strings.xml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea 4 | .DS_Store 5 | /build 6 | /captures 7 | 8 | ### OSX template 9 | *.DS_Store 10 | .AppleDouble 11 | .LSOverride 12 | 13 | # Icon must end with two \r 14 | Icon 15 | 16 | # Thumbnails 17 | ._* 18 | 19 | # Files that might appear in the root of a volume 20 | .DocumentRevisions-V100 21 | .fseventsd 22 | .Spotlight-V100 23 | .TemporaryItems 24 | .Trashes 25 | .VolumeIcon.icns 26 | .com.apple.timemachine.donotpresent 27 | 28 | # Directories potentially created on remote AFP share 29 | .AppleDB 30 | .AppleDesktop 31 | Network Trash Folder 32 | Temporary Items 33 | .apdisk 34 | 35 | ### Android template 36 | # Built application files 37 | *.apk 38 | *.ap_ 39 | 40 | # Files for the ART/Dalvik VM 41 | *.dex 42 | 43 | # Java class files 44 | *.class 45 | 46 | # Generated files 47 | bin/ 48 | gen/ 49 | out/ 50 | 51 | # Gradle files 52 | .gradle/ 53 | build/ 54 | 55 | # Local configuration file (sdk path, etc) 56 | local.properties 57 | 58 | # Proguard folder generated by Eclipse 59 | proguard/ 60 | 61 | # Log Files 62 | *.log 63 | 64 | # Android Studio Navigation editor temp files 65 | .navigation/ 66 | 67 | # Android Studio captures folder 68 | captures/ 69 | 70 | # Intellij 71 | *.iml 72 | .idea/workspace.xml 73 | 74 | # Keystore files 75 | *.jks 76 | 77 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | CHANGELOG 2 | ================= 3 | 4 | | 操作 | 时间 | 版本 | 详情 | 5 | | ------|------ |------| ------| 6 | | `A` | 2016/9/26 | v1.2.0 | 添加点击高亮布局背景是否自动移除标志`autoRemove` | 7 | | `A` | 2016/10/5 | v1.3.0 | 添加Next模式-按顺序依次显示添加的提示布局
&&给`HighLightView`添加唯一id防止重复添加 | 8 | | `F` | 2016/10/8 | v1.3.1 | 修复Next模式-HightLightView中校验mPostion问题 | 9 | | `I` | 2016/10/27 | v1.4.0 | 扩展高亮形状`LightShape`支持开发者自定义配置 | 10 | | `A` | 2016/11/01 | v1.5.0 | 为`HighLight`添加接口约束| 11 | | `A` | 2016/11/01 | v1.5.1 | 显示与隐藏监听及`isShowing`属性 | 12 | | `I` | 2016/11/02 | v1.5.2 | 优化`HightLightView`中提示布局添加与显示 兼容`AutoFrameLayout` | 13 | | `A` | 2016/11/16 | v1.6.0 | 添加椭圆高亮形状&修复显示问题 | 14 | | `A` | 2016/11/25 | v1.7.0 | 添加下一个监听 回调返回当前的目标控件及提示控件| 15 | | `R` | 2016/12/02 | v1.7.1 | 显示及移除回调不依赖`intercept`属性 | 16 | | `F` | 2016/12/07 | v1.7.2 | 修复#21 在`ViewPager`中用户获取目标布局位置信息错误 | 17 | | `I` | 2016/12/14 | v1.7.3 | `RectLightShape`构造函数添加x-radius和y-radius圆角半径属性 | 18 | | `F` | 2016/12/21 | v1.7.4 | 修复`HightLightView`绘制时图片回收异常 | 19 | | `F` | 2017/1/3 | v1.7.5 | 修复`ViewUtils#getLocationInView`中获取位置空异常 | 20 | | `A` | 2017/5/25 | v1.8.0 | 添加`setOnLayoutCallback`回调 支持onCreated中初始化,界面布局完成显示 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Highlight 2 | [ ![Download](https://api.bintray.com/packages/isanwenyu/maven/Highlight/images/download.svg) ](https://bintray.com/isanwenyu/maven/Highlight/_latestVersion) 3 | 4 | 一个用于app指向性功能高亮的库。 5 | 6 | 有任何意见,欢迎提issue。新建dev分支,欢迎pull request。 7 | 8 | ## 效果图 9 | 10 | 竖屏: 11 | 12 | 13 | 14 | 横屏: 15 | 16 | 17 | 18 | 19 | ## 引入 20 | 21 | 下载代码,然后: 22 | 23 | ```xml 24 | dependencies { 25 | compile project(':highlight') 26 | } 27 | 28 | ``` 29 | 30 | 或者 31 | 32 | ``` 33 | compile 'com.isanwenyu.highlight:highlight:1.8.0' 34 | ``` 35 | 再或者 36 | 37 | ``` 38 | 39 | com.isanwenyu.highlight 40 | highlight 41 | 1.8.0 42 | pom 43 | 44 | 45 | ``` 46 | ## 用法 47 | 48 | > 最新用法详情:[https://isanwenyu.github.io/2016/11/23/HighLight-latest-usage/ 49 | ](https://isanwenyu.github.io/2016/11/23/HighLight-latest-usage/) 50 | 51 | ### Next Mode 下一步模式 52 | > Enable next mode and invoke show() method then invoke next() method in HighLight to display tip view in order till remove itself 53 | > 调用`enableNext()`开启next模式并显示,然后调用next()方法显示下一个提示布局 直到删除自己 54 | 55 | #### 1. 开启next模式并显示 56 | 57 | 58 | ``` 59 | /** 60 | * 显示 next模式 我知道了提示高亮布局 61 | * @param view id为R.id.iv_known的控件 62 | * @author isanwenyu@163.com 63 | */ 64 | public void showNextKnownTipView(View view) 65 | { 66 | mHightLight = new HighLight(MainActivity.this)// 67 | .autoRemove(false)//设置背景点击高亮布局自动移除为false 默认为true 68 | // .intercept(false)//设置拦截属性为false 高亮布局不影响后面布局的滑动效果 69 | .intercept(true)//拦截属性默认为true 使下方ClickCallback生效 70 | .enableNext()//开启next模式并通过show方法显示 然后通过调用next()方法切换到下一个提示布局,直到移除自身 71 | // .setClickCallback(new HighLight.OnClickCallback() { 72 | // @Override 73 | // public void onClick() { 74 | // Toast.makeText(MainActivity.this, "clicked and remove HightLight view by yourself", Toast.LENGTH_SHORT).show(); 75 | // remove(null); 76 | // } 77 | // }) 78 | .anchor(findViewById(R.id.id_container))//如果是Activity上增加引导层,不需要设置anchor 79 | .addHighLight(R.id.btn_rightLight,R.layout.info_known,new OnLeftPosCallback(45),new RectLightShape(0,0,15,0,0))//矩形去除圆角 80 | .addHighLight(R.id.btn_light,R.layout.info_known,new OnRightPosCallback(5),new BaseLightShape(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,5,getResources().getDisplayMetrics()), TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,5,getResources().getDisplayMetrics()),0) { 81 | @Override 82 | protected void resetRectF4Shape(RectF viewPosInfoRectF, float dx, float dy) { 83 | //缩小高亮控件范围 84 | viewPosInfoRectF.inset(dx,dy); 85 | } 86 | 87 | @Override 88 | protected void drawShape(Bitmap bitmap, HighLight.ViewPosInfo viewPosInfo) { 89 | //custom your hight light shape 自定义高亮形状 90 | Canvas canvas = new Canvas(bitmap); 91 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); 92 | paint.setDither(true); 93 | paint.setAntiAlias(true); 94 | //blurRadius必须大于0 95 | if(blurRadius>0){ 96 | paint.setMaskFilter(new BlurMaskFilter(blurRadius, BlurMaskFilter.Blur.SOLID)); 97 | } 98 | RectF rectF = viewPosInfo.rectF; 99 | canvas.drawOval(rectF, paint); 100 | } 101 | }) 102 | .addHighLight(R.id.btn_bottomLight,R.layout.info_known,new OnTopPosCallback(),new CircleLightShape()) 103 | .addHighLight(view,R.layout.info_known,new OnBottomPosCallback(10),new OvalLightShape(5,5,20)) 104 | .setOnRemoveCallback(new HighLightInterface.OnRemoveCallback() {//监听移除回调 105 | @Override 106 | public void onRemove() { 107 | Toast.makeText(MainActivity.this, "The HightLight view has been removed", Toast.LENGTH_SHORT).show(); 108 | 109 | } 110 | }) 111 | .setOnShowCallback(new HighLightInterface.OnShowCallback() {//监听显示回调 112 | @Override 113 | public void onShow(HightLightView hightLightView) { 114 | Toast.makeText(MainActivity.this, "The HightLight view has been shown", Toast.LENGTH_SHORT).show(); 115 | } 116 | }).setOnNextCallback(new HighLightInterface.OnNextCallback() { 117 | @Override 118 | public void onNext(HightLightView hightLightView, View targetView, View tipView) { 119 | // targetView 目标按钮 tipView添加的提示布局 可以直接找到'我知道了'按钮添加监听事件等处理 120 | Toast.makeText(MainActivity.this, "The HightLight show next TipView,targetViewID:"+(targetView==null?null:targetView.getId())+",tipViewID:"+(tipView==null?null:tipView.getId()), Toast.LENGTH_SHORT).show(); 121 | } 122 | }); 123 | mHightLight.show(); 124 | } 125 | ``` 126 | 127 | #### 2. 调用next()方法依次显示之前添加到提示布局 最后自动移除 128 | 129 | ``` 130 | /** 131 | * 响应所有R.id.iv_known的控件的点击事件 132 | *

133 | * 移除高亮布局 134 | *

135 | * 136 | * @param view 137 | */ 138 | public void clickKnown(View view) 139 | { 140 | if(mHightLight.isShowing() && mHightLight.isNext())//如果开启next模式 141 | { 142 | mHightLight.next(); 143 | }else 144 | { 145 | remove(null); 146 | } 147 | } 148 | ``` 149 | #### 3. 下一步回调监听 150 | 151 | ``` 152 | /** 153 | * 下一个回调监听 只有Next模式下生效 154 | */ 155 | public static interface OnNextCallback { 156 | /** 157 | * 监听下一步动作 158 | * 159 | * @param hightLightView 高亮布局控件 160 | * @param targetView 高亮目标控件 161 | * @param tipView 高亮提示控件 162 | */ 163 | void onNext(HightLightView hightLightView, View targetView, View tipView); 164 | } 165 | ``` 166 | 167 | #### 4. mAnchor根布局完成回调监听(页面加载完成,自动显示) 168 | > 针对下方问题4的优化方案 在Activity或Fragment onCreated方法中构造HighLight 169 | > 通过mAnchor.getViewTreeObserver().addOnGlobalLayoutListener(this)实现 170 | 171 | 172 | ``` 173 | /** 174 | * 当界面布局完成显示next模式提示布局 175 | * 显示方法必须在onLayouted中调用 176 | * 适用于Activity及Fragment中使用 177 | * 可以直接在onCreated方法中调用 178 | * @author isanwenyu@163.com 179 | */ 180 | public void showNextTipViewOnCreated(){ 181 | mHightLight = new HighLight(MainActivity.this)// 182 | .anchor(findViewById(R.id.id_container))//如果是Activity上增加引导层,不需要设置anchor 183 | .autoRemove(false) 184 | .enableNext() 185 | .setOnLayoutCallback(new HighLightInterface.OnLayoutCallback() { 186 | @Override 187 | public void onLayouted() { 188 | //mAnchor界面布局完成添加tipview 189 | mHightLight.addHighLight(R.id.btn_rightLight,R.layout.info_gravity_left_down,new OnLeftPosCallback(45),new RectLightShape()) 190 | .addHighLight(R.id.btn_light,R.layout.info_gravity_left_down,new OnRightPosCallback(5),new CircleLightShape()) 191 | .addHighLight(R.id.btn_bottomLight,R.layout.info_gravity_left_down,new OnTopPosCallback(),new CircleLightShape()); 192 | //然后显示高亮布局 193 | mHightLight.show(); 194 | } 195 | }) 196 | .setClickCallback(new HighLight.OnClickCallback() { 197 | @Override 198 | public void onClick() { 199 | Toast.makeText(MainActivity.this, "clicked and show next tip view by yourself", Toast.LENGTH_SHORT).show(); 200 | mHightLight.next(); 201 | } 202 | }); 203 | } 204 | 205 | ``` 206 | 207 | ### Nomarl Mode 普通模式 208 | 209 | 对于上面效果图中的一个需要高亮的View,需要通过下面的代码 210 | 211 | ``` 212 | /** 213 | * 显示我知道了提示高亮布局 214 | * @param view id为R.id.iv_known的控件 215 | * @author isanwenyu@163.com 216 | */ 217 | public void showKnownTipView(View view) 218 | { 219 | mHightLight = new HighLight(MainActivity.this)// 220 | .autoRemove(false)//设置背景点击高亮布局自动移除为false 默认为true 221 | .intercept(false)//设置拦截属性为false 高亮布局不影响后面布局的滑动效果 而且使下方点击回调失效 222 | .setClickCallback(new HighLight.OnClickCallback() { 223 | @Override 224 | public void onClick() { 225 | Toast.makeText(MainActivity.this, "clicked and remove HightLight view by yourself", Toast.LENGTH_SHORT).show(); 226 | remove(null); 227 | } 228 | }) 229 | .anchor(findViewById(R.id.id_container))//如果是Activity上增加引导层,不需要设置anchor 230 | .addHighLight(R.id.btn_rightLight,R.layout.info_known,new OnLeftPosCallback(45),new RectLightShape()) 231 | .addHighLight(R.id.btn_light,R.layout.info_known,new OnRightPosCallback(5),new CircleLightShape(0,0,0)) 232 | .addHighLight(R.id.btn_bottomLight,R.layout.info_known,new OnTopPosCallback(),new CircleLightShape()) 233 | .addHighLight(view,R.layout.info_known,new OnBottomPosCallback(10),new OvalLightShape(5,5,20)); 234 | mHightLight.show(); 235 | 236 | // //added by isanwenyu@163.com 设置监听器只有最后一个添加到HightLightView的knownView响应了事件 237 | // //优化在布局中声明onClick方法 {@link #clickKnown(view)}响应所有R.id.iv_known的控件的点击事件 238 | // View decorLayout = mHightLight.getHightLightView(); 239 | // ImageView knownView = (ImageView) decorLayout.findViewById(R.id.iv_known); 240 | // knownView.setOnClickListener(new View.OnClickListener() 241 | // { 242 | // @Override 243 | // public void onClick(View view) { 244 | // remove(null); 245 | // } 246 | // }); 247 | } 248 | 249 | ``` 250 | 251 | anchor()指你需要在哪个view上加一层透明的蒙版,如果不设置,默认为android.R.id.content。也就是说,该库支持局部范围内去高亮某些View. 252 | 253 | addHighLight包含3个参数: 254 | 255 | * 参数1:需要高亮view的id,这个没什么说的 256 | * 参数2:你的tip布局的layoutId,也就是箭头和文字,你自己编写个布局,参考demo即可。 257 | * 参数3:是个接口,接口包含一系列的位置信息,如下 258 | 259 | ```xml 260 | /** 261 | * @param rightMargin 高亮view在anchor中的右边距 262 | * @param bottomMargin 高亮view在anchor中的下边距 263 | * @param rectF 高亮view的l,t,r,b,w,h都有 264 | * @param marginInfo 设置你的布局的位置,一般设置l,t或者r,b 265 | */ 266 | ``` 267 | 哈,提供了一堆的位置信息,但是你要做的,只是去设置leftMargin和topMargin;或者rightMargin和bottomMargin。 268 | 269 | 目前看起来,我觉得位置信息够了,当然如果你有想法欢迎提出。 270 | 271 | 哈,是不是参数比较多,看着烦,如果你图省事,可以提供一个枚举,提供4个或者8个默认的位置,这个事呢,dota1群`@李志云`已经完成~认识的话可以去找他。 272 | * 参数4:高亮形状 抽象类BaseLightShape(dx,dy,blurRadius) 273 | 274 | ```xml 275 | /** 276 | * @param dx 水平方向偏移 277 | * @param dy 垂直方向偏移 278 | * @param blurRadius 模糊半径 默认15px 0不模糊 279 | */ 280 | ``` 281 | 两个抽象方法: 282 | 283 | ``` 284 | /** 285 | * reset RectF for Shape by dx and dy. 根据dx,dy重置viewPosInfoRectF大小 286 | * @param viewPosInfoRectF 287 | * @param dx 288 | * @param dy 289 | */ 290 | protected abstract void resetRectF4Shape(RectF viewPosInfoRectF, float dx, float dy); 291 | 292 | /** 293 | * draw shape into bitmap. 绘制高亮形状到传递过来的图片画布上 294 | * @param bitmap 295 | * @param viewPosInfo 296 | * @see zhy.com.highlight.view.HightLightView#addViewForEveryTip(HighLight.ViewPosInfo) 297 | * @see HightLightView#buildMask() 298 | */ 299 | protected abstract void drawShape(Bitmap bitmap, HighLight.ViewPosInfo viewPosInfo); 300 | ``` 301 | BaseLightShape的实现类:RectLightShape(矩形)、CircleLightShape(圆形)、OvalLightShape(椭圆),具体实现请查看代码 302 | 303 | ## Question 问题 304 | 305 | 1. 添加的提示布局怎么在屏幕中水平居中显示(垂直居中类似) 306 | > 提示布局根布局`android:layout_width="match_parent"` `android:gravity="center_horizontal"` 307 | 308 | > 自定义定位参数`rightMargin=0` 309 | 310 | 2. 怎么针对同一个高亮控件添加多个提示布局 311 | 312 | > `addHighLight` 多次添加 第一个参数使用同一个控件id即可 313 | 314 | 3. 高亮布局显示后 底层布局有变化 怎么更新高亮布局 315 | > `mHighLight.getHightLightView().requestLayout()` 掉用后高亮布局会重新布局及绘制 316 | 4. ~~页面加载完成,自动显示,应该放在哪里调用?~~ 317 | 318 | **v1.8.0及以后版本建议使用`setOnLayoutCallback`方式 老版本使用下面方案** 319 | 320 | ``` 321 | @Override 322 | public void onWindowFocusChanged(boolean hasFocus) { 323 | super.onWindowFocusChanged(hasFocus); 324 | //界面初始化后显示高亮布局 325 | mHightLight.show(); 326 | } 327 | 328 | 或者: 329 | 330 | getWindow().getDecorView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { 331 | @Override 332 | public void onGlobalLayout() { 333 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { 334 | getWindow().getDecorView().getViewTreeObserver() 335 | .removeOnGlobalLayoutListener(this); 336 | } 337 | 338 | //界面初始化后显示高亮布局 339 | initHightLight(); 340 | mHightLight.show(); 341 | } 342 | 343 | }); 344 | ``` 345 | 346 | 5. ~~如果使用viewpager非第一页高亮布局 有可能定位到屏幕外~~ 347 | 348 | **v1.7.2版本已修复 具体方案参考#21** 349 | 350 | > 感谢 @liyanxi 提供的方案 会更新到 [README.md](https://github.com/isanwenyu/Highlight/blob/master/README.md) 351 | 352 | ``` 353 | //自定义高亮形状 354 | final HighLight.LightShape mLightShape = new BaseLightShape() { 355 | @Override 356 | protected void resetRectF4Shape(RectF viewPosInfoRectF, float dx, float dy) { 357 | //重置viewPosInfoRectF 模掉屏幕宽度 得到真实的left 358 | viewPosInfoRectF.offsetTo(viewPosInfoRectF.left % DeviceUtil.getScreenDispaly(getActivity())[0], viewPosInfoRectF.top); 359 | } 360 | ...... 361 | ``` 362 | 363 | ## Changelog 更改历史 364 | 365 | See details in [CHANGELOG.md](CHANGELOG.md) file. 366 | 367 | ## 致谢 368 | 369 | - 感谢android day day dota1群,苏苏,提供的图片资源。 370 | - thx for `李志云@dota1`的测试、修改、提议。 371 | - thx for [@zj593743143](https://github.com/zj593743143)的测试和建议 372 | 373 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 24 5 | buildToolsVersion "23.0.1" 6 | 7 | defaultConfig { 8 | applicationId "com.zhy.highlight" 9 | minSdkVersion 11 10 | targetSdkVersion 21 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(include: ['*.jar'], dir: 'libs') 24 | compile project(':highlight') 25 | compile 'com.android.support:appcompat-v7:24.2.0' 26 | debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta2' 27 | releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2' 28 | testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2' 29 | } 30 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/zhy/android/sdk/android-sdk-macosx/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in show.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/zhy/highlight/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.zhy.highlight; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase 10 | { 11 | public ApplicationTest() 12 | { 13 | super(Application.class); 14 | } 15 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/zhy/highlight/LeakCanaryApplication.java: -------------------------------------------------------------------------------- 1 | package com.zhy.highlight; 2 | 3 | import android.app.Application; 4 | 5 | import com.squareup.leakcanary.LeakCanary; 6 | 7 | /** 8 | *
 9 |  * 内存溢出检测应用
10 |  * Created by isanwenyu@163.com on 2016/12/9.
11 |  * 
12 | */ 13 | public class LeakCanaryApplication extends Application{ 14 | @Override 15 | public void onCreate() { 16 | super.onCreate(); 17 | if (LeakCanary.isInAnalyzerProcess(this)) { 18 | // This process is dedicated to LeakCanary for heap analysis. 19 | // You should not init your app in this process. 20 | return; 21 | } 22 | LeakCanary.install(this); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/zhy/highlight/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.zhy.highlight; 2 | 3 | import android.graphics.Bitmap; 4 | import android.graphics.BlurMaskFilter; 5 | import android.graphics.Canvas; 6 | import android.graphics.Paint; 7 | import android.graphics.RectF; 8 | import android.os.Bundle; 9 | import android.support.v7.app.AppCompatActivity; 10 | import android.util.TypedValue; 11 | import android.view.Menu; 12 | import android.view.MenuItem; 13 | import android.view.View; 14 | import android.widget.Toast; 15 | 16 | import zhy.com.highlight.HighLight; 17 | import zhy.com.highlight.interfaces.HighLightInterface; 18 | import zhy.com.highlight.position.OnBottomPosCallback; 19 | import zhy.com.highlight.position.OnLeftPosCallback; 20 | import zhy.com.highlight.position.OnRightPosCallback; 21 | import zhy.com.highlight.position.OnTopPosCallback; 22 | import zhy.com.highlight.shape.BaseLightShape; 23 | import zhy.com.highlight.shape.CircleLightShape; 24 | import zhy.com.highlight.shape.OvalLightShape; 25 | import zhy.com.highlight.shape.RectLightShape; 26 | import zhy.com.highlight.view.HightLightView; 27 | 28 | public class MainActivity extends AppCompatActivity 29 | { 30 | 31 | private HighLight mHightLight; 32 | 33 | @Override 34 | protected void onCreate(Bundle savedInstanceState) 35 | { 36 | super.onCreate(savedInstanceState); 37 | setContentView(R.layout.activity_main); 38 | 39 | 40 | // findViewById(R.id.id_btn_amazing).post( 41 | // new Runnable() 42 | // { 43 | // @Override 44 | // public void run() 45 | // { 46 | // showTipMask(); 47 | // } 48 | // } 49 | // 50 | // ); 51 | showNextTipViewOnCreated(); 52 | 53 | } 54 | 55 | @Override 56 | public void onWindowFocusChanged(boolean hasFocus) { 57 | super.onWindowFocusChanged(hasFocus); 58 | //界面初始化后直接显示高亮布局 59 | // if(hasFocus) mHightLight.show(); 60 | } 61 | 62 | public void showTipView(View view){ 63 | mHightLight = new HighLight(MainActivity.this)// 64 | .anchor(findViewById(R.id.id_container))//如果是Activity上增加引导层,不需要设置anchor 65 | .addHighLight(R.id.btn_rightLight,R.layout.info_gravity_left_down,new OnLeftPosCallback(45),new RectLightShape()) 66 | .addHighLight(R.id.btn_light,R.layout.info_gravity_left_down,new OnRightPosCallback(5),new CircleLightShape()) 67 | .addHighLight(R.id.btn_bottomLight,R.layout.info_gravity_left_down,new OnTopPosCallback(),new CircleLightShape()) 68 | .addHighLight(view,R.layout.info_gravity_left_down,new OnBottomPosCallback(60),new CircleLightShape()); 69 | mHightLight.show(); 70 | } 71 | 72 | /** 73 | * 当界面布局完成显示next模式提示布局 74 | * 显示方法必须在onLayouted中调用 75 | * 适用于Activity及Fragment中使用 76 | * 可以直接在onCreated方法中调用 77 | * @author isanwenyu@163.com 78 | */ 79 | public void showNextTipViewOnCreated(){ 80 | mHightLight = new HighLight(MainActivity.this)// 81 | .anchor(findViewById(R.id.id_container))//如果是Activity上增加引导层,不需要设置anchor 82 | .autoRemove(false) 83 | .enableNext() 84 | .setOnLayoutCallback(new HighLightInterface.OnLayoutCallback() { 85 | @Override 86 | public void onLayouted() { 87 | //界面布局完成添加tipview 88 | mHightLight.addHighLight(R.id.btn_rightLight,R.layout.info_gravity_left_down,new OnLeftPosCallback(45),new RectLightShape()) 89 | .addHighLight(R.id.btn_light,R.layout.info_gravity_left_down,new OnRightPosCallback(5),new CircleLightShape()) 90 | .addHighLight(R.id.btn_bottomLight,R.layout.info_gravity_left_down,new OnTopPosCallback(),new CircleLightShape()); 91 | //然后显示高亮布局 92 | mHightLight.show(); 93 | } 94 | }) 95 | .setClickCallback(new HighLight.OnClickCallback() { 96 | @Override 97 | public void onClick() { 98 | Toast.makeText(MainActivity.this, "clicked and show next tip view by yourself", Toast.LENGTH_SHORT).show(); 99 | mHightLight.next(); 100 | } 101 | }); 102 | } 103 | /** 104 | * 显示next模式提示布局 105 | * @param view 106 | * @author isanwenyu@163.com 107 | */ 108 | public void showNextTipView(View view){ 109 | mHightLight = new HighLight(MainActivity.this)// 110 | .anchor(findViewById(R.id.id_container))//如果是Activity上增加引导层,不需要设置anchor 111 | .addHighLight(R.id.btn_rightLight,R.layout.info_gravity_left_down,new OnLeftPosCallback(45),new RectLightShape()) 112 | .addHighLight(R.id.btn_light,R.layout.info_gravity_left_down,new OnRightPosCallback(5),new CircleLightShape()) 113 | .addHighLight(R.id.btn_bottomLight,R.layout.info_gravity_left_down,new OnTopPosCallback(),new CircleLightShape()) 114 | .addHighLight(view,R.layout.info_gravity_left_down,new OnBottomPosCallback(60),new CircleLightShape()) 115 | .autoRemove(false) 116 | .enableNext() 117 | .setClickCallback(new HighLight.OnClickCallback() { 118 | @Override 119 | public void onClick() { 120 | Toast.makeText(MainActivity.this, "clicked and show next tip view by yourself", Toast.LENGTH_SHORT).show(); 121 | mHightLight.next(); 122 | } 123 | }); 124 | mHightLight.show(); 125 | } 126 | 127 | /** 128 | * 显示我知道了提示高亮布局 129 | * @param view id为R.id.iv_known的控件 130 | * @author isanwenyu@163.com 131 | */ 132 | public void showKnownTipView(View view) 133 | { 134 | mHightLight = new HighLight(MainActivity.this)// 135 | .autoRemove(false)//设置背景点击高亮布局自动移除为false 默认为true 136 | .intercept(false)//设置拦截属性为false 高亮布局不影响后面布局的滑动效果 而且使下方点击回调失效 137 | .setClickCallback(new HighLight.OnClickCallback() { 138 | @Override 139 | public void onClick() { 140 | Toast.makeText(MainActivity.this, "clicked and remove HightLight view by yourself", Toast.LENGTH_SHORT).show(); 141 | remove(null); 142 | } 143 | }) 144 | .anchor(findViewById(R.id.id_container))//如果是Activity上增加引导层,不需要设置anchor 145 | .addHighLight(R.id.btn_rightLight,R.layout.info_known,new OnLeftPosCallback(45),new RectLightShape()) 146 | .addHighLight(R.id.btn_light,R.layout.info_known,new OnRightPosCallback(5),new CircleLightShape(0,0,0)) 147 | .addHighLight(R.id.btn_bottomLight,R.layout.info_known,new OnTopPosCallback(),new CircleLightShape()) 148 | .addHighLight(view,R.layout.info_known,new OnBottomPosCallback(10),new OvalLightShape(5,5,20)); 149 | mHightLight.show(); 150 | 151 | // //added by isanwenyu@163.com 设置监听器只有最后一个添加到HightLightView的knownView响应了事件 152 | // //优化在布局中声明onClick方法 {@link #clickKnown(view)}响应所有R.id.iv_known的控件的点击事件 153 | // View decorLayout = mHightLight.getHightLightView(); 154 | // ImageView knownView = (ImageView) decorLayout.findViewById(R.id.iv_known); 155 | // knownView.setOnClickListener(new View.OnClickListener() 156 | // { 157 | // @Override 158 | // public void onClick(View view) { 159 | // remove(null); 160 | // } 161 | // }); 162 | } 163 | 164 | /** 165 | * 显示 next模式 我知道了提示高亮布局 166 | * @param view id为R.id.iv_known的控件 167 | * @author isanwenyu@163.com 168 | */ 169 | public void showNextKnownTipView(View view) 170 | { 171 | mHightLight = new HighLight(MainActivity.this)// 172 | .autoRemove(false)//设置背景点击高亮布局自动移除为false 默认为true 173 | // .intercept(false)//设置拦截属性为false 高亮布局不影响后面布局的滑动效果 174 | .intercept(true)//拦截属性默认为true 使下方ClickCallback生效 175 | .enableNext()//开启next模式并通过show方法显示 然后通过调用next()方法切换到下一个提示布局,直到移除自身 176 | // .setClickCallback(new HighLight.OnClickCallback() { 177 | // @Override 178 | // public void onClick() { 179 | // Toast.makeText(MainActivity.this, "clicked and remove HightLight view by yourself", Toast.LENGTH_SHORT).show(); 180 | // remove(null); 181 | // } 182 | // }) 183 | .anchor(findViewById(R.id.id_container))//如果是Activity上增加引导层,不需要设置anchor 184 | .addHighLight(R.id.btn_rightLight,R.layout.info_known,new OnLeftPosCallback(45),new RectLightShape(0,0,15,0,0))//矩形去除圆角 185 | .addHighLight(R.id.btn_light,R.layout.info_known,new OnRightPosCallback(5),new BaseLightShape(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,5,getResources().getDisplayMetrics()), TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,5,getResources().getDisplayMetrics()),0) { 186 | @Override 187 | protected void resetRectF4Shape(RectF viewPosInfoRectF, float dx, float dy) { 188 | //缩小高亮控件范围 189 | viewPosInfoRectF.inset(dx,dy); 190 | } 191 | 192 | @Override 193 | protected void drawShape(Bitmap bitmap, HighLight.ViewPosInfo viewPosInfo) { 194 | //custom your hight light shape 自定义高亮形状 195 | Canvas canvas = new Canvas(bitmap); 196 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); 197 | paint.setDither(true); 198 | paint.setAntiAlias(true); 199 | //blurRadius必须大于0 200 | if(blurRadius>0){ 201 | paint.setMaskFilter(new BlurMaskFilter(blurRadius, BlurMaskFilter.Blur.SOLID)); 202 | } 203 | RectF rectF = viewPosInfo.rectF; 204 | canvas.drawOval(rectF, paint); 205 | } 206 | }) 207 | .addHighLight(R.id.btn_bottomLight,R.layout.info_known,new OnTopPosCallback(),new CircleLightShape()) 208 | .addHighLight(view,R.layout.info_known,new OnBottomPosCallback(10),new OvalLightShape(5,5,20)) 209 | .setOnRemoveCallback(new HighLightInterface.OnRemoveCallback() {//监听移除回调 210 | @Override 211 | public void onRemove() { 212 | Toast.makeText(MainActivity.this, "The HightLight view has been removed", Toast.LENGTH_SHORT).show(); 213 | 214 | } 215 | }) 216 | .setOnShowCallback(new HighLightInterface.OnShowCallback() {//监听显示回调 217 | @Override 218 | public void onShow(HightLightView hightLightView) { 219 | Toast.makeText(MainActivity.this, "The HightLight view has been shown", Toast.LENGTH_SHORT).show(); 220 | } 221 | }).setOnNextCallback(new HighLightInterface.OnNextCallback() { 222 | @Override 223 | public void onNext(HightLightView hightLightView, View targetView, View tipView) { 224 | // targetView 目标按钮 tipView添加的提示布局 可以直接找到'我知道了'按钮添加监听事件等处理 225 | Toast.makeText(MainActivity.this, "The HightLight show next TipView,targetViewID:"+(targetView==null?null:targetView.getId())+",tipViewID:"+(tipView==null?null:tipView.getId()), Toast.LENGTH_SHORT).show(); 226 | } 227 | }); 228 | mHightLight.show(); 229 | } 230 | 231 | /** 232 | * 响应所有R.id.iv_known的控件的点击事件 233 | *

234 | * 移除高亮布局 235 | *

236 | * 237 | * @param view 238 | */ 239 | public void clickKnown(View view) 240 | { 241 | if(mHightLight.isShowing() && mHightLight.isNext())//如果开启next模式 242 | { 243 | mHightLight.next(); 244 | }else 245 | { 246 | remove(null); 247 | } 248 | } 249 | 250 | private void showTipMask() 251 | { 252 | // mHightLight = new HighLight(MainActivity.this)// 253 | // .anchor(findViewById(R.id.id_container)) 254 | //如果是Activity上增加引导层,不需要设置anchor 255 | // .addHighLight(R.id.id_btn_important, R.layout.info_up, 256 | // new HighLight.OnPosCallback() 257 | // { 258 | // @Override 259 | // public void getPos(float rightMargin, float bottomMargin, RectF rectF, HighLight.MarginInfo marginInfo) 260 | // { 261 | // marginInfo.leftMargin = rectF.right - rectF.width() / 2; 262 | // marginInfo.topMargin = rectF.bottom; 263 | // } 264 | // })// 265 | // .addHighLight(R.id.id_btn_amazing, R.layout.info_down, new HighLight.OnPosCallback() 266 | // { 267 | // /** 268 | // * @param rightMargin 高亮view在anchor中的右边距 269 | // * @param bottomMargin 高亮view在anchor中的下边距 270 | // * @param rectF 高亮view的l,t,r,b,w,h都有 271 | // * @param marginInfo 设置你的布局的位置,一般设置l,t或者r,b 272 | // */ 273 | // @Override 274 | // public void getPos(float rightMargin, float bottomMargin, RectF rectF, HighLight.MarginInfo marginInfo) 275 | // { 276 | // marginInfo.rightMargin = rightMargin + rectF.width() / 2; 277 | // marginInfo.bottomMargin = bottomMargin + rectF.height(); 278 | // } 279 | // 280 | // }); 281 | // .addHighLight(R.id.id_btn_important_right,R.layout.info_gravity_right_up, new HighLight.OnPosCallback(){ 282 | // 283 | // 284 | // @Override 285 | // public void getPos(float rightMargin, float bottomMargin, RectF rectF, HighLight.MarginInfo marginInfo) { 286 | // marginInfo.rightMargin = rightMargin; 287 | // marginInfo.topMargin = rectF.top + rectF.height(); 288 | // } 289 | // }) 290 | // .addHighLight(R.id.id_btn_whoami, R.layout.info_gravity_left_down, new HighLight.OnPosCallback() { 291 | // 292 | // 293 | // @Override 294 | // public void getPos(float rightMargin, float bottomMargin, RectF rectF, HighLight.MarginInfo marginInfo) { 295 | // marginInfo.leftMargin = rectF.right - rectF.width()/2; 296 | // marginInfo.bottomMargin = bottomMargin + rectF.height(); 297 | // } 298 | // }) 299 | // .setClickCallback(new HighLight.OnClickCallback() { 300 | // @Override 301 | // public void onClick() { 302 | // Toast.makeText(MainActivity.this,"clicked",Toast.LENGTH_SHORT).show(); 303 | // } 304 | // }); 305 | 306 | // mHightLight.show(); 307 | // mHightLight = new HighLight(MainActivity.this)// 308 | // .anchor(findViewById(R.id.id_container))//如果是Activity上增加引导层,不需要设置anchor 309 | // .addHighLight(R.id.btn_rightLight,R.layout.info_left, new OnLeftPosCallback(10),new RectLightShape()) 310 | // .addHighLight(R.id.btn_light,R.layout.info_right,new OnRightPosCallback(),new CircleLightShape()) 311 | // .addHighLight(R.id.btn_bottomLight,R.layout.info_up,new OnTopPosCallback(46),new CircleLightShape()) 312 | // .addHighLight(R.id.id_btn_amazing,R.layout.info_up,new OnBottomPosCallback(46),new CircleLightShape()); 313 | // mHightLight.show(); 314 | } 315 | 316 | 317 | public void remove(View view) 318 | { 319 | mHightLight.remove(); 320 | } 321 | 322 | public void add(View view) 323 | { 324 | mHightLight.show(); 325 | } 326 | 327 | 328 | @Override 329 | public boolean onCreateOptionsMenu(Menu menu) 330 | { 331 | getMenuInflater().inflate(R.menu.menu_main, menu); 332 | 333 | 334 | return true; 335 | } 336 | 337 | @Override 338 | public boolean onOptionsItemSelected(MenuItem item) 339 | { 340 | // Handle action bar item clicks here. The action bar will 341 | // automatically handle clicks on the Home/Up button, so long 342 | // as you specify a parent activity in AndroidManifest.xml. 343 | int id = item.getItemId(); 344 | 345 | //noinspection SimplifiableIfStatement 346 | if (id == R.id.action_settings) 347 | { 348 | //test container change 349 | // View container = findViewById(R.id.id_container); 350 | // ViewGroup.LayoutParams lp = 351 | // container.getLayoutParams(); 352 | // lp.height = container.getMeasuredHeight() + 100; 353 | // findViewById(R.id.id_container).setLayoutParams(lp); 354 | } 355 | return super.onOptionsItemSelected(item); 356 | } 357 | } 358 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/info_text.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/Highlight/681488714b58d676ac7ea3365d27da194dbbbe9b/app/src/main/res/drawable-xxhdpi/info_text.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/jt_down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/Highlight/681488714b58d676ac7ea3365d27da194dbbbe9b/app/src/main/res/drawable-xxhdpi/jt_down.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/jt_known.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/Highlight/681488714b58d676ac7ea3365d27da194dbbbe9b/app/src/main/res/drawable-xxhdpi/jt_known.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/jt_up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/Highlight/681488714b58d676ac7ea3365d27da194dbbbe9b/app/src/main/res/drawable-xxhdpi/jt_up.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 |