├── .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 | [  ](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 |
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 ApplicationTestCase9 | * 内存溢出检测应用 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 |
239 | * 高亮布局的id在{@link #show()}中hightLightView.setId(R.id.high_light_view)设置
240 | *
241 | * @return 返回id为R.id.high_light_view的高亮布局对象
242 | * @author isanwenyu@163.com
243 | * @see #show()
244 | */
245 | @Override
246 | public HightLightView getHightLightView() {
247 | if (mHightLightView != null) return mHightLightView;
248 | return mHightLightView = (HightLightView) ((Activity) mContext).findViewById(R.id.high_light_view);
249 |
250 | }
251 |
252 | /**
253 | * 开启next模式
254 | *
255 | * @return 链式接口 返回自身
256 | * @author isanwenyu@163.com
257 | * @see #show()
258 | */
259 | public HighLight enableNext() {
260 | this.isNext = true;
261 | return this;
262 | }
263 |
264 | /**
265 | * 返回是否是next模式
266 | *
267 | * @return
268 | * @author isanwenyu@163.com
269 | */
270 | public boolean isNext() {
271 | return isNext;
272 | }
273 |
274 | /**
275 | * 切换到下个提示布局
276 | *
277 | * @return HighLight自身对象
278 | * @author isanwenyu@163.com
279 | */
280 | @Override
281 | public HighLight next() {
282 | if (getHightLightView() != null) getHightLightView().addViewForTip();
283 | else
284 | throw new NullPointerException("The HightLightView is null,you must invoke show() before this!");
285 | return this;
286 | }
287 |
288 | @Override
289 | public HighLight show() {
290 |
291 | if (getHightLightView() != null) {
292 | mHightLightView = getHightLightView();
293 | //重置当前HighLight对象属性
294 | mShowing = true;
295 | isNext = mHightLightView.isNext();
296 | // TODO: 2016/11/16 按需重置其他属性
297 | return this;
298 | }
299 | //如果View rect 容器为空 直接返回 added by isanwenyu 2016/10/26.
300 | if (mViewRects.isEmpty()) return this;
301 | HightLightView hightLightView = new HightLightView(mContext, this, maskColor, mViewRects, isNext);
302 | //add high light view unique id by isanwenyu@163.com on 2016/9/28.
303 | hightLightView.setId(R.id.high_light_view);
304 | //compatible with AutoFrameLayout ect.
305 | if (mAnchor instanceof FrameLayout) {
306 | ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams
307 | (ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
308 | ((ViewGroup) mAnchor).addView(hightLightView, ((ViewGroup) mAnchor).getChildCount(), lp);
309 |
310 | } else {
311 | FrameLayout frameLayout = new FrameLayout(mContext);
312 | ViewGroup parent = (ViewGroup) mAnchor.getParent();
313 | parent.removeView(mAnchor);
314 | parent.addView(frameLayout, mAnchor.getLayoutParams());
315 | ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams
316 | (ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
317 | frameLayout.addView(mAnchor, lp);
318 |
319 | frameLayout.addView(hightLightView);
320 | }
321 |
322 | if (intercept) {
323 | hightLightView.setOnClickListener(new View.OnClickListener() {
324 | @Override
325 | public void onClick(View v) {
326 | //added autoRemove by isanwenyu@163.com
327 | if (autoRemove) remove();
328 |
329 | sendClickMessage();
330 | }
331 | });
332 | }
333 | //延迟添加提示布局
334 | hightLightView.addViewForTip();
335 | mHightLightView = hightLightView;
336 | mShowing = true;
337 | //响应显示回调
338 | sendShowMessage();
339 | return this;
340 | }
341 |
342 | @Override
343 | public HighLight remove() {
344 | if (getHightLightView() == null) return this;
345 | ViewGroup parent = (ViewGroup) mHightLightView.getParent();
346 | if (parent instanceof RelativeLayout || parent instanceof FrameLayout) {
347 | parent.removeView(mHightLightView);
348 | } else {
349 | parent.removeView(mHightLightView);
350 | View origin = parent.getChildAt(0);
351 | ViewGroup graParent = (ViewGroup) parent.getParent();
352 | graParent.removeView(parent);
353 | graParent.addView(origin, parent.getLayoutParams());
354 | }
355 | mHightLightView = null;
356 |
357 | sendRemoveMessage();
358 | mShowing = false;
359 | return this;
360 | }
361 |
362 |
363 | private void sendClickMessage() {
364 | if (mClickMessage != null) {
365 | // Obtain a new message so this highlight can be re-used
366 | Message.obtain(mClickMessage).sendToTarget();
367 | }
368 | }
369 |
370 | private void sendRemoveMessage() {
371 | if (mRemoveMessage != null) {
372 | // Obtain a new message so this highlight can be re-used
373 | Message.obtain(mRemoveMessage).sendToTarget();
374 | }
375 | }
376 |
377 | private void sendShowMessage() {
378 | if (mShowMessage != null) {
379 | // Obtain a new message so this highlight can be re-used
380 | Message.obtain(mShowMessage).sendToTarget();
381 | }
382 | }
383 |
384 | private void sendLayoutMessage() {
385 | if (mLayoutMessage != null) {
386 | // Obtain a new message so this highlight can be re-used
387 | Message.obtain(mLayoutMessage).sendToTarget();
388 | }
389 | }
390 |
391 | public void sendNextMessage() {
392 |
393 | if (!isNext)
394 | throw new IllegalArgumentException("only for isNext mode,please invoke enableNext() first");
395 |
396 | if (getHightLightView() == null) {
397 | return;
398 | }
399 | //发送下一步消息事件
400 | ViewPosInfo viewPosInfo = getHightLightView().getCurentViewPosInfo();
401 | if (mNextMessage != null && viewPosInfo != null) {
402 | mNextMessage.arg1 = viewPosInfo.view == null ? -1 : viewPosInfo.view.getId();
403 | mNextMessage.arg2 = viewPosInfo.layoutId;
404 | Message.obtain(mNextMessage).sendToTarget();
405 | }
406 | }
407 |
408 | /**
409 | * 为mAnchor注册全局布局监听器
410 | */
411 | private void registerGlobalLayoutListener() {
412 | mAnchor.getViewTreeObserver().addOnGlobalLayoutListener(this);
413 | }
414 |
415 |
416 | /**
417 | * mAnchor反注册全局布局监听器
418 | */
419 | private void unRegisterGlobalLayoutListener() {
420 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
421 | mAnchor.getViewTreeObserver()
422 | .removeOnGlobalLayoutListener(this);
423 | }
424 | }
425 |
426 | @Override
427 | public void onGlobalLayout() {
428 | unRegisterGlobalLayoutListener();
429 | sendLayoutMessage();
430 |
431 | }
432 |
433 |
434 | /**
435 | * @see android.app.Dialog.ListenersHandler
436 | */
437 | private static final class ListenersHandler extends Handler {
438 | private WeakReference
10 | * 控制高亮控件的接口
11 | * Created by isanwenyu on 2016/11/01.
12 | * Copyright (c) 2016 isanwenyu@163.com. All rights reserved.
13 | *
14 | */
15 | public interface HighLightInterface {
16 |
17 | /**
18 | * 移除
19 | */
20 | HighLight remove();
21 |
22 | /**
23 | * 显示
24 | */
25 | HighLight show();
26 |
27 | /**
28 | * 显示下一个布局
29 | *
30 | * @return
31 | */
32 | HighLight next();
33 |
34 | /**
35 | * @return 锚点布局
36 | */
37 | View getAnchor();
38 |
39 | /**
40 | * @return 高亮布局控件
41 | */
42 | HightLightView getHightLightView();
43 |
44 | public static interface OnClickCallback {
45 | void onClick();
46 | }
47 |
48 | /**
49 | * 显示回调监听
50 | */
51 | public static interface OnShowCallback {
52 | /**
53 | * @param hightLightView 高亮布局控件
54 | */
55 | void onShow(HightLightView hightLightView);
56 | }
57 |
58 | /**
59 | * 移除回调监听
60 | */
61 | public static interface OnRemoveCallback {
62 | /**
63 | * 移除高亮布局
64 | */
65 | void onRemove();
66 | }
67 |
68 | /**
69 | * 下一个回调监听 只有Next模式下生效
70 | */
71 | public static interface OnNextCallback {
72 | /**
73 | * 监听下一步动作
74 | *
75 | * @param hightLightView 高亮布局控件
76 | * @param targetView 高亮目标控件
77 | * @param tipView 高亮提示控件
78 | */
79 | void onNext(HightLightView hightLightView, View targetView, View tipView);
80 | }
81 |
82 | /**
83 | * mAnchor全局布局监听器
84 | */
85 | public static interface OnLayoutCallback {
86 | /**
87 | * 布局结束
88 | */
89 | void onLayouted();
90 | }
91 | }
--------------------------------------------------------------------------------
/highlight/src/main/java/zhy/com/highlight/position/OnBaseCallback.java:
--------------------------------------------------------------------------------
1 | package zhy.com.highlight.position;
2 |
3 | import android.graphics.RectF;
4 |
5 | import zhy.com.highlight.HighLight;
6 |
7 | /**
8 | * Created by caizepeng on 16/8/20.
9 | */
10 | public abstract class OnBaseCallback implements HighLight.OnPosCallback {
11 | protected float offset ;
12 |
13 | public OnBaseCallback() {
14 | }
15 |
16 | public OnBaseCallback(float offset) {
17 | this.offset = offset;
18 | }
19 |
20 | /**
21 | * 如果需要调整位置,重写该方法
22 | * @param rightMargin
23 | * @param bottomMargin
24 | * @param rectF
25 | * @param marginInfo
26 | */
27 | public void posOffset(float rightMargin, float bottomMargin, RectF rectF, HighLight.MarginInfo marginInfo){}
28 |
29 | @Override
30 | public void getPos(float rightMargin, float bottomMargin, RectF rectF, HighLight.MarginInfo marginInfo) {
31 | getPosition(rightMargin,bottomMargin,rectF,marginInfo);
32 | posOffset(rightMargin,bottomMargin,rectF,marginInfo);
33 | }
34 | public abstract void getPosition(float rightMargin, float bottomMargin, RectF rectF, HighLight.MarginInfo marginInfo);
35 | }
36 |
--------------------------------------------------------------------------------
/highlight/src/main/java/zhy/com/highlight/position/OnBottomPosCallback.java:
--------------------------------------------------------------------------------
1 | package zhy.com.highlight.position;
2 |
3 | import android.graphics.RectF;
4 |
5 | import zhy.com.highlight.HighLight;
6 |
7 | /**
8 | * Created by caizepeng on 16/8/20.
9 | */
10 | public class OnBottomPosCallback extends OnBaseCallback{
11 | public OnBottomPosCallback() {
12 | }
13 |
14 | public OnBottomPosCallback(float offset) {
15 | super(offset);
16 | }
17 |
18 | @Override
19 | public void getPosition(float rightMargin, float bottomMargin, RectF rectF, HighLight.MarginInfo marginInfo) {
20 | marginInfo.rightMargin = rightMargin;
21 | marginInfo.topMargin = rectF.top + rectF.height()+offset;
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/highlight/src/main/java/zhy/com/highlight/position/OnLeftPosCallback.java:
--------------------------------------------------------------------------------
1 | package zhy.com.highlight.position;
2 |
3 | import android.graphics.RectF;
4 |
5 | import zhy.com.highlight.HighLight;
6 |
7 | /**
8 | * Created by caizepeng on 16/8/20.
9 | */
10 | public class OnLeftPosCallback extends OnBaseCallback {
11 | public OnLeftPosCallback() {
12 | }
13 |
14 | public OnLeftPosCallback(float offset) {
15 | super(offset);
16 | }
17 |
18 | @Override
19 | public void getPosition(float rightMargin, float bottomMargin, RectF rectF, HighLight.MarginInfo marginInfo) {
20 | marginInfo.rightMargin = rightMargin+rectF.width()+offset;
21 | marginInfo.topMargin = rectF.top;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/highlight/src/main/java/zhy/com/highlight/position/OnRightPosCallback.java:
--------------------------------------------------------------------------------
1 | package zhy.com.highlight.position;
2 |
3 | import android.graphics.RectF;
4 |
5 | import zhy.com.highlight.HighLight;
6 |
7 | /**
8 | * Created by caizepeng on 16/8/20.
9 | */
10 | public class OnRightPosCallback extends OnBaseCallback {
11 | public OnRightPosCallback() {
12 | }
13 |
14 | public OnRightPosCallback(float offset) {
15 | super(offset);
16 | }
17 |
18 | @Override
19 | public void getPosition(float rightMargin, float bottomMargin, RectF rectF, HighLight.MarginInfo marginInfo) {
20 | marginInfo.leftMargin = rectF.right + offset;
21 | marginInfo.topMargin = rectF.top;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/highlight/src/main/java/zhy/com/highlight/position/OnTopPosCallback.java:
--------------------------------------------------------------------------------
1 | package zhy.com.highlight.position;
2 |
3 | import android.graphics.RectF;
4 |
5 | import zhy.com.highlight.HighLight;
6 |
7 | /**
8 | * Created by caizepeng on 16/8/20.
9 | */
10 | public class OnTopPosCallback extends OnBaseCallback {
11 | public OnTopPosCallback() {
12 | }
13 |
14 | public OnTopPosCallback(float offset) {
15 | super(offset);
16 | }
17 |
18 | @Override
19 | public void getPosition(float rightMargin, float bottomMargin, RectF rectF, HighLight.MarginInfo marginInfo) {
20 | marginInfo.leftMargin = rectF.right - rectF.width() / 2;
21 | marginInfo.bottomMargin = bottomMargin+rectF.height()+offset;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/highlight/src/main/java/zhy/com/highlight/shape/BaseLightShape.java:
--------------------------------------------------------------------------------
1 | package zhy.com.highlight.shape;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.RectF;
5 |
6 | import zhy.com.highlight.HighLight;
7 | import zhy.com.highlight.view.HightLightView;
8 |
9 | /**
10 | *
11 | * 高亮形状的超类
12 | * Created by isanwenyu on 2016/10/26.
13 | * Copyright (c) 2016 isanwenyu@163.com. All rights reserved.
14 | *
15 | */
16 | public abstract class BaseLightShape implements HighLight.LightShape{
17 | protected float dx;//水平方向偏移
18 | protected float dy;//垂直方向偏移
19 | protected float blurRadius=15;//模糊半径 默认15
20 |
21 | public BaseLightShape() {
22 | }
23 |
24 | /**
25 | * @param dx 水平方向偏移
26 | * @param dy 垂直方向偏移
27 | */
28 | public BaseLightShape(float dx,float dy) {
29 | this.dx = dx;
30 | this.dy = dy;
31 | }
32 |
33 | /**
34 | * @param dx 水平方向偏移
35 | * @param dy 垂直方向偏移
36 | * @param blurRadius 模糊半径 默认15px 0不模糊
37 | */
38 | public BaseLightShape(float dx, float dy, float blurRadius) {
39 | this.dx = dx;
40 | this.dy = dy;
41 | this.blurRadius = blurRadius;
42 | }
43 |
44 | @Override
45 | public void shape(Bitmap bitmap, HighLight.ViewPosInfo viewPosInfo) {
46 | resetRectF4Shape(viewPosInfo.rectF,dx,dy);
47 | drawShape(bitmap,viewPosInfo);
48 | }
49 |
50 | /**
51 | * reset RectF for Shape by dx and dy.
52 | * @param viewPosInfoRectF
53 | * @param dx
54 | * @param dy
55 | */
56 | protected abstract void resetRectF4Shape(RectF viewPosInfoRectF, float dx, float dy);
57 |
58 | /**
59 | * draw shape into bitmap
60 | * @param bitmap
61 | * @param viewPosInfo
62 | * @see zhy.com.highlight.view.HightLightView#addViewForEveryTip(HighLight.ViewPosInfo)
63 | * @see HightLightView#buildMask()
64 | */
65 | protected abstract void drawShape(Bitmap bitmap, HighLight.ViewPosInfo viewPosInfo);
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/highlight/src/main/java/zhy/com/highlight/shape/CircleLightShape.java:
--------------------------------------------------------------------------------
1 | package zhy.com.highlight.shape;
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 |
9 | import zhy.com.highlight.HighLight;
10 |
11 | /**
12 | * Created by caizepeng on 16/8/20.
13 | * Edited by isanwenyu@163.com 16/10/26.
14 | */
15 | public class CircleLightShape extends BaseLightShape {
16 | public CircleLightShape() {
17 | super();
18 | }
19 |
20 | public CircleLightShape(float dx, float dy) {
21 | super(dx, dy);
22 | }
23 |
24 | public CircleLightShape(float dx, float dy, float blurRadius) {
25 | super(dx, dy, blurRadius);
26 | }
27 |
28 | @Override
29 | protected void drawShape(Bitmap bitmap, HighLight.ViewPosInfo viewPosInfo) {
30 | Canvas canvas = new Canvas(bitmap);
31 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
32 | paint.setDither(true);
33 | paint.setAntiAlias(true);
34 | if (blurRadius > 0) {
35 | paint.setMaskFilter(new BlurMaskFilter(blurRadius, BlurMaskFilter.Blur.SOLID));
36 | }
37 | RectF rectF = viewPosInfo.rectF;
38 | canvas.drawCircle(rectF.left+(rectF.width()/2),rectF.top+(rectF.height()/2),
39 | Math.max(rectF.width(),rectF.height())/2,paint);
40 | }
41 |
42 | @Override
43 | protected void resetRectF4Shape(RectF viewPosInfoRectF, float dx, float dy) {
44 | viewPosInfoRectF.inset(dx,dy);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/highlight/src/main/java/zhy/com/highlight/shape/OvalLightShape.java:
--------------------------------------------------------------------------------
1 | package zhy.com.highlight.shape;
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 |
9 | import zhy.com.highlight.HighLight;
10 |
11 | /**
12 | * 椭圆形高亮形状
13 | * Created by isanwenyu on 16/11/15.
14 | * Edited by isanwenyu@163.com 16/10/26.
15 | */
16 | public class OvalLightShape extends BaseLightShape {
17 | public OvalLightShape() {
18 | super();
19 | }
20 |
21 | public OvalLightShape(float dx, float dy) {
22 | super(dx, dy);
23 | }
24 |
25 | public OvalLightShape(float dx, float dy, float blurRadius) {
26 | super(dx, dy, blurRadius);
27 | }
28 |
29 | @Override
30 | protected void drawShape(Bitmap bitmap, HighLight.ViewPosInfo viewPosInfo) {
31 | Canvas canvas = new Canvas(bitmap);
32 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
33 | paint.setDither(true);
34 | paint.setAntiAlias(true);
35 | if (blurRadius > 0) {
36 | paint.setMaskFilter(new BlurMaskFilter(blurRadius, BlurMaskFilter.Blur.SOLID));
37 | }
38 | RectF rectF = viewPosInfo.rectF;
39 | canvas.drawOval(rectF, paint);
40 | }
41 |
42 | @Override
43 | protected void resetRectF4Shape(RectF viewPosInfoRectF, float dx, float dy) {
44 | //默认根据dx dy横向和竖向缩小RectF范围
45 | viewPosInfoRectF.inset(dx, dy);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/highlight/src/main/java/zhy/com/highlight/shape/RectLightShape.java:
--------------------------------------------------------------------------------
1 | package zhy.com.highlight.shape;
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 |
9 | import zhy.com.highlight.HighLight;
10 |
11 | /**
12 | * Created by caizepeng on 16/8/20.
13 | * Edited by isanwenyu@163.com 16/10/26.
14 | */
15 | public class RectLightShape extends BaseLightShape {
16 |
17 | private float rx=6; //The x-radius of the oval used to round the corners
18 | private float ry=6; //The y-radius of the oval used to round the corners
19 | public RectLightShape() {
20 | super();
21 | }
22 |
23 | /**
24 | * @param dx 水平方向偏移
25 | * @param dy 垂直方向偏移
26 | * @param blurRadius 模糊半径 默认15px 0不模糊
27 | * @param rx The x-radius of the oval used to round the corners,default 6px.
28 | * @param ry The y-radius of the oval used to round the corners,default 6px.
29 | */
30 | public RectLightShape(float dx, float dy, float blurRadius,float rx,float ry) {
31 | super(dx, dy, blurRadius);
32 | this.rx=rx;
33 | this.ry=ry;
34 | }
35 |
36 | public RectLightShape(float dx, float dy, float blurRadius) {
37 | super(dx, dy, blurRadius);
38 | }
39 |
40 | public RectLightShape(float dx, float dy) {
41 | super(dx, dy);
42 | }
43 |
44 | @Override
45 | protected void drawShape(Bitmap bitmap, HighLight.ViewPosInfo viewPosInfo) {
46 | Canvas canvas = new Canvas(bitmap);
47 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
48 | paint.setDither(true);
49 | paint.setAntiAlias(true);
50 | if (blurRadius > 0) {
51 | paint.setMaskFilter(new BlurMaskFilter(blurRadius, BlurMaskFilter.Blur.SOLID));
52 | }
53 | canvas.drawRoundRect(viewPosInfo.rectF,rx,ry,paint);
54 | }
55 |
56 | @Override
57 | protected void resetRectF4Shape(RectF viewPosInfoRectF, float dx, float dy) {
58 | viewPosInfoRectF.inset(dx,dy);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/highlight/src/main/java/zhy/com/highlight/util/L.java:
--------------------------------------------------------------------------------
1 | package zhy.com.highlight.util;
2 |
3 | import android.util.Log;
4 |
5 | /**
6 | * Created by zhy on 15/9/23.
7 | */
8 | public class L
9 | {
10 | private static final String TAG = "HighLight";
11 | private static boolean debug = true;
12 |
13 | public static void e(String msg)
14 | {
15 | if (debug)
16 | Log.e(TAG, msg);
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/highlight/src/main/java/zhy/com/highlight/util/ViewUtils.java:
--------------------------------------------------------------------------------
1 | package zhy.com.highlight.util;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.graphics.Rect;
6 | import android.support.v4.view.ViewPager;
7 | import android.view.View;
8 |
9 | /**
10 | * Created by zhy on 15/10/8.
11 | */
12 | public class ViewUtils
13 | {
14 | private static final String FRAGMENT_CON = "NoSaveStateFrameLayout";
15 |
16 | public static Rect getLocationInView(View parent, View child)
17 | {
18 | if (child == null || parent == null)
19 | {
20 | throw new IllegalArgumentException("parent and child can not be null .");
21 | }
22 |
23 | View decorView = null;
24 | Context context = child.getContext();
25 | if (context instanceof Activity)
26 | {
27 | decorView = ((Activity) context).getWindow().getDecorView();
28 | }
29 |
30 | Rect result = new Rect();
31 | Rect tmpRect = new Rect();
32 |
33 | View tmp = child;
34 |
35 | if (child == parent)
36 | {
37 | child.getHitRect(result);
38 | return result;
39 | }
40 | while (tmp != decorView && tmp != parent)
41 | {
42 | tmp.getHitRect(tmpRect);
43 | if (!tmp.getClass().equals(FRAGMENT_CON))
44 | {
45 | result.left += tmpRect.left;
46 | result.top += tmpRect.top;
47 | }
48 | tmp = (View) tmp.getParent();
49 |
50 | //added by isanwenyu@163.com fix bug #21 the wrong rect user will received in ViewPager
51 | if(tmp!=null && tmp.getParent()!=null &&(tmp.getParent() instanceof ViewPager)){
52 | tmp = (View) tmp.getParent();
53 | }
54 | }
55 | result.right = result.left + child.getMeasuredWidth();
56 | result.bottom = result.top + child.getMeasuredHeight();
57 | return result;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/highlight/src/main/java/zhy/com/highlight/view/HightLightView.java:
--------------------------------------------------------------------------------
1 | package zhy.com.highlight.view;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.Canvas;
6 | import android.graphics.Paint;
7 | import android.graphics.PorterDuff;
8 | import android.graphics.PorterDuffXfermode;
9 | import android.view.Gravity;
10 | import android.view.LayoutInflater;
11 | import android.view.View;
12 | import android.widget.FrameLayout;
13 |
14 | import java.util.List;
15 |
16 | import zhy.com.highlight.HighLight;
17 |
18 | /**
19 | * Created by zhy on 15/10/8.
20 | */
21 | public class HightLightView extends FrameLayout
22 | {
23 | private static final int DEFAULT_WIDTH_BLUR = 15;
24 | private static final int DEFAULT_RADIUS = 6;
25 | private static final PorterDuffXfermode MODE_DST_OUT = new PorterDuffXfermode(PorterDuff.Mode.DST_OUT);
26 |
27 | private Bitmap mMaskBitmap;
28 | private Bitmap mLightBitmap;
29 | private Paint mPaint;
30 | private List