Subversion Repositories ES

Compare Revisions

Last modification

Ignore whitespace Rev 14 → Rev 15

/trunk/src/de/pointedears/converter/app/CurrenciesActivity.java
23,6 → 23,7
import android.widget.TextView;
import de.pointedears.converter.R;
import de.pointedears.converter.db.CurrenciesDatabase;
import de.pointedears.converter.helpers.CurrenciesUpdateThread;
 
/**
* Activity that implements currency conversion
278,15 → 279,19
*
* @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem)
*/
/*
* (non-Javadoc)
*
* @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem)
*/
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
/* update here */
return super.onOptionsItemSelected(item);
// Handle item selection
switch (item.getItemId())
{
case R.id.item_options_update:
Thread updateThread = new CurrenciesUpdateThread();
updateThread.start();
return true;
 
default:
return super.onOptionsItemSelected(item);
}
}
}
/trunk/src/de/pointedears/converter/helpers/CurrenciesUpdateThread.java
New file
0,0 → 1,105
/**
* Defines a class to update table rates in the background
*/
package de.pointedears.converter.helpers;
 
import java.io.IOException;
 
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
 
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
 
/**
* @author pelinux
*
*/
public class CurrenciesUpdateThread extends Thread
{
private static final String URL_ECB =
"http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"; //$NON-NLS-1$
 
/**
* Default constructor which sets the runnable
*
* @param runnable
*/
private CurrenciesUpdateThread(Runnable runnable)
{
super(runnable);
}
 
/**
* Default constructor
*/
public CurrenciesUpdateThread()
{
this(new Runnable() {
@Override
public void run()
{
DocumentBuilderFactory documentBuilderFactory =
DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
try
{
DocumentBuilder builder =
documentBuilderFactory.newDocumentBuilder();
try
{
Document doc = builder.parse(CurrenciesUpdateThread.URL_ECB);
XPathFactory xpathFactory = XPathFactory.newInstance();
XPath xpath = xpathFactory.newXPath();
try
{
XPathExpression expr = xpath.compile("/Cube/Cube//Cube"); //$NON-NLS-1$
Object result = expr.evaluate(doc, XPathConstants.NODESET);
NodeList nodes = (NodeList) result;
for (int i = 0, len = nodes.getLength(); i < len; i++)
{
Node item = nodes.item(i);
NamedNodeMap attributes = item.getAttributes();
String currency =
attributes.getNamedItem("currency").getNodeValue(); //$NON-NLS-1$
String rate = attributes.getNamedItem("rate").toString(); //$NON-NLS-1$
 
/* TODO: Update UI */
System.out.println(currency + ": " + rate); //$NON-NLS-1$
}
}
catch (XPathExpressionException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
catch (SAXException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
catch (ParserConfigurationException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
}
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: trunk/bin/resources.ap_
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: trunk/bin/classes.dex
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: trunk/bin/Converter.apk
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: trunk/res/menu/options.xml
===================================================================
--- trunk/res/menu/options.xml (revision 14)
+++ trunk/res/menu/options.xml (revision 15)
@@ -6,7 +6,8 @@
android:title="@string/caption_update" />
<!-- android:icon="@drawable/ic_quit" -->
-
+<!--
<item android:id="@+id/quit"
android:title="@string/option_quit" />
+ -->
</menu>
\ No newline at end of file
/trunk/res/layout/activity_currencies.xml
27,17 → 27,20
android:entryValues="@array/currency_units_values" />
</TableRow>
</TableLayout>
 
<Button android:text="@string/button_clear" android:id="@+id/currencies_button_clear"
android:layout_height="wrap_content" android:layout_width="100sp"
android:layout_gravity="center_horizontal"></Button>
 
<TableLayout android:id="@+id/currencies_table_rates"
android:scrollbars="vertical" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:stretchColumns="*">
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:scrollbars="vertical" android:stretchColumns="*">
<View android:layout_height="2dip" android:background="#FF909090" />
<TableRow>
<TextView android:text="@string/currencies_currency1" />
<TextView android:text="@string/currencies_currency2" />
<TextView android:text="@string/currencies_rate" />
</TableRow>
<View android:layout_height="1dip" android:background="#FF909090" />
</TableLayout>
</LinearLayout>
/trunk/res/values/strings.xml
2,6 → 2,7
<resources>
<string name="app_name">Converter</string>
<string name="title">Android Unit Converter</string>
<string name="button_clear">Clear</string>
 
<string name="activity_lengths">Lengths</string>
 
12,10 → 13,6
<string name="currencies_currency1"><b>Currency 1</b></string>
<string name="currencies_currency2"><b>Currency 2</b></string>
<string name="currencies_rate"><b>Rate</b></string>
 
<string name="caption_update">Update</string>
<string name="option_quit">Quit</string>
<string name="bar">Quit</string>
<string name="button_clear">Clear</string>
 
<string name="caption_update">Update table rates</string>
<!-- <string name="option_quit">Quit</string> -->
</resources>