Subversion Repositories ES

Compare Revisions

Last modification

Ignore whitespace Rev 19 → Rev 20

/trunk/res/values/strings.xml
10,10 → 10,17
<string name="temperatures_off_scale"><sup>*</sup> Theoretical value off the scale</string>
 
<string name="activity_currencies">Currencies</string>
<string name="currencies_CHF">CHF</string>
<string name="currencies_EUR">EUR</string>
<string name="currencies_USD">USD</string>
<string name="currencies_notification">&#xA0;exchange rates updated to&#xA0;</string>
<string name="currencies_updating">Updating table rates ...</string>
<string name="currencies_currency"><b>Currency</b></string>
<string name="currencies_rate"><b>Rate (1 EUR)</b></string>
<string name="currencies_updated"><b>Updated</b></string>
<string name="currencies_never_updated"><b>Updated</b></string>
<string name="caption_update">Update exchange rates</string>
<string name="option_quit">Quit</string>
<string name="activity_browser">Browser</string>
</resources>
/trunk/src/de/pointedears/converter/app/CurrenciesActivity.java
1,7 → 1,6
package de.pointedears.converter.app;
 
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map.Entry;
44,13 → 43,8
/**
* String to use to indicate that an exchange rate has never been updated
*/
private static final String TEXT_NEVER = "never";
private String TEXT_NEVER;
 
/**
* Serialization version id
*/
private static final long serialVersionUID = 1L;
 
/*
* Constants for mapping value strings
*
59,26 → 53,30
/**
* Database field/spinner value for Swiss Francs
*/
public static final String VALUE_CHF = "CHF"; //$NON-NLS-1$
public static String VALUE_CHF;
 
/**
* Database field/spinner value for Euros
*/
public static String VALUE_EUR;
 
public static final String VALUE_EUR = "EUR"; //$NON-NLS-1$
 
/**
* Database field/spinner value for US Dollars
*/
public static final String VALUE_USD = "USD"; //$NON-NLS-1$
public static String VALUE_USD;
 
/* Unit spinners (dropdowns) */
private Spinner spinnerUnit1;
private Spinner spinnerUnit2;
private CurrenciesDatabase database;
private static CurrenciesDatabase database;
 
private HashMap<String, ConversionData> conversionRates;
private static HashMap<String, ConversionData> conversionRates;
 
private static String EXCHANGE_RATES_UPDATED_TO;
 
private final static DateFormat dateFormatter = DateFormat
.getDateInstance(DateFormat.SHORT);
 
/**
* Receiver for intent broadcasts, registered in
* {@link CurrenciesActivity#onCreate(Bundle)}
88,8 → 86,6
/**
* Notification message template
*/
private static final String EXCHANGE_RATES_UPDATED_TO =
" exchange rates updated to ";
 
/*
* (non-Javadoc)
105,11 → 101,12
CurrenciesActivity.this.fillTableRates();
 
Bundle extras = intent.getExtras();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); //$NON-NLS-1$
Notifier.sendMessage(CurrenciesActivity.this,
Notifier.sendMessage(
CurrenciesActivity.this,
extras.get(UpdateService.EXTRA_NUM_RATES)
+ UpdateBroadcastReceiver.EXCHANGE_RATES_UPDATED_TO
+ df.format(extras.get(UpdateService.EXTRA_DATE)));
+ CurrenciesActivity.EXCHANGE_RATES_UPDATED_TO
+ CurrenciesActivity.dateFormatter.format(extras
.get(UpdateService.EXTRA_DATE)));
}
}
}
121,12 → 118,23
super.onCreate(savedInstanceState);
this.setContentView(R.layout.activity_currencies);
 
this.TEXT_NEVER =
this.getString(R.string.currencies_never_updated);
 
CurrenciesActivity.VALUE_CHF = this.getString(R.string.currencies_CHF);
CurrenciesActivity.VALUE_EUR = this.getString(R.string.currencies_EUR);
CurrenciesActivity.VALUE_USD = this.getString(R.string.currencies_USD);
 
CurrenciesActivity.EXCHANGE_RATES_UPDATED_TO =
this.getString(R.string.currencies_notification);
 
UpdateBroadcastReceiver br = new UpdateBroadcastReceiver();
this.registerReceiver(br, new IntentFilter(UpdateService.ACTION_UPDATE));
 
/* Set up currency database, and retrieve conversion rates */
this.database = new CurrenciesDatabase(this);
this.setConversionRates(this.getDatabase().getConversionRates());
CurrenciesActivity.database = new CurrenciesDatabase(this);
this.setConversionRates(CurrenciesActivity.database
.getConversionRates());
this.fillTableRates();
 
final EditText editValue1 =
258,7 → 266,8
tableRates.removeViewAt(3);
}
 
for (Entry<String, ConversionData> factorEntry : this.getConversionRates()
for (Entry<String, ConversionData> factorEntry : CurrenciesActivity
.getConversionRates()
.entrySet())
{
TableRow row = new TableRow(this);
276,13 → 285,11
Date updated = conversionData.getUpdated();
if (updated.getTime() > 0)
{
DateFormat df =
DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
columnUpdated.setText(df.format(updated));
columnUpdated.setText(CurrenciesActivity.dateFormatter.format(updated));
}
else
{
columnUpdated.setText(CurrenciesActivity.TEXT_NEVER);
columnUpdated.setText(this.TEXT_NEVER);
}
 
row.addView(columnUpdated);
321,7 → 328,8
Double factorToEuro = 1.0;
if (selectedItemValue1 != null)
{
conversionData1 = this.getConversionRates().get(selectedItemValue1);
conversionData1 =
CurrenciesActivity.getConversionRates().get(selectedItemValue1);
if (conversionData1 != null)
{
factorToEuro = conversionData1.getRate();
332,7 → 340,8
Double factorFromEuro = 1.0;
if (selectedItemValue2 != null)
{
conversionData2 = this.getConversionRates().get(selectedItemValue2);
conversionData2 =
CurrenciesActivity.getConversionRates().get(selectedItemValue2);
if (conversionData2 != null)
{
factorFromEuro = conversionData2.getRate();
380,13 → 389,6
*/
Intent intent = new Intent(this, UpdateService.class);
intent.setAction(UpdateService.ACTION_UPDATE);
 
/*
* FIXME: Not thread-safe!
* Get the activity context from the intent directly instead
*/
UpdateService.setActivityContext(this);
 
this.startService(intent);
return true;
 
398,9 → 400,9
/**
* @return the conversionRates
*/
public HashMap<String, ConversionData> getConversionRates()
public static HashMap<String, ConversionData> getConversionRates()
{
return this.conversionRates;
return CurrenciesActivity.conversionRates;
}
 
/**
409,14 → 411,14
*/
public void setConversionRates(HashMap<String, ConversionData> conversionRates)
{
this.conversionRates = conversionRates;
CurrenciesActivity.conversionRates = conversionRates;
}
 
/**
* @return the database
*/
public CurrenciesDatabase getDatabase()
public static CurrenciesDatabase getDatabase()
{
return this.database;
return CurrenciesActivity.database;
}
}
/trunk/src/de/pointedears/converter/MenuActivity.java
32,7 → 32,6
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import de.pointedears.converter.helpers.UpdateService;
 
/**
* Generates the main menu as a list of activities from the manifest
49,8 → 48,6
{
super.onCreate(savedInstanceState);
 
this.startService(new Intent(this, UpdateService.class));
 
Intent intent = this.getIntent();
String path = intent.getStringExtra("de.pointedears.converter.Path"); //$NON-NLS-1$
 
/trunk/src/de/pointedears/converter/helpers/UpdateService.java
14,9 → 14,6
*/
public class UpdateService extends Service
{
// private Timer myTimer = null;
// private final BroadcastTimerTask sendTime = null;
private static CurrenciesActivity activityContext;
private ConverterThread updateThread;
private Handler handler;
private RatesUpdater ratesUpdater;
100,8 → 97,7
{
if (this.updateThread == null)
{
this.ratesUpdater =
new RatesUpdater(UpdateService.activityContext, this);
this.ratesUpdater = new RatesUpdater(this);
this.updateThread =
new ConverterThread(this.ratesUpdater, this.handler);
this.ratesUpdater.setUpdateThread(this.updateThread);
138,13 → 134,4
// return true;
}
}
 
/**
* @param activityContext
* the activityContext to set
*/
public static void setActivityContext(CurrenciesActivity activityContext)
{
UpdateService.activityContext = activityContext;
}
}
/trunk/src/de/pointedears/converter/net/RatesUpdater.java
26,9 → 26,6
 
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import de.pointedears.converter.R;
import de.pointedears.converter.app.CurrenciesActivity;
import de.pointedears.converter.db.ConversionData;
import de.pointedears.converter.helpers.ConverterThread;
50,7 → 47,6
private static final String URL_ECB =
"http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"; //$NON-NLS-1$
 
private final CurrenciesActivity activityContext;
private ConverterThread updateThread = null;
 
private final UpdateService service;
62,10 → 58,8
* @param updateService
* The service that started this updater
*/
public RatesUpdater(CurrenciesActivity activityContext,
UpdateService updateService)
public RatesUpdater(UpdateService updateService)
{
this.activityContext = activityContext;
this.service = updateService;
}
 
100,10 → 94,10
 
if (this.getUpdateThread() != null)
{
TextView textUpdating =
(TextView) this.activityContext
.findViewById(R.id.currencies_text_updating);
textUpdating.setVisibility(View.VISIBLE);
// TextView textUpdating =
// (TextView) this.activityContext
// .findViewById(R.id.currencies_text_updating);
// textUpdating.setVisibility(View.VISIBLE);
 
DocumentBuilderFactory documentBuilderFactory =
DocumentBuilderFactory.newInstance();
163,7 → 157,7
len = childCubes.getLength();
 
HashMap<String, ConversionData> conversionRates =
this.activityContext.getConversionRates();
CurrenciesActivity.getConversionRates();
for (int i = 0; i < len; ++i)
{
Element item = (Element) childCubes.item(i);
182,7 → 176,7
}
}
 
this.activityContext.getDatabase().writeConversionsToDatabase(null);
CurrenciesActivity.getDatabase().writeConversionsToDatabase(null);
}
catch (XPathExpressionException e)
{
218,7 → 212,7
this.service.sendBroadcast(intent);
}
 
textUpdating.setVisibility(View.GONE);
// textUpdating.setVisibility(View.GONE);
}
}
}
/trunk/src/de/pointedears/converter/ConverterApplication.java
5,6 → 5,8
package de.pointedears.converter;
 
import android.app.Application;
import android.content.Intent;
import de.pointedears.converter.helpers.UpdateService;
 
/**
* Converter application class. Holds the intent category for building
28,6 → 30,8
@Override
public void onCreate()
{
this.startService(new Intent(this, UpdateService.class));
 
/*
* This populates the default values from the preferences XML file. See
* {@link DefaultValues} for more details.