Subversion Repositories ES

Compare Revisions

Last modification

Regard whitespace Rev 10 → Rev 11

/trunk/src/de/pointedears/converter/app/CurrenciesActivity.java
3,6 → 3,9
import java.util.HashMap;
 
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.os.Bundle;
import android.text.Editable;
import android.view.KeyEvent;
16,6 → 19,7
import android.widget.EditText;
import android.widget.Spinner;
import de.pointedears.converter.R;
import de.pointedears.converter.db.CurrenciesDatabase;
 
/**
* Activity that implements currency conversion
31,7 → 35,7
private static final String VALUE_EUR = "EUR"; //$NON-NLS-1$
private static final String VALUE_USD = "USD"; //$NON-NLS-1$
 
private static HashMap<String, HashMap<String, Double>> currencyConversions;
protected static HashMap<String, HashMap<String, Double>> currencyConversions;
 
/* Unit spinners (dropdowns) */
private Spinner spinnerUnit1;
45,7 → 49,7
super.onCreate(savedInstanceState);
this.setContentView(R.layout.activity_currencies);
 
/* TODO: Set up currency database */
/* Set up currency database */
CurrenciesActivity.currencyConversions =
new HashMap<String, HashMap<String, Double>>();
 
57,7 → 61,7
 
conversionFactors = new HashMap<String, Double>();
conversionFactors.put(CurrenciesActivity.VALUE_CHF, 1.30235077);
conversionFactors.put(CurrenciesActivity.VALUE_CHF, 1.3468);
conversionFactors.put(CurrenciesActivity.VALUE_USD, 1.3468);
CurrenciesActivity.currencyConversions.put(CurrenciesActivity.VALUE_EUR,
conversionFactors);
 
67,6 → 71,64
CurrenciesActivity.currencyConversions.put(CurrenciesActivity.VALUE_USD,
conversionFactors);
 
/* Create database with values above if it does not exist */
CurrenciesDatabase db = new CurrenciesDatabase(this);
try
{
SQLiteDatabase dbConn = db.getReadableDatabase();
 
@SuppressWarnings("nls")
Cursor myCursor =
dbConn.query(true, CurrenciesDatabase.TABLE, null, null, null, null,
null, CurrenciesDatabase.COLUMN_CURRENCY1 + ","
+ CurrenciesDatabase.COLUMN_CURRENCY2, null);
 
@SuppressWarnings({ "unused", "nls" })
String queryResult = "";
if (myCursor != null)
{
try
{
int currency1Id =
myCursor
.getColumnIndexOrThrow(CurrenciesDatabase.COLUMN_CURRENCY1);
int currency2Id =
myCursor
.getColumnIndexOrThrow(CurrenciesDatabase.COLUMN_CURRENCY2);
int factorId =
myCursor.getColumnIndexOrThrow(CurrenciesDatabase.COLUMN_FACTOR);
 
if (myCursor.moveToFirst())
{
do
{
String currency1Str = myCursor.getString(currency1Id);
String currency2Str = myCursor.getString(currency2Id);
Double factor = myCursor.getDouble(factorId);
 
/* DEBUG */
queryResult +=
currency1Str + " --> " + currency2Str + ": " + factor + "\n";
}
while (myCursor.moveToNext());
}
}
catch (IllegalArgumentException e)
{
/* Could not retrieve column index */
e.printStackTrace();
}
}
 
/* TODO: Close only on exit */
dbConn.close();
}
catch (SQLiteException e1)
{
/* Could not open database */
e1.printStackTrace();
}
 
final EditText editValue1 =
(EditText) this.findViewById(R.id.currencies_edit_value1);
final EditText editValue2 =
229,4 → 291,12
/* update here */
return super.onOptionsItemSelected(item);
}
 
/**
* @return
*/
public HashMap<String, HashMap<String, Double>> getCurrencyConversions()
{
return CurrenciesActivity.currencyConversions;
}
}