Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

marginInfo 未设置时,addHighLight 未添加进去,导致显示时 crash #80

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 9 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "23.0.1"
compileSdkVersion 30

defaultConfig {
applicationId "com.zhy.highlight"
minSdkVersion 11
targetSdkVersion 21
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
}
Expand All @@ -20,10 +19,10 @@ android {
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':highlight')
compile 'com.android.support:appcompat-v7:24.2.0'
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta2'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(':highlight')
implementation 'androidx.appcompat:appcompat:1.3.1'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.4-beta2'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
testImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
}
106 changes: 54 additions & 52 deletions app/src/main/java/com/zhy/highlight/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
import android.graphics.Paint;
import android.graphics.RectF;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
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;
Expand All @@ -25,14 +26,12 @@
import zhy.com.highlight.shape.RectLightShape;
import zhy.com.highlight.view.HightLightView;

public class MainActivity extends AppCompatActivity
{
public class MainActivity extends AppCompatActivity {

private HighLight mHightLight;

@Override
protected void onCreate(Bundle savedInstanceState)
{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Expand All @@ -59,13 +58,13 @@ public void onWindowFocusChanged(boolean hasFocus) {
// if(hasFocus) mHightLight.show();
}

public void showTipView(View view){
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());
.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();
}

Expand All @@ -74,9 +73,10 @@ public void showTipView(View view){
* 显示方法必须在onLayouted中调用
* 适用于Activity及Fragment中使用
* 可以直接在onCreated方法中调用
*
* @author isanwenyu@163.com
*/
public void showNextTipViewOnCreated(){
public void showNextTipViewOnCreated() {
mHightLight = new HighLight(MainActivity.this)//
.anchor(findViewById(R.id.id_container))//如果是Activity上增加引导层,不需要设置anchor
.autoRemove(false)
Expand All @@ -85,9 +85,9 @@ public void showNextTipViewOnCreated(){
@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.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();
}
Expand All @@ -100,18 +100,20 @@ public void onClick() {
}
});
}

/**
* 显示next模式提示布局
*
* @param view
* @author isanwenyu@163.com
*/
public void showNextTipView(View view){
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())
.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() {
Expand All @@ -126,11 +128,11 @@ public void onClick() {

/**
* 显示我知道了提示高亮布局
*
* @param view id为R.id.iv_known的控件
* @author isanwenyu@163.com
*/
public void showKnownTipView(View view)
{
public void showKnownTipView(View view) {
mHightLight = new HighLight(MainActivity.this)//
.autoRemove(false)//设置背景点击高亮布局自动移除为false 默认为true
.intercept(false)//设置拦截属性为false 高亮布局不影响后面布局的滑动效果 而且使下方点击回调失效
Expand All @@ -142,10 +144,18 @@ public void onClick() {
}
})
.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),new OvalLightShape(5,5,20));
.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响应了事件
Expand All @@ -163,11 +173,11 @@ public void onClick() {

/**
* 显示 next模式 我知道了提示高亮布局
*
* @param view id为R.id.iv_known的控件
* @author isanwenyu@163.com
*/
public void showNextKnownTipView(View view)
{
public void showNextKnownTipView(View view) {
mHightLight = new HighLight(MainActivity.this)//
.autoRemove(false)//设置背景点击高亮布局自动移除为false 默认为true
// .intercept(false)//设置拦截属性为false 高亮布局不影响后面布局的滑动效果
Expand All @@ -181,12 +191,12 @@ public void showNextKnownTipView(View view)
// }
// })
.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) {
.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);
viewPosInfoRectF.inset(dx, dy);
}

@Override
Expand All @@ -197,15 +207,15 @@ protected void drawShape(Bitmap bitmap, HighLight.ViewPosInfo viewPosInfo) {
paint.setDither(true);
paint.setAntiAlias(true);
//blurRadius必须大于0
if(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))
.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() {
Expand All @@ -222,7 +232,7 @@ public void onShow(HightLightView hightLightView) {
@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();
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();
Expand All @@ -231,24 +241,21 @@ public void onNext(HightLightView hightLightView, View targetView, View tipView)
/**
* 响应所有R.id.iv_known的控件的点击事件
* <p>
* 移除高亮布局
* 移除高亮布局
* </p>
*
* @param view
*/
public void clickKnown(View view)
{
if(mHightLight.isShowing() && mHightLight.isNext())//如果开启next模式
public void clickKnown(View view) {
if (mHightLight.isShowing() && mHightLight.isNext())//如果开启next模式
{
mHightLight.next();
}else
{
} else {
remove(null);
}
}

private void showTipMask()
{
private void showTipMask() {
// mHightLight = new HighLight(MainActivity.this)//
// .anchor(findViewById(R.id.id_container))
//如果是Activity上增加引导层,不需要设置anchor
Expand Down Expand Up @@ -314,37 +321,32 @@ private void showTipMask()
}


public void remove(View view)
{
public void remove(View view) {
mHightLight.remove();
}

public void add(View view)
{
public void add(View view) {
mHightLight.show();
}


@Override
public boolean onCreateOptionsMenu(Menu menu)
{
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);


return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item)
{
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)
{
if (id == R.id.action_settings) {
//test container change
// View container = findViewById(R.id.id_container);
// ViewGroup.LayoutParams lp =
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
android:id="@+id/btn_show_known_tip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="showKnownTipView"
android:layout_margin="10dp"
android:layout_alignParentLeft="true"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:onClick="showKnownTipView"
android:text="showKnownTip" />
<Button
android:id="@+id/btn_show_next_known_tip"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
</style>

Expand Down
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.android.tools.build:gradle:7.0.3'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'

Expand All @@ -17,6 +18,7 @@ buildscript {
allprojects {
repositories {
jcenter()
google()
mavenCentral()
}
}
Loading