+ protected void onSaveInstanceState(Bundle outState) {
+ // Store the current `DomainSettingsFragment` state in `outState`.
+ if (findViewById(R.id.domain_settings_scrollview) != null) { // `DomainSettingsFragment` is displayed.
+ // Save any changes that have been made to the domain settings.
+ saveDomainSettings(coordinatorLayout, resources);
+
+ // Store `DomainSettingsDisplayed`.
+ outState.putBoolean("domain_settings_displayed", true);
+ outState.putInt("domain_settings_database_id", DomainSettingsFragment.databaseId);
+ } else { // `DomainSettingsFragment` is not displayed.
+ outState.putBoolean("domain_settings_displayed", false);
+ outState.putInt("domain_settings_database_id", -1);
+ }
+
+ super.onSaveInstanceState(outState);
+ }
+
+ // Control what the navigation bar back button does.
+ @Override
+ public void onBackPressed() {
+ // Get a handle for the fragment manager.
+ FragmentManager fragmentManager = getSupportFragmentManager();
+
+ if (twoPanedMode) { // The device is in two-paned mode.
+ // Save the current domain settings if the domain settings fragment is displayed.
+ if (findViewById(R.id.domain_settings_scrollview) != null) {
+ saveDomainSettings(coordinatorLayout, resources);
+ }
+
+ // Dismiss the undo delete SnackBar if it is shown.
+ if ((undoDeleteSnackbar != null) && undoDeleteSnackbar.isShown()) {
+ // Set the close flag.
+ closeActivityAfterDismissingSnackbar = true;
+
+ // Dismiss the snackbar.
+ undoDeleteSnackbar.dismiss();
+ } else {
+ // Pass `onBackPressed()` to the system.
+ super.onBackPressed();
+ }
+ } else if (closeOnBack) { // Go directly back to the main WebView activity because the domains activity was launched from the options menu.
+ // Save the current domain settings.
+ saveDomainSettings(coordinatorLayout, resources);
+
+ // Pass `onBackPressed()` to the system.
+ super.onBackPressed();
+ } else if (findViewById(R.id.domain_settings_scrollview) != null) { // The device is in single-paned mode and domain settings fragment is displayed.
+ // Save the current domain settings.
+ saveDomainSettings(coordinatorLayout, resources);
+
+ // Display the domains list fragment.
+ DomainsListFragment domainsListFragment = new DomainsListFragment();
+ fragmentManager.beginTransaction().replace(R.id.domains_listview_fragment_container, domainsListFragment).commit();
+ fragmentManager.executePendingTransactions();
+
+ // Populate the list of domains. `-1` highlights the first domain if in two-paned mode. It has no effect in single-paned mode.
+ populateDomainsListView(-1);
+
+ // Show the add domain floating action button.
+ addDomainFAB.show();
+
+ // Hide the delete menu item.
+ deleteMenuItem.setVisible(false);
+ } else { // The device is in single-paned mode and the domain list fragment is displayed.
+ // Dismiss the undo delete SnackBar if it is shown.
+ if ((undoDeleteSnackbar != null) && undoDeleteSnackbar.isShown()) {
+ // Set the close flag.
+ closeActivityAfterDismissingSnackbar = true;
+
+ // Dismiss the snackbar.
+ undoDeleteSnackbar.dismiss();
+ } else {
+ // Pass `onBackPressed()` to the system.
+ super.onBackPressed();
+ }
+ }
+ }
+
+ @Override
+ public void onAddDomain(DialogFragment dialogFragment) {
+ // Dismiss the undo delete snackbar if it is currently displayed.
+ if ((undoDeleteSnackbar != null) && undoDeleteSnackbar.isShown()) {
+ undoDeleteSnackbar.dismiss();
+ }
+
+ // Get the new domain name String from the dialog fragment.
+ EditText domainNameEditText = dialogFragment.getDialog().findViewById(R.id.domain_name_edittext);