-
Notifications
You must be signed in to change notification settings - Fork 586
Expand file tree
/
Copy pathMainActivity.java
More file actions
359 lines (329 loc) · 17 KB
/
MainActivity.java
File metadata and controls
359 lines (329 loc) · 17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
package com.zhy.highlight;
import android.graphics.Bitmap;
import android.graphics.BlurMaskFilter;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import zhy.com.highlight.HighLight;
import zhy.com.highlight.interfaces.HighLightInterface;
import zhy.com.highlight.position.OnBottomPosCallback;
import zhy.com.highlight.position.OnLeftPosCallback;
import zhy.com.highlight.position.OnRightPosCallback;
import zhy.com.highlight.position.OnTopPosCallback;
import zhy.com.highlight.shape.BaseLightShape;
import zhy.com.highlight.shape.CircleLightShape;
import zhy.com.highlight.shape.OvalLightShape;
import zhy.com.highlight.shape.RectLightShape;
import zhy.com.highlight.view.HightLightView;
public class MainActivity extends AppCompatActivity {
private HighLight mHightLight;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// findViewById(R.id.id_btn_amazing).post(
// new Runnable()
// {
// @Override
// public void run()
// {
// showTipMask();
// }
// }
//
// );
showNextTipViewOnCreated();
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
//界面初始化后直接显示高亮布局
// if(hasFocus) mHightLight.show();
}
public void showTipView(View view) {
mHightLight = new HighLight(MainActivity.this)//
.anchor(findViewById(R.id.id_container))//如果是Activity上增加引导层,不需要设置anchor
.addHighLight(R.id.btn_rightLight, R.layout.info_gravity_left_down, new OnLeftPosCallback(45), new RectLightShape())
.addHighLight(R.id.btn_light, R.layout.info_gravity_left_down, new OnRightPosCallback(5), new CircleLightShape())
.addHighLight(R.id.btn_bottomLight, R.layout.info_gravity_left_down, new OnTopPosCallback(), new CircleLightShape())
.addHighLight(view, R.layout.info_gravity_left_down, new OnBottomPosCallback(60), new CircleLightShape());
mHightLight.show();
}
/**
* 当界面布局完成显示next模式提示布局
* 显示方法必须在onLayouted中调用
* 适用于Activity及Fragment中使用
* 可以直接在onCreated方法中调用
*
* @author isanwenyu@163.com
*/
public void showNextTipViewOnCreated() {
mHightLight = new HighLight(MainActivity.this)//
.anchor(findViewById(R.id.id_container))//如果是Activity上增加引导层,不需要设置anchor
.autoRemove(false)
.enableNext()
.setOnLayoutCallback(new HighLightInterface.OnLayoutCallback() {
@Override
public void onLayouted() {
//界面布局完成添加tipview
mHightLight.addHighLight(R.id.btn_rightLight, R.layout.info_gravity_left_down, new OnLeftPosCallback(45), new RectLightShape())
.addHighLight(R.id.btn_light, R.layout.info_gravity_left_down, new OnRightPosCallback(5), new CircleLightShape())
.addHighLight(R.id.btn_bottomLight, R.layout.info_gravity_left_down, new OnTopPosCallback(), new CircleLightShape());
//然后显示高亮布局
mHightLight.show();
}
})
.setClickCallback(new HighLight.OnClickCallback() {
@Override
public void onClick() {
Toast.makeText(MainActivity.this, "clicked and show next tip view by yourself", Toast.LENGTH_SHORT).show();
mHightLight.next();
}
});
}
/**
* 显示next模式提示布局
*
* @param view
* @author isanwenyu@163.com
*/
public void showNextTipView(View view) {
mHightLight = new HighLight(MainActivity.this)//
.anchor(findViewById(R.id.id_container))//如果是Activity上增加引导层,不需要设置anchor
.addHighLight(R.id.btn_rightLight, R.layout.info_gravity_left_down, new OnLeftPosCallback(45), new RectLightShape())
.addHighLight(R.id.btn_light, R.layout.info_gravity_left_down, new OnRightPosCallback(5), new CircleLightShape())
.addHighLight(R.id.btn_bottomLight, R.layout.info_gravity_left_down, new OnTopPosCallback(), new CircleLightShape())
.addHighLight(view, R.layout.info_gravity_left_down, new OnBottomPosCallback(60), new CircleLightShape())
.autoRemove(false)
.enableNext()
.setClickCallback(new HighLight.OnClickCallback() {
@Override
public void onClick() {
Toast.makeText(MainActivity.this, "clicked and show next tip view by yourself", Toast.LENGTH_SHORT).show();
mHightLight.next();
}
});
mHightLight.show();
}
/**
* 显示我知道了提示高亮布局
*
* @param view id为R.id.iv_known的控件
* @author isanwenyu@163.com
*/
public void showKnownTipView(View view) {
mHightLight = new HighLight(MainActivity.this)//
.autoRemove(false)//设置背景点击高亮布局自动移除为false 默认为true
.intercept(false)//设置拦截属性为false 高亮布局不影响后面布局的滑动效果 而且使下方点击回调失效
.setClickCallback(new HighLight.OnClickCallback() {
@Override
public void onClick() {
Toast.makeText(MainActivity.this, "clicked and remove HightLight view by yourself", Toast.LENGTH_SHORT).show();
remove(null);
}
})
.anchor(findViewById(R.id.id_container))//如果是Activity上增加引导层,不需要设置anchor
.addHighLight(R.id.btn_rightLight, R.layout.info_known, new OnLeftPosCallback(45), new RectLightShape())
.addHighLight(R.id.btn_light, R.layout.info_known, new OnRightPosCallback(5), new CircleLightShape(0, 0, 0))
.addHighLight(R.id.btn_bottomLight, R.layout.info_known, new OnTopPosCallback(), new CircleLightShape())
.addHighLight(view, R.layout.info_known,
new OnBottomPosCallback(10) {
@Override
public void getPosition(float rightMargin, float bottomMargin, RectF rectF, HighLight.MarginInfo marginInfo) {
marginInfo.topMargin = rectF.top;
}
},
new OvalLightShape(5, 5, 20)
);
mHightLight.show();
// //added by isanwenyu@163.com 设置监听器只有最后一个添加到HightLightView的knownView响应了事件
// //优化在布局中声明onClick方法 {@link #clickKnown(view)}响应所有R.id.iv_known的控件的点击事件
// View decorLayout = mHightLight.getHightLightView();
// ImageView knownView = (ImageView) decorLayout.findViewById(R.id.iv_known);
// knownView.setOnClickListener(new View.OnClickListener()
// {
// @Override
// public void onClick(View view) {
// remove(null);
// }
// });
}
/**
* 显示 next模式 我知道了提示高亮布局
*
* @param view id为R.id.iv_known的控件
* @author isanwenyu@163.com
*/
public void showNextKnownTipView(View view) {
mHightLight = new HighLight(MainActivity.this)//
.autoRemove(false)//设置背景点击高亮布局自动移除为false 默认为true
// .intercept(false)//设置拦截属性为false 高亮布局不影响后面布局的滑动效果
.intercept(true)//拦截属性默认为true 使下方ClickCallback生效
.enableNext()//开启next模式并通过show方法显示 然后通过调用next()方法切换到下一个提示布局,直到移除自身
// .setClickCallback(new HighLight.OnClickCallback() {
// @Override
// public void onClick() {
// Toast.makeText(MainActivity.this, "clicked and remove HightLight view by yourself", Toast.LENGTH_SHORT).show();
// remove(null);
// }
// })
.anchor(findViewById(R.id.id_container))//如果是Activity上增加引导层,不需要设置anchor
.addHighLight(R.id.btn_rightLight, R.layout.info_known, new OnLeftPosCallback(45), new RectLightShape(0, 0, 15, 0, 0))//矩形去除圆角
.addHighLight(R.id.btn_light, R.layout.info_known, new OnRightPosCallback(5), new BaseLightShape(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, getResources().getDisplayMetrics()), TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, getResources().getDisplayMetrics()), 0) {
@Override
protected void resetRectF4Shape(RectF viewPosInfoRectF, float dx, float dy) {
//缩小高亮控件范围
viewPosInfoRectF.inset(dx, dy);
}
@Override
protected void drawShape(Bitmap bitmap, HighLight.ViewPosInfo viewPosInfo) {
//custom your hight light shape 自定义高亮形状
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setDither(true);
paint.setAntiAlias(true);
//blurRadius必须大于0
if (blurRadius > 0) {
paint.setMaskFilter(new BlurMaskFilter(blurRadius, BlurMaskFilter.Blur.SOLID));
}
RectF rectF = viewPosInfo.rectF;
canvas.drawOval(rectF, paint);
}
})
.addHighLight(R.id.btn_bottomLight, R.layout.info_known, new OnTopPosCallback(), new CircleLightShape())
.addHighLight(view, R.layout.info_known, new OnBottomPosCallback(10), new OvalLightShape(5, 5, 20))
.setOnRemoveCallback(new HighLightInterface.OnRemoveCallback() {//监听移除回调
@Override
public void onRemove() {
Toast.makeText(MainActivity.this, "The HightLight view has been removed", Toast.LENGTH_SHORT).show();
}
})
.setOnShowCallback(new HighLightInterface.OnShowCallback() {//监听显示回调
@Override
public void onShow(HightLightView hightLightView) {
Toast.makeText(MainActivity.this, "The HightLight view has been shown", Toast.LENGTH_SHORT).show();
}
}).setOnNextCallback(new HighLightInterface.OnNextCallback() {
@Override
public void onNext(HightLightView hightLightView, View targetView, View tipView) {
// targetView 目标按钮 tipView添加的提示布局 可以直接找到'我知道了'按钮添加监听事件等处理
Toast.makeText(MainActivity.this, "The HightLight show next TipView,targetViewID:" + (targetView == null ? null : targetView.getId()) + ",tipViewID:" + (tipView == null ? null : tipView.getId()), Toast.LENGTH_SHORT).show();
}
});
mHightLight.show();
}
/**
* 响应所有R.id.iv_known的控件的点击事件
* <p>
* 移除高亮布局
* </p>
*
* @param view
*/
public void clickKnown(View view) {
if (mHightLight.isShowing() && mHightLight.isNext())//如果开启next模式
{
mHightLight.next();
} else {
remove(null);
}
}
private void showTipMask() {
// mHightLight = new HighLight(MainActivity.this)//
// .anchor(findViewById(R.id.id_container))
//如果是Activity上增加引导层,不需要设置anchor
// .addHighLight(R.id.id_btn_important, R.layout.info_up,
// new HighLight.OnPosCallback()
// {
// @Override
// public void getPos(float rightMargin, float bottomMargin, RectF rectF, HighLight.MarginInfo marginInfo)
// {
// marginInfo.leftMargin = rectF.right - rectF.width() / 2;
// marginInfo.topMargin = rectF.bottom;
// }
// })//
// .addHighLight(R.id.id_btn_amazing, R.layout.info_down, new HighLight.OnPosCallback()
// {
// /**
// * @param rightMargin 高亮view在anchor中的右边距
// * @param bottomMargin 高亮view在anchor中的下边距
// * @param rectF 高亮view的l,t,r,b,w,h都有
// * @param marginInfo 设置你的布局的位置,一般设置l,t或者r,b
// */
// @Override
// public void getPos(float rightMargin, float bottomMargin, RectF rectF, HighLight.MarginInfo marginInfo)
// {
// marginInfo.rightMargin = rightMargin + rectF.width() / 2;
// marginInfo.bottomMargin = bottomMargin + rectF.height();
// }
//
// });
// .addHighLight(R.id.id_btn_important_right,R.layout.info_gravity_right_up, new HighLight.OnPosCallback(){
//
//
// @Override
// public void getPos(float rightMargin, float bottomMargin, RectF rectF, HighLight.MarginInfo marginInfo) {
// marginInfo.rightMargin = rightMargin;
// marginInfo.topMargin = rectF.top + rectF.height();
// }
// })
// .addHighLight(R.id.id_btn_whoami, R.layout.info_gravity_left_down, new HighLight.OnPosCallback() {
//
//
// @Override
// public void getPos(float rightMargin, float bottomMargin, RectF rectF, HighLight.MarginInfo marginInfo) {
// marginInfo.leftMargin = rectF.right - rectF.width()/2;
// marginInfo.bottomMargin = bottomMargin + rectF.height();
// }
// })
// .setClickCallback(new HighLight.OnClickCallback() {
// @Override
// public void onClick() {
// Toast.makeText(MainActivity.this,"clicked",Toast.LENGTH_SHORT).show();
// }
// });
// mHightLight.show();
// mHightLight = new HighLight(MainActivity.this)//
// .anchor(findViewById(R.id.id_container))//如果是Activity上增加引导层,不需要设置anchor
// .addHighLight(R.id.btn_rightLight,R.layout.info_left, new OnLeftPosCallback(10),new RectLightShape())
// .addHighLight(R.id.btn_light,R.layout.info_right,new OnRightPosCallback(),new CircleLightShape())
// .addHighLight(R.id.btn_bottomLight,R.layout.info_up,new OnTopPosCallback(46),new CircleLightShape())
// .addHighLight(R.id.id_btn_amazing,R.layout.info_up,new OnBottomPosCallback(46),new CircleLightShape());
// mHightLight.show();
}
public void remove(View view) {
mHightLight.remove();
}
public void add(View view) {
mHightLight.show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
//test container change
// View container = findViewById(R.id.id_container);
// ViewGroup.LayoutParams lp =
// container.getLayoutParams();
// lp.height = container.getMeasuredHeight() + 100;
// findViewById(R.id.id_container).setLayoutParams(lp);
}
return super.onOptionsItemSelected(item);
}
}