Skip to content

Commit

Permalink
[ADD]get content view support ,offset all support agp upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
soulqw committed Jul 23, 2023
1 parent 2b93999 commit 0ebc31e
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 31 deletions.
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
namespace 'com.qw.curtain.sample'
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
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'
}
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:dist="http://schemas.android.com/apk/distribution"
package="com.qw.curtain.sample">
xmlns:dist="http://schemas.android.com/apk/distribution">

<dist:module dist:instant="true" />

Expand Down
18 changes: 18 additions & 0 deletions app/src/main/java/com/qw/curtain/sample/SimpleGuideActivity.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -18,6 +19,8 @@

public class SimpleGuideActivity extends AppCompatActivity {

private static String TAG = "SimpleGuideActivity";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -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
Expand All @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions curtain/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 30
versionCode 9
versionName "0.0.9"
}

buildTypes {
Expand All @@ -17,6 +15,7 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
namespace 'com.qw.curtain.lib'

}

Expand Down
3 changes: 1 addition & 2 deletions curtain/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
<manifest package="com.qw.curtain.lib"
xmlns:android="http://schemas.android.com/apk/res/android" />
<manifest xmlns:android="http://schemas.android.com/apk/res/android" />
32 changes: 20 additions & 12 deletions curtain/src/main/java/com/qw/curtain/lib/GuideDialogFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public void show() {
show(param.fragmentManager, Constance.CURTAIN_FRAGMENT);
}


public void setParam(Curtain.Param param) {
this.param = param;
}
Expand Down Expand Up @@ -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 extends View> T findViewByIdInTopView(int id) {
if (null == contentView) {
Expand All @@ -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);
Expand Down
24 changes: 18 additions & 6 deletions curtain/src/main/java/com/qw/curtain/lib/GuideView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
8 changes: 5 additions & 3 deletions curtain/src/main/java/com/qw/curtain/lib/HollowInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
*/
public class HollowInfo {

private static final int SHIFT = 30;
private static final int SHIFT = 29;

private static final int MODE_MASK = 0x3 << SHIFT;

public static final int VERTICAL = 1 << SHIFT;

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
*/
Expand All @@ -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 {
}
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions curtain/src/main/java/com/qw/curtain/lib/IGuide.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions curtain/src/main/java/com/qw/curtain/lib/InnerUtils.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0ebc31e

Please sign in to comment.