Skip to content

Commit 79be372

Browse files
authored
Merge pull request #127 from gbumps/release/2.0.1
Release/2.0.1
2 parents aaa829b + 5c2f1b4 commit 79be372

7 files changed

Lines changed: 36 additions & 36 deletions

File tree

android/src/main/java/com/screenguard/ScreenGuardObserver.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ public class ScreenGuardObserver extends ContentObserver {
2424
private int mLimitCount = 0;
2525
private int mCurrentCount = 0;
2626
private long mRegistrationTime = 0;
27+
private long mLastChangeTime = 0;
2728
private static final long INITIAL_IGNORE_DURATION_MS = 500;
29+
private static final long DEBOUNCE_DURATION_MS = 1000;
2830

2931
public ScreenGuardObserver(
3032
ReactApplicationContext context,
@@ -64,6 +66,12 @@ public void onChange(boolean selfChange, Uri uri) {
6466
return;
6567
}
6668

69+
long now = System.currentTimeMillis();
70+
if (now - mLastChangeTime < DEBOUNCE_DURATION_MS) {
71+
return;
72+
}
73+
mLastChangeTime = now;
74+
6775
mCurrentCount++;
6876
if (mLimitCount > 0 && mCurrentCount < mLimitCount) {
6977
return;

android/src/main/java/com/screenguard/ScreenGuardOverlay.java

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public enum OverlayType {
4646
private boolean isActivated = false;
4747

4848
private static final int COLOR_TRANS = 0x00000000;
49-
private static final int OVERLAY_VIEW_ID = View.generateViewId();
5049

5150
private ScreenGuardOverlay() {
5251
handler = new Handler(Looper.getMainLooper());
@@ -77,15 +76,22 @@ private ViewGroup getDecorView(Activity activity) {
7776

7877
private void createOverlayView(Activity activity) {
7978
ViewGroup decorView = getDecorView(activity);
80-
View existingOverlay = decorView.findViewById(OVERLAY_VIEW_ID);
81-
if (existingOverlay != null) {
82-
overlayView = (FrameLayout) existingOverlay;
83-
imageView = (ImageView) overlayView.getChildAt(0);
79+
80+
if (overlayView != null && overlayView.getParent() == decorView) {
81+
if (imageView != null && imageView.getParent() == overlayView) {
82+
return;
83+
}
84+
overlayView.removeAllViews();
85+
imageView = createImageView(activity);
86+
overlayView.addView(imageView);
8487
return;
8588
}
8689

90+
if (overlayView != null && overlayView.getParent() != null) {
91+
((ViewGroup) overlayView.getParent()).removeView(overlayView);
92+
}
93+
8794
overlayView = new FrameLayout(activity);
88-
overlayView.setId(OVERLAY_VIEW_ID);
8995

9096
overlayView.setClickable(false);
9197
overlayView.setFocusable(false);
@@ -95,14 +101,7 @@ private void createOverlayView(Activity activity) {
95101
FrameLayout.LayoutParams.MATCH_PARENT,
96102
FrameLayout.LayoutParams.MATCH_PARENT);
97103

98-
imageView = new ImageView(activity);
99-
imageView.setLayoutParams(new FrameLayout.LayoutParams(
100-
FrameLayout.LayoutParams.MATCH_PARENT,
101-
FrameLayout.LayoutParams.MATCH_PARENT));
102-
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
103-
104-
imageView.setClickable(false);
105-
imageView.setFocusable(false);
104+
imageView = createImageView(activity);
106105

107106
overlayView.addView(imageView);
108107
overlayView.setBackgroundColor(COLOR_TRANS);
@@ -111,6 +110,17 @@ private void createOverlayView(Activity activity) {
111110
decorView.addView(overlayView, overlayParams);
112111
}
113112

113+
private ImageView createImageView(Activity activity) {
114+
ImageView iv = new ImageView(activity);
115+
iv.setLayoutParams(new FrameLayout.LayoutParams(
116+
FrameLayout.LayoutParams.MATCH_PARENT,
117+
FrameLayout.LayoutParams.MATCH_PARENT));
118+
iv.setScaleType(ImageView.ScaleType.FIT_CENTER);
119+
iv.setClickable(false);
120+
iv.setFocusable(false);
121+
return iv;
122+
}
123+
114124
public void prepareColor(Activity activity, String hexColor, int timeAfterResume) {
115125
android.util.Log.d("ScreenGuard", "prepareColor called, color=" + hexColor + ", time=" + timeAfterResume);
116126
this.activityRef = new WeakReference<>(activity);

android/src/main/java/com/screenguard/model/ScreenGuardBlurData.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,22 @@ public class ScreenGuardBlurData extends ScreenGuardData implements Parcelable {
1111

1212
public String bitmapPath;
1313

14-
public ScreenGuardBlurData(int radius, String bitmapPath, int timeAfterResume) {
14+
public ScreenGuardBlurData(int radius, String bitmapPath) {
1515
this.action = ScreenGuardActionEnum.blur;
1616
this.radius = radius;
1717
this.bitmapPath = bitmapPath;
18-
this.timeAfterResume = timeAfterResume;
1918
}
2019

2120
protected ScreenGuardBlurData(Parcel in) {
2221
action = ScreenGuardActionEnum.blur;
2322
radius = in.readInt();
2423
bitmapPath = in.readString();
25-
timeAfterResume = in.readInt();
2624
}
2725

2826
@Override
2927
public void writeToParcel(Parcel dest, int flags) {
3028
dest.writeInt(radius);
3129
dest.writeString(bitmapPath);
32-
dest.writeInt(timeAfterResume);
3330
}
3431

3532
@Override
@@ -65,11 +62,4 @@ public void setBitmapPath(String bitmapPath) {
6562
this.bitmapPath = bitmapPath;
6663
}
6764

68-
public int getTimeAfterSync() {
69-
return timeAfterResume;
70-
}
71-
72-
public void setTimeAfterSync(int timeAfterSync) {
73-
this.timeAfterResume = timeAfterResume;
74-
}
7565
}

android/src/main/java/com/screenguard/model/ScreenGuardColorData.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@
99

1010
public class ScreenGuardColorData extends ScreenGuardData implements Parcelable {
1111

12-
public ScreenGuardColorData(String color, int timeAfterResume) {
12+
public ScreenGuardColorData(String color) {
1313
this.backgroundColor = color;
14-
this.timeAfterResume = timeAfterResume;
1514
this.action = ScreenGuardActionEnum.color;
1615
}
1716

1817
protected ScreenGuardColorData(Parcel in) {
1918
backgroundColor = in.readString();
20-
timeAfterResume = in.readInt();
2119
action = ScreenGuardActionEnum.color;
2220
}
2321

@@ -41,6 +39,5 @@ public int describeContents() {
4139
@Override
4240
public void writeToParcel(@NonNull Parcel parcel, int i) {
4341
parcel.writeString(backgroundColor);
44-
parcel.writeInt(timeAfterResume);
4542
}
4643
}

android/src/main/java/com/screenguard/model/ScreenGuardData.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
abstract class ScreenGuardData {
66
public String backgroundColor;
7-
public int timeAfterResume;
87
public ScreenGuardActionEnum action;
98
}
109

android/src/main/java/com/screenguard/model/ScreenGuardImageData.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,13 @@ public ScreenGuardImageData(
2525
String imageUrl,
2626
double width,
2727
double height,
28-
int alignmentIndex,
29-
int timeAfterResume
28+
int alignmentIndex
3029
) {
3130
this.width = width;
3231
this.height = height;
3332
this.backgroundColor = backgroundColor;
3433
this.imageUrl = imageUrl;
3534
this.position = ScreenGuardImagePosition.getEnumFromNumber(alignmentIndex);
36-
this.timeAfterResume = timeAfterResume;
3735
this.action = ScreenGuardActionEnum.image;
3836
}
3937

@@ -43,7 +41,6 @@ protected ScreenGuardImageData(Parcel in) {
4341
backgroundColor = in.readString();
4442
imageUrl = in.readString();
4543
position = ScreenGuardImagePosition.getEnumFromNumber(in.readInt());
46-
timeAfterResume = in.readInt();
4744
action = ScreenGuardActionEnum.image;
4845
}
4946

@@ -78,6 +75,5 @@ public void writeToParcel(@NonNull Parcel parcel, int i) {
7875
parcel.writeString(backgroundColor);
7976
parcel.writeString(imageUrl);
8077
parcel.writeInt(pos);
81-
parcel.writeInt(timeAfterResume);
8278
}
8379
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-screenguard",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"description": "A Native screenshot blocking library for React-Native developer, with background customizable after captured. Screenshot detector are also supported.",
55
"main": "lib/commonjs/index.js",
66
"module": "lib/module/index.js",

0 commit comments

Comments
 (0)