Subject Computer Science App Development

Question

Instructions:

Create a web browser that can have multiple “tabs”. Each page will be loaded by taking a user supplied URL, fetching the (HTML) data from the specified URL, and then loading the information in a WebView. Your application must use fragments, with each fragment containing its own WebView. Your app will also use the activity AppBar, and it will contain (at least) 3 buttons: New, Previous, and Forward. Clicking the New button creates a new tab (browser fragment) and places it on top, awaiting the user's URL. The Previous and Next buttons will cycle through the next and previous fragments.

Each fragment will also have a Next and Previous button (you may want to use difference images on the buttons to differentiate them) to navigate back and forward among pages viewed in that specific browser fragment (the same Back and Forward function of a conventional web browser).

Since you will need to navigate back and forth among your browser windows (fragments), you will not be able to rely solely on the FragmentManager (the fragment manager operates as a stack, which means you would lose fragments when they were popped). You will need to implement some other data structure to assist in the management of your fragments. This structure can be implemented in various ways, such as an ArrayList (e.g. ArrayList<Fragment>). In addition to maintaining the list of browser windows, you will use the ViewPager and FragmentStatePagerAdapter to facilitate moving among previously opened browser windows using a swipe function.
The FragmentStatePagerAdapter allows you to easily implement swipe-to-switch functionality for your browser fragments.

1. Familiarize yourself with the WebView widget as well as the ViewPager and FragmentStatePagerAdapter.

2. Add the following permission request line to your AndroidManifest.xml as a child of the
<manifest> tag as follows:

<manifest xmlns:android="..." package="...">

<uses-permission android:name="android.permission.INTERNET"/>

This will allow your application to access the internet (it’s a web browser after all).

3. Design the layout for your main activity to contain an EditText (to get the URL), and a Button (the Go button) aligned at the top of the screen as in a traditional web browser.

The EditText will allow the user to enter a URL, the button will be used to initiate the fetch process

4. Your browser fragments should be designed as follows:

1. Create a layout for your fragment containing a WebView.

The WebView will be used to display the downloaded content.

2. When the user clicks the Go button in the activity, load the URL typed into the activity’s EditText in the fragment’s WebView object using its loadURL() method.

3. When the user switches from one fragment to another (fragment1 to fragment2), fragment1 must remember its URL (if it had one) and it should be displayed in the activity’s EditText if we navigate back to fragment1. It’s OK if fragment1’s WebView has to be reloaded, but the URL should be remembered and displayed to the user in the activity, and the webview reload should be done automatically (i.e. the user should not have to click Go a second time).

5. Create and upload a signed APK along with an archive of your Android Studio project (or a GitHub link)
Considerations:
▪ You can enable JavaScript in your browser by making a call to:

webView.getSettings().setJavaScriptEnabled(true);

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

public class WebViewFragment extends Fragment {
    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";

    // List of visited url within the fragment
    // Each fragment will have its own list of visited urls.
    private ArrayList<CharSequence> lstUrls;

    // Current visited url position. This position will be
    // updated by the back/next buttons.
    private int position;

    private Button btnBack;

    private Button btnNext;

    private OnFragmentInteractionListener mListener;
    private WebView webView;

    public WebViewFragment() {
       // Required empty public constructor
       lstUrls = new ArrayList<>();
    }

    /**
    * Use this factory method to create a new instance of
    * this fragment using the provided parameters.
    *
    * @param param Parameter 1.
    * @return A new instance of fragment WebViewFragment.
    */
    // TODO: Rename and change types and number of parameters
    public static WebViewFragment newInstance(String param) {
       WebViewFragment fragment = new WebViewFragment();
       Bundle args = new Bundle();
       args.putString(ARG_PARAM1, param);
       fragment.setArguments(args);
       return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
    }

    @Override
    public void onSaveInstanceState(@NonNull Bundle outState) {
       super.onSaveInstanceState(outState);
       // Saving the list of visited urls, when the fragment goes
       // to background
       outState.putCharSequenceArrayList("urls", lstUrls);
       // Also store the position of the last visited url from the list.
       outState.putInt("position", position);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
       super.onActivityCreated(savedInstanceState);
       if(savedInstanceState != null) {
            // Getting the list of urls when this fragment become active
            // and visible.
            lstUrls = savedInstanceState.getCharSequenceArrayList("urls");
            // Getting the last visited url, corresponding page
            // will be loaded in the web view.
            position = savedInstanceState.getInt("position");
       }
       //onUrlChange();
    }...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Assisting Tutor
Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats