In this programming assignment, you should create an application that can be used to search for and browse through news articles. You can name the application “News”. When application begins, the user should be presented with a simple user interface, including the title of the application, a text field and search button, and then the remaining space can be used to display the search results. The user should be able to complete one-keyword searches to get articles related to that topic, browse through them, and even view the entire article on the original website.
Take a close look at the animation, demonstrating how the application should work. Take note of a few things in particular:
ListView
.
You also should create an appropriate Adapter, and data structure(s), as necessary.
Each result in the result list should include the article’s Original website, and the author.WebView
.Activity
for this application.
You should utilize fragments for the majority of the UI functionality.
More on this later.You should use the News API to complete news article searches. The news API was already mentioned in-class, and there was even an activity asking you to use it. In order to use the API, you’ll have to get an API key. for the flickr API, you were all able to use the same key, but for this one, you should create your own account to get an API key. Thankfully, newsapi.org does not ask for a significant amount of personal information to set up an account - just name, email, password, user-case, and having to agree to a few things.
After creating an account, you should be able to find your API key.
In order to make a search for this application, you’ll want to use a URL along the lines of the following:
https://newsapi.org/v2/everything?sortBy=publishedAt&q=SEARCH_TERM&from=START_DATE&apiKey=API_KEY
You should:
SEARCH_TERM
with the single-word search term that the user types in into the text box.START_DATE
with a date string of the format YYYY-MM-DD
, where the date represents one week prior to the present day.API_KEY
with your API key.As long as you submit a valid request, you receive the results in JSON format.
You can navigate the results using the JSONObject
and JSONArray
classes.
As a first step after generating the project, create a new Fragmen
class with the appropriate UI components.
This should include a title, EditText, search button, and a ListView to use to display the search results.
Then, add an activity transaction to get the Fragment displaying on the view.
Next, create an AsyncTask that you can use to search using the News API. In order to search as you should, you’ll need to:
YYYY-MM-DD
.You should assemble all of these things into a search URL for the news API, and them execute the search. After receiving the results, use the JSONObject and JSONArray classes to access the results and display them in the ListView. You are expected to use a ListView with an Adapter for this.
Next, create another Fragment class that can be used for displaying a preview of an article. The Fragment should contain a title, a TextView for the article preview, and a button. Then, you should update the code in the activity and/or the previously-created fragment so that when a result is clicked on, a fragment is created and displayed to preview the article. You should use another Fragment transaction for this.
You should create a third Fragment with a WebView for viewing the original article. Clicking on the “Read On . . .” button should cause one of these fragments to be created an displayed.
For this application, you should target:
This is due at 7pm on October 26th at 7pm. Use the Android Studio Zip feature to zip up the assignment. Then, submit the zip file to gradescope. Note that there are not automated tests for this PA, so please ensure that your app works how the specification says it should!