├── .gitignore ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── app │ │ └── hubert │ │ └── newbieguide │ │ ├── AbcFragment.java │ │ ├── App.java │ │ ├── FirstActivity.java │ │ ├── GridViewActivity.java │ │ ├── MainActivity.java │ │ ├── ObservableScrollView.java │ │ ├── RecyclerViewActivity.java │ │ ├── ScrollViewActivity.java │ │ └── TestFragmentActivity.java │ └── res │ ├── drawable-xxhdpi │ ├── huiyuan_cebianlan_mengban.png │ └── right.png │ ├── drawable │ └── solid_white_bg.xml │ ├── layout │ ├── activity_first.xml │ ├── activity_grid_view.xml │ ├── activity_main.xml │ ├── activity_recylerview.xml │ ├── activity_scroll_view.xml │ ├── activity_text_fragment.xml │ ├── fragment_abc.xml │ ├── item.xml │ ├── picture_item.xml │ ├── view_guide.xml │ ├── view_guide_anchor.xml │ ├── view_guide_custom.xml │ ├── view_guide_dialog.xml │ ├── view_guide_rv1.xml │ ├── view_guide_simple.xml │ └── view_relative_guide.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── guide ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── app │ │ └── hubert │ │ └── guide │ │ ├── NewbieGuide.java │ │ ├── core │ │ ├── Builder.java │ │ ├── Controller.java │ │ └── GuideLayout.java │ │ ├── lifecycle │ │ ├── FragmentLifecycle.java │ │ ├── FragmentLifecycleAdapter.java │ │ ├── ListenerFragment.java │ │ └── V4ListenerFragment.java │ │ ├── listener │ │ ├── AnimationListenerAdapter.java │ │ ├── OnGuideChangedListener.java │ │ ├── OnHighlightDrewListener.java │ │ ├── OnLayoutInflatedListener.java │ │ └── OnPageChangedListener.java │ │ ├── model │ │ ├── GuidePage.java │ │ ├── HighLight.java │ │ ├── HighlightOptions.java │ │ ├── HighlightRectF.java │ │ ├── HighlightView.java │ │ └── RelativeGuide.java │ │ └── util │ │ ├── LogUtil.java │ │ ├── ScreenUtils.java │ │ └── ViewUtils.java │ └── res │ └── values │ └── strings.xml ├── screenshoot ├── anchor.png ├── change_size.png ├── device-2017-08-09-161703.png ├── device-2017-11-03-151550.png ├── relative_default_gravity.png ├── sample.png ├── shape_dialog.png └── simple_use.png └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea 5 | .DS_Store 6 | /build 7 | /captures 8 | .externalNativeBuild -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![](https://jitpack.io/v/huburt-Hu/NewbieGuide.svg)](https://jitpack.io/#huburt-Hu/NewbieGuide) 2 | 3 | 4 | # NewbieGuide 5 | Android 快速实现新手引导层的库 6 | 7 | 这是一款可以通过简洁链式调用,一行代码实现引导层的显示,自动判断首次显示,当然也可以通过参数配置来满足不同的显示逻辑和需求。 8 | 通过自定义layout.xml实现文本及image的添加,非常方便位置的调整,避免代码调整各种不好控制的情况:实验5,6次才最终确定文字等的位置。 9 | 10 | ## 更新日志 11 | 12 | [更新日志](https://github.com/huburt-Hu/NewbieGuide/wiki) 13 | 14 | 15 | ## 效果 16 | 17 | 改变高亮view的尺寸,并不用调整显示引导层的代码 18 | 19 | ![sample](https://github.com/huburt-Hu/NewbieGuide/raw/master/screenshoot/device-2017-08-09-161703.png)   20 | ![sample](https://github.com/huburt-Hu/NewbieGuide/raw/master/screenshoot/change_size.png) 21 | 22 | 引导层的xml可以完全自定义,像怎样显示就怎样显示 23 | 24 | ![sample](https://github.com/huburt-Hu/NewbieGuide/raw/master/screenshoot/shape_dialog.png) 25 | 26 | 27 | ## 此库依赖 28 | 29 | 30 | ` 31 | compileOnly 'com.android.support:appcompat-v7:25.3.1' 32 | ` 33 | 34 | ## 导入 35 | 36 | 项目的build.gradle添加 37 | 38 | ``` 39 | allprojects { 40 | repositories { 41 | ... 42 | maven { url 'https://jitpack.io' } 43 | } 44 | } 45 | ``` 46 | 47 | module的build.gradle添加 48 | 49 | ``` 50 | dependencies { 51 | compile 'com.github.huburt-Hu:NewbieGuide:v2.4.0' 52 | } 53 | ``` 54 | 55 | **确保你的项目中已经依赖了appcompat-v7** 56 | 57 | 58 | ## 使用 59 | 60 | ### 简单使用 61 | 62 | ``` 63 | NewbieGuide.with(activity) 64 | .setLabel("guide1") 65 | .addGuidePage(GuidePage.newInstance() 66 | .addHighLight(btnSimple) 67 | .setLayoutRes(R.layout.view_guide_simple)) 68 | .show(); 69 | ``` 70 | 71 | 通过链式调用,一行代码即可实现引导层的显示,来看下效果: 72 | 73 | ![simple use](https://github.com/huburt-Hu/NewbieGuide/raw/master/screenshoot/simple_use.png) 74 | 75 | 其中: 76 | 77 | + `with`方法可以传入Activity或者Fragment,获取引导页的依附者。Fragment中使用建议传入fragment,内部会添加监听,当依附的Fragment销毁时,引导层自动消失。 78 | + `setLabel`方法用于设置引导页的标签,区别不同的引导页,该方法**必须**调用设置,否则会抛出异常。内部使用该label控制引导页的显示次数。 79 | + `addGuidePage`方法添加一页引导页,这里的引导层可以有多个引导页,但至少需要一页。 80 | + `GuidePage`即为引导页对象,表示一页引导页,可以通过`.newInstance()`创建对象。并通过`addHighLight`添加一个或多个需要高亮的view,该方法有多个重载,可以设置高亮的形状,以及padding等(默认是矩形)。`setLayoutRes`方法用于引导页说明布局,就是上图的说明文字的布局。 81 | + `show`方法直接显示引导层,如果不想马上显示可以使用`build`方法返回一个Controller对象,完成构建。需要显示得时候再次调用Controller对象的show方法进行显示。 82 | 83 | ### 添加高亮 84 | 85 | #### 高亮view 86 | 87 | addHighLight方法有多个重写,完整参数如下: 88 | 89 | ``` 90 | /** 91 | * 添加需要高亮的view 92 | * 93 | * @param view 需要高亮的view 94 | * @param shape 高亮形状{@link com.app.hubert.guide.model.HighLight.Shape} 95 | * @param round 圆角尺寸,单位dp,仅{@link com.app.hubert.guide.model.HighLight.Shape#ROUND_RECTANGLE}有效 96 | * @param padding 高亮相对view的padding,单位px 97 | * @param relativeGuide 相对于高亮的引导布局 98 | */ 99 | public GuidePage addHighLight(View view, HighLight.Shape shape, int round, int padding, @Nullable RelativeGuide relativeGuide) 100 | 101 | ``` 102 | #### 高亮区域(v2.3.0新增) 103 | 104 | 有些情况可能不太容易获得高亮view的引用,那么此时可以用添加高亮区域的方式来代替, 105 | 计算出需要高亮的view在anchor中位置,将获得的rectF传入addHighLight方法 106 | 107 | ``` 108 | /** 109 | * 添加高亮区域 110 | * 111 | * @param rectF 高亮区域,相对于anchor view(默认是android.R.id.content) 112 | * @param shape 高亮形状{@link com.app.hubert.guide.model.HighLight.Shape} 113 | * @param round 圆角尺寸,单位dp,仅{@link com.app.hubert.guide.model.HighLight.Shape#ROUND_RECTANGLE}有效 114 | * @param relativeGuide 相对于高亮的引导布局 115 | */ 116 | public GuidePage addHighLight(RectF rectF, HighLight.Shape shape, int round, @Nullable RelativeGuide relativeGuide) 117 | ``` 118 | 119 | ### 高亮区域点击事件(v2.4.0新增) 120 | 121 | 之前也是issues中提到需要这个功能,希望能够开放此api,因此在2.4版本中增加了。 122 | 由于目前高亮view的相关参数过多,因此将一些新增的配置都放入了HighlightOptions中,HighlightOptions可以通过内部Builder对象构建: 123 | 124 | ``` 125 | HighlightOptions options = new HighlightOptions.Builder() 126 | .setOnClickListener(new View.OnClickListener() { 127 | @Override 128 | public void onClick(View v) { 129 | Toast.makeText(FirstActivity.this, "highlight click", Toast.LENGTH_SHORT).show(); 130 | } 131 | }) 132 | .build(); 133 | GuidePage page = GuidePage.newInstance().addHighLightWithOptions(btnRelative, options); 134 | NewbieGuide.with(FirstActivity.this) 135 | .setLabel("relative") 136 | .alwaysShow(true)//总是显示,调试时可以打开 137 | .addGuidePage(page) 138 | .show(); 139 | ``` 140 | 141 | ### 自定义高亮区域绘制内容(v2.4.0新增) 142 | 143 | 该功能主要是为了满足[issue51](https://github.com/huburt-Hu/NewbieGuide/issues/51)提出的需求。 144 | 145 | 首先构建一个HighlightOptions,并设置OnHighlightDrewListener: 146 | 147 | ``` 148 | HighlightOptions options = new HighlightOptions.Builder() 149 | .setOnHighlightDrewListener(new OnHighlightDrewListener() { 150 | @Override 151 | public void onHighlightDrew(Canvas canvas, RectF rectF) { 152 | Paint paint = new Paint(); 153 | paint.setColor(Color.WHITE); 154 | paint.setStyle(Paint.Style.STROKE); 155 | paint.setStrokeWidth(10); 156 | paint.setPathEffect(new DashPathEffect(new float[]{20, 20}, 0)); 157 | canvas.drawCircle(rectF.centerX(), rectF.centerY(), rectF.width() / 2 + 10, paint); 158 | } 159 | }) 160 | .build(); 161 | ``` 162 | 163 | onHighlightDrew方法会在引导层绘制高亮之后马上回调,可通过canvas,以及给定的高亮区域rectF,绘制想要任何视图,例如上述示例中完成的issue提出的虚线。 164 | 165 | 然后与高亮区域点击事件类似,传入highlight以及option到addHighLightWithOptions方法中: 166 | 167 | ``` 168 | GuidePage page = GuidePage.newInstance().addHighLightWithOptions(btnRelative, options); 169 | ``` 170 | 171 | 172 | ### 显示次数控制 173 | 174 | 通常情况下引导页只在用户首次打开app的时候显示,第二次进入时不显示,因此默认只显示一次。当然你也可以通过`.setShowCounts(3)`自定义显示的次数,调试的时候可以使用`.alwaysShow(true)`设置每次都显示。 175 | 176 | ``` 177 | NewbieGuide.with(activity) 178 | .setLabel("guide1") 179 | //.setShowCounts(3)//控制次数 180 | .alwaysShow(true)//总是显示,调试时可以打开 181 | .addGuidePage(GuidePage.newInstance() 182 | .addHighLight(btnSimple) 183 | .setLayoutRes(R.layout.view_guide_simple)) 184 | .show(); 185 | ``` 186 | 187 | 就算设置了`.alwaysShow(true)`,内部还是会记录显示得次数,之后改会`setShowCounts(3)`可能实际记录的次数早已超过限制,因此不会再次显示。使用Controller对象的`resetLabel`方法重置次数。(或者清除应用缓存也能重置次数) 188 | 189 | 190 | ### 引导布局 191 | 192 | 着重说明一下setLayoutRes方法,通常其他的类似的库都是通过代码参数来控制说明内容展示在高亮view相对的位置,如下方。经常需要多次运行才能找到满意的位置的参数。大多说明内容只能出现在高亮的上下左右,需要库的支持,自定义的程度不是很高。 193 | 194 | 我所采用的方式是将说明内容通过xml的方式,自定义摆放位置。使得说明内容高度自定义,不管你是简单的图片,还是对话框类型的都可以。 195 | 196 | ![like dialog](https://github.com/huburt-Hu/NewbieGuide/raw/master/screenshoot/shape_dialog.png) 197 | 198 | ``` 199 | GuidePage.newInstance() 200 | .addHighLight(btnDialog) 201 | .setEverywhereCancelable(false)//是否点击任意位置消失引导页,默认true 202 | .setLayoutRes(R.layout.view_guide_dialog, R.id.btn_ok) 203 | .setOnLayoutInflatedListener(new OnLayoutInflatedListener() { 204 | @Override 205 | public void onLayoutInflated(View view, Controller controller) { 206 | TextView tv = view.findViewById(R.id.tv_text); 207 | } 208 | }) 209 | ``` 210 | 211 | 该方法还有一个可变参数`setLayoutRes(@LayoutRes int resId, int... id)`,传入id数组表示在布局中点击让引导页消失或者进入下一页的View(例如,Button ok的id)。 212 | `setOnLayoutInflatedListener`设置布局填充完成的监听,当传入的xml(`R.layout.view_guide_dialog`)填充完成时会回答调用该监听,用于初始化自定布局的元素。 213 | 214 | #### 相对高亮位置的引导布局(v2.3.0新增) 215 | 216 | 鉴于好多人提出上面的方法对于箭头指向的引导控制起来比较麻烦,在不用的手机屏幕尺寸上会有位置差异。 217 | 因此v2.3版本新增在高亮相对位置添加引导布局的方法。扩展addHighLight方法的重载,新增参数RelativeGuide: 218 | ``` 219 | .addGuidePage( 220 | GuidePage.newInstance() 221 | .addHighLight(btnRelative, new RelativeGuide(R.layout.view_relative_guide, 222 | Gravity.RIGHT, 100)) 223 | ) 224 | ``` 225 | 226 | RelativeGuide构造需要2个必传参数: 227 | + 布局layout的res id; 228 | + gravity 目前仅支持 Gravity.LEFT Gravity.TOP Gravity.RIGHT Gravity.BOTTOM 229 | 230 | 还有一个可选参数padding,表示与高亮view的padding 231 | 232 | 引导层本质是一个FrameLayout,RelativeGuide与setLayoutRes都会成为FrameLayout的子view,两者可以共存, 233 | setLayoutRes在下层,多个RelativeGuide按照添加顺序依次添加。 234 | 235 | 各个方向的对齐方式如下图所示: 236 | 237 | ![sample](https://github.com/huburt-Hu/NewbieGuide/raw/master/screenshoot/relative_default_gravity.png) 238 | 239 | 如Gravity.LEFT 的top与高亮view的top对齐,如果想改变,可以通过在传入布局的根布局添加marginTop。 240 | 或者还可以继承RelativeGuide并复写offsetMargin方法修改位置,具体细节可查看RelativeGuide类。 241 | 242 | ### 引导页控制(v2.2.1版本新增) 243 | 244 | v2.2.1版本Controller新增两个方法用于控制引导页的回退,可以在OnLayoutInflatedListener接口的回调方法中获取到controller对象,执行相应的操作。 245 | 246 | ``` 247 | .setOnLayoutInflatedListener(new OnLayoutInflatedListener() { 248 | @Override 249 | public void onLayoutInflated(View view, final Controller controller) { 250 | view.findViewById(R.id.btn_ok).setOnClickListener(new View.OnClickListener() { 251 | @Override 252 | public void onClick(View v) { 253 | controller.showPage(0); 254 | } 255 | }); 256 | } 257 | }) 258 | ``` 259 | 260 | ### 背景色 261 | 262 | 引导页的背景色不要在xml中设置,通过`GuidePage.setBackgroundColor()`设置引导页的背景色,不同引导页可以有不同背景色,默认是0xb2000000,建议设置有透明度的背景色。 263 | 264 | ### anchor 265 | 266 | 默认的话引导层是添加在DecorView中的,我借鉴了[Highlight](https://github.com/hongyangAndroid/Highlight)的anchor概念,可以改变引导层添加到的view,实现局部引导层的显示。通过调用`.anchor(view)`传入anchorView,即为引导层的根布局。 267 | ``` 268 | final View anchorView = findViewById(R.id.ll_anchor); 269 | 270 | NewbieGuide.with(FirstActivity.this) 271 | .setLabel("anchor") .anchor(anchorView) 272 | .alwaysShow(true)//总是显示,调试时可以打开 273 | .addGuidePage(GuidePage.newInstance() .addHighLight(btnAnchor, HighLight.Shape.CIRCLE, 5) 274 | .setLayoutRes(R.layout.view_guide_anchor)) 275 | .show(); 276 | ``` 277 | 这里实现了具体显示引导层。 278 | 279 | ![anchor](https://github.com/huburt-Hu/NewbieGuide/raw/master/screenshoot/anchor.png) 280 | 281 | 引导层其实是一个FrameLayout,设置anchor之后,引导层的大小就与anchor所占的位置相同。默认是android.R.id.content。setLayoutRes方法设置的说明布局则会添加到引导层的FrameLayout中。 282 | 283 | ### 引导层显示隐藏监听 284 | 285 | setOnGuideChangedListener添加引导层的显示隐藏监听,一个label表示一个引导层,一个引导层可以有多个引导页,引导页切换不会触发该监听。 286 | 287 | ``` 288 | NewbieGuide.with(FirstActivity.this) 289 | .setLabel("listener") 290 | .alwaysShow(true)//总是显示,调试时可以打开 291 | .setOnGuideChangedListener(new OnGuideChangedListener() { 292 | @Override 293 | public void onShowed(Controller controller) { 294 | Toast.makeText(FirstActivity.this, "引导层显示", Toast.LENGTH_SHORT).show(); 295 | } 296 | 297 | @Override 298 | public void onRemoved(Controller controller) { 299 | Toast.makeText(FirstActivity.this, "引导层消失", Toast.LENGTH_SHORT).show(); 300 | } 301 | }) 302 | .addGuidePage(GuidePage.newInstance().addHighLight(btnListener)) 303 | .show(); 304 | ``` 305 | 306 | ### 多页引导页与监听 307 | 308 | ``` 309 | .setOnPageChangedListener(new OnPageChangedListener() { 310 | @Override 311 | public void onPageChanged(int page) { 312 | //引导页切换,page为当前页位置,从0开始 313 | Toast.makeText(MainActivity.this, "引导页切换:" + page, Toast.LENGTH_SHORT).show(); 314 | } 315 | }) 316 | .addGuidePage(//添加一页引导页 317 | GuidePage.newInstance()//创建一个实例 318 | .addHighLight(button)//添加高亮的view 319 | .addHighLight(tvBottom, HighLight.Shape.RECTANGLE) 320 | .setLayoutRes(R.layout.view_guide)//设置引导页布局 321 | .setOnLayoutInflatedListener(new OnLayoutInflatedListener() { 322 | @Override 323 | public void onLayoutInflated(View view, Controller controller) { 324 | //引导页布局填充后回调,用于初始化 325 | TextView tv = view.findViewById(R.id.textView2); 326 | tv.setText("我是动态设置的文本"); 327 | } 328 | }) 329 | .setEnterAnimation(enterAnimation)//进入动画 330 | .setExitAnimation(exitAnimation)//退出动画 331 | ) 332 | .addGuidePage( 333 | GuidePage.newInstance() 334 | .addHighLight(tvBottom, HighLight.Shape.RECTANGLE, 20) 335 | .setLayoutRes(R.layout.view_guide_custom, R.id.iv)//引导页布局,点击跳转下一页或者消失引导层的控件id 336 | .setEverywhereCancelable(false)//是否点击任意地方跳转下一页或者消失引导层,默认true 337 | .setBackgroundColor(getResources().getColor(R.color.testColor))//设置背景色,建议使用有透明度的颜色 338 | .setEnterAnimation(enterAnimation)//进入动画 339 | .setExitAnimation(exitAnimation)//退出动画 340 | ) 341 | ``` 342 | 343 | ### 引导页切换动画 344 | 345 | 如上面的例子所示,还可以添加引导页的切换动画 346 | 347 | ``` 348 | Animation enterAnimation = new AlphaAnimation(0f, 1f); 349 | enterAnimation.setDuration(600); 350 | enterAnimation.setFillAfter(true); 351 | 352 | Animation exitAnimation = new AlphaAnimation(1f, 0f); 353 | exitAnimation.setDuration(600); 354 | exitAnimation.setFillAfter(true); 355 | 356 | GuidePage.setEnterAnimation(enterAnimation)//进入动画 357 | GuidePage.setExitAnimation(exitAnimation)//退出动画 358 | ``` 359 | 360 | 361 | 362 | 363 | 364 | ## [Q&A](https://github.com/huburt-Hu/NewbieGuide/wiki/Q&A) 365 | 366 | 遇到问题可以看查看Q&A 367 | 368 | ## 关于我 369 | 370 | Github:https://github.com/huburt-Hu 371 | 372 | CSDN:http://blog.csdn.net/Hubert_bing 373 | 374 | 简书:https://www.jianshu.com/u/002f99a0df6b 375 | 376 | 掘金:https://juejin.im/user/57bb1fdcc4c971006152d7b0/posts 377 | 378 | 379 | 380 | ## License 381 | 382 | 383 | ``` 384 | Copyright 2017 huburt-Hu 385 | 386 | Licensed under the Apache License, Version 2.0 (the "License"); 387 | you may not use this file except in compliance with the License. 388 | You may obtain a copy of the License at 389 | 390 | http://www.apache.org/licenses/LICENSE-2.0 391 | 392 | Unless required by applicable law or agreed to in writing, software 393 | distributed under the License is distributed on an "AS IS" BASIS, 394 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 395 | See the License for the specific language governing permissions and 396 | limitations under the License. 397 | 398 | ``` 399 | 400 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | /src/test 3 | /src/androidTest 4 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion rootProject.ext.compileSdkVersion 5 | buildToolsVersion rootProject.ext.buildToolsVersion 6 | 7 | defaultConfig { 8 | applicationId "com.app.hubert.newbieguide" 9 | minSdkVersion 14 10 | targetSdkVersion 26 11 | versionCode 1 12 | versionName "1.0" 13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | 22 | } 23 | 24 | dependencies { 25 | implementation fileTree(include: ['*.jar'], dir: 'libs') 26 | androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { 27 | exclude group: 'com.android.support', module: 'support-annotations' 28 | }) 29 | implementation project(':guide') 30 | // implementation ('com.github.huburt-Hu:NewbieGuide:v2.4.4') 31 | implementation "com.android.support:appcompat-v7:$rootProject.ext.supportLibraryVersion" 32 | implementation 'com.android.support.constraint:constraint-layout:1.0.2' 33 | implementation "com.android.support:recyclerview-v7:$rootProject.ext.supportLibraryVersion" 34 | implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.28' 35 | implementation("com.jaeger.statusbarutil:library:1.4.0") { 36 | exclude group: 'com.android.support' 37 | } 38 | testImplementation 'junit:junit:4.12' 39 | 40 | // Lifecycles, LiveData 和 ViewModel 41 | implementation 'android.arch.lifecycle:runtime:1.0.3' 42 | implementation 'android.arch.lifecycle:extensions:1.0.0' 43 | annotationProcessor "android.arch.lifecycle:compiler:1.0.0" 44 | // Room 45 | implementation 'android.arch.persistence.room:runtime:1.0.0' 46 | annotationProcessor "android.arch.persistence.room:compiler:1.0.0" 47 | 48 | debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.4' 49 | releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4' 50 | } 51 | -------------------------------------------------------------------------------- /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/julie/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.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 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /app/src/main/java/com/app/hubert/newbieguide/AbcFragment.java: -------------------------------------------------------------------------------- 1 | package com.app.hubert.newbieguide; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.app.Fragment; 6 | import android.util.Log; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.TextView; 11 | 12 | import com.app.hubert.guide.core.Controller; 13 | import com.app.hubert.guide.listener.OnGuideChangedListener; 14 | import com.app.hubert.guide.model.GuidePage; 15 | import com.app.hubert.guide.model.HighLight; 16 | import com.app.hubert.guide.NewbieGuide; 17 | 18 | /** 19 | * Created by hubert 20 | *

21 | * Created on 2017/9/13. 22 | */ 23 | 24 | public class AbcFragment extends Fragment { 25 | 26 | private String text; 27 | 28 | public static AbcFragment newInstance(String text) { 29 | Bundle args = new Bundle(); 30 | args.putString("text", text); 31 | AbcFragment fragment = new AbcFragment(); 32 | fragment.setArguments(args); 33 | return fragment; 34 | } 35 | 36 | @Override 37 | public void onCreate(@Nullable Bundle savedInstanceState) { 38 | super.onCreate(savedInstanceState); 39 | Bundle arguments = getArguments(); 40 | if (arguments != null) { 41 | text = arguments.getString("text"); 42 | } 43 | } 44 | 45 | @Nullable 46 | @Override 47 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 48 | return inflater.inflate(R.layout.fragment_abc, container, false); 49 | } 50 | 51 | @Override 52 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 53 | TextView textView = (TextView) view.findViewById(R.id.tv); 54 | textView.setText("fragment:" + text); 55 | if ("2".equals(text)) { 56 | NewbieGuide.with(this)//传入fragment 57 | .setLabel("guide2")//设置引导层标示,必传!否则报错 58 | .alwaysShow(true) 59 | .setOnGuideChangedListener(new OnGuideChangedListener() { 60 | @Override 61 | public void onShowed(Controller controller) { 62 | 63 | } 64 | 65 | @Override 66 | public void onRemoved(Controller controller) { 67 | Log.e("tag", "onRemoved"); 68 | } 69 | }) 70 | .addGuidePage(GuidePage.newInstance() 71 | .addHighLight(textView, HighLight.Shape.CIRCLE)//添加需要高亮的view 72 | .setLayoutRes(R.layout.view_guide)//自定义的提示layout,不要添加背景色,引导层背景色通过setBackgroundColor()设置 73 | ) 74 | .show();//直接显示引导层 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /app/src/main/java/com/app/hubert/newbieguide/App.java: -------------------------------------------------------------------------------- 1 | package com.app.hubert.newbieguide; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | 6 | import com.squareup.leakcanary.LeakCanary; 7 | import com.squareup.leakcanary.RefWatcher; 8 | 9 | /** 10 | * Created by hubert on 2018/5/2. 11 | */ 12 | public class App extends Application { 13 | 14 | private RefWatcher refWatcher; 15 | private static App instance; 16 | 17 | @Override 18 | public void onCreate() { 19 | super.onCreate(); 20 | instance = this; 21 | if (LeakCanary.isInAnalyzerProcess(this)) { 22 | // This process is dedicated to LeakCanary for heap analysis. 23 | // You should not init your app in this process. 24 | return; 25 | } 26 | refWatcher = LeakCanary.install(this); 27 | // Normal app init code... 28 | } 29 | 30 | public static App getInstance() { 31 | return instance; 32 | } 33 | 34 | public RefWatcher getRefWatcher() { 35 | return refWatcher; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/com/app/hubert/newbieguide/FirstActivity.java: -------------------------------------------------------------------------------- 1 | package com.app.hubert.newbieguide; 2 | 3 | import android.graphics.Canvas; 4 | import android.graphics.Color; 5 | import android.graphics.DashPathEffect; 6 | import android.graphics.Paint; 7 | import android.graphics.RectF; 8 | import android.support.annotation.IntDef; 9 | import android.support.v7.app.AppCompatActivity; 10 | import android.os.Bundle; 11 | import android.view.Gravity; 12 | import android.view.View; 13 | import android.widget.Button; 14 | import android.widget.TextView; 15 | import android.widget.Toast; 16 | 17 | import com.app.hubert.guide.NewbieGuide; 18 | import com.app.hubert.guide.core.Controller; 19 | import com.app.hubert.guide.listener.OnGuideChangedListener; 20 | import com.app.hubert.guide.listener.OnHighlightDrewListener; 21 | import com.app.hubert.guide.listener.OnLayoutInflatedListener; 22 | import com.app.hubert.guide.model.GuidePage; 23 | import com.app.hubert.guide.model.HighLight; 24 | import com.app.hubert.guide.model.HighlightOptions; 25 | import com.app.hubert.guide.model.RelativeGuide; 26 | import com.app.hubert.guide.util.ViewUtils; 27 | 28 | import java.lang.annotation.Retention; 29 | import java.lang.annotation.RetentionPolicy; 30 | 31 | public class FirstActivity extends AppCompatActivity { 32 | 33 | @Override 34 | protected void onCreate(Bundle savedInstanceState) { 35 | super.onCreate(savedInstanceState); 36 | setContentView(R.layout.activity_first); 37 | //简单使用 38 | final Button btnSimple = (Button) findViewById(R.id.btn_simple); 39 | btnSimple.setOnClickListener(new View.OnClickListener() { 40 | @Override 41 | public void onClick(View v) { 42 | NewbieGuide.with(FirstActivity.this) 43 | .setLabel("guide1") 44 | // .setShowCounts(3)//控制次数 45 | .alwaysShow(true)//总是显示,调试时可以打开 46 | .addGuidePage(GuidePage.newInstance() 47 | .addHighLight(btnSimple) 48 | .addHighLight(new RectF(0, 800, 200, 1200)) 49 | .setLayoutRes(R.layout.view_guide_simple)) 50 | .show(); 51 | } 52 | }); 53 | //对话框形式 54 | final Button btnDialog = (Button) findViewById(R.id.btn_dialog); 55 | btnDialog.setOnClickListener(new View.OnClickListener() { 56 | @Override 57 | public void onClick(View v) { 58 | NewbieGuide.with(FirstActivity.this) 59 | .setLabel("guide2") 60 | .alwaysShow(true)//总是显示,调试时可以打开 61 | .addGuidePage(GuidePage.newInstance() 62 | .addHighLight(btnDialog) 63 | .setEverywhereCancelable(false)//是否点击任意位置消失引导页 64 | .setLayoutRes(R.layout.view_guide_dialog, R.id.btn_ok) 65 | .setOnLayoutInflatedListener(new OnLayoutInflatedListener() { 66 | 67 | @Override 68 | public void onLayoutInflated(View view, Controller controller) { 69 | TextView tv = view.findViewById(R.id.tv_text); 70 | tv.setText("this like dialog"); 71 | } 72 | })) 73 | .show(); 74 | } 75 | }); 76 | //设置anchor 及 自定义绘制图形 77 | final View anchorView = findViewById(R.id.ll_anchor); 78 | final Button btnAnchor = (Button) findViewById(R.id.btn_anchor); 79 | btnAnchor.setOnClickListener(new View.OnClickListener() { 80 | @Override 81 | public void onClick(View v) { 82 | HighlightOptions options = new HighlightOptions.Builder() 83 | .setOnHighlightDrewListener(new OnHighlightDrewListener() { 84 | @Override 85 | public void onHighlightDrew(Canvas canvas, RectF rectF) { 86 | Paint paint = new Paint(); 87 | paint.setColor(Color.WHITE); 88 | paint.setStyle(Paint.Style.STROKE); 89 | paint.setStrokeWidth(10); 90 | paint.setPathEffect(new DashPathEffect(new float[]{20, 20}, 0)); 91 | canvas.drawCircle(rectF.centerX(), rectF.centerY(), rectF.width() / 2 + 10, paint); 92 | } 93 | }) 94 | .build(); 95 | NewbieGuide.with(FirstActivity.this) 96 | .setLabel("anchor") 97 | .anchor(anchorView) 98 | .alwaysShow(true)//总是显示,调试时可以打开 99 | .addGuidePage(GuidePage.newInstance() 100 | .addHighLightWithOptions(btnAnchor, HighLight.Shape.CIRCLE, options) 101 | .setLayoutRes(R.layout.view_guide_anchor)) 102 | .show(); 103 | } 104 | }); 105 | //监听 106 | final Button btnListener = findViewById(R.id.btn_listener); 107 | btnListener.setOnClickListener(new View.OnClickListener() { 108 | @Override 109 | public void onClick(View v) { 110 | NewbieGuide.with(FirstActivity.this) 111 | .setLabel("listener") 112 | .alwaysShow(true)//总是显示,调试时可以打开 113 | .setOnGuideChangedListener(new OnGuideChangedListener() { 114 | @Override 115 | public void onShowed(Controller controller) { 116 | Toast.makeText(FirstActivity.this, "引导层显示", Toast.LENGTH_SHORT).show(); 117 | } 118 | 119 | @Override 120 | public void onRemoved(Controller controller) { 121 | Toast.makeText(FirstActivity.this, "引导层消失", Toast.LENGTH_SHORT).show(); 122 | } 123 | }) 124 | .addGuidePage(GuidePage.newInstance() 125 | .addHighLight(btnListener)) 126 | .show(); 127 | } 128 | }); 129 | 130 | findViewById(R.id.btn_multi).setOnClickListener(new View.OnClickListener() { 131 | @Override 132 | public void onClick(View v) { 133 | MainActivity.start(FirstActivity.this); 134 | } 135 | }); 136 | 137 | findViewById(R.id.btn_list).setOnClickListener(new View.OnClickListener() { 138 | @Override 139 | public void onClick(View v) { 140 | RecyclerViewActivity.start(FirstActivity.this); 141 | } 142 | }); 143 | findViewById(R.id.btn_scroll).setOnClickListener(new View.OnClickListener() { 144 | @Override 145 | public void onClick(View v) { 146 | ScrollViewActivity.start(FirstActivity.this); 147 | } 148 | }); 149 | 150 | final View btnRelative = findViewById(R.id.btn_relative); 151 | btnRelative.setOnClickListener(new View.OnClickListener() { 152 | @Override 153 | public void onClick(View v) { 154 | HighlightOptions options = new HighlightOptions.Builder() 155 | .setRelativeGuide(new RelativeGuide(R.layout.view_relative_guide, Gravity.LEFT, 100) { 156 | @Override 157 | protected void onLayoutInflated(View view, Controller controller) { 158 | TextView textView = view.findViewById(R.id.tv); 159 | textView.setText("inflated"); 160 | } 161 | }) 162 | .setOnClickListener(new View.OnClickListener() { 163 | @Override 164 | public void onClick(View v) { 165 | Toast.makeText(FirstActivity.this, "highlight click", Toast.LENGTH_SHORT).show(); 166 | } 167 | }) 168 | .build(); 169 | GuidePage page = GuidePage.newInstance() 170 | .addHighLightWithOptions(btnRelative, options); 171 | NewbieGuide.with(FirstActivity.this) 172 | .setLabel("relative") 173 | .alwaysShow(true)//总是显示,调试时可以打开 174 | .addGuidePage(page) 175 | .show(); 176 | } 177 | }); 178 | 179 | findViewById(R.id.btn_rect).setOnClickListener(new View.OnClickListener() { 180 | @Override 181 | public void onClick(View v) { 182 | NewbieGuide.with(FirstActivity.this) 183 | .setLabel("rect") 184 | .alwaysShow(true)//总是显示,调试时可以打开 185 | .addGuidePage(GuidePage.newInstance() 186 | .addHighLight(new RectF(0, 800, 500, 1000)) 187 | ) 188 | .show(); 189 | } 190 | }); 191 | } 192 | } 193 | -------------------------------------------------------------------------------- /app/src/main/java/com/app/hubert/newbieguide/GridViewActivity.java: -------------------------------------------------------------------------------- 1 | package com.app.hubert.newbieguide; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.os.Bundle; 7 | import android.view.View; 8 | import android.widget.GridView; 9 | import android.widget.SimpleAdapter; 10 | 11 | import com.app.hubert.guide.model.GuidePage; 12 | import com.app.hubert.guide.model.HighLight; 13 | import com.app.hubert.guide.NewbieGuide; 14 | 15 | import java.util.ArrayList; 16 | import java.util.HashMap; 17 | import java.util.List; 18 | import java.util.Map; 19 | 20 | public class GridViewActivity extends AppCompatActivity { 21 | 22 | private String[] from = {"image", "title"}; 23 | private int[] to = {R.id.image, R.id.title}; 24 | 25 | public static void start(Context context) { 26 | Intent starter = new Intent(context, GridViewActivity.class); 27 | context.startActivity(starter); 28 | } 29 | 30 | @Override 31 | protected void onCreate(Bundle savedInstanceState) { 32 | super.onCreate(savedInstanceState); 33 | setContentView(R.layout.activity_grid_view); 34 | final GridView gridView = (GridView) findViewById(R.id.grid_view); 35 | final SimpleAdapter pictureAdapter = new SimpleAdapter(this, getList(), 36 | R.layout.picture_item, from, to); 37 | gridView.setAdapter(pictureAdapter); 38 | gridView.post(new Runnable() { 39 | @Override 40 | public void run() { 41 | //高亮gridView的第2个子view 42 | View childAt = gridView.getChildAt(1); 43 | NewbieGuide.with(GridViewActivity.this) 44 | .setLabel("grid_view_guide") 45 | .alwaysShow(true) 46 | .addGuidePage(GuidePage.newInstance() 47 | .addHighLight(childAt, HighLight.Shape.RECTANGLE) 48 | .setEverywhereCancelable(false) 49 | .setLayoutRes(R.layout.view_guide, R.id.iv)) 50 | .show(); 51 | } 52 | }); 53 | } 54 | 55 | public List> getList() { 56 | List> list = new ArrayList>(); 57 | 58 | String[] titles = new String[]{"本地音乐", "我的最爱", "我的下载", "我的歌单", "最近播放", "我的最爱", "我的下载", "我的歌单", "最近播放"}; 59 | Integer[] images = {R.mipmap.ic_launcher, R.mipmap.ic_launcher, 60 | R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, 61 | R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher}; 62 | 63 | for (int i = 0; i < 50; i++) { 64 | int position = i; 65 | Map map = new HashMap(); 66 | int length = images.length - 1; 67 | if (position > length) { 68 | position = position % length; 69 | } 70 | map.put("image", images[position]); 71 | map.put("title", titles[position]); 72 | list.add(map); 73 | } 74 | return list; 75 | } 76 | } 77 | 78 | -------------------------------------------------------------------------------- /app/src/main/java/com/app/hubert/newbieguide/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.app.hubert.newbieguide; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.util.Log; 8 | import android.view.Gravity; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.view.animation.AlphaAnimation; 12 | import android.view.animation.Animation; 13 | import android.widget.Button; 14 | import android.widget.TextView; 15 | import android.widget.Toast; 16 | 17 | import com.app.hubert.guide.core.Controller; 18 | import com.app.hubert.guide.NewbieGuide; 19 | import com.app.hubert.guide.listener.OnGuideChangedListener; 20 | import com.app.hubert.guide.listener.OnLayoutInflatedListener; 21 | import com.app.hubert.guide.listener.OnPageChangedListener; 22 | import com.app.hubert.guide.model.GuidePage; 23 | import com.app.hubert.guide.model.HighLight; 24 | import com.app.hubert.guide.model.RelativeGuide; 25 | 26 | public class MainActivity extends AppCompatActivity { 27 | 28 | private final String TAG = this.getClass().getSimpleName(); 29 | 30 | public static void start(Context context) { 31 | Intent starter = new Intent(context, MainActivity.class); 32 | context.startActivity(starter); 33 | } 34 | 35 | @Override 36 | protected void onCreate(Bundle savedInstanceState) { 37 | super.onCreate(savedInstanceState); 38 | // StatusBarUtil.setTranslucent(this, 0); 39 | setContentView(R.layout.activity_main); 40 | TextView textView = (TextView) findViewById(R.id.tv); 41 | TextView tvBottom = (TextView) findViewById(R.id.tv_bottom); 42 | textView.setOnClickListener(new View.OnClickListener() { 43 | @Override 44 | public void onClick(View v) { 45 | GridViewActivity.start(MainActivity.this); 46 | } 47 | }); 48 | final Button button = (Button) findViewById(R.id.btn); 49 | button.setOnClickListener(new View.OnClickListener() { 50 | @Override 51 | public void onClick(View v) { 52 | TestFragmentActivity.start(MainActivity.this); 53 | } 54 | }); 55 | 56 | View anchor = findViewById(R.id.ll_anchor); 57 | 58 | Animation enterAnimation = new AlphaAnimation(0f, 1f); 59 | enterAnimation.setDuration(600); 60 | enterAnimation.setFillAfter(true); 61 | 62 | Animation exitAnimation = new AlphaAnimation(1f, 0f); 63 | exitAnimation.setDuration(600); 64 | exitAnimation.setFillAfter(true); 65 | 66 | //新增多页模式,即一个引导层显示多页引导内容 67 | NewbieGuide.with(this) 68 | .setLabel("page")//设置引导层标示区分不同引导层,必传!否则报错 69 | // .anchor(anchor) 70 | .setOnGuideChangedListener(new OnGuideChangedListener() { 71 | @Override 72 | public void onShowed(Controller controller) { 73 | Log.e(TAG, "NewbieGuide onShowed: "); 74 | //引导层显示 75 | } 76 | 77 | @Override 78 | public void onRemoved(Controller controller) { 79 | Log.e(TAG, "NewbieGuide onRemoved: "); 80 | //引导层消失(多页切换不会触发) 81 | } 82 | }) 83 | .setOnPageChangedListener(new OnPageChangedListener() { 84 | 85 | @Override 86 | public void onPageChanged(int page) { 87 | //引导页切换,page为当前页位置,从0开始 88 | Toast.makeText(MainActivity.this, "引导页切换:" + page, Toast.LENGTH_SHORT).show(); 89 | } 90 | }) 91 | .alwaysShow(true)//是否每次都显示引导层,默认false,只显示一次 92 | .addGuidePage(//添加一页引导页 93 | GuidePage.newInstance()//创建一个实例 94 | .addHighLight(button)//添加高亮的view 95 | .addHighLight(tvBottom, 96 | new RelativeGuide(R.layout.view_relative_guide, Gravity.TOP, 100) { 97 | @Override 98 | protected void offsetMargin(MarginInfo marginInfo, ViewGroup viewGroup, View view) { 99 | marginInfo.leftMargin += 100; 100 | } 101 | }) 102 | .setLayoutRes(R.layout.view_guide)//设置引导页布局 103 | .setOnLayoutInflatedListener(new OnLayoutInflatedListener() { 104 | 105 | @Override 106 | public void onLayoutInflated(View view, Controller controller) { 107 | //引导页布局填充后回调,用于初始化 108 | TextView tv = view.findViewById(R.id.textView2); 109 | tv.setText("我是动态设置的文本"); 110 | } 111 | }) 112 | .setEnterAnimation(enterAnimation)//进入动画 113 | .setExitAnimation(exitAnimation)//退出动画 114 | ) 115 | .addGuidePage(GuidePage.newInstance() 116 | .addHighLight(tvBottom, HighLight.Shape.RECTANGLE, 20) 117 | .setLayoutRes(R.layout.view_guide_custom, R.id.iv)//引导页布局,点击跳转下一页或者消失引导层的控件id 118 | .setOnLayoutInflatedListener(new OnLayoutInflatedListener() { 119 | @Override 120 | public void onLayoutInflated(View view, final Controller controller) { 121 | view.findViewById(R.id.textView).setOnClickListener(new View.OnClickListener() { 122 | @Override 123 | public void onClick(View v) { 124 | controller.showPreviewPage(); 125 | } 126 | }); 127 | } 128 | }) 129 | .setEverywhereCancelable(false)//是否点击任意地方跳转下一页或者消失引导层,默认true 130 | .setBackgroundColor(getResources().getColor(R.color.testColor))//设置背景色,建议使用有透明度的颜色 131 | .setEnterAnimation(enterAnimation)//进入动画 132 | .setExitAnimation(exitAnimation)//退出动画 133 | ) 134 | .addGuidePage(GuidePage.newInstance() 135 | .addHighLight(tvBottom) 136 | .setLayoutRes(R.layout.view_guide_dialog) 137 | .setOnLayoutInflatedListener(new OnLayoutInflatedListener() { 138 | @Override 139 | public void onLayoutInflated(View view, final Controller controller) { 140 | view.findViewById(R.id.btn_ok).setOnClickListener(new View.OnClickListener() { 141 | @Override 142 | public void onClick(View v) { 143 | controller.showPage(0); 144 | } 145 | }); 146 | } 147 | }) 148 | ) 149 | .show();//显示引导层(至少需要一页引导页才能显示) 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /app/src/main/java/com/app/hubert/newbieguide/ObservableScrollView.java: -------------------------------------------------------------------------------- 1 | package com.app.hubert.newbieguide; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.widget.ScrollView; 6 | 7 | public class ObservableScrollView extends ScrollView { 8 | 9 | private OnScrollChangeListener scrollChangeListener = null; 10 | 11 | public ObservableScrollView(Context context) { 12 | super(context); 13 | } 14 | 15 | public ObservableScrollView(Context context, AttributeSet attrs) { 16 | super(context, attrs); 17 | } 18 | 19 | public ObservableScrollView(Context context, AttributeSet attrs, int defStyleAttr) { 20 | super(context, attrs, defStyleAttr); 21 | } 22 | 23 | public void setScrollViewListener(OnScrollChangeListener onScrollChangeListener) { 24 | this.scrollChangeListener = onScrollChangeListener; 25 | } 26 | 27 | @Override 28 | protected void onScrollChanged(int x, int y, int oldx, int oldy) { 29 | super.onScrollChanged(x, y, oldx, oldy); 30 | if (scrollChangeListener != null) { 31 | scrollChangeListener.onScrollChanged(this, x, y, oldx, oldy); 32 | } 33 | } 34 | 35 | public interface OnScrollChangeListener { 36 | void onScrollChanged(ObservableScrollView scrollView, int x, int y, int oldx, int oldy); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/src/main/java/com/app/hubert/newbieguide/RecyclerViewActivity.java: -------------------------------------------------------------------------------- 1 | package com.app.hubert.newbieguide; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.support.annotation.Nullable; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.support.v7.widget.GridLayoutManager; 9 | import android.support.v7.widget.LinearLayoutManager; 10 | import android.support.v7.widget.RecyclerView; 11 | import android.view.View; 12 | import android.widget.TextView; 13 | 14 | import com.app.hubert.guide.NewbieGuide; 15 | import com.app.hubert.guide.core.Controller; 16 | import com.app.hubert.guide.listener.OnLayoutInflatedListener; 17 | import com.app.hubert.guide.model.GuidePage; 18 | import com.chad.library.adapter.base.BaseQuickAdapter; 19 | import com.chad.library.adapter.base.BaseViewHolder; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | /** 25 | * Created by hubert 26 | *

27 | * Created on 2017/9/23. 28 | */ 29 | 30 | public class RecyclerViewActivity extends AppCompatActivity { 31 | 32 | private LinearLayoutManager layoutManager; 33 | 34 | @Override 35 | protected void onCreate(@Nullable Bundle savedInstanceState) { 36 | super.onCreate(savedInstanceState); 37 | setContentView(R.layout.activity_recylerview); 38 | final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view); 39 | layoutManager = new LinearLayoutManager(this); 40 | recyclerView.setLayoutManager(layoutManager); 41 | ArrayList data = new ArrayList<>(); 42 | for (int i = 0; i < 30; i++) { 43 | data.add("item " + i); 44 | } 45 | recyclerView.setAdapter(new Adapter(data)); 46 | recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { 47 | 48 | @Override 49 | public void onScrollStateChanged(RecyclerView recyclerView, int newState) { 50 | super.onScrollStateChanged(recyclerView, newState); 51 | if (newState == RecyclerView.SCROLL_STATE_IDLE) { 52 | int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition(); 53 | int lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition(); 54 | int targetPosition = 20; 55 | if (firstVisibleItemPosition <= targetPosition 56 | && targetPosition < lastVisibleItemPosition) {//指定位置滚动到屏幕中 57 | NewbieGuide.with(RecyclerViewActivity.this) 58 | .setLabel("grid_view_guide") 59 | .alwaysShow(true) 60 | .addGuidePage(GuidePage.newInstance() 61 | //注意获取position位置view的方法,不要使用getChildAt 62 | .addHighLight(layoutManager.findViewByPosition(targetPosition)) 63 | .setLayoutRes(R.layout.view_guide_rv1) 64 | .setOnLayoutInflatedListener(new OnLayoutInflatedListener() { 65 | @Override 66 | public void onLayoutInflated(View view, Controller controller) { 67 | TextView tv = view.findViewById(R.id.tv); 68 | tv.setText("滚动后才能可见的item这样使用"); 69 | } 70 | }) 71 | ) 72 | .show(); 73 | } 74 | } 75 | } 76 | }); 77 | 78 | recyclerView.post(new Runnable() { 79 | @Override 80 | public void run() { 81 | NewbieGuide.with(RecyclerViewActivity.this) 82 | .setLabel("grid_view_guide") 83 | .alwaysShow(true) 84 | .addGuidePage(GuidePage.newInstance() 85 | //getChildAt获取的是屏幕中可见的第一个,并不是数据中的position 86 | .addHighLight(recyclerView.getChildAt(0)) 87 | .setLayoutRes(R.layout.view_guide_rv1) 88 | .setOnLayoutInflatedListener(new OnLayoutInflatedListener() { 89 | @Override 90 | public void onLayoutInflated(View view, Controller controller) { 91 | TextView tv = view.findViewById(R.id.tv); 92 | tv.setText("第一页可见的item这样使用"); 93 | } 94 | }) 95 | ) 96 | .show(); 97 | } 98 | }); 99 | } 100 | 101 | public static void start(Context context) { 102 | context.startActivity(new Intent(context, RecyclerViewActivity.class)); 103 | } 104 | 105 | public static class Adapter extends BaseQuickAdapter { 106 | public Adapter(@Nullable List data) { 107 | super(R.layout.item, data); 108 | } 109 | 110 | @Override 111 | protected void convert(BaseViewHolder helper, String item) { 112 | helper.setText(R.id.tv, item); 113 | } 114 | } 115 | 116 | } 117 | -------------------------------------------------------------------------------- /app/src/main/java/com/app/hubert/newbieguide/ScrollViewActivity.java: -------------------------------------------------------------------------------- 1 | package com.app.hubert.newbieguide; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.graphics.Rect; 6 | import android.os.Bundle; 7 | import android.support.annotation.Nullable; 8 | import android.support.v7.app.AppCompatActivity; 9 | import android.view.View; 10 | 11 | import com.app.hubert.guide.NewbieGuide; 12 | import com.app.hubert.guide.core.Controller; 13 | import com.app.hubert.guide.model.GuidePage; 14 | import com.app.hubert.guide.model.HighlightOptions; 15 | 16 | /** 17 | * Created by hubert on 2018/12/11. 18 | */ 19 | public class ScrollViewActivity extends AppCompatActivity { 20 | 21 | private Controller controller; 22 | 23 | public static void start(Context context) { 24 | Intent starter = new Intent(context, ScrollViewActivity.class); 25 | context.startActivity(starter); 26 | } 27 | 28 | @Override 29 | protected void onCreate(@Nullable Bundle savedInstanceState) { 30 | super.onCreate(savedInstanceState); 31 | setContentView(R.layout.activity_scroll_view); 32 | final View light = findViewById(R.id.v_light); 33 | final View lightNext = findViewById(R.id.v_light_next); 34 | 35 | HighlightOptions options = new HighlightOptions.Builder() 36 | .isFetchLocationEveryTime(true) 37 | .build(); 38 | controller = NewbieGuide.with(ScrollViewActivity.this) 39 | .setLabel("scroll1") 40 | .alwaysShow(true) 41 | .addGuidePage(GuidePage.newInstance() 42 | .addHighLightWithOptions(light, options)) 43 | .build(); 44 | ObservableScrollView scrollView = findViewById(R.id.scrollView); 45 | scrollView.setScrollViewListener(new ObservableScrollView.OnScrollChangeListener() { 46 | @Override 47 | public void onScrollChanged(ObservableScrollView scrollView, int x, int y, int oldx, int oldy) { 48 | // if (scrollView.getScrollY() + scrollView.getHeight() - 49 | // scrollView.getPaddingTop() - scrollView.getPaddingBottom() 50 | // == scrollView.getChildAt(0).getHeight()) {//判断滑动到底部 51 | // LogUtil.i("call show"); 52 | // controller.show(); 53 | // } 54 | 55 | Rect scrollBounds = new Rect(); 56 | scrollView.getHitRect(scrollBounds); 57 | if (lightNext.getLocalVisibleRect(scrollBounds)) { 58 | controller.show(); 59 | } 60 | } 61 | }); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /app/src/main/java/com/app/hubert/newbieguide/TestFragmentActivity.java: -------------------------------------------------------------------------------- 1 | package com.app.hubert.newbieguide; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.support.annotation.Nullable; 7 | import android.support.v4.app.Fragment; 8 | import android.support.v7.app.AppCompatActivity; 9 | import android.view.View; 10 | import android.widget.Button; 11 | 12 | /** 13 | * Created by hubert 14 | *

15 | * Created on 2017/9/13. 16 | */ 17 | 18 | public class TestFragmentActivity extends AppCompatActivity { 19 | 20 | Fragment fragment = AbcFragment.newInstance("1"); 21 | Fragment fragment2 = AbcFragment.newInstance("2"); 22 | 23 | public static void start(Context context) { 24 | Intent starter = new Intent(context, TestFragmentActivity.class); 25 | context.startActivity(starter); 26 | } 27 | 28 | @Override 29 | protected void onCreate(@Nullable Bundle savedInstanceState) { 30 | super.onCreate(savedInstanceState); 31 | setContentView(R.layout.activity_text_fragment); 32 | Button button = (Button) findViewById(R.id.btn_change); 33 | Button button1 = (Button) findViewById(R.id.btn_1); 34 | button.setOnClickListener(new View.OnClickListener() { 35 | @Override 36 | public void onClick(View v) { 37 | getSupportFragmentManager().beginTransaction() 38 | .replace(R.id.fl_container, fragment) 39 | .addToBackStack("fragment1") 40 | .commit(); 41 | } 42 | }); 43 | button1.setOnClickListener(new View.OnClickListener() { 44 | @Override 45 | public void onClick(View v) { 46 | getSupportFragmentManager().beginTransaction() 47 | .replace(R.id.fl_container, fragment2) 48 | .addToBackStack("fragment2") 49 | .commit(); 50 | } 51 | }); 52 | 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/huiyuan_cebianlan_mengban.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huburt-Hu/NewbieGuide/d22aac4e82603ca6684d87b215ae451f7e6a0622/app/src/main/res/drawable-xxhdpi/huiyuan_cebianlan_mengban.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huburt-Hu/NewbieGuide/d22aac4e82603ca6684d87b215ae451f7e6a0622/app/src/main/res/drawable-xxhdpi/right.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/solid_white_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_first.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 14 | 15 |