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