-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix 多次调用show重复显示
- Loading branch information
Showing
8 changed files
with
230 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
app/src/main/java/com/app/hubert/newbieguide/ObservableScrollView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.app.hubert.newbieguide; | ||
|
||
import android.content.Context; | ||
import android.util.AttributeSet; | ||
import android.widget.ScrollView; | ||
|
||
public class ObservableScrollView extends ScrollView { | ||
|
||
private OnScrollChangeListener scrollChangeListener = null; | ||
|
||
public ObservableScrollView(Context context) { | ||
super(context); | ||
} | ||
|
||
public ObservableScrollView(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
} | ||
|
||
public ObservableScrollView(Context context, AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
} | ||
|
||
public void setScrollViewListener(OnScrollChangeListener onScrollChangeListener) { | ||
this.scrollChangeListener = onScrollChangeListener; | ||
} | ||
|
||
@Override | ||
protected void onScrollChanged(int x, int y, int oldx, int oldy) { | ||
super.onScrollChanged(x, y, oldx, oldy); | ||
if (scrollChangeListener != null) { | ||
scrollChangeListener.onScrollChanged(this, x, y, oldx, oldy); | ||
} | ||
} | ||
|
||
public interface OnScrollChangeListener { | ||
void onScrollChanged(ObservableScrollView scrollView, int x, int y, int oldx, int oldy); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
app/src/main/java/com/app/hubert/newbieguide/ScrollViewActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.app.hubert.newbieguide; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.graphics.Rect; | ||
import android.graphics.RectF; | ||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.view.View; | ||
import android.widget.ScrollView; | ||
|
||
import com.app.hubert.guide.NewbieGuide; | ||
import com.app.hubert.guide.core.Controller; | ||
import com.app.hubert.guide.model.GuidePage; | ||
import com.app.hubert.guide.util.LogUtil; | ||
|
||
/** | ||
* Created by hubert on 2018/12/11. | ||
*/ | ||
public class ScrollViewActivity extends AppCompatActivity { | ||
|
||
private Controller controller; | ||
|
||
public static void start(Context context) { | ||
Intent starter = new Intent(context, ScrollViewActivity.class); | ||
context.startActivity(starter); | ||
} | ||
|
||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_scroll_view); | ||
final View light = findViewById(R.id.v_light); | ||
controller = NewbieGuide.with(ScrollViewActivity.this) | ||
.setLabel("scroll1") | ||
.alwaysShow(true) | ||
.addGuidePage(GuidePage.newInstance() | ||
.addHighLight(light)) | ||
.build(); | ||
ObservableScrollView scrollView = findViewById(R.id.scrollView); | ||
scrollView.setScrollViewListener(new ObservableScrollView.OnScrollChangeListener() { | ||
@Override | ||
public void onScrollChanged(ObservableScrollView scrollView, int x, int y, int oldx, int oldy) { | ||
if (scrollView.getScrollY() + scrollView.getHeight() - | ||
scrollView.getPaddingTop() - scrollView.getPaddingBottom() | ||
== scrollView.getChildAt(0).getHeight()) {//判断滑动到底部 | ||
LogUtil.i("call show"); | ||
controller.show(); | ||
} | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<com.app.hubert.newbieguide.ObservableScrollView xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/scrollView" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:orientation="vertical" | ||
android:layout_height="wrap_content"> | ||
|
||
<View | ||
android:layout_width="match_parent" | ||
android:background="@color/colorAccent" | ||
android:layout_height="100dp" /> | ||
|
||
<View | ||
android:layout_width="match_parent" | ||
android:background="@color/colorPrimary" | ||
android:layout_height="100dp" /> | ||
|
||
<View | ||
android:layout_width="match_parent" | ||
android:background="@color/colorPrimaryDark" | ||
android:layout_height="100dp" /> | ||
|
||
<View | ||
android:layout_width="match_parent" | ||
android:background="@color/colorAccent" | ||
android:layout_height="100dp" /> | ||
|
||
<View | ||
android:layout_width="match_parent" | ||
android:background="@color/colorPrimary" | ||
android:layout_height="100dp" /> | ||
|
||
<View | ||
android:layout_width="match_parent" | ||
android:background="@color/colorPrimaryDark" | ||
android:layout_height="100dp" /> | ||
|
||
<View | ||
android:layout_width="match_parent" | ||
android:background="@color/colorAccent" | ||
android:layout_height="100dp" /> | ||
|
||
<View | ||
android:layout_width="match_parent" | ||
android:background="@color/colorPrimary" | ||
android:layout_height="100dp" /> | ||
|
||
<View | ||
android:layout_width="match_parent" | ||
android:background="@color/colorPrimaryDark" | ||
android:layout_height="100dp" /> | ||
|
||
<View | ||
android:layout_width="match_parent" | ||
android:background="@color/colorAccent" | ||
android:layout_height="100dp" /> | ||
|
||
<View | ||
android:layout_width="match_parent" | ||
android:background="@color/colorPrimary" | ||
android:layout_height="100dp" /> | ||
|
||
<View | ||
android:layout_width="match_parent" | ||
android:background="@color/colorPrimaryDark" | ||
android:layout_height="100dp" /> | ||
|
||
<TextView | ||
android:id="@+id/v_light" | ||
android:layout_width="match_parent" | ||
android:text="Highlight View" | ||
android:gravity="center" | ||
android:textSize="20sp" | ||
android:background="@color/testColor" | ||
android:layout_height="100dp" /> | ||
|
||
<View | ||
android:layout_width="match_parent" | ||
android:background="@android:color/black" | ||
android:layout_height="100dp" /> | ||
|
||
<View | ||
android:layout_width="match_parent" | ||
android:background="@android:color/darker_gray" | ||
android:layout_height="100dp" /> | ||
|
||
<View | ||
android:layout_width="match_parent" | ||
android:background="@android:color/holo_purple" | ||
android:layout_height="100dp" /> | ||
</LinearLayout> | ||
</com.app.hubert.newbieguide.ObservableScrollView> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
import android.graphics.Rect; | ||
import android.support.v4.view.ViewPager; | ||
import android.view.View; | ||
import android.widget.HorizontalScrollView; | ||
import android.widget.ScrollView; | ||
|
||
/** | ||
* Created by zhy on 15/10/8. | ||
|
@@ -33,7 +35,9 @@ public static Rect getLocationInView(View parent, View child) { | |
return result; | ||
} | ||
while (tmp != decorView && tmp != parent) { | ||
LogUtil.i("tmp class:" + tmp.getClass().getSimpleName()); | ||
tmp.getHitRect(tmpRect); | ||
LogUtil.i("tmp hit Rect:" + tmpRect); | ||
if (!tmp.getClass().equals(FRAGMENT_CON)) { | ||
result.left += tmpRect.left; | ||
result.top += tmpRect.top; | ||
|
@@ -42,6 +46,19 @@ public static Rect getLocationInView(View parent, View child) { | |
if (tmp == null) { | ||
throw new IllegalArgumentException("the view is not showing in the window!"); | ||
} | ||
//fix ScrollView中无法获取正确的位置 | ||
if (tmp.getParent() instanceof ScrollView) { | ||
ScrollView scrollView = (ScrollView) tmp.getParent(); | ||
int scrollY = scrollView.getScrollY(); | ||
LogUtil.i("scrollY:" + scrollY); | ||
result.top -= scrollY; | ||
} | ||
if (tmp.getParent() instanceof HorizontalScrollView) { | ||
HorizontalScrollView horizontalScrollView = (HorizontalScrollView) tmp.getParent(); | ||
int scrollX = horizontalScrollView.getScrollX(); | ||
LogUtil.i("scrollX:" + scrollX); | ||
result.left -= scrollX; | ||
} | ||
|
||
//added by [email protected] fix bug #21 the wrong rect user will received in ViewPager | ||
if (tmp.getParent() != null && (tmp.getParent() instanceof ViewPager)) { | ||
|