CS 442: Assignment 3 – Stock Watch solved

$40.00

Category: You will receive a download link of the .ZIP file upon Payment

Description

5/5 - (1 vote)

Uses: Internet, RecyclerView, Option-Menus, Multi-threads,
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:
Add Stock Options-Menu
Item (shown as Icon)
RecyclerView list of Stocks (list
entries have their own layout)
List scrolls up & down
Long-Click on a Stock entry to
delete (with delete confirmation)
Click on a Stock entry opens a
web browser to the Market
Watch site for the selected stock
CS 442 Mobile Applications
Development (Android Section)
© Christopher Hield 2 of 16
A) Internet Data:
Downloading data for a stock symbol requires 2 downloads – one download to acquire the full set of 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 should be saved in your application, 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.”,
“date”: “2018-09-21”,
“isEnabled”: true,
“type”: “cs”,
“iexId”: “2”
}, {
“symbol”: “AA”,
“name”: “Alcoa Corporation”,
“date”: “2018-09-21”,
“isEnabled”: true,
“type”: “cs”,
“iexId”: “12042”
}, {
“symbol”: “AAAU”,
“name”: “Perth Mint Physical Gold”,
“date”: “2018-09-21”,
“isEnabled”: true,
“type”: “N/A”,
“iexId”: “14924”
}, {
“symbol”: “AABA”,
“name”: “Altaba Inc.”,
“date”: “2018-09-21”,
“isEnabled”: true,
“type”: “cs”,
“iexId”: “7653”
}, {
“symbol”: “AAC”,
“name”: “AAC Holdings Inc.”,
“date”: “2018-09-21”,
“isEnabled”: true,
“type”: “cs”,
“iexId”: “9169”
}, {
. . .
}, {
“symbol”: “ICXUSDT”,
“name”: “ICON USD”,
“date”: “2018-09-21”,
“isEnabled”: true,
“type”: “crypto”,
“iexId”: 10000013
}, {
“symbol”: “NEOUSDT”,
“name”: “NEO USD”,
“date”: “2018-09-21”,
“isEnabled”: true,
“type”: “crypto”,
“iexId”: 10000014
}, {
“symbol”: “VENUSDT”,
“name”: “VeChain USD”,
“date”: “2018-09-21”,
“isEnabled”: true,
“type”: “crypto”,
“iexId”: 10000015
}, {
“symbol”: “XLMUSDT”,
“name”: “Stellar Lumens USD”,
“date”: “2018-09-21”,
“isEnabled”: true,
“type”: “crypto”,
“iexId”: 10000016
}, {
“symbol”: “QTUMUSDT”,
“name”: “Qtum USD”,
“date”: “2018-09-21”,
“isEnabled”: true,
“type”: “crypto”,
“iexId”: 10000017
}]
CS 442 Mobile Applications
Development (Android Section)
© Christopher Hield 3 of 16
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. For this you will need an API key. You can get this by registering at:
https://iexcloud.io/cloud-login#/register
• Go to: https://iexcloud.io/cloud-login#/register
• Select “Individual”
• Enter your name, email address, and select a password.
• Click the terms checkbox and click “Create acount”
• Select the “START” plan (0/mo) – click Select Start
• Go to your email – look for message with Subject “IEX Cloud Email Verification”
• Click the iexcloud.io link in the email.
• From the page that link opens, click ‘API Tokens” in the upper-left (under Home)
Query Format: https://cloud.iexapis.com/stable/stock/STOCK_SYMBOL/quote?token=API_KEY
For example, if the selected stock symbol was TSLA and your API token was pk_123abc, then your full
URL would be: https://cloud.iexapis.com/stable/stock/TSLA/quote?token=pk_123abc
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”: “TGT”,
“companyName”: “Target Corp.”,
“primaryExchange”: “New York Stock Exchange”,
“calculationPrice”: “previousclose”,
“open”: null,
“openTime”: null,
“close”: null,
“closeTime”: null,
“high”: null,
“low”: null,
“latestPrice”: 116.63,
“latestSource”: “Previous close”,
“latestTime”: “February 14, 2020”,
“latestUpdate”: 1581656400000,
“latestVolume”: null,
“iexRealtimePrice”: null,
“iexRealtimeSize”: null,
“iexLastUpdated”: null,
“delayedPrice”: null,
“delayedPriceTime”: null,
“oddLotDelayedPrice”: null,
“oddLotDelayedPriceTime”: null,
“extendedPrice”: null,
“extendedChange”: null,
“extendedChangePercent”: null,
“extendedPriceTime”: null,
“previousClose”: 116.63,
“previousVolume”: 3289074,
“change”: 0,
“changePercent”: 0,
“volume”: null,
“iexMarketPercent”: null,
“iexVolume”: null,
“avgTotalVolume”: 5489347,
“iexBidPrice”: null,
“iexBidSize”: null,
“iexAskPrice”: null,
“iexAskSize”: null,
“marketCap”: 59100736310,
“peRatio”: 18.48,
“week52High”: 130.24,
“week52Low”: 70.03,
“ytdChange”: -0.0941,
“lastTradeTime”: 1581714000046,
“isUSMarketOpen”: false
}

CS 442 Mobile Applications
Development (Android Section)
© Christopher Hield 4 of 16
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.
CS 442 Mobile Applications
Development (Android Section)
© Christopher Hield 5 of 16
B) Application Behavior Diagrams:
1) App MainActivity
“Add Stock” action is
an Options-Menu
with a single item
(shown as Icon)
Each stock entry contains the
Stock Symbol (i.e., AAPL), the
company name (i.e., Apple
Inc.), the Last Trade Price
(135.72), the price change
direction (▲ for positive
Price Change Amount, ▼ for
negative Price Change
Amount), the Price Change
Amount (0.38), and the Price
Change Percentage (0.28%)
in parentheses.
If the stock’s Price Change
Amount is a positive value,
then entire entry should use
a green font. If the Price
Change Amount is a negative
value, then entire entry
should use a red font.
A scrollbar should be
present along the
right-hand side
Long-Click on a Stock
entry to delete (with
delete confirmation)
Clicking on a Stock entry opens a
web browser to the Market
Watch website site for the
selected stock
RecyclerView list
entries have their
own layout
CS 442 Mobile Applications
Development (Android Section)
© Christopher Hield 6 of 16
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):
AMZN
CS 442 Mobile Applications
Development (Android Section)
© Christopher Hield 7 of 16
3) Adding a stock with no Network Connection – test using “Airplane Mode” (No buttons on the error dialog):
4) Adding a stock – specified stock is a duplicate (Stock Selection dialog should only allow capital letters, No
buttons on the warning dialog):
AMZN
CS 442 Mobile Applications
Development (Android Section)
© Christopher Hield 8 of 16
1) Adding a stock – specified stock is not found (Stock Selection dialog should only allow capital letters, No buttons
on the dialog):
6) Swipe-Refresh (pull-down) reloads (re-downloads) all stock data:
WXYZ
Pull
CS 442 Mobile Applications
Development (Android Section)
© Christopher Hield 9 of 16
7) Swipe-Refresh attempt with no network connection (No buttons on the error dialog):
8) Long-Press on a stock to delete it:
Pull
CS 442 Mobile Applications
Development (Android Section)
© Christopher Hield 10 of 16
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
For example: http://www.marketwatch.com/investing/stock/TSLA
CS 442 Mobile Applications
Development (Android Section)
© Christopher Hield 11 of 16
C) Application Behavior Flowcharts:
a) App Startup
MainActivity
onCreate
Connected to
Network?
Show No-Network
Error Dialog
No
Get all Stocks from
the DB, store in a
Temporary List
For Each Stock in
the Temporary
Stock List:
Execute
StockDownloader
AsyncTask
Sort Stock List
Notify Adapter
of Changed
Dataset
Next Stock
Startup Process Flow
No more stocks
to process
Yes
Put all stocks in the
display, with price,
change & percent
change as zero.
Execute
NameDownloader
AsyncTask
Done
More
Stocks
Add Stock to
Stock List Sort Stock List
Notify Adapter
of Changed
Dataset
RETURN from
StockDownloader
AsyncTask
Done
b) NameDownloader (AsyncTask)
Connect to data
provider via API
Download stock
symbols & names
JSON
Parse symbol &
name data
Add symbol &
names to
symbol:name
HashMap
Done
c) StockDownloader (AsyncTask)
Using provided stock
symbol, connect to
stock data provider
via API
Download stock
data JSON
Parse symbol &
name data
Create Stock object
& pass it back to
MainActivity
Done
CS 442 Mobile Applications
Development (Android Section)
© Christopher Hield 12 of 16
d) Add New Stock Process
Display Add Stock
Symbol Entry
Dialog
Get matching
symbols/names
from
NameDownloader
Did you
Get a Stock
result?
Display a list of the
resulting Stock Symbols
& Company Names in a
Dialog
No Stock Found Multiple Stocks
Use selected symbol to
execute
StockDownloader
AsyncTask
ONE Stock
Show Error Dialog
DONE
Selection Made
DONE
Dialog
Cancelled
Duplicate
Stock?
Yes
Add Stock to
Stock List
N o
Select
Add Stock
Menu option
from Main
Activity
Add Stock Process Flow
Sort Stock List Add Stock to
D B
Notify Adapter
of Changed
Dataset
Yes
Connected to
Network?
Show Error Dialog
N o
DONE
RETURN from
StockDownloader
AsyncTask
CS 442 Mobile Applications
Development (Android Section)
© Christopher Hield 13 of 16
e) Swipe-Refresh (pull-down) List:
onSwipe
Refresh
Connected to
Network?
Show No-Network
Error Dialog
No
Get all Stocks from
the DB, store in a
Temporary List
For Each Stock in
the Temporary
Stock List:
Execute
StockDownloader
AsyncTask
Next Stock
SwipeRefresh Process Flow
No more stocks
to process
Yes
Done
More
Stocks
Add Stock to
Stock List Sort Stock List
Notify Adapter
of Changed
Dataset
RETURN from
StockDownloader
AsyncTask
Done
f) Long-Press Delete Stock:
Delete Stock Process Flow
Display Delete Stock
Confirmation
Dialog
Long-Click on a
Stock from the
List in Main
Activity
Confirmed
Cancelled Done
Remove Stock
from Stock List
Delete Stock
from DB
Notify Adapter
of Changed
Dataset
CS 442 Mobile Applications
Development (Android Section)
© Christopher Hield 14 of 16
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);
}
CS 442 Mobile Applications
Development (Android Section)
© Christopher Hield 15 of 16
• 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; } CS 442 Mobile Applications Development (Android Section) © Christopher Hield 16 of 16 Assignment Assistance The TAs for our course is available to assist you with your assignment if needed. Questions on assignment requirements and course concepts can be sent to the instructor. 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.
3) Late submissions will be penalized by 10% per class late. (i.e., from one second late to 1 class late:
10% penalty, from one class plus one second late to 2 classes late: 20% penalty, etc.).
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!