Subversion Repositories ES

Rev

Rev 18 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
17 PointedEar 1
package de.pointedears.converter.helpers;
2
 
3
import android.app.Service;
4
import android.content.Intent;
5
import android.os.Handler;
6
import android.os.IBinder;
7
import de.pointedears.converter.app.CurrenciesActivity;
8
import de.pointedears.converter.net.RatesUpdater;
9
 
10
/**
11
 * Update service to run a thread to update currency rates
12
 *
13
 * @author Thomas 'PointedEars' Lahn
14
 */
15
public class UpdateService extends Service
16
{
17
  private ConverterThread updateThread;
18
  private Handler handler;
19
  private RatesUpdater ratesUpdater;
20
 
21
  public static final String ACTION_UPDATE =
22
    "de.pointedears.converter.ACTION_UPDATE"; //$NON-NLS-1$
23
  public static final String EXTRA_ACTIVITY =
24
    "de.pointedears.converter.extra_activity"; //$NON-NLS-1$
25
  public static final String EXTRA_NUM_RATES =
26
    "de.pointedears.converter.extra_num_rates"; //$NON-NLS-1$
27
  public static final String EXTRA_DATE = "de.pointedears.converter.extra_date"; //$NON-NLS-1$
28
 
18 PointedEar 29
  /* NOTE: Don't remove; may be used later for automated updates */
17 PointedEar 30
  // private sendTimerTask sendTime = null;
31
 
32
  // /** inner class implements the broadcast timer */
33
  // private class BroadcastTimerTask extends TimerTask
34
  // {
35
  // int counter = 0;
36
  //
37
  // @Override
38
  // public void run()
39
  // {
40
  // Intent intent = new Intent(UpdateService.ACTION_UPDATE);
41
  // String theTime =
42
  // "Time: " + System.currentTimeMillis() + ",  Counter = "
43
  // + Integer.toString(this.counter);
44
  // this.counter++;
45
  // intent.putExtra("TIME", theTime);
46
  // UpdateService.this.sendBroadcast(intent);
47
  // }
48
  // };
49
 
50
  @Override
51
  public IBinder onBind(Intent intent)
52
  {
53
    /* NOTE: Clients cannot bind to this service */
54
    return null;
55
  }
56
 
57
  @Override
58
  public void onCreate()
59
  {
60
    super.onCreate();
61
    // this.myTimer = new Timer("myTimer");
62
 
63
    if (this.handler == null)
64
    {
65
      this.handler = new Handler();
66
    }
67
 
68
    this.updateThread = null;
69
  }
70
 
71
  // /*
72
  // * (non-Javadoc)
73
  // *
74
  // * @see android.app.Service#onStartCommand(android.content.Intent, int, int)
75
  // */
76
  // @Override
77
  // public int onStartCommand(Intent intent, int flags, int startId)
78
  // {
79
  // // TODO Auto-generated method stub
80
  // return super.onStartCommand(intent, flags, startId);
81
  // }
82
 
83
  @Override
84
  /**
85
   * @deprecated since SDK 2.0
86
   */
87
  public void onStart(Intent intent, int startId)
88
  {
89
    super.onStart(intent, startId);
90
    // this.myTimer.cancel();
91
    // this.myTimer = new Timer("myTimer");
92
    // this.sendTime = new BroadcastTimerTask();
93
    // this.myTimer.scheduleAtFixedRate(this.sendTime, 0, 1000 * 5);
94
 
95
    String action = intent.getAction();
96
    if (UpdateService.ACTION_UPDATE.equals(action))
97
    {
98
      if (this.updateThread == null)
99
      {
20 PointedEar 100
        this.ratesUpdater = new RatesUpdater(this);
17 PointedEar 101
        this.updateThread =
102
          new ConverterThread(this.ratesUpdater, this.handler);
103
        this.ratesUpdater.setUpdateThread(this.updateThread);
104
      }
105
 
106
      try
107
      {
108
        this.updateThread.start();
109
        // this.editValue1.setText("Gestartet!");
110
      }
111
      catch (IllegalThreadStateException e)
112
      {
113
        // this.editValue1.setText("Bereits gestartet!");
114
      }
115
 
116
      // case R.id.item_options_quit:
117
      // if (this.updateThread != null)
118
      // {
119
      // try
120
      // {
121
      // this.updateThread.join();
122
      // }
123
      // catch (InterruptedException e)
124
      // {
125
      // // TODO Auto-generated catch block
126
      // }
127
      //
128
      // // this.editValue1.setText("Gestoppt -> Warten auf Start");
129
      // }
130
      // else
131
      // {
132
      // // this.editValue1.setText("Bereits gestoppt -> Warten auf Start");
133
      // }
134
      // return true;
135
    }
136
  }
137
}