import java.util.ArrayList;
public class UrlHistoryDialog extends DialogFragment{
-
- // `historyArrayList` and `currentPageId` pass information from `onCreate()` to `onCreateDialog()`.
+ // Declare the class variables.
private final ArrayList<History> historyArrayList = new ArrayList<>();
private int currentPageId;
+ // Create a URL history listener.
+ private UrlHistoryListener urlHistoryListener;
+
+
+ // 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();
+ }
+
+ @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.");
+ }
+ }
+
+
public static UrlHistoryDialog loadBackForwardList(Context context, WebBackForwardList webBackForwardList) {
// Create an arguments bundle.
Bundle argumentsBundle = new Bundle();
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`.