2 * Copyright © 2019-2020 Soren Stoutner <soren@stoutner.com>.
4 * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
6 * Privacy Browser is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * Privacy Browser is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Privacy Browser. If not, see <http://www.gnu.org/licenses/>.
20 package com.stoutner.privacybrowser.dialogs;
22 import android.app.Dialog;
23 import android.content.Context;
24 import android.content.DialogInterface;
25 import android.content.SharedPreferences;
26 import android.content.res.Configuration;
27 import android.os.Bundle;
28 import android.view.WindowManager;
30 import androidx.annotation.NonNull;
31 import androidx.appcompat.app.AlertDialog;
32 import androidx.fragment.app.DialogFragment;
33 import androidx.preference.PreferenceManager;
36 import com.stoutner.privacybrowser.helpers.ProxyHelper;
37 import com.stoutner.privacybrowser.R;
39 public class ProxyNotInstalledDialog extends DialogFragment {
40 public static ProxyNotInstalledDialog displayDialog(String proxyMode) {
41 // Create an arguments bundle.
42 Bundle argumentsBundle = new Bundle();
44 // Store the proxy mode in the bundle.
45 argumentsBundle.putString("proxy_mode", proxyMode);
47 // Create a new instance of the dialog.
48 ProxyNotInstalledDialog proxyNotInstalledDialog = new ProxyNotInstalledDialog();
50 // Add the bundle to the dialog.
51 proxyNotInstalledDialog.setArguments(argumentsBundle);
53 // Return the new dialog.
54 return proxyNotInstalledDialog;
59 public Dialog onCreateDialog(Bundle savedInstanceState) {
61 Context context = requireContext();
64 Bundle arguments = getArguments();
66 // Remove the incorrect lint warning below that the arguments might be null.
67 assert arguments != null;
69 // Get the proxy mode from the arguments.
70 String proxyMode = arguments.getString("proxy_mode");
72 // Remove the incorrect lint warning below that the proxy mode might be null.
73 assert proxyMode != null;
75 // Use a builder to create the alert dialog.
76 AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context, R.style.PrivacyBrowserAlertDialog);
78 // Get the current theme status.
79 int currentThemeStatus = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
81 // Set the icon according to the theme.
82 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
83 dialogBuilder.setIcon(R.drawable.proxy_enabled_night);
85 dialogBuilder.setIcon(R.drawable.proxy_enabled_day);
88 // Set the title and the message according to the proxy mode.
92 dialogBuilder.setTitle(R.string.orbot_not_installed_title);
95 dialogBuilder.setMessage(R.string.orbot_not_installed_message);
100 dialogBuilder.setTitle(R.string.i2p_not_installed_title);
103 dialogBuilder.setMessage(R.string.i2p_not_installed_message);
107 // Set the positive button.
108 dialogBuilder.setPositiveButton(R.string.close, (DialogInterface dialog, int which) -> {
109 // Do nothing. The alert dialog will close automatically.
112 // Create an alert dialog from the alert dialog builder.
113 AlertDialog alertDialog = dialogBuilder.create();
115 // Get a handle for the shared preferences.
116 SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
118 // Get the screenshot preference.
119 boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
121 // Disable screenshots if not allowed.
122 if (!allowScreenshots) {
123 // Remove the warning below that `getWindows()` might be null.
124 assert alertDialog.getWindow() != null;
126 // Disable screenshots.
127 alertDialog.getWindow().addFlags((WindowManager.LayoutParams.FLAG_SECURE));
130 // Return the alert dialog.