Permalink
Browse files

v0.7.1 - Data table clears if dividend parse fails

v0.7 - Added dividends
  • Loading branch information...
1 parent 5de79c5 commit e768491e2cfa0382c6c933e4b3a0fad3d37ad816 raad287 committed Nov 15, 2012
Showing with 145 additions and 21 deletions.
  1. +2 −2 AndroidManifest.xml
  2. +2 −2 bin/AndroidManifest.xml
  3. BIN bin/classes.dex
  4. BIN bin/classes/com/raad287/ltcglobal/BrowseActivity$1.class
  5. BIN bin/classes/com/raad287/ltcglobal/BrowseActivity$DownloadBrowse.class
  6. BIN bin/classes/com/raad287/ltcglobal/BrowseActivity.class
  7. BIN bin/classes/com/raad287/ltcglobal/BuildConfig.class
  8. BIN bin/classes/com/raad287/ltcglobal/MainActivity$1.class
  9. BIN bin/classes/com/raad287/ltcglobal/MainActivity$2.class
  10. BIN bin/classes/com/raad287/ltcglobal/MainActivity$3.class
  11. BIN bin/classes/com/raad287/ltcglobal/MainActivity$DownloadHistory$1.class
  12. BIN bin/classes/com/raad287/ltcglobal/MainActivity$DownloadHistory.class
  13. BIN bin/classes/com/raad287/ltcglobal/MainActivity$DownloadSecurity.class
  14. BIN bin/classes/com/raad287/ltcglobal/MainActivity$DownloadTicker.class
  15. BIN bin/classes/com/raad287/ltcglobal/MainActivity$SpinnerListener.class
  16. BIN bin/classes/com/raad287/ltcglobal/MainActivity.class
  17. BIN bin/classes/com/raad287/ltcglobal/R$array.class
  18. BIN bin/classes/com/raad287/ltcglobal/R$attr.class
  19. BIN bin/classes/com/raad287/ltcglobal/R$dimen.class
  20. BIN bin/classes/com/raad287/ltcglobal/R$drawable.class
  21. BIN bin/classes/com/raad287/ltcglobal/R$id.class
  22. BIN bin/classes/com/raad287/ltcglobal/R$layout.class
  23. BIN bin/classes/com/raad287/ltcglobal/R$menu.class
  24. BIN bin/classes/com/raad287/ltcglobal/R$string.class
  25. BIN bin/classes/com/raad287/ltcglobal/R$style.class
  26. BIN bin/classes/com/raad287/ltcglobal/R.class
  27. BIN bin/com.raad287.ltcglobal.MainActivity.apk
  28. BIN bin/resources.ap_
  29. +1 −0 res/values/arrays.xml
  30. +2 −2 src/com/raad287/ltcglobal/BrowseActivity.java
  31. +138 −15 src/com/raad287/ltcglobal/MainActivity.java
View
@@ -1,7 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.raad287.ltcglobal"
- android:versionCode="10"
- android:versionName="0.6" >
+ android:versionCode="12"
+ android:versionName="0.7.1" >
<uses-sdk
android:minSdkVersion="6"
View
@@ -1,7 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.raad287.ltcglobal"
- android:versionCode="8"
- android:versionName="0.5.1" >
+ android:versionCode="12"
+ android:versionName="0.7.1" >
<uses-sdk
android:minSdkVersion="6"
View
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
View
@@ -5,6 +5,7 @@
<item >Contract &amp; Prospectus</item>
<item >Notifications</item>
<item >Motions</item>
+ <item >Dividends</item>
</string-array>
</resources>
@@ -109,7 +109,7 @@ public void populateList(JSONObject jTickers)
{
try {
items[i]=jTickers.names().getString(i);
- Log.i("LG", "Item"+items[i]);
+ //Log.i("LG", "Item"+items[i]);
} catch (JSONException e) {
// if populateList fails finish the activity
Log.i("LG", "JSONException:"+e.getMessage());
@@ -120,7 +120,7 @@ public void populateList(JSONObject jTickers)
}
}
Arrays.sort(items);
- Log.i("LG", "Items:"+items.toString());
+ //Log.i("LG", "Items:"+items.toString());
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, items);
ListView lv_tickers = (ListView) this.findViewById(R.id.browse_listView_tickers);
@@ -224,14 +224,77 @@ public JSONObject parseNotificationsHTML(String sPage)
}
- Log.i("LG", "Parsed Notifications: "+sNotifications);
+ //Log.i("LG", "Parsed Notifications: "+sNotifications);
try {
jNotifications.put("string", sNotifications);
}catch (JSONException e) { Log.i("LG", e.getMessage()); }
return jNotifications;
}
+ public JSONObject parseDividendsHTML(String sPage)
+ {
+ Log.i("LG", "parseDividendsHTML");
+ JSONObject jDividends = new JSONObject();
+
+ int id_notification_start = sPage.indexOf("<th colspan=\"5\" scope=\"col\">Dividends</th>");
+ int id_notification_end = sPage.indexOf("<th colspan=\"3\" scope=\"col\">Trade History (last 20)</th>");
+
+ if (id_notification_start==-1 || id_notification_end==-1) { return null; }
+
+ String sDividends= sPage.substring(id_notification_start, id_notification_end);
+ sDividends = stripHTML(sDividends);
+
+ StringBuffer sb = new StringBuffer();
+
+ //Filter out \r and \t from
+ for (int j = 0; j < sDividends.length(); j++) {
+ if ((sDividends.charAt(j) != '\r') && (sDividends.charAt(j) != '\t')) {
+
+ // Filter out &xx;
+ if(j<sDividends.length()-2) {
+ if( (sDividends.charAt(j)!='&') && (sDividends.charAt(j+2)!=';') )
+ {
+ sb.append(sDividends.charAt(j));
+ }
+ else {
+ // skip over
+ j=j+3;
+ }
+ }else
+ { sb.append(sDividends.charAt(j)); }
+
+ }}
+ sDividends = sb.toString();
+
+ // Filter out leading newline's and whitespace
+ int marker=0;
+ for (int i=0; i<sDividends.length(); i++)
+ {
+ if(sDividends.charAt(i)!=(' ') && sDividends.charAt(i)!=('\r')
+ && sDividends.charAt(i)!=('\r'))
+ {
+ marker=i;
+ break;
+ }
+ }
+
+ StringBuilder sb2 = new StringBuilder(sDividends);
+ if(sDividends.length()>11)
+ {
+ sb2.delete(0, 10);
+ sDividends = sb2.toString();
+ }
+
+ //Log.i("LG", "Parsed Dividends: "+sDividends);
+ try {
+ jDividends.put("string", sDividends);
+ }catch (JSONException e) { Log.i("LG", e.getMessage()); }
+
+ return jDividends;
+ }
+
+
public JSONObject parseMotionsHTML(String sPage)
{
Log.i("LG", "parseMotionsHTML");
@@ -281,7 +344,7 @@ public JSONObject parseMotionsHTML(String sPage)
}
- Log.i("LG", "Parsed Notifications: "+sMotions);
+ //Log.i("LG", "Parsed Notifications: "+sMotions);
try {
jMotions.put("string", sMotions);
}catch (JSONException e) { Log.i("LG", e.getMessage()); }
@@ -539,7 +602,7 @@ public void fillTable(JSONObject jHistory, boolean desc)
}
// Get ids
- Log.i("LG", "Get Ids");
+ //Log.i("LG", "Get Ids");
JSONArray jIds = new JSONArray();
jIds = jHistory.names();
if(jIds==null)
@@ -566,7 +629,7 @@ public void fillTable(JSONObject jHistory, boolean desc)
}
// Fill Layout
- Log.i("LG", "Fill Layout");
+ //Log.i("LG", "Fill Layout");
// Description Row
TableRow tr_desc = new TableRow(this);
@@ -593,7 +656,7 @@ public void fillTable(JSONObject jHistory, boolean desc)
tl_trade_history.addView(tr_desc);
for (int i=0; i<num_trades; i++)
{
- Log.i("LG", "Fill Table");
+ //Log.i("LG", "Fill Table");
// Trade Row
TableRow tr_trade = new TableRow(this);
tr_trade.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
@@ -614,7 +677,7 @@ public void fillTable(JSONObject jHistory, boolean desc)
Log.i("LG", "JSONException:"+e.getMessage());
}
- Log.i("LG", "Add TextViews");
+ //Log.i("LG", "Add TextViews");
tr_trade.addView(tv_timestamp);
tr_trade.addView(tv_amount);
tr_trade.addView(tv_quantity);
@@ -818,7 +881,8 @@ else if(type.equals("Motions"))
}
else if(type.equals("Dividends"))
{
-
+ new DownloadTicker().execute(ticker);
+ new DownloadDividends().execute(ticker);
}
else if(type.equals("Contract & Prospectus"))
{
@@ -832,6 +896,67 @@ else if(type.equals("Notifications"))
}
}
+ public class DownloadDividends extends AsyncTask<String, Integer, JSONObject>
+ {
+ @Override
+ protected void onPreExecute() {
+ TextView tv = (TextView) findViewById(R.id.main_tv_downloading);
+ tv.setText("Downloading Dividends...");
+ tv.invalidate();
+ super.onPreExecute();
+ }
+
+ @Override
+ // doInBackground: take string array containing ticker names and download
+ protected JSONObject doInBackground(String... tickers) {
+ Log.i("LG", "MainActivity:DownloadMotions:doInBackground: Executing download dividends");
+
+ HttpClient http_client = new DefaultHttpClient();
+ StringBuilder sb = new StringBuilder();
+ HttpGet http_get = new HttpGet(URL_API_SECURITY+tickers[0]);
+
+ try {
+ HttpResponse http_response=http_client.execute(http_get);
+ sb.append(EntityUtils.toString(http_response.getEntity()));
+ } catch (Exception e) { Log.i("LG", "Exception:"+e.getMessage()); }
+
+ // Check for errors
+ if(sb.toString().contains("only please") || sb.toString().startsWith("0")
+ || sb.toString().contains("Error")) // error
+ {
+ return null;
+ }
+
+ //return sb.toString();
+ return parseDividendsHTML(sb.toString());
+ }
+
+ @Override
+ protected void onPostExecute(JSONObject jPage) {
+ TextView tv = (TextView) findViewById(R.id.main_tv_downloading);
+ Log.i("LG", "Notification download postExecute");
+
+ //JSONObject jMotions = parseMotionsHTML(sPage);
+ if(jPage!=null) {
+ fillNotifications(jPage, "Dividends");
+ tv.setText("Success");
+ }
+ else {
+ tv.setText("No Dividends, or failed to parse");
+ TableLayout tl_data = (TableLayout)findViewById(R.id.main_tableLayout_data);
+ tl_data.removeAllViews();
+ tl_data.invalidate();
+
+ }
+ tv.invalidate();
+
+ super.onPostExecute(jPage);
+ }
+ }
+
+
+
+
public class DownloadHistory extends AsyncTask<String, Integer, JSONObject>
{
@@ -847,7 +972,7 @@ protected void onPreExecute() {
@Override
// doInBackground: take string array containing ticker names and download
protected JSONObject doInBackground(String... tickers) {
- Log.i("LG", "MainActivity:DownloadURL:doInBackground: Executing download trades");
+ Log.i("LG", "MainActivity:DownloadURL:doInBackground: Executing download history");
HttpClient http_client = new DefaultHttpClient();
StringBuilder sb = new StringBuilder();
@@ -929,7 +1054,7 @@ protected void onPreExecute() {
@Override
// doInBackground: take string array containing ticker names and download
protected JSONObject doInBackground(String... tickers) {
- Log.i("LG", "MainActivity:DownloadURL:doInBackground: Executing download trades");
+ Log.i("LG", "MainActivity:DownloadURL:doInBackground: Executing download ticker");
HttpClient http_client = new DefaultHttpClient();
StringBuilder sb = new StringBuilder();
@@ -980,7 +1105,7 @@ protected void onPreExecute() {
@Override
// doInBackground: take string array containing ticker names and download
protected JSONObject doInBackground(String... tickers) {
- Log.i("LG", "MainActivity:DownloadURL:doInBackground: Executing download trades");
+ Log.i("LG", "MainActivity:DownloadURL:doInBackground: Executing download security");
HttpClient http_client = new DefaultHttpClient();
StringBuilder sb = new StringBuilder();
@@ -1030,7 +1155,7 @@ protected void onPreExecute() {
@Override
// doInBackground: take string array containing ticker names and download
protected JSONObject doInBackground(String... tickers) {
- Log.i("LG", "MainActivity:DownloadURL:doInBackground: Executing download trades");
+ Log.i("LG", "MainActivity:DownloadURL:doInBackground: Executing download notifications");
HttpClient http_client = new DefaultHttpClient();
StringBuilder sb = new StringBuilder();
@@ -1082,7 +1207,7 @@ protected void onPreExecute() {
@Override
// doInBackground: take string array containing ticker names and download
protected JSONObject doInBackground(String... tickers) {
- Log.i("LG", "MainActivity:DownloadMotions:doInBackground: Executing download trades");
+ Log.i("LG", "MainActivity:DownloadMotions:doInBackground: Executing download motions");
HttpClient http_client = new DefaultHttpClient();
StringBuilder sb = new StringBuilder();
@@ -1121,9 +1246,7 @@ protected void onPostExecute(JSONObject jPage) {
}
}
-
-
- @Override
+ @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

0 comments on commit e768491

Please sign in to comment.