Rev 18 |
View as "text/plain" |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
1
package de.pointedears.converter.helpers;
import android.app.Service;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
import de.pointedears.converter.app.CurrenciesActivity;
import de.pointedears.converter.net.RatesUpdater;
/**
* Update service to run a thread to update currency rates
*
* @author Thomas 'PointedEars' Lahn
*/
public class UpdateService
extends Service
{
private ConverterThread updateThread
;
private Handler handler
;
private RatesUpdater ratesUpdater
;
public static final String ACTION_UPDATE =
"de.pointedears.converter.ACTION_UPDATE"; //$NON-NLS-1$
public static final String EXTRA_ACTIVITY =
"de.pointedears.converter.extra_activity"; //$NON-NLS-1$
public static final String EXTRA_NUM_RATES =
"de.pointedears.converter.extra_num_rates"; //$NON-NLS-1$
public static final String EXTRA_DATE =
"de.pointedears.converter.extra_date"; //$NON-NLS-1$
/* NOTE: Don't remove; may be used later for automated updates */
// private sendTimerTask sendTime = null;
// /** inner class implements the broadcast timer */
// private class BroadcastTimerTask extends TimerTask
// {
// int counter = 0;
//
// @Override
// public void run()
// {
// Intent intent = new Intent(UpdateService.ACTION_UPDATE);
// String theTime =
// "Time: " + System.currentTimeMillis() + ", Counter = "
// + Integer.toString(this.counter);
// this.counter++;
// intent.putExtra("TIME", theTime);
// UpdateService.this.sendBroadcast(intent);
// }
// };
@
Override
public IBinder onBind
(Intent intent
)
{
/* NOTE: Clients cannot bind to this service */
return null;
}
@
Override
public void onCreate
()
{
super.
onCreate();
// this.myTimer = new Timer("myTimer");
if (this.
handler ==
null)
{
this.
handler =
new Handler();
}
this.
updateThread =
null;
}
// /*
// * (non-Javadoc)
// *
// * @see android.app.Service#onStartCommand(android.content.Intent, int, int)
// */
// @Override
// public int onStartCommand(Intent intent, int flags, int startId)
// {
// // TODO Auto-generated method stub
// return super.onStartCommand(intent, flags, startId);
// }
@
Override
/**
* @deprecated since SDK 2.0
*/
public void onStart
(Intent intent,
int startId
)
{
super.
onStart(intent, startId
);
// this.myTimer.cancel();
// this.myTimer = new Timer("myTimer");
// this.sendTime = new BroadcastTimerTask();
// this.myTimer.scheduleAtFixedRate(this.sendTime, 0, 1000 * 5);
String action = intent.
getAction();
if (UpdateService.
ACTION_UPDATE.
equals(action
))
{
if (this.
updateThread ==
null)
{
this.
ratesUpdater =
new RatesUpdater
(this);
this.
updateThread =
new ConverterThread
(this.
ratesUpdater,
this.
handler);
this.
ratesUpdater.
setUpdateThread(this.
updateThread);
}
try
{
this.
updateThread.
start();
// this.editValue1.setText("Gestartet!");
}
catch (IllegalThreadStateException e
)
{
// this.editValue1.setText("Bereits gestartet!");
}
// case R.id.item_options_quit:
// if (this.updateThread != null)
// {
// try
// {
// this.updateThread.join();
// }
// catch (InterruptedException e)
// {
// // TODO Auto-generated catch block
// }
//
// // this.editValue1.setText("Gestoppt -> Warten auf Start");
// }
// else
// {
// // this.editValue1.setText("Bereits gestoppt -> Warten auf Start");
// }
// return true;
}
}
}