- // Get the original current page ID.
- int originalCurrentPageId = getArguments().getInt("Current_Page");
-
- // Subtract `originalCurrentPageId` from the array size because we reversed the order of the array so that the newest entries are at the top. `-1` is needed because the array is zero-based.
- currentPageId = urlStringArrayList.size() - 1 - originalCurrentPageId;
- }
-
- // The public interface is used to send information back to the parent activity.
- public interface UrlHistoryListener {
- // Send back the number of steps to move forward or back.
- void onUrlHistoryEntrySelected(int moveBackOrForwardSteps);
-
- // Clear the history.
- void onClearHistory();
- }
-
- // `urlHistoryListener` is used in `onAttach()` and `onCreateDialog()`.
- private UrlHistoryListener urlHistoryListener;
-
- @Override
- public void onAttach(Context context) {
- super.onAttach(context);
-
- // Check to make sure tha the parent activity implements the listener.
- try {
- urlHistoryListener = (UrlHistoryListener) context;
- } catch (ClassCastException exception) {
- throw new ClassCastException(context.toString() + " must implement UrlHistoryListener.");
- }
- }
-
- @Override
- @NonNull
- // `@SuppressLing("InflateParams")` removes the warning about using `null` as the parent view group when inflating the `AlertDialog`.
- @SuppressLint("InflateParams")
- public Dialog onCreateDialog(Bundle savedInstanceState) {
- // Remove the incorrect lint warning that `getActivity()` might be null.
- assert getActivity() != null;
-
- // Get the activity's layout inflater.
- LayoutInflater layoutInflater = getActivity().getLayoutInflater();