Description
CS 442 Mobile Applications
Development (Android Section)
CS 442: Mobile Applications Development
Assignment 3 – Stock Watch (300 pts)
Uses: Internet, RecyclerView, Option-Menus, Multiple AsyncTasks, JSON Data, Swipe-Refresh, Dialogs, SQLite Database
App Highlights:
• This app allows the user to display a sorted list of selected stocks. List entries include the stock symbol (and company name), the current price, the daily price change amount and price percent change.
• There is no need to use a different layout for landscape orientation in this application – the same layout should work in any orientation.
• Selected stock symbols and the related names should be stored in the device’s SQLite Database.
• A Stock class should be created to represent each individual stock in the application. Required data includes: Stock Symbol (String), Company Name (String), Price (double), Price Change (double), and Change Percentage (double).
• Clicking on a stock opens a browser displaying the Market Watch web page for that stock
• Swipe-Refresh (pull-down) refreshes stock data.
• The application is made up of only 1 activity, shown below:
© Christopher Hield
CS 442 Mobile Applications
Development (Android Section)
A) Internet Data:
Downloading data for a stock symbol requires 2 downloads – one download to acquire the full set or supported stock symbol and company names, and a second download to acquire the financial data for a particular stock.
Download 1: Stock Symbol & Company Data
When started, your app should initiate a download of the full set or supported stock symbol and company names. This data is saved, and then used whenever the user the user adds a new stock.
Download Source: https://api.iextrading.com/1.0/ref-data/symbols Download Results Example:
Results are returned in JSON format, as a JSONArray containing the results data from the query. The data we are interested in is the stock “symbol” and “name”. Below is a sample of the JSON you will download :
[{
“symbol”: “A”, }, {
“name”: “Agilent Technologies Inc.”, “symbol”: “ICXUSDT”,
“type”: “cs”, “isEnabled”: true,
“iexId”: “2” “type”: “crypto”,
}, { “iexId”: 10000013
“symbol”: “AA”, }, {
“name”: “Alcoa Corporation”, “symbol”: “NEOUSDT”,
“type”: “cs”, “isEnabled”: true,
“iexId”: “12042” “type”: “crypto”,
}, { “iexId”: 10000014
“symbol”: “AAAU”, }, {
“name”: “Perth Mint Physical Gold”, “symbol”: “VENUSDT”,
“type”: “N/A”, “isEnabled”: true,
“iexId”: “14924” “type”: “crypto”,
}, { “iexId”: 10000015
“symbol”: “AABA”, }, {
“name”: “Altaba Inc.”, “symbol”: “XLMUSDT”,
“type”: “cs”, “isEnabled”: true,
“iexId”: “7653” “type”: “crypto”,
}, { “iexId”: 10000016
“symbol”: “AAC”, }, {
“name”: “AAC Holdings Inc.”, “symbol”: “QTUMUSDT”,
“type”: “cs”, “isEnabled”: true,
“iexId”: “9169” “type”: “crypto”,
}, { “iexId”: 10000017
}] . . .
© Christopher Hield
CS 442 Mobile Applications
Development (Android Section)
Download 2: Stock Financial Data
When you have the desired stock symbol (and company name), you use the stock symbol to download financial data for that stock.
Download Source: https://api.iextrading.com
Query Format: https://api.iextrading.com/1.0/stock/stock_symbol/quote?displayPercent=true
For example, if the selected stock symbol was TSLA, your full URL would be: https://api.iextrading.com/1.0/stock/TSLA/quote?displayPercent=true
Download Results:
Results are returned in JSON format, as a JSONObject containing the results data from the query. The data we are interested in is highlighted below (Example using search text “TSLA”):
{
symbol
companyName
” “: “TSLA”,
” “: “Tesla Inc.”, “delayedPriceTime”: 1537560000292,
“primaryExchange”: “Nasdaq Global Select”, “extendedPrice”: 299.81,
“sector”: “Consumer Cyclical”, “extendedChange”: 0.71,
“calculationPrice”: “close”, “extendedChangePercent”: 0.2370000002,
“open”: 297.7, “extendedPriceTime”: 1537563572798,
“openTime”: 1537536600046, “previousClose”: 298.33,
change “: 0.77,
changePercent
“close”: 299.1, ”
“closeTime”: 1537560000292, “”: 0.258,
“high”: 300.58, “iexMarketPercent”: 0,
“low”: 295.37, “iexVolume”: null,
“latestPrice”: 299.1, “avgTotalVolume”: 9530433,
“latestSource”: “Close”, “iexBidPrice”: null,
“latestUpdate”: 1537560000292, “iexAskPrice”: null,
“latestVolume”: 5034657, “iexAskSize”: null,
“iexRealtimePrice”: null, “marketCap”: 51024409370,
“iexRealtimeSize”: null, “peRatio”: -18.88,
“iexLastUpdated”: null, “week52High”: 387.46,
“delayedPrice”: 299.1, “week52Low”: 244.5901,
“ytdChange”: -6.427801641032025
}
If the requested stock symbol does not exist, the following is returned: (Example using search text “ZZZZZ”):
Response Code: 404 Not Found
The symbol, companyName, latestPrice, change & changePercentage make up the data for one stock. Your code should parse these 5 data elements.
Using these 5 data elements, you can create a Stock object with all data reflecting the user’s choice.
© Christopher Hield
CS 442 Mobile Applications
Development (Android Section)
B) Application Behavior Diagrams:
1) App MainActivity
© Christopher Hield
CS 442 Mobile Applications
Development (Android Section)
1) Adding a stock – when only one stock matches the search symbol/name search string (NOTE: The Stock Selection dialog should only allow capital letters):
2) Adding a stock – when multiple stocks matched the search string (Stock Selection dialog should only allow capital letters, stock selection dialog should display the stock symbol and company name):
© Christopher Hield
CS 442 Mobile Applications
Development (Android Section)
© Christopher Hield
CS 442 Mobile Applications
Development (Android Section)
1) Adding a stock – specified stock is not found (Stock Selection dialog should only allow capital letters, No buttons
© Christopher Hield
CS 442 Mobile Applications
Development (Android Section)
7) Swipe-Refresh attempt with no network connection (No buttons on the error dialog):
© Christopher Hield
CS 442 Mobile Applications
Development (Android Section)
9) Tap on a stock to open the MarketWatch.com website entry for the selected stock:
MarketWatch URL’s are in the form: http://www.marketwatch.com/investing/stock/some_stock
© Christopher Hield
CS 442 Mobile Applications
Development (Android Section)
C) Application Behavior Flowcharts:
c) StockDownloader (AsyncTask)
© Christopher Hield 10 of 16
CS 442 Mobile Applications
Development (Android Section)
© Christopher Hield 11 of 16
CS 442 Mobile Applications
Development (Android Section)
e) Swipe-Refresh (pull-down) List:
f) Long-Press Delete Stock:
Delete Stock Process Flow
© Christopher Hield 12 of 16
CS 442 Mobile Applications
Development (Android Section)
D) Database
Your application must store the Stock Symbol and Company Name in the android device’s SQLite database. You will need a Database handler class as we have done in class (you have a posted example of a Database handler that you can use as a model).
StockWatchTable
StockSymbol CompanyName
AAPL Apple, Inc
AMZN Amazon.com, Inc.
… …
private static final String DATABASE_NAME = “StockAppDB”; private static final String TABLE_NAME = “StockWatchTable”; private static final String SYMBOL = “StockSymbol”; private static final String COMPANY = “CompanyName”; • DB creation (done in onCreate):
CREATE TABLE TABLE_NAME (
SYMBOL TEXT not null unique,
COMPANY TEXT not null)
• DB Add (Sample method to add a stock to the DB):
public void addStock(Stock stock) {
Log.d(TAG, “addStock: Adding ” + stock.getSymbol());
ContentValues values = new ContentValues(); values.put(SYMBOL, stock.getSymbol()); values.put(COMPANY, stock.getCompany());
database.insert(TABLE_NAME, null, values);
Log.d(TAG, “addStock: Add Complete”); }
• DB Delete (Sample method to delete a stock from the DB):
public void deleteStock(String symbol) {
Log.d(TAG, “deleteStock: Deleting Stock ” + symbol);
int cnt = database.delete(
TABLE_NAME, “SYMBOL = ?”, new String[] { symbol });
Log.d(TAG, “deleteStock: ” + cnt); }
© Christopher Hield 13 of 16
CS 442 Mobile Applications
Development (Android Section)
• DB Load All (Sample method to get all stock-company entries from the DB):
public ArrayList<String[]> loadStocks() {
ArrayList<String[]> stocks = new ArrayList<>();
Cursor cursor = database.query(
TABLE_NAME, // The table to query
new String[]{SYMBOL, COMPANY}, // The columns to return null, // The columns for the WHERE clause null, // The values for the WHERE clause null, // don’t group the rows null, // don’t filter by row groups null); // The sort order
if (cursor != null) { cursor.moveToFirst();
for (int i = 0; i < cursor.getCount(); i++) {
String symbol = cursor.getString(0); String company = cursor.getString(1); stocks.add(new String[]{symbol, company}); cursor.moveToNext();
}
cursor.close();
}
return stocks;
}
© Christopher Hield 14 of 16
CS 442 Mobile Applications
Development (Android Section)
E) Development Plan
1) Create the base app:
a. MainActivity with RecyclerView & SwipeRefreshLayout b. Stock Class
c. RecyclerView Adapter
d. RecyclerView ViewHolder
e. Create fake “dummy” stocks to populate the list in the MainActivity onCreate.
f. Add the onClick and onLongClick methods. The onLongClick should delete an entry. The onClick can open a Toast message for now.
g. Add Stock options-menu opens dialog, on confirmation you can open a Toast message for now.
h. SwipeRefresh callback method can open a Toast message for now.
2) Add the database elements:
a. Create the database handler.
b. Add database handler calls to MainActivity (load, add, delete)
c. Code the onClick method to open the browser to the stock’s Market Watch site.
3) Add the internet elements and final integration:
a. Create the Stock Symbol – Company Name downloader/parser AsyncTask (http://d.yimg.com/aq/autoc)
b. Create the Stock Financial Data downloader/parser AsyncTask (finance.google.com)
c. Add a method to MainActivity that allows the Stock Symbol – Company Name downloader/parser AsyncTask to send the newly downloaded Stock Symbol & Company Name data back to MainActivity. This method should create and execute the Stock Financial Data downloader/parser AsyncTask.
d. Add a method to MainActivity that allows the Stock Financial Data downloader/parser AsyncTask to send the newly created Stock back to MainActivity.
e. Implement the Add Stock feature (this uses the results of the above tasks)
f. Implement the SwipeRefresh callback to re-download the Stock Financial Data for the loaded stocks
g. Add alerts when startup, add, & refresh are attempted when no internet connection is available.
© Christopher Hield 15 of 16
CS 442 Mobile Applications
Development (Android Section)
Assignment Assistance
Submissions & Grading
1) Submissions must consist of your zipped project folder (please execute Build =>Clean Project before generating the zip file).
2) Submissions should reflect the concepts and practices we cover in class, and the requirements specified in this document.
4) Grading will be based upon the presence and proper functionality of all features and behaviors described in this document.
NOTE
This assignment is worth 300 points. This means (for example) that if you get 89% on this assignment, your recorded score will be:
(89% * 300 points = 267 points)
Note that this also means that the 10% late submission penalty will be 10% * 300 points = 30 points.
If you do not understand anything in this handout, please ask.
Otherwise the assumption is that you understand the content.
Unsure? Ask!
© Christopher Hield 16 of 16
Reviews
There are no reviews yet.