├── .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/#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 | 
20 | 
21 |
22 | 引导层的xml可以完全自定义,像怎样显示就怎样显示
23 |
24 | 
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 | 
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 | 
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 | 
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 | 
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 |
20 |
21 |
26 |
27 |
32 |
33 |
38 |
39 |
40 |
46 |
47 |
52 |
53 |
58 |
59 |
64 |
65 |
71 |
72 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_grid_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
16 |
26 |
27 |
39 |
40 |
41 |
42 |
50 |
51 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_recylerview.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_scroll_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
10 |
11 |
15 |
16 |
20 |
21 |
25 |
26 |
30 |
31 |
35 |
36 |
40 |
41 |
45 |
46 |
50 |
51 |
55 |
56 |
60 |
61 |
65 |
66 |
70 |
71 |
79 |
80 |
85 |
86 |
90 |
91 |
95 |
96 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_text_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
12 |
17 |
18 |
23 |
24 |
25 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_abc.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/picture_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
13 |
14 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_guide.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
20 |
21 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_guide_anchor.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_guide_custom.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
19 |
20 |
28 |
29 |
36 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_guide_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
14 |
15 |
21 |
22 |
27 |
28 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_guide_rv1.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_guide_simple.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_relative_guide.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huburt-Hu/NewbieGuide/d22aac4e82603ca6684d87b215ae451f7e6a0622/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huburt-Hu/NewbieGuide/d22aac4e82603ca6684d87b215ae451f7e6a0622/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huburt-Hu/NewbieGuide/d22aac4e82603ca6684d87b215ae451f7e6a0622/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huburt-Hu/NewbieGuide/d22aac4e82603ca6684d87b215ae451f7e6a0622/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huburt-Hu/NewbieGuide/d22aac4e82603ca6684d87b215ae451f7e6a0622/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huburt-Hu/NewbieGuide/d22aac4e82603ca6684d87b215ae451f7e6a0622/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huburt-Hu/NewbieGuide/d22aac4e82603ca6684d87b215ae451f7e6a0622/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huburt-Hu/NewbieGuide/d22aac4e82603ca6684d87b215ae451f7e6a0622/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huburt-Hu/NewbieGuide/d22aac4e82603ca6684d87b215ae451f7e6a0622/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huburt-Hu/NewbieGuide/d22aac4e82603ca6684d87b215ae451f7e6a0622/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
8 | #9e4891ff
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | NewbieGuide
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | google()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:3.1.2'
10 |
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 |
14 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | jcenter()
21 | maven { url "https://jitpack.io" }
22 | google()
23 | }
24 | }
25 |
26 | task clean(type: Delete) {
27 | delete rootProject.buildDir
28 | }
29 |
30 | ext{
31 | supportLibraryVersion = "27.0.0"
32 | compileSdkVersion = 26
33 | buildToolsVersion = '27.0.3'
34 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huburt-Hu/NewbieGuide/d22aac4e82603ca6684d87b215ae451f7e6a0622/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed May 02 17:58:10 CST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -shape d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/guide/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/guide/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 |
4 | group = 'com.github.huburt-Hu'
5 |
6 | android {
7 | compileSdkVersion rootProject.ext.compileSdkVersion
8 |
9 | defaultConfig {
10 | minSdkVersion 14
11 | targetSdkVersion 26
12 | versionCode 22
13 | versionName "2.2.0"
14 |
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | implementation fileTree(dir: 'libs', include: ['*.jar'])
26 | compileOnly "com.android.support:appcompat-v7:$rootProject.ext.supportLibraryVersion"
27 | }
28 |
--------------------------------------------------------------------------------
/guide/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 |
--------------------------------------------------------------------------------
/guide/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/guide/src/main/java/com/app/hubert/guide/NewbieGuide.java:
--------------------------------------------------------------------------------
1 | package com.app.hubert.guide;
2 |
3 | import android.app.Activity;
4 | import android.app.Fragment;
5 | import android.content.Context;
6 | import android.content.SharedPreferences;
7 |
8 | import com.app.hubert.guide.core.Builder;
9 |
10 | /**
11 | * Created by hubert
12 | *
13 | * Created on 2017/7/27.
14 | */
15 | public class NewbieGuide {
16 |
17 | public static final String TAG = "NewbieGuide";
18 |
19 | /**
20 | * 成功显示标示
21 | */
22 | public static final int SUCCESS = 1;
23 |
24 | /**
25 | * 显示失败标示,即已经显示过一次
26 | */
27 | public static final int FAILED = -1;
28 |
29 | /**
30 | * 新手指引入口
31 | *
32 | * @param activity activity
33 | * @return builder对象,设置参数
34 | */
35 | public static Builder with(Activity activity) {
36 | return new Builder(activity);
37 | }
38 |
39 | public static Builder with(Fragment fragment) {
40 | return new Builder(fragment);
41 | }
42 |
43 | public static Builder with(android.support.v4.app.Fragment v4Fragment) {
44 | return new Builder(v4Fragment);
45 | }
46 |
47 | /**
48 | * 重置标签的显示次数
49 | *
50 | * @param context
51 | * @param label 标签名
52 | */
53 | public static void resetLabel(Context context, String label) {
54 | SharedPreferences sp = context.getSharedPreferences(NewbieGuide.TAG, Activity.MODE_PRIVATE);
55 | sp.edit().putInt(label, 0).apply();
56 | }
57 | }
58 |
59 |
--------------------------------------------------------------------------------
/guide/src/main/java/com/app/hubert/guide/core/Builder.java:
--------------------------------------------------------------------------------
1 | package com.app.hubert.guide.core;
2 |
3 | import android.app.Activity;
4 | import android.app.Fragment;
5 | import android.text.TextUtils;
6 | import android.view.View;
7 |
8 | import com.app.hubert.guide.listener.OnGuideChangedListener;
9 | import com.app.hubert.guide.listener.OnPageChangedListener;
10 | import com.app.hubert.guide.model.GuidePage;
11 |
12 | import java.util.ArrayList;
13 | import java.util.List;
14 |
15 | public class Builder {
16 | Activity activity;
17 | Fragment fragment;
18 | android.support.v4.app.Fragment v4Fragment;
19 | String label;
20 | boolean alwaysShow;//总是显示 default false
21 | View anchor;//锚点view
22 | int showCounts = 1;//显示次数 default once
23 | OnGuideChangedListener onGuideChangedListener;
24 | OnPageChangedListener onPageChangedListener;
25 | List guidePages = new ArrayList<>();
26 |
27 | public Builder(Activity activity) {
28 | this.activity = activity;
29 | }
30 |
31 | public Builder(Fragment fragment) {
32 | this.fragment = fragment;
33 | this.activity = fragment.getActivity();
34 | }
35 |
36 | public Builder(android.support.v4.app.Fragment v4Fragment) {
37 | this.v4Fragment = v4Fragment;
38 | this.activity = v4Fragment.getActivity();
39 | }
40 |
41 | /**
42 | * 引导层显示的锚点,即根布局,不设置的话默认是decorView
43 | *
44 | * @param anchor root
45 | */
46 | public Builder anchor(View anchor) {
47 | this.anchor = anchor;
48 | return this;
49 | }
50 |
51 | /**
52 | * 引导层的显示次数,默认是1次。
53 | * 这里的次数是通过sp控制的,是指同一个label在不清除缓存的情况下可以显示的总次数。
54 | *
55 | * @param count 次数
56 | */
57 | public Builder setShowCounts(int count) {
58 | this.showCounts = count;
59 | return this;
60 | }
61 |
62 | /**
63 | * 是否总是显示引导层,即是否无限次的显示。
64 | * 默认为false,如果设置了true,{@link Builder#setShowCounts} 将无效。
65 | *
66 | * @param b
67 | */
68 | public Builder alwaysShow(boolean b) {
69 | this.alwaysShow = b;
70 | return this;
71 | }
72 |
73 | /**
74 | * 添加引导页
75 | */
76 | public Builder addGuidePage(GuidePage page) {
77 | guidePages.add(page);
78 | return this;
79 | }
80 |
81 | /**
82 | * 设置引导层隐藏,显示监听
83 | */
84 | public Builder setOnGuideChangedListener(OnGuideChangedListener listener) {
85 | onGuideChangedListener = listener;
86 | return this;
87 | }
88 |
89 | /**
90 | * 设置引导页切换监听
91 | */
92 | public Builder setOnPageChangedListener(OnPageChangedListener onPageChangedListener) {
93 | this.onPageChangedListener = onPageChangedListener;
94 | return this;
95 | }
96 |
97 | /**
98 | * 设置引导层的辨识名,必须设置项,否则报错
99 | */
100 | public Builder setLabel(String label) {
101 | this.label = label;
102 | return this;
103 | }
104 |
105 | /**
106 | * 构建引导层controller
107 | *
108 | * @return controller
109 | */
110 | public Controller build() {
111 | check();
112 | return new Controller(this);
113 | }
114 |
115 | /**
116 | * 构建引导层controller并直接显示引导层
117 | *
118 | * @return controller
119 | */
120 | public Controller show() {
121 | check();
122 | Controller controller = new Controller(this);
123 | controller.show();
124 | return controller;
125 | }
126 |
127 | private void check() {
128 | if (TextUtils.isEmpty(label)) {
129 | throw new IllegalArgumentException("the param 'label' is missing, please call setLabel()");
130 | }
131 | if (activity == null && (fragment != null || v4Fragment != null)) {
132 | throw new IllegalStateException("activity is null, please make sure that fragment is showing when call NewbieGuide");
133 | }
134 | }
135 | }
--------------------------------------------------------------------------------
/guide/src/main/java/com/app/hubert/guide/core/Controller.java:
--------------------------------------------------------------------------------
1 | package com.app.hubert.guide.core;
2 |
3 | import android.app.Activity;
4 | import android.app.Fragment;
5 | import android.app.FragmentManager;
6 | import android.content.SharedPreferences;
7 | import android.os.Build;
8 | import android.util.Log;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.view.WindowManager;
13 | import android.widget.FrameLayout;
14 | import android.widget.RelativeLayout;
15 |
16 | import com.app.hubert.guide.NewbieGuide;
17 | import com.app.hubert.guide.lifecycle.FragmentLifecycleAdapter;
18 | import com.app.hubert.guide.lifecycle.ListenerFragment;
19 | import com.app.hubert.guide.lifecycle.V4ListenerFragment;
20 | import com.app.hubert.guide.listener.OnGuideChangedListener;
21 | import com.app.hubert.guide.listener.OnLayoutInflatedListener;
22 | import com.app.hubert.guide.listener.OnPageChangedListener;
23 | import com.app.hubert.guide.model.GuidePage;
24 | import com.app.hubert.guide.model.RelativeGuide;
25 | import com.app.hubert.guide.util.LogUtil;
26 | import com.app.hubert.guide.util.ScreenUtils;
27 |
28 | import java.lang.reflect.Field;
29 | import java.security.InvalidParameterException;
30 | import java.util.List;
31 |
32 | /**
33 | * Created by hubert
34 | *
35 | * Created on 2017/7/27.
36 | *
37 | * guide的控制器,可以通过该类控制引导层的显示与回退,或者重置label
38 | */
39 | public class Controller {
40 |
41 | private static final String LISTENER_FRAGMENT = "listener_fragment";
42 |
43 | private Activity activity;
44 | private Fragment fragment;
45 | private android.support.v4.app.Fragment v4Fragment;
46 | private OnGuideChangedListener onGuideChangedListener;
47 | private OnPageChangedListener onPageChangedListener;
48 | private String label;
49 | private boolean alwaysShow;
50 | private int showCounts;//显示次数
51 | private List guidePages;
52 | private int current;//当前页
53 | private GuideLayout currentLayout;
54 | private FrameLayout mParentView;
55 | private SharedPreferences sp;
56 | private int indexOfChild = -1;//使用anchor时记录的在父布局的位置
57 | private boolean isShowing;
58 |
59 | public Controller(Builder builder) {
60 | this.activity = builder.activity;
61 | this.fragment = builder.fragment;
62 | this.v4Fragment = builder.v4Fragment;
63 | this.onGuideChangedListener = builder.onGuideChangedListener;
64 | this.onPageChangedListener = builder.onPageChangedListener;
65 | this.label = builder.label;
66 | this.alwaysShow = builder.alwaysShow;
67 | this.guidePages = builder.guidePages;
68 | showCounts = builder.showCounts;
69 |
70 | View anchor = builder.anchor;
71 | if (anchor == null) {
72 | anchor = activity.findViewById(android.R.id.content);
73 | }
74 | if (anchor instanceof FrameLayout) {
75 | mParentView = (FrameLayout) anchor;
76 | } else {
77 | FrameLayout frameLayout = new FrameLayout(activity);
78 | ViewGroup parent = (ViewGroup) anchor.getParent();
79 | indexOfChild = parent.indexOfChild(anchor);
80 | parent.removeView(anchor);
81 | if (indexOfChild >= 0) {
82 | parent.addView(frameLayout, indexOfChild, anchor.getLayoutParams());
83 | } else {
84 | parent.addView(frameLayout, anchor.getLayoutParams());
85 | }
86 | ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams
87 | (ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
88 | frameLayout.addView(anchor, lp);
89 | mParentView = frameLayout;
90 | }
91 |
92 | sp = activity.getSharedPreferences(NewbieGuide.TAG, Activity.MODE_PRIVATE);
93 |
94 | }
95 |
96 | /**
97 | * 显示指引layout
98 | */
99 | public void show() {
100 | final int showed = sp.getInt(label, 0);
101 | if (!alwaysShow) {
102 | if (showed >= showCounts) {
103 | return;
104 | }
105 | }
106 |
107 | if (isShowing) {
108 | return;
109 | }
110 | isShowing = true;
111 | mParentView.post(new Runnable() {
112 | @Override
113 | public void run() {
114 | if (guidePages == null || guidePages.size() == 0) {
115 | throw new IllegalStateException("there is no guide to show!! Please add at least one Page.");
116 | }
117 | current = 0;
118 | showGuidePage();
119 | if (onGuideChangedListener != null) {
120 | onGuideChangedListener.onShowed(Controller.this);
121 | }
122 | addListenerFragment();
123 | sp.edit().putInt(label, showed + 1).apply();
124 | }
125 | });
126 | }
127 |
128 | /**
129 | * 显示相应position的引导页
130 | *
131 | * @param position from 0 to (pageSize - 1)
132 | */
133 | public void showPage(int position) {
134 | if (position < 0 || position > guidePages.size() - 1) {
135 | throw new InvalidParameterException("The Guide page position is out of range. current:"
136 | + position + ", range: [ 0, " + guidePages.size() + " )");
137 | }
138 | if (current == position) {
139 | return;
140 | }
141 | current = position;
142 | //fix #59 GuideLayout.setOnGuideLayoutDismissListener() on a null object reference
143 | if (currentLayout != null) {
144 | currentLayout.setOnGuideLayoutDismissListener(new GuideLayout.OnGuideLayoutDismissListener() {
145 | @Override
146 | public void onGuideLayoutDismiss(GuideLayout guideLayout) {
147 | showGuidePage();
148 | }
149 | });
150 | currentLayout.remove();
151 | } else {
152 | showGuidePage();
153 | }
154 | }
155 |
156 | /**
157 | * 显示当前引导页的前一页
158 | */
159 | public void showPreviewPage() {
160 | showPage(--current);
161 | }
162 |
163 | /**
164 | * 显示current引导页
165 | */
166 | private void showGuidePage() {
167 | GuidePage page = guidePages.get(current);
168 | GuideLayout guideLayout = new GuideLayout(activity, page, this);
169 | guideLayout.setOnGuideLayoutDismissListener(new GuideLayout.OnGuideLayoutDismissListener() {
170 | @Override
171 | public void onGuideLayoutDismiss(GuideLayout guideLayout) {
172 | showNextOrRemove();
173 | }
174 | });
175 | mParentView.addView(guideLayout, new FrameLayout.LayoutParams(
176 | ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
177 | currentLayout = guideLayout;
178 | if (onPageChangedListener != null) {
179 | onPageChangedListener.onPageChanged(current);
180 | }
181 | isShowing = true;
182 | }
183 |
184 | private void showNextOrRemove() {
185 | if (current < guidePages.size() - 1) {
186 | current++;
187 | showGuidePage();
188 | } else {
189 | if (onGuideChangedListener != null) {
190 | onGuideChangedListener.onRemoved(Controller.this);
191 | }
192 | removeListenerFragment();
193 | isShowing = false;
194 | }
195 | }
196 |
197 | /**
198 | * 清楚当前Controller的label记录
199 | */
200 | public void resetLabel() {
201 | resetLabel(label);
202 | }
203 |
204 | /**
205 | * 清除"显示过"的标记
206 | *
207 | * @param label 引导标示
208 | */
209 | public void resetLabel(String label) {
210 | sp.edit().putInt(label, 0).apply();
211 | }
212 |
213 | /**
214 | * 中断引导层的显示,后续未显示的page将不再显示
215 | */
216 | public void remove() {
217 | if (currentLayout != null && currentLayout.getParent() != null) {
218 | ViewGroup parent = (ViewGroup) currentLayout.getParent();
219 | parent.removeView(currentLayout);
220 | //移除anchor添加的frameLayout
221 | if (!(parent instanceof FrameLayout)) {
222 | ViewGroup original = (ViewGroup) parent.getParent();
223 | View anchor = parent.getChildAt(0);
224 | parent.removeAllViews();
225 | if (anchor != null) {
226 | if (indexOfChild > 0) {
227 | original.addView(anchor, indexOfChild, parent.getLayoutParams());
228 | } else {
229 | original.addView(anchor, parent.getLayoutParams());
230 | }
231 | }
232 | }
233 | if (onGuideChangedListener != null) {
234 | onGuideChangedListener.onRemoved(this);
235 | }
236 | currentLayout = null;
237 | }
238 | isShowing = false;
239 | }
240 |
241 | public boolean isShowing() {
242 | return isShowing;
243 | }
244 |
245 | private void addListenerFragment() {
246 | //fragment监听销毁界面关闭引导层
247 | if (fragment != null && Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
248 | compatibleFragment(fragment);
249 | FragmentManager fm = fragment.getChildFragmentManager();
250 | ListenerFragment listenerFragment = (ListenerFragment) fm.findFragmentByTag(LISTENER_FRAGMENT);
251 | if (listenerFragment == null) {
252 | listenerFragment = new ListenerFragment();
253 | fm.beginTransaction().add(listenerFragment, LISTENER_FRAGMENT).commitAllowingStateLoss();
254 | }
255 | listenerFragment.setFragmentLifecycle(new FragmentLifecycleAdapter() {
256 | @Override
257 | public void onDestroyView() {
258 | LogUtil.i("ListenerFragment.onDestroyView");
259 | remove();
260 | }
261 | });
262 | }
263 |
264 | if (v4Fragment != null && v4Fragment.isAdded()) {
265 | android.support.v4.app.FragmentManager v4Fm = v4Fragment.getChildFragmentManager();
266 | V4ListenerFragment v4ListenerFragment = (V4ListenerFragment) v4Fm.findFragmentByTag(LISTENER_FRAGMENT);
267 | if (v4ListenerFragment == null) {
268 | v4ListenerFragment = new V4ListenerFragment();
269 | v4Fm.beginTransaction().add(v4ListenerFragment, LISTENER_FRAGMENT).commitAllowingStateLoss();
270 | }
271 | v4ListenerFragment.setFragmentLifecycle(new FragmentLifecycleAdapter() {
272 | @Override
273 | public void onDestroyView() {
274 | LogUtil.i("v4ListenerFragment.onDestroyView");
275 | remove();
276 | }
277 | });
278 | }
279 | }
280 |
281 | private void removeListenerFragment() {
282 | //隐藏引导层时移除监听fragment
283 | if (fragment != null && Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
284 | FragmentManager fm = fragment.getChildFragmentManager();
285 | ListenerFragment listenerFragment = (ListenerFragment) fm.findFragmentByTag(LISTENER_FRAGMENT);
286 | if (listenerFragment != null) {
287 | fm.beginTransaction().remove(listenerFragment).commitAllowingStateLoss();
288 | }
289 | }
290 | if (v4Fragment != null) {
291 | android.support.v4.app.FragmentManager v4Fm = v4Fragment.getChildFragmentManager();
292 | V4ListenerFragment v4ListenerFragment = (V4ListenerFragment) v4Fm.findFragmentByTag(LISTENER_FRAGMENT);
293 | if (v4ListenerFragment != null) {
294 | v4Fm.beginTransaction().remove(v4ListenerFragment).commitAllowingStateLoss();
295 | }
296 | }
297 | }
298 |
299 | /**
300 | * For bug of Fragment in Android
301 | * https://issuetracker.google.com/issues/36963722
302 | *
303 | * @param fragment
304 | */
305 | private void compatibleFragment(Fragment fragment) {
306 | try {
307 | Field childFragmentManager = Fragment.class.getDeclaredField("mChildFragmentManager");
308 | childFragmentManager.setAccessible(true);
309 | childFragmentManager.set(fragment, null);
310 | } catch (NoSuchFieldException e) {
311 | throw new RuntimeException(e);
312 | } catch (IllegalAccessException e) {
313 | throw new RuntimeException(e);
314 | }
315 | }
316 |
317 | }
318 |
--------------------------------------------------------------------------------
/guide/src/main/java/com/app/hubert/guide/core/GuideLayout.java:
--------------------------------------------------------------------------------
1 | package com.app.hubert.guide.core;
2 |
3 | import android.content.Context;
4 | import android.graphics.BlurMaskFilter;
5 | import android.graphics.Canvas;
6 | import android.graphics.Paint;
7 | import android.graphics.PorterDuff;
8 | import android.graphics.PorterDuffXfermode;
9 | import android.graphics.RectF;
10 | import android.util.AttributeSet;
11 | import android.util.Log;
12 | import android.view.LayoutInflater;
13 | import android.view.MotionEvent;
14 | import android.view.View;
15 | import android.view.ViewConfiguration;
16 | import android.view.ViewGroup;
17 | import android.view.animation.Animation;
18 | import android.widget.FrameLayout;
19 | import android.widget.RelativeLayout;
20 |
21 | import com.app.hubert.guide.NewbieGuide;
22 | import com.app.hubert.guide.listener.AnimationListenerAdapter;
23 | import com.app.hubert.guide.listener.OnHighlightDrewListener;
24 | import com.app.hubert.guide.listener.OnLayoutInflatedListener;
25 | import com.app.hubert.guide.model.GuidePage;
26 | import com.app.hubert.guide.model.HighLight;
27 | import com.app.hubert.guide.model.HighlightOptions;
28 | import com.app.hubert.guide.model.RelativeGuide;
29 |
30 | import java.util.ArrayList;
31 | import java.util.List;
32 |
33 | /**
34 | * Created by hubert
35 | *
36 | * Created on 2017/7/27.
37 | */
38 | public class GuideLayout extends FrameLayout {
39 |
40 | public static final int DEFAULT_BACKGROUND_COLOR = 0xb2000000;
41 |
42 | private Controller controller;
43 | private Paint mPaint;
44 | public GuidePage guidePage;
45 | private OnGuideLayoutDismissListener listener;
46 | private float downX;
47 | private float downY;
48 | private int touchSlop;
49 |
50 | public GuideLayout(Context context, GuidePage page, Controller controller) {
51 | super(context);
52 | init();
53 | setGuidePage(page);
54 | this.controller = controller;
55 | }
56 |
57 | private GuideLayout(Context context, AttributeSet attrs) {
58 | super(context, attrs);
59 | }
60 |
61 | private GuideLayout(Context context, AttributeSet attrs, int defStyleAttr) {
62 | super(context, attrs, defStyleAttr);
63 | }
64 |
65 | private void init() {
66 | mPaint = new Paint();
67 | mPaint.setAntiAlias(true);
68 | PorterDuffXfermode xfermode = new PorterDuffXfermode(PorterDuff.Mode.CLEAR);
69 | mPaint.setXfermode(xfermode);
70 |
71 | //设置画笔遮罩滤镜,可以传入BlurMaskFilter或EmbossMaskFilter,前者为模糊遮罩滤镜而后者为浮雕遮罩滤镜
72 | //这个方法已经被标注为过时的方法了,如果你的应用启用了硬件加速,你是看不到任何阴影效果的
73 | mPaint.setMaskFilter(new BlurMaskFilter(10, BlurMaskFilter.Blur.INNER));
74 | //关闭当前view的硬件加速
75 | setLayerType(LAYER_TYPE_SOFTWARE, null);
76 |
77 | //ViewGroup默认设定为true,会使onDraw方法不执行,如果复写了onDraw(Canvas)方法,需要清除此标记
78 | setWillNotDraw(false);
79 |
80 | touchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
81 | }
82 |
83 | private void setGuidePage(GuidePage page) {
84 | this.guidePage = page;
85 | setOnClickListener(new View.OnClickListener() {
86 | @Override
87 | public void onClick(View v) {
88 | if (guidePage.isEverywhereCancelable()) {
89 | remove();
90 | }
91 | }
92 | });
93 | }
94 |
95 | @Override
96 | public boolean performClick() {
97 | return super.performClick();
98 | }
99 |
100 | @Override
101 | public boolean onTouchEvent(MotionEvent event) {
102 | int action = event.getAction();
103 | switch (action) {
104 | case MotionEvent.ACTION_DOWN:
105 | downX = event.getX();
106 | downY = event.getY();
107 | break;
108 | case MotionEvent.ACTION_MOVE:
109 | break;
110 | case MotionEvent.ACTION_UP:
111 | case MotionEvent.ACTION_CANCEL:
112 | float upX = event.getX();
113 | float upY = event.getY();
114 | if (Math.abs(upX - downX) < touchSlop && Math.abs(upY - downY) < touchSlop) {
115 | List highLights = guidePage.getHighLights();
116 | for (HighLight highLight : highLights) {
117 | RectF rectF = highLight.getRectF((ViewGroup) getParent());
118 | if (rectF.contains(upX, upY)) {
119 | notifyClickListener(highLight);
120 | return true;
121 | }
122 | }
123 | performClick();
124 | }
125 | break;
126 |
127 | }
128 | return super.onTouchEvent(event);
129 | }
130 |
131 | private void notifyClickListener(HighLight highLight) {
132 | HighlightOptions options = highLight.getOptions();
133 | if (options != null) {
134 | if (options.onClickListener != null) {
135 | options.onClickListener.onClick(this);
136 | }
137 | }
138 | }
139 |
140 | @Override
141 | protected void onDraw(Canvas canvas) {
142 | super.onDraw(canvas);
143 | int backgroundColor = guidePage.getBackgroundColor();
144 | canvas.drawColor(backgroundColor == 0 ? DEFAULT_BACKGROUND_COLOR : backgroundColor);
145 | drawHighlights(canvas);
146 | }
147 |
148 | private void drawHighlights(Canvas canvas) {
149 | List highLights = guidePage.getHighLights();
150 | if (highLights != null) {
151 | for (HighLight highLight : highLights) {
152 | RectF rectF = highLight.getRectF((ViewGroup) getParent());
153 | switch (highLight.getShape()) {
154 | case CIRCLE:
155 | canvas.drawCircle(rectF.centerX(), rectF.centerY(), highLight.getRadius(), mPaint);
156 | break;
157 | case OVAL:
158 | canvas.drawOval(rectF, mPaint);
159 | break;
160 | case ROUND_RECTANGLE:
161 | canvas.drawRoundRect(rectF, highLight.getRound(), highLight.getRound(), mPaint);
162 | break;
163 | case RECTANGLE:
164 | default:
165 | canvas.drawRect(rectF, mPaint);
166 | break;
167 | }
168 | notifyDrewListener(canvas, highLight, rectF);
169 | }
170 | }
171 | }
172 |
173 | private void notifyDrewListener(Canvas canvas, HighLight highLight, RectF rectF) {
174 | HighlightOptions options = highLight.getOptions();
175 | if (options != null) {
176 | if (options.onHighlightDrewListener != null) {
177 | options.onHighlightDrewListener.onHighlightDrew(canvas, rectF);
178 | }
179 | }
180 | }
181 |
182 | @Override
183 | protected void onAttachedToWindow() {
184 | super.onAttachedToWindow();
185 | addCustomToLayout(guidePage);
186 | Animation enterAnimation = guidePage.getEnterAnimation();
187 | if (enterAnimation != null) {
188 | startAnimation(enterAnimation);
189 | }
190 | }
191 |
192 | /**
193 | * 将自定义布局填充到guideLayout中
194 | */
195 | private void addCustomToLayout(GuidePage guidePage) {
196 | removeAllViews();
197 | int layoutResId = guidePage.getLayoutResId();
198 | if (layoutResId != 0) {
199 | View view = LayoutInflater.from(getContext()).inflate(layoutResId, this, false);
200 | RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
201 | ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
202 | int[] viewIds = guidePage.getClickToDismissIds();
203 | if (viewIds != null && viewIds.length > 0) {
204 | for (int viewId : viewIds) {
205 | View click = view.findViewById(viewId);
206 | if (click != null) {
207 | click.setOnClickListener(new View.OnClickListener() {
208 | @Override
209 | public void onClick(View v) {
210 | remove();
211 | }
212 | });
213 | } else {
214 | Log.w(NewbieGuide.TAG, "can't find the view by id : " + viewId + " which used to remove guide page");
215 | }
216 | }
217 | }
218 | OnLayoutInflatedListener inflatedListener = guidePage.getOnLayoutInflatedListener();
219 | if (inflatedListener != null) {
220 | inflatedListener.onLayoutInflated(view, controller);
221 | }
222 | addView(view, params);
223 | }
224 | List relativeGuides = guidePage.getRelativeGuides();
225 | if (relativeGuides.size() > 0) {
226 | for (RelativeGuide relativeGuide : relativeGuides) {
227 | addView(relativeGuide.getGuideLayout((ViewGroup) getParent(), controller));
228 | }
229 | }
230 | }
231 |
232 | public void setOnGuideLayoutDismissListener(OnGuideLayoutDismissListener listener) {
233 | this.listener = listener;
234 | }
235 |
236 | public void remove() {
237 | Animation exitAnimation = guidePage.getExitAnimation();
238 | if (exitAnimation != null) {
239 | exitAnimation.setAnimationListener(new AnimationListenerAdapter() {
240 | @Override
241 | public void onAnimationEnd(Animation animation) {
242 | dismiss();
243 | }
244 | });
245 | startAnimation(exitAnimation);
246 | } else {
247 | dismiss();
248 | }
249 | }
250 |
251 | private void dismiss() {
252 | if (getParent() != null) {
253 | ((ViewGroup) getParent()).removeView(this);
254 | if (listener != null) {
255 | listener.onGuideLayoutDismiss(this);
256 | }
257 | }
258 | }
259 |
260 | public interface OnGuideLayoutDismissListener {
261 | void onGuideLayoutDismiss(GuideLayout guideLayout);
262 | }
263 |
264 | }
265 |
--------------------------------------------------------------------------------
/guide/src/main/java/com/app/hubert/guide/lifecycle/FragmentLifecycle.java:
--------------------------------------------------------------------------------
1 | package com.app.hubert.guide.lifecycle;
2 |
3 | public interface FragmentLifecycle {
4 | void onStart();
5 |
6 | void onStop();
7 |
8 | void onDestroyView();
9 |
10 | void onDestroy();
11 | }
--------------------------------------------------------------------------------
/guide/src/main/java/com/app/hubert/guide/lifecycle/FragmentLifecycleAdapter.java:
--------------------------------------------------------------------------------
1 | package com.app.hubert.guide.lifecycle;
2 |
3 | public abstract class FragmentLifecycleAdapter implements FragmentLifecycle {
4 | @Override
5 | public void onStart() {
6 | }
7 |
8 | @Override
9 | public void onStop() {
10 | }
11 |
12 | @Override
13 | public void onDestroyView() {
14 | }
15 |
16 | @Override
17 | public void onDestroy() {
18 | }
19 | }
--------------------------------------------------------------------------------
/guide/src/main/java/com/app/hubert/guide/lifecycle/ListenerFragment.java:
--------------------------------------------------------------------------------
1 | package com.app.hubert.guide.lifecycle;
2 |
3 | import android.app.Fragment;
4 |
5 | import com.app.hubert.guide.util.LogUtil;
6 |
7 | public class ListenerFragment extends Fragment {
8 |
9 | FragmentLifecycle mFragmentLifecycle;
10 |
11 | public void setFragmentLifecycle(FragmentLifecycle lifecycle) {
12 | mFragmentLifecycle = lifecycle;
13 | }
14 |
15 | @Override
16 | public void onStart() {
17 | super.onStart();
18 | LogUtil.d("onStart: ");
19 | if (mFragmentLifecycle != null) mFragmentLifecycle.onStart();
20 | }
21 |
22 | @Override
23 | public void onStop() {
24 | super.onStop();
25 | if (mFragmentLifecycle != null) mFragmentLifecycle.onStop();
26 | }
27 |
28 | @Override
29 | public void onDestroyView() {
30 | super.onDestroyView();
31 | if (mFragmentLifecycle != null) mFragmentLifecycle.onDestroyView();
32 | }
33 |
34 | @Override
35 | public void onDestroy() {
36 | super.onDestroy();
37 | LogUtil.d("onDestroy: ");
38 | if (mFragmentLifecycle != null) mFragmentLifecycle.onDestroy();
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/guide/src/main/java/com/app/hubert/guide/lifecycle/V4ListenerFragment.java:
--------------------------------------------------------------------------------
1 | package com.app.hubert.guide.lifecycle;
2 |
3 | import android.support.v4.app.Fragment;
4 |
5 | import com.app.hubert.guide.util.LogUtil;
6 |
7 | /**
8 | * Created by hubert
9 | *
10 | * Created on 2017/9/13.
11 | */
12 |
13 | public class V4ListenerFragment extends Fragment {
14 |
15 | FragmentLifecycle mFragmentLifecycle;
16 |
17 | public void setFragmentLifecycle(FragmentLifecycle lifecycle) {
18 | mFragmentLifecycle = lifecycle;
19 | }
20 |
21 | @Override
22 | public void onStart() {
23 | super.onStart();
24 | LogUtil.d("onStart: ");
25 | if (mFragmentLifecycle != null) mFragmentLifecycle.onStart();
26 | }
27 |
28 | @Override
29 | public void onStop() {
30 | super.onStop();
31 | if (mFragmentLifecycle != null) mFragmentLifecycle.onStop();
32 | }
33 |
34 | @Override
35 | public void onDestroyView() {
36 | super.onDestroyView();
37 | if (mFragmentLifecycle != null) mFragmentLifecycle.onDestroyView();
38 | }
39 |
40 | @Override
41 | public void onDestroy() {
42 | super.onDestroy();
43 | LogUtil.d("onDestroy: ");
44 | if (mFragmentLifecycle != null) mFragmentLifecycle.onDestroy();
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/guide/src/main/java/com/app/hubert/guide/listener/AnimationListenerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.app.hubert.guide.listener;
2 |
3 | import android.view.animation.Animation;
4 |
5 | /**
6 | * Created by hubert on 2018/2/12.
7 | */
8 |
9 | public abstract class AnimationListenerAdapter implements Animation.AnimationListener {
10 | @Override
11 | public void onAnimationStart(Animation animation) {
12 |
13 | }
14 |
15 | @Override
16 | public void onAnimationEnd(Animation animation) {
17 |
18 | }
19 |
20 | @Override
21 | public void onAnimationRepeat(Animation animation) {
22 |
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/guide/src/main/java/com/app/hubert/guide/listener/OnGuideChangedListener.java:
--------------------------------------------------------------------------------
1 | package com.app.hubert.guide.listener;
2 |
3 | import com.app.hubert.guide.core.Controller;
4 |
5 | /**
6 | * Created by hubert on 2017/7/27.
7 | *
8 | * 引导层显示和消失的监听
9 | */
10 | public interface OnGuideChangedListener {
11 | /**
12 | * 当引导层显示时回调
13 | *
14 | * @param controller
15 | */
16 | void onShowed(Controller controller);
17 |
18 | /**
19 | * 当引导层消失时回调
20 | *
21 | * @param controller
22 | */
23 | void onRemoved(Controller controller);
24 | }
--------------------------------------------------------------------------------
/guide/src/main/java/com/app/hubert/guide/listener/OnHighlightDrewListener.java:
--------------------------------------------------------------------------------
1 | package com.app.hubert.guide.listener;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.RectF;
5 |
6 | /**
7 | * Created by hubert on 2018/7/9.
8 | */
9 | public interface OnHighlightDrewListener {
10 |
11 | void onHighlightDrew(Canvas canvas, RectF rectF);
12 | }
13 |
--------------------------------------------------------------------------------
/guide/src/main/java/com/app/hubert/guide/listener/OnLayoutInflatedListener.java:
--------------------------------------------------------------------------------
1 | package com.app.hubert.guide.listener;
2 |
3 | import android.view.View;
4 |
5 | import com.app.hubert.guide.core.Controller;
6 |
7 | /**
8 | * Created by hubert on 2018/2/12.
9 | *
10 | * 用于引导层布局初始化
11 | */
12 |
13 | public interface OnLayoutInflatedListener {
14 |
15 | /**
16 | * @param view {@link com.app.hubert.guide.model.GuidePage#setLayoutRes(int, int...)}方法传入的layoutRes填充后的view
17 | * @param controller {@link Controller}
18 | */
19 | void onLayoutInflated(View view, Controller controller);
20 | }
21 |
--------------------------------------------------------------------------------
/guide/src/main/java/com/app/hubert/guide/listener/OnPageChangedListener.java:
--------------------------------------------------------------------------------
1 | package com.app.hubert.guide.listener;
2 |
3 | /**
4 | * Created by hubert on 2017/11/16.
5 | *
6 | * 引导页改变的监听
7 | */
8 |
9 | public interface OnPageChangedListener {
10 | /**
11 | * @param page 当前引导页的position,第一页为0
12 | */
13 | void onPageChanged(int page);
14 | }
15 |
--------------------------------------------------------------------------------
/guide/src/main/java/com/app/hubert/guide/model/GuidePage.java:
--------------------------------------------------------------------------------
1 | package com.app.hubert.guide.model;
2 |
3 | import android.graphics.RectF;
4 | import android.support.annotation.ColorInt;
5 | import android.support.annotation.LayoutRes;
6 | import android.support.annotation.Nullable;
7 | import android.view.View;
8 | import android.view.animation.Animation;
9 |
10 | import com.app.hubert.guide.listener.OnHighlightDrewListener;
11 | import com.app.hubert.guide.listener.OnLayoutInflatedListener;
12 |
13 | import java.util.ArrayList;
14 | import java.util.Arrays;
15 | import java.util.List;
16 |
17 | /**
18 | * Created by hubert
19 | *
20 | * Created on 2017/11/16.
21 | */
22 |
23 | public class GuidePage {
24 |
25 | private List highLights = new ArrayList<>();
26 | private boolean everywhereCancelable = true;
27 | private int backgroundColor;
28 |
29 | private int layoutResId;
30 | private int[] clickToDismissIds;
31 | private OnLayoutInflatedListener onLayoutInflatedListener;
32 | private OnHighlightDrewListener onHighlightDrewListener;
33 | private Animation enterAnimation, exitAnimation;
34 |
35 | public static GuidePage newInstance() {
36 | return new GuidePage();
37 | }
38 |
39 | public GuidePage addHighLight(View view) {
40 | return addHighLight(view, HighLight.Shape.RECTANGLE, 0, 0, null);
41 | }
42 |
43 | public GuidePage addHighLight(View view, RelativeGuide relativeGuide) {
44 | return addHighLight(view, HighLight.Shape.RECTANGLE, 0, 0, relativeGuide);
45 | }
46 |
47 | public GuidePage addHighLight(View view, HighLight.Shape shape) {
48 | return addHighLight(view, shape, 0, 0, null);
49 | }
50 |
51 | public GuidePage addHighLight(View view, HighLight.Shape shape, RelativeGuide relativeGuide) {
52 | return addHighLight(view, shape, 0, 0, relativeGuide);
53 | }
54 |
55 | public GuidePage addHighLight(View view, HighLight.Shape shape, int padding) {
56 | return addHighLight(view, shape, 0, padding, null);
57 | }
58 |
59 | public GuidePage addHighLight(View view, HighLight.Shape shape, int padding, RelativeGuide relativeGuide) {
60 | return addHighLight(view, shape, 0, padding, relativeGuide);
61 | }
62 |
63 | /**
64 | * 添加需要高亮的view
65 | *
66 | * @param view 需要高亮的view
67 | * @param shape 高亮形状{@link com.app.hubert.guide.model.HighLight.Shape}
68 | * @param round 圆角尺寸,单位dp,仅{@link com.app.hubert.guide.model.HighLight.Shape#ROUND_RECTANGLE}有效
69 | * @param padding 高亮相对view的padding,单位px
70 | * @param relativeGuide 相对于高亮的引导布局
71 | */
72 | public GuidePage addHighLight(View view, HighLight.Shape shape, int round, int padding,
73 | @Nullable RelativeGuide relativeGuide) {
74 | HighlightView highlight = new HighlightView(view, shape, round, padding);
75 | if (relativeGuide != null) {
76 | relativeGuide.highLight = highlight;
77 | highlight.setOptions(new HighlightOptions.Builder().setRelativeGuide(relativeGuide).build());
78 | }
79 | highLights.add(highlight);
80 | return this;
81 | }
82 |
83 | public GuidePage addHighLight(RectF rectF) {
84 | return addHighLight(rectF, HighLight.Shape.RECTANGLE, 0, null);
85 | }
86 |
87 | public GuidePage addHighLight(RectF rectF, RelativeGuide relativeGuide) {
88 | return addHighLight(rectF, HighLight.Shape.RECTANGLE, 0, relativeGuide);
89 | }
90 |
91 | public GuidePage addHighLight(RectF rectF, HighLight.Shape shape) {
92 | return addHighLight(rectF, shape, 0, null);
93 | }
94 |
95 | public GuidePage addHighLight(RectF rectF, HighLight.Shape shape, RelativeGuide relativeGuide) {
96 | return addHighLight(rectF, shape, 0, relativeGuide);
97 | }
98 |
99 | public GuidePage addHighLight(RectF rectF, HighLight.Shape shape, int round) {
100 | return addHighLight(rectF, shape, round, null);
101 | }
102 |
103 | /**
104 | * 添加高亮区域
105 | *
106 | * @param rectF 高亮区域,相对与anchor view(默认是decorView)
107 | * @param shape 高亮形状{@link com.app.hubert.guide.model.HighLight.Shape}
108 | * @param round 圆角尺寸,单位dp,仅{@link com.app.hubert.guide.model.HighLight.Shape#ROUND_RECTANGLE}有效
109 | * @param relativeGuide 相对于高亮的引导布局
110 | */
111 | public GuidePage addHighLight(RectF rectF, HighLight.Shape shape, int round, RelativeGuide relativeGuide) {
112 | HighlightRectF highlight = new HighlightRectF(rectF, shape, round);
113 | if (relativeGuide != null) {
114 | relativeGuide.highLight = highlight;
115 | highlight.setOptions(new HighlightOptions.Builder().setRelativeGuide(relativeGuide).build());
116 | }
117 | highLights.add(highlight);
118 | return this;
119 | }
120 |
121 | public GuidePage addHighLightWithOptions(View view, HighlightOptions options) {
122 | return addHighLightWithOptions(view, HighLight.Shape.RECTANGLE, 0, 0, options);
123 | }
124 |
125 | public GuidePage addHighLightWithOptions(View view, HighLight.Shape shape, HighlightOptions options) {
126 | return addHighLightWithOptions(view, shape, 0, 0, options);
127 | }
128 |
129 | public GuidePage addHighLightWithOptions(View view, HighLight.Shape shape, int round, int padding, HighlightOptions options) {
130 | HighlightView highlight = new HighlightView(view, shape, round, padding);
131 | if (options != null) {
132 | if (options.relativeGuide != null) {
133 | options.relativeGuide.highLight = highlight;
134 | }
135 | }
136 | highlight.setOptions(options);
137 | highLights.add(highlight);
138 | return this;
139 | }
140 |
141 | public GuidePage addHighLightWithOptions(RectF rectF, HighlightOptions options) {
142 | return addHighLightWithOptions(rectF, HighLight.Shape.RECTANGLE, 0, options);
143 | }
144 |
145 | public GuidePage addHighLightWithOptions(RectF rectF, HighLight.Shape shape, HighlightOptions options) {
146 | return addHighLightWithOptions(rectF, shape, 0, options);
147 | }
148 |
149 | public GuidePage addHighLightWithOptions(RectF rectF, HighLight.Shape shape, int round, HighlightOptions options) {
150 | HighlightRectF highlight = new HighlightRectF(rectF, shape, round);
151 | if (options != null) {
152 | if (options.relativeGuide != null) {
153 | options.relativeGuide.highLight = highlight;
154 | }
155 | }
156 | highlight.setOptions(options);
157 | highLights.add(highlight);
158 | return this;
159 | }
160 |
161 | /**
162 | * 添加引导层布局
163 | *
164 | * @param resId 布局id
165 | * @param id 布局中点击消失引导页的控件id
166 | */
167 | public GuidePage setLayoutRes(@LayoutRes int resId, int... id) {
168 | this.layoutResId = resId;
169 | clickToDismissIds = id;
170 | return this;
171 | }
172 |
173 | public GuidePage setEverywhereCancelable(boolean everywhereCancelable) {
174 | this.everywhereCancelable = everywhereCancelable;
175 | return this;
176 | }
177 |
178 | /**
179 | * 设置背景色
180 | */
181 | public GuidePage setBackgroundColor(@ColorInt int backgroundColor) {
182 | this.backgroundColor = backgroundColor;
183 | return this;
184 | }
185 |
186 | /**
187 | * 设置自定义layout填充监听,用于自定义layout初始化
188 | *
189 | * @param onLayoutInflatedListener listener
190 | */
191 | public GuidePage setOnLayoutInflatedListener(OnLayoutInflatedListener onLayoutInflatedListener) {
192 | this.onLayoutInflatedListener = onLayoutInflatedListener;
193 | return this;
194 | }
195 |
196 | /**
197 | * 设置进入动画
198 | */
199 | public GuidePage setEnterAnimation(Animation enterAnimation) {
200 | this.enterAnimation = enterAnimation;
201 | return this;
202 | }
203 |
204 | /**
205 | * 设置退出动画
206 | */
207 | public GuidePage setExitAnimation(Animation exitAnimation) {
208 | this.exitAnimation = exitAnimation;
209 | return this;
210 | }
211 |
212 | public boolean isEverywhereCancelable() {
213 | return everywhereCancelable;
214 | }
215 |
216 | public boolean isEmpty() {
217 | return layoutResId == 0 && highLights.size() == 0;
218 | }
219 |
220 | public List getHighLights() {
221 | return highLights;
222 | }
223 |
224 | public int getBackgroundColor() {
225 | return backgroundColor;
226 | }
227 |
228 | public int getLayoutResId() {
229 | return layoutResId;
230 | }
231 |
232 | public int[] getClickToDismissIds() {
233 | return clickToDismissIds;
234 | }
235 |
236 | public OnLayoutInflatedListener getOnLayoutInflatedListener() {
237 | return onLayoutInflatedListener;
238 | }
239 |
240 | public Animation getEnterAnimation() {
241 | return enterAnimation;
242 | }
243 |
244 | public Animation getExitAnimation() {
245 | return exitAnimation;
246 | }
247 |
248 | public List getRelativeGuides() {
249 | List relativeGuides = new ArrayList<>();
250 | for (HighLight highLight : highLights) {
251 | HighlightOptions options = highLight.getOptions();
252 | if (options != null) {
253 | if (options.relativeGuide != null) {
254 | relativeGuides.add(options.relativeGuide);
255 | }
256 | }
257 | }
258 | return relativeGuides;
259 | }
260 | }
261 |
--------------------------------------------------------------------------------
/guide/src/main/java/com/app/hubert/guide/model/HighLight.java:
--------------------------------------------------------------------------------
1 | package com.app.hubert.guide.model;
2 |
3 | import android.graphics.RectF;
4 | import android.support.annotation.Nullable;
5 | import android.view.View;
6 |
7 | /**
8 | * Created by hubert on 2018/6/6.
9 | */
10 | public interface HighLight {
11 |
12 | Shape getShape();
13 |
14 | /**
15 | * @param view anchor view
16 | * @return highlight's rectF
17 | */
18 | RectF getRectF(View view);
19 |
20 | /**
21 | * 当shape为CIRCLE时调用此方法获取半径
22 | */
23 | float getRadius();
24 |
25 | /**
26 | * 获取圆角,仅当shape = Shape.ROUND_RECTANGLE才调用次方法
27 | */
28 | int getRound();
29 |
30 | /**
31 | * 额外参数
32 | */
33 | @Nullable
34 | HighlightOptions getOptions();
35 |
36 | public enum Shape {
37 | CIRCLE,//圆形
38 | RECTANGLE, //矩形
39 | OVAL,//椭圆
40 | ROUND_RECTANGLE;//圆角矩形
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/guide/src/main/java/com/app/hubert/guide/model/HighlightOptions.java:
--------------------------------------------------------------------------------
1 | package com.app.hubert.guide.model;
2 |
3 | import android.view.View;
4 |
5 | import com.app.hubert.guide.listener.OnHighlightDrewListener;
6 |
7 | /**
8 | * Created by hubert on 2018/7/9.
9 | */
10 | public class HighlightOptions {
11 | public View.OnClickListener onClickListener;
12 | public RelativeGuide relativeGuide;
13 | public OnHighlightDrewListener onHighlightDrewListener;
14 | public boolean fetchLocationEveryTime;
15 |
16 | public static class Builder {
17 |
18 | private HighlightOptions options;
19 |
20 | public Builder() {
21 | options = new HighlightOptions();
22 | }
23 |
24 | /**
25 | * 高亮点击事件
26 | */
27 | public Builder setOnClickListener(View.OnClickListener listener) {
28 | options.onClickListener = listener;
29 | return this;
30 | }
31 |
32 | /**
33 | * @param relativeGuide 高亮相对位置引导布局
34 | */
35 | public Builder setRelativeGuide(RelativeGuide relativeGuide) {
36 | options.relativeGuide = relativeGuide;
37 | return this;
38 | }
39 |
40 | /**
41 | * @param listener 高亮绘制后回调该监听,用于绘制额外内容
42 | */
43 | public Builder setOnHighlightDrewListener(OnHighlightDrewListener listener) {
44 | options.onHighlightDrewListener = listener;
45 | return this;
46 | }
47 |
48 | /**
49 | * 是否每次显示引导层都重新获取高亮位置
50 | */
51 | public Builder isFetchLocationEveryTime(boolean b) {
52 | options.fetchLocationEveryTime = b;
53 | return this;
54 | }
55 |
56 | public HighlightOptions build() {
57 | return options;
58 | }
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/guide/src/main/java/com/app/hubert/guide/model/HighlightRectF.java:
--------------------------------------------------------------------------------
1 | package com.app.hubert.guide.model;
2 |
3 | import android.graphics.RectF;
4 | import android.support.annotation.NonNull;
5 | import android.support.annotation.Nullable;
6 | import android.view.View;
7 |
8 | /**
9 | * Created by hubert on 2018/6/6.
10 | */
11 | public class HighlightRectF implements HighLight {
12 |
13 | private RectF rectF;
14 | private Shape shape;
15 | private int round;
16 | private HighlightOptions options;
17 |
18 | public HighlightRectF(@NonNull RectF rectF, @NonNull Shape shape, int round) {
19 | this.rectF = rectF;
20 | this.shape = shape;
21 | this.round = round;
22 | }
23 |
24 | public void setOptions(HighlightOptions options) {
25 | this.options = options;
26 | }
27 |
28 | @Override
29 | public Shape getShape() {
30 | return shape;
31 | }
32 |
33 | @Override
34 | public RectF getRectF(View view) {
35 | return rectF;
36 | }
37 |
38 | @Override
39 | public float getRadius() {
40 | return Math.min(rectF.width() / 2, rectF.height() / 2);
41 | }
42 |
43 | @Override
44 | public int getRound() {
45 | return round;
46 | }
47 |
48 | @Override
49 | public HighlightOptions getOptions() {
50 | return options;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/guide/src/main/java/com/app/hubert/guide/model/HighlightView.java:
--------------------------------------------------------------------------------
1 | package com.app.hubert.guide.model;
2 |
3 | import android.graphics.Rect;
4 | import android.graphics.RectF;
5 | import android.view.View;
6 |
7 | import com.app.hubert.guide.util.LogUtil;
8 | import com.app.hubert.guide.util.ViewUtils;
9 |
10 | /**
11 | * Created by hubert
12 | *
13 | * Created on 2017/7/27.
14 | */
15 | public class HighlightView implements HighLight {
16 |
17 | private View mHole;
18 | private Shape shape;
19 | private int round;
20 | /**
21 | * 高亮相对view的padding
22 | */
23 | private int padding;
24 | private HighlightOptions options;
25 | private RectF rectF;
26 |
27 | public HighlightView(View mHole, Shape shape, int round, int padding) {
28 | this.mHole = mHole;
29 | this.shape = shape;
30 | this.round = round;
31 | this.padding = padding;
32 | }
33 |
34 | public void setOptions(HighlightOptions options) {
35 | this.options = options;
36 | }
37 |
38 | @Override
39 | public Shape getShape() {
40 | return shape;
41 | }
42 |
43 | @Override
44 | public int getRound() {
45 | return round;
46 | }
47 |
48 | @Override
49 | public HighlightOptions getOptions() {
50 | return options;
51 | }
52 |
53 | @Override
54 | public float getRadius() {
55 | if (mHole == null) {
56 | throw new IllegalArgumentException("the highlight view is null!");
57 | }
58 | return Math.max(mHole.getWidth() / 2, mHole.getHeight() / 2) + padding;
59 | }
60 |
61 | @Override
62 | public RectF getRectF(View target) {
63 | if (mHole == null) {
64 | throw new IllegalArgumentException("the highlight view is null!");
65 | }
66 | if (rectF == null) {
67 | rectF = fetchLocation(target);
68 | } else if (options != null && options.fetchLocationEveryTime) {
69 | rectF = fetchLocation(target);
70 | }
71 | LogUtil.i(mHole.getClass().getSimpleName() + "'s location:" + rectF);
72 | return rectF;
73 | }
74 |
75 | private RectF fetchLocation(View target) {
76 | RectF location = new RectF();
77 | Rect locationInView = ViewUtils.getLocationInView(target, mHole);
78 | location.left = locationInView.left - padding;
79 | location.top = locationInView.top - padding;
80 | location.right = locationInView.right + padding;
81 | location.bottom = locationInView.bottom + padding;
82 | return location;
83 | }
84 |
85 | }
--------------------------------------------------------------------------------
/guide/src/main/java/com/app/hubert/guide/model/RelativeGuide.java:
--------------------------------------------------------------------------------
1 | package com.app.hubert.guide.model;
2 |
3 | import android.graphics.RectF;
4 | import android.support.annotation.IntDef;
5 | import android.support.annotation.LayoutRes;
6 | import android.view.Gravity;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.FrameLayout;
11 |
12 | import com.app.hubert.guide.core.Controller;
13 | import com.app.hubert.guide.util.LogUtil;
14 |
15 | import java.lang.annotation.Retention;
16 | import java.lang.annotation.RetentionPolicy;
17 |
18 | /**
19 | * Created by hubert on 2018/6/28.
20 | */
21 | public class RelativeGuide {
22 |
23 | @IntDef({android.view.Gravity.LEFT, android.view.Gravity.TOP,
24 | android.view.Gravity.RIGHT, android.view.Gravity.BOTTOM})
25 | @Retention(RetentionPolicy.SOURCE)
26 | @interface LimitGravity {
27 |
28 | }
29 |
30 | public static class MarginInfo {
31 | public int leftMargin;
32 | public int topMargin;
33 | public int rightMargin;
34 | public int bottomMargin;
35 | public int gravity;
36 |
37 | @Override
38 | public String toString() {
39 | return "MarginInfo{" +
40 | "leftMargin=" + leftMargin +
41 | ", topMargin=" + topMargin +
42 | ", rightMargin=" + rightMargin +
43 | ", bottomMargin=" + bottomMargin +
44 | ", gravity=" + gravity +
45 | '}';
46 | }
47 | }
48 |
49 | public HighLight highLight;
50 | @LayoutRes
51 | public int layout;
52 | public int padding;
53 | public int gravity;
54 |
55 | public RelativeGuide(@LayoutRes int layout, @LimitGravity int gravity) {
56 | this.layout = layout;
57 | this.gravity = gravity;
58 | }
59 |
60 | /**
61 | * @param layout 相对位置引导布局
62 | * @param gravity 仅限left top right bottom
63 | * @param padding 与高亮view的padding,单位px
64 | */
65 | public RelativeGuide(@LayoutRes int layout, @LimitGravity int gravity, int padding) {
66 | this.layout = layout;
67 | this.gravity = gravity;
68 | this.padding = padding;
69 | }
70 |
71 | public final View getGuideLayout(ViewGroup viewGroup, Controller controller) {
72 | View view = LayoutInflater.from(viewGroup.getContext()).inflate(layout, viewGroup, false);
73 | onLayoutInflated(view);
74 | onLayoutInflated(view, controller);
75 | FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) view.getLayoutParams();
76 | MarginInfo marginInfo = getMarginInfo(gravity, viewGroup, view);
77 | LogUtil.e(marginInfo.toString());
78 | offsetMargin(marginInfo, viewGroup, view);
79 | layoutParams.gravity = marginInfo.gravity;
80 | layoutParams.leftMargin += marginInfo.leftMargin;
81 | layoutParams.topMargin += marginInfo.topMargin;
82 | layoutParams.rightMargin += marginInfo.rightMargin;
83 | layoutParams.bottomMargin += marginInfo.bottomMargin;
84 | view.setLayoutParams(layoutParams);
85 | return view;
86 | }
87 |
88 | private MarginInfo getMarginInfo(@LimitGravity int gravity, ViewGroup viewGroup, View view) {
89 | MarginInfo marginInfo = new MarginInfo();
90 | RectF rectF = highLight.getRectF(viewGroup);
91 | switch (gravity) {
92 | case Gravity.LEFT:
93 | marginInfo.gravity = Gravity.RIGHT;
94 | marginInfo.rightMargin = (int) (viewGroup.getWidth() - rectF.left + padding);
95 | marginInfo.topMargin = (int) rectF.top;
96 | break;
97 | case Gravity.TOP:
98 | marginInfo.gravity = Gravity.BOTTOM;
99 | marginInfo.bottomMargin = (int) (viewGroup.getHeight() - rectF.top + padding);
100 | marginInfo.leftMargin = (int) rectF.left;
101 | break;
102 | case Gravity.RIGHT:
103 | marginInfo.leftMargin = (int) (rectF.right + padding);
104 | marginInfo.topMargin = (int) rectF.top;
105 | break;
106 | case Gravity.BOTTOM:
107 | marginInfo.topMargin = (int) (rectF.bottom + padding);
108 | marginInfo.leftMargin = (int) rectF.left;
109 | break;
110 | }
111 | return marginInfo;
112 | }
113 |
114 | protected void offsetMargin(MarginInfo marginInfo, ViewGroup viewGroup, View view) {
115 | //do nothing
116 | }
117 |
118 | /**
119 | * 复写初始化布局
120 | *
121 | * @param view inflated from layout
122 | * @see RelativeGuide#onLayoutInflated(View view, Controller controller)
123 | */
124 | @Deprecated
125 | protected void onLayoutInflated(View view) {
126 | //do nothing
127 | }
128 |
129 | /**
130 | * 复写初始化布局
131 | *
132 | * @param view inflated from layout
133 | * @param controller controller
134 | */
135 | protected void onLayoutInflated(View view, Controller controller) {
136 | //do nothing
137 | }
138 | }
139 |
--------------------------------------------------------------------------------
/guide/src/main/java/com/app/hubert/guide/util/LogUtil.java:
--------------------------------------------------------------------------------
1 | package com.app.hubert.guide.util;
2 |
3 | import android.text.TextUtils;
4 | import android.util.Log;
5 |
6 | import com.app.hubert.guide.NewbieGuide;
7 |
8 | import java.util.Locale;
9 |
10 | /**
11 | * 简易控制日志输出的util
12 | */
13 | public class LogUtil {
14 |
15 | private static final int NONE = 8;
16 | private static final String tagPrefix = NewbieGuide.TAG;
17 |
18 |
19 | /**
20 | * 修改打印级别
21 | */
22 | public static final int level = NONE;
23 | // public static final int level = Log.VERBOSE;
24 |
25 | /**
26 | * 得到tag(所在类.方法(L:行))
27 | */
28 | private static String generateTag() {
29 | StackTraceElement stackTraceElement = Thread.currentThread().getStackTrace()[4];
30 | String callerClazzName = stackTraceElement.getClassName();
31 | callerClazzName = callerClazzName.substring(callerClazzName.lastIndexOf(".") + 1);
32 | String tag = "%s.%s(L:%d)";
33 | tag = String.format(Locale.CHINA, tag, callerClazzName, stackTraceElement.getMethodName(), stackTraceElement.getLineNumber());
34 | //给tag设置前缀
35 | tag = TextUtils.isEmpty(tagPrefix) ? tag : tagPrefix + ":" + tag;
36 | return tag;
37 | }
38 |
39 | public static void v(String msg) {
40 | if (level <= Log.VERBOSE) {
41 | String tag = generateTag();
42 | Log.v(tag, msg);
43 | }
44 | }
45 |
46 | public static void v(String msg, Throwable tr) {
47 | if (level <= Log.VERBOSE) {
48 | String tag = generateTag();
49 | Log.v(tag, msg, tr);
50 | }
51 | }
52 |
53 | public static void d(String msg) {
54 | if (level <= Log.DEBUG) {
55 | String tag = generateTag();
56 | Log.d(tag, msg);
57 | }
58 | }
59 |
60 | public static void d(String msg, Throwable tr) {
61 | if (level <= Log.DEBUG) {
62 | String tag = generateTag();
63 | Log.d(tag, msg, tr);
64 | }
65 | }
66 |
67 | public static void i(String msg) {
68 | if (level <= Log.INFO) {
69 | String tag = generateTag();
70 | Log.i(tag, msg);
71 | }
72 | }
73 |
74 | public static void i(String msg, Throwable tr) {
75 | if (level <= Log.INFO) {
76 | String tag = generateTag();
77 | Log.i(tag, msg, tr);
78 | }
79 | }
80 |
81 | public static void w(String msg) {
82 | if (level <= Log.WARN) {
83 | String tag = generateTag();
84 | Log.w(tag, msg);
85 | }
86 | }
87 |
88 | public static void w(String msg, Throwable tr) {
89 | if (level <= Log.WARN) {
90 | String tag = generateTag();
91 | Log.w(tag, msg, tr);
92 | }
93 | }
94 |
95 | public static void e(String msg) {
96 | if (level <= Log.ERROR) {
97 | String tag = generateTag();
98 | Log.e(tag, msg);
99 | }
100 | }
101 |
102 | public static void e(String msg, Throwable tr) {
103 | if (level <= Log.ERROR) {
104 | String tag = generateTag();
105 | Log.e(tag, msg, tr);
106 | }
107 | }
108 | }
--------------------------------------------------------------------------------
/guide/src/main/java/com/app/hubert/guide/util/ScreenUtils.java:
--------------------------------------------------------------------------------
1 | package com.app.hubert.guide.util;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.content.res.Resources;
6 | import android.graphics.Point;
7 | import android.os.Build;
8 | import android.util.DisplayMetrics;
9 | import android.view.Display;
10 | import android.view.KeyCharacterMap;
11 | import android.view.KeyEvent;
12 | import android.view.ViewConfiguration;
13 |
14 | /**
15 | * Created by hubert
16 | *
17 | * Created on 2017/7/27.
18 | */
19 | public class ScreenUtils {
20 |
21 | private ScreenUtils() {
22 | throw new AssertionError();
23 | }
24 |
25 | /**
26 | * dp单位转成px
27 | *
28 | * @param context context
29 | * @param dp dp值
30 | * @return px值
31 | */
32 | public static int dp2px(Context context, int dp) {
33 | return (int) (dp * context.getResources().getDisplayMetrics().density);
34 | }
35 |
36 | /**
37 | * 获取屏幕宽度
38 | */
39 | public static int getScreenWidth(Context context) {
40 | DisplayMetrics dm = context.getResources().getDisplayMetrics();
41 | return dm.widthPixels;
42 | }
43 |
44 | /**
45 | * 获取屏幕高度
46 | */
47 | public static int getScreenHeight(Context context) {
48 | DisplayMetrics dm = context.getResources().getDisplayMetrics();
49 | return dm.heightPixels;
50 | }
51 |
52 | /**
53 | * 获取状态栏高度
54 | */
55 | public static int getStatusBarHeight(Context context) {
56 | // 一般是25dp
57 | int height = dp2px(context, 20);
58 | LogUtil.i("common statusBar height:" + height);
59 | //获取status_bar_height资源的ID
60 | int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
61 | if (resourceId > 0) {
62 | height = context.getResources().getDimensionPixelSize(resourceId);
63 | LogUtil.i("real statusBar height:" + height);
64 | }
65 | LogUtil.i("finally statusBar height:" + height);
66 | return height;
67 | }
68 |
69 | /**
70 | * 虚拟操作拦(home等)是否显示
71 | */
72 | public static boolean isNavigationBarShow(Activity activity) {
73 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
74 | Display display = activity.getWindowManager().getDefaultDisplay();
75 | Point size = new Point();
76 | Point realSize = new Point();
77 | display.getSize(size);
78 | display.getRealSize(realSize);
79 | return realSize.y != size.y;
80 | } else {
81 | boolean menu = ViewConfiguration.get(activity).hasPermanentMenuKey();
82 | boolean back = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
83 | if (menu || back) {
84 | return false;
85 | } else {
86 | return true;
87 | }
88 | }
89 | }
90 |
91 | /**
92 | * 获取虚拟操作拦(home等)高度
93 | */
94 | public static int getNavigationBarHeight(Activity activity) {
95 | if (!isNavigationBarShow(activity))
96 | return 0;
97 | int height = 0;
98 | Resources resources = activity.getResources();
99 | //获取NavigationBar的高度
100 | int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
101 | if (resourceId > 0)
102 | height = resources.getDimensionPixelSize(resourceId);
103 | LogUtil.i("NavigationBar的高度:" + height);
104 | return height;
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/guide/src/main/java/com/app/hubert/guide/util/ViewUtils.java:
--------------------------------------------------------------------------------
1 | package com.app.hubert.guide.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 | import android.widget.HorizontalScrollView;
9 | import android.widget.ScrollView;
10 |
11 | /**
12 | * Created by zhy on 15/10/8.
13 | */
14 | public class ViewUtils {
15 | private static final String FRAGMENT_CON = "NoSaveStateFrameLayout";
16 |
17 | public static Rect getLocationInView(View parent, View child) {
18 | if (child == null || parent == null) {
19 | throw new IllegalArgumentException("parent and child can not be null .");
20 | }
21 |
22 | View decorView = null;
23 | Context context = child.getContext();
24 | if (context instanceof Activity) {
25 | decorView = ((Activity) context).getWindow().getDecorView();
26 | }
27 |
28 | Rect result = new Rect();
29 | Rect tmpRect = new Rect();
30 |
31 | View tmp = child;
32 |
33 | if (child == parent) {
34 | child.getHitRect(result);
35 | return result;
36 | }
37 | while (tmp != decorView && tmp != parent) {
38 | LogUtil.i("tmp class:" + tmp.getClass().getSimpleName());
39 | tmp.getHitRect(tmpRect);
40 | LogUtil.i("tmp hit Rect:" + tmpRect);
41 | if (!tmp.getClass().equals(FRAGMENT_CON)) {
42 | result.left += tmpRect.left;
43 | result.top += tmpRect.top;
44 | }
45 | tmp = (View) tmp.getParent();
46 | if (tmp == null) {
47 | throw new IllegalArgumentException("the view is not showing in the window!");
48 | }
49 | //fix ScrollView中无法获取正确的位置
50 | if (tmp.getParent() instanceof ScrollView) {
51 | ScrollView scrollView = (ScrollView) tmp.getParent();
52 | int scrollY = scrollView.getScrollY();
53 | LogUtil.i("scrollY:" + scrollY);
54 | result.top -= scrollY;
55 | }
56 | if (tmp.getParent() instanceof HorizontalScrollView) {
57 | HorizontalScrollView horizontalScrollView = (HorizontalScrollView) tmp.getParent();
58 | int scrollX = horizontalScrollView.getScrollX();
59 | LogUtil.i("scrollX:" + scrollX);
60 | result.left -= scrollX;
61 | }
62 |
63 | //added by isanwenyu@163.com fix bug #21 the wrong rect user will received in ViewPager
64 | if (tmp.getParent() != null && (tmp.getParent() instanceof ViewPager)) {
65 | tmp = (View) tmp.getParent();
66 | }
67 | }
68 | result.right = result.left + child.getMeasuredWidth();
69 | result.bottom = result.top + child.getMeasuredHeight();
70 | return result;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/guide/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/screenshoot/anchor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huburt-Hu/NewbieGuide/d22aac4e82603ca6684d87b215ae451f7e6a0622/screenshoot/anchor.png
--------------------------------------------------------------------------------
/screenshoot/change_size.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huburt-Hu/NewbieGuide/d22aac4e82603ca6684d87b215ae451f7e6a0622/screenshoot/change_size.png
--------------------------------------------------------------------------------
/screenshoot/device-2017-08-09-161703.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huburt-Hu/NewbieGuide/d22aac4e82603ca6684d87b215ae451f7e6a0622/screenshoot/device-2017-08-09-161703.png
--------------------------------------------------------------------------------
/screenshoot/device-2017-11-03-151550.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huburt-Hu/NewbieGuide/d22aac4e82603ca6684d87b215ae451f7e6a0622/screenshoot/device-2017-11-03-151550.png
--------------------------------------------------------------------------------
/screenshoot/relative_default_gravity.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huburt-Hu/NewbieGuide/d22aac4e82603ca6684d87b215ae451f7e6a0622/screenshoot/relative_default_gravity.png
--------------------------------------------------------------------------------
/screenshoot/sample.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huburt-Hu/NewbieGuide/d22aac4e82603ca6684d87b215ae451f7e6a0622/screenshoot/sample.png
--------------------------------------------------------------------------------
/screenshoot/shape_dialog.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huburt-Hu/NewbieGuide/d22aac4e82603ca6684d87b215ae451f7e6a0622/screenshoot/shape_dialog.png
--------------------------------------------------------------------------------
/screenshoot/simple_use.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huburt-Hu/NewbieGuide/d22aac4e82603ca6684d87b215ae451f7e6a0622/screenshoot/simple_use.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':guide'
2 |
--------------------------------------------------------------------------------