altosdroid: Clean up imports in TelemetryService
[fw/altos] / altosdroid / src / org / altusmetrum / AltosDroid / TelemetryService.java
1 /*
2  * Copyright © 2012 Mike Beattie <mike@ethernal.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 package org.altusmetrum.AltosDroid;
19
20 import android.app.Notification;
21 import android.app.NotificationManager;
22 import android.app.PendingIntent;
23 import android.app.Service;
24 import android.content.Intent;
25 import android.os.Binder;
26 import android.os.IBinder;
27 import android.util.Log;
28 import android.widget.Toast;
29
30 // Need the following import to get access to the app resources, since this
31 // class is in a sub-package.
32 //import org.altusmetrum.AltosDroid.R;
33
34 import org.altusmetrum.AltosLib.*;
35
36 public class TelemetryService extends Service {
37
38         private static final String TAG = "TelemetryService";
39         private static final boolean D = true;
40
41     /**
42      * Class for clients to access.  Because we know this service always
43      * runs in the same process as its clients, we don't need to deal with
44      * IPC.
45      */
46     public class TelemetryBinder extends Binder {
47         TelemetryService getService() {
48             return TelemetryService.this;
49         }
50     }
51         // Unique Identification Number for the Notification.
52         // We use it on Notification start, and to cancel it.
53         private int NOTIFICATION = R.string.telemetry_service_label;
54         private NotificationManager mNM;
55
56
57         // Name of the connected device
58         private String mConnectedDeviceName = null;
59         private AltosBluetooth mAltosBluetooth = null;
60
61         LinkedBlockingQueue<AltosLine> telem;
62
63         @Override
64         public void onCreate() {
65                 // Create a reference to the NotificationManager so that we can update our notifcation text later
66                 mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
67         }
68
69         @Override
70         public int onStartCommand(Intent intent, int flags, int startId) {
71                 Log.i("TelemetryService", "Received start id " + startId + ": " + intent);
72
73                 CharSequence text = getText(R.string.telemetry_service_started);
74
75                 // Create notification to be displayed while the service runs
76                 Notification notification = new Notification(R.drawable.am_status_c, text, 0);
77
78                 // The PendingIntent to launch our activity if the user selects this notification
79                 PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
80                                 new Intent(this, AltosDroid.class), 0);
81
82                 // Set the info for the views that show in the notification panel.
83                 notification.setLatestEventInfo(this, getText(R.string.telemetry_service_label), text, contentIntent);
84
85                 // Set the notification to be in the "Ongoing" section.
86                 notification.flags |= Notification.FLAG_ONGOING_EVENT;
87
88                 // Move us into the foreground.
89                 startForeground(NOTIFICATION, notification);
90
91                 // We want this service to continue running until it is explicitly
92                 // stopped, so return sticky.
93                 return START_STICKY;
94         }
95
96         @Override
97         public void onDestroy() {
98
99
100                 // Demote us from the foreground, and cancel the persistent notification.
101                 stopForeground(true);
102
103                 // Tell the user we stopped.
104                 Toast.makeText(this, R.string.telemetry_service_stopped, Toast.LENGTH_SHORT).show();
105         }
106
107         @Override
108         public IBinder onBind(Intent intent) {
109         return mBinder;
110         }
111
112     // This is the object that receives interactions from clients.  See
113     // RemoteService for a more complete example.
114     private final IBinder mBinder = new TelemetryBinder();
115
116 }