Skip to content

Commit

Permalink
Test Android Implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroOrozco committed Feb 23, 2017
1 parent f3fe221 commit c87a2be
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 13 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
"cordova": {
"id": "com.lukemiles.screenshot",
"platforms": [
"android",
"ios"
]
},
"repository": {
"type": "git",
"url": "https://github.com/restocks/cordova-plugin-detect-screenshot"
"url": "https://github.com/AlejandroOrozco/cordova-plugin-detect-screenshot"
},
"keywords": [
"cordova",
"ecosystem:cordova",
"cordova-android",
"cordova-ios"
],
"author": "Restocks",
Expand Down
38 changes: 26 additions & 12 deletions plugin.xml
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>
10 changes: 10 additions & 0 deletions src/android/plugin.gradle
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'
}
68 changes: 68 additions & 0 deletions src/android/screenshot.java
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);
}

}

0 comments on commit c87a2be

Please sign in to comment.