From 14fb5eefbcb4a9d7661e476cc2a05fe10da3f11a Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Fri, 30 Nov 2018 19:49:47 +0100 Subject: let the user forbid android from taking screenshots --- .../de/pixart/messenger/ui/ActionBarActivity.java | 26 ++++++++++++++++++++++ .../java/de/pixart/messenger/ui/XmppActivity.java | 1 + 2 files changed, 27 insertions(+) (limited to 'src/main/java/de/pixart/messenger') diff --git a/src/main/java/de/pixart/messenger/ui/ActionBarActivity.java b/src/main/java/de/pixart/messenger/ui/ActionBarActivity.java index bc0557f1f..cab311d58 100644 --- a/src/main/java/de/pixart/messenger/ui/ActionBarActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ActionBarActivity.java @@ -1,8 +1,14 @@ package de.pixart.messenger.ui; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; +import android.support.annotation.BoolRes; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.view.MenuItem; +import android.view.WindowManager; + +import de.pixart.messenger.R; public abstract class ActionBarActivity extends AppCompatActivity { public static void configureActionBar(ActionBar actionBar) { @@ -25,4 +31,24 @@ public abstract class ActionBarActivity extends AppCompatActivity { } return super.onOptionsItemSelected(item); } + + void initializeScreenshotSecurity() { + if (isScreenSecurityEnabled()) { + getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE); + } else { + getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE); + } + } + + public boolean isScreenSecurityEnabled() { + return getBooleanPreference("screen_security", R.bool.screen_security); + } + + protected SharedPreferences getPreferences() { + return PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); + } + + protected boolean getBooleanPreference(String name, @BoolRes int res) { + return getPreferences().getBoolean(name, getResources().getBoolean(res)); + } } diff --git a/src/main/java/de/pixart/messenger/ui/XmppActivity.java b/src/main/java/de/pixart/messenger/ui/XmppActivity.java index ee606395a..06ee2692d 100644 --- a/src/main/java/de/pixart/messenger/ui/XmppActivity.java +++ b/src/main/java/de/pixart/messenger/ui/XmppActivity.java @@ -1028,6 +1028,7 @@ public abstract class XmppActivity extends ActionBarActivity { @Override public void onResume() { super.onResume(); + initializeScreenshotSecurity(); } protected int findTheme() { -- cgit v1.2.3