]>
Commit | Line | Data |
---|---|---|
8dfb76c9 MG |
1 | package ro.ieval.fonbot; |
2 | ||
3 | import org.eclipse.jdt.annotation.Nullable; | |
4 | ||
5 | import android.content.Context; | |
6 | import android.content.Intent; | |
7 | import android.os.Handler; | |
8 | import android.os.Looper; | |
9 | ||
10 | import com.google.android.gcm.GCMBaseIntentService; | |
11 | ||
12 | /* | |
13 | * Copyright © 2013 Marius Gavrilescu | |
14 | * | |
15 | * This file is part of FonBot. | |
16 | * | |
17 | * FonBot is free software: you can redistribute it and/or modify | |
18 | * it under the terms of the GNU General Public License as published by | |
19 | * the Free Software Foundation, either version 3 of the License, or | |
20 | * (at your option) any later version. | |
21 | * | |
22 | * FonBot is distributed in the hope that it will be useful, | |
23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25 | * GNU General Public License for more details. | |
26 | * | |
27 | * You should have received a copy of the GNU General Public License | |
28 | * along with FonBot. If not, see <http://www.gnu.org/licenses/>. | |
29 | */ | |
30 | ||
31 | /** | |
32 | * Service that responds to GCM events | |
33 | * | |
34 | * @author Marius Gavrilescu <marius@ieval.ro> | |
35 | */ | |
36 | public class GCMIntentService extends GCMBaseIntentService { | |
37 | /** Handler instance */ | |
38 | private final Handler handler=new Handler(Looper.getMainLooper()); | |
39 | ||
40 | /** | |
41 | * Constructs a GCMIntentService with the iEval sender id | |
42 | */ | |
43 | public GCMIntentService() { | |
44 | super(FonBotApplication.GCM_SENDER_ID); | |
45 | } | |
46 | ||
47 | @Override | |
48 | protected void onError(@Nullable final Context context, @Nullable final String errID) { | |
49 | //TODO error handling here | |
50 | } | |
51 | ||
52 | @Override | |
53 | protected void onMessage(@Nullable final Context context, @Nullable final Intent intent) { | |
54 | handler.post(new Runnable(){ | |
55 | @Override | |
56 | public void run() { | |
57 | new PollServerAsyncTask().execute(); | |
58 | } | |
59 | }); | |
60 | } | |
61 | ||
62 | @Override | |
63 | protected void onRegistered(@Nullable final Context context, @Nullable final String regID) { | |
64 | FonBotApplication.instance.regID=regID; | |
65 | } | |
66 | ||
67 | @Override | |
68 | protected void onUnregistered(@Nullable final Context context, @Nullable final String regID) { | |
69 | //do nothing | |
70 | } | |
71 | } |