2 * Copyright © 2019 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.Activity;
23 import android.app.Dialog;
24 import android.content.Context;
25 import android.content.DialogInterface;
26 import android.content.SharedPreferences;
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) {
60 // Get the context and the activity.
61 Context context = getContext();
62 Activity activity = getActivity();
64 // Remove the incorrect lint warnings below that the context or the activity might be null.
65 assert context != null;
66 assert activity != null;
69 Bundle arguments = getArguments();
71 // Remove the incorrect lint warning below that the arguments might be null.
72 assert arguments != null;
74 // Get the proxy mode from the arguments.
75 String proxyMode = arguments.getString("proxy_mode");
77 // Remove the incorrect lint warning below tha tth eproxy mode migth be null.
78 assert proxyMode != null;
80 // Get a handle for the shared preferences.
81 SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
83 // Get the screenshot and the theme preferences.
84 boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
85 boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
87 // Use a builder to create the alert dialog.
88 AlertDialog.Builder dialogBuilder;
90 // Set the style and the icon according to the theme.
93 dialogBuilder = new AlertDialog.Builder(activity, R.style.PrivacyBrowserAlertDialogDark);
96 dialogBuilder.setIcon(R.drawable.proxy_enabled_dark);
99 dialogBuilder = new AlertDialog.Builder(activity, R.style.PrivacyBrowserAlertDialogLight);
102 dialogBuilder.setIcon(R.drawable.proxy_enabled_light);
105 // Set the title and the message according to the proxy mode.
107 case ProxyHelper.TOR:
109 dialogBuilder.setTitle(R.string.orbot_not_installed_title);
112 dialogBuilder.setMessage(R.string.orbot_not_installed_message);
115 case ProxyHelper.I2P:
117 dialogBuilder.setTitle(R.string.i2p_not_installed_title);
120 dialogBuilder.setMessage(R.string.i2p_not_installed_message);
124 // Set the positive button.
125 dialogBuilder.setPositiveButton(R.string.close, (DialogInterface dialog, int which) -> {
126 // Do nothing. The alert dialog will close automatically.
129 // Create an alert dialog from the alert dialog builder.
130 AlertDialog alertDialog = dialogBuilder.create();
132 // Disable screenshots if not allowed.
133 if (!allowScreenshots) {
134 // Remove the warning below that `getWindows()` might be null.
135 assert alertDialog.getWindow() != null;
137 // Disable screenshots.
138 alertDialog.getWindow().addFlags((WindowManager.LayoutParams.FLAG_SECURE));
141 // Return the alert dialog.