Starting from:
$35

$29

Assignment 3 Stock Watch SOlution

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:




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










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",
"date": "2018-09-21",
"name": "ICON USD",
"isEnabled": true,
"date": "2018-09-21",
"type": "cs",
"isEnabled": true,
"iexId": "2"
"type": "crypto",
}, {
"iexId": 10000013
"symbol": "AA",
}, {
"name": "Alcoa Corporation",
"symbol": "NEOUSDT",
"date": "2018-09-21",
"name": "NEO USD",
"isEnabled": true,
"date": "2018-09-21",
"type": "cs",
"isEnabled": true,
"iexId": "12042"
"type": "crypto",
}, {
"iexId": 10000014
"symbol": "AAAU",
}, {
"name": "Perth Mint Physical Gold",
"symbol": "VENUSDT",
"date": "2018-09-21",
"name": "VeChain USD",
"isEnabled": true,
"date": "2018-09-21",
"type": "N/A",
"isEnabled": true,
"iexId": "14924"
"type": "crypto",
}, {
"iexId": 10000015
"symbol": "AABA",
}, {
"name": "Altaba Inc.",
"symbol": "XLMUSDT",
"date": "2018-09-21",
"name": "Stellar Lumens USD",
"isEnabled": true,
"date": "2018-09-21",
"type": "cs",
"isEnabled": true,
"iexId": "7653"
"type": "crypto",
}, {
"iexId": 10000016
"symbol": "AAC",
}, {
"name": "AAC Holdings Inc.",
"symbol": "QTUMUSDT",
"date": "2018-09-21",
"name": "Qtum USD",
"isEnabled": true,
"date": "2018-09-21",
"type": "cs",
"isEnabled": true,
"iexId": "9169"
"type": "crypto",
}, {
"iexId": 10000017
. . .
}]


© Christopher Hield
2 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.




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":
"TSLA",










"companyName":
"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,
"close": 299.1,


"change":
0.77,
"closeTime": 1537560000292,


"changePercent":
0.258,
"high": 300.58,
"iexMarketPercent": 0,
"low": 295.37,
"iexVolume": null,


"latestPrice":
299.1,
"avgTotalVolume": 9530433,
"latestSource": "Close",
"iexBidPrice": null,
"latestTime": "September 21, 2018",
"iexBidSize": 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.






















 
Application Behavior Diagrams:




 
App MainActivity



















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.













Clicking on a Stock entry opens a




web browser to the Market




Watch website site for the




selected stock

CS 442 Mobile Applications Development (Android Section)































“Add Stock” action is

an Options-Menu




with a single item




(shown as Icon)
















A scrollbar should be




present along the




right-hand side



















Long-Click on a Stock




entry to delete (with

delete confirmation)




RecyclerView list




entries have their

own layout


 
Adding a stock – when only one stock matches the search symbol/name search string (NOTE: The Stock Selection dialog should only allow capital letters):








































AMZN







 
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):










3) Adding a stock with no Network Connection – test using “Airplane Mode” (No buttons on the error dialog):







 
Adding a stock – specified stock is a duplicate (Stock Selection dialog should only allow capital letters, No buttons on the warning dialog):










AMZN










 
Adding a stock – specified stock is not found (Stock Selection dialog should only allow capital letters, No buttons on the dialog):




WXYZ













6) Swipe-Refresh (pull-down) reloads (re-downloads) all stock data:













7) Swipe-Refresh attempt with no network connection (No buttons on the error dialog):










8) Long-Press on a stock to delete it:




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




For example: http://www.marketwatch.com/investing/stock/TSLA







 
Application Behavior Flowcharts:




 
App Startup




MainActivity


Execute






Get all Stocks from




Connected to








NameDownloader






the DB, store in a






No
onCreate














Network?






AsyncTask








Temporary List


































































Yes




























































































Startup Process Flow














Show No-Network




































Error Dialog


























For Each Stock in








































































the Temporary








































Put all stocks in the


























Stock List:


































display, with price,






































































change & percent






































































change as zero.
























More
Next Stock


































Stocks
No more stocks








































































to process










































Sort Stock List










































Notify Adapter














Execute
















of Changed


Done






StockDownloader


































Dataset














AsyncTask


































Notify Adapter


















































































































of Changed






























































RETURN from


Done


Dataset
















Add Stock to






























































































Sort Stock List






StockDownloader


















Stock List


































AsyncTask

























































































b) NameDownloader (AsyncTask)








Download stock






Add symbol &


Connect to data




Parse symbol &


names to




symbols & names




Done
provider via API




name data


symbol:name


JSON
















HashMap






































c) StockDownloader (AsyncTask)







Using provided stock
















Create Stock object




symbol, connect to




Download stock




Parse symbol &




















& pass it back to


Done
stock data provider




data JSON




name data


















MainActivity




via API














































































© Christopher Hield
10 of 16
CS 442 Mobile Applications




Development (Android Section)







d) Add New Stock Process







Select










Display Add Stock
Add Stock




Connected to




Menu option




Yes


Symbol Entry




Network?


from Main








Dialog










Activity




















No


















































Get matching
DONE






Show Error Dialog




symbols/names










from




























NameDownloader


























Did you




Display a list of the










resulting Stock Symbols


No Stock Found
Get a Stock
Multiple Stocks






& Company Names in a






result?














Dialog












Dialog












Cancelled

ONE Stock




Show Error Dialog




Use selected symbol to




execute
Selection Made


StockDownloader






AsyncTask
Yes
DONE






DONE




RETURN from

StockDownloader Duplicate

AsyncTask Stock?










Add Stock Process Flow







No




Add Stock to

Stock List













Sort Stock List












e) Swipe-Refresh (pull-down) List:







onSwipe
Get all Stocks from


Connected to


the DB, store in a


No
Refresh


Network?
Temporary List


















Yes
























SwipeRefresh Process Flow


Show No-Network










Error Dialog




For Each Stock in














the Temporary








Stock List:






















More
Next Stock


Stocks
No more stocks






to process















Notify Adapter






Execute


of Changed


Done


StockDownloader


Dataset






AsyncTask












Done


















RETURN from




Add Stock to










Sort Stock List


StockDownloader




Stock List








AsyncTask

































 
Long-Press Delete Stock:




Delete Stock Process Flow
Long-Click on a
Display Delete Stock
Stock from the




Confirmation
List in Main
Dialog
Activity



















Cancelled Done





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);

}










 
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;

}







 
Development Plan







 
Create the base app:




 
MainActivity with RecyclerView & SwipeRefreshLayout




 
Stock Class




 
RecyclerView Adapter




 
RecyclerView ViewHolder




 
Create fake “dummy” stocks to populate the list in the MainActivity onCreate.




 
Add the onClick and onLongClick methods. The onLongClick should delete an entry. The onClick can open a Toast message for now.




 
Add Stock options-menu opens dialog, on confirmation you can open a Toast message for now.




 
SwipeRefresh callback method can open a Toast message for now.













 
Add the database elements:




 
Create the database handler.




 
Add database handler calls to MainActivity (load, add, delete)




 
Code the onClick method to open the browser to the stock’s Market Watch site.













 
Add the internet elements and final integration:




 
Create the Stock Symbol - Company Name downloader/parser AsyncTask (http://d.yimg.com/aq/autoc)




 
Create the Stock Financial Data downloader/parser AsyncTask (finance.google.com)




 
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.



 
Add a method to MainActivity that allows the Stock Financial Data downloader/parser AsyncTask to send the newly created Stock back to MainActivity.




 
Implement the Add Stock feature (this uses the results of the above tasks)




 
Implement the SwipeRefresh callback to re-download the Stock Financial Data for the loaded stocks




 
Add alerts when startup, add, & refresh are attempted when no internet connection is available.




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




 
Submissions must consist of your zipped project folder (please execute Build =Clean Project before generating the zip file).




 
Submissions should reflect the concepts and practices we cover in class, and the requirements specified in this document.




 
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.).




 
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.






More products