diff --git a/app/build.gradle b/app/build.gradle index 7a39e3d..49ae707 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -16,6 +16,7 @@ android { proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } + namespace 'com.qw.curtain.sample' } dependencies { @@ -23,6 +24,6 @@ dependencies { implementation 'com.google.android.material:material:1.3.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation 'androidx.recyclerview:recyclerview:1.2.0' -// implementation project(':curtain') - implementation 'com.github.soulqw:Curtain:0.2.1' + implementation project(':curtain') +// implementation 'com.github.soulqw:Curtain:0.2.1' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 7d3c1bb..cb71c22 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,7 +1,6 @@ + xmlns:dist="http://schemas.android.com/apk/distribution"> diff --git a/app/src/main/java/com/qw/curtain/sample/SimpleGuideActivity.java b/app/src/main/java/com/qw/curtain/sample/SimpleGuideActivity.java index f8a34a2..9d817cc 100644 --- a/app/src/main/java/com/qw/curtain/sample/SimpleGuideActivity.java +++ b/app/src/main/java/com/qw/curtain/sample/SimpleGuideActivity.java @@ -1,6 +1,7 @@ package com.qw.curtain.sample; import android.os.Bundle; +import android.util.Log; import android.view.View; import android.widget.Toast; @@ -18,6 +19,8 @@ public class SimpleGuideActivity extends AppCompatActivity { + private static String TAG = "SimpleGuideActivity"; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -71,6 +74,8 @@ private void showInitGuide() { // .setNoCurtainAnimation(true) //如果你希望高亮的目标View仍然可以响应touch事件的话(默认true) .setInterceptTargetView(false) + //offset +// .withOffset(findViewById(R.id.btn_shape_circle),20, HollowInfo.HORIZONTAL) //如果你不希望Curtain拦截蒙层之下的事件的话(默认true) // .setInterceptTouchEvent(false) //add onclick listener in the top view @@ -81,6 +86,19 @@ public void onClick(View current, IGuide currentHost) { currentHost.dismissGuide(); } }) + .setCallBack(new Curtain.CallBack() { + @Override + public void onShow(IGuide curtain) { + //get top view when curtain showed + Log.d(TAG, "on guide show: " + curtain.getCurrentTopView() + + "\n and size is" + curtain.getCurrentTopView().getWidth() + " " + curtain.getCurrentTopView().getHeight()); + } + + @Override + public void onDismiss(IGuide iGuide) { + + } + }) .show(); } diff --git a/build.gradle b/build.gradle index f8f002a..7bdaca8 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.4.1' + classpath 'com.android.tools.build:gradle:7.4.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } diff --git a/curtain/build.gradle b/curtain/build.gradle index d9e46f0..eb29d32 100644 --- a/curtain/build.gradle +++ b/curtain/build.gradle @@ -7,8 +7,6 @@ android { defaultConfig { minSdkVersion 14 targetSdkVersion 30 - versionCode 9 - versionName "0.0.9" } buildTypes { @@ -17,6 +15,7 @@ android { proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } + namespace 'com.qw.curtain.lib' } diff --git a/curtain/src/main/AndroidManifest.xml b/curtain/src/main/AndroidManifest.xml index d515b34..94cbbcf 100644 --- a/curtain/src/main/AndroidManifest.xml +++ b/curtain/src/main/AndroidManifest.xml @@ -1,2 +1 @@ - + diff --git a/curtain/src/main/java/com/qw/curtain/lib/GuideDialogFragment.java b/curtain/src/main/java/com/qw/curtain/lib/GuideDialogFragment.java index 1e74c91..40cad1e 100644 --- a/curtain/src/main/java/com/qw/curtain/lib/GuideDialogFragment.java +++ b/curtain/src/main/java/com/qw/curtain/lib/GuideDialogFragment.java @@ -66,6 +66,7 @@ public void show() { show(param.fragmentManager, Constance.CURTAIN_FRAGMENT); } + public void setParam(Curtain.Param param) { this.param = param; } @@ -112,6 +113,17 @@ public void updateTopView(@LayoutRes int layoutId) { updateTopView(); } + @Override + @Nullable + public View getCurrentTopView() { + try { + return contentView.getChildAt(0); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + @Override public T findViewByIdInTopView(int id) { if (null == contentView) { @@ -138,23 +150,19 @@ public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { new NoInterceptViewAlertDialog(requireActivity(), R.style.TransparentDialog, param.hollows); } dialog.setContentView(contentView); + dialog.setOnShowListener(new DialogInterface.OnShowListener() { + @Override + public void onShow(DialogInterface dialogInterface) { + if (null != param.callBack) { + param.callBack.onShow(GuideDialogFragment.this); + } + } + }); setAnimation(dialog); } return dialog; } - @Override - public void onActivityCreated(@Nullable Bundle savedInstanceState) { - try { - super.onActivityCreated(savedInstanceState); - } catch (Exception e) { - return; - } - if (null != param.callBack) { - param.callBack.onShow(this); - } - } - @Override public void onDismiss(@NonNull DialogInterface dialog) { super.onDismiss(dialog); diff --git a/curtain/src/main/java/com/qw/curtain/lib/GuideView.java b/curtain/src/main/java/com/qw/curtain/lib/GuideView.java index 1a396e3..c865440 100644 --- a/curtain/src/main/java/com/qw/curtain/lib/GuideView.java +++ b/curtain/src/main/java/com/qw/curtain/lib/GuideView.java @@ -114,6 +114,24 @@ private void drawSingleHollow(HollowInfo info, Canvas canvas) { //set the padding setTheBoundPadding(info); //set the offset + setHollowOffset(info); + //status bar height + info.targetBound.top -= getStatusBarHeight(getContext()); + info.targetBound.bottom -= getStatusBarHeight(getContext()); + //draw highlight info + realDrawHollows(info, canvas); + mPositionCache.put(info, info); + } + + private void setHollowOffset(HollowInfo info) { + if (info.getOffset((HollowInfo.BOTH)) > 0) { + int offset = info.getOffset(HollowInfo.BOTH); + info.targetBound.left += offset; + info.targetBound.top += offset; + info.targetBound.bottom += offset; + info.targetBound.right += offset; + return; + } if (info.getOffset((HollowInfo.VERTICAL)) > 0) { info.targetBound.top += info.getOffset(HollowInfo.VERTICAL); info.targetBound.bottom += info.getOffset(HollowInfo.VERTICAL); @@ -122,12 +140,6 @@ private void drawSingleHollow(HollowInfo info, Canvas canvas) { info.targetBound.right += info.getOffset(HollowInfo.HORIZONTAL); info.targetBound.left += info.getOffset(HollowInfo.HORIZONTAL); } - //status bar height - info.targetBound.top -= getStatusBarHeight(getContext()); - info.targetBound.bottom -= getStatusBarHeight(getContext()); - //draw highlight info - realDrawHollows(info, canvas); - mPositionCache.put(info, info); } private void setTheBoundPadding(HollowInfo info) { diff --git a/curtain/src/main/java/com/qw/curtain/lib/HollowInfo.java b/curtain/src/main/java/com/qw/curtain/lib/HollowInfo.java index 0f83461..610ddf0 100644 --- a/curtain/src/main/java/com/qw/curtain/lib/HollowInfo.java +++ b/curtain/src/main/java/com/qw/curtain/lib/HollowInfo.java @@ -15,7 +15,7 @@ */ public class HollowInfo { - private static final int SHIFT = 30; + private static final int SHIFT = 29; private static final int MODE_MASK = 0x3 << SHIFT; @@ -23,6 +23,8 @@ public class HollowInfo { public static final int HORIZONTAL = 2 << SHIFT; + public static final int BOTH = 3 << SHIFT; + /** * Whether the hollow,s shape will adjust the shape of the view automatic */ @@ -34,7 +36,7 @@ public class HollowInfo { private int mOffsetMask; @IntDef(flag = true, - value = {VERTICAL, HORIZONTAL}) + value = {VERTICAL, HORIZONTAL, BOTH}) @Retention(RetentionPolicy.SOURCE) public @interface direction { } @@ -66,7 +68,7 @@ public void setAutoAdaptViewBackGround(boolean autoAdaptViewBackGround) { /** * set the highlight shape * - * @param shape highlight shape + * @param shape highlight shape */ public void setShape(Shape shape) { this.shape = shape; diff --git a/curtain/src/main/java/com/qw/curtain/lib/IGuide.java b/curtain/src/main/java/com/qw/curtain/lib/IGuide.java index 52f0706..1bbcafb 100644 --- a/curtain/src/main/java/com/qw/curtain/lib/IGuide.java +++ b/curtain/src/main/java/com/qw/curtain/lib/IGuide.java @@ -24,6 +24,13 @@ public interface IGuide { */ void updateTopView(@LayoutRes int layoutId); + /** + * get current top view + * + * @return current top view + */ + View getCurrentTopView(); + /** * if you want do more operate in top view (onClickListener or onTouchListener) * you can find it by this method diff --git a/curtain/src/main/java/com/qw/curtain/lib/InnerUtils.java b/curtain/src/main/java/com/qw/curtain/lib/InnerUtils.java index 76f13ac..c8693b0 100644 --- a/curtain/src/main/java/com/qw/curtain/lib/InnerUtils.java +++ b/curtain/src/main/java/com/qw/curtain/lib/InnerUtils.java @@ -1,6 +1,8 @@ package com.qw.curtain.lib; import android.content.Context; +import android.graphics.Point; +import android.os.Build; import android.util.DisplayMetrics; import android.view.WindowManager; @@ -12,6 +14,11 @@ class InnerUtils { static int getScreenWidth(Context context) { WindowManager wm = (WindowManager) context .getSystemService(Context.WINDOW_SERVICE); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + Point size = new Point(); + wm.getDefaultDisplay().getRealSize(size); + return size.x; + } DisplayMetrics outMetrics = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(outMetrics); return outMetrics.widthPixels; @@ -23,6 +30,11 @@ static int getScreenWidth(Context context) { static int getScreenHeight(Context context) { WindowManager wm = (WindowManager) context .getSystemService(Context.WINDOW_SERVICE); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + Point size = new Point(); + wm.getDefaultDisplay().getRealSize(size); + return size.y; + } DisplayMetrics outMetrics = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(outMetrics); return outMetrics.heightPixels; diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a776d36..45b4d8d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip