Skip to content

Commit

Permalink
Merge branch 'development' into incorporate_updates
Browse files Browse the repository at this point in the history
  • Loading branch information
fonkamloic authored Jul 15, 2024
2 parents 7ff69d0 + cb7cdc6 commit c7e21dc
Show file tree
Hide file tree
Showing 12 changed files with 209 additions and 184 deletions.
35 changes: 2 additions & 33 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,8 @@
{
"name": "no_screenshot",
"request": "launch",
"type": "dart"
},
{
"name": "no_screenshot (profile mode)",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "no_screenshot (release mode)",
"request": "launch",
"type": "dart",
"flutterMode": "release"
},
{
"name": "example",
"cwd": "example",
"request": "launch",
"type": "dart"
},
{
"name": "example (profile mode)",
"cwd": "example",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "example (release mode)",
"cwd": "example",
"request": "launch",
"type": "dart",
"flutterMode": "release"
"type": "dart",
"program": "example/lib/main.dart"
}
]
}
46 changes: 23 additions & 23 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
Copyright (c) 2022, FlutterPlaza
All rights reserved.
Copyright (c) 2022, FlutterPlaza
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of FlutterPlaza nor the names of its contributors may
be used to endorse or promote products derived from this software
without specific prior written permission.
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of FlutterPlaza nor the names of its contributors may
be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ If you want to prevent user from taking screenshot or recording of your app. You

```dart
class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver {
final _noScreenshot = NoScreenshot();
final _noScreenshot = NoScreenshot.instance;
AppLifecycleState? _notification;
@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,71 +9,89 @@ import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result
import android.view.WindowManager.LayoutParams;
import android.view.WindowManager.LayoutParams
import io.flutter.embedding.engine.plugins.activity.ActivityAware
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding

const val SCREENSHOT_ON_CONST = "screenshotOn"
const val SCREENSHOT_OFF_CONST = "screenshotOff"
const val TOGGLE_SCREENSHOT_CONST = "toggleScreenshot"

/** NoScreenshotPlugin */
class NoScreenshotPlugin: FlutterPlugin, MethodCallHandler, ActivityAware {
/// The MethodChannel that will the communication between Flutter and native Android
///
/// This local reference serves to register the plugin with the Flutter Engine and unregister it
/// when the Flutter Engine is detached from the Activity
private lateinit var channel : MethodChannel
private lateinit var context: Context
private lateinit var activity: Activity

override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "com.flutterplaza.no_screenshot")
channel.setMethodCallHandler(this)
context = flutterPluginBinding.applicationContext

}

override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) =
if (call.method == "screenshotOff") {
screenshotOff();
result.success(true);
}
else if(call.method == "screenshotOn"){
screenshotOn();
result.success(true);
}
else if(call.method == "toggleScreenshot"){
var flags: Int = activity.window.attributes.flags;
if( (flags and LayoutParams.FLAG_SECURE) != 0){
screenshotOn();
}else {
screenshotOff();
}
result.success(true);
class NoScreenshotPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
/// The MethodChannel that will the communication between Flutter and native Android
///
/// This local reference serves to register the plugin with the Flutter Engine and unregister it
/// when the Flutter Engine is detached from the Activity
private lateinit var channel: MethodChannel
private lateinit var context: Context
private lateinit var activity: Activity

override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
channel =
MethodChannel(flutterPluginBinding.binaryMessenger, "com.flutterplaza.no_screenshot")
channel.setMethodCallHandler(this)
context = flutterPluginBinding.applicationContext

}
else {
result.notImplemented()

override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) =
when (call.method) {
SCREENSHOT_OFF_CONST -> {
val value: Boolean = screenshotOff()
result.success(value)
}
SCREENSHOT_ON_CONST -> {
val value = screenshotOn()

result.success(value)
}
TOGGLE_SCREENSHOT_CONST -> {
val flags: Int = activity.window.attributes.flags
if ((flags and LayoutParams.FLAG_SECURE) != 0) {
screenshotOn()
} else {
screenshotOff()
}
result.success(true)
}
else -> {
result.notImplemented()
}
}

private fun screenshotOff(): Boolean {
try {
activity.window.addFlags(LayoutParams.FLAG_SECURE)
return true
} catch (e: Exception) {
return false
}
}

private fun screenshotOff(){
activity.window.addFlags(LayoutParams.FLAG_SECURE);
}
private fun screenshotOn(){
activity.window.clearFlags(LayoutParams.FLAG_SECURE);
}
private fun screenshotOn() : Boolean{
try {
activity.window.clearFlags(LayoutParams.FLAG_SECURE)
return true
} catch (e: Exception) {
return false
}
}

override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
channel.setMethodCallHandler(null)
}
override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
channel.setMethodCallHandler(null)
}

override fun onAttachedToActivity(binding: ActivityPluginBinding) {
activity = binding.activity;
}
override fun onAttachedToActivity(binding: ActivityPluginBinding) {
activity = binding.activity
}

override fun onDetachedFromActivityForConfigChanges() {}

override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
activity = binding.activity;
override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
activity = binding.activity

}
}

override fun onDetachedFromActivity() {}
}
1 change: 0 additions & 1 deletion example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ android {
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.flutterplaza.no_screenshot_example"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
Expand Down
6 changes: 3 additions & 3 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@ class _MyAppState extends State<MyApp> {
child: const Text('Press to toggle screenshot'),
onPressed: () async {
final result = await _noScreenshot.toggleScreenshot();
print(result);
debugPrint(result.toString());
},
),
ElevatedButton(
child: const Text('Press to turn off screenshot'),
onPressed: () async {
final result = await _noScreenshot.screenshotOff();
print(result);
debugPrint(result.toString());
},
),
ElevatedButton(
child: const Text('Press to turn on screenshot'),
onPressed: () async {
final result = await _noScreenshot.screenshotOn();
print(result);
debugPrint(result.toString());
},
),
],
Expand Down
Loading

0 comments on commit c7e21dc

Please sign in to comment.