forked from AlejandroOrozco/cordova-plugin-detect-screenshot
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3fe221
commit c87a2be
Showing
4 changed files
with
107 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,31 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<plugin id="com.lukemiles.screenshot" version="1.0.6" xmlns="http://apache.org/cordova/ns/plugins/1.0"> | ||
<name>cordova-plugin-screenshot</name> <!-- ios --> | ||
<platform name="ios"> | ||
<name>cordova-plugin-screenshot</name> | ||
|
||
<config-file target="config.xml" parent="/*"> | ||
<feature name="screenshot"> | ||
<param name="ios-package" value="screenshot" /> | ||
<param name="onload" value="true" /> | ||
</feature> | ||
</config-file> | ||
<platform name="android"> | ||
<framework src="src/android/plugin.gradle" custom="true" type="gradleReference"/> | ||
<config-file target="res/xml/config.xml" parent="/*"> | ||
<feature name="screenshot"> | ||
<param name="android-package" value="org.android.screenshot.ScreenshotPlugin"/> | ||
<param name="onload" value="true" /> | ||
</feature> | ||
</config-file> | ||
<source-file src="src/android/screenshot.java"/> | ||
|
||
</platform> | ||
|
||
<header-file src="src/ios/screenshot.h" /> | ||
<source-file src="src/ios/screenshot.m" /> | ||
|
||
</platform> | ||
</plugin> | ||
<platform name="ios"> | ||
|
||
<config-file target="config.xml" parent="/*"> | ||
<feature name="screenshot"> | ||
<param name="ios-package" value="screenshot" /> | ||
<param name="onload" value="true" /> | ||
</feature> | ||
</config-file> | ||
|
||
<header-file src="src/ios/screenshot.h" /> | ||
<source-file src="src/ios/screenshot.m" /> | ||
|
||
</platform> | ||
</plugin> |
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,10 @@ | ||
repositories { | ||
maven { | ||
url "http://dl.bintray.com/piasy/maven" | ||
} | ||
} | ||
|
||
dependencies { | ||
compile 'com.github.piasy:rxscreenshotdetector:1.2.0' | ||
compile 'com.trello.rxlifecycle2:rxlifecycle-components:2.0.1' | ||
} |
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,68 @@ | ||
package org.android.screenshot; | ||
|
||
import android.app.Activity; | ||
import android.net.Uri; | ||
import android.os.Bundle; | ||
import com.github.piasy.rxscreenshotdetector.RxScreenshotDetector; | ||
import com.google.android.gms.appindexing.Action; | ||
import com.google.android.gms.appindexing.AppIndex; | ||
import com.google.android.gms.appindexing.Thing; | ||
import com.google.android.gms.common.api.GoogleApiClient; | ||
import com.trello.rxlifecycle2.LifecycleProvider; | ||
import com.trello.rxlifecycle2.LifecycleTransformer; | ||
import com.trello.rxlifecycle2.RxLifecycle; | ||
import com.trello.rxlifecycle2.android.ActivityEvent; | ||
import com.trello.rxlifecycle2.android.RxLifecycleAndroid; | ||
|
||
import io.reactivex.Observable; | ||
import io.reactivex.android.schedulers.AndroidSchedulers; | ||
import io.reactivex.functions.Consumer; | ||
import io.reactivex.schedulers.Schedulers; | ||
import io.reactivex.subjects.BehaviorSubject; | ||
|
||
import android.os.Bundle; | ||
import android.view.Gravity; | ||
import android.widget.Toast; | ||
|
||
import org.apache.cordova.*; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import static android.icu.lang.UCharacter.GraphemeClusterBreak.T; | ||
|
||
public class PrivacyScreenPlugin extends CordovaPlugin implements LifecycleProvider<ActivityEvent> { | ||
|
||
private final BehaviorSubject<ActivityEvent> lifecycleSubject = BehaviorSubject.create(); | ||
|
||
public void initialize(CordovaInterface cordova, CordovaWebView webView) { | ||
super.initialize(cordova, webView); | ||
Activity activity = this.cordova.getActivity(); | ||
RxScreenshotDetector.start(activity).compose(this.<String>bindToLifecycle()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<String>() { | ||
@Override | ||
public void accept(String s) throws Exception { | ||
webView.loadUrl("javascript: alert('Screenshot');"); | ||
} | ||
}); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public Observable<ActivityEvent> lifecycle() { | ||
return lifecycleSubject.hide(); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public <T> LifecycleTransformer<T> bindUntilEvent(@Nonnull ActivityEvent event) { | ||
return RxLifecycle.bindUntilEvent(lifecycleSubject, event); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public <T> LifecycleTransformer<T> bindToLifecycle() { | ||
return RxLifecycleAndroid.bindActivity(lifecycleSubject); | ||
} | ||
|
||
} |